3 SASL PLAIN Support
. Patch submitted upstream
4 http
://sourceforge.net/tracker/?func=detail&aid=3610674&group_id=311&atid=300311
6 --- src
/imapcommon
.c
.orig
2010-02-20 18:16:58.000000000 +0100
7 +++ src
/imapcommon
.c
2013-04-15 12:12:45.000000000 +0200
10 #endif /* HAVE_LIBSSL */
14 + * If configured to do so, use SASL PLAIN instead of IMAP LOGIN
16 + if ( PC_Struct
.auth_sasl_mech
&&
17 + !strcmp( PC_Struct
.auth_sasl_mech
, "plain" ) )
20 + * Build SASL AUTH PLAIN string:
21 + * username\0username\0password
24 + unsigned int username_size
;
26 + unsigned int password_size
;
27 + unsigned int total_size
;
28 + unsigned int AuthBufIndex
;
29 + char AuthBuf
[BUFSIZE
];
30 + char EncodedAuthBuf
[BUFSIZE
];
33 + * Strip quotes From username
35 + ptr_username
= Username
;
36 + username_size
= strlen( Username
);
37 + if ( *ptr_username
== '"' && *(ptr_username
+ username_size
- 1) == '"' )
40 + username_size
= username_size
- 2;
44 + * Same with password
46 + ptr_password
= Password
;
47 + password_size
= strlen( Password
);
48 + if ( *ptr_password
== '"' && *(ptr_password
+ password_size
- 1) == '"' )
51 + password_size
= password_size
- 2;
55 + * Make sure output buffer is big enough ( +3 for three \0 )
57 + total_size
= username_size
+ username_size
+ password_size
+ 3;
58 + if ( total_size
> sizeof(AuthBuf
) ) {
60 + "LOGIN: '%s' (%s:%s) failed: PLAIN AUTH needs %d/%d bytes",
61 + Username
, ClientAddr
, portstr
, total_size
, sizeof(AuthBuf
));
66 + * Prepare the buffer
70 + memcpy( AuthBuf
+ AuthBufIndex
, ptr_username
, username_size
);
71 + AuthBufIndex
+= username_size
;
72 + AuthBuf
[AuthBufIndex
++] = '\0';
74 + memcpy( AuthBuf
+ AuthBufIndex
, ptr_username
, username_size
);
75 + AuthBufIndex
+= username_size
;
76 + AuthBuf
[AuthBufIndex
++] = '\0';
78 + memcpy( AuthBuf
+ AuthBufIndex
, ptr_password
, password_size
);
79 + AuthBufIndex
+= password_size
;
80 + AuthBuf
[AuthBufIndex
++] = '\0';
82 + EVP_EncodeBlock( EncodedAuthBuf
, AuthBuf
, AuthBufIndex
);
84 + snprintf( SendBuf
, BufLen
, "A0001 AUTHENTICATE PLAIN %s\r\n", EncodedAuthBuf
);
86 + /* syslog( LOG_INFO, "sending auth plain '%s'", EncodedAuthBuf ); */
88 + if ( IMAP_Write( Server
.conn
, SendBuf
, strlen(SendBuf
) ) == -1 )
91 + "LOGIN: '%s' (%s:%s) failed: IMAP_Write() failed attempting to send AUTHENTICATE command to IMAP server: %s",
92 + Username
, ClientAddr
, portstr
, strerror( errno
) );
97 * Send the login command off to the IMAP server. Have to treat a literal
100 - if ( LiteralPasswd
)
101 + else if ( LiteralPasswd
)
103 snprintf( SendBuf
, BufLen
, "A0001 LOGIN %s {%d}\r\n",
104 Username
, strlen( Password
) );
105 if ( IMAP_Write( Server
.conn
, SendBuf
, strlen(SendBuf
) ) == -1 )