/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 recompile
  • Date: 2011-12-31 13:25:58 UTC
  • mto: This revision was merged to the branch mainline in revision 541.
  • Revision ID: teddy@recompile.se-20111231132558-z0dh7qgofgctmgri
* network-hooks.s/bridge: Don't use interface names directly; search
                          for interface names using their address.
  (addrtoif): New function.
* network-hooks.s/bridge.conf (PORTS): Removed.
  (PORT_ADDRESSES): New.
* network-hooks.s/wireless: Don't use interface names directly; search
                            for interface names using their address.
  (addrtoif): New function.
* network-hooks.s/wireless.conf: Specify address.

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-2016 Teddy Hogeborn
6
 
 * Copyright © 2010-2016 Björn Påhlsson
 
5
 * Copyright © 2010-2011 Teddy Hogeborn
 
6
 * Copyright © 2010-2011 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
84
84
  
85
85
  va_start(ap, formatstring);
86
86
  ret = vasprintf(&text, formatstring, ap);
87
 
  if(ret == -1){
 
87
  if (ret == -1){
88
88
    fprintf(stderr, "Mandos plugin %s: ",
89
89
            program_invocation_short_name);
90
90
    vfprintf(stderr, formatstring, ap);
156
156
 
157
157
__attribute__((nonnull (2, 3)))
158
158
bool exec_and_wait(pid_t *pid_return, const char *path,
159
 
                   const char * const *argv, bool interruptable,
 
159
                   const char **argv, bool interruptable,
160
160
                   bool daemonize){
161
161
  int status;
162
162
  int ret;
174
174
      }
175
175
    }
176
176
    
177
 
    char **new_argv = malloc(sizeof(const char *));
178
 
    if(new_argv == NULL){
179
 
      error_plus(0, errno, "malloc");
180
 
      _exit(EX_OSERR);
181
 
    }
 
177
    char **new_argv = NULL;
182
178
    char **tmp;
183
179
    int i = 0;
184
180
    for (; argv[i]!=NULL; i++){
185
 
      tmp = realloc(new_argv, sizeof(const char *) * ((size_t)i + 2));
186
 
      if(tmp == NULL){
 
181
      tmp = realloc(new_argv, sizeof(const char *) * ((size_t)i + 1));
 
182
      if (tmp == NULL){
187
183
        error_plus(0, errno, "realloc");
188
184
        free(new_argv);
189
185
        _exit(EX_OSERR);
222
218
int is_plymouth(const struct dirent *proc_entry){
223
219
  int ret;
224
220
  {
225
 
    uintmax_t proc_id;
 
221
    uintmax_t maxvalue;
226
222
    char *tmp;
227
223
    errno = 0;
228
 
    proc_id = strtoumax(proc_entry->d_name, &tmp, 10);
 
224
    maxvalue = strtoumax(proc_entry->d_name, &tmp, 10);
229
225
 
230
226
    if(errno != 0 or *tmp != '\0'
231
 
       or proc_id != (uintmax_t)((pid_t)proc_id)){
 
227
       or maxvalue != (uintmax_t)((pid_t)maxvalue)){
232
228
      return 0;
233
229
    }
234
230
  }
269
265
 
270
266
pid_t get_pid(void){
271
267
  int ret;
272
 
  uintmax_t proc_id = 0;
 
268
  uintmax_t maxvalue = 0;
273
269
  FILE *pidfile = fopen(plymouth_pid, "r");
274
270
  /* Try the new pid file location */
275
271
  if(pidfile != NULL){
276
 
    ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
 
272
    ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
277
273
    if(ret != 1){
278
 
      proc_id = 0;
 
274
      maxvalue = 0;
279
275
    }
280
276
    fclose(pidfile);
281
277
  }
282
278
  /* Try the old pid file location */
283
 
  if(proc_id == 0){
 
279
  if(maxvalue == 0){
284
280
    pidfile = fopen(plymouth_pid, "r");
285
281
    if(pidfile != NULL){
286
 
      ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
 
282
      ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
287
283
      if(ret != 1){
288
 
        proc_id = 0;
 
284
        maxvalue = 0;
289
285
      }
290
286
      fclose(pidfile);
291
287
    }
292
288
  }
293
289
  /* Look for a plymouth process */
294
 
  if(proc_id == 0){
 
290
  if(maxvalue == 0){
295
291
    struct dirent **direntries = NULL;
296
292
    ret = scandir("/proc", &direntries, is_plymouth, alphasort);
297
 
    if(ret == -1){
 
293
    if (ret == -1){
298
294
      error_plus(0, errno, "scandir");
299
295
    }
300
 
    if(ret > 0){
301
 
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &proc_id);
302
 
      if(ret < 0){
 
296
    if (ret > 0){
 
297
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &maxvalue);
 
298
      if (ret < 0){
303
299
        error_plus(0, errno, "sscanf");
304
300
      }
305
301
    }
308
304
    free(direntries);
309
305
  }
310
306
  pid_t pid;
311
 
  pid = (pid_t)proc_id;
312
 
  if((uintmax_t)pid == proc_id){
 
307
  pid = (pid_t)maxvalue;
 
308
  if((uintmax_t)pid == maxvalue){
313
309
    return pid;
314
310
  }
315
311
  
316
312
  return 0;
317
313
}
318
314
 
319
 
const char * const * getargv(pid_t pid){
 
315
const char **getargv(pid_t pid){
320
316
  int cl_fd;
321
317
  char *cmdline_filename;
322
318
  ssize_t sret;
383
379
    return NULL;
384
380
  }
385
381
  argz_extract(cmdline, cmdline_len, argv); /* Create argv */
386
 
  return (const char * const *)argv;
 
382
  return (const char **)argv;
387
383
}
388
384
 
389
385
int main(__attribute__((unused))int argc,
464
460
  }
465
461
  kill_and_wait(plymouth_command_pid);
466
462
  
467
 
  const char * const *plymouthd_argv;
 
463
  const char **plymouthd_argv;
468
464
  pid_t pid = get_pid();
469
465
  if(pid == 0){
470
466
    error_plus(0, 0, "plymouthd pid not found");