]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei add-external --mirror: respect client umask
authorEric Wong <e@80x24.org>
Thu, 14 Oct 2021 04:32:54 +0000 (04:32 +0000)
committerEric Wong <e@80x24.org>
Thu, 14 Oct 2021 09:07:16 +0000 (09:07 +0000)
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.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiMirror.pm
script/lei

index bd8a6bef632b9c1252c6b70ea258bd5a028c3196..635cd0c5508aa3050640b3c2b001b5e8faf992e9 100644 (file)
@@ -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;
index 1369c00c57fde351cdf7a910dc166b6024d92786..fb73d86316707f83d2df32431e89bc97ae97fb63 100644 (file)
@@ -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', []);
index bc43779821e7bbb26026dd405505579f0dd788a0..8f6e8aacb86b67470d2dade0fdd7225cc6e7df0a 100755 (executable)
@@ -122,6 +122,8 @@ while (1) {
                $exec_cmd->(\@fds, split(/\0/, $1));
        } elsif ($buf eq '-WINCH') {
                kill($buf, @parent); # for MUA
+       } elsif ($buf eq 'umask') {
+               send($sock, 'u'.pack('V', umask), MSG_EOR) or die "send: $!"
        } elsif ($buf =~ /\Ax_it ([0-9]+)\z/) {
                $x_it_code ||= $1 + 0;
                last;