Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mail / imapproxy / patches / patch-src_imapcommon.c
blob1dd85a6f8b9247b07f65ef59c8071b59dccff9e4
1 $NetBSD$
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
8 @@ -689,13 +689,96 @@
10 #endif /* HAVE_LIBSSL */
13 + /*
14 + * If configured to do so, use SASL PLAIN instead of IMAP LOGIN
15 + */
16 + if ( PC_Struct.auth_sasl_mech &&
17 + !strcmp( PC_Struct.auth_sasl_mech, "plain" ) )
18 + {
19 + /*
20 + * Build SASL AUTH PLAIN string:
21 + * username\0username\0password
22 + */
23 + char *ptr_username;
24 + unsigned int username_size;
25 + char *ptr_password;
26 + unsigned int password_size;
27 + unsigned int total_size;
28 + unsigned int AuthBufIndex;
29 + char AuthBuf[BUFSIZE];
30 + char EncodedAuthBuf[BUFSIZE];
32 + /*
33 + * Strip quotes From username
34 + */
35 + ptr_username = Username;
36 + username_size = strlen( Username );
37 + if ( *ptr_username == '"' && *(ptr_username + username_size - 1) == '"' )
38 + {
39 + ++ptr_username;
40 + username_size = username_size - 2;
41 + }
43 + /*
44 + * Same with password
45 + */
46 + ptr_password = Password;
47 + password_size = strlen( Password );
48 + if ( *ptr_password == '"' && *(ptr_password + password_size - 1) == '"' )
49 + {
50 + ++ptr_password;
51 + password_size = password_size - 2;
52 + }
54 + /*
55 + * Make sure output buffer is big enough ( +3 for three \0 )
56 + */
57 + total_size = username_size + username_size + password_size + 3;
58 + if ( total_size > sizeof(AuthBuf) ) {
59 + syslog( LOG_INFO,
60 + "LOGIN: '%s' (%s:%s) failed: PLAIN AUTH needs %d/%d bytes",
61 + Username, ClientAddr, portstr, total_size, sizeof(AuthBuf));
62 + goto fail;
63 + }
65 + /*
66 + * Prepare the buffer
67 + */
68 + AuthBufIndex = 0;
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 )
89 + {
90 + syslog( LOG_INFO,
91 + "LOGIN: '%s' (%s:%s) failed: IMAP_Write() failed attempting to send AUTHENTICATE command to IMAP server: %s",
92 + Username, ClientAddr, portstr, strerror( errno ) );
93 + goto fail;
94 + }
95 + }
97 * Send the login command off to the IMAP server. Have to treat a literal
98 * password different.
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 )