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