2000-12-13 13:19:03 +00:00
|
|
|
/*
|
2000-12-13 15:35:14 +00:00
|
|
|
$Source$
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2000 by CyberSolutions GmbH, Germany.
|
|
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
This file is part of Petidomo.
|
2000-12-13 15:35:14 +00:00
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
Petidomo is free software; you can redistribute it and/or modify
|
2000-12-13 15:35:14 +00:00
|
|
|
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.
|
|
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
Petidomo is distributed in the hope that it will be useful, but
|
2000-12-13 15:35:14 +00:00
|
|
|
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.
|
|
|
|
|
*/
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2000-12-16 13:11:54 +00:00
|
|
|
#include "libargv/argv.h"
|
2001-01-19 12:49:44 +00:00
|
|
|
#include "libtext/text.h"
|
2000-12-13 15:35:14 +00:00
|
|
|
#include "petidomo.h"
|
2000-12-13 13:19:03 +00:00
|
|
|
|
2001-01-19 15:01:19 +00:00
|
|
|
#define _VERSION_C_AS_HEADER_
|
|
|
|
|
#include "version.c"
|
|
|
|
|
#undef _VERSION_C_AS_HEADER_
|
|
|
|
|
|
2000-12-13 13:19:03 +00:00
|
|
|
#ifndef LOG_PERROR
|
|
|
|
|
# define LOG_PERROR 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-01-08 15:55:07 +00:00
|
|
|
static char* listname = NULL;
|
|
|
|
|
static char* mode = NULL;
|
|
|
|
|
static char* masterconfig_path = SYSCONFDIR "/petidomo.conf";
|
2001-01-15 17:06:48 +00:00
|
|
|
char g_is_approved = ARGV_FALSE;
|
2001-01-19 12:49:44 +00:00
|
|
|
const char* who_am_i;
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char * argv[])
|
2000-12-13 15:35:14 +00:00
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
const struct PD_Config * MasterConfig;
|
|
|
|
|
char * incoming_mail;
|
2000-12-16 13:11:54 +00:00
|
|
|
argv_t args[] =
|
|
|
|
|
{
|
|
|
|
|
{ARGV_MAND, "mode", ARGV_CHAR_P, &mode, "mode", "listserv, deliver, or approve."},
|
2001-01-08 20:36:19 +00:00
|
|
|
{ARGV_MAYBE, "listname", ARGV_CHAR_P, &listname, "listname", "Default mailing list."},
|
2001-01-08 15:55:07 +00:00
|
|
|
{ARGV_MAYBE, "masterconf", ARGV_CHAR_P, &masterconfig_path, "masterconf", "Path to petidomo.conf."},
|
2001-01-15 17:06:48 +00:00
|
|
|
{ARGV_MAYBE, "approved", ARGV_BOOL, &g_is_approved, "approved", "approved flag."},
|
2000-12-13 13:19:03 +00:00
|
|
|
{ARGV_LAST}
|
2000-12-16 13:11:54 +00:00
|
|
|
};
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
/* Init logging routines first of all, so that we can report
|
|
|
|
|
errors. */
|
|
|
|
|
|
2000-12-16 13:11:54 +00:00
|
|
|
openlog("petidomo", LOG_CONS | LOG_PID | LOG_PERROR, LOG_MAIL);
|
2000-12-13 13:19:03 +00:00
|
|
|
|
2001-01-19 12:49:44 +00:00
|
|
|
/* Store our full path and program name in who_am_I, so that
|
|
|
|
|
queue_posting() and queue_command() know where to find the
|
|
|
|
|
Petidomo binary. */
|
|
|
|
|
|
|
|
|
|
if (argv[0][0] == '/')
|
|
|
|
|
{
|
|
|
|
|
who_am_i = argv[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char buf[4096];
|
|
|
|
|
if (getcwd(buf, sizeof(buf)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_CRIT, "Failed to get the path to my current working directory.");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
who_am_i = text_easy_sprintf("%s/%s", buf, argv[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-19 13:05:13 +00:00
|
|
|
/* Set our real user id equal to the effective user id to avoid
|
|
|
|
|
confusion in case we're started as a setuid binary. */
|
|
|
|
|
|
|
|
|
|
setreuid(geteuid(), geteuid());
|
|
|
|
|
|
2000-12-13 13:19:03 +00:00
|
|
|
/* Parse the command line. */
|
|
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
argv_help_string = "Petidomo Mailing List Server";
|
2001-01-19 15:01:19 +00:00
|
|
|
argv_version_string = (char *)petidomo_version.v_gnu;
|
2000-12-13 13:19:03 +00:00
|
|
|
argv_process(args, argc, argv);
|
|
|
|
|
|
2001-01-19 14:26:48 +00:00
|
|
|
/* Log a few helpful facts about this Petidomo instance. */
|
|
|
|
|
|
2001-01-19 15:08:26 +00:00
|
|
|
syslog(LOG_DEBUG, "%s starting up; mode=%s, listname=%s, masterconf=%s, approved=%s, ruid=%d, euid=%d, gid=%d, egid=%d",
|
|
|
|
|
(char *)petidomo_version.v_gnu, mode, listname, masterconfig_path, (g_is_approved) ? "true" : "false",
|
|
|
|
|
getuid(), geteuid(), getgid(), getegid());
|
2001-01-19 14:26:48 +00:00
|
|
|
|
2000-12-13 13:19:03 +00:00
|
|
|
/* Init Petidomo's internal stuff. */
|
|
|
|
|
|
2001-01-08 15:55:07 +00:00
|
|
|
if (InitPetidomo(masterconfig_path) != 0) {
|
2000-12-13 13:19:03 +00:00
|
|
|
syslog(LOG_CRIT, "Failed to initialize my internals.");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
MasterConfig = getMasterConfig();
|
|
|
|
|
|
|
|
|
|
/* Load the file from standard input and save it, so that it isn't
|
|
|
|
|
lost in case of an error. */
|
|
|
|
|
|
|
|
|
|
incoming_mail = LoadFromDescriptor(STDIN_FILENO);
|
|
|
|
|
if (incoming_mail == NULL) {
|
|
|
|
|
syslog(LOG_ERR, "Failed to read incoming mail from standard input.");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now decide what we actually do with the mail. */
|
|
|
|
|
|
2000-12-16 13:11:54 +00:00
|
|
|
if (strcasecmp("listserv", mode) == 0)
|
2001-01-15 17:06:48 +00:00
|
|
|
listserv_main(incoming_mail, listname);
|
2000-12-16 13:11:54 +00:00
|
|
|
else if (strcasecmp("deliver", mode) == 0)
|
2000-12-13 15:35:14 +00:00
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
if (listname != NULL)
|
2001-01-15 17:06:48 +00:00
|
|
|
hermes_main(incoming_mail, listname);
|
2000-12-13 15:35:14 +00:00
|
|
|
else
|
|
|
|
|
{
|
2000-12-16 13:11:54 +00:00
|
|
|
syslog(LOG_ERR, "Wrong command line syntax; deliver mode requires a parameter.");
|
2000-12-13 13:19:03 +00:00
|
|
|
exit(1);
|
2000-12-13 15:35:14 +00:00
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
}
|
2001-01-15 18:48:49 +00:00
|
|
|
else if (strcasecmp("approve", mode) == 0)
|
|
|
|
|
{
|
|
|
|
|
approve_main(incoming_mail);
|
|
|
|
|
}
|
2000-12-13 15:35:14 +00:00
|
|
|
else
|
|
|
|
|
{
|
2000-12-16 13:11:54 +00:00
|
|
|
syslog(LOG_ERR, "I don't know anything about mode \"%s\".", mode);
|
2000-12-13 13:19:03 +00:00
|
|
|
exit(1);
|
2000-12-13 15:35:14 +00:00
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
/* Exit gracefully. */
|
|
|
|
|
|
|
|
|
|
return 0;
|
2000-12-13 15:35:14 +00:00
|
|
|
}
|