]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added PostgreSQL support, patch by Alex Howansky
authorTimo Sirainen <tss@iki.fi>
Thu, 6 Mar 2003 23:20:16 +0000 (01:20 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 6 Mar 2003 23:20:16 +0000 (01:20 +0200)
--HG--
branch : HEAD

INSTALL
configure.in
doc/auth.txt
doc/dovecot-ldap.conf
dovecot-example.conf
src/auth/Makefile.am
src/auth/passdb.c
src/auth/passdb.h
src/auth/userdb.c
src/auth/userdb.h

diff --git a/INSTALL b/INSTALL
index 9a2a5f3567cd1ead9c093473db8b2f55b53bcfb1..f8d6984dfbc02b5618db559a17e076c4611552a2 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -88,6 +88,7 @@ file.
   --with-ldap             Build with LDAP support
   --with-vpopmail         Build with vpopmail support (default)
   --with-static-userdb    Build with static userdb support (default)
+  --with-pgsql            Build with PostgreSQL support
 
 Specify which authentication modules to use. Disabling them give you a few
 bytes smaller binary, but not much else.
@@ -107,8 +108,13 @@ gcc -shared -fPIC -DUSERDB_LDAP -DPASSDB_LDAP \
 db-ldap.c userdb-ldap.c passdb-ldap.c -o ldap.so \
 ../lib-settings/libsettings.a -lldap
 
+gcc -shared -fPIC -DUSERDB_PGSQL -DPASSDB_PGSQL \
+-I../.. -I../lib -I../lib-settings -I/usr/include/postgresql \
+db-pgsql.c userdb-pgsql.c passdb-pgsql.c -o pgsql.so \
+../lib-settings/libsettings.a -L/usr/lib/postgresql -lpq
+
 gcc -shared -fPIC -DUSERDB_VPOPMAIL -DPASSDB_VPOPMAIL -I../.. -I../lib \
 userdb-vpopmail.c passdb-vpopmail.c -o vpopmail.so -lvpopmail
 
-Including libsettings.a in ldap.so is kind of annoying, but it's not
-currently needed elsewhere in dovecot-auth.
+Including libsettings.a in ldap.so and pgsql.so is kind of annoying, but it's
+not needed elsewhere in dovecot-auth.
index f229b6391e84434855b6df81e1dc91410b114c93..e1ba83fb6752c0b39ff1a611ac435a0c5037240c 100644 (file)
@@ -115,6 +115,15 @@ AC_ARG_WITH(static-userdb,
        fi,
        want_static_userdb=yes)
 
+AC_ARG_WITH(pgsql,
+[  --with-pgsql            Build with PostgreSQL support],
+       if test x$withval = xno; then
+               want_pgsql=no
+       else
+               want_pgsql=yes
+       fi,
+       want_pgsql=no)
+
 AC_ARG_WITH(cyrus-sasl2,
 [  --with-cyrus-sasl2      Build with Cyrus SASL 2 library support],
        if test x$withval = xno; then
@@ -769,6 +778,38 @@ if test $want_ldap = yes; then
        ])
 fi
 
