summaryrefslogtreecommitdiff
path: root/lib/libc/compat-43
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-10-30 20:15:30 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-10-30 20:15:30 +0000
commit8b855eebd1cada447595924e5d32c1c859e07ff2 (patch)
treefd45309c752ff4f14c2a81b5993db10012f1433f /lib/libc/compat-43
parent60b14187d21c7733684258d7f3443339972d610f (diff)
Add [gs]etres[ug]id(2) syscall to libc and use it in emulating some 4.3BSD
functions.
Diffstat (limited to 'lib/libc/compat-43')
-rw-r--r--lib/libc/compat-43/Makefile.inc7
-rw-r--r--lib/libc/compat-43/setregid.c27
-rw-r--r--lib/libc/compat-43/setreuid.c27
-rw-r--r--lib/libc/compat-43/setrgid.c6
-rw-r--r--lib/libc/compat-43/setruid.c6
5 files changed, 49 insertions, 24 deletions
diff --git a/lib/libc/compat-43/Makefile.inc b/lib/libc/compat-43/Makefile.inc
index 58227126664..1bf6ec18537 100644
--- a/lib/libc/compat-43/Makefile.inc
+++ b/lib/libc/compat-43/Makefile.inc
@@ -1,11 +1,10 @@
-# $OpenBSD: Makefile.inc,v 1.4 2000/03/28 22:43:34 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2002/10/30 20:15:29 millert Exp $
# compat-43 sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/compat-43 ${LIBCSRCDIR}/compat-43
-SRCS+= __setreuid.c __setregid.c creat.c getdtablesize.c gethostid.c \
- getwd.c killpg.c sethostid.c setpgrp.c setregid.c setreuid.c \
- setrgid.c setruid.c sigcompat.c
+SRCS+= creat.c getdtablesize.c gethostid.c getwd.c killpg.c sethostid.c \
+ setpgrp.c setregid.c setreuid.c setrgid.c setruid.c sigcompat.c
MAN+= creat.3 getdtablesize.3 gethostid.3 killpg.3 setregid.3 setreuid.3 \
setruid.3 sigblock.3 sigpause.3 sigsetmask.3 sigvec.3
diff --git a/lib/libc/compat-43/setregid.c b/lib/libc/compat-43/setregid.c
index ee25b1ac0b3..084b049a369 100644
--- a/lib/libc/compat-43/setregid.c
+++ b/lib/libc/compat-43/setregid.c
@@ -32,21 +32,36 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: setregid.c,v 1.4 2002/02/16 21:27:21 millert Exp $";
+static char *rcsid = "$OpenBSD: setregid.c,v 1.5 2002/10/30 20:15:29 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <unistd.h>
-extern int __setregid(gid_t, gid_t);
-
#ifndef NO_WARN_REFERENCES
__warn_references(setregid, "warning: this program uses setregid(), which is deprecated.");
#endif
int
-setregid(rgid, egid)
- int rgid, egid;
+setregid(gid_t rgid, gid_t egid)
{
- return (__setregid(rgid, egid));
+ int error;
+ gid_t sgid, cur_rgid, cur_egid, cur_sgid;
+
+ if (error == (getresgid(&cur_rgid, &cur_egid, &cur_sgid)) != 0)
+ return (error);
+
+ /*
+ * The saved gid presents a bit of a dilemma, as it did not
+ * appear in 4.3BSD. We only set the saved gid when the real
+ * gid is specified and either its value would change, or,
+ * where the saved and effective gids are different.
+ */
+ if (rgid != (gid_t)-1 && (rgid != cur_rgid ||
+ cur_sgid != (egid != (gid_t)-1 ? egid : cur_egid)))
+ sgid = rgid;
+ else
+ sgid = (gid_t)-1;
+
+ return (setresgid(rgid, egid, sgid));
}
diff --git a/lib/libc/compat-43/setreuid.c b/lib/libc/compat-43/setreuid.c
index 7b48b2b0d15..5da47c8e1f3 100644
--- a/lib/libc/compat-43/setreuid.c
+++ b/lib/libc/compat-43/setreuid.c
@@ -32,19 +32,34 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: setreuid.c,v 1.5 2002/02/16 21:27:21 millert Exp $";
+static char *rcsid = "$OpenBSD: setreuid.c,v 1.6 2002/10/30 20:15:29 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <unistd.h>
-extern int __setreuid(uid_t, uid_t);
-
__warn_references(setreuid, "warning: this program uses setreuid(), which is deprecated.");
int
-setreuid(ruid, euid)
- int ruid, euid;
+setreuid(uid_t ruid, uid_t euid)
{
- return (__setreuid(ruid, euid));
+ int error;
+ uid_t suid, cur_ruid, cur_euid, cur_suid;
+
+ if (error == (getresuid(&cur_ruid, &cur_euid, &cur_suid)) != 0)
+ return (error);
+
+ /*
+ * The saved uid presents a bit of a dilemma, as it did not
+ * appear in 4.3BSD. We only set the saved uid when the real
+ * uid is specified and either its value would change, or,
+ * where the saved and effective uids are different.
+ */
+ if (ruid != (uid_t)-1 && (ruid != cur_ruid ||
+ cur_suid != (euid != (uid_t)-1 ? euid : cur_euid)))
+ suid = ruid;
+ else
+ suid = (uid_t)-1;
+
+ return (setresuid(ruid, euid, suid));
}
diff --git a/lib/libc/compat-43/setrgid.c b/lib/libc/compat-43/setrgid.c
index 1ce12ce86ac..a7829632010 100644
--- a/lib/libc/compat-43/setrgid.c
+++ b/lib/libc/compat-43/setrgid.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: setrgid.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
+static char *rcsid = "$OpenBSD: setrgid.c,v 1.9 2002/10/30 20:15:29 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -40,10 +40,8 @@ static char *rcsid = "$OpenBSD: setrgid.c,v 1.8 2002/02/19 19:39:36 millert Exp
__warn_references(setrgid, "warning: this program uses setrgid(), which is deprecated.");
-extern int __setregid(gid_t, gid_t);
-
int
setrgid(gid_t rgid)
{
- return (__setregid(rgid, (gid_t)-1));
+ return (setresgid(rgid, (gid_t)-1, rgid));
}
diff --git a/lib/libc/compat-43/setruid.c b/lib/libc/compat-43/setruid.c
index 78d7372e791..a99f5700d8f 100644
--- a/lib/libc/compat-43/setruid.c
+++ b/lib/libc/compat-43/setruid.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: setruid.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
+static char *rcsid = "$OpenBSD: setruid.c,v 1.9 2002/10/30 20:15:29 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -40,10 +40,8 @@ static char *rcsid = "$OpenBSD: setruid.c,v 1.8 2002/02/19 19:39:36 millert Exp
__warn_references(setruid, "warning: this program uses setruid(), which is deprecated.");
-extern int __setreuid(uid_t, uid_t);
-
int
setruid(uid_t ruid)
{
- return (__setreuid(ruid, (uid_t)-1));
+ return (setresuid(ruid, (uid_t)-1, ruid));
}