changeset 708:0dd4fb9dfcc8

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.
author David Demelier <markand@malikania.fr>
date Sat, 07 Jul 2018 09:21:10 +0200
parents 48afa8c41f50
children 1b04ffb2b35e
files CHANGES.md CMakeLists.txt cmake/IrccdSystem.cmake cmake/check/GidIsSigned.cmake cmake/check/UidIsSigned.cmake cmake/internal/sysconfig.hpp.in doc/examples/irccd.conf.sample doc/src/irccd.conf.md doc/src/irccd.md irccd/main.cpp libcommon/irccd/system.cpp libcommon/irccd/system.hpp libirccd/irccd/daemon/irccd.cpp libirccd/irccd/daemon/irccd.hpp systemd/irccd.service
diffstat 15 files changed, 2 insertions(+), 343 deletions(-) [+]
line wrap: on
line diff
--- 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:
 
--- 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)
--- 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 <cstdlib>
-check_function_exists(daemon HAVE_DAEMON)
-
 # Check of setprogname(3) function, include:
 #
 # #include <cstdlib>
@@ -144,33 +135,6 @@
     set(HAVE_GETLOGIN FALSE)
 endif ()
 
-# getpid() function
-#
-# If HAVE_GETPID is defined, include:
-#
-# #include <sys/types.h>
-# #include <unistd.h>
-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 <sys/types.h>
-# #include <unistd.h>
-# #include <grp.h>        // 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 <cstdio>
 check_function_exists(popen HAVE_POPEN)
 
-# setuid() function (and getpwnam)
-#
-# If HAVE_SETUID is defined, include:
-#
-# #include <sys/types.h>
-# #include <unistd.h>
-# #include <pwd.h>        // 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:
--- 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 <markand@malikania.fr>
-#
-# 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 <sys/types.h>
-
-     #include <type_traits>
-
-     int main()
-     {
-        static_assert(std::is_signed<gid_t>::value, \"gid is signed\");
-     }
-    "
-    HAVE_SIGNED_GID_T
-)
--- 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 <markand@malikania.fr>
-#
-# 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 <sys/types.h>
-
-     #include <type_traits>
-
-     int main()
-     {
-        static_assert(std::is_signed<uid_t>::value, \"uid is signed\");
-     }
-    "
-    HAVE_SIGNED_UID_T
-)
--- 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
--- 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.
 #
--- 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.
--- 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.
 
--- 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 <sys/types.h>
-#  include <unistd.h>
-#  include <cerrno>
-#  include <cstring>
-#  include <fstream>
-#endif
-
-#if defined(HAVE_DAEMON)
-#  include <cstdlib>
-#endif
-
 #include <csignal>
 #include <iostream>
 
@@ -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   },
--- 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:
- *   - <sys/types.h>
- *   - <unistd.h>
- */
-void set_uid(const std::string& value)
-{
-    assert(value.c_str());
-
-#if defined(HAVE_SIGNED_UID_T)
-    auto id = string_util::to_int<uid_t>(value);
-#else
-    auto id = string_util::to_uint<uid_t>(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:
- *   - <sys/types.h>
- *   - <unistd.h>
- */
-void set_gid(const std::string& value)
-{
-    assert(value.c_str());
-
-#if defined(HAVE_SIGNED_GID_T)
-    auto id = string_util::to_int<gid_t>(value);
-#else
-    auto id = string_util::to_uint<gid_t>(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()
--- 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.
--- 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_);
 
--- 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:
     /**
--- 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]