1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-26 05:02:18 +00:00

Various fixes:

- add standard rc.subr startup script.
- add post-install message mentioning necessary configuration steps.
- move pid-file to /var/run, the usual place. Do setuid/setgid later,
so that we can create it.
- make message about stale pid file a bit more explanatory.
This commit is contained in:
Anders Nordby 2007-06-03 20:41:10 +00:00
parent 713a278bc4
commit e905822938
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=192644
5 changed files with 147 additions and 1 deletions

View File

@ -7,6 +7,7 @@
PORTNAME= pxe
PORTVERSION= 1.4.2
PORTREVISION= 1
CATEGORIES= net
MASTER_SITES= http://www.kano.org.uk/projects/pxe/ \
ftp://ftp.nuug.no/pub/anders/distfiles/
@ -14,15 +15,20 @@ MASTER_SITES= http://www.kano.org.uk/projects/pxe/ \
MAINTAINER= anders@FreeBSD.org
COMMENT= PXE daemon, set up a boot menu for netbooting PXE enabled clients
USE_RC_SUBR= pxe.sh
SUB_FILES= pkg-message
GNU_CONFIGURE= yes
CONFIGURE_ARGS+= --with-config=${PREFIX}/etc/pxe.conf \
--with-log=/var/log/pxe.log \
--with-setuid=nobody
DOCS= Changes INSTALL LICENCE README
DOCS= Changes INSTALL LICENCE README THANKS
.include <bsd.port.pre.mk>
post-patch:
${REINPLACE_CMD} -e 's|/tmp/pxe.pid|/var/run/pxe.pid|' ${WRKSRC}/autoconf.h.in
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/pxe ${PREFIX}/sbin/
${INSTALL_DATA} ${WRKSRC}/pxe.conf ${PREFIX}/etc/pxe.conf.sample
@ -33,4 +39,7 @@ do-install:
.endfor
.endif
post-install:
${CAT} ${PKGMESSAGE}
.include <bsd.port.post.mk>

101
net/pxe/files/patch-pxe.cc Normal file
View File

@ -0,0 +1,101 @@
--- pxe.cc.orig Sun Feb 2 13:39:26 2003
+++ pxe.cc Sun Jun 3 21:34:25 2007
@@ -208,6 +208,31 @@
return(retval);
}
+/******************************************************************************
+ * DoSetUID - set uid and gid *
+ ******************************************************************************/
+void DoSetUID()
+{
+ // set the UID/GID to a low user
+#ifndef NO_SUID
+ struct passwd *pw;
+ pw = getpwnam(SETUID);
+
+ if(NULL == pw)
+ std::cout << "Unable to find passwd entry for " << SETUID
+ << ", continuing with user id " << getuid() << "\n";
+ else
+ {
+ if((-1 == setgid(pw->pw_gid)) || (-1 == setegid(pw->pw_gid)))
+ std::cout << "Unable to change group id, continuing with group id "
+ << getgid() << "\n";
+ if((-1 == setuid(pw->pw_uid)) || (-1 == seteuid(pw->pw_uid)))
+ std::cout << "Unable to change user id, continuing with user id "
+ << getuid() << "\n";
+ }
+#endif
+}
+
/******************************************************************************
* main - kick things off and do cool things *
@@ -247,6 +272,15 @@
}
debug.close();
+ // check to see if the daemon is already running
+ chk = open(LOCKFILE, O_WRONLY|O_CREAT|O_EXCL, 0644);
+ if(-1 == chk)
+ {
+ std::cerr << "PXE daemon already running, or left-over pid file " << LOCKFILE << " exists?\n";
+ std::cerr << "Aborting startup.\n";
+ return(-1);
+ }
+
// redirect the file descriptors
if (0 == _debug) {
debug.open("/dev/null", std::ios::out);
@@ -258,34 +292,6 @@
debug.close();
}
-
- // set the UID/GID to a low user
-#ifndef NO_SUID
- struct passwd *pw;
- pw = getpwnam(SETUID);
-
- if(NULL == pw)
- std::cout << "Unable to find passwd entry for " << SETUID
- << ", continuing with user id " << getuid() << "\n";
- else
- {
- if((-1 == setgid(pw->pw_gid)) || (-1 == setegid(pw->pw_gid)))
- std::cout << "Unable to change group id, continuing with group id "
- << getgid() << "\n";
- if((-1 == setuid(pw->pw_uid)) || (-1 == seteuid(pw->pw_uid)))
- std::cout << "Unable to change user id, continuing with user id "
- << getuid() << "\n";
- }
-#endif
-
- // check to see if the daemon is already running
- chk = open(LOCKFILE, O_WRONLY|O_CREAT|O_EXCL, 0644);
- if(-1 == chk)
- {
- std::cerr << "PXE daemon already running\n";
- return(-1);
- }
-
// if not in debug mode, fork and go
if (0 == _debug) {
signal(SIGCHLD, SIG_IGN);
@@ -320,6 +326,7 @@
}
close(chk);
+ DoSetUID;
StartPxeService(configfile);
exit(0);
@@ -328,6 +335,7 @@
}
} else { // debug
+ DoSetUID;
StartPxeService(configfile);
}

View File

@ -0,0 +1,6 @@
===> CONFIGURATION NOTE:
You need to create a configuration file. Copy
%%PREFIX%%/etc/pxe.conf.sample to %%PREFIX%%/etc/pxe.conf
and change what you need there.
To enable the pxe daemon, add pxe_enable="YES" to your /etc/rc.conf.

29
net/pxe/files/pxe.sh.in Normal file
View File

@ -0,0 +1,29 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: pxe
# REQUIRE: NETWORKING
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the pxe daemon:
#
# pxe_enable="YES"
. %%RC_SUBR%%
name=pxe
rcvar=`set_rcvar`
command="%%PREFIX%%/sbin/pxe"
required_files=%%PREFIX%%/etc/pxe.conf
command_args="-c ${required_files}"
pidfile=/var/pxe/${name}.pid
# set defaults
pxe_enable=${pxe_enable:-"NO"}
load_rc_config ${name}
run_rc_command "$1"

View File

@ -4,4 +4,5 @@ etc/pxe.conf.sample
%%PORTDOCS%%share/doc/pxe/INSTALL
%%PORTDOCS%%share/doc/pxe/LICENCE
%%PORTDOCS%%share/doc/pxe/README
%%PORTDOCS%%share/doc/pxe/THANKS
%%PORTDOCS%%@dirrm share/doc/pxe