uwrap: Add support for getresuid() and getresgid() glibc/syscall.
authorRobin Hack <hack.robin@gmail.com>
Tue, 21 Oct 2014 06:53:32 +0000 (08:53 +0200)
committerAndreas Schneider <asn@samba.org>
Wed, 7 Jan 2015 12:49:21 +0000 (13:49 +0100)
Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
ConfigureChecks.cmake
config.h.cmake
src/uid_wrapper.c

index e1eeadf7bde276d60c07db029f820732e91185f5..150d89b4dbe0ba0223ca8d0e90ca8f4f29679f14 100644 (file)
@@ -61,6 +61,8 @@ check_function_exists(snprintf HAVE_SNPRINTF)
 check_function_exists(seteuid HAVE_SETEUID)
 check_function_exists(setreuid HAVE_SETREUID)
 check_function_exists(setresuid HAVE_SETRESUID)
+check_function_exists(getresuid HAVE_GETRESUID)
+check_function_exists(getresgid HAVE_GETRESGID)
 
 check_function_exists(setegid HAVE_SETEGID)
 check_function_exists(setregid HAVE_SETREGID)
index e9294a9b21f9372ea059244a5f756017a673c1df..b862048c6acf07dd5dc35f996aaf0e63459e5e7a 100644 (file)
@@ -31,6 +31,9 @@
 /* Define to 1 if you have the `setresuid' function. */
 #cmakedefine HAVE_SETRESUID 1
 
+/* Define to 1 if you have the `getresuid' function. */
+#cmakedefine HAVE_GETRESUID 1
+
 /* Define to 1 if you have the `setegid' function. */
 #cmakedefine HAVE_SETEGID 1
 
@@ -40,6 +43,9 @@
 /* Define to 1 if you have the `setresgid' function. */
 #cmakedefine HAVE_SETRESGID 1
 
+/* Define to 1 if you have the `getresgid' function. */
+#cmakedefine HAVE_GETRESGID 1
+
 /* Define to 1 if you have the `setgroups' function. */
 #cmakedefine HAVE_SETGROUPS 1
 #cmakedefine HAVE_SETGROUPS_INT 1
index efc4407c7e238e734b6ec4fc771df009b5d89f34..cb7db5f5ccbe1c39ffd77b8d78739cc0f1154f10 100644 (file)
@@ -189,6 +189,9 @@ struct uwrap_libc_fns {
 #endif
 #ifdef HAVE_SETRESUID
        int (*_libc_setresuid)(uid_t ruid, uid_t euid, uid_t suid);
+#endif
+#ifdef HAVE_GETRESUID
+       int (*_libc_getresuid)(uid_t *ruid, uid_t *euid, uid_t *suid);
 #endif
        uid_t (*_libc_geteuid)(void);
 
@@ -202,6 +205,9 @@ struct uwrap_libc_fns {
 #endif
 #ifdef HAVE_SETRESGID
        int (*_libc_setresgid)(uid_t rgid, uid_t egid, uid_t sgid);
+#endif
+#ifdef HAVE_GETRESGID
+       int (*_libc_getresgid)(gid_t *rgid, gid_t *egid, gid_t *sgid);
 #endif
        gid_t (*_libc_getegid)(void);
        int (*_libc_getgroups)(int size, gid_t list[]);
@@ -413,6 +419,15 @@ static int libc_setresuid(uid_t ruid, uid_t euid, uid_t suid)
 }
 #endif
 
+#ifdef HAVE_GETRESUID
+static int libc_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
+{
+       uwrap_load_lib_function(UWRAP_LIBC, getresuid);
+
+       return uwrap.libc.fns._libc_getresuid(ruid, euid, suid);
+}
+#endif
+
 static uid_t libc_geteuid(void)
 {
        uwrap_load_lib_function(UWRAP_LIBC, geteuid);
@@ -461,6 +476,15 @@ static int libc_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
 }
 #endif
 
+#ifdef HAVE_GETRESGID
+static int libc_getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
+{
+       uwrap_load_lib_function(UWRAP_LIBC, setresgid);
+
+       return uwrap.libc.fns._libc_getresgid(rgid, egid, sgid);
+}
+#endif
+
 static gid_t libc_getegid(void)
 {
        uwrap_load_lib_function(UWRAP_LIBC, getegid);
@@ -720,6 +744,23 @@ bool uid_wrapper_enabled(void)
        return enabled;
 }
 
+#ifdef HAVE_GETRESUID
+static int uwrap_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
+{
+       struct uwrap_thread *id = uwrap_tls_id;
+
+       UWRAP_LOCK(uwrap_id);
+
+       *ruid = id->ruid;
+       *euid = id->euid;
+       *suid = id->suid;
+
+       UWRAP_UNLOCK(uwrap_id);
+
+       return 0;
+}
+#endif
+
 static int uwrap_setresuid_thread(uid_t ruid, uid_t euid, uid_t suid)
 {
        struct uwrap_thread *id = uwrap_tls_id;
@@ -762,6 +803,23 @@ static int uwrap_setresuid_thread(uid_t ruid, uid_t euid, uid_t suid)
        return 0;
 }
 
+#ifdef HAVE_GETRESGID
+static int uwrap_getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
+{
+       struct uwrap_thread *id = uwrap_tls_id;
+
+       UWRAP_LOCK(uwrap_id);
+
+       *rgid = id->rgid;
+       *egid = id->egid;
+       *sgid = id->sgid;
+
+       UWRAP_UNLOCK(uwrap_id);
+
+       return 0;
+}
+#endif
+
 static int uwrap_setresuid(uid_t ruid, uid_t euid, uid_t suid)
 {
        struct uwrap_thread *id;
@@ -867,6 +925,18 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid)
 }
 #endif
 
