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