Skip to content

Commit ed2c431

Browse files
committed
initial commit
0 parents  commit ed2c431

26 files changed

+3465
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
**/*~
2+
**/*.d
3+
**/*.o
4+
5+
**/.deps
6+
**/Makefile
7+
**/Makefile.in
8+
**/aclocal.m4
9+
**/.dirstamp
10+
**/autom4te.cache
11+
**/config.h
12+
**/config.h.in
13+
**/config.log
14+
**/config.status
15+
**/configure
16+
**/stamp-h1
17+
18+
table-sqlite

Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
noinst_PROGRAMS = table-sqlite
2+
3+
table_sqlite_SOURCES = table_sqlite.c dict.c log.c table_stdio.c util.c
4+
5+
AM_CFLAGS =
6+
LDADD = $(LIBOBJS)
7+
8+
smtpdir = ${prefix}/libexec/smtpd
9+
10+
install-exec-local: $(noinst_PROGRAMS)
11+
$(MKDIR_P) $(DESTDIR)$(smtpdir)
12+
$(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $(noinst_PROGRAMS) $(DESTDIR)$(smtpdir)
13+
14+
README.md: table-sqlite.5
15+
mandoc -Tmarkdown -l table-sqlite.5 > README.md

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
TABLE\_SQLITE(5) - File Formats Manual
2+
3+
# NAME
4+
5+
**table\_sqlite** - format description for smtpd sqlite tables
6+
7+
# DESCRIPTION
8+
9+
This manual page documents the file format of sqlite tables used by the
10+
smtpd(8)
11+
mail daemon.
12+
13+
The format described here applies to tables as defined in
14+
smtpd.conf(5).
15+
16+
# SQLITE TABLE
17+
18+
A sqlite table allows the storing of usernames, passwords, aliases, and domains
19+
in a format that is shareable across various machines that support
20+
sqlite3(1)
21+
(SQLite version 3).
22+
23+
The table is used by
24+
smtpd(8)
25+
when authenticating a user, when user information such as user-id and/or
26+
home directory is required for a delivery, when a domain lookup may be required,
27+
and/or when looking for an alias.
28+
29+
A sqlite table consists of one or more
30+
sqlite3(1)
31+
databases with one or more tables.
32+
33+
If the table is used for authentication, the password should be
34+
encrypted using the
35+
crypt(3)
36+
function. Such passwords can be generated using the
37+
encrypt(1)
38+
utility or
39+
smtpctl(8)
40+
encrypt command.
41+
42+
# SQLITE TABLE CONFIG FILE
43+
44+
The following configuration options are available:
45+
46+
**dbpath**
47+
*file*
48+
49+
> This is the path to where the DB file is located.
50+
> For example:
51+
52+
> > dbpath /etc/mail/smtp.sqlite
53+
54+
**query\_alias**
55+
*SQL statement*
56+
57+
> This is used to provide a query to look up aliases. The question mark
58+
> is replaced with the appropriate data. For alias it is the left hand side of
59+
> the SMTP address. This expects one VARCHAR to be returned with the user name
60+
> the alias resolves to.
61+
62+
**query\_credentials**
63+
*SQL statement*
64+
65+
> This is used to provide a query for looking up user credentials. The question
66+
> mark is replaced with the appropriate data. For credentials it is the left
67+
> hand side of the SMTP address. The query expects that there are two VARCHARS
68+
> returned, one with a user name and one with a password in
69+
> crypt(3)
70+
> format.
71+
72+
**query\_domain**
73+
*SQL statement*
74+
75+
> This is used to provide a query for looking up a domain. The question mark
76+
> is replaced with the appropriate data. For the domain it would be the
77+
> right hand side of the SMTP address. This expects one VARCHAR to be returned
78+
> with a matching domain name.
79+
80+
**query\_mailaddrmap**
81+
*SQL statement*
82+
83+
> This is used to provide a query for looking up a senders. The question mark
84+
> is replaced with the appropriate data. This expects one VARCHAR to be returned
85+
> with the address the sender is allowed to send mails from.
86+
87+
A generic SQL statement would be something like:
88+
89+
query_ SELECT value FROM table WHERE key=?;
90+
91+
# EXAMPLES
92+
93+
Example based on the OpenSMTPD FAQ: Building a Mail Server
94+
The filtering part is excluded in this example.
95+
96+
The configuration below is for a medium-size mail server which handles
97+
multiple domains with multiple virtual users and is based on several
98+
assumptions. One is that a single system user named vmail is used for all
99+
virtual users. This user needs to be created:
100+
101+
# useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
102+
# mkdir /var/vmail
103+
# chown vmail:vmail /var/vmail
104+
105+
*sqlite schema*
106+
107+
CREATE TABLE virtuals (
108+
id INTEGER PRIMARY KEY AUTOINCREMENT,
109+
email VARCHAR(255) NOT NULL,
110+
destination VARCHAR(255) NOT NULL
111+
);
112+
CREATE TABLE credentials (
113+
id INTEGER PRIMARY KEY AUTOINCREMENT,
114+
email VARCHAR(255) NOT NULL,
115+
password VARCHAR(255) NOT NULL
116+
);
117+
CREATE TABLE domains (
118+
id INTEGER PRIMARY KEY AUTOINCREMENT,
119+
domain VARCHAR(255) NOT NULL
120+
);
121+
INSERT INTO domains VALUES (1, "example.com");
122+
INSERT INTO domains VALUES (2, "example.net");
123+
INSERT INTO domains VALUES (3, "example.org");
124+
125+
INSERT INTO virtuals VALUES (1, "[email protected]", "[email protected]");
126+
INSERT INTO virtuals VALUES (2, "[email protected]", "[email protected]");
127+
INSERT INTO virtuals VALUES (3, "[email protected]", "[email protected]");
128+
INSERT INTO virtuals VALUES (4, "[email protected]", "vmail");
129+
INSERT INTO virtuals VALUES (5, "[email protected]", "[email protected]");
130+
INSERT INTO virtuals VALUES (6, "[email protected]", "[email protected]");
131+
INSERT INTO virtuals VALUES (7, "[email protected]", "[email protected]");
132+
INSERT INTO virtuals VALUES (8, "[email protected]", "vmail");
133+
134+
INSERT INTO credentials VALUES (1, "[email protected]", "$2b$08$ANGFKBL.BnDLL0bUl7I6aumTCLRJSQluSQLuueWRG.xceworWrUIu");
135+
INSERT INTO credentials VALUES (2, "[email protected]", "$2b$08$AkHdB37kaj2NEoTcISHSYOCEBA5vyW1RcD8H1HG.XX0P/G1KIYwii");
136+
137+
*/etc/mail/sqlite.conf*
138+
139+
dbpath /etc/mail/smtp.sqlite
140+
query_alias SELECT destination FROM virtuals WHERE email=?;
141+
query_credentials SELECT email, password FROM credentials WHERE email=?;
142+
query_domain SELECT domain FROM domains WHERE domain=?;
143+
144+
*/etc/mail/smtpd.conf*
145+
146+
table domains sqlite:/etc/mail/sqlite.conf
147+
table virtuals sqlite:/etc/mail/sqlite.conf
148+
table credentials sqlite:/etc/mail/sqlite.conf
149+
listen on egress port 25 tls pki mail.example.com
150+
listen on egress port 587 tls-require pki mail.example.com auth <credentials>
151+
accept from any for domain <domains> virtual <virtuals> deliver to mbox
152+
153+
# FILES
154+
155+
*/etc/mail/sqlite.conf*
156+
157+
> Default
158+
> table-sqlite(8)
159+
> configuration file.
160+
161+
*/etc/mail/smtp.sqlite*
162+
163+
> Suggested
164+
> sqlite3(1)
165+
> database file.
166+
167+
# TODO
168+
169+
Documenting the following query options:
170+
171+
**query_netaddr**
172+
**query_userinfo**
173+
**query_source**
174+
**query_mailaddr**
175+
**query_addrname**
176+
177+
# SEE ALSO
178+
179+
smtpd.conf(5),
180+
smtpctl(8),
181+
smtpd(8),
182+
encrypt(1),
183+
crypt(3)
184+
185+
Nixpkgs - July 4, 2016

bootstrap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/sh
2+
3+
autoreconf -vfi

compat.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "config.h"
2+
3+
#include <stddef.h>
4+
#include <limits.h>
5+
6+
#ifndef UID_MAX
7+
#define UID_MAX UINT_MAX
8+
#endif
9+
#ifndef GID_MAX
10+
#define GID_MAX UINT_MAX
11+
#endif
12+
13+
#ifndef __dead
14+
#define __dead __attribute__((noreturn))
15+
#endif
16+
17+
#ifndef HAVE_ASPRINTF
18+
int asprintf(char **, const char *, ...);
19+
#endif
20+
21+
#ifndef HAVE_GETPROGNAME
22+
const char *getprogname(void);
23+
#endif
24+
25+
#ifndef HAVE_STRLCAT
26+
size_t strlcat(char *, const char *, size_t);
27+
#endif
28+
29+
#ifndef HAVE_STRLCPY
30+
size_t strlcpy(char *, const char *, size_t);
31+
#endif
32+
33+
#ifndef HAVE_STRSEP
34+
char *strsep(char **, const char *);
35+
#endif
36+
37+
#ifndef HAVE_STRTONUM
38+
long long strtonum(const char *, long long, long long, const char **);
39+
#endif

configure.ac

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
AC_INIT([table-sqlite], [0.1], [[email protected]])
2+
AC_CONFIG_AUX_DIR(etc)
3+
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
4+
AC_CONFIG_LIBOBJ_DIR(openbsd-compat)
5+
AC_PROG_CC
6+
AC_USE_SYSTEM_EXTENSIONS
7+
8+
AC_ARG_WITH([libbsd],
9+
AS_HELP_STRING([--with-libbsd],
10+
[Build with libbsd library (default: disabled)]))
11+
12+
AS_IF([test "x$with_libbsd" = "xyes"], [
13+
PKG_CHECK_MODULES([libbsd], [libbsd-overlay libbsd-ctor], [
14+
CFLAGS="$libbsd_CFLAGS $CFLAGS"
15+
LIBS="$libbsd_LIBS $LIBS"
16+
])
17+
])
18+
19+
AC_REPLACE_FUNCS([ \
20+
asprintf \
21+
getprogname \
22+
err \
23+
strlcat \
24+
strlcpy \
25+
strsep \
26+
strtonum \
27+
])
28+
29+
AC_SEARCH_LIBS([sqlite3_open_v2], [sqlite3], [], [
30+
AC_MSG_ERROR([requires sqlite3])
31+
])
32+
33+
CFLAGS="$CFLAGS -I$srcdir/openbsd-compat"
34+
35+
AC_CHECK_HEADER([sys/tree.h], [], [
36+
CFLAGS="$CFLAGS -I$srcdir/openbsd-compat/tree"
37+
])
38+
39+
AC_DEFUN([CC_ADD_CHECK_FLAGS], [
40+
AC_MSG_CHECKING([if $CC supports $1 flag])
41+
old_CFLAGS="$CFLAGS"
42+
CFLAGS="$CFLAGS $1"
43+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
44+
AC_MSG_RESULT(yes)
45+
], [
46+
AC_MSG_RESULT(no)
47+
CFLAGS="$old_CFLAGS"
48+
])
49+
])
50+
CC_ADD_CHECK_FLAGS([-MMD])
51+
52+
AC_CONFIG_HEADERS([config.h])
53+
AC_CONFIG_FILES([
54+
Makefile
55+
])
56+
AC_OUTPUT

0 commit comments

Comments
 (0)