all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#58541] [PATCH] gnu: dovecot: Use standard mkdir-p/perms.
@ 2022-10-15  7:51 Julien Lepiller
       [not found] ` <handler.58541.B.166582035710658.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Lepiller @ 2022-10-15  7:51 UTC (permalink / raw)
  To: 58541

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

Hi Guix!

While investigating an issue I have with dovecot and knot, I figured
that the dovecot service had a custom mkdir-p/perms procedure that
hard-coded the directory to chown, which would not chown any other
directories created with it. The patch makes it use mkdir-p/perms from
(gnu build utils) instead. I don't think this will fix my issue, but at
least, that's one bug fixed :)

[-- Attachment #2: 0001-gnu-dovecot-Use-standard-mkdir-p-perms.patch --]
[-- Type: text/x-patch, Size: 7456 bytes --]

From 7b754b0f8b31475d22a0bf4c106f0249fc5dd1b7 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 15 Oct 2022 09:19:38 +0200
Subject: [PATCH] gnu: dovecot: Use standard mkdir-p/perms.

* gnu/services/mail.scm (%dovecot-activation): Use (gnu build utils).
---
 gnu/services/mail.scm | 114 +++++++++++++++++++++---------------------
 1 file changed, 56 insertions(+), 58 deletions(-)

diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm
index 43f144a42d..2dc235a585 100644
--- a/gnu/services/mail.scm
+++ b/gnu/services/mail.scm
@@ -35,6 +35,7 @@ (define-module (gnu services mail)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages dav)
   #:use-module (gnu packages tls)
+  #:use-module (guix modules)
   #:use-module (guix records)
   #:use-module (guix packages)
   #:use-module (guix gexp)
@@ -1512,64 +1513,61 @@ (define (%dovecot-activation config)
              (lambda ()
                (serialize-configuration config
                                         dovecot-configuration-fields)))))))
-    #~(begin
-        (use-modules (guix build utils))
-        (define (mkdir-p/perms directory owner perms)
-          (mkdir-p directory)
-          (chown "/var/run/dovecot" (passwd:uid owner) (passwd:gid owner))
-          (chmod directory perms))
-        (define (build-subject parameters)
-          (string-concatenate
-           (map (lambda (pair)
-                  (let ((k (car pair)) (v (cdr pair)))
-                    (define (escape-char str chr)
-                      (string-join (string-split str chr) (string #\\ chr)))
-                    (string-append "/" k "="
-                                   (escape-char (escape-char v #\=) #\/))))
-                (filter (lambda (pair) (cdr pair)) parameters))))
-        (define* (create-self-signed-certificate-if-absent
-                  #:key private-key public-key (owner (getpwnam "root"))
-                  (common-name (gethostname))
-                  (organization-name "Guix")
-                  (organization-unit-name "Default Self-Signed Certificate")
-                  (subject-parameters `(("CN" . ,common-name)
-                                        ("O" . ,organization-name)
-                                        ("OU" . ,organization-unit-name)))
-                  (subject (build-subject subject-parameters)))
-          ;; Note that by default, OpenSSL outputs keys in PEM format.  This
-          ;; is what we want.
-          (unless (file-exists? private-key)
-            (cond
-             ((zero? (system* (string-append #$openssl "/bin/openssl")
-                              "genrsa" "-out" private-key "2048"))
-              (chown private-key (passwd:uid owner) (passwd:gid owner))
-              (chmod private-key #o400))
-             (else
-              (format (current-error-port)
-                      "Failed to create private key at ~a.\n" private-key))))
-          (unless (file-exists? public-key)
-            (cond
-             ((zero? (system* (string-append #$openssl "/bin/openssl")
-                              "req" "-new" "-x509" "-key" private-key
-                              "-out" public-key "-days" "3650"
-                              "-batch" "-subj" subject))
-              (chown public-key (passwd:uid owner) (passwd:gid owner))
-              (chmod public-key #o444))
-             (else
-              (format (current-error-port)
-                      "Failed to create public key at ~a.\n" public-key)))))
-        (let ((user (getpwnam "dovecot")))
-          (mkdir-p/perms "/var/run/dovecot" user #o755)
-          (mkdir-p/perms "/var/lib/dovecot" user #o755)
-          (mkdir-p/perms "/etc/dovecot" user #o755)
-          (copy-file #$(plain-file "dovecot.conf" config-str)
-                     "/etc/dovecot/dovecot.conf")
-          (mkdir-p/perms "/etc/dovecot/private" user #o700)
-          (create-self-signed-certificate-if-absent
-           #:private-key "/etc/dovecot/private/default.pem"
-           #:public-key "/etc/dovecot/default.pem"
-           #:owner (getpwnam "root")
-           #:common-name (format #f "Dovecot service on ~a" (gethostname)))))))
+    (with-imported-modules (source-module-closure '((gnu build activation)))
+      #~(begin
+          (use-modules (guix build utils) (gnu build activation))
+          (define (build-subject parameters)
+            (string-concatenate
+             (map (lambda (pair)
+                    (let ((k (car pair)) (v (cdr pair)))
+                      (define (escape-char str chr)
+                        (string-join (string-split str chr) (string #\\ chr)))
+                      (string-append "/" k "="
+                                     (escape-char (escape-char v #\=) #\/))))
+                  (filter (lambda (pair) (cdr pair)) parameters))))
+          (define* (create-self-signed-certificate-if-absent
+                    #:key private-key public-key (owner (getpwnam "root"))
+                    (common-name (gethostname))
+                    (organization-name "Guix")
+                    (organization-unit-name "Default Self-Signed Certificate")
+                    (subject-parameters `(("CN" . ,common-name)
+                                          ("O" . ,organization-name)
+                                          ("OU" . ,organization-unit-name)))
+                    (subject (build-subject subject-parameters)))
+            ;; Note that by default, OpenSSL outputs keys in PEM format.  This
+            ;; is what we want.
+            (unless (file-exists? private-key)
+              (cond
+               ((zero? (system* (string-append #$openssl "/bin/openssl")
+                                "genrsa" "-out" private-key "2048"))
+                (chown private-key (passwd:uid owner) (passwd:gid owner))
+                (chmod private-key #o400))
+               (else
+                (format (current-error-port)
+                        "Failed to create private key at ~a.\n" private-key))))
+            (unless (file-exists? public-key)
+              (cond
+               ((zero? (system* (string-append #$openssl "/bin/openssl")
+                                "req" "-new" "-x509" "-key" private-key
+                                "-out" public-key "-days" "3650"
+                                "-batch" "-subj" subject))
+                (chown public-key (passwd:uid owner) (passwd:gid owner))
+                (chmod public-key #o444))
+               (else
+                (format (current-error-port)
+                        "Failed to create public key at ~a.\n" public-key)))))
+          (let ((user (getpwnam "dovecot")))
+            (mkdir-p/perms "/var/run/dovecot" user #o755)
+            (mkdir-p/perms "/var/lib/dovecot" user #o755)
+            (mkdir-p/perms "/etc/dovecot" user #o755)
+            (copy-file #$(plain-file "dovecot.conf" config-str)
+                       "/etc/dovecot/dovecot.conf")
+            (mkdir-p/perms "/etc/dovecot/private" user #o700)
+            (create-self-signed-certificate-if-absent
+             #:private-key "/etc/dovecot/private/default.pem"
+             #:public-key "/etc/dovecot/default.pem"
+             #:owner (getpwnam "root")
+             #:common-name (format #f "Dovecot service on ~a" (gethostname))))))))
 
 (define (dovecot-shepherd-service config)
   "Return a list of <shepherd-service> for CONFIG."
-- 
2.38.0


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

* bug#58541: gnu: dovecot: Use standard mkdir-p/perms.
       [not found] ` <handler.58541.B.166582035710658.ack@debbugs.gnu.org>
@ 2022-11-02 16:00   ` Julien Lepiller
  0 siblings, 0 replies; 2+ messages in thread
From: Julien Lepiller @ 2022-11-02 16:00 UTC (permalink / raw)
  To: 58541-done

After two weeks with no answer, pushed to master as
853b49c4192b75fca8775920c2db88a0e395da7c, thanks.




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

end of thread, other threads:[~2022-11-02 16:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-15  7:51 [bug#58541] [PATCH] gnu: dovecot: Use standard mkdir-p/perms Julien Lepiller
     [not found] ` <handler.58541.B.166582035710658.ack@debbugs.gnu.org>
2022-11-02 16:00   ` bug#58541: " Julien Lepiller

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.