head 1.20; access; symbols PETIDOMO_4_0b6:1.20 PETIDOMO_4_0b5:1.20 PETIDOMO_4_0b4:1.20 PETIDOMO_4_0b3:1.20 BEFORETHL:1.20 petidomo-2-2:1.1.1.1 petidomo:1.1.1; locks; strict; comment @ * @; 1.20 date 2001.02.17.21.59.17; author simons; state Exp; branches; next 1.19; 1.19 date 2001.01.21.12.00.35; author rse; state Exp; branches; next 1.18; 1.18 date 2001.01.20.13.52.41; author rse; state Exp; branches; next 1.17; 1.17 date 2001.01.20.11.19.14; author rse; state Exp; branches; next 1.16; 1.16 date 2001.01.19.15.27.58; author simons; state Exp; branches; next 1.15; 1.15 date 2001.01.19.15.08.26; author simons; state Exp; branches; next 1.14; 1.14 date 2001.01.19.15.01.19; author rse; state Exp; branches; next 1.13; 1.13 date 2001.01.19.14.26.48; author simons; state Exp; branches; next 1.12; 1.12 date 2001.01.19.14.09.48; author simons; state Exp; branches; next 1.11; 1.11 date 2001.01.19.13.05.13; author simons; state Exp; branches; next 1.10; 1.10 date 2001.01.19.12.49.44; author simons; state Exp; branches; next 1.9; 1.9 date 2001.01.18.20.30.50; author rse; state Exp; branches; next 1.8; 1.8 date 2001.01.15.18.48.49; author simons; state Exp; branches; next 1.7; 1.7 date 2001.01.15.17.06.48; author simons; state Exp; branches; next 1.6; 1.6 date 2001.01.15.16.27.52; author simons; state Exp; branches; next 1.5; 1.5 date 2001.01.08.20.36.19; author simons; state Exp; branches; next 1.4; 1.4 date 2001.01.08.15.55.07; author simons; state Exp; branches; next 1.3; 1.3 date 2000.12.16.13.11.54; author simons; state Exp; branches; next 1.2; 1.2 date 2000.12.13.15.35.14; author simons; state Exp; branches; next 1.1; 1.1 date 2000.12.13.13.19.24; author simons; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2000.12.13.13.19.24; author simons; state Exp; branches; next ; desc @@ 1.20 log @Added check whether the required listname parameter is there _before_ we try and read the mail from standard input. @ text @/* $Source: /e/ossp/cvs/ossp-pkg/petidomo/main.c,v $ $Revision: 1.19 $ Copyright (C) 2000 by CyberSolutions GmbH, Germany. This file is part of Petidomo. Petidomo 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. Petidomo 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. */ #include #include #include #include #include #include "libargv/argv.h" #include "libtext/text.h" #include "petidomo.h" #define _VERSION_C_AS_HEADER_ #include "version.c" #undef _VERSION_C_AS_HEADER_ #ifndef LOG_PERROR # define LOG_PERROR 0 #endif static char* listname = NULL; static char* mode = NULL; char* masterconfig_path = SYSCONFDIR "/petidomo.conf"; char g_is_approved = ARGV_FALSE; const char* who_am_i; int main(int argc, char * argv[]) { const struct PD_Config * MasterConfig; char * incoming_mail; argv_t args[] = { {ARGV_MAND, "mode", ARGV_CHAR_P, &mode, "mode", "listserv, deliver, approve or dump."}, {ARGV_MAYBE, "listname", ARGV_CHAR_P, &listname, "listname", "Default mailing list."}, {ARGV_MAYBE, "masterconf", ARGV_CHAR_P, &masterconfig_path, "masterconf", "Path to petidomo.conf."}, {ARGV_MAYBE, "approved", ARGV_BOOL, &g_is_approved, "approved", "approved flag."}, {ARGV_LAST} }; /* Init logging routines first of all, so that we can report errors. */ openlog("petidomo", LOG_CONS | LOG_PID | LOG_PERROR, LOG_MAIL); /* 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]); } /* 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()); /* Parse the command line. */ argv_help_string = "Petidomo Mailing List Server"; argv_version_string = (char *)petidomo_version.v_gnu; argv_process(args, argc, argv); /* Make sure we got all required parameters. */ if ((!strcasecmp(mode, "deliver") || !strcasecmp(mode, "dump")) && listname == NULL) { fprintf(stderr, "petidomo: %s mode requires a list name argument\n", mode); exit(1); } /* Member Dump Mode */ if (strcasecmp(mode, "dump") == 0) { char *cp; const struct List_Config *ListConfig; if (InitPetidomo(masterconfig_path) != 0) { fprintf(stderr, "petidomo: failed load master configuration.\n"); exit(1); } MasterConfig = getMasterConfig(); ListConfig = getListConfig(listname); if ((cp = loadfile(ListConfig->address_file)) == NULL) { fprintf(stderr, "petidomo: failed to open file \"%s\"\n", ListConfig->address_file); exit(1); } fwrite(cp, strlen(cp), 1, stdout); free(cp); exit(0); } /* Log a few helpful facts about this Petidomo instance. */ syslog(LOG_DEBUG, "%s starting up; mode=%s, listname=%s, masterconf=%s, approved=%s, ruid=%d, euid=%d, gid=%d, egid=%d", petidomo_version.v_gnu, mode, (listname != NULL ? listname : ""), masterconfig_path, (g_is_approved) ? "true" : "false", getuid(), geteuid(), getgid(), getegid()); /* Init Petidomo's internal stuff. */ if (InitPetidomo(masterconfig_path) != 0) { 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. */ if (strcasecmp("listserv", mode) == 0) listserv_main(incoming_mail, listname); else if (strcasecmp("deliver", mode) == 0) { if (listname != NULL) hermes_main(incoming_mail, listname); else { syslog(LOG_ERR, "Wrong command line syntax; deliver mode requires a parameter."); exit(1); } } else if (strcasecmp("approve", mode) == 0) { approve_main(incoming_mail); } else { syslog(LOG_ERR, "I don't know anything about mode \"%s\".", mode); exit(1); } /* Exit gracefully. */ return 0; } @ 1.19 log @Provide a "petidomo --mode=dump " and use this in petidomo-kickout instead of directly fiddling with Petidomo's files. @ text @d3 1 a3 1 $Revision: 1.18 $ d93 8 d102 3 a104 1 if (strcasecmp(mode, "dump") == 0) { d107 2 a108 5 if (listname == NULL) { fprintf(stderr, "petidomo: dump mode requires a list name argument\n"); exit(1); } if (InitPetidomo(masterconfig_path) != 0) { d111 1 a111 1 } d114 2 a115 1 if ((cp = loadfile(ListConfig->address_file)) == NULL) { d118 1 a118 1 } @ 1.18 log @First bunch of cosmetic adjustments to text messages. Additionally --masterconf=FILE is also passed through to files created in acknowledge directory. @ text @d3 1 a3 1 $Revision: 1.17 $ d51 1 a51 1 {ARGV_MAND, "mode", ARGV_CHAR_P, &mode, "mode", "listserv, deliver, or approve."}, d92 23 @ 1.17 log @Be careful, listname can be NULL in global operation mode and not all printf implementations are as smart as BSD's variant. Instead of printing "(null)" others just dump core. @ text @d3 1 a3 1 $Revision: 1.16 $ d40 1 a40 1 static char* masterconfig_path = SYSCONFDIR "/petidomo.conf"; @ 1.16 log @Removed unnecessary cast. @ text @d3 1 a3 1 $Revision: 1.15 $ d96 1 a96 1 petidomo_version.v_gnu, mode, listname, masterconfig_path, (g_is_approved) ? "true" : "false", @ 1.15 log @Added version information to the start-up log message. @ text @d3 1 a3 1 $Revision: 1.14 $ d96 1 a96 1 (char *)petidomo_version.v_gnu, mode, listname, masterconfig_path, (g_is_approved) ? "true" : "false", @ 1.14 log @First step in GNu shtool version support: Add version.c and use it for "petidomo --version". Support for handling version.c in Makefile.in is coming later. @ text @d3 1 a3 1 $Revision: 1.13 $ d95 3 a97 2 syslog(LOG_DEBUG, "Petidomo starting up; mode=%s, listname=%s, masterconf=%s, approved=%s, ruid=%d, euid=%d, gid=%d, egid=%d", mode, listname, masterconfig_path, (g_is_approved) ? "true" : "false", getuid(), geteuid(), getgid(), getegid()); @ 1.13 log @Moved the initial startup log message up so that it is logged before the main config file is parsed. Also added the path of the main config file to the message so that people can see where Petidomo locks for it in case parsing fails. @ text @d3 1 a3 1 $Revision: 1.12 $ d30 4 d90 1 a90 1 argv_version_string = "Petidomo"; @ 1.12 log @Added a message that is logged every time Petidomo starts up. This message will "dump" the configuration of Petidomo so that the user has a clue which Petidomo instance is doing what. @ text @d3 1 a3 1 $Revision: 1.11 $ d89 5 a109 5 /* Log a few helpful facts about this Petidomo instance. */ syslog(LOG_DEBUG, "Petidomo starting up; mode=%s, listname=%s, approved=%s, ruid=%d, euid=%d, gid=%d, egid=%s", mode, listname, (g_is_approved) ? "true" : "false", getuid(), geteuid(), getgid(), getegid()); @ 1.11 log @Added code that will set the real user id of the process equal to the effective user id. @ text @d3 1 a3 1 $Revision: 1.10 $ d105 5 @ 1.10 log @Petidomo needs to know the path to the executable in order to write the ack-spool file, which starts Petidomo again to process the acknowledged command or posting. I used BINDIR for that, but realized that this sucks when somebody manually moves the binary. Hence, I am using the contents of argv[0] now, normalized to an absolute path. This value is stored in the global variable who_am_i, which the queue_*() routines now use. @ text @d3 1 a3 1 $Revision: 1.9 $ d77 5 @ 1.9 log @As we agreed today, Petidomo is now open because licensed under GPL and always will be licensed under GPL, so use "Petidomo" as the program name everywhere and consistently. @ text @d3 1 a3 1 $Revision: 1.8 $ d27 1 d38 1 d58 19 @ 1.8 log @Implemented the approve mode, where incoming mails are searched for confirmation cookies and the apropriate queue entries will be executed. @ text @d2 2 a3 2 $Source: /d1/e/petidomo/cvs/petidomo/source/main.c,v $ $Revision: 1.7 $ d7 1 a7 1 This file is part of OpenPetidomo. d9 1 a9 1 OpenPetidomo is free software; you can redistribute it and/or modify d14 1 a14 1 OpenPetidomo is distributed in the hope that it will be useful, but d59 2 a60 2 argv_help_string = "OpenPetidomo Mailing List Server"; argv_version_string = "OpenPetidomo"; @ 1.7 log @Had to make is_approved a global variable, because it is actually tested in subroutines of listserv_main() and hermes_main(), like subscribe(), which's parameter list I don't want to change. @ text @d3 1 a3 1 $Revision: 1.6 $ d93 4 @ 1.6 log @Added --approved command line parameter, which is treated as a boolean. Whether it is set or not will be passed through to listserv_main() and to hermes_main(). The parameter will be used by the spooling mechanism. @ text @d3 1 a3 1 $Revision: 1.5 $ d36 1 a36 1 static char is_approved = ARGV_FALSE; d48 1 a48 1 {ARGV_MAYBE, "approved", ARGV_BOOL, &is_approved, "approved", "approved flag."}, d83 1 a83 1 listserv_main(incoming_mail, listname, is_approved); d87 1 a87 1 hermes_main(incoming_mail, listname, is_approved); @ 1.5 log @Rewrote Petidomo so that virtually any file's path can be configured at run-time now. @ text @d3 1 a3 1 $Revision: 1.4 $ d36 1 d48 1 d83 1 a83 1 listserv_main(incoming_mail, listname); d87 1 a87 1 hermes_main(incoming_mail, listname); a92 4 } else if (strcasecmp("petidomo", mode) == 0) { /* do nothing */ @ 1.4 log @Petidomo will now expect its master config file at SYSCONFDIR/petidomo.conf. This location can be changed at run-time with the command line parameter --masterconf. @ text @d3 1 a3 1 $Revision: 1.3 $ d45 1 a46 1 {ARGV_MAYBE, 0L, ARGV_CHAR_P, &listname, "listname", "Default mailing list."}, a67 2 return 0; @ 1.3 log @Reversed all changes concerning C++ in Petidomo ... it isn't worth the major rewrite. @ text @d2 2 a3 2 $Source: /d1/e/petidomo/cvs/petidomo/source/Attic/main.c,v $ $Revision: 1.2 $ d33 3 a35 2 static char* listname = NULL; static char* mode = NULL; d45 1 d63 1 a63 1 if (InitPetidomo() != 0) { d68 2 @ 1.2 log @ - Added correct GNU GPL copyright statements to the files. - Removed unnecessary include statements. @ text @d2 2 a3 2 $Source$ $Revision$ d26 1 d33 2 a34 5 MODULE_TABLE /* defined in debug.h */ static char * listname = NULL; #ifdef DEBUG static argv_array_t debug; #endif d41 3 a43 6 char * programname; argv_t args[] = { #ifdef DEBUG {'d', "debug", ARGV_CHAR_P | ARGV_FLAG_ARRAY , &debug, "debug", "Set debug level per module."}, #endif d46 1 a46 10 }; int fd; /* Determine the name we have been called under. */ programname = strrchr(argv[0], (int) '/'); if (programname == NULL) programname = argv[0]; else programname++; d51 1 a51 14 openlog(programname, LOG_CONS | LOG_PID | LOG_PERROR, LOG_MAIL); /* Set our umask. */ umask(S_IRWXO); /* We don't care for "others". */ /* Switch real and effective uid/gid to 'petidomo'. */ #ifdef HAVE_SETREUID setreuid(geteuid(), geteuid()); #endif #ifdef HAVE_SETREGID setregid(getegid(), getegid()); #endif a58 7 /* Set debug level according to the wishes of the user. */ #ifdef DEBUG if (argvSetDebugLevel(debug) != 0) exit(1); #endif a74 25 RescueMail(incoming_mail); /* Detach ourselves, if the configurator wished it so. */ if (MasterConfig->detach == TRUE) { debug((DEBUG_MAIN, 3, "Detaching from control terminal and running asyncronously.")); switch (fork()) { case -1: syslog(LOG_CRIT, "Can't fork(): %m"); exit(1); case 0: setsid(); fd = open("/dev/null", O_RDWR, 0); if (fd != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (fd > 2) close (fd); } break; default: _exit(0); } } d78 1 a78 1 if (strcasecmp("listserv", programname) == 0) d80 1 a80 1 else if (strcasecmp("hermes", programname) == 0) d86 1 a86 1 syslog(LOG_ERR, "Wrong command line syntax. \"hermes\" requires a parameter."); d90 1 a90 1 else if (strcasecmp("petidomo", programname) == 0) d96 1 a96 1 syslog(LOG_ERR, "I have been called under an unknown name \"%s\".", programname); a101 1 RemoveRescueMail(); @ 1.1 log @Initial revision @ text @d2 17 a18 7 * $Source: /usr/local/libdata/cvs/simons/petidomo/src/petidomo/main.c,v $ * $Revision: 1.27 $ * $Date: 1998/01/19 10:15:01 $ * * Copyright (C) 1996 by CyberSolutions GmbH. * All rights reserved. */ d26 1 a26 3 #include #include #include "version.h" d34 1 d36 1 d40 1 a40 1 { d46 1 a46 1 {'d', "debug", ARGV_CHARP | ARGV_ARRAY , &debug, "debug", d49 1 a49 1 {ARGV_MAYBE, 0L, ARGV_CHARP, &listname, "listname", "Default mailing list."}, d82 2 a83 2 argv_help_string = "Petidomo Mailing List Server"; argv_version_string = VERS; d138 3 a140 2 listserv_main(incoming_mail, listname); else if (strcasecmp("hermes", programname) == 0) { d142 3 a144 2 hermes_main(incoming_mail, listname); else { d147 5 d153 2 a154 2 } else { d157 1 a157 1 } d163 1 a163 1 } @ 1.1.1.1 log @Imported Petidomo 2.2 as found on www.petidomo.com. @ text @@