Added configuration option use-dbus to allow disabling D-BUS usage.

This commit is contained in:
Nikos Mavrogiannopoulos
2014-01-09 21:32:24 +01:00
parent 9b4e98be71
commit 9079e2b67a
5 changed files with 24 additions and 3 deletions
+6 -1
View File
@@ -119,7 +119,12 @@ cookie-validity = 172800
# UTMP # UTMP
use-utmp = true use-utmp = true
# PID file # D-BUS usage. If disabled occtl tool cannot be used. If enabled
# then ocserv must have access to register org.infradead.ocserv
# D-BUS service. See doc/dbus/org.infradead.ocserv.conf
use-dbus = true
# PID file. It can be overriden in the command line.
pid-file = /var/run/ocserv.pid pid-file = /var/run/ocserv.pid
# The default server directory. Does not require any devices present. # The default server directory. Does not require any devices present.
+2
View File
@@ -74,6 +74,7 @@ static struct cfg_options available_options[] = {
{ .name = "banner", .type = OPTION_STRING, .mandatory = 0 }, { .name = "banner", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "always-require-cert", .type = OPTION_BOOLEAN, .mandatory = 0 }, { .name = "always-require-cert", .type = OPTION_BOOLEAN, .mandatory = 0 },
{ .name = "use-utmp", .type = OPTION_BOOLEAN, .mandatory = 0 }, { .name = "use-utmp", .type = OPTION_BOOLEAN, .mandatory = 0 },
{ .name = "use-dbus", .type = OPTION_BOOLEAN, .mandatory = 1 },
{ .name = "try-mtu-discovery", .type = OPTION_BOOLEAN, .mandatory = 0 }, { .name = "try-mtu-discovery", .type = OPTION_BOOLEAN, .mandatory = 0 },
{ .name = "ping-leases", .type = OPTION_BOOLEAN, .mandatory = 0 }, { .name = "ping-leases", .type = OPTION_BOOLEAN, .mandatory = 0 },
{ .name = "tls-priorities", .type = OPTION_STRING, .mandatory = 0 }, { .name = "tls-priorities", .type = OPTION_STRING, .mandatory = 0 },
@@ -329,6 +330,7 @@ unsigned prefix = 0;
READ_STRING("banner", config->banner); READ_STRING("banner", config->banner);
READ_TF("always-require-cert", config->force_cert_auth, 1); READ_TF("always-require-cert", config->force_cert_auth, 1);
READ_TF("use-utmp", config->use_utmp, 1); READ_TF("use-utmp", config->use_utmp, 1);
READ_TF("use-dbus", config->use_dbus, 0);
READ_TF("try-mtu-discovery", config->try_mtu, 0); READ_TF("try-mtu-discovery", config->try_mtu, 0);
READ_TF("ping-leases", config->ping_leases, 0); READ_TF("ping-leases", config->ping_leases, 0);
+9 -1
View File
@@ -220,7 +220,7 @@ static void toggle_watch(DBusWatch * watch, void *data)
void ctl_handler_deinit(main_server_st * s) void ctl_handler_deinit(main_server_st * s)
{ {
if (s->ctl_ctx != NULL) { if (s->config->use_dbus != 0 && s->ctl_ctx != NULL) {
mslog(s, NULL, LOG_DEBUG, "closing DBUS connection"); mslog(s, NULL, LOG_DEBUG, "closing DBUS connection");
dbus_connection_close(s->ctl_ctx); dbus_connection_close(s->ctl_ctx);
dbus_bus_release_name(s->ctl_ctx, OCSERV_DBUS_NAME, NULL); dbus_bus_release_name(s->ctl_ctx, OCSERV_DBUS_NAME, NULL);
@@ -236,6 +236,9 @@ int ctl_handler_init(main_server_st * s)
DBusError err; DBusError err;
DBusConnection *conn; DBusConnection *conn;
if (s->config->use_dbus == 0)
return 0;
dbus_error_init(&err); dbus_error_init(&err);
conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
@@ -1049,6 +1052,11 @@ void ctl_handle_commands(main_server_st * s, struct ctl_handler_st *ctl)
int ret; int ret;
unsigned flags, i; unsigned flags, i;
if (s->config->use_dbus == 0) {
mslog(s, NULL, LOG_ERR, "%s called when D-BUS is disabled!", __func__);
return;
}
if (ctl->type == CTL_READ) if (ctl->type == CTL_READ)
flags = DBUS_WATCH_READABLE; flags = DBUS_WATCH_READABLE;
else else
+6 -1
View File
@@ -209,7 +209,12 @@ cookie-validity = 172800
# UTMP # UTMP
use-utmp = true use-utmp = true
# PID file # D-BUS usage. If disabled occtl tool cannot be used. If enabled
# then ocserv must have access to register org.infradead.ocserv
# D-BUS service. See doc/dbus/org.infradead.ocserv.conf
use-dbus = true
# PID file. It can be overriden in the command line.
pid-file = /var/run/ocserv.pid pid-file = /var/run/ocserv.pid
# The default server directory. Does not require any devices present. # The default server directory. Does not require any devices present.
+1
View File
@@ -180,6 +180,7 @@ struct cfg_st {
unsigned max_clients; unsigned max_clients;
unsigned max_same_clients; unsigned max_same_clients;
unsigned use_utmp; unsigned use_utmp;
unsigned use_dbus; /* whether the D-BUS service is registered */
unsigned try_mtu; /* MTU discovery enabled */ unsigned try_mtu; /* MTU discovery enabled */
unsigned force_cert_auth; /* always require client certificate */ unsigned force_cert_auth; /* always require client certificate */
unsigned rate_limit_ms; /* if non zero force a connection every rate_limit milliseconds */ unsigned rate_limit_ms; /* if non zero force a connection every rate_limit milliseconds */