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