2 * Unix SMB/CIFS implementation.
3 * libnet smbconf registry Support
4 * Copyright (C) Michael Adam 2007-2008
5 * Copyright (C) Guenther Deschner 2007
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.
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.
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/>.
22 #include "smbconf_private.h"
24 /**********************************************************************
26 * Helper functions (mostly registry related)
28 **********************************************************************/
31 * add a string to a talloced array of strings.
33 static WERROR
smbconf_add_string_to_array(TALLOC_CTX
*mem_ctx
,
38 char **new_array
= NULL
;
40 if ((array
== NULL
) || (string
== NULL
)) {
41 return WERR_INVALID_PARAM
;
44 new_array
= TALLOC_REALLOC_ARRAY(mem_ctx
, *array
, char *, count
+ 1);
45 if (new_array
== NULL
) {
49 new_array
[count
] = talloc_strdup(new_array
, string
);
50 if (new_array
[count
] == NULL
) {
51 TALLOC_FREE(new_array
);
61 * Open a registry key specified by "path"
63 static WERROR
smbconf_reg_open_path(TALLOC_CTX
*mem_ctx
,
64 struct smbconf_ctx
*ctx
,
66 uint32 desired_access
,
67 struct registry_key
**key
)
69 WERROR werr
= WERR_OK
;
72 DEBUG(1, ("Error: configuration is not open!\n"));
73 werr
= WERR_INVALID_PARAM
;
77 if (ctx
->token
== NULL
) {
78 DEBUG(1, ("Error: token missing from smbconf_ctx. "
79 "was smbconf_open() called?\n"));
80 werr
= WERR_INVALID_PARAM
;
85 DEBUG(1, ("Error: NULL path string given\n"));
86 werr
= WERR_INVALID_PARAM
;
90 werr
= reg_open_path(mem_ctx
, path
, desired_access
, ctx
->token
, key
);
92 if (!W_ERROR_IS_OK(werr
)) {
93 DEBUG(1, ("Error opening registry path '%s': %s\n",
94 path
, dos_errstr(werr
)));
102 * Open a subkey of KEY_SMBCONF (i.e a service)
104 static WERROR
smbconf_reg_open_service_key(TALLOC_CTX
*mem_ctx
,
105 struct smbconf_ctx
*ctx
,
106 const char *servicename
,
107 uint32 desired_access
,
108 struct registry_key
**key
)
110 WERROR werr
= WERR_OK
;
113 if (servicename
== NULL
) {
114 DEBUG(3, ("Error: NULL servicename given.\n"));
115 werr
= WERR_INVALID_PARAM
;
119 path
= talloc_asprintf(mem_ctx
, "%s\\%s", KEY_SMBCONF
, servicename
);
125 werr
= smbconf_reg_open_path(mem_ctx
, ctx
, path
, desired_access
, key
);
133 * open the base key KEY_SMBCONF
135 static WERROR
smbconf_reg_open_base_key(TALLOC_CTX
*mem_ctx
,
136 struct smbconf_ctx
*ctx
,
137 uint32 desired_access
,
138 struct registry_key
**key
)
140 return smbconf_reg_open_path(mem_ctx
, ctx
, KEY_SMBCONF
, desired_access
,
145 * check if a value exists in a given registry key
147 static bool smbconf_value_exists(struct registry_key
*key
, const char *param
)
150 WERROR werr
= WERR_OK
;
151 TALLOC_CTX
*ctx
= talloc_stackframe();
152 struct registry_value
*value
= NULL
;
154 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
155 if (W_ERROR_IS_OK(werr
)) {
164 * create a subkey of KEY_SMBCONF
166 static WERROR
smbconf_reg_create_service_key(TALLOC_CTX
*mem_ctx
,
167 struct smbconf_ctx
*ctx
,
168 const char * subkeyname
,
169 struct registry_key
**newkey
)
171 WERROR werr
= WERR_OK
;
172 struct registry_key
*create_parent
= NULL
;
173 TALLOC_CTX
*create_ctx
;
174 enum winreg_CreateAction action
= REG_ACTION_NONE
;
176 /* create a new talloc ctx for creation. it will hold
177 * the intermediate parent key (SMBCONF) for creation
178 * and will be destroyed when leaving this function... */
179 if (!(create_ctx
= talloc_stackframe())) {
184 werr
= smbconf_reg_open_base_key(create_ctx
, ctx
, REG_KEY_WRITE
,
186 if (!W_ERROR_IS_OK(werr
)) {
190 werr
= reg_createkey(mem_ctx
, create_parent
, subkeyname
,
191 REG_KEY_WRITE
, newkey
, &action
);
192 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
193 DEBUG(10, ("Key '%s' already exists.\n", subkeyname
));
194 werr
= WERR_ALREADY_EXISTS
;
196 if (!W_ERROR_IS_OK(werr
)) {
197 DEBUG(5, ("Error creating key %s: %s\n",
198 subkeyname
, dos_errstr(werr
)));
202 TALLOC_FREE(create_ctx
);
207 * add a value to a key.
209 static WERROR
smbconf_reg_set_value(struct registry_key
*key
,
213 struct registry_value val
;
214 WERROR werr
= WERR_OK
;
216 const char *canon_valname
;
217 const char *canon_valstr
;
219 if (!lp_canonicalize_parameter_with_value(valname
, valstr
,
223 if (canon_valname
== NULL
) {
224 DEBUG(5, ("invalid parameter '%s' given\n",
227 DEBUG(5, ("invalid value '%s' given for "
228 "parameter '%s'\n", valstr
, valname
));
230 werr
= WERR_INVALID_PARAM
;
237 val
.v
.sz
.str
= CONST_DISCARD(char *, canon_valstr
);
238 val
.v
.sz
.len
= strlen(canon_valstr
) + 1;
240 if (registry_smbconf_valname_forbidden(canon_valname
)) {
241 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
243 werr
= WERR_INVALID_PARAM
;
247 subkeyname
= strrchr_m(key
->key
->name
, '\\');
248 if ((subkeyname
== NULL
) || (*(subkeyname
+1) == '\0')) {
249 DEBUG(5, ("Invalid registry key '%s' given as "
250 "smbconf section.\n", key
->key
->name
));
251 werr
= WERR_INVALID_PARAM
;
255 if (!strequal(subkeyname
, GLOBAL_NAME
) &&
256 lp_parameter_is_global(valname
))
258 DEBUG(5, ("Global paramter '%s' not allowed in "
259 "service definition ('%s').\n", canon_valname
,
261 werr
= WERR_INVALID_PARAM
;
265 werr
= reg_setvalue(key
, canon_valname
, &val
);
266 if (!W_ERROR_IS_OK(werr
)) {
267 DEBUG(5, ("Error adding value '%s' to "
269 canon_valname
, key
->key
->name
, dos_errstr(werr
)));
277 * format a registry_value into a string.
279 * This is intended to be used for smbconf registry values,
280 * which are ar stored as REG_SZ values, so the incomplete
281 * handling should be ok.
283 static char *smbconf_format_registry_value(TALLOC_CTX
*mem_ctx
,
284 struct registry_value
*value
)
288 /* alternatively, create a new talloc context? */
289 if (mem_ctx
== NULL
) {
293 switch (value
->type
) {
295 result
= talloc_asprintf(mem_ctx
, "%d", value
->v
.dword
);
299 result
= talloc_asprintf(mem_ctx
, "%s", value
->v
.sz
.str
);
303 for (j
= 0; j
< value
->v
.multi_sz
.num_strings
; j
++) {
304 result
= talloc_asprintf(mem_ctx
, "%s \"%s\" ",
306 value
->v
.multi_sz
.strings
[j
]);
307 if (result
== NULL
) {
314 result
= talloc_asprintf(mem_ctx
, "binary (%d bytes)",
315 (int)value
->v
.binary
.length
);
318 result
= talloc_asprintf(mem_ctx
, "<unprintable>");
325 * Get the values of a key as a list of value names
326 * and a list of value strings (ordered)
328 static WERROR
smbconf_reg_get_values(TALLOC_CTX
*mem_ctx
,
329 struct registry_key
*key
,
330 uint32_t *num_values
,
332 char ***value_strings
)
334 TALLOC_CTX
*tmp_ctx
= NULL
;
335 WERROR werr
= WERR_OK
;
337 struct registry_value
*valvalue
= NULL
;
338 char *valname
= NULL
;
339 char **tmp_valnames
= NULL
;
340 char **tmp_valstrings
= NULL
;
342 if ((num_values
== NULL
) || (value_names
== NULL
) ||
343 (value_strings
== NULL
))
345 werr
= WERR_INVALID_PARAM
;
349 tmp_ctx
= talloc_stackframe();
350 if (tmp_ctx
== NULL
) {
356 W_ERROR_IS_OK(werr
= reg_enumvalue(tmp_ctx
, key
, count
, &valname
,
362 werr
= smbconf_add_string_to_array(tmp_ctx
,
365 if (!W_ERROR_IS_OK(werr
)) {
369 valstring
= smbconf_format_registry_value(tmp_ctx
, valvalue
);
370 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
372 if (!W_ERROR_IS_OK(werr
)) {
376 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
384 *value_names
= talloc_move(mem_ctx
, &tmp_valnames
);
385 *value_strings
= talloc_move(mem_ctx
, &tmp_valstrings
);
388 *value_strings
= NULL
;
392 TALLOC_FREE(tmp_ctx
);
396 static int smbconf_destroy_ctx(struct smbconf_ctx
*ctx
)
398 return ctx
->ops
->close_conf(ctx
);
401 static WERROR
smbconf_global_check(struct smbconf_ctx
*ctx
)
403 if (!smbconf_share_exists(ctx
, GLOBAL_NAME
)) {
404 return smbconf_create_share(ctx
, GLOBAL_NAME
);
410 /**********************************************************************
412 * smbconf operations: registry implementations
414 **********************************************************************/
417 * initialize the registry smbconf backend
419 static WERROR
smbconf_reg_init(struct smbconf_ctx
*ctx
)
421 WERROR werr
= WERR_OK
;
423 if (!registry_init_smbconf()) {
424 werr
= WERR_REG_IO_FAILURE
;
428 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
,
430 if (!W_ERROR_IS_OK(werr
)) {
431 DEBUG(1, ("Error creating admin token\n"));
439 static WERROR
smbconf_reg_open(struct smbconf_ctx
*ctx
)
444 static int smbconf_reg_close(struct smbconf_ctx
*ctx
)
446 return regdb_close();
450 * Get the change sequence number of the given service/parameter.
451 * service and parameter strings may be NULL.
453 static void smbconf_reg_get_csn(struct smbconf_ctx
*ctx
,
454 struct smbconf_csn
*csn
,
455 const char *service
, const char *param
)
460 csn
->csn
= (uint64_t)regdb_get_seqnum();
464 * Drop the whole configuration (restarting empty) - registry version
466 static WERROR
smbconf_reg_drop(struct smbconf_ctx
*ctx
)
469 WERROR werr
= WERR_OK
;
470 struct registry_key
*parent_key
= NULL
;
471 struct registry_key
*new_key
= NULL
;
472 TALLOC_CTX
* mem_ctx
= talloc_stackframe();
473 enum winreg_CreateAction action
;
475 path
= talloc_strdup(mem_ctx
, KEY_SMBCONF
);
480 p
= strrchr(path
, '\\');
482 werr
= smbconf_reg_open_path(mem_ctx
, ctx
, path
, REG_KEY_WRITE
,
485 if (!W_ERROR_IS_OK(werr
)) {
489 werr
= reg_deletekey_recursive(mem_ctx
, parent_key
, p
+1);
491 if (!W_ERROR_IS_OK(werr
)) {
495 werr
= reg_createkey(mem_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
499 TALLOC_FREE(mem_ctx
);
504 * get the list of share names defined in the configuration.
507 static WERROR
smbconf_reg_get_share_names(struct smbconf_ctx
*ctx
,
509 uint32_t *num_shares
,
513 uint32_t added_count
= 0;
514 TALLOC_CTX
*tmp_ctx
= NULL
;
515 WERROR werr
= WERR_OK
;
516 struct registry_key
*key
= NULL
;
517 char *subkey_name
= NULL
;
518 char **tmp_share_names
= NULL
;
520 if ((num_shares
== NULL
) || (share_names
== NULL
)) {
521 werr
= WERR_INVALID_PARAM
;
525 tmp_ctx
= talloc_stackframe();
526 if (tmp_ctx
== NULL
) {
531 /* make sure "global" is always listed first */
532 if (smbconf_share_exists(ctx
, GLOBAL_NAME
)) {
533 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
535 if (!W_ERROR_IS_OK(werr
)) {
541 werr
= smbconf_reg_open_base_key(tmp_ctx
, ctx
,
542 SEC_RIGHTS_ENUM_SUBKEYS
, &key
);
543 if (!W_ERROR_IS_OK(werr
)) {
548 W_ERROR_IS_OK(werr
= reg_enumkey(tmp_ctx
, key
, count
,
549 &subkey_name
, NULL
));
552 if (strequal(subkey_name
, GLOBAL_NAME
)) {
556 werr
= smbconf_add_string_to_array(tmp_ctx
,
560 if (!W_ERROR_IS_OK(werr
)) {
565 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
570 *num_shares
= added_count
;
571 if (added_count
> 0) {
572 *share_names
= talloc_move(mem_ctx
, &tmp_share_names
);
578 TALLOC_FREE(tmp_ctx
);
583 * check if a share/service of a given name exists - registry version
585 static bool smbconf_reg_share_exists(struct smbconf_ctx
*ctx
,
586 const char *servicename
)
589 WERROR werr
= WERR_OK
;
590 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
591 struct registry_key
*key
= NULL
;
593 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
595 if (W_ERROR_IS_OK(werr
)) {
599 TALLOC_FREE(mem_ctx
);
604 * Add a service if it does not already exist - registry version
606 static WERROR
smbconf_reg_create_share(struct smbconf_ctx
*ctx
,
607 const char *servicename
)
610 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
611 struct registry_key
*key
= NULL
;
613 werr
= smbconf_reg_create_service_key(mem_ctx
, ctx
, servicename
, &key
);
615 TALLOC_FREE(mem_ctx
);
620 * get a definition of a share (service) from configuration.
622 static WERROR
smbconf_reg_get_share(struct smbconf_ctx
*ctx
,
624 const char *servicename
,
625 uint32_t *num_params
,
626 char ***param_names
, char ***param_values
)
628 WERROR werr
= WERR_OK
;
629 struct registry_key
*key
= NULL
;
631 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
633 if (!W_ERROR_IS_OK(werr
)) {
637 werr
= smbconf_reg_get_values(mem_ctx
, key
, num_params
,
638 param_names
, param_values
);
646 * delete a service from configuration
648 static WERROR
smbconf_reg_delete_share(struct smbconf_ctx
*ctx
,
649 const char *servicename
)
651 WERROR werr
= WERR_OK
;
652 struct registry_key
*key
= NULL
;
653 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
655 werr
= smbconf_reg_open_base_key(mem_ctx
, ctx
, REG_KEY_WRITE
, &key
);
656 if (!W_ERROR_IS_OK(werr
)) {
660 werr
= reg_deletekey_recursive(key
, key
, servicename
);
663 TALLOC_FREE(mem_ctx
);
668 * set a configuration parameter to the value provided.
670 static WERROR
smbconf_reg_set_parameter(struct smbconf_ctx
*ctx
,
676 struct registry_key
*key
= NULL
;
677 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
679 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
680 REG_KEY_WRITE
, &key
);
681 if (!W_ERROR_IS_OK(werr
)) {
685 werr
= smbconf_reg_set_value(key
, param
, valstr
);
688 TALLOC_FREE(mem_ctx
);
693 * get the value of a configuration parameter as a string
695 static WERROR
smbconf_reg_get_parameter(struct smbconf_ctx
*ctx
,
701 WERROR werr
= WERR_OK
;
702 struct registry_key
*key
= NULL
;
703 struct registry_value
*value
= NULL
;
705 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
707 if (!W_ERROR_IS_OK(werr
)) {
711 if (!smbconf_value_exists(key
, param
)) {
712 werr
= WERR_INVALID_PARAM
;
716 werr
= reg_queryvalue(mem_ctx
, key
, param
, &value
);
717 if (!W_ERROR_IS_OK(werr
)) {
721 *valstr
= smbconf_format_registry_value(mem_ctx
, value
);
723 if (*valstr
== NULL
) {
734 * delete a parameter from configuration
736 static WERROR
smbconf_reg_delete_parameter(struct smbconf_ctx
*ctx
,
740 struct registry_key
*key
= NULL
;
741 WERROR werr
= WERR_OK
;
742 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
744 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
746 if (!W_ERROR_IS_OK(werr
)) {
750 if (!smbconf_value_exists(key
, param
)) {
751 werr
= WERR_INVALID_PARAM
;
755 werr
= reg_deletevalue(key
, param
);
758 TALLOC_FREE(mem_ctx
);
762 struct smbconf_ops smbconf_ops_reg
= {
763 .init
= smbconf_reg_init
,
764 .open_conf
= smbconf_reg_open
,
765 .close_conf
= smbconf_reg_close
,
766 .get_csn
= smbconf_reg_get_csn
,
767 .drop
= smbconf_reg_drop
,
768 .get_share_names
= smbconf_reg_get_share_names
,
769 .share_exists
= smbconf_reg_share_exists
,
770 .create_share
= smbconf_reg_create_share
,
771 .get_share
= smbconf_reg_get_share
,
772 .delete_share
= smbconf_reg_delete_share
,
773 .set_parameter
= smbconf_reg_set_parameter
,
774 .get_parameter
= smbconf_reg_get_parameter
,
775 .delete_parameter
= smbconf_reg_delete_parameter
779 /**********************************************************************
781 * The actual libsmbconf API functions that are exported.
783 **********************************************************************/
786 * Open the configuration.
788 * This should be the first function in a sequence of calls to smbconf
791 * Upon success, this creates and returns the conf context
792 * that should be passed around in subsequent calls to the other
795 * After the work with the configuration is completed, smbconf_close()
798 WERROR
smbconf_open(TALLOC_CTX
*mem_ctx
, struct smbconf_ctx
**conf_ctx
)
800 WERROR werr
= WERR_OK
;
801 struct smbconf_ctx
*ctx
;
803 if (conf_ctx
== NULL
) {
804 return WERR_INVALID_PARAM
;
807 ctx
= TALLOC_ZERO_P(mem_ctx
, struct smbconf_ctx
);
812 ctx
->ops
= &smbconf_ops_reg
;
814 werr
= ctx
->ops
->init(ctx
);
815 if (!W_ERROR_IS_OK(werr
)) {
819 talloc_set_destructor(ctx
, smbconf_destroy_ctx
);
830 * Close the configuration.
832 void smbconf_close(struct smbconf_ctx
*ctx
)
834 /* this also closes the registry (by destructor): */
839 * Detect changes in the configuration.
840 * The given csn struct is filled with the current csn.
841 * smbconf_changed() can also be used for initial retrieval
844 bool smbconf_changed(struct smbconf_ctx
*ctx
, struct smbconf_csn
*csn
,
845 const char *service
, const char *param
)
847 struct smbconf_csn old_csn
;
855 ctx
->ops
->get_csn(ctx
, csn
, service
, param
);
856 return (csn
->csn
!= old_csn
.csn
);
860 * Drop the whole configuration (restarting empty).
862 WERROR
smbconf_drop(struct smbconf_ctx
*ctx
)
864 return ctx
->ops
->drop(ctx
);
868 * Get the whole configuration as lists of strings with counts:
870 * num_shares : number of shares
871 * share_names : list of length num_shares of share names
872 * num_params : list of length num_shares of parameter counts for each share
873 * param_names : list of lists of parameter names for each share
874 * param_values : list of lists of parameter values for each share
876 WERROR
smbconf_get_config(struct smbconf_ctx
*ctx
,
878 uint32_t *num_shares
,
879 char ***share_names
, uint32_t **num_params
,
880 char ****param_names
, char ****param_values
)
882 WERROR werr
= WERR_OK
;
883 TALLOC_CTX
*tmp_ctx
= NULL
;
884 uint32_t tmp_num_shares
;
885 char **tmp_share_names
;
886 uint32_t *tmp_num_params
;
887 char ***tmp_param_names
;
888 char ***tmp_param_values
;
891 if ((num_shares
== NULL
) || (share_names
== NULL
) ||
892 (num_params
== NULL
) || (param_names
== NULL
) ||
893 (param_values
== NULL
))
895 werr
= WERR_INVALID_PARAM
;
899 tmp_ctx
= talloc_stackframe();
900 if (tmp_ctx
== NULL
) {
905 werr
= smbconf_get_share_names(ctx
, tmp_ctx
, &tmp_num_shares
,
907 if (!W_ERROR_IS_OK(werr
)) {
911 tmp_num_params
= TALLOC_ARRAY(tmp_ctx
, uint32_t, tmp_num_shares
);
912 tmp_param_names
= TALLOC_ARRAY(tmp_ctx
, char **, tmp_num_shares
);
913 tmp_param_values
= TALLOC_ARRAY(tmp_ctx
, char **, tmp_num_shares
);
915 if ((tmp_num_params
== NULL
) || (tmp_param_names
== NULL
) ||
916 (tmp_param_values
== NULL
))
922 for (count
= 0; count
< tmp_num_shares
; count
++) {
923 werr
= smbconf_get_share(ctx
, mem_ctx
,
924 tmp_share_names
[count
],
925 &tmp_num_params
[count
],
926 &tmp_param_names
[count
],
927 &tmp_param_values
[count
]);
928 if (!W_ERROR_IS_OK(werr
)) {
935 *num_shares
= tmp_num_shares
;
936 if (tmp_num_shares
> 0) {
937 *share_names
= talloc_move(mem_ctx
, &tmp_share_names
);
938 *num_params
= talloc_move(mem_ctx
, &tmp_num_params
);
939 *param_names
= talloc_move(mem_ctx
, &tmp_param_names
);
940 *param_values
= talloc_move(mem_ctx
, &tmp_param_values
);
945 *param_values
= NULL
;
949 TALLOC_FREE(tmp_ctx
);
954 * get the list of share names defined in the configuration.
956 WERROR
smbconf_get_share_names(struct smbconf_ctx
*ctx
,
958 uint32_t *num_shares
,
961 return ctx
->ops
->get_share_names(ctx
, mem_ctx
, num_shares
,
966 * check if a share/service of a given name exists
968 bool smbconf_share_exists(struct smbconf_ctx
*ctx
,
969 const char *servicename
)
971 if (servicename
== NULL
) {
974 return ctx
->ops
->share_exists(ctx
, servicename
);
978 * Add a service if it does not already exist.
980 WERROR
smbconf_create_share(struct smbconf_ctx
*ctx
,
981 const char *servicename
)
983 if (smbconf_share_exists(ctx
, servicename
)) {
984 return WERR_ALREADY_EXISTS
;
987 return ctx
->ops
->create_share(ctx
, servicename
);
991 * get a definition of a share (service) from configuration.
993 WERROR
smbconf_get_share(struct smbconf_ctx
*ctx
,
995 const char *servicename
, uint32_t *num_params
,
996 char ***param_names
, char ***param_values
)
998 if (!smbconf_share_exists(ctx
, servicename
)) {
999 return WERR_NO_SUCH_SERVICE
;
1002 return ctx
->ops
->get_share(ctx
, mem_ctx
, servicename
, num_params
,
1003 param_names
, param_values
);
1007 * delete a service from configuration
1009 WERROR
smbconf_delete_share(struct smbconf_ctx
*ctx
, const char *servicename
)
1011 if (!smbconf_share_exists(ctx
, servicename
)) {
1012 return WERR_NO_SUCH_SERVICE
;
1015 return ctx
->ops
->delete_share(ctx
, servicename
);
1019 * set a configuration parameter to the value provided.
1021 WERROR
smbconf_set_parameter(struct smbconf_ctx
*ctx
,
1022 const char *service
,
1026 if (!smbconf_share_exists(ctx
, service
)) {
1027 return WERR_NO_SUCH_SERVICE
;
1030 return ctx
->ops
->set_parameter(ctx
, service
, param
, valstr
);
1034 * Set a global parameter
1035 * (i.e. a parameter in the [global] service).
1037 * This also creates [global] when it does not exist.
1039 WERROR
smbconf_set_global_parameter(struct smbconf_ctx
*ctx
,
1040 const char *param
, const char *val
)
1044 werr
= smbconf_global_check(ctx
);
1045 if (W_ERROR_IS_OK(werr
)) {
1046 werr
= smbconf_set_parameter(ctx
, GLOBAL_NAME
, param
, val
);
1053 * get the value of a configuration parameter as a string
1055 WERROR
smbconf_get_parameter(struct smbconf_ctx
*ctx
,
1056 TALLOC_CTX
*mem_ctx
,
1057 const char *service
,
1061 if (valstr
== NULL
) {
1062 return WERR_INVALID_PARAM
;
1065 if (!smbconf_share_exists(ctx
, service
)) {
1066 return WERR_NO_SUCH_SERVICE
;
1069 return ctx
->ops
->get_parameter(ctx
, mem_ctx
, service
, param
, valstr
);
1073 * Get the value of a global parameter.
1075 * Create [global] if it does not exist.
1077 WERROR
smbconf_get_global_parameter(struct smbconf_ctx
*ctx
,
1078 TALLOC_CTX
*mem_ctx
,
1084 werr
= smbconf_global_check(ctx
);
1085 if (W_ERROR_IS_OK(werr
)) {
1086 werr
= smbconf_get_parameter(ctx
, mem_ctx
, GLOBAL_NAME
, param
,
1094 * delete a parameter from configuration
1096 WERROR
smbconf_delete_parameter(struct smbconf_ctx
*ctx
,
1097 const char *service
, const char *param
)
1099 if (!smbconf_share_exists(ctx
, service
)) {
1100 return WERR_NO_SUCH_SERVICE
;
1103 return ctx
->ops
->delete_parameter(ctx
, service
, param
);
1107 * Delete a global parameter.
1109 * Create [global] if it does not exist.
1111 WERROR
smbconf_delete_global_parameter(struct smbconf_ctx
*ctx
,
1116 werr
= smbconf_global_check(ctx
);
1117 if (W_ERROR_IS_OK(werr
)) {
1118 werr
= smbconf_delete_parameter(ctx
, GLOBAL_NAME
, param
);