/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/splashy.c

  • Committer: Teddy Hogeborn
  • Date: 2009-12-25 23:13:47 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091225231347-gg9u9ru0wj0f24hh
More consistent terminology: Clients are no longer "invalid" - they
are "disabled".  All code and documentation changed to reflect this.

D=Bus API change: The "properties" argument was removed from the
"ClientAdded" signal on interface "se.bsnet.fukt.Mandos".  All code in
both "mandos" and "mandos-monitor" changed to reflect this.

* mandos: Replaced "with closing(F)" with simply "with F" in all
          places where F is a file object.
  (Client.still_valid): Removed.  All callers changed to look at
                        "Client.enabled" instead.
  (dbus_service_property): Check for unsupported signatures with the
                           "byte_arrays" option.
  (DBusObjectWithProperties.Set): - '' -
  (ClientHandler.handle): Use the reverse pipe to receive the
                          "Client.enabled" attribute instead of the
                          now-removed "Client.still_valid()" method.
  (ForkingMixInWithPipe): Renamed to "ForkingMixInWithPipes" (all
                          users changed).  Now also create a reverse
                          pipe for sending data to the child process.
  (ForkingMixInWithPipes.add_pipe): Now takes two pipe fd's as
                                    arguments.  All callers changed.
  (IPv6_TCPServer.handle_ipc): Take an additional "reply_fd" argument
                               (all callers changed).  Close the reply
                               pipe when the child data pipe is
                               closed.  New "GETATTR" IPC method; will
                               pickle client attribute and send it
                               over the reply pipe FD.
  (MandosDBusService.ClientAdded): Removed "properties" argument.  All
                                   emitters changed.
* mandos-clients.conf.xml (DESCRIPTION, OPTIONS): Use
                                                  "enabled/disabled"
                                                  terminology.
* mandos-ctl: Option "--is-valid" renamed to "--is-enabled".
* mandos-monitor: Enable user locale.  Try to log exceptions.
  (MandosClientPropertyCache.__init__): Removed "properties" argument.
                                        All callers changed.
  (UserInterface.add_new_client): Remove "properties" argument.  All
                                  callers changed.  Supply "logger"
                                  argument to MandosClientWidget().
  (UserInterface.add_client): New "logger" argument.  All callers
                              changed.
* mandos.xml (BUGS, SECURITY/CLIENTS): Use "enabled/disabled"
                                       terminology.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Splashy - Read a password from splashy and output it
4
4
 * 
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
 
5
 * Copyright © 2008,2009 Teddy Hogeborn
 
6
 * Copyright © 2008,2009 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
16
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
17
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
16
 * General Public License for more details.
19
17
 * 
20
18
 * You should have received a copy of the GNU General Public License
21
 
 * along with Mandos.  If not, see <http://www.gnu.org/licenses/>.
 
19
 * along with this program.  If not, see
 
20
 * <http://www.gnu.org/licenses/>.
22
21
 * 
23
 
 * Contact the authors at <mandos@recompile.se>.
 
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
24
23
 */
25
24
 
26
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), asprintf() */
30
29
                                   SIG_IGN, kill(), SIGKILL */
31
30
#include <stddef.h>             /* NULL */
32
31
#include <stdlib.h>             /* getenv() */
33
 
#include <stdio.h>              /* asprintf(), vasprintf(), vprintf(),
34
 
                                   fprintf() */
 
32
#include <stdio.h>              /* asprintf(), perror() */
35
33
#include <stdlib.h>             /* EXIT_FAILURE, free(),
36
34
                                   EXIT_SUCCESS */
37
35
#include <sys/types.h>          /* pid_t, DIR, struct dirent,
44
42
                                   sleep(), dup2() STDERR_FILENO,
45
43
                                   STDOUT_FILENO, _exit(),
46
44
                                   pause() */
47
 
#include <string.h>             /* memcmp(), strerror() */
 
45
#include <string.h>             /* memcmp() */
48
46
#include <errno.h>              /* errno, EACCES, ENOTDIR, ELOOP,
49
47
                                   ENOENT, ENAMETOOLONG, EMFILE,
50
48
                                   ENFILE, ENOMEM, ENOEXEC, EINVAL,
