r21834: Remove unnecessary includes
[Samba/ekacnet.git] / source4 / lib / registry / tools / regdiff.c
blobab6f7c1a576820a2ad6edcee89b606d562751c86
1 /*
2 Unix SMB/CIFS implementation.
3 simple registry frontend
5 Copyright (C) Jelmer Vernooij 2004-2005
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.
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.
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.
22 #include "includes.h"
23 #include "lib/registry/registry.h"
24 #include "lib/events/events.h"
25 #include "lib/cmdline/popt_common.h"
27 int main(int argc, char **argv)
29 int opt;
30 poptContext pc;
31 char *outputfile = NULL;
32 struct registry_context *h1 = NULL, *h2 = NULL;
33 int from_null = 0;
34 WERROR error;
35 struct reg_diff *diff;
36 struct poptOption long_options[] = {
37 POPT_AUTOHELP
38 {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
39 {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL },
40 {"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL },
41 {"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL },
42 POPT_COMMON_SAMBA
43 POPT_COMMON_CREDENTIALS
44 POPT_COMMON_VERSION
45 { NULL }
48 registry_init();
50 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
52 while((opt = poptGetNextOpt(pc)) != -1) {
53 error = WERR_OK;
54 switch(opt) {
55 case 'L':
56 if (!h1 && !from_null) error = reg_open_local(NULL, &h1, NULL, cmdline_credentials);
57 else if (!h2) error = reg_open_local(NULL, &h2, NULL, cmdline_credentials);
58 break;
59 case 'R':
60 if (!h1 && !from_null)
61 error = reg_open_remote(&h1, NULL, cmdline_credentials,
62 poptGetOptArg(pc), NULL);
63 else if (!h2) error = reg_open_remote(&h2, NULL, cmdline_credentials,
64 poptGetOptArg(pc), NULL);
65 break;
68 if (!W_ERROR_IS_OK(error)) {
69 fprintf(stderr, "Error: %s\n", win_errstr(error));
70 return 1;
74 poptFreeContext(pc);
76 diff = reg_generate_diff(NULL, h1, h2);
77 if (!diff) {
78 fprintf(stderr, "Unable to generate diff between keys\n");
79 return -1;
82 reg_diff_save(diff, outputfile);
84 return 0;