rsc | 2277c5d | 2004-03-21 04:33:13 +0000 | [diff] [blame] | 1 | #include <u.h> |
| 2 | #include <libc.h> |
| 3 | #include <auth.h> |
| 4 | #include <fcall.h> |
| 5 | #include <thread.h> |
| 6 | #include <9p.h> |
| 7 | |
| 8 | /* |
| 9 | * simplistic permission checking. assume that |
| 10 | * each user is the leader of her own group. |
| 11 | */ |
| 12 | int |
| 13 | hasperm(File *f, char *uid, int p) |
| 14 | { |
| 15 | int m; |
| 16 | |
| 17 | m = f->dir.mode & 7; /* other */ |
| 18 | if((p & m) == p) |
| 19 | return 1; |
| 20 | |
| 21 | if(strcmp(f->dir.uid, uid) == 0) { |
| 22 | m |= (f->dir.mode>>6) & 7; |
| 23 | if((p & m) == p) |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | if(strcmp(f->dir.gid, uid) == 0) { |
| 28 | m |= (f->dir.mode>>3) & 7; |
| 29 | if((p & m) == p) |
| 30 | return 1; |
| 31 | } |
| 32 | |
| 33 | return 0; |
| 34 | } |