r23792: convert Samba4 to GPLv3
[metze/samba/wip.git] / source4 / lib / registry / tools / regdiff.c
1 /* 
2    Unix SMB/CIFS implementation.
3    simple registry frontend
4    
5    Copyright (C) Jelmer Vernooij 2004-2005
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "lib/registry/registry.h"
23 #include "lib/events/events.h"
24 #include "lib/cmdline/popt_common.h"
25
26 int main(int argc, char **argv)
27 {
28         int opt;
29         poptContext pc;
30         char *outputfile = NULL;
31         struct registry_context *h1 = NULL, *h2 = NULL;
32         int from_null = 0;
33         WERROR error;
34         struct reg_diff *diff;
35         struct poptOption long_options[] = {
36                 POPT_AUTOHELP
37                 {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
38                 {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL },
39                 {"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL },
40                 {"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL },
41                 POPT_COMMON_SAMBA
42                 POPT_COMMON_CREDENTIALS
43                 POPT_COMMON_VERSION
44                 { NULL }
45         };
46
47         registry_init();
48
49         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
50
51         while((opt = poptGetNextOpt(pc)) != -1) {
52                 error = WERR_OK;
53                 switch(opt)     {
54                 case 'L':
55                         if (!h1 && !from_null) error = reg_open_local(NULL, &h1, NULL, cmdline_credentials);
56                         else if (!h2) error = reg_open_local(NULL, &h2, NULL, cmdline_credentials);
57                         break;
58                 case 'R':
59                         if (!h1 && !from_null) 
60                                 error = reg_open_remote(&h1, NULL, cmdline_credentials, 
61                                                         poptGetOptArg(pc), NULL);
62                         else if (!h2) error = reg_open_remote(&h2, NULL, cmdline_credentials, 
63                                                               poptGetOptArg(pc), NULL);
64                         break;
65                 }
66
67                 if (!W_ERROR_IS_OK(error)) {
68                         fprintf(stderr, "Error: %s\n", win_errstr(error));
69                         return 1;
70                 }
71         }
72
73         poptFreeContext(pc);
74
75         diff = reg_generate_diff(NULL, h1, h2);
76         if (!diff) {
77                 fprintf(stderr, "Unable to generate diff between keys\n");
78                 return -1;
79         }
80
81         reg_diff_save(diff, outputfile);
82
83         return 0;
84 }