/mandos/release

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

« back to all changes in this revision

Viewing changes to plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2019-08-02 22:16:53 UTC
  • mto: This revision was merged to the branch mainline in revision 386.
  • 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
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
5
 
 * Copyright © 2008-2017 Teddy Hogeborn
6
 
 * Copyright © 2008-2017 Björn Påhlsson
 
5
 * Copyright © 2008-2018 Teddy Hogeborn
 
6
 * Copyright © 2008-2018 Björn Påhlsson
7
7
 * 
8
8
 * This file is part of Mandos.
9
9
 * 
313
313
__attribute__((nonnull))
314
314
static void free_plugin(plugin *plugin_node){
315
315
  
 
316
  for(char **arg = (plugin_node->argv)+1; *arg != NULL; arg++){
 
317
    free(*arg);
 
318
  }
316
319
  free(plugin_node->name);
317
 
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
318
 
    free(*arg);
319
 
  }
320
320
  free(plugin_node->argv);
321
321
  for(char **env = plugin_node->environ; *env != NULL; env++){
322
322
    free(*env);
565
565
    case '?':                   /* --help */
566
566
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
567
567
      argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
 
568
      __builtin_unreachable();
568
569
    case -3:                    /* --usage */
569
570
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
570
571
      argp_state_help(state, state->out_stream,
571
572
                      ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
 
573
      __builtin_unreachable();
572
574
    case 'V':                   /* --version */
573
575
      fprintf(state->out_stream, "%s\n", argp_program_version);
574
576
      exit(EXIT_SUCCESS);
584
586
      if(arg[0] == '\0'){
585
587
        break;
586
588
      }
 
589
#if __GNUC__ >= 7
 
590
      __attribute__((fallthrough));
 
591
#else
 
592
          /* FALLTHROUGH */
 
593
#endif
587
594
    default:
588
595
      return ARGP_ERR_UNKNOWN;
589
596
    }
1093
1100
    
1094
1101
    new_plugin->pid = pid;
1095
1102
    new_plugin->fd = pipefd[0];
1096
 
    
 
1103
 
 
1104
    if(debug){
 
1105
      fprintf(stderr, "Plugin %s started (PID %" PRIdMAX ")\n",
 
1106
              new_plugin->name, (intmax_t) (new_plugin->pid));
 
1107
    }
 
1108
 
1097
1109
    /* Unblock SIGCHLD so signal handler can be run if this process
1098
1110
       has already completed */
1099
1111
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,