]> code.citadel.org Git - citadel.git/commitdiff
* Implemented the AUTHENTICATE LOGIN command in IMAP
authorArt Cancro <ajc@citadel.org>
Wed, 25 Oct 2000 21:37:10 +0000 (21:37 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 25 Oct 2000 21:37:10 +0000 (21:37 +0000)
citadel/ChangeLog
citadel/serv_imap.c
citadel/serv_imap.h

index 900d092d7cdcb9625c1ec4d5426c70d8447d6144..b717d5ec1f69064597bc7c8fca521851c1c68136 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 573.17  2000/10/25 21:37:09  ajc
+ * Implemented the AUTHENTICATE LOGIN command in IMAP
+
  Revision 573.16  2000/10/25 19:20:37  ajc
  * FETCH now works for ranges *and* sets, and with sequence numbers *and* UID's
 
@@ -2106,3 +2109,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 4a3bc9f7cdd00f727d62133dce37290c7122d3d0..de733270e2641c4273c170eab4cce4ac0467ee39 100644 (file)
@@ -136,6 +136,7 @@ void imap_greeting(void) {
        strcpy(CC->cs_clientname, "IMAP session");
        CC->internal_pgm = 1;
        CtdlAllocUserData(SYM_IMAP, sizeof(struct citimap));
+       IMAP->authstate = imap_as_normal;
 
        cprintf("* OK %s Citadel/UX IMAP4rev1 server ready\r\n",
                config.c_fqdn);
@@ -157,6 +158,58 @@ void imap_login(int num_parms, char *parms[]) {
 }
 
 
+/*
+ * Implements the AYTHENTICATE command
+ */
+void imap_authenticate(int num_parms, char *parms[]) {
+       char buf[256];
+
+       if (num_parms != 3) {
+               cprintf("%s BAD incorrect number of parameters\r\n", parms[0]);
+               return;
+       }
+
+       if (!strcasecmp(parms[2], "LOGIN")) {
+               encode_base64(buf, "Username:");
+               cprintf("+ %s\r\n", buf);
+               IMAP->authstate = imap_as_expecting_username;
+               strcpy(IMAP->authseq, parms[0]);
+               return;
+       }
+
+       else {
+               cprintf("%s NO AUTHENTICATE %s failed\r\n",
+                       parms[0], parms[1]);
+       }
+}
+
+void imap_auth_login_user(char *cmd) {
+       char buf[256];
+
+       decode_base64(buf, cmd);
+       CtdlLoginExistingUser(buf);
+       encode_base64(buf, "Password:");
+       cprintf("+ %s\r\n", buf);
+       IMAP->authstate = imap_as_expecting_password;
+       return;
+}
+
+void imap_auth_login_pass(char *cmd) {
+       char buf[256];
+
+       decode_base64(buf, cmd);
+       if (CtdlTryPassword(buf) == pass_ok) {
+               cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
+       }
+       else {
+               cprintf("%s NO authentication failed\r\n", IMAP->authseq);
+       }
+       IMAP->authstate = imap_as_normal;
+       return;
+}
+
+
+
 /*
  * implements the CAPABILITY command
  */
@@ -337,6 +390,19 @@ void imap_command_loop(void) {
        if (cmdbuf[strlen(cmdbuf)-1]=='\r') cmdbuf[strlen(cmdbuf)-1]=0;
        striplt(cmdbuf);
 
+       /* If we're in the middle of a multi-line command, handle that */
+       if (IMAP->authstate == imap_as_expecting_username) {
+               imap_auth_login_user(cmdbuf);
+               return;
+       }
+       if (IMAP->authstate == imap_as_expecting_password) {
+               imap_auth_login_pass(cmdbuf);
+               return;
+       }
+
+
+       /* Ok, at this point we're in normal command mode */
+
        /* grab the tag */
        num_parms = imap_parameterize(parms, cmdbuf);
        for (i=0; i<num_parms; ++i) {
@@ -362,6 +428,10 @@ void imap_command_loop(void) {
                imap_login(num_parms, parms);
        }
 
+       else if (!strcasecmp(parms[1], "AUTHENTICATE")) {
+               imap_authenticate(num_parms, parms);
+       }
+
        else if (!strcasecmp(parms[1], "CAPABILITY")) {
                imap_capability(num_parms, parms);
        }
index 930fe24e732f1cdf33d759693c23722923875f01..217b62f6f9ccd05a522071d7e6d918f249b7465d 100644 (file)
@@ -10,6 +10,8 @@ void imap_command_loop(void);
 
 
 struct citimap {
+       int authstate;
+       char authseq[256];
        int selected;           /* set to 1 if in the SELECTED state */
        int readonly;           /* mailbox is open read only */
        int num_msgs;           /* Number of messages being mapped */
@@ -17,6 +19,15 @@ struct citimap {
        unsigned int *flags;
 };
 
+/*
+ * values of 'authstate'
+ */
+enum {
+       imap_as_normal,
+       imap_as_expecting_username,
+       imap_as_expecting_password
+};
+
 /* Flags for the above struct.  Note that some of these are for internal use,
  * and are not to be reported to IMAP clients.
  */