summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-03-22 10:08:50 -0400
committerNick Mathewson <nickm@torproject.org>2016-03-22 10:08:50 -0400
commitca8423a703803db860ee39906f8b5d362e0f64f2 (patch)
tree062a37a27f446b20eaba8713d2c6415e2b1dc752 /src/or/connection.c
parent778e8e604d561a47ca6223a570a691b6dc81128e (diff)
parentf930824914a1ebf10f502543dbc8bf598be19c3c (diff)
downloadtor-ca8423a703803db860ee39906f8b5d362e0f64f2.tar.gz
tor-ca8423a703803db860ee39906f8b5d362e0f64f2.zip
Merge remote-tracking branch 'public/bug18253'
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 4e915f1213..9c8dcdebb9 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -49,6 +49,7 @@
#include "routerlist.h"
#include "transports.h"
#include "routerparse.h"
+#include "sandbox.h"
#include "transports.h"
#ifdef USE_BUFFEREVENTS
@@ -1287,11 +1288,16 @@ connection_listener_new(const struct sockaddr *listensockaddr,
#ifdef HAVE_PWD_H
if (options->User) {
pw = tor_getpwnam(options->User);
+ struct stat st;
if (pw == NULL) {
log_warn(LD_NET,"Unable to chown() %s socket: user %s not found.",
address, options->User);
goto err;
- } else if (chown(address, pw->pw_uid, pw->pw_gid) < 0) {
+ } else if (fstat(s, &st) == 0 &&
+ st.st_uid == pw->pw_uid && st.st_gid == pw->pw_gid) {
+ /* No change needed */
+ } else if (chown(sandbox_intern_string(address),
+ pw->pw_uid, pw->pw_gid) < 0) {
log_warn(LD_NET,"Unable to chown() %s socket: %s.",
address, strerror(errno));
goto err;
@@ -1302,6 +1308,7 @@ connection_listener_new(const struct sockaddr *listensockaddr,
{
unsigned mode;
const char *status;
+ struct stat st;
if (port_cfg->is_world_writable) {
mode = 0666;
status = "world-writable";
@@ -1314,7 +1321,9 @@ connection_listener_new(const struct sockaddr *listensockaddr,
}
/* We need to use chmod; fchmod doesn't work on sockets on all
* platforms. */
- if (chmod(address, mode) < 0) {
+ if (fstat(s, &st) == 0 && (st.st_mode & 0777) == mode) {
+ /* no change needed */
+ } else if (chmod(sandbox_intern_string(address), mode) < 0) {
log_warn(LD_FS,"Unable to make %s %s.", address, status);
goto err;
}