/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: Björn Påhlsson
  • Date: 2011-10-02 19:18:24 UTC
  • mto: This revision was merged to the branch mainline in revision 505.
  • Revision ID: belorn@fukt.bsnet.se-20111002191824-eweh4pvneeg3qzia
transitional stuff actually working
documented change to D-Bus API

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