2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

Extend atobool() so we can use it in the LDAP code.

This commit is contained in:
Todd C. Miller 2010-06-03 08:50:02 -04:00
parent 59e2925374
commit 40e591c309
2 changed files with 36 additions and 44 deletions

View File

@ -45,9 +45,39 @@
int
atobool(const char *str)
{
if (strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0)
switch (*str) {
case '0':
case '1':
if (str[1] == '\0')
return *str - '0';
break;
case 'y':
case 'Y':
if (strcasecmp(str, "yes") == 0)
return 1;
if (strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0)
break;
case 't':
case 'T':
if (strcasecmp(str, "true") == 0)
return 1;
break;
case 'o':
case 'O':
if (strcasecmp(str, "on") == 0)
return 1;
if (strcasecmp(str, "off") == 0)
return 0;
break;
case 'n':
case 'N':
if (strcasecmp(str, "no") == 0)
return 0;
break;
case 'f':
case 'F':
if (strcasecmp(str, "false") == 0)
return 0;
break;
}
return -1;
}

View File

@ -818,44 +818,6 @@ sudo_ldap_build_pass1(struct passwd *pw)
return(buf);
}
/*
* Map yes/true/on to TRUE, no/false/off to FALSE, else -1
*/
int
_atobool(const char *s)
{
switch (*s) {
case 'y':
case 'Y':
if (strcasecmp(s, "yes") == 0)
return(TRUE);
break;
case 't':
case 'T':
if (strcasecmp(s, "true") == 0)
return(TRUE);
break;
case 'o':
case 'O':
if (strcasecmp(s, "on") == 0)
return(TRUE);
if (strcasecmp(s, "off") == 0)
return(FALSE);
break;
case 'n':
case 'N':
if (strcasecmp(s, "no") == 0)
return(FALSE);
break;
case 'f':
case 'F':
if (strcasecmp(s, "false") == 0)
return(FALSE);
break;
}
return(-1);
}
static void
sudo_ldap_read_secret(const char *path)
{
@ -917,7 +879,7 @@ sudo_ldap_read_config(void)
if (strcasecmp(keyword, cur->conf_str) == 0) {
switch (cur->type) {
case CONF_BOOL:
*(int *)(cur->valp) = _atobool(value);
*(int *)(cur->valp) = atobool(value) == TRUE;
break;
case CONF_INT:
*(int *)(cur->valp) = atoi(value);
@ -1025,7 +987,7 @@ sudo_ldap_read_config(void)
if (ldap_conf.ssl != NULL) {
if (strcasecmp(ldap_conf.ssl, "start_tls") == 0)
ldap_conf.ssl_mode = SUDO_LDAP_STARTTLS;
else if (_atobool(ldap_conf.ssl))
else if (atobool(ldap_conf.ssl) == TRUE)
ldap_conf.ssl_mode = SUDO_LDAP_SSL;
}