r1429: enable spnego in smbclient too.
[samba.git] / source / gtk / tools / gregedit.c
1 /* 
2    Unix SMB/CIFS implementation.
3    GTK+ registry frontend
4    
5    Copyright (C) Jelmer Vernooij 2004
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <stdio.h>
31
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtk.h>
34 #include "includes.h"
35
36 GtkWidget *openfilewin;
37 GtkWidget *savefilewin;
38 GtkTreeStore *store_keys;
39 GtkListStore *store_vals;
40 GtkWidget *tree_keys;
41 GtkWidget *aboutwin;
42 GtkWidget *mainwin;
43
44 GtkWidget *save;
45 GtkWidget *save_as;
46 static GtkWidget* create_openfilewin (void);
47 static GtkWidget* create_savefilewin (void);
48 REG_HANDLE *registry = NULL;
49
50 static void expand_key(GtkTreeView *treeview, GtkTreeIter *parent, GtkTreePath *arg2)
51 {
52         GtkTreeIter firstiter, iter, tmpiter;
53         REG_KEY *k, *sub;
54         char *name;
55         GValue value;
56         WERROR error;
57         int i;
58
59     gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), &firstiter, parent);
60
61     /* See if this row has ever had a name gtk_tree_store_set()'ed to it.
62        If not, read the directory contents */
63     gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &firstiter, 0, &name, -1);
64
65         if(name) return;
66
67         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), parent, 1, &k, -1);
68
69         g_assert(k);
70         
71         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(k, i, &sub)); i++) {
72                 int count;
73                 /* Replace the blank child with the first directory entry
74            You may be tempted to remove the blank child node and then 
75            append a new one.  Don't.  If you remove the blank child 
76            node GTK gets confused and won't expand the parent row. */
77
78                 if(i == 0) {
79                         iter = firstiter;
80                 } else {
81                         gtk_tree_store_append(store_keys, &iter, parent);
82                 }
83                 gtk_tree_store_set (store_keys,
84                                             &iter, 
85                                                 0,
86                                                 reg_key_name(sub),
87                                                 1, 
88                                                 sub,
89                                                 -1);
90                 
91                 if(W_ERROR_IS_OK(reg_key_num_subkeys(sub, &count)) && count > 0) 
92                         gtk_tree_store_append(store_keys, &tmpiter, &iter);
93         }
94
95         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(mainwin, error);
96 }
97
98 static void registry_load_root() 
99 {
100         REG_KEY *root;
101         GtkTreeIter iter, tmpiter;
102         WERROR error = WERR_OK;
103         int i = 0;
104         if(!registry) return;
105
106         gtk_tree_store_clear(store_keys);
107
108         while(1) {
109                 error = reg_get_hive(registry, i, &root);
110                 if(W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
111                         return;
112                 }
113                 if(!W_ERROR_IS_OK(error)) {
114                         gtk_show_werror(mainwin, error);
115                         return;
116                 }
117
118                 /* Add the root */
119                 gtk_tree_store_append(store_keys, &iter, NULL);
120                 gtk_tree_store_set (store_keys,
121                                             &iter, 
122                                                 0,
123                                                 reg_key_name(root),
124                                                 1,
125                                                 root,
126                                                 -1);
127
128                 gtk_tree_store_append(store_keys, &tmpiter, &iter);
129                 i++;
130         }
131
132         gtk_widget_set_sensitive( save, True );
133         gtk_widget_set_sensitive( save_as, True );
134 }
135
136 static void on_open_file_activate (GtkMenuItem *menuitem, gpointer user_data)
137 {
138         gint result = gtk_dialog_run(GTK_DIALOG(create_openfilewin()));
139         char *filename;
140         WERROR error;
141         switch(result) {
142         case GTK_RESPONSE_OK:
143                 filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(openfilewin)));
144                 error = reg_open(user_data, filename, NULL, &registry);
145                 if(!W_ERROR_IS_OK(error)) {
146                         gtk_show_werror(mainwin, error);
147                         break;
148                 }
149                 registry_load_root();
150                 break;
151         default:
152                 break;
153         }
154
155         gtk_widget_destroy(openfilewin);
156 }
157
158 static void on_open_gconf_activate                       (GtkMenuItem     *menuitem,
159                                                       gpointer         user_data)
160 {
161         WERROR error = reg_open("gconf", NULL, NULL, &registry);
162         if(!W_ERROR_IS_OK(error)) {
163                 gtk_show_werror(mainwin, error);
164                 return;
165         }
166
167         registry_load_root();
168 }
169
170 static void on_open_remote_activate(GtkMenuItem *menuitem, gpointer user_data)
171 {
172         char *credentials;
173         const char *location;
174         GtkWidget *rpcwin = GTK_WIDGET(gtk_rpc_binding_dialog_new(TRUE));
175         gint result = gtk_dialog_run(GTK_DIALOG(rpcwin));
176         WERROR error;
177         switch(result) {
178         case GTK_RESPONSE_ACCEPT:
179                 location = gtk_rpc_binding_dialog_get_binding(GTK_RPC_BINDING_DIALOG(rpcwin), NULL);
180                 asprintf(&credentials, "%s%%%s", gtk_rpc_binding_dialog_get_username(GTK_RPC_BINDING_DIALOG(rpcwin)), gtk_rpc_binding_dialog_get_password(GTK_RPC_BINDING_DIALOG(rpcwin)));
181                 error = reg_open("rpc", location, credentials, &registry);
182                 if(!W_ERROR_IS_OK(error)) {
183                         gtk_show_werror(mainwin, error);
184                         break;
185                 }
186                 free(credentials);
187                 registry_load_root();
188                 break;
189         default:
190                 break;
191         }
192
193         gtk_widget_destroy(rpcwin);
194 }
195
196
197 static void on_save_activate                       (GtkMenuItem     *menuitem,
198                                                                                 gpointer         user_data)
199 {
200         WERROR error = reg_save(registry, NULL);
201         if(!W_ERROR_IS_OK(error)) {
202                 gtk_show_werror(mainwin, error);
203         }
204 }
205
206
207 static void on_save_as_activate                    (GtkMenuItem     *menuitem,
208                                                                                 gpointer         user_data)
209 {
210         gint result;
211         WERROR error;
212         create_savefilewin();
213         result = gtk_dialog_run(GTK_DIALOG(savefilewin));
214         switch(result) {
215         case GTK_RESPONSE_OK:
216                 error = reg_save(registry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(savefilewin)));
217                 if(!W_ERROR_IS_OK(error)) {
218                         gtk_show_werror(mainwin, error);
219                 }
220                 break;
221
222         default:
223                 break;
224
225         }
226         gtk_widget_destroy(savefilewin);
227 }
228
229
230 static void on_quit_activate                       (GtkMenuItem     *menuitem,
231                                                                                 gpointer         user_data)
232 {
233         gtk_main_quit();
234 }
235
236
237 static void on_cut_activate                        (GtkMenuItem     *menuitem,
238                                                                                 gpointer         user_data)
239 {
240         /* FIXME */
241 }
242
243
244 static void on_copy_activate                       (GtkMenuItem     *menuitem,
245                                                                                 gpointer         user_data)
246 {
247         /* FIXME */
248 }
249
250
251 static void on_paste_activate                      (GtkMenuItem     *menuitem,
252                                                                                 gpointer         user_data)
253 {
254         /* FIXME */
255 }
256
257
258 static void on_delete_activate                     (GtkMenuItem     *menuitem,
259                                                                                 gpointer         user_data)
260 {
261         /* FIXME */
262 }
263
264
265 static void on_about_activate                      (GtkMenuItem     *menuitem,
266                                                                                 gpointer         user_data)
267 {
268         GtkDialog *aboutwin = GTK_DIALOG(create_gtk_samba_about_dialog());
269         gtk_dialog_run(aboutwin);
270         gtk_widget_destroy(GTK_WIDGET(aboutwin));
271 }
272
273 static void on_key_activate (GtkTreeView *treeview,
274                                           GtkTreePath *path,
275                                           gpointer user_data)
276 {
277         int i;
278         REG_KEY *k;
279         REG_VAL *val;
280         WERROR error;
281         GtkTreeIter parent;
282
283         gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
284         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
285
286         g_assert(k);
287
288         gtk_list_store_clear(store_vals);
289
290         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(k, i, &val)); i++) {
291                 GtkTreeIter iter;
292                 gtk_list_store_append(store_vals, &iter);
293                 gtk_list_store_set (store_vals,
294                                             &iter, 
295                                                 0,
296                                                 reg_val_name(val),
297                                                 1,
298                                                 str_regtype(reg_val_type(val)),
299                                                 2,
300                                                 reg_val_data_string(val),
301                                                 3, 
302                                                 val,
303                                                 -1);
304         }
305
306         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(mainwin, error);
307 }
308
309 static GtkWidget* create_mainwin (void)
310 {
311         GtkWidget *vbox1;
312         GtkWidget *menubar;
313         GtkWidget *menu_file;
314         GtkWidget *menu_file_menu;
315         GtkWidget *open_nt4;
316         GtkWidget *open_w95;
317         GtkWidget *open_gconf;
318         GtkWidget *open_remote;
319         GtkWidget *separatormenuitem1;
320         GtkWidget *quit;
321         GtkWidget *men_edit;
322         GtkWidget *men_edit_menu;
323         GtkWidget *cut;
324         GtkWidget *copy;
325         GtkWidget *paste;
326         GtkWidget *delete;
327         GtkCellRenderer *renderer;
328         GtkTreeViewColumn *curcol;
329         GtkWidget *help;
330         GtkWidget *help_menu;
331         GtkWidget *about;
332         GtkWidget *hbox1;
333         GtkWidget *scrolledwindow1;
334         GtkWidget *scrolledwindow2;
335         GtkWidget *tree_vals;
336         GtkWidget *statusbar;
337         GtkAccelGroup *accel_group;
338         GtkTreeIter iter, child;
339
340         accel_group = gtk_accel_group_new ();
341
342         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
343         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
344         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
345
346         vbox1 = gtk_vbox_new (FALSE, 0);
347         gtk_widget_show (vbox1);
348         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
349
350         menubar = gtk_menu_bar_new ();
351         gtk_widget_show (menubar);
352         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
353
354         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
355         gtk_widget_show (menu_file);
356         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
357
358         menu_file_menu = gtk_menu_new ();
359         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
360
361         if(reg_has_backend("nt4")) {
362                 open_nt4 = gtk_image_menu_item_new_with_mnemonic("Open _NT4 file");
363                 gtk_widget_show (open_nt4);
364                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
365
366                 g_signal_connect ((gpointer) open_nt4, "activate",
367                     G_CALLBACK (on_open_file_activate),
368                     "nt4");
369         }
370
371         if(reg_has_backend("w95")) {
372                 open_w95 = gtk_image_menu_item_new_with_mnemonic("Open Win_9x file");
373                 gtk_widget_show (open_w95);
374                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_w95);
375
376                 g_signal_connect ((gpointer) open_w95, "activate",
377                     G_CALLBACK (on_open_file_activate),
378                     "w95");
379         }
380
381         if(reg_has_backend("gconf")) {
382                 open_gconf = gtk_image_menu_item_new_with_mnemonic ("Open _GConf");
383                 gtk_widget_show (open_gconf);
384                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
385
386                 g_signal_connect ((gpointer) open_gconf, "activate",
387                     G_CALLBACK (on_open_gconf_activate),
388                     NULL);
389         }
390
391         if(reg_has_backend("rpc")) {
392                 open_remote = gtk_menu_item_new_with_mnemonic ("Open _Remote");
393                 gtk_widget_show (open_remote);
394                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
395
396                 g_signal_connect ((gpointer) open_remote, "activate",
397                     G_CALLBACK (on_open_remote_activate),
398                     NULL);
399         }
400
401         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
402         gtk_widget_show (save);
403         gtk_widget_set_sensitive( save, False );
404         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
405
406         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
407         gtk_widget_show (save_as);
408         gtk_widget_set_sensitive( save_as, False );
409         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
410
411         separatormenuitem1 = gtk_menu_item_new ();
412         gtk_widget_show (separatormenuitem1);
413         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
414         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
415
416         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
417         gtk_widget_show (quit);
418         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
419
420         men_edit = gtk_menu_item_new_with_mnemonic ("_Edit");
421         gtk_widget_show (men_edit);
422         gtk_container_add (GTK_CONTAINER (menubar), men_edit);
423
424   men_edit_menu = gtk_menu_new ();
425   gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_edit), men_edit_menu);
426
427   cut = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
428   gtk_widget_show (cut);
429   gtk_widget_set_sensitive(cut, False);
430   gtk_container_add (GTK_CONTAINER (men_edit_menu), cut);
431
432   copy = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
433   gtk_widget_show (copy);
434   gtk_widget_set_sensitive(copy, False);
435   gtk_container_add (GTK_CONTAINER (men_edit_menu), copy);
436
437   paste = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
438   gtk_widget_show (paste);
439   gtk_widget_set_sensitive(paste, False);
440   gtk_container_add (GTK_CONTAINER (men_edit_menu), paste);
441
442   delete = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
443   gtk_widget_show (delete);
444   gtk_widget_set_sensitive(delete, False);
445   gtk_container_add (GTK_CONTAINER (men_edit_menu), delete);
446
447   help = gtk_menu_item_new_with_mnemonic ("_Help");
448   gtk_widget_show (help);
449   gtk_container_add (GTK_CONTAINER (menubar), help);
450
451   help_menu = gtk_menu_new ();
452   gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
453
454   about = gtk_menu_item_new_with_mnemonic ("_About");
455   gtk_widget_show (about);
456   gtk_container_add (GTK_CONTAINER (help_menu), about);
457
458   hbox1 = gtk_hbox_new (FALSE, 0);
459   gtk_widget_show (hbox1);
460   gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
461
462   scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
463   gtk_widget_show (scrolledwindow1);
464   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
465
466   tree_keys = gtk_tree_view_new ();
467
468   /* Column names */
469   curcol = gtk_tree_view_column_new ();
470   gtk_tree_view_column_set_title(curcol, "Name");
471   renderer = gtk_cell_renderer_text_new();
472   gtk_tree_view_column_pack_start(curcol, renderer, True);
473
474   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
475
476   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
477   gtk_widget_show (tree_keys);
478   gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
479   store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
480   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
481   g_object_unref(store_keys);
482
483   g_signal_connect ((gpointer) tree_keys, "row-activated",
484                     G_CALLBACK (on_key_activate),
485                     NULL);
486
487   g_signal_connect ((gpointer) tree_keys, "row-expanded",
488                     G_CALLBACK (expand_key),
489                     NULL);
490
491   scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
492   gtk_widget_show (scrolledwindow2);
493   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
494
495   tree_vals = gtk_tree_view_new ();
496     /* Column names */
497
498   curcol = gtk_tree_view_column_new ();
499   gtk_tree_view_column_set_title(curcol, "Name");
500   renderer = gtk_cell_renderer_text_new();
501   gtk_tree_view_column_pack_start(curcol, renderer, True);
502   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
503   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
504
505   curcol = gtk_tree_view_column_new ();
506   gtk_tree_view_column_set_title(curcol, "Type");
507   renderer = gtk_cell_renderer_text_new();
508   gtk_tree_view_column_pack_start(curcol, renderer, True);
509   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
510   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
511
512   curcol = gtk_tree_view_column_new ();
513   gtk_tree_view_column_set_title(curcol, "Value");
514   renderer = gtk_cell_renderer_text_new();
515   gtk_tree_view_column_pack_start(curcol, renderer, True);
516   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
517   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
518
519   
520   gtk_widget_show (tree_vals);
521   gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
522
523   store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
524   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
525   g_object_unref(store_vals);
526
527   statusbar = gtk_statusbar_new ();
528   gtk_widget_show (statusbar);
529   gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
530   gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
531
532   g_signal_connect ((gpointer) save, "activate",
533                     G_CALLBACK (on_save_activate),
534                     NULL);
535   g_signal_connect ((gpointer) save_as, "activate",
536                     G_CALLBACK (on_save_as_activate),
537                     NULL);
538   g_signal_connect ((gpointer) quit, "activate",
539                     G_CALLBACK (on_quit_activate),
540                     NULL);
541   g_signal_connect ((gpointer) cut, "activate",
542                     G_CALLBACK (on_cut_activate),
543                     NULL);
544   g_signal_connect ((gpointer) copy, "activate",
545                     G_CALLBACK (on_copy_activate),
546                     NULL);
547   g_signal_connect ((gpointer) paste, "activate",
548                     G_CALLBACK (on_paste_activate),
549                     NULL);
550   g_signal_connect ((gpointer) delete, "activate",
551                     G_CALLBACK (on_delete_activate),
552                     NULL);
553   g_signal_connect ((gpointer) about, "activate",
554                     G_CALLBACK (on_about_activate),
555                     NULL);
556
557   gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
558
559   return mainwin;
560 }
561
562 static GtkWidget* create_openfilewin (void)
563 {
564   GtkWidget *ok_button;
565   GtkWidget *cancel_button;
566
567   openfilewin = gtk_file_selection_new ("Select File");
568   gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
569
570   ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
571   gtk_widget_show (ok_button);
572   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
573
574   cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
575   gtk_widget_show (cancel_button);
576   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
577
578   return openfilewin;
579 }
580
581 static GtkWidget* create_savefilewin (void)
582 {
583   GtkWidget *ok_button;
584   GtkWidget *cancel_button;
585
586   savefilewin = gtk_file_selection_new ("Select File");
587   gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
588
589   ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
590   gtk_widget_show (ok_button);
591   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
592
593   cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
594   gtk_widget_show (cancel_button);
595   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
596
597   return savefilewin;
598 }
599
600  int main(int argc, char *argv[])
601 {
602   poptContext pc;
603   const char *backend = NULL;
604   const char *credentials = NULL;
605   const char *location;
606   int opt;
607   struct poptOption long_options[] = {
608        POPT_AUTOHELP
609        {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
610            {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials (user%%password)", NULL},
611        POPT_TABLEEND
612     };
613                                                                               
614     gtk_init (&argc, &argv);
615
616     pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
617                                                                               
618     while((opt = poptGetNextOpt(pc)) != -1) {
619     }
620
621         location = poptGetArg(pc);
622
623         if(location) {
624                 WERROR error;
625
626                 if(!backend) {
627                         if(credentials)backend = "rpc";
628                         else backend = "nt4";
629                 }
630                 
631                 error = reg_open(backend, location, credentials, &registry);
632                 if(!W_ERROR_IS_OK(error)) {
633                         gtk_show_werror(mainwin, error);
634                         return -1;
635                 }
636                 mainwin = create_mainwin ();
637                 registry_load_root();
638         } else 
639                 mainwin = create_mainwin ();
640
641         gtk_widget_show (mainwin);
642
643         gtk_main ();
644
645         if(registry)reg_free(registry);
646         return 0;
647 }