/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/usplash.c

  • Committer: Teddy Hogeborn
  • Date: 2019-08-02 22:16:53 UTC
  • Revision ID: teddy@recompile.se-20190802221653-ic1iko9hbefzwsk7
Fix bug in server Debian package: Fails to start on first install

There has been a very long-standing bug where installation of the
server (the "mandos" Debian package) would fail to start the server
properly right after installation.  It would work on manual (re)start
after installation, or after reboot, and even after package purge and
reinstall, it would then work the first time.  The problem, it turns
out, is when the new "_mandos" user (and corresponding group) is
created, the D-Bus server is not reloaded, and is therefore not aware
of that user, and does not recognize the user and group name in the
/etc/dbus-1/system.d/mandos.conf file.  The Mandos server, when it
tries to start and access the D-Bus, is then not permitted to connect
to its D-Bus bus name, and disables D-Bus use as a fallback measure;
i.e. the server works, but it is not controllable via D-Bus commands
(via mandos-ctl or mandos-monitor).  The next time the D-Bus daemon is
reloaded for any reason, the new user & group would become visible to
the D-Bus daemon and after that, any restart of the Mandos server
would succeed and it would bind to its D-Bus name properly, and
thereby be visible and controllable by mandos-ctl & mandos-monitor.
This was mostly invisible when using sysvinit, but systemd makes the
problem visible since the systemd service file for the Mandos server
is configured to not consider the Mandos server "started" until the
D-Bus name has been bound; this makes the starting of the service wait
for 90 seconds and then fail with a timeout error.

Fixing this should also make the Debian CI autopkgtest tests work.

* debian/mandos.postinst (configure): After creating (or renaming)
                                      user & group, reload D-Bus
                                      daemon (if present).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Usplash - Read a password from usplash and output it
4
4
 * 
5
 
 * Copyright © 2008-2011 Teddy Hogeborn
6
 
 * Copyright © 2008-2011 Björn Påhlsson
7
 
 * 
8
 
 * This program is free software: you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public License as
10
 
 * published by the Free Software Foundation, either version 3 of the
11
 
 * License, or (at your option) any later version.
12
 
 * 
13
 
 * This program is distributed in the hope that it will be useful, but
 
5
 * Copyright © 2008-2018 Teddy Hogeborn
 
6
 * Copyright © 2008-2018 Björn Påhlsson
 
7
 * 
 
8
 * This file is part of Mandos.
 
9
 * 
 
10
 * Mandos is free software: you can redistribute it and/or modify it
 
11
 * under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation, either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 * 
 
15
 * Mandos is distributed in the hope that it will be useful, but
14
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
18
 * General Public License for more details.
17
19
 * 
18
20
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program.  If not, see
20
 
 * <http://www.gnu.org/licenses/>.
 
21
 * along with Mandos.  If not, see <http://www.gnu.org/licenses/>.
21
22
 * 
22
23
 * Contact the authors at <mandos@recompile.se>.
23
24
 */
58
59
const char usplash_name[] = "/sbin/usplash";
59
60
 
60
61
/* Function to use when printing errors */
 
62
__attribute__((format (gnu_printf, 3, 4)))
61
63
void error_plus(int status, int errnum, const char *formatstring,
62
64
                ...){
63
65
  va_list ap;
66
68
  
67
69
  va_start(ap, formatstring);
68
70
  ret = vasprintf(&text, formatstring, ap);
69
 
  if (ret == -1){
 
71
  if(ret == -1){
70
72
    fprintf(stderr, "Mandos plugin %s: ",
71
73
            program_invocation_short_name);
72
74
    vfprintf(stderr, formatstring, ap);
116
118
      ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
117
119
      if(ret == -1){
118
120
        int e = errno;
119
 
        TEMP_FAILURE_RETRY(close(*fifo_fd_r));
 
121
        close(*fifo_fd_r);
120
122
        errno = e;
121
123
        return false;
122
124
      }
132
134
                 cmd_line_len - written);
133
135
    if(sret == -1){
134
136
      int e = errno;
135
 
      TEMP_FAILURE_RETRY(close(*fifo_fd_r));
 
137
      close(*fifo_fd_r);
136
138
      free(cmd_line_alloc);
137
139
      errno = e;
138
140
      return false;
490
492
        error_plus(0, errno, "read");
491
493
        status = EX_OSERR;
492
494
      }
493
 
      TEMP_FAILURE_RETRY(close(outfifo_fd));
 
495
      close(outfifo_fd);
494
496
      goto failure;
495
497
    }
496
498
    if(interrupted_by_signal){
577
579
  
578
580
  /* Close FIFO */
579
581
  if(fifo_fd != -1){
580
 
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
582
    ret = close(fifo_fd);
581
583
    if(ret == -1 and errno != EINTR){
582
584
      error_plus(0, errno, "close");
583
585
    }
586
588
  
587
589
  /* Close output FIFO */
588
590
  if(outfifo_fd != -1){
589
 
    ret = (int)TEMP_FAILURE_RETRY(close(outfifo_fd));
 
591
    ret = close(outfifo_fd);
590
592
    if(ret == -1){
591
593
      error_plus(0, errno, "close");
592
594
    }
654
656
  
655
657
  /* Close FIFO (again) */
656
658
  if(fifo_fd != -1){
657
 
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
659
    ret = close(fifo_fd);
658
660
    if(ret == -1 and errno != EINTR){
659
661
      error_plus(0, errno, "close");
660
662
    }