hostname.1: Fix markup
[dragonfly.git] / test / caps / decoder.c
blob8ecb34d95466340ded5d1bf468d435bbc83d8c8d
1 /*
2 * DECODER.C
4 * Decode CAPS encoded buffers, one per line, into a struct passwd and
5 * report the results.
7 * $DragonFly: src/test/caps/decoder.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 int error;
21 int len;
22 char buf[1024];
23 struct passwd pw;
25 while (fgets(buf, sizeof(buf), stdin) != NULL) {
26 len = strlen(buf);
27 bzero(&pw, sizeof(pw));
28 n = caps_decode(buf, len, &pw, &caps_passwd_struct, &error);
29 printf("decode %d bytes error %d\n", n, error);
30 if (error) {
31 if (n > len)
32 n = len;
33 if (n && buf[n] == '\n') /* don't highlight a 'newline' */
34 --n;
35 printf("%*.*s", n, n, buf);
36 printf("\033[7m%c\033[m", buf[n]);
37 n = len - n - 1;
38 if (n > 0)
39 printf("%*.*s", n, n, buf + len - n);
40 } else {
41 printf("{\n");
42 printf(" pw_name = \"%s\"\n", pw.pw_name);
43 printf(" pw_passwd = \"%s\"\n", pw.pw_passwd);
44 printf(" pw_uid = %d\n", pw.pw_uid);
45 printf(" pw_gid = %d\n", pw.pw_gid);
46 printf(" pw_change = %08llx\n", (long long)pw.pw_change);
47 printf(" pw_class = \"%s\"\n", pw.pw_class);
48 printf(" pw_gecos = \"%s\"\n", pw.pw_gecos);
49 printf(" pw_dir = \"%s\"\n", pw.pw_dir);
50 printf(" pw_shell = \"%s\"\n", pw.pw_shell);
51 printf(" pw_expire = %08llx\n", (long long)pw.pw_expire);
52 printf("}\n");
54 caps_struct_free_pointers(&pw, &caps_passwd_struct);
56 return(0);