1 /*
2 ** Copyright 1998 - 2004 Double Precision, Inc. See COPYING for
3 ** distribution information.
4 */
5
6 #include "auth.h"
7 #include "courierauthstaticlist.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
usage()22 static void usage()
23 {
24 fprintf(stderr, "Usage: authtest [-s service] userid [ password [ newpassword ] ]\n");
25 exit(1);
26 }
27
callback_pre(struct authinfo * a,void * dummy)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
main(int argc,char ** argv)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 setenv("TCPREMOTEIP", "::1", 0);
101
102 if (argc - argn >= 2)
103 {
104 if (auth_login_meta(NULL, service, argv[argn],
105 argv[argn+1],
106 callback_pre,
107 NULL))
108 {
109 perror("Authentication FAILED");
110 exit(1);
111 }
112 }
113 else if (argc - argn >= 1)
114 {
115 if (auth_getuserinfo_meta(NULL, service, argv[argn],
116 callback_pre,
117 NULL))
118 {
119 perror("Authentication FAILED");
120 exit(1);
121 }
122 }
123 exit(0);
124 }
125