mirror of
https://github.com/anope/anope.git
synced 2026-07-03 16:33:13 +02:00
Fix bug with User::SetRealname crashing when a user with a custom GECOS connects.
Fix handling of Anope's current directory, binary name, binary directory, and data directory. This also fixes using /os restart if run from outside the bin directory. (The second fix above is a little hackish, should look into cleaning it up later.) git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2462 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
@@ -24,7 +24,6 @@ class CommandOSRestart : public Command
|
||||
|
||||
CommandReturn Execute(User *u, std::vector<ci::string> ¶ms)
|
||||
{
|
||||
#ifdef SERVICES_BIN
|
||||
quitmsg = new char[31 + strlen(u->nick)];
|
||||
if (!quitmsg)
|
||||
quitmsg = "RESTART command received, but out of memory!";
|
||||
@@ -35,9 +34,6 @@ class CommandOSRestart : public Command
|
||||
oper_global(NULL, "%s", GlobalOnCycleMessage);
|
||||
/* raise(SIGHUP); */
|
||||
do_restart_services();
|
||||
#else
|
||||
notice_lang(s_OperServ, u, OPER_CANNOT_RESTART);
|
||||
#endif
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
|
||||
+24
-10
@@ -43,6 +43,8 @@
|
||||
|
||||
/* Command-line options: (note that configuration variables are in config.c) */
|
||||
std::string services_dir; /* -dir dirname */
|
||||
std::string services_bin; /* Binary as specified by the user */
|
||||
std::string orig_cwd; /* Original current working directory */
|
||||
const char *log_filename = LOG_FILENAME; /* -log filename */
|
||||
int debug = 0; /* -debug */
|
||||
int readonly = 0; /* -readonly */
|
||||
@@ -175,8 +177,8 @@ void do_restart_services()
|
||||
/* First don't unload protocol module, then do so */
|
||||
modules_unload_all(false);
|
||||
modules_unload_all(true);
|
||||
chdir(binary_dir.c_str());
|
||||
execve(SERVICES_BIN, my_av, my_envp);
|
||||
chdir(orig_cwd.c_str());
|
||||
execve(services_bin.c_str(), my_av, my_envp);
|
||||
if (!readonly) {
|
||||
open_log();
|
||||
log_perror("Restart failed");
|
||||
@@ -324,6 +326,7 @@ std::string GetFullProgDir(char *argv0)
|
||||
if (GetModuleFileName(NULL, buffer, PATH_MAX))
|
||||
{
|
||||
std::string fullpath = buffer;
|
||||
services_dir = fullpath.substr(orig_cwd.size() + 1);
|
||||
std::string::size_type n = fullpath.rfind("\\" SERVICES_BIN);
|
||||
return std::string(fullpath, 0, n);
|
||||
}
|
||||
@@ -336,10 +339,12 @@ std::string GetFullProgDir(char *argv0)
|
||||
/* Does argv[0] start with /? If so, it's a full path, use it */
|
||||
if (remainder[0] == '/')
|
||||
{
|
||||
services_bin = remainder.substr(orig_cwd.size() + 1);
|
||||
std::string::size_type n = remainder.rfind("/" SERVICES_BIN);
|
||||
return std::string(remainder, 0, n);
|
||||
}
|
||||
|
||||
services_bin = remainder;
|
||||
std::string fullpath = static_cast<std::string>(buffer) + "/" + remainder;
|
||||
std::string::size_type n = fullpath.rfind("/" SERVICES_BIN);
|
||||
return std::string(fullpath, 0, n);
|
||||
@@ -365,6 +370,14 @@ int main(int ac, char **av, char **envp)
|
||||
my_av = av;
|
||||
my_envp = envp;
|
||||
|
||||
char cwd[PATH_MAX] = "";
|
||||
#ifdef _WIN32
|
||||
GetCurrentDirectory(PATH_MAX, cwd);
|
||||
#else
|
||||
getcwd(cwd, PATH_MAX);
|
||||
#endif
|
||||
orig_cwd = cwd;
|
||||
|
||||
#ifndef _WIN32
|
||||
/* If we're root, issue a warning now */
|
||||
if ((getuid() == 0) && (getgid() == 0)) {
|
||||
@@ -377,7 +390,13 @@ int main(int ac, char **av, char **envp)
|
||||
#endif
|
||||
|
||||
binary_dir = GetFullProgDir(av[0]);
|
||||
services_dir = binary_dir + "/../data";
|
||||
#ifdef _WIN32
|
||||
std::string::size_type n = binary_dir.rfind("\\");
|
||||
services_dir = binary_dir.substr(0, n) + "\\data";
|
||||
#else
|
||||
std::string::size_type n = binary_dir.rfind("/");
|
||||
services_dir = binary_dir.substr(0, n) + "/data";
|
||||
#endif
|
||||
|
||||
/* Clean out the module runtime directory prior to running, just in case files were left behind during a previous run */
|
||||
ModuleRunTimeDirCleanUp();
|
||||
@@ -496,25 +515,20 @@ int main(int ac, char **av, char **envp)
|
||||
|
||||
/* Check for restart instead of exit */
|
||||
if (save_data == -2) {
|
||||
#ifdef SERVICES_BIN
|
||||
alog("Restarting");
|
||||
if (!quitmsg)
|
||||
quitmsg = "Restarting";
|
||||
ircdproto->SendSquit(ServerName, quitmsg);
|
||||
disconn(servsock);
|
||||
close_log();
|
||||
chdir(binary_dir.c_str());
|
||||
execve(SERVICES_BIN, av, envp);
|
||||
chdir(orig_cwd.c_str());
|
||||
execve(services_bin.c_str(), av, envp);
|
||||
if (!readonly) {
|
||||
open_log();
|
||||
log_perror("Restart failed");
|
||||
close_log();
|
||||
}
|
||||
return 1;
|
||||
#else
|
||||
quitmsg =
|
||||
"Restart attempt failed--SERVICES_BIN not defined (rerun configure)";
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Disconnect and exit */
|
||||
|
||||
+2
-3
@@ -183,8 +183,7 @@ void User::SetRealname(const std::string &srealname)
|
||||
this->realname = sstrdup(srealname.c_str());
|
||||
NickAlias *na = findnick(this->nick);
|
||||
|
||||
if (na && (nick_identified(this) ||
|
||||
(!(this->nc->flags & NI_SECURE) && nick_recognized(this))))
|
||||
if (na && (nick_identified(this) || (!this->nc || (this->nc && !(this->nc->flags & NI_SECURE) && nick_recognized(this)))))
|
||||
{
|
||||
if (na->last_realname)
|
||||
delete [] na->last_realname;
|
||||
@@ -591,7 +590,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const
|
||||
}
|
||||
delete [] logrealname;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate User structure and fill it in. */
|
||||
user = new User(nick, uid ? uid : "");
|
||||
user->SetIdent(username);
|
||||
|
||||
Reference in New Issue
Block a user