2018-04-01 00:09:00 +00:00
|
|
|
/*
|
|
|
|
FILENAME : pam_panic_reject.c
|
|
|
|
DESCRIPTION : Panic function
|
|
|
|
AUTHOR : Bandie
|
|
|
|
DATE : 2018-03-27T02:34:08+02:00
|
|
|
|
LICENSE : GNU-GPLv3
|
|
|
|
*/
|
|
|
|
|
2018-09-28 19:00:16 +00:00
|
|
|
#include "pam_panic_reject.h"
|
2018-04-01 19:32:15 +00:00
|
|
|
#include <unistd.h>
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifdef TEST
|
|
|
|
#include <stdio.h>
|
|
|
|
#else
|
|
|
|
#include <security/pam_ext.h>
|
|
|
|
#endif
|
2018-04-01 19:32:15 +00:00
|
|
|
#include <sys/wait.h>
|
2018-03-31 23:53:41 +00:00
|
|
|
|
|
|
|
int reject(char *serious_dev, int8_t bSerious, int8_t bReboot, int8_t bPoweroff){
|
|
|
|
if(bSerious){
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
int ser_stat;
|
|
|
|
int yes[2];
|
|
|
|
pipe(yes);
|
|
|
|
if(fork() == 0){
|
|
|
|
close(yes[1]);
|
|
|
|
dup2(yes[0], 0);
|
2018-03-31 23:53:41 +00:00
|
|
|
|
2018-05-10 23:29:13 +00:00
|
|
|
execlp(CRYPTSETUP, CRYPTSETUP, "luksErase", serious_dev, NULL);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
close(yes[0]);
|
|
|
|
write(yes[1], "YES\n", 4);
|
|
|
|
close(yes[1]);
|
2018-03-31 23:53:41 +00:00
|
|
|
|
2018-05-10 23:29:13 +00:00
|
|
|
wait(&ser_stat);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(bReboot)
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
execlp(REBOOT, REBOOT, NULL);
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
if(bPoweroff)
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
execlp(POWEROFF, POWEROFF, NULL);
|
|
|
|
#else
|
|
|
|
return 2;
|
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
|
2018-05-10 23:29:13 +00:00
|
|
|
#ifndef TEST
|
|
|
|
return (PAM_MAXTRIES);
|
|
|
|
#else
|
|
|
|
return 3;
|
|
|
|
#endif
|
2018-03-31 23:53:41 +00:00
|
|
|
}
|
|
|
|
|