From nobody Mon Dec 02 19:57:26 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y2F1f71xrz5gLvd; Mon, 02 Dec 2024 19:57:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y2F1f6SXBz4rQx; Mon, 2 Dec 2024 19:57:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733169446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kdxPvf76/+9cRuzaIQgBthe0c4jPRyzirjW8J/iBs0M=; b=aif25XKv7QKsf6NJTzhcpHg8dT0fpp5I/cEGjYIoNASssr/jK8aWmynFaGYYow9Ss1Ux9F MXow/xSs+Pj/jKRAb34q3iVqeehgOQ0y+D4RkWwIuXMK9ZuEHjdhuVJXpOSYsBAxtOle1/ pImqp2uLqkqt1ahP7ZyBP5lFb0opMP9rdJx/hGaXDBJNYGvD8gc7sZXPjV/OqXcdPEtXIs glIEemWjxE5CmW3skQkytfJerRdIS01azTE1Mi5b6O6/Q34weh5BjhlWJTfdAh9E9zUENf hVco05t5kOHsqFGfwz9CBnOhIsYNtbLDPG2ZY7cPPNGRcUdPoCj1SLTH5L3E/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733169446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kdxPvf76/+9cRuzaIQgBthe0c4jPRyzirjW8J/iBs0M=; b=ZZrsTVJGbXebVJ3vfrOMDb3uB6io4TEvrEmkJHCxkpmZgaBW86/wK4O/QSJ3d5arh0P0G5 fcsd3byZkwulcHP7Rj8fJeA1CcmDzNE7t6uHvCmVzqXw8GJujNQ0tteLIOJ7wpVo2BX27x PrwCeTXi9d0bYinqmtIw5cqkENVfjShxDyT2Fr87auLCNFRHN15ZLk83T2TyHPogOwQm9N oTYRovUN2gwqyLncwB0bPEKOfXoXhpkZHFhyMKfklmQN/9MVlkg/rAF+1cwziH3v+P+hxj LwL2yXbsejc735787x6LtOCnt6zhLswDcB1+jOx30qacknWybbhybhDD3TSvTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733169446; a=rsa-sha256; cv=none; b=QxUlbkps3Ym3uiItoNXsf+zpVbWCi8KxaPpTBBcLECs+jiZVzkhJwHYzJnoQfkOdVEBThB j0VCO6aUocrie/WSBVpOAH7y95OWplVN/sAHNva/yCyaHohs9T14PjgetUfzuZQIUeTkaI xz+lBB1WI/Ldn/u5ZbXyl6yzXtXYHXFd5vYKr36A7KvRrX8nN38NhdtUWTbgd2IXAa5aIM 9BjEdjXmqD+pQ7vyPOWW75sVc+2k856IGM2wgEd3xPLuUM1yDMXw+n4P7wOpS2BCyqcIB1 RqEKEHswehme1nv9YCBzkOE4lX7I+NX468nr2QI9DFjiLB+9df7yFVTLOLluQg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Y2F1f5lktzrQ7; Mon, 2 Dec 2024 19:57:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4B2JvQ86061229; Mon, 2 Dec 2024 19:57:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B2JvQ4D061226; Mon, 2 Dec 2024 19:57:26 GMT (envelope-from git) Date: Mon, 2 Dec 2024 19:57:26 GMT Message-Id: <202412021957.4B2JvQ4D061226@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 91629228e3df - main - comsat: move uid/gid setting earlier List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 91629228e3df14997df12ffc6e7be6b9964e5463 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=91629228e3df14997df12ffc6e7be6b9964e5463 commit 91629228e3df14997df12ffc6e7be6b9964e5463 Author: Ed Maste AuthorDate: 2024-12-01 20:43:10 +0000 Commit: Ed Maste CommitDate: 2024-12-02 19:57:13 +0000 comsat: move uid/gid setting earlier It's good to reduce privilege as early as possible. Suggested by: jlduran Reviewed by: jlduran Obtained from: NetBSD Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47869 --- libexec/comsat/comsat.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c index e2aea1b709b6..d5d1eedeb5f3 100644 --- a/libexec/comsat/comsat.c +++ b/libexec/comsat/comsat.c @@ -59,7 +59,7 @@ static int debug = 0; static char hostname[MAXHOSTNAMELEN]; -static void jkfprintf(FILE *, char[], char[], off_t); +static void jkfprintf(FILE *, char[], off_t); static void mailfor(char *); static void notify(struct utmpx *, char[], off_t, int); static void reapchildren(int); @@ -147,6 +147,7 @@ notify(struct utmpx *utp, char file[], off_t offset, int folder) FILE *tp; struct stat stb; struct termios tio; + struct passwd *p; char tty[20]; const char *s = utp->ut_line; @@ -180,6 +181,14 @@ notify(struct utmpx *utp, char file[], off_t offset, int folder) } (void)tcgetattr(fileno(tp), &tio); cr = ((tio.c_oflag & (OPOST|ONLCR)) == (OPOST|ONLCR)) ? "\n" : "\n\r"; + + /* Set uid/gid/groups to user's in case mail drop is on nfs */ + if ((p = getpwnam(utp->ut_user)) == NULL || + initgroups(p->pw_name, p->pw_gid) == -1 || + setgid(p->pw_gid) == -1 || + setuid(p->pw_uid) == -1) + return; + switch (stb.st_mode & (S_IXUSR | S_IXGRP)) { case S_IXUSR: case (S_IXUSR | S_IXGRP): @@ -188,7 +197,7 @@ notify(struct utmpx *utp, char file[], off_t offset, int folder) cr, utp->ut_user, (int)sizeof(hostname), hostname, folder ? cr : "", folder ? "to " : "", folder ? file : "", cr, cr); - jkfprintf(tp, utp->ut_user, file, offset); + jkfprintf(tp, file, offset); break; case S_IXGRP: (void)fprintf(tp, "\007"); @@ -204,21 +213,13 @@ notify(struct utmpx *utp, char file[], off_t offset, int folder) } static void -jkfprintf(FILE *tp, char user[], char file[], off_t offset) +jkfprintf(FILE *tp, char file[], off_t offset) { unsigned char *cp, ch; FILE *fi; int linecnt, charcnt, inheader; - struct passwd *p; unsigned char line[BUFSIZ]; - /* Set uid/gid/groups to user's in case mail drop is on nfs */ - if ((p = getpwnam(user)) == NULL || - initgroups(p->pw_name, p->pw_gid) == -1 || - setgid(p->pw_gid) == -1 || - setuid(p->pw_uid) == -1) - return; - if ((fi = fopen(file, "r")) == NULL) return;