test_grp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * test_grp.c - This file is part of the libc-8086/grp 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 <grp.h>
  24. int main(int argc, char **argv)
  25. {
  26. struct group *group;
  27. char **tmp_mem;
  28. int test_gid;
  29. fprintf(stdout, "Beginning test of libc/grp...\n");
  30. fprintf(stdout, "=> Testing setgrent(), getgrent(), endgrent()...\n");
  31. fprintf(stdout, "-> setgrent()...\n");
  32. setgrent();
  33. fprintf(stdout, "-> getgrent()...\n");
  34. printf
  35. ("********************************************************************************\n");
  36. while ((group = getgrent()) != NULL) {
  37. printf("gr_name\t\t: %s\n", group->gr_name);
  38. printf("gr_passwd\t: %s\n", group->gr_passwd);
  39. printf("gr_gid\t\t: %d\n", (int) group->gr_gid);
  40. printf("gr_mem\t\t: ");
  41. fflush(stdout);
  42. tmp_mem = group->gr_mem;
  43. while (*tmp_mem != NULL) {
  44. printf("%s, ", *tmp_mem);
  45. tmp_mem++;
  46. }
  47. printf
  48. ("\n********************************************************************************\n");
  49. }
  50. fprintf(stdout, "-> endgrent()...\n");
  51. endgrent();
  52. fprintf(stdout,
  53. "=> Test of setgrent(), getgrent(), endgrent() complete.\n");
  54. fprintf(stdout, "=> Testing getgrid(), getgrnam()...\n");
  55. fprintf(stdout, "-> getgrgid()...\n");
  56. printf
  57. ("********************************************************************************\n");
  58. for (test_gid = 0; test_gid < 100; test_gid++) {
  59. fprintf(stdout, "-> getgrgid(%d)...\n", test_gid);
  60. group = getgrgid((gid_t) test_gid);
  61. if (group != NULL) {
  62. printf("gr_name\t: %s\n", group->gr_name);
  63. printf("gr_passwd\t: %s\n", group->gr_passwd);
  64. printf("gr_gid\t: %d\n", (int) group->gr_gid);
  65. printf("gr_mem\t\t: ");
  66. fflush(stdout);
  67. tmp_mem = group->gr_mem;
  68. while (*tmp_mem != NULL) {
  69. printf("%s, ", *tmp_mem);
  70. tmp_mem++;
  71. }
  72. }
  73. printf
  74. ("\n********************************************************************************\n");
  75. }
  76. fprintf(stdout, "-> getgrnam()...\n");
  77. group = getgrnam("root");
  78. if (group == NULL) {
  79. printf(">NULL<\n");
  80. } else {
  81. printf("gr_name\t: %s\n", group->gr_name);
  82. printf("gr_passwd\t: %s\n", group->gr_passwd);
  83. printf("gr_gid\t: %d\n", (int) group->gr_gid);
  84. printf("gr_mem\t\t: ");
  85. fflush(stdout);
  86. tmp_mem = group->gr_mem;
  87. while (*tmp_mem != NULL) {
  88. printf("%s, ", *tmp_mem);
  89. tmp_mem++;
  90. }
  91. printf("\n");
  92. }
  93. return 0;
  94. }