s4-dns: dlz_bind9: Fix ipv6 updates
[samba.git] / source3 / utils / net_rpc_conf.c
1 /*
2  *  Samba Unix/Linux SMB client library
3  *  Distributed SMB/CIFS Server Management Utility
4  *  Local configuration interface
5  *  Copyright (C) Vicentiu Ciorbaru 2011
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 /*
22  * This is an interface to Samba's configuration.
23  *
24  * This tool supports local as well as remote interaction via rpc
25  * with the configuration stored in the registry.
26  */
27
28
29 #include "includes.h"
30 #include "utils/net.h"
31 #include "utils/net_conf_util.h"
32 #include "rpc_client/cli_pipe.h"
33 #include "../librpc/gen_ndr/ndr_samr_c.h"
34 #include "rpc_client/init_samr.h"
35 #include "../librpc/gen_ndr/ndr_winreg_c.h"
36 #include "../libcli/registry/util_reg.h"
37 #include "rpc_client/cli_winreg.h"
38 #include "lib/smbconf/smbconf.h"
39 #include "lib/smbconf/smbconf_init.h"
40 #include "lib/smbconf/smbconf_reg.h"
41 #include "lib/param/loadparm.h"
42
43
44
45 /* internal functions */
46 /**********************************************************
47  *
48  * usage functions
49  *
50  **********************************************************/
51 const char confpath[100] = "Software\\Samba\\smbconf";
52
53 static int rpc_conf_list_usage(struct net_context *c, int argc,
54                                const char **argv)
55 {
56         d_printf("%s net rpc conf list\n", _("Usage:"));
57         return -1;
58 }
59
60 static int rpc_conf_listshares_usage(struct net_context *c, int argc,
61                                      const char **argv)
62 {
63         d_printf("%s net rpc conf listshares\n", _("Usage:"));
64         return -1;
65 }
66
67 static int rpc_conf_delshare_usage(struct net_context *c, int argc,
68                                    const char **argv)
69 {
70         d_printf("%s\n%s",
71                  _("Usage:"),
72                  _("net rpc conf delshare <sharename>\n"));
73         return -1;
74 }
75
76 static int rpc_conf_addshare_usage(struct net_context *c, int argc,
77                                    const char **argv)
78 {
79         d_printf("%s\n%s",
80                  _("Usage:"),
81                  _(" net rpc conf addshare <sharename> <path> "
82                    "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
83                    "\t<sharename>      the new share name.\n"
84                    "\t<path>           the path on the filesystem to export.\n"
85                    "\twriteable={y|N}  set \"writeable to \"yes\" or "
86                    "\"no\" (default) on this share.\n"
87                    "\tguest_ok={y|N}   set \"guest ok\" to \"yes\" or "
88                    "\"no\" (default)   on this share.\n"
89                    "\t<comment>        optional comment for the new share.\n"));
90         return -1;
91
92 }
93
94 static int rpc_conf_import_usage(struct net_context *c, int argc,
95                                  const char**argv)
96 {
97         d_printf("%s\n%s",
98                  _("Usage:"),
99                  _(" net rpc conf import [--test|-T] <filename> "
100                    "[<servicename>]\n"
101                    "\t[--test|-T]    testmode - do not act, just print "
102                         "what would be done\n"
103                    "\t<servicename>  only import service <servicename>, "
104                         "ignore the rest\n"));
105         return -1;
106 }
107
108 static int rpc_conf_showshare_usage(struct net_context *c, int argc,
109                                     const char **argv)
110 {
111         d_printf("%s\n%s",
112                  _("Usage:"),
113                  _("net rpc conf showshare <sharename>\n"));
114         return -1;
115 }
116
117 static int rpc_conf_drop_usage(struct net_context *c, int argc,
118                                const char **argv)
119 {
120         d_printf("%s\nnet rpc conf drop\n", _("Usage:"));
121         return -1;
122 }
123
124 static int rpc_conf_getparm_usage(struct net_context *c, int argc,
125                                const char **argv)
126 {
127         d_printf("%s\nnet rpc conf getparm <sharename> <parameter>\n",
128                         _("Usage:"));
129         return -1;
130 }
131
132 static int rpc_conf_setparm_usage(struct net_context *c, int argc,
133                                   const char **argv)
134 {
135         d_printf("%s\n%s",
136                  _("Usage:"),
137                  _(" net rpc conf setparm <section> <param> <value>\n"));
138         return -1;
139 }
140
141 static int rpc_conf_delparm_usage(struct net_context *c, int argc,
142                                 const char **argv)
143 {
144         d_printf("%s\nnet rpc conf delparm <sharename> <parameter>\n",
145                         _("Usage:"));
146         return -1;
147 }
148
149 static int rpc_conf_getincludes_usage(struct net_context *c, int argc,
150                                 const char **argv)
151 {
152         d_printf("%s\nnet rpc conf getincludes <sharename>\n",
153                         _("Usage:"));
154         return -1;
155 }
156
157 static int rpc_conf_setincludes_usage(struct net_context *c, int argc,
158                                 const char **argv)
159 {
160         d_printf("%s\nnet rpc conf setincludes <sharename> [<filename>]*\n",
161                         _("Usage:"));
162         return -1;
163 }
164
165 static int rpc_conf_delincludes_usage(struct net_context *c, int argc,
166                                 const char **argv)
167 {
168         d_printf("%s\nnet rpc conf delincludes <sharename>\n",
169                         _("Usage:"));
170         return -1;
171 }
172
173 /**********************************************************
174  *
175  * helper functions
176  *
177  **********************************************************/
178
179 /*
180  * The function deletes a registry value with the name 'value' from the share
181  * with the name 'share_name'. 'parent_hnd' is the handle for the smbconf key.
182  */
183 static NTSTATUS rpc_conf_del_value(TALLOC_CTX *mem_ctx,
184                                    struct dcerpc_binding_handle *b,
185                                    struct policy_handle *parent_hnd,
186                                    const char *share_name,
187                                    const char *value,
188                                    WERROR *werr)
189 {
190
191         TALLOC_CTX *frame = talloc_stackframe();
192         NTSTATUS status = NT_STATUS_OK;
193         WERROR result = WERR_OK;
194         WERROR _werr;
195
196         struct winreg_String keyname, valuename;
197         struct policy_handle child_hnd;
198
199         ZERO_STRUCT(child_hnd);
200         ZERO_STRUCT(keyname);
201         ZERO_STRUCT(valuename);
202
203         keyname.name = share_name;
204         valuename.name = value;
205
206         status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, keyname, 0,
207                                        REG_KEY_WRITE, &child_hnd, &result);
208
209         if (!(NT_STATUS_IS_OK(status))) {
210                 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
211                                 keyname.name, nt_errstr(status));
212                 goto error;
213         }
214
215         if (!(W_ERROR_IS_OK(result))) {
216                 d_fprintf(stderr, _("Failed to open key '%s': %s\n"),
217                                 keyname.name, win_errstr(result));
218                 goto error;
219         }
220
221         status = dcerpc_winreg_DeleteValue(b,
222                                            frame,
223                                            &child_hnd,
224                                            valuename,
225                                            &result);
226
227         if (!(NT_STATUS_IS_OK(status))) {
228                 d_fprintf(stderr, _("Failed to delete value %s\n"),
229                                 nt_errstr(status));
230                 goto error;
231         }
232
233         if (!(W_ERROR_IS_OK(result))) {
234                 if (W_ERROR_EQUAL(result, WERR_BADFILE)){
235                         result = WERR_OK;
236                         goto error;
237                 }
238
239                 d_fprintf(stderr, _("Failed to delete value  %s\n"),
240                                 win_errstr(result));
241                 goto error;
242         }
243
244 error:
245         *werr = result;
246
247         dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
248
249         TALLOC_FREE(frame);
250         return status;;
251
252 }
253
254 /*
255  * The function sets a share in the registry with the parameters
256  * held in the smbconf_service struct
257  */
258 static NTSTATUS rpc_conf_set_share(TALLOC_CTX *mem_ctx,
259                                    struct dcerpc_binding_handle *b,
260                                    struct policy_handle *parent_hnd,
261                                    struct smbconf_service *service,
262                                    WERROR *werr)
263 {
264         TALLOC_CTX *frame = talloc_stackframe();
265
266         NTSTATUS status = NT_STATUS_OK;
267         WERROR result = WERR_OK;
268         WERROR _werr;
269         enum winreg_CreateAction action;
270         uint32_t i, j;
271
272         const char **includes;
273
274         struct winreg_String wkey, wkeyclass;
275         struct policy_handle share_hnd;
276
277         ZERO_STRUCT(share_hnd);
278         ZERO_STRUCT(wkey);
279         ZERO_STRUCT(wkeyclass);
280
281         wkey.name = service->name;
282         wkeyclass.name = "";
283         action = REG_ACTION_NONE;
284
285         status = dcerpc_winreg_CreateKey(b,
286                                          frame,
287                                          parent_hnd,
288                                          wkey,
289                                          wkeyclass,
290                                          0,
291                                          REG_KEY_ALL,
292                                          NULL,
293                                          &share_hnd,
294                                          &action,
295                                          &result);
296
297         if (!NT_STATUS_IS_OK(status)) {
298                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
299                 goto error;
300         }
301
302         if (!W_ERROR_IS_OK(result)) {
303                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
304                 goto error;
305         }
306
307         for (i = 0; i < service->num_params; i++) {
308                 if (strequal(service->param_names[i], "include") == 0)
309                 {
310
311                         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
312                                                       service->param_names[i],
313                                                       service->param_values[i],
314                                                       &result);
315
316                         if (!(NT_STATUS_IS_OK(status))) {
317                                 d_fprintf(stderr,
318                                           "ERROR: Share: '%s'\n"
319                                           "Could not set parameter '%s'"
320                                           " with value %s\n %s\n",
321                                           service->name,
322                                           service->param_names[i],
323                                           service->param_values[i],
324                                           nt_errstr(status));
325                                 goto error;
326                         }
327
328                         if (!(W_ERROR_IS_OK(result))) {
329                                 d_fprintf(stderr,
330                                           "ERROR: Share: '%s'\n"
331                                           "Could not set parameter '%s'"
332                                           " with value %s\n %s\n",
333                                           service->name,
334                                           service->param_names[i],
335                                           service->param_values[i],
336                                           win_errstr(result));
337                                 goto error;
338                         }
339                 } else {
340
341                         includes = talloc_zero_array(frame,
342                                                      const char *,
343                                                      service->num_params + 1);
344                         if (includes == NULL) {
345                                 result = WERR_NOMEM;
346                                 d_fprintf(stderr, "ERROR: out of memory\n");
347                                 goto error;
348                         }
349
350                         for (j = i; j < service->num_params; j++) {
351
352                                 includes[j - i] = talloc_strdup(
353                                                         frame,
354                                                         service->param_values[j]);
355
356                                 if (includes[j-i] == NULL) {
357                                         result = WERR_NOMEM;
358                                         d_fprintf(stderr, "ERROR: out of memory\n");
359                                         goto error;
360                                 }
361                         }
362
363                         status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
364                                                 "includes",
365                                                 includes,
366                                                 &result);
367
368                         if (!(NT_STATUS_IS_OK(status))) {
369                                 d_fprintf(stderr, "ERROR: Share: '%s'\n"
370                                                 "Could not set includes\n %s\n",
371                                                 service->name,
372                                                 nt_errstr(status));
373                                 goto error;
374                         }
375
376                         if (!(W_ERROR_IS_OK(result))) {
377                                 d_fprintf(stderr, "ERROR: Share: '%s'\n"
378                                                 "Could not set includes\n %s\n",
379                                                 service->name,
380                                                 win_errstr(result));
381                                 goto error;
382                         }
383
384                         i = service->num_params;
385                 }
386         }
387
388 error:
389         /* in case of error, should it delete the created key? */
390         if (!(W_ERROR_IS_OK(result))) {
391                 status =  werror_to_ntstatus(result);
392
393         }
394
395         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
396
397         TALLOC_FREE(frame);
398         return status;
399
400 }
401
402 /*
403  * The function opens the registry database and retrieves
404  * as a smbconf_service struct the share with the name
405  * 'share_name'
406  */
407 static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx,
408                                    struct dcerpc_binding_handle *b,
409                                    struct policy_handle *parent_hnd,
410                                    const char *share_name,
411                                    struct smbconf_service *share,
412                                    WERROR *werr)
413 {
414         TALLOC_CTX *frame = talloc_stackframe();
415
416         NTSTATUS status = NT_STATUS_OK;
417         WERROR result = WERR_OK;
418         WERROR _werr;
419         struct policy_handle child_hnd;
420         int32_t includes_cnt, includes_idx = -1;
421         uint32_t num_vals, i, param_cnt = 0;
422         const char **val_names;
423         enum winreg_Type *types;
424         DATA_BLOB *data;
425         struct winreg_String key = { 0, };
426         const char **multi_s = NULL;
427         const char *s = NULL;
428         struct smbconf_service tmp_share;
429
430         ZERO_STRUCT(tmp_share);
431
432         key.name = share_name;
433         status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0,
434                                REG_KEY_READ, &child_hnd, &result);
435
436         if (!(NT_STATUS_IS_OK(status))) {
437                 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
438                                 nt_errstr(status));
439                 goto error;
440         }
441         if (!(W_ERROR_IS_OK(result))) {
442                 d_fprintf(stderr, _("Failed to open subkey: %s\n"),
443                                 win_errstr(result));
444                 goto error;
445         }
446         /* get all the info from the share key */
447         status = dcerpc_winreg_enumvals(frame,
448                         b,
449                         &child_hnd,
450                         &num_vals,
451                         &val_names,
452                         &types,
453                         &data,
454                         &result);
455
456         if (!(NT_STATUS_IS_OK(status))) {
457                 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
458                                 nt_errstr(status));
459                 goto error;
460         }
461         if (!(W_ERROR_IS_OK(result))) {
462                 d_fprintf(stderr, _("Failed to enumerate values: %s\n"),
463                                 win_errstr(result));
464                 goto error;
465         }
466         /* check for includes */
467         for (i = 0; i < num_vals; i++) {
468                 if (strcmp(val_names[i], "includes") == 0){
469                         if (!pull_reg_multi_sz(frame,
470                                                &data[i],
471                                                &multi_s))
472                         {
473                                 result = WERR_NOMEM;
474                                 d_fprintf(stderr,
475                                           _("Failed to enumerate values: %s\n"),
476                                           win_errstr(result));
477                                 goto error;
478                         }
479                         includes_idx = i;
480                 }
481         }
482         /* count the number of includes */
483         includes_cnt = 0;
484         if (includes_idx != -1) {
485                 for (includes_cnt = 0;
486                      multi_s[includes_cnt] != NULL;
487                      includes_cnt ++);
488         }
489         /* place the name of the share in the smbconf_service struct */
490         tmp_share.name = talloc_strdup(frame, share_name);
491         if (tmp_share.name == NULL) {
492                 result = WERR_NOMEM;
493                 d_fprintf(stderr, _("Failed to create share: %s\n"),
494                                 win_errstr(result));
495                 goto error;
496         }
497         /* place the number of parameters in the smbconf_service struct */
498         tmp_share.num_params = num_vals;
499         if (includes_idx != -1) {
500                 tmp_share.num_params = num_vals + includes_cnt - 1;
501         }
502         /* allocate memory for the param_names and param_values lists */
503         tmp_share.param_names = talloc_zero_array(frame, char *, tmp_share.num_params);
504         if (tmp_share.param_names == NULL) {
505                 result = WERR_NOMEM;
506                 d_fprintf(stderr, _("Failed to create share: %s\n"),
507                                 win_errstr(result));
508                 goto error;
509         }
510         tmp_share.param_values = talloc_zero_array(frame, char *, tmp_share.num_params);
511         if (tmp_share.param_values == NULL) {
512                 result = WERR_NOMEM;
513                 d_fprintf(stderr, _("Failed to create share: %s\n"),
514                                 win_errstr(result));
515                 goto error;
516         }
517         /* place all params except includes */
518         for (i = 0; i < num_vals; i++) {
519                 if (strcmp(val_names[i], "includes") != 0) {
520                         if (!pull_reg_sz(frame, &data[i], &s)) {
521                                 result = WERR_NOMEM;
522                                 d_fprintf(stderr,
523                                           _("Failed to enumerate values: %s\n"),
524                                           win_errstr(result));
525                                 goto error;
526                         }
527                         /* place param_names */
528                         tmp_share.param_names[param_cnt] = talloc_strdup(frame, val_names[i]);
529                         if (tmp_share.param_names[param_cnt] == NULL) {
530                                 result = WERR_NOMEM;
531                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
532                                                 win_errstr(result));
533                                 goto error;
534                         }
535
536                         /* place param_values */
537                         tmp_share.param_values[param_cnt++] = talloc_strdup(frame, s);
538                         if (tmp_share.param_values[param_cnt - 1] == NULL) {
539                                 result = WERR_NOMEM;
540                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
541                                                 win_errstr(result));
542                                 goto error;
543                         }
544                 }
545         }
546         /* place the includes last */
547         for (i = 0; i < includes_cnt; i++) {
548                 tmp_share.param_names[param_cnt] = talloc_strdup(frame, "include");
549                 if (tmp_share.param_names[param_cnt] == NULL) {
550                                 result = WERR_NOMEM;
551                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
552                                                 win_errstr(result));
553                                 goto error;
554                 }
555
556                 tmp_share.param_values[param_cnt++] = talloc_strdup(frame, multi_s[i]);
557                 if (tmp_share.param_values[param_cnt - 1] == NULL) {
558                                 result = WERR_NOMEM;
559                                 d_fprintf(stderr, _("Failed to create share: %s\n"),
560                                                 win_errstr(result));
561                                 goto error;
562                 }
563         }
564
565         /* move everything to the main memory ctx */
566         for (i = 0; i < param_cnt; i++) {
567                 tmp_share.param_names[i] = talloc_move(mem_ctx, &tmp_share.param_names[i]);
568                 tmp_share.param_values[i] = talloc_move(mem_ctx, &tmp_share.param_values[i]);
569         }
570
571         tmp_share.name = talloc_move(mem_ctx, &tmp_share.name);
572         tmp_share.param_names = talloc_move(mem_ctx, &tmp_share.param_names);
573         tmp_share.param_values = talloc_move(mem_ctx, &tmp_share.param_values);
574         /* out parameter */
575         *share = tmp_share;
576 error:
577         /* close child */
578         dcerpc_winreg_CloseKey(b, frame, &child_hnd, &_werr);
579         *werr = result;
580         TALLOC_FREE(frame);
581         return status;
582 }
583
584 /*
585  * The function prints the shares held as smbconf_service structs
586  * in a smbconf file format.
587  */
588 static int rpc_conf_print_shares(uint32_t num_shares,
589                                  struct smbconf_service *shares)
590 {
591
592         uint32_t share_count, param_count;
593         const char *indent = "\t";
594
595         if (num_shares == 0) {
596                 return 0;
597         }
598
599         for (share_count = 0; share_count < num_shares; share_count++) {
600                 d_printf("\n");
601                 if (shares[share_count].name != NULL) {
602                 d_printf("[%s]\n", shares[share_count].name);
603                 }
604
605                 for (param_count = 0;
606                      param_count < shares[share_count].num_params;
607                      param_count++)
608                 {
609                         d_printf("%s%s = %s\n",
610                                  indent,
611                                  shares[share_count].param_names[param_count],
612                                  shares[share_count].param_values[param_count]);
613                 }
614         }
615         d_printf("\n");
616
617         return 0;
618
619 }
620
621 /*
622  * The function openes the registry key
623  * HKLM/Software/Samba/smbconf with the give access_mask
624  */
625 static NTSTATUS rpc_conf_open_conf(TALLOC_CTX *mem_ctx,
626                                    struct dcerpc_binding_handle *b,
627                                    uint32_t access_mask,
628                                    struct policy_handle *hive_hnd,
629                                    struct policy_handle *key_hnd,
630                                    WERROR *werr)
631 {
632         TALLOC_CTX *frame = talloc_stackframe();
633         NTSTATUS status = NT_STATUS_OK;
634         WERROR result = WERR_OK;
635         WERROR _werr;
636         struct policy_handle tmp_hive_hnd, tmp_key_hnd;
637         struct winreg_String key;
638
639         ZERO_STRUCT(key);
640
641         status = dcerpc_winreg_OpenHKLM(b, frame, NULL,
642                         access_mask, &tmp_hive_hnd, &result);
643
644         /*
645          * print no error messages if it is a read only open
646          * and key does not exist
647          * error still gets returned
648          */
649
650         if (access_mask == REG_KEY_READ &&
651             W_ERROR_EQUAL(result, WERR_BADFILE))
652         {
653                 goto error;
654         }
655
656         if (!(NT_STATUS_IS_OK(status))) {
657                 d_fprintf(stderr, _("Failed to open hive: %s\n"),
658                                 nt_errstr(status));
659                 goto error;
660         }
661         if (!W_ERROR_IS_OK(result)) {
662                 d_fprintf(stderr, _("Failed to open hive: %s\n"),
663                                 win_errstr(result));
664                 goto error;
665         }
666
667         key.name = confpath;
668         status = dcerpc_winreg_OpenKey(b, frame, &tmp_hive_hnd, key, 0,
669                                        access_mask, &tmp_key_hnd, &result);
670
671         /*
672          * print no error messages if it is a read only open
673          * and key does not exist
674          * error still gets returned
675          */
676
677         if (access_mask == REG_KEY_READ &&
678             W_ERROR_EQUAL(result, WERR_BADFILE))
679         {
680                 goto error;
681         }
682
683         if (!(NT_STATUS_IS_OK(status))) {
684                 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
685                                 nt_errstr(status));
686                 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
687                 goto error;
688         }
689         if (!(W_ERROR_IS_OK(result))) {
690                 d_fprintf(stderr, _("Failed to open smbconf key: %s\n"),
691                         win_errstr(result));
692                 dcerpc_winreg_CloseKey(b, frame, &tmp_hive_hnd, &_werr);
693                 goto error;
694         }
695
696         *hive_hnd = tmp_hive_hnd;
697         *key_hnd = tmp_key_hnd;
698
699 error:
700         TALLOC_FREE(frame);
701         *werr = result;
702
703         return status;
704 }
705
706 /**********************************************************
707  *
708  * internal functions that provide the functionality
709  * net rpc conf
710  *
711  **********************************************************/
712
713 static NTSTATUS rpc_conf_listshares_internal(struct net_context *c,
714                                              const struct dom_sid *domain_sid,
715                                              const char *domain_name,
716                                              struct cli_state *cli,
717                                              struct rpc_pipe_client *pipe_hnd,
718                                              TALLOC_CTX *mem_ctx,
719                                              int argc,
720                                              const char **argv )
721 {
722
723         TALLOC_CTX *frame = talloc_stackframe();
724         NTSTATUS status = NT_STATUS_OK;
725         WERROR werr = WERR_OK;
726         WERROR _werr;
727
728         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
729
730         /* key info */
731         struct policy_handle hive_hnd, key_hnd;
732         uint32_t num_subkeys;
733         uint32_t i;
734         const char **subkeys = NULL;
735
736
737         ZERO_STRUCT(hive_hnd);
738         ZERO_STRUCT(key_hnd);
739
740
741         if (argc != 0 || c->display_usage) {
742                 rpc_conf_listshares_usage(c, argc, argv);
743                 status = NT_STATUS_INVALID_PARAMETER;
744                 goto error;
745         }
746
747
748         status = rpc_conf_open_conf(frame,
749                                     b,
750                                     REG_KEY_READ,
751                                     &hive_hnd,
752                                     &key_hnd,
753                                     &werr);
754
755         if (!(NT_STATUS_IS_OK(status))) {
756                 goto error;
757         }
758
759         if (!(W_ERROR_IS_OK(werr))) {
760                 goto error;
761         }
762
763         status = dcerpc_winreg_enum_keys(frame,
764                                          b,
765                                          &key_hnd,
766                                          &num_subkeys,
767                                          &subkeys,
768                                          &werr);
769
770         if (!(NT_STATUS_IS_OK(status))) {
771                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
772                                 nt_errstr(status));
773                 goto error;
774         }
775
776         if (!(W_ERROR_IS_OK(werr))) {
777                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
778                                 win_errstr(werr));
779                 goto error;
780         }
781
782         for (i = 0; i < num_subkeys; i++) {
783                 d_printf("%s\n", subkeys[i]);
784         }
785
786 error:
787         if (!(W_ERROR_IS_OK(werr))) {
788                 status =  werror_to_ntstatus(werr);
789         }
790
791         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
792         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
793
794         TALLOC_FREE(frame);
795         return status;;
796 }
797
798 static NTSTATUS rpc_conf_delshare_internal(struct net_context *c,
799                                            const struct dom_sid *domain_sid,
800                                            const char *domain_name,
801                                            struct cli_state *cli,
802                                            struct rpc_pipe_client *pipe_hnd,
803                                            TALLOC_CTX *mem_ctx,
804                                            int argc,
805                                            const char **argv )
806 {
807
808         TALLOC_CTX *frame = talloc_stackframe();
809         NTSTATUS status = NT_STATUS_OK;
810         WERROR werr = WERR_OK;
811         WERROR _werr;
812
813         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
814
815         /* key info */
816         struct policy_handle hive_hnd, key_hnd;
817
818         ZERO_STRUCT(hive_hnd);
819         ZERO_STRUCT(key_hnd);
820
821
822         if (argc != 1 || c->display_usage) {
823                 rpc_conf_delshare_usage(c, argc, argv);
824                 status = NT_STATUS_INVALID_PARAMETER;
825                 goto error;
826         }
827
828         status = rpc_conf_open_conf(frame,
829                                     b,
830                                     REG_KEY_ALL,
831                                     &hive_hnd,
832                                     &key_hnd,
833                                     &werr);
834
835         if (!(NT_STATUS_IS_OK(status))) {
836                 goto error;
837         }
838
839         if (!(W_ERROR_IS_OK(werr))) {
840                 goto error;
841         }
842
843         status = dcerpc_winreg_delete_subkeys_recursive(frame,
844                                                         b,
845                                                         &key_hnd,
846                                                         REG_KEY_ALL,
847                                                         argv[0],
848                                                         &werr);
849
850         if (!NT_STATUS_IS_OK(status)) {
851                 d_fprintf(stderr,
852                           "winreg_delete_subkeys: Could not delete key %s: %s\n",
853                           argv[0], nt_errstr(status));
854                 goto error;
855         }
856
857         if (W_ERROR_EQUAL(werr, WERR_BADFILE)){
858                 d_fprintf(stderr, _("ERROR: Key does not exist\n"));
859         }
860
861
862         if (!W_ERROR_IS_OK(werr)) {
863                 d_fprintf(stderr,
864                           "winreg_delete_subkeys: Could not delete key %s: %s\n",
865                           argv[0], win_errstr(werr));
866                 goto error;
867         }
868
869 error:
870         if (!(W_ERROR_IS_OK(werr))) {
871                 status =  werror_to_ntstatus(werr);
872         }
873
874         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
875         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
876
877         TALLOC_FREE(frame);
878
879         return status;
880 }
881
882 static NTSTATUS rpc_conf_list_internal(struct net_context *c,
883                                        const struct dom_sid *domain_sid,
884                                        const char *domain_name,
885                                        struct cli_state *cli,
886                                        struct rpc_pipe_client *pipe_hnd,
887                                        TALLOC_CTX *mem_ctx,
888                                        int argc,
889                                        const char **argv )
890 {
891
892         TALLOC_CTX *frame = talloc_stackframe();
893         NTSTATUS status = NT_STATUS_OK;
894         WERROR werr = WERR_OK;
895         WERROR _werr;
896
897         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
898
899         /* key info */
900         struct policy_handle hive_hnd, key_hnd;
901         uint32_t num_subkeys;
902         uint32_t i;
903         struct smbconf_service *shares;
904         const char **subkeys = NULL;
905
906
907         ZERO_STRUCT(hive_hnd);
908         ZERO_STRUCT(key_hnd);
909
910
911         if (argc != 0 || c->display_usage) {
912                 rpc_conf_list_usage(c, argc, argv);
913                 status = NT_STATUS_INVALID_PARAMETER;
914                 goto error;
915         }
916
917         status = rpc_conf_open_conf(frame,
918                                     b,
919                                     REG_KEY_READ,
920                                     &hive_hnd,
921                                     &key_hnd,
922                                     &werr);
923
924         if (!(NT_STATUS_IS_OK(status))) {
925                 goto error;
926         }
927
928         if (!(W_ERROR_IS_OK(werr))) {
929                 goto error;
930         }
931
932         status = dcerpc_winreg_enum_keys(frame,
933                                          b,
934                                          &key_hnd,
935                                          &num_subkeys,
936                                          &subkeys,
937                                          &werr);
938
939         if (!(NT_STATUS_IS_OK(status))) {
940                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
941                                 nt_errstr(status));
942                 goto error;
943         }
944
945         if (!(W_ERROR_IS_OK(werr))) {
946                 d_fprintf(stderr, _("Failed to enumerate keys: %s\n"),
947                                 win_errstr(werr));
948                 goto error;
949         }
950
951         if (num_subkeys == 0) {
952                 dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
953                 dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
954                 TALLOC_FREE(frame);
955                 return NT_STATUS_OK;
956         }
957
958         /* get info from each subkey */
959         shares = talloc_zero_array(frame, struct smbconf_service, num_subkeys);
960         if (shares == NULL) {
961                 werr = WERR_NOMEM;
962                 d_fprintf(stderr, _("Failed to create shares: %s\n"),
963                                 win_errstr(werr));
964                 goto error;
965
966         }
967
968         for (i = 0; i < num_subkeys; i++) {
969                 /* get each share and place it in the shares array */
970                 status = rpc_conf_get_share(frame,
971                                 b,
972                                 &key_hnd,
973                                 subkeys[i],
974                                 &shares[i],
975                                 &werr);
976                 if (!(NT_STATUS_IS_OK(status))) {
977                         goto error;
978                 }
979                 if (!(W_ERROR_IS_OK(werr))) {
980                         goto error;
981                 }
982
983         }
984         /* print the shares array */
985         rpc_conf_print_shares(num_subkeys, shares);
986
987 error:
988         if (!(W_ERROR_IS_OK(werr))) {
989                 status =  werror_to_ntstatus(werr);
990         }
991
992         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
993         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
994
995         TALLOC_FREE(frame);
996         return status;
997
998 }
999
1000 static NTSTATUS rpc_conf_drop_internal(struct net_context *c,
1001                                        const struct dom_sid *domain_sid,
1002                                        const char *domain_name,
1003                                        struct cli_state *cli,
1004                                        struct rpc_pipe_client *pipe_hnd,
1005                                        TALLOC_CTX *mem_ctx,
1006                                        int argc,
1007                                        const char **argv )
1008 {
1009         TALLOC_CTX *frame = talloc_stackframe();
1010         NTSTATUS status = NT_STATUS_OK;
1011         WERROR werr = WERR_OK;
1012         WERROR _werr;
1013
1014         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1015
1016         /* key info */
1017         struct policy_handle hive_hnd, key_hnd;
1018         const char *keyname = confpath;
1019         struct winreg_String wkey, wkeyclass;
1020         enum winreg_CreateAction action = REG_ACTION_NONE;
1021
1022
1023         ZERO_STRUCT(hive_hnd);
1024         ZERO_STRUCT(key_hnd);
1025
1026
1027         if (argc != 0 || c->display_usage) {
1028                 rpc_conf_drop_usage(c, argc, argv);
1029                 status = NT_STATUS_INVALID_PARAMETER;
1030                 goto error;
1031         }
1032
1033         status = rpc_conf_open_conf(frame,
1034                                     b,
1035                                     REG_KEY_ALL,
1036                                     &hive_hnd,
1037                                     &key_hnd,
1038                                     &werr);
1039
1040         if (!(NT_STATUS_IS_OK(status))) {
1041                 goto error;
1042         }
1043
1044         if (!(W_ERROR_IS_OK(werr))) {
1045                 goto error;
1046         }
1047
1048         status = dcerpc_winreg_delete_subkeys_recursive(frame,
1049                                                         b,
1050                                                         &hive_hnd,
1051                                                         REG_KEY_ALL,
1052                                                         keyname,
1053                                                         &werr);
1054
1055         if (!NT_STATUS_IS_OK(status)) {
1056                 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1057                           keyname, nt_errstr(status));
1058                 goto error;
1059         }
1060
1061         if (!W_ERROR_IS_OK(werr)) {
1062                 d_printf("winreg_delete_subkeys: Could not delete key %s: %s\n",
1063                           keyname, win_errstr(werr));
1064                 goto error;
1065         }
1066
1067         ZERO_STRUCT(wkey);
1068         wkey.name = keyname;
1069         ZERO_STRUCT(wkeyclass);
1070         wkeyclass.name = "";
1071         action = REG_ACTION_NONE;
1072
1073         status = dcerpc_winreg_CreateKey(b,
1074                                          frame,
1075                                          &hive_hnd,
1076                                          wkey,
1077                                          wkeyclass,
1078                                          0,
1079                                          REG_KEY_ALL,
1080                                          NULL,
1081                                          &key_hnd,
1082                                          &action,
1083                                          &werr);
1084
1085         if (!NT_STATUS_IS_OK(status)) {
1086                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1087                 goto error;
1088         }
1089
1090         if (!W_ERROR_IS_OK(werr)) {
1091                 d_printf("winreg_CreateKey: Could not create smbconf key\n");
1092                 goto error;
1093         }
1094
1095
1096 error:
1097         if (!(W_ERROR_IS_OK(werr))) {
1098                 status =  werror_to_ntstatus(werr);
1099         }
1100
1101         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1102         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1103
1104         TALLOC_FREE(frame);
1105         return status;
1106 }
1107
1108 static NTSTATUS rpc_conf_import_internal(struct net_context *c,
1109                                          const struct dom_sid *domain_sid,
1110                                          const char *domain_name,
1111                                          struct cli_state *cli,
1112                                          struct rpc_pipe_client *pipe_hnd,
1113                                          TALLOC_CTX *mem_ctx,
1114                                          int argc,
1115                                          const char **argv )
1116 {
1117
1118         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1119
1120         struct policy_handle hive_hnd, key_hnd;
1121
1122         const char *filename = NULL;
1123         const char *servicename = NULL;
1124         char *conf_source = NULL;
1125         TALLOC_CTX *frame;
1126         struct smbconf_ctx *txt_ctx;
1127         struct smbconf_service *service = NULL;
1128         struct smbconf_service **services = NULL;
1129         uint32_t num_shares, i;
1130         sbcErr err = SBC_ERR_UNKNOWN_FAILURE;
1131
1132         WERROR werr = WERR_OK;
1133         NTSTATUS status = NT_STATUS_OK;
1134
1135         ZERO_STRUCT(hive_hnd);
1136         ZERO_STRUCT(key_hnd);
1137
1138         frame = talloc_stackframe();
1139
1140         if (c->display_usage) {
1141                 rpc_conf_import_usage(c, argc, argv);
1142                 status = NT_STATUS_INVALID_PARAMETER;
1143                 goto error;
1144         }
1145
1146         switch (argc) {
1147                 case 0:
1148                 default:
1149                         rpc_conf_import_usage(c, argc, argv);
1150                         status = NT_STATUS_INVALID_PARAMETER;
1151                         goto error;
1152                 case 2:
1153                         servicename = talloc_strdup(frame, argv[1]);
1154                         if (servicename == NULL) {
1155                                 d_printf(_("error: out of memory!\n"));
1156                                 goto error;
1157                         }
1158                 case 1:
1159                         filename = argv[0];
1160                         break;
1161         }
1162
1163         DEBUG(3,("rpc_conf_import: reading configuration from file %s.\n",
1164                 filename));
1165
1166         conf_source = talloc_asprintf(frame, "file:%s", filename);
1167         if (conf_source == NULL) {
1168                 d_fprintf(stderr, _("error: out of memory!\n"));
1169                 goto error;
1170         }
1171
1172         err = smbconf_init(frame, &txt_ctx, conf_source);
1173         if (!SBC_ERROR_IS_OK(err)) {
1174                 d_fprintf(stderr, _("error loading file '%s': %s\n"), filename,
1175                          sbcErrorString(err));
1176                 goto error;
1177         }
1178
1179         if (c->opt_testmode) {
1180                 d_printf(_("\nTEST MODE - "
1181                          "would import the following configuration:\n\n"));
1182         }
1183
1184         if (servicename != NULL) {
1185                 err = smbconf_get_share(txt_ctx, frame,
1186                                         servicename,
1187                                         &service);
1188                 if (!SBC_ERROR_IS_OK(err)) {
1189                         goto error;
1190                 }
1191
1192                 num_shares = 1;
1193
1194         } else {
1195
1196                 err = smbconf_get_config(txt_ctx, frame,
1197                                           &num_shares,
1198                                           &services);
1199                 if (!SBC_ERROR_IS_OK(err)) {
1200                         goto error;
1201                 }
1202         }
1203
1204         if (c->opt_testmode) {
1205                 if (servicename != NULL) {
1206                         rpc_conf_print_shares(1, service);
1207                 }
1208                 for (i = 0; i < num_shares; i++) {
1209                         rpc_conf_print_shares(1, services[i]);
1210                 }
1211                 goto error;
1212         }
1213
1214         status = rpc_conf_drop_internal(c,
1215                                domain_sid,
1216                                domain_name,
1217                                cli,
1218                                pipe_hnd,
1219                                frame,
1220                                0,
1221                                NULL );
1222
1223         if (!(NT_STATUS_IS_OK(status))) {
1224                 goto error;
1225         }
1226
1227         status = rpc_conf_open_conf(frame,
1228                                     b,
1229                                     REG_KEY_READ,
1230                                     &hive_hnd,
1231                                     &key_hnd,
1232                                     &werr);
1233
1234         if (!(NT_STATUS_IS_OK(status))) {
1235                 goto error;
1236         }
1237
1238         if (!(W_ERROR_IS_OK(werr))) {
1239                 goto error;
1240         }
1241
1242         if (servicename != NULL) {
1243                 status = rpc_conf_set_share(frame,
1244                                             b,
1245                                             &key_hnd,
1246                                             service,
1247                                             &werr);
1248
1249                 if (!(NT_STATUS_IS_OK(status))) {
1250                         goto error;
1251                 }
1252
1253                 if (!(W_ERROR_IS_OK(werr))) {
1254                         goto error;
1255                 }
1256
1257         } else {
1258
1259                 for (i = 0; i < num_shares; i++) {
1260                         status = rpc_conf_set_share(frame,
1261                                         b,
1262                                         &key_hnd,
1263                                         services[i],
1264                                         &werr);
1265
1266                         if (!(NT_STATUS_IS_OK(status))) {
1267                                 goto error;
1268                         }
1269
1270                         if (!(W_ERROR_IS_OK(werr))) {
1271                                 goto error;
1272                         }
1273
1274                 }
1275         }
1276
1277 error:
1278         if (!SBC_ERROR_IS_OK(err)) {
1279                 d_fprintf(stderr, "ERROR: %s\n", sbcErrorString(err));
1280         }
1281
1282         if (!(W_ERROR_IS_OK(werr))) {
1283                 status =  werror_to_ntstatus(werr);
1284         }
1285         TALLOC_FREE(frame);
1286         return status;
1287 }
1288
1289 static NTSTATUS rpc_conf_showshare_internal(struct net_context *c,
1290                                             const struct dom_sid *domain_sid,
1291                                             const char *domain_name,
1292                                             struct cli_state *cli,
1293                                             struct rpc_pipe_client *pipe_hnd,
1294                                             TALLOC_CTX *mem_ctx,
1295                                             int argc,
1296                                             const char **argv )
1297 {
1298         TALLOC_CTX *frame = talloc_stackframe();
1299         NTSTATUS status = NT_STATUS_OK;
1300         WERROR werr = WERR_OK;
1301         WERROR _werr;
1302
1303         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1304
1305         /* key info */
1306         struct policy_handle hive_hnd, key_hnd;
1307         struct smbconf_service *service = NULL;
1308         const char *sharename = NULL;
1309
1310
1311         ZERO_STRUCT(hive_hnd);
1312         ZERO_STRUCT(key_hnd);
1313
1314
1315         if (argc != 1 || c->display_usage) {
1316                 rpc_conf_showshare_usage(c, argc, argv);
1317                 status = NT_STATUS_INVALID_PARAMETER;
1318                 goto error;
1319         }
1320
1321         status = rpc_conf_open_conf(frame,
1322                                     b,
1323                                     REG_KEY_READ,
1324                                     &hive_hnd,
1325                                     &key_hnd,
1326                                     &werr);
1327
1328         if (!(NT_STATUS_IS_OK(status))) {
1329                 goto error;
1330         }
1331
1332         if (!(W_ERROR_IS_OK(werr))) {
1333                 goto error;
1334         }
1335
1336         sharename = talloc_strdup(frame, argv[0]);
1337         if (sharename == NULL) {
1338                 werr = WERR_NOMEM;
1339                 d_fprintf(stderr, _("Failed to create share: %s\n"),
1340                                 win_errstr(werr));
1341                 goto error;
1342         }
1343
1344         service = talloc(frame, struct smbconf_service);
1345         if (service == NULL) {
1346                 werr = WERR_NOMEM;
1347                 d_fprintf(stderr, _("Failed to create share: %s\n"),
1348                                 win_errstr(werr));
1349                 goto error;
1350         }
1351
1352         status = rpc_conf_get_share(frame,
1353                         b,
1354                         &key_hnd,
1355                         sharename,
1356                         service,
1357                         &werr);
1358
1359         if (!(NT_STATUS_IS_OK(status))) {
1360                 goto error;
1361         }
1362         if (!(W_ERROR_IS_OK(werr))) {
1363                 goto error;
1364         }
1365
1366         rpc_conf_print_shares(1, service);
1367
1368 error:
1369         if (!(W_ERROR_IS_OK(werr))) {
1370                 status =  werror_to_ntstatus(werr);
1371         }
1372
1373         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1374         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1375
1376         TALLOC_FREE(frame);
1377         return status;
1378 }
1379
1380 static NTSTATUS rpc_conf_addshare_internal(struct net_context *c,
1381                                            const struct dom_sid *domain_sid,
1382                                            const char *domain_name,
1383                                            struct cli_state *cli,
1384                                            struct rpc_pipe_client *pipe_hnd,
1385                                            TALLOC_CTX *mem_ctx,
1386                                            int argc,
1387                                            const char **argv )
1388 {
1389         TALLOC_CTX *frame = talloc_stackframe();
1390         NTSTATUS status = NT_STATUS_OK;
1391         WERROR werr = WERR_OK;
1392         WERROR _werr;
1393
1394         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1395
1396         /* key info */
1397         struct policy_handle hive_hnd, key_hnd, share_hnd;
1398         char *sharename = NULL;
1399         const char *path = NULL;
1400         const char *comment = NULL;
1401         const char *guest_ok = "no";
1402         const char *read_only = "yes";
1403         struct winreg_String key, keyclass;
1404         enum winreg_CreateAction action = 0;
1405
1406
1407         ZERO_STRUCT(hive_hnd);
1408         ZERO_STRUCT(key_hnd);
1409         ZERO_STRUCT(share_hnd);
1410
1411         ZERO_STRUCT(key);
1412         ZERO_STRUCT(keyclass);
1413
1414         if (c->display_usage) {
1415                 rpc_conf_addshare_usage(c, argc, argv);
1416                 status = NT_STATUS_INVALID_PARAMETER;
1417                 goto error;
1418         }
1419
1420         switch (argc) {
1421                 case 0:
1422                 case 1:
1423                 default:
1424                         rpc_conf_addshare_usage(c, argc, argv);
1425                         status = NT_STATUS_INVALID_PARAMETER;
1426                         goto error;
1427                 case 5:
1428                         comment = argv[4];
1429                 case 4:
1430                         if (!strnequal(argv[3], "guest_ok=", 9)) {
1431                                 rpc_conf_addshare_usage(c, argc, argv);
1432                                 status = NT_STATUS_INVALID_PARAMETER;
1433                                 goto error;
1434                         }
1435                         switch (argv[3][9]) {
1436                                 case 'y':
1437                                 case 'Y':
1438                                         guest_ok = "yes";
1439                                         break;
1440                                 case 'n':
1441                                 case 'N':
1442                                         guest_ok = "no";
1443                                         break;
1444                                 default:
1445                                         rpc_conf_addshare_usage(c, argc, argv);
1446                                         status = NT_STATUS_INVALID_PARAMETER;
1447                                         goto error;
1448                         }
1449                 case 3:
1450                         if (!strnequal(argv[2], "writeable=", 10)) {
1451                                 rpc_conf_addshare_usage(c, argc, argv);
1452                                 status = NT_STATUS_INVALID_PARAMETER;
1453                                 goto error;
1454                         }
1455                         switch (argv[2][10]) {
1456                                 case 'y':
1457                                 case 'Y':
1458                                         read_only = "no";
1459                                         break;
1460                                 case 'n':
1461                                 case 'N':
1462                                         read_only = "yes";
1463                                         break;
1464                                 default:
1465                                         rpc_conf_addshare_usage(c, argc, argv);
1466                                         status = NT_STATUS_INVALID_PARAMETER;
1467                                         goto error;
1468                         }
1469                 case 2:
1470                         path = argv[1];
1471                         sharename = talloc_strdup(frame, argv[0]);
1472                         if (sharename == NULL) {
1473                                 d_printf(_("error: out of memory!\n"));
1474                                 goto error;
1475                         }
1476
1477                         break;
1478         }
1479
1480         status = rpc_conf_open_conf(frame,
1481                                     b,
1482                                     REG_KEY_READ,
1483                                     &hive_hnd,
1484                                     &key_hnd,
1485                                     &werr);
1486
1487         if (!(NT_STATUS_IS_OK(status))) {
1488                 goto error;
1489         }
1490
1491         if (!(W_ERROR_IS_OK(werr))) {
1492                 goto error;
1493         }
1494
1495         key.name = argv[0];
1496         keyclass.name = "";
1497
1498         status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1499                         0, REG_KEY_READ, NULL, &share_hnd,
1500                         &action, &werr);
1501
1502         if (!(NT_STATUS_IS_OK(status))) {
1503                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1504                                 argv[0], nt_errstr(status));
1505                 goto error;
1506         }
1507
1508         if (!W_ERROR_IS_OK(werr)) {
1509                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1510                                 argv[0], win_errstr(werr));
1511                 goto error;
1512         }
1513
1514         switch (action) {
1515                 case REG_ACTION_NONE:
1516                         werr = WERR_CREATE_FAILED;
1517                         d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1518                                 argv[0], win_errstr(werr));
1519                         goto error;
1520                 case REG_CREATED_NEW_KEY:
1521                         DEBUG(5, ("net rpc conf setincludes:"
1522                                         "createkey created %s\n", argv[0]));
1523                         break;
1524                 case REG_OPENED_EXISTING_KEY:
1525                         d_fprintf(stderr, _("ERROR: Share '%s' already exists\n"), argv[0]);
1526                         status = NT_STATUS_INVALID_PARAMETER;
1527                         goto error;
1528         }
1529
1530         /* set the path parameter */
1531         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1532                                         "path", path, &werr);
1533
1534         if (!(NT_STATUS_IS_OK(status))) {
1535                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1536                                 " with value %s\n %s\n",
1537                                 "path", path, nt_errstr(status));
1538                 goto error;
1539         }
1540
1541         if (!(W_ERROR_IS_OK(werr))) {
1542                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1543                                 " with value %s\n %s\n",
1544                                 "path", path, win_errstr(werr));
1545                 goto error;
1546         }
1547
1548         /* set the writeable parameter */
1549         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1550                                         "read only", read_only, &werr);
1551
1552         if (!(NT_STATUS_IS_OK(status))) {
1553                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1554                                 " with value %s\n %s\n",
1555                                 "read only", read_only, nt_errstr(status));
1556                 goto error;
1557         }
1558
1559         if (!(W_ERROR_IS_OK(werr))) {
1560                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1561                                 " with value %s\n %s\n",
1562                                 "read only", read_only, win_errstr(werr));
1563                 goto error;
1564         }
1565
1566         /* set the guest ok parameter */
1567         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1568                                         "guest ok", guest_ok, &werr);
1569
1570         if (!(NT_STATUS_IS_OK(status))) {
1571                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1572                                 " with value %s\n %s\n",
1573                                 "guest ok", guest_ok, nt_errstr(status));
1574                 goto error;
1575         }
1576
1577         if (!(W_ERROR_IS_OK(werr))) {
1578                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1579                                 " with value %s\n %s\n",
1580                                 "guest ok", guest_ok, win_errstr(werr));
1581                 goto error;
1582         }
1583
1584         if (argc == 5) {
1585                 /* set the comment parameter */
1586                 status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1587                                                 "comment", comment, &werr);
1588
1589                 if (!(NT_STATUS_IS_OK(status))) {
1590                         d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1591                                         " with value %s\n %s\n",
1592                                         "comment", comment, nt_errstr(status));
1593                         goto error;
1594                 }
1595
1596                 if (!(W_ERROR_IS_OK(werr))) {
1597                         d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1598                                         " with value %s\n %s\n",
1599                                         "comment", comment, win_errstr(werr));
1600                         goto error;
1601                 }
1602         }
1603 error:
1604         if (!(W_ERROR_IS_OK(werr))) {
1605                 status =  werror_to_ntstatus(werr);
1606         }
1607
1608         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1609         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1610         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1611
1612         TALLOC_FREE(frame);
1613         return status;
1614 }
1615
1616 static NTSTATUS rpc_conf_getparm_internal(struct net_context *c,
1617                                           const struct dom_sid *domain_sid,
1618                                           const char *domain_name,
1619                                           struct cli_state *cli,
1620                                           struct rpc_pipe_client *pipe_hnd,
1621                                           TALLOC_CTX *mem_ctx,
1622                                           int argc,
1623                                           const char **argv )
1624 {
1625         TALLOC_CTX *frame = talloc_stackframe();
1626         NTSTATUS status = NT_STATUS_OK;
1627         WERROR werr = WERR_OK;
1628         WERROR _werr;
1629
1630         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1631
1632         /* key info */
1633         struct policy_handle hive_hnd, key_hnd;
1634         struct smbconf_service *service = NULL;
1635
1636         bool param_is_set = false;
1637         uint32_t param_count;
1638
1639         ZERO_STRUCT(hive_hnd);
1640         ZERO_STRUCT(key_hnd);
1641
1642
1643         if (argc != 2 || c->display_usage) {
1644                 rpc_conf_getparm_usage(c, argc, argv);
1645                 status = NT_STATUS_INVALID_PARAMETER;
1646                 goto error;
1647         }
1648
1649         status = rpc_conf_open_conf(frame,
1650                                     b,
1651                                     REG_KEY_READ,
1652                                     &hive_hnd,
1653                                     &key_hnd,
1654                                     &werr);
1655
1656         if (!(NT_STATUS_IS_OK(status))) {
1657                 goto error;
1658         }
1659
1660         if (!(W_ERROR_IS_OK(werr))) {
1661                 goto error;
1662         }
1663
1664
1665         service = talloc(frame, struct smbconf_service);
1666
1667         status = rpc_conf_get_share(frame,
1668                                     b,
1669                                     &key_hnd,
1670                                     argv[0],
1671                                     service,
1672                                     &werr);
1673
1674         if (!(NT_STATUS_IS_OK(status))) {
1675                         goto error;
1676         }
1677
1678         if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
1679                 d_fprintf(stderr, _("ERROR: Share %s does not exist\n"),
1680                                 argv[0]);
1681                 goto error;
1682         }
1683
1684         if (!(W_ERROR_IS_OK(werr))) {
1685                         goto error;
1686         }
1687
1688         for (param_count = 0;
1689              param_count < service->num_params;
1690              param_count++)
1691         {
1692                 /* should includes also be printed? */
1693                 if (strcmp(service->param_names[param_count], argv[1]) == 0) {
1694                         d_printf(_("%s\n"),
1695                                 service->param_values[param_count]);
1696                         param_is_set = true;
1697                 }
1698         }
1699
1700         if (!param_is_set) {
1701                 d_fprintf(stderr, _("ERROR: Given parameter '%s' has not been set\n"),
1702                                 argv[1]);
1703                 werr = WERR_BADFILE;
1704                 goto error;
1705         }
1706
1707 error:
1708
1709         if (!(W_ERROR_IS_OK(werr))) {
1710                 status =  werror_to_ntstatus(werr);
1711         }
1712
1713         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1714         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1715
1716         TALLOC_FREE(frame);
1717         return status;
1718
1719 }
1720
1721 static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
1722                                           const struct dom_sid *domain_sid,
1723                                           const char *domain_name,
1724                                           struct cli_state *cli,
1725                                           struct rpc_pipe_client *pipe_hnd,
1726                                           TALLOC_CTX *mem_ctx,
1727                                           int argc,
1728                                           const char **argv )
1729 {
1730         TALLOC_CTX *frame = talloc_stackframe();
1731         NTSTATUS status = NT_STATUS_OK;
1732         WERROR werr = WERR_OK;
1733         WERROR _werr;
1734
1735         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1736
1737         /* key info */
1738         struct policy_handle hive_hnd, key_hnd, share_hnd;
1739
1740         struct winreg_String key, keyclass;
1741         enum winreg_CreateAction action = 0;
1742
1743         const char *service_name, *param_name, *valstr;
1744
1745         ZERO_STRUCT(hive_hnd);
1746         ZERO_STRUCT(key_hnd);
1747         ZERO_STRUCT(share_hnd);
1748
1749         ZERO_STRUCT(key);
1750         ZERO_STRUCT(keyclass);
1751
1752         if (argc != 3 || c->display_usage) {
1753                 rpc_conf_setparm_usage(c, argc, argv);
1754                 status = NT_STATUS_INVALID_PARAMETER;
1755                 goto error;
1756         }
1757
1758         status = rpc_conf_open_conf(frame,
1759                                     b,
1760                                     REG_KEY_READ,
1761                                     &hive_hnd,
1762                                     &key_hnd,
1763                                     &werr);
1764
1765         if (!(NT_STATUS_IS_OK(status))) {
1766                 goto error;
1767         }
1768
1769         if (!(W_ERROR_IS_OK(werr))) {
1770                 goto error;
1771         }
1772
1773         service_name = argv[0];
1774         param_name = argv[1];
1775         valstr = argv[2];
1776
1777         key.name = service_name;
1778         keyclass.name = "";
1779
1780         status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
1781                         0, REG_KEY_READ, NULL, &share_hnd,
1782                         &action, &werr);
1783
1784         if (!(NT_STATUS_IS_OK(status))) {
1785                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1786                           service_name, nt_errstr(status));
1787                 goto error;
1788         }
1789
1790         if (!W_ERROR_IS_OK(werr)) {
1791                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1792                           service_name, win_errstr(werr));
1793                 goto error;
1794         }
1795
1796         switch (action) {
1797                 case REG_ACTION_NONE:
1798                         werr = WERR_CREATE_FAILED;
1799                         d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
1800                                   service_name, win_errstr(werr));
1801                         goto error;
1802                 case REG_CREATED_NEW_KEY:
1803                         DEBUG(5, ("net rpc conf setparm:"
1804                                   "createkey created %s\n", service_name));
1805                         break;
1806                 case REG_OPENED_EXISTING_KEY:
1807                         DEBUG(5, ("net rpc conf setparm:"
1808                                   "createkey opened existing %s\n",
1809                                   service_name));
1810
1811                         /* delete posibly existing value */
1812                         status = rpc_conf_del_value(frame,
1813                                                     b,
1814                                                     &key_hnd,
1815                                                     service_name,
1816                                                     param_name,
1817                                                     &werr);
1818
1819                         if (!(NT_STATUS_IS_OK(status))) {
1820                                 goto error;
1821                         }
1822
1823                         if (!(W_ERROR_IS_OK(werr))) {
1824                                 goto error;
1825                         }
1826
1827                         break;
1828         }
1829
1830         /*
1831          * check if parameter is valid for writing
1832          */
1833
1834         if (!net_conf_param_valid(service_name, param_name, valstr)) {
1835                 werr = WERR_INVALID_PARAM;
1836                 goto error;
1837         }
1838
1839         /* set the parameter */
1840         status = dcerpc_winreg_set_sz(frame, b, &share_hnd,
1841                                       param_name, valstr, &werr);
1842
1843         if (!(NT_STATUS_IS_OK(status))) {
1844                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1845                                 " with value %s\n %s\n",
1846                                 param_name, valstr, nt_errstr(status));
1847                 goto error;
1848         }
1849
1850         if (!(W_ERROR_IS_OK(werr))) {
1851                 d_fprintf(stderr, "ERROR: Could not set parameter '%s'"
1852                                 " with value %s\n %s\n",
1853                                 param_name, valstr, win_errstr(werr));
1854                 goto error;
1855         }
1856
1857 error:
1858
1859         if (!(W_ERROR_IS_OK(werr))) {
1860                 status =  werror_to_ntstatus(werr);
1861         }
1862
1863         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1864         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1865         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
1866
1867         TALLOC_FREE(frame);
1868         return status;
1869 }
1870
1871 static NTSTATUS rpc_conf_delparm_internal(struct net_context *c,
1872                                           const struct dom_sid *domain_sid,
1873                                           const char *domain_name,
1874                                           struct cli_state *cli,
1875                                           struct rpc_pipe_client *pipe_hnd,
1876                                           TALLOC_CTX *mem_ctx,
1877                                           int argc,
1878                                           const char **argv )
1879 {
1880         TALLOC_CTX *frame = talloc_stackframe();
1881         NTSTATUS status = NT_STATUS_OK;
1882         WERROR werr = WERR_OK;
1883         WERROR _werr;
1884
1885         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1886
1887         /* key info */
1888         struct policy_handle hive_hnd, key_hnd;
1889
1890
1891         ZERO_STRUCT(hive_hnd);
1892         ZERO_STRUCT(key_hnd);
1893
1894
1895         if (argc != 2 || c->display_usage) {
1896                 rpc_conf_delparm_usage(c, argc, argv);
1897                 status = NT_STATUS_INVALID_PARAMETER;
1898                 goto error;
1899         }
1900
1901         status = rpc_conf_open_conf(frame,
1902                                     b,
1903                                     REG_KEY_READ,
1904                                     &hive_hnd,
1905                                     &key_hnd,
1906                                     &werr);
1907
1908         if (!(NT_STATUS_IS_OK(status))) {
1909                 goto error;
1910         }
1911
1912         if (!(W_ERROR_IS_OK(werr))) {
1913                 goto error;
1914         }
1915
1916         status = rpc_conf_del_value(frame,
1917                                     b,
1918                                     &key_hnd,
1919                                     argv[0],
1920                                     argv[1],
1921                                     &werr);
1922
1923 error:
1924
1925         if (!(W_ERROR_IS_OK(werr))) {
1926                 status =  werror_to_ntstatus(werr);
1927         }
1928
1929         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
1930         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
1931
1932         TALLOC_FREE(frame);
1933         return status;
1934
1935 }
1936
1937 static NTSTATUS rpc_conf_getincludes_internal(struct net_context *c,
1938                                               const struct dom_sid *domain_sid,
1939                                               const char *domain_name,
1940                                               struct cli_state *cli,
1941                                               struct rpc_pipe_client *pipe_hnd,
1942                                               TALLOC_CTX *mem_ctx,
1943                                               int argc,
1944                                               const char **argv )
1945 {
1946         TALLOC_CTX *frame = talloc_stackframe();
1947         NTSTATUS status = NT_STATUS_OK;
1948         WERROR werr = WERR_OK;
1949         WERROR _werr;
1950
1951         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1952
1953         /* key info */
1954         struct policy_handle hive_hnd, key_hnd;
1955         struct smbconf_service *service = NULL;
1956
1957         uint32_t param_count;
1958
1959
1960         ZERO_STRUCT(hive_hnd);
1961         ZERO_STRUCT(key_hnd);
1962
1963
1964         if (argc != 1 || c->display_usage) {
1965                 rpc_conf_getincludes_usage(c, argc, argv);
1966                 status = NT_STATUS_INVALID_PARAMETER;
1967                 goto error;
1968         }
1969
1970         status = rpc_conf_open_conf(frame,
1971                                     b,
1972                                     REG_KEY_READ,
1973                                     &hive_hnd,
1974                                     &key_hnd,
1975                                     &werr);
1976
1977         if (!(NT_STATUS_IS_OK(status))) {
1978                 goto error;
1979         }
1980
1981         if (!(W_ERROR_IS_OK(werr))) {
1982                 goto error;
1983         }
1984
1985         service = talloc(frame, struct smbconf_service);
1986
1987         status = rpc_conf_get_share(frame,
1988                                     b,
1989                                     &key_hnd,
1990                                     argv[0],
1991                                     service,
1992                                     &werr);
1993
1994         if (!(NT_STATUS_IS_OK(status))) {
1995                         goto error;
1996         }
1997
1998         if (!(W_ERROR_IS_OK(werr))) {
1999                         goto error;
2000         }
2001
2002         for (param_count = 0;
2003              param_count < service->num_params;
2004              param_count++)
2005         {
2006                 if (strcmp(service->param_names[param_count], "include") == 0) {
2007                         d_printf(_("%s = %s\n"),
2008                                 service->param_names[param_count],
2009                                 service->param_values[param_count]);
2010                 }
2011         }
2012
2013 error:
2014
2015         if (!(W_ERROR_IS_OK(werr))) {
2016                 status =  werror_to_ntstatus(werr);
2017         }
2018
2019         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2020         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2021
2022         TALLOC_FREE(frame);
2023         return status;
2024
2025 }
2026
2027 static NTSTATUS rpc_conf_setincludes_internal(struct net_context *c,
2028                                               const struct dom_sid *domain_sid,
2029                                               const char *domain_name,
2030                                               struct cli_state *cli,
2031                                               struct rpc_pipe_client *pipe_hnd,
2032                                               TALLOC_CTX *mem_ctx,
2033                                               int argc,
2034                                               const char **argv )
2035 {
2036         TALLOC_CTX *frame = talloc_stackframe();
2037         NTSTATUS status = NT_STATUS_OK;
2038         WERROR werr = WERR_OK;
2039         WERROR _werr;
2040
2041         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2042
2043         /* key info */
2044         struct policy_handle hive_hnd, key_hnd, share_hnd;
2045
2046         struct winreg_String key, keyclass;
2047         enum winreg_CreateAction action = 0;
2048
2049         ZERO_STRUCT(hive_hnd);
2050         ZERO_STRUCT(key_hnd);
2051         ZERO_STRUCT(share_hnd);
2052
2053         ZERO_STRUCT(key);
2054         ZERO_STRUCT(keyclass);
2055
2056         if (argc < 1 || c->display_usage) {
2057                 rpc_conf_setincludes_usage(c, argc, argv);
2058                 status = NT_STATUS_INVALID_PARAMETER;
2059                 goto error;
2060         }
2061
2062         status = rpc_conf_open_conf(frame,
2063                                     b,
2064                                     REG_KEY_READ,
2065                                     &hive_hnd,
2066                                     &key_hnd,
2067                                     &werr);
2068
2069         if (!(NT_STATUS_IS_OK(status))) {
2070                 goto error;
2071         }
2072
2073         if (!(W_ERROR_IS_OK(werr))) {
2074                 goto error;
2075         }
2076
2077         key.name = argv[0];
2078         keyclass.name = "";
2079
2080         status = dcerpc_winreg_CreateKey(b, frame, &key_hnd, key, keyclass,
2081                         0, REG_KEY_READ, NULL, &share_hnd,
2082                         &action, &werr);
2083
2084         if (!(NT_STATUS_IS_OK(status))) {
2085                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2086                                 argv[0], nt_errstr(status));
2087                 goto error;
2088         }
2089
2090         if (!W_ERROR_IS_OK(werr)) {
2091                 d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2092                                 argv[0], win_errstr(werr));
2093                 goto error;
2094         }
2095
2096         switch (action) {
2097                 case REG_ACTION_NONE:
2098                         /* Is there any other way to treat this? */
2099                         werr = WERR_CREATE_FAILED;
2100                         d_fprintf(stderr, _("ERROR: Could not create share key '%s'\n%s\n"),
2101                                 argv[0], win_errstr(werr));
2102                         goto error;
2103                 case REG_CREATED_NEW_KEY:
2104                         DEBUG(5, ("net rpc conf setincludes:"
2105                                         "createkey created %s\n", argv[0]));
2106                         break;
2107                 case REG_OPENED_EXISTING_KEY:
2108                         DEBUG(5, ("net rpc conf setincludes:"
2109                                         "createkey opened existing %s\n", argv[0]));
2110
2111                         /* delete posibly existing value */
2112                         status = rpc_conf_del_value(frame,
2113                                                     b,
2114                                                     &key_hnd,
2115                                                     argv[0],
2116                                                     "includes",
2117                                                     &werr);
2118
2119                         if (!(NT_STATUS_IS_OK(status))) {
2120                                 goto error;
2121                         }
2122
2123                         if (!(W_ERROR_IS_OK(werr))) {
2124                                 goto error;
2125                         }
2126                         break;
2127         }
2128
2129         /* set the 'includes' values */
2130         status = dcerpc_winreg_set_multi_sz(frame, b, &share_hnd,
2131                                             "includes", argv + 1, &werr);
2132         if (!(NT_STATUS_IS_OK(status))) {
2133                 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2134                                 nt_errstr(status));
2135                 goto error;
2136         }
2137
2138         if (!(W_ERROR_IS_OK(werr))) {
2139                 d_fprintf(stderr, "ERROR: Could not set includes\n %s\n",
2140                                 win_errstr(werr));
2141                 goto error;
2142         }
2143
2144 error:
2145
2146         if (!(W_ERROR_IS_OK(werr))) {
2147                 status =  werror_to_ntstatus(werr);
2148         }
2149
2150         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2151         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2152         dcerpc_winreg_CloseKey(b, frame, &share_hnd, &_werr);
2153
2154         TALLOC_FREE(frame);
2155         return status;
2156 }
2157
2158 static NTSTATUS rpc_conf_delincludes_internal(struct net_context *c,
2159                                               const struct dom_sid *domain_sid,
2160                                               const char *domain_name,
2161                                               struct cli_state *cli,
2162                                               struct rpc_pipe_client *pipe_hnd,
2163                                               TALLOC_CTX *mem_ctx,
2164                                               int argc,
2165                                               const char **argv )
2166 {
2167         TALLOC_CTX *frame = talloc_stackframe();
2168         NTSTATUS status = NT_STATUS_OK;
2169         WERROR werr = WERR_OK;
2170         WERROR _werr;
2171
2172         struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2173
2174         /* key info */
2175         struct policy_handle hive_hnd, key_hnd;
2176
2177
2178         ZERO_STRUCT(hive_hnd);
2179         ZERO_STRUCT(key_hnd);
2180
2181
2182         if (argc != 1 || c->display_usage) {
2183                 rpc_conf_delincludes_usage(c, argc, argv);
2184                 status = NT_STATUS_INVALID_PARAMETER;
2185                 goto error;
2186         }
2187
2188         status = rpc_conf_open_conf(frame,
2189                                     b,
2190                                     REG_KEY_READ,
2191                                     &hive_hnd,
2192                                     &key_hnd,
2193                                     &werr);
2194
2195         if (!(NT_STATUS_IS_OK(status))) {
2196                 goto error;
2197         }
2198
2199         if (!(W_ERROR_IS_OK(werr))) {
2200                 goto error;
2201         }
2202
2203         status = rpc_conf_del_value(frame,
2204                                     b,
2205                                     &key_hnd,
2206                                     argv[0],
2207                                     "includes",
2208                                     &werr);
2209
2210 error:
2211
2212         if (!(W_ERROR_IS_OK(werr))) {
2213                 status =  werror_to_ntstatus(werr);
2214         }
2215
2216         dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr);
2217         dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr);
2218
2219         TALLOC_FREE(frame);
2220         return status;
2221
2222 }
2223
2224 /**********************************************************
2225  *
2226  * Functions that run the rpc commands for net rpc conf modules
2227  *
2228  **********************************************************/
2229
2230 static int rpc_conf_drop(struct net_context *c, int argc,
2231                                 const char **argv)
2232 {
2233         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2234                 rpc_conf_drop_internal, argc, argv );
2235
2236 }
2237
2238 static int rpc_conf_showshare(struct net_context *c, int argc,
2239                                 const char **argv)
2240 {
2241         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2242                 rpc_conf_showshare_internal, argc, argv );
2243 }
2244
2245 static int rpc_conf_addshare(struct net_context *c, int argc,
2246                                 const char **argv)
2247 {
2248         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2249                 rpc_conf_addshare_internal, argc, argv );
2250 }
2251
2252 static int rpc_conf_listshares(struct net_context *c, int argc,
2253                                 const char **argv)
2254 {
2255         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2256                 rpc_conf_listshares_internal, argc, argv );
2257 }
2258
2259 static int rpc_conf_list(struct net_context *c, int argc,
2260                              const char **argv)
2261 {
2262         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2263                 rpc_conf_list_internal, argc, argv );
2264 }
2265
2266 static int rpc_conf_import(struct net_context *c, int argc,
2267                                 const char **argv)
2268 {
2269         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2270                 rpc_conf_import_internal, argc, argv );
2271 }
2272 static int rpc_conf_delshare(struct net_context *c, int argc,
2273                              const char **argv)
2274 {
2275         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2276                 rpc_conf_delshare_internal, argc, argv );
2277 }
2278
2279 static int rpc_conf_getparm(struct net_context *c, int argc,
2280                              const char **argv)
2281 {
2282         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2283                 rpc_conf_getparm_internal, argc, argv );
2284 }
2285
2286 static int rpc_conf_setparm(struct net_context *c, int argc,
2287                                 const char **argv)
2288 {
2289         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2290                 rpc_conf_setparm_internal, argc, argv );
2291 }
2292 static int rpc_conf_delparm(struct net_context *c, int argc,
2293                                 const char **argv)
2294 {
2295         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2296                 rpc_conf_delparm_internal, argc, argv );
2297 }
2298
2299 static int rpc_conf_getincludes(struct net_context *c, int argc,
2300                              const char **argv)
2301 {
2302         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2303                 rpc_conf_getincludes_internal, argc, argv );
2304 }
2305
2306 static int rpc_conf_setincludes(struct net_context *c, int argc,
2307                                 const char **argv)
2308 {
2309         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2310                 rpc_conf_setincludes_internal, argc, argv );
2311 }
2312
2313 static int rpc_conf_delincludes(struct net_context *c, int argc,
2314                                 const char **argv)
2315 {
2316         return run_rpc_command(c, NULL, &ndr_table_winreg, 0,
2317                 rpc_conf_delincludes_internal, argc, argv );
2318 }
2319
2320 /* function calls */
2321 int net_rpc_conf(struct net_context *c, int argc,
2322                  const char **argv)
2323 {
2324         struct functable func_table[] = {
2325                 {
2326                         "list",
2327                         rpc_conf_list,
2328                         NET_TRANSPORT_RPC,
2329                         N_("Dump the complete remote configuration in smb.conf like "
2330                            "format."),
2331                         N_("net rpc conf list\n"
2332                            "    Dump the complete remote configuration in smb.conf "
2333                            "like format.")
2334
2335                 },
2336                 {
2337                         "import",
2338                         rpc_conf_import,
2339                         NET_TRANSPORT_RPC,
2340                         N_("Import configuration from file in smb.conf "
2341                            "format."),
2342                         N_("net rpc conf import\n"
2343                            "    Import configuration from file in smb.conf "
2344                            "format.")
2345                 },
2346                 {
2347                         "listshares",
2348                         rpc_conf_listshares,
2349                         NET_TRANSPORT_RPC,
2350                         N_("List the remote share names."),
2351                         N_("net rpc conf list\n"
2352                            "    List the remote share names.")
2353
2354                 },
2355                 {
2356                         "drop",
2357                         rpc_conf_drop,
2358                         NET_TRANSPORT_RPC,
2359                         N_("Delete the complete remote configuration."),
2360                         N_("net rpc conf drop\n"
2361                            "    Delete the complete remote configuration.")
2362
2363                 },
2364                 {
2365                         "showshare",
2366                         rpc_conf_showshare,
2367                         NET_TRANSPORT_RPC,
2368                         N_("Show the definition of a remote share."),
2369                         N_("net rpc conf showshare\n"
2370                            "    Show the definition of a remote share.")
2371
2372                 },
2373                 {
2374                         "addshare",
2375                         rpc_conf_addshare,
2376                         NET_TRANSPORT_RPC,
2377                         N_("Create a new remote share."),
2378                         N_("net rpc conf addshare\n"
2379                            "    Create a new remote share.")
2380                 },
2381                 {
2382                         "delshare",
2383                         rpc_conf_delshare,
2384                         NET_TRANSPORT_RPC,
2385                         N_("Delete a remote share."),
2386                         N_("net rpc conf delshare\n"
2387                            "    Delete a remote share.")
2388                 },
2389                 {
2390                         "getparm",
2391                         rpc_conf_getparm,
2392                         NET_TRANSPORT_RPC,
2393                         N_("Retrieve the value of a parameter."),
2394                         N_("net rpc conf getparm\n"
2395                            "    Retrieve the value of a parameter.")
2396                 },
2397                 {
2398                         "setparm",
2399                         rpc_conf_setparm,
2400                         NET_TRANSPORT_RPC,
2401                         N_("Store a parameter."),
2402                         N_("net rpc conf setparm\n"
2403                            "    Store a parameter.")
2404                 },
2405                 {
2406                         "delparm",
2407                         rpc_conf_delparm,
2408                         NET_TRANSPORT_RPC,
2409                         N_("Delete a parameter."),
2410                         N_("net rpc conf delparm\n"
2411                            "    Delete a parameter.")
2412                 },
2413                 {
2414                         "getincludes",
2415                         rpc_conf_getincludes,
2416                         NET_TRANSPORT_RPC,
2417                         N_("Show the includes of a share definition."),
2418                         N_("net rpc conf getincludes\n"
2419                            "    Show the includes of a share definition.")
2420                 },
2421                 {
2422                         "setincludes",
2423                         rpc_conf_setincludes,
2424                         NET_TRANSPORT_RPC,
2425                         N_("Set includes for a share."),
2426                         N_("net rpc conf setincludes\n"
2427                            "    Set includes for a share.")
2428                 },
2429                 {
2430                         "delincludes",
2431                         rpc_conf_delincludes,
2432                         NET_TRANSPORT_RPC,
2433                         N_("Delete includes from a share definition."),
2434                         N_("net rpc conf delincludes\n"
2435                            "    Delete includes from a share definition.")
2436                 },
2437                 {NULL, NULL, 0, NULL, NULL}
2438         };
2439
2440         return net_run_function(c, argc, argv, "net rpc conf", func_table);
2441
2442 }