#!/bin/sh # /etc/init.d/x11-common: set up the X server and ICE socket directories ### BEGIN INIT INFO # Provides: x11-common # Required-Start: $remote_fs # Required-Stop: $remote_fs # Default-Start: S # Default-Stop: # Short-Description: set up the X server and ICE socket directories ### END INIT INFO set -e global PATH := '/usr/bin:/usr/sbin:/bin:/sbin' global SOCKET_DIR := '.X11-unix' global ICE_DIR := '.ICE-unix' source /lib/lsb/init-functions if test -f /etc/default/rcS { source /etc/default/rcS } proc do_restorecon { # Restore file security context (SELinux). if which restorecon >/dev/null !2 > !1 { restorecon $1 } } # create a directory in /tmp. # assumes /tmp has a sticky bit set (or is only writeable by root) proc set_up_dir { global DIR := ""/tmp/$1"" if test $VERBOSE != no { log_progress_msg $DIR } # if $DIR exists and isn't a directory, move it aside if test -e $DIR && ! test -d $DIR || test -h $DIR { mv $DIR $[mktemp -d $DIR.XXXXXX] } global error := '0' while : { if test $error -ne 0 { # an error means the file-system is readonly or an attacker # is doing evil things, distinguish by creating a temporary file, # but give up after a while. if test $error -gt 5 { log_failure_msg "failed to set up $DIR" return 1 } global fn := $[mktemp /tmp/testwriteable.XXXXXXXXXX] || return 1 rm $fn } mkdir -p -m 01777 $DIR || do { rm $DIR || global error := $(error + 1) ; continue ; } matchstr $[env LC_ALL=C stat -c '%u %g %a %F' $DIR] { "0 0 1777 directory" { # everything as it is supposed to be break } "0 0 "*" directory" { # as it is owned by root, cannot be replaced with a symlink: chmod 01777 $DIR break } *" directory" { # if the chown succeeds, the next step can change it savely chown -h root:root $DIR || global error := $(error + 1) continue } * { log_failure_msg "failed to set up $DIR" return 1 } } } do_restorecon $DIR return 0 } proc do_status { if test -d "/tmp/$ICE_DIR" && test -d "/tmp/$SOCKET_DIR" { return 0 } else { return 4 } } matchstr $1 { start { if test $VERBOSE != no { log_begin_msg "Setting up X socket directories..." } set_up_dir $SOCKET_DIR set_up_dir $ICE_DIR if test $VERBOSE != no { log_end_msg 0 } } restart|reload|force-reload { /etc/init.d/x11-common start } stop { : } status { do_status } * { log_success_msg "Usage: /etc/init.d/x11-common {start|stop|status|restart|reload|force-reload}" exit 1 } } exit 0 # vim:set ai et sts=2 sw=2 tw=0: (CommandList children: [ (C {(set)} {(-e)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: {(/usr/bin) (Lit_Other ":") (/usr/sbin) (Lit_Other ":") (/bin) (Lit_Other ":") (/sbin)} spids: [36] ) ] spids: [36] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:SOCKET_DIR) op:Equal rhs:{(.X11-unix)} spids:[45])] spids: [45] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ICE_DIR) op:Equal rhs:{(.ICE-unix)} spids:[48])] spids: [48] ) (C {(.)} {(/lib/lsb/init-functions)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-f)} {(/etc/default/rcS)} {(Lit_Other "]")}) terminator: ) ] action: [(C {(.)} {(/etc/default/rcS)})] spids: [-1 67] ) ] spids: [-1 74] ) (FuncDef name: do_restorecon body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(which)} {(restorecon)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [95] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [98] ) ] ) terminator: ) ] action: [(C {(restorecon)} {(DQ ($ VSub_Number "$1"))})] spids: [-1 102] ) ] spids: [-1 112] ) ] spids: [82] ) spids: [77 81] ) (FuncDef name: set_up_dir body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DIR) op: Equal rhs: {(DQ (/tmp/) ($ VSub_Number "$1"))} spids: [131] ) ] spids: [131] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(KW_Bang "!") (Lit_Other "=")} {(no)} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(log_progress_msg)} {(DQ ($ VSub_Name "$DIR"))})] spids: [-1 155] ) ] spids: [-1 165] ) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (C {(Lit_Other "[")} {(-e)} {($ VSub_Name "$DIR")} {(Lit_Other "]")}) (AndOr children: [ (Pipeline children: [ (C {(Lit_Other "[")} {(-d)} {($ VSub_Name "$DIR")} {(Lit_Other "]")}) ] negated: True ) (C {(Lit_Other "[")} {(-h)} {($ VSub_Name "$DIR")} {(Lit_Other "]")}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) terminator: ) ] action: [ (C {(mv)} {(DQ ($ VSub_Name "$DIR"))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(mktemp)} {(-d)} {($ VSub_Name "$DIR") (.XXXXXX)})] ) left_token: spids: [215 222] ) ) } ) ] spids: [-1 205] ) ] spids: [-1 226] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:error) op:Equal rhs:{(0)} spids:[230])] spids: [230] ) (While cond: [(Sentence child:(C {(Lit_Other ":")}) terminator:)] body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$error")} {(-ne)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$error")} {(-gt)} {(5)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(log_failure_msg)} {(DQ ("failed to set up ") ($ VSub_Name "$DIR"))} ) (ControlFlow token: arg_word: {(1)} ) ] spids: [-1 284] ) ] spids: [-1 300] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fn) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(mktemp)} {(/tmp/testwriteable.XXXXXXXXXX)}) ] ) left_token: spids: [305 309] ) ) } spids: [303] ) ] spids: [303] ) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) (C {(rm)} {(DQ ($ VSub_Name "$fn"))}) ] spids: [-1 256] ) ] spids: [-1 326] ) (AndOr children: [ (C {(mkdir)} {(-p)} {(-m)} {(01777)} {(DQ ($ VSub_Name "$DIR"))}) (BraceGroup children: [ (Sentence child: (AndOr children: [ (C {(rm)} {(DQ ($ VSub_Name "$DIR"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:error) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:error) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [354 361] ) } spids: [353] ) ] spids: [353] ) ] op_id: Op_DPipe ) terminator: ) (Sentence child: (ControlFlow token:) terminator: ) ] spids: [343] ) ] op_id: Op_DPipe ) (Case to_match: { (DQ (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [ {(stat)} {(-c)} {(SQ <"%u %g %a %F">)} {(DQ ($ VSub_Name "$DIR"))} ] more_env: [(env_pair name:LC_ALL val:{(C)} spids:[376])] ) ] ) left_token: spids: [375 390] ) ) } arms: [ (case_arm pat_list: [{(DQ ("0 0 1777 directory"))}] action: [(ControlFlow token:)] spids: [397 399 409 -1] ) (case_arm pat_list: [{(DQ ("0 0 ")) (Lit_Other "*") (DQ (" directory"))}] action: [ (C {(chmod)} {(01777)} {(DQ ($ VSub_Name "$DIR"))}) (ControlFlow token:) ] spids: [413 419 438 -1] ) (case_arm pat_list: [{(Lit_Other "*") (DQ (" directory"))}] action: [ (AndOr children: [ (C {(chown)} {(-h)} {(root) (Lit_Other ":") (root)} {(DQ ($ VSub_Name "$DIR"))} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:error) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:error) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [467 474] ) } spids: [466] ) ] spids: [466] ) ] op_id: Op_DPipe ) (ControlFlow token: ) ] spids: [441 445 480 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (C {(log_failure_msg)} {(DQ ("failed to set up ") ($ VSub_Name "$DIR"))}) (ControlFlow token: arg_word: {(1)} ) ] spids: [483 484 500 -1] ) ] spids: [372 393 503] ) ] spids: [239 506] ) ) (C {(do_restorecon)} {(DQ ($ VSub_Name "$DIR"))}) (ControlFlow token: arg_word:{(0)}) ] spids: [128] ) spids: [123 127] ) (FuncDef name: do_status body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (C {(Lit_Other "[")} {(-d)} {(DQ (/tmp/) ($ VSub_Name "$ICE_DIR"))} {(Lit_Other "]")} ) (C {(Lit_Other "[")} {(-d)} {(DQ (/tmp/) ($ VSub_Name "$SOCKET_DIR"))} {(Lit_Other "]")} ) ] op_id: Op_DAmp ) terminator: ) ] action: [(ControlFlow token: arg_word:{(0)})] spids: [-1 559] ) ] else_action: [(ControlFlow token: arg_word:{(4)})] spids: [567 575] ) ] spids: [529] ) spids: [524 528] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list: [{(start)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(KW_Bang "!") (Lit_Other "=")} {(no)} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(log_begin_msg)} {(DQ ("Setting up X socket directories..."))})] spids: [-1 609] ) ] spids: [-1 619] ) (C {(set_up_dir)} {(DQ ($ VSub_Name "$SOCKET_DIR"))}) (C {(set_up_dir)} {(DQ ($ VSub_Name "$ICE_DIR"))}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(KW_Bang "!") (Lit_Other "=")} {(no)} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(log_end_msg)} {(0)})] spids: [-1 652] ) ] spids: [-1 660] ) ] spids: [589 590 663 -1] ) (case_arm pat_list: [{(restart)} {(reload)} {(force-reload)}] action: [(C {(/etc/init.d/x11-common)} {(start)})] spids: [667 672 680 -1] ) (case_arm pat_list:[{(stop)}] action:[(C {(Lit_Other ":")})] spids:[684685691-1]) (case_arm pat_list:[{(status)}] action:[(C {(do_status)})] spids:[695696702-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (C {(log_success_msg)} { (DQ ("Usage: /etc/init.d/x11-common {start|stop|status|restart|reload|force-reload}")) } ) (C {(exit)} {(1)}) ] spids: [705 706 721 -1] ) ] spids: [580 586 723] ) (C {(exit)} {(0)}) ] )