From 2b06b58a328e13df4704df8a48d4cd0b1100ba7e Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Thu, 17 Apr 2008 17:19:41 -0700 Subject: Apple: Added privileged_startx --- Makefile.am | 8 +- configure.ac | 12 +- privileged_startx/10-tmpdirs.cpp | 37 +++ privileged_startx/20-font_cache.cpp | 35 +++ privileged_startx/Makefile.am | 64 ++++++ privileged_startx/client.c | 56 +++++ .../org.x.privileged_startx.plist.cpp | 21 ++ privileged_startx/privileged_startx.c | 59 +++++ privileged_startx/privileged_startx.defs | 40 ++++ privileged_startx/privileged_startx_types.h | 6 + privileged_startx/server.c | 250 +++++++++++++++++++++ 11 files changed, 582 insertions(+), 6 deletions(-) create mode 100755 privileged_startx/10-tmpdirs.cpp create mode 100755 privileged_startx/20-font_cache.cpp create mode 100644 privileged_startx/Makefile.am create mode 100644 privileged_startx/client.c create mode 100644 privileged_startx/org.x.privileged_startx.plist.cpp create mode 100644 privileged_startx/privileged_startx.c create mode 100644 privileged_startx/privileged_startx.defs create mode 100644 privileged_startx/privileged_startx_types.h create mode 100644 privileged_startx/server.c diff --git a/Makefile.am b/Makefile.am index ae259bd..d514251 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,10 +63,14 @@ CPP_FILES_FLAGS = \ -D__bindir__="$(bindir)" if LAUNCHD -launchagents_PRE = org.x.startx.plist.pre -launchagents_DATA = $(launchagents_PRE:plist.pre=plist) +launchagents_PRE = org.x.startx.plist.cpp +launchagents_DATA = $(launchagents_PRE:plist.cpp=plist) + +SUBDIRS = privileged_startx endif +DIST_SUBDIRS = privileged_startx + xinitrc: xinitrc.cpp Makefile startx: startx.cpp Makefile diff --git a/configure.ac b/configure.ac index f473580..f33fd13 100644 --- a/configure.ac +++ b/configure.ac @@ -92,12 +92,13 @@ AC_ARG_WITH(xinit, [XINIT="$withval"], [XINIT="$DEFAULT_XINIT"]) -AC_ARG_WITH(launchd, AS_HELP_STRING([--with-launchd], [Build with suppo -rt for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto]) -AC_ARG_WITH(launchagents-dir,AS_HELP_STRING([--with-launchagents-dir=PATH], [Pat -h to launchd's LaunchAgents directory (default: /Library/LaunchAgents)]), +AC_ARG_WITH(launchd, AS_HELP_STRING([--with-launchd], [Build with support for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto]) +AC_ARG_WITH(launchagents-dir, AS_HELP_STRING([--with-launchagents-dir=PATH], [Path to launchd's LaunchAgents directory (default: /Library/LaunchAgents)]), [ launchagentsdir="${withval}" ], [ launchagentsdir="/Library/LaunchAgents" ]) +AC_ARG_WITH(launchdaemons-dir, AS_HELP_STRING([--with-launchdaemons-dir=PATH], [Path to launchd's LaunchDaemonss directory (default: /Library/LaunchDaemons)]), + [ launchdaemonsdir="${withval}" ], + [ launchdaemonsdir="/Library/LaunchDaemons" ]) if test "x$LAUNCHD" = "xauto"; then unset LAUNCHD @@ -121,8 +122,10 @@ if test "x$LAUNCHD" = "xyes" ; then else AM_CONDITIONAL(APPLE,false) launchagentsdir="" + launchdaemonsdir="" fi AC_SUBST([launchagentsdir]) +AC_SUBST([launchdaemonsdir]) AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"]) # Checks for pkg-config packages @@ -182,3 +185,4 @@ XORG_MANPAGE_SECTIONS XORG_RELEASE_VERSION AC_OUTPUT([Makefile]) +AC_OUTPUT([privileged_startx/Makefile]) diff --git a/privileged_startx/10-tmpdirs.cpp b/privileged_startx/10-tmpdirs.cpp new file mode 100755 index 0000000..dd5071c --- /dev/null +++ b/privileged_startx/10-tmpdirs.cpp @@ -0,0 +1,37 @@ +XCOMM!/bin/sh +XCOMM Copyright (c) 2008 Apple Inc. +XCOMM +XCOMM Permission is hereby granted, free of charge, to any person +XCOMM obtaining a copy of this software and associated documentation files +XCOMM (the "Software"), to deal in the Software without restriction, +XCOMM including without limitation the rights to use, copy, modify, merge, +XCOMM publish, distribute, sublicense, and/or sell copies of the Software, +XCOMM and to permit persons to whom the Software is furnished to do so, +XCOMM subject to the following conditions: +XCOMM +XCOMM The above copyright notice and this permission notice shall be +XCOMM included in all copies or substantial portions of the Software. +XCOMM +XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +XCOMM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +XCOMM NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT +XCOMM HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +XCOMM WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +XCOMM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +XCOMM DEALINGS IN THE SOFTWARE. +XCOMM +XCOMM Except as contained in this notice, the name(s) of the above +XCOMM copyright holders shall not be used in advertising or otherwise to +XCOMM promote the sale, use or other dealings in this Software without +XCOMM prior written authorization. + +XCOMM Make sure these are owned by root +for dir in /tmp/.ICE-unix /tmp/.X11-unix /tmp/.font-unix ; do + # Use mktemp rather than mkdir to avoid possible security issue + # if $dir exists and is a symlink + if mktemp -d ${dir} > /dev/null ; then + chmod 1777 $dir + chown root:wheel $dir + fi +done diff --git a/privileged_startx/20-font_cache.cpp b/privileged_startx/20-font_cache.cpp new file mode 100755 index 0000000..c13384b --- /dev/null +++ b/privileged_startx/20-font_cache.cpp @@ -0,0 +1,35 @@ +XCOMM!/bin/sh +XCOMM Copyright (c) 2008 Apple Inc. +XCOMM +XCOMM Permission is hereby granted, free of charge, to any person +XCOMM obtaining a copy of this software and associated documentation files +XCOMM (the "Software"), to deal in the Software without restriction, +XCOMM including without limitation the rights to use, copy, modify, merge, +XCOMM publish, distribute, sublicense, and/or sell copies of the Software, +XCOMM and to permit persons to whom the Software is furnished to do so, +XCOMM subject to the following conditions: +XCOMM +XCOMM The above copyright notice and this permission notice shall be +XCOMM included in all copies or substantial portions of the Software. +XCOMM +XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +XCOMM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +XCOMM NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT +XCOMM HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +XCOMM WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +XCOMM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +XCOMM DEALINGS IN THE SOFTWARE. +XCOMM +XCOMM Except as contained in this notice, the name(s) of the above +XCOMM copyright holders shall not be used in advertising or otherwise to +XCOMM promote the sale, use or other dealings in this Software without +XCOMM prior written authorization. + +if [ -x BINDIR/font_cache ] ; then + BINDIR/font_cache & +elif [ -x BINDIR/font_cache.sh ] ; then + BINDIR/font_cache.sh -s & +elif [ -x /usr/X11/bin/fc-cache ] ; then + BINDIR/fc-cache & +fi diff --git a/privileged_startx/Makefile.am b/privileged_startx/Makefile.am new file mode 100644 index 0000000..0a3956d --- /dev/null +++ b/privileged_startx/Makefile.am @@ -0,0 +1,64 @@ +# Copyright (c) 2008 Apple Inc. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT +# HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name(s) of the above +# copyright holders shall not be used in advertising or otherwise to +# promote the sale, use or other dealings in this Software without +# prior written authorization. + +include $(top_srcdir)/cpprules.in + +xinitrcdir = $(libdir)/X11/xinit +privstartxdir = $(xinitrcdir)/privileged_startx.d + +xinitrc_PROGRAMS = privileged_startx +privstartx_SCRIPTS = 10-tmpdirs 20-font_cache + +AM_CPPFLAGS = -DXINITDIR=\"$(xinitrcdir)\" -DSCRIPTDIR=\"$(privstartxdir)\" -DBINDIR=\"$(bindir)\" + +CPP_FILES_FLAGS = -DXINITDIR="$(xinitrcdir)" -DSCRIPTDIR="$(privstartxdir)" -DBINDIR="$(bindir)" + +privileged_startx_SOURCES = \ + privileged_startxServer.c \ + privileged_startxUser.c \ + server.c \ + client.c \ + privileged_startx.c + +BUILT_SOURCES = \ + privileged_startxServer.c \ + privileged_startxUser.c \ + privileged_startxServer.h \ + privileged_startx.h + +launchdaemons_PRE = org.x.privileged_startx.plist.cpp +launchdaemons_DATA = $(launchdaemons_PRE:plist.cpp=plist) + +10-tmpdirs: 10-tmpdirs.cpp Makefile +20-font_cache: 20-font_cache.cpp Makefile + +CLEANFILES = $(privstartx_SCRIPTS) $(BUILT_SOURCES) $(launchdaemons_DATA) + +EXTRA_DIST = 10-tmpdirs.cpp 20-font_cache.cpp org.x.privileged_startx.plist.cpp privileged_startx.defs + +$(BUILT_SOURCES): privileged_startx.defs + mig -sheader privileged_startxServer.h privileged_startx.defs diff --git a/privileged_startx/client.c b/privileged_startx/client.c new file mode 100644 index 0000000..2a24a70 --- /dev/null +++ b/privileged_startx/client.c @@ -0,0 +1,56 @@ +/* Copyright (c) 2008 Apple Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name(s) of the above + * copyright holders shall not be used in advertising or otherwise to + * promote the sale, use or other dealings in this Software without + * prior written authorization. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "privileged_startx.h" + +int client_main(void) { + kern_return_t kr; + mach_port_t mp; + + kr = bootstrap_look_up(bootstrap_port, BOOTSTRAP_NAME, &mp); + if (kr != KERN_SUCCESS) { + fprintf(stderr, "bootstrap_look_up(): %s\n", bootstrap_strerror(kr)); + exit(EXIT_FAILURE); + } + + kr = privileged_startx(mp); + if (kr != KERN_SUCCESS) { + fprintf(stderr, "privileged_startx client: %s\n", mach_error_string(kr)); + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); +} diff --git a/privileged_startx/org.x.privileged_startx.plist.cpp b/privileged_startx/org.x.privileged_startx.plist.cpp new file mode 100644 index 0000000..e878dc3 --- /dev/null +++ b/privileged_startx/org.x.privileged_startx.plist.cpp @@ -0,0 +1,21 @@ + + + + + Label + org.x.privileged_startx + MachServices + + org.x.privileged_startx + + + ProgramArguments + + XINITDIR/privileged_startx + -d + SCRIPTDIR + + TimeOut + 60 + + diff --git a/privileged_startx/privileged_startx.c b/privileged_startx/privileged_startx.c new file mode 100644 index 0000000..725a1b0 --- /dev/null +++ b/privileged_startx/privileged_startx.c @@ -0,0 +1,59 @@ +/* Copyright (c) 2008 Apple Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name(s) of the above + * copyright holders shall not be used in advertising or otherwise to + * promote the sale, use or other dealings in this Software without + * prior written authorization. + */ + +#include +#include + +#ifndef SCRIPTDIR +#define SCRIPTDIR="/usr/X11/lib/X11/xinit/privileged_startx.d" +#endif + +static void usage(const char *prog) { + fprintf(stderr, "%s: usage\n", prog); + fprintf(stderr, " %s [-d [