summaryrefslogtreecommitdiff
path: root/lib/util/setid.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2012-07-02 10:22:10 -0700
committerJeremy Allison <jra@samba.org>2012-07-02 18:38:14 -0700
commitec9aae6251e7d6d1a073924b6e58908454001625 (patch)
tree3645906397a2815040d1f79b5f18d18c548fa57a /lib/util/setid.c
parent4b47e1b30d8a6676f807cd1198f3b4e949b313ba (diff)
downloadsamba-ec9aae6251e7d6d1a073924b6e58908454001625.tar.gz
samba-ec9aae6251e7d6d1a073924b6e58908454001625.tar.bz2
samba-ec9aae6251e7d6d1a073924b6e58908454001625.zip
Ensure we select the correct syscall numbers on a 32-bit Linux system.
Diffstat (limited to 'lib/util/setid.c')
-rw-r--r--lib/util/setid.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/util/setid.c b/lib/util/setid.c
index 885b8bf186..ed8615517c 100644
--- a/lib/util/setid.c
+++ b/lib/util/setid.c
@@ -109,13 +109,25 @@ int samba_setgroups(size_t setlen, const gid_t *gidset);
#if defined(HAVE_SYS_SYSCALL_H)
#include <sys/syscall.h>
#endif
+
+/* Ensure we can't compile in a mixed syscall setup. */
+#if !defined(USE_LINUX_32BIT_SYSCALLS)
+#if defined(SYS_setresuid32) || defined(SYS_setresgid32) || defined(SYS_setreuid32) || defined(SYS_setregid32) || defined(SYS_setuid32) || defined(SYS_setgid32) || defined(SYS_setgroups32)
+#error Mixture of 32-bit Linux system calls and 64-bit calls.
+#endif
+#endif
+
#endif
/* All the setXX[ug]id functions and setgroups Samba uses. */
int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setresuid32, ruid, euid, suid);
+#else
return syscall(SYS_setresuid, ruid, euid, suid);
+#endif
#elif defined(HAVE_SETRESUID)
return setresuid(ruid, euid, suid);
#else
@@ -127,7 +139,11 @@ int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid)
int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setresgid32, rgid, egid, sgid);
+#else
return syscall(SYS_setresgid, rgid, egid, sgid);
+#endif
#elif defined(HAVE_SETRESGID)
return setresgid(rgid, egid, sgid);
#else
@@ -139,7 +155,11 @@ int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
int samba_setreuid(uid_t ruid, uid_t euid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setreuid32, ruid, euid);
+#else
return syscall(SYS_setreuid, ruid, euid);
+#endif
#elif defined(HAVE_SETREUID)
return setreuid(ruid, euid);
#else
@@ -151,7 +171,11 @@ int samba_setreuid(uid_t ruid, uid_t euid)
int samba_setregid(gid_t rgid, gid_t egid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setregid32, rgid, egid);
+#else
return syscall(SYS_setregid, rgid, egid);
+#endif
#elif defined(HAVE_SETREGID)
return setregid(rgid, egid);
#else
@@ -163,8 +187,13 @@ int samba_setregid(gid_t rgid, gid_t egid)
int samba_seteuid(uid_t euid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ /* seteuid is not a separate system call. */
+ return syscall(SYS_setresuid32, -1, euid, -1);
+#else
/* seteuid is not a separate system call. */
return syscall(SYS_setresuid, -1, euid, -1);
+#endif
#elif defined(HAVE_SETEUID)
return seteuid(euid);
#else
@@ -176,8 +205,13 @@ int samba_seteuid(uid_t euid)
int samba_setegid(gid_t egid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ /* setegid is not a separate system call. */
+ return syscall(SYS_setresgid32, -1, egid, -1);
+#else
/* setegid is not a separate system call. */
return syscall(SYS_setresgid, -1, egid, -1);
+#endif
#elif defined(HAVE_SETEGID)
return setegid(egid);
#else
@@ -189,7 +223,11 @@ int samba_setegid(gid_t egid)
int samba_setuid(uid_t uid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setuid32, uid);
+#else
return syscall(SYS_setuid, uid);
+#endif
#elif defined(HAVE_SETUID)
return setuid(uid);
#else
@@ -201,7 +239,11 @@ int samba_setuid(uid_t uid)
int samba_setgid(gid_t gid)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setgid32, gid);
+#else
return syscall(SYS_setgid, gid);
+#endif
#elif defined(HAVE_SETGID)
return setgid(gid);
#else
@@ -235,7 +277,11 @@ int samba_setgidx(int flags, gid_t gid)
int samba_setgroups(size_t setlen, const gid_t *gidset)
{
#if defined(USE_LINUX_THREAD_CREDENTIALS)
+#if defined(USE_LINUX_32BIT_SYSCALLS)
+ return syscall(SYS_setgroups32, setlen, gidset);
+#else
return syscall(SYS_setgroups, setlen, gidset);
+#endif
#elif defined(HAVE_SETGROUPS)
return setgroups(setlen, gidset);
#else