2 Unix SMB/CIFS implementation.
3 simple registry frontend
5 Copyright (C) Jelmer Vernooij 2004
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.
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.
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.
26 * ls - list values/keys
27 * rmval/rm - remove value
28 * rmkey/rmdir - remove key
29 * mkkey/mkdir - make key
34 static REG_KEY *cmd_set(REG_KEY *cur, int argc, char **argv)
40 static REG_KEY *cmd_ck(REG_KEY *cur, int argc, char **argv)
46 new = reg_open_key(cur, argv[1]);
51 printf("Current path is: %s\n", reg_key_get_path(new));
56 static REG_KEY *cmd_ls(REG_KEY *cur, int argc, char **argv)
59 num = reg_key_num_subkeys(cur);
60 for(i = 0; i < num; i++) {
61 REG_KEY *sub = reg_key_get_subkey_by_index(cur, i);
62 printf("K %s\n", reg_key_name(sub));
65 num = reg_key_num_values(cur);
66 for(i = 0; i < num; i++) {
67 REG_VAL *sub = reg_key_get_value_by_index(cur, i);
68 printf("V %s %s %s\n", reg_val_name(sub), str_regtype(reg_val_type(sub)), reg_val_data_string(sub));
73 static REG_KEY *cmd_mkkey(REG_KEY *cur, int argc, char **argv)
76 fprintf(stderr, "Usage: mkkey <keyname>\n");
80 if(!reg_key_add_name(cur, argv[1])) {
81 fprintf(stderr, "Error adding new subkey '%s'\n", argv[1]);
85 fprintf(stderr, "Successfully added new subkey '%s' to '%s'\n", argv[1], reg_key_get_path(cur));
90 static REG_KEY *cmd_rmkey(REG_KEY *cur, int argc, char **argv)
94 fprintf(stderr, "Usage: rmkey <name>\n");
98 key = reg_open_key(cur, argv[1]);
100 fprintf(stderr, "No such subkey '%s'\n", argv[1]);
104 if(!reg_key_del(key)) {
105 fprintf(stderr, "Error deleting '%s'\n", argv[1]);
107 fprintf(stderr, "Successfully deleted '%s'\n", argv[1]);
113 static REG_KEY *cmd_rmval(REG_KEY *cur, int argc, char **argv)
117 fprintf(stderr, "Usage: rmval <valuename>\n");
121 val = reg_key_get_value_by_name(cur, argv[1]);
123 fprintf(stderr, "No such value '%s'\n", argv[1]);
127 if(!reg_val_del(val)) {
128 fprintf(stderr, "Error deleting value '%s'\n", argv[1]);
130 fprintf(stderr, "Successfully deleted value '%s'\n", argv[1]);
136 static REG_KEY *cmd_exit(REG_KEY *cur, int argc, char **argv)
142 static REG_KEY *cmd_help(REG_KEY *, int, char **);
148 REG_KEY *(*handle)(REG_KEY *, int argc, char **argv);
149 } regshell_cmds[] = {
150 {"ck", "cd", "Change current key", cmd_ck },
151 {"list", "ls", "List values/keys in current key", cmd_ls },
152 {"mkkey", "mkdir", "Make new key", cmd_mkkey },
153 {"rmval", "rm", "Remove value", cmd_rmval },
154 {"rmkey", "rmdir", "Remove key", cmd_rmkey },
155 {"set", "update", "Update value", cmd_set },
156 {"help", "?", "Help", cmd_help },
157 {"exit", "quit", "Exit", cmd_exit },
161 static REG_KEY *cmd_help(REG_KEY *cur, int argc, char **argv)
164 printf("Available commands:\n");
165 for(i = 0; regshell_cmds[i].name; i++) {
166 printf("%s - %s\n", regshell_cmds[i].name, regshell_cmds[i].help);
171 REG_KEY *process_cmd(REG_KEY *k, char *line)
177 if ((ret = poptParseArgvString(line, &argc, (const char ***) &argv)) != 0) {
178 fprintf(stderr, "regshell: %s\n", poptStrerror(ret));
182 for(i = 0; regshell_cmds[i].name; i++) {
183 if(!strcmp(regshell_cmds[i].name, argv[0]) ||
184 (regshell_cmds[i].alias && !strcmp(regshell_cmds[i].alias, argv[0]))) {
185 return regshell_cmds[i].handle(k, argc, argv);
189 fprintf(stderr, "No such command '%s'\n", argv[0]);
194 int main (int argc, char **argv)
196 uint32 setparms, checkparms;
198 char *backend = "dir";
199 REG_KEY *curkey = NULL;;
202 struct poptOption long_options[] = {
205 {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
209 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
211 while((opt = poptGetNextOpt(pc)) != -1) {
214 h = reg_open(backend, poptPeekArg(pc), True);
216 fprintf(stderr, "Unable to open '%s' with backend '%s'\n", poptGetArg(pc), backend);
221 setup_logging("regtree", True);
223 curkey = reg_get_root(h);
225 if(!curkey) return 1;
230 asprintf(&prompt, "%s> ", reg_key_get_path(curkey));
232 line = smb_readline(prompt, NULL, NULL);
237 if(line[0] != '\n') {
238 REG_KEY *new = process_cmd(curkey, line);