10 /* #include <open_as.h>
12 /* int open_as(path, flags, mode, euid, egid)
18 /* open_as() opens the named \fIpath\fR with the named \fIflags\fR
19 /* and \fImode\fR, and with the effective rights specified by \fIeuid\fR
20 /* and \fIegid\fR. A -1 result means the open failed.
22 /* Fatal error: no permission to change privilege level.
24 /* set_eugid(3) switch effective rights
28 /* The Secure Mailer license must be distributed with this software.
31 /* IBM T.J. Watson Research
33 /* Yorktown Heights, NY 10598, USA
42 /* Utility library. */
45 #include "set_eugid.h"
48 /* open_as - open file as user */
50 int open_as(const char *path
, int flags
, int mode
, uid_t euid
, gid_t egid
)
52 uid_t saved_euid
= geteuid();
53 gid_t saved_egid
= getegid();
57 * Switch to the target user privileges.
59 set_eugid(euid
, egid
);
64 fd
= open(path
, flags
, mode
);
67 * Restore saved privileges.
69 set_eugid(saved_euid
, saved_egid
);