~ubuntu-branches/ubuntu/jaunty/openvas-server/jaunty

« back to all changes in this revision

Viewing changes to openvasd/piic.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Schulze
  • Date: 2008-12-13 16:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20081213164640-och5em54157kbth8
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* OpenVAS
 
2
* $Id: piic.c 140 2006-05-31 15:24:25Z tarik $
 
3
* Description: Reads from plugin output pipe, writes to arglist.
 
4
*
 
5
* Authors: - Renaud Deraison <deraison@nessus.org> (Original pre-fork develoment)
 
6
*          - Tim Brown <mailto:timb@openvas.org> (Initial fork)
 
7
*          - Laban Mwangi <mailto:labanm@openvas.org> (Renaming work)
 
8
*          - Tarik El-Yassem <mailto:tarik@openvas.org> (Headers section)
 
9
*
 
10
* Copyright:
 
11
* Portions Copyright (C) 2006 Software in the Public Interest, Inc.
 
12
* Based on work Copyright (C) 1998 - 2006 Tenable Network Security, Inc.
 
13
*
 
14
* This program is free software; you can redistribute it and/or modify
 
15
* it under the terms of the GNU General Public License version 2,
 
16
* as published by the Free Software Foundation
 
17
*
 
18
* This program is distributed in the hope that it will be useful,
 
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
* GNU General Public License for more details.
 
22
*
 
23
* You should have received a copy of the GNU General Public License
 
24
* along with this program; if not, write to the Free Software
 
25
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
26
*
 
27
*
 
28
*/
 
29
 
 
30
 
 
31
#include <includes.h>
 
32
#include "log.h"
 
33
#include "save_kb.h"
 
34
#include "utils.h"
 
35
#include "piic.h"
 
36
 
 
37
 
 
38
void kb_parse(int soc, struct arglist * globals, struct kb_item ** kb, char * buf, int msg )
 
39
{
 
40
 char * t;
 
41
 int type;
 
42
 char *c;
 
43
 int buf_len;
 
44
 char * copy;
 
45
 char * name;
 
46
 char * value;
 
47
 
 
48
 if( buf == NULL || kb == NULL )
 
49
  return;
 
50
 
 
51
 if ( msg & INTERNAL_COMM_KB_GET )
 
52
 { 
 
53
  struct kb_item * kitem = kb_item_get_single(kb, buf, 0);
 
54
 
 
55
  if ( kitem == NULL )
 
56
  {
 
57
   internal_send(soc, NULL, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_ERROR);
 
58
   return;
 
59
  }
 
60
 
 
61
  if ( kitem->type == KB_TYPE_STR  )
 
62
  {
 
63
   internal_send(soc, kitem->v.v_str, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_SENDING_STR);
 
64
   return;
 
65
  }
 
66
  else  if ( kitem->type == KB_TYPE_INT )
 
67
  {
 
68
   char buf[64];
 
69
   snprintf(buf, sizeof(buf), "%d", kitem->v.v_int);
 
70
   internal_send(soc, buf, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_SENDING_INT);
 
71
  }
 
72
  else 
 
73
   internal_send(soc, NULL, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_ERROR);
 
74
  return;       
 
75
 }
 
76
  
 
77
 if ( buf[0] == '\0' ) 
 
78
    return;
 
79
    
 
80
 buf_len = strlen(buf);
 
81
  
 
82
 if(buf[buf_len - 1]=='\n')
 
83
        buf[ buf_len - 1 ]='\0';
 
84
        
 
85
 c = strrchr(buf, ';');
 
86
 if(c != NULL )
 
87
    c[0] = '\0';
 
88
    
 
89
 t = strchr(buf, ' ');
 
90
 if( t == NULL )
 
91
    return;
 
92
 
 
93
 t[0] = '\0';
 
94
 type = atoi(buf);
 
95
 t[0] = ' ';
 
96
 
 
97
 
 
98
  value = strchr(buf, '=');
 
99
    
 
100
  if( value == NULL )
 
101
        return;
 
102
        
 
103
  value[0]='\0';
 
104
  value++;
 
105
  
 
106
  name = t+1;
 
107
  
 
108
  if ( type == ARG_INT )
 
109
  { 
 
110
   int v = atoi(value);
 
111
   if ( msg & INTERNAL_COMM_KB_REPLACE )
 
112
        kb_item_set_int(kb, name,v);
 
113
    else
 
114
        {
 
115
        kb_item_add_int(kb, name,v);
 
116
        if(save_kb(globals))save_kb_write_int(globals, arg_get_value(globals, "CURRENTLY_TESTED_HOST"), name,v);   
 
117
        }
 
118
  }
 
119
  else
 
120
  {
 
121
   copy = rmslashes(value);
 
122
   if ( msg & INTERNAL_COMM_KB_REPLACE )
 
123
        kb_item_set_str(kb, name, copy);
 
124
   else
 
125
        {
 
126
        kb_item_add_str(kb, name, copy);
 
127
        if(save_kb(globals))save_kb_write_str(globals, arg_get_value(globals, "CURRENTLY_TESTED_HOST"), name, copy);
 
128
        }
 
129
   efree(&copy);
 
130
  }
 
131
}
 
132
 
 
133