FAQ FAQ     Rechercher Rechercher    Liste des Membres Liste des Membres    Groupes d'utilisateurs Groupes d'utilisateurs    S'enregistrer S'enregistrer 
  Profil Profil    Se connecter pour vérifier ses messages privés Se connecter pour vérifier ses messages privés    Connexion Connexion 
sudisplay

 
Poster un nouveau sujet   Répondre au sujet    SunQuebec.com Index du Forum -> Autres
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
ecantin
Administrateur
Administrateur


Inscrit le: 09 Déc 2004
Messages: 1273
Localisation: Canada, Québec, Lévis

MessagePosté le: Mer Sep 24, 2008 9:45 am    Sujet du message: sudisplay Répondre en citant

Voici un petit script fait par Laurent Blume qui permet de donner les droits du su avec le display a un simple utilisateur.

http://www.elanor.org/~laurent/sudisplay


Code:
#!/bin/bash
#
# sudisplay
#
# Use to su to another user while setting the $DISPLAY variable, and allowing
# to connect to the X session with the magic cookie (secure, since only
# the cookie's owner can connect).
# By default, the shell defined in $SHELL is used, a command can also be
# given as a parameter, using its absolute path.
# A - parameter is allowed fo su compatibility, but is ignored (always active).
#
# Usage:
#  sudisplay [-] [user] [-s shell]
#
# Ex:
#   sudisplay /bin/ksh
#
# Note:
# It can be used to test for a given user without knowing her password, by
# doing it first for root, then to the user.
# To use through
#
# laurent / AT / elanor.org 20060914
#
# -- Do not remove this line --
#
#
# Modifi� pour remplacer localhost par le nom de machine si c'est ce que
# DISPLAY utilise
# Attention, ~user n'est pas support� avec /bin/sh sur Solaris
# Modif 20060517: support connexion vers utilisateur normal,
# am�liorations diverses
# 20060914: translated to English, minor cleanup, allow the script to continue
# without DISPLAY to at least get the user's shell automatically
# 20060914 (again): use $XAUTHORITY when present

PARMS="$@"

#
# Display the command line help
#
# Parameter:
#   $1 script name
showHelp() {

  fichier="$1"

  if [ -f "${fichier}" ]; then
    sed -n '2,/^# -- Do not remove this line --/{
              /^# -- Do not remove this line --/b
              /.*/s/^#//p
            }' "${fichier}"
  fi
  exit 0
}

# Parameter analysis

while (( $# > 0 )); do

  case "$1" in
    # Display help
    --help|-h)
      showHelp $0
      exit 0
      ;;
   
    # Ignore this
    -)
      ;;
   
    # Name of the given shell
    -s)
      shift
      USESHELL=$1
      ;;

    # The user's name
    *)
      SUUSER=$1
      ;;
     
  esac

  shift
done

if [ -n "${USESHELL}" ]; then
  if [ ! -x "${USESHELL}" ]; then
    printf "%s non valide, utilisation du defaut: %s\n" "${USESHELL}" "${SHELL}"
    USESHELL="${SHELL}"
  fi
else
  USESHELL="${SHELL}"
fi

# If no user name given, use root
if [ -z "${SUUSER}" ]; then
  SUUSER=root
fi

# If no DISPLAY variable, show a warning only
if [[ -z "${DISPLAY}" ]]; then
  printf "Warning: no DISPLAY variable set, no X session will be available.\n"
fi

# The current host name
HOST="$(uname -n)"

# If the variable uses localhost, substitute the hostname
case "${DISPLAY}" in
  localhost:*|:*)
    DISPLAY_HOST="${HOST}/Unix${DISPLAY##localhost}"
    ;;
  *)
    DISPLAY_HOST="${DISPLAY}"
    ;;
esac

# Check if xauth is already in the PATH
XAUTH="$(type xauth 2> /dev/null | cut -f 3 -d " " )"

# If not found...
if [ -z "${XAUTH}" ]; then
  # ... look for it in the usual places
  LISTXAUTHS="/usr/openwin/bin/xauth /usr/X11R6/bin/xauth /usr/bin/X11/xauth"

  for i in ${LISTXAUTHS}; do
    if [[ -x "${i}" ]]; then
      XAUTH="${i}"
    fi
  done

  # If still not found, exit: it won't work
  if [[ -z "${XAUTH}" ]]; then
    printf "Error: xauth was not found.\n"
    exit 4
  fi
fi

# Look for the cookie
if [[ -z "$(${XAUTH} list ${DISPLAY_HOST} )" ]]; then
  printf "Error: magic cookie not found using DISPLAY_HOST=%s\n" "${DISPLAY_HOST}"
  exit 3
fi

# Check for .Xauthority
if [[ -n "${XAUTHORITY}" && \
      ! -f "${XAUTHORITY}" ]]; then
  XAUTHORITY=""
fi

