[ScryMUD] SVN Commit Info r710 - branches/version-2-1/mud/grrmud/server
scrymud at wanfear.com
scrymud at wanfear.com
Wed Nov 24 19:01:28 PST 2004
Author: eroper
Date: 2004-11-24 19:01:27 -0800 (Wed, 24 Nov 2004)
New Revision: 710
Modified:
branches/version-2-1/mud/grrmud/server/BugEntry.cc
branches/version-2-1/mud/grrmud/server/ServerConfig.cc
branches/version-2-1/mud/grrmud/server/ServerConfig.h
branches/version-2-1/mud/grrmud/server/grrmud.cc
branches/version-2-1/mud/grrmud/server/load_wld.cc
Log:
ported 676:677 from main-line dev.
--Khaav
Modified: branches/version-2-1/mud/grrmud/server/BugEntry.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/BugEntry.cc 2004-11-25 01:57:05 UTC (rev 709)
+++ branches/version-2-1/mud/grrmud/server/BugEntry.cc 2004-11-25 03:01:27 UTC (rev 710)
@@ -632,6 +632,7 @@
dafile << flush;
dafile.close();
+ dafile.clear();
String cmd(50);
Sprintf(cmd, "./mv_logs.bash %S", &tmp_name);
Modified: branches/version-2-1/mud/grrmud/server/ServerConfig.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/ServerConfig.cc 2004-11-25 01:57:05 UTC (rev 709)
+++ branches/version-2-1/mud/grrmud/server/ServerConfig.cc 2004-11-25 03:01:27 UTC (rev 710)
@@ -2,6 +2,11 @@
ServerConfig::ServerConfig() {
port=4000;
+
+ daemonize=0;
+ suid=0;
+ suid_user=0;
+ suid_group=0;
bootLoadModifier=300;
regularLoadModifier=100;
@@ -270,15 +275,32 @@
mySQLport = (int)strtol(val, NULL, 0);
}
else if (strcasecmp(key, "useViolenceTimer") == 0) {
- cout << "Found useViolenceTimer.\n";
if (strcasecmp(val, "true") == 0) {
useViolenceTimer=true;
- cout << "Using useViolenceTimer.\n";
} else if (strcasecmp(val, "false") == 0) {
useViolenceTimer=false;
- cout << "NOT Using useViolenceTimer.\n";
}
+ } // useViolenceTimer
+ else if (strcasecmp(key, "daemonize") == 0) {
+ if (strcasecmp(val, "true") == 0) {
+ daemonize=true;
+ } else if (strcasecmp(val, "false") == 0) {
+ daemonize=false;
+ }
+ } // daemonize
+ else if (strcasecmp(key, "suid") == 0) {
+ if (strcasecmp(val, "true") == 0) {
+ suid=true;
+ } else if (strcasecmp(val, "false") == 0) {
+ suid=false;
+ }
+ } // suid
+ else if (strcasecmp(key, "suidUser") == 0) {
+ suid_user = (int)strtol(val, NULL, 0);
}
+ else if (strcasecmp(key, "suidGroup") == 0) {
+ suid_group = (int)strtol(val, NULL, 0);
+ }
}
}
}
@@ -402,6 +424,20 @@
else {
file << "useViolenceTimer false\n";
}
+ if (daemonize) {
+ file << "daemonize true\n";
+ }
+ else {
+ file << "daemonize false\n";
+ }
+ if (suid) {
+ file << "suid true\n";
+ }
+ else {
+ file << "suid false\n";
+ }
+ file << "suidUser" << suid_user << '\n';
+ file << "suidGroup" << suid_group << '\n';
file << "maxRedundantDonates " << maxRedundantDonates << '\n';
Modified: branches/version-2-1/mud/grrmud/server/ServerConfig.h
===================================================================
--- branches/version-2-1/mud/grrmud/server/ServerConfig.h 2004-11-25 01:57:05 UTC (rev 709)
+++ branches/version-2-1/mud/grrmud/server/ServerConfig.h 2004-11-25 03:01:27 UTC (rev 710)
@@ -4,8 +4,9 @@
#include <string.h>
#include <string2.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
-
class ServerConfig {
public:
ServerConfig();
@@ -15,6 +16,12 @@
void write(char* filename);
void writeDynamic(char* filename);
+ // chroot+daemonize
+ int daemonize;
+ int suid;
+ uid_t suid_user;
+ gid_t suid_group;
+
// Network
int port;
Modified: branches/version-2-1/mud/grrmud/server/grrmud.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/grrmud.cc 2004-11-25 01:57:05 UTC (rev 709)
+++ branches/version-2-1/mud/grrmud/server/grrmud.cc 2004-11-25 03:01:27 UTC (rev 710)
@@ -1,5 +1,5 @@
// $Id$
-// $Revision: 1.45 $ $Author$ $Date$
+// $Revision: 1.47 $ $Author$ $Date$
//
//ScryMUD Server Code
@@ -78,6 +78,8 @@
#include "spells.h"
#include <new>
+#include "telnet.h"
+
#define MAX_HOSTNAME 256
int initCmdsCollection(); //found in parse_gen.cc
@@ -518,52 +520,12 @@
//String::setLogFile(&mudlog);
extra_memory = (char*)(malloc(20000));
- signal(SIGTERM, (&sig_term_handler));
- //signal(SIGABRT, (&sig_term_handler));
- signal(SIGALRM, (&sig_term_handler));
- signal(SIGFPE, (&sig_term_handler));
- signal(SIGHUP, (&sig_term_handler));
- signal(SIGILL, (&sig_term_handler));
- signal(SIGINT, (&sig_term_handler));
- signal(SIGIO, (&sig_term_handler));
- //signal(SIGIOT, (&sig_term_handler));
- signal(SIGPIPE, (&sig_term_handler));
- //signal(SIGPOLL, (&sig_term_handler));
- signal(SIGPROF, (&sig_term_handler));
- signal(SIGQUIT, (&sig_term_handler));
- signal(SIGSTOP, (&sig_term_handler));
- //signal(SIGSYS, (&sig_term_handler));
- signal(SIGTERM, (&sig_term_handler));
-
- // This is like: ctrl-z, no need to catch it.
- //signal(SIGTRAP, (&sig_term_handler));
-
- signal(SIGTSTP, (&sig_term_handler));
- signal(SIGTTIN, (&sig_term_handler));
- signal(SIGTTOU, (&sig_term_handler));
- signal(SIGUSR1, (&sig_term_handler));
- signal(SIGUSR2, (&sig_term_handler));
- signal(SIGVTALRM, (&sig_term_handler));
- signal(SIGXCPU, (&sig_term_handler));
- signal(SIGXFSZ, (&sig_term_handler));
-
- /* Trap a few beasties, but only once!! */
- signal(SIGSEGV, (&sig_term_handler));
- signal(SIGSEGV, (&sig_term_handler));
-
- std::set_new_handler(scry_new_handler);
-
String buf(50);
room_list.ensureCapacity(NUMBER_OF_ROOMS + 1);
BOOT_TIME = time(NULL);
- Sprintf(buf, "echo \"%i\" > GRRMUD.PID", getpid());
- system("rm -f GRRMUD.PID");
- system(buf);
- system("chmod a+r GRRMUD.PID");
-
cout << "ScryMUD version: " << BuildInfo::getVersion() << endl;
cout << "Built on: " << BuildInfo::getBuildDate() << endl;
cout << "On machine: " << BuildInfo::getBuildMachine() << endl;
@@ -583,9 +545,34 @@
config.read("grrmud.cfg");
config.readDynamic("dynamic.cfg");
-
CmdLineInfo::init(argc, argv);
+ // Daemonize if we're supposed to.
+ if ( config.daemonize ) {
+ pid_t pid;
+ if ( ( pid = fork() ) == -1 ) {
+ cout << "Couldn't Fork. Quitting." << endl;
+ exit(-1);
+ }
+ if ( pid > 0 ) {
+ // Kill the parent
+ do_shutdown = TRUE;
+ return(0);
+ }
+ // The child
+ setsid();
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ } else {
+ } // config.daemonize
+
+ // Write out our PID to grrmud.pid
+ std::ofstream pid_file("grrmud.pid");
+ pid_file << getpid();
+ pid_file.close();
+ pid_file.clear();
+
#ifdef USEMYSQL
if (config.useMySQL) {
mysql_init(database);
@@ -607,6 +594,15 @@
readSiteBanned();
+ // setup signal handling AFTER we (potentially) daemonize
+ signal(SIGTERM, (&sig_term_handler));
+ signal(SIGIO, (&sig_term_handler));
+ signal(SIGPIPE, (&sig_term_handler));
+ signal(SIGQUIT, (&sig_term_handler));
+ /* Trap a few beasties, but only once!! */
+ signal(SIGSEGV, (&sig_term_handler));
+ std::set_new_handler(scry_new_handler);
+
// Drop into our endless loop.
run_the_game(config.port);
@@ -633,6 +629,18 @@
mudlog << "Opening mother connection.\n";
mother_desc = s = init_socket(port);
+
+ // If configured to do so, drop permissions as soon as we open the socket.
+ if ( config.suid ) {
+ if ( setgid(config.suid_group) == -1 ) {
+ cout << "Couldn't setgid. Quitting." << endl;
+ exit(-1);
+ }
+ if ( setuid(config.suid_user) == -1 ) {
+ cout << "Couldn't setuid. Quitting." << endl;
+ exit(-1);
+ }
+ }
system("rm -f .reboot"); //if it crashes in this next bit stay down,
//the world files are corrupt probably
@@ -692,6 +700,7 @@
init_masks(); //set all the masks for miscelaneous bitfields
+
mudlog.log(DBG, "Entering game loop.\n");
@@ -990,6 +999,64 @@
if ((pc_ptr->MODE != MODE_GO_LINKDEAD_PLEASE) &&
(pc_ptr->MODE != MODE_LOGOFF_NEWBIE_PLEASE) &&
(pc_ptr->MODE != MODE_QUIT_ME_PLEASE)) {
+
+ /* Yes I need a better place for this, it has to happen before
+ * snooping and has to be able to put crap in the output buffer
+ */
+ {
+ String tmp;
+ int i;
+ int imax;
+ unsigned char telnet_cmd;
+
+ // Process telnet protocol commands
+
+ /* window size negotinations:
+ * (client) IAC WILL NAWS
+ * (server) IAC DO NAWS
+ * (client) IAC SB NAWS WIDTH[1] WIDTH[0] HEIGHT[1] HEIGHT[0] IAC SE
+ * < 16 bit value > < 16 bit value >
+ * For now though, I'm going to be lazy ;)
+ * (client) IAC WILL NAWS
+ * (server) IAC DON'T NAWS
+ */
+
+ imax = pc_ptr->getInput()->Strlen();
+ tmp.Clear();
+ for(i=0;i<imax;i++) {
+ if ( pc_ptr->getInput()->charAt(i) == (char)IAC ) {
+ if ( i+1 < imax )
+ telnet_cmd = pc_ptr->getInput()->charAt(++i);
+
+ switch ( telnet_cmd ) {
+ case WILL:
+ if ( i+1 < imax ) {
+ telnet_cmd = pc_ptr->getInput()->charAt(++i);
+ switch ( telnet_cmd ) {
+ /*
+ case TELOPT_NAWS:
+ pc_ptr->pc->output.append((char)IAC);
+ pc_ptr->pc->output.append((char)DO);
+ pc_ptr->pc->output.append((char)telnet_cmd);
+ break;
+ */
+ default:
+ pc_ptr->pc->output.append((char)IAC);
+ pc_ptr->pc->output.append((char)DONT);
+ pc_ptr->pc->output.append((char)telnet_cmd);
+ }
+ }
+ break;
+ }
+ } //if telnet cmd
+ else {
+ tmp.append(pc_ptr->getInput()->charAt(i));
+ }
+ } //for
+ pc_ptr->getInput()->Clear();
+ pc_ptr->getInput()->append(tmp);
+ } // telnet parser
+
len = pc_ptr->getInput()->Strlen();
if (len && ((pc_ptr->getInput()->charAt(len - 1) == '\n') ||
pc_ptr->getInput()->Contains('\n')) || (len >= MAX_INPUT_LEN)) {
Modified: branches/version-2-1/mud/grrmud/server/load_wld.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/load_wld.cc 2004-11-25 01:57:05 UTC (rev 709)
+++ branches/version-2-1/mud/grrmud/server/load_wld.cc 2004-11-25 03:01:27 UTC (rev 710)
@@ -1,5 +1,5 @@
// $Id$
-// $Revision: 1.10 $ $Author$ $Date$
+// $Revision: 1.11 $ $Author$ $Date$
//
//ScryMUD Server Code
@@ -216,10 +216,10 @@
load_boards(); //add messages to all the boards
load_skill_spells(); //skill/spell DB info
- cout << "Max_Obj# is: " << Cur_Max_Obj_Num << endl;
- cout << "Max_Door# is: " << Cur_Max_Door_Num << endl;
- cout << "Max_Crit# is: " << Cur_Max_Crit_Num << endl;
- cout << "Max_Room# is: " << Cur_Max_Room_Num << endl;
+ mudlog << "Max_Obj# is: " << Cur_Max_Obj_Num << endl;
+ mudlog << "Max_Door# is: " << Cur_Max_Door_Num << endl;
+ mudlog << "Max_Crit# is: " << Cur_Max_Crit_Num << endl;
+ mudlog << "Max_Room# is: " << Cur_Max_Room_Num << endl;
init_loads(); /* calculate how many of each item is in game.
*these values are stored in the CUR_IN_GAME fields
@@ -252,7 +252,7 @@
init_casting_objs(); //Initialize the SkillSpell list
- cout << "The world has been constructed at least somewhat successfully!"
+ mudlog << "The world has been constructed at least somewhat successfully!"
<< endl;
//write_all_zones(); //this used for updating the WORLD DB
More information about the ScryMUD
mailing list