diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-06-14T11·53+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-06-14T11·53+0000 |
commit | b454977909f31cf560518042f22d930c375caaac (patch) | |
tree | b21aaf4486a8aee787d38348d78d914026f36bfb | |
parent | 3a68622dda35d448d1baa61825edda45ca846b97 (diff) |
* Fix for a problem with BSD's group ownership semantics when the user
is not in the "wheel" group.
-rw-r--r-- | src/libutil/util.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 4e93464865f7..556c3c3a2aa4 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -300,7 +300,19 @@ Path createTempDir() while (1) { checkInterrupt(); Path tmpDir = tempName(); - if (mkdir(tmpDir.c_str(), 0777) == 0) return tmpDir; + if (mkdir(tmpDir.c_str(), 0777) == 0) { + /* Explicitly set the group of the directory. This is to + work around around problems caused by BSD's group + ownership semantics (directories inherit the group of + the parent). For instance, the group of /tmp on + FreeBSD is "wheel", so all directories created in /tmp + will be owned by "wheel"; but if the user is not in + "wheel", then "tar" will fail to unpack archives that + have the setgid bit set on directories. */ + if (chown(tmpDir.c_str(), (uid_t) -1, getegid()) != 0) + throw SysError(format("setting group of directory `%1%'") % tmpDir); + return tmpDir; + } if (errno != EEXIST) throw SysError(format("creating directory `%1%'") % tmpDir); } |