diff --git a/rdo.c b/rdo.c index 26f2bdc..1b463c3 100644 --- a/rdo.c +++ b/rdo.c @@ -68,7 +68,7 @@ void runprog(char** program_argv) { int main(int argc, char** argv) { char groupname[64], wrong_pw_sleep[64], session_ttl[64], password[128]; - unsigned int sleep_us, tries, ts_ttl; + int sleep_us, tries, ts_ttl; int read_pw_from_stdin = 0; if (argc > 1) diff --git a/sessions.h b/sessions.h index 5f2d0d0..63908cf 100644 --- a/sessions.h +++ b/sessions.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -77,12 +78,19 @@ int ensuredir() { return 0; } -void setsession(int pid, unsigned int ts_ttl, int ruid) { +void setsession(int pid, int ts_ttl, int ruid) { + if (ts_ttl <= 0) + return; + +#ifdef TIOCSETVERAUTH + int ttyfd = open("/dev/tty", O_RDWR); + ioctl(ttyfd, TIOCSETVERAUTH, &ts_ttl); + close(ttyfd); + +#else unsigned long long startts; char path[1024], ts_str[32]; - if (ts_ttl == 0) - return; if (ensuredir() < 0 || getpstartts(pid, &startts) < 0) return; @@ -104,17 +112,25 @@ void setsession(int pid, unsigned int ts_ttl, int ruid) { } close(fd); +#endif return; } -int getsession(int pid, unsigned int ts_ttl, int ruid) { +int getsession(int pid, int ts_ttl, int ruid) { + if (ts_ttl <= 0) + return -1; + +#ifdef TIOCCHKVERAUTH + int ttyfd = open("/dev/tty", O_RDWR); + int ret = ioctl(ttyfd, TIOCCHKVERAUTH); + close(ttyfd); + return ret; + +#else unsigned long long startts, current; char path[1024], ts_str[32]; - if (ts_ttl == 0) - return -1; - if (ensuredir() < 0 || getpstartts(pid, &startts) < 0) return -1; @@ -138,10 +154,11 @@ int getsession(int pid, unsigned int ts_ttl, int ruid) { startts = strtoull(ts_str, NULL, 10); current = time(NULL); - if (current - startts > ts_ttl) { + if (current - startts > (unsigned int)ts_ttl) { unlink(path); return -1; } return 0; +#endif }