Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Sep 2008 17:23:06 GMT
From:      Frank Wall <fw@moov.de>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/127303: [patch] misc/amanda-server Add pkg-install to create missing user and group
Message-ID:  <200809111723.m8BHN6Ee025133@www.freebsd.org>
Resent-Message-ID: <200809111730.m8BHU2F3017145@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         127303
>Category:       ports
>Synopsis:       [patch] misc/amanda-server Add pkg-install to create missing user and group
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 11 17:30:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Frank Wall
>Release:        7.0-RELEASE-p4
>Organization:
>Environment:
FreeBSD XXX 7.0-RELEASE-p2 FreeBSD 7.0-RELEASE-p2 #0: Wed Jun 18 07:33:20 UTC 2008     root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
The ports misc/amanda-server and misc/amanda-client offer the possibility to set AMANDA_USER and AMANDA_GROUP variables to adjust user/group. But these ports do not check if the user/group already exists.

This make trouble when trying to build on a system where the (user defined) user or group does not exist. Think further, it makes it impossible to automate the build process for these ports when using custom AMANDA_USER and AMANDA_GROUP variables.


>How-To-Repeat:
1. set AMANDA_USER=amanda (or any user that does not currently exist on your system)
2. try to install misc/amanda-server or misc/amanda-client
3. install will fail:

[...]
/usr/sbin/chown amanda:operator /usr/local/var/amanda/gnutar-lists
chown: amanda: Invalid argument
*** Error code 1

>Fix:
I would choose to adjust the misc/amanda-server port to create the user and group if possible. A good example for this is mail/dovecot. I copied the pkg-install script from mail/dovecot and adjusted the Makefile a bit.

Now misc/amanda-server also takes AMANDA_UID and AMANDA_GID. This allows to automatically set up the user and group if it does not exist. Most users won't need this, but it allows to build these ports with e.g. ports-mgmt/tinderbox AND custom user/group settings.

I am using the following settings....
AMANDA_USER=amanda
AMANDA_UID=11

And with the Makefile patched and the new pkg-install script everything is fine now:
[...]
/usr/sbin/chown amanda:operator /usr/local/var/amanda/gnutar-lists
/usr/bin/touch /etc/amandates
/usr/sbin/chown amanda:operator /etc/amandates
===>   Compressing manual pages for amanda-client-2.5.1p3_3,1
[...]

The Makefile patch is below this line :-) The new pkg-install.in file is attached (with .txt file extension).
===================================================================
--- misc/amanda-server/Makefile.orig    2008-09-11 19:02:02.000000000 +0200
+++ misc/amanda-server/Makefile 2008-09-11 19:02:34.000000000 +0200
@@ -8,11 +8,11 @@
 PORTNAME=      amanda
 PORTVERSION=   2.5.1p3
 PORTREVISION?= 5
-PKGNAMESUFFIX?=        -server
 PORTEPOCH=     1
 CATEGORIES=    misc
 MASTER_SITES=  ${MASTER_SITE_SOURCEFORGE}
 MASTER_SITE_SUBDIR=    amanda
+PKGNAMESUFFIX?=        -server
 
 MAINTAINER=    kuriyama@FreeBSD.org
 COMMENT?=      The Advanced Maryland Automatic Network Disk Archiver (server)
@@ -38,11 +38,16 @@
 
 .include <bsd.port.pre.mk>
 
+AMANDA_UID?=           2
+AMANDA_GID?=           5
 AMANDA_USER?=          operator
 AMANDA_GROUP?=         operator
 AMANDA_GNUTAR_LISTDIR?=        ${PREFIX}/var/amanda/gnutar-lists
 PLIST_SUB=             SHLIBVER=${PORTVERSION}
 
+SUB_LIST+=             REQUIRE="${_REQUIRE}" AMANDA_UID=${AMANDA_UID} AMANDA_GID=${AMANDA_GID} AMANDA_USER=${AMANDA_USER} AMANDA_GROUP=${AMANDA_GROUP}
+SUB_FILES+=            pkg-install
+
 # amanda-server/amanda-client common part
 .if defined (AMANDA_SERVER)
 CONFIGURE_ARGS+=       --with-index-server=${AMANDA_SERVER}
@@ -166,6 +171,9 @@
 PLIST_SUB+=    SCSICHG=''
 .endif
 