+if test $want_pgsql = yes; then
+       # based on code from PHP
+       for i in /usr /usr/local /usr/local/pgsql; do
+               for j in include include/pgsql include/postgres include/postgresql ""; do
+                       if test -r "$i/$j/libpq-fe.h"; then
+                       PGSQL_INC_BASE=$i
+                       PGSQL_INCLUDE=$i/$j
+               fi
+               done
+               for j in lib lib/pgsql lib/postgres lib/postgresql ""; do
+                       if test -f "$i/$j/libpq.so" || test -f "$i/$j/libpq.a"; then
+                               PGSQL_LIBDIR=$i/$j
+                       fi
+               done
+       done
+
+       old_LIBS=$LIBS
+       LIBS="$LIBS -L$PGSQL_LIBDIR"
+
+       AC_CHECK_LIB(pq, PQconnectdb, [
+               AC_CHECK_HEADER($PGSQL_INCLUDE/libpq-fe.h, [
+                       AUTH_CFLAGS="$AUTH_CFLAGS -I$PGSQL_INCLUDE"
+                       PASSDB_LIBS="$PASSDB_LIBS -L$PGSQL_LIBDIR -lpq"
+                       AC_DEFINE(USERDB_PGSQL,, Build with PostgreSQL support)
+                       AC_DEFINE(PASSDB_PGSQL,, Build with PostgreSQL support)
+                       userdb="$userdb pgsql"
+                       passdb="$passdb pgsql"
+               ])
+       ])
+       LIBS=$old_LIBS
+fi
+
 if test $want_vpopmail = yes; then
        vpopmail_home="`echo ~vpopmail`"
        vpop_libdeps="$vpopmail_home/etc/lib_deps"
