Skip to content

Commit

Permalink
Merge branch 'master' into compliance-types
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier authored Jul 10, 2019
2 parents 01e48f1 + 826a1e1 commit ddd3a1b
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 1,900 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/comm.h 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/otp.h src/scanner.h src/sql.h src/types.h src/utils.h src/comm.c && git diff --exit-code
command: clang-format -i -style=file src/comm.h 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 src/comm.c && git diff --exit-code
test_units:
docker:
- image: greenbone/build-env-gvm-master-debian-stretch-gcc-postgresql
Expand Down
5 changes: 0 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ add_executable (manage-utils-test
manage_migrators.c scanner.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c comm.c
otp.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
gmp_tickets.c gmp_tls_certificates.c)

Expand All @@ -114,7 +113,6 @@ add_executable (manage-test
manage_migrators.c scanner.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c comm.c
otp.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
gmp_tickets.c gmp_tls_certificates.c)

Expand All @@ -138,7 +136,6 @@ add_executable (gmp-tickets-test
manage_migrators.c scanner.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c comm.c
otp.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
gmp_tls_certificates.c)

Expand All @@ -162,7 +159,6 @@ add_executable (gvmd
manage_migrators.c scanner.c
sql_pg.c manage_pg.c
lsc_user.c lsc_crypt.c utils.c comm.c
otp.c
gmp.c gmp_base.c gmp_configs.c gmp_delete.c gmp_get.c
gmp_tickets.c gmp_tls_certificates.c)

Expand Down Expand Up @@ -341,7 +337,6 @@ set (C_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gvmd.c"
"${CMAKE_CURRENT_SOURCE_DIR}/gmp_configs.c"
"${CMAKE_CURRENT_SOURCE_DIR}/gmp_tickets.c"
"${CMAKE_CURRENT_SOURCE_DIR}/gmp_tls_certificates.c"
"${CMAKE_CURRENT_SOURCE_DIR}/otp.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_utils.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_acl.c"
Expand Down
2 changes: 0 additions & 2 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
#include "manage.h"
#include "manage_acl.h"
#include "utils.h"
/** @todo For access to scanner_t scanner. */
#include "otp.h"

#include <arpa/inet.h>
#include <assert.h>
Expand Down
27 changes: 10 additions & 17 deletions src/gmp_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,23 +354,16 @@ log_event_fail (const char *, const char *, const char *, const char *);
*
* @param tag Name of the command generating the response.
*/
#define SEND_XML_SERVICE_DOWN(tag) \
do \
{ \
char *str; \
if (scanner_current_loading && scanner_total_loading) \
str = \
g_strdup_printf ("<%s_response status='%s' " \
"status_text='Scanner loading nvts (%d/%d)'/>", \
tag, STATUS_SERVICE_DOWN, scanner_current_loading, \
scanner_total_loading); \
else \
str = \
g_strdup_printf ("<%s_response status='%s' status_text='%s'/>", tag, \
STATUS_SERVICE_DOWN, STATUS_SERVICE_DOWN_TEXT); \
SEND_TO_CLIENT_OR_FAIL (str); \
g_free (str); \
} \
#define SEND_XML_SERVICE_DOWN(tag) \
do \
{ \
char *str; \
str = \
g_strdup_printf ("<%s_response status='%s' status_text='%s'/>", tag, \
STATUS_SERVICE_DOWN, STATUS_SERVICE_DOWN_TEXT); \
SEND_TO_CLIENT_OR_FAIL (str); \
g_free (str); \
} \
while (0);

#endif /* not _GVMD_GMP_BASE_H */
119 changes: 3 additions & 116 deletions src/gmpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#include "gmpd.h"
#include "scanner.h"
#include "gmp.h"
/** @todo For scanner_init_state. */
#include "otp.h"
#include "comm.h"

#include <assert.h>
Expand Down Expand Up @@ -447,9 +445,9 @@ session_clean (gvm_connection_t *client_connection)
* the input, and writing any results to the appropriate socket.
* Exit the loop on reaching end of file on the client socket.
*
* Read input from the client and scanner.
* Process the input with \ref process_gmp_client_input and
* \ref process_otp_scanner_input. Write the results to the client.
* Read input from the client.
* Process the input with \ref process_gmp_client_input. Write the results
* to the client.
*
* \if STATIC
*
Expand Down Expand Up @@ -492,25 +490,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
(void*) client_connection,
disable);

/* Setup the scanner address and try to connect. */
if (gmpd_nvt_cache_mode && !openvas_scanner_connected ())
{
int ret;

/* Is here because it queries the DB and needs it initialized.
* XXX: Move outside serve_gmp ().
*/

ret = manage_scanner_set_default ();
if (ret)
return ret;
if (openvas_scanner_connect () || openvas_scanner_init ())
{
openvas_scanner_close ();
return -1;
}
}

client_input_stalled = 0;

