Fix a NULL pointer dereference when a DDB 'ps' attempts to
[dragonfly.git] / test / caps / encoder.c
blobc22f22a553835a6c235addc7298799e448542be8
1 /*
2 * ENCODER.C
4 * CAPS-Encode the passwd structure for the specified usernames, generate
5 * to stdout.
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>
15 int
16 main(int ac, char **av)
18 int i;
19 int n;
20 char buf[1024];
22 for (i = 1; i < ac; ++i) {
23 struct passwd *pw;
25 if ((pw = getpwnam(av[i])) == NULL) {
26 printf("%s: lookup failed\n");
27 continue;
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);
37 return(0);