r24994: Fix some C++ warnings.
[nivanova/samba-autobuild/.git] / source4 / lib / registry / tools / common.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Popt routines specifically for registry
4
5    Copyright (C) Jelmer Vernooij 2007
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 "auth/credentials/credentials.h"
23 #include "lib/registry/registry.h"
24 #include "lib/registry/tools/common.h"
25
26 struct registry_context *reg_common_open_remote(const char *remote, struct cli_credentials *creds)
27 {
28         struct registry_context *h;
29         WERROR error;
30         
31         error = reg_open_remote(&h, NULL, creds, remote, NULL);
32
33         if (!W_ERROR_IS_OK(error)) {
34                 fprintf(stderr, "Unable to open remote registry at %s:%s \n", remote, win_errstr(error));
35                 return NULL;
36         }
37
38         return h;
39 }
40
41 struct registry_key *reg_common_open_file(const char *path, struct cli_credentials *creds)
42 {
43         struct hive_key *hive_root;
44         struct registry_context *h;
45         WERROR error;
46
47         error = reg_open_hive(NULL, path, NULL, creds, &hive_root);
48
49         if(!W_ERROR_IS_OK(error)) {
50                 fprintf(stderr, "Unable to open '%s': %s \n", path, win_errstr(error));
51                 return NULL;
52         }
53
54         error = reg_open_local(NULL, &h, NULL, creds);
55         if (!W_ERROR_IS_OK(error)) {
56                 fprintf(stderr, "Unable to initialize local registry: %s\n", win_errstr(error));
57                 return NULL;
58         }
59
60         return reg_import_hive_key(h, hive_root, -1, NULL);
61 }
62
63 struct registry_context *reg_common_open_local(struct cli_credentials *creds)
64 {
65         WERROR error;
66         struct registry_context *h;
67         
68         error = reg_open_samba(NULL, &h, NULL, creds);
69
70         if(!W_ERROR_IS_OK(error)) {
71                 fprintf(stderr, "Unable to open local registry:%s \n", win_errstr(error));
72                 return NULL;
73         }
74
75         return h;
76 }