]> git.ipfire.org Git - thirdparty/util-linux.git/blob - login-utils/islocal.c
Imported from util-linux-2.10s 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 <stdlib.h>
21 #include <string.h>
22
23 #include "nls.h"
24 #include "pathnames.h"
25 #include "islocal.h"
26
27 #define MAX_LENGTH 1024
28
29 int
30 is_local(char *user)
31 {
32 FILE *fd;
33 char line[MAX_LENGTH];
34 int local = 0;
35 int len;
36
37 if(!(fd = fopen(_PATH_PASSWD, "r"))) {
38 fprintf(stderr,_("Can't read %s, exiting."),_PATH_PASSWD);
39 exit(1);
40 }
41
42 len = strlen(user);
43 while(fgets(line, MAX_LENGTH, fd) > 0) {
44 if(!strncmp(line, user, len) && line[len] == ':') {
45 local = 1;
46 break;
47 }
48 }
49 fclose(fd);
50 return local;
51 }
52