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