d9898ee8 |
1 | /* |
2 | ** Copyright 1998 - 2004 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 "courierauthdebug.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 | |
18 | #include "debug.c" |
19 | /* libtool bork-age */ |
20 | |
d9898ee8 |
21 | |
22 | static void usage() |
23 | { |
24 | fprintf(stderr, "Usage: authtest [-s service] userid [ password [ newpassword ] ]\n"); |
25 | exit(1); |
26 | } |
27 | |
28 | static int callback_pre(struct authinfo *a, void *dummy) |
29 | { |
30 | #define PTR(x) ((x) ? (x):"(none)") |
31 | |
32 | printf("Authentication succeeded.\n\n"); |
33 | printf(" Authenticated: %s ", PTR(a->address)); |
34 | if (a->sysusername) |
35 | printf(" (system username: %s)\n", a->sysusername); |
36 | else if (a->sysuserid) |
37 | printf(" (uid %lu, gid %lu)\n", (unsigned long)*a->sysuserid, |
38 | (unsigned long)a->sysgroupid); |
39 | else printf(" (*** UID/GID initialization error***)\n"); |
40 | |
41 | printf(" Home Directory: %s\n", PTR(a->homedir)); |
42 | printf(" Maildir: %s\n", PTR(a->maildir)); |
43 | printf(" Quota: %s\n", PTR(a->quota)); |
44 | printf("Encrypted Password: %s\n", PTR(a->passwd)); |
45 | printf("Cleartext Password: %s\n", PTR(a->clearpasswd)); |
46 | printf(" Options: %s\n", PTR(a->options)); |
47 | #undef PTR |
48 | |
49 | return (0); |
50 | } |
51 | |
52 | int main(int argc, char **argv) |
53 | { |
54 | int argn; |
55 | const char *service="login"; |
56 | |
57 | for (argn=1; argn<argc; argn++) |
58 | { |
59 | const char *argp; |
60 | |
61 | if (argv[argn][0] != '-') break; |
62 | if (argv[argn][1] == 0) |
63 | { |
64 | ++argn; |
65 | break; |
66 | } |
67 | |
68 | argp=argv[argn]+2; |
69 | |
70 | switch (argv[argn][1]) { |
71 | case 's': |
72 | if (!*argp && argn+1 < argc) |
73 | argp=argv[++argn]; |
74 | service=argp; |
75 | break; |
76 | default: |
77 | usage(); |
78 | } |
79 | } |
80 | if (argc - argn <= 0) |
81 | usage(); |
82 | |
83 | courier_authdebug_login_level = 2; |
84 | |
85 | if (argc - argn >= 3) |
86 | { |
87 | if (auth_passwd(service, argv[argn], |
88 | argv[argn+1], |
89 | argv[argn+2])) |
90 | { |
91 | perror("Authentication FAILED"); |
92 | exit(1); |
93 | } |
94 | else |
95 | { |
96 | fprintf(stderr, "Password change succeeded.\n"); |
97 | exit(0); |
98 | } |
99 | } |
100 | if (argc - argn >= 2) |
101 | { |
102 | if (auth_login(service, argv[argn], |
103 | argv[argn+1], |
104 | callback_pre, |
105 | NULL)) |
106 | { |
107 | perror("Authentication FAILED"); |
108 | exit(1); |
109 | } |
110 | } |
111 | else if (argc - argn >= 1) |
112 | { |
113 | if (auth_getuserinfo(service, argv[argn], |
114 | callback_pre, |
115 | NULL)) |
116 | { |
117 | perror("Authentication FAILED"); |
118 | exit(1); |
119 | } |
120 | } |
121 | exit(0); |
122 | } |