# suexec library script : <<"END_OF_COPYRIGHT" Copyright (c) 2000-2012, CyberLeo All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of the source code must retain the above copyright notice, this list of conditions, and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILTY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_OF_COPYRIGHT if [ -z "${__suexec_sh_loaded}" ] then __suexec_sh_loaded=yes # exec a command via sudo/su # Can be used to reexec this process under su/sudo, if run like this from # the top-level: # # suexec "${0}" "${@}" # # Specify target user name with -u as the first parameter # # suexec -u user "${0}" "${@}" # # Just as exec, this will replace the current process entirely, and will not # return except upon error. suexec() { user="root" # Set name if user provided if [ "${1}" = "-u" ] then user="${2}" shift 2 fi # suexec if needed if [ "$(id -un)" != "${user}" ] then # Find a su/sudo cmd="sudo -u ${user}" [ -x "$(which sudo 2>/dev/null)" ] || cmd="su ${user} -c" exec ${cmd} "${@}" fi } fi