Commit f949b9c5 f949b9c591afe6e0b2ef5874f49d69f168f0cf45 by Sergey Poznyakoff

* comsat/Makefile.am: Remove cfg.c

* comsat/cfg.c: Remove.
* comsat/comsat.c: Use MU configuration and acls.
* comsat/comsat.h: Include acl.h
* libproto/maildir/mbox.c (maildir_qfetch): Bugfix.
1 parent 643be57e
2007-12-30 Sergey Poznyakoff <gray@gnu.org.ua>
* examples/config/comsat.conf: Remove obsolete example file.
* examples/config/mailutils.rc: Remove obsolete example file.
* comsat/oldcfg.c: New file.
* comsat/Makefile.am: Add oldcfg.c.
* comsat/comsat.c: Handle old -c option and provide a new option
for converting old-style config file to the new format.
* comsat/Makefile.am: Remove cfg.c
* comsat/cfg.c: Remove.
* comsat/comsat.c: Use MU configuration and acls.
......
......@@ -21,7 +21,8 @@ INCLUDES = @MU_COMMON_INCLUDES@
sbin_PROGRAMS = comsatd
comsatd_SOURCES = action.c comsat.c comsat.h
comsatd_SOURCES = action.c comsat.c comsat.h oldcfg.c
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
comsatd_LDADD = \
${MU_APP_LIBRARIES}\
......
......@@ -58,12 +58,15 @@ static char doc[] = "GNU comsatd";
static struct argp_option options[] =
{
{ "config", 'c', N_("FILE"), 0, N_("Read configuration from FILE"), 0 },
{ "config", 'c', N_("FILE"), OPTION_HIDDEN, "", 0 },
{ "convert-config", 'C', N_("FILE"), 0,
N_("Convert the configuration FILE to new format."), 0 },
{ "test", 't', NULL, 0, N_("Run in test mode"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t comsatd_parse_opt (int key, char *arg, struct argp_state *state);
static error_t comsatd_parse_opt (int key, char *arg,
struct argp_state *state);
static struct argp argp = {
options,
......@@ -119,25 +122,6 @@ static int xargc;
static char **xargv;
int test_mode;
static error_t
comsatd_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'c':
/* FIXME: convert config to the new format and parse it */
break;
case 't':
test_mode = 1;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct mu_cfg_param comsat_cfg_param[] = {
{ "allow-biffrc", mu_cfg_bool, &allow_biffrc, 0, NULL,
N_("Read .biffrc file from the user home directory") },
......@@ -159,6 +143,48 @@ struct mu_cfg_param comsat_cfg_param[] = {
{ NULL }
};
static error_t
comsatd_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'c':
{
char *cfg;
int fd;
FILE *fp;
mu_diag_output (MU_DIAG_WARNING,
_("The old configuration file format and the --config command\n"
"line option are deprecated and will be removed in the future\n"
"release. Please use --convert-config option to convert your\n"
"settings to the new format."));
/* FIXME: Refer to the docs */
fd = mu_tempfile (NULL, &cfg);
fp = fdopen (fd, "w");
convert_config (arg, fp);
fclose (fp);
mu_get_config (cfg, mu_program_name, comsat_cfg_param, 0, NULL);
unlink (cfg);
free (cfg);
}
break;
case 'C':
convert_config (arg, stdout);
exit (0);
case 't':
test_mode = 1;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
int
main (int argc, char **argv)
{
......
......@@ -79,3 +79,5 @@ extern char hostname[];
extern struct daemon_param daemon_param;
void run_user_action (FILE *tty, const char *cr, mu_message_t msg);
void convert_config (const char *config_file, FILE *outfile);
......
/* This file is part of GNU Mailutils.
Copyright (C) 1998, 2001, 2002, 2005, 2007 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 published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils; see the file COPYING. If not, write
to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301 USA. */
#include "comsat.h"
static int
print_and_free_acl (void *item, void *data)
{
FILE *outfile = data;
char **argv = item;
fprintf (outfile, " %s from %s;\n", argv[1], argv[2]);
mu_argv_free (argv);
return 0;
}
void
convert_config (const char *config_file, FILE *outfile)
{
FILE *fp;
int line;
char buf[128];
char *ptr;
mu_list_t aclist = NULL;
if (!config_file)
return;
fp = fopen (config_file, "r");
if (!fp)
{
mu_error (_("Cannot open config file %s: %s"), config_file,
mu_strerror (errno));
return;
}
fprintf (outfile,
"# Configuration file for GNU comsatd, converted from %s\n",
config_file);
fprintf (outfile,
"# Copy it to the comsatd configuration file\n");
fprintf (outfile,
"# or to %s/mailutils.rc, in section `program %s'\n\n",
SYSCONFDIR, mu_program_name);
line = 0;
while ((ptr = fgets (buf, sizeof buf, fp)))
{
int len;
int argc;
char **argv;
line++;
len = strlen (ptr);
if (len > 0 && ptr[len-1] == '\n')
ptr[--len] = 0;
while (*ptr && isspace (*ptr))
ptr++;
if (!*ptr || *ptr == '#')
{
fprintf (outfile, "%s\n", ptr);
continue;
}
mu_argcv_get (ptr, "", NULL, &argc, &argv);
if (argc < 2)
{
mu_error (_("%s:%d: too few fields"), config_file, line);
mu_argcv_free (argc, argv);
continue;
}
if (strcmp (argv[0], "acl") == 0)
{
if (!aclist)
mu_list_create (&aclist);
mu_list_append (aclist, argv);
}
else
{
mu_argcv_free (argc, argv);
fprintf (outfile, "%s;\n", ptr);
}
}
fclose (fp);
if (aclist)
{
fprintf (outfile, "acl {\n");
mu_list_do (aclist, print_and_free_acl, outfile);
fprintf (outfile, "};\n");
mu_list_destroy (&aclist);
}
}
# This is an example configuration file for GNU comsatd utility.
# To use, run comsatd -c <path>/comsat.conf
## General settings
# Dump on screen at most 5 lines of the message body
max-lines 5
# Honour per-user .biffrc files
allow-biffrc yes
## Security settings
# Allow no more than 10 requests in 10 seconds, then register overflow.
max-requests 10
request-control-interval 10
# Sleep for 5 seconds when the first overflow occurs.
overflow-delay-time 5
# If two overflows happen within a 15 seconds interval, double the
# sleep time.
overflow-control-interval 15
## Access Control Lists
acl allow 127.0.0.1
acl deny any
## This is a sample mailutils configuration file
## Upon startup, a mailutils program scans this file for a line that
## begins either with a program name or with word `mailutils'. When
## found, the rest of the line following the first word is split up
## at whitespace characters and resulting words are added to the
## program arguments _before_ the command line options.
:mailutils --maildir /var/spool/mail
:auth --sql-host sql.sample.net --sql-db Passwd \
--sql-port 3306 --sql-user mailutils \
--sql-passwd guessme \
--sql-getpwnam 'select user_name,password,uid,10000,"/dev/null","/dev/null" from pass where user_name="%u" and service="EMAIL"' \
--sql-getpwuid 'select user_name,password,uid,10000,"/dev/null","/dev/null" from pass where uid=%u and service="EMAIL"'
imap4d --daemon=20 --timeout=1800
mail.local --source %h/.filter.scm
......@@ -42,7 +42,9 @@ extern int mu_argcv_get_np (const char *command, int len,
int *pargc, char ***pargv, char **endp);
extern int mu_argcv_string (int argc, char **argv, char **string);
extern int mu_argcv_free (int argc, char **argv);
extern void mu_argcv_free (int argc, char **argv);
extern void mu_argv_free (char **argv);
extern int mu_argcv_unquote_char (int c);
extern int mu_argcv_quote_char (int c);
extern size_t mu_argcv_quoted_length (const char *str, int *quote);
......
......@@ -30,7 +30,8 @@
#define argcv_get_n mu_argcv_get_n
#define argcv_get_np mu_argcv_get_np
#define argcv_string mu_argcv_string
#define argcv_free mu_argcv_free
#define argcv_free mu_argcv_free
#define argv_free mu_argv_free
#define argcv_unquote_char mu_argcv_unquote_char
#define argcv_quote_char mu_argcv_quote_char
#define argcv_quoted_length mu_argcv_quoted_length
......@@ -443,14 +444,23 @@ argcv_get (const char *command, const char *delim, const char *cmnt,
* argc is the number of elements
* argv is the array
*/
int
void
argcv_free (int argc, char **argv)
{
while (--argc >= 0)
if (argv[argc])
free (argv[argc]);
free (argv);
return 0;
}
void
argv_free (char **argv)
{
int i;
for (i = 0; argv[i]; i++)
free (argv[i]);
free (argv);
}
/* Make a argv an make string separated by ' '. */
......
......@@ -585,7 +585,7 @@ mu_parse_config (const char *file, const char *progname,
if (access (full_name, R_OK) == 0)
{
rc = mu_get_config (full_name, progname, progparam, flags,
target_ptr);
target_ptr);
free (full_name);
}
else
......