X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Fngircd.c;h=e7183e31fcb4387a0ae8e35b235c51ab10f2de7a;hb=c7693f625e9d6c5a7c8aea7a8c8bb5c5a5378843;hp=985d09a9fe8beae2dae1fa00ba8197e8cfced8f9;hpb=ead79d3e39954ca8eed73f45cfc30287da79d46a;p=ngircd-alex.git diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index 985d09a9..e7183e31 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -12,7 +12,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: ngircd.c,v 1.105 2005/07/08 21:04:39 alex Exp $"; +static char UNUSED id[] = "$Id: ngircd.c,v 1.107 2005/07/10 21:07:22 fw Exp $"; /** * @file @@ -438,7 +438,7 @@ NGIRCd_Rehash( void ) /* Recover old server name: it can't be changed during run-time */ if( strcmp( old_name, Conf_ServerName ) != 0 ) { - strcpy( Conf_ServerName, old_name ); + strlcpy( Conf_ServerName, old_name, sizeof Conf_ServerName ); Log( LOG_ERR, "Can't change \"ServerName\" on runtime! Ignored new name." ); } @@ -711,28 +711,34 @@ NGIRCd_Init( bool NGIRCd_NoDaemon ) } } - if ( Conf_UID == 0 ) { - Log( LOG_INFO, "ServerUID must not be 0, switching to user nobody", Conf_UID ); + if (Conf_UID == 0) { + Log(LOG_INFO, "ServerUID must not be 0, using \"nobody\" instead.", Conf_UID); - if (!NGIRCd_getNobodyID(&Conf_UID, &Conf_GID )) { - Log( LOG_WARNING, "Could not get uid/gid of user nobody: %s", + if (! NGIRCd_getNobodyID(&Conf_UID, &Conf_GID)) { + Log(LOG_WARNING, "Could not get user/group ID of user \"nobody\": %s", errno ? strerror(errno) : "not found" ); return false; } } - if( setgid( Conf_GID ) != 0 ) { - real_errno = errno; - Log( LOG_ERR, "Can't change group ID to %u: %s", Conf_GID, strerror( errno )); - if (real_errno != EPERM) - return false; + if (getgid() != Conf_GID) { + /* Change group ID */ + if (setgid(Conf_GID) != 0) { + real_errno = errno; + Log( LOG_ERR, "Can't change group ID to %u: %s", Conf_GID, strerror( errno )); + if (real_errno != EPERM) + return false; + } } - if( setuid( Conf_UID ) != 0 ) { - real_errno = errno; - Log( LOG_ERR, "Can't change user ID to %u: %s", Conf_UID, strerror( errno )); - if (real_errno != EPERM) - return false; + if (getuid() != Conf_UID) { + /* Change user ID */ + if (setuid(Conf_UID) != 0) { + real_errno = errno; + Log(LOG_ERR, "Can't change user ID to %u: %s", Conf_UID, strerror(errno)); + if (real_errno != EPERM) + return false; + } } initialized = true; @@ -764,16 +770,14 @@ NGIRCd_Init( bool NGIRCd_NoDaemon ) Pidfile_Create( pid ); - /* check uid we are running as, can be different from values configured (e.g. if we were already - started with a uid > 0 */ + /* Check UID/GID we are running as, can be different from values + * configured (e. g. if we were already started with a UID>0. */ Conf_UID = getuid(); Conf_GID = getgid(); - assert( Conf_GID > 0); - assert( Conf_UID > 0); - pwd = getpwuid( Conf_UID ); grp = getgrgid( Conf_GID ); + Log( LOG_INFO, "Running as user %s(%ld), group %s(%ld), with PID %ld.", pwd ? pwd->pw_name : "unknown", Conf_UID, grp ? grp->gr_name : "unknown", Conf_GID, pid);