--- /dev/null
+CFLAGS=-g -Wall -I/usr/local/include
+
+SMTPSINK_OBJS=conn_pool.o conn_queue.o io.o smtp.o smtpsink.o
+
+default: smtpsink
+
+smtpsink: $(SMTPSINK_OBJS)
+ cc -o smtpsink $(SMTPSINK_OBJS) -L/usr/local/lib -levent -lpthread
+
+conn_pool.o: conn_pool.c smtpsink.h conn_queue.h smtpsink-int.h
+ cc $(CFLAGS) -c conn_pool.c
+
+conn_queue.o: conn_queue.c smtpsink.h conn_queue.h
+ cc $(CFLAGS) -c conn_queue.c
+
+io.o: io.c smtpsink.h conn_queue.h smtpsink-int.h
+ cc $(CFLAGS) -c io.c
+
+smtp.o: smtp.c smtpsink.h conn_queue.h smtpsink-int.h responses.inc
+ cc $(CFLAGS) -c smtp.c
+
+smtpsink.o: smtpsink.c smtpsink.h conn_queue.h smtpsink-int.h
+
+clean:
+ rm -f $(SMTPSINK_OBJS) smtpsink
* before all queues are initialized.
*/
if (pthread_mutex_lock(&lmtx)) assert(0);
- if (pthread_cond_wait(&lc)) assert(0);
+ if (pthread_cond_wait(&lc, &lmtx)) assert(0);
pthread_mutex_unlock(&lmtx);
while (1) {
c->peer = addr;
c->fd = fd;
io_initconn(c);
- respond(c, greeting);
+ greeting(c);
if (c->wdata.s) {
c->event = EV_WRITE;
} else {
smtp_queue.enqueue(&smtp_queue, c);
break;
case EV_TIMEOUT:
- respond(c, readtimeoutresp);
+ read_timeout(c);
if (c->wdata.s) {
c->state = SMTP_CLOSED;
event_add(&c->we, &timeout);
}
void
-conn_startio(struct conn *c)
+io_initconn(struct conn *c)
{
event_set(&c->re, c->fd, EV_READ, read_cb, (void *)c);
event_set(&c->re, c->fd, EV_WRITE, write_cb, (void *)c);
#include "responses.inc"
+int
+greeting(struct conn *c)
+{
+ return respond(c, banner, banner_hostname);
+}
+
+int
+read_timeout(struct conn *c)
+{
+ return respond(c, err_timeout);
+
+}
+
static int
smtpd_helo(struct conn *c, char *cmd, int len, int argoff)
{
const char *resp = helo_ok;
if (cmd[0] == 'e' || cmd[0] == 'E')
resp = ehlo_ok;
- }
/* if (c->state == SMTP_GREET) {
call-hook;
} */
len += nr;
}
else {
- if (nr == 0)
- close_conn(c);
- else if (respond(c, readerrresp))
- close_conn(c);
- else {
- c->event = EV_WRITE;
- io_queue.enqueue(&io_queue, c);
- }
+ close_conn(c);
return;
}
}
/* internal functions and interfaces */
-void conn_pool_init(int);
-void close_conn(struct conn *);
-void new_listener(char *);
-void start_listeners(void);
+extern void conn_pool_init(int);
+extern void close_conn(struct conn *);
+extern void new_listener(char *);
+extern void start_listeners(void);
-void io_init(void);
-void io_initconn(struct conn *);
+extern void io_init(void);
+extern void io_initconn(struct conn *);
-int conn_queue_init(struct conn_queue *, void (*)(struct conn *), int);
-int conn_queue_set_tpool_size(struct conn_queue *, int);
+extern int conn_queue_init(struct conn_queue *, void (*)(struct conn *), int);
+extern int conn_queue_set_tpool_size(struct conn_queue *, int);
-void smtp_init(int);
+extern void smtp_init(int);
+extern int greeting(struct conn *);
+extern int read_timeout(struct conn *);
extern struct conn_queue io_queue, smtp_queue;
extern char *banner_hostname;
-/* #include system header files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <syslog.h>
+#include <err.h>
+
+#include <sys/queue.h>
+#include <netinet/in.h>
+#include <event.h>
#include "smtpsink.h"
-#include "queues.h"
+#include "conn_queue.h"
+#include "smtpsink-int.h"
static void
-sig_exit(int fd, short event, void *arg)
+sigev_exit(int fd, short event, void *arg)
{
- exit 0;
+ exit(0);
}
int
-main(char **argv, int argc)
+main(int argc, char **argv)
{
/* defaults */
int concurrency = 10000;
- int defaultport = "0.0.0.0:25";
+ char *l_default = "0.0.0.0:25";
int daemonize = 1;
+ int pidfd = -1;
uid_t uid = 0;
gid_t gid = 0;
+
+ struct event sigint, sigterm;
struct group *gr;
struct passwd *pw;
- int tstart = 1, tmax = 1, tspare = 1;
+ int tstart = 1;
/* parse cmdline args */
write (pidfd, pid, strlen(pid));
}
- s_addr.sin_family=AF_INET;
- s_addr.sin_port=htons(listen_port);
- s_addr.sin_addr.s_addr = listen_ip;
-
- lsock = socket(PF_INET, SOCK_STREAM, 0);
- if (lsock < 0) err (1, "socket");
- setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-
- if (bind(lsock, (struct sockaddr *)&s_addr, sizeof s_addr) < 0)
- err (1, "bind");
-
- if (listen(lsock, -1) < 0) errx (1, "listen");
+ new_listener(l_default);
if (gid) {
if (setgid(gid) < 0) {
conn_pool_init(concurrency);
io_init();
- smtp_init(tstart, tmax, tspare);
+ smtp_init(tstart);
+ start_listeners();
/* modules_init(); */
event_dispatch();
}