smtp fix;

master
Alexander Vdolainen 4 years ago
parent 26d8dd7e5e
commit 1aff05ea29

@ -51,45 +51,57 @@ int smtp_checkuser(struct tlsport *p, struct ejabber_msg *m, const char *host)
len = mlen = r = 0; len = mlen = r = 0;
memset(buf, 0, SMTPLINE_LENGTH); memset(buf, 0, SMTPLINE_LENGTH);
/* read greetings, shall be 220 for error code */
len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ);
if(len < 3) return -1;
else if(strncmp(buf, "220", 3)) return -1;
memset(buf, 0, len + sizeof(char));
/* start with hello */ /* start with hello */
mlen = strlen(host) + sizeof(char)*5; mlen = strlen(host) + sizeof(char)*6;
if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */ if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */
snprintf(buf, mlen + sizeof(char), "HELO %s", host); snprintf(buf, mlen + sizeof(char), "HELO %s\n", host);
len = tls_io(p, buf, mlen, TLSIO_WRITE); len = tls_io(p, buf, mlen, TLSIO_WRITE);
if(len < 0) return -1; if(len < 0) return -1;
else memset(buf, 0, mlen); else memset(buf, 0, mlen);
/* check the reply if any */ /* check the reply if any */
len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ); len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ);
if(len < 4) return -1; if(len < 4) return -1;
else if(strncmp(buf, "250 ", 4)) return -1; else if(strncmp(buf, "250 ", 4)) return -1;
memset(buf, 0, len + sizeof(char));
/* set mail from */ /* set mail from */
mlen = strlen(m->user) + strlen(m->domain) + 15*sizeof(char); mlen = strlen(m->user) + strlen(m->domain) + 14*sizeof(char);
if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */ if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */
snprintf(buf, mlen + sizeof(char), "mail from:<%s@%s>", m->user, m->domain); snprintf(buf, mlen + sizeof(char), "mail from:<%s@%s>\n", m->user, m->domain);
len = tls_io(p, buf, mlen, TLSIO_WRITE); len = tls_io(p, buf, mlen, TLSIO_WRITE);
if(len < 0) return -1; if(len < 0) return -1;
else memset(buf, 0, mlen); else memset(buf, 0, mlen);
/* check the reply if any */ /* check the reply if any */
len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ); len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ);
if(len < 4) return -1; if(len < 4) return -1;
else if(strncmp(buf, "250 ", 4)) return -1; else if(strncmp(buf, "250 ", 4)) return -1;
memset(buf, 0, len + sizeof(char));
/* set recepient, if it's ok - user exists, if it's not - no such user */ /* set recepient, if it's ok - user exists, if it's not - no such user */
mlen = strlen(m->user) + strlen(m->domain) + 11*sizeof(char); mlen = strlen(m->user) + strlen(m->domain) + 12*sizeof(char);
if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */ if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */
snprintf(buf, mlen + sizeof(char), "rcpt to:<%s@%s>", m->user, m->domain); snprintf(buf, mlen + sizeof(char), "rcpt to:<%s@%s>\n", m->user, m->domain);
len = tls_io(p, buf, mlen, TLSIO_WRITE); len = tls_io(p, buf, mlen, TLSIO_WRITE);
if(len < 0) return -1; if(len < 0) return -1;
else memset(buf, 0, mlen); else memset(buf, 0, mlen);
/* check the reply if any */ /* check the reply if any */
len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ); len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ);
if(len < 4) return -1; if(len < 4) return -1;
else if(strncmp(buf, "250 ", 4)) r = -1; else if(strncmp(buf, "250 ", 4)) r = -1;
/* gracefully end smtp session */ /* gracefully end smtp session */
mlen = strlen("quit"); mlen = strlen("quit\n");
snprintf(buf, mlen + sizeof(char), "quit"); snprintf(buf, mlen + sizeof(char), "quit\n");
tls_io(p, buf, mlen, TLSIO_WRITE); tls_io(p, buf, mlen, TLSIO_WRITE);
return r; return r;

Loading…
Cancel
Save