- GALILEO -> MARVELL
[dragonfly.git] / test / caps / encoder.c
1 /*
2  * ENCODER.C
3  *
4  * CAPS-Encode the passwd structure for the specified usernames, generate
5  * to stdout.
6  *
7  * $DragonFly: src/test/caps/encoder.c,v 1.1 2004/03/07 23:36:45 dillon Exp $
8  */
9 #include <sys/types.h>
10 #include <libcaps/caps_struct.h>
11 #include <pwd.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14
15 int
16 main(int ac, char **av)
17 {
18     int i;
19     int n;
20     char buf[1024];
21
22     for (i = 1; i < ac; ++i) {
23         struct passwd *pw;
24
25         if ((pw = getpwnam(av[i])) == NULL) {
26             printf("%s: lookup failed\n");
27             continue;
28         }
29         n = caps_encode(buf, sizeof(buf), pw, &caps_passwd_struct);
30         if (n > sizeof(buf)) {
31             printf("buffer overflow during encoding\n");
32         } else {
33             buf[n] = 0;
34             printf("%s\n", buf);
35         }
36     }
37     return(0);
38 }
39