]> granicus.if.org Git - sudo/commitdiff
Use readline() in sudo_ldap_read_secret()
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Nov 2016 16:22:18 +0000 (09:22 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Nov 2016 16:22:18 +0000 (09:22 -0700)
plugins/sudoers/ldap.c

index db38b73631990c381ed014aaa967093b74d73815..3aed80e21d1e3ca8626749964731c9bda0771984 100644 (file)
@@ -1885,25 +1885,31 @@ static void
 sudo_ldap_read_secret(const char *path)
 {
     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)
 
-    /* XXX - getline */
     if ((fp = fopen(path_ldap_secret, "r")) != NULL) {
-       if (fgets(buf, sizeof(buf), fp) != NULL) {
-           buf[strcspn(buf, "\n")] = '\0';
+       len = getline(&line, &linesize, fp);
+       if (len != -1) {
+           /* trim newline */
+           while (len > 0 && line[len - 1] == '\n')
+               line[--len] = '\0';
            /* copy to bindpw and binddn */
            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 = strdup(buf)) == NULL)
-                   sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
+               /* not base64 encoded, use directly */
+               ldap_conf.bindpw = line;
+               line = NULL;
            }
            free(ldap_conf.binddn);
            ldap_conf.binddn = ldap_conf.rootbinddn;
            ldap_conf.rootbinddn = NULL;
        }
        fclose(fp);
+       free(line);
     }
     debug_return;
 }