Qsmtp  0.30dev
Functions | Variables
vpop.c File Reference

function to get domain directory of vpopmail virtual domain More...

#include <qsmtpd/vpop.h>
#include <cdb.h>
#include <control.h>
#include <diropen.h>
#include <qsmtpd/addrparse.h>
#include <qsmtpd/qsmtpd.h>
#include <qsmtpd/userconf.h>
#include <qsmtpd/userfilters.h>
#include <sstring.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

Functions

int vget_dir (const char *domain, struct userconf *ds)
 query the users/cdb file for information about this domain More...
 
static int qmexists (int domaindirfd, const char *suff1, const size_t len, const int def, int *fd)
 check if a .qmail file exists for the user More...
 
int user_exists (const string *localpart, const char *domain, struct userconf *dsp)
 check if the user identified by localpart and ds->domainpath exists More...
 
int userbackend_init (void)
 initialize the backend to query for local users More...
 
void userbackend_free (void)
 free the resources needed by the user backend
 
void userconf_init (struct userconf *ds)
 initialize the struct userconf More...
 
void userconf_free (struct userconf *ds)
 free all information in a struct userconf More...
 
int userconf_load_configs (struct userconf *ds)
 load the filter settings for user and domain More...
 
int userconf_get_buffer (const struct userconf *ds, const char *key, char ***values, checkfunc cf, const unsigned int flags)
 get a config buffer for a given user or domain More...
 
int userconf_find_domain (const struct userconf *ds, const char *key, const char *domain, const unsigned int flags)
 find a domain in the user configuration key More...
 

Variables

static char * vpopbounce
 
static struct userconf uconf
 

Detailed Description

function to get domain directory of vpopmail virtual domain

Function Documentation

static int qmexists ( int  domaindirfd,
const char *  suff1,
const size_t  len,
const int  def,
int *  fd 
)
static

check if a .qmail file exists for the user

Parameters
domaindirfddescriptor of the domain directory
suff1the suffix to test (e.g. localpart), may be NULL when def is 1
lenlength of suff1
defwhich suffixes to use (logically or'ed)
  • 1: append "default"
  • 2: append suff1
fdfile descriptor of .qmail file is returned here if argument is not NULL
Returns
if the file exists
Return values
0file does not exist
1file exists
<0error code from opening the file

The contents of fd are undefined if the return value is not 1.

int user_exists ( const string localpart,
const char *  domain,
struct userconf dsp 
)

check if the user identified by localpart and ds->domainpath exists

Parameters
localpartlocalpart of mail address
domaindomainpart of the domain
dspath of domain
Return values
0user doesn't exist
1user exists
2mail would be catched by .qmail-default and .qmail-default != vpopbounce
3domain is not filtered (use for domains not local)
4mail would be catched by .qmail-foo-default (i.e. mailinglist)
5domain is not local
<0error code

If the user has it's own mail directory ds->userpath will be filled with the correct values.

This function must be implemented by the password backend (i.e. currently vpop.c).

int userbackend_init ( void  )

initialize the backend to query for local users

Returns
if initialization was successful
Return values
0backend was successfully initialized
>0error code
int userconf_find_domain ( const struct userconf ds,
const char *  key,
const char *  domain,
const unsigned int  flags 
)

find a domain in the user configuration key

Parameters
dsthe userconf buffer
keythe key name for lookup
domainthe domain name to search for
flagssearch flags
Returns
the type of the configuration entry returned
Return values
CONFIG_NONEthe domain was not found in the configuration
>0the domain was found in the configuration
<0negative error code
void userconf_free ( struct userconf ds)

free all information in a struct userconf

Parameters
dsthe struct to clear

This will not free the struct itself so it is safe to use a static or stack allocated struct. It will reset all values to a safe value so the struct can be reused.

int userconf_get_buffer ( const struct userconf ds,
const char *  key,
char ***  values,
checkfunc  cf,
const unsigned int  flags 
)

get a config buffer for a given user or domain

Parameters
dsthe userconf buffer
keythe key name to load the information for
valuesthe result array
cfa function to filter the entries (may be NULL)
flagssearch flags
Returns
the type of the configuration entry returned
Return values
<0negative error code
void userconf_init ( struct userconf ds)

initialize the struct userconf

Parameters
dsthe struct to initialize

All fields of the struct are reset to a safe invalid value.

int userconf_load_configs ( struct userconf ds)

load the filter settings for user and domain

Parameters
dsthe userconf buffer to hold the information
Returns
if filters were successfully loaded or error code
Return values
0filters were loaded (or no configuration is present)
>0error code
int vget_dir ( const char *  domain,
struct userconf ds 
)

query the users/cdb file for information about this domain

Parameters
domainthe domain to query
dspointer to userconf struct holding the domain info
Returns
negative error code or flag if domain was found
Return values
0domain is not in database
1domain was found
<0negative error code
-EDONEthe error was already handled

Function will return 1 on success, memory for domaindir will be malloced. The directory name will always end with a single '/' and be 0-terminated. If the domain does not exist 0 is returned, also if no users/cdb exists. On error a negative error code is returned.

If ds already contains information about the same domain directory then the already existing information is preserved.

Variable Documentation

struct userconf uconf
static

global userconfig cache

char* vpopbounce
static

the bounce command in vpopmails .qmail-default