This is a do-nothing module where custom authentication code
diff --git a/aclocal.m4 b/aclocal.m4
index 6379c8b..8a0d7e7 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.15 -*- Autoconf -*-
+# generated automatically by aclocal 1.15.1 -*- Autoconf -*-
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -20,6 +20,83 @@ You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
+dnl Sets the COURIER_UNICODE_CXXFLAGS variable to any additional compiler
+dnl flags needed to build the courier-unicode package and packages that
+dnl use the courier-unicode package.
+
+AC_DEFUN([AX_COURIER_UNICODE_CXXFLAGS],[
+
+save_FLAGS="$CXXFLAGS"
+
+AC_LANG_PUSH([C++])
+
+AC_TRY_COMPILE([
+#include
+], [
+ std::u32string s;
+ char32_t c;
+ ],
+ [
+ ],
+ [
+
+COURIER_UNICODE_CXXFLAGS="-std=c++11"
+CXXFLAGS="$save_CFLAGS $COURIER_UNICODE_CXXFLAGS"
+
+AC_TRY_COMPILE([
+#include
+], [
+ std::u32string s;
+ char32_t c;
+ ],
+ [
+ ],
+ [
+
+COURIER_UNICODE_CXXFLAGS="-std=c++0x"
+CXXFLAGS="$save_CFLAGS $COURIER_UNICODE_CXXFLAGS"
+
+AC_TRY_COMPILE([
+#include
+], [
+ std::u32string s;
+ char32_t c;
+ ],
+ [
+ ],
+ [
+AC_MSG_ERROR([*** A compiler with C++11 Unicode support was not found])
+])
+])
+])
+CXXFLAGS="$save_FLAGS"
+AC_LANG_POP([C++])
+])
+
+AC_DEFUN([AX_COURIER_UNICODE_VERSION],[
+
+AC_MSG_CHECKING(courier-unicode library and version)
+
+AC_TRY_COMPILE([
+#include
+#ifndef COURIER_UNICODE_VERSION
+#define COURIER_UNICODE_VERSION 0
+#endif
+
+#if COURIER_UNICODE_VERSION < 210
+#error "courier-unicode 2.1 library is required"
+#endif
+
+],[],[],
+AC_MSG_ERROR([
+ERROR: The Courier Unicode Library 2.1 header files appear not to be installed.
+You may need to upgrade the library or install a separate development
+subpackage in addition to the main package.])
+)
+
+AC_MSG_RESULT([ok])
+])
+
# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
#
# Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc.
@@ -10075,7 +10152,7 @@ AC_DEFUN([AC_PROG_SYSCONFTOOL],
]
)
-# Copyright (C) 2002-2014 Free Software Foundation, Inc.
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10090,7 +10167,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.15'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.15], [],
+m4_if([$1], [1.15.1], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -10106,14 +10183,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.15])dnl
+[AM_AUTOMAKE_VERSION([1.15.1])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10165,7 +10242,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd`
# AM_CONDITIONAL -*- Autoconf -*-
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10196,7 +10273,7 @@ AC_CONFIG_COMMANDS_PRE(
Usually this means the macro was only invoked conditionally.]])
fi])])
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10387,7 +10464,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
# Generate code to set up dependency tracking. -*- Autoconf -*-
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10463,7 +10540,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# Do all the work for Automake. -*- Autoconf -*-
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10660,7 +10737,7 @@ for _am_header in $config_headers :; do
done
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10681,7 +10758,7 @@ if test x"${install_sh+set}" != xset; then
fi
AC_SUBST([install_sh])])
-# Copyright (C) 2003-2014 Free Software Foundation, Inc.
+# Copyright (C) 2003-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10702,7 +10779,7 @@ AC_SUBST([am__leading_dot])])
# Check to see how 'make' treats includes. -*- Autoconf -*-
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10752,7 +10829,7 @@ rm -f confinc confmf
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10791,7 +10868,7 @@ fi
# Helper functions for option handling. -*- Autoconf -*-
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10820,7 +10897,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10867,7 +10944,7 @@ AC_LANG_POP([C])])
# For backward compatibility.
AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10886,7 +10963,7 @@ AC_DEFUN([AM_RUN_LOG],
# Check to make sure that the build environment is sane. -*- Autoconf -*-
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -10967,7 +11044,7 @@ AC_CONFIG_COMMANDS_PRE(
rm -f conftest.file
])
-# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+# Copyright (C) 2009-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -11027,7 +11104,7 @@ AC_SUBST([AM_BACKSLASH])dnl
_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
])
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -11055,7 +11132,7 @@ fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
-# Copyright (C) 2006-2014 Free Software Foundation, Inc.
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -11074,7 +11151,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
# Check how to create a tarball. -*- Autoconf -*-
-# Copyright (C) 2004-2014 Free Software Foundation, Inc.
+# Copyright (C) 2004-2017 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/auth.h b/auth.h
index 837eb41..316495c 100644
--- a/auth.h
+++ b/auth.h
@@ -47,17 +47,6 @@ int auth_sys_common( int (*auth_pre_func)(const char *,
int (*callback_func)(struct authinfo *, void *),
void *callback_arg);
-const char *authgetconfig(const char *filename, const char *env);
-
-char *auth_parse_select_clause (char *(*escape_func)(const char *, size_t),
- const char *clause, const char *username,
- const char *defdomain,
- const char *service);
-
-char *auth_parse_chpass_clause (char *(*escape_func)(const char *, size_t),
- const char *clause, const char *username,
- const char *defdomain, const char *newpass,
- const char *newpass_crypt);
#ifdef __cplusplus
}
diff --git a/auth_enumerate.3 b/auth_enumerate.3
index 9b8bbf8..3a40fd3 100644
--- a/auth_enumerate.3
+++ b/auth_enumerate.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_enumerate
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_ENUMERATE" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_ENUMERATE" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_generic.3 b/auth_generic.3
index f6020c2..b566adf 100644
--- a/auth_generic.3
+++ b/auth_generic.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_generic
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_GENERIC" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_GENERIC" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_getoption.3 b/auth_getoption.3
index f5dcc11..bbd88bc 100644
--- a/auth_getoption.3
+++ b/auth_getoption.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_getoption
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_GETOPTION" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_GETOPTION" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_getuserinfo.3 b/auth_getuserinfo.3
index 16f4c47..57150c4 100644
--- a/auth_getuserinfo.3
+++ b/auth_getuserinfo.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_getuserinfo
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_GETUSERINFO" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_GETUSERINFO" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_login.3 b/auth_login.3
index d617d53..b2bccc5 100644
--- a/auth_login.3
+++ b/auth_login.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_login
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_LOGIN" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_LOGIN" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_mkhomedir.3 b/auth_mkhomedir.3
index 314e931..ed0155c 100644
--- a/auth_mkhomedir.3
+++ b/auth_mkhomedir.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_mkhomedir
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 11/04/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_MKHOMEDIR" "3" "11/04/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_MKHOMEDIR" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_passwd.3 b/auth_passwd.3
index 33e6d3a..573e32b 100644
--- a/auth_passwd.3
+++ b/auth_passwd.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_passwd
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_PASSWD" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_PASSWD" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/auth_sasl.3 b/auth_sasl.3
index 705157c..4c59c8e 100644
--- a/auth_sasl.3
+++ b/auth_sasl.3
@@ -2,14 +2,14 @@
.\"
.\"
.\" Title: auth_sasl
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1
-.\" Date: 06/20/2015
+.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot
+.\" Date: 09/08/2017
.\" Manual: Double Precision, Inc.
.\" Source: Double Precision, Inc.
.\" Language: English
.\"
-.TH "AUTH_SASL" "3" "06/20/2015" "Double Precision, Inc." "Double Precision, Inc."
+.TH "AUTH_SASL" "3" "09/08/2017" "Double Precision, Inc." "Double Precision, Inc."
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -136,7 +136,8 @@ conversation\&.
is a version of
\fBauth_sasl\fR
that recognizes the
-EXTERNALSASL
+EXTERNAL
+SASL
method\&. It takes an extra parameter,
\fIexternalauth\fR\&. This parameter should be set to indicate an login that was authenticated via some other means, such as, perhaps, an
SSL
diff --git a/authconfigfile.cpp b/authconfigfile.cpp
new file mode 100644
index 0000000..0a79c5b
--- /dev/null
+++ b/authconfigfile.cpp
@@ -0,0 +1,263 @@
+/*
+** Copyright 2016 Double Precision, Inc. See COPYING for
+** distribution information.
+*/
+
+#if HAVE_CONFIG_H
+#include "courier_auth_config.h"
+#endif
+
+#if HAVE_SYS_STAT_H
+#include
+#endif
+
+extern "C" {
+#include "authldap.h"
+#include "auth.h"
+#include "authldaprc.h"
+#include "courierauthdebug.h"
+};
+
+#include
+#include
+#include
+
+#include "authconfigfile.h"
+
+courier::auth::config_file::config_file(const char *filenameArg)
+ : filename(filenameArg), loaded(false)
+{
+}
+
+bool courier::auth::config_file::load(bool reload)
+{
+ struct stat stat_buf;
+
+ if (stat(filename, &stat_buf) < 0)
+ {
+ courier_auth_err("stat(%s) failed", filename);
+ return false;
+ }
+
+ if (loaded)
+ {
+ if (stat_buf.st_mtime != config_timestamp)
+ do_reload();
+ return true;
+ }
+
+ loaded=open_and_load_file(reload);
+
+ if (loaded)
+ config_timestamp=stat_buf.st_mtime;
+ return loaded;
+}
+
+class courier::auth::config_file::isspace {
+
+public:
+
+ bool operator()(char c)
+ {
+ return std::isspace(c);
+ }
+};
+
+class courier::auth::config_file::not_isspace : public isspace {
+
+public:
+
+ bool operator()(char c)
+ {
+ return !isspace::operator()(c);
+ }
+};
+
+
+bool courier::auth::config_file::open_and_load_file(bool reload)
+{
+ std::ifstream f(filename);
+
+ if (!f.is_open())
+ {
+ courier_auth_err("Cannot open %s", filename);
+
+ return false;
+ }
+
+ std::string s;
+
+ bool seen_marker=false;
+
+ while (s.clear(), !std::getline(f, s).eof() || !s.empty())
+ {
+ std::string::iterator e=s.end();
+
+ std::string::iterator p=
+ std::find_if(s.begin(), e, not_isspace());
+
+ if (p == s.end() || *p == '#')
+ {
+ static const char marker[]="##NAME: MARKER:";
+
+ if (s.substr(0, sizeof(marker)-1) == marker)
+ seen_marker=true;
+ continue;
+ }
+
+ std::string::iterator q=std::find_if(p, e, isspace());
+
+ std::string name(p, q);
+ std::string setting;
+
+ while (1)
+ {
+ q=std::find_if(q, e, not_isspace());
+
+ while (q != e && isspace()(e[-1]))
+ --e;
+
+ if (q == e)
+ break;
+
+ bool continuing=false;
+
+ if (e[-1] == '\\')
+ {
+ continuing=true;
+ e[-1]=' ';
+ }
+
+ setting.insert(setting.end(), q, e);
+
+ if (!continuing)
+ break;
+
+ std::getline(f, s);
+
+ q=s.begin();
+ e=s.end();
+ }
+
+ parsed_config.insert(std::make_pair(name, setting));
+ }
+
+ if (!seen_marker)
+ {
+ courier_auth_err((reload
+ ? "marker line not found in %s will try again later"
+ : "marker line not found in %s (probably forgot to run sysconftool after an upgrade)"), filename);
+ return false;
+ }
+
+ return do_load();
+}
+
+bool courier::auth::config_file::getconfig(const char *name,
+ std::string &value,
+ bool required,
+ const char *default_value) const
+{
+ std::map::const_iterator
+ iter=parsed_config.find(name);
+
+ if (iter != parsed_config.end())
+ {
+ value=iter->second;
+ return true;
+ }
+
+ if (required)
+ {
+ courier_auth_err("%s not found in %s",
+ name, filename);
+ return false;
+ }
+
+ value.clear();
+ if (default_value)
+ value=default_value;
+ return true;
+}
+
+template<>
+bool courier::auth::config_file::config(const char *name,
+ std::string &value,
+ bool required,
+ const char *default_value) const
+{
+ return getconfig(name, value, required, default_value);
+}
+
+std::string courier::auth::config_file::config(const char *name) const
+{
+ return config(name, 0);
+}
+
+std::string courier::auth::config_file::config(const char *name,
+ const char *default_value) const
+{
+ std::string retval;
+
+ config(name, retval, false, default_value);
+
+ return retval;
+}
+
+std::string
+courier::auth::config_file::expand_string(const std::string &s,
+ const std::map ¶meters)
+{
+ std::ostringstream o;
+
+ std::string::const_iterator b=s.begin(), e=s.end(), p;
+ std::map::const_iterator p_iter;
+
+ while (b != e)
+ {
+ p=std::find(b, e, '$');
+
+ o << std::string(b, p);
+
+ b=p;
+
+ if (b == e)
+ continue;
+
+ if (*++b != '(')
+ {
+ o << '$';
+ continue;
+ }
+
+ p=std::find(++b, e, ')');
+
+ p_iter=parameters.find(std::string(b, p));
+ b=p;
+ if (b != e)
+ ++b;
+
+ if (p_iter != parameters.end())
+ o << p_iter->second;
+ }
+ return o.str();
+}
+
+std::string
+courier::auth::config_file::parse_custom_query(const std::string &s,
+ const std::string &login,
+ const std::string &defdomain,
+ std::map ¶meters)
+{
+
+ std::string::const_iterator b=login.begin(),
+ e=login.end(),
+ p=std::find(b, e, '@');
+
+ parameters["local_part"]=std::string(b, p);
+ parameters["domain"]=p == e ? defdomain:std::string(p+1, e);
+
+ return expand_string(s, parameters);
+}
diff --git a/authconfigfile.h b/authconfigfile.h
new file mode 100644
index 0000000..e87258c
--- /dev/null
+++ b/authconfigfile.h
@@ -0,0 +1,101 @@
+#ifndef authconfigfile_h
+#define authconfigfile_h
+
+#if HAVE_CONFIG_H
+#include "courier_auth_config.h"
+#endif
+
+#include
+#if HAVE_SYS_TIME_H
+#include
+#endif
+
+#include
+#include
+#include