test_pwd.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with this library; if not, write to the Free
  17. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. */
  20. #include <unistd.h>
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <pwd.h>
  24. int main(int argc, char **argv)
  25. {
  26. struct passwd *passwd;
  27. int test_uid;
  28. fprintf(stdout, "Beginning test of libc/pwd...\n");
  29. fprintf(stdout, "=> Testing setpwent(), getpwent(), endpwent()...\n");
  30. fprintf(stdout, "-> setpwent()...\n");
  31. setpwent();
  32. fprintf(stdout, "-> getpwent()...\n");
  33. printf
  34. ("********************************************************************************\n");
  35. while ((passwd = getpwent()) != NULL) {
  36. printf("pw_name\t\t: %s\n", passwd->pw_name);
  37. printf("pw_passwd\t: %s\n", passwd->pw_passwd);
  38. printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
  39. printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
  40. printf("pw_gecos\t: %s\n", passwd->pw_gecos);
  41. printf("pw_dir\t\t: %s\n", passwd->pw_dir);
  42. printf("pw_shell\t: %s\n", passwd->pw_shell);
  43. printf
  44. ("********************************************************************************\n");
  45. }
  46. fprintf(stdout, "-> endpwent()...\n");
  47. endpwent();
  48. fprintf(stdout,
  49. "=> Test of setpwent(), getpwent(), endpwent() complete.\n");
  50. fprintf(stdout, "=> Testing getpwuid(), getpwnam()...\n");
  51. fprintf(stdout, "-> getpwuid()...\n");
  52. printf
  53. ("********************************************************************************\n");
  54. for (test_uid = 0; test_uid < 1000; test_uid++) {
  55. fprintf(stdout, "-> getpwuid(%d)...\n", test_uid);
  56. passwd = getpwuid((uid_t) test_uid);
  57. if (passwd != NULL) {
  58. printf("pw_name\t\t: %s\n", passwd->pw_name);
  59. printf("pw_passwd\t: %s\n", passwd->pw_passwd);
  60. printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
  61. printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
  62. printf("pw_gecos\t: %s\n", passwd->pw_gecos);
  63. printf("pw_dir\t\t: %s\n", passwd->pw_dir);
  64. printf("pw_shell\t: %s\n", passwd->pw_shell);
  65. printf
  66. ("********************************************************************************\n");
  67. }
  68. }
  69. fprintf(stdout, "-> getpwnam()...\n");
  70. passwd = getpwnam("root");
  71. if (passwd == NULL) {
  72. printf(">NULL<\n");
  73. } else {
  74. printf("pw_name\t\t: %s\n", passwd->pw_name);
  75. printf("pw_passwd\t: %s\n", passwd->pw_passwd);
  76. printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
  77. printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
  78. printf("pw_gecos\t: %s\n", passwd->pw_gecos);
  79. printf("pw_dir\t\t: %s\n", passwd->pw_dir);
  80. printf("pw_shell\t: %s\n", passwd->pw_shell);
  81. }
  82. return 0;
  83. }