0bc7c63471326dbd4558a43f77ded84c42c31a14
[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         if (!(token = registry_create_admin_token(mem_ctx))) {
399                 DEBUG(1, ("Error creating admin token\n"));
400                 /* what is the appropriate error code here? */
401                 werr = WERR_CAN_NOT_COMPLETE;
402                 goto done;
403         }
404
405         path = talloc_strdup(mem_ctx, KEY_SMBCONF);
406         if (path == NULL) {
407                 werr = WERR_NOMEM;
408                 goto done;
409         }
410         p = strrchr(path, '\\');
411         *p = '\0';
412         werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token, &parent_key);
413
414         if (!W_ERROR_IS_OK(werr)) {
415                 goto done;
416         }
417
418         werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1);
419
420         if (!W_ERROR_IS_OK(werr)) {
421                 goto done;
422         }
423
424         werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
425                              &new_key, &action);
426
427 done:
428         TALLOC_FREE(mem_ctx);
429         return werr;
430 }
431
432 /**
433  * Get the whole configuration as lists of strings with counts:
434  *
435  *  num_shares   : number of shares
436  *  share_names  : list of length num_shares of share names
437  *  num_params   : list of length num_shares of parameter counts for each share
438  *  param_names  : list of lists of parameter names for each share
439  *  param_values : list of lists of parameter values for each share
440  */
441 WERROR libnet_smbconf_get_config(TALLOC_CTX *mem_ctx, uint32_t *num_shares,
442                                  char ***share_names, uint32_t **num_params,
443                                  char ****param_names, char ****param_values)
444 {
445         WERROR werr = WERR_OK;
446         TALLOC_CTX *tmp_ctx = NULL;
447         uint32_t tmp_num_shares;
448         char **tmp_share_names;
449         uint32_t *tmp_num_params;
450         char ***tmp_param_names;
451         char ***tmp_param_values;
452         uint32_t count;
453
454         if ((num_shares == NULL) || (share_names == NULL) ||
455             (num_params == NULL) || (param_names == NULL) ||
456             (param_values == NULL))
457         {
458                 werr = WERR_INVALID_PARAM;
459                 goto done;
460         }
461
462         tmp_ctx = talloc_new(mem_ctx);
463         if (tmp_ctx == NULL) {
464                 werr = WERR_NOMEM;
465                 goto done;
466         }
467
468         werr = libnet_smbconf_get_share_names(tmp_ctx, &tmp_num_shares,
469                                               &tmp_share_names);
470         if (!W_ERROR_IS_OK(werr)) {
471                 goto done;
472         }
473
474         tmp_num_params   = TALLOC_ARRAY(tmp_ctx, uint32_t, tmp_num_shares);
475         tmp_param_names  = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
476         tmp_param_values = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
477
478         if ((tmp_num_params == NULL) || (tmp_param_names == NULL) ||
479             (tmp_param_values == NULL))
480         {
481                 werr = WERR_NOMEM;
482                 goto done;
483         }
484
485         for (count = 0; count < tmp_num_shares; count++) {
486                 werr = libnet_smbconf_getshare(mem_ctx, tmp_share_names[count],
487                                                &tmp_num_params[count],
488                                                &tmp_param_names[count],
489                                                &tmp_param_values[count]);
490                 if (!W_ERROR_IS_OK(werr)) {
491                         goto done;
492                 }
493         }
494
495         werr = WERR_OK;
496
497         *num_shares = tmp_num_shares;
498         if (tmp_num_shares > 0) {
499                 *share_names = talloc_move(mem_ctx, &tmp_share_names);
500                 *num_params = talloc_move(mem_ctx, &tmp_num_params);
501                 *param_names = talloc_move(mem_ctx, &tmp_param_names);
502                 *param_values = talloc_move(mem_ctx, &tmp_param_values);
503         } else {
504                 *share_names = NULL;
505                 *num_params = NULL;
506                 *param_names = NULL;
507                 *param_values = NULL;
508         }
509
510 done:
511         TALLOC_FREE(tmp_ctx);
512         return werr;
513 }
514
515
516 /**
517  * get the list of share names defined in the configuration.
518  */
519 WERROR libnet_smbconf_get_share_names(TALLOC_CTX *mem_ctx, uint32_t *num_shares,
520                                       char ***share_names)
521 {
522         uint32_t count;
523         uint32_t added_count = 0;
524         TALLOC_CTX *tmp_ctx = NULL;
525         WERROR werr = WERR_OK;
526         struct registry_key *key = NULL;
527         char *subkey_name = NULL;
528         char **tmp_share_names = NULL;
529
530         if ((num_shares == NULL) || (share_names == NULL)) {
531                 werr = WERR_INVALID_PARAM;
532                 goto done;
533         }
534
535         tmp_ctx = talloc_new(mem_ctx);
536         if (tmp_ctx == NULL) {
537                 werr = WERR_NOMEM;
538                 goto done;
539         }
540
541         /* make sure "global" is always listed first */
542         if (libnet_smbconf_share_exists(GLOBAL_NAME)) {
543                 werr = libnet_smbconf_add_string_to_array(tmp_ctx,
544                                                           &tmp_share_names,
545                                                           0, GLOBAL_NAME);
546                 if (!W_ERROR_IS_OK(werr)) {
547                         goto done;
548                 }
549                 added_count++;
550         }
551
552         werr = libnet_smbconf_reg_open_basekey(tmp_ctx,
553                                                SEC_RIGHTS_ENUM_SUBKEYS,
554                                                &key);
555         if (!W_ERROR_IS_OK(werr)) {
556                 goto done;
557         }
558
559         for (count = 0;
560              W_ERROR_IS_OK(werr = reg_enumkey(tmp_ctx, key, count,
561                                               &subkey_name, NULL));
562              count++)
563         {
564                 if (strequal(subkey_name, GLOBAL_NAME)) {
565                         continue;
566                 }
567
568                 werr = libnet_smbconf_add_string_to_array(tmp_ctx,
569                                                           &tmp_share_names,
570                                                           added_count,
571                                                           subkey_name);
572                 if (!W_ERROR_IS_OK(werr)) {
573                         goto done;
574                 }
575                 added_count++;
576         }
577         if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
578                 goto done;
579         }
580         werr = WERR_OK;
581
582         *num_shares = added_count;
583         if (added_count > 0) {
584                 *share_names = talloc_move(mem_ctx, &tmp_share_names);
585         } else {
586                 *share_names = NULL;
587         }
588
589 done:
590         TALLOC_FREE(tmp_ctx);
591         return werr;
592 }
593
594 /**
595  * check if a share/service of a given name exists
596  */
597 bool libnet_smbconf_share_exists(const char *servicename)
598 {
599         bool ret = false;
600         WERROR werr = WERR_OK;
601         TALLOC_CTX *mem_ctx = talloc_stackframe();
602         struct registry_key *key = NULL;
603
604         werr = libnet_smbconf_reg_open_service_key(mem_ctx, servicename,
605                                                    REG_KEY_READ, &key);
606         if (W_ERROR_IS_OK(werr)) {
607                 ret = true;
608         }
609
610         TALLOC_FREE(mem_ctx);
611         return ret;
612 }
613
614 /**
615  * get a definition of a share (service) from configuration.
616  */
617 WERROR libnet_smbconf_getshare(TALLOC_CTX *mem_ctx, const char *servicename,
618                                uint32_t *num_params, char ***param_names,
619                                char ***param_values)
620 {
621         WERROR werr = WERR_OK;
622         struct registry_key *key = NULL;
623
624         werr = libnet_smbconf_reg_open_service_key(mem_ctx, servicename,
625                                                    REG_KEY_READ, &key);
626         if (!W_ERROR_IS_OK(werr)) {
627                 goto done;
628         }
629
630         werr = libnet_smbconf_reg_get_values(mem_ctx, key, num_params,
631                                              param_names, param_values);
632
633 done:
634         TALLOC_FREE(key);
635         return werr;
636 }
637
638 /**
639  * delete a service from configuration
640  */
641 WERROR libnet_smbconf_delshare(const char *servicename)
642 {
643         WERROR werr = WERR_OK;
644         struct registry_key *key = NULL;
645         TALLOC_CTX *ctx = talloc_stackframe();
646
647         werr = libnet_smbconf_reg_open_basekey(ctx, REG_KEY_WRITE, &key);
648         if (!W_ERROR_IS_OK(werr)) {
649                 goto done;
650         }
651
652         werr = reg_deletekey_recursive(key, key, servicename);
653
654 done:
655         TALLOC_FREE(ctx);
656         return werr;
657 }
658
659 /**
660  * set a configuration parameter to the value provided.
661  */
662 WERROR libnet_smbconf_setparm(const char *service,
663                               const char *param,
664                               const char *valstr)
665 {
666         WERROR werr;
667         struct registry_key *key = NULL;
668         TALLOC_CTX *mem_ctx = talloc_stackframe();
669
670         if (!libnet_smbconf_share_exists(service)) {
671                 werr = libnet_smbconf_reg_createkey_internal(mem_ctx, service,
672                                                              &key);
673         } else {
674                 werr = libnet_smbconf_reg_open_service_key(mem_ctx, service,
675                                                            REG_KEY_WRITE, &key);
676         }
677         if (!W_ERROR_IS_OK(werr)) {
678                 goto done;
679         }
680
681         werr = libnet_smbconf_reg_setvalue_internal(key, param, valstr);
682
683 done:
684         TALLOC_FREE(mem_ctx);
685         return werr;
686 }
687
688 /**
689  * get the value of a configuration parameter as a string
690  */
691 WERROR libnet_smbconf_getparm(TALLOC_CTX *mem_ctx,
692                               const char *service,
693                               const char *param,
694                               char **valstr)
695 {
696         WERROR werr = WERR_OK;
697         struct registry_key *key = NULL;
698         struct registry_value *value = NULL;
699
700         if (valstr == NULL) {
701                 werr = WERR_INVALID_PARAM;
702                 goto done;
703         }
704
705         if (!libnet_smbconf_share_exists(service)) {
706                 werr = WERR_NO_SUCH_SERVICE;
707                 goto done;
708         }
709
710         werr = libnet_smbconf_reg_open_service_key(mem_ctx, service,
711                                                    REG_KEY_READ, &key);
712         if (!W_ERROR_IS_OK(werr)) {
713                 goto done;
714         }
715
716         if (!libnet_smbconf_value_exists(key, param)) {
717                 werr = WERR_INVALID_PARAM;
718                 goto done;
719         }
720
721         werr = reg_queryvalue(mem_ctx, key, param, &value);
722         if (!W_ERROR_IS_OK(werr)) {
723                 goto done;
724         }
725
726         *valstr = libnet_smbconf_format_registry_value(mem_ctx, value);
727
728         if (*valstr == NULL) {
729                 werr = WERR_NOMEM;
730         }
731
732 done:
733         TALLOC_FREE(key);
734         TALLOC_FREE(value);
735         return werr;
736 }
737
738 /**
739  * delete a parameter from configuration
740  */
741 WERROR libnet_smbconf_delparm(const char *service,
742                               const char *param)
743 {
744         struct registry_key *key = NULL;
745         WERROR werr = WERR_OK;
746         TALLOC_CTX *mem_ctx = talloc_stackframe();
747
748         if (!libnet_smbconf_share_exists(service)) {
749                 return WERR_NO_SUCH_SERVICE;
750         }
751
752         werr = libnet_smbconf_reg_open_service_key(mem_ctx, service,
753                                                    REG_KEY_ALL, &key);
754         if (!W_ERROR_IS_OK(werr)) {
755                 goto done;
756         }
757
758         if (!libnet_smbconf_value_exists(key, param)) {
759                 werr = WERR_INVALID_PARAM;
760                 goto done;
761         }
762
763         werr = reg_deletevalue(key, param);
764
765 done:
766         TALLOC_FREE(mem_ctx);
767         return werr;
768 }
769
770
771 /**********************************************************************
772  *
773  * Convenience functions that are also exported.
774  *
775  **********************************************************************/
776
777 WERROR libnet_smbconf_set_global_param(const char *param,
778                                        const char *val)
779 {
780         return libnet_smbconf_setparm(GLOBAL_NAME, param, val);
781 }
782