]> git.ipfire.org Git - thirdparty/util-linux.git/blob - login-utils/islocal.c
Imported from util-linux-2.9v tarball.
[thirdparty/util-linux.git] / login-utils / islocal.c
1 /*
2 islocal.c - returns true if user is registered in the local
3 /etc/passwd file. Written by Alvaro Martinez Echevarria,
4 alvaro@enano.etsit.upm.es, to allow peaceful coexistence with yp. Nov 94.
5
6 Hacked a bit by poe@daimi.aau.dk
7 See also ftp://ftp.daimi.aau.dk/pub/linux/poe/admutil*
8
9 Hacked by Peter Breitenlohner, peb@mppmu.mpg.de,
10 to distinguish user names where one is a prefix of the other,
11 and to use "pathnames.h". Oct 5, 96.
12
13 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
14 - added Native Language Support
15
16
17 */
18
19 #include <stdio.h>
20 #include <string.h>
21
22 #include "nls.h"
23 #include "pathnames.h"
24
25 #define MAX_LENGTH 1024
26
27 int
28 is_local(char *user)
29 {
30 FILE *fd;
31 char line[MAX_LENGTH];
32 int local = 0;
33 int len;
34
35 if(!(fd = fopen(_PATH_PASSWD, "r"))) {
36 fprintf(stderr,_("Can't read %s, exiting."),_PATH_PASSWD);
37 exit(1);
38 }
39
40 len = strlen(user);
41 while(fgets(line, MAX_LENGTH, fd) > 0) {
42 if(!strncmp(line, user, len) && line[len] == ':') {
43 local = 1;
44 break;
45 }
46 }
47 fclose(fd);
48 return local;
49 }
50