Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pam_ecp

download and compile pam-python-1.0.4 (http://pam-python.sourceforge.net/) on CentOS

(python-pam is a pam client, NOT to write pam modules)

Put everything under /lib64/security, such as pam_python.so, and python pam scripts, e.g. pam_permit.py

Here is a test script. It allows you to log in as test1 with password '11'. (User test1 needs to exist on the host.) Some output will be written to /var/log/secure.

#
# Duplicates pam_permit.c
#
#import sys
import syslog
#from aaf import get

DEFAULT_USER	= "nobody"

def pam_sm_authenticate(pamh, flags, argv):
  try:

    syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: %s"%flags)
    syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: %s"%argv)
    syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: %s"%pamh.ruser)
    msg_style = pamh.PAM_TEXT_INFO
    msg = "IdP password:"
    try:
      pamh.conversation(pamh.Message(msg_style, msg))
    except pamh.exception:
      return pamh.PAM_SYSTEM_ERR

    user = pamh.get_user(None)
    syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: %s"%user)
    if user != "test1":
      return pamh.PAM_USER_UNKNOWN
    pamh.ruser="test11"
    syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: %s"%pamh.authtok)
    p = pamh.authtok
    if p is None or p != "11":
      return pamh.PAM_AUTH_ERR
  except pamh.exception, e:
    return e.pam_result
  if user == None:
    pamh.user = DEFAULT_USER
  syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: password is correct %d" %pamh.PAM_SUCCESS)
  return pamh.PAM_SUCCESS

def pam_sm_setcred(pamh, flags, argv):
  syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: pam_sm_setcred")
  return pamh.PAM_SUCCESS

def pam_sm_acct_mgmt(pamh, flags, argv):
  syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: pam_sm_acct_mgmt")
  return pamh.PAM_SUCCESS

def pam_sm_open_session(pamh, flags, argv):
  syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: pam_sm_open_session")
  return pamh.PAM_SUCCESS

def pam_sm_close_session(pamh, flags, argv):
  syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: pam_sm_close_session")
  return pamh.PAM_SUCCESS

def pam_sm_chauthtok(pamh, flags, argv):
  syslog.syslog(syslog.LOG_ERR, "MY MESSAGE: pam_sm_chauthtok")
  return pamh.PAM_SUCCESS

Add it to pam:

/etc/pam.d/password-auth-ac

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        sufficient    pam_python.so pam_permit.py
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account      requisite   pam_python.so pam_permit.py
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3 type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password      requisite   pam_python.so pam_permit.py
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
session      requisite   pam_python.so pam_permit.py

/etc/pam.d/system-auth-ac

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        requisite    pam_python.so pam_permit.py
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
auth        requisite    pam_python.so pam_permit.py
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3 type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
auth        requisite    pam_python.so pam_permit.py
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
auth        requisite    pam_python.so pam_permit.py
session     required      pam_unix.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.