Remove getcpid
This function is used to get the child of the current login process of a user connected over ssh. However, it's actually completely unnecessary, as the login process, given in the utmp file, is all we need, yes, it's owned by root, but the daemon should be owned by root as well, so we can simply hang-up the login process, the exact same way we would do to a normal terminal session, the other users of sshd will not be affected.
This commit is contained in:
parent
256a972787
commit
696a3973f1
54
timeoutd.c
54
timeoutd.c
|
@ -101,7 +101,6 @@ int chk_ssh(pid_t pid); /* seppy: check if user is logged in via ssh (we
|
|||
char *getusr(pid_t pid); /*seppy: get the owner of a running process */
|
||||
void segfault(); /* seppy: catch segfault and log them */
|
||||
int chk_xterm(); /* seppy: is it a xterm? */
|
||||
pid_t getcpid(); /* seppy: get the child's pid. Needed for ssh */
|
||||
|
||||
#ifdef TIMEOUTDX11
|
||||
Time get_xidle(); /* seppy: how long is user idle? (user,display) */
|
||||
|
@ -953,7 +952,6 @@ char *dev;
|
|||
char *host;
|
||||
{
|
||||
int tty;
|
||||
pid_t cpid;
|
||||
|
||||
if (chk_xsession(dev, host) && !chk_xterm(dev, host)) {
|
||||
killit_xsession(utmpp->ut_pid, user, host);
|
||||
|
@ -969,18 +967,14 @@ char *host;
|
|||
/* check if the pid is sshd. If so, get PID of the child process (another ssh, owned by the user).
|
||||
Test reverse if this child process is also ssh and owned by the user we want to log out.
|
||||
(because we don't want to slay another user ;) */
|
||||
cpid = getcpid(pid);
|
||||
#ifdef DEBUG
|
||||
syslog(LOG_NOTICE, "I am at killit() pid=%d user=%s child=%d line %d", pid, user, cpid,
|
||||
__LINE__);
|
||||
syslog(LOG_NOTICE, "I am at killit() pid=%d user=%s line %d", pid, user, __LINE__);
|
||||
#endif
|
||||
|
||||
if (chk_ssh(pid) && chk_ssh(cpid) && !strcmp(getusr(cpid), user)) {
|
||||
if (chk_ssh(pid)) {
|
||||
#ifdef DEBUG
|
||||
syslog(LOG_NOTICE, "User %s (pid:%d, cpid:%d) logged in via ssh from %s.", user, pid, cpid,
|
||||
host);
|
||||
syslog(LOG_NOTICE, "User %s (pid:%d) logged in via ssh from %s.", user, pid, host);
|
||||
#endif
|
||||
pid = cpid;
|
||||
}
|
||||
|
||||
logoff_msg(tty);
|
||||
|
@ -1238,45 +1232,3 @@ char *display;
|
|||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* seppy; getchild()
|
||||
returns the pid of the first child-process found.
|
||||
- 1 if a error occured,
|
||||
- 0 if none found
|
||||
|
||||
We need this because utmp returns a process owned by
|
||||
root when a user is connected via ssh. If we kill its
|
||||
child (owned by the user) he/she gets logged off */
|
||||
pid_t getcpid(ppid)
|
||||
pid_t ppid;
|
||||
{
|
||||
DIR *proc;
|
||||
FILE *proc_file;
|
||||
struct dirent *cont;
|
||||
char akt_pid[99];
|
||||
char path[512];
|
||||
|
||||
proc = opendir("/proc/");
|
||||
if (proc == NULL) {
|
||||
printf("error opening directory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((cont = readdir(proc)) != NULL) {
|
||||
if (cont->d_type == DT_DIR && isdigit(cont->d_name[0])) { /* check only PIDs */
|
||||
sprintf(path, "/proc/%s/status", cont->d_name);
|
||||
proc_file = fopen(path, "r");
|
||||
if (!proc_file)
|
||||
printf("error opening proc status file %s\n", path);
|
||||
|
||||
while (!fscanf(proc_file, "PPid: %s", akt_pid))
|
||||
fgets(akt_pid, 10, proc_file);
|
||||
|
||||
if (atoi(akt_pid) == ppid)
|
||||
return (pid_t) atoi(cont->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
return 0; /* no child found */
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue