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