=== modified file 'plugins.d/password-prompt.c' --- plugins.d/password-prompt.c 2010-09-26 18:32:58 +0000 +++ plugins.d/password-prompt.c 2010-11-05 18:30:07 +0000 @@ -22,22 +22,23 @@ * Contact the authors at . */ -#define _GNU_SOURCE /* getline() */ +#define _GNU_SOURCE /* getline(), asprintf() */ #include /* struct termios, tcsetattr(), TCSAFLUSH, tcgetattr(), ECHO */ #include /* struct termios, tcsetattr(), STDIN_FILENO, TCSAFLUSH, - tcgetattr(), ECHO */ + tcgetattr(), ECHO, readlink() */ #include /* sig_atomic_t, raise(), struct sigaction, sigemptyset(), sigaction(), sigaddset(), SIGINT, SIGQUIT, SIGHUP, SIGTERM, raise() */ #include /* NULL, size_t, ssize_t */ -#include /* ssize_t */ +#include /* ssize_t, struct dirent, pid_t, ssize_t */ #include /* EXIT_SUCCESS, EXIT_FAILURE, - getenv() */ + getenv(), free() */ +#include /* scandir(), alphasort() */ #include /* fprintf(), stderr, getline(), stdin, feof(), fputc() */ @@ -47,7 +48,9 @@ #include /* error() */ #include /* or, not */ #include /* bool, false, true */ -#include /* strlen, rindex */ +#include /* strtoumax() */ +#include /* struct stat, lstat() */ +#include /* strlen, rindex, memcmp */ #include /* struct argp_option, struct argp_state, struct argp, argp_parse(), error_t, @@ -62,6 +65,10 @@ const char *argp_program_version = "password-prompt " VERSION; const char *argp_program_bug_address = ""; +/* Needed for conflic resolution */ +const char plymouthd_path[] = "/sbin/plymouth"; + + static void termination_handler(int signum){ if(quit_now){ return; @@ -70,6 +77,74 @@ signal_received = signum; } +bool conflict_detection(void){ + + /* plymouth conflicts with password-promt since both want to control the + associated terminal. Password-prompt exit since plymouth perferms the same + functionallity. + */ + int is_plymouth(const struct dirent *proc_entry){ + int ret; + { + uintmax_t maxvalue; + char *tmp; + errno = 0; + maxvalue = strtoumax(proc_entry->d_name, &tmp, 10); + + if(errno != 0 or *tmp != '\0' + or maxvalue != (uintmax_t)((pid_t)maxvalue)){ + return 0; + } + } + char exe_target[sizeof(plymouthd_path)]; + char *exe_link; + ret = asprintf(&exe_link, "/proc/%s/exe", proc_entry->d_name); + if(ret == -1){ + error(0, errno, "asprintf"); + return 0; + } + + struct stat exe_stat; + ret = lstat(exe_link, &exe_stat); + if(ret == -1){ + free(exe_link); + if(errno != ENOENT){ + error(0, errno, "lstat"); + } + return 0; + } + + if(not S_ISLNK(exe_stat.st_mode) + or exe_stat.st_uid != 0 + or exe_stat.st_gid != 0){ + free(exe_link); + return 0; + } + + ssize_t sret = readlink(exe_link, exe_target, sizeof(exe_target)); + free(exe_link); + if((sret != (ssize_t)sizeof(plymouthd_path)-1) or + (memcmp(plymouthd_path, exe_target, + sizeof(plymouthd_path)-1) != 0)){ + return 0; + } + return 1; + } + + struct dirent **direntries; + int ret; + ret = scandir("/proc", &direntries, is_plymouth, alphasort); + if (ret == -1){ + error(1, errno, "scandir"); + } + if (ret < 0){ + return 1; + } else { + return 0; + } +} + + int main(int argc, char **argv){ ssize_t sret; int ret; @@ -151,6 +226,14 @@ if(debug){ fprintf(stderr, "Starting %s\n", argv[0]); } + + if (conflict_detection()){ + if(debug){ + fprintf(stderr, "Stopping %s because of conflict", argv[0]); + } + return EXIT_FAILURE; + } + if(debug){ fprintf(stderr, "Storing current terminal attributes\n"); } === modified file 'plugins.d/plymouth.c' --- plugins.d/plymouth.c 2010-11-16 17:58:49 +0000 +++ plugins.d/plymouth.c 2010-11-16 18:10:22 +0000 @@ -198,7 +198,7 @@ return 0; } } - char exe_target[sizeof(plymouth_path)]; + char exe_target[sizeof(plymouthd_path)]; char *exe_link; ret = asprintf(&exe_link, "/proc/%s/exe", proc_entry->d_name); if(ret == -1){ @@ -225,9 +225,9 @@ ssize_t sret = readlink(exe_link, exe_target, sizeof(exe_target)); free(exe_link); - if((sret != (ssize_t)sizeof(plymouth_path)-1) or - (memcmp(plymouth_path, exe_target, - sizeof(plymouth_path)-1) != 0)){ + if((sret != (ssize_t)sizeof(plymouthd_path)-1) or + (memcmp(plymouthd_path, exe_target, + sizeof(plymouthd_path)-1) != 0)){ return 0; } return 1; @@ -247,7 +247,15 @@ if(maxvalue == 0){ struct dirent **direntries; ret = scandir("/proc", &direntries, is_plymouth, alphasort); - sscanf(direntries[0]->d_name, "%" SCNuMAX, &maxvalue); + if (ret == -1){ + error(0, errno, "scandir"); + } + if (ret > 0){ + ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &maxvalue); + if (ret < 0){ + error(0, errno, "sscanf"); + } + } } pid_t pid; pid = (pid_t)maxvalue;