FreeBSD/lib/libpam/modules/pam_ssh/pam_ssh.c
/*
 * Adds previously stored keys to a running agent.
 */
Adds previously stored keys to a running agent.
Adds previously stored keys to a running agent .
static int
pam_ssh_add_keys_to_agent(pam_handle_t *pamh)
{
	const struct pam_ssh_key *psk;
	const char **kfn;
	const void *item;
	char **envlist, **env;
	int fd, pam_err;
	envlist = environ;
	if ((environ = pam_getenvlist(pamh)) == NULL) {
		environ = envlist;
		return (PAM_SYSTEM_ERR);
	}
	if (ssh_get_authentication_socket(&fd) != 0) {
		openpam_log(PAM_LOG_DEBUG, "failed to connect to the agent");
		pam_err = PAM_SYSTEM_ERR;
		goto end;
	}
	for (kfn = pam_ssh_keyfiles; *kfn != NULL; ++kfn) {
		pam_err = pam_get_data(pamh, *kfn, &item);
		if (pam_err == PAM_SUCCESS && item != NULL) {
			psk = item;
			if (ssh_add_identity(fd, psk->key, psk->comment) == 0)
				openpam_log(PAM_LOG_DEBUG,
				    "added %s to ssh agent", psk->comment);
			else
				openpam_log(PAM_LOG_DEBUG, "failed "
				    "to add %s to ssh agent", psk->comment);
			pam_set_data(pamh, *kfn, NULL, NULL);
		}
	}
	pam_err = PAM_SUCCESS;
	ssh_close_authentication_socket(fd);
 end:
	for (env = environ; *env != NULL; ++env)
		free(*env);
	free(environ);
	environ = envlist;
	return (pam_err);
}
static int pam_ssh_add_keys_to_agent ( pam_handle_t * pamh ) { const struct pam_ssh_key * psk ; const char * * kfn ; const void * item ; char * * envlist , * * env ; int fd , pam_err ; envlist = environ ; if ( ( environ = pam_getenvlist ( pamh ) ) == NULL ) { environ = envlist ; return ( PAM_SYSTEM_ERR ) ; } if ( ssh_get_authentication_socket ( & fd ) != 0 ) { openpam_log ( PAM_LOG_DEBUG , " " ) ; pam_err = PAM_SYSTEM_ERR ; goto end ; } for ( kfn = pam_ssh_keyfiles ; * kfn != NULL ; ++ kfn ) { pam_err = pam_get_data ( pamh , * kfn , & item ) ; if ( pam_err == PAM_SUCCESS && item != NULL ) { psk = item ; if ( ssh_add_identity ( fd , psk -> key , psk -> comment ) == 0 ) openpam_log ( PAM_LOG_DEBUG , " " , psk -> comment ) ; else openpam_log ( PAM_LOG_DEBUG , " " " " , psk -> comment ) ; pam_set_data ( pamh , * kfn , NULL , NULL ) ; } } pam_err = PAM_SUCCESS ; ssh_close_authentication_socket ( fd ) ; end : for ( env = environ ; * env != NULL ; ++ env ) free ( * env ) ; free ( environ ) ; environ = envlist ; return ( pam_err ) ; }
Adds previously stored keys to a running agent.
Adds previously stored keys to a running agent .
/* switch to PAM environment */ /* get a connection to the agent */ /* look for keys to add to it */ /* we won't need the key again, so wipe it */ /* disconnect from agent */ /* switch back to original environment */