The bug lies in your auth-pam.c, where you use the fork() replacement for the posix thread mechanisms. It seems that you never check for their availability and therefore never use it. The problem is that a pam module may be called several times, and some pam modules (pam_krb5* for example) rely on the fact that it can give informations to further calls, may it be through pam_set(/get)data or the pam environment. Since the pam_xx calls get called from different (forked) pids, it looses the address space and as a result all pam informations get lost. A force of the posix thread system (#define USE_POSIX_THREADS) solves that problem since the created thread operates in the same address space.
*** This bug has been marked as a duplicate of 688 ***
Mass change of RESOLVED bugs to CLOSED