Debian Codegraph @

launchd/privileged_startx/10-tmpdirs.cpp

raw
1 XCOMM!/bin/sh
2 XCOMM Copyright (c) 2008-2012 Apple Inc.
3 XCOMM
4 XCOMM Permission is hereby granted, free of charge, to any person
5 XCOMM obtaining a copy of this software and associated documentation files
6 XCOMM (the "Software"), to deal in the Software without restriction,
7 XCOMM including without limitation the rights to use, copy, modify, merge,
8 XCOMM publish, distribute, sublicense, and/or sell copies of the Software,
9 XCOMM and to permit persons to whom the Software is furnished to do so,
10 XCOMM subject to the following conditions:
11 XCOMM
12 XCOMM The above copyright notice and this permission notice shall be
13 XCOMM included in all copies or substantial portions of the Software.
14 XCOMM
15 XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 XCOMM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 XCOMM NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
19 XCOMM HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 XCOMM WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 XCOMM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 XCOMM DEALINGS IN THE SOFTWARE.
23 XCOMM
24 XCOMM Except as contained in this notice, the name(s) of the above
25 XCOMM copyright holders shall not be used in advertising or otherwise to
26 XCOMM promote the sale, use or other dealings in this Software without
27 XCOMM prior written authorization.
28
29 XCOMM Make sure these are owned by root
30
31 XCOMM Our usage of mktemp fails with GNU, so prefer /usr/bin to hopefully
32 XCOMM get BSD mktemp
33 if [ -x /usr/bin/mktemp ] ; then
34 MKTEMP=/usr/bin/mktemp
35 else
36 MKTEMP=mktemp
37 fi
38
39 STAT=/usr/bin/stat
40
41 for dir in /tmp/.ICE-unix /tmp/.X11-unix /tmp/.font-unix ; do
42 success=0
43 for attempt in 1 2 3 4 5 ; do
44 check=`${STAT} -f '%#p %u %g' ${dir} 2> /dev/null`
45 if [ "${check}" = "041777 0 0" ] ; then
46 success=1
47 break
48 elif [ -n "${check}" ] ; then
49 saved=$(${MKTEMP} -d ${dir}-XXXXXXXX)
50 mv ${dir} ${saved}
51 echo "${dir} exists but is insecure. It has been moved into ${saved}" >&2
52 fi
53
54 # Use mktemp rather than mkdir to avoid possible security issue
55 # if $dir exists and is a symlink (ie protect against a race
56 # against the above check)
57 if ${MKTEMP} -d ${dir} >& /dev/null ; then
58 chmod 1777 $dir
59 chown root:wheel $dir
60 success=1
61 break
62 fi
63 done
64
65 if [ "${success}" -eq 0 ] ; then
66 echo "Could not successfully create ${dir}" >&2
67 fi
68 done