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

  • Committer: teddy at bsnet
  • Date: 2011-12-24 23:17:02 UTC
  • Revision ID: teddy@fukt.bsnet.se-20111224231702-1ffgu6r02p0bz9co
* plugins.d/splashy.c (error_plus): Check format string.
* plugins.d/askpass-fifo.c (error_plus): - '' -
* plugins.d/plymouth.c (error_plus): - '' -
* plugins.d/password-prompt.c (error_plus): - '' -
* plugins.d/usplash.c (error_plus): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Plymouth - Read a password from Plymouth and output it
4
4
 * 
5
 
 * Copyright © 2010-2017 Teddy Hogeborn
6
 
 * Copyright © 2010-2017 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 © 2010-2011 Teddy Hogeborn
 
6
 * Copyright © 2010-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
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
22
 * Contact the authors at <mandos@recompile.se>.
24
23
 */
85
84
  
86
85
  va_start(ap, formatstring);
87
86
  ret = vasprintf(&text, formatstring, ap);
88
 
  if(ret == -1){
 
87
  if (ret == -1){
89
88
    fprintf(stderr, "Mandos plugin %s: ",
90
89
            program_invocation_short_name);
91
90
    vfprintf(stderr, formatstring, ap);
155
154
  return true;
156
155
}
157
156
 
158
 
__attribute__((nonnull (2, 3)))
159
157
bool exec_and_wait(pid_t *pid_return, const char *path,
160
 
                   const char * const *argv, bool interruptable,
 
158
                   const char **argv, bool interruptable,
161
159
                   bool daemonize){
162
160
  int status;
163
161
  int ret;
175
173
      }
176
174
    }
177
175
    
178
 
    char **new_argv = malloc(sizeof(const char *));
179
 
    if(new_argv == NULL){
180
 
      error_plus(0, errno, "malloc");
181
 
      _exit(EX_OSERR);
182
 
    }
 
176
    char **new_argv = NULL;
183
177
    char **tmp;
184
178
    int i = 0;
185
 
    for (; argv[i] != NULL; i++){
186
 
      tmp = realloc(new_argv, sizeof(const char *) * ((size_t)i + 2));
187
 
      if(tmp == NULL){
 
179
    for (; argv[i]!=NULL; i++){
 
180
      tmp = realloc(new_argv, sizeof(const char *) * ((size_t)i + 1));
 
181
      if (tmp == NULL){
188
182
        error_plus(0, errno, "realloc");
189
183
        free(new_argv);
190
184
        _exit(EX_OSERR);
219
213
  return false;
220
214
}
221
215
 
222
 
__attribute__((nonnull))
223
216
int is_plymouth(const struct dirent *proc_entry){
224
217
  int ret;
225
218
  {
226
 
    uintmax_t proc_id;
 
219
    uintmax_t maxvalue;
227
220
    char *tmp;
228
221
    errno = 0;
229
 
    proc_id = strtoumax(proc_entry->d_name, &tmp, 10);
 
222
    maxvalue = strtoumax(proc_entry->d_name, &tmp, 10);
230
223
 
231
224
    if(errno != 0 or *tmp != '\0'
232
 
       or proc_id != (uintmax_t)((pid_t)proc_id)){
 
225
       or maxvalue != (uintmax_t)((pid_t)maxvalue)){
233
226
      return 0;
234
227
    }
235
228
  }
270
263
 
271
264
pid_t get_pid(void){
272
265
  int ret;
273
 
  uintmax_t proc_id = 0;
 
266
  uintmax_t maxvalue = 0;
274
267
  FILE *pidfile = fopen(plymouth_pid, "r");
275
268
  /* Try the new pid file location */
276
269
  if(pidfile != NULL){
277
 
    ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
 
270
    ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
278
271
    if(ret != 1){
279
 
      proc_id = 0;
 
272
      maxvalue = 0;
280
273
    }
281
274
    fclose(pidfile);
282
275
  }
283
276
  /* Try the old pid file location */
284
 
  if(proc_id == 0){
 
277
  if(maxvalue == 0){
285
278
    pidfile = fopen(plymouth_pid, "r");
286
279
    if(pidfile != NULL){
287
 
      ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
 
280
      ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
288
281
      if(ret != 1){
289
 
        proc_id = 0;
 
282
        maxvalue = 0;
290
283
      }
291
284
      fclose(pidfile);
292
285
    }
293
286
  }
294
287
  /* Look for a plymouth process */
295
 
  if(proc_id == 0){
 
288
  if(maxvalue == 0){
296
289
    struct dirent **direntries = NULL;
297
290
    ret = scandir("/proc", &direntries, is_plymouth, alphasort);
298
 
    if(ret == -1){
 
291
    if (ret == -1){
299
292
      error_plus(0, errno, "scandir");
300
293
    }
301
 
    if(ret > 0){
302
 
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &proc_id);
303
 
      if(ret < 0){
 
294
    if (ret > 0){
 
295
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &maxvalue);
 
296
      if (ret < 0){
304
297
        error_plus(0, errno, "sscanf");
305
298
      }
306
299
    }
309
302
    free(direntries);
310
303
  }
311
304
  pid_t pid;
312
 
  pid = (pid_t)proc_id;
313
 
  if((uintmax_t)pid == proc_id){
 
305
  pid = (pid_t)maxvalue;
 
306
  if((uintmax_t)pid == maxvalue){
314
307
    return pid;
315
308
  }
316
309
  
317
310
  return 0;
318
311
}
319
312
 
320
 
const char * const * getargv(pid_t pid){
 
313
const char **getargv(pid_t pid){
321
314
  int cl_fd;
322
315
  char *cmdline_filename;
323
316
  ssize_t sret;
384
377
    return NULL;
385
378
  }
386
379
  argz_extract(cmdline, cmdline_len, argv); /* Create argv */
387
 
  return (const char * const *)argv;
 
380
  return (const char **)argv;
388
381
}
389
382
 
390
383
int main(__attribute__((unused))int argc,
465
458
  }
466
459
  kill_and_wait(plymouth_command_pid);
467
460
  
468
 
  const char * const *plymouthd_argv;
 
461
  const char **plymouthd_argv;
469
462
  pid_t pid = get_pid();
470
463
  if(pid == 0){
471
464
    error_plus(0, 0, "plymouthd pid not found");