summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Alexander <wired@gentoo.org>2012-11-21 18:11:31 +0000
committerAlex Alexander <wired@gentoo.org>2012-11-21 18:11:31 +0000
commit0d94c5f0feb833853bb82498adb19418aeb8f6c6 (patch)
tree17f45102bb9de5f98d91373e03cfb00c553f9f81 /net-irc/znc
parentAdd ~amd64 (diff)
downloadgentoo-2-0d94c5f0feb833853bb82498adb19418aeb8f6c6.tar.gz
gentoo-2-0d94c5f0feb833853bb82498adb19418aeb8f6c6.tar.bz2
gentoo-2-0d94c5f0feb833853bb82498adb19418aeb8f6c6.zip
version bump, bug #438430. added system-wide daemon use flag that installs init.d/conf.d files, bug #415389. systemWideConfig patch.
(Portage version: 2.2.0_alpha142/cvs/Linux x86_64, signed Manifest commit with key EB9B4AFA)
Diffstat (limited to 'net-irc/znc')
-rw-r--r--net-irc/znc/ChangeLog11
-rw-r--r--net-irc/znc/files/znc-1.0-systemwideconfig.patch147
-rw-r--r--net-irc/znc/files/znc.confd7
-rw-r--r--net-irc/znc/files/znc.initd39
-rw-r--r--net-irc/znc/metadata.xml1
-rw-r--r--net-irc/znc/znc-1.0.ebuild138
6 files changed, 342 insertions, 1 deletions
diff --git a/net-irc/znc/ChangeLog b/net-irc/znc/ChangeLog
index 672f41f2c3e0..d96061329484 100644
--- a/net-irc/znc/ChangeLog
+++ b/net-irc/znc/ChangeLog
@@ -1,6 +1,15 @@
# ChangeLog for net-irc/znc
# Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/net-irc/znc/ChangeLog,v 1.59 2012/05/29 17:49:40 jlec Exp $
+# $Header: /var/cvsroot/gentoo-x86/net-irc/znc/ChangeLog,v 1.60 2012/11/21 18:11:31 wired Exp $
+
+*znc-1.0 (21 Nov 2012)
+
+ 21 Nov 2012; Alex Alexander <wired@gentoo.org> +znc-1.0.ebuild,
+ +files/znc-1.0-systemwideconfig.patch, +files/znc.confd, +files/znc.initd,
+ metadata.xml:
+ version bump, bug #438430. added system-wide daemon use flag that installs
+ init.d/conf.d files, bug #415389. systemWideConfig patch. Many thanks to
+ Manuel Rüger and Uli Schlachter.
*znc-0.206 (29 May 2012)
diff --git a/net-irc/znc/files/znc-1.0-systemwideconfig.patch b/net-irc/znc/files/znc-1.0-systemwideconfig.patch
new file mode 100644
index 000000000000..336163dd6a0c
--- /dev/null
+++ b/net-irc/znc/files/znc-1.0-systemwideconfig.patch
@@ -0,0 +1,147 @@
+diff --git a/include/znc/znc.h b/include/znc/znc.h
+index 03be646..f493c83 100644
+--- a/include/znc/znc.h
++++ b/include/znc/znc.h
+@@ -169,6 +169,8 @@ public:
+
+ static void DumpConfig(const CConfig* Config);
+
++ void SetSystemWideConfig(bool systemWideConfig);
++
+ private:
+ CFile* InitPidFile();
+ bool DoRehash(CString& sError);
+@@ -209,6 +211,7 @@ protected:
+ unsigned int m_uiConnectPaused;
+ TCacheMap<CString> m_sConnectThrottle;
+ bool m_bProtectWebSessions;
++ bool m_bSystemWideConfig;
+ };
+
+ #endif // !_ZNC_H
+diff --git a/src/main.cpp b/src/main.cpp
+index a1f3904..4950911 100644
+--- a/src/main.cpp
++++ b/src/main.cpp
+@@ -10,6 +10,9 @@
+ #include <znc/FileUtils.h>
+ #include <sys/wait.h>
+ #include <signal.h>
++#include <sys/types.h>
++#include <pwd.h>
++#include <grp.h>
+
+ using std::cout;
+ using std::endl;
+@@ -46,6 +49,7 @@ static const struct option g_LongOpts[] = {
+ { "makepass", no_argument, 0, 's' },
+ { "makepem", no_argument, 0, 'p' },
+ { "datadir", required_argument, 0, 'd' },
++ { "system-wide-config-as", required_argument, 0, 'S' },
+ { 0, 0, 0, 0 }
+ };
+
+@@ -127,6 +131,8 @@ int main(int argc, char** argv) {
+ bool bMakeConf = false;
+ bool bMakePass = false;
+ bool bAllowRoot = false;
++ bool bSystemWideConfig = false;
++ CString sSystemWideConfigUser = "znc";
+ bool bForeground = false;
+ #ifdef ALWAYS_RUN_IN_FOREGROUND
+ bForeground = true;
+@@ -135,7 +141,7 @@ int main(int argc, char** argv) {
+ bool bMakePem = false;
+ #endif
+
+- while ((iArg = getopt_long(argc, argv, "hvnrcspd:Df", g_LongOpts, &iOptIndex)) != -1) {
++ while ((iArg = getopt_long(argc, argv, "hvnrcspd:DfS:", g_LongOpts, &iOptIndex)) != -1) {
+ switch (iArg) {
+ case 'h':
+ GenerateHelp(argv[0]);
+@@ -153,6 +159,10 @@ int main(int argc, char** argv) {
+ case 'c':
+ bMakeConf = true;
+ break;
++ case 'S':
++ bSystemWideConfig = true;
++ sSystemWideConfigUser = optarg;
++ break;
+ case 's':
+ bMakePass = true;
+ break;
+@@ -187,8 +197,36 @@ int main(int argc, char** argv) {
+ return 1;
+ }
+
++ if (bSystemWideConfig && getuid() == 0) {
++ struct passwd *pwd;
++
++ pwd = getpwnam(sSystemWideConfigUser.c_str());
++ if (pwd == NULL) {
++ CUtils::PrintError("Daemon user not found.");
++ return 1;
++ }
++
++ if ((long) pwd->pw_uid == 0) {
++ CUtils::PrintError("Please define a daemon user other than root.");
++ return 1;
++ }
++ if (setgroups(0, NULL) != 0) {
++ CUtils::PrintError("setgroups: Unable to clear supplementary group IDs");
++ return 1;
++ }
++ if (setgid((long) pwd->pw_gid) != 0) {
++ CUtils::PrintError("setgid: Unable to drop group privileges");
++ return 1;
++ }
++ if (setuid((long) pwd->pw_uid) != 0) {
++ CUtils::PrintError("setuid: Unable to drop user privileges");
++ return 1;
++ }
++ }
++
+ CZNC* pZNC = &CZNC::Get();
+ pZNC->InitDirs(((argc) ? argv[0] : ""), sDataDir);
++ pZNC->SetSystemWideConfig(bSystemWideConfig);
+
+ #ifdef HAVE_LIBSSL
+ if (bMakePem) {
+@@ -229,7 +267,7 @@ int main(int argc, char** argv) {
+ CUtils::PrintStatus(true, "");
+ }
+
+- if (isRoot()) {
++ if (isRoot() && !bSystemWideConfig) {
+ CUtils::PrintError("You are running ZNC as root! Don't do that! There are not many valid");
+ CUtils::PrintError("reasons for this and it can, in theory, cause great damage!");
+ if (!bAllowRoot) {
+diff --git a/src/znc.cpp b/src/znc.cpp
+index 9469790..297b021 100644
+--- a/src/znc.cpp
++++ b/src/znc.cpp
+@@ -47,6 +47,7 @@ CZNC::CZNC() {
+ m_sConnectThrottle.SetTTL(30000);
+ m_pLockFile = NULL;
+ m_bProtectWebSessions = true;
++ m_bSystemWideConfig = false;
+ }
+
+ CZNC::~CZNC() {
+@@ -952,7 +953,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
+ CUtils::PrintMessage("");
+
+ File.UnLock();
+- return bFileOpen && CUtils::GetBoolInput("Launch ZNC now?", true);
++ return bFileOpen && !m_bSystemWideConfig && CUtils::GetBoolInput("Launch ZNC now?", true);
+ }
+
+ size_t CZNC::FilterUncommonModules(set<CModInfo>& ssModules) {
+@@ -1971,3 +1972,7 @@ void CZNC::LeakConnectQueueTimer(CConnectQueueTimer *pTimer) {
+ bool CZNC::WaitForChildLock() {
+ return m_pLockFile && m_pLockFile->ExLock();
+ }
++
++void CZNC::SetSystemWideConfig(bool systemWideConfig) {
++ m_bSystemWideConfig = systemWideConfig;
++}
diff --git a/net-irc/znc/files/znc.confd b/net-irc/znc/files/znc.confd
new file mode 100644
index 000000000000..44bb497eab5a
--- /dev/null
+++ b/net-irc/znc/files/znc.confd
@@ -0,0 +1,7 @@
+# /etc/conf.d/znc
+
+# Location of the znc configuration folder
+ZNC_CONF="/etc/znc"
+
+# User to run znc as
+ZNC_USER="znc"
diff --git a/net-irc/znc/files/znc.initd b/net-irc/znc/files/znc.initd
new file mode 100644
index 000000000000..8b7c8bca5ee4
--- /dev/null
+++ b/net-irc/znc/files/znc.initd
@@ -0,0 +1,39 @@
+#!/sbin/runscript
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/net-irc/znc/files/znc.initd,v 1.1 2012/11/21 18:11:31 wired Exp $
+
+extra_commands="config"
+extra_started_commands="reload save"
+
+depend() {
+ need net
+}
+
+start() {
+ ebegin "Starting ZNC"
+ start-stop-daemon --start --user ${ZNC_USER} --name znc \
+ --exec /usr/bin/znc -- -d ${ZNC_CONF}
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping ZNC"
+ start-stop-daemon --signal SIGINT --name znc \
+ --exec /usr/bin/znc -- -d ${ZNC_CONF}
+ eend $?
+}
+
+reload() {
+ ebegin "Reloading ZNC Configuration File from Disk"
+ start-stop-daemon --signal SIGHUP --name znc \
+ --exec /usr/bin/znc -- -d ${ZNC_CONF}
+ eend $?
+}
+
+save() {
+ ebegin "Saving ZNC Configuration File to Disk"
+ start-stop-daemon --signal SIGUSR1 --name znc \
+ --exec /usr/bin/znc -- -d ${ZNC_CONF}
+ eend $?
+}
diff --git a/net-irc/znc/metadata.xml b/net-irc/znc/metadata.xml
index ea5a9ff6de88..851c2f9c4ffa 100644
--- a/net-irc/znc/metadata.xml
+++ b/net-irc/znc/metadata.xml
@@ -7,6 +7,7 @@
<name>Alex Alexander</name>
</maintainer>
<use>
+ <flag name="daemon">Allow znc to run as a system-wide service. Installs an init script and creates a znc user:group.</flag>
<flag name="extras">Enable some additional modules</flag>
<flag name="ares">Enables support for asynchronous DNS using the c-ares library</flag>
<flag name="dns-threads">Use threads for DNS resolving</flag>
diff --git a/net-irc/znc/znc-1.0.ebuild b/net-irc/znc/znc-1.0.ebuild
new file mode 100644
index 000000000000..e61cd17d7f64
--- /dev/null
+++ b/net-irc/znc/znc-1.0.ebuild
@@ -0,0 +1,138 @@
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/net-irc/znc/znc-1.0.ebuild,v 1.1 2012/11/21 18:11:31 wired Exp $
+
+EAPI=5
+
+PYTHON_DEPEND="python? 3"
+inherit base python user
+
+MY_PV=${PV/_/-}
+DESCRIPTION="An advanced IRC Bouncer"
+HOMEPAGE="http://znc.in"
+SRC_URI="http://znc.in/releases/${PN}-${MY_PV}.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64 ~arm ~x86"
+IUSE="daemon debug ipv6 perl python ssl sasl tcl"
+
+RDEPEND="
+ perl? ( >=dev-lang/perl-5.10 )
+ sasl? ( >=dev-libs/cyrus-sasl-2 )
+ ssl? ( >=dev-libs/openssl-0.9.7d )
+ tcl? ( dev-lang/tcl )
+"
+DEPEND="
+ virtual/pkgconfig
+ perl? ( dev-lang/swig )
+ python? (
+ >=dev-lang/swig-2.0.2
+ >=dev-lang/perl-5.10
+ )
+ ${RDEPEND}
+"
+
+S=${WORKDIR}/${PN}-${MY_PV}
+
+PATCHES=(
+ "${FILESDIR}/${P}-systemwideconfig.patch"
+)
+
+pkg_setup() {
+ if use python; then
+ python_set_active_version 3
+ python_pkg_setup
+ fi
+ if use daemon; then
+ enewgroup ${PN}
+ enewuser ${PN} -1 -1 /dev/null ${PN}
+ fi
+}
+
+src_configure() {
+ econf \
+ $(use_enable debug) \
+ $(use_enable ipv6) \
+ $(use_enable perl) \
+ $(use python && echo "--enable-python=python-$(python_get_version)") \
+ $(use_enable sasl cyrus) \
+ $(use_enable ssl openssl) \
+ $(use_enable tcl tcl)
+}
+
+src_install() {
+ emake install DESTDIR="${D}"
+ dodoc AUTHORS README.md
+ if use daemon; then
+ newinitd "${FILESDIR}"/znc.initd znc
+ newconfd "${FILESDIR}"/znc.confd znc
+ fi
+}
+
+pkg_postinst() {
+ if use !daemon; then
+ elog
+ elog "Run 'znc --makeconf' as the user you want to run ZNC as"
+ elog "to make a configuration file"
+ elog "If you are using SSL you should also run 'znc --makepem'"
+ elog
+ else
+ elog
+ elog "An init-script was installed in /etc/init.d"
+ elog "A config file was installed in /etc/conf.d"
+ if [[ ! -d "${EROOT}"/etc/znc ]]; then
+ elog
+ elog "Run 'emerge --config znc' to configure ZNC"
+ elog "as a system-wide daemon."
+ elog
+ elog "If you are using SSL you should also run:"
+ elog " znc --system-wide-config-as znc --makepem -d /etc/znc"
+ elog "as root"
+ elog
+ elog "If migrating from a user-based install"
+ elog "you can use your existing config files:"
+ elog " mkdir /etc/znc"
+ elog " mv /home/\$USER/.znc/* /etc/znc/"
+ elog " rm -rf /home/\$USER/.znc"
+ elog " chown -R znc:znc /etc/znc"
+ elog
+ elog "If you already have znc set up and want take advantage of the"
+ elog "init script but skip of all the above, you can also edit"
+ elog " /etc/conf.d/znc"
+ elog "and adjust the variables to your current znc user and config"
+ elog "location."
+ else
+ elog "Existing config detected in /etc/znc"
+ elog "You're good to go :)"
+ fi
+ elog
+ fi
+}
+
+pkg_config() {
+ if use daemon && ! [[ -d "${EROOT}"/etc/znc ]]; then
+ einfo "Press ENTER to interactively create a new configuration file for znc."
+ einfo "To abort, press Control-C"
+ read
+ mkdir -p "${EROOT}"/etc/znc || die
+ chown -R ${PN}:${PN} "${EROOT}"/etc/znc ||
+ die "Setting permissions failed"
+ "${EROOT}"/usr/bin/znc --system-wide-config-as znc -c -r -d "${EROOT}"/etc/znc ||
+ die "Config failed"
+ echo
+ einfo "To start znc, run '/etc/init.d/znc start'"
+ einfo "or add znc to a runlevel:"
+ einfo " rc-update add znc default"
+ else
+ if use daemon; then
+ ewarn "/etc/znc already exists, aborting to avoid damaging"
+ ewarn "any existing configuration. If you are sure you want"
+ ewarn "to generate a new configuration, remove the folder"
+ ewarn "and try again."
+ else
+ ewarn "To configure znc as a system-wide daemon you have to"
+ ewarn "enable the 'daemon' use flag."
+ fi
+ fi
+}