I do have a workaround using pam_exec, but do not feel that mounting of file shares belongs in the pam framework.
By inserting the following lines into /etc/pam.d/password-auth the listed script at the end will mount the right homedir upon password authentication. A lazy unmount is performed at session_close, but might not be the right thing to do.
Put this into password-auth
auth optional pam_exec.so expose_authtok /usr/bin/pam_mount_cifs.s
and this
session optional pam_exec.so /usr/bin/pam_mount_cifs.sh
both lines should be inserted after pam_mkhomedir lines inserted by the realm join command.
Another alternative is using pam_mount as described in this post, but then you must compile and install pam_mount manually as it is not provided with CentOS. (or get it from the Nux repo)
Here is the script itself, it shoud be saved as /usr/bin/pam_mount_cifs.sh
#!/bin/bash
# this script is called from pam by adding entries to /etc/pam.d/password-auth like this
#
# auth optional pam_exec.so expose_authtok /usr/bin/pam_mount_cifs.sh
#
# and
#
# session optional pam_exec.so /usr/bin/pam_mount_cifs.sh
# the script assumes that the home dir is already created by pam_mkhomedir and pam_oddjob_mkhomedir.
DOMAIN=my.domain
FILESERVER=fileserver.my.domain
MNTPNT=/home
# turn of globbing because getent returns as string containing a *
set -f
pwstring=$(getent passwd $PAM_USER)
userinfo=(${pwstring//:/ })
USER=$PAM_USER
# strip off @my.domain from user.
SHORTUSER=${USER%@$DOMAIN}
USERUID=${userinfo[2]}
USERGID=${userinfo[3]}
USERDIR=$MNTPNT/$USER
if [ -z "$PAM_TYPE" ]; then
echo this script should only be called from pam
exit 1
fi
if [ $PAM_TYPE = "open_session" ]; then
# nothing to do here, mount happened in auth.
exit 0
fi
if [ $PAM_TYPE = "close_session" ]; then
# this might cause problems if you have services that doesn't create procs in /home. (rstudio is one example)
umount -l $USERDIR
exit 0
fi
if [ ! -d $USERDIR ]; then
mkdir -p $USERDIR
# chown $USERID:$USERGID $USERDIR
fi
# skip if the share is already mounted.
mountpoint -q $USERDIR && exit 0
# make mount.cifs read password from stdin
export PASSWD_FD=0
mount -t cifs //$FILESERVER/$SHORTUSER $USERDIR -o user=$SHORTUSER,uid=$USERUID,gid=$USERGID,noserverino