getpwnam.c 507 B

1234567891011121314151617181920212223242526272829
  1. #include "lib.h"
  2. #include <stddef.h>
  3. #include <pwd.h>
  4. #include <string.h>
  5. static struct passwd holdpw;
  6. static char dirbuf[40] = "/usr/";
  7. static char *rc = "/bin/rc";
  8. struct passwd *
  9. getpwnam(const char *name)
  10. {
  11. int num;
  12. char *nam, *mem;
  13. num = 0;
  14. nam = name;
  15. mem = 0;
  16. if(_getpw(&num, &nam, &mem)){
  17. holdpw.pw_name = nam;
  18. holdpw.pw_uid = num;
  19. holdpw.pw_gid = num;
  20. strncpy(dirbuf+5, nam, sizeof(dirbuf)-6);
  21. holdpw.pw_dir = dirbuf;
  22. holdpw.pw_shell = rc;
  23. return &holdpw;
  24. }
  25. return NULL;
  26. }