/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 plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2011-12-31 20:07:11 UTC
  • mfrom: (535.1.9 wireless-network-hook)
  • Revision ID: teddy@recompile.se-20111231200711-6dli3r8drftem57r
Merge new wireless network hook.  Fix bridge network hook to use
hardware addresses instead of interface names.  Implement and document
new "CONNECT" environment variable for network hooks.

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-2010 Teddy Hogeborn
6
 
 * Copyright © 2008-2010 Björn Påhlsson
 
5
 * Copyright © 2008-2011 Teddy Hogeborn
 
6
 * Copyright © 2008-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
171
171
}
172
172
 
173
173
/* Helper function for add_argument and add_environment */
 
174
__attribute__((nonnull))
174
175
static bool add_to_char_array(const char *new, char ***array,
175
176
                              int *len){
176
177
  /* Resize the pointed-to array to hold one more pointer */
199
200
}
200
201
 
201
202
/* Add to a plugin's argument vector */
 
203
__attribute__((nonnull(2)))
202
204
static bool add_argument(plugin *p, const char *arg){
203
205
  if(p == NULL){
204
206
    return false;
207
209
}
208
210
 
209
211
/* Add to a plugin's environment */
 
212
__attribute__((nonnull(2)))
210
213
static bool add_environment(plugin *p, const char *def, bool replace){
211
214
  if(p == NULL){
212
215
    return false;
286
289
}
287
290
 
288
291
/* Prints out a password to stdout */
 
292
__attribute__((nonnull))
289
293
static bool print_out_password(const char *buffer, size_t length){
290
294
  ssize_t ret;
291
295
  for(size_t written = 0; written < length; written += (size_t)ret){
299
303
}
300
304
 
301
305
/* Removes and free a plugin from the plugin list */
 
306
__attribute__((nonnull))
302
307
static void free_plugin(plugin *plugin_node){
303
308
  
304
309
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
416
421
    { .name = NULL }
417
422
  };
418
423
  
 
424
  __attribute__((nonnull(3)))
419
425
  error_t parse_opt(int key, char *arg, struct argp_state *state){
420
426
    errno = 0;
421
427
    switch(key){
422
428
      char *tmp;
423
 
      intmax_t tmpmax;
 
429
      intmax_t tmp_id;
424
430
    case 'g':                   /* --global-options */
425
431
      {
426
432
        char *plugin_option;
499
505
      /* This is already done by parse_opt_config_file() */
500
506
      break;
501
507
    case 130:                   /* --userid */
502
 
      tmpmax = strtoimax(arg, &tmp, 10);
 
508
      tmp_id = strtoimax(arg, &tmp, 10);
503
509
      if(errno != 0 or tmp == arg or *tmp != '\0'
504
 
         or tmpmax != (uid_t)tmpmax){
 
510
         or tmp_id != (uid_t)tmp_id){
505
511
        argp_error(state, "Bad user ID number: \"%s\", using %"
506
512
                   PRIdMAX, arg, (intmax_t)uid);
507
513
        break;
508
514
      }
509
 
      uid = (uid_t)tmpmax;
 
515
      uid = (uid_t)tmp_id;
510
516
      break;
511
517
    case 131:                   /* --groupid */
512
 
      tmpmax = strtoimax(arg, &tmp, 10);
 
518
      tmp_id = strtoimax(arg, &tmp, 10);
513
519
      if(errno != 0 or tmp == arg or *tmp != '\0'
514
 
         or tmpmax != (gid_t)tmpmax){
 
520
         or tmp_id != (gid_t)tmp_id){
515
521
        argp_error(state, "Bad group ID number: \"%s\", using %"
516
522
                   PRIdMAX, arg, (intmax_t)gid);
517
523
        break;
518
524
      }
519
 
      gid = (gid_t)tmpmax;
 
525
      gid = (gid_t)tmp_id;
520
526
      break;
521
527
    case 132:                   /* --debug */
522
528
      debug = true;
742
748
    }
743
749
  }
744
750
  
745
 
  {
 
751
  if(getuid() == 0){
746
752
    /* Work around Debian bug #633582:
747
753
       <http://bugs.debian.org/633582> */
748
754
    int plugindir_fd = open(/* plugindir or */ PDIR, O_RDONLY);