Add support for parsing quoted strings in a sudoOption just like

sudoers Defaults settings.
This commit is contained in:
Todd C. Miller
2015-07-07 10:58:05 -06:00
parent e3586e2a43
commit ea85db3ecd
2 changed files with 28 additions and 11 deletions

View File

@@ -1046,7 +1046,8 @@ static bool
sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry) sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry)
{ {
struct berval **bv, **p; struct berval **bv, **p;
char op, *var, *val; char *var, *val;
int op;
bool rc = false; bool rc = false;
debug_decl(sudo_ldap_parse_options, SUDOERS_DEBUG_LDAP) debug_decl(sudo_ldap_parse_options, SUDOERS_DEBUG_LDAP)
@@ -1066,15 +1067,23 @@ sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry)
val = strchr(var, '='); val = strchr(var, '=');
if (val > var) { if (val > var) {
*val++ = '\0'; /* split on = and truncate var */ *val++ = '\0'; /* split on = and truncate var */
op = *(val - 2); /* peek for += or -= cases */ op = val[-2]; /* peek for += or -= cases */
if (op == '+' || op == '-') { if (op == '+' || op == '-') {
*(val - 2) = '\0'; /* found, remove extra char */
/* case var+=val or var-=val */ /* case var+=val or var-=val */
set_default(var, val, (int) op); val[-2] = '\0'; /* remove extra + or - char */
} else { } else {
/* case var=val */ /* case var=val */
set_default(var, val, true); op = true;
} }
/* Strip double quotes if present. */
if (*val == '"') {
char *ep = val + strlen(val);
if (ep != val && ep[-1] == '"') {
val++;
ep[-1] = '\0';
}
}
set_default(var, val, op);
} else if (*var == '!') { } else if (*var == '!') {
/* case !var Boolean False */ /* case !var Boolean False */
set_default(var + 1, NULL, false); set_default(var + 1, NULL, false);

View File

@@ -1021,9 +1021,9 @@ sudo_sss_check_command(struct sudo_sss_handle *handle,
static bool static bool
sudo_sss_parse_options(struct sudo_sss_handle *handle, struct sss_sudo_rule *rule) sudo_sss_parse_options(struct sudo_sss_handle *handle, struct sss_sudo_rule *rule)
{ {
int i; int i, op;
bool ret = false; bool ret = false;
char op, *v, *val; char *v, *val;
char **val_array = NULL; char **val_array = NULL;
debug_decl(sudo_sss_parse_options, SUDOERS_DEBUG_SSSD); debug_decl(sudo_sss_parse_options, SUDOERS_DEBUG_SSSD);
@@ -1054,15 +1054,23 @@ sudo_sss_parse_options(struct sudo_sss_handle *handle, struct sss_sudo_rule *rul
val = strchr(v, '='); val = strchr(v, '=');
if (val > v) { if (val > v) {
*val++ = '\0'; /* split on = and truncate var */ *val++ = '\0'; /* split on = and truncate var */
op = *(val - 2); /* peek for += or -= cases */ op = val[-2]; /* peek for += or -= cases */
if (op == '+' || op == '-') { if (op == '+' || op == '-') {
*(val - 2) = '\0'; /* found, remove extra char */
/* case var+=val or var-=val */ /* case var+=val or var-=val */
set_default(v, val, (int) op); val[-2] = '\0'; /* remove extra + or - char */
} else { } else {
/* case var=val */ /* case var=val */
set_default(v, val, true); op = true;
} }
/* Strip double quotes if present. */
if (*val == '"') {
char *ep = val + strlen(val);
if (ep != val && ep[-1] == '"') {
val++;
ep[-1] = '\0';
}
}
set_default(v, val, op);
} else if (*v == '!') { } else if (*v == '!') {
/* case !var Boolean False */ /* case !var Boolean False */
set_default(v + 1, NULL, false); set_default(v + 1, NULL, false);