If there is no session or terminal group ID, pass the plugin a value of 0.

This behavior already matches what is documented in the sudo_plugin
manual for "sid" but the "tcpgid" entry needed to be updated.
This commit is contained in:
Todd C. Miller
2019-11-18 16:25:52 -07:00
parent d10220162d
commit 368e12b0f9
3 changed files with 12 additions and 19 deletions

View File

@@ -542,8 +542,7 @@ tcpgid=int
The ID of the foreground process group associated with the terminal The ID of the foreground process group associated with the terminal
device associated with the device associated with the
\fBsudo\fR \fBsudo\fR
process or \-1 if there is no process or 0 if there is no terminal present.
terminal present.
Only available starting with API version 1.2. Only available starting with API version 1.2.
.TP 6n .TP 6n
tty=string tty=string

View File

@@ -483,8 +483,7 @@ Only available starting with API version 1.2.
The ID of the foreground process group associated with the terminal The ID of the foreground process group associated with the terminal
device associated with the device associated with the
.Nm sudo .Nm sudo
process or \-1 if there is no process or 0 if there is no terminal present.
terminal present.
Only available starting with API version 1.2. Only available starting with API version 1.2.
.It tty=string .It tty=string
The path to the user's terminal device. The path to the user's terminal device.

View File

@@ -521,13 +521,14 @@ get_user_info(struct user_details *ud)
ud->pid = getpid(); ud->pid = getpid();
ud->ppid = getppid(); ud->ppid = getppid();
ud->pgid = getpgid(0); ud->pgid = getpgid(0);
ud->tcpgid = -1;
fd = open(_PATH_TTY, O_RDWR); fd = open(_PATH_TTY, O_RDWR);
if (fd != -1) { if (fd != -1) {
ud->tcpgid = tcgetpgrp(fd); if ((ud->tcpgid = tcgetpgrp(fd)) == -1)
ud->tcpgid = 0;
close(fd); close(fd);
} }
ud->sid = getsid(0); if ((ud->sid = getsid(0)) == -1)
ud->sid = 0;
ud->uid = getuid(); ud->uid = getuid();
ud->euid = geteuid(); ud->euid = geteuid();
@@ -560,18 +561,12 @@ get_user_info(struct user_details *ud)
goto oom; goto oom;
if (asprintf(&user_info[++i], "ppid=%d", (int)ud->ppid) == -1) if (asprintf(&user_info[++i], "ppid=%d", (int)ud->ppid) == -1)
goto oom; goto oom;
if (ud->pgid != -1) { if (asprintf(&user_info[++i], "pgid=%d", (int)ud->pgid) == -1)
if (asprintf(&user_info[++i], "pgid=%d", (int)ud->pgid) == -1) goto oom;
goto oom; if (asprintf(&user_info[++i], "tcpgid=%d", (int)ud->tcpgid) == -1)
} goto oom;
if (ud->tcpgid != -1) { if (asprintf(&user_info[++i], "sid=%d", (int)ud->sid) == -1)
if (asprintf(&user_info[++i], "tcpgid=%d", (int)ud->tcpgid) == -1) goto oom;
goto oom;
}
if (ud->sid != -1) {
if (asprintf(&user_info[++i], "sid=%d", (int)ud->sid) == -1)
goto oom;
}
if (asprintf(&user_info[++i], "uid=%u", (unsigned int)ud->uid) == -1) if (asprintf(&user_info[++i], "uid=%u", (unsigned int)ud->uid) == -1)
goto oom; goto oom;
if (asprintf(&user_info[++i], "euid=%u", (unsigned int)ud->euid) == -1) if (asprintf(&user_info[++i], "euid=%u", (unsigned int)ud->euid) == -1)