Rework this to prevent a nasty problem involving different modules'

option interacting with each other.
This commit is contained in:
Mark Murray 2001-08-10 14:16:47 +00:00
parent 0b2e8123ef
commit cfa285d9e4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=81453

View File

@ -52,62 +52,54 @@ pam_std_option(struct options *options, struct opttab other_options[],
int argc, const char **argv) int argc, const char **argv)
{ {
struct opttab *oo; struct opttab *oo;
int i, j, arglen, found; int i, j, std, extra, arglen, found;
j = 0; std = 1;
extra = 1;
oo = other_options;
for (i = 0; i < PAM_MAX_OPTIONS; i++) { for (i = 0; i < PAM_MAX_OPTIONS; i++) {
if (std_options[i].name == NULL) { if (std && std_options[i].name == NULL)
j = i; std = 0;
break; else if (extra && (oo == NULL || oo->name == NULL))
extra = 0;
if (std)
options->opt[i].name = std_options[i].name;
else if (extra) {
if (oo->value != i)
syslog(LOG_DEBUG, "Extra option fault: %d %d",
oo->value, i);
options->opt[i].name = oo->name;
oo++;
} }
/* XXX Bad juju happens if loop exits with j == 0 */ else
} options->opt[i].name = NULL;
if (other_options)
for (oo = other_options; oo->name != NULL; oo++) {
found = 0;
for (i = 0; std_options[i].name; i++)
if (strcmp((char *)oo->name,
std_options[i].name) == 0)
found = 1;
if (!found) {
std_options[j].name = oo->name;
std_options[j].value = oo->value;
j++;
}
}
for (i = 0; i < PAM_MAX_OPTIONS; i++) {
options->opt[i].bool = 0; options->opt[i].bool = 0;
options->opt[i].arg = NULL; options->opt[i].arg = NULL;
} }
if (j < PAM_MAX_OPTIONS) {
std_options[j].name = NULL;
std_options[j].value = 0;
}
for (j = 0; j < argc; j++) { for (j = 0; j < argc; j++) {
#ifdef DEBUG #ifdef DEBUG
syslog(LOG_DEBUG, "Doing arg %s ", argv[j]); syslog(LOG_DEBUG, "Doing arg %s", argv[j]);
#endif #endif
found = 0; found = 0;
for (i = 0; i < PAM_MAX_OPTIONS; i++) { for (i = 0; i < PAM_MAX_OPTIONS; i++) {
if (std_options[i].name == NULL) if (options->opt[i].name == NULL)
break; break;
if (strcmp(argv[j], std_options[i].name) == 0) { arglen = strlen(options->opt[i].name);
options->opt[std_options[i].value].bool = 1; if (strcmp(argv[j], options->opt[i].name) == 0) {
options->opt[i].bool = 1;
found = 1; found = 1;
break; break;
} }
else { else if (strncmp(argv[j], options->opt[i].name, arglen)
arglen = strlen(std_options[i].name); == 0 && argv[j][arglen] == '=') {
if (strncmp(argv[j], std_options[i].name, options->opt[i].bool = 1;
arglen) == 0 options->opt[i].arg
&& argv[j][arglen] == '=') { = strdup(&argv[j][arglen + 1]);
options->opt[std_options[i].value].bool found = 1;
= 1; break;
options->opt[std_options[i].value].arg =
strdup(&argv[j][arglen + 1]);
found = 1;
break;
}
} }
} }
if (!found) if (!found)
@ -150,7 +142,7 @@ pam_clear_option(struct options *options, enum opt option)
#endif #endif
} }
#if DEBUG1 #ifdef DEBUG1
enum { PAM_OPT_FOO=PAM_OPT_STD_MAX, PAM_OPT_BAR, PAM_OPT_BAZ, PAM_OPT_QUX }; enum { PAM_OPT_FOO=PAM_OPT_STD_MAX, PAM_OPT_BAR, PAM_OPT_BAZ, PAM_OPT_QUX };
struct opttab other_options[] = { struct opttab other_options[] = {