Skip to content

Commit

Permalink
Merge branch 'master' of github.com:greenbone/gvm into bulk-tag-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier committed Aug 22, 2019
2 parents 65fd58e + 1f0d7c9 commit 3dacfdb
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 754 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- checkout
- run:
name: Check Source Format
command: clang-format -i -style=file src/gmp.h src/gmp_base.h src/gmp_delete.h src/gmp_get.h src/gmp_tickets.h src/gmpd.h src/iterator.h src/manage_utils.h src/scanner.h src/sql.h src/types.h src/utils.h && git diff --exit-code
command: clang-format -i -style=file src/gmp.h src/gmp_base.h src/gmp_delete.h src/gmp_get.h src/gmp_tickets.h src/gmpd.h src/iterator.h src/manage_utils.h src/sql.h src/types.h src/utils.h && git diff --exit-code
test_units:
docker:
- image: greenbone/build-env-gvm-master-debian-stretch-gcc-postgresql
Expand Down
9 changes: 4 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ add_executable (manage-utils-test
manage_sql_configs.c
manage_sql_tickets.c manage_sql_tls_certificates.c
manage_tls_certificates.c
manage_migrators.c scanner.c
manage_migrators.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
Expand All @@ -112,7 +112,7 @@ add_executable (manage-test
manage_sql_configs.c
manage_sql_tickets.c manage_sql_tls_certificates.c
manage_tls_certificates.c
manage_migrators.c scanner.c
manage_migrators.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
Expand All @@ -136,7 +136,7 @@ add_executable (gmp-tickets-test
manage_sql_configs.c
manage_sql_tickets.c manage_sql_tls_certificates.c
manage_tls_certificates.c
manage_migrators.c scanner.c
manage_migrators.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
Expand All @@ -160,7 +160,7 @@ add_executable (gvmd
manage_sql_configs.c
manage_sql_tickets.c manage_sql_tls_certificates.c
manage_tls_certificates.c
manage_migrators.c scanner.c
manage_migrators.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
Expand Down Expand Up @@ -344,7 +344,6 @@ set (C_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gvmd.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_utils.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_acl.c"
"${CMAKE_CURRENT_SOURCE_DIR}/scanner.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_config_discovery.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_config_host_discovery.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_config_system_discovery.c"
Expand Down
105 changes: 26 additions & 79 deletions src/gmpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*/

#include "gmpd.h"
#include "scanner.h"
#include "gmp.h"

#include <assert.h>
Expand Down Expand Up @@ -121,7 +120,6 @@ init_gmpd (GSList *log_config, const gchar *database,
void
init_gmpd_process (const gchar *database, gchar **disable)
{
openvas_scanner_fork ();
from_client_start = 0;
from_client_end = 0;
init_gmp_process (0, database, NULL, NULL, disable);
Expand Down Expand Up @@ -437,6 +435,19 @@ session_clean (gvm_connection_t *client_connection)
}
}

/**
* @brief Get nfds value.
*
* @param[in] socket Highest socket number.
*
* @return nfds value for select.
*/
static int
get_nfds (int socket)
{
return 1 + socket;
}

/**
* @brief Serve the Greenbone Management Protocol (GMP).
*
Expand All @@ -450,9 +461,8 @@ session_clean (gvm_connection_t *client_connection)
*
* \if STATIC
*
* Read input with \ref read_from_client and \ref openvas_scanner_read.
* Write the results with \ref write_to_client. Write to the server
* with \ref openvas_scanner_write.
* Read input with \ref read_from_client.
* Write the results with \ref write_to_client.
*
* \endif
*
Expand All @@ -470,7 +480,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
{
int nfds, scan_handler = 0, rc = 0;
/* True if processing of the client input is waiting for space in the
* to_scanner or to_client buffer. */
* to_client buffer. */
short client_input_stalled;
/* Client status flag. Set to 0 when the client closes the connection
* while the scanner is active. */
Expand All @@ -496,15 +506,11 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
*
* That is, select on all the socket fds and then, as necessary
* - read from the client into buffer from_client
* - write to the scanner from buffer to_scanner
* - read from the scanner into buffer from_scanner
* - write to the client from buffer to_client.
*
* On reading from an fd, immediately try react to the input. On reading
* from the client call process_gmp_client_input, which parses GMP
* commands and may write to to_scanner and to_client. On reading from
* the scanner call process_otp_scanner_input, which updates information
* kept about the scanner.
* commands and may write to to_client.
*
* There are a few complications here
* - the program must read from or write to an fd returned by select
Expand All @@ -513,17 +519,13 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
* something to write,
* - similarly, the program need only select on the fds for reading
* if there is buffer space available,
* - the buffers from_client and from_scanner can become full during
* reading
* - a read from the client can be stalled by the to_scanner buffer
* filling up, or the to_client buffer filling up (in which case
* process_gmp_client_input will try to write the to_client buffer
* itself),
* - a read from the scanner can, theoretically, be stalled by the
* to_scanner buffer filling up (during initialisation).
* - the buffers from_client can become full during reading
* - a read from the client can be stalled by the to_client buffer
* filling up (in which case process_gmp_client_input will try to
* write the to_client buffer itself),
*/

nfds = openvas_scanner_get_nfds (client_connection->socket);
nfds = get_nfds (client_connection->socket);
while (1)
{
int ret;
Expand All @@ -536,11 +538,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
__FUNCTION__,
sys_siglist[get_termination_signal()]);

if (openvas_scanner_connected ())
{
openvas_scanner_close ();
}

goto client_free;
}

Expand Down Expand Up @@ -580,25 +577,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
ret++;
FD_SET (client_connection->socket, &readfds);
}
if (openvas_scanner_fd_isset (&readfds))
{
if (openvas_scanner_session_peek ())
{
if (!ret)
{
FD_ZERO (&readfds);
FD_ZERO (&writefds);
}
ret++;
openvas_scanner_fd_set (&readfds);
}
else if (openvas_scanner_peek () == 0)
{
/* Scanner has gone down. Exit. */
rc = -1;
goto client_free;
}
}

if (!ret)
{
Expand Down Expand Up @@ -675,8 +653,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
{
/* In the parent after a start_task fork. Free the scanner session
* without closing it, for usage by the child process. */
openvas_scanner_free ();
nfds = openvas_scanner_get_nfds (client_connection->socket);
nfds = get_nfds (client_connection->socket);
client_input_stalled = 0;
/* Skip the rest of the loop because the scanner socket is
* a new socket. This is asking for select trouble, really. */
Expand Down Expand Up @@ -740,35 +717,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
}
}

/* Read any data from the scanner. */
if (openvas_scanner_connected ()
&& (openvas_scanner_fd_isset (&readfds) || scan_handler))
{
switch (openvas_scanner_read ())
{
case 0: /* Read everything. */
break;
case -1: /* Error. */
/* This may be because the scanner closed the connection
* at the end of a command. */
/** @todo Then should get EOF (-3). */
rc = -1;
goto client_free;
case -2: /* from_scanner buffer full. */
/* There may be more to read. */
break;
case -3: /* End of file. */
if (client_active == 0)
/* The client has closed the connection, so exit. */
return 0;
/* Scanner went down, exit. */
rc = -1;
goto client_free;
default: /* Programming error. */
assert (0);
}
}

/* Write any data to the client. */
if (client_connection->socket > 0
&& FD_ISSET (client_connection->socket, &writefds))
Expand All @@ -791,8 +739,8 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,

if (client_input_stalled)
{
/* Try process the client input, in case writing to the scanner
* or client has freed some space in to_scanner or to_client. */
/* Try process the client input, in case writing to the client
* has freed some space in to_client. */

ret = process_gmp_client_input ();
if (ret == 0)
Expand All @@ -802,8 +750,7 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
{
/* In the parent after a start_task fork. Free the scanner session
* without closing it, for usage by the child process. */
openvas_scanner_free ();
nfds = openvas_scanner_get_nfds (client_connection->socket);
nfds = get_nfds (client_connection->socket);
/* Skip the rest of the loop because the scanner socket is
* a new socket. This is asking for select trouble, really. */
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/gmpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#endif

/**
* @brief Size of \ref from_client and \ref from_scanner data buffers, in bytes.
* @brief Size of \ref from_client data buffers, in bytes.
*/
#define FROM_BUFFER_SIZE 1048576

Expand Down
1 change: 0 additions & 1 deletion src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@

#include "manage.h"
#include "manage_sql_secinfo.h"
#include "scanner.h"
#include "gmpd.h"
#include "utils.h"

Expand Down
44 changes: 10 additions & 34 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

/**
* @file manage.c
* @brief The Greenbone Vulnerability Manager management library.
* @brief The Greenbone Vulnerability Manager management layer.
*
* This file defines a management library, for implementing
* This file defines a management layer, for implementing
* Managers such as the Greenbone Vulnerability Manager daemon.
*
* This library provides facilities for storing and manipulating credential
* and task information, and manipulating reports. Task manipulation
* includes sending task commands to the OTP server (the "scanner") that is
* running the tasks.
* This layer provides facilities for storing and manipulating user
* data (credentials, targets, tasks, reports, schedules, roles, etc)
* and general security data (NVTs, CVEs, etc).
* Task manipulation includes controlling external facilities such as
* OSP scanners.
*
* Simply put, the daemon's GMP implementation uses this layer to do the work.
*/

/**
Expand All @@ -45,7 +48,6 @@
#define _GNU_SOURCE

#include "manage.h"
#include "scanner.h"
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_secinfo.h"
Expand Down Expand Up @@ -4503,33 +4505,7 @@ run_cve_task (task_t task)
}


/* OTP tasks. */

/**
* @brief Initialise OpenVAS scanner variables, checking for defaults.
*
* @param[in] ca_pub CA Certificate.
* @param[in] key_pub Scanner Certificate.
* @param[in] key_priv Scanner private key.
*
* @return 0 success, 1 both default CA cert setting and ca_pub were NULL.
*/
int
set_certs (const char *ca_pub, const char *key_pub, const char *key_priv)
{
const char *fallback;

if (ca_pub == NULL)
fallback = manage_default_ca_cert ();
else
fallback = NULL;

openvas_scanner_set_certs (fallback ? fallback : ca_pub, key_pub, key_priv);

if (ca_pub || fallback)
return 0;
return 1;
}
/* Tasks. */

/**
* @brief Initialise variables required for running a scan.
Expand Down
3 changes: 0 additions & 3 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3911,9 +3911,6 @@ manage_user_uuid (const gchar *, auth_method_t);
int
manage_user_exists (const gchar *, auth_method_t);

int
manage_scanner_set_default ();

int
copy_user (const char*, const char*, const char*, user_t*);

Expand Down
Loading

0 comments on commit 3dacfdb

Please sign in to comment.