Skip to content

Commit

Permalink
Add --broker-address command line option
Browse files Browse the repository at this point in the history
The new option sets the address of the publish-subscribe broker used for
communication with the licensing service.
  • Loading branch information
timopollmeier committed Oct 26, 2021
1 parent 7b77eeb commit ee61232
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/gvmd.8
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ It manages the storage of any vulnerability management configurations and of the
\fB-h, --help\f1
Show help options.
.TP
\fB--broker-address=\fIADDRESS\fB\f1
Sets the address for the publish-subscribe message (MQTT) broker. Defaults to localhost:9138. Set to empty to disable.
.TP
\fB--check-alerts\f1
Check SecInfo alerts.
.TP
Expand Down
9 changes: 9 additions & 0 deletions doc/gvmd.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<p>Show help options.</p>
</optdesc>
</option>
<option>
<p><opt>--broker-address=<arg>ADDRESS</arg></opt></p>
<optdesc>
<p>
Sets the address for the publish-subscribe message (MQTT) broker.
Defaults to localhost:9138. Set to empty to disable.
</p>
</optdesc>
</option>
<option>
<p><opt>--check-alerts</opt></p>
<optdesc>
Expand Down
7 changes: 7 additions & 0 deletions doc/gvmd.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ <h2>Options</h2>



<p><b>--broker-address=<em>ADDRESS</em></b></p>

<p>Sets the address for the publish-subscribe message (MQTT) broker.
Defaults to localhost:9138. Set to empty to disable.</p>



<p><b>--check-alerts</b></p>

<p>Check SecInfo alerts.</p>
Expand Down
16 changes: 16 additions & 0 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@
*/
#define DEFAULT_CLIENT_WATCH_INTERVAL 1

/**
* @brief Default broker address
*/
#define DEFAULT_BROKER_ADDRESS "localhost:9138"

/**
* @brief Interval in seconds to check whether client connection was closed.
*/
Expand Down Expand Up @@ -1841,6 +1846,7 @@ gvmd (int argc, char** argv)
static gchar *role = NULL;
static gchar *disable = NULL;
static gchar *value = NULL;
static gchar *broker_address = NULL;
static gchar *feed_lock_path = NULL;
static int feed_lock_timeout = 0;
static gchar *vt_verification_collation = NULL;
Expand All @@ -1851,6 +1857,11 @@ gvmd (int argc, char** argv)
GOptionContext *option_context;
static GOptionEntry option_entries[]
= {
{ "broker-address", '\0', 0, G_OPTION_ARG_STRING,
&broker_address,
"Sets the address for the publish-subscribe message (MQTT) broker."
" Defaults to " DEFAULT_BROKER_ADDRESS ". Set to empty to disable.",
"<address>" },
{ "check-alerts", '\0', 0, G_OPTION_ARG_NONE,
&check_alerts,
"Check SecInfo alerts.",
Expand Down Expand Up @@ -2217,6 +2228,11 @@ gvmd (int argc, char** argv)
client_watch_interval = 0;
}

/* Set broker address */
set_broker_address (broker_address
? broker_address
: DEFAULT_BROKER_ADDRESS);

/* Set feed lock path */
set_feed_lock_path (feed_lock_path);

Expand Down
31 changes: 31 additions & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
*/
#define MAX_HOSTS_DEFAULT "20"

/**
* @brief Address of the broker used for publish-subscribe messaging (MQTT).
*/
static gchar *broker_address = NULL;

/**
* @brief Path to the feed lock file
*/
Expand Down Expand Up @@ -5918,6 +5923,32 @@ manage_gvmd_data_feed_dirs_exist ()
&& report_formats_feed_dir_exists ();
}

/**
* @brief Get the publish-subscribe messaging (MQTT) broker address.
*
* @return The current broker address.
*/
const gchar *
get_broker_address ()
{
return broker_address;
}

/**
* @brief Set the publish-subscribe messaging (MQTT) broker address.
*
* @param new_path The new broker address.
*/
void
set_broker_address (const char *new_address)
{
g_free (broker_address);
if (new_address && strcmp (new_address, ""))
broker_address = g_strdup (new_address);
else
broker_address = NULL;
}

/**
* @brief Get the feed lock file path.
*
Expand Down
6 changes: 6 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3611,6 +3611,12 @@ manage_gvmd_data_feed_dir_exists (const char *);
gboolean
manage_gvmd_data_feed_dirs_exist ();

const gchar *
get_broker_address ();

void
set_broker_address (const char *);

const gchar *
get_feed_lock_path ();

Expand Down
4 changes: 2 additions & 2 deletions src/manage_license.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ manage_get_license (gchar **status,

#ifdef HAS_LIBTHEIA
int ret;
char *broker_address;
const char *broker_address;
theia_client_t *client;
theia_get_license_cmd_t *get_license_cmd;
theia_got_license_info_t *got_license_info;

// TODO: Replace with command line option
broker_address = g_strdup ("localhost:9138");
broker_address = get_broker_address ();
if (broker_address == NULL)
return 1;

Expand Down

0 comments on commit ee61232

Please sign in to comment.