OpenVAS Libraries  4.0+rc3.SVN
Defines | Functions | Variables
misc/openvas_server.c File Reference

GnuTLS based functions for communication with an OpenVAS server. More...

#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <gcrypt.h>
#include <glib.h>
#include <string.h>
#include "openvas_server.h"

Defines

#define G_LOG_DOMAIN   "lib serv"
 GLib log domain.

Functions

int openvas_server_open (gnutls_session_t *session, const char *host, int port)
 Connect to the server using a given host and port.
int openvas_server_close (int socket, gnutls_session_t session)
 Close a server connection.
int openvas_server_connect (int server_socket, struct sockaddr_in *server_address, gnutls_session_t *server_session, gboolean interrupted)
 Connect to a server.
int openvas_server_attach (int socket, gnutls_session_t *session)
 Attach a socket to a session, and shake hands with the peer.
int openvas_server_send (gnutls_session_t *session, const char *string)
 Send a string to the server.
int openvas_server_sendf (gnutls_session_t *session, const char *format,...)
 Format and send a string to the server.
int openvas_server_sendf_xml (gnutls_session_t *session, const char *format,...)
 Format and send an XML string to the server.
int openvas_server_new (gnutls_connection_end_t end_type, gchar *ca_cert_file, gchar *cert_file, gchar *key_file, gnutls_session_t *server_session, gnutls_certificate_credentials_t *server_credentials)
 Make a session for connecting to a server.
int openvas_server_free (int server_socket, gnutls_session_t server_session, gnutls_certificate_credentials_t server_credentials)
 Cleanup a server session.

Variables

struct sockaddr_in address
 Server address.

Detailed Description

GnuTLS based functions for communication with an OpenVAS server.

GnuTLS based functions for communication with an OpenVAS server. Copyright (C) 2009 Greenbone Networks GmbH

Authors: Matthew Mundell matt@.nosp@m.mund.nosp@m.ell.u.nosp@m.kfsn.nosp@m..org Jan-Oliver Wagner jan-o.nosp@m.live.nosp@m.r.wag.nosp@m.ner@.nosp@m.green.nosp@m.bone.nosp@m..net Michael Wiegand micha.nosp@m.el.w.nosp@m.iegan.nosp@m.d@gr.nosp@m.eenbo.nosp@m.ne.n.nosp@m.et

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

This library supplies low-level communication functions for communication with an OpenVAS server over GnuTLS.


Define Documentation

#define G_LOG_DOMAIN   "lib serv"

GLib log domain.

Todo:
Ensure that every global init gets a free.
Todo:
This module nearly fulfils the requirements to be placed in the base library (the gnutls dependency makes it a candidate for the net library).

Function Documentation

int openvas_server_attach ( int  socket,
gnutls_session_t *  session 
)

Attach a socket to a session, and shake hands with the peer.

Parameters:
[in]sessionPointer to GNUTLS session.
[in]socketSocket.
Returns:
0 on success, -1 on error.
int openvas_server_close ( int  socket,
gnutls_session_t  session 
)

Close a server connection.

Parameters:
[in]socketSocket connected to server (from connect_to_server).
[in]sessionGNUTLS session with server.
Returns:
0 on success, -1 on error.
int openvas_server_connect ( int  server_socket,
struct sockaddr_in *  server_address,
gnutls_session_t *  server_session,
gboolean  interrupted 
)

Connect to a server.

Parameters:
[in]server_socketSocket to connect to server.
[in]server_addressServer address.
[in]server_sessionSession to connect to server.
[in]interrupted0 if first connect attempt, else retrying after an interrupted connect.
Returns:
0 on success, -1 on error, -2 on connect interrupt.
int openvas_server_free ( int  server_socket,
gnutls_session_t  server_session,
gnutls_certificate_credentials_t  server_credentials 
)

Cleanup a server session.

Todo:
vs openvas_server_close
Parameters:
[in]server_socketThe socket connected to the server.
[in]server_sessionThe session with the server.
[in]server_credentialsCredentials.
Returns:
0 success, -1 error.
int openvas_server_new ( gnutls_connection_end_t  end_type,
gchar *  ca_cert_file,
gchar *  cert_file,
gchar *  key_file,
gnutls_session_t *  server_session,
gnutls_certificate_credentials_t *  server_credentials 
)

Make a session for connecting to a server.

Parameters:
[in]end_typeConnecton end type (GNUTLS_SERVER or GNUTLS_CLIENT).
[in]ca_fileCertificate authority file.
[in]cert_fileCertificate file.
[in]key_fileKey file.
[out]server_sessionThe session with the server.
[out]server_credentialsServer credentials.
Returns:
0 on success, -1 on error.
int openvas_server_open ( gnutls_session_t *  session,
const char *  host,
int  port 
)

Connect to the server using a given host and port.

Parameters:
[in]sessionPointer to GNUTLS session.
[in]hostHost to connect to.
[in]portPort to connect to.
Returns:
0 on success, -1 on error.
Todo:
Ensure that host and port have sane values.
Todo:
Improve logging.
Todo:
Use openvas_server_new.
Todo:
Use openvas_server_connect.
int openvas_server_send ( gnutls_session_t *  session,
const char *  string 
)

Send a string to the server.

Parameters:
[in]sessionPointer to GNUTLS session.
[in]stringString to send.
Returns:
0 on success, 1 if server closed connection, -1 on error.
int openvas_server_sendf ( gnutls_session_t *  session,
const char *  format,
  ... 
)

Format and send a string to the server.

Parameters:
[in]sessionPointer to GNUTLS session.
[in]formatprintf-style format string for message.
Returns:
0 on success, -1 on error.
int openvas_server_sendf_xml ( gnutls_session_t *  session,
const char *  format,
  ... 
)

Format and send an XML string to the server.

Escape XML in string and character args.

Parameters:
[in]sessionPointer to GNUTLS session.
[in]formatprintf-style format string for message.
Returns:
0 on success, -1 on error.