/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 22:51:46 UTC
  • mfrom: (15.1.4 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080721225146-55gbo7fqocy4m930
* plugins.d/mandosclient.c (pgp_packet_decrypt): Cast "0" argument to
                                                 gpgme_data_seek.
 (start_mandos_communication): Change "ip" arg to "const char *".  New
                               variable "written".  Remove setsockopt.
                               Bug fix: Do not change decrypted_buffer.
 (resolve_callback): Removed AVAHI_GCC_UNUSED from "interface".

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
 
1
27
#include <stdio.h>      /* popen, fileno */
2
28
#include <iso646.h>     /* and, or, not */
3
29
#include <sys/types.h>  /* DIR, opendir, stat, struct stat, waitpid,
7
33
#include <sys/stat.h>   /* stat, struct stat */
8
34
#include <unistd.h>     /* stat, struct stat, chdir */
9
35
#include <stdlib.h>     /* EXIT_FAILURE */
10
 
#include <sys/select.h> /* fd_set, select, FD_ZERO, FD_SET, FD_ISSET */
 
36
#include <sys/select.h> /* fd_set, select, FD_ZERO, FD_SET,
 
37
                           FD_ISSET */
11
38
#include <string.h>     /* strlen, strcpy, strcat */
12
39
#include <stdbool.h>    /* true */
13
40
#include <sys/wait.h>   /* waitpid, WIFEXITED, WEXITSTATUS */
19
46
  pid_t pid;
20
47
  int fd;
21
48
  char *buffer;
22
 
  int buffer_size;
23
 
  int buffer_length;
 
49
  size_t buffer_size;
 
50
  size_t buffer_length;
24
51
  struct process *next;
25
52
} process;
26
53
 
60
87
        or dirst->d_name[d_name_len - 1] == '~'){
61
88
      continue;
62
89
    }
63
 
    
64
 
    char *filename = malloc(d_name_len + plugindir_len + 1);
 
90
 
 
91
    char *filename = malloc(d_name_len + plugindir_len + 2);
65
92
    strcpy(filename, plugindir);
66
93
    strcat(filename, "/");
67
94
    strcat(filename, dirst->d_name);    
68
 
    
 
95
 
69
96
    stat(filename, &st);
70
97
 
71
98
    if (S_ISREG(st.st_mode) and (access(filename, X_OK) == 0)){
80
107
        close(pipefd[0]);       /* close unused read end of pipe */
81
108
        dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
82
109
        /* create a new modified argument list */
83
 
        char **new_argv = malloc(sizeof(char *) * argc + 1);
 
110
        char **new_argv = malloc(sizeof(char *)
 
111
                                 * ((unsigned int) argc + 1));
84
112
        new_argv[0] = filename;
85
113
        for(int i = 1; i < argc; i++){
86
114
          new_argv[i] = argv[i];
131
159
               > process_itr->buffer_size){
132
160
                process_itr->buffer = realloc(process_itr->buffer,
133
161
                                              process_itr->buffer_size
134
 
                                              + BUFFER_SIZE);
 
162
                                              + (size_t) BUFFER_SIZE);
135
163
                if (process_itr->buffer == NULL){
136
164
                  perror(argv[0]);
137
165
                  goto end;
140
168
            }
141
169
            ret = read(process_itr->fd, process_itr->buffer
142
170
                       + process_itr->buffer_length, BUFFER_SIZE);
143
 
            process_itr->buffer_length+=ret;
 
171
            if(ret < 0){
 
172
              /* Read error from this process; ignore it */
 
173
              continue;
 
174
            }
 
175
            process_itr->buffer_length += (size_t) ret;
144
176
            if(ret == 0){
145
177
              /* got EOF */
146
178
              /* wait for process exit */