Changeset - 0509696bfda3
[Not reviewed]
0 3 0
HanzZ - 14 years ago 2011-10-09 22:01:02
hanzz.k@gmail.com
refresh coredump limit after setuid
3 files changed with 32 insertions and 25 deletions:
0 comments (0 inline, 0 general)
spectrum/src/main.cpp
Show inline comments
 
@@ -12,12 +12,13 @@
 
#include "Swiften/EventLoop/SimpleEventLoop.h"
 
#include <boost/filesystem.hpp>
 
#ifndef WIN32
 
#include "sys/signal.h"
 
#include <pwd.h>
 
#include <grp.h>
 
#include <sys/resource.h>
 
#else
 
#include <Windows.h>
 
#include <tchar.h>
 
#endif
 
#include "log4cxx/logger.h"
 
#include "log4cxx/consoleappender.h"
 
@@ -227,36 +228,42 @@ int main(int argc, char **argv)
 
		p.setProperty("pid", boost::lexical_cast<std::string>(getpid()));
 
		p.setProperty("jid", CONFIG_STRING(&config, "service.jid"));
 
		log4cxx::PropertyConfigurator::configure(p);
 
	}
 
 
#ifndef WIN32
 
	if (!CONFIG_STRING(&config, "service.group").empty()) {
 
		struct group *gr;
 
		if ((gr = getgrnam(CONFIG_STRING(&config, "service.group").c_str())) == NULL) {
 
			LOG4CXX_ERROR(logger, "Invalid service.group name " << CONFIG_STRING(&config, "service.group"));
 
			return 1;
 
	if (!CONFIG_STRING(&config, "service.group").empty() ||!CONFIG_STRING(&config, "service.user").empty() ) {
 
		struct rlimit limit;
 
		getrlimit(RLIMIT_CORE, &limit);
 
 
		if (!CONFIG_STRING(&config, "service.group").empty()) {
 
			struct group *gr;
 
			if ((gr = getgrnam(CONFIG_STRING(&config, "service.group").c_str())) == NULL) {
 
				LOG4CXX_ERROR(logger, "Invalid service.group name " << CONFIG_STRING(&config, "service.group"));
 
				return 1;
 
			}
 
 
			if (((setgid(gr->gr_gid)) != 0) || (initgroups(CONFIG_STRING(&config, "service.user").c_str(), gr->gr_gid) != 0)) {
 
				LOG4CXX_ERROR(logger, "Failed to set service.group name " << CONFIG_STRING(&config, "service.group") << " - " << gr->gr_gid << ":" << strerror(errno));
 
				return 1;
 
			}
 
		}
 
 
		if (((setgid(gr->gr_gid)) != 0) || (initgroups(CONFIG_STRING(&config, "service.user").c_str(), gr->gr_gid) != 0)) {
 
			LOG4CXX_ERROR(logger, "Failed to set service.group name " << CONFIG_STRING(&config, "service.group") << " - " << gr->gr_gid << ":" << strerror(errno));
 
			return 1;
 
		}
 
	}
 
 
	if (!CONFIG_STRING(&config, "service.user").empty()) {
 
		struct passwd *pw;
 
		if ((pw = getpwnam(CONFIG_STRING(&config, "service.user").c_str())) == NULL) {
 
			LOG4CXX_ERROR(logger, "Invalid service.user name " << CONFIG_STRING(&config, "service.user"));
 
			return 1;
 
		}
 
 
		if ((setuid(pw->pw_uid)) != 0) {
 
			LOG4CXX_ERROR(logger, "Failed to set service.user name " << CONFIG_STRING(&config, "service.user") << " - " << pw->pw_uid << ":" << strerror(errno));
 
			return 1;
 
		if (!CONFIG_STRING(&config, "service.user").empty()) {
 
			struct passwd *pw;
 
			if ((pw = getpwnam(CONFIG_STRING(&config, "service.user").c_str())) == NULL) {
 
				LOG4CXX_ERROR(logger, "Invalid service.user name " << CONFIG_STRING(&config, "service.user"));
 
				return 1;
 
			}
 
 
			if ((setuid(pw->pw_uid)) != 0) {
 
				LOG4CXX_ERROR(logger, "Failed to set service.user name " << CONFIG_STRING(&config, "service.user") << " - " << pw->pw_uid << ":" << strerror(errno));
 
				return 1;
 
			}
 
		}
 
		setrlimit(RLIMIT_CORE, &limit);
 
	}
 
#endif
 
 
	Swift::SimpleEventLoop eventLoop;
 
 
	Swift::BoostNetworkFactories *factories = new Swift::BoostNetworkFactories(&eventLoop);
spectrum/src/sample.cfg
Show inline comments
 
@@ -8,14 +8,14 @@ backend_host=localhost # < this option doesn't work yet
 
backend_port=10001
 
admin_username=admin
 
admin_password=test
 
#cert=server.pfx #patch to PKCS#12 certificate
 
#cert_password=test #password to that certificate if any
 
users_per_backend=10
 
#backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend
 
backend=/usr/bin/mono /home/hanzz/code/networkplugin-csharp/msnp-sharp-backend/bin/Debug/msnp-sharp-backend.exe
 
backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend
 
#backend=/usr/bin/mono /home/hanzz/code/networkplugin-csharp/msnp-sharp-backend/bin/Debug/msnp-sharp-backend.exe
 
#backend=/home/hanzz/code/libtransport/backends/frotz/spectrum2_frotz_backend
 
#backend=../../backends/libircclient-qt/spectrum2_libircclient-qt_backend
 
#protocol=prpl-msn
 
protocol=any
 
#protocol=prpl-icq
 

	
src/mysqlbackend.cpp
Show inline comments
 
@@ -203,14 +203,14 @@ int MySQLBackend::Statement::fetch() {
 
}
 

	
 
template <typename T>
 
MySQLBackend::Statement& MySQLBackend::Statement::operator << (const T& t) {
 
	if (m_offset >= m_params.size())
 
		return *this;
 
	int *data = (int *) m_params[m_offset].buffer;
 
	*data = (int) t;
 
	T *data = (T *) m_params[m_offset].buffer;
 
	*data = (T) t;
 

	
 
// 	LOG4CXX_INFO(logger, "adding " << m_offset << ":" << (int) t);
 
	m_offset++;
 
	return *this;
 
}
 

	
0 comments (0 inline, 0 general)