/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 plugins.d/usplash.c

  • Committer: Teddy Hogeborn
  • Date: 2020-12-06 12:02:04 UTC
  • mto: This revision was merged to the branch mainline in revision 404.
  • Revision ID: teddy@recompile.se-20201206120204-pkx839mdn2x2v2m7
Minor code cleanup

* dracut-module/password-agent.c
  (test_send_password_to_socket_EMSGSIZE): Replace a free()/malloc()
  pair with single realloc() call.

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
 
 * Contact the authors at <mandos@fukt.bsnet.se>.
 
23
 * Contact the authors at <mandos@recompile.se>.
23
24
 */
24
25
 
25
26
#define _GNU_SOURCE             /* asprintf(), TEMP_FAILURE_RETRY() */
36
37
                                   dirent */
37
38
#include <stddef.h>             /* NULL */
38
39
#include <string.h>             /* strlen(), memcmp(), strerror() */
39
 
#include <stdio.h>              /* asprintf(), vasprintf(), vprintf(), fprintf() */
 
40
#include <stdio.h>              /* asprintf(), vasprintf(), vprintf(),
 
41
                                   fprintf() */
40
42
#include <unistd.h>             /* close(), write(), readlink(),
41
43
                                   read(), STDOUT_FILENO, sleep(),
42
44
                                   fork(), setuid(), geteuid(),
57
59
const char usplash_name[] = "/sbin/usplash";
58
60
 
59
61
/* Function to use when printing errors */
60
 
void error_plus(int status, int errnum, const char *formatstring, ...){
 
62
__attribute__((format (gnu_printf, 3, 4)))
 
63
void error_plus(int status, int errnum, const char *formatstring,
 
64
                ...){
61
65
  va_list ap;
62
66
  char *text;
63
67
  int ret;
64
68
  
65
69
  va_start(ap, formatstring);
66
70
  ret = vasprintf(&text, formatstring, ap);
67
 
  if (ret == -1){
68
 
    fprintf(stderr, "Mandos plugin %s: ", program_invocation_short_name);
 
71
  if(ret == -1){
 
72
    fprintf(stderr, "Mandos plugin %s: ",
 
73
            program_invocation_short_name);
69
74
    vfprintf(stderr, formatstring, ap);
70
75
    fprintf(stderr, ": ");
71
76
    fprintf(stderr, "%s\n", strerror(errnum));
113
118
      ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
114
119
      if(ret == -1){
115
120
        int e = errno;
116
 
        TEMP_FAILURE_RETRY(close(*fifo_fd_r));
 
121
        close(*fifo_fd_r);
117
122
        errno = e;
118
123
        return false;
119
124
      }
129
134
                 cmd_line_len - written);
130
135
    if(sret == -1){
131
136
      int e = errno;
132
 
      TEMP_FAILURE_RETRY(close(*fifo_fd_r));
 
137
      close(*fifo_fd_r);
133
138
      free(cmd_line_alloc);
134
139
      errno = e;
135
140
      return false;
487
492
        error_plus(0, errno, "read");
488
493
        status = EX_OSERR;
489
494
      }
490
 
      TEMP_FAILURE_RETRY(close(outfifo_fd));
 
495
      close(outfifo_fd);
491
496
      goto failure;
492
497
    }
493
498
    if(interrupted_by_signal){
574
579
  
575
580
  /* Close FIFO */
576
581
  if(fifo_fd != -1){
577
 
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
582
    ret = close(fifo_fd);
578
583
    if(ret == -1 and errno != EINTR){
579
584
      error_plus(0, errno, "close");
580
585
    }
583
588
  
584
589
  /* Close output FIFO */
585
590
  if(outfifo_fd != -1){
586
 
    ret = (int)TEMP_FAILURE_RETRY(close(outfifo_fd));
 
591
    ret = close(outfifo_fd);
587
592
    if(ret == -1){
588
593
      error_plus(0, errno, "close");
589
594
    }
651
656
  
652
657
  /* Close FIFO (again) */
653
658
  if(fifo_fd != -1){
654
 
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
659
    ret = close(fifo_fd);
655
660
    if(ret == -1 and errno != EINTR){
656
661
      error_plus(0, errno, "close");
657
662
    }