From 7b05ec98b5a3227967c82f601a1c06ffd5c6dee6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 23 Oct 2003 12:14:48 +0000 Subject: [PATCH] Change owner of log file WRT uid setting --- src/Makefile.am | 4 +-- src/proxy.sh | 86 --------------------------------------------- src/yaz-proxy-main.cpp | 12 +++++-- src/yaz-proxy.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 90 deletions(-) delete mode 100755 src/proxy.sh create mode 100755 src/yaz-proxy.sh diff --git a/src/Makefile.am b/src/Makefile.am index 09eb729..95be80e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.17 2003-10-23 10:02:14 adam Exp $ +## $Id: Makefile.am,v 1.18 2003-10-23 12:14:48 adam Exp $ AM_CXXFLAGS = $(YAZINC) -I$(srcdir)/../include $(XML2_CFLAGS) @@ -13,7 +13,7 @@ libyazcpp_la_SOURCES=yaz-socket-manager.cpp yaz-pdu-assoc.cpp \ bin_PROGRAMS = yaz-proxy noinst_PROGRAMS = yaz-my-server yaz-my-client bin_SCRIPTS = yaz++-config -EXTRA_DIST = config.xml proxy.sh +EXTRA_DIST = config.xml yaz-proxy.sh yaz_my_client_SOURCES=yaz-my-client.cpp diff --git a/src/proxy.sh b/src/proxy.sh deleted file mode 100755 index 8adf7e0..0000000 --- a/src/proxy.sh +++ /dev/null @@ -1,86 +0,0 @@ -#! /bin/sh -# -# skeleton example file to build /etc/init.d/ scripts. -# This file should be used to construct scripts for /etc/init.d. -# -# Written by Miquel van Smoorenburg . -# Modified for Debian GNU/Linux -# by Ian Murdock . -# -# Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl -# -PATH=/usr/local/bin:/bin:/usr/bin -export PATH - -# Proxy CWD is here. Should be writable by it. -DIR=/var/yaz-proxy -# Proxy Path -DAEMON=/usr/local/bin/yaz-proxy -# Proxy PIDFILE. Must be writable by it. -PIDFILE=$DIR/yaz-proxy.pid -# Log file -LOGFILE=/var/log/yaz-proxy.log -# Port -PORT=9000 -# Run as this user. Set to empty to keep uid as is -RUNAS=nobody -RUNAS= -# Extra args . Config file _WITH_ option -ARGS="-c config.xml" - -if test -n "RUNAS"; then - ARGS="-u $RUNAS $ARGS" -fi - -# Name, Description (not essential) -NAME=yaz-proxy -DESC="YAZ proxy" - -test -d $DIR || exit 0 -test -f $DAEMON || exit 0 - -set -e - -case "$1" in - start) - echo -n "Starting $DESC: " - cd $DIR - $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT & - echo "$NAME." - ;; - stop) - echo -n "Stopping $DESC: " - - if test -f $PIDFILE; then - kill `cat $PIDFILE` - rm -f $PIDFILE - echo "$NAME." - else - echo "No PID $PIDFILE" - fi - ;; - reload) - if test -f $PIDFILE; then - kill -INT `cat $PIDFILE` - fi - ;; - restart|force-reload) - echo -n "Restarting $DESC: " - if test -f $PIDFILE; then - kill `cat $PIDFILE` - rm -f $PIDFILE - fi - sleep 1 - cd $DIR - $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT & - echo "$NAME." - ;; - *) - N=/etc/init.d/$NAME - # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 - echo "Usage: $N {start|stop|restart|force-reload}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/src/yaz-proxy-main.cpp b/src/yaz-proxy-main.cpp index 8a37ada..af64283 100644 --- a/src/yaz-proxy-main.cpp +++ b/src/yaz-proxy-main.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-main.cpp,v 1.22 2003-10-23 11:45:08 adam Exp $ + * $Id: yaz-proxy-main.cpp,v 1.23 2003-10-23 12:14:48 adam Exp $ */ #include @@ -26,6 +26,7 @@ void usage(char *prog) static char *pid_fname = 0; static char *uid = 0; +static char *log_file = 0; int args(Yaz_Proxy *proxy, int argc, char **argv) { @@ -77,6 +78,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv) break; case 'l': yaz_log_init_file (arg); + log_file = xstrdup(arg); break; case 'm': proxy->set_max_clients(atoi(arg)); @@ -150,12 +152,18 @@ int main(int argc, char **argv) if (uid) { struct passwd *pw; - + if (!(pw = getpwnam(uid))) { yaz_log(LOG_FATAL, "%s: Unknown user", uid); exit(3); } + if (log_file) + { + chown(log_file, pw->pw_uid, pw->pw_gid); + xfree(log_file); + } + if (setuid(pw->pw_uid) < 0) { yaz_log(LOG_FATAL|LOG_ERRNO, "setuid"); diff --git a/src/yaz-proxy.sh b/src/yaz-proxy.sh new file mode 100755 index 0000000..10fb455 --- /dev/null +++ b/src/yaz-proxy.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# +# skeleton example file to build /etc/init.d/ scripts. +# This file should be used to construct scripts for /etc/init.d. +# +# Written by Miquel van Smoorenburg . +# Modified for Debian GNU/Linux +# by Ian Murdock . +# +# Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl +# +PATH=/usr/local/bin:/bin:/usr/bin +export PATH + +# Proxy CWD is here. Should be writable by it. +DIR=/var/yaz-proxy +# Proxy Path +DAEMON="/usr/local/bin/yaz-proxy" + +# Proxy PIDFILE. Must be writable by it. +PIDFILE="$DIR/yaz-proxy.pid" + +# Log file +LOGFILE=/var/log/yaz-proxy.log + +# Port +PORT=9000 + +# Run as this user. Set to empty to keep uid as is +RUNAS=nobody + +# Extra args . Config file _WITH_ option +ARGS="-c config.xml" + +if test -n "RUNAS"; then + ARGS="-u $RUNAS $ARGS" +fi + +# Name, Description (not essential) +NAME=yaz-proxy +DESC="YAZ proxy" + +test -d $DIR || exit 0 +test -f $DAEMON || exit 0 + +set -e + +case "$1" in + start) + echo -n "Starting $DESC: " + cd $DIR + $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT & + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + + if test -f $PIDFILE; then + kill `cat $PIDFILE` + rm -f $PIDFILE + echo "$NAME." + else + echo "No PID $PIDFILE" + fi + ;; + reload) + if test -f $PIDFILE; then + kill -INT `cat $PIDFILE` + fi + ;; + restart|force-reload) + echo -n "Restarting $DESC: " + if test -f $PIDFILE; then + kill `cat $PIDFILE` + rm -f $PIDFILE + fi + sleep 1 + cd $DIR + $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT & + echo "$NAME." + ;; + *) + N=/etc/init.d/$NAME + # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 1 + ;; +esac + +exit 0 -- 1.7.10.4