(file) Return to installpam-sles CVS log (file) (dir) Up to [OMI] / omi / scripts

File: [OMI] / omi / scripts / installpam-sles (download)
Revision: 1.3, Mon Apr 20 17:20:13 2015 UTC (9 years ago) by krisbash
Branch: MAIN
CVS Tags: OMI_1_0_8_2, OMI_1_0_8_1, HEAD
Changes since 1.2: +1 -1 lines
OMI 1.0.8-1

#!/bin/sh

get_new_pam_config_file() {
  #
  # Get configuration for sshd, service modules types auth and account
  #
  sshd_conf=`egrep "^[# ]*sshd[ ]+(auth|account)" /etc/pam.conf`
  if [ $? -ne 0 ]; then
    # No match found
    # sshd not explicitly configured.
    # Use passwd
    sshd_conf=`echo "omi    auth     include        common-auth
omi    auth     required       pam_nologin.so
omi    account  include        common-account"`
  fi
  
  #
  # Substitute sshd with omi.
  #
  omi_conf=`echo "$sshd_conf" | sed "s/sshd/omi/g"`
  if [ $? -ne 0 ]; then
    echo "can't parse /etc/pam.conf"
    return 1
  fi
}

configure_pam_file() {
  #
  # First check if omi is already configured in pam.conf
  #
  grep -s "^[# ]*omi" /etc/pam.conf > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    # Match found
    # Looks like omi is already configured
    echo "omi already configured"
    return 0
  fi
  
  get_new_pam_config_file 
  
  #
  # Write the final configuration to pam.conf
  #
  # copy file first and modify this copy, so in case of low disk space we preserve the original file
  cp /etc/pam.conf /etc/pam.conf.omi-copy && echo "# The configuration of omi is generated by the omi installer.
$omi_conf
# End of section generated by the omi installer.
" >> /etc/pam.conf.omi-copy
  if [ $? -ne 0 ]; then
    echo "can't update file /etc/pam.conf.omi-copy"
    rm -f /etc/pam.conf.omi-copy
    return 1
  fi
  # verify that complete file was written 
  grep "# End of section generated by the omi installer." /etc/pam.conf.omi-copy > /dev/null 2>&1
  if [ $? -ne 0 ]; then
    echo "can't update file /etc/pam.conf.omi-copy"
    rm -f /etc/pam.conf.omi-copy
    return 1
  fi
  # use move to substitute original file with verified copy
  mv /etc/pam.conf.omi-copy /etc/pam.conf
  if [ $? -ne 0 ]; then
    echo "can't replace /etc/pam.conf"
    return 1
  fi
}

get_new_pam_config_dir() {
  #
  # Get configuration for sshd, service modules types auth and account
  #
  sshd_conf=`egrep "(auth|account)" /etc/pam.d/sshd 2> /dev/null`
  if [ $? -ne 0 ]; then
    # No match found
    # sshd not explicitly configured.
    # Use passwd
    sshd_conf=`echo "auth     include        common-auth
auth     required       pam_nologin.so
account  include        common-account"`
  fi
  
  omi_conf=$sshd_conf
}

configure_pam_dir() {
  #
  # First check if omi is already configured
  #
  if [ -f /etc/pam.d/omi ]; then
    # Match found
    # Looks like omi is already configured
    echo "omi already configured"
    return 0
  fi
  
  get_new_pam_config_dir 
  echo "#%PAM-1.0
# The configuration of omi is generated by the omi installer.
$omi_conf" > /etc/pam.d/omi
  if [ $? -ne 0 ]; then
    echo "can't create /etc/pam.d/omi"
    return 1
  fi
}

configure_pam() {
  #
  # Check if pam is configured with single
  # configuration file or with configuration
  # directory.
  #
  if [ -s /etc/pam.conf ]; then
    configure_pam_file 
  elif [ -d /etc/pam.d ]; then
    configure_pam_dir 
  else
    # No pam configuration.
    echo "PAM does not seem to be configured."
    echo "Checked both /etc/pam.conf and /etc/pam.d."
    return 1
  fi
  return 0
}

id=`__BUILDTOOL__ username`

if [ "$id" != "root" ]; then
    echo
    echo "************************************************************"
    echo "* Warning: PAM configuration not performed (requires root  *"
    echo "* privileges).                                             *"
    echo "************************************************************"
    echo
    exit 0
fi

configure_pam 
exit 0

ViewCVS 0.9.2