diff --git a/src/imap.c b/src/imap.c index 37900d4..ee44afd 100644 --- a/src/imap.c +++ b/src/imap.c @@ -42,15 +42,15 @@ int imap_auth(struct tlsport *p, struct ejabber_msg *m) int len = 0, mlen = 0; /* sanity check */ - if(!m || !m->user) return -1; - if(!m->domain || !m->password) return -1; - if(!p || !p->ssl) return -1; + if(!m || !m->user) return 0; + if(!m->domain || !m->password) return 0; + if(!p || !p->ssl) return 0; /* read welcome message */ memset(buf, '\0', IMAPLINE_LENGTH); len = tls_io(p, buf, IMAPLINE_LENGTH - sizeof(char), TLSIO_READ); - if(len < 5) return -1; - else if(strncmp(buf, "* OK", 4)) return -1; + if(len < 5) return 0; + else if(strncmp(buf, "* OK", 4)) return 0; /* check the leftovers in TLS channel */ if(len == IMAPLINE_LENGTH - sizeof(char)) { do { @@ -62,19 +62,19 @@ int imap_auth(struct tlsport *p, struct ejabber_msg *m) /* try to login with provided credentials */ mlen = strlen(m->user) + strlen(m->domain) + strlen(m->password); mlen += 16; /* "a login 11 22" */ - if(mlen > IMAPLINE_LENGTH - sizeof(char)) return -1; /* too long */ + if(mlen > IMAPLINE_LENGTH - sizeof(char)) return 0; /* too long */ /* create a message */ snprintf(buf, mlen, "a login \"%s@%s\" \"%s\"\n", m->user, m->domain, m->password); len = tls_io(p, buf, mlen - sizeof(char), TLSIO_WRITE); - if(len < 0) return -1; + if(len < 0) return 0; else memset(buf, '\0', mlen); /* read */ len = tls_io(p, buf, IMAPLINE_LENGTH - sizeof(char), TLSIO_READ); - if(len < 5) return -1; + if(len < 5) return 0; - if(strncmp(buf, "a OK", 4)) return -1; + if(strncmp(buf, "a OK", 4)) return 0; /* check for leftovers */ if(len == IMAPLINE_LENGTH - sizeof(char)) { @@ -88,5 +88,5 @@ int imap_auth(struct tlsport *p, struct ejabber_msg *m) snprintf(buf, IMAPLINE_LENGTH - sizeof(char), "a logout"); len = tls_io(p, buf, 9, TLSIO_WRITE); - return 0; + return 1; } diff --git a/src/smtp.c b/src/smtp.c index 33ef9f4..23f946a 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -42,62 +42,63 @@ int smtp_checkuser(struct tlsport *p, struct ejabber_msg *m, const char *host) int len, mlen, r; /* sanity check */ - if(!m || !m->user) return -1; - if(!m->domain || !m->password) return -1; - if(!p || !p->ssl) return -1; - if(!host) return -1; + if(!m || !m->user) return 0; + if(!m->domain || !m->password) return 0; + if(!p || !p->ssl) return 0; + if(!host) return 0; /* clear stack buffers */ - len = mlen = r = 0; + len = mlen = 0; memset(buf, 0, SMTPLINE_LENGTH); + r = 1; /* 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; + if(len < 3) return 0; + else if(strncmp(buf, "220", 3)) return 0; memset(buf, 0, len + sizeof(char)); /* start with hello */ mlen = strlen(host) + sizeof(char)*6; - if(mlen > SMTPLINE_LENGTH - sizeof(char)) return -1; /* too long message */ + if(mlen > SMTPLINE_LENGTH - sizeof(char)) return 0; /* too long message */ snprintf(buf, mlen + sizeof(char), "HELO %s\n", host); len = tls_io(p, buf, mlen, TLSIO_WRITE); - if(len < 0) return -1; + if(len < 0) return 0; else memset(buf, 0, mlen); /* check the reply if any */ len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ); - if(len < 4) return -1; - else if(strncmp(buf, "250 ", 4)) return -1; + if(len < 4) return 0; + else if(strncmp(buf, "250 ", 4)) return 0; memset(buf, 0, len + sizeof(char)); /* set mail from */ 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 0; /* too long message */ snprintf(buf, mlen + sizeof(char), "mail from:<%s@%s>\n", m->user, m->domain); len = tls_io(p, buf, mlen, TLSIO_WRITE); - if(len < 0) return -1; + if(len < 0) return 0; else memset(buf, 0, mlen); /* check the reply if any */ len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ); - if(len < 4) return -1; - else if(strncmp(buf, "250 ", 4)) return -1; + if(len < 4) return 0; + else if(strncmp(buf, "250 ", 4)) return 0; memset(buf, 0, len + sizeof(char)); /* set recepient, if it's ok - user exists, if it's not - no such user */ 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 0; /* too long message */ snprintf(buf, mlen + sizeof(char), "rcpt to:<%s@%s>\n", m->user, m->domain); len = tls_io(p, buf, mlen, TLSIO_WRITE); - if(len < 0) return -1; + if(len < 0) return 0; else memset(buf, 0, mlen); /* check the reply if any */ len = tls_io(p, buf, SMTPLINE_LENGTH - sizeof(char), TLSIO_READ); - if(len < 4) return -1; - else if(strncmp(buf, "250 ", 4)) r = -1; + if(len < 4) return 0; + else if(strncmp(buf, "250 ", 4)) r = 0; /* gracefully end smtp session */ mlen = strlen("quit\n");