+#ifdef HAVE_GETRESUID
+int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
+{
+       if (!uid_wrapper_enabled()) {
+               return libc_getresuid(ruid, euid, suid);
+       }
+
+       uwrap_init();
+       return uwrap_getresuid(ruid, euid, suid);
+}
+#endif
+
 /*
  * GETUID
  */
@@ -1057,6 +1127,18 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
 }
 #endif
 
+#ifdef HAVE_GETRESGID
+int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
+{
+       if (!uid_wrapper_enabled()) {
+               return libc_getresgid(rgid, egid, sgid);
+       }
+
+       uwrap_init();
+       return uwrap_getresgid(rgid, egid, sgid);
+}
+#endif
+
 /*
  * GETGID
  */
@@ -1315,6 +1397,20 @@ static long int uwrap_syscall (long int sysno, va_list vp)
                        }
                        break;
 #endif /* SYS_setresgid */
+#ifdef SYS_getresgid
+               case SYS_getresgid:
+#ifdef HAVE_LINUX_32BIT_SYSCALLS
+               case SYS_getresgid32:
+#endif
+                       {
+                               gid_t *rgid = (gid_t *) va_arg(vp, gid_t *);
+                               gid_t *egid = (gid_t *) va_arg(vp, gid_t *);
+                               gid_t *sgid = (gid_t *) va_arg(vp, gid_t *);
+
+                               rc = uwrap_getresgid(rgid, egid, sgid);
+                       }
+                       break;
+#endif /* SYS_getresgid */
 
                /* uid */
                case SYS_getuid:
@@ -1370,7 +1466,20 @@ static long int uwrap_syscall (long int sysno, va_list vp)
                        }
                        break;
 #endif /* SYS_setresuid */
+#ifdef SYS_getresuid
+               case SYS_getresuid:
+#ifdef HAVE_LINUX_32BIT_SYSCALLS
+               case SYS_getresuid32:
+#endif
+                       {
+                               uid_t *ruid = (uid_t *) va_arg(vp, uid_t *);
+                               uid_t *euid = (uid_t *) va_arg(vp, uid_t *);
+                               uid_t *suid = (uid_t *) va_arg(vp, uid_t *);
 
+                               rc = uwrap_getresuid(ruid, euid, suid);
+                       }
+                       break;
+#endif /* SYS_getresuid */
                /* groups */
                case SYS_setgroups:
 #ifdef HAVE_LINUX_32BIT_SYSCALLS