summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2007-07-07 22:18:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:51 -0500
commitc2c96bccda2b5dd9c3991ee54426f27b88812d3c (patch)
treea374d324c4c69b84005013ba20006f44f780c8cd /source3
parentfeff1fcfd8844859b339bc14c2fe4650b3784fe4 (diff)
downloadsamba-c2c96bccda2b5dd9c3991ee54426f27b88812d3c.tar.gz
samba-c2c96bccda2b5dd9c3991ee54426f27b88812d3c.tar.bz2
samba-c2c96bccda2b5dd9c3991ee54426f27b88812d3c.zip
r23747: Move formatting of a parameter's value into a value string
to a function of its own. (for storing it in registry), Eliminate the valtype variable : store everything as "sz". Eliminate some trailing white spaces on the way. Michael (This used to be commit 76f4f224aa65b1414222818996e215ec80d117a4)
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/net_conf.c162
1 files changed, 82 insertions, 80 deletions
diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c
index febc8dc9e1..d05a36f44d 100644
--- a/source3/utils/net_conf.c
+++ b/source3/utils/net_conf.c
@@ -449,7 +449,84 @@ done:
return werr;
}
-static int import_process_service(TALLOC_CTX *ctx,
+static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm,
+ struct share_params *share)
+{
+ char *valstr = NULL;
+ int i = 0;
+ void *ptr = parm->ptr;
+
+ if (parm->p_class == P_LOCAL && share->service >= 0) {
+ ptr = lp_local_ptr(share->service, ptr);
+ }
+
+ switch (parm->type) {
+ case P_CHAR:
+ valstr = talloc_asprintf(ctx, "%c", *(char *)ptr);
+ break;
+ case P_STRING:
+ case P_USTRING:
+ valstr = talloc_asprintf(ctx, "%s", *(char **)ptr);
+ break;
+ case P_GSTRING:
+ case P_UGSTRING:
+ valstr = talloc_asprintf(ctx, "%s", (char *)ptr);
+ break;
+ case P_BOOL:
+ valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(BOOL *)ptr));
+ break;
+ case P_BOOLREV:
+ valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(BOOL *)ptr));
+ break;
+ case P_ENUM:
+ for (i = 0; parm->enum_list[i].name; i++) {
+ if (*(int *)ptr == parm->enum_list[i].value)
+ {
+ valstr = talloc_asprintf(ctx, "%s",
+ parm->enum_list[i].name);
+ break;
+ }
+ }
+ break;
+ case P_OCTAL:
+ valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr));
+ break;
+ case P_LIST:
+ valstr = talloc_strdup(ctx, "");
+ if ((char ***)ptr && *(char ***)ptr) {
+ char **list = *(char ***)ptr;
+ for (; *list; list++) {
+ /* surround strings with whitespace
+ * in double quotes */
+ if (strchr_m(*list, ' '))
+ {
+ valstr = talloc_asprintf_append(
+ valstr, "\"%s\"%s",
+ *list,
+ ((*(list+1))?", ":""));
+ }
+ else {
+ valstr = talloc_asprintf_append(
+ valstr, "%s%s", *list,
+ ((*(list+1))?", ":""));
+ }
+ }
+ }
+ break;
+ case P_INTEGER:
+ valstr = talloc_asprintf(ctx, "%d", *(int *)ptr);
+ break;
+ case P_SEP:
+ break;
+ default:
+ valstr = talloc_asprintf(ctx, "<type unimplemented>\n");
+ break;
+ }
+
+ return valstr;
+}
+
+static int import_process_service(TALLOC_CTX *ctx,
struct share_params *share)
{
int ret = -1;
@@ -458,7 +535,6 @@ static int import_process_service(TALLOC_CTX *ctx,
const char *servicename;
struct registry_key *key;
WERROR werr;
- const char *valtype = NULL;
char *valstr = NULL;
servicename = (share->service == GLOBAL_SECTION_SNUM)?
@@ -482,93 +558,19 @@ static int import_process_service(TALLOC_CTX *ctx,
while ((parm = lp_next_parameter(share->service, &pnum, 0)))
{
- void *ptr = parm->ptr;
- int i = 0;
-
- if ((share->service < 0 && parm->p_class == P_LOCAL)
+ if ((share->service < 0 && parm->p_class == P_LOCAL)
&& !(parm->flags & FLAG_GLOBAL))
continue;
- if (parm->p_class == P_LOCAL && share->service >= 0) {
- ptr = lp_local_ptr(share->service, ptr);
- }
-
- valtype = "sz";
-
- switch (parm->type) {
- case P_CHAR:
- valstr = talloc_asprintf(ctx, "%c", *(char *)ptr);
- break;
- case P_STRING:
- case P_USTRING:
- valstr = talloc_asprintf(ctx, "%s", *(char **)ptr);
- break;
- case P_GSTRING:
- case P_UGSTRING:
- valstr = talloc_asprintf(ctx, "%s", (char *)ptr);
- break;
- case P_BOOL:
- valstr = talloc_asprintf(ctx, "%s",
- BOOLSTR(*(BOOL *)ptr));
- break;
- case P_BOOLREV:
- valstr = talloc_asprintf(ctx, "%s",
- BOOLSTR(!*(BOOL *)ptr));
- break;
- case P_ENUM:
- for (i = 0; parm->enum_list[i].name; i++) {
- if (*(int *)ptr ==
- parm->enum_list[i].value)
- {
- valstr = talloc_asprintf(ctx, "%s",
- parm->enum_list[i].name);
- break;
- }
- }
- break;
- case P_OCTAL:
- valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr));
- break;
- case P_LIST:
- valstr = talloc_strdup(ctx, "");
- if ((char ***)ptr && *(char ***)ptr) {
- char **list = *(char ***)ptr;
- for (; *list; list++) {
- /* surround strings with whitespace
- * in double quotes */
- if (strchr_m(*list, ' '))
- {
- valstr = talloc_asprintf_append(
- valstr, "\"%s\"%s",
- *list,
- ((*(list+1))?", ":""));
- }
- else {
- valstr = talloc_asprintf_append(
- valstr, "%s%s", *list,
- ((*(list+1))?", ":""));
- }
- }
- }
- break;
- case P_INTEGER:
- valtype = "dword";
- valstr = talloc_asprintf(ctx, "%d", *(int *)ptr);
- break;
- case P_SEP:
- break;
- default:
- valstr = talloc_asprintf(ctx, "<type unimplemented>\n");
- break;
- }
+ valstr = parm_valstr(ctx, parm, share);
if (parm->type != P_SEP) {
if (opt_testmode) {
d_printf("\t%s = %s\n", parm->label, valstr);
}
else {
- werr = reg_setvalue_internal(key, parm->label,
- valtype, valstr);
+ werr = reg_setvalue_internal(key, parm->label,
+ "sz", valstr);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}