Scripts :

Download location (HTTP):       http://linux.bononline.nl/linux/encfs4session/src
                                



Adjusting PAM configuration

I've used pam_script in the auth and in the session part of the pam (login,kde) service file.
First I describe howto adjust the auth part, where pam_script is used more than once.

The auth part


Pam_script has the ability (from version 0.1.5) to get the password provided at login, and make this via an evironmentvariable PAM_AUTHTOK available to scripts.

The purpose here is to create a safe directory where confidential information (like credentials) are stored.

The module is stacked in the authpart:

cat /etc/pam.d/login
-- snip --

auth		required	pam_shells.so
auth		required	pam_script.so expose=1
auth		sufficient	pam_unix.so use_first_pass
auth		required	pam_script.so onauth=/etc/security/onauth.ldap
auth		sufficient	pam_ldap.so use_first_pass
auth		required	pam_script.so onauth=/etc/security/onauth.failed
auth		required	pam_deny.so

As you can see I use pam_scripts.so multiple times:

- The first time to run a script which creates a encrypted directory (with encfs) and to write the secret password to a file in this directory for use by credential sensitive programs like fusesmb and mount.cifs. This is done for the first auth module following, pam_unix.

- The second time to run a script which adjusts this encrypted directory to store the password in a ldap-subdirectory.

- The last time to run a script when authentication is not succesfull. When the preceding authmodules fail (pam_unix and pam_ldap) (and only then) this module is reached. It's neccasary to unmount the encrypted directory and to remove temporary files.

- Note that the last module of all is pam_deny, is really neccasary. Without it everybody is able to login. This is because pam_script always returns "PAM_SUCCESS", no mather what the return value is of the scripts.

Do not forget to add the flag "use_first_pass" to the existing module pam_unix.so.




The session part

When the session part is reached, it's sure that the credentials provided (password) are correct. This means that the password - in the the auth fase stored in a temporary file - is correct. So one thing to do in the session fase is to move the contents of the password.tmp to the permanent one, password.

A second thing is running script which need these credentials for own use, like mounting CIFS shares or fusesmb.
It's logical that any confidential information stays inside the safe directory. That's what it was all about in the first place!!

Note that this modules runs two scripts on default:
. /etc/security/onsessionopen : when a session start/opens;
. /etc/security/onsessionclose : when a session ends/closes.

I follow the default, there is no reason to do otherwise.

My /etc/pam.d/login file (the sessionpart) looks like:

cat /etc/pam.d/login
-- snip --

session		required	pam_mkhomedir.so
session		required	pam_motd.so
session	 	optional	pam_mail.so empty dir=/var/mail
session		optional	pam_lastlog.so
session		required	pam_env.so
session		required	pam_script.so
session  	required       	pam_unix.so
session		required	pam_ldap.so