[sane-devel] [PATCH] Invoke setgid before setuid

Nick Andrew nick at nick-andrew.net
Mon Jul 28 02:36:01 UTC 2008


Invoke setgid before setuid

When called with the "-a user" parameter, saned calls first
setuid and then setgid, but the second call fails because
uid is no longer root.

So call setgid first, and check the return code from the
two calls. If you can't set your gid or uid, that's a fatal
error.

Signed-off-by: Nick Andrew <nick at nick-andrew.net>
---

 frontend/saned.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)


diff --git a/frontend/saned.c b/frontend/saned.c
index 29bf39d..cddd6fa 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -2788,8 +2788,20 @@ run_standalone (int argc, char **argv)
       /* Drop privileges if requested */
       if (runas_uid > 0)
 	{
-	  seteuid (runas_uid);
-	  setegid (runas_gid);
+	  int err;
+
+	  err = setegid (runas_gid);
+	  if (err)
+	    {
+	      DBG (DBG_ERR, "FATAL ERROR: setegid to gid %d failed: %s\n", runas_gid, strerror (errno));
+	      exit (1);
+	    }
+	  err = seteuid (runas_uid);
+	  if (err)
+	    {
+	      DBG (DBG_ERR, "FATAL ERROR: seteuid to uid %d failed: %s\n", runas_uid, strerror (errno));
+	      exit (1);
+	    }
 
 	  DBG (DBG_WARN, "Dropped privileges to uid %d gid %d\n", runas_uid, runas_gid);
 	}





More information about the sane-devel mailing list