d9898ee8 |
1 | /* |
2 | ** Copyright 2003 Double Precision, Inc. See COPYING for |
3 | ** distribution information. |
4 | */ |
5 | |
6 | #include "auth.h" |
b0322a85 |
7 | #include "courierauthstaticlist.h" |
d9898ee8 |
8 | #include "courierauthsasl.h" |
9 | #include "courierauth.h" |
10 | #include <stdio.h> |
11 | #include <stdlib.h> |
12 | #include <string.h> |
13 | #include <errno.h> |
14 | #if HAVE_UNISTD_H |
15 | #include <unistd.h> |
16 | #endif |
17 | #include "numlib/numlib.h" |
18 | |
d9898ee8 |
19 | |
20 | static int with_options = 0; |
21 | static int shared_only = 0; |
22 | |
23 | static void enum_cb(const char *name, |
24 | uid_t uid, |
25 | gid_t gid, |
26 | const char *homedir, |
27 | const char *maildir, |
28 | const char *options, |
29 | void *void_arg) |
30 | { |
31 | char buf1[NUMBUFSIZE]; |
32 | char buf2[NUMBUFSIZE]; |
33 | |
34 | if (name == NULL) |
35 | { |
36 | *(int *)void_arg=0; |
37 | return; |
38 | } |
39 | |
40 | if (shared_only) |
41 | { |
42 | char *opt = auth_getoption(options, "disableshared"); |
43 | if (opt) |
44 | { |
45 | int disable = atoi(opt); |
46 | free(opt); |
47 | if (disable) |
48 | return; |
49 | } |
50 | } |
51 | |
52 | printf("%s\t%s\t\%s\t%s", name, |
53 | libmail_str_uid_t(uid, buf1), |
54 | libmail_str_gid_t(gid, buf2), |
55 | homedir); |
56 | printf("\t%s", maildir ? maildir : ""); |
57 | if (with_options) |
58 | printf("\t%s", options ? options : ""); |
59 | printf("\n"); |
60 | } |
61 | |
62 | int main(int argc, char **argv) |
63 | { |
64 | int exit_code; |
65 | |
66 | while (argc > 1) |
67 | { |
68 | if (!strcmp(argv[1], "-s")) |
69 | shared_only = 1; |
70 | else if (!strcmp(argv[1], "-o")) |
71 | with_options = 1; |
72 | else |
73 | { |
74 | fprintf(stderr, "Usage: authenumerate [-s] [-o]\n"); |
75 | exit(1); |
76 | } |
77 | argv++; |
78 | argc--; |
79 | } |
80 | |
81 | exit_code=1; |
82 | |
83 | auth_enumerate(enum_cb, &exit_code); |
84 | exit(exit_code); |
85 | return (0); |
86 | } |