191692dc62d80a7b239b1f209407322471560945
[ira/wip.git] / source3 / libnet / libnet_conf.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  libnet smbconf registry Support
4  *  Copyright (C) Michael Adam 2007-2008
5  *  Copyright (C) Guenther Deschner 2007
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 #include "includes.h"
22 #include "libnet/libnet.h"
23
24 /**********************************************************************
25  *
26  * Helper functions (mostly registry related)
27  * TODO: These should be eventually static.
28
29  **********************************************************************/
30
31 /**
32  * add a string to a talloced array of strings.
33  */
34 static WERROR libnet_conf_add_string_to_array(TALLOC_CTX *mem_ctx,
35                                               char ***array,
36                                               uint32_t count,
37                                               const char *string)
38 {
39         char **new_array = NULL;
40
41         if ((array == NULL) || (string == NULL)) {
42                 return WERR_INVALID_PARAM;
43         }
44
45         new_array = TALLOC_REALLOC_ARRAY(mem_ctx, *array, char *, count + 1);
46         if (new_array == NULL) {
47                 return WERR_NOMEM;
48         }
49
50         new_array[count] = talloc_strdup(new_array, string);
51
52         *array = new_array;
53
54         return WERR_OK;
55 }
56
57 /**
58  * Open a registry key specified by "path"
59  */
60 static WERROR libnet_conf_reg_open_path(TALLOC_CTX *mem_ctx,
61                                         const char *path,
62                                         uint32 desired_access,
63                                         struct registry_key **key)
64 {
65         WERROR werr = WERR_OK;
66         NT_USER_TOKEN *token;
67         TALLOC_CTX *tmp_ctx = NULL;
68
69         if (path == NULL) {
70                 DEBUG(1, ("Error: NULL path string given\n"));
71                 werr = WERR_INVALID_PARAM;
72                 goto done;
73         }
74
75         tmp_ctx = talloc_new(mem_ctx);
76         if (tmp_ctx == NULL) {
77                 werr = WERR_NOMEM;
78                 goto done;
79         }
80
81         token = registry_create_admin_token(tmp_ctx);
82         if (token == NULL) {
83                 DEBUG(1, ("Error creating admin token\n"));
84                 /* what is the appropriate error code here? */
85                 werr = WERR_CAN_NOT_COMPLETE;
86                 goto done;
87         }
88
89         werr = reg_open_path(mem_ctx, path, desired_access, token, key);
90
91         if (!W_ERROR_IS_OK(werr)) {
92                 DEBUG(1, ("Error opening registry path '%s': %s\n",
93                           path, dos_errstr(werr)));
94         }
95
96 done:
97         TALLOC_FREE(tmp_ctx);
98         return werr;
99 }
100
101 /**
102  * Open a subkey of KEY_SMBCONF (i.e a service)
103  */
104 static WERROR libnet_conf_reg_open_service_key(TALLOC_CTX *ctx,
105                                                const char *servicename,
106                                                uint32 desired_access,
107                                                struct registry_key **key)
108 {
109         WERROR werr = WERR_OK;
110         char *path = NULL;
111
112         if (servicename == NULL) {
113                 DEBUG(3, ("Error: NULL servicename given.\n"));
114                 werr = WERR_INVALID_PARAM;
115                 goto done;
116         }
117
118         path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, servicename);
119
120         werr = libnet_conf_reg_open_path(ctx, path, desired_access, key);
121
122 done:
123         TALLOC_FREE(path);
124         return werr;
125 }
126
127 /*
128  * open the base key KEY_SMBCONF
129  */
130 static WERROR libnet_conf_reg_open_base_key(TALLOC_CTX *ctx,
131                                             uint32 desired_access,
132                                             struct registry_key **key)
133 {
134         return libnet_conf_reg_open_path(ctx, KEY_SMBCONF, desired_access, key);
135 }
136
137 static bool libnet_conf_value_exists(struct registry_key *key,
138                                      const char *param)
139 {
140         bool ret = false;
141         WERROR werr = WERR_OK;
142         TALLOC_CTX *ctx = talloc_stackframe();
143         struct registry_value *value = NULL;
144
145         werr = reg_queryvalue(ctx, key, param, &value);
146         if (W_ERROR_IS_OK(werr)) {
147                 ret = true;
148         }
149
150         TALLOC_FREE(ctx);
151         return ret;
152 }
153
154 /*
155  * create a subkey of KEY_SMBCONF
156  */
157 static WERROR libnet_conf_reg_create_service_key(TALLOC_CTX *ctx,
158                                                  const char * subkeyname,
159                                                  struct registry_key **newkey)
160 {
161         WERROR werr = WERR_OK;
162         struct registry_key *create_parent = NULL;
163         TALLOC_CTX *create_ctx;
164         enum winreg_CreateAction action = REG_ACTION_NONE;
165
166         /* create a new talloc ctx for creation. it will hold
167          * the intermediate parent key (SMBCONF) for creation
168          * and will be destroyed when leaving this function... */
169         if (!(create_ctx = talloc_new(ctx))) {
170                 werr = WERR_NOMEM;
171                 goto done;
172         }
173
174         werr = libnet_conf_reg_open_base_key(create_ctx, REG_KEY_WRITE,
175                                              &create_parent);
176         if (!W_ERROR_IS_OK(werr)) {
177                 goto done;
178         }
179
180         werr = reg_createkey(ctx, create_parent, subkeyname,
181                              REG_KEY_WRITE, newkey, &action);
182         if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
183                 DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
184                 werr = WERR_ALREADY_EXISTS;
185         }
186         if (!W_ERROR_IS_OK(werr)) {
187                 DEBUG(5, ("Error creating key %s: %s\n",
188                          subkeyname, dos_errstr(werr)));
189         }
190
191 done:
192         TALLOC_FREE(create_ctx);
193         return werr;
194 }
195
196 /*
197  * add a value to a key.
198  */
199 static WERROR libnet_conf_reg_set_value(struct registry_key *key,
200                                         const char *valname,
201                                         const char *valstr)
202 {
203         struct registry_value val;
204         WERROR werr = WERR_OK;
205         char *subkeyname;
206         const char *canon_valname;
207         const char *canon_valstr;
208
209         if (!lp_canonicalize_parameter_with_value(valname, valstr,
210                                                   &canon_valname,
211                                                   &canon_valstr))
212         {
213                 if (canon_valname == NULL) {
214                         DEBUG(5, ("invalid parameter '%s' given\n",
215                                   valname));
216                 } else {
217                         DEBUG(5, ("invalid value '%s' given for "
218                                   "parameter '%s'\n", valstr, valname));
219                 }
220                 werr = WERR_INVALID_PARAM;
221                 goto done;
222         }
223
224         ZERO_STRUCT(val);
225
226         val.type = REG_SZ;
227         val.v.sz.str = CONST_DISCARD(char *, canon_valstr);
228         val.v.sz.len = strlen(canon_valstr) + 1;
229
230         if (registry_smbconf_valname_forbidden(canon_valname)) {
231                 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
232                           canon_valname));
233                 werr = WERR_INVALID_PARAM;
234                 goto done;
235         }
236
237         subkeyname = strrchr_m(key->key->name, '\\');
238         if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
239                 DEBUG(5, ("Invalid registry key '%s' given as "
240                           "smbconf section.\n", key->key->name));
241                 werr = WERR_INVALID_PARAM;
242                 goto done;
243         }
244         subkeyname++;
245         if (!strequal(subkeyname, GLOBAL_NAME) &&
246             lp_parameter_is_global(valname))
247         {
248                 DEBUG(5, ("Global paramter '%s' not allowed in "
249                           "service definition ('%s').\n", canon_valname,
250                           subkeyname));
251                 werr = WERR_INVALID_PARAM;
252                 goto done;
253         }
254
255         werr = reg_setvalue(key, canon_valname, &val);
256         if (!W_ERROR_IS_OK(werr)) {
257                 DEBUG(5, ("Error adding value '%s' to "
258                           "key '%s': %s\n",
259                           canon_valname, key->key->name, dos_errstr(werr)));
260         }
261
262 done:
263         return werr;
264 }
265
266 /**
267  * format a registry_value into a string.
268  *
269  * This is intended to be used for smbconf registry values,
270  * which are ar stored as REG_SZ values, so the incomplete
271  * handling should be ok.
272  */
273 static char *libnet_conf_format_registry_value(TALLOC_CTX *mem_ctx,
274                                                struct registry_value *value)
275 {
276         char *result = NULL;
277
278         /* alternatively, create a new talloc context? */
279         if (mem_ctx == NULL) {
280                 return result;
281         }
282
283         switch (value->type) {
284         case REG_DWORD:
285                 result = talloc_asprintf(mem_ctx, "%d", value->v.dword);
286                 break;
287         case REG_SZ:
288         case REG_EXPAND_SZ:
289                 result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str);
290                 break;
291         case REG_MULTI_SZ: {
292                 uint32 j;
293                 for (j = 0; j < value->v.multi_sz.num_strings; j++) {
294                         result = talloc_asprintf(mem_ctx, "\"%s\" ",
295                                                  value->v.multi_sz.strings[j]);
296                 }
297                 break;
298         }
299         case REG_BINARY:
300                 result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
301                                          (int)value->v.binary.length);
302                 break;
303         default:
304                 result = talloc_asprintf(mem_ctx, "<unprintable>");
305                 break;
306         }
307         return result;
308 }
309
310 /**
311  * Get the values of a key as a list of value names
312  * and a list of value strings (ordered)
313  */
314 static WERROR libnet_conf_reg_get_values(TALLOC_CTX *mem_ctx,
315                                          struct registry_key *key,
316                                          uint32_t *num_values,
317                                          char ***value_names,
318                                          char ***value_strings)
319 {
320         TALLOC_CTX *tmp_ctx = NULL;
321         WERROR werr = WERR_OK;
322         uint32_t count;
323         struct registry_value *valvalue = NULL;
324         char *valname = NULL;
325         char **tmp_valnames = NULL;
326         char **tmp_valstrings = NULL;
327
328         if ((num_values == NULL) || (value_names == NULL) ||
329             (value_strings == NULL))
330         {
331                 werr = WERR_INVALID_PARAM;
332                 goto done;
333         }
334
335         tmp_ctx = talloc_new(mem_ctx);
336         if (tmp_ctx == NULL) {
337                 werr = WERR_NOMEM;
338                 goto done;
339         }
340
341         for (count = 0;
342              W_ERROR_IS_OK(werr = reg_enumvalue(tmp_ctx, key, count, &valname,
343                                                 &valvalue));
344              count++)
345         {
346                 char *valstring;
347
348                 werr = libnet_conf_add_string_to_array(tmp_ctx,
349                                                        &tmp_valnames,
350                                                        count, valname);
351                 if (!W_ERROR_IS_OK(werr)) {
352                         goto done;
353                 }
354
355                 valstring = libnet_conf_format_registry_value(tmp_ctx,
356                                                               valvalue);
357                 werr = libnet_conf_add_string_to_array(tmp_ctx,
358                                                        &tmp_valstrings,
359                                                        count,
360                                                        valstring);
361                 if (!W_ERROR_IS_OK(werr)) {
362                         goto done;
363                 }
364         }
365         if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
366                 goto done;
367         }
368
369         werr = WERR_OK;
370
371         *num_values = count;
372         if (count > 0) {
373                 *value_names = talloc_move(mem_ctx, &tmp_valnames);
374                 *value_strings = talloc_move(mem_ctx, &tmp_valstrings);
375         } else {
376                 *value_names = NULL;
377                 *value_strings = NULL;
378         }
379
380 done:
381         TALLOC_FREE(tmp_ctx);
382         return werr;
383 }
384
385 /**********************************************************************
386  *
387  * The actual net conf api functions, that are exported.
388  *
389  **********************************************************************/
390
391 /**
392  * Drop the whole configuration (restarting empty).
393  */
394 WERROR libnet_smbconf_drop(void)
395 {
396         char *path, *p;
397         WERROR werr = WERR_OK;
398         struct registry_key *parent_key = NULL;
399         struct registry_key *new_key = NULL;
400         TALLOC_CTX* mem_ctx = talloc_stackframe();
401         enum winreg_CreateAction action;
402
403         path = talloc_strdup(mem_ctx, KEY_SMBCONF);
404         if (path == NULL) {
405                 werr = WERR_NOMEM;
406                 goto done;
407         }
408         p = strrchr(path, '\\');
409         *p = '\0';
410         werr = libnet_conf_reg_open_path(mem_ctx, path, REG_KEY_WRITE,
411                                          &parent_key);
412
413         if (!W_ERROR_IS_OK(werr)) {
414                 goto done;
415         }
416
417         werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1);
418
419         if (!W_ERROR_IS_OK(werr)) {
420                 goto done;
421         }
422
423         werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
424                              &new_key, &action);
425
426 done:
427         TALLOC_FREE(mem_ctx);
428         return werr;
429 }
430
431 /**
432  * Get the whole configuration as lists of strings with counts:
433  *
434  *  num_shares   : number of shares
435  *  share_names  : list of length num_shares of share names
436  *  num_params   : list of length num_shares of parameter counts for each share
437  *  param_names  : list of lists of parameter names for each share
438  *  param_values : list of lists of parameter values for each share
439  */
440 WERROR libnet_smbconf_get_config(TALLOC_CTX *mem_ctx, uint32_t *num_shares,
441                                  char ***share_names, uint32_t **num_params,
442                                  char ****param_names, char ****param_values)
443 {
444         WERROR werr = WERR_OK;
445         TALLOC_CTX *tmp_ctx = NULL;
446         uint32_t tmp_num_shares;
447         char **tmp_share_names;
448         uint32_t *tmp_num_params;
449         char ***tmp_param_names;
450         char ***tmp_param_values;
451         uint32_t count;
452
453         if ((num_shares == NULL) || (share_names == NULL) ||
454             (num_params == NULL) || (param_names == NULL) ||
455             (param_values == NULL))
456         {
457                 werr = WERR_INVALID_PARAM;
458                 goto done;
459         }
460
461         tmp_ctx = talloc_new(mem_ctx);
462         if (tmp_ctx == NULL) {
463                 werr = WERR_NOMEM;
464                 goto done;
465         }
466
467         werr = libnet_smbconf_get_share_names(tmp_ctx, &tmp_num_shares,
468                                               &tmp_share_names);
469         if (!W_ERROR_IS_OK(werr)) {
470                 goto done;
471         }
472
473         tmp_num_params   = TALLOC_ARRAY(tmp_ctx, uint32_t, tmp_num_shares);
474         tmp_param_names  = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
475         tmp_param_values = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
476
477         if ((tmp_num_params == NULL) || (tmp_param_names == NULL) ||
478             (tmp_param_values == NULL))
479         {
480                 werr = WERR_NOMEM;
481                 goto done;
482         }
483
484         for (count = 0; count < tmp_num_shares; count++) {
485                 werr = libnet_smbconf_getshare(mem_ctx, tmp_share_names[count],
486                                                &tmp_num_params[count],
487                                                &tmp_param_names[count],
488                                                &tmp_param_values[count]);
489                 if (!W_ERROR_IS_OK(werr)) {
490                         goto done;
491                 }
492         }
493
494         werr = WERR_OK;
495
496         *num_shares = tmp_num_shares;
497         if (tmp_num_shares > 0) {
498                 *share_names = talloc_move(mem_ctx, &tmp_share_names);
499                 *num_params = talloc_move(mem_ctx, &tmp_num_params);
500                 *param_names = talloc_move(mem_ctx, &tmp_param_names);
501                 *param_values = talloc_move(mem_ctx, &tmp_param_values);
502         } else {
503                 *share_names = NULL;
504                 *num_params = NULL;
505                 *param_names = NULL;
506                 *param_values = NULL;
507         }
508
509 done:
510         TALLOC_FREE(tmp_ctx);
511         return werr;
512 }
513
514
515 /**
516  * get the list of share names defined in the configuration.
517  */
518 WERROR libnet_smbconf_get_share_names(TALLOC_CTX *mem_ctx, uint32_t *num_shares,
519                                       char ***share_names)
520 {
521         uint32_t count;
522         uint32_t added_count = 0;
523         TALLOC_CTX *tmp_ctx = NULL;
524         WERROR werr = WERR_OK;
525         struct registry_key *key = NULL;
526         char *subkey_name = NULL;
527         char **tmp_share_names = NULL;
528
529         if ((num_shares == NULL) || (share_names == NULL)) {
530                 werr = WERR_INVALID_PARAM;
531                 goto done;
532         }
533
534         tmp_ctx = talloc_new(mem_ctx);
535         if (tmp_ctx == NULL) {
536                 werr = WERR_NOMEM;
537                 goto done;
538         }
539
540         /* make sure "global" is always listed first */
541         if (libnet_smbconf_share_exists(GLOBAL_NAME)) {
542                 werr = libnet_conf_add_string_to_array(tmp_ctx,
543                                                        &tmp_share_names,
544                                                        0, GLOBAL_NAME);
545                 if (!W_ERROR_IS_OK(werr)) {
546                         goto done;
547                 }
548                 added_count++;
549         }
550
551         werr = libnet_conf_reg_open_base_key(tmp_ctx, SEC_RIGHTS_ENUM_SUBKEYS,
552                                              &key);
553         if (!W_ERROR_IS_OK(werr)) {
554                 goto done;
555         }
556
557         for (count = 0;
558              W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count,
559                                               &subkey_name, NULL));
560              count++)
561         {
562                 if (strequal(subkey_name, GLOBAL_NAME)) {
563                         continue;
564                 }
565
566                 werr = libnet_conf_add_string_to_array(tmp_ctx,
567                                                        &tmp_share_names,
568                                                        added_count,
569                                                        subkey_name);
570                 if (!W_ERROR_IS_OK(werr)) {
571                         goto done;
572                 }
573                 added_count++;
574         }
575         if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
576                 goto done;
577         }
578         werr = WERR_OK;
579
580         *num_shares = added_count;
581         if (added_count > 0) {
582                 *share_names = talloc_move(mem_ctx, &tmp_share_names);
583         } else {
584                 *share_names = NULL;
585         }
586
587 done:
588         TALLOC_FREE(tmp_ctx);
589         return werr;
590 }
591
592 /**
593  * check if a share/service of a given name exists
594  */
595 bool libnet_smbconf_share_exists(const char *servicename)
596 {
597         bool ret = false;
598         WERROR werr = WERR_OK;
599         TALLOC_CTX *mem_ctx = talloc_stackframe();
600         struct registry_key *key = NULL;
601
602         werr = libnet_conf_reg_open_service_key(mem_ctx, servicename,
603                                                 REG_KEY_READ, &key);
604         if (W_ERROR_IS_OK(werr)) {
605                 ret = true;
606         }
607
608         TALLOC_FREE(mem_ctx);
609         return ret;
610 }
611
612 /**
613  * Add a service if it does not already exist.
614  */
615 WERROR libnet_smbconf_create_share(const char *servicename)
616 {
617         WERROR werr;
618         TALLOC_CTX *mem_ctx = talloc_stackframe();
619         struct registry_key *key = NULL;
620
621         if (libnet_smbconf_share_exists(servicename)) {
622                 werr = WERR_ALREADY_EXISTS;
623                 goto done;
624         }
625
626         werr = libnet_conf_reg_create_service_key(mem_ctx, servicename, &key);
627
628 done:
629         TALLOC_FREE(mem_ctx);
630         return werr;
631 }
632
633 /**
634  * get a definition of a share (service) from configuration.
635  */
636 WERROR libnet_smbconf_getshare(TALLOC_CTX *mem_ctx, const char *servicename,
637                                uint32_t *num_params, char ***param_names,
638                                char ***param_values)
639 {
640         WERROR werr = WERR_OK;
641         struct registry_key *key = NULL;
642
643         werr = libnet_conf_reg_open_service_key(mem_ctx, servicename,
644                                                 REG_KEY_READ, &key);
645         if (!W_ERROR_IS_OK(werr)) {
646                 goto done;
647         }
648
649         werr = libnet_conf_reg_get_values(mem_ctx, key, num_params,
650                                           param_names, param_values);
651
652 done:
653         TALLOC_FREE(key);
654         return werr;
655 }
656
657 /**
658  * delete a service from configuration
659  */
660 WERROR libnet_smbconf_delshare(const char *servicename)
661 {
662         WERROR werr = WERR_OK;
663         struct registry_key *key = NULL;
664         TALLOC_CTX *ctx = talloc_stackframe();
665
666         werr = libnet_conf_reg_open_base_key(ctx, REG_KEY_WRITE, &key);
667         if (!W_ERROR_IS_OK(werr)) {
668                 goto done;
669         }
670
671         werr = reg_deletekey_recursive(key, key, servicename);
672
673 done:
674         TALLOC_FREE(ctx);
675         return werr;
676 }
677
678 /**
679  * set a configuration parameter to the value provided.
680  */
681 WERROR libnet_smbconf_setparm(const char *service,
682                               const char *param,
683                               const char *valstr)
684 {
685         WERROR werr;
686         struct registry_key *key = NULL;
687         TALLOC_CTX *mem_ctx = talloc_stackframe();
688
689         if (!libnet_smbconf_share_exists(service)) {
690                 werr = WERR_NO_SUCH_SERVICE;
691                 goto done;
692         }
693
694         werr = libnet_conf_reg_open_service_key(mem_ctx, service, REG_KEY_WRITE,
695                                                 &key);
696         if (!W_ERROR_IS_OK(werr)) {
697                 goto done;
698         }
699
700         werr = libnet_conf_reg_set_value(key, param, valstr);
701
702 done:
703         TALLOC_FREE(mem_ctx);
704         return werr;
705 }
706
707 /**
708  * get the value of a configuration parameter as a string
709  */
710 WERROR libnet_smbconf_getparm(TALLOC_CTX *mem_ctx,
711                               const char *service,
712                               const char *param,
713                               char **valstr)
714 {
715         WERROR werr = WERR_OK;
716         struct registry_key *key = NULL;
717         struct registry_value *value = NULL;
718
719         if (valstr == NULL) {
720                 werr = WERR_INVALID_PARAM;
721                 goto done;
722         }
723
724         if (!libnet_smbconf_share_exists(service)) {
725                 werr = WERR_NO_SUCH_SERVICE;
726                 goto done;
727         }
728
729         werr = libnet_conf_reg_open_service_key(mem_ctx, service, REG_KEY_READ,
730                                                 &key);
731         if (!W_ERROR_IS_OK(werr)) {
732                 goto done;
733         }
734
735         if (!libnet_conf_value_exists(key, param)) {
736                 werr = WERR_INVALID_PARAM;
737                 goto done;
738         }
739
740         werr = reg_queryvalue(mem_ctx, key, param, &value);
741         if (!W_ERROR_IS_OK(werr)) {
742                 goto done;
743         }
744
745         *valstr = libnet_conf_format_registry_value(mem_ctx, value);
746
747         if (*valstr == NULL) {
748                 werr = WERR_NOMEM;
749         }
750
751 done:
752         TALLOC_FREE(key);
753         TALLOC_FREE(value);
754         return werr;
755 }
756
757 /**
758  * delete a parameter from configuration
759  */
760 WERROR libnet_smbconf_delparm(const char *service,
761                               const char *param)
762 {
763         struct registry_key *key = NULL;
764         WERROR werr = WERR_OK;
765         TALLOC_CTX *mem_ctx = talloc_stackframe();
766
767         if (!libnet_smbconf_share_exists(service)) {
768                 return WERR_NO_SUCH_SERVICE;
769         }
770
771         werr = libnet_conf_reg_open_service_key(mem_ctx, service, REG_KEY_ALL,
772                                                 &key);
773         if (!W_ERROR_IS_OK(werr)) {
774                 goto done;
775         }
776
777         if (!libnet_conf_value_exists(key, param)) {
778                 werr = WERR_INVALID_PARAM;
779                 goto done;
780         }
781
782         werr = reg_deletevalue(key, param);
783
784 done:
785         TALLOC_FREE(mem_ctx);
786         return werr;
787 }
788
789
790 /**********************************************************************
791  *
792  * Convenience functions that are also exported.
793  *
794  **********************************************************************/
795
796 WERROR libnet_smbconf_set_global_param(const char *param,
797                                        const char *val)
798 {
799         return libnet_smbconf_setparm(GLOBAL_NAME, param, val);
800 }
801