r23792: convert Samba4 to GPLv3
[kai/samba-autobuild/.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 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
26 int main(int argc, char **argv)
27 {
28         int opt;
29         poptContext pc;
30         const char *patch;
31         struct registry_context *h;
32         const char *remote = NULL;
33         struct reg_diff *diff;
34         WERROR error;
35         struct poptOption long_options[] = {
36                 POPT_AUTOHELP
37                 {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
38                 POPT_COMMON_SAMBA
39                 POPT_COMMON_CREDENTIALS
40                 { NULL }
41         };
42
43         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
44
45         while((opt = poptGetNextOpt(pc)) != -1) {
46         }
47
48         registry_init();
49
50         if (remote) {
51                 error = reg_open_remote (&h, NULL, cmdline_credentials, remote, NULL);
52         } else {
53                 error = reg_open_local (NULL, &h, NULL, cmdline_credentials);
54         }
55
56         if (W_ERROR_IS_OK(error)) {
57                 fprintf(stderr, "Error: %s\n", win_errstr(error));
58                 return 1;
59         }
60                 
61         patch = poptGetArg(pc);
62         poptFreeContext(pc);
63
64         diff = reg_diff_load(NULL, patch);
65         if (!diff) {
66                 fprintf(stderr, "Unable to load registry patch from `%s'\n", patch);
67                 return 1;
68         }
69
70         reg_diff_apply(diff, h);
71
72         return 0;
73 }