I was a little quick when I originally wrote this: the code only

supported setting new options.  Add support for unsetting options
and changing the value of existing options.

Sponsored by:	DARPA, NAI Labs


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@85 185d5e19-27fe-0310-9dcf-9bff6b9f3609
This commit is contained in:
Dag-Erling Smørgrav 2002-02-25 17:37:00 +00:00
parent bad941d5b0
commit 7a936aa997
1 changed files with 14 additions and 0 deletions

View File

@ -72,10 +72,20 @@ openpam_set_option(pam_handle_t *pamh,
(cur->optv[i][len] == '\0' || cur->optv[i][len] == '='))
break;
}
if (value == NULL) {
/* remove */
if (i == cur->optc)
return (PAM_SUCCESS);
for (free(cur->optv[i]); i < cur->optc; ++i)
cur->optv[i] = cur->optv[i + 1];
cur->optv[i] = NULL;
return (PAM_SUCCESS);
}
if ((opt = malloc(len + strlen(value) + 2)) == NULL)
return (PAM_BUF_ERR);
sprintf(opt, "%.*s=%s", (int)len, option, value);
if (i == cur->optc) {
/* add */
optv = realloc(cur->optv, sizeof(char *) * (cur->optc + 2));
if (optv == NULL) {
free(opt);
@ -85,6 +95,10 @@ openpam_set_option(pam_handle_t *pamh,
optv[i + 1] = NULL;
cur->optv = optv;
++cur->optc;
} else {
/* replace */
free(cur->optv[i]);
cur->optv[i] = opt;
}
return (PAM_SUCCESS);
}