test_pwd.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * test_pwd.c - This file is part of the libc-8086/pwd package for ELKS,
  3. * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10. #include <pwd.h>
  11. int main(int argc, char **argv)
  12. {
  13. struct passwd *passwd;
  14. int test_uid;
  15. fprintf(stdout, "Beginning test of libc/pwd...\n");
  16. fprintf(stdout, "=> Testing setpwent(), getpwent(), endpwent()...\n");
  17. fprintf(stdout, "-> setpwent()...\n");
  18. setpwent();
  19. fprintf(stdout, "-> getpwent()...\n");
  20. printf
  21. ("********************************************************************************\n");
  22. while ((passwd = getpwent()) != NULL) {
  23. printf("pw_name\t\t: %s\n", passwd->pw_name);
  24. printf("pw_passwd\t: %s\n", passwd->pw_passwd);
  25. printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
  26. printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
  27. printf("pw_gecos\t: %s\n", passwd->pw_gecos);
  28. printf("pw_dir\t\t: %s\n", passwd->pw_dir);
  29. printf("pw_shell\t: %s\n", passwd->pw_shell);
  30. printf
  31. ("********************************************************************************\n");
  32. }
  33. fprintf(stdout, "-> endpwent()...\n");
  34. endpwent();
  35. fprintf(stdout,
  36. "=> Test of setpwent(), getpwent(), endpwent() complete.\n");
  37. fprintf(stdout, "=> Testing getpwuid(), getpwnam()...\n");
  38. fprintf(stdout, "-> getpwuid()...\n");
  39. printf
  40. ("********************************************************************************\n");
  41. for (test_uid = 0; test_uid < 1000; test_uid++) {
  42. fprintf(stdout, "-> getpwuid(%d)...\n", test_uid);
  43. passwd = getpwuid((uid_t) test_uid);
  44. if (passwd != NULL) {
  45. printf("pw_name\t\t: %s\n", passwd->pw_name);
  46. printf("pw_passwd\t: %s\n", passwd->pw_passwd);
  47. printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
  48. printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
  49. printf("pw_gecos\t: %s\n", passwd->pw_gecos);
  50. printf("pw_dir\t\t: %s\n", passwd->pw_dir);
  51. printf("pw_shell\t: %s\n", passwd->pw_shell);
  52. printf
  53. ("********************************************************************************\n");
  54. }
  55. }
  56. fprintf(stdout, "-> getpwnam()...\n");
  57. passwd = getpwnam("root");
  58. if (passwd == NULL) {
  59. printf(">NULL<\n");
  60. } else {
  61. printf("pw_name\t\t: %s\n", passwd->pw_name);
  62. printf("pw_passwd\t: %s\n", passwd->pw_passwd);
  63. printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
  64. printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
  65. printf("pw_gecos\t: %s\n", passwd->pw_gecos);
  66. printf("pw_dir\t\t: %s\n", passwd->pw_dir);
  67. printf("pw_shell\t: %s\n", passwd->pw_shell);
  68. }
  69. return 0;
  70. }