[rt-commit] r164 - in /redwax-tool/trunk: ChangeLog redwax-tool.c

rt-commit at redwax.eu rt-commit at redwax.eu
Mon Nov 6 10:19:53 CET 2023


Author: minfrin at redwax.eu
Date: Mon Nov  6 10:19:51 2023
New Revision: 164

Log:
Complete error handling for seteuid() and setegid().

Modified:
    redwax-tool/trunk/ChangeLog
    redwax-tool/trunk/redwax-tool.c

Modified: redwax-tool/trunk/ChangeLog
==============================================================================
--- redwax-tool/trunk/ChangeLog	(original)
+++ redwax-tool/trunk/ChangeLog	Mon Nov  6 10:19:51 2023
@@ -1,5 +1,8 @@
 
 Changes with v0.9.4
+
+ *) Complete error handling for seteuid() and setegid().
+    [Graham Leggett]
 
  *) Use seteuid() and setegid() for temporarily switching
     users. [Graham Leggett]

Modified: redwax-tool/trunk/redwax-tool.c
==============================================================================
--- redwax-tool/trunk/redwax-tool.c	(original)
+++ redwax-tool/trunk/redwax-tool.c	Mon Nov  6 10:19:51 2023
@@ -1159,7 +1159,13 @@
 {
     struct passwd *pw;
 
-    seteuid(euid);
+    if (seteuid(euid)) {
+
+        redwax_print_error(r, "Error: could not restore original user: %s\n",
+                strerror(errno));
+
+        return apr_get_os_error();
+    }
 
     if (!user) {
         return APR_SUCCESS;
@@ -1171,18 +1177,19 @@
 
     if (pw) {
 
-        seteuid(pw->pw_uid);
-
-        if (errno) {
-            redwax_print_error(r, "Could not set the user to '%s': %s\n", user,
+        if (seteuid(pw->pw_uid)) {
+
+            redwax_print_error(r, "Error: could not set the user to '%s': %s\n", user,
                     strerror(errno));
-            return APR_EGENERAL;
+
+            return apr_get_os_error();
         }
 
     }
     else {
         redwax_print_error(r,
-                "User '%s' could not be found: %s\n", user, strerror(errno));
+                "Error: user '%s' could not be found.\n", user);
+
         return APR_EGENERAL;
     }
 
@@ -1194,6 +1201,14 @@
     struct group *gr;
 
     setegid(egid);
+
+    if (setegid(egid)) {
+
+        redwax_print_error(r, "Error: could not restore original group: %s\n",
+                strerror(errno));
+
+        return apr_get_os_error();
+    }
 
     if (!group) {
         return APR_SUCCESS;
@@ -1203,18 +1218,18 @@
 
     if (gr) {
 
-        setegid(gr->gr_gid);
-
-        if (errno) {
-            redwax_print_error(r, "Could not set the group to '%s': %s\n", group,
+        if (setegid(gr->gr_gid)) {
+
+            redwax_print_error(r, "Error: could not set the group to '%s': %s\n", group,
                     strerror(errno));
-            return APR_EGENERAL;
+
+            return apr_get_os_error();
         }
 
     }
     else {
         redwax_print_error(r,
-                "Group '%s' could not be found: %s\n", group, strerror(errno));
+                "Error: group '%s' could not be found.\n", group);
         return APR_EGENERAL;
     }
 



More information about the rt-commit mailing list