regedit: search values and repeat search from cursor positions
[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 #include "regedit_treeview.h"
26 #include "regedit_valuelist.h"
27 #include "regedit_dialog.h"
28 #include "regedit_list.h"
29 #include <ncurses.h>
30 #include <menu.h>
31 #include <panel.h>
32
33 #define KEY_START_X     0
34 #define KEY_START_Y     1
35 #define KEY_WIDTH       (COLS / 4)
36 #define KEY_HEIGHT      (LINES - KEY_START_Y - 2)
37 #define VAL_START_X     KEY_WIDTH
38 #define VAL_START_Y     1
39 #define VAL_WIDTH       (COLS - KEY_WIDTH)
40 #define VAL_HEIGHT      (LINES - VAL_START_Y - 2)
41
42 #define HELP1_START_Y   (LINES - 2)
43 #define HELP1_START_X   0
44 #define HELP1_WIDTH     (LINES)
45 #define HELP2_START_Y   (LINES - 1)
46 #define HELP2_START_X   0
47 #define HELP2_WIDTH     (LINES)
48 #define PATH_START_Y    0
49 #define PATH_START_X    6
50 #define PATH_MAX_Y      (COLS - 1)
51 #define PATH_WIDTH      (COLS - 6)
52 #define PATH_WIDTH_MAX  1024
53
54 struct regedit {
55         struct registry_context *registry_context;
56         WINDOW *main_window;
57         WINDOW *path_label;
58         size_t path_len;
59         struct value_list *vl;
60         struct tree_view *keys;
61         bool tree_input;
62         struct regedit_search_opts active_search;
63 };
64
65 static struct regedit *regedit_main = NULL;
66
67 static void show_path(struct regedit *regedit)
68 {
69         int start_pad = 0;
70         int start_win = PATH_START_X;
71
72         if (PATH_START_X + regedit->path_len > COLS) {
73                 start_pad = 3 + PATH_START_X + regedit->path_len - COLS;
74                 mvprintw(PATH_START_Y, start_win, "...");
75                 start_win += 3;
76         }
77         copywin(regedit->path_label, regedit->main_window, 0, start_pad,
78                 PATH_START_Y, start_win, PATH_START_Y, PATH_MAX_Y, false);
79
80         mvchgat(0, 0, COLS, A_BOLD, PAIR_YELLOW_CYAN, NULL);
81 }
82
83 static void print_path(struct regedit *regedit, struct tree_node *node)
84 {
85         regedit->path_len = tree_node_print_path(regedit->path_label, node);
86         show_path(regedit);
87 }
88
89 static void print_help(struct regedit *regedit)
90 {
91         const char *khelp = "[n] New Key [s] New Subkey [d] Del Key "
92                             "[LEFT] Ascend [RIGHT] Descend";
93         const char *vhelp = "[n] New Value [d] Del Value [ENTER] Edit "
94                             "[b] Edit binary";
95         const char *msg = "KEYS";
96         const char *help = khelp;
97         const char *genhelp = "[TAB] Switch sections [q] Quit "
98                               "[UP] List up [DOWN] List down "
99                               "[/] Search [x] Next";
100         int i, pad;
101
102         if (!regedit->tree_input) {
103                 msg = "VALUES";
104                 help = vhelp;
105         }
106
107         move(HELP1_START_Y, HELP1_START_X);
108         clrtoeol();
109         attron(COLOR_PAIR(PAIR_BLACK_CYAN));
110         mvaddstr(HELP1_START_Y, HELP1_START_X, help);
111         pad = COLS - strlen(msg) - strlen(help);
112         for (i = 0; i < pad; ++i) {
113                 addch(' ');
114         }
115         attroff(COLOR_PAIR(PAIR_BLACK_CYAN));
116         attron(COLOR_PAIR(PAIR_YELLOW_CYAN) | A_BOLD);
117         addstr(msg);
118         attroff(COLOR_PAIR(PAIR_YELLOW_CYAN) | A_BOLD);
119
120         move(HELP2_START_Y, HELP2_START_X);
121         clrtoeol();
122         mvaddstr(HELP2_START_Y, HELP2_START_X, genhelp);
123 }
124
125 static void print_heading(struct regedit *regedit)
126 {
127         if (regedit->tree_input) {
128                 tree_view_set_selected(regedit->keys, true);
129                 value_list_set_selected(regedit->vl, false);
130         } else {
131                 tree_view_set_selected(regedit->keys, false);
132                 value_list_set_selected(regedit->vl, true);
133         }
134
135         print_help(regedit);
136 }
137
138 static void load_values(struct regedit *regedit)
139 {
140         struct tree_node *node;
141
142         node = tree_view_get_current_node(regedit->keys);
143         value_list_load(regedit->vl, node->key);
144 }
145
146 static void add_reg_key(struct regedit *regedit, struct tree_node *node,
147                         bool subkey)
148 {
149         const char *name;
150         const char *msg;
151
152         if (!subkey && tree_node_is_top_level(node)) {
153                 return;
154         }
155
156         msg = "Enter name of new key";
157         if (subkey) {
158                 msg = "Enter name of new subkey";
159         }
160         dialog_input(regedit, &name, "New Key", msg);
161         if (name) {
162                 WERROR rv;
163                 struct registry_key *new_key;
164                 struct tree_node *new_node;
165                 struct tree_node *list;
166                 struct tree_node *parent;
167
168                 if (subkey) {
169                         parent = node;
170                         list = node->child_head;
171                 } else {
172                         parent = node->parent;
173                         list = tree_node_first(node);
174                         SMB_ASSERT(list != NULL);
175                 }
176                 rv = reg_key_add_name(regedit, parent->key, name,
177                                       NULL, NULL, &new_key);
178                 if (W_ERROR_IS_OK(rv)) {
179                         /* The list of subkeys may not be present in
180                            cache yet, so if not, don't bother allocating
181                            a new node for the key. */
182                         if (list) {
183                                 new_node = tree_node_new(parent, parent,
184                                                          name, new_key);
185                                 SMB_ASSERT(new_node);
186                                 tree_node_insert_sorted(list, new_node);
187                         } else {
188                                 /* Reopen the parent key to make sure the
189                                    new subkey will be noticed. */
190                                 tree_node_reopen_key(regedit->registry_context,
191                                                      parent);
192                         }
193
194                         list = tree_node_first(node);
195                         tree_view_clear(regedit->keys);
196                         tree_view_update(regedit->keys, list);
197                         if (!subkey) {
198                                 node = new_node;
199                         }
200                         tree_view_set_current_node(regedit->keys, node);
201                         load_values(regedit);
202                 } else {
203                         msg = get_friendly_werror_msg(rv);
204                         dialog_notice(regedit, DIA_ALERT, "New Key",
205                                       "Failed to create key: %s", msg);
206                 }
207                 talloc_free(discard_const(name));
208         }
209 }
210
211 enum search_flags {
212         SEARCH_NEXT = (1<<0),
213         SEARCH_PREV = (1<<1),
214         SEARCH_REPEAT = (1<<2)
215 };
216 static WERROR regedit_search(struct regedit *regedit, struct tree_node *node,
217                              struct value_item *vitem, unsigned flags)
218 {
219         struct regedit_search_opts *opts;
220         struct tree_node *found;
221         struct value_item *found_value;
222         bool search_key, need_sync;
223         char *save_value_name;
224         WERROR rv;
225
226         opts = &regedit->active_search;
227
228         if (!opts->query || !opts->match) {
229                 return WERR_OK;
230         }
231
232         SMB_ASSERT(opts->search_key || opts->search_value);
233
234         rv = WERR_OK;
235         found = NULL;
236         found_value = NULL;
237         save_value_name = NULL;
238         search_key = opts->search_key;
239         need_sync = false;
240
241         if (opts->search_value) {
242                 struct value_item *it;
243
244                 it = value_list_get_current_item(regedit->vl);
245                 if (it) {
246                         save_value_name = talloc_strdup(regedit,
247                                                         it->value_name);
248                         if (save_value_name == NULL) {
249                                 return WERR_NOMEM;
250                         }
251                 }
252
253                 if (vitem) {
254                         search_key = false;
255                 }
256         }
257
258         if (!vitem && (flags & SEARCH_REPEAT)) {
259                 if (opts->search_value) {
260                         search_key = false;
261                 } else if (!tree_node_next(&node, opts->search_recursive, &rv)) {
262                         beep();
263                         return rv;
264                 }
265         }
266
267         do {
268                 if (search_key) {
269                         SMB_ASSERT(opts->search_key == true);
270                         if (opts->match(node->name, opts->query)) {
271                                 found = node;
272                         } else if (opts->search_value) {
273                                 search_key = false;
274                         }
275                 }
276                 if (!search_key) {
277                         SMB_ASSERT(opts->search_value == true);
278                         if (!vitem) {
279                                 rv = value_list_load_quick(regedit->vl,
280                                                            node->key);
281                                 if (!W_ERROR_IS_OK(rv)) {
282                                         goto out;
283                                 }
284                                 need_sync = true;
285                         }
286                         found_value = value_list_find_next_item(regedit->vl,
287                                                                 vitem,
288                                                                 opts->query,
289                                                                 opts->match);
290                         if (found_value) {
291                                 found = node;
292                         } else {
293                                 vitem = NULL;
294                                 search_key = opts->search_key;
295                         }
296                 }
297         } while (!found && tree_node_next(&node, opts->search_recursive, &rv));
298
299         if (!W_ERROR_IS_OK(rv)) {
300                 goto out;
301         }
302
303         if (found) {
304                 /* Put the cursor on the node that was found */
305                 if (!tree_view_is_node_visible(regedit->keys, found)) {
306                         tree_view_update(regedit->keys,
307                                          tree_node_first(found));
308                         print_path(regedit, found);
309                 }
310                 tree_view_set_current_node(regedit->keys, found);
311                 if (found_value) {
312                         if (need_sync) {
313                                 value_list_sync(regedit->vl);
314                         }
315                         value_list_set_current_item(regedit->vl, found_value);
316                         regedit->tree_input = false;
317                 } else {
318                         load_values(regedit);
319                         regedit->tree_input = true;
320                 }
321                 tree_view_show(regedit->keys);
322                 value_list_show(regedit->vl);
323                 print_heading(regedit);
324         } else {
325                 if (need_sync) {
326                         load_values(regedit);
327                         value_list_set_current_item_by_name(regedit->vl,
328                                                             save_value_name);
329                 }
330                 beep();
331         }
332
333 out:
334         talloc_free(save_value_name);
335
336         return rv;
337 }
338
339 static void regedit_search_repeat(struct regedit *regedit, unsigned flags)
340 {
341         struct tree_node *node;
342         struct value_item *vitem;
343         struct regedit_search_opts *opts;
344
345         opts = &regedit->active_search;
346         if (opts->query == NULL) {
347                 return;
348         }
349
350         node = tree_view_get_current_node(regedit->keys);
351         vitem = NULL;
352         if (opts->search_value && !regedit->tree_input) {
353                 vitem = value_list_get_current_item(regedit->vl);
354         }
355         regedit_search(regedit, node, vitem, flags | SEARCH_REPEAT);
356 }
357
358 static void handle_tree_input(struct regedit *regedit, int c)
359 {
360         struct tree_node *node;
361
362         switch (c) {
363         case KEY_DOWN:
364                 tree_view_driver(regedit->keys, ML_CURSOR_DOWN);
365                 load_values(regedit);
366                 break;
367         case KEY_UP:
368                 tree_view_driver(regedit->keys, ML_CURSOR_UP);
369                 load_values(regedit);
370                 break;
371         case '\n':
372         case KEY_ENTER:
373         case KEY_RIGHT:
374                 node = tree_view_get_current_node(regedit->keys);
375                 if (node && tree_node_has_children(node)) {
376                         WERROR rv;
377
378                         rv = tree_node_load_children(node);
379                         if (W_ERROR_IS_OK(rv)) {
380                                 print_path(regedit, node->child_head);
381                                 tree_view_update(regedit->keys, node->child_head);
382                                 value_list_load(regedit->vl, node->child_head->key);
383                         } else {
384                                 const char *msg = get_friendly_werror_msg(rv);
385                                 dialog_notice(regedit, DIA_ALERT, "Loading Subkeys",
386                                               "Failed to load subkeys: %s", msg);
387                         }
388                 }
389                 break;
390         case KEY_LEFT:
391                 node = tree_view_get_current_node(regedit->keys);
392                 if (node && !tree_node_is_top_level(node)) {
393                         print_path(regedit, node->parent);
394                         node = node->parent;
395                         tree_view_update(regedit->keys, tree_node_first(node));
396                         tree_view_set_current_node(regedit->keys, node);
397                         value_list_load(regedit->vl, node->key);
398                 }
399                 break;
400         case 'n':
401         case 'N':
402                 node = tree_view_get_current_node(regedit->keys);
403                 add_reg_key(regedit, node, false);
404                 break;
405         case 's':
406         case 'S':
407                 node = tree_view_get_current_node(regedit->keys);
408                 add_reg_key(regedit, node, true);
409                 break;
410         case 'd':
411         case 'D': {
412                 int sel;
413
414                 node = tree_view_get_current_node(regedit->keys);
415                 if (tree_node_is_top_level(node)) {
416                         break;
417                 }
418                 sel = dialog_notice(regedit, DIA_CONFIRM,
419                                     "Delete Key",
420                                      "Really delete key \"%s\"?",
421                                      node->name);
422                 if (sel == DIALOG_OK) {
423                         WERROR rv;
424                         struct tree_node *pop;
425                         struct tree_node *parent = node->parent;
426
427                         rv = reg_key_del(node, parent->key, node->name);
428                         if (W_ERROR_IS_OK(rv)) {
429                                 tree_node_reopen_key(regedit->registry_context,
430                                                      parent);
431                                 tree_view_clear(regedit->keys);
432                                 pop = tree_node_pop(&node);
433                                 talloc_free(pop);
434                                 node = parent->child_head;
435                                 if (node == NULL) {
436                                         node = tree_node_first(parent);
437                                         print_path(regedit, node);
438                                 }
439                                 tree_view_update(regedit->keys, node);
440                                 value_list_load(regedit->vl, node->key);
441                         } else {
442                                 const char *msg = get_friendly_werror_msg(rv);
443                                 dialog_notice(regedit, DIA_ALERT, "Delete Key",
444                                               "Failed to delete key: %s", msg);
445                         }
446                 }
447                 break;
448         }
449         }
450
451         tree_view_show(regedit->keys);
452         value_list_show(regedit->vl);
453 }
454
455 static void handle_value_input(struct regedit *regedit, int c)
456 {
457         struct value_item *vitem;
458         bool binmode = false;
459         WERROR err;
460         int sel;
461
462         switch (c) {
463         case KEY_DOWN:
464                 value_list_driver(regedit->vl, ML_CURSOR_DOWN);
465                 break;
466         case KEY_UP:
467                 value_list_driver(regedit->vl, ML_CURSOR_UP);
468                 break;
469         case 'b':
470         case 'B':
471                 binmode = true;
472                 /* Falthrough... */
473         case '\n':
474         case KEY_ENTER:
475                 vitem = value_list_get_current_item(regedit->vl);
476                 if (vitem) {
477                         struct tree_node *node;
478                         const char *name = NULL;
479                         node = tree_view_get_current_node(regedit->keys);
480                         sel = dialog_edit_value(regedit, node->key, vitem->type,
481                                                 vitem, binmode, &err, &name);
482                         if (!W_ERROR_IS_OK(err)) {
483                                 const char *msg = get_friendly_werror_msg(err);
484                                 dialog_notice(regedit, DIA_ALERT, "Error",
485                                               "Error editing value:\n%s", msg);
486                         } else if (sel == DIALOG_OK) {
487                                 tree_node_reopen_key(regedit->registry_context,
488                                                      node);
489                                 value_list_load(regedit->vl, node->key);
490                                 value_list_set_current_item_by_name(regedit->vl,
491                                                                     name);
492                                 talloc_free(discard_const(name));
493                         }
494                 }
495                 break;
496         case 'n':
497         case 'N': {
498                 int new_type;
499
500                 sel = dialog_select_type(regedit, &new_type);
501                 if (sel == DIALOG_OK) {
502                         struct tree_node *node;
503                         const char *name = NULL;
504                         node = tree_view_get_current_node(regedit->keys);
505                         sel = dialog_edit_value(regedit, node->key, new_type,
506                                                 NULL, false, &err, &name);
507                         if (!W_ERROR_IS_OK(err)) {
508                                 const char *msg = get_friendly_werror_msg(err);
509                                 dialog_notice(regedit, DIA_ALERT, "Error",
510                                               "Error creating value:\n%s", msg);
511                         } else if (sel == DIALOG_OK) {
512                                 tree_node_reopen_key(regedit->registry_context,
513                                                      node);
514                                 value_list_load(regedit->vl, node->key);
515                                 value_list_set_current_item_by_name(regedit->vl,
516                                                                     name);
517                                 talloc_free(discard_const(name));
518                         }
519                 }
520                 break;
521         }
522         case 'd':
523         case 'D':
524                 vitem = value_list_get_current_item(regedit->vl);
525                 if (vitem) {
526                         sel = dialog_notice(regedit, DIA_CONFIRM,
527                                             "Delete Value",
528                                              "Really delete value \"%s\"?",
529                                              vitem->value_name);
530                         if (sel == DIALOG_OK) {
531                                 struct tree_node *node;
532                                 node = tree_view_get_current_node(regedit->keys);
533                                 reg_del_value(regedit, node->key,
534                                               vitem->value_name);
535                                 tree_node_reopen_key(regedit->registry_context,
536                                                      node);
537                                 value_list_load(regedit->vl, node->key);
538                         }
539                 }
540                 break;
541         }
542
543         value_list_show(regedit->vl);
544 }
545
546 static bool find_substring(const char *haystack, const char *needle)
547 {
548         return strstr(haystack, needle) != NULL;
549 }
550
551 static bool find_substring_nocase(const char *haystack, const char *needle)
552 {
553         return strcasestr(haystack, needle) != NULL;
554 }
555
556 static void handle_main_input(struct regedit *regedit, int c)
557 {
558         switch (c) {
559         case 18: { /* CTRL-R */
560                 struct tree_node *root, *node;
561                 const char **path;
562
563                 node = tree_view_get_current_node(regedit->keys);
564                 path = tree_node_get_path(regedit, node);
565                 SMB_ASSERT(path != NULL);
566
567                 root = tree_node_new_root(regedit, regedit->registry_context);
568                 SMB_ASSERT(root != NULL);
569
570                 tree_view_set_root(regedit->keys, root);
571                 tree_view_set_path(regedit->keys, path);
572                 node = tree_view_get_current_node(regedit->keys);
573                 value_list_load(regedit->vl, node->key);
574                 tree_view_show(regedit->keys);
575                 value_list_show(regedit->vl);
576                 print_path(regedit, node);
577                 talloc_free(discard_const(path));
578                 break;
579         }
580         case 'f':
581         case 'F':
582         case '/': {
583                 int rv;
584                 struct regedit_search_opts *opts;
585                 struct tree_node *node;
586
587                 opts = &regedit->active_search;
588                 rv = dialog_search_input(regedit, opts);
589                 if (rv == DIALOG_OK) {
590                         SMB_ASSERT(opts->query != NULL);
591                         opts->match = find_substring_nocase;
592                         node = regedit->keys->root;
593                         if (opts->search_case) {
594                                 opts->match = find_substring;
595                         }
596                         if (!opts->search_recursive) {
597                                 node = tree_view_get_current_node(regedit->keys);
598                                 node = tree_node_first(node);
599                         }
600                         regedit_search(regedit, node, NULL, SEARCH_NEXT);
601                 }
602                 break;
603         }
604         case 'x':
605         case 'X':
606                 regedit_search_repeat(regedit, SEARCH_NEXT);
607                 break;
608         case '\t':
609                 regedit->tree_input = !regedit->tree_input;
610                 print_heading(regedit);
611                 break;
612         default:
613                 if (regedit->tree_input) {
614                         handle_tree_input(regedit, c);
615                 } else {
616                         handle_value_input(regedit, c);
617                 }
618         }
619 }
620
621 int regedit_getch(void)
622 {
623         int c;
624
625         SMB_ASSERT(regedit_main);
626
627         c = getch();
628         if (c == KEY_RESIZE) {
629                 tree_view_resize(regedit_main->keys, KEY_HEIGHT, KEY_WIDTH,
630                                  KEY_START_Y, KEY_START_X);
631                 value_list_resize(regedit_main->vl, VAL_HEIGHT, VAL_WIDTH,
632                                   VAL_START_Y, VAL_START_X);
633                 print_heading(regedit_main);
634                 show_path(regedit_main);
635         }
636
637         return c;
638 }
639
640 static void regedit_panic_handler(const char *msg)
641 {
642         endwin();
643         smb_panic_s3(msg);
644 }
645
646 static void display_window(TALLOC_CTX *mem_ctx, struct registry_context *ctx)
647 {
648         struct regedit *regedit;
649         struct tree_node *root;
650         bool colors;
651         int key;
652
653         initscr();
654
655         cbreak();
656         noecho();
657
658         fault_configure(regedit_panic_handler);
659
660         colors = has_colors();
661         if (colors) {
662                 start_color();
663                 use_default_colors();
664                 assume_default_colors(COLOR_WHITE, COLOR_BLUE);
665                 init_pair(PAIR_YELLOW_CYAN, COLOR_YELLOW, COLOR_CYAN);
666                 init_pair(PAIR_BLACK_CYAN, COLOR_BLACK, COLOR_CYAN);
667                 init_pair(PAIR_YELLOW_BLUE, COLOR_YELLOW, COLOR_BLUE);
668         }
669
670         regedit = talloc_zero(mem_ctx, struct regedit);
671         SMB_ASSERT(regedit != NULL);
672         regedit_main = regedit;
673
674         regedit->registry_context = ctx;
675         regedit->main_window = stdscr;
676         keypad(regedit->main_window, TRUE);
677
678         mvwprintw(regedit->main_window, 0, 0, "Path: ");
679         regedit->path_label = newpad(1, PATH_WIDTH_MAX);
680         SMB_ASSERT(regedit->path_label);
681         wprintw(regedit->path_label, "/");
682         show_path(regedit_main);
683
684         root = tree_node_new_root(regedit, ctx);
685         SMB_ASSERT(root != NULL);
686
687         regedit->keys = tree_view_new(regedit, root, KEY_HEIGHT, KEY_WIDTH,
688                                       KEY_START_Y, KEY_START_X);
689         SMB_ASSERT(regedit->keys != NULL);
690
691         regedit->vl = value_list_new(regedit, VAL_HEIGHT, VAL_WIDTH,
692                                      VAL_START_Y, VAL_START_X);
693         SMB_ASSERT(regedit->vl != NULL);
694
695         regedit->tree_input = true;
696         print_heading(regedit);
697
698         tree_view_show(regedit->keys);
699         load_values(regedit);
700         value_list_show(regedit->vl);
701
702         update_panels();
703         doupdate();
704
705         do {
706                 key = regedit_getch();
707
708                 handle_main_input(regedit, key);
709                 update_panels();
710                 doupdate();
711         } while (key != 'q' || key == 'Q');
712
713         endwin();
714 }
715
716 int main(int argc, const char **argv)
717 {
718         struct poptOption long_options[] = {
719                 POPT_AUTOHELP
720                 /* ... */
721                 POPT_COMMON_SAMBA
722                 POPT_COMMON_CONNECTION
723                 POPT_COMMON_CREDENTIALS
724                 POPT_TABLEEND
725         };
726         int opt;
727         poptContext pc;
728         struct user_auth_info *auth_info;
729         TALLOC_CTX *frame;
730         struct registry_context *ctx;
731         WERROR rv;
732
733         frame = talloc_stackframe();
734
735         setup_logging("regedit", DEBUG_DEFAULT_STDERR);
736         lp_set_cmdline("log level", "0");
737
738         /* process options */
739         auth_info = user_auth_info_init(frame);
740         if (auth_info == NULL) {
741                 exit(1);
742         }
743         popt_common_set_auth_info(auth_info);
744         pc = poptGetContext("regedit", argc, argv, long_options, 0);
745
746         while ((opt = poptGetNextOpt(pc)) != -1) {
747                 /* TODO */
748         }
749
750         if (!lp_load_global(get_dyn_CONFIGFILE())) {
751                 DEBUG(0, ("ERROR loading config file...\n"));
752                 exit(1);
753         }
754
755         /* some simple tests */
756
757         rv = reg_open_samba3(frame, &ctx);
758         if (!W_ERROR_IS_OK(rv)) {
759                 TALLOC_FREE(frame);
760
761                 return 1;
762         }
763
764         display_window(frame, ctx);
765
766         TALLOC_FREE(frame);
767
768         return 0;
769 }