source: branches/samba-3.0/testsuite/nsswitch/getpwuid.c@ 165

Last change on this file since 165 was 1, checked in by Paul Smedley, 18 years ago

Initial code import

File size: 898 bytes
Line 
1/*
2 * Lookup a user by uid.
3 */
4
5#include <stdio.h>
6#include <pwd.h>
7#include <sys/types.h>
8
9int main(int argc, char **argv)
10{
11 struct passwd *pw;
12 uid_t uid;
13
14 /* Check args */
15
16 if (argc != 2) {
17 printf("ERROR: no arg specified\n");
18 exit(1);
19 }
20
21 if ((uid = atoi(argv[1])) == 0) {
22 printf("ERROR: invalid uid specified\n");
23 exit(1);
24 }
25
26 /* Do getpwuid() */
27
28 if ((pw = getpwuid(uid)) == NULL) {
29 printf("FAIL: uid %d does not exist\n", uid);
30 exit(1);
31 }
32
33 printf("PASS: uid %d exists\n", uid);
34 printf("pw_name = %s\n", pw->pw_name);
35 printf("pw_passwd = %s\n", pw->pw_passwd);
36 printf("pw_uid = %d\n", pw->pw_uid);
37 printf("pw_gid = %d\n", pw->pw_gid);
38 printf("pw_gecos = %s\n", pw->pw_gecos);
39 printf("pw_dir = %s\n", pw->pw_dir);
40 printf("pw_shell = %s\n", pw->pw_shell);
41
42 exit(0);
43}
Note: See TracBrowser for help on using the repository browser.