diff options
author | Karel Zak | 2006-12-07 00:25:34 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:34 +0100 |
commit | fd6b7a7ffc50400704beb41d5a23af5f9edb1eed (patch) | |
tree | 997c0ca2abc018369babd7da59bcd0afe492068e /login-utils/islocal.c | |
parent | Imported from util-linux-2.5 tarball. (diff) | |
download | kernel-qcow2-util-linux-fd6b7a7ffc50400704beb41d5a23af5f9edb1eed.tar.gz kernel-qcow2-util-linux-fd6b7a7ffc50400704beb41d5a23af5f9edb1eed.tar.xz kernel-qcow2-util-linux-fd6b7a7ffc50400704beb41d5a23af5f9edb1eed.zip |
Imported from util-linux-2.7.1 tarball.
Diffstat (limited to 'login-utils/islocal.c')
-rw-r--r-- | login-utils/islocal.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/login-utils/islocal.c b/login-utils/islocal.c index a4cfb16ab..5480c5744 100644 --- a/login-utils/islocal.c +++ b/login-utils/islocal.c @@ -1,13 +1,22 @@ -/* islocal.c - returns true if user is registered in the local +/* + islocal.c - returns true if user is registered in the local /etc/passwd file. Written by Alvaro Martinez Echevarria, alvaro@enano.etsit.upm.es, to allow peaceful coexistence with yp. Nov 94. + Hacked a bit by poe@daimi.aau.dk See also ftp://ftp.daimi.aau.dk/pub/linux/poe/admutil* + + Hacked by Peter Breitenlohner, peb@mppmu.mpg.de, + to distinguish user names where one is a prefix of the other, + and to use "pathnames.h". Oct 5, 96. + */ #include <stdio.h> #include <string.h> +#include "pathnames.h" + #define MAX_LENGTH 1024 int @@ -16,14 +25,16 @@ is_local(char *user) FILE *fd; char line[MAX_LENGTH]; int local = 0; + int len; - if(!(fd = fopen("/etc/passwd", "r"))) { - puts("Can't read /etc/passwd, exiting."); + if(!(fd = fopen(_PATH_PASSWD, "r"))) { + fprintf(stderr,"Can't read %s, exiting.",_PATH_PASSWD); exit(1); } + len = strlen(user); while(fgets(line, MAX_LENGTH, fd) > 0) { - if(!strncmp(line, user, strlen(user))) { + if(!strncmp(line, user, len) && line[len] == ':') { local = 1; break; } |