if [[ -z "${XAUTHORITY}" && \
      -f "${HOME}/.Xauthority" ]]; then
  XAUTHORITY="${HOME}/.Xauthority"
fi

# Get xauth directory
DIRXAUTH="$(dirname ${XAUTH} )"

# Check who we really are
WHOAMI="$(who am I | cut -f 1 -d " ")"

# Check variables again before doing su
#if [[ -n "${DISPLAY_HOST}"   && \
if [[ -n "${USESHELL}"     && \
      -n "${WHOAMI}"    && \
      -n "${XAUTH}"     && \
      -n "${DIRXAUTH}" ]]; then
  # Do the su while transmitting the magic cookie of the current user
  # xauth directory is added to the PATH as a convenience
  # The shell must be Bourne compatible at this point
  case "${SHELL}" in
    */sh|*/ksh|*/bash|*/zsh)
      ;;

    */csh|*/tcsh)
        if [ -x /bin/bash ]; then
          SHELL=/bin/bash
        else
          SHELL=/bin/sh
        fi
      ;;

    *)
      printf "Error: unsupported user shell: %s\n" "${SHELL}"
      exit 5
      ;;
  esac
 
  if [ "${SUUSER}" = "root" ]; then
    case "${USESHELL}" in
      */sh|*/ksh|*/bash|*/zsh)
      ;;

    *)
        if [ -x /bin/bash ]; then
          USESHELL=/bin/bash
        else
          USESHELL=/bin/sh
        fi

        printf "Warning: the use of shell %s was forced by user %s\n" "${USESHELL}" "${SUUSER}"
      ;;
    esac
  fi


  if [[ -n "${DISPLAY_HOST}" ]]; then
    COOKIE="$(${XAUTH} -f ${XAUTHORITY} list ${DISPLAY_HOST} )"
 
    su - "${SUUSER}" \
      -c "${SHELL} \
        -c \"(${XAUTH} add ${COOKIE}; DISPLAY=${DISPLAY}; export DISPLAY; PATH=\${PATH}:${DIRXAUTH}; export PATH; ${USESHELL})\""
  else
    su - "${SUUSER}" \
      -c "${SHELL} \
        -c \"(${USESHELL})\""
  fi
     
else
  printf "Error: there was a problem with one or more environment variable.\n"
  printf "Please check DISPLAY and SHELL, and that xauth is present on the\n"
  printf "system\n"
  exit 2
fi

# Normal end
exit 0

_________________

Sun Fire 3800 - 8x UltraSPARC-III+ 900 MHz - Solaris 10 U8 (à vendre)
Sun Fire v120 - 1x UtraSPARC-IIi 550MHz - Solaris 10 U8
Sun StorEdge T3+
Sun Fire V20Z - 2 x AMD Opteron 2.4 GHz - Solaris 10 U8
4 X SunRay 1(G) - SRSS v4.1
Sun Fire v100 - 1x UtraSPARC-IIi 550MHz - Solaris 10 U8
Sun Netra x1 - 1x UtraSPARC-IIe 500MHz - Solaris 10 U8
Sun Netra x1 - 1x UtraSPARC-IIe 500MHz - Solaris 10 U8
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
ecantin
Administrateur
Administrateur


Inscrit le: 09 Déc 2004
Messages: 1273
Localisation: Canada, Québec, Lévis

MessagePosté le: Mer Sep 24, 2008 9:55 am    Sujet du message: Répondre en citant

Laurent dit qu'il a testé sur Solaris 8-10, RHEL 4/5, Debian 3.1/4.

Code:
ssh -X utilisateur@machine
sudisplay
xlogo &

_________________

Sun Fire 3800 - 8x UltraSPARC-III+ 900 MHz - Solaris 10 U8 (à vendre)
Sun Fire v120 - 1x UtraSPARC-IIi 550MHz - Solaris 10 U8
Sun StorEdge T3+
Sun Fire V20Z - 2 x AMD Opteron 2.4 GHz - Solaris 10 U8
4 X SunRay 1(G) - SRSS v4.1
Sun Fire v100 - 1x UtraSPARC-IIi 550MHz - Solaris 10 U8
Sun Netra x1 - 1x UtraSPARC-IIe 500MHz - Solaris 10 U8
Sun Netra x1 - 1x UtraSPARC-IIe 500MHz - Solaris 10 U8
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    SunQuebec.com Index du Forum -> Autres Toutes les heures sont au format GMT - 5 Heures
Page 1 sur 1

 
Sauter vers:  
Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum



Propulsé par phpBB © 2001, 2005 phpBB Group - Traduction par : phpBB-fr.com

Accueil Forum de discussions La plateforme Sun/SPARC Procédures et documentations Les galeries d'images
Copyright © 2010, SunQuebec (www.sunquebec.com), tous droits réservés.
Protégé par les lois du copyright des États-Unis et du Canada et par des traités internationaux.
CFAQ