7 /* set effective user and group attributes
9 /* #include <set_eugid.h>
11 /* void set_eugid(euid, egid)
15 /* void SAVE_AND_SET_EUGID(uid, gid)
19 /* void RESTORE_SAVED_EUGID()
21 /* set_eugid() sets the effective user and group process attributes
22 /* and updates the process group access list to be just the specified
23 /* effective group id.
25 /* SAVE_AND_SET_EUGID() opens a block that executes with the
26 /* specified privilege. RESTORE_SAVED_EUGID() closes the block.
28 /* All system call errors are fatal.
30 /* seteuid(2), setegid(2), setgroups(2)
34 /* The Secure Mailer license must be distributed with this software.
37 /* IBM T.J. Watson Research
39 /* Yorktown Heights, NY 10598, USA
49 /* Utility library. */
52 #include "set_eugid.h"
54 /* set_eugid - set effective user and group attributes */
56 void set_eugid(uid_t euid
, gid_t egid
)
58 int saved_errno
= errno
;
62 msg_fatal("set_eugid: seteuid(0): %m");
63 if (setegid(egid
) < 0)
64 msg_fatal("set_eugid: setegid(%ld): %m", (long) egid
);
65 if (setgroups(1, &egid
) < 0)
66 msg_fatal("set_eugid: setgroups(%ld): %m", (long) egid
);
67 if (euid
!= 0 && seteuid(euid
) < 0)
68 msg_fatal("set_eugid: seteuid(%ld): %m", (long) euid
);
70 msg_info("set_eugid: euid %ld egid %ld", (long) euid
, (long) egid
);