FreeBSD/lib/libpam/modules/pam_ssh/pam_ssh.c
/*
 * Attempts to load a private key from the specified file in the specified
 * directory, using the specified passphrase.  If successful, returns a
 * struct pam_ssh_key containing the key and its comment.
 */
Attempts to load a private key from the specified file in the specified
directory, using the specified passphrase.  If successful, returns a
struct pam_ssh_key containing the key and its comment.
Attempts to load a private key from the specified file in the specified directory using the specified passphrase . If successful returns a struct pam_ssh_key containing the key and its comment .
static struct pam_ssh_key *
pam_ssh_load_key(const char *dir, const char *kfn, const char *passphrase,
    int nullok)
{
	struct pam_ssh_key *psk;
	char fn[PATH_MAX];
	char *comment;
	Key *key;
	if (snprintf(fn, sizeof(fn), "%s/%s", dir, kfn) > (int)sizeof(fn))
		return (NULL);
	comment = NULL;
	key = key_load_private(fn, "", &comment);
	if (key != NULL && !(*passphrase == '\0' && nullok)) {
		key_free(key);
		return (NULL);
	}
	if (key == NULL)
		key = key_load_private(fn, passphrase, &comment);
	if (key == NULL) {
		openpam_log(PAM_LOG_DEBUG, "failed to load key from %s", fn);
		return (NULL);
	}
	openpam_log(PAM_LOG_DEBUG, "loaded '%s' from %s", comment, fn);
	if ((psk = malloc(sizeof(*psk))) == NULL) {
		key_free(key);
		free(comment);
		return (NULL);
	}
	psk->key = key;
	psk->comment = comment;
	return (psk);
}
static struct pam_ssh_key * pam_ssh_load_key ( const char * dir , const char * kfn , const char * passphrase , int nullok ) { struct pam_ssh_key * psk ; char fn [ PATH_MAX ] ; char * comment ; Key * key ; if ( snprintf ( fn , sizeof ( fn ) , " " , dir , kfn ) > ( int ) sizeof ( fn ) ) return ( NULL ) ; comment = NULL ; key = key_load_private ( fn , " " , & comment ) ; if ( key != NULL && ! ( * passphrase == ' \0 ' && nullok ) ) { key_free ( key ) ; return ( NULL ) ; } if ( key == NULL ) key = key_load_private ( fn , passphrase , & comment ) ; if ( key == NULL ) { openpam_log ( PAM_LOG_DEBUG , " " , fn ) ; return ( NULL ) ; } openpam_log ( PAM_LOG_DEBUG , " " , comment , fn ) ; if ( ( psk = malloc ( sizeof ( * psk ) ) ) == NULL ) { key_free ( key ) ; free ( comment ) ; return ( NULL ) ; } psk -> key = key ; psk -> comment = comment ; return ( psk ) ; }
Attempts to load a private key from the specified file in the specified
 directory, using the specified passphrase.
Attempts to load a private key from the specified file in the specified directory using the specified passphrase .
/*
	 * If the key is unencrypted, OpenSSL ignores the passphrase, so
	 * it will seem like the user typed in the right one.  This allows
	 * a user to circumvent nullok by providing a dummy passphrase.
	 * Verify that the key really *is* encrypted by trying to load it
	 * with an empty passphrase, and if the key is not encrypted,
	 * accept only an empty passphrase.
	 */