all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Thompson <dthompson2@worcester.edu>
To: guix-devel@gnu.org
Subject: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
Date: Thu, 03 Dec 2015 10:37:55 -0500	[thread overview]
Message-ID: <871tb3tuek.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (raw)

[-- 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

             reply	other threads:[~2015-12-03 15:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03 15:37 David Thompson [this message]
2015-12-04  8:00 ` [DMD] [PATCH] service: Change gid before uid when dropping privileges 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871tb3tuek.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me \
    --to=dthompson2@worcester.edu \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.