2018-04-01 00:09:00 +00:00
|
|
|
/*
|
|
|
|
FILENAME : pam_panic_authdevice.c
|
|
|
|
DESCRIPTION : Authenticates against the removable media
|
|
|
|
AUTHOR : Bandie
|
|
|
|
DATE : 2018-03-27T02:34:08+02:00
|
|
|
|
LICENSE : GNU-GPLv3
|
|
|
|
*/
|
|
|
|
|
2018-09-28 19:00:16 +00:00
|
|
|
#include "pam_panic_authdevice.h"
|
2018-09-21 20:48:13 +00:00
|
|
|
|
2018-04-01 19:32:15 +00:00
|
|
|
#include <unistd.h>
|
2018-09-21 20:48:13 +00:00
|
|
|
|
|
|
|
#include "../../lib/gettext.h"
|
2018-05-11 02:03:19 +00:00
|
|
|
#include <security/pam_modules.h>
|
|
|
|
#include <security/pam_ext.h>
|
2018-04-01 19:32:15 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
|
2018-09-21 20:48:13 +00:00
|
|
|
#include "pam_panic_reject.h"
|
2018-04-01 19:32:15 +00:00
|
|
|
#include "pam_panic_authdevice.h"
|
2018-03-31 23:53:41 +00:00
|
|
|
|
2018-09-21 20:48:13 +00:00
|
|
|
#define _(String) gettext(String)
|
|
|
|
|
|
|
|
|
2018-03-31 23:53:41 +00:00
|
|
|
int authDevice(pam_handle_t *pamh, char *allowed, char *rejected, char *serious_dev, int8_t bSerious, int8_t bReboot, int8_t bPoweroff){
|
|
|
|
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
2018-09-21 20:48:13 +00:00
|
|
|
|
|
|
|
// gettext
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
2018-05-10 23:29:13 +00:00
|
|
|
int8_t counter = 0;
|
|
|
|
while(access(allowed, F_OK) == -1 && access(rejected, F_OK) == -1){
|
2018-09-21 20:48:13 +00:00
|
|
|
pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, NULL, _("Key? "));
|
2018-05-10 23:29:13 +00:00
|
|
|
if(++counter >= 3){
|
2018-09-21 20:48:13 +00:00
|
|
|
pam_syslog(pamh, LOG_NOTICE, _("Couldn't identify any key after 3 tries."));
|
2018-05-10 23:29:13 +00:00
|
|
|
return (PAM_MAXTRIES);
|
|
|
|
}
|
2018-03-31 23:53:41 +00:00
|
|
|
}
|
2018-05-10 23:29:13 +00:00
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
|
|
|
|
if(access(allowed, F_OK) != -1)
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
return (PAM_SUCCESS);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
if(access(rejected, F_OK) != -1)
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
return reject(serious_dev, bSerious, bReboot, bPoweroff);
|
|
|
|
#else
|
|
|
|
return 99;
|
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
return (PAM_MAXTRIES);
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
2018-04-01 19:32:15 +00:00
|
|
|
|
2018-03-31 23:53:41 +00:00
|
|
|
}
|