regedit: Add regedit main source file
[samba.git] / source3 / utils / regedit.c
1 /*
2  * Samba Unix/Linux SMB client library
3  * Registry Editor
4  * Copyright (C) Christopher Davis 2012
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "includes.h"
21 #include "popt_common.h"
22 #include "lib/util/data_blob.h"
23 #include "lib/registry/registry.h"
24 #include "regedit.h"
25
26 int main(int argc, char **argv)
27 {
28         struct poptOption long_options[] = {
29                 POPT_AUTOHELP
30                 /* ... */
31                 POPT_COMMON_SAMBA
32                 POPT_COMMON_CONNECTION
33                 POPT_COMMON_CREDENTIALS
34                 POPT_TABLEEND
35         };
36         int opt;
37         poptContext pc;
38         struct user_auth_info *auth_info;
39         TALLOC_CTX *frame;
40         struct registry_context *ctx;
41         struct registry_key *hklm;
42         struct registry_key *smbconf;
43         uint32_t n;
44         WERROR rv;
45
46         frame = talloc_stackframe();
47
48         setup_logging("regedit", DEBUG_DEFAULT_STDERR);
49         lp_set_cmdline("log level", "0");
50         lp_load_global(get_dyn_CONFIGFILE());
51
52         /* process options */
53         auth_info = user_auth_info_init(frame);
54         if (auth_info == NULL) {
55                 exit(1);
56         }
57         popt_common_set_auth_info(auth_info);
58         pc = poptGetContext("regedit", argc, (const char **)argv, long_options, 0);
59
60         while ((opt = poptGetNextOpt(pc)) != -1) {
61                 /* TODO */
62         }
63
64         /* some simple tests */
65
66         rv = reg_open_samba3(frame, &ctx);
67         SMB_ASSERT(W_ERROR_IS_OK(rv));
68
69         rv = reg_get_predefined_key_by_name(ctx, "HKEY_LOCAL_MACHINE", &hklm);
70         SMB_ASSERT(W_ERROR_IS_OK(rv));
71
72         printf("contents of hklm/SOFTWARE/Samba/smbconf...\n");
73
74         rv = reg_open_key(ctx, hklm, "SOFTWARE\\Samba\\smbconf", &smbconf);
75         SMB_ASSERT(W_ERROR_IS_OK(rv));
76
77         printf("subkeys...\n");
78
79         for (n = 0; ;++n) {
80                 const char *name, *klass;
81                 NTTIME modified;
82
83                 rv = reg_key_get_subkey_by_index(ctx, smbconf, n, &name,
84                                                 &klass, &modified);
85                 if (!W_ERROR_IS_OK(rv)) {
86                         break;
87                 }
88
89                 printf("%u: %s\n", (unsigned)n, name);
90         }
91
92         TALLOC_FREE(frame);
93
94         return 0;
95 }