Merge pull request #49 from Bandie/master

Test suits with dirty autoconf
This commit is contained in:
Jordy Dickinson
2018-05-16 18:25:51 -04:00
committed by GitHub
10 changed files with 224 additions and 33 deletions

View File

@ -7,7 +7,7 @@ nobase_dist_cant_believe_its_not_man_DATA = \
fr/man8/pam_panic.8.gz
%.gz: %
{ sldr=$$(echo "$(securelibdir)" | $(SED) 's/\//\\\//g') ; bdr=$$(echo "$(bindir)" | $(SED) 's/\//\\\//g') ; $(SED) "s/__PAMPANICSO__/$$sldr\/pam_panic\\\\\&.so/; s/__PAMPANICPW__/$$bdr\/pam_panic\\\\\&.so/" $< >$<.tmp ; }
{ sldr=$$(echo "$(securelibdir)" | $(SED) 's/\//\\\//g') ; bdr=$$(echo "$(bindir)" | $(SED) 's/\//\\\//g') ; $(SED) "s/__PAMPANICSO__/$$sldr\/pam_panic\\\\\&.so/; s/__PAMPANICPW__/$$bdr\/pam_panic_pw/" $< >$<.tmp ; }
gzip -c $<.tmp >$@

View File

@ -17,20 +17,34 @@ LICENSE : GNU-GPLv3
int authDevice(pam_handle_t *pamh, char *allowed, char *rejected, char *serious_dev, int8_t bSerious, int8_t bReboot, int8_t bPoweroff){
int8_t counter = 0;
while(access(allowed, F_OK) == -1 && access(rejected, F_OK) == -1){
pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, NULL, ASK);
if(++counter >= 3){
pam_syslog(pamh, LOG_NOTICE, "Couldn't identify any keys. 3 tries.");
return (PAM_MAXTRIES);
#ifndef TEST
int8_t counter = 0;
while(access(allowed, F_OK) == -1 && access(rejected, F_OK) == -1){
pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, NULL, ASK);
if(++counter >= 3){
pam_syslog(pamh, LOG_NOTICE, "Couldn't identify any keys. 3 tries.");
return (PAM_MAXTRIES);
}
}
}
#endif
if(access(allowed, F_OK) != -1)
return (PAM_SUCCESS);
#ifndef TEST
return (PAM_SUCCESS);
#else
return 0;
#endif
if(access(rejected, F_OK) != -1)
return reject(serious_dev, bSerious, bReboot, bPoweroff);
#ifndef TEST
return reject(serious_dev, bSerious, bReboot, bPoweroff);
#else
return 99;
#endif
return (PAM_MAXTRIES);
#ifndef TEST
return (PAM_MAXTRIES);
#else
return 1;
#endif
}

View File

@ -18,17 +18,21 @@ LICENSE : GNU-GPLv3
#include "pam_panic_password.h"
#include "pam_panic_reject.h"
#define MSG_NOFILE "ALERT for password option: No password file detected."
#define MSG_ERROPEN "ERROR: Couldn't open password file."
#define MSG_CORRUPT "CRITICAL: Password file is corrupt!"
int readPassword(pam_handle_t *pamh, char pw[2][99]){
// Open file
if(access(PPASSFILE, F_OK) == -1){
pam_syslog(pamh, LOG_ALERT, "ALERT for password option: No password file detected.");
pam_syslog(pamh, LOG_ALERT, MSG_NOFILE);
return 2;
}
FILE *f = fopen(PPASSFILE, "r");
if(f == NULL){
pam_syslog(pamh, LOG_ALERT, "ERROR: Couldn't open file.");
pam_syslog(pamh, LOG_ALERT, MSG_ERROPEN);
return 1;
}
@ -40,7 +44,7 @@ int readPassword(pam_handle_t *pamh, char pw[2][99]){
fclose(f);
if(nread != 198){
pam_syslog(pamh, LOG_CRIT, "CRITICAL: Password file is corrupt!");
pam_syslog(pamh, LOG_CRIT, MSG_CORRUPT);
return 3;
}
@ -103,5 +107,6 @@ int authPassword(pam_handle_t *pamh, char *serious_dev, int8_t bSerious, int8_t
if(!strcmp(pwpanic, pw[1])){
return reject(serious_dev, bSerious, bReboot, bPoweroff);
}
return (PAM_AUTH_ERR);
}

View File

@ -8,35 +8,56 @@ LICENSE : GNU-GPLv3
#include <stdint.h>
#include <unistd.h>
#include <security/pam_ext.h>
#ifdef TEST
#include <stdio.h>
#else
#include <security/pam_ext.h>
#endif
#include <sys/wait.h>
#include "config.h"
#include "pam_panic_reject.h"
int reject(char *serious_dev, int8_t bSerious, int8_t bReboot, int8_t bPoweroff){
if(bSerious){
int ser_stat;
int yes[2];
pipe(yes);
if(fork() == 0){
close(yes[1]);
dup2(yes[0], 0);
#ifndef TEST
int ser_stat;
int yes[2];
pipe(yes);
if(fork() == 0){
close(yes[1]);
dup2(yes[0], 0);
execlp(CRYPTSETUP, CRYPTSETUP, "luksErase", serious_dev, NULL);
}else {
close(yes[0]);
write(yes[1], "YES\n", 4);
close(yes[1]);
execlp(CRYPTSETUP, CRYPTSETUP, "luksErase", serious_dev, NULL);
}else {
close(yes[0]);
write(yes[1], "YES\n", 4);
close(yes[1]);
wait(&ser_stat);
}
wait(&ser_stat);
}
#else
return 0;
#endif
}
if(bReboot)
execlp(REBOOT, REBOOT, NULL);
#ifndef TEST
execlp(REBOOT, REBOOT, NULL);
#else
return 1;
#endif
if(bPoweroff)
execlp(POWEROFF, POWEROFF, NULL);
#ifndef TEST
execlp(POWEROFF, POWEROFF, NULL);
#else
return 2;
#endif
return (PAM_MAXTRIES);
#ifndef TEST
return (PAM_MAXTRIES);
#else
return 3;
#endif
}