OpenVAS Libraries  6.0+beta5
Macros | Functions
openvas_ssh_login.c File Reference
#include <glib/gstdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "openvas_ssh_login.h"

Macros

#define KEY_SSHLOGIN_USERNAME   "username"
 
#define KEY_SSHLOGIN_USERPASSWORD   "userpassword"
 
#define KEY_SSHLOGIN_PUBKEY_FILE   "pubkey_file"
 
#define KEY_SSHLOGIN_PRIVKEY_FILE   "privkey_file"
 
#define KEY_SSHLOGIN_COMMENT   "comment"
 
#define KEY_SSHLOGIN_PASSPHRASE   "passphrase"
 

Functions

int file_check_exists (const char *name)
 
openvas_ssh_loginopenvas_ssh_login_new (char *name, char *pubkey_file, char *privkey_file, char *passphrase, char *comment, char *uname, char *upass)
 Initializes a openvas_ssh_login. More...
 
void openvas_ssh_login_free (openvas_ssh_login *loginfo)
 Frees data associated with a openvas_ssh_login. More...
 
char * openvas_ssh_login_prefstring (openvas_ssh_login *loginfo)
 Creates a string to be sent to the server as value for a SSH_LOGIN plugin preference. More...
 
gboolean openvas_ssh_login_file_write (GHashTable *ssh_logins, char *filename)
 Writes information of all ssh logins found in a hashtable into a file. More...
 
GHashTable * openvas_ssh_login_file_read (char *filename, gboolean check_keyfiles)
 Reads a ssh_login file and returns info in a GHashTable. More...
 
GHashTable * openvas_ssh_login_file_read_buffer (const char *buffer, gsize buffer_size, gboolean check_keyfiles)
 Reads from contents of a ssh_login file and returns info in a. More...
 

Macro Definition Documentation

#define KEY_SSHLOGIN_COMMENT   "comment"
#define KEY_SSHLOGIN_PASSPHRASE   "passphrase"
#define KEY_SSHLOGIN_PRIVKEY_FILE   "privkey_file"
#define KEY_SSHLOGIN_PUBKEY_FILE   "pubkey_file"
#define KEY_SSHLOGIN_USERNAME   "username"
#define KEY_SSHLOGIN_USERPASSWORD   "userpassword"

Function Documentation

int file_check_exists ( const char *  name)
Todo:
This module fulfils the reqirements to be placed in the base library.

Replacement for g_file_test which is unreliable on windows if OpenVAS and GTK are compiled with a different libc. TODO: The windows issue needs verification and proper documentation. Maybe a proper build could prohibit any problems.

FIXME: handle symbolic links FIXME: this one is a code duplicate of check_exists in openvas-client/context.c, but needed in openvas-libraries as well.

Returns
1 if file exists, 0 otherwise.
GHashTable* openvas_ssh_login_file_read ( char *  filename,
gboolean  check_keyfiles 
)

Reads a ssh_login file and returns info in a GHashTable.

The GHashTable contains the names as keys and pointers to openvas_ssh_logins as values. If check_keyfiles TRUE, openvas_ssh_logins are checked before being added to the hashtable: if the public and private key files do not exist, the openvas_ssh_login would not be added.

Parameters
filenameFile to read from.
check_keyfilesIf TRUE, checks if referenced keyfiles do exist, before adding the openvas_ssh_login to the HashTable.
Returns
GHashTable, keys are names of openvas_ssh_logins, who are values.
GHashTable* openvas_ssh_login_file_read_buffer ( const char *  buffer,
gsize  buffer_size,
gboolean  check_keyfiles 
)

Reads from contents of a ssh_login file and returns info in a.

GHashTable.

Like openvas_ssh_login_file_read, but used when the file content is known already.

Parameters
filenameBuffer to read from.
check_keyfilesIf TRUE, checks if referenced keyfiles do exist, before adding the openvas_ssh_login to the HashTable.
Returns
GHashTable, keys are names of openvas_ssh_logins, who are values.
See Also
openvas_ssh_login_file_read
gboolean openvas_ssh_login_file_write ( GHashTable *  ssh_logins,
char *  filename 
)

Writes information of all ssh logins found in a hashtable into a file.

To load the information again, openvas_ssh_login_file_read can be used.

Parameters
ssh_loginsHashtable with pointers to openvas_ssh_login s as values.
filenamePath to file to wtite to.
Returns
TRUE if file was written (success), FALSE if an error occured.
void openvas_ssh_login_free ( openvas_ssh_login loginfo)

Frees data associated with a openvas_ssh_login.

Parameters
loginfoopenvas_ssh_login to free.
openvas_ssh_login* openvas_ssh_login_new ( char *  name,
char *  pubkey_file,
char *  privkey_file,
char *  passphrase,
char *  comment,
char *  uname,
char *  upass 
)

Initializes a openvas_ssh_login.

Key and Info files have to be created separately. However, it is tested if the keyfiles do exist and the 'valid' flag is set accordingly. Note that the parameter are not copied, so ensure they live as long as this login.

Returns
A fresh openvas_ssh_login.
char* openvas_ssh_login_prefstring ( openvas_ssh_login loginfo)

Creates a string to be sent to the server as value for a SSH_LOGIN plugin preference.

It follows the pattern: username|userpass|pubkeyfilepath|privkeyfilepath|passphrase .

Parameters
loginfoopenvas_ssh_login that will be used to assemble the string.
Returns
Freshly created string or NULL if loginfo == NULL.