Simple PAM Example

I want to develop an authentication module using PAM, but it's hard for me to get a simple example of work.

To start, I would like to make a simple SSH registration system, where if a user enters a username backdoor, then the user will log in without a password (as in TRON Legacy).

I tried to use this guide as a template, but I cannot get it to work. Here is my code:

PAM_EXTERN int pam_sm_setcred( pam_handle_t *pamh, int flags, int argc, const char **argv ) {
    return PAM_SUCCESS ;
}

PAM_EXTERN int pam_sm_authenticate( pam_handle_t *pamh, int flags,int argc, const char **argv ) {
    int retval;

    printf("I'm here");

    const char* pUsername;
    retval = pam_get_user(pamh, &pUsername, "Username: ");
    if (retval != PAM_SUCCESS) {
        return retval;
    }

    if (strcmp(pUsername, "backdoor") != 0) {
        return PAM_AUTH_ERR;
    }
    return PAM_SUCCESS;
}

When I log in with a name backdoor, I get permission to refuse. I tried to create a user account, but I will still be asked to enter a password.

, " ". - ?

EDIT:

/etc/pam.d/sshd @include common-auth:

auth sufficient mypam.so

.so , , .

pam.conf( ). , SSH , .

EDIT:

- . :

https://github.com/beatgammit/simple-pam

open-source, , , !

+3
1

-, - , . , common-auth, , - common-auth . , sshd .

, , pam, - . , /etc/pam.d/check_user, pam_unix.

+3

All Articles