all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [DMD] [PATCH] service: Change gid before uid when dropping privileges.
@ 2015-12-03 15:37 David Thompson
  2015-12-04  8:00 ` Ricardo Wurmus
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: David Thompson @ 2015-12-03 15:37 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 96 bytes --]

Found this little order of operations issue when trying to button up the
Transmission service.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-service-Change-gid-before-uid-when-dropping-privileg.patch --]
[-- Type: text/x-patch, Size: 1650 bytes --]

From 552eafe882e3c059525e79c0f222becb9d73eb93 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 3 Dec 2015 10:09:34 -0500
Subject: [PATCH] service: Change gid before uid when dropping privileges.

---
 modules/dmd/service.scm | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/modules/dmd/service.scm b/modules/dmd/service.scm
index aece069..34826b1 100644
--- a/modules/dmd/service.scm
+++ b/modules/dmd/service.scm
@@ -614,23 +614,25 @@ false."
            (catch-system-error (close-fdes i))
            (loop (+ i 1)))))
 
-     (when user
+     ;; setgid must be done *before* setuid, otherwise the user will
+     ;; likely no longer have permissions to setgid.
+     (when group
        (catch #t
          (lambda ()
-           (setuid (passwd:uid (getpw user))))
+           (setgid (group:gid (getgr group))))
          (lambda (key . args)
            (format (current-error-port)
-                   "failed to change to user ~s:~%" user)
+                   "failed to change to group ~s:~%" group)
            (print-exception (current-error-port) #f key args)
            (primitive-exit 1))))
 
-     (when group
+     (when user
        (catch #t
          (lambda ()
-           (setgid (group:gid (getgr group))))
+           (setuid (passwd:uid (getpw user))))
          (lambda (key . args)
            (format (current-error-port)
-                   "failed to change to group ~s:~%" group)
+                   "failed to change to user ~s:~%" user)
            (print-exception (current-error-port) #f key args)
            (primitive-exit 1))))
 
-- 
2.5.0


[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


-- 
David Thompson
GPG Key: 0FF1D807

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-01-06 22:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03 15:37 [DMD] [PATCH] service: Change gid before uid when dropping privileges David Thompson
2015-12-04  8:00 ` Ricardo Wurmus
2015-12-04 19:08   ` Thompson, David
2015-12-06 21:56     ` Ludovic Courtès
2015-12-07 13:22       ` Thompson, David
2015-12-07 14:08         ` Thompson, David
2015-12-08 17:09           ` Ludovic Courtès
2015-12-04 14:27 ` Ludovic Courtès
2016-01-06 22:53 ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.