drop_setuid_root, when set to true, will detect
and try to drop getuid()==0. This is done by
recovering current effective UID to set->uid
if set->uid == -1, and then doing seteuid(0).
It will also drop out any other extra privileges,
such as extra groups not requested for.
is_root = geteuid() == 0;
+ if (!is_root &&
+ set->drop_setuid_root &&
+ getuid() == 0) {
+ /* recover current effective UID */
+ if (set->uid == (uid_t)-1)
+ set->uid = geteuid();
+ else
+ i_assert(set->uid > 0);
+ /* try to elevate to root */
+ if (seteuid(0) < 0)
+ i_fatal("seteuid(0) failed: %m");
+ is_root = TRUE;
+ }
+
/* set the primary/privileged group */
process_primary_gid = set->gid;
process_privileged_gid = set->privileged_gid;
/* Chroot directory */
const char *chroot_dir;
+
+ /* Set TRUE to attempt to drop any root privileges
+ FIXME: Reverse logic on v2.3 */
+ bool drop_setuid_root;
};
/* Initialize settings with values that don't change anything. */