about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-14 04:32:54 +0000
committerEric Wong <e@80x24.org>2021-10-14 09:07:16 +0000
commiteb0e4dd09d540eb29c71fe1cc92161a13a0b608a (patch)
tree1051f61a3db1b62dd99d21e67d6e6be00c31611e /lib/PublicInbox
parent896c59c925e61caf5d985e8531a35825eeecc99d (diff)
downloadpublic-inbox-eb0e4dd09d540eb29c71fe1cc92161a13a0b608a.tar.gz
While lei is intended for non-public mail and runs umask(077)
by default, externals are one area which can safely defer to
the user's umask.

Instead of sending it unconditionally with every command, only
have lei-daemon request it when necessary.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LEI.pm11
-rw-r--r--lib/PublicInbox/LeiMirror.pm2
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index bd8a6bef..635cd0c5 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -1518,4 +1518,15 @@ sub cfg_dump ($$) {
         undef;
 }
 
+sub request_umask {
+        my ($lei) = @_;
+        my $s = $lei->{sock} // return;
+        send($s, 'umask', MSG_EOR) // die "send: $!";
+        vec(my $rvec = '', fileno($s), 1) = 1;
+        select($rvec, undef, undef, 2) or die 'timeout waiting for umask';
+        recv($s, my $v, 5, 0) // die "recv: $!";
+        (my $u, $lei->{client_umask}) = unpack('AV', $v);
+        $u eq 'u' or warn "E: recv $v has no umask";
+}
+
 1;
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index 1369c00c..fb73d863 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -424,6 +424,7 @@ sub start_clone_url {
 sub do_mirror { # via wq_io_do
         my ($self) = @_;
         my $lei = $self->{lei};
+        umask($lei->{client_umask}) if defined $lei->{client_umask};
         eval {
                 my $iv = $lei->{opt}->{'inbox-version'};
                 if (defined $iv) {
@@ -448,6 +449,7 @@ sub start {
         require PublicInbox::Inbox;
         require PublicInbox::Admin;
         require PublicInbox::InboxWritable;
+        $lei->request_umask;
         my ($op_c, $ops) = $lei->workers_start($self, 1);
         $lei->{wq1} = $self;
         $self->wq_io_do('do_mirror', []);