1
0
Fork 0
forked from soccera/rdo

Add support for TIOCSETVERAUTH ioctl

This commit is contained in:
sw1tchbl4d3 2023-02-04 10:32:21 +01:00
parent 6a34dbb90a
commit 44d44e86d1
2 changed files with 26 additions and 9 deletions

2
rdo.c
View file

@ -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)

View file

@ -4,6 +4,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <time.h>
@ -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
}