+pre-install:
+       @${SETENV} ${SCRIPTS_ENV} ${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL
+
 # amanda-client part
 .else
 
@@ -201,6 +209,9 @@
 
 OPTIONS+=      DUMP_SNAPSHOT "use snapshot by using dump -L" off
 
+pre-install:
+       @${SETENV} ${SCRIPTS_ENV} ${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL
+
 post-install:
        ${MKDIR} ${PREFIX}/share/examples/amanda
        ${CP} -R ${WRKSRC}/example/amanda.conf \


Patch attached with submission follows:

#!/bin/sh
#
# ex:ts=4

ask() {
	local question default answer

	question=$1
	default=$2
	if [ -z "${PACKAGE_BUILDING}" -a -z "${BATCH}" ]; then
		read -p "${question} [${default}]? " answer
	fi
	echo ${answer:-${default}}
}

yesno() {
	local question default answer

	question=$1
	default=$2
	while :; do
		answer=$(ask "${question}" "${default}")
		case "${answer}" in
		[Yy]*)	return 0;;
		[Nn]*)	return 1;;
		esac
		echo "Please answer yes or no."
	done
}

create_account() {
	local port user uid group gid gcos home shell

	port=$1
	user=${2%:*}
	uid=${2#*:}
	group=${3%:*}
	gid=${3#*:}
	gcos=$4
	home=$5
	shell=$6

	pw_user_uid=$(pw usershow -n "${user}" 2>/dev/null | cut -d: -f3)
	pw_uid_user=$(pw usershow -u "${uid}" 2>/dev/null | cut -d: -f1)
	pw_group_gid=$(pw groupshow -n "${group}" 2>/dev/null | cut -d: -f3)
	pw_gid_group=$(pw groupshow -g "${gid}" 2>/dev/null | cut -d: -f1)

	if [ -z "${pw_group_gid}" -a -z "${pw_gid_group}" ]; then
		echo "You need a ${group} group; creating it..."
		pw groupadd "${group}" -g "${gid}" || exit
		echo "Done."
	elif [ "${gid}" = "${pw_group_gid}" -a "${group}" = "${pw_gid_group}" ]; then
		echo "Using existing ${group} group."
	else
		echo "${port} has reserved the groupname '${group}' and gid '${gid}':"
		[ -n "${pw_group_gid}" -a "${gid}"   != "${pw_group_gid}" ] \
			&& echo "ERROR: groupname '${group}' already in use by gid '${pw_group_gid}'"
		[ -n "${pw_gid_group}" -a "${group}" != "${pw_gid_group}" ] \
			&& echo "ERROR: gid '${gid}' already in use by group '${pw_gid_group}'"
		echo "Please resolve these issues and try again:"
		echo "Either remove the conflicting group or if you wish to continue using a legacy group override AMANDA_GID."
		exit 1
	fi

	if [ -z "${pw_user_uid}" -a -z "${pw_uid_user}" ]; then
		echo "You need a ${user} user; creating it..."
		pw useradd "${user}" -u "${uid}" -g "${group}" -c "${gcos}" -d "${home}" -s "${shell}"
		echo "Done."
	elif [ "${uid}" = "${pw_user_uid}" -a "${user}" = "${pw_uid_user}" ]; then
		echo "Using existing ${user} user."
	else
		echo "${port} has reserved the username '${user}' and uid '${uid}':"
		[ -n "${pw_user_uid}" -a "${uid}"  != "${pw_user_uid}" ] \
			&& echo "ERROR: username '${user}' already in use by uid '${pw_user_uid}'"
		[ -n "${pw_uid_user}" -a "${user}" != "${pw_uid_user}" ] \
			&& echo "ERROR: uid '${uid}' already in use by user '${pw_uid_user}'"
		echo "Please resolve these issues and try again:"
		echo "Either remove the conflicting user or if you wish to continue using a legacy user override AMANDA_UID."
		exit 1
	fi
}

case $2 in

PRE-INSTALL)
	create_account Amanda ${AMANDA_USER:-%%AMANDA_USER%%}:${AMANDA_UID:-%%AMANDA_UID%%} ${AMANDA_GROUP:-%%AMANDA_GROUP%%}:${AMANDA_GID:-%%AMANDA_GID%%} "Amanda User" /var/empty /usr/sbin/nologin
	;;

esac


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809111723.m8BHN6Ee025133>