Qsmtp  0.30dev
Macros | Functions | Variables
qsmtpd.c File Reference

main part of Qsmtpd More...

#include <qsmtpd/qsmtpd.h>
#include <control.h>
#include <diropen.h>
#include <log.h>
#include <mmap.h>
#include <netio.h>
#include <qdns.h>
#include <qmaildir.h>
#include <qsmtpd/antispam.h>
#include <qsmtpd/commands.h>
#include <qsmtpd/qsauth.h>
#include <qsmtpd/qsdata.h>
#include <qsmtpd/starttls.h>
#include <qsmtpd/syntax.h>
#include <qsmtpd/userconf.h>
#include <sstring.h>
#include <tls.h>
#include <version.h>
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>

Macros

#define _C(c, m, f, s, o)   { .name = c, .len = sizeof(c) - 1, .mask = m, .func = f, .state = s, .flags = o }
 

Functions

int err_control (const char *fn)
 write and log error message if opening config file leads to an error More...
 
int err_control2 (const char *msg, const char *fn)
 write and log error message if opening config file leads to an error More...
 
void dieerror (int error)
 
static int setup (void)
 
static int connsetup (void)
 
void freedata (void)
 free all ressources allocated for mail transaction
 
pid_t fork_clean ()
 fork() but clean up internal structures More...
 
void conn_cleanup (const int rc)
 clean up the allocated data and exit the process More...
 
static int smtp_temperror (void)
 
static int line_valid ()
 
static void smtploop (void)
 
int main (int argc, char **argv)
 

Variables

struct smtpcommcurrent_command
 
static struct smtpcomm commands []
 
unsigned int rcptcount
 
int relayclient
 
char * rcpthosts
 
off_t rcpthsize
 
unsigned long sslauth
 
unsigned long databytes
 
unsigned int goodrcpt
 
int badbounce
 
struct xmitstat xmitstat
 
const char ** globalconf
 
string heloname
 
string msgidhost
 
string liphost
 
int socketd = 1
 
unsigned long comstate = 0x001
 
int authhide
 
int submission_mode
 
struct recipthisrecip
 
static int flagbogus
 

Detailed Description

main part of Qsmtpd

This file contains the main function and the basic commands of Qsmtpd SMTP server.

Function Documentation

void conn_cleanup ( const int  rc)

clean up the allocated data and exit the process

Parameters
rcdesired return code of the process
static int connsetup ( void  )
static

initialize variables related to this connection

void dieerror ( int  error)

log error message and terminate program

Parameters
errorerror code that caused the program termination
int err_control ( const char *  fn)

write and log error message if opening config file leads to an error

Parameters
fnname of the file that caused the error
See also
err_control2
int err_control2 ( const char *  msg,
const char *  fn 
)

write and log error message if opening config file leads to an error

Parameters
msgadditional message to log
fnname of the file that caused the error
See also
err_control
pid_t fork_clean ( )

fork() but clean up internal structures

This will work exactly like fork(). If it returns 0 (i.e. you are the child) it will also clean the memory mappings etc. of the Qsmtpd process that the child doesn't need.

static int line_valid ( )
static

line_valid - check if input line contains only syntactically correct characters

Returns
: 0 on success, else error code

Variable Documentation

int authhide

hide source of authenticated mail

int badbounce

bounce message with more than one recipient

struct smtpcomm commands[]
static
Initial value:
= {
_C("NOOP", 0xffff, smtp_noop, -1, 0),
_C("QUIT", 0xfffd, smtp_quit, 0, 0),
_C("RSET", 0xfffd, smtp_rset, 0x1, 0),
_C("HELO", 0xfffd, smtp_helo, 0, 5),
_C("EHLO", 0xfffd, smtp_ehlo, 0, 5),
_C("MAIL FROM:",0x0018, smtp_from, 0, 3),
_C("RCPT TO:", 0x0060, smtp_rcpt, 0, 1),
_C("DATA", 0x0040, smtp_data, 0x10, 0),
_C("STARTTLS", 0x0010, smtp_starttls, 0x1, 0),
_C("AUTH", 0x0010, smtp_auth, -1, 5),
_C("VRFY", 0xffff, smtp_vrfy, -1, 5),
_C("POST", 0xffff, http_post, -1, 1)
}
int smtp_auth(void)
Definition: auth.c:381
int smtp_starttls(void)
Definition: starttls.c:336
int http_post(void)
Definition: commands.c:844
int smtp_data(void)
Definition: data.c:233
unsigned long comstate = 0x001

status of the command state machine, initialized to noop

struct smtpcomm* current_command

the SMTP command currently processed

unsigned long databytes

maximum message size

const char** globalconf

contents of the global "filterconf" file (or NULL)

unsigned int goodrcpt

number of valid recipients

string heloname

the fqdn to show in helo

string liphost

replacement domain if TO address is <foo@[ip]>

string msgidhost

the fqdn to use if a message-id is added

unsigned int rcptcount

number of recipients in lists including rejected

char* rcpthosts

memory mapping of control/rcpthosts

off_t rcpthsize

sizeof("control/rcpthosts")

int relayclient

flag if this client is allowed to relay by IP: 0 unchecked, 1 allowed, 2 denied

int socketd = 1

the descriptor where messages to network are written to

unsigned long sslauth

if SMTP AUTH is only allowed after STARTTLS

int submission_mode

if we should act as message submission agent

This contains some flags describing the transmission and it's status.