view tests/test-idpriv-drop.sh @ 16817:7747cb9b54b9

unistd_h: make it easier to avoid sys_types_h This is useful for Emacs, which has its own method of porting to Windows, and which therefore does not need the sys_types_h module. * m4/off_t.m4: New file, defining gl_TYPE_OFF_T, which contains code moved here from gl_SYS_TYPES_H. * m4/sys_types_h.m4 (gl_SYS_TYPES_H): Require it instead of using the code directly. * m4/unistd_h.m4 (gl_UNISTD_H): Require gl_TYPE_OFF_T, not gl_SYS_TYPES_H. * modules/sys_types (Files): * modules/unistd (Files): Add m4/off_t.m4.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 04 May 2012 13:05:31 -0700
parents b3e5d914be7d
children
line wrap: on
line source

#!/bin/sh

# A POSIX compliant 'id' program.
if test -f /usr/xpg4/bin/id; then
  ID=/usr/xpg4/bin/id
else
  ID=id
fi

# The user's original uid and gid.
uid=`$ID -u`
gid=`$ID -g`

if test `$ID -u` = 0; then
  # No need to ask for a password.
  "${srcdir}/test-idpriv-drop.su.sh" "$uid" "$gid"
else
  echo "Need root privileges for the 'test-idpriv-drop' test. Deny if you don't trust." > /dev/tty
  if (type sudo) > /dev/null 2>&1; then
    # Use the 'sudo' program.
    sudo "${srcdir}/test-idpriv-drop.su.sh" "$uid" "$gid"
  else
    # Use the 'su' program.
    su root -c "${srcdir}/test-idpriv-drop.su.sh \"$uid\" \"$gid\""
  fi
  result=$?
  case $result in
    0)  exit 0;;
    77) exit 77;;
    13) exit 1;;
    *)  echo "Skipping test: root privileges not granted"; exit 77;;
  esac
fi