@@ -825,6 +866,7 @@ AC_CHECK_LIB(dl, dlopen, [
 
 AM_CONDITIONAL(AUTH_MODULES, test "$auth_modules" = "yes")
 
+AC_SUBST(AUTH_CFLAGS)
 AC_SUBST(PASSDB_LIBS)
 
 dnl **
index baa67b2d7e95b45cb2b9b79bbb25a1c4838dca83..02c71ec04495055eca35c600e15f321aa8b769b4 100644 (file)
@@ -17,6 +17,7 @@ Currently supported password databases:
  - passwd-file: /etc/passwd-like file in specified location
  - ldap: Lightweight Directory Access Protocol
  - vpopmail: External software used to handle virtual domains
+ - pgsql: A PostgreSQL database.
 
 Currently supported user databases:
 
@@ -25,6 +26,7 @@ Currently supported user databases:
  - ldap: Lightweight Directory Access Protocol
  - vpopmail: External software used to handle virtual domains
  - static: Static UID and GID, home directory from given template
+ - pgsql: A PostgreSQL database.
 
 Most password databases support only plaintext authentication. passwd-file
 and LDAP exceptions since they support multiple password schemes.
@@ -126,6 +128,15 @@ All users share the same UID and GID. Home directory template can use %u,
 %n and %d variables, see default_mail_env description in dovecot-example.conf.
 
 
+PostgreSQL
+----------
+
+See dovecot-pgsql.conf for more information. Password and user databases may
+use different configuration files to keep the information in separate
+locations. If both refer to same file, they share the same PostgreSQL
+connection.
+
+
 Generating passwords
 --------------------
 
index 2b35f3bd10a73f5c13ccbfc1e1af09d42c6a3fa8..25ec89d773f104072ed451a0053c657527d9e631 100644 (file)
@@ -18,6 +18,9 @@
 # Password for LDAP server
 #dnpass = 
 
+# LDAP protocol version to use. Likely 2 or 3.
+#ldap_version = 2
+
 # LDAP base
 base = uid=someone, dc=foo, dc=bar, dc=org
 
index bf39456fa23504e454d84e3900d15a214d4cf413..8754fcfccd4de9f7fd481b5162cbabf89c6c43f7 100644 (file)
@@ -362,6 +362,7 @@ auth_mechanisms = plain
 #   static uid=<uid> gid=<gid> home=<dir template>: static settings
 #   vpopmail: vpopmail library
 #   ldap <config path>: LDAP, see doc/dovecot-ldap.conf
+#   pgsql <config path>: a PostgreSQL database, see doc/dovecot-pgsql.conf
 auth_userdb = passwd
 
 # Where password database is kept:
@@ -371,6 +372,7 @@ auth_userdb = passwd
 #   passwd-file <path>: passwd-like file with specified location
 #   vpopmail: vpopmail authentication
 #   ldap <config path>: LDAP, see doc/dovecot-ldap.conf
+#   pgsql <config path>: a PostgreSQL database, see doc/dovecot-pgsql.conf
 auth_passdb = pam
 
 # Executable location
index 4b2a7658b4e786f8cf1800c40c582f7da6d33194..8dcbf7ae18ea671856fe5d6ed8eb3919833cb849 100644 (file)
@@ -6,6 +6,7 @@ INCLUDES = \
        -I$(top_srcdir)/src/lib \
        -I$(top_srcdir)/src/lib-settings \
        -DAUTH_MODULE_DIR=\""$(libdir)/dovecot/auth"\" \
+       $(AUTH_CFLAGS) \
        $(VPOPMAIL_CFLAGS)
 
 dovecot_auth_LDADD = \
@@ -22,6 +23,7 @@ endif
 dovecot_auth_SOURCES = \
        auth-module.c \
        db-ldap.c \
+       db-pgsql.c \
        db-passwd-file.c \
        login-connection.c \
        main.c \
@@ -39,13 +41,15 @@ dovecot_auth_SOURCES = \
        passdb-pam.c \
        passdb-shadow.c \
        passdb-vpopmail.c \
+       passdb-pgsql.c \
        password-scheme.c \
        userdb.c \
        userdb-ldap.c \
        userdb-passwd.c \
        userdb-passwd-file.c \
        userdb-static.c \
-       userdb-vpopmail.c
+       userdb-vpopmail.c \
+       userdb-pgsql.c
 
 noinst_HEADERS = \
        auth-login-interface.h \
@@ -53,6 +57,7 @@ noinst_HEADERS = \
        auth-mech-desc.h \
        auth-module.h \
        db-ldap.h \
+       db-pgsql.h \
        db-passwd-file.h \
        common.h \
        login-connection.h \
index 477aa63ef9f04387fe80c512bea09e7a95bf31f7..27ee564146f42ab12418c284bdb909307429f5b6 100644 (file)
@@ -106,6 +106,10 @@ void passdb_init(void)
        if (strcasecmp(name, "ldap") == 0)
                passdb = &passdb_ldap;
 #endif
+#ifdef PASSDB_PGSQL
+    if (strcasecmp(name, "pgsql") == 0)
+        passdb = &passdb_pgsql;
+#endif
 #ifdef AUTH_MODULES
        passdb_module = auth_module_open(name);
        if (passdb_module != NULL) {
index 837d391a96e1aba6f3536015b9bba04482895929..4d28f37aff12dbde160b2e253f38d8d312a8d84d 100644 (file)
@@ -57,6 +57,7 @@ extern struct passdb_module passdb_passwd_file;
 extern struct passdb_module passdb_pam;
 extern struct passdb_module passdb_vpopmail;
 extern struct passdb_module passdb_ldap;
+extern struct passdb_module passdb_pgsql;
 
 void passdb_init(void);
 void passdb_deinit(void);
index b4d68358534fdfe6323e2c895951ee469928a09f..712d78bbfe8190eae3c0e91104bf03b3e95e4235 100644 (file)
@@ -45,6 +45,10 @@ void userdb_init(void)
        if (strcasecmp(name, "ldap") == 0)
                userdb = &userdb_ldap;
 #endif
+#ifdef USERDB_PGSQL
+    if (strcasecmp(name, "pgsql") == 0)
+        userdb = &userdb_pgsql;
+#endif
 #ifdef AUTH_MODULES
        userdb_module = auth_module_open(name);
        if (userdb_module != NULL) {
index 227fea5ac000da215facb817e58c71a6563aab11..9553c7d096ea286bb894e163ade30b99c33da280 100644 (file)
@@ -30,6 +30,7 @@ extern struct userdb_module userdb_passwd;
 extern struct userdb_module userdb_passwd_file;
 extern struct userdb_module userdb_vpopmail;
 extern struct userdb_module userdb_ldap;
+extern struct userdb_module userdb_pgsql;
 
 void userdb_init(void);
 void userdb_deinit(void);