Duplicate argv data before poptFreeContext().
[rsync.git] / authenticate.c
index 8fd6ff69b3d06365d645ce2ae99c8f50ad9e031c..b7f6ead93a9b10e33a3c17bd83f2ce93edd2dfd1 100644 (file)
@@ -2,7 +2,7 @@
  * Support rsync daemon authentication.
  *
  * Copyright (C) 1998-2000 Andrew Tridgell
- * Copyright (C) 2002-2020 Wayne Davison
+ * Copyright (C) 2002-2022 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
 
 extern int read_only;
 extern char *password_file;
+extern struct name_num_obj valid_auth_checksums;
 
 /***************************************************************************
 encode a buffer using base64 - simple and slow algorithm. null terminates
@@ -72,9 +73,9 @@ static void gen_challenge(const char *addr, char *challenge)
        SIVAL(input, 20, tv.tv_usec);
        SIVAL(input, 24, getpid());
 
-       sum_init(-1, 0);
+       len = sum_init(valid_auth_checksums.negotiated_nni, 0);
        sum_update(input, sizeof input);
-       len = sum_end(digest);
+       sum_end(digest);
 
        base64_encode(digest, len, challenge, 0);
 }
@@ -86,10 +87,10 @@ static void generate_hash(const char *in, const char *challenge, char *out)
        char buf[MAX_DIGEST_LEN];
        int len;
 
-       sum_init(-1, 0);
+       len = sum_init(valid_auth_checksums.negotiated_nni, 0);
        sum_update(in, strlen(in));
        sum_update(challenge, strlen(challenge));
-       len = sum_end(buf);
+       sum_end(buf);
 
        base64_encode(buf, len, out, 0);
 }
@@ -119,7 +120,7 @@ static const char *check_secret(int module, const char *user, const char *group,
                if ((st.st_mode & 06) != 0) {
                        rprintf(FLOG, "secrets file must not be other-accessible (see strict modes option)\n");
                        ok = 0;
-               } else if (MY_UID() == 0 && st.st_uid != 0) {
+               } else if (MY_UID() == ROOT_UID && st.st_uid != ROOT_UID) {
                        rprintf(FLOG, "secrets file must be owned by root when running as root (see strict modes)\n");
                        ok = 0;
                }
@@ -196,7 +197,7 @@ static const char *getpassf(const char *filename)
                        rprintf(FERROR, "ERROR: password file must not be other-accessible\n");
                        exit_cleanup(RERR_SYNTAX);
                }
-               if (MY_UID() == 0 && st.st_uid != 0) {
+               if (MY_UID() == ROOT_UID && st.st_uid != ROOT_UID) {
                        rprintf(FERROR, "ERROR: password file must be owned by root when running as root\n");
                        exit_cleanup(RERR_SYNTAX);
                }
@@ -238,6 +239,7 @@ char *auth_server(int f_in, int f_out, int module, const char *host,
        if (!users || !*users)
                return "";
 
+       negotiate_daemon_auth(f_out, 0);
        gen_challenge(addr, challenge);
 
        io_printf(f_out, "%s%s\n", leader, challenge);
@@ -350,6 +352,7 @@ void auth_client(int fd, const char *user, const char *challenge)
 
        if (!user || !*user)
                user = "nobody";
+       negotiate_daemon_auth(-1, 1);
 
        if (!(pass = getpassf(password_file))
         && !(pass = getenv("RSYNC_PASSWORD"))) {