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

  • Committer: Teddy Hogeborn
  • Date: 2008-07-21 01:50:31 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080721015031-ivjiclli2j06hwgs
* Makefile: Include targets for all binaries.

* plugins.d/Makefile: Do nothing but call the parent Makefile.

* server.py: Added copyright statement and information.
  (Client.__init__): Added doc string.
  (Client.stop): Bug fix: Only log message if stopping for the first
                 time.  Check if the "stop_initiator_tag" and
                 "checker_initiator_tag" attributes exist before using
                 them.
  (Client.__del__): Call self.stop() instead of doing things here.
  (Client.checker_callback): Set self.checker_callback_tag and
                             self.checker to None unconditionally and
                             immediately.
  (Client.stop_checker): Added some checks to handle multiple calls.
  (tcp_handler.handle): Use "self.server.clients" instead of "clients".
  (__main__): Moved all code to the "main" function.
  (main): New.  New option "--address".  Instantiate IPv6_TCPServer
          with "options.address".  Log before starting main loop.
  (main.cleanup) Use "clients.pop()" to remove clients from the set as
                 they are stopped.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
2
 
/*
3
 
 * Mandos plugin runner - Run Mandos plugins
4
 
 *
5
 
 * Copyright © 2007-2008 Teddy Hogeborn and Björn Påhlsson.
6
 
 * 
7
 
 * This program is free software: you can redistribute it and/or
8
 
 * modify it under the terms of the GNU General Public License as
9
 
 * published by the Free Software Foundation, either version 3 of the
10
 
 * License, or (at your option) any later version.
11
 
 * 
12
 
 * This program is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * General Public License for more details.
16
 
 * 
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program.  If not, see
19
 
 * <http://www.gnu.org/licenses/>.
20
 
 * 
21
 
 * Contact the authors at <https://www.fukt.bsnet.se/~belorn/> and
22
 
 * <https://www.fukt.bsnet.se/~teddy/>.
23
 
 */
24
 
 
25
 
#define _FORTIFY_SOURCE 2
26
 
 
27
1
#include <stdio.h>      /* popen, fileno */
28
2
#include <iso646.h>     /* and, or, not */
29
3
#include <sys/types.h>  /* DIR, opendir, stat, struct stat, waitpid,
33
7
#include <sys/stat.h>   /* stat, struct stat */
34
8
#include <unistd.h>     /* stat, struct stat, chdir */
35
9
#include <stdlib.h>     /* EXIT_FAILURE */
36
 
#include <sys/select.h> /* fd_set, select, FD_ZERO, FD_SET,
37
 
                           FD_ISSET */
 
10
#include <sys/select.h> /* fd_set, select, FD_ZERO, FD_SET, FD_ISSET */
38
11
#include <string.h>     /* strlen, strcpy, strcat */
39
12
#include <stdbool.h>    /* true */
40
13
#include <sys/wait.h>   /* waitpid, WIFEXITED, WEXITSTATUS */
46
19
  pid_t pid;
47
20
  int fd;
48
21
  char *buffer;
49
 
  size_t buffer_size;
50
 
  size_t buffer_length;
 
22
  int buffer_size;
 
23
  int buffer_length;
51
24
  struct process *next;
52
25
} process;
53
26
 
107
80
        close(pipefd[0]);       /* close unused read end of pipe */
108
81
        dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
109
82
        /* create a new modified argument list */
110
 
        char **new_argv = malloc(sizeof(char *)
111
 
                                 * ((unsigned int) argc + 1));
 
83
        char **new_argv = malloc(sizeof(char *) * (argc + 1));
112
84
        new_argv[0] = filename;
113
85
        for(int i = 1; i < argc; i++){
114
86
          new_argv[i] = argv[i];
159
131
               > process_itr->buffer_size){
160
132
                process_itr->buffer = realloc(process_itr->buffer,
161
133
                                              process_itr->buffer_size
162
 
                                              + (size_t) BUFFER_SIZE);
 
134
                                              + BUFFER_SIZE);
163
135
                if (process_itr->buffer == NULL){
164
136
                  perror(argv[0]);
165
137
                  goto end;
168
140
            }
169
141
            ret = read(process_itr->fd, process_itr->buffer
170
142
                       + process_itr->buffer_length, BUFFER_SIZE);
171
 
            if(ret < 0){
172
 
              /* Read error from this process; ignore it */
173
 
              continue;
174
 
            }
175
 
            process_itr->buffer_length += (size_t) ret;
 
143
            process_itr->buffer_length+=ret;
176
144
            if(ret == 0){
177
145
              /* got EOF */
178
146
              /* wait for process exit */