]> bicyclesonthemoon.info Git - botm/git/commitdiff
correct SETUID handling
authorb <rowerynaksiezycu@gmail.com>
Sat, 12 Nov 2022 20:24:35 +0000 (20:24 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sat, 12 Nov 2022 20:24:35 +0000 (20:24 +0000)
exec.c
makefile

diff --git a/exec.c b/exec.c
index c747a98af7960fb0f3adacfc5a58f9a3e5edda4a..50940918959af5a3614e6fc100b681b1d5a92d22 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1,10 +1,20 @@
+// 12.11.2022
 #include <unistd.h>
+#include <errno.h>
 
 #define TARGET "###TARGET;"
 
 int main(int argc, char *argv[], char *envp[])
 {
+       uid_t euid;
+       gid_t egid;
        int r;
+       euid = geteuid();
+       egid = getegid();
+       if ((r = setreuid(euid, euid)))
+               return (r = errno);
+       if ((r = setregid(egid, egid)))
+               return (r = errno);
        r=execve(TARGET,argv,envp);
        return r;
 }
index f1a3a171d8593fc23390fc19715e764e74d5a34e..ec0c3abbd66ea0e0c60b62ed1e4d7b1cd46f6f2e 100644 (file)
--- a/makefile
+++ b/makefile
@@ -23,7 +23,7 @@ git-http-backend: git-http-backend.c
 
 cpbin: git-http-backend
        $(MKDIR) -p $(OD)
-       $(CP) git-http-backend $(OD)
+       $(CP) -p git-http-backend $(OD)
 
 rmbin:
        $rm -f $(OD)/git-http-backend