X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/9af3c5495821f33fc0bdd09375ff246120b6ca99..3b7ac02caeb878252361e602dc46e96104f773a9:/src/src/exim.c diff --git a/src/src/exim.c b/src/src/exim.c index 198e81d89..b6d926b50 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -628,10 +628,10 @@ if (euid == root_uid || euid != uid || egid != gid || igflag) DEBUG(D_uid) { int group_count, save_errno; - gid_t group_list[NGROUPS_MAX]; + gid_t group_list[EXIM_GROUPLIST_SIZE]; debug_printf("changed uid/gid: %s\n uid=%ld gid=%ld pid=%ld\n", msg, (long int)geteuid(), (long int)getegid(), (long int)getpid()); - group_count = getgroups(NGROUPS_MAX, group_list); + group_count = getgroups(nelem(group_list), group_list); save_errno = errno; debug_printf(" auxiliary group list:"); if (group_count > 0) @@ -1492,6 +1492,7 @@ int recipients_arg = argc; int sender_address_domain = 0; int test_retry_arg = -1; int test_rewrite_arg = -1; +gid_t original_egid; BOOL arg_queue_only = FALSE; BOOL bi_option = FALSE; BOOL checking = FALSE; @@ -1541,7 +1542,7 @@ struct passwd *pw; struct stat statbuf; pid_t passed_qr_pid = (pid_t)0; int passed_qr_pipe = -1; -gid_t group_list[NGROUPS_MAX]; +gid_t group_list[EXIM_GROUPLIST_SIZE]; /* For the -bI: flag */ enum commandline_info info_flag = CMDINFO_NONE; @@ -1818,6 +1819,7 @@ if ((namelen == 10 && Ustrcmp(argv[0], "newaliases") == 0) || normally be root, but in some esoteric environments it may not be. */ original_euid = geteuid(); +original_egid = getegid(); /* Get the real uid and gid. If the caller is root, force the effective uid/gid to be the same as the real ones. This makes a difference only if Exim is setuid @@ -3532,7 +3534,7 @@ check on the additional groups for the admin user privilege - can't do that till after reading the config, which might specify the exim gid. Therefore, save the group list here first. */ -if ((group_count = getgroups(NGROUPS_MAX, group_list)) < 0) +if ((group_count = getgroups(nelem(group_list), group_list)) < 0) exim_fail("exim: getgroups() failed: %s\n", strerror(errno)); /* There is a fundamental difference in some BSD systems in the matter of @@ -3546,6 +3548,11 @@ over a single group - the current group, which is always the first group in the list. Calling setgroups() with zero groups on a "different" system results in an error return. The following code should cope with both types of system. + Unfortunately, recent MacOS, which should be a FreeBSD, "helpfully" succeeds + the "setgroups() with zero groups" - and changes the egid. + Thanks to that we had to stash the original_egid above, for use below + in the call to exim_setugid(). + However, if this process isn't running as root, setgroups() can't be used since you have to be root to run it, even if throwing away groups. Not being root here happens only in some unusual configurations. We just ignore the @@ -3605,7 +3612,7 @@ the real uid to the effective so that subsequent re-execs of Exim are done by a privileged user. */ else - exim_setugid(geteuid(), getegid(), FALSE, US"forcing real = effective"); + exim_setugid(geteuid(), original_egid, FALSE, US"forcing real = effective"); /* If testing a filter, open the file(s) now, before wasting time doing other setups and reading the message. */