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

« back to all changes in this revision

Viewing changes to openvasd/otp_1_0.c

  • Committer: Bazaar Package Importer
  • Author(s): Javier Fernandez-Sanguino Pen~a
  • Date: 2009-01-02 01:38:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090102013847-74xy2uo1e3hovqjo
Tags: 2.0.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* OpenVAS
 
2
* $Id$
 
3
* Description: Implements OpenVAS Transfer Protocol 1.0.
 
4
*
 
5
* Authors:
 
6
* Jan-Oliver Wagner <jan-oliver.wagner@intevation.de>
 
7
*
 
8
* Copyright:
 
9
* Copyright (C) 2008 Intevation GmbH
 
10
*
 
11
* This program is free software; you can redistribute it and/or modify
 
12
* it under the terms of the GNU General Public License version 2 or later,
 
13
* as published by the Free Software Foundation
 
14
*
 
15
* This program is distributed in the hope that it will be useful,
 
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
* GNU General Public License for more details.
 
19
*
 
20
* You should have received a copy of the GNU General Public License
 
21
* along with this program; if not, write to the Free Software
 
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
23
*
 
24
*/
 
25
 
 
26
#include <includes.h>
 
27
 
 
28
#include <string.h>
 
29
 
 
30
#include <corevers.h>
 
31
#include <network.h>
 
32
 
 
33
#include <nasl.h>
 
34
 
 
35
#include "otp_1_0.h"
 
36
 
 
37
#include <gpgme.h>
 
38
#include <glib.h>
 
39
 
 
40
/* Find the enum identifier for the client request which is given
 
41
 * as string.
 
42
 */
 
43
client_request_t otp_1_0_get_client_request(str)
 
44
  char * str;
 
45
{
 
46
  if (!strcmp(str, "ATTACHED_FILE")) return(CREQ_ATTACHED_FILE);
 
47
  if (!strcmp(str, "CERTIFICATES")) return(CREQ_CERTIFICATES);
 
48
  if (!strcmp(str, "LONG_ATTACK")) return(CREQ_LONG_ATTACK);
 
49
  if (!strcmp(str, "OPENVAS_VERSION")) return(CREQ_OPENVAS_VERSION);
 
50
  if (!strcmp(str, "PLUGIN_INFO")) return(CREQ_PLUGIN_INFO);
 
51
  if (!strcmp(str, "PREFERENCES")) return(CREQ_PREFERENCES);
 
52
  if (!strcmp(str, "RULES")) return(CREQ_RULES);
 
53
  if (!strcmp(str, "SESSIONS_LIST")) return(CREQ_SESSIONS_LIST);
 
54
  if (!strcmp(str, "SESSION_DELETE")) return(CREQ_SESSION_DELETE);
 
55
  if (!strcmp(str, "SESSION_RESTORE")) return(CREQ_SESSION_RESTORE);
 
56
  if (!strcmp(str, "STOP_ATTACK")) return(CREQ_STOP_ATTACK);
 
57
  if (!strcmp(str, "STOP_WHOLE_TEST")) return(CREQ_STOP_WHOLE_TEST);
 
58
 
 
59
  return(CREQ_UNKNOWN);
 
60
}
 
61
 
 
62
/* Send server response OPENVAS_VERSION
 
63
 */
 
64
void otp_1_0_server_openvas_version(globals)
 
65
  struct arglist * globals;
 
66
{
 
67
  auth_printf(globals,
 
68
              "SERVER <|> OPENVAS_VERSION <|> %s <|> SERVER\n",
 
69
              OPENVAS_VERSION);
 
70
}
 
71
 
 
72
 
 
73
/**
 
74
 * Send server response to certificate request by client.
 
75
 */
 
76
void otp_1_0_server_send_certificates(struct arglist* globals)
 
77
{
 
78
  auth_printf(globals, "SERVER <|> CERTIFICATES\n");
 
79
 
 
80
  GSList* certificates = nasl_get_all_certificates();
 
81
  GSList* cert_list_elem = g_slist_nth(certificates, 0);
 
82
 
 
83
  // Iterate over certificates
 
84
  while(cert_list_elem != NULL)
 
85
    {
 
86
      openvas_certificate* cert = cert_list_elem->data;
 
87
      
 
88
      // Replace newlines by semicolons
 
89
      char* pos = cert->full_public_key;
 
90
      while(pos[0] != '\0')
 
91
        {
 
92
        if(pos[0] == '\n') pos[0] = ';';
 
93
        pos++;
 
94
        }
 
95
 
 
96
      char* trustlevel = (cert->trusted == TRUE)? "trusted" : "notrust";
 
97
      cert_list_elem = g_slist_next(cert_list_elem);
 
98
      auth_printf(globals, "%s <|> %s <|> %s <|> %d <|> %s\n", cert->fpr,
 
99
                              cert->ownername, trustlevel,
 
100
                              (int)strlen(cert->full_public_key),
 
101
                              cert->full_public_key);
 
102
      // Release each element
 
103
      openvas_certificate_free(cert);
 
104
    }
 
105
  
 
106
  // Release list
 
107
  g_slist_free(certificates);
 
108
  
 
109
  auth_printf(globals, "<|> SERVER\n");
 
110
}