xref: /plan9/sys/src/libauth/noworld.c (revision 7dd7cddf99dd7472612f1413b4da293630e6b1bc)
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <auth.h>
5 
6 /*
7  *  see if user is in the group noworld, i.e., has all file
8  *  priviledges masked with 770, and all directories with
9  *  771, before checking access rights
10  */
11 int
noworld(char * user)12 noworld(char *user)
13 {
14 	Biobuf *b;
15 	char *p;
16 	int n;
17 
18 	b = Bopen("/adm/users", OREAD);
19 	if(b == nil)
20 		return 0;
21 	while((p = Brdline(b, '\n')) != nil){
22 		p[Blinelen(b)-1] = 0;
23 		p = strchr(p, ':');
24 		if(p == nil)
25 			continue;
26 		if(strncmp(p, ":noworld:", 9) == 0){
27 			p += 9;
28 			break;
29 		}
30 	}
31 	n = strlen(user);
32 	while(p != nil && *p != 0){
33 		p = strstr(p, user);
34 		if(p == nil)
35 			break;
36 		if(*(p-1) == ':' || *(p-1) == ',')
37 		if(*(p+n) == ':' || *(p+n) == ',' || *(p+n) == 0){
38 			Bterm(b);
39 			return 1;
40 		}
41 		p++;
42 	}
43 	Bterm(b);
44 	return 0;
45 }
46