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