Commit d7e10d9e d7e10d9ea4d1726f5253cad4fe06a9114365255b by Sergey Poznyakoff

* auth/ldap.c (_mu_ldap_search): Provide %u expansion for backward

compatibility with other modules.
* auth/radius.c, auth/sql.c: Use mu_vartab_t for expansion.
* include/mailutils/mailutils.h: Include mailutils/assoc.h
* lib/tcpwrap.c (mu_tcpwrapper_access): Ignore local sockets.
* libargp/muinit.c (mu_app_init): Re-assign mu_program_name after
command line parsing, so that --program-name takes effect.
* libcfg/sql.c (mu_sql_param): Fix typo in statement name.
* libproto/include/amd.h (struct _amd_message.create): New member.
* libproto/maildir/mbox.c (maildir_create): New function.
(_mailbox_maildir_init): Set amd->create.
* mailbox/amd.c (amd_open): Call amd->create after successfully
creating the directory.
* mailbox/cfg_driver.c (_cb_include): Mask out
MU_PARSE_CONFIG_GLOBAL in the flags.
(mu_build_container): Bugfix. Take struct include_data as
argument, instead of using an auto variable. All callers updated.
* mailbox/ipsrv.c (mu_ip_tcp_accept): Bugfix: use client address,
not server, to print diagnostics.
* mailbox/msrv.c (m_srv_conn): Fix prefork condition for
single-process mode.
1 parent 6d1d8ecf
2008-01-09 Sergey Poznyakoff <gray@gnu.org.ua>
* auth/ldap.c (_mu_ldap_search): Provide %u expansion for backward
compatibility with other modules.
* auth/radius.c, auth/sql.c: Use mu_vartab_t for expansion.
* include/mailutils/mailutils.h: Include mailutils/assoc.h
* lib/tcpwrap.c (mu_tcpwrapper_access): Ignore local sockets.
* libargp/muinit.c (mu_app_init): Re-assign mu_program_name after
command line parsing, so that --program-name takes effect.
* libcfg/sql.c (mu_sql_param): Fix typo in statement name.
* libproto/include/amd.h (struct _amd_message.create): New member.
* libproto/maildir/mbox.c (maildir_create): New function.
(_mailbox_maildir_init): Set amd->create.
* mailbox/amd.c (amd_open): Call amd->create after successfully
creating the directory.
* mailbox/cfg_driver.c (_cb_include): Mask out
MU_PARSE_CONFIG_GLOBAL in the flags.
(mu_build_container): Bugfix. Take struct include_data as
argument, instead of using an auto variable. All callers updated.
* mailbox/ipsrv.c (mu_ip_tcp_accept): Bugfix: use client address,
not server, to print diagnostics.
* mailbox/msrv.c (m_srv_conn): Fix prefork condition for
single-process mode.
* TODO: Update.
* include/mailutils/server.h (mu_m_server_set_foreground)
(mu_m_server_foreground,mu_m_server_pidfile)
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -516,6 +516,7 @@ _mu_ldap_search (LDAP *ld, const char *filter_pat, const char *key,
mu_vartab_create (&vtab);
mu_vartab_define (vtab, "user", key, 1);
mu_vartab_define (vtab, "u", key, 1);
rc = mu_vartab_expand (vtab, filter_pat, &filter);
mu_vartab_destroy (&vtab);
if (rc)
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -40,6 +40,7 @@
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/nls.h>
#include <mailutils/vartab.h>
#ifdef ENABLE_RADIUS
......@@ -202,96 +203,38 @@ mu_radius_module_init (void *data)
static char *
_expand_query (const char *query, const char *ustr, const char *passwd)
{
char *p, *q, *res;
int len;
int rc;
mu_vartab_t vtab;
char *str, *ret;
if (!query)
return NULL;
mu_vartab_create (&vtab);
if (ustr)
{
mu_vartab_define (vtab, "user", ustr, 1);
mu_vartab_define (vtab, "u", ustr, 1);
}
/* Compute resulting query length */
for (len = 0, p = (char *) query; *p; )
if (passwd)
{
if (*p == '%')
{
if (p[1] == 'u')
{
len += ustr ? strlen (ustr) : 2;
p += 2;
}
else if (p[1] == 'p')
{
len += passwd ? strlen (passwd) : 2;
p += 2;
}
else if (p[1] == '%')
{
len++;
p += 2;
}
else
{
len++;
p++;
}
}
else
{
len++;
p++;
}
mu_vartab_define (vtab, "passwd", passwd, 1);
mu_vartab_define (vtab, "p", ustr, 1);
}
res = grad_emalloc (len + 1);
if (!res)
return res;
for (p = (char *) query, q = res; *p; )
rc = mu_vartab_expand (vtab, query, &str);
if (rc == 0)
{
if (*p == '%')
{
switch (*++p)
{
case 'u':
if (ustr)
{
strcpy (q, ustr);
q += strlen (q);
}
else
{
*q++ = '%';
*q++ = 'u';
}
p++;
break;
case 'p':
if (passwd)
{
strcpy (q, passwd);
q += strlen (q);
}
else
{
*q++ = '%';
*q++ = 'p';
}
p++;
break;
case '%':
*q++ = *p++;
break;
default:
*q++ = *p++;
}
}
else
*q++ = *p++;
ret = grad_emalloc (strlen (str) + 1);
strcpy (ret, str);
free (str);
}
*q = 0;
return res;
else
ret = NULL;
mu_vartab_destroy (&vtab);
return ret;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2002, 2003, 2004, 2005, 2006,
2007 Free Software Foundation, Inc.
2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -51,6 +51,7 @@
#include <mailutils/nls.h>
#include <mailutils/mutil.h>
#include <mailutils/sql.h>
#include <mailutils/vartab.h>
#include "sql.h"
#ifdef USE_SQL
......@@ -88,74 +89,22 @@ sql_escape_string (const char *ustr)
char *
mu_sql_expand_query (const char *query, const char *ustr)
{
char *p, *q, *res;
int len;
int rc;
char *res;
char *esc_ustr;
mu_vartab_t vtab;
if (!query)
return NULL;
esc_ustr = sql_escape_string (ustr);
/* Compute resulting query length */
for (len = 0, p = (char *) query; *p; )
{
if (*p == '%')
{
if (p[1] == 'u')
{
len += strlen (esc_ustr);
p += 2;
}
else if (p[1] == '%')
{
len++;
p += 2;
}
else
{
len++;
p++;
}
}
else
{
len++;
p++;
}
}
res = malloc (len + 1);
if (!res)
{
free (esc_ustr);
return res;
}
for (p = (char *) query, q = res; *p; )
{
if (*p == '%')
{
switch (*++p)
{
case 'u':
strcpy (q, esc_ustr);
q += strlen (q);
p++;
break;
case '%':
*q++ = *p++;
break;
default:
*q++ = *p++;
}
}
else
*q++ = *p++;
}
*q = 0;
mu_vartab_create (&vtab);
mu_vartab_define (vtab, "user", ustr, 1);
mu_vartab_define (vtab, "u", ustr, 1);
rc = mu_vartab_expand (vtab, query, &res);
if (rc)
res = NULL;
mu_vartab_destroy (&vtab);
free (esc_ustr);
return res;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2004, 2007 Free Software Foundation, Inc.
2004, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -19,6 +19,7 @@
#include <mailutils/acl.h>
#include <mailutils/address.h>
#include <mailutils/assoc.h>
#include <mailutils/argcv.h>
#include <mailutils/attribute.h>
#include <mailutils/auth.h>
......
......@@ -144,7 +144,9 @@ mu_tcpwrapper_access (int fd)
int
mu_tcp_wrapper_prefork (int fd, void *data, struct sockaddr *sa, int salen)
{
if (mu_tcp_wrapper_enable && !mu_tcpwrapper_access (fd))
if (mu_tcp_wrapper_enable
&& sa->sa_family == AF_INET
&& !mu_tcpwrapper_access (fd))
{
char *p = mu_sockaddr_to_astr (sa, salen);
mu_error (_("Access from %s blocked by TCP wrappers."), p);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 Free Software Foundation, Inc.
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -77,6 +77,10 @@ mu_app_init (struct argp *myargp, const char **capa,
mu_argp_done (argp);
if (rc)
return rc;
/* Reset program name, it may have been changed using the `--program-name'
option. */
mu_set_program_name (program_invocation_name);
mu_libcfg_init (excapa);
free (excapa);
......
/* This file is part of GNU Mailutils
Copyright (C) 2007 Free Software Foundation, Inc.
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
......@@ -52,7 +52,7 @@ cb_field_map (mu_debug_t debug, void *data, char *arg)
static struct mu_cfg_param mu_sql_param[] = {
{ "interface", mu_cfg_string, &sql_settings.interface, 0, NULL,
N_("Set SQL interface to use (one of: mysql, odbc, or postgres).") },
{ "getwpnam", mu_cfg_string, &sql_settings.getpwnam_query, 0, NULL,
{ "getpwnam", mu_cfg_string, &sql_settings.getpwnam_query, 0, NULL,
N_("SQL query to use for getpwnam requests."),
N_("query") },
{ "getpwuid", mu_cfg_string, &sql_settings.getpwuid_query, 0, NULL,
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2007 Free Software Foundation, Inc.
2004, 2005, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -63,6 +63,7 @@ struct _amd_message
struct _amd_data
{
size_t msg_size; /* Size of struct _amd_message */
int (*create) (struct _amd_data *, int flags);
int (*msg_init_delivery) (struct _amd_data *, struct _amd_message *);
int (*msg_finish_delivery) (struct _amd_data *, struct _amd_message *);
void (*msg_free) (struct _amd_message *);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2007 Free Software Foundation, Inc.
2004, 2005, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -404,7 +404,7 @@ maildir_delete_file (char *dirname, char *filename)
int
static int
maildir_opendir (DIR **dir, char *name, int permissions)
{
*dir = opendir (name);
......@@ -424,6 +424,25 @@ maildir_opendir (DIR **dir, char *name, int permissions)
return 0;
}
static int
maildir_create (struct _amd_data *amd, int flags)
{
static char *dirs[] = { TMPSUF, NEWSUF, CURSUF };
int i;
for (i = 0; i < 3; i++)
{
DIR *dir;
char *tmpname = maildir_mkfilename (amd->name, dirs[i], NULL);
int rc = maildir_opendir (&dir, tmpname, PERMS);
if (rc)
return rc;
closedir (dir);
free (tmpname);
}
return 0;
}
#define NTRIES 30
......@@ -738,6 +757,7 @@ _mailbox_maildir_init (mu_mailbox_t mailbox)
amd->msg_size = sizeof (struct _maildir_message);
amd->msg_free = maildir_msg_free;
amd->create = maildir_create;
amd->msg_init_delivery = maildir_msg_init;
amd->msg_finish_delivery = maildir_msg_finish_delivery;
amd->cur_msg_file_name = maildir_cur_message_name;
......
......@@ -335,10 +335,14 @@ amd_open (mu_mailbox_t mailbox, int flags)
{
if ((flags & MU_STREAM_CREAT) && errno == ENOENT)
{
int rc;
if (mkdir (amd->name, S_IRUSR|S_IWUSR|S_IXUSR))
return errno;
if (stat (amd->name, &st) < 0)
return errno;
if (amd->create && (rc = amd->create (amd, flags)))
return rc;
}
else
return errno;
......
......@@ -488,7 +488,8 @@ _cb_include (mu_debug_t debug, void *data, char *arg)
if (S_ISDIR (sb.st_mode))
{
char *file = make_file_name (dirname, idp->progname);
ret = mu_get_config (file, idp->progname, idp->progparam, 0,
ret = mu_get_config (file, idp->progname, idp->progparam,
idp->flags & ~MU_PARSE_CONFIG_GLOBAL,
idp->target);
}
else
......@@ -513,13 +514,11 @@ _cb_include (mu_debug_t debug, void *data, char *arg)
}
struct mu_cfg_cont *
mu_build_container (const char *progname,
struct mu_cfg_param *progparam, int flags, void *target)
mu_build_container (const char *progname, struct include_data *idp)
{
struct mu_cfg_cont *cont = root_container;
struct include_data idata;
struct mu_cfg_param mu_include_param[] = {
{ "include", mu_cfg_callback, &idata, 0, _cb_include,
{ "include", mu_cfg_callback, NULL, 0, _cb_include,
N_("Include contents of the given file. If a directory is given, "
"include contents of the file <file>/<program>, where <program> is "
"the name of the program. This latter form is allowed only in "
......@@ -527,25 +526,23 @@ mu_build_container (const char *progname,
N_("file-or-directory") },
{ NULL }
};
mu_include_param[0].data = idp;
mu_config_clone_container (cont);
idata.progname = progname;
idata.progparam = progparam;
idata.flags = flags & MU_PARSE_CONFIG_GLOBAL;
idata.target = target;
_mu_config_register_section (&cont, NULL, NULL, NULL,
(void*) progname, mu_include_param, NULL);
if (flags & MU_PARSE_CONFIG_GLOBAL)
if (idp->flags & MU_PARSE_CONFIG_GLOBAL)
{
mu_iterator_t iter;
struct mu_cfg_section *prog_sect;
struct mu_cfg_cont *old_root = root_container;
static struct mu_cfg_param empty_param = { NULL };
if (!progparam)
progparam = &empty_param;
_mu_config_register_section (&cont, NULL, "program", progname,
prog_parser, progparam, &prog_sect);
prog_parser,
idp->progparam ?
idp->progparam : &empty_param,
&prog_sect);
if (old_root->v.section.children)
{
......@@ -562,9 +559,9 @@ mu_build_container (const char *progname,
mu_iterator_destroy (&iter);
}
}
else if (progparam)
else if (idp->progparam)
_mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
progparam, NULL);
idp->progparam, NULL);
return cont;
}
......@@ -577,8 +574,16 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname,
if (root_container)
{
struct mu_cfg_cont *cont = mu_build_container (progname, progparam,
flags, target_ptr);
struct include_data idata;
struct mu_cfg_cont *cont;
idata.progname = progname;
idata.progparam = progparam;
idata.flags = flags;
idata.target = target_ptr;
cont = mu_build_container (progname, &idata);
rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr,
(void*) progname);
mu_config_destroy_container (&cont);
......@@ -601,8 +606,14 @@ void
mu_format_config_tree (mu_stream_t stream, const char *progname,
struct mu_cfg_param *progparam, int flags)
{
struct mu_cfg_cont *cont = mu_build_container (progname, progparam, flags,
NULL);
struct include_data idata;
struct mu_cfg_cont *cont;
idata.progname = progname;
idata.progparam = progparam;
idata.flags = flags;
idata.target = NULL;
cont = mu_build_container (progname, &idata);
mu_cfg_format_container (stream, cont);
mu_config_destroy_container (&cont);
}
......
......@@ -416,7 +416,7 @@ mu_ip_tcp_accept (mu_ip_server_t srv, void *call_data)
IDENTSTR (srv), strerror (rc));
if (res == mu_acl_result_deny)
{
char *p = mu_sockaddr_to_astr (srv->addr, srv->addrlen);
char *p = mu_sockaddr_to_astr (&client.sa, size);
mu_diag_output (MU_DIAG_INFO, "Denying connection from %s", p);
free (p);
......
......@@ -632,8 +632,8 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
children++;
}
}
else if (pconf->msrv->prefork
&& pconf->msrv->prefork (fd, pconf->msrv->data, sa, salen) == 0)
else if (!pconf->msrv->prefork
|| pconf->msrv->prefork (fd, pconf->msrv->data, sa, salen) == 0)
pconf->msrv->conn (fd, sa, salen, pconf->msrv->data, srv,
pconf->timeout, pconf->transcript);
return 0;
......