From owner-svn-src-all@freebsd.org Tue Sep 10 04:21:50 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3A218EFB25; Tue, 10 Sep 2019 04:21:50 +0000 (UTC) (envelope-from glebius@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46SBgf0mT1z3MhM; Tue, 10 Sep 2019 04:21:50 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D8EC920A07; Tue, 10 Sep 2019 04:21:49 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x8A4Lnos074512; Tue, 10 Sep 2019 04:21:49 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8A4LnQv074510; Tue, 10 Sep 2019 04:21:49 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201909100421.x8A4LnQv074510@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Tue, 10 Sep 2019 04:21:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352116 - head/usr.bin/calendar X-SVN-Group: head X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: head/usr.bin/calendar X-SVN-Commit-Revision: 352116 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Sep 2019 04:21:50 -0000 Author: glebius Date: Tue Sep 10 04:21:48 2019 New Revision: 352116 URL: https://svnweb.freebsd.org/changeset/base/352116 Log: Fix 'calendar -a' in several ways. o Do not run any iconv() processing in -a. The locale of root user is not what is desired by most of the users who receive their calendar mail. Just assume that users store their calendars in a format that is readable to them. This fixes regression from r344340. o fork() and setusercontext(LOGIN_SETALL) for every user. This makes LANG set inside a calendar file mostly excessive, as we will pick up user's login class LANG. o This also executes complex function cal() that parses user owned files with appropriate user privileges. Previously it was run with privileges dropped only temporary for execution of cal(), and fully dropped only before invoking sendmail (see r22473). Reviewed by: bapt (older version of patch) Modified: head/usr.bin/calendar/Makefile head/usr.bin/calendar/calendar.c head/usr.bin/calendar/io.c Modified: head/usr.bin/calendar/Makefile ============================================================================== --- head/usr.bin/calendar/Makefile Tue Sep 10 04:01:41 2019 (r352115) +++ head/usr.bin/calendar/Makefile Tue Sep 10 04:21:48 2019 (r352116) @@ -6,7 +6,7 @@ PROG= calendar SRCS= calendar.c locale.c events.c dates.c parsedata.c io.c day.c \ ostern.c paskha.c pom.c sunpos.c -LIBADD= m +LIBADD= m util INTER= de_AT.ISO_8859-15 de_DE.ISO8859-1 fr_FR.ISO8859-1 \ hr_HR.ISO8859-2 hu_HU.ISO8859-2 pt_BR.ISO8859-1 \ pt_BR.UTF-8 ru_RU.KOI8-R ru_RU.UTF-8 uk_UA.KOI8-U Modified: head/usr.bin/calendar/calendar.c ============================================================================== --- head/usr.bin/calendar/calendar.c Tue Sep 10 04:01:41 2019 (r352115) +++ head/usr.bin/calendar/calendar.c Tue Sep 10 04:21:48 2019 (r352116) @@ -44,9 +44,11 @@ static char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) #include __FBSDID("$FreeBSD$"); +#include #include #include #include +#include #include #include #include @@ -68,7 +70,7 @@ static time_t f_time = 0; double UTCOffset = UTCOFFSET_NOTSET; int EastLongitude = LONGITUDE_NOTSET; #ifdef WITH_ICONV -const char *outputEncoding; +const char *outputEncoding = NULL; #endif static void usage(void) __dead2; @@ -84,12 +86,6 @@ main(int argc, char *argv[]) struct tm tp1, tp2; (void)setlocale(LC_ALL, ""); -#ifdef WITH_ICONV - /* save the information about the encoding used in the terminal */ - outputEncoding = strdup(nl_langinfo(CODESET)); - if (outputEncoding == NULL) - errx(1, "cannot allocate memory"); -#endif while ((ch = getopt(argc, argv, "-A:aB:D:dF:f:l:t:U:W:?")) != -1) switch (ch) { @@ -218,15 +214,33 @@ main(int argc, char *argv[]) if (doall) while ((pw = getpwent()) != NULL) { - (void)setegid(pw->pw_gid); - (void)initgroups(pw->pw_name, pw->pw_gid); - (void)seteuid(pw->pw_uid); - if (!chdir(pw->pw_dir)) + pid_t pid; + + if (chdir(pw->pw_dir) == -1) + continue; + pid = fork(); + if (pid < 0) + err(1, "fork"); + if (pid == 0) { + login_cap_t *lc; + + lc = login_getpwclass(pw); + if (setusercontext(lc, pw, pw->pw_uid, + LOGIN_SETALL) != 0) + errx(1, "setusercontext"); cal(); - (void)seteuid(0); + exit(0); + } } - else + else { +#ifdef WITH_ICONV + /* Save the information about the encoding used in the terminal. */ + outputEncoding = strdup(nl_langinfo(CODESET)); + if (outputEncoding == NULL) + errx(1, "cannot allocate memory"); +#endif cal(); + } exit(0); } Modified: head/usr.bin/calendar/io.c ============================================================================== --- head/usr.bin/calendar/io.c Tue Sep 10 04:01:41 2019 (r352115) +++ head/usr.bin/calendar/io.c Tue Sep 10 04:21:48 2019 (r352116) @@ -290,16 +290,24 @@ cal_parse(FILE *in, FILE *out) if (buf[0] == '\0') continue; - /* Parse special definitions: LANG, Easter, Paskha etc */ + /* + * Setting LANG in user's calendar was an old workaround + * for 'calendar -a' being run with C locale to properly + * print user's calendars in their native languages. + * Now that 'calendar -a' does fork with setusercontext(), + * and does not run iconv(), this variable has little use. + */ if (strncmp(buf, "LANG=", 5) == 0) { (void)setlocale(LC_ALL, buf + 5); d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); #ifdef WITH_ICONV - set_new_encoding(); + if (!doall) + set_new_encoding(); #endif setnnames(); continue; } + /* Parse special definitions: Easter, Paskha etc */ REPLACE("Easter=", 7, neaster); REPLACE("Paskha=", 7, npaskha); REPLACE("ChineseNewYear=", 15, ncny); @@ -445,7 +453,6 @@ opencalout(void) void closecal(FILE *fp) { - uid_t uid; struct stat sbuf; int nread, pdes[2], status; char buf[1024]; @@ -470,19 +477,6 @@ closecal(FILE *fp) (void)close(pdes[0]); } (void)close(pdes[1]); - uid = geteuid(); - if (setuid(getuid()) < 0) { - warnx("setuid failed"); - _exit(1); - } - if (setgid(getegid()) < 0) { - warnx("setgid failed"); - _exit(1); - } - if (setuid(uid) < 0) { - warnx("setuid failed"); - _exit(1); - } execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F", "\"Reminder Service\"", (char *)NULL); warn(_PATH_SENDMAIL);