summaryrefslogtreecommitdiffstats
path: root/login-utils/islocal.c
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:32 +0100
committerKarel Zak2006-12-07 00:25:32 +0100
commit6dbe3af945a63f025561abb83275cee9ff06c57b (patch)
tree19e59eac8ac465b5bc409b5adf815b582c92f633 /login-utils/islocal.c
downloadkernel-qcow2-util-linux-6dbe3af945a63f025561abb83275cee9ff06c57b.tar.gz
kernel-qcow2-util-linux-6dbe3af945a63f025561abb83275cee9ff06c57b.tar.xz
kernel-qcow2-util-linux-6dbe3af945a63f025561abb83275cee9ff06c57b.zip
Imported from util-linux-2.2 tarball.
Diffstat (limited to 'login-utils/islocal.c')
-rw-r--r--login-utils/islocal.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/login-utils/islocal.c b/login-utils/islocal.c
new file mode 100644
index 000000000..a4cfb16ab
--- /dev/null
+++ b/login-utils/islocal.c
@@ -0,0 +1,34 @@
+/* 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*
+*/
+
+#include <stdio.h>
+#include <string.h>
+
+#define MAX_LENGTH 1024
+
+int
+is_local(char *user)
+{
+ FILE *fd;
+ char line[MAX_LENGTH];
+ int local = 0;
+
+ if(!(fd = fopen("/etc/passwd", "r"))) {
+ puts("Can't read /etc/passwd, exiting.");
+ exit(1);
+ }
+
+ while(fgets(line, MAX_LENGTH, fd) > 0) {
+ if(!strncmp(line, user, strlen(user))) {
+ local = 1;
+ break;
+ }
+ }
+ fclose(fd);
+ return local;
+}
+