summaryrefslogtreecommitdiff
path: root/testsuite/nsswitch/getpwuid.c
blob: 3f364df29d51091a60e33baa84d01ebda908bd4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Lookup a user by uid.
 */

#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>

int main(int argc, char **argv)
{
    struct passwd *pw;
    uid_t uid;

    /* Check args */

    if (argc != 2) {
        printf("ERROR: no arg specified\n");
        exit(1);
    }

    if ((uid = atoi(argv[1])) == 0) {
        printf("ERROR: invalid uid specified\n");
        exit(1);
    }

    /* Do getpwuid() */

    if ((pw = getpwuid(uid)) == NULL) {
        printf("FAIL: uid %d does not exist\n", uid);
        exit(1);
    }
    
    printf("PASS: uid %d exists\n", uid);
    printf("pw_name = %s\n", pw->pw_name);
    printf("pw_passwd = %s\n", pw->pw_passwd);
    printf("pw_uid = %d\n", pw->pw_uid);
    printf("pw_gid = %d\n", pw->pw_gid);
    printf("pw_gecos = %s\n", pw->pw_gecos);
    printf("pw_dir = %s\n", pw->pw_dir);
    printf("pw_shell = %s\n", pw->pw_shell);

    exit(0);
}