Recent Posts
Bash | 47 sec ago
None | 54 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Sasa Tomic on the 23rd of May 2008 04:02:41 PM Download | Raw | Embed | Report
  1. #!/bin/sh
  2.  
  3. #
  4. # Control script grant/revoke access to X for the ATI External Events Daemon
  5. #
  6. # Distro maintainers may modify this reference script as necessary to conform
  7. # to their distribution policies.
  8. #
  9. # Copyright (c) 2006, ATI Technologies Inc.  All rights reserved.
  10. #
  11.  
  12. #
  13. # Parameters:
  14. #   $1 is a keyword, either "grant" or "revoke"
  15. #   $2 is the display name
  16. #   $3 is the X authorization file to be authorized
  17. #
  18. # Returns:
  19. #   0 if authorization was successfully granted/revoked
  20. #   nonzero on failure
  21. #
  22. # Note:
  23. #   The third parameter only makes sense if xauth is being used.  If another
  24. #   mechanism such as xhost is being used it can be ignored.  For setups that
  25. #   do not do any form of authentication(!) this script can be trimmed down
  26. #   to just "exit 0" and the daemon will assume that it is always authorized.
  27. #
  28.  
  29. GetServerAuthFile()
  30. {
  31.     # Determine where the authorization key may be hiding.  The location will
  32.     # vary depending upon whether X was started via xdm/kdm, gdm or startx, so
  33.     # check each one in turn.
  34.  
  35.     # Check xorg 7
  36.     XDM_AUTH_MASK=/var/run/xauth/A$1*
  37.     XDM_AUTH_FILE=`ls -t $XDM_AUTH_MASK 2>/dev/null | head -n 1`   # Choose the newest file
  38.     if [ -n "$XDM_AUTH_FILE" ]; then
  39.       SERVER_AUTH_FILE=$XDM_AUTH_FILE
  40.       DISP_SEARCH_STRING="#ffff#"
  41.       return 0
  42.     fi
  43.  
  44.     # Check xdm/kdm
  45.  
  46.     XDM_AUTH_MASK=/var/lib/xdm/authdir/authfiles/A$1*
  47.     XDM_AUTH_FILE=`ls -t $XDM_AUTH_MASK 2>/dev/null | head -n 1`   # Choose the newest file
  48.     if [ -n "$XDM_AUTH_FILE" ]; then
  49.         SERVER_AUTH_FILE=$XDM_AUTH_FILE
  50.         DISP_SEARCH_STRING="#ffff#"
  51.         return 0
  52.     fi
  53.  
  54.     # Check gdm
  55.  
  56.     GDM_AUTH_FILE=/var/lib/gdm/$1.Xauth
  57.     if [ -e $GDM_AUTH_FILE ]; then
  58.         SERVER_AUTH_FILE=$GDM_AUTH_FILE
  59.         DISP_SEARCH_STRING="$1"
  60.         return 0
  61.     fi
  62.  
  63.     # Finally, check for startx
  64.  
  65.     for XPID in `pidof X`; do
  66.         TRIAL_XAUTH_FILE=`tr '\0' '\n' < /proc/$XPID/environ | grep -e "^XAUTHORITY=" | cut -d= -f2`
  67.         TRIAL_XAUTH_KEY=`xauth -f $TRIAL_XAUTH_FILE list | grep "unix$1"`
  68.         if [ -n "$TRIAL_XAUTH_KEY" ]; then
  69.             SERVER_AUTH_FILE=$TRIAL_XAUTH_FILE
  70.             DISP_SEARCH_STRING="unix$1"
  71.             return 0
  72.         fi
  73.     done
  74.  
  75.     # Couldn't find the key
  76.  
  77.     return -1
  78. }
  79.  
  80. # Main part of script
  81.  
  82. #
  83. # Since the daemon is usually started during init time before X comes up,
  84. # $PATH may not yet contain the paths to the X binaries, particularly xauth.
  85. # Add the usual location for where xauth may live and fail out if we still
  86. # can't find it.
  87. #
  88.  
  89. PATH=$PATH:/usr/bin:/usr/X11R6/bin
  90. which xauth > /dev/null || exit -1
  91.  
  92. case "$1" in
  93.     grant)
  94.         GetServerAuthFile $2 || exit -1
  95.         DISP_AUTH_KEY=`xauth -f $SERVER_AUTH_FILE list | grep $DISP_SEARCH_STRING | awk '{ print $3 }'`
  96.         if [ -n "$DISP_AUTH_KEY" ]; then
  97.             xauth -f $3 add $2 . $DISP_AUTH_KEY || exit -1
  98.         else
  99.             exit -1
  100.         fi
  101.         ;;
  102.  
  103.     revoke)
  104.         xauth -f $3 remove $2 || exit -1
  105.         ;;
  106.  
  107.     *)
  108.         exit -1
  109.         ;;
  110. esac
  111. exit 0
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: