home *** CD-ROM | disk | FTP | other *** search
/ ftp.rsa.com / 2014.05.ftp.rsa.com.tar / ftp.rsa.com / pub / agents / AuthenticationAgent_60_PAM_95_060308.tar / install_pam.sh next >
Linux/UNIX/POSIX Shell Script  |  2008-06-03  |  17KB  |  582 lines

  1. #!/bin/sh 
  2. #
  3. # Installation script for the RSA Authentication Agent 6.0 for PAM.
  4. #
  5. #
  6. #********************************************************************************
  7. #* COPYRIGHT (C) 2007  by RSA Security Inc.
  8. #*    ---ALL RIGHTS RESERVED---
  9. #********************************************************************************
  10. #
  11.  
  12. ############################################################
  13. # Set default values and commands for the shell script.
  14. ############################################################
  15. UNAME=`uname`
  16. UNAMER=`uname -r`
  17. HOSTNAME=`hostname`
  18. USER_NAME=""
  19. GREP=`which grep`
  20. ECHO=`which echo`
  21.  
  22. HERE=`dirname $0` 
  23. THEPWD=`/bin/pwd`
  24. if [ "$HERE" = "." ]; then
  25.     HERE="$THEPWD"
  26. else
  27. #if $HERE isn't absolute path add `pwd` to it
  28.  
  29.     cd "$HERE"
  30.     HERE=`/bin/pwd`
  31.     cd "$THEPWD"
  32. fi
  33.  
  34. ########################
  35. ########################
  36. CONFIG_FILE=""
  37. PAM_AGENT="/tmp/toto"
  38. PAM_AGENT_TAR="sd_pam_agent.tar"
  39. PAM_AGENT_MODULE="pam_securid"
  40. PAM_AGENT_DOC="doc"
  41. PAM_AGENT_README="readme.html"
  42. PAM_AGENT_TAR_GZ="$PAM_AGENT_TAR.gz"
  43. PAM_CONFIG="/etc/sd_pam.conf"
  44. LICENSE="$HERE/license.txt"
  45. LICENSE2="$HERE/license2.txt"
  46. MODULE_DIR="/usr/lib/security"
  47. PATH_ROOT=""
  48. echo_no_nl_mode="unknown"
  49.  
  50. ##############################################################################
  51. # Trap 
  52. #    this will trap any escape characters, and allow the program to abort normally 
  53. #    by calling abort_installation
  54. ##############################################################################
  55. trap 'trap "" 1 2 15; abort_installation' 1 2 15
  56.  
  57. ##############################################################################
  58. # echo_no_nl()
  59. #       Echo a string with no carriage return (if possible).  Must set
  60. #       $echo_no_nl to "unknown" before using for the first time.
  61. ##############################################################################
  62. echo_no_nl()
  63. {
  64.   if [ "$echo_no_nl_mode" = "unknown" ] ; then
  65.      echo_test=`echo \\\c`
  66.      if [ "$echo_test" = "\c" ] ; then
  67.         echo_no_nl_mode="-n"
  68.      else
  69.         echo_no_nl_mode="\c"
  70.      fi
  71.   fi
  72.  
  73.   if [ "$echo_no_nl_mode" = "\c" ] ; then
  74.      echo $* \\c
  75.   else
  76.      echo -n $*
  77.   fi
  78. }
  79.  
  80.  
  81. ##############################################################################
  82. # getfilename()
  83. # Gets a filename
  84. #   $1  The string to print to prompt the user
  85. #   $2  The default value if user hits <Enter> (y/n)
  86. #   $3  Type : DIRECTORY, EXISTINGFILE, NEWFILE, NEWDIRECTORY
  87. # The variable $YESORNO is set in accordance to what the user entered.
  88. ##############################################################################
  89. getfilename()
  90. {
  91. #####################################################
  92. # Set up line parameters as $1 and $2 are overwritten
  93. #####################################################
  94.   theprompt=$1
  95.   thedefault=$2
  96.   thetype=$3
  97.  
  98.   theans=""
  99.   until [ -n "$theans" ] ;
  100.   do
  101.     echo ""
  102.     echo_no_nl "$theprompt [$thedefault] "
  103.     read theans
  104.  
  105.     if [ "$theans" = "" ] ; then
  106.       theans=$thedefault
  107.     fi
  108.     case $thetype in
  109.         DIRECTORY) if [ ! -d "$theans" ]; then
  110.                         echo Directory $theans doesn\'t exist
  111.                         theans=""
  112.                    fi;;
  113.         READFILE)  if [ ! -f "$theans" ]; then
  114.                         echo File $theans doesn\'t exist
  115.                         theans=""
  116.                    elif [ ! -r "$theans" ]; then
  117.                         echo File "$theans" isn\'t readable
  118.                         theans=""
  119.                    fi;;
  120.         WRITEFILE)  if [ ! -f "$theans" ]; then
  121.                         echo File $theans doesn\'t exist
  122.                         theans=""
  123.                    elif [ ! -w "$theans" ]; then
  124.                         echo File "$theans" isn\'t writable
  125.                         theans=""
  126.                    fi;;
  127.         EXECFILE)  if [ ! -f "$theans" ]; then
  128.                         echo File $theans doesn\'t exist
  129.                         theans=""
  130.                    elif [ ! -x "$theans" ]; then
  131.                         echo File "$theans" isn\'t writable
  132.                         theans=""
  133.                    fi;;
  134.         NEWFILE)   if [ -f "$theans" ]; then
  135.                         echo File $theans already exist
  136.                         theans=""
  137.                    elif [ ! -d `dirname $theans` ]; then
  138.                         echo Directory `dirname $theans` doesn\'t exist
  139.                         theans=""
  140.                    elif [ ! -w `dirname $theans` ]; then
  141.                         echo Directory `dirname $theans` isn\'t writable
  142.                         theans=""
  143.                    fi;;
  144.         *);;
  145.     esac
  146.   done
  147.  
  148. }
  149.  
  150. ##############################################################################
  151. # getAcceptDecline()
  152. # Gets either a "Accept" or a "Decline" in the traditional (a/d) pattern 
  153. #               $1      The default value if user hits <Enter> (TRUE/FALSE)
  154. #               $2      The string to print to prompt the user
  155. # The variable $AORD is set in accordance to what the user entered.
  156. ##############################################################################
  157. getAcceptDecline()
  158. {
  159. #####################################################
  160. # Set up line parameters as $1 and $2 are overwritten
  161. #####################################################
  162.   AorDdef=$1
  163.   AorDprompt=$2
  164.  
  165.   AORD=""
  166.   until [ -n "$AORD" ] ;
  167.   do
  168.     echo ""
  169.     echo_no_nl $AorDprompt
  170.     read AORD
  171.  
  172.     AORD=`echo $AORD | tr '[a-z]' '[A-Z]'`
  173.  
  174.     case "$AORD"
  175.     in
  176.       A|ACCEPT )  AORD=TRUE;;
  177.       D|DECLINE )  AORD=FALSE;;
  178.       ''  )  AORD=$AorDdef;;
  179.       *   )  echo ""
  180.              echo "Please enter 'A', 'D' or '<return>' "
  181.              AORD="";;
  182.     esac
  183.   done
  184.  
  185. }
  186.  
  187.  
  188. ##############################################################################
  189. # getyesorno()
  190. # Gets either a "yes" or a "no" in the traditional (y/n) pattern 
  191. #               $1      The default value if user hits <Enter> (TRUE/FALSE)
  192. #               $2      The string to print to prompt the user
  193. # The variable $YESORNO is set in accordance to what the user entered.
  194. ##############################################################################
  195. getyesorno()
  196. {
  197. #####################################################
  198. # Set up line parameters as $1 and $2 are overwritten
  199. #####################################################
  200.   yesornodef=$1
  201.   yesornoprompt=$2
  202.  
  203.   YESORNO=""
  204.   until [ -n "$YESORNO" ] ;
  205.   do
  206.     echo ""
  207.     echo_no_nl $yesornoprompt
  208.     read YESORNO
  209.  
  210.     case "$YESORNO"
  211.     in
  212.       y|Y )  YESORNO=TRUE;;
  213.       n|N )  YESORNO=FALSE;;
  214.       ''  )  YESORNO=$yesornodef;;
  215.       *   )  echo ""
  216.              echo "Please enter 'y', 'n' or '<return>' "
  217.              YESORNO="";;
  218.     esac
  219.   done
  220.  
  221. }
  222.  
  223.  
  224. ##############################################################################
  225. # abort_installation()
  226. # This subroutine removes files that were recently installed and restores
  227. # the previous installation files, if they existed.
  228. ##############################################################################
  229. abort_installation()
  230. {
  231. #CP__need to fix this when done. Make sure to set values for each file placed somewhere
  232. echo ""
  233.   echo "Aborting Installation..."
  234.   exit 1
  235. }
  236.  
  237.  
  238. ############################################################
  239. # Display the License and Copyright files.
  240. ############################################################
  241. startup_screen()
  242. {
  243.  
  244.     # Changed so that we could have both license files shown
  245.     getyesorno TRUE "ARE YOU A CUSTOMER ORDERING THIS RSA PRODUCT FROM RSA SECURITY INC., FROM EITHER NORTH AMERICA, SOUTH AMERICA OR THE PEOPLE'S REPUBLIC OF CHINA (EXCLUDING HONG KONG): (y/n) [y]"
  246.     if [ "$YESORNO" = TRUE ] ; then
  247.         if [ -f "$LICENSE" ] ; then
  248.         more "$LICENSE" 
  249.     else
  250.         echo "The License Agreement text file could not be found in the current directory."
  251.         echo "Installation is aborting..."
  252.             abort_installation
  253.     fi
  254.     else
  255.         if [ -f "$LICENSE2" ] ; then
  256.         more "$LICENSE2" 
  257.     else
  258.         echo "The License Agreement text file could not be found in the current directory."
  259.         echo "Installation is aborting..."
  260.         abort_installation
  261.     fi
  262.     fi
  263.  
  264.      getAcceptDecline FALSE "Do you accept the License Terms and Conditions stated above? (Accept/Decline) [D]"
  265.     if [ "$AORD" = FALSE ] ; then
  266.     abort_installation;
  267.     fi
  268.     echo ""
  269.     echo ""
  270.     echo ""
  271. }
  272.  
  273. ############################################################
  274. # Check to see if the environment variable VAR_ACE is
  275. # defined and sdconf.rec exists
  276. ############################################################
  277. check_sdconf()
  278. {
  279. noerror=0
  280. if [ ! -n "$VAR_ACE" ]; then
  281.     VAR_ACE="/var/ace"
  282. fi
  283. theans=""
  284. while [ "$theans" = "" ] 
  285. do
  286.     getfilename "Enter Directory where sdconf.rec is located" $VAR_ACE DIRECTORY
  287.     if [ ! -f "$theans/sdconf.rec" ]; then 
  288.     echo file "$theans/sdconf.rec" not found
  289.     theans=""
  290.     elif [ ! -r "$theans/sdconf.rec" ]; then
  291.     echo file "$theans/sdconf.rec" not readable: change protection if needed
  292.         VAR_ACE="$theans"
  293.     theans=""
  294.     else
  295.     if [ "$theans" != "" ]; then
  296.             VAR_ACE="$theans"
  297.     fi
  298.     break
  299.     fi
  300.     
  301. done
  302.  
  303. }
  304.  
  305. ############################################################
  306. # Check to see if this is a supported platform.
  307. ############################################################
  308. check_platform()
  309. {
  310. #echo "check_platform: uname is [$UNAME]"
  311. case $UNAME
  312.    in
  313.      'SunOS'  )  SUN_HARDWARE=`uname -p`
  314.                 case "$SUN_HARDWARE" in
  315.                 'i386' )
  316.             WHOAMISOL=`/usr/ucb/whoami`
  317.                     OS_DIR="solx86" 
  318.             OS_EXT="so"
  319.             #
  320.             # Need this so grep handles extended expressions like '[[:space:]]'.
  321.             #
  322.             GREP="/usr/xpg4/bin/grep -E"
  323.  
  324.             USER_NAME=`echo $WHOAMISOL`;;
  325.         'sparc' )
  326.             WHOAMISOL=`/usr/ucb/whoami`
  327.                     OS_DIR="solsparc" 
  328.             OS_EXT="so"
  329.             #
  330.             # Need this so grep handles extended expressions like '[[:space:]]'.
  331.             #
  332.             GREP="/usr/xpg4/bin/grep -E"
  333.  
  334.             USER_NAME=`echo $WHOAMISOL`;;
  335.                 esac;;
  336.  
  337.      'Linux' ) LNX_VERS=`uname -i`
  338.                 case "$LNX_VERS" in
  339.                 'x86_64' ) 
  340.                     WHOAMILNX=`/usr/bin/whoami`
  341.                     OS_DIR="lnx64"
  342.                     OS_EXT="so"
  343.             
  344.             #
  345.             # Need this so that echo does the right thing with newlines.
  346.             #
  347.             ECHO="$ECHO -e"
  348.  
  349.             if [ -d "/lib64/security" ]; then
  350.             MODULE_DIR="/lib64/security"
  351.             else
  352.             MODULE_DIR="/lib/security"
  353.             fi
  354.                     USER_NAME=`echo $WHOAMILNX`;;
  355.                 'i386' ) 
  356.                     WHOAMILNX=`/usr/bin/whoami`
  357.                     OS_DIR="lnx32"
  358.                     OS_EXT="so"
  359.             
  360.             #
  361.             # Need this so that echo does the right thing with newlines.
  362.             #
  363.             ECHO="$ECHO -e"
  364.  
  365.                 MODULE_DIR="/lib/security"
  366.                     USER_NAME=`echo $WHOAMILNX`;;
  367.                *   )  echo ""
  368.                     echo "Sorry, this is not a supported configureation"
  369.                     echo ""
  370.                     abort_installation ;;
  371.                 esac;;
  372.  
  373.      'HP-UX' ) HP_VERS=`echo $UNAMER`
  374.                case "$HP_VERS" in
  375.            'B.11.23' )
  376.            WHOAMIHP11=`/bin/whoami`
  377.                    OS_DIR="hpitan"
  378.                    OS_EXT="1"
  379.            PAM_AGENT_MODULE="pam_securid"
  380.            MODULE_DIR="/usr/lib/security/hpux32"
  381.            USER_NAME=`echo $WHOAMIHP11`;;
  382.  
  383.                * )
  384.            WHOAMIHP11=`/bin/whoami`
  385.                    OS_DIR="hp11"
  386.                    OS_EXT="1"
  387.            USER_NAME=`echo $WHOAMIHP11`;;
  388.                esac;;
  389.      
  390.      'AIX' ) AIX_VERS=`uname -vr | awk '{print $2 * 1000 + $1}'`
  391.                 case "$AIX_VERS" in 
  392.             *)
  393.             OS_DIR="aix"
  394.                     OS_EXT="so"
  395.                     USER_NAME=`/usr/bin/whoami`
  396.                esac;; 
  397.      *   )  echo ""
  398.             echo "Sorry, $UNAME is not currently supported."
  399.             echo ""
  400.             abort_installation ;;
  401. esac
  402. }
  403.  
  404.  
  405. ############################################################
  406. # Ask the user for the destination of the Agent files and
  407. # other installation information, documentation
  408. ############################################################
  409. setup_paths()
  410. {
  411. ###########################################
  412. # Get the Agent directory path
  413. ###########################################
  414. theans=""
  415. DEFAULT_AGENT_ROOT="/opt"
  416. AGENT_ROOT=""
  417.  
  418. echo ""
  419. getfilename "Please enter the root path for the RSA Authentication Agent for PAM directory" $DEFAULT_AGENT_ROOT DIRECTORY
  420. if [ "$theans" = "" ]; then
  421.     theans="$DEFAULT_AGENT_ROOT"
  422. fi
  423. while [ -d "$theans/pam" ] 
  424. do
  425.     echo PAM Agent is already installed in the "$theans/pam"
  426.     getyesorno TRUE "Would you like to overwrite it? (y/n) [y]"
  427.     if [ "$YESORNO" = FALSE ] ; then
  428.         getfilename "Please enter the root path for the new RSA Authentication Agent for PAM directory" $DEFAULT_AGENT_ROOT DIRECTORY
  429.     else
  430.         AGENT_ROOT="$theans"
  431.         break
  432.     fi
  433. done
  434. if [ "$AGENT_ROOT" = "" ]; then
  435.     AGENT_ROOT="$theans"
  436. fi
  437.  
  438.  
  439. echo ""
  440. echo "The RSA Authentication Agent for PAM will be installed in the $AGENT_ROOT directory."
  441.  
  442. }
  443.  
  444. #################
  445. # Check PAM_CONFIG to see if it has a line that defines VARIABLE.
  446. # If so, do nothing.  If not, append ENTRY to the end of PAM_CONFIG.
  447. #################
  448. check_config_line()
  449. {
  450. VARIABLE=$1
  451. ENTRY=$2
  452.  
  453. if $GREP "^[[:space:]]*$VARIABLE[[:space:]]*=" $PAM_CONFIG > /dev/null; then
  454.     echo "$VARIABLE exists - entry will not be updated"
  455. else
  456.     echo "$VARIABLE does not exist - entry will be appended"
  457.     $ECHO "$ENTRY" >> "$PAM_CONFIG"
  458.     echo "" >> "$PAM_CONFIG"
  459.     echo "" >> "$PAM_CONFIG"
  460. fi
  461. }
  462.  
  463. #################
  464. # Create PAM config file
  465. #################
  466.  
  467. create_conf()
  468. {
  469. if [ -f "$PAM_CONFIG" ]; then
  470.     cp "$PAM_CONFIG" "$PAM_CONFIG".bak
  471. fi
  472.  
  473. touch "$PAM_CONFIG"
  474.  
  475. $ECHO "\nChecking $PAM_CONFIG:\n"
  476.  
  477. check_config_line VAR_ACE \
  478. "#VAR_ACE ::  the location where the sdconf.rec, sdstatus.12 and securid files will go\n\
  479. VAR_ACE=$VAR_ACE"
  480.  
  481. check_config_line ENABLE_GROUP_SUPPORT \
  482. "#ENABLE_GROUP_SUPPORT :: 1 to enable; 0 to disable group support\n\
  483. ENABLE_GROUP_SUPPORT=0"
  484.  
  485. check_config_line INCL_EXCL_GROUPS \
  486. "#INCL_EXCL_GROUPS :: 1 to always prompt the listed groups for securid authentication (include)\n\
  487. #                 :: 0 to never prompt the listed groups for securid authentication (exclude)\n\
  488. INCL_EXCL_GROUPS=0"
  489.  
  490. check_config_line LIST_OF_GROUPS \
  491. "#LIST_OF_GROUPS :: a list of groups to include or exclude...Example\n\
  492. LIST_OF_GROUPS=other:wheel:eng:othergroupnames "
  493.  
  494. check_config_line PAM_IGNORE_SUPPORT \
  495. "#PAM_IGNORE_SUPPORT :: 1 to return PAM_IGNORE if a user is not SecurID authenticated due to their group membership\n\
  496. #                   :: 0 to UNIX authenticate a user that is not SecurID authenticated due to their group membership\n\
  497. PAM_IGNORE_SUPPORT=0"
  498.  
  499. check_config_line AUTH_CHALLENGE_USERNAME_STR \
  500. "#AUTH_CHALLENGE_USERNAME_STR :: prompt message to ask user for their username/login id\n\
  501. AUTH_CHALLENGE_USERNAME_STR=Enter USERNAME :"
  502.  
  503. check_config_line AUTH_CHALLENGE_RESERVE_REQUEST_STR \
  504. "#AUTH_CHALLENGE_RESERVE_REQUEST_STR :: prompt message to ask administrator for their System password\n\
  505. AUTH_CHALLENGE_RESERVE_REQUEST_STR=Please enter System Password for root :"
  506.  
  507. check_config_line AUTH_CHALLENGE_PASSCODE_STR \
  508. "#AUTH_CHALLENGE_PASSCODE_STR :: prompt message to ask user for their Passcode\n\
  509. AUTH_CHALLENGE_PASSCODE_STR=Enter PASSCODE :"
  510.  
  511. check_config_line AUTH_CHALLENGE_PASSWORD_STR \
  512. "#AUTH_CHALLENGE_PASSWORD_STR :: prompt message to ask user for their Password\n\
  513. AUTH_CHALLENGE_PASSWORD_STR=Enter your PASSWORD :"
  514.  
  515. chmod 644 "$PAM_CONFIG" 
  516. }
  517.  
  518.  
  519. ############################################################
  520. # Install the RSA Authentication Agent 6.0 for PAM library and documentation.
  521. ############################################################
  522. install_pam_agent()
  523. {
  524. ##############
  525. #untar the RPM file
  526. ##############
  527.  
  528. cd $AGENT_ROOT/
  529. if [ -f "$HERE/$OS_DIR/$PAM_AGENT_TAR" ]; then
  530.     tar xvf "$HERE/$OS_DIR/$PAM_AGENT_TAR"
  531. elif [ -f "$HERE/$OS_DIR/$PAM_AGENT_TAR_GZ" ]; then
  532.     tar xzvf "$HERE/$OS_DIR/$PAM_AGENT_TAR_GZ"
  533. else
  534.     echo Error $HERE/$OS_DIR/$PAM_AGENT_TAR or $HERE/$OS_DIR/$PAM_AGENT_TAR_GZ does not exist
  535.     abort_installation
  536. fi
  537.  
  538. if [ -d "$AGENT_ROOT/pam/$PAM_AGENT_DOC" ]; then
  539.     cp  "$HERE/"*.pdf "$AGENT_ROOT/pam/$PAM_AGENT_DOC"
  540. fi
  541.  
  542. if [ -f $AGENT_ROOT/pam/lib/$PAM_AGENT_MODULE.$OS_EXT ]; then
  543.         cp "$HERE/"uninstall* "$AGENT_ROOT/pam"
  544.         cp "$AGENT_ROOT/pam/lib/$PAM_AGENT_MODULE.$OS_EXT" "$MODULE_DIR"
  545.         chmod 755 "$MODULE_DIR/$PAM_AGENT_MODULE.$OS_EXT"
  546. else
  547.         echo Error Could not find $PAM_AGENT_MODULE.$OS_EXT in $AGENT_ROOT/pam/$OS_DIR directory.
  548.         abort_installation
  549. fi
  550. cd "$HERE"
  551. chown -R root "$AGENT_ROOT/pam"
  552. chmod -R 700  "$AGENT_ROOT/pam"
  553.  
  554. }
  555.  
  556. check_user()
  557. {
  558. #########################
  559. # make sure user is root
  560. #########################
  561.  
  562. if [ "$USER_NAME" != root ]; then 
  563.     echo "You Must be ROOT to install this agent"
  564.     abort_installation
  565. fi
  566. }
  567.  
  568.  
  569. check_platform
  570. check_user
  571. startup_screen
  572. check_sdconf
  573. setup_paths
  574. install_pam_agent
  575. create_conf
  576.  
  577. echo ""
  578. echo "*************************************************************"
  579. echo "* You have successfully installed RSA Authentication Agent 6.0 for PAM"
  580. echo "*************************************************************"
  581. echo ""
  582.