Blame src/vlock/pam.c

Packit Service 50ad14
Packit Service 50ad14
/*
Packit Service 50ad14
Packit Service 50ad14
  PAM initialization routine for vlock, the VT locking program for linux.
Packit Service 50ad14
Packit Service 50ad14
  Copyright (C) 2002, 2005 Dmitry V. Levin <ldv@altlinux.org>
Packit Service 50ad14
Packit Service 50ad14
  This program is free software; you can redistribute it and/or modify
Packit Service 50ad14
  it under the terms of the GNU General Public License as published by
Packit Service 50ad14
  the Free Software Foundation; either version 2 of the License, or
Packit Service 50ad14
  (at your option) any later version.
Packit Service 50ad14
Packit Service 50ad14
  This program is distributed in the hope that it will be useful,
Packit Service 50ad14
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 50ad14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Packit Service 50ad14
  GNU General Public License for more details.
Packit Service 50ad14
Packit Service 50ad14
  You should have received a copy of the GNU General Public License
Packit Service 50ad14
  along with this program; if not, write to the Free Software
Packit Service 50ad14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Packit Service 50ad14
*/
Packit Service 50ad14
#include "config.h"
Packit Service 50ad14
Packit Service 50ad14
#include <stdio.h>
Packit Service 50ad14
#include <errno.h>
Packit Service 50ad14
#include <stdlib.h>
Packit Service 50ad14
#include <syslog.h>
Packit Service 50ad14
Packit Service 50ad14
#include <security/pam_misc.h>
Packit Service 50ad14
Packit Service 50ad14
#include "pam_auth.h"
Packit Service 50ad14
#include "vlock.h"
Packit Service 50ad14
#include "kbd_error.h"
Packit Service 50ad14
Packit Service 50ad14
static struct pam_conv conv = {
Packit Service 50ad14
	&misc_conv,
Packit Service 50ad14
	NULL
Packit Service 50ad14
};
Packit Service 50ad14
Packit Service 50ad14
pam_handle_t *
Packit Service 50ad14
init_pam(const char *username, const char *tty, int log)
Packit Service 50ad14
{
Packit Service 50ad14
	pam_handle_t *pamh = 0;
Packit Service 50ad14
	int rc             = pam_start("vlock", username, &conv, &pamh);
Packit Service 50ad14
Packit Service 50ad14
	if (rc != PAM_SUCCESS) {
Packit Service 50ad14
		/* pam_strerror is not available atm. */
Packit Service 50ad14
		if (log)
Packit Service 50ad14
			syslog(LOG_WARNING, "pam_start failed: %m");
Packit Service 50ad14
		else
Packit Service 50ad14
			kbd_warning(errno, "pam_start");
Packit Service 50ad14
		return 0;
Packit Service 50ad14
	}
Packit Service 50ad14
Packit Service 50ad14
	rc = pam_set_item(pamh, PAM_TTY, tty);
Packit Service 50ad14
	if (rc != PAM_SUCCESS) {
Packit Service 50ad14
		if (log)
Packit Service 50ad14
			syslog(LOG_WARNING, "pam_set_item: %s",
Packit Service 50ad14
			       pam_strerror(pamh, rc));
Packit Service 50ad14
		else
Packit Service 50ad14
			kbd_warning(0, "pam_set_item: %s",
Packit Service 50ad14
			            pam_strerror(pamh, rc));
Packit Service 50ad14
		pam_end(pamh, rc);
Packit Service 50ad14
		return 0;
Packit Service 50ad14
	}
Packit Service 50ad14
Packit Service 50ad14
	return pamh;
Packit Service 50ad14
}