"Fossies" - the Fresh Open Source Software Archive 
Member "nss_ldap-265/tests/testpw5.c" (6 Nov 2009, 2004 Bytes) of package /linux/privat/old/nss_ldap-265.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1
2 /* $Id: testpw5.c,v 1.2 2001/01/09 00:21:22 lukeh Exp $ */
3
4 /* This program just tests getpwent/getpwnam. You want to have nss_ldap
5 * plugged in, so to speak, to test anything useful.
6 */
7
8 #include "config.h"
9
10 #ifdef _REENTRANT
11 #ifdef HAVE_THREAD_H
12 #include <thread.h>
13 #else
14 #include <pthread.h>
15 #endif
16 #endif
17 #include <stdio.h>
18 #include <pwd.h>
19 #include <stdlib.h>
20
21 #if NeXT
22 #define uid_t int
23 #else
24 #include <dlfcn.h> /* why? */
25 #endif
26
27 void test_passwd (void);
28
29 int ARGC;
30 char **ARGV;
31
32 #define MAX_THREADS 16
33
34 void
35 main (int argc, char **argv)
36 {
37 #ifdef _REENTRANT
38 int i;
39 #endif
40 ARGC = argc;
41 ARGV = argv;
42
43 #ifdef _REENTRANT
44 for (i = 0; i < MAX_THREADS; i++)
45 {
46 thread_t tid;
47 thr_create (NULL, 0, test_passwd, NULL, 0, &tid);
48 thr_continue (tid);
49 }
50 while (thr_join (NULL, NULL, NULL) == 0);
51 #else
52 test_passwd ();
53 #endif
54 exit (0);
55 }
56
57 #ifdef _REENTRANT
58 static void
59 ret (int status)
60 {
61 thr_exit (&status);
62 }
63 #else
64 #define ret exit
65 #endif
66
67 void
68 test_passwd (void)
69 {
70 struct passwd *pw;
71 uid_t uid;
72 #ifdef _REENTRANT
73 char buf[1024];
74 struct passwd pbuf;
75 #endif
76
77
78
79 printf (">>>>>> setpwent()\n");
80 setpwent ();
81
82 printf (">>>>>> getpwent()\n");
83 scan_passwd ();
84
85 printf (">>>>>> endpwent()\n");
86 endpwent ();
87
88 ret (0);
89 }
90
91 scan_passwd ()
92 {
93 int i = 1;
94 struct passwd *p;
95 #ifdef _REENTRANT
96 char buf[1024];
97 struct passwd pbuf;
98 while ((p = getpwent_r (&pbuf, buf, sizeof (buf))) != NULL)
99 #else
100 while ((p = getpwent ()) != NULL)
101 #endif
102 {
103 printf ("%s:%s:%d:%d:%s:%s:%s\n",
104 p->pw_name,
105 p->pw_passwd,
106 p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
107
108 if (p == NULL)
109 ret (1);
110
111 #ifdef _REENTRANT
112 p = getpwnam_r (p->pw_name, &pbuf, buf, sizeof (buf));
113 #else
114 p = getpwnam (p->pw_name);
115 #endif
116
117 if (p == NULL)
118 ret (2);
119
120 printf ("%s:%s:%d:%d:%s:%s:%s\n",
121 p->pw_name,
122 p->pw_passwd,
123 p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
124
125 i++;
126 }
127 }