* The size constant "256" which shows up everywhere as a buffer size has now
[citadel.git] / citadel / serv_pas2.c
1 /*
2  * cmd_pas2 - MD5 APOP style auth keyed off of the hash of the password
3  *            plus a nonce displayed at the login banner.
4  */
5
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <time.h>
10 #include <ctype.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "sysdep_decls.h"
14 #include "citadel.h"
15 #include "server.h"
16 #include "citserver.h"
17 #include "support.h"
18 #include "dynloader.h"
19 #include "user_ops.h"
20 #include "md5.h"
21 #include "tools.h"
22
23
24 void cmd_pas2(char *argbuf)
25 {
26         char pw[SIZ];
27         char hexstring[MD5_HEXSTRING_SIZE];
28         
29
30         if (!strcmp(CC->curr_user, NLI))
31         {
32                 cprintf("%d You must enter a user with the USER command first.\n", ERROR);
33                 return;
34         }
35         
36         if (CC->logged_in)
37         {
38                 cprintf("%d Already logged in.\n", ERROR);
39                 return;
40         }
41         
42         extract(pw, argbuf, 0);
43         
44         if (getuser(&CC->usersupp, CC->curr_user))
45         {
46                 cprintf("%d Unable to find user record for %s.\n", ERROR, CC->curr_user);
47                 return;
48         }
49         
50         strproc(pw);
51         strproc(CC->usersupp.password);
52         
53         if (strlen(pw) != (MD5_HEXSTRING_SIZE-1))
54         {
55                 cprintf("%d Auth string of length %d is the wrong length (should be %d).\n", ERROR, strlen(pw), MD5_HEXSTRING_SIZE-1);
56                 return;
57         }
58         
59         make_apop_string(CC->usersupp.password, CC->cs_nonce, hexstring);
60         
61         if (!strcmp(hexstring, pw))
62         {
63                 do_login();
64                 return;
65         }
66         else
67         {
68                 cprintf("%d Wrong password.\n", ERROR);
69                 return;
70         }
71 }
72
73
74
75
76
77 char *Dynamic_Module_Init(void)
78 {
79         CtdlRegisterProtoHook(cmd_pas2, "PAS2", "APOP-based login");
80         return "$(RCSID)";
81 }