# HG changeset patch # User David Demelier # Date 1530948070 -7200 # Node ID 0dd4fb9dfcc82a0548f71f1aaa5699a22598235b # Parent 48afa8c41f501328e686e303be9635864cfca8f7 Irccd: disable pid, gid, uid and daemon options, closes #846 @1h Those options are too platform specific and should be handled by the service manager instead. diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 CHANGES.md --- a/CHANGES.md Sat Jul 07 08:56:25 2018 +0200 +++ b/CHANGES.md Sat Jul 07 09:21:10 2018 +0200 @@ -10,7 +10,8 @@ default (#607), - New sections `[paths]` and `[paths.plugin]` have been added to control standard paths for both irccd and plugins (#611), - - If Mercurial is found, the version is bundled in `irccd --version`. + - If Mercurial is found, the version is bundled in `irccd --version`, + - Irccd no longer supports uid, gid, pid and daemon features (#846). Irccd test: diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 CMakeLists.txt --- a/CMakeLists.txt Sat Jul 07 08:56:25 2018 +0200 +++ b/CMakeLists.txt Sat Jul 07 09:21:10 2018 +0200 @@ -76,8 +76,6 @@ include(cmake/function/IrccdIndentMessage.cmake) include(cmake/check/PutTime.cmake) -include(cmake/check/UidIsSigned.cmake) -include(cmake/check/GidIsSigned.cmake) include(cmake/IrccdVersion.cmake) include(cmake/IrccdOptions.cmake) diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 cmake/IrccdSystem.cmake --- a/cmake/IrccdSystem.cmake Sat Jul 07 08:56:25 2018 +0200 +++ b/cmake/IrccdSystem.cmake Sat Jul 07 09:21:10 2018 +0200 @@ -95,13 +95,9 @@ # # The following variables are defined in irccd/sysconfig.h # -# HAVE_DAEMON True if daemon(3), # HAVE_GETLOGIN True if getlogin(3) function (and unistd.h) -# HAVE_GETPID True if has getpid(2) function (and sys/types.h and unistd.h and grp.h), # HAVE_POPEN True if has popen(3) function (in stdio.h) -# HAVE_SETGID True if has setgid(2) function and getgrnam(3) (and sys/types.h and unistd.h and pwd.h), # HAVE_SETPROGNAME True if setprogname(3) is available from C library, -# HAVE_SETUID True if has setuid(2) function and getpwnam(3) (and sys/types.h and unistd.h and pwd.h), # HAVE_STAT True if has stat(2) function (and sys/types.h and sys/stat.h), # HAVE_STAT_ST_DEV The struct stat has st_dev field, # HAVE_STAT_ST_INO The struct stat has st_ino field, @@ -123,11 +119,6 @@ # Check for sys/types.h check_include_file(sys/types.h HAVE_SYS_TYPES_H) -# Check for daemon(3) function, include: -# -# #include -check_function_exists(daemon HAVE_DAEMON) - # Check of setprogname(3) function, include: # # #include @@ -144,33 +135,6 @@ set(HAVE_GETLOGIN FALSE) endif () -# getpid() function -# -# If HAVE_GETPID is defined, include: -# -# #include -# #include -check_function_exists(getpid HAVE_GETPID) - -if (NOT HAVE_UNISTD_H OR NOT HAVE_SYS_TYPES_H) - set(HAVE_GETPID FALSE) -endif () - -# setgid() function (and getgrnam) -# -# If HAVE_SETGID is defined, include: -# -# #include -# #include -# #include // only for getgrnam -check_include_file(grp.h HAVE_GRP_H) -check_function_exists(getgrnam HAVE_GETGRNAM) -check_function_exists(setgid HAVE_SETGID) - -if (NOT HAVE_UNISTD_H OR NOT HAVE_SYS_TYPES_H OR NOT HAVE_GETGRNAM OR NOT HAVE_GRP_H) - set(HAVE_SETGID FALSE) -endif () - # popen() function # # If HAVE_POPEN is defined, include; @@ -178,21 +142,6 @@ # #include check_function_exists(popen HAVE_POPEN) -# setuid() function (and getpwnam) -# -# If HAVE_SETUID is defined, include: -# -# #include -# #include -# #include // only for getpwnam -check_include_file(pwd.h HAVE_PWD_H) -check_function_exists(getpwnam HAVE_GETPWNAM) -check_function_exists(setuid HAVE_SETUID) - -if (NOT HAVE_UNISTD_H OR NOT HAVE_SYS_TYPES_H OR NOT HAVE_GETPWNAM OR NOT HAVE_PWD_H) - set(HAVE_SETUID FALSE) -endif () - # stat(2) function # # If HAVE_STAT is defined, include: diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 cmake/check/GidIsSigned.cmake --- a/cmake/check/GidIsSigned.cmake Sat Jul 07 08:56:25 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -# -# CMakeLists.txt -- CMake build system for irccd -# -# Copyright (c) 2013-2018 David Demelier -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -include(CheckCXXSourceCompiles) - -# Check if gid_t is signed. -check_cxx_source_compiles( - "#include - - #include - - int main() - { - static_assert(std::is_signed::value, \"gid is signed\"); - } - " - HAVE_SIGNED_GID_T -) diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 cmake/check/UidIsSigned.cmake --- a/cmake/check/UidIsSigned.cmake Sat Jul 07 08:56:25 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -# -# CMakeLists.txt -- CMake build system for irccd -# -# Copyright (c) 2013-2018 David Demelier -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -include(CheckCXXSourceCompiles) - -# Check if uid_t is signed. -check_cxx_source_compiles( - "#include - - #include - - int main() - { - static_assert(std::is_signed::value, \"uid is signed\"); - } - " - HAVE_SIGNED_UID_T -) diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 cmake/internal/sysconfig.hpp.in --- a/cmake/internal/sysconfig.hpp.in Sat Jul 07 08:56:25 2018 +0200 +++ b/cmake/internal/sysconfig.hpp.in Sat Jul 07 09:21:10 2018 +0200 @@ -67,15 +67,9 @@ * ------------------------------------------------------------------ */ -#cmakedefine HAVE_DAEMON #cmakedefine HAVE_GETLOGIN -#cmakedefine HAVE_GETPID #cmakedefine HAVE_POPEN -#cmakedefine HAVE_SETGID #cmakedefine HAVE_SETPROGNAME -#cmakedefine HAVE_SETUID -#cmakedefine HAVE_SIGNED_GID_T -#cmakedefine HAVE_SIGNED_UID_T #cmakedefine HAVE_STAT #cmakedefine HAVE_STAT_ST_ATIME #cmakedefine HAVE_STAT_ST_BLKSIZE diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 doc/examples/irccd.conf.sample --- a/doc/examples/irccd.conf.sample Sat Jul 07 08:56:25 2018 +0200 +++ b/doc/examples/irccd.conf.sample Sat Jul 07 09:21:10 2018 +0200 @@ -2,18 +2,6 @@ # irccd.conf -- config file for irccd # -# Section general: -# This section describe global options used by irccd. -# -# [general] -# uid = "nobody" # (string or number) the user id to use (Optional, default: none), -# gid = "nobody" # (string or number) the group id to use (Optional, default: none), -# foreground = false # (bool) set to true to not daemonize (Optional, default: false), -# pidfile = "/tmp/irccd.pid" # (string) path to a file where to store the irccd pid (Optional, default: none). - -[general] -foreground = true - # Section plugins: # Load plugins by name or by paths. # diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 doc/src/irccd.conf.md --- a/doc/src/irccd.conf.md Sat Jul 07 08:56:25 2018 +0200 +++ b/doc/src/irccd.conf.md Sat Jul 07 09:21:10 2018 +0200 @@ -67,31 +67,6 @@ - abc - server-tz2 -# The general section - -This section contains global options that are used in the whole irccd -application. - -The available options: - - - **uid**: (string or number) the user id to use (Optional, default: none), - - **gid**: (string or number) the group id to use (Optional, default: none), - - **foreground**: (bool) set to true to not daemonize - (Optional, default: false) - - **pidfile**: (string) path to a file where to store the irccd pid - (Optional, default: none). - -**Warning:** these options are available only if the system supports them. - -## Example - -```ini -[general] -pidfile = "/var/run/irccd/pid" -uid = "nobody" -gid = 1002 -``` - # The logs section This section can let you configure how irccd should log the messages. diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 doc/src/irccd.md --- a/doc/src/irccd.md Sat Jul 07 08:56:25 2018 +0200 +++ b/doc/src/irccd.md Sat Jul 07 09:21:10 2018 +0200 @@ -14,7 +14,6 @@ The following options are available: - `-c, --config file`: specify the configuration file, - - `-f, --foreground`: do not run as a daemon, - `-v, --verbose`: be verbose, - `--version`: show the version. diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 irccd/main.cpp --- a/irccd/main.cpp Sat Jul 07 08:56:25 2018 +0200 +++ b/irccd/main.cpp Sat Jul 07 09:21:10 2018 +0200 @@ -18,18 +18,6 @@ #include "sysconfig.hpp" -#if defined(HAVE_GETPID) -# include -# include -# include -# include -# include -#endif - -#if defined(HAVE_DAEMON) -# include -#endif - #include #include @@ -93,7 +81,6 @@ std::cerr << "usage: irccd [options...]\n\n"; std::cerr << "Available options:\n"; std::cerr << " -c, --config file specify the configuration file\n"; - std::cerr << " -f, --foreground do not run as a daemon\n"; std::cerr << " -h, --help show this help\n"; std::cerr << " -v, --verbose be verbose\n"; std::cerr << " --version show the version\n"; @@ -156,8 +143,6 @@ option::options options{ { "-c", true }, { "--config", true }, - { "-f", false }, - { "--foreground", false }, { "-h", false }, { "--help", false }, { "-v", false }, diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 libcommon/irccd/system.cpp --- a/libcommon/irccd/system.cpp Sat Jul 07 08:56:25 2018 +0200 +++ b/libcommon/irccd/system.cpp Sat Jul 07 09:21:10 2018 +0200 @@ -421,78 +421,6 @@ // }}} -// {{{ set_uid - -#if defined(HAVE_SETUID) - -/* - * Requires: - * - - * - - */ -void set_uid(const std::string& value) -{ - assert(value.c_str()); - -#if defined(HAVE_SIGNED_UID_T) - auto id = string_util::to_int(value); -#else - auto id = string_util::to_uint(value); -#endif - - if (!id) { - auto pw = getpwnam(value.c_str()); - - if (!pw) - throw std::runtime_error(string_util::sprintf("uid %s not found", value)); - - id = pw->pw_uid; - } - - if (setuid(*id) < 0) - throw std::runtime_error(std::strerror(errno)); -} - -#endif // !HAVE_SETUID - -// }}} - -// {{{ set_gid - -#if defined(HAVE_SETGID) - -/* - * Requires: - * - - * - - */ -void set_gid(const std::string& value) -{ - assert(value.c_str()); - -#if defined(HAVE_SIGNED_GID_T) - auto id = string_util::to_int(value); -#else - auto id = string_util::to_uint(value); -#endif - - if (!id) { - auto gr = getgrnam(value.c_str()); - - if (!gr) - throw std::runtime_error(string_util::sprintf("gid %s not found", value)); - - id = gr->gr_gid; - } - - if (setgid(*id) < 0) - throw std::runtime_error(std::strerror(errno)); -} - -#endif // !HAVE_SETGID - -// }}} - // {{{ cachedir boost::filesystem::path cachedir() diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 libcommon/irccd/system.hpp --- a/libcommon/irccd/system.hpp Sat Jul 07 08:56:25 2018 +0200 +++ b/libcommon/irccd/system.hpp Sat Jul 07 09:21:10 2018 +0200 @@ -89,28 +89,6 @@ */ std::string home(); -#if defined(HAVE_SETUID) - -/** - * Set the effective uid by name or numeric value. - * - * \param value the value - */ -void set_uid(const std::string& value); - -#endif - -#if defined(HAVE_SETGID) - -/** - * Set the effective gid by name or numeric value. - * - * \param value the value - */ -void set_gid(const std::string& value); - -#endif - /** * Get the cache directory as specified as compile time option * IRCCD_WITH_CACHEDIR, if the value is absolute, it is returned as-is. diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 libirccd/irccd/daemon/irccd.cpp --- a/libirccd/irccd/daemon/irccd.cpp Sat Jul 07 08:56:25 2018 +0200 +++ b/libirccd/irccd/daemon/irccd.cpp Sat Jul 07 09:21:10 2018 +0200 @@ -153,65 +153,6 @@ )); } -void irccd::load_pid() -{ - const auto path = config_.get("general").get("pidfile").value(); - - if (path.empty()) - return; - -#if defined(HAVE_GETPID) - std::ofstream out(path, std::ofstream::trunc); - - if (!out) - logger_->warning() << "irccd: could not open" << path << ": " << std::strerror(errno) << std::endl; - else { - logger_->debug() << "irccd: pid written in " << path << std::endl; - out << getpid() << std::endl; - } -#else - logger_->warning() << "irccd: pidfile not supported on this platform" << std::endl; -#endif -} - -void irccd::load_gid() -{ - const auto gid = config_.get("general").get("gid").value(); - - if (gid.empty()) - return; - -#if defined(HAVE_SETGID) - try { - sys::set_gid(gid); - logger_->info() << "irccd: setting gid to: " << gid << std::endl; - } catch (const std::exception& ex) { - logger_->warning() << "irccd: failed to set gid: " << ex.what() << std::endl; - } -#else - logger_->warning() << "irccd: gid option not supported" << std::endl; -#endif -} - -void irccd::load_uid() -{ - const auto uid = config_.get("general").get("uid").value(); - - if (uid.empty()) - return; - -#if defined(HAVE_SETUID) - try { - sys::set_uid(uid); - logger_->info() << "irccd: setting uid to: " << uid << std::endl; - } catch (const std::exception& ex) { - logger_->warning() << "irccd: failed to set uid: " << ex.what() << std::endl; - } -#else - logger_->warning() << "irccd: uid option not supported" << std::endl; -#endif -} - irccd::irccd(boost::asio::io_service& service, std::string config) : config_(std::move(config)) , service_(service) @@ -250,13 +191,6 @@ else logger_->info() << "irccd: reloading configuration" << std::endl; - // [general] section. - if (!loaded_) { - load_pid(); - load_gid(); - load_uid(); - } - if (!loaded_) tpt_service_->load(config_); diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 libirccd/irccd/daemon/irccd.hpp --- a/libirccd/irccd/daemon/irccd.hpp Sat Jul 07 08:56:25 2018 +0200 +++ b/libirccd/irccd/daemon/irccd.hpp Sat Jul 07 09:21:10 2018 +0200 @@ -79,9 +79,6 @@ void load_logs_syslog(); void load_logs(); void load_formats(); - void load_pid(); - void load_gid(); - void load_uid(); public: /** diff -r 48afa8c41f50 -r 0dd4fb9dfcc8 systemd/irccd.service --- a/systemd/irccd.service Sat Jul 07 08:56:25 2018 +0200 +++ b/systemd/irccd.service Sat Jul 07 09:21:10 2018 +0200 @@ -3,7 +3,6 @@ After=network.target [Service] -Type=forking ExecStart=@PATH@ [Install]