noworld.c 779 B

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