Use readline() in sudo_ldap_read_secret()
This commit is contained in:
@@ -1885,25 +1885,31 @@ static void
|
|||||||
sudo_ldap_read_secret(const char *path)
|
sudo_ldap_read_secret(const char *path)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[LINE_MAX];
|
char *line = NULL;
|
||||||
|
size_t linesize = 0;
|
||||||
|
ssize_t len;
|
||||||
debug_decl(sudo_ldap_read_secret, SUDOERS_DEBUG_LDAP)
|
debug_decl(sudo_ldap_read_secret, SUDOERS_DEBUG_LDAP)
|
||||||
|
|
||||||
/* XXX - getline */
|
|
||||||
if ((fp = fopen(path_ldap_secret, "r")) != NULL) {
|
if ((fp = fopen(path_ldap_secret, "r")) != NULL) {
|
||||||
if (fgets(buf, sizeof(buf), fp) != NULL) {
|
len = getline(&line, &linesize, fp);
|
||||||
buf[strcspn(buf, "\n")] = '\0';
|
if (len != -1) {
|
||||||
|
/* trim newline */
|
||||||
|
while (len > 0 && line[len - 1] == '\n')
|
||||||
|
line[--len] = '\0';
|
||||||
/* copy to bindpw and binddn */
|
/* copy to bindpw and binddn */
|
||||||
free(ldap_conf.bindpw);
|
free(ldap_conf.bindpw);
|
||||||
ldap_conf.bindpw = sudo_ldap_decode_secret(buf);
|
ldap_conf.bindpw = sudo_ldap_decode_secret(line);
|
||||||
if (ldap_conf.bindpw == NULL) {
|
if (ldap_conf.bindpw == NULL) {
|
||||||
if ((ldap_conf.bindpw = strdup(buf)) == NULL)
|
/* not base64 encoded, use directly */
|
||||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
ldap_conf.bindpw = line;
|
||||||
|
line = NULL;
|
||||||
}
|
}
|
||||||
free(ldap_conf.binddn);
|
free(ldap_conf.binddn);
|
||||||
ldap_conf.binddn = ldap_conf.rootbinddn;
|
ldap_conf.binddn = ldap_conf.rootbinddn;
|
||||||
ldap_conf.rootbinddn = NULL;
|
ldap_conf.rootbinddn = NULL;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
debug_return;
|
debug_return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user