#include #include #include #include #include #include #define BUF_SIZE 1024 #define MAX_PARAMS 4 #define TRUE_RESULT 0x01 #define FALSE_RESULT 0x00 int pop3_check(char *user, char *domain, char *userpass ) { char buffer[2560]; char *port="pop3", hostname="mars.neolocation.net", *getstr , username[1000] ; // *username int i, hnp; i=hnp=0; /* connecting to host */ struct addrinfo hints, *res, *res0; int error; int s; const char *cause = NULL; memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(hostname, port, &hints, &res0); if (error) { errx(1, "%s", gai_strerror(error)); /*NOTREACHED*/ } s = -1; for (res = res0; res; res = res->ai_next) { s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s < 0) { cause = "socket"; continue; } if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { cause = "connect"; close(s); s = -1; continue; } break; /* okay we got one */ } if (s < 0) { err(1, "%s", cause); /*NOTREACHED*/ } freeaddrinfo(res0); /* end connecting to host */ fd_set fds; struct timeval timeout; timeout.tv_sec = 50; timeout.tv_usec = 0; memset(buffer, 0, sizeof(buffer)); FD_ZERO(&fds); FD_SET(s, &fds); select(FD_SETSIZE, &fds, NULL, NULL, &timeout); read(s,buffer,sizeof(buffer)); //read "OK" //printf("got response <- %s\n",buffer); memset(buffer, 0, sizeof(buffer)); FD_ZERO(&fds); FD_SET(s, &fds); select(FD_SETSIZE, NULL, &fds, NULL, &timeout); strcpy(buffer,"user "); strcpy(buffer+strlen(buffer),user); strcpy(buffer+strlen(buffer),"@"); strcpy(buffer+strlen(buffer),domain); strcpy(buffer+strlen(buffer),"\n"); //printf("say -> %s\n",buffer); syslog( LOG_ERR, "%s", buffer); write(s,buffer,strlen(buffer)); memset(buffer, 0, sizeof(buffer)); FD_ZERO(&fds); FD_SET(s, &fds); select(FD_SETSIZE, &fds, NULL, NULL, &timeout); read(s,buffer,sizeof(buffer)); //read "OK" //printf("got response <- %s\n",buffer); syslog( LOG_ERR, "%s", buffer); memset(buffer, 0, sizeof(buffer)); FD_ZERO(&fds); FD_SET(s, &fds); select(FD_SETSIZE, NULL, &fds, NULL, &timeout); strcpy(buffer,"pass "); strcpy(buffer+strlen(buffer),userpass); strcpy(buffer+strlen(buffer),"\n"); //printf("say -> %s\n",buffer); syslog( LOG_ERR, "%s", buffer); write(s,buffer,strlen(buffer)); memset(buffer, 0, sizeof(buffer)); FD_ZERO(&fds); FD_SET(s, &fds); select(FD_SETSIZE, &fds, NULL, NULL, &timeout); read(s,buffer,sizeof(buffer)); //read "OK" //printf("got response <- %s\n",buffer); syslog( LOG_ERR, "%s", buffer); if ( strstr(buffer,"+OK")!=NULL ) { return 1; //ok } else { return 0; //fail } } int main() { char buf[BUF_SIZE + 1]; // Allow for string termination char c; char* param[MAX_PARAMS]; param[0] = &buf[0]; // this won't change... short len; int i,j; int result; openlog( "ejabberd", LOG_NDELAY, LOG_AUTH ); syslog( LOG_INFO, "Starting ejabberd check_pop3" ); while( 1 ) { // read first two bytes from stdin // convert bytes to integer len i=0; while( i<2 ) { c = getchar(); if( c == EOF ) return 0; buf[i++] = c; } len = buf[0]*256 + buf[1]; if( len == 0 ) { syslog( LOG_WARNING, "Packet length is zero" ); // try again continue; } else if( len < 0 ) { syslog( LOG_ERR, "Negative packet length; exiting" ); return 1; } else if( len > BUF_SIZE ) { syslog( LOG_ERR, "Packet length of %d larger than buffer of size %d", len, BUF_SIZE ); return 1; } //syslog( LOG_DEBUG, "packet length %d", len ); // read packet of len bytes from stdin to buffer // note: packet is on the form [auth|setpass|isuser]::: // example: 36auth:christoffer:jabberwocky.se:test i=0; j=0; while( i