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

  • Committer: Teddy Hogeborn
  • Date: 2008-08-01 06:33:15 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080801063315-4k33q3ek28hjc3tu
* plugins.d/plugbasedclient.c: Update include file comments.
  (struct process.disable): Renamed to "disabled".  All users changed.
  (addarguments): Renamed to "addargument".  All callers changed.
  (doc, args_doc): Removed.
  (main): Changed default "plugindir" to
          "/conf/conf.d/mandos/plugins.d".  Renamed "rfds_orig" to
           "rfds_all"; all users changed.  New "debug" and
           "exitstatus" variables.  New "--debug" option.  Removed
           unnecessary ".flags = 0" from all options.  Changed so that
           "--disable-plugin" only takes one plugin.  Check for
           non-existence of ":" in argument to "--options-for".  Added
           some debugging outputs.  Set the FD_CLOEXEC flag on the
           directory FD.  More capable code for dealing with
           disallowed plugin file name prefixes and suffixes.  Bug
           fix: check for some malloc failures.  Moved allocating the
           "struct process *new_process" to after the fork.  Do
           _exit() instead of exit() in the child.

* plugins.d/mandosclient.c: Updated contact information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
  p->argv[p->argc] = NULL;
107
107
}
108
108
 
109
 
/*
110
 
 * Based on the example in the GNU LibC manual chapter 13.13 "File
111
 
 * Descriptor Flags".
112
 
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
113
 
 */
114
 
int set_cloexec_flag(int fd)
115
 
{
116
 
  int ret = fcntl(fd, F_GETFD, 0);
117
 
  /* If reading the flags failed, return error indication now. */
118
 
  if(ret < 0){
119
 
    return ret;
120
 
  }
121
 
  /* Store modified flag word in the descriptor. */
122
 
  return fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
123
 
}
124
 
 
125
 
 
126
109
#define BUFFER_SIZE 256
127
110
 
128
111
const char *argp_program_version =
221
204
  if(debug){
222
205
    for(plugin *p = plugin_list; p != NULL; p=p->next){
223
206
      fprintf(stderr, "Plugin: %s has %d arguments\n",
224
 
              p->name ? p->name : "Global", p->argc - 1);
 
207
              p->name ? p->name : "Global", p->argc);
225
208
      for(char **a = p->argv; *a != NULL; a++){
226
209
        fprintf(stderr, "\tArg: %s\n", *a);
227
210
      }
229
212
  }
230
213
  
231
214
  dir = opendir(plugindir);
232
 
  /* Set the FD_CLOEXEC flag on the directory */
233
 
  ret = set_cloexec_flag(dirfd(dir));
234
 
  if(ret < 0){
235
 
    perror("set_cloexec_flag");
236
 
    goto end;
 
215
  {
 
216
    /* Set the FD_CLOEXEC flag on the directory */
 
217
    int fd = dirfd(dir);
 
218
    ret = fcntl (fd, F_GETFD, 0);
 
219
    if(ret < 0){
 
220
      perror("fcntl F_GETFD");
 
221
      goto end;
 
222
    }
 
223
    ret = fcntl(fd, F_SETFD, FD_CLOEXEC | ret);
 
224
    if(ret < 0){
 
225
      perror("fcntl F_SETFD");
 
226
      goto end;
 
227
    }
237
228
  }
238
229
  
239
230
  if(dir == NULL){
328
319
    int pipefd[2]; 
329
320
    ret = pipe(pipefd);
330
321
    if (ret == -1){
331
 
      perror("pipe");
 
322
      perror(argv[0]);
332
323
      goto end;
333
324
    }
334
 
    plugin *p = getplugin(dirst->d_name, &plugin_list);
335
 
    {
336
 
      /* Add global arguments to argument list for this plugin */
337
 
      plugin *g = getplugin(NULL, &plugin_list);
338
 
      for(char **a = g->argv + 1; *a != NULL; a++){
339
 
        addargument(p, *a);
340
 
      }
341
 
    }
342
325
    pid_t pid = fork();
343
326
    if(pid == 0){
344
327
      /* this is the child process */
345
328
      closedir(dir);
346
329
      close(pipefd[0]); /* close unused read end of pipe */
347
330
      dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
348
 
      if(pipefd[1] > 2){
349
 
        close(pipefd[1]);
 
331
      
 
332
      plugin *p = getplugin(dirst->d_name, &plugin_list);
 
333
      plugin *g = getplugin(NULL, &plugin_list);
 
334
      for(char **a = g->argv + 1; *a != NULL; a++){
 
335
        addargument(p, *a);
350
336
      }
351
 
      
352
337
      if(execv(filename, p->argv) < 0){
353
338
        perror(argv[0]);
354
339
        close(pipefd[1]);