I am using an Active Domain jamie_ad1.net, and I have a user greg there.
When I ssh -l greg@jamie_ad1.net x.x.x.x I am successfully being logged in.
When, however, I am authenticating the user in my program, my process_user() function (below) returns error 7 (PAM_PERM_DENIED - The caller does not possess the required authority.)
What do I do wrong? Note that during ssh, it is /etc/pam.d/system-auth that is being used. I am using the same PAM service name "system_auth" in my program, too (and I also used "sshd", and "login" - all failed.)
static int process_user( const char* uname, const char* pwd )
{
int rv = 0 ;
struct pam_conv conv ;
pam_handle_t* pamh = NULL;
conv.conv = &pamauth_conv ;
conv.appdata_ptr = ( void* )pwd ;
if (
(( rv = pam_start( "system-auth", uname, &conv, &pamh )) == PAM_SUCCESS )
&& (( rv = pam_acct_mgmt(pamh, PAM_SILENT | PAM_DISALLOW_NULL_AUTHTOK )) == PAM_SUCCESS )
&& (( rv = pam_authenticate( pamh, PAM_SILENT | PAM_DISALLOW_NULL_AUTHTOK )) == PAM_SUCCESS )
)
...
pam_end( pamh, rv ) ;
...
}
Below I am showing the convesation funcion used by process_user()
While under gdb I see that num_msg is 1, and the msg[ 0 ]->msg is "Password: ", and that the function properly sets p[ 0 ].resp as strduped password (I have checked that the password is correct.)
static int pamauth_conv( int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr )
{
int rv = PAM_SUCCESS ;
struct pam_response* p = NULL ;
int i ;
p = calloc( num_msg, sizeof( struct pam_response )) ;
if ( p == NULL )
rv = PAM_BUF_ERR ;
else
{
for ( i = 0; ( rv == PAM_SUCCESS ) && ( i < num_msg ); i++ )
if ( strcmp( msg[ i ]->msg, "Password: " ) == 0 ) /* support password conversation only */
{
p[ i ].resp = strdup(( char* )appdata_ptr ) ;
if ( p[ i ].resp == NULL )
rv = PAM_BUF_ERR;
}
}
if ( rv == PAM_SUCCESS )
*resp = p ;
else if ( p )
{
for ( i = 0; i < num_msg; i++ )
if ( p[ i ].resp )
free( p[ i ].resp ) ;
free( p ) ;
}
return rv ;
}
NOTE: The pam_acct_mgmt() call returns SUCCESS, so it confirms that the greg@jamie_ad1.net user exists. It is pam_authenticate() that complains.
Contents of /etc/pam.d/system-auth, which is exactly the same as `/etc/pam.d/password-auth' :
#%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_fprintd.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 500 quiet
auth sufficient pam_ldap.so use_first_pass
auth sufficient pam_winbind.so use_first_pass
auth required pam_deny.so
account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 500 quiet
account [default=bad success=ok user_unknown=ignore] pam_ldap.so
account [default=bad success=ok user_unknown=ignore] pam_winbind.so
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 sufficient pam_ldap.so use_authtok
password sufficient pam_winbind.so use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
session optional pam_oddjob_mkhomedir.so umask=0077
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_ldap.so
Contents of /etc/pam.d/sshd
#%PAM-1.0
auth required pam_sepermit.so
auth include password-auth
account required pam_nologin.so
account include password-auth
password include password-auth
session required pam_selinux.so close
session required pam_loginuid.so
session required pam_selinux.so open env_params
session optional pam_keyinit.so force revoke
session include password-auth
session required pam_lastlog.so showfailed
/etc/pam.d/system-authand nothing else? I would typically expect sshd to use its own service configuration (/etc/pam.d/sshd) which would include this common configuration and add its service specific config... - Peter Brittainpam_start( "sshd" ...)as well, and the result was the same. - Grzegorz/etc/krb5.confto see if it has configuration for domainjamie_ad1.net. Or alternatively runklistright after successful ssh session and check if it displays active Kerberos tickets. In that case you might need to learn usingpam_krb5. - void/etc/krb5.confcontains proper configuration. Howeverklistshows this:klist: No credentials cache found (ticket cache FILE:/tmp/krb5cc_16777216)- BTW/tmp/krb5cc_16777216does not exist. - Grzegorzklistafter successfullyssh-ing(I am putting <lf> at the end of each line to make it easier to reconstruct it:)Ticket cache: FILE:/tmp/krb5cc_16777216<lf>Default principal: grg@JAMIE_AD1.NET<lf> <lf>Valid starting Expires Service principal<lf>08/02/16 15:09:59 08/03/16 01:10:05 krbtgt/JAMIE_AD1.NET@JAMIE_AD1.NET<lf>renew until 08/09/16 15:09:59<lf> - Grzegorz