/*
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2015 by the citadel.org team
*
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3.
*
- * 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.
+ * 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.
*/
#include "serv_extensions.h"
TEST_PORT(c_nntp_port, 119);
TEST_PORT(c_nntps_port, 563);
- if (config.c_ctdluid == 0)
- syslog(LOG_EMERG, "citadel should not be configured to run as root! Check the value of c_ctdluid");
- else if (getpwuid(CTDLUID) == NULL)
- syslog(LOG_EMERG, "The UID (%d) citadel is configured to use is not defined in your system (/etc/passwd?)! Check the value of c_ctdluid", CTDLUID);
+ if (getpwuid(ctdluid) == NULL) {
+ syslog(LOG_EMERG, "The UID (%d) citadel is configured to use is not defined in your system (/etc/passwd?)!", ctdluid);
+ }
}
*/
void brand_new_installation_set_defaults(void) {
- struct passwd *pw;
struct utsname my_utsname;
struct hostent *he;
config.c_port_number = 504;
config.c_sleeping = 900;
- if (config.c_ctdluid == 0) {
- pw = getpwnam("citadel");
- if (pw != NULL) {
- config.c_ctdluid = pw->pw_uid;
- }
- }
- if (config.c_ctdluid == 0) {
- pw = getpwnam("bbs");
- if (pw != NULL) {
- config.c_ctdluid = pw->pw_uid;
- }
- }
- if (config.c_ctdluid == 0) {
- pw = getpwnam("guest");
- if (pw != NULL) {
- config.c_ctdluid = pw->pw_uid;
- }
- }
if (config.c_createax == 0) {
config.c_createax = 3;
}
control_fp = fopen(file_citadel_control, "rb+");
if (control_fp != NULL) {
lock_control();
- rv = fchown(fileno(control_fp), config.c_ctdluid, -1);
+ rv = fchown(fileno(control_fp), ctdluid, -1);
if (rv == -1)
syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n",
file_citadel_control, strerror(errno));
lock_control();
memset(&CitControl, 0, sizeof(struct CitControl));
- rv = fchown(fileno(control_fp), config.c_ctdluid, -1);
+ rv = fchown(fileno(control_fp), ctdluid, -1);
if (rv == -1)
syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n",
file_citadel_control, strerror(errno));
syslog(LOG_EMERG, "Failed to read Controlfile: %s [%s]\n",
file_citadel_control, strerror(errno));
already_have_control = 1;
- rv = chown(file_citadel_control, config.c_ctdluid, (-1));
+ rv = chown(file_citadel_control, ctdluid, (-1));
if (rv == -1)
syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n",
file_citadel_control, strerror(errno));
cprintf("%d\n", config.c_spam_flag_only);
cprintf("%d\n", config.c_guest_logins);
cprintf("%d\n", config.c_port_number);
- cprintf("%d\n", config.c_ctdluid);
+ cprintf("%d\n", ctdluid);
cprintf("%d\n", config.c_nntp_port);
cprintf("%d\n", config.c_nntps_port);
cprintf("000\n");
config.c_port_number = atoi(buf);
break;
case 69:
- config.c_ctdluid = atoi(buf);
+ /* niu */
break;
case 70:
config.c_nntp_port = atoi(buf);
#define NODENAME config.c_nodename
#define FQDN config.c_fqdn
-#define CTDLUID config.c_ctdluid
+#define CTDLUID ctdluid
#define CREATAIDE config.c_creataide
#define REGISCALL config.c_regiscall
#define TWITDETECT config.c_twitdetect
/*
* This module dumps and/or loads the Citadel database in XML format.
*
- * Copyright (c) 1987-2014 by the citadel.org team
+ * Copyright (c) 1987-2015 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
client_write("<c_fqdn>", 8); xml_strout(config.c_fqdn); client_write("</c_fqdn>\n", 10);
client_write("<c_humannode>", 13); xml_strout(config.c_humannode); client_write("</c_humannode>\n", 15);
client_write("<c_phonenum>", 12); xml_strout(config.c_phonenum); client_write("</c_phonenum>\n", 14);
- cprintf("<c_ctdluid>%d</c_ctdluid>\n", config.c_ctdluid);
cprintf("<c_creataide>%d</c_creataide>\n", config.c_creataide);
cprintf("<c_sleeping>%d</c_sleeping>\n", config.c_sleeping);
cprintf("<c_initax>%d</c_initax>\n", config.c_initax);
else if (!strcasecmp(el, "c_fqdn")) SET_CFGSTRBUF(c_fqdn, migr_chardata);
else if (!strcasecmp(el, "c_humannode")) SET_CFGSTRBUF(c_humannode, migr_chardata);
else if (!strcasecmp(el, "c_phonenum")) SET_CFGSTRBUF(c_phonenum, migr_chardata);
- else if (!strcasecmp(el, "c_ctdluid")) config.c_ctdluid = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "c_creataide")) config.c_creataide = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "c_sleeping")) config.c_sleeping = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "c_initax")) config.c_initax = atoi(ChrPtr(migr_chardata));
else {
OutBuffer = NewStrBuf();
CfgIt = GetNewHashPos(CfgTypeHash, 1);
- fchown(TmpFD, config.c_ctdluid, 0);
+ fchown(TmpFD, ctdluid, 0);
for (eCfg = subpending; eCfg < maxRoomNetCfg; eCfg ++)
{
const CfgLineType *pCfg;
#define CTDLEXIT_DB 105 /* Unable to initialize database */
#define CTDLEXIT_LIBCITADEL 106 /* Incorrect version of libcitadel */
#define CTDL_EXIT_UNSUP_AUTH 107 /* Unsupported auth mode configured */
+#define CTDLEXIT_UNUSER 108 /* Could not determine uid to run as */
/*
* Reasons why a session would be terminated (set CC->kill_me to these values)
extern int ScheduledShutdown;
extern struct CitControl CitControl;
+extern uid_t ctdluid;
struct ExpressMessage {
struct ExpressMessage *next;
#include "user_ops.h"
#include "ecrash.h"
+uid_t ctdluid = 0;
const char *CitadelServiceUDS="citadel-UDS";
const char *CitadelServiceTCP="citadel-TCP";
-
-
-
void go_threading(void);
/*
char ctdldir[PATH_MAX]=CTDLDIR;
int syslog_facility = LOG_DAEMON;
const char *eDebuglist[] = {NULL, NULL};
+ uid_t u = 0;
+ struct passwd *p = NULL;
#ifdef HAVE_RUN_DIR
struct stat filestats;
#endif
InitializeMasterTSD();
/* parse command-line arguments */
- while ((a=getopt(argc, argv, "l:dh:x:t:B:Dr")) != EOF) switch(a) {
+ while ((a=getopt(argc, argv, "l:dh:x:t:B:Dru:")) != EOF) switch(a) {
case 'l':
safestrncpy(facility, optarg, sizeof(facility));
drop_root_perms = 0;
break;
+ /* -u tells the server what uid to run under... */
+ case 'u':
+ u = atoi(optarg);
+ if (u > 0) {
+ ctdluid = u;
+ }
+ else {
+ p = getpwnam(optarg);
+ if (p) {
+ u = p->pw_uid;
+ }
+ }
+ if (u > 0) {
+ ctdluid = u;
+ }
+ break;
+
default:
/* any other parameter makes it crash and burn */
fprintf(stderr, "citserver: usage: "
"citserver "
"[-l LogFacility] "
"[-d] [-D] [-r] "
+ "[-u user] "
"[-h HomeDir]\n"
);
exit(1);
}
+
+ /* Last ditch effort to determine the user name ... if there's a user called "citadel" then use that */
+ if (ctdluid == 0) {
+ p = getpwnam("citadel");
+ if (!p) {
+ p = getpwnam("bbs");
+ }
+ if (!p) {
+ p = getpwnam("guest");
+ }
+ if (p) {
+ u = p->pw_uid;
+ }
+ if (u > 0) {
+ ctdluid = u;
+ }
+ }
+
+ if ((ctdluid == 0) && (drop_root_perms == 0)) {
+ fprintf(stderr, "citserver: cannot determine user to run as; please specify -r or -u options\n");
+ exit(CTDLEXIT_UNUSER);
+ }
+
StartLibCitadel(basesize);
openlog("citserver",
( running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR) ),
if (stat(ctdl_run_dir, &filestats)==-1){
#ifdef HAVE_GETPWUID_R
#ifdef SOLARIS_GETPWUID
- pwp = getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf));
+ pwp = getpwuid_r(ctdluid, &pw, pwbuf, sizeof(pwbuf));
#else // SOLARIS_GETPWUID
- getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
+ getpwuid_r(ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
#endif // SOLARIS_GETPWUID
#else // HAVE_GETPWUID_R
pwp = NULL;
"unable to create run directory [%s]: %s",
ctdl_run_dir, strerror(errno));
- if (chown(ctdl_run_dir, config.c_ctdluid, (pwp==NULL)?-1:pw.pw_gid) != 0)
+ if (chown(ctdl_run_dir, ctdluid, (pwp==NULL)?-1:pw.pw_gid) != 0)
syslog(LOG_EMERG,
"unable to set the access rights for [%s]: %s",
ctdl_run_dir, strerror(errno));
#ifdef HAVE_GETPWUID_R
#ifdef SOLARIS_GETPWUID
- pwp = getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf));
+ pwp = getpwuid_r(ctdluid, &pw, pwbuf, sizeof(pwbuf));
#else // SOLARIS_GETPWUID
- getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
+ getpwuid_r(ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
#endif // SOLARIS_GETPWUID
#else // HAVE_GETPWUID_R
pwp = NULL;
activity = _("Setting file permissions");
progress(activity, 0, 2);
- //chown(file_citadel_config, config.c_ctdluid, gid);
progress(activity, 1, 2);
chmod(file_citadel_config, S_IRUSR | S_IWUSR);
progress(activity, 2, 2);