From 7a936aa9975af47a16e0aa91caa9ca0b8b41e6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 25 Feb 2002 17:37:00 +0000 Subject: [PATCH] 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 --- lib/openpam_set_option.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/openpam_set_option.c b/lib/openpam_set_option.c index 4e2033b..13fcee5 100644 --- a/lib/openpam_set_option.c +++ b/lib/openpam_set_option.c @@ -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); }