mirror of
https://github.com/samba-team/samba.git
synced 2025-03-10 12:58:35 +03:00
r24527: Add a function lp_canonicalize_parameter_with_value that turns
a parameter and value into the canonical paramter with the value inverted if it was in invers boolean synonym. Make net conf use this function when storing parameters. Michael
This commit is contained in:
parent
0dfb5eee25
commit
3b762ab183
@ -2845,6 +2845,51 @@ BOOL lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Determine the canonical name for a parameter.
|
||||
Turn the value given into the inverse boolean expression when
|
||||
the synonym is an invers boolean synonym.
|
||||
|
||||
Return True if parm_name is a valid parameter name and
|
||||
in case it is an invers boolean synonym, if the val string could
|
||||
successfully be converted to the reverse bool.
|
||||
Return false in all other cases.
|
||||
**************************************************************************/
|
||||
|
||||
BOOL lp_canonicalize_parameter_with_value(const char *parm_name,
|
||||
const char *val,
|
||||
const char **canon_parm,
|
||||
const char **canon_val)
|
||||
{
|
||||
int num;
|
||||
BOOL inverse;
|
||||
|
||||
if (!lp_parameter_is_valid(parm_name)) {
|
||||
*canon_parm = NULL;
|
||||
*canon_val = NULL;
|
||||
return False;
|
||||
}
|
||||
|
||||
num = map_parameter_canonical(parm_name, &inverse);
|
||||
if (num < 0) {
|
||||
/* parametric option */
|
||||
*canon_parm = parm_name;
|
||||
*canon_val = val;
|
||||
} else {
|
||||
*canon_parm = parm_table[num].label;
|
||||
if (inverse) {
|
||||
if (!lp_invert_boolean(val, canon_val)) {
|
||||
*canon_val = NULL;
|
||||
return False;
|
||||
}
|
||||
} else {
|
||||
*canon_val = val;
|
||||
}
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
Map a parameter's string representation to something we can use.
|
||||
Returns False if the parameter string is not recognised, else TRUE.
|
||||
|
@ -154,44 +154,21 @@ static WERROR reg_setvalue_internal(struct registry_key *key,
|
||||
char *subkeyname;
|
||||
const char *canon_valname;
|
||||
const char *canon_valstr;
|
||||
BOOL canon_inverse;
|
||||
struct parm_struct *parm;
|
||||
|
||||
if (!lp_parameter_is_valid(valname)) {
|
||||
d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname);
|
||||
werr = WERR_INVALID_PARAM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!lp_canonicalize_parameter(valname, &canon_valname, &canon_inverse))
|
||||
if (!lp_canonicalize_parameter_with_value(valname, valstr,
|
||||
&canon_valname,
|
||||
&canon_valstr))
|
||||
{
|
||||
d_fprintf(stderr, "ERROR: could not canonicalize parameter "
|
||||
"'%s' after successful validation: this should not "
|
||||
"happen!\n", valname);
|
||||
if (canon_valname == NULL) {
|
||||
d_fprintf(stderr, "invalid parameter '%s' given\n",
|
||||
valname);
|
||||
} else {
|
||||
d_fprintf(stderr, "invalid value '%s' given for "
|
||||
"parameter '%s'\n", valstr, valname);
|
||||
}
|
||||
werr = WERR_INVALID_PARAM;
|
||||
goto done;
|
||||
}
|
||||
if (canon_inverse) {
|
||||
if (!lp_invert_boolean(valstr, &canon_valstr)) {
|
||||
d_fprintf(stderr, "invalid value '%s' given for "
|
||||
"parameter '%s'\n", valstr, canon_valname);
|
||||
werr = WERR_INVALID_PARAM;
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
parm = lp_get_parameter(canon_valname);
|
||||
if (parm->type == P_BOOL) {
|
||||
if (!lp_canonicalize_boolean(valstr, &canon_valstr)) {
|
||||
d_fprintf(stderr, "invalied value '%s' given "
|
||||
"for parameter '%s'\n", valstr,
|
||||
canon_valname);
|
||||
werr = WERR_INVALID_PARAM;
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
canon_valstr = valstr;
|
||||
}
|
||||
}
|
||||
|
||||
ZERO_STRUCT(val);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user