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