r12499: Move smb_build.h out of includes.h
[samba.git] / source4 / lib / registry / tools / regpatch.c
1 /* 
2    Unix SMB/CIFS implementation.
3    simple registry frontend
4    
5    Copyright (C) 2004-2005 Jelmer Vernooij, jelmer@samba.org
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 "system/filesys.h"
27 #include "librpc/gen_ndr/winreg.h"
28 #include "smb_build.h"
29
30 int main(int argc, char **argv)
31 {
32         int opt;
33         poptContext pc;
34         const char *patch;
35         struct registry_context *h;
36         const char *remote = NULL;
37         struct reg_diff *diff;
38         WERROR error;
39         struct poptOption long_options[] = {
40                 POPT_AUTOHELP
41                 {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
42                 POPT_COMMON_SAMBA
43                 POPT_COMMON_CREDENTIALS
44                 POPT_TABLEEND
45         };
46
47         regpatch_init_subsystems;
48
49         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
50
51         while((opt = poptGetNextOpt(pc)) != -1) {
52         }
53
54         if (remote) {
55                 error = reg_open_remote (&h, cmdline_credentials, remote, NULL);
56         } else {
57                 error = reg_open_local (&h);
58         }
59
60         if (W_ERROR_IS_OK(error)) {
61                 fprintf(stderr, "Error: %s\n", win_errstr(error));
62                 return 1;
63         }
64                 
65         patch = poptGetArg(pc);
66         poptFreeContext(pc);
67
68         diff = reg_diff_load(NULL, patch);
69         if (!diff) {
70                 fprintf(stderr, "Unable to load registry patch from `%s'\n", patch);
71                 return 1;
72         }
73
74         reg_diff_apply(diff, h);
75
76         return 0;
77 }