46 |
#include <argcv.h> |
#include <argcv.h> |
47 |
#include <mu_asprintf.h> |
#include <mu_asprintf.h> |
48 |
|
|
|
#ifdef HAVE_MYSQL |
|
|
# include "../MySql/MySql.h" |
|
|
#endif |
|
|
|
|
49 |
#define ARG_LOG_FACILITY 1 |
#define ARG_LOG_FACILITY 1 |
50 |
#define ARG_SQL_GETPWNAM 2 |
#define ARG_LOCK_FLAGS 2 |
|
#define ARG_SQL_GETPWUID 3 |
|
|
#define ARG_SQL_GETPASS 4 |
|
|
#define ARG_SQL_HOST 5 |
|
|
#define ARG_SQL_USER 6 |
|
|
#define ARG_SQL_PASSWD 7 |
|
|
#define ARG_SQL_DB 8 |
|
|
#define ARG_SQL_PORT 9 |
|
|
#define ARG_PAM_SERVICE 10 |
|
|
#define ARG_LOCK_FLAGS 11 |
|
51 |
|
|
52 |
const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; |
const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; |
53 |
|
|
95 |
{ NULL, 0, NULL, 0, NULL, 0 } |
{ NULL, 0, NULL, 0, NULL, 0 } |
96 |
}; |
}; |
97 |
|
|
|
/* Options used by programs that use extended authentication mechanisms. */ |
|
|
static struct argp_option mu_auth_argp_option[] = { |
|
|
#ifdef USE_LIBPAM |
|
|
{ "pam-service", ARG_PAM_SERVICE, "STRING", 0, |
|
|
"Use STRING as PAM service name", 0}, |
|
|
#endif |
|
|
#ifdef HAVE_MYSQL |
|
|
{"sql-getpwnam", ARG_SQL_GETPWNAM, "QUERY", 0, |
|
|
"SQL query to retrieve a passwd entry based on username", 0}, |
|
|
{"sql-getpwuid", ARG_SQL_GETPWUID, "QUERY", 0, |
|
|
"SQL query to retrieve a passwd entry based on UID", 0}, |
|
|
{"sql-getpass", ARG_SQL_GETPASS, "QUERY", 0, |
|
|
"SQL query to retrieve a password from the database", 0}, |
|
|
{"sql-host", ARG_SQL_HOST, "HOSTNAME", 0, |
|
|
"Name or IP of MySQL server to connect to", 0}, |
|
|
{"sql-user", ARG_SQL_USER, "NAME", 0, |
|
|
"SQL user name", 0}, |
|
|
{"sql-passwd", ARG_SQL_PASSWD, "STRING", 0, |
|
|
"SQL connection password", 0}, |
|
|
{"sql-db", ARG_SQL_DB, "STRING", 0, |
|
|
"Name of the database to connect to", 0}, |
|
|
{"sql-port", ARG_SQL_PORT, "NUMBER", 0, |
|
|
"Port to use", 0}, |
|
|
#endif |
|
|
{ NULL, 0, NULL, 0, NULL, 0 } |
|
|
}; |
|
98 |
|
|
99 |
/* Options used by programs that become daemons. */ |
/* Options used by programs that become daemons. */ |
100 |
static struct argp_option mu_daemon_argp_option[] = { |
static struct argp_option mu_daemon_argp_option[] = { |
188 |
0 |
0 |
189 |
}; |
}; |
190 |
|
|
|
struct argp mu_auth_argp = { |
|
|
mu_auth_argp_option, |
|
|
mu_common_argp_parser, |
|
|
}; |
|
|
|
|
|
struct argp_child mu_auth_argp_child = { |
|
|
&mu_auth_argp, |
|
|
0, |
|
|
"Authentication options", |
|
|
0 |
|
|
}; |
|
|
|
|
191 |
struct argp mu_daemon_argp = { |
struct argp mu_daemon_argp = { |
192 |
mu_daemon_argp_option, |
mu_daemon_argp_option, |
193 |
mu_daemon_argp_parser, |
mu_daemon_argp_parser, |
250 |
" along with this program; if not, write to the Free Software\n" |
" along with this program; if not, write to the Free Software\n" |
251 |
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"; |
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"; |
252 |
|
|
|
#ifdef HAVE_MYSQL |
|
|
char *sql_getpwnam_query; |
|
|
char *sql_getpass_query; |
|
|
char *sql_getpwuid_query; |
|
|
char *sql_host = MHOST; |
|
|
char *sql_user = MUSER; |
|
|
char *sql_passwd = MPASS; |
|
|
char *sql_db = MDB; |
|
|
char *sql_socket = MSOCKET; |
|
|
int sql_port = MPORT; |
|
|
#endif |
|
|
#ifdef USE_LIBPAM |
|
|
char *pam_service = NULL; |
|
|
#endif |
|
|
|
|
253 |
static error_t |
static error_t |
254 |
mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
255 |
{ |
{ |
328 |
log_facility = parse_log_facility (arg); |
log_facility = parse_log_facility (arg); |
329 |
break; |
break; |
330 |
|
|
|
/* authentication */ |
|
|
#ifdef USE_LIBPAM |
|
|
case ARG_PAM_SERVICE: |
|
|
pam_service = arg; |
|
|
break; |
|
|
#endif |
|
|
|
|
|
#ifdef HAVE_MYSQL |
|
|
case ARG_SQL_GETPWNAM: |
|
|
sql_getpwnam_query = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_GETPWUID: |
|
|
sql_getpwuid_query = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_GETPASS: |
|
|
sql_getpass_query = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_HOST: |
|
|
sql_host = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_USER: |
|
|
sql_user = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_PASSWD: |
|
|
sql_passwd = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_DB: |
|
|
sql_db = arg; |
|
|
break; |
|
|
|
|
|
case ARG_SQL_PORT: |
|
|
sql_port = strtoul (arg, NULL, 0); |
|
|
if (sql_port == 0) |
|
|
{ |
|
|
sql_host = NULL; |
|
|
sql_socket = arg; |
|
|
} |
|
|
break; |
|
|
|
|
|
#endif |
|
331 |
case ARGP_KEY_FINI: |
case ARGP_KEY_FINI: |
332 |
p = mu_normalize_maildir (mu_path_maildir); |
p = mu_normalize_maildir (mu_path_maildir); |
333 |
if (!p) |
if (!p) |
628 |
*p_argv = x_argv; |
*p_argv = x_argv; |
629 |
} |
} |
630 |
|
|
631 |
|
#define MU_MAX_CAPA 24 |
632 |
|
|
633 |
struct argp_capa { |
struct argp_capa { |
634 |
char *capability; |
char *capability; |
635 |
struct argp_child *child; |
struct argp_child *child; |
636 |
} mu_argp_capa[] = { |
} mu_argp_capa[MU_MAX_CAPA] = { |
637 |
{"common", &mu_common_argp_child}, |
{"common", &mu_common_argp_child}, |
638 |
{"license", &mu_license_argp_child}, |
{"license", &mu_license_argp_child}, |
639 |
{"mailbox", &mu_mailbox_argp_child}, |
{"mailbox", &mu_mailbox_argp_child}, |
640 |
{"address", &mu_address_argp_child}, |
{"address", &mu_address_argp_child}, |
641 |
{"mailer", &mu_mailer_argp_child}, |
{"mailer", &mu_mailer_argp_child}, |
642 |
{"logging", &mu_logging_argp_child}, |
{"logging", &mu_logging_argp_child}, |
|
{"auth", &mu_auth_argp_child}, |
|
643 |
{"daemon", &mu_daemon_argp_child}, |
{"daemon", &mu_daemon_argp_child}, |
644 |
{NULL,} |
{NULL,} |
645 |
}; |
}; |
646 |
|
|
647 |
|
int |
648 |
|
mu_register_capa (const char *name, struct argp_child *child) |
649 |
|
{ |
650 |
|
int i; |
651 |
|
|
652 |
|
for (i = 0; i < MU_MAX_CAPA; i++) |
653 |
|
if (mu_argp_capa[i].capability == NULL) |
654 |
|
{ |
655 |
|
mu_argp_capa[i].capability = strdup (name); |
656 |
|
mu_argp_capa[i].child = child; |
657 |
|
return 0; |
658 |
|
} |
659 |
|
return 1; |
660 |
|
} |
661 |
|
|
662 |
|
|
663 |
static struct argp_child * |
static struct argp_child * |
664 |
find_argp_child (const char *capa) |
find_argp_child (const char *capa) |
665 |
{ |
{ |