From 7ee486c15f51177016baf85c1d21244b84667dc2 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 12 Sep 2017 17:37:25 -0400 Subject: [PATCH 1/2] Log correctly on owner/user mismatch. Found with clang's scan-build while looking at dead assignments. Fixes bug 23487; bugfix on 1135405c8c6ea31 in 0.2.9.1-alpha --- changes/bug23487 | 5 +++++ src/common/util.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changes/bug23487 diff --git a/changes/bug23487 b/changes/bug23487 new file mode 100644 index 0000000000..89b55c243a --- /dev/null +++ b/changes/bug23487 @@ -0,0 +1,5 @@ + o Minor bugfixes (logging): + - When warning about a directory owned by the wrong user, log the actual + name of the user owning the directory. Previously, we'd log the name + of the process owner twice. Fixes bug 23487; bugfix on 0.2.9.1-alpha. + diff --git a/src/common/util.c b/src/common/util.c index d2cbacde31..40f05468d8 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2334,8 +2334,8 @@ check_private_dir,(const char *dirname, cpd_check_t check, log_warn(LD_FS, "%s is not owned by this user (%s, %d) but by " "%s (%d). Perhaps you are running Tor as the wrong user?", - dirname, process_ownername, (int)running_uid, - pw ? pw->pw_name : "", (int)st.st_uid); + dirname, process_ownername, (int)running_uid, + pw_uid ? pw_uid->pw_name : "", (int)st.st_uid); tor_free(process_ownername); close(fd); From 75659fd548cbb6d597c9cf3fc6748f9771a746e9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 15 Sep 2017 14:26:59 -0400 Subject: [PATCH 2/2] Use different variable names for pw_uid usages Catalyst points out that using pw_uid for two different purposes here is likely to be confusing. --- src/common/util.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/common/util.c b/src/common/util.c index 40f05468d8..6b1b4296b5 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2323,21 +2323,27 @@ check_private_dir,(const char *dirname, cpd_check_t check, running_gid = getgid(); } if (st.st_uid != running_uid) { - const struct passwd *pw_uid = NULL; - char *process_ownername = NULL; + char *process_ownername = NULL, *file_ownername = NULL; - pw_uid = tor_getpwuid(running_uid); - process_ownername = pw_uid ? tor_strdup(pw_uid->pw_name) : - tor_strdup(""); + { + const struct passwd *pw_running = tor_getpwuid(running_uid); + process_ownername = pw_running ? tor_strdup(pw_running->pw_name) : + tor_strdup(""); + } - pw_uid = tor_getpwuid(st.st_uid); + { + const struct passwd *pw_stat = tor_getpwuid(st.st_uid); + file_ownername = pw_stat ? tor_strdup(pw_stat->pw_name) : + tor_strdup(""); + } log_warn(LD_FS, "%s is not owned by this user (%s, %d) but by " "%s (%d). Perhaps you are running Tor as the wrong user?", dirname, process_ownername, (int)running_uid, - pw_uid ? pw_uid->pw_name : "", (int)st.st_uid); + file_ownername, (int)st.st_uid); tor_free(process_ownername); + tor_free(file_ownername); close(fd); return -1; }