Commit 3dc97482 3dc974822b70bec356ef67234667a85033260e1b by Sergey Poznyakoff

Added to repository

1 parent d81db5ae
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program 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 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <mu_scm.h>
static void _scheme_main (void *closure, int argc, char **argv);
void
mu_process_mailbox (int argc, char *argv[], guimb_param_t *param)
{
scm_boot_guile (argc, argv, _scheme_main, param);
}
SCM _current_mailbox;
SCM _user_name;
static SCM
catch_body (void *closure)
{
guimb_param_t *param = closure;
return param->catch_body (param->data, param->mbox);
}
void
_scheme_main (void *closure, int argc, char **argv)
{
guimb_param_t *param = closure;
SCM *scm_loc;
if (param->debug_guile)
{
SCM_DEVAL_P = 1;
SCM_BACKTRACE_P = 1;
SCM_RECORD_POSITIONS_P = 1;
SCM_RESET_DEBUG_MODE;
}
/* Initialize scheme library */
mu_scm_init ();
/* Provide basic primitives */
#include <mu_guimb.x>
_current_mailbox = mu_scm_mailbox_create (param->mbox);
scm_loc = SCM_CDRLOC (scm_sysintern ("current-mailbox", SCM_EOL));
*scm_loc = _current_mailbox;
_user_name = param->user_name ?
scm_makfrom0str (param->user_name) : SCM_BOOL_F;
scm_loc = SCM_CDRLOC (scm_sysintern ("user-name", SCM_EOL));
*scm_loc = _user_name;
if (param->init)
param->init (param->data);
do {
scm_internal_lazy_catch (SCM_BOOL_T,
catch_body, closure,
param->catch_handler, param->data);
} while (param->next && param->next (param->data, param->mbox));
if (param->exit)
exit (param->exit (param->data, param->mbox));
exit (0);
}
AUTOMAKE_OPTIONS = ../lib/ansi2knr
INCLUDES =-I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)/libmu_scm
libexec_PROGRAMS = mail.local
mail_local_SOURCES = main.c mailquota.c script.c mail.local.h
mail_local_LDADD = @LIBMU_SCM@ ../mailbox/libmailbox.la ../lib/libmailutils.a @GUILE_LIBS@
install-exec-hook:
for i in $(libexec_PROGRAMS); do\
chown root:mail $(libexecdir)/$$i;\
chmod 4755 $(libexecdir)/$$i;\
done
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program 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 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include <pwd.h>
#include <grp.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sysexits.h>
#include "getopt.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/mailbox.h>
#include <mailutils/message.h>
#include <mailutils/error.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/mutil.h>
#include <mu_dbm.h>
/* Debug */
extern int debug_level;
#define dbg() if (debug_level) debug
/* mailquota settings */
#define MQUOTA_OK 0
#define MQUOTA_EXCEEDED 1
#define MQUOTA_UNLIMITED 2
struct mda_data
{
FILE *fp;
char *progfile;
char *progfile_pattern;
char **argv;
char *tempfile;
};
extern char *quotadbname;
extern int exit_code;
extern void setgroupquota (char *str);
extern int check_quota (char *name, size_t size, size_t *rest);
int mda (FILE *fp, char *username, mailbox_t mbox);
char *make_progfile_name (char *pattern, char *username);
#ifdef WITH_GUILE
int prog_mda (struct mda_data *data);
#endif
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program 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 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <mail.local.h>
#ifdef USE_DBM
#define DEFRETVAL MQUOTA_UNLIMITED
size_t groupquota = 5*1024*1024UL;
static int get_size (char *, size_t *, char **);
int
get_size (char *str, size_t *size, char **endp)
{
size_t s;
s = strtol (str, &str, 0);
switch (*str)
{
case 0:
break;
case 'k':
case 'K':
s *= 1024;
break;
case 'm':
case 'M':
s *= 1024*1024;
break;
default:
*endp = str;
return -1;
}
*size = s;
return 0;
}
int
check_quota (char *name, size_t size, size_t *rest)
{
DBM_FILE db;
DBM_DATUM named, contentd;
size_t quota;
char buffer[64];
int unlimited = 0;
int rc;
if (!quotadbname || mu_dbm_open (quotadbname, &db, MU_STREAM_READ, 0600))
return DEFRETVAL;
memset (&named, 0, sizeof named);
MU_DATUM_PTR (named) = name;
MU_DATUM_SIZE (named) = strlen (name);
rc = mu_dbm_fetch (db, named, &contentd);
if (rc || !MU_DATUM_PTR (contentd))
{
/* User not in database, try default quota */
memset (&named, 0, sizeof named);
MU_DATUM_PTR (named) = "DEFAULT";
MU_DATUM_SIZE (named) = strlen ("DEFAULT");
rc = mu_dbm_fetch (db, named, &contentd);
if (rc)
{
//mu_error("can't fetch data: %s", strerror (rc));
return DEFRETVAL;
}
if (!MU_DATUM_PTR (contentd))
return DEFRETVAL;
}
if (strncasecmp("none",
MU_DATUM_PTR (contentd),
MU_DATUM_SIZE (contentd)) == 0)
unlimited = 1;
else if (MU_DATUM_SIZE (contentd) > sizeof(buffer)-1)
{
mu_error ("mailbox quota for `%s' is too big: %d digits",
name, MU_DATUM_SIZE (contentd));
quota = groupquota;
}
else
{
char *p;
strncpy(buffer, MU_DATUM_PTR (contentd), MU_DATUM_SIZE (contentd));
buffer[MU_DATUM_SIZE (contentd)] = 0;
quota = strtoul (buffer, &p, 0);
if (get_size (buffer, &quota, &p))
{
mu_error ("bogus mailbox quota for `%s' (near `%s')", name, p);
quota = groupquota;
}
}
mu_dbm_close (db);
if (unlimited)
return MQUOTA_UNLIMITED;
else if (quota < size) /* Mailbox full */
return MQUOTA_EXCEEDED;
if (rest)
*rest = quota - size;
return MQUOTA_OK;
}
#endif
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program 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 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <mail.local.h>
#ifdef WITH_GUILE
#include <mu_scm.h>
SCM mda_catch_body (void *data, mailbox_t mbox);
SCM mda_catch_handler (void *unused, SCM tag, SCM throw_args);
int mda_next (void *data, mailbox_t mbox);
int mda_exit (void *data, mailbox_t mbox);
int mda_init (void *data);
int
prog_mda (struct mda_data *data)
{
char *x_argv[2];
guimb_param_t param;
mailbox_t mbox;
x_argv[0] = "mail.local";
x_argv[1] = NULL;
fflush (data->fp);
if (mailbox_create (&mbox, data->tempfile)
|| mailbox_open (mbox, MU_STREAM_RDWR) != 0)
{
mailer_err ("can't open temporary storage");
return EX_UNAVAILABLE;
}
unlink (data->tempfile);
param.debug_guile = 1 /*FIXME*/;
param.mbox = mbox;
param.user_name = NULL;
param.init = mda_init;
param.catch_body = mda_catch_body;
param.catch_handler = mda_catch_handler;
param.next = mda_next;
param.exit = mda_exit;
param.data = data;
mu_process_mailbox (1, x_argv, &param);
return EX_UNAVAILABLE;
}
int
mda_init (void *data)
{
struct mda_data *md = data;
md->progfile = make_progfile_name (md->progfile_pattern, md->argv[0]);
return 0;
}
SCM
mda_catch_body (void *data, mailbox_t mbox)
{
struct mda_data *md = data;
if (access (md->progfile, R_OK))
{
syslog (LOG_ERR, "access to %s failed: %m", md->progfile);
}
else
scm_primitive_load (scm_makfrom0str (md->progfile));
mda (md->fp, md->argv[0], mbox);
return SCM_BOOL_F;
}
SCM
mda_catch_handler (void *data, SCM tag, SCM throw_args)
{
exit_code = EX_TEMPFAIL;
return scm_handle_by_message_noexit ("mail.local", tag, throw_args);
}
int
mda_next (void *data, mailbox_t mbox)
{
struct mda_data *md = data;
message_t mesg = NULL;
attribute_t attr = NULL;
md->argv++;
if (*md->argv == NULL)
return 0;
if (md->progfile)
free (md->progfile);
md->progfile = make_progfile_name (md->progfile_pattern, *md->argv);
mailbox_get_message (mbox, 1, &mesg);
message_get_attribute (mesg, &attr);
attribute_unset_deleted (attr);
return md->progfile != NULL;
}
int
mda_exit (void *data, mailbox_t mbox)
{
return exit_code;
}
#endif