Qsmtp  0.37
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/socket.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
 
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

◆ conn_cleanup()

void conn_cleanup ( const int  rc)

clean up the allocated data and exit the process

Parameters
rcdesired return code of the process

◆ connsetup()

static int connsetup ( void  )
static

initialize variables related to this connection

◆ dieerror()

void dieerror ( int  error)

log error message and terminate program

Parameters
errorerror code that caused the program termination

◆ err_control()

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

◆ 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

◆ fork_clean()

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.

◆ line_valid()

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

◆ authhide

int authhide

hide source of authenticated mail

◆ commands

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)
}

◆ comstate

unsigned long comstate = 0x001

status of the command state machine, initialized to noop

◆ current_command

struct smtpcomm* current_command

the SMTP command currently processed

◆ databytes

unsigned long databytes

maximum message size

◆ globalconf

const char** globalconf

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

◆ goodrcpt

unsigned int goodrcpt

number of valid recipients

◆ heloname

string heloname

the fqdn to show in helo

◆ liphost

string liphost

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

◆ msgidhost

string msgidhost

the fqdn to use if a message-id is added

◆ rcptcount

unsigned int rcptcount

number of recipients in lists including rejected

◆ rcpthosts

char* rcpthosts

memory mapping of control/rcpthosts

◆ rcpthsize

off_t rcpthsize

sizeof("control/rcpthosts")

◆ relayclient

int relayclient

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

◆ socketd

int socketd = 1

the descriptor where messages to network are written to

◆ sslauth

unsigned long sslauth

if SMTP AUTH is only allowed after STARTTLS

◆ submission_mode

int submission_mode

if we should act as message submission agent

◆ xmitstat

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

http_post
int http_post(void)
Definition: commands.c:852
smtp_auth
int smtp_auth(void)
Definition: auth.c:375
smtp_data
int smtp_data(void)
Definition: data.c:279
smtp_starttls
int smtp_starttls(void)
Definition: starttls.c:381