27 #include "../base/hosts.h" 28 #include "../util/serverutils.h" 29 #include "../util/xmlutils.h" 32 #include <gnutls/gnutls.h> 36 #include <sys/socket.h> 44 #define G_LOG_DOMAIN "lib osp" 72 __attribute__ ((__format__ (__printf__, 3, 4)));
87 const
char *cert, const
char *key)
91 if (host && *host ==
'/')
93 struct sockaddr_un addr;
96 connection = g_malloc0 (
sizeof (*connection));
97 connection->
socket = socket (AF_UNIX, SOCK_STREAM, 0);
98 if (connection->
socket == -1)
101 addr.sun_family = AF_UNIX;
102 strncpy (addr.sun_path, host, sizeof (addr.sun_path) - 1);
103 len = strlen (addr.sun_path) +
sizeof (addr.sun_family);
104 if (connect (connection->
socket, (
struct sockaddr *) &addr, len) == -1)
106 close (connection->
socket);
112 if (port <= 0 || port > 65535)
116 if (!cert || !key || !cacert)
119 connection = g_malloc0 (
sizeof (*connection));
121 &connection->
session, host, port, cacert, cert, key);
123 if (connection->
socket == -1)
129 connection->
host = g_strdup (host);
130 connection->
port = port;
145 const char *fmt, ...)
152 if (!connection || !fmt || !response)
155 if (*connection->
host ==
'/')
189 if (*connection->
host ==
'/')
190 close (connection->
socket);
193 g_free (connection->
host);
212 char **d_name,
char **d_version,
char **p_name,
225 goto err_get_version;
228 goto err_get_version;
233 goto err_get_version;
239 goto err_get_version;
242 goto err_get_version;
247 goto err_get_version;
253 goto err_get_version;
256 goto err_get_version;
261 goto err_get_version;
269 g_warning (
"Erroneous OSP <get_version/> response.");
312 if (strcmp (status,
"200"))
332 char **report_xml,
int details,
char **error)
341 "<get_scans scan_id='%s' details='%d'/>", scan_id,
346 *error = g_strdup (
"Couldn't send get_scans command to scanner");
357 *error = g_strdup (text);
366 string = g_string_new (
"");
368 *report_xml = g_string_free (
string, FALSE);
396 *error = g_strdup (
"Couldn't send stop_scan command to scanner");
412 *error = g_strdup (text);
429 char *options_str, *tmp, *key_escaped, *value_escaped;
431 options_str = *(
char **) pstr;
433 key_escaped = g_markup_escape_text ((
char *) key, -1);
434 value_escaped = g_markup_escape_text ((
char *) value, -1);
435 tmp = g_strdup_printf (
"%s<%s>%s</%s>", options_str ? options_str :
"",
436 key_escaped, value_escaped, key_escaped);
438 g_free (options_str);
439 g_free (key_escaped);
440 g_free (value_escaped);
441 *(
char **) pstr = tmp;
458 const char *ports, GHashTable *options,
const char *scan_id,
462 char *options_str = NULL;
473 "<start_scan target='%s' ports='%s' scan_id='%s'>" 474 "<scanner_params>%s</scanner_params></start_scan>",
475 target, ports ? ports :
"", scan_id ? scan_id :
"",
476 options_str ? options_str :
"");
477 g_free (options_str);
481 *error = g_strdup (
"Couldn't send start_scan command to scanner");
497 *error = g_strdup (text);
514 if (!strcmp (str,
"integer"))
516 else if (!strcmp (str,
"string"))
518 else if (!strcmp (str,
"password"))
520 else if (!strcmp (str,
"file"))
522 else if (!strcmp (str,
"boolean"))
524 else if (!strcmp (str,
"ovaldef_file"))
526 else if (!strcmp (str,
"selection"))
528 else if (!strcmp (str,
"credential_up"))
559 return "ovaldef_file";
563 return "credential_up";
601 child = entities->data;
613 *params = g_slist_append (*params, param);
725 g_free (param->
name);
726 g_free (param->
desc);
Struct holding options for OSP parameters.
Struct holding options for OSP connection.
void osp_param_free(osp_param_t *param)
Free an OSP parameter.
osp_param_t * osp_param_new(void)
Create a new OSP parameter.
osp_param_type_t
OSP parameter types.
int osp_get_scanner_details(osp_connection_t *connection, char **desc, GSList **params)
Get an OSP scanner's details.
const char * osp_param_type_str(const osp_param_t *param)
Get an OSP parameter in string format form its type.
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
API for Open Scanner Protocol communication.
void print_entity_to_string(entity_t entity, GString *string)
Print an XML entity tree to a GString, appending it if string is not.
int osp_get_version(osp_connection_t *connection, char **s_name, char **s_version, char **d_name, char **d_version, char **p_name, char **p_version)
Get the scanner version from an OSP server.
static int osp_send_command(osp_connection_t *, entity_t *, const char *,...)
Send a command to an OSP server.
static void option_concat_as_xml(gpointer key, gpointer value, gpointer pstr)
Concatenate options as xml.
int gvm_socket_vsendf(int socket, const char *fmt, va_list ap)
Send a string to the server.
entities_t entities
Children.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
const char * osp_param_name(const osp_param_t *param)
Get an OSP parameter's name.
const char * osp_param_desc(const osp_param_t *param)
Get an OSP parameter's description.
static osp_param_type_t osp_param_str_to_type(const char *str)
Get an OSP parameter's type from its string format.
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
int osp_stop_scan(osp_connection_t *connection, const char *scan_id, char **error)
Stop a scan on an OSP server.
int osp_delete_scan(osp_connection_t *connection, const char *scan_id)
Delete a scan from an OSP server.
int osp_param_mandatory(const osp_param_t *param)
Get an OSP parameter's mandatory value.
int read_entity_s(int socket, entity_t *entity)
Read an XML entity tree from the socket.
int osp_start_scan(osp_connection_t *connection, const char *target, const char *ports, GHashTable *options, const char *scan_id, char **error)
Start an OSP scan against a target.
void osp_connection_close(osp_connection_t *connection)
Close a connection to an OSP server.
int osp_get_scan(osp_connection_t *connection, const char *scan_id, char **report_xml, int details, char **error)
Get a scan from an OSP server.
char * entity_text(entity_t entity)
Get the text an entity.
const char * osp_param_id(const osp_param_t *param)
Get an OSP parameter's id.
int gvm_server_open_with_cert(gnutls_session_t *session, const char *host, int port, const char *ca_mem, const char *pub_mem, const char *priv_mem)
Connect to the server using a given host, port and cert.
int gvm_server_close(int socket, gnutls_session_t session)
Close a server connection and its socket.
int gvm_server_vsendf(gnutls_session_t *session, const char *fmt, va_list ap)
Send a string to the server.
void free_entity(entity_t entity)
Free an entity, recursively.
const char * osp_param_default(const osp_param_t *param)
Get an OSP parameter's default value.
GSList * entities_t
Entities.
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
osp_connection_t * osp_connection_new(const char *, int, const char *, const char *, const char *)