/** @todo Confirm and clarify complications, especially last one. */
Expand Down Expand Up @@ -585,21 +564,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
FD_SET (client_connection->socket, &writefds);
}

/* See whether we need to read from the scannner. */
if (openvas_scanner_connected ()
&& (scanner_init_state == SCANNER_INIT_DONE
|| scanner_init_state == SCANNER_INIT_SENT_VERSION)
&& !openvas_scanner_full ())
openvas_scanner_fd_set (&readfds);

/* See whether we need to write to the scanner. */
if (openvas_scanner_connected ()
&& (((scanner_init_state == SCANNER_INIT_TOP
|| scanner_init_state == SCANNER_INIT_DONE)
&& to_server_buffer_space () > 0)
|| scanner_init_state == SCANNER_INIT_CONNECTED))
openvas_scanner_fd_set (&writefds);

/* Select, then handle result. Due to GNUTLS internal buffering
* we test for pending records first and emulate a select call
* in that case. Note, that GNUTLS guarantees that writes are
Expand Down Expand Up @@ -716,7 +680,6 @@ 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. */
set_scanner_init_state (SCANNER_INIT_TOP);
openvas_scanner_free ();
nfds = openvas_scanner_get_nfds (client_connection->socket);
client_input_stalled = 0;
Expand Down Expand Up @@ -794,14 +757,12 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
/* This may be because the scanner closed the connection
* at the end of a command. */
/** @todo Then should get EOF (-3). */
set_scanner_init_state (SCANNER_INIT_TOP);
rc = -1;
goto client_free;
case -2: /* from_scanner buffer full. */
/* There may be more to read. */
break;
case -3: /* End of file. */
set_scanner_init_state (SCANNER_INIT_TOP);
if (client_active == 0)
/* The client has closed the connection, so exit. */
return 0;
Expand All @@ -813,30 +774,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
}
}

/* Write any data to the scanner. */
if (openvas_scanner_connected ()
&& (openvas_scanner_fd_isset (&writefds) || scan_handler))
{
/* Write as much as possible to the scanner. */

switch (openvas_scanner_write ())
{
case 0: /* Wrote everything in to_scanner. */
break;
case -1: /* Error. */
/** @todo This may be because the scanner closed the connection
* at the end of a command? */
rc = -1;
goto client_free;
case -2: /* Wrote as much as scanner was willing to accept. */
break;
case -3: /* Did an initialisation step. */
break;
default: /* Programming error. */
assert (0);
}
}

/* Write any data to the client. */
if (client_connection->socket > 0
&& FD_ISSET (client_connection->socket, &writefds))
Expand Down Expand Up @@ -871,7 +808,6 @@ 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 ();
set_scanner_init_state (SCANNER_INIT_TOP);
nfds = openvas_scanner_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. */
Expand Down Expand Up @@ -932,55 +868,6 @@ serve_gmp (gvm_connection_t *client_connection, const gchar *database,
}
}

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

ret = process_otp_scanner_input ();
if (ret == 1)
{
/* Received scanner BYE. Write out the rest of to_scanner (the
* BYE ACK).
*/
openvas_scanner_write ();
set_scanner_init_state (SCANNER_INIT_TOP);
if (client_active == 0)
return 0;
openvas_scanner_free ();
nfds = openvas_scanner_get_nfds (client_connection->socket);
}
else if (ret == 2)
{
/* Bad login to scanner. */
if (client_active == 0)
return 0;
rc = -1;
goto client_free;
}
else if (ret == 3)
{
/* Calls via serve_client() should continue. */
if (gmpd_nvt_cache_mode)
return 1;
openvas_scanner_close ();
}
else if (ret == -1)
{
/* Error. */
rc = -1;
goto client_free;
}
else if (ret == -3)
/* to_scanner buffer still full. */
g_debug (" scanner input stalled");
else
{
/* Programming error. */
assert (ret == 0 || ret == 5);
}
}

if (process_gmp_change () == -1)
{
rc = -1;
Expand Down
10 changes: 4 additions & 6 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@
* The command line entry to the manager is defined in
* src/\ref gvmd.c. The manager is a GMP server.
*
* The GMP server is defined in src/\ref gmpd.c. It uses the OTP library
* to handle the OTP server and the GMP library to handle the GMP client.
* The OTP library is defined in src/\ref otp.c. The GMP library is defined
* in src/\ref gmp.c. Both the GMP and OTP libraries use the Manage library
* The GMP server is defined in src/\ref gmpd.c. The GMP library is defined
* in src/\ref gmp.c. The GMP library use the Manage library
* to manage credentials and tasks. The manage
* library is defined in src/\ref manage.c and src/\ref manage_sql.c .
*
* The OTP and Manage libraries both use the Comm library to communication
* with the OTP server (src/\ref comm.c).
* The Manage library uses the Comm library to communication
* with servers (src/\ref comm.c).
*
* \subsection Forking
*
Expand Down
Loading

0 comments on commit ddd3a1b

Please sign in to comment.