about summary refs log tree commit diff
path: root/src/nix-daemon
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-17T13·49+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-17T13·49+0200
commit0c730887c4ec4a03fb854490e422c134a1bf8139 (patch)
treeec5a32c13d403e919cca8840c106e9d6859b4e8a /src/nix-daemon
parent77c972c898b325997fa2f527264a9706f1e414a5 (diff)
nix-daemon: Show name of connecting user
Diffstat (limited to 'src/nix-daemon')
-rw-r--r--src/nix-daemon/nix-daemon.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc
index f486806353b9..fd030fe47674 100644
--- a/src/nix-daemon/nix-daemon.cc
+++ b/src/nix-daemon/nix-daemon.cc
@@ -17,6 +17,7 @@
 #include <sys/un.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <pwd.h>
 
 using namespace nix;
 
@@ -855,23 +856,23 @@ static void daemonLoop()
             closeOnExec(remote);
 
             bool trusted = false;
-
             pid_t clientPid = -1;
 
 #if defined(SO_PEERCRED)
             /* Get the identity of the caller, if possible. */
-            uid_t clientUid = -1;
-
             ucred cred;
             socklen_t credLen = sizeof(cred);
             if (getsockopt(remote, SOL_SOCKET, SO_PEERCRED, &cred, &credLen) == -1)
                 throw SysError("getting peer credentials");
 
             clientPid = cred.pid;
-            clientUid = cred.uid;
-            if (clientUid == 0) trusted = true;
 
-            printMsg(lvlInfo, format("accepted connection from pid %1%, uid %2%") % clientPid % clientUid);
+            struct passwd * pw = getpwuid(cred.uid);
+            string user = pw ? pw->pw_name : int2String(cred.uid);
+
+            if (cred.uid == 0) trusted = true;
+
+            printMsg(lvlInfo, format("accepted connection from pid %1%, user %2%") % clientPid % user);
 #endif
 
             /* Fork a child to handle the connection. */