[hackers] [utmp] Copy test of getpwuid from st || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 17 Sep 2014 10:01:57 +0200

commit 9631182347109af70cc725aabd6d567c83e989ec
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Thu Aug 28 11:41:54 2014 +0200

    Copy test of getpwuid from st
    
    This part of the code is identicall to the code of st, and st does
    better tests that utmp was doing, so we take the code of st.

diff --git a/utmp.c b/utmp.c
index bda11d3..f551f9d 100644
--- a/utmp.c
+++ b/utmp.c
_AT_@ -46,9 +46,13 @@ main(int argc, char *argv[])
         gid = getgid();
         setgid(gid);
 
- pw = getpwuid(uid = getuid());
- if (!pw || !pw->pw_name)
- die("Process is running with an incorrect uid %d", uid);
+ errno = 0;
+ if ((pw = getpwuid(uid = getuid())) == NULL) {
+ if(errno)
+ die("getpwuid:%s", strerror(errno));
+ else
+ die("who are you?");
+ }
 
         setenv("LOGNAME", pw->pw_name, 1);
         setenv("USER", pw->pw_name, 1);
Received on Wed Sep 17 2014 - 10:01:57 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 17 2014 - 10:12:09 CEST