r24667: Finally merge the registry improvements that Wilco Baan Hofman and I have
[bbaumbach/samba-autobuild/.git] / source4 / lib / registry / tools / regpatch.c
1 /* 
2    Unix SMB/CIFS implementation.
3    simple registry frontend
4    
5    Copyright (C) 2004-2007 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 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/events/events.h"
23 #include "lib/registry/registry.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "lib/registry/tools/common.h"
26 #include "lib/registry/patchfile.h"
27
28 int main(int argc, char **argv)
29 {
30         int opt;
31         poptContext pc;
32         const char *patch;
33         struct registry_context *h;
34         const char *file = NULL;
35         const char *remote = NULL;
36         struct poptOption long_options[] = {
37                 POPT_AUTOHELP
38                 {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
39                 {"file", 'F', POPT_ARG_STRING, &file, 0, "file path", NULL },
40                 POPT_COMMON_SAMBA
41                 POPT_COMMON_CREDENTIALS
42                 { NULL }
43         };
44
45         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
46
47         while((opt = poptGetNextOpt(pc)) != -1) {
48         }
49
50         if (remote) {
51                 h = reg_common_open_remote (remote, cmdline_credentials);
52         } else {
53                 h = reg_common_open_local (cmdline_credentials);
54         }
55         
56         if (h == NULL)
57                 return 1;
58                 
59         patch = poptGetArg(pc);
60         if (patch == NULL) {
61                 poptPrintUsage(pc, stderr, 0);
62                 return 1;
63         }
64
65         poptFreeContext(pc);
66
67         reg_diff_apply(patch, h);
68
69         return 0;
70 }