]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Automatically append "\n" to string written to child process
authorNick Porter <nick@portercomputing.co.uk>
Tue, 12 Mar 2024 17:35:47 +0000 (17:35 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Fri, 29 Mar 2024 12:40:53 +0000 (12:40 +0000)
src/modules/rlm_mschap/rlm_mschap.c

index 131efa4a490d781d78cbc11d35aaaaba302a4699..f0ceb05e7e95b58d5af99e8c76a7044ea55f6f2c 100644 (file)
@@ -805,6 +805,9 @@ static void mppe_add_reply(UNUSED rlm_mschap_t const *inst,
        REXDENT();
 }
 
+/*
+ *     Write a string to an fd, followed by "\n"
+ */
 static int write_all(int fd, char const *buf, int len) {
        int rv, done=0;
 
@@ -814,6 +817,8 @@ static int write_all(int fd, char const *buf, int len) {
                        break;
                done += rv;
        }
+       rv = write(fd, "\n", 1);
+       if (rv <= 0) return rv;
        return done;
 }
 
@@ -886,9 +891,6 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t const *inst,
                                goto ntlm_auth_err;
                        }
 
-                       buf[len++] = '\n';
-                       buf[len] = '\0';
-
                        if (write_all(to_child, buf, len) != len) {
                                REDEBUG("Failed to write username to child");
                                goto ntlm_auth_err;
@@ -903,9 +905,6 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t const *inst,
                                goto ntlm_auth_err;
                        }
 
-                       buf[len++] = '\n';
-                       buf[len] = '\0';
-
                        if (write_all(to_child, buf, len) != len) {
                                REDEBUG("Failed to write domain to child");
                                goto ntlm_auth_err;
@@ -917,8 +916,6 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t const *inst,
                /* now the password blobs */
                len = snprintf(buf, sizeof(buf), "new-nt-password-blob: ");
                fr_base16_encode(&FR_SBUFF_OUT(buf + len, sizeof(buf) - len), &FR_DBUFF_TMP(new_nt_password, 516));
-               buf[len+1032] = '\n';
-               buf[len+1033] = '\0';
                len = strlen(buf);
                if (write_all(to_child, buf, len) != len) {
                        RDEBUG2("failed to write new password blob to child");
@@ -927,8 +924,6 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t const *inst,
 
                len = snprintf(buf, sizeof(buf), "old-nt-hash-blob: ");
                fr_base16_encode(&FR_SBUFF_OUT(buf + len, sizeof(buf) - len), &FR_DBUFF_TMP(old_nt_hash, NT_DIGEST_LENGTH));
-               buf[len+32] = '\n';
-               buf[len+33] = '\0';
                len = strlen(buf);
                if (write_all(to_child, buf, len) != len) {
                        REDEBUG("Failed to write old hash blob to child");
@@ -939,17 +934,17 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t const *inst,
                 *  In current samba versions, failure to supply empty LM password/hash
                 *  blobs causes the change to fail.
                 */
-               len = snprintf(buf, sizeof(buf), "new-lm-password-blob: %01032i\n", 0);
+               len = snprintf(buf, sizeof(buf), "new-lm-password-blob: %01032i", 0);
                if (write_all(to_child, buf, len) != len) {
                        REDEBUG("Failed to write dummy LM password to child");
                        goto ntlm_auth_err;
                }
-               len = snprintf(buf, sizeof(buf), "old-lm-hash-blob: %032i\n", 0);
+               len = snprintf(buf, sizeof(buf), "old-lm-hash-blob: %032i", 0);
                if (write_all(to_child, buf, len) != len) {
                        REDEBUG("Failed to write dummy LM hash to child");
                        goto ntlm_auth_err;
                }
-               if (write_all(to_child, ".\n", 2) != 2) {
+               if (write_all(to_child, ".", 1) != 1) {
                        REDEBUG("Failed to send finish to child");
                        goto ntlm_auth_err;
                }