6653471 Do not use shell pid in lpadmin(1M)
6655640 Do not use shell pid in ppdmgr(1M)
Contributed by Mike Gerdts <mgerdts@gmail.com>
1 --- a/usr/src/cmd/print/scripts/lpadmin Tue Jan 13 14:13:08 2009 +0800
2 +++ b/usr/src/cmd/print/scripts/lpadmin Mon Jan 12 23:17:13 2009 -0800
3 @@ -20,11 +20,10 @@
4 # CDDL HEADER END
5 #
6 #
7 -# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
8 +# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
9 # Use is subject to license terms.
10 #
11 #
12 -set -o noclobber
13
14 PATH=/bin:/usr/bin:/usr/sbin export PATH
15
16 @@ -39,6 +38,7 @@
17 LPFILTER=/usr/sbin/lpfilter
18 COMM=/usr/bin/comm
19 PPDMGR=/usr/sbin/ppdmgr
20 +MKTEMP="/usr/bin/mktemp -t"
21
22 HOST=$(/bin/uname -n)
23 exit_code=0
24 @@ -110,7 +110,11 @@
25 # Add new ppd file and echo full path it was actually saved to
26 ppdmgrcmd="${PFEXEC} ${PPDMGR} -a ${1} -w"
27
28 - ppderrfile=/tmp/lpadminerror.$$
29 + ppderrfile=$(${MKTEMP} lpadminerror.XXXXXX)
30 + if [[ -z "${ppderrfile}" ]] ; then
31 + gettext "lpadmin: System error; cannot create temporary file\n" 1>&2
32 + exit 2
33 + fi
34 ppd_file=$(${ppdmgrcmd} 2>${ppderrfile})
35 ppdmgrrc=$?
36 if [[ -s "${ppderrfile}" ]] ; then
37 @@ -293,7 +297,12 @@
38 # Do the LP configuration for a local printer served by lpsched
39 if [[ -x ${LPADMIN} && -n "${local}" ]] ; then
40 # enumerate LP configured printers before modification
41 - PRE=/tmp/lpadmin-pre.$$
42 + PRE=$(${MKTEMP} lpadmin-pre.XXXXXX)
43 + if [[ -z "${PRE}" ]] ; then
44 + gettext "lpadmin: System error; cannot create temporary file\n" 1>&2
45 + exit 2
46 + fi
47 +
48 (/bin/ls /etc/lp/printers 2>/dev/null ; /bin/ls /etc/lp/classes \
49 2>/dev/null) >${PRE}
50
51 @@ -331,7 +340,13 @@
52 exit_code=$?
53
54 # enumerate LP configured printers after modification
55 - POST=/tmp/lpadmin-post.$$
56 + POST=$(${MKTEMP} lpadmin-post.XXXXXX)
57 + if [[ -z "${POST}" ]] ; then
58 + gettext "lpadmin: System error; cannot create temporary file\n" 1>&2
59 + /bin/rm -f ${PRE} >/dev/null 2>&1
60 + exit 2
61 + fi
62 +
63 (/bin/ls /etc/lp/printers 2>/dev/null ; /bin/ls /etc/lp/classes \
64 2>/dev/null) >${POST}
65
1.1 --- a/usr/src/cmd/print/scripts/ppdmgr Tue Jan 13 14:13:08 2009 +0800
1.2 +++ b/usr/src/cmd/print/scripts/ppdmgr Mon Jan 12 23:17:13 2009 -0800
1.3 @@ -19,7 +19,7 @@
1.4 #
1.5 # CDDL HEADER END
1.6 #
1.7 -# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
1.8 +# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
1.9 # Use is subject to license terms.
1.10 #
1.11
1.12 @@ -325,8 +325,8 @@
1.13 # Combine the contents of all cache files into a
1.14 # temporary golden cache file.
1.15 #
1.16 - tmpgoldencache=$(/bin/mktemp -p "${ppdmgrtmpdir}" \
1.17 - tmpgoldencache.XXXXXX 2>/dev/null)
1.18 + tmpgoldencache=$ppdmgrtmpdir/tmpgoldencache
1.19 +
1.20 /bin/sort "${VARCACHES}"/* >>"${tmpgoldencache}" 2>/dev/null
1.21
1.22 if [[ ! -s "${tmpgoldencache}" ]] ; then
1.23 @@ -440,8 +440,7 @@
1.24 # Generate a cache file containing cache entries for
1.25 # all files in the label.
1.26 #
1.27 - ucfile=$(/bin/mktemp -p "${ppdmgrtmpdir}" \
1.28 - unsortedcache.XXXXXX 2>/dev/null)
1.29 + ucfile=$ppdmgrtmpdir/unsortedcache
1.30
1.31 #
1.32 # Before processing new files, remove any cache entries
1.33 @@ -632,8 +631,7 @@
1.34 # of the PPD files under it is newer than the
1.35 # existing cache file), then generate a new cache file.
1.36 #
1.37 - tmpcachepath=$(/bin/mktemp -p "${ppdmgrtmpdir}" \
1.38 - tmpcachepath.XXXXXX 2>/dev/null)
1.39 + tmpcachepath=$ppdmgrtmpdir/tmpcachepath
1.40
1.41 # if this is a system repository, check for a prepopulated cache
1.42 if [[ "${2}" = "${SYSTEM}" && -e ${FOOCACHEDIR}/${3}.cache ]] ; then
1.43 @@ -1477,9 +1475,12 @@
1.44 devidmdl=
1.45 devidmfg=
1.46
1.47 -ppdmgrtmpdir=/tmp/ppdmgr.$$
1.48 -/bin/mkdir "${ppdmgrtmpdir}" >/dev/null 2>&1
1.49 -set_perms ${DIRMODE} ${DIROWNER} "${ppdmgrtmpdir}"
1.50 +ppdmgrtmpdir=$(/usr/bin/mktemp -t -d ppdmgr.XXXXXX)
1.51 +if [ -z "$ppdmgrtmpdir" ] ; then
1.52 + print -n "$myprog: " 1>&2
1.53 + gettext "Fatal error: could not create temporary directory\n" 1>&2
1.54 + exit 1
1.55 +fi
1.56
1.57 aliasfile=${USERREP}/manufaliases
1.58 tmpfilepath=