OSDN Git Service

fix license notice
[uclinux-h8/uclibc-ng.git] / test / pwd_grp / test_pwd.c
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
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <pwd.h>
12
13 int main(int argc, char **argv)
14 {
15         struct passwd *passwd;
16         int test_uid;
17
18         fprintf(stdout, "Beginning test of libc/pwd...\n");
19
20         fprintf(stdout, "=> Testing setpwent(), getpwent(), endpwent()...\n");
21         fprintf(stdout, "-> setpwent()...\n");
22         setpwent();
23         fprintf(stdout, "-> getpwent()...\n");
24         printf
25                 ("********************************************************************************\n");
26         while ((passwd = getpwent()) != NULL) {
27                 printf("pw_name\t\t: %s\n", passwd->pw_name);
28                 printf("pw_passwd\t: %s\n", passwd->pw_passwd);
29                 printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
30                 printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
31                 printf("pw_gecos\t: %s\n", passwd->pw_gecos);
32                 printf("pw_dir\t\t: %s\n", passwd->pw_dir);
33                 printf("pw_shell\t: %s\n", passwd->pw_shell);
34                 printf
35                         ("********************************************************************************\n");
36         }
37         fprintf(stdout, "-> endpwent()...\n");
38         endpwent();
39         fprintf(stdout,
40                         "=> Test of setpwent(), getpwent(), endpwent() complete.\n");
41         fprintf(stdout, "=> Testing getpwuid(), getpwnam()...\n");
42         fprintf(stdout, "-> getpwuid()...\n");
43         printf
44                 ("********************************************************************************\n");
45         for (test_uid = 0; test_uid < 1000; test_uid++) {
46                 fprintf(stdout, "-> getpwuid(%d)...\n", test_uid);
47                 passwd = getpwuid((uid_t) test_uid);
48                 if (passwd != NULL) {
49                         printf("pw_name\t\t: %s\n", passwd->pw_name);
50                         printf("pw_passwd\t: %s\n", passwd->pw_passwd);
51                         printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
52                         printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
53                         printf("pw_gecos\t: %s\n", passwd->pw_gecos);
54                         printf("pw_dir\t\t: %s\n", passwd->pw_dir);
55                         printf("pw_shell\t: %s\n", passwd->pw_shell);
56                         printf
57                                 ("********************************************************************************\n");
58                 }
59         }
60         fprintf(stdout, "-> getpwnam()...\n");
61         passwd = getpwnam("root");
62         if (passwd == NULL) {
63                 printf(">NULL<\n");
64         } else {
65                 printf("pw_name\t\t: %s\n", passwd->pw_name);
66                 printf("pw_passwd\t: %s\n", passwd->pw_passwd);
67                 printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
68                 printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
69                 printf("pw_gecos\t: %s\n", passwd->pw_gecos);
70                 printf("pw_dir\t\t: %s\n", passwd->pw_dir);
71                 printf("pw_shell\t: %s\n", passwd->pw_shell);
72         }
73         return 0;
74 }