util-linux/login-utils/islocal.c

53 lines
1.1 KiB
C
Raw Normal View History

/*
islocal.c - returns true if user is registered in the local
2006-12-06 17:25:32 -06:00
/etc/passwd file. Written by Alvaro Martinez Echevarria,
alvaro@enano.etsit.upm.es, to allow peaceful coexistence with yp. Nov 94.
2006-12-06 17:25:32 -06:00
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.
1999-02-22 Arkadiusz Mi<EFBFBD>kiewicz <misiek@pld.ORG.PL>
2006-12-06 17:25:39 -06:00
- added Native Language Support
2006-12-06 17:25:32 -06:00
*/
#include <stdio.h>
#include <stdlib.h>
2006-12-06 17:25:32 -06:00
#include <string.h>
2006-12-06 17:25:39 -06:00
#include "nls.h"
#include "pathnames.h"
#include "islocal.h"
2006-12-06 17:25:32 -06:00
#define MAX_LENGTH 1024
int
is_local(char *user)
{
FILE *fd;
char line[MAX_LENGTH];
int local = 0;
int len;
2006-12-06 17:25:32 -06:00
if(!(fd = fopen(_PATH_PASSWD, "r"))) {
2006-12-06 17:25:39 -06:00
fprintf(stderr,_("Can't read %s, exiting."),_PATH_PASSWD);
2006-12-06 17:25:32 -06:00
exit(1);
}
len = strlen(user);
2006-12-06 17:25:32 -06:00
while(fgets(line, MAX_LENGTH, fd) > 0) {
if(!strncmp(line, user, len) && line[len] == ':') {
2006-12-06 17:25:32 -06:00
local = 1;
break;
}
}
fclose(fd);
return local;
}