51
49
                                   E2BIG, EFAULT, EIO, ETXTBSY,
52
50
                                   EISDIR, ELIBBAD, EPERM, EINTR,
53
51
                                   ECHILD */
54
 
#include <error.h>              /* error() */
55
52
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
56
53
                                   WEXITSTATUS() */
57
54
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
58
55
                                   EX_UNAVAILABLE */
59
 
#include <stdarg.h>             /* va_list, va_start(), ... */
60
56
 
61
57
sig_atomic_t interrupted_by_signal = 0;
62
58
int signal_received;
63
59
 
64
 
/* Function to use when printing errors */
65
 
__attribute__((format (gnu_printf, 3, 4)))
66
 
void error_plus(int status, int errnum, const char *formatstring,
67
 
                ...){
68
 
  va_list ap;
69
 
  char *text;
70
 
  int ret;
71
 
  
72
 
  va_start(ap, formatstring);
73
 
  ret = vasprintf(&text, formatstring, ap);
74
 
  if(ret == -1){
75
 
    fprintf(stderr, "Mandos plugin %s: ",
76
 
            program_invocation_short_name);
77
 
    vfprintf(stderr, formatstring, ap);
78
 
    fprintf(stderr, ": ");
79
 
    fprintf(stderr, "%s\n", strerror(errnum));
80
 
    error(status, errno, "vasprintf while printing error");
81
 
    return;
82
 
  }
83
 
  fprintf(stderr, "Mandos plugin ");
84
 
  error(status, errnum, "%s", text);
85
 
  free(text);
86
 
}
87
 
 
88
 
 
89
60
static void termination_handler(int signum){
90
61
  if(interrupted_by_signal){
91
62
    return;
138
109
    proc_dir = opendir("/proc");
139
110
    if(proc_dir == NULL){
140
111
      int e = errno;
141
 
      error_plus(0, errno, "opendir");
 
112
      perror("opendir");
142
113
      switch(e){
143
114
      case EACCES:
144
115
      case ENOTDIR:
180
151
        char *exe_link;
181
152
        ret = asprintf(&exe_link, "/proc/%s/exe", proc_ent->d_name);
182
153
        if(ret == -1){
183
 
          error_plus(0, errno, "asprintf");
 
154
          perror("asprintf");
184
155
          exitstatus = EX_OSERR;
185
156
          goto failure;
186
157
        }
194
165
            continue;
195
166
          }
196
167
          int e = errno;
197
 
          error_plus(0, errno, "lstat");
 
168
          perror("lstat");
198
169
          free(exe_link);
199
170
          switch(e){
200
171
          case EACCES:
242
213
    sigemptyset(&new_action.sa_mask);
243
214
    ret = sigaddset(&new_action.sa_mask, SIGINT);
244
215
    if(ret == -1){
245
 
      error_plus(0, errno, "sigaddset");
 
216
      perror("sigaddset");
246
217
      exitstatus = EX_OSERR;
247
218
      goto failure;
248
219
    }
249
220
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
250
221
    if(ret == -1){
251
 
      error_plus(0, errno, "sigaddset");
 
222
      perror("sigaddset");
252
223
      exitstatus = EX_OSERR;
253
224
      goto failure;
254
225
    }
255
226
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
256
227
    if(ret == -1){
257
 
      error_plus(0, errno, "sigaddset");
 
228
      perror("sigaddset");
258
229
      exitstatus = EX_OSERR;
259
230
      goto failure;
260
231
    }
261
232
    ret = sigaction(SIGINT, NULL, &old_action);
262
233
    if(ret == -1){
263
 
      error_plus(0, errno, "sigaction");
 
234
      perror("sigaction");
264
235
      exitstatus = EX_OSERR;
265
236
      goto failure;
266
237
    }
267
238
    if(old_action.sa_handler != SIG_IGN){
268
239
      ret = sigaction(SIGINT, &new_action, NULL);
269
240
      if(ret == -1){
270
 
        error_plus(0, errno, "sigaction");
 
241
        perror("sigaction");
271
242
        exitstatus = EX_OSERR;
272
243
        goto failure;
273
244
      }
274
245
    }
275
246
    ret = sigaction(SIGHUP, NULL, &old_action);
276
247
    if(ret == -1){
277
 
      error_plus(0, errno, "sigaction");
 
248
      perror("sigaction");
278
249
      exitstatus = EX_OSERR;
279
250
      goto failure;
280
251
    }
281
252
    if(old_action.sa_handler != SIG_IGN){
282
253
      ret = sigaction(SIGHUP, &new_action, NULL);
283
254
      if(ret == -1){
284
 
        error_plus(0, errno, "sigaction");
 
255
        perror("sigaction");
285
256
        exitstatus = EX_OSERR;
286
257
        goto failure;
287
258
      }
288
259
    }
289
260
    ret = sigaction(SIGTERM, NULL, &old_action);
290
261
    if(ret == -1){
291
 
      error_plus(0, errno, "sigaction");
 
262
      perror("sigaction");
292
263
      exitstatus = EX_OSERR;
293
264
      goto failure;
294
265
    }
295
266
    if(old_action.sa_handler != SIG_IGN){
296
267
      ret = sigaction(SIGTERM, &new_action, NULL);
297
268
      if(ret == -1){
298
 
        error_plus(0, errno, "sigaction");
 
269
        perror("sigaction");
299
270
        exitstatus = EX_OSERR;
300
271
        goto failure;
301
272
      }
312
283
    goto failure;
313
284
  }
314
285
  if(splashy_command_pid == -1){
315
 
    error_plus(0, errno, "fork");
 
286
    perror("fork");
316
287
    exitstatus = EX_OSERR;
317
288
    goto failure;
318
289
  }
322
293
      const char splashy_command[] = "/sbin/splashy_update";
323
294
      execl(splashy_command, splashy_command, prompt, (char *)NULL);
324
295
      int e = errno;
325
 
      error_plus(0, errno, "execl");
 
296
      perror("execl");
326
297
      switch(e){
327
298
      case EACCES:
328
299
      case ENOENT:
342
313
      case ENOTDIR:
343
314
      case ELOOP:
344
315
      case EISDIR:
345
 
#ifdef ELIBBAD
346
 
      case ELIBBAD:             /* Linux only */
347
 
#endif
 
316
      case ELIBBAD:
348
317
      case EPERM:
349
318
        _exit(EX_OSFILE);
350
319
      }
372
341
      goto failure;
373
342
    }
374
343
    if(ret == -1){
375
 
      error_plus(0, errno, "waitpid");
 
344
      perror("waitpid");
376
345
      if(errno == ECHILD){
377
346
        splashy_command_pid = 0;
378
347
      }
410
379
         the real user ID (_mandos) */
411
380
      ret = setuid(geteuid());
412
381
      if(ret == -1){
413
 
        error_plus(0, errno, "setuid");
 
382
        perror("setuid");
414
383
      }
415
384
      
416
385
      setsid();
417
386
      ret = chdir("/");
418
387
      if(ret == -1){
419
 
        error_plus(0, errno, "chdir");
 
388
        perror("chdir");
420
389
      }
421
390
/*       if(fork() != 0){ */
422
391
/*      _exit(EXIT_SUCCESS); */
423
392
/*       } */
424
393
      ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
425
394
      if(ret == -1){
426
 
        error_plus(0, errno, "dup2");
 
395
        perror("dup2");
427
396
        _exit(EX_OSERR);
428
397
      }
429
398
      
430
399
      execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
431
400
      {
432
401
        int e = errno;
433
 
        error_plus(0, errno, "execl");
 
402
        perror("execl");
434
403
        switch(e){
435
404
        case EACCES:
436
405
        case ENOENT:
456
425
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
457
426
                                            &signal_action, NULL));
458
427
    if(ret == -1){
459
 
      error_plus(0, errno, "sigaction");
 
428
      perror("sigaction");
460
429
    }
461
430
    do {
462
431
      ret = raise(signal_received);
463
432
    } while(ret != 0 and errno == EINTR);
464
433
    if(ret != 0){
465
 
      error_plus(0, errno, "raise");
 
434
      perror("raise");
466
435
      abort();
467
436
    }
468
437
    TEMP_FAILURE_RETRY(pause());