/* FILENAME : grub2-se-verifyserv.c DESCRIPTION : Service which touches a file to VRFFILE if the return code of PROGRAM is STATUS_OK. AUTHOR : Bandie DATE : 2018-03-17T20:31:48+01:00 LICENSE : GNU-GPLv3 */ #include #include #include #include #include #include #include #include #define VRFFILE "/verified" #define SLEEP 20 #define PROGRAM "/usr/bin/grub2-verify" #define STATUS_OK 0 void help(){ printf("grub2-se-verifyserv [ -v | --verbose ]\n\n" "It checks if GRUB2 is verified using %s. If it is \"%s\" will be touched as file. " "If not it will be erased.\n\n" "The purpose is to integrate it with i3status; " "you can then see if could get locked out after a reboot/poweroff.\n\n" "i3status integration\n" "====================\n" "You may want to copy paste the following into your i3status.conf:\n\n" "order += \"path_exists GRUB2_signed\"\n" "[...]\n[...]\n" "path_exist GRUB2_signed {\n" "\tpath = \"%s\"\n" "}\n\n", PROGRAM, VRFFILE, VRFFILE); } void exec_failed(){ fprintf(stderr, "ERROR: It is not possible to execute %s: ", PROGRAM); if(access(PROGRAM, F_OK)) fprintf(stderr, "It does not exist (in your PATH variable).\n"); else fprintf(stderr, "Access denied. (Are you root?)\n"); if(access(VRFFILE, F_OK) != -1) unlink(VRFFILE); exit(EXIT_FAILURE); } void sig_handler(int signo){ if(signo == SIGTERM || signo == SIGINT){ // Unverify if(access(VRFFILE, F_OK) != -1) //File exists? unlink(VRFFILE); exit(0); } } int main(int argc, char *argv[]){ int verbose = 0; int statval; // Argument handling for(int i=0; i