getpw.c 634 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * getpw - get a password from the password file
  3. */
  4. /* $Id$ */
  5. #include <stdio.h>
  6. getpw(int uid, char buf[])
  7. {
  8. register FILE *pwf;
  9. register int ch, i;
  10. register char *bp;
  11. pwf = fopen("/etc/passwd", "r");
  12. if (pwf == NULL) return(1);
  13. for (;;) {
  14. bp = buf;
  15. while ((ch = getc(pwf)) != '\n') {
  16. if (ch == EOF) return 1;
  17. *bp++ = ch;
  18. }
  19. *bp++ = '\0';
  20. bp = buf;
  21. for (i = 2; i; i--) {
  22. while ((ch = *bp++) != ':') {
  23. if(ch = '\0') return 1;
  24. }
  25. }
  26. i = 0;
  27. while ((ch = *bp++) != ':') {
  28. if (ch < '0' || ch > '9') return 1;
  29. i = i * 10 + (ch - '0');
  30. }
  31. if (i == uid) return(0);
  32. }
  33. /*NOTREACHED*/
  34. }