Blame tests/pam_ssh_agent_auth/pam_save_ssh_var.c

Petr Šabata 81d24c
/*
Petr Šabata 81d24c
This simple pam module saves the content of SSH_USER_AUTH variable to /tmp/SSH_USER_AUTH
Petr Šabata 81d24c
file.
Petr Šabata 81d24c
Petr Šabata 81d24c
Setup:
Petr Šabata 81d24c
  - gcc -fPIC -DPIC -shared -rdynamic -o pam_save_ssh_var.o pam_save_ssh_var.c
Petr Šabata 81d24c
  - copy pam_save_ssh_var.o to /lib/security resp. /lib64/security
Petr Šabata 81d24c
  - add to /etc/pam.d/sshd
Petr Šabata 81d24c
	auth	requisite	pam_save_ssh_var.o
Petr Šabata 81d24c
*/
Petr Šabata 81d24c
Petr Šabata 81d24c
/* Define which PAM interfaces we provide */
Petr Šabata 81d24c
#define PAM_SM_ACCOUNT
Petr Šabata 81d24c
#define PAM_SM_AUTH
Petr Šabata 81d24c
#define PAM_SM_PASSWORD
Petr Šabata 81d24c
#define PAM_SM_SESSION
Petr Šabata 81d24c
Petr Šabata 81d24c
/* Include PAM headers */
Petr Šabata 81d24c
#include <security/pam_appl.h>
Petr Šabata 81d24c
#include <security/pam_modules.h>
Petr Šabata 81d24c
#include <stdlib.h>
Petr Šabata 81d24c
#include <stdio.h>
Petr Šabata 81d24c
Petr Šabata 81d24c
int save_ssh_var(pam_handle_t *pamh, const char *phase) {
Petr Šabata 81d24c
	FILE *fp;
Petr Šabata 81d24c
	const char *var;
Petr Šabata 81d24c
Petr Šabata 81d24c
	fp = fopen("/tmp/SSH_USER_AUTH","a");
Petr Šabata 81d24c
	fprintf(fp, "BEGIN (%s)\n", phase);
Petr Šabata 81d24c
	var = pam_getenv(pamh, "SSH_USER_AUTH");
Petr Šabata 81d24c
	if (var != NULL) {
Petr Šabata 81d24c
		fprintf(fp, "SSH_USER_AUTH: '%s'\n", var);
Petr Šabata 81d24c
	}
Petr Šabata 81d24c
	fprintf(fp, "END (%s)\n", phase);
Petr Šabata 81d24c
	fclose(fp);
Petr Šabata 81d24c
Petr Šabata 81d24c
	return 0;
Petr Šabata 81d24c
}
Petr Šabata 81d24c
Petr Šabata 81d24c
/* PAM entry point for session creation */
Petr Šabata 81d24c
int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) {
Petr Šabata 81d24c
	return(PAM_IGNORE);
Petr Šabata 81d24c
}
Petr Šabata 81d24c
Petr Šabata 81d24c
/* PAM entry point for session cleanup */
Petr Šabata 81d24c
int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv) {
Petr Šabata 81d24c
	return(PAM_IGNORE);
Petr Šabata 81d24c
}
Petr Šabata 81d24c
Petr Šabata 81d24c
/* PAM entry point for accounting */
Petr Šabata 81d24c
int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) {
Petr Šabata 81d24c
	return(PAM_IGNORE);
Petr Šabata 81d24c
}
Petr Šabata 81d24c
Petr Šabata 81d24c
/* PAM entry point for authentication verification */
Petr Šabata 81d24c
int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) {
Petr Šabata 81d24c
	save_ssh_var(pamh, "auth");
Petr Šabata 81d24c
	return(PAM_IGNORE);
Petr Šabata 81d24c
}
Petr Šabata 81d24c
Petr Šabata 81d24c
/*
Petr Šabata 81d24c
   PAM entry point for setting user credentials (that is, to actually
Petr Šabata 81d24c
   establish the authenticated user's credentials to the service provider)
Petr Šabata 81d24c
 */
Petr Šabata 81d24c
int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) {
Petr Šabata 81d24c
	return(PAM_IGNORE);
Petr Šabata 81d24c
}
Petr Šabata 81d24c
Petr Šabata 81d24c
/* PAM entry point for authentication token (password) changes */
Petr Šabata 81d24c
int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, const char **argv) {
Petr Šabata 81d24c
	return(PAM_IGNORE);
Petr Šabata 81d24c
}
Petr Šabata 81d24c