From 19dab12a49b05e17b3fc9e6fc246c31f157b4f48 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Wed, 16 Apr 2008 12:50:14 -0700 Subject: [PATCH] Switch the user name on startup. --- apt-p2p.conf | 4 ++++ apt-p2p.py | 6 +++--- apt_p2p/apt_p2p_conf.py | 3 +++ debian/apt-p2p.conf.sgml | 8 ++++++++ debian/init.d | 2 +- debian/postinst | 8 ++++---- debian/postrm | 4 ++-- test.py | 3 +++ 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/apt-p2p.conf b/apt-p2p.conf index eb5d0ca..6528935 100644 --- a/apt-p2p.conf +++ b/apt-p2p.conf @@ -51,6 +51,9 @@ UNLOAD_PACKAGES_CACHE = 5m # This should be a time slightly less than the DHT's KEY_EXPIRE value. KEY_REFRESH = 57m +# The user name to try and run as (leave blank to run as current user) +USERNAME = apt-p2p + # Which DHT implementation to use. # It must be possible to do "from .DHT import DHT" to get a class that # implements the IDHT interface. There should also be a similarly named @@ -70,6 +73,7 @@ DHT-ONLY = no # bootstrap nodes to contact to join the DHT BOOTSTRAP = www.camrdale.org:9977 + www.camrdale.org:9976 steveholt.hopto.org:9976 # whether this node is a bootstrap node diff --git a/apt-p2p.py b/apt-p2p.py index c3d48ef..adbc7bd 100644 --- a/apt-p2p.py +++ b/apt-p2p.py @@ -53,9 +53,9 @@ if __name__ == '__main__': log.msg("Loading config files: '%s'" % "', '".join(DEFAULT_CONFIG_FILES + [config_file])) config_read = config.read(DEFAULT_CONFIG_FILES + [config_file]) log.msg("Successfully loaded config files: '%s'" % "', '".join(config_read)) -if config.has_option('DEFAULT', 'username') and config.get('DEFAULT', 'username'): - uid,gid = pwd.getpwnam(config.get('DEFAULT', 'username'))[2:4] -else: +try: + uid,gid = pwd.getpwnam(config.get('DEFAULT', 'USERNAME'))[2:4] +except: uid,gid = None,None log.msg('Starting application') diff --git a/apt_p2p/apt_p2p_conf.py b/apt_p2p/apt_p2p_conf.py index e4f0bf9..3f17473 100644 --- a/apt_p2p/apt_p2p_conf.py +++ b/apt_p2p/apt_p2p_conf.py @@ -73,6 +73,9 @@ DEFAULTS = { # This should be a time slightly less than the DHT's KEY_EXPIRE value. 'KEY_REFRESH': '57m', + # The user name to try and run as (leave blank to run as current user) + 'USERNAME': 'apt-p2p', + # Which DHT implementation to use. # It must be possible to do "from .DHT import DHT" to get a class that # implements the IDHT interface. diff --git a/debian/apt-p2p.conf.sgml b/debian/apt-p2p.conf.sgml index f73d85b..cd08a40 100644 --- a/debian/apt-p2p.conf.sgml +++ b/debian/apt-p2p.conf.sgml @@ -156,6 +156,14 @@ (Default is 57 minutes.) + + + + The user name to try and run as. + Leaving this blank will try to run as current user. + (Default is 'apt-p2p'.) + + diff --git a/debian/init.d b/debian/init.d index 2faf531..a3a374f 100755 --- a/debian/init.d +++ b/debian/init.d @@ -24,7 +24,7 @@ pidfile=$rundir/apt-p2p.pid logfile=/var/log/apt-p2p.log application=/usr/sbin/apt-p2p twistd=/usr/bin/twistd -user=aptp2p +user=apt-p2p group=nogroup [ -r /etc/default/apt-p2p ] && . /etc/default/apt-p2p diff --git a/debian/postinst b/debian/postinst index eb87fd2..24147f2 100644 --- a/debian/postinst +++ b/debian/postinst @@ -25,17 +25,17 @@ set -e case "$1" in configure) - if ! getent passwd aptp2p >/dev/null; then + if ! getent passwd apt-p2p >/dev/null; then adduser --quiet --system --no-create-home \ --home /var/cache/apt-p2p --disabled-password \ --disabled-login --shell /bin/false --ingroup nogroup \ - aptp2p + apt-p2p fi touch /var/log/apt-p2p.log - chown aptp2p:adm /var/log/apt-p2p.log + chown apt-p2p:adm /var/log/apt-p2p.log mkdir -p /var/cache/apt-p2p - chown -R aptp2p:adm /var/cache/apt-p2p + chown -R apt-p2p:adm /var/cache/apt-p2p ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/debian/postrm b/debian/postrm index b604ced..fa48524 100644 --- a/debian/postrm +++ b/debian/postrm @@ -24,8 +24,8 @@ if test "$1" = "purge"; then echo Purging apt-p2p cache directory rm -rf /var/cache/apt-p2p - if id aptp2p >/dev/null; then - deluser aptp2p + if id apt-p2p >/dev/null; then + deluser apt-p2p fi fi diff --git a/test.py b/test.py index ec64de2..150b5c2 100755 --- a/test.py +++ b/test.py @@ -372,6 +372,9 @@ UNLOAD_PACKAGES_CACHE = 5m # This should be a time slightly less than the DHT's KEY_EXPIRE value. KEY_REFRESH = 57m +# The user name to try and run as (leave blank to run as current user) +USERNAME = + # Which DHT implementation to use. # It must be possile to do "from .DHT import DHT" to get a class that # implements the IDHT interface. -- 2.39.5