Don't try to change gid unless we're privileged.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 16 Mar 2012 01:17:31 +0000 (01:17 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 16 Mar 2012 01:17:31 +0000 (01:17 +0000)
This affects both tripe(8) and tripectl(1).  The options are still
useful, since they determine the ownership of the administration socket.

This is a result of a long-standing error by the author, who assumed
that it was possible to setgid(2) to any existing supplementary group.

client/tripectl.1.in
common/util.c
server/tripe.8.in

index d517f9b..4c6777e 100644 (file)
@@ -200,7 +200,9 @@ and
 options.
 .TP
 .BI "\-G, \-\-setgid=" group
-Set gid to that of
+If the current effective uid is zero (i.e., the daemon was invoked as
+.BR root )
+then set gid to that of
 .I group
 (either a group name or integer gid) after initialization.  If a new
 .BR tripe (8)
index 92b9853..78358b3 100644 (file)
@@ -137,7 +137,9 @@ gid_t u_getgroup(const char *name)
 
 void u_setugid(uid_t u, gid_t g)
 {
-  if (g != (gid_t)-1) {
+  uid_t cu = geteuid();
+
+  if (cu == 0 && g != (gid_t)-1) {
     if (setgid(g) || (getuid() == 0 && setgroups(1, &g))) {
       die(EXIT_FAILURE, "couldn't setgid to %u: %s",
          (unsigned)g, strerror(errno));
index 9721246..14ee0ab 100644 (file)
@@ -223,9 +223,13 @@ option.  The selected user (and group) will also be the owner of the
 administration socket.
 .TP
 .BI "\-G, \-\-setgid=" group
-Set gid to that of
+If the current effective uid is zero (i.e., the daemon was invoked as
+.BR root )
+then set gid to that of
 .I group
-(either a group name or integer gid) after initialization.
+(either a group name or integer gid) after initialization.  In any
+event, arrange hat the administration socket be owned by the given
+.IR group .
 .TP
 .BI "\-k, \-\-priv\-keyring=" file
 Reads the private key from