r12500: Use init functions explicitly in a few more places. 'gensec' and 'librpc'
[bbaumbach/samba-autobuild/.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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "dynconfig.h"
24 #include "lib/registry/registry.h"
25 #include "lib/cmdline/popt_common.h"
26 #include "smb_build.h"
27
28 int main(int argc, char **argv)
29 {
30         int opt;
31         poptContext pc;
32         char *outputfile = NULL;
33         struct registry_context *h1 = NULL, *h2 = NULL;
34         int from_null = 0;
35         WERROR error;
36         struct reg_diff *diff;
37         struct poptOption long_options[] = {
38                 POPT_AUTOHELP
39                 {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
40                 {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL },
41                 {"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL },
42                 {"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL },
43                 POPT_COMMON_SAMBA
44                 POPT_COMMON_CREDENTIALS
45                 POPT_COMMON_VERSION
46                 POPT_TABLEEND
47         };
48
49         regdiff_init_subsystems;
50
51         registry_init();
52
53         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
54
55         while((opt = poptGetNextOpt(pc)) != -1) {
56                 error = WERR_OK;
57                 switch(opt)     {
58                 case 'L':
59                         if (!h1 && !from_null) error = reg_open_local(&h1);
60                         else if (!h2) error = reg_open_local(&h2);
61                         break;
62                 case 'R':
63                         if (!h1 && !from_null) 
64                                 error = reg_open_remote(&h1, cmdline_credentials, 
65                                                         poptGetOptArg(pc), NULL);
66                         else if (!h2) error = reg_open_remote(&h2, cmdline_credentials, 
67                                                               poptGetOptArg(pc), NULL);
68                         break;
69                 }
70
71                 if (!W_ERROR_IS_OK(error)) {
72                         fprintf(stderr, "Error: %s\n", win_errstr(error));
73                         return 1;
74                 }
75         }
76
77         poptFreeContext(pc);
78
79         diff = reg_generate_diff(NULL, h1, h2);
80         if (!diff) {
81                 fprintf(stderr, "Unable to generate diff between keys\n");
82                 return -1;
83         }
84
85         reg_diff_save(diff, outputfile);
86
87         return 0;
88 }