summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>1994-04-21 02:41:36 +0000
committerRoland McGrath <roland@redhat.com>1994-04-21 02:41:36 +0000
commiteb0dbf19930c2ebee0cb8502030092b0ec137c04 (patch)
tree9f88ed750405f6385b00d858cee33a4d4601b9c2 /misc.c
parent5ebd380d7a012997ab628f3d6a6d3b8637f8a777 (diff)
downloadmake-eb0dbf19930c2ebee0cb8502030092b0ec137c04.tar.gz
[HAVE_SETEUID]: Declare seteuid.
[HAVE_SETEGID]: Declare setegid. (make_access, user_access) [HAVE_SETEUID]: Use seteuid. [HAVE_SETEGID]: Use setegid.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/misc.c b/misc.c
index f5d45ed1..5a8327d1 100644
--- a/misc.c
+++ b/misc.c
@@ -494,12 +494,20 @@ dep_name (dep)
#ifndef HAVE_UNISTD_H
extern int getuid (), getgid (), geteuid (), getegid ();
extern int setuid (), setgid ();
+#ifdef HAVE_SETEUID
+extern int seteuid ();
+#else
#ifdef HAVE_SETREUID
extern int setreuid ();
#endif /* Have setreuid. */
+#endif /* Have seteuid. */
+#ifdef HAVE_SETEGID
+extern int setegid ();
+#else
#ifdef HAVE_SETREGID
extern int setregid ();
#endif /* Have setregid. */
+#endif /* Have setegid. */
#endif /* No <unistd.h>. */
/* Keep track of the user and group IDs for user- and make- access. */
@@ -565,6 +573,16 @@ user_access ()
We now want to set the effective user and group IDs to the real IDs,
which are the IDs of the process that exec'd make. */
+#ifdef HAVE_SETEUID
+
+ /* Modern systems have the seteuid/setegid calls which set only the
+ effective IDs, which is ideal. */
+
+ if (seteuid (user_uid) < 0)
+ pfatal_with_name ("user_access: seteuid");
+
+#else /* Not HAVE_SETEUID. */
+
#ifndef HAVE_SETREUID
/* System V has only the setuid/setgid calls to set user/group IDs.
@@ -578,7 +596,7 @@ user_access ()
if (setuid (user_uid) < 0)
pfatal_with_name ("user_access: setuid");
-#else
+#else /* HAVE_SETREUID. */
/* In 4BSD, the setreuid/setregid calls set both the real and effective IDs.
They may be set to themselves or each other. So you have two alternatives
@@ -590,8 +608,13 @@ user_access ()
if (setreuid (make_uid, user_uid) < 0)
pfatal_with_name ("user_access: setreuid");
-#endif
+#endif /* Not HAVE_SETREUID. */
+#endif /* HAVE_SETEUID. */
+#ifdef HAVE_SETEGID
+ if (setegid (user_gid) < 0)
+ pfatal_with_name ("user_access: setegid");
+#else
#ifndef HAVE_SETREGID
if (setgid (user_gid) < 0)
pfatal_with_name ("user_access: setgid");
@@ -599,6 +622,7 @@ user_access ()
if (setregid (make_gid, user_gid) < 0)
pfatal_with_name ("user_access: setregid");
#endif
+#endif
current_access = user;
@@ -622,6 +646,10 @@ make_access ()
/* See comments in user_access, above. */
+#ifdef HAVE_SETEUID
+ if (seteuid (make_uid) < 0)
+ pfatal_with_name ("make_access: seteuid");
+#else
#ifndef HAVE_SETREUID
if (setuid (make_uid) < 0)
pfatal_with_name ("make_access: setuid");
@@ -629,7 +657,12 @@ make_access ()
if (setreuid (user_uid, make_uid) < 0)
pfatal_with_name ("make_access: setreuid");
#endif
+#endif
+#ifdef HAVE_SETEGID
+ if (setegid (make_gid) < 0)
+ pfatal_with_name ("make_access: setegid");
+#else
#ifndef HAVE_SETREGID
if (setgid (make_gid) < 0)
pfatal_with_name ("make_access: setgid");
@@ -637,6 +670,7 @@ make_access ()
if (setregid (user_gid, make_gid) < 0)
pfatal_with_name ("make_access: setregid");
#endif
+#endif
current_access = make;