occtl will print the user's dns, nbns, routes, and iroutes.

This commit is contained in:
Nikos Mavrogiannopoulos
2014-03-01 15:27:34 +01:00
parent 20cc945383
commit a0ba998222
4 changed files with 158 additions and 20 deletions

2
NEWS
View File

@@ -10,6 +10,8 @@
options. They ensure that an idle session will be disconnected.
- Added the 'rekey-method' config option. With this option the
advertized rekey method to the client can be overriden.
- occtl will now print the routes, iroutes, dns and nbns values
per user.
- Added configure options to disable checking for certain libraries,
and disable features on request.

View File

@@ -221,4 +221,5 @@ unsigned i;
free(config->ipv6_network);
free(config->ipv4_netmask);
free(config->ipv6_netmask);
memset(config, 0, sizeof(*config));
}

View File

@@ -72,6 +72,7 @@ typedef struct {
{name, sizeof(name)-1, iface, sizeof(iface)-1, desc, sizeof(desc)-1, func}
#define LIST_USERS_SIG "(ussssssssusssss)"
#define LIST_SINGLE_USER_SIG "(ussssssssusssssasasasas)"
#define DESC_LIST \
" <method name=\"list\">\n" \
@@ -80,13 +81,13 @@ typedef struct {
#define DESC_USER_INFO \
" <method name=\"user_info\">\n" \
" <arg name=\"user-info\" direction=\"out\" type=\"a"LIST_USERS_SIG"\"/>\n" \
" <arg name=\"user-info\" direction=\"out\" type=\"a"LIST_SINGLE_USER_SIG"\"/>\n" \
" </method>\n"
/* ID-INFO returns an array of 0 or 1 elements */
#define DESC_ID_INFO \
" <method name=\"id_info\">\n" \
" <arg name=\"id-info\" direction=\"out\" type=\"a"LIST_USERS_SIG"\"/>\n" \
" <arg name=\"id-info\" direction=\"out\" type=\"a"LIST_SINGLE_USER_SIG"\"/>\n" \
" </method>\n"
#define DESC_DISC_NAME \
@@ -126,9 +127,9 @@ static const ctl_method_st methods[] = {
ENTRY("reload", "org.infradead.ocserv", DESC_RELOAD, method_reload),
ENTRY("stop", "org.infradead.ocserv", DESC_RELOAD, method_stop),
ENTRY("list", "org.infradead.ocserv", DESC_LIST, method_list_users),
ENTRY("user_info", "org.infradead.ocserv", DESC_USER_INFO,
ENTRY("user_info2", "org.infradead.ocserv", DESC_USER_INFO,
method_user_info),
ENTRY("id_info", "org.infradead.ocserv", DESC_ID_INFO, method_id_info),
ENTRY("id_info2", "org.infradead.ocserv", DESC_ID_INFO, method_id_info),
ENTRY("disconnect_name", "org.infradead.ocserv", DESC_DISC_NAME,
method_disconnect_user_name),
ENTRY("disconnect_id", "org.infradead.ocserv", DESC_DISC_ID,
@@ -399,11 +400,39 @@ static void method_stop(main_server_st * s, DBusConnection * conn,
return;
}
static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
static int append_list(DBusMessageIter * subs, char **list, unsigned list_size)
{
DBusMessageIter suba;
unsigned i;
if (dbus_message_iter_open_container
(subs, DBUS_TYPE_ARRAY, "s", &suba) == 0) {
return -1;
}
for (i = 0; i < list_size; i++) {
if (dbus_message_iter_append_basic
(&suba, DBUS_TYPE_STRING, &list[i]) == 0) {
return -1;
}
}
if (dbus_message_iter_close_container(subs, &suba) == 0) {
return -1;
}
return 0;
}
static int append_user_info(main_server_st * s, DBusMessageIter * subs,
struct proc_st *ctmp, unsigned single)
{
dbus_uint32_t tmp;
char ipbuf[128];
const char *strtmp;
char **list;
unsigned list_size;
int ret;
/* ID: pid */
tmp = ctmp->pid;
@@ -425,7 +454,7 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
strtmp =
human_addr2((struct sockaddr *)&ctmp->remote_addr,
ctmp->remote_addr_len, ipbuf, sizeof(ipbuf), 0);
ctmp->remote_addr_len, ipbuf, sizeof(ipbuf), 0);
if (strtmp == NULL)
strtmp = "";
if (dbus_message_iter_append_basic
@@ -442,7 +471,7 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
if (ctmp->ipv4 != NULL)
strtmp =
human_addr2((struct sockaddr *)&ctmp->ipv4->rip,
ctmp->ipv4->rip_len, ipbuf, sizeof(ipbuf), 0);
ctmp->ipv4->rip_len, ipbuf, sizeof(ipbuf), 0);
if (strtmp == NULL)
strtmp = "";
if (dbus_message_iter_append_basic
@@ -454,7 +483,7 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
if (ctmp->ipv4 != NULL)
strtmp =
human_addr2((struct sockaddr *)&ctmp->ipv4->lip,
ctmp->ipv4->lip_len, ipbuf, sizeof(ipbuf), 0);
ctmp->ipv4->lip_len, ipbuf, sizeof(ipbuf), 0);
if (strtmp == NULL)
strtmp = "";
if (dbus_message_iter_append_basic
@@ -466,7 +495,7 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
if (ctmp->ipv6 != NULL)
strtmp =
human_addr2((struct sockaddr *)&ctmp->ipv6->rip,
ctmp->ipv6->rip_len, ipbuf, sizeof(ipbuf), 0);
ctmp->ipv6->rip_len, ipbuf, sizeof(ipbuf), 0);
if (strtmp == NULL)
strtmp = "";
if (dbus_message_iter_append_basic
@@ -478,7 +507,7 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
if (ctmp->ipv6 != NULL)
strtmp =
human_addr2((struct sockaddr *)&ctmp->ipv6->lip,
ctmp->ipv6->lip_len, ipbuf, sizeof(ipbuf), 0);
ctmp->ipv6->lip_len, ipbuf, sizeof(ipbuf), 0);
if (strtmp == NULL)
strtmp = "";
if (dbus_message_iter_append_basic
@@ -533,6 +562,52 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
return -1;
}
if (single > 0) {
if (ctmp->config.dns_size > 0) {
list = ctmp->config.dns;
list_size = ctmp->config.dns_size;
} else {
list = s->config->network.dns;
list_size = s->config->network.dns_size;
}
ret = append_list(subs, list, list_size);
if (ret < 0)
return ret;
if (ctmp->config.nbns_size > 0) {
list = ctmp->config.nbns;
list_size = ctmp->config.nbns_size;
} else {
list = s->config->network.nbns;
list_size = s->config->network.nbns_size;
}
ret = append_list(subs, list, list_size);
if (ret < 0)
return ret;
if (ctmp->config.routes_size > 0) {
list = ctmp->config.routes;
list_size = ctmp->config.routes_size;
} else {
list = s->config->network.routes;
list_size = s->config->network.routes_size;
}
ret = append_list(subs, list, list_size);
if (ret < 0)
return ret;
if (ctmp->config.iroutes_size > 0) {
list = ctmp->config.iroutes;
list_size = ctmp->config.iroutes_size;
} else {
list = NULL;
list_size = 0;
}
ret = append_list(subs, list, list_size);
if (ret < 0)
return ret;
}
return 0;
}
@@ -572,7 +647,7 @@ static void method_list_users(main_server_st * s, DBusConnection * conn,
goto error;
}
ret = append_user_info(&subs, ctmp);
ret = append_user_info(s, &subs, ctmp, 0);
if (ret < 0) {
mslog(s, NULL, LOG_ERR,
"error appending container to dbus reply");
@@ -603,7 +678,7 @@ static void method_list_users(main_server_st * s, DBusConnection * conn,
return;
}
static void info_common(main_server_st * s, DBusConnection * conn,
static void single_info_common(main_server_st * s, DBusConnection * conn,
DBusMessage * msg, const char *user, unsigned id)
{
DBusMessage *reply;
@@ -628,7 +703,7 @@ static void info_common(main_server_st * s, DBusConnection * conn,
dbus_message_iter_init_append(reply, &args);
if (dbus_message_iter_open_container
(&args, DBUS_TYPE_ARRAY, LIST_USERS_SIG, &suba) == 0) {
(&args, DBUS_TYPE_ARRAY, LIST_SINGLE_USER_SIG, &suba) == 0) {
mslog(s, NULL, LOG_ERR,
"error appending container to dbus reply");
goto error;
@@ -652,7 +727,7 @@ static void info_common(main_server_st * s, DBusConnection * conn,
goto error;
}
ret = append_user_info(&subs, ctmp);
ret = append_user_info(s, &subs, ctmp, 1);
if (ret < 0) {
mslog(s, NULL, LOG_ERR,
"error appending to dbus reply");
@@ -716,7 +791,7 @@ static void method_user_info(main_server_st * s, DBusConnection * conn,
dbus_message_iter_get_basic(&args, &name);
info_common(s, conn, msg, name, 0);
single_info_common(s, conn, msg, name, 0);
return;
}
@@ -741,7 +816,7 @@ static void method_id_info(main_server_st * s, DBusConnection * conn,
dbus_message_iter_get_basic(&args, &id);
info_common(s, conn, msg, NULL, id);
single_info_common(s, conn, msg, NULL, id);
return;
}

View File

@@ -734,6 +734,37 @@ int handle_list_users_cmd(DBusConnection * conn, const char *arg)
return ret;
}
int print_list_entries(FILE* out, const char* name, DBusMessageIter * subs)
{
DBusMessageIter suba;
const char * tmp;
unsigned int i = 0;
if (dbus_message_iter_get_arg_type(subs) != DBUS_TYPE_ARRAY)
return -1;
dbus_message_iter_recurse(subs, &suba);
for (;;) {
if (dbus_message_iter_get_arg_type(&suba) != DBUS_TYPE_STRING)
break; /* empty */
dbus_message_iter_get_basic(&suba, &tmp);
if (tmp != NULL) {
if (i==0)
fprintf(out, "%s %s\n", name, tmp);
else
fprintf(out, "\t\t%s\n", tmp);
}
i++;
if (!dbus_message_iter_next(&suba))
break;
}
return i;
}
int common_info_cmd(DBusMessageIter * args)
{
DBusMessageIter suba, subs;
@@ -751,7 +782,7 @@ int common_info_cmd(DBusMessageIter * args)
FILE *out;
unsigned at_least_one = 0;
const char *dtls_ciphersuite, *tls_ciphersuite;
int ret = 1;
int ret = 1, r;
out = pager_start();
@@ -877,6 +908,9 @@ int common_info_cmd(DBusMessageIter * args)
goto error_parse;
dbus_message_iter_get_basic(&subs, &dtls_ciphersuite);
if (!dbus_message_iter_next(&subs))
goto error_recv;
if (username == NULL || username[0] == 0)
username = NO_USER;
@@ -919,10 +953,36 @@ int common_info_cmd(DBusMessageIter * args)
if (dtls_ciphersuite != NULL && dtls_ciphersuite[0] != 0)
fprintf(out, "\tDTLS cipher: %s\n", dtls_ciphersuite);
at_least_one = 1;
/* user network info */
fputs("\n", out);
if (print_list_entries(out, "\tDNS:", &subs) < 0)
goto error_parse;
if (!dbus_message_iter_next(&subs))
goto error_recv;
if (print_list_entries(out, "\tNBNS:", &subs) < 0)
goto error_parse;
if (!dbus_message_iter_next(&subs))
goto error_recv;
if ((r = print_list_entries(out, "\tRoutes:", &subs)) < 0)
goto error_parse;
if (r == 0) {
fprintf(out, "Routes: defaultroute\n");
}
if (!dbus_message_iter_next(&subs))
goto error_recv;
if (print_list_entries(out, "\tiRoutes:", &subs) < 0)
goto error_parse;
at_least_one = 1;
if (!dbus_message_iter_next(&suba))
break;
}
ret = 0;
@@ -954,7 +1014,7 @@ int handle_show_user_cmd(DBusConnection * conn, const char *arg)
msg = send_dbus_cmd(conn, "org.infradead.ocserv",
"/org/infradead/ocserv",
"org.infradead.ocserv", "user_info",
"org.infradead.ocserv", "user_info2",
DBUS_TYPE_STRING, &arg);
if (msg == NULL) {
goto error_send;
@@ -1000,7 +1060,7 @@ int handle_show_id_cmd(DBusConnection * conn, const char *arg)
msg = send_dbus_cmd(conn, "org.infradead.ocserv",
"/org/infradead/ocserv",
"org.infradead.ocserv", "id_info",
"org.infradead.ocserv", "id_info2",
DBUS_TYPE_UINT32, &id);
if (msg == NULL) {
goto error_send;