Merge remote-tracking branch 'origin/rm-userset'

There; it's merged.  Yay!
This commit is contained in:
Dan Williams
2011-02-12 22:51:12 -06:00
267 changed files with 18303 additions and 11381 deletions

11
.gitignore vendored
View File

@@ -3,6 +3,8 @@
*.lo
*.la
*.bz2
*.gir
*.typelib
Makefile
Makefile.in*
configure
@@ -59,6 +61,12 @@ docs/generate-settings-spec
docs/settings-spec.html
docs/spec.html
examples/C/add-connection-glib
examples/C/get-active-connections
examples/C/get-ap-info-libnm-glib
examples/C/list-connections-dbus
examples/C/list-connections-libnm-glib
callouts/nm-dhcp-client.action
callouts/nm-avahi-autoipd.action
callouts/nm-dispatcher.action
@@ -91,8 +99,10 @@ libnm-util/tests/test-settings-defaults
libnm-util/tests/test-general
libnm-util/tests/test-need-secrets
libnm-util/tests/test-setting-8021x
libnm-glib/tests/test-remote-settings-client
src/tests/test-dhcp-options
src/tests/test-policy-hosts
src/tests/test-wifi-ap-utils
src/dhcp-manager/tests/test-dhcp-dhclient
system-settings/plugins/keyfile/tests/test-keyfile
@@ -101,6 +111,7 @@ system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils
system-settings/plugins/ifcfg-rh/tests/network-scripts/Test_Write_*
system-settings/plugins/ifcfg-rh/tests/network-scripts/*-Test_Write_*
system-settings/plugins/ifupdown/tests/test-ifupdown
system-settings/plugins/ifnet/tests/check_ifnet
m4/gtk-doc.m4
m4/intltool.m4

View File

@@ -1,12 +1,12 @@
SUBDIRS = \
marshallers \
include \
libnm-util \
libnm-glib \
src \
include \
introspection \
callouts \
system-settings \
src \
callouts \
cli \
tools \
policy \
@@ -29,7 +29,8 @@ DISTCHECK_CONFIGURE_FLAGS = \
--with-tests=yes \
--with-docs=yes \
--with-udev-dir=$$dc_install_base/lib/udev \
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \
--enable-wimax=no
DISTCLEANFILES = intltool-extract intltool-merge intltool-update

View File

@@ -22,7 +22,6 @@
#define NM_DISPATCHER_DBUS_IFACE "org.freedesktop.nm_dispatcher"
#define NM_DISPATCHER_DBUS_PATH "/org/freedesktop/nm_dispatcher"
#define NMD_CONNECTION_PROPS_SERVICE_NAME "service-name"
#define NMD_CONNECTION_PROPS_PATH "path"
#define NMD_DEVICE_PROPS_INTERFACE "interface"

View File

@@ -47,9 +47,6 @@
#include <nm-device-bt.h>
//#include <nm-device-olpc-mesh.h>
#include <nm-remote-settings.h>
#include <nm-remote-settings-system.h>
#include <nm-settings-interface.h>
#include <nm-settings-connection-interface.h>
#include <nm-vpn-connection.h>
#include "utils.h"
@@ -62,32 +59,29 @@ static NmcOutputField nmc_fields_con_status[] = {
{"NAME", N_("NAME"), 25, NULL, 0}, /* 0 */
{"UUID", N_("UUID"), 38, NULL, 0}, /* 1 */
{"DEVICES", N_("DEVICES"), 10, NULL, 0}, /* 2 */
{"SCOPE", N_("SCOPE"), 8, NULL, 0}, /* 3 */
{"DEFAULT", N_("DEFAULT"), 8, NULL, 0}, /* 4 */
{"DBUS-SERVICE", N_("DBUS-SERVICE"), 45, NULL, 0}, /* 5 */
{"SPEC-OBJECT", N_("SPEC-OBJECT"), 10, NULL, 0}, /* 6 */
{"VPN", N_("VPN"), 5, NULL, 0}, /* 7 */
{"DBUS-PATH", N_("DBUS-PATH"), 51, NULL, 0}, /* 8 */
{"DEFAULT", N_("DEFAULT"), 8, NULL, 0}, /* 3 */
{"SPEC-OBJECT", N_("SPEC-OBJECT"), 10, NULL, 0}, /* 4 */
{"VPN", N_("VPN"), 5, NULL, 0}, /* 5 */
{"DBUS-PATH", N_("DBUS-PATH"), 51, NULL, 0}, /* 6 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_CON_STATUS_ALL "NAME,UUID,DEVICES,SCOPE,DEFAULT,VPN,DBUS-SERVICE,DBUS-PATH,SPEC-OBJECT"
#define NMC_FIELDS_CON_STATUS_COMMON "NAME,UUID,DEVICES,SCOPE,DEFAULT,VPN"
#define NMC_FIELDS_CON_STATUS_ALL "NAME,UUID,DEVICES,DEFAULT,VPN,DBUS-PATH,SPEC-OBJECT"
#define NMC_FIELDS_CON_STATUS_COMMON "NAME,UUID,DEVICES,DEFAULT,VPN"
/* Available fields for 'con list' */
static NmcOutputField nmc_fields_con_list[] = {
{"NAME", N_("NAME"), 25, NULL, 0}, /* 0 */
{"UUID", N_("UUID"), 38, NULL, 0}, /* 1 */
{"TYPE", N_("TYPE"), 17, NULL, 0}, /* 2 */
{"SCOPE", N_("SCOPE"), 8, NULL, 0}, /* 3 */
{"TIMESTAMP", N_("TIMESTAMP"), 12, NULL, 0}, /* 4 */
{"TIMESTAMP-REAL", N_("TIMESTAMP-REAL"), 34, NULL, 0}, /* 5 */
{"AUTOCONNECT", N_("AUTOCONNECT"), 13, NULL, 0}, /* 6 */
{"READONLY", N_("READONLY"), 10, NULL, 0}, /* 7 */
{"DBUS-PATH", N_("DBUS-PATH"), 42, NULL, 0}, /* 8 */
{"TIMESTAMP", N_("TIMESTAMP"), 12, NULL, 0}, /* 3 */
{"TIMESTAMP-REAL", N_("TIMESTAMP-REAL"), 34, NULL, 0}, /* 4 */
{"AUTOCONNECT", N_("AUTOCONNECT"), 13, NULL, 0}, /* 5 */
{"READONLY", N_("READONLY"), 10, NULL, 0}, /* 6 */
{"DBUS-PATH", N_("DBUS-PATH"), 42, NULL, 0}, /* 7 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_CON_LIST_ALL "NAME,UUID,TYPE,SCOPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,READONLY,DBUS-PATH"
#define NMC_FIELDS_CON_LIST_COMMON "NAME,UUID,TYPE,SCOPE,TIMESTAMP-REAL"
#define NMC_FIELDS_CON_LIST_ALL "NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,READONLY,DBUS-PATH"
#define NMC_FIELDS_CON_LIST_COMMON "NAME,UUID,TYPE,TIMESTAMP-REAL"
/* Helper macro to define fields */
@@ -150,8 +144,8 @@ static gboolean find_device_for_connection (NmCli *nmc, NMConnection *connection
const char *nsp, NMDevice **device, const char **spec_object, GError **error);
static const char *active_connection_state_to_string (NMActiveConnectionState state);
static void active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpointer user_data);
static void activate_connection_cb (gpointer user_data, const char *path, GError *error);
static void get_connections_cb (NMSettingsInterface *settings, gpointer user_data);
static void activate_connection_cb (NMClient *client, const char *path, GError *error, gpointer user_data);
static void get_connections_cb (NMRemoteSettings *settings, gpointer user_data);
static NMCResultCode do_connections_list (NmCli *nmc, int argc, char **argv);
static NMCResultCode do_connections_status (NmCli *nmc, int argc, char **argv);
static NMCResultCode do_connection_up (NmCli *nmc, int argc, char **argv);
@@ -163,7 +157,7 @@ usage (void)
fprintf (stderr,
_("Usage: nmcli con { COMMAND | help }\n"
" COMMAND := { list | status | up | down }\n\n"
" list [id <id> | uuid <id> | system | user]\n"
" list [id <id> | uuid <id>]\n"
" status\n"
" up id <id> | uuid <id> [iface <iface>] [ap <hwaddr>] [nsp <name>] [--nowait] [--timeout <timeout>]\n"
" down id <id> | uuid <id>\n"));
@@ -395,12 +389,11 @@ show_connection (NMConnection *data, gpointer user_data)
nmc->allowed_fields[0].value = nm_setting_connection_get_id (s_con);
nmc->allowed_fields[1].value = nm_setting_connection_get_uuid (s_con);
nmc->allowed_fields[2].value = nm_setting_connection_get_connection_type (s_con);
nmc->allowed_fields[3].value = nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM ? _("system") : _("user");
nmc->allowed_fields[4].value = timestamp_str;
nmc->allowed_fields[5].value = timestamp ? timestamp_real_str : _("never");
nmc->allowed_fields[6].value = nm_setting_connection_get_autoconnect (s_con) ? _("yes") : _("no");
nmc->allowed_fields[7].value = nm_setting_connection_get_read_only (s_con) ? _("yes") : _("no");
nmc->allowed_fields[8].value = nm_connection_get_path (connection);
nmc->allowed_fields[3].value = timestamp_str;
nmc->allowed_fields[4].value = timestamp ? timestamp_real_str : _("never");
nmc->allowed_fields[5].value = nm_setting_connection_get_autoconnect (s_con) ? _("yes") : _("no");
nmc->allowed_fields[6].value = nm_setting_connection_get_read_only (s_con) ? _("yes") : _("no");
nmc->allowed_fields[7].value = nm_connection_get_path (connection);
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
print_fields (nmc->print_fields, nmc->allowed_fields);
@@ -471,22 +464,15 @@ do_connections_list (NmCli *nmc, int argc, char **argv)
goto error;
valid_param_specified = TRUE;
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("System connections");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
print_fields (nmc->print_fields, nmc->allowed_fields);
g_slist_foreach (nmc->system_connections, (GFunc) show_connection, nmc);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("User connections");
print_fields (nmc->print_fields, nmc->allowed_fields);
g_slist_foreach (nmc->user_connections, (GFunc) show_connection, nmc);
}
else {
while (argc > 0) {
if (strcmp (*argv, "id") == 0 || strcmp (*argv, "uuid") == 0) {
const char *selector = *argv;
NMConnection *con1;
NMConnection *con2;
NMConnection *con;
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
@@ -497,42 +483,16 @@ do_connections_list (NmCli *nmc, int argc, char **argv)
if (!nmc->mode_specified)
nmc->multiline_output = TRUE; /* multiline mode is default for 'con list id|uuid' */
con1 = find_connection (nmc->system_connections, selector, *argv);
con2 = find_connection (nmc->user_connections, selector, *argv);
if (con1) nmc_connection_detail (con1, nmc);
if (con2) nmc_connection_detail (con2, nmc);
if (!con1 && !con2) {
con = find_connection (nmc->system_connections, selector, *argv);
if (con) {
nmc_connection_detail (con, nmc);
}
else {
g_string_printf (nmc->return_text, _("Error: %s - no such connection."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
}
break;
}
else if (strcmp (*argv, "system") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error2))
goto error;
if (error1)
goto error;
valid_param_specified = TRUE;
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("System connections");
print_fields (nmc->print_fields, nmc->allowed_fields);
g_slist_foreach (nmc->system_connections, (GFunc) show_connection, nmc);
break;
}
else if (strcmp (*argv, "user") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error2))
goto error;
if (error1)
goto error;
valid_param_specified = TRUE;
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("User connections");
print_fields (nmc->print_fields, nmc->allowed_fields);
g_slist_foreach (nmc->user_connections, (GFunc) show_connection, nmc);
break;
}
else {
fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
}
@@ -566,29 +526,19 @@ error:
return nmc->return_value;
}
typedef struct {
NmCli *nmc;
NMConnectionScope scope;
} StatusInfo;
static void
show_active_connection (gpointer data, gpointer user_data)
{
NMActiveConnection *active = NM_ACTIVE_CONNECTION (data);
StatusInfo *info = (StatusInfo *) user_data;
NmCli *nmc = (NmCli *) user_data;
GSList *con_list, *iter;
const char *active_path;
NMConnectionScope active_service_scope;
NMSettingConnection *s_con;
const GPtrArray *devices;
GString *dev_str;
int i;
active_path = nm_active_connection_get_connection (active);
active_service_scope = nm_active_connection_get_scope (active);
if (active_service_scope != info->scope)
return;
/* Get devices of the active connection */
dev_str = g_string_new (NULL);
@@ -602,7 +552,7 @@ show_active_connection (gpointer data, gpointer user_data)
if (dev_str->len > 0)
g_string_truncate (dev_str, dev_str->len - 1); /* Cut off last ',' */
con_list = (info->scope == NM_CONNECTION_SCOPE_SYSTEM) ? info->nmc->system_connections : info->nmc->user_connections;
con_list = nmc->system_connections;
for (iter = con_list; iter; iter = g_slist_next (iter)) {
NMConnection *connection = (NMConnection *) iter->data;
const char *con_path = nm_connection_get_path (connection);
@@ -613,18 +563,16 @@ show_active_connection (gpointer data, gpointer user_data)
g_assert (s_con != NULL);
/* Obtain field values */
info->nmc->allowed_fields[0].value = nm_setting_connection_get_id (s_con);
info->nmc->allowed_fields[1].value = nm_setting_connection_get_uuid (s_con);
info->nmc->allowed_fields[2].value = dev_str->str;
info->nmc->allowed_fields[3].value = active_service_scope == NM_CONNECTION_SCOPE_SYSTEM ? _("system") : _("user");
info->nmc->allowed_fields[4].value = nm_active_connection_get_default (active) ? _("yes") : _("no");
info->nmc->allowed_fields[5].value = nm_active_connection_get_service_name (active);
info->nmc->allowed_fields[6].value = nm_active_connection_get_specific_object (active);
info->nmc->allowed_fields[7].value = NM_IS_VPN_CONNECTION (active) ? _("yes") : _("no");
info->nmc->allowed_fields[8].value = nm_object_get_path (NM_OBJECT (active));
nmc->allowed_fields[0].value = nm_setting_connection_get_id (s_con);
nmc->allowed_fields[1].value = nm_setting_connection_get_uuid (s_con);
nmc->allowed_fields[2].value = dev_str->str;
nmc->allowed_fields[3].value = nm_active_connection_get_default (active) ? _("yes") : _("no");
nmc->allowed_fields[4].value = nm_active_connection_get_specific_object (active);
nmc->allowed_fields[5].value = NM_IS_VPN_CONNECTION (active) ? _("yes") : _("no");
nmc->allowed_fields[6].value = nm_object_get_path (NM_OBJECT (active));
info->nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
print_fields (info->nmc->print_fields, info->nmc->allowed_fields);
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
print_fields (nmc->print_fields, nmc->allowed_fields);
break;
}
}
@@ -637,7 +585,6 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
{
const GPtrArray *active_cons;
GError *error = NULL;
StatusInfo *info;
char *fields_str;
char *fields_all = NMC_FIELDS_CON_STATUS_ALL;
char *fields_common = NMC_FIELDS_CON_STATUS_COMMON;
@@ -686,15 +633,8 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
active_cons = nm_client_get_active_connections (nmc->client);
if (active_cons && active_cons->len) {
info = g_malloc0 (sizeof (StatusInfo));
info->nmc = nmc;
info->scope = NM_CONNECTION_SCOPE_SYSTEM;
g_ptr_array_foreach ((GPtrArray *) active_cons, show_active_connection, (gpointer) info);
info->scope = NM_CONNECTION_SCOPE_USER;
g_ptr_array_foreach ((GPtrArray *) active_cons, show_active_connection, (gpointer) info);
g_free (info);
}
if (active_cons && active_cons->len)
g_ptr_array_foreach ((GPtrArray *) active_cons, show_active_connection, (gpointer) nmc);
error:
return nmc->return_value;
@@ -1393,11 +1333,11 @@ foo_active_connections_changed_cb (NMClient *client,
/* Call again activate_connection_cb with dummy arguments;
* the correct ones are taken from its first call.
*/
activate_connection_cb (NULL, NULL, NULL);
activate_connection_cb (NULL, NULL, NULL, NULL);
}
static void
activate_connection_cb (gpointer user_data, const char *path, GError *error)
activate_connection_cb (NMClient *client, const char *path, GError *error, gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
NMActiveConnection *active;
@@ -1471,7 +1411,6 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
gboolean device_found;
NMConnection *connection = NULL;
NMSettingConnection *s_con;
gboolean is_system;
const char *con_path;
const char *con_type;
const char *iface = NULL;
@@ -1497,8 +1436,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
goto error;
}
if ((connection = find_connection (nmc->system_connections, selector, *argv)) == NULL)
connection = find_connection (nmc->user_connections, selector, *argv);
connection = find_connection (nmc->system_connections, selector, *argv);
if (!connection) {
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), *argv);
@@ -1578,7 +1516,6 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
/* create NMClient */
nmc->get_client (nmc);
is_system = (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) ? TRUE : FALSE;
con_path = nm_connection_get_path (connection);
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
@@ -1602,7 +1539,6 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
nmc->nowait_flag = !wait;
nmc->should_wait = TRUE;
nm_client_activate_connection (nmc->client,
is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
con_path,
device,
spec_object,
@@ -1624,7 +1560,6 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
const GPtrArray *active_cons;
const char *con_path;
const char *active_path;
NMConnectionScope active_service_scope, con_scope;
gboolean id_specified = FALSE;
gboolean wait = TRUE;
int i;
@@ -1640,8 +1575,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
goto error;
}
if ((connection = find_connection (nmc->system_connections, selector, *argv)) == NULL)
connection = find_connection (nmc->user_connections, selector, *argv);
connection = find_connection (nmc->system_connections, selector, *argv);
if (!connection) {
g_string_printf (nmc->return_text, _("Error: Unknown connection: %s."), *argv);
@@ -1682,20 +1616,21 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
con_path = nm_connection_get_path (connection);
con_scope = nm_connection_get_scope (connection);
active_cons = nm_client_get_active_connections (nmc->client);
for (i = 0; active_cons && (i < active_cons->len); i++) {
NMActiveConnection *candidate = g_ptr_array_index (active_cons, i);
active_path = nm_active_connection_get_connection (candidate);
active_service_scope = nm_active_connection_get_scope (candidate);
if (!strcmp (active_path, con_path) && active_service_scope == con_scope) {
if (!strcmp (active_path, con_path)) {
active = candidate;
break;
}
}
/* TODO: fail gracefully if we are using an old N-M with user settings
* support */
if (active)
nm_client_deactivate_connection (nmc->client, active);
else {
@@ -1710,26 +1645,12 @@ error:
/* callback called when connections are obtained from the settings service */
static void
get_connections_cb (NMSettingsInterface *settings, gpointer user_data)
get_connections_cb (NMRemoteSettings *settings, gpointer user_data)
{
ArgsInfo *args = (ArgsInfo *) user_data;
static gboolean system_cb_called = FALSE;
static gboolean user_cb_called = FALSE;
GError *error = NULL;
if (NM_IS_REMOTE_SETTINGS_SYSTEM (settings)) {
system_cb_called = TRUE;
args->nmc->system_connections = nm_settings_interface_list_connections (settings);
}
else {
user_cb_called = TRUE;
args->nmc->user_connections = nm_settings_interface_list_connections (settings);
}
/* return and wait for the callback of the second settings is called */
if ( (args->nmc->system_settings_running && !system_cb_called)
|| (args->nmc->user_settings_running && !user_cb_called))
return;
args->nmc->system_connections = nm_remote_settings_list_connections (settings);
if (args->argc == 0) {
if (!nmc_terse_option_check (args->nmc->print_output, args->nmc->required_fields, &error))
@@ -1798,38 +1719,26 @@ do_connections (NmCli *nmc, int argc, char **argv)
}
/* get system settings */
if (!(nmc->system_settings = nm_remote_settings_system_new (bus))) {
if (!(nmc->system_settings = nm_remote_settings_new (bus))) {
g_string_printf (nmc->return_text, _("Error: Could not get system settings."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
return nmc->return_value;
}
/* get user settings */
if (!(nmc->user_settings = nm_remote_settings_new (bus, NM_CONNECTION_SCOPE_USER))) {
g_string_printf (nmc->return_text, _("Error: Could not get user settings."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
return nmc->return_value;
}
/* find out whether setting services are running */
/* find out whether settings service is running */
g_object_get (nmc->system_settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &nmc->system_settings_running, NULL);
g_object_get (nmc->user_settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &nmc->user_settings_running, NULL);
if (!nmc->system_settings_running && !nmc->user_settings_running) {
g_string_printf (nmc->return_text, _("Error: Can't obtain connections: settings services are not running."));
if (!nmc->system_settings_running) {
g_string_printf (nmc->return_text, _("Error: Can't obtain connections: settings service is not running."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
return nmc->return_value;
}
/* connect to signal "connections-read" - emitted when connections are fetched and ready */
if (nmc->system_settings_running)
g_signal_connect (nmc->system_settings, NM_SETTINGS_INTERFACE_CONNECTIONS_READ,
G_CALLBACK (get_connections_cb), &args_info);
g_signal_connect (nmc->system_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
G_CALLBACK (get_connections_cb), &args_info);
if (nmc->user_settings_running)
g_signal_connect (nmc->user_settings, NM_SETTINGS_INTERFACE_CONNECTIONS_READ,
G_CALLBACK (get_connections_cb), &args_info);
dbus_g_connection_unref (bus);

View File

@@ -33,9 +33,6 @@
#include <nm-client.h>
#include <nm-setting-connection.h>
#include <nm-remote-settings.h>
#include <nm-remote-settings-system.h>
#include <nm-settings-interface.h>
#include <nm-settings-connection-interface.h>
#include "nmcli.h"
#include "utils.h"
@@ -275,13 +272,8 @@ nmc_init (NmCli *nmc)
nmc->timeout = 10;
nmc->system_settings = NULL;
nmc->user_settings = NULL;
nmc->system_settings_running = FALSE;
nmc->user_settings_running = FALSE;
nmc->system_connections = NULL;
nmc->user_connections = NULL;
nmc->should_wait = FALSE;
nmc->nowait_flag = TRUE;
@@ -302,10 +294,7 @@ nmc_cleanup (NmCli *nmc)
g_string_free (nmc->return_text, TRUE);
if (nmc->system_settings) g_object_unref (nmc->system_settings);
if (nmc->user_settings) g_object_unref (nmc->user_settings);
g_slist_free (nmc->system_connections);
g_slist_free (nmc->user_connections);
g_free (nmc->required_fields);
if (nmc->print_fields.indices)

View File

@@ -24,7 +24,6 @@
#include <nm-client.h>
#include <nm-remote-settings.h>
#include <nm-remote-settings-system.h>
/* nmcli exit codes */
typedef enum {
@@ -95,14 +94,9 @@ typedef struct _NmCli {
int timeout; /* Operation timeout */
NMRemoteSettingsSystem *system_settings; /* System settings */
NMRemoteSettings *user_settings; /* User settings */
NMRemoteSettings *system_settings; /* System settings */
gboolean system_settings_running; /* Is system settings service running? */
gboolean user_settings_running; /* Is user settings service running? */
GSList *system_connections; /* List of system connections */
GSList *user_connections; /* List of user connections */
gboolean should_wait; /* Indication that nmcli should not end yet */
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */

View File

@@ -93,8 +93,7 @@ static NmcOutputField nmc_fields_setting_8021X[] = {
SETTING_FIELD (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, 20), /* 18 */
SETTING_FIELD (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD, 20), /* 19 */
SETTING_FIELD (NM_SETTING_802_1X_PIN, 8), /* 20 */
SETTING_FIELD (NM_SETTING_802_1X_PSK, 8), /* 21 */
SETTING_FIELD (NM_SETTING_802_1X_SYSTEM_CA_CERTS, 17), /* 22 */
SETTING_FIELD (NM_SETTING_802_1X_SYSTEM_CA_CERTS, 17), /* 21 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_SETTING_802_1X_ALL "name"","\
@@ -118,7 +117,6 @@ static NmcOutputField nmc_fields_setting_8021X[] = {
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY","\
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD","\
NM_SETTING_802_1X_PIN","\
NM_SETTING_802_1X_PSK","\
NM_SETTING_802_1X_SYSTEM_CA_CERTS
#define NMC_FIELDS_SETTING_802_1X_COMMON NMC_FIELDS_SETTING_802_1X_ALL
@@ -660,8 +658,7 @@ setting_802_1X_details (NMSetting *setting, NmCli *nmc)
nmc->allowed_fields[18].value = phase2_private_key_str;
nmc->allowed_fields[19].value = nm_setting_802_1x_get_phase2_private_key_password (s_8021X);
nmc->allowed_fields[20].value = nm_setting_802_1x_get_pin (s_8021X);
nmc->allowed_fields[21].value = nm_setting_802_1x_get_psk (s_8021X);
nmc->allowed_fields[22].value = nm_setting_802_1x_get_system_ca_certs (s_8021X) ? _("yes") : _("no");
nmc->allowed_fields[21].value = nm_setting_802_1x_get_system_ca_certs (s_8021X) ? _("yes") : _("no");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */

View File

@@ -241,6 +241,8 @@ PKG_CHECK_MODULES(GIO, gio-2.0)
AC_SUBST(GIO_CFLAGS)
AC_SUBST(GIO_LIBS)
GOBJECT_INTROSPECTION_CHECK([0.9.6])
AC_ARG_WITH(udev-dir, AS_HELP_STRING([--with-udev-dir=DIR], [where the udev base directory is]))
if test -n "$with_udev_dir" ; then
UDEV_BASE_DIR="$with_udev_dir"
@@ -259,6 +261,19 @@ if test "x$with_systemdsystemunitdir" != xno; then
fi
AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
dnl
dnl Disable ConsoleKit support
dnl
AC_ARG_WITH(ck, AS_HELP_STRING([--without-ck], [Build NetworkManager without ConsoleKit session tracking support]))
AM_CONDITIONAL(WITH_CONSOLEKIT, test x"$with_ck" != xno)
no_ck=0
if test x"$with_ck" = x"no"; then
no_ck="1"
else
with_ck="yes"
fi
AC_DEFINE_UNQUOTED(NO_CONSOLEKIT, $no_ck, [Define to disable use of ConsoleKit])
PKG_CHECK_MODULES(LIBNL, libnl-1 >= 1.0-pre8)
AC_SUBST(LIBNL_CFLAGS)
AC_SUBST(LIBNL_LIBS)
@@ -537,8 +552,8 @@ src/ppp-manager/Makefile
src/dnsmasq-manager/Makefile
src/modem-manager/Makefile
src/bluez-manager/Makefile
src/settings/Makefile
src/wimax/Makefile
src/system-settings/Makefile
src/backends/Makefile
libnm-util/libnm-util.pc
libnm-util/Makefile
@@ -547,6 +562,7 @@ libnm-util/tests/certs/Makefile
libnm-glib/libnm-glib.pc
libnm-glib/libnm-glib-vpn.pc
libnm-glib/Makefile
libnm-glib/tests/Makefile
callouts/Makefile
tools/Makefile
system-settings/Makefile
@@ -630,6 +646,12 @@ else
echo systemd support: no
fi
if test -n "${with_ck}"; then
echo ConsoleKit support: ${with_ck}
else
echo ConsoleKit support: no
fi
if test "${enable_wimax}" = "yes"; then
echo WiMAX support: yes
else

View File

@@ -45,13 +45,11 @@ IGNORE_HFILES= \
nm-device-wifi-bindings.h \
nm-dhcp4-config-bindings.h \
nm-dhcp6-config-bindings.h \
nm-exported-connection-bindings.h \
nm-exported-connection-glue.h \
nm-settings-connection-glue.h \
nm-ip4-config-bindings.h \
nm-ip6-config-bindings.h \
nm-settings-bindings.h \
nm-settings-glue.h \
nm-settings-system-bindings.h \
nm-vpn-connection-bindings.h \
nm-vpn-plugin-glue.h

View File

@@ -22,20 +22,15 @@
<xi:include href="xml/nm-gsm-device.xml"/>
<xi:include href="xml/nm-cdma-device.xml"/>
<xi:include href="xml/nm-device-bt.xml"/>
<xi:include href="xml/nm-device-wimax.xml"/>
<xi:include href="xml/nm-access-point.xml"/>
<xi:include href="xml/nm-ip4-config.xml"/>
<xi:include href="xml/nm-ip6-config.xml"/>
<xi:include href="xml/nm-dhcp4-config.xml"/>
<xi:include href="xml/nm-dhcp6-config.xml"/>
<xi:include href="xml/nm-exported-connection.xml"/>
<xi:include href="xml/nm-object.xml"/>
<xi:include href="xml/nm-remote-connection.xml"/>
<xi:include href="xml/nm-remote-settings.xml"/>
<xi:include href="xml/nm-remote-settings-system.xml"/>
<xi:include href="xml/nm-settings-connection-interface.xml"/>
<xi:include href="xml/nm-settings-interface.xml"/>
<xi:include href="xml/nm-settings-service.xml"/>
<xi:include href="xml/nm-settings-system-interface.xml"/>
<xi:include href="xml/nm-types.xml"/>
<xi:include href="xml/nm-vpn-connection.xml"/>
<xi:include href="xml/nm-vpn-plugin.xml"/>

View File

@@ -13,7 +13,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 Red Hat, Inc.
* (C) Copyright 2011 Red Hat, Inc.
*/
/*
@@ -74,7 +74,7 @@ add_connection (DBusGProxy *proxy, const char *con_name)
NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
hash = nm_connection_to_hash (connection);
hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
/* Call AddConnection with the hash as argument */
dbus_g_proxy_call (proxy, "AddConnection", &error,
@@ -99,7 +99,7 @@ int main (int argc, char *argv[])
/* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */
proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
NM_DBUS_SERVICE,
NM_DBUS_PATH_SETTINGS,
NM_DBUS_IFACE_SETTINGS);

View File

@@ -13,7 +13,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 Red Hat, Inc.
* (C) Copyright 2011 Red Hat, Inc.
*/
/*
@@ -69,7 +69,7 @@ int main (int argc, char *argv[])
/* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */
proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
NM_DBUS_SERVICE,
NM_DBUS_PATH_SETTINGS,
NM_DBUS_IFACE_SETTINGS);

View File

@@ -13,7 +13,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 Red Hat, Inc.
* (C) Copyright 2011 Red Hat, Inc.
*/
/*
@@ -36,8 +36,6 @@
#include <NetworkManager.h>
#include <nm-utils.h>
#include <nm-remote-settings.h>
#include <nm-remote-settings-system.h>
#include <nm-settings-interface.h>
/* Global variables */
@@ -101,17 +99,17 @@ show_connection (NMConnection *data, gpointer user_data)
* Now the connections can be listed.
*/
static void
get_connections_cb (NMSettingsInterface *settings, gpointer user_data)
get_connections_cb (NMRemoteSettings *settings, gpointer user_data)
{
GSList *system_connections;
GSList *connections;
system_connections = nm_settings_interface_list_connections (settings);
connections = nm_remote_settings_list_connections (settings);
printf ("System connections:\n===================\n");
printf ("Connections:\n===================\n");
g_slist_foreach (system_connections, (GFunc) show_connection, NULL);
g_slist_foreach (connections, (GFunc) show_connection, NULL);
g_slist_free (system_connections);
g_slist_free (connections);
g_object_unref (settings);
/* We are done, exit main loop */
@@ -123,11 +121,11 @@ static gboolean
list_connections (gpointer data)
{
DBusGConnection *bus = (DBusGConnection *) data;
NMRemoteSettingsSystem *system_settings;
gboolean system_settings_running;
NMRemoteSettings *settings;
gboolean settings_running;
/* Get system settings */
if (!(system_settings = nm_remote_settings_system_new (bus))) {
if (!(settings = nm_remote_settings_new (bus))) {
g_message ("Error: Could not get system settings.");
result = EXIT_FAILURE;
g_main_loop_quit (loop);
@@ -135,9 +133,9 @@ list_connections (gpointer data)
}
/* Find out whether setting service is running */
g_object_get (system_settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &system_settings_running, NULL);
g_object_get (settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &settings_running, NULL);
if (!system_settings_running) {
if (!settings_running) {
g_message ("Error: Can't obtain connections: settings service is not running.");
result = EXIT_FAILURE;
g_main_loop_quit (loop);
@@ -145,7 +143,7 @@ list_connections (gpointer data)
}
/* Connect to signal "connections-read" - emitted when connections are fetched and ready */
g_signal_connect (system_settings, NM_SETTINGS_INTERFACE_CONNECTIONS_READ,
g_signal_connect (settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
G_CALLBACK (get_connections_cb), NULL);
return FALSE;

View File

@@ -41,8 +41,8 @@ con = dbus.Dictionary({
bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.NetworkManagerSystemSettings", "/org/freedesktop/NetworkManagerSettings")
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings")
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
settings.AddConnection(con)

View File

@@ -70,25 +70,24 @@ def connection_to_string(config):
print ""
def print_one_services_connections(service_name, desc):
def print_connections():
# Ask the settings service for the list of connections it provides
proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManagerSettings")
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings")
service_name = "org.freedesktop.NetworkManager"
proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
connection_paths = settings.ListConnections()
print "%s connections --------------------------------------------\n" % desc
# List each connection's name, UUID, and type
for path in connection_paths:
con_proxy = bus.get_object(service_name, path)
connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManagerSettings.Connection")
connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
config = connection.GetSettings()
# Now get secrets too; we grab the secrets for each type of connection
# (since there isn't a "get all secrets" call because most of the time
# you only need 'wifi' secrets or '802.1x' secrets, not everything) and
# merge that into the configuration data
connection_secrets = dbus.Interface(con_proxy, "org.freedesktop.NetworkManagerSettings.Connection.Secrets")
connection_secrets = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection.Secrets")
merge_secrets(connection_secrets, config, '802-11-wireless')
merge_secrets(connection_secrets, config, '802-11-wireless-security')
merge_secrets(connection_secrets, config, '802-1x')
@@ -106,7 +105,5 @@ def print_one_services_connections(service_name, desc):
print ""
# Print out connection information for all connections
print_one_services_connections("org.freedesktop.NetworkManagerSystemSettings", "System")
print_one_services_connections("org.freedesktop.NetworkManagerUserSettings", "User")
print_connections()

View File

@@ -53,11 +53,8 @@ for a in active:
# needed to connect to a specific network. Lets get those details so we
# can find the user-readable name of the connection.
con_path = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "Connection")
con_service = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "ServiceName")
# ask the provider of the connection for its details
service_proxy = bus.get_object(con_service, con_path)
con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManagerSettings.Connection")
service_proxy = bus.get_object("org.freedesktop.NetworkManager", con_path)
con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
con_details = con_iface.GetSettings()
con_name = con_details['connection']['id']

View File

@@ -37,16 +37,16 @@ DBusGMainLoop(set_as_default=True)
def get_connections():
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManagerUserSettings', '/org/freedesktop/NetworkManagerSettings')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManagerSettings')
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager/Settings')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings')
return iface.ListConnections()
def get_connection_by_uuid(uuid):
bus = dbus.SystemBus()
for c in get_connections():
proxy = bus.get_object('org.freedesktop.NetworkManagerUserSettings', c)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManagerSettings.Connection')
proxy = bus.get_object('org.freedesktop.NetworkManager', c)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
settings = iface.GetSettings()
if settings['connection']['uuid'] == uuid:
return c
@@ -57,8 +57,8 @@ def get_connection_by_uuid(uuid):
def list_uuids():
bus = dbus.SystemBus()
for c in get_connections():
proxy = bus.get_object('org.freedesktop.NetworkManagerUserSettings', c)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManagerSettings.Connection')
proxy = bus.get_object('org.freedesktop.NetworkManager', c)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
settings = iface.GetSettings()
conn = settings['connection']
print "%s - %s (%s)" % (conn['uuid'], conn['id'], conn['type'])
@@ -76,8 +76,8 @@ def get_active_connection_path(uuid):
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')
path = iface.Get('org.freedesktop.NetworkManager.Connection.Active', 'Connection')
proxy = bus.get_object('org.freedesktop.NetworkManagerUserSettings', path)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManagerSettings.Connection')
proxy = bus.get_object('org.freedesktop.NetworkManager', path)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
settings = iface.GetSettings()
if settings['connection']['uuid'] == uuid:
@@ -112,7 +112,7 @@ def activate_connection(connection_path, device_path):
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager')
iface.ActivateConnection('org.freedesktop.NetworkManagerUserSettings',
iface.ActivateConnection('org.freedesktop.NetworkManager',
connection_path,
device_path,
"/",

View File

@@ -48,16 +48,18 @@
#define NM_DBUS_INTERFACE_DHCP6_CONFIG NM_DBUS_INTERFACE ".DHCP6Config"
#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings"
#define NM_DBUS_SERVICE_SYSTEM_SETTINGS "org.freedesktop.NetworkManagerSystemSettings"
#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManagerSettings"
#define NM_DBUS_IFACE_SETTINGS_SYSTEM "org.freedesktop.NetworkManagerSettings.System"
#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManagerSettings"
#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager.Settings"
#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManager/Settings"
#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection"
#define NM_DBUS_PATH_SETTINGS_CONNECTION "/org/freedesktop/NetworkManagerSettings/Connection"
#define NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS "org.freedesktop.NetworkManagerSettings.Connection.Secrets"
#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManager.Settings.Connection"
#define NM_DBUS_PATH_SETTINGS_CONNECTION "/org/freedesktop/NetworkManager/Settings/Connection"
#define NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS "org.freedesktop.NetworkManager.Settings.Connection.Secrets"
#define NM_DBUS_INTERFACE_AGENT_MANAGER NM_DBUS_INTERFACE ".AgentManager"
#define NM_DBUS_PATH_AGENT_MANAGER "/org/freedesktop/NetworkManager/AgentManager"
#define NM_DBUS_INTERFACE_SECRET_AGENT NM_DBUS_INTERFACE ".SecretAgent"
#define NM_DBUS_PATH_SECRET_AGENT "/org/freedesktop/NetworkManager/SecretAgent"
/*
* Types of NetworkManager states
@@ -154,7 +156,7 @@ typedef enum {
* NMBluetoothCapabilities:
* @NM_BT_CAPABILITY_NONE: device has no usable capabilities
* @NM_BT_CAPABILITY_DUN: device provides Dial-Up Networking capability
* @NM_BT_CAPABILITY_PAN: device provides Personal Area Networking capability
* @NM_BT_CAPABILITY_NAP: device provides Network Access Point capability
*
* #NMBluetoothCapabilities values indicate the usable capabilities of a
* Bluetooth device.

View File

@@ -18,13 +18,14 @@ EXTRA_DIST = \
nm-manager.xml \
nm-manager-client.xml \
nm-settings.xml \
nm-settings-system.xml \
nm-exported-connection.xml \
nm-settings-connection.xml \
nm-vpn-plugin.xml \
nm-vpn-connection.xml \
nm-ppp-manager.xml \
nm-active-connection.xml \
nm-dhcp4-config.xml \
nm-dhcp6-config.xml \
nm-wimax-nsp.xml
nm-agent-manager.xml \
nm-wimax-nsp.xml \
nm-secret-agent.xml

View File

@@ -42,8 +42,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</
<xi:include href="nm-dhcp4-config.xml"/>
<xi:include href="nm-dhcp6-config.xml"/>
<xi:include href="nm-settings.xml"/>
<xi:include href="nm-exported-connection.xml"/>
<xi:include href="nm-settings-connection.xml"/>
<xi:include href="nm-active-connection.xml"/>
<xi:include href="nm-agent-manager.xml"/>
<xi:include href="nm-vpn-connection.xml"/>
<xi:include href="nm-vpn-plugin.xml"/>

View File

@@ -5,7 +5,7 @@
<tp:error name="Unknown Connection">
<tp:docstring>
Connection was not provided by any known settings service.
Connection was not provided by the settings service.
</tp:docstring>
</tp:error>
@@ -15,18 +15,6 @@
</tp:docstring>
</tp:error>
<tp:error name="Invalid Service">
<tp:docstring>
Invalid settings service (not a recognized system or user settings service name).
</tp:docstring>
</tp:error>
<tp:error name="System Connection">
<tp:docstring>
Connection was superseded by a system connection.
</tp:docstring>
</tp:error>
<tp:error name="Permission Denied">
<tp:docstring>
User does not have the permission to activate this connection.

View File

@@ -2,9 +2,6 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.Connection.Active">
<property name="ServiceName" type="s" access="read">
<tp:docstring>The D-Bus service name providing this connection.</tp:docstring>
</property>
<property name="Connection" type="o" access="read">
<tp:docstring>The path of the connection.</tp:docstring>
</property>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.AgentManager">
<method name="Register">
<tp:docstring>
Called by secret Agents to register their ability to provide and save
network secrets.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="identifier" type="s" direction="in">
<tp:docstring>
Identifies this agent; only one agent in each user session may use the
same identifier. Identifier formatting follows the same rules as
D-Bus bus names with the exception that the ':' character is not
allowed. The valid set of characters is "[A-Z][a-z][0-9]_-." and the
identifier is limited in length to 255 characters with a minimum
of 3 characters. An example valid identifier is 'org.gnome.nm-applet'
(without quotes).
</tp:docstring>
</arg>
</method>
<method name="Unregister">
<tp:docstring>
Called by secret Agents to notify NetworkManager that they will no
longer handle requests for network secrets. Agents are automatically
unregistered when they disconnect from D-Bus.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_unregister"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method>
</interface>
</node>

View File

@@ -22,13 +22,22 @@ object. dbus-glib generates the same bound function names for D-Bus the methods
<method name="ActivateConnection">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="service_name" type="s" direction="in"/>
<arg name="connection" type="o" direction="in"/>
<arg name="device" type="o" direction="in"/>
<arg name="specific_object" type="o" direction="in"/>
<arg name="active_connection" type="o" direction="out"/>
</method>
<method name="AddAndActivateConnection">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_add_and_activate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in"/>
<arg name="device" type="o" direction="in"/>
<arg name="specific_object" type="o" direction="in"/>
<arg name="path" type="o" direction="out"/>
<arg name="active_connection" type="o" direction="out"/>
</method>
<method name="DeactivateConnection">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_deactivate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>

View File

@@ -27,11 +27,6 @@
<tp:docstring>
Activate a connection using the supplied device.
</tp:docstring>
<arg name="service_name" type="s" direction="in">
<tp:docstring>
The D-Bus service name of the settings service that provides this connection.
</tp:docstring>
</arg>
<arg name="connection" type="o" direction="in">
<tp:docstring>
The connection to activate the devices with.
@@ -62,7 +57,6 @@
<tp:possible-errors>
<tp:error name="org.freedesktop.NetworkManager.Error.UnknownConnection"/>
<tp:error name="org.freedesktop.NetworkManager.Error.UnknownDevice"/>
<tp:error name="org.freedesktop.NetworkManager.Error.InvalidService"/>
<tp:error name="org.freedesktop.NetworkManager.Error.ConnectionActivating">
<tp:docstring>Another connection is already activating or the same connection is already active. FIXME: check if the error name is correct. FIXME: split into 2 errors?</tp:docstring>
</tp:error>
@@ -72,6 +66,55 @@
</tp:possible-errors>
</method>
<method name="AddAndActivateConnection">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_add_and_activate_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<tp:docstring>
Adds a new connection using the given details (if any) as a template
(automatically filling in missing settings with the capabilities of the
given device and specific object), then activate the new connection.
Cannot be used for VPN connections at this time.
</tp:docstring>
<arg name="connection" type="a{sa{sv}}" direction="in">
<tp:docstring>
Connection settings and properties; if incomplete missing settings will
be automatically completed using the given device and specific object.
</tp:docstring>
</arg>
<arg name="device" type="o" direction="in">
<tp:docstring>
The object path of device to be activated using the given connection.
</tp:docstring>
</arg>
<arg name="specific_object" type="o" direction="in">
<tp:docstring>
The path of a connection-type-specific object this activation should use.
This parameter is currently ignored for wired and mobile broadband connections,
and the value of "/" should be used (ie, no specific object). For WiFi
connections, pass the object path of a specific AP from the card's scan
list, which will be used to complete the details of the newly added
connection.
</tp:docstring>
</arg>
<arg name="path" type="o" direction="out">
<tp:docstring>
Object path of the new connection that was just added.
</tp:docstring>
</arg>
<arg name="active_connection" type="o" direction="out">
<tp:docstring>
The path of the active connection object representing this active connection.
</tp:docstring>
</arg>
<tp:possible-errors>
<tp:error name="org.freedesktop.NetworkManager.Error.UnknownConnection"/>
<tp:error name="org.freedesktop.NetworkManager.Error.UnknownDevice"/>
<tp:error name="org.freedesktop.NetworkManager.Error.ConnectionInvalid">
<tp:docstring>The connection is invalid for this device.</tp:docstring>
</tp:error>
</tp:possible-errors>
</method>
<method name="DeactivateConnection">
<tp:docstring>
Deactivate an active connection.

View File

@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.SecretAgent">
<tp:docstring>
Private D-Bus interface used by secret agents that store and provide
secrets to NetworkManager.
</tp:docstring>
<method name="GetSecrets">
<tp:docstring>
Retrieve and return stored secrets, if any, or request new
secrets from the agent's user.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_get_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
Nested settings maps containing the connection for which
secrets are being requested. This may contain system-owned
secrets if the agent has successfully authenticated to
modify system network settings and the GetSecrets request
flags allow user interaction.
</tp:docstring>
</arg>
<arg name="connection_path" type="o" direction="in">
<tp:docstring>
Object path of the connection for which secrets are being
requested.
</tp:docstring>
</arg>
<arg name="setting_name" type="s" direction="in">
<tp:docstring>
Setting name for which secrets are being requested.
</tp:docstring>
</arg>
<arg name="hints" type="as" direction="in">
<tp:docstring>
Array of strings of key names in the requested setting for
which NetworkManager thinks a secrets may be required. The
Agent should return any secrets it has, or that it thinks
are required, regardless of what hints NetworkManager sends
in this request.
</tp:docstring>
</arg>
<arg name="flags" type="u" direction="in" tp:type="NM_SECRET_AGENT_GET_SECRETS_FLAGS">
<tp:docstring>
Flags which modify the behavior of the secrets request.
If true, new secrets are assumed to be invalid or incorrect,
and the agent should ask the user for new secrets. If false,
existing secrets should be retrieved from storage and
returned without interrupting the user.
</tp:docstring>
</arg>
<arg name="secrets" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
Nested settings maps containing secrets. Each setting MUST
contain at least the 'name' field, containing the name of
the setting, and one or more secrets.
</tp:docstring>
</arg>
</method>
<tp:flags name="NM_SECRET_AGENT_GET_SECRETS_FLAGS" value-prefix="NM_SECRET_AGENT_GET_SECRETS_FLAG" type="u">
<tp:docstring>
Flags modifying the behavior of GetSecrets request.
</tp:docstring>
<tp:flag suffix="NONE" value="0x0">
<tp:docstring>
No special behavior; by default no user interaction is allowed and
requests for secrets are fulfilled from persistent storage, or
if no secrets are available an error is returned.
</tp:docstring>
</tp:flag>
<tp:flag suffix="ALLOW_INTERACTION" value="0x1">
<tp:docstring>
Allows the request to interact with the user, possibly prompting
via UI for secrets if any are required, or if none are found in
persistent storage.
</tp:docstring>
</tp:flag>
<tp:flag suffix="REQUEST_NEW" value="0x2">
<tp:docstring>
Explicitly prompt for new secrets from the user. This flag
signals that NetworkManager thinks any existing secrets are
invalid or wrong. This flag implies that interaction is allowed.
</tp:docstring>
</tp:flag>
</tp:flags>
<method name="CancelGetSecrets">
<tp:docstring>
Cancel a pending GetSecrets request for secrets of the given
connection. Any matching request should be canceled.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_cancel_get_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection_path" type="o" direction="in">
<tp:docstring>
Object path of the connection for which, if secrets are being
requested, the request should be canceled.
</tp:docstring>
</arg>
<arg name="setting_name" type="s" direction="in">
<tp:docstring>
Setting name for which secrets for this connection were
originally being requested.
</tp:docstring>
</arg>
</method>
<method name="SaveSecrets">
<tp:docstring>
Save given secrets to backing storage.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_save_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
Nested settings maps containing the entire connection
(including secrets), for which the agent should save the
secrets to backing storage.
</tp:docstring>
</arg>
<arg name="connection_path" type="o" direction="in">
<tp:docstring>
Object path of the connection for which the agent should
save secrets to backing storage.
</tp:docstring>
</arg>
</method>
<method name="DeleteSecrets">
<tp:docstring>
Delete secrets from backing storage.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_delete_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
Nested settings maps containing the connection properties
(sans secrets), for which the agent should delete the
secrets from backing storage.
</tp:docstring>
</arg>
<arg name="connection_path" type="o" direction="in">
<tp:docstring>
Object path of the connection for which the agent should
delete secrets from backing storage.
</tp:docstring>
</arg>
</method>
</interface>
</node>

View File

@@ -2,20 +2,23 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManagerSettings.Connection">
<interface name="org.freedesktop.NetworkManager.Settings.Connection">
<tp:docstring>
Represents a single network connection configuration.
</tp:docstring>
<method name="Update">
<tp:docstring>
Update the connection with new settings and properties, replacing all previous settings and properties.
Update the connection with new settings and properties, replacing
all previous settings and properties. Secrets may be part of the
update request, and will be either stored in persistent storage or
given to a Secret Agent for storage, depending on the request.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_update"/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_update"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="properties" type="a{sa{sv}}" direction="in">
<tp:docstring>
New connection properties.
New connection settings, properties, and (optionally) secrets.
</tp:docstring>
</arg>
</method>
@@ -24,15 +27,19 @@
<tp:docstring>
Delete the connection.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_delete"/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_delete"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method>
<method name="GetSettings">
<tp:docstring>
Get the settings maps describing this object.
Get the settings maps describing this network configuration.
This will never include any secrets required for connection
to the network, as those are often protected. Secrets must
be requested separately using the GetSecrets() call.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_get_settings"/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_get_settings"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="settings" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
The nested settings maps describing this object.
@@ -40,60 +47,47 @@
</arg>
</method>
<signal name="Updated">
<tp:docstring>
Emitted when some settings changed.
</tp:docstring>
<arg name="settings" type="a{sa{sv}}" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
Contains complete connection setting parameters, including changes.
</tp:docstring>
</arg>
</signal>
<signal name="Removed">
<tp:docstring>
Emitted when this connection has been deleted/removed. After receipt of this signal, the object no longer exists.
</tp:docstring>
</signal>
</interface>
<interface name="org.freedesktop.NetworkManagerSettings.Connection.Secrets">
<tp:docstring>
Secrets have a separate interface so that they can be locked down.
</tp:docstring>
<method name="GetSecrets">
<tp:docstring>
Get the secrets encapsulated in this object.
Get the secrets belonging to this network configuration. Only
secrets from persistent storage or a Secret Agent running in
the requestor's session will be returned. The user will never
be prompted for secrets as a result of this request.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_get_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_get_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="setting_name" type="s" direction="in">
<tp:docstring>
Name of the setting to return.
</tp:docstring>
</arg>
<arg name="hints" type="as" direction="in">
<tp:docstring>
Array of strings of key names in the Setting for which NM thinks
a secrets may be required.
</tp:docstring>
</arg>
<arg name="request_new" type="b" direction="in">
<tp:docstring>
Indicates whether new secrets should be requested or if the request can be fulfilled from storage.
Name of the setting to return secrets for. If empty, all
all secrets will be returned.
</tp:docstring>
</arg>
<arg name="secrets" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map">
<tp:docstring>
Nested settings maps containing secrets. Each setting MUST contain at least the 'name' field, containing the name of the setting, and one or more secrets.
Nested settings maps containing secrets.
</tp:docstring>
</arg>
</method>
<signal name="Updated">
<tp:docstring>
Emitted when any settings or permissions change. When handling
this signal, clients should re-read the connection using the
GetSettings method to get the changes and to ensure the client
still has permission to access the connection.
</tp:docstring>
</signal>
<signal name="Removed">
<tp:docstring>
Emitted when this connection is no longer available. This
happens when the connection is deleted or if it is no longer
accessable by any of the system's logged-in users. After
receipt of this signal, the object no longer exists.
</tp:docstring>
</signal>
</interface>
</node>

View File

@@ -1,81 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManagerSettings.System">
<tp:docstring>
Implemented by the system settings service to provide additional settings to NetworkManager.
</tp:docstring>
<method name="SaveHostname">
<tp:docstring>
Save the hostname to persistent configuration.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_save_hostname"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="hostname" type="s" direction="in">
<tp:docstring>
The hostname to save to persistent configuration. If blank, the persistent hostname is cleared.
</tp:docstring>
</arg>
</method>
<property name="Hostname" type="s" access="read">
<tp:docstring>
The machine hostname stored in persistent configuration.
</tp:docstring>
</property>
<property name="CanModify" type="b" access="read">
<tp:docstring>
If true, adding and modifying connections is supported.
</tp:docstring>
</property>
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
<tp:docstring>
A dictionary mapping property names to variant boxed values
</tp:docstring>
</arg>
</signal>
<signal name="CheckPermissions">
<tp:docstring>
Emitted when system authorization details change, indicating that clients may wish to recheck permissions with GetPermissions.
</tp:docstring>
</signal>
<method name="GetPermissions">
<tp:docstring>
Returns a bitfield indicating certain operations the caller is permitted to perform. Some of these operations may require authorization by the user.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_get_permissions"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="permissions" type="u" direction="out" tp:type="NM_SETTINGS_SYSTEM_PERMISSIONS">
<tp:docstring>
A bitfield of permitted operations. Some of these operations may require the user to authorize via password entry or other means.
</tp:docstring>
</arg>
</method>
<tp:flags name="NM_SETTINGS_SYSTEM_PERMISSIONS" value-prefix="NM_SETTINGS_SYSTEM_PERMISSION" type="u">
<tp:flag suffix="NONE" value="0x0">
<tp:docstring>No permissions.</tp:docstring>
</tp:flag>
<tp:flag suffix="CONNECTION_MODIFY" value="0x1">
<tp:docstring>Can modify/add/delete connections.</tp:docstring>
</tp:flag>
<tp:flag suffix="WIFI_SHARING_PROTECTED" value="0x2">
<tp:docstring>Can share connections via a encrypted user-created WiFi network.</tp:docstring>
</tp:flag>
<tp:flag suffix="WIFI_SHARING_OPEN" value="0x4">
<tp:docstring>Can share connections via a open/unencrypted user-created WiFi network.</tp:docstring>
</tp:flag>
<tp:flag suffix="HOSTNAME_MODIFY" value="0x8">
<tp:docstring>Can modify the persistent system hostname.</tp:docstring>
</tp:flag>
</tp:flags>
</interface>
</node>

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManagerSettings">
<interface name="org.freedesktop.NetworkManager.Settings">
<tp:docstring>
The NetworkManagerSettings interface is provided by the service which provides connections to NetworkManager.
The Settings interface allows clients to view and administrate the connections stored and used by NetworkManager.
</tp:docstring>
<method name="ListConnections">
@@ -29,8 +29,46 @@
Connection settings and properties.
</tp:docstring>
</arg>
<arg name="path" type="o" direction="out">
<tp:docstring>
Object path of the new connection that was just added.
</tp:docstring>
</arg>
</method>
<method name="SaveHostname">
<tp:docstring>
Save the hostname to persistent configuration.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_save_hostname"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="hostname" type="s" direction="in">
<tp:docstring>
The hostname to save to persistent configuration. If blank, the persistent hostname is cleared.
</tp:docstring>
</arg>
</method>
<property name="Hostname" type="s" access="read">
<tp:docstring>
The machine hostname stored in persistent configuration.
</tp:docstring>
</property>
<property name="CanModify" type="b" access="read">
<tp:docstring>
If true, adding and modifying connections is supported.
</tp:docstring>
</property>
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
<tp:docstring>
A dictionary mapping property names to variant boxed values
</tp:docstring>
</arg>
</signal>
<signal name="NewConnection">
<tp:docstring>
Emitted when a new connection has been added.

View File

@@ -1,3 +1,5 @@
SUBDIRS=. tests
INCLUDES = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/libnm-util \
@@ -10,26 +12,27 @@ BUILT_SOURCES = \
nm-device-ethernet-bindings.h \
nm-device-wifi-bindings.h \
nm-device-bt-bindings.h \
nm-settings-connection-bindings.h \
nm-device-wimax-bindings.h \
nm-exported-connection-glue.h \
nm-exported-connection-bindings.h \
nm-settings-glue.h \
nm-settings-bindings.h \
nm-settings-system-bindings.h \
nm-vpn-connection-bindings.h \
nm-vpn-plugin-glue.h \
nm-active-connection-bindings.h \
nm-ip4-config-bindings.h \
nm-dhcp4-config-bindings.h \
nm-ip6-config-bindings.h \
nm-dhcp6-config-bindings.h
nm-dhcp6-config-bindings.h \
nm-secret-agent-glue.h
noinst_LTLIBRARIES = \
libdeprecated-nm-glib.la \
libnm-glib-test.la
#####################################################
# Deprecated original libnm_glib bits
#####################################################
noinst_LTLIBRARIES = libdeprecated-nm-glib.la
libdeprecated_nm_glib_la_SOURCES = \
libnm_glib.h \
libnm_glib.c
@@ -44,6 +47,9 @@ libdeprecated_nm_glib_la_LIBADD = \
$(DBUS_LIBS) \
$(GLIB_LIBS)
libdeprecateddir = $(includedir)/libnm-glib
libdeprecated_HEADERS = libnm_glib.h
#####################################################
# Real libnm-glib stuff
#####################################################
@@ -56,9 +62,9 @@ libnm_glib_la_CFLAGS = \
$(GUDEV_CFLAGS)
libnmincludedir = $(includedir)/libnm-glib
libnmvpndir = $(includedir)/libnm-glib
libnminclude_HEADERS = \
libnm_glib.h \
nm-object.h \
nm-client.h \
nm-device.h \
@@ -71,32 +77,27 @@ libnminclude_HEADERS = \
nm-cdma-device.h \
nm-serial-device.h \
nm-vpn-connection.h \
nm-vpn-plugin.h \
nm-vpn-plugin-ui-interface.h \
nm-types.h \
nm-active-connection.h \
nm-dhcp4-config.h \
nm-ip6-config.h \
nm-dhcp6-config.h \
nm-remote-connection.h \
nm-settings-interface.h \
nm-settings-system-interface.h \
nm-remote-settings.h \
nm-remote-settings-system.h \
nm-settings-connection-interface.h \
nm-exported-connection.h \
nm-settings-service.h \
nm-secret-agent.h \
nm-device-wimax.h \
nm-wimax-nsp.h
libnm_glib_la_SOURCES = \
libnmvpn_HEADERS = \
nm-vpn-plugin.h \
nm-vpn-plugin-ui-interface.h \
nm-vpn-plugin-utils.h
libnm_glib_la_csources = \
nm-object.c \
nm-object-private.h \
nm-client.c \
nm-dbus-utils.c \
nm-dbus-utils.h \
nm-device.c \
nm-device-private.h \
nm-device-ethernet.c \
nm-device-wifi.c \
nm-device-bt.c \
@@ -107,25 +108,29 @@ libnm_glib_la_SOURCES = \
nm-serial-device.c \
nm-vpn-connection.c \
nm-types.c \
nm-types-private.h \
nm-object-cache.c \
nm-object-cache.h \
nm-active-connection.c \
nm-dhcp4-config.c \
nm-ip6-config.c \
nm-dhcp6-config.c \
nm-remote-connection.c \
nm-remote-connection-private.h \
nm-settings-interface.c \
nm-settings-system-interface.c \
nm-remote-settings.c \
nm-remote-settings-system.c \
nm-settings-connection-interface.c \
nm-exported-connection.c \
nm-settings-service.c \
nm-secret-agent.c \
nm-device-wimax.c \
nm-wimax-nsp.c
libnm_glib_la_private_headers = \
nm-object-private.h \
nm-dbus-utils.h \
nm-device-private.h \
nm-types-private.h \
nm-object-cache.h \
nm-remote-connection-private.h
libnm_glib_la_SOURCES = \
$(libnm_glib_la_csources) \
$(libnm_glib_la_private_headers)
libnm_glib_la_LIBADD = \
$(top_builddir)/libnm-util/libnm-util.la \
$(top_builddir)/marshallers/libmarshallers.la \
@@ -135,7 +140,7 @@ libnm_glib_la_LIBADD = \
$(GUDEV_LIBS)
libnm_glib_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnm-glib.ver \
-version-info "6:2:4"
-version-info "7:0:5"
noinst_PROGRAMS = libnm-glib-test
@@ -144,12 +149,37 @@ libnm_glib_test_CFLAGS = $(GLIB_CFLAGS) $(DBUS_CFLAGS)
libnm_glib_test_LDADD = libnm-glib.la $(top_builddir)/libnm-util/libnm-util.la $(GLIB_LIBS) $(DBUS_LIBS)
libnm_glib_vpn_la_SOURCES = nm-vpn-plugin.c nm-vpn-plugin-ui-interface.c
libnm_glib_vpn_la_SOURCES = \
nm-vpn-plugin.c \
nm-vpn-plugin-ui-interface.c \
nm-vpn-plugin-utils.c
libnm_glib_vpn_la_CFLAGS = $(GLIB_CFLAGS) $(DBUS_CFLAGS)
libnm_glib_vpn_la_LIBADD = $(top_builddir)/libnm-util/libnm-util.la $(GLIB_LIBS) $(DBUS_LIBS)
libnm_glib_vpn_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnm-glib-vpn.ver \
-version-info "1:0:0"
#####################################################
# Test libnm-glib stuff
#####################################################
libnm_glib_test_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
$(GUDEV_CFLAGS) \
-DLIBNM_GLIB_TEST
libnm_glib_test_la_SOURCES = \
$(libnminclude_HEADERS) \
$(libnm_glib_la_SOURCES)
libnm_glib_test_la_LIBADD = \
$(top_builddir)/libnm-util/libnm-util.la \
$(top_builddir)/marshallers/libmarshallers.la \
$(GLIB_LIBS) \
$(DBUS_LIBS) \
$(GUDEV_LIBS)
#####################################################
nm-client-bindings.h: $(top_srcdir)/introspection/nm-manager-client.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_client --mode=glib-client --output=$@ $<
@@ -169,20 +199,11 @@ nm-device-bt-bindings.h: $(top_srcdir)/introspection/nm-device-bt.xml
nm-access-point-bindings.h: $(top_srcdir)/introspection/nm-access-point.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_access_point --mode=glib-client --output=$@ $<
nm-settings-glue.h: $(top_srcdir)/introspection/nm-settings.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_settings --mode=glib-server --output=$@ $<
nm-settings-bindings.h: $(top_srcdir)/introspection/nm-settings.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_settings --mode=glib-client --output=$@ $<
nm-settings-system-bindings.h: $(top_srcdir)/introspection/nm-settings-system.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_settings_system --mode=glib-client --output=$@ $<
nm-exported-connection-glue.h: $(top_srcdir)/introspection/nm-exported-connection.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_exported_connection --mode=glib-server --output=$@ $<
nm-exported-connection-bindings.h: $(top_srcdir)/introspection/nm-exported-connection.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_exported_connection --mode=glib-client --output=$@ $<
nm-settings-connection-bindings.h: $(top_srcdir)/introspection/nm-settings-connection.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_settings_connection --mode=glib-client --output=$@ $<
nm-vpn-connection-bindings.h: $(top_srcdir)/introspection/nm-vpn-connection.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-client --output=$@ $<
@@ -205,6 +226,9 @@ nm-ip6-config-bindings.h: $(top_srcdir)/introspection/nm-ip6-config.xml
nm-dhcp6-config-bindings.h: $(top_srcdir)/introspection/nm-dhcp6-config.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_dhcp6_config --mode=glib-client --output=$@ $<
nm-secret-agent-glue.h: $(top_srcdir)/introspection/nm-secret-agent.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_secret_agent --mode=glib-server --output=$@ $<
nm-device-wimax-bindings.h: $(top_srcdir)/introspection/nm-device-wimax.xml
dbus-binding-tool --prefix=nm_device_wimax --mode=glib-client --output=$@ $<
@@ -216,3 +240,28 @@ DISTCLEANFILES = libnm-glib.pc libnm-glib.pc
EXTRA_DIST = libnm-glib.pc.in libnm-glib-vpn.pc.in libnm-glib.ver libnm-glib-vpn.ver
CLEANFILES = $(BUILT_SOURCES)
-include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_GIRS =
INTROSPECTION_COMPILER_ARGS = --includedir=$(top_builddir)/libnm-util
if HAVE_INTROSPECTION
introspection_sources = $(libnminclude_HEADERS) $(libnm_glib_la_csources)
NMClient-1.0.gir: libnm-glib.la
NMClient_1_0_gir_INCLUDES = GObject-2.0 DBusGLib-1.0
NMClient_1_0_gir_PACKAGES = gobject-2.0 dbus-glib-1 gudev-1.0
NMClient_1_0_gir_CFLAGS = $(INCLUDES) -I$(top_srcdir)/libnm-glib -I$(top_srcdir)/libnm-util
NMClient_1_0_gir_LIBS = libnm-glib.la
NMClient_1_0_gir_FILES = $(introspection_sources)
NMClient_1_0_gir_SCANNERFLAGS = --warn-all --identifier-prefix=NM --symbol-prefix=nm_ --include-uninstalled=$(top_builddir)/libnm-util/NetworkManager-1.0.gir
INTROSPECTION_GIRS += NMClient-1.0.gir
girdir = $(datadir)/gir-1.0
gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = $(libdir)/girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
CLEANFILES += $(gir_DATA) $(typelib_DATA)
endif

View File

@@ -21,6 +21,8 @@ global:
nm_vpn_plugin_ui_widget_interface_get_widget;
nm_vpn_plugin_ui_widget_interface_save_secrets;
nm_vpn_plugin_ui_widget_interface_update_connection;
nm_vpn_plugin_utils_get_secret_flags;
nm_vpn_plugin_utils_read_vpn_details;
local:
*;
};

View File

@@ -6,7 +6,7 @@ includedir=@includedir@
Name: libnm-glib
Description: Convenience library for clients of NetworkManager
Version: @VERSION@
Requires: NetworkManager >= 0.7.999 glib-2.0 dbus-glib-1
Requires: NetworkManager >= 0.7.999 gobject-2.0 dbus-glib-1
Cflags: -I${includedir}/libnm-glib
Libs: -L${libdir} -lnm-glib

View File

@@ -20,8 +20,6 @@ global:
nm_active_connection_get_default;
nm_active_connection_get_default6;
nm_active_connection_get_devices;
nm_active_connection_get_scope;
nm_active_connection_get_service_name;
nm_active_connection_get_specific_object;
nm_active_connection_get_state;
nm_active_connection_get_type;
@@ -29,6 +27,7 @@ global:
nm_cdma_device_get_type;
nm_cdma_device_new;
nm_client_activate_connection;
nm_client_add_and_activate_connection;
nm_client_deactivate_connection;
nm_client_get_active_connections;
nm_client_get_device_by_path;
@@ -94,6 +93,17 @@ global:
nm_device_wifi_get_mode;
nm_device_wifi_get_type;
nm_device_wifi_new;
nm_device_wimax_get_bsid;
nm_device_wimax_get_center_frequency;
nm_device_wimax_get_cinr;
nm_device_wimax_get_hw_address;
nm_device_wimax_get_active_nsp;
nm_device_wimax_get_nsp_by_path;
nm_device_wimax_get_nsps;
nm_device_wimax_get_rssi;
nm_device_wimax_get_tx_power;
nm_device_wimax_get_type;
nm_device_wimax_new;
nm_dhcp4_config_get_one_option;
nm_dhcp4_config_get_options;
nm_dhcp4_config_get_type;
@@ -102,9 +112,6 @@ global:
nm_dhcp6_config_get_options;
nm_dhcp6_config_get_type;
nm_dhcp6_config_new;
nm_exported_connection_export;
nm_exported_connection_get_type;
nm_exported_connection_new;
nm_gsm_device_get_type;
nm_gsm_device_new;
nm_ip4_config_get_addresses;
@@ -128,38 +135,31 @@ global:
nm_object_get_connection;
nm_object_get_path;
nm_object_get_type;
nm_remote_connection_delete;
nm_remote_connection_get_secrets;
nm_remote_connection_commit_changes;
nm_remote_connection_get_type;
nm_remote_connection_new;
nm_remote_settings_add_connection;
nm_remote_settings_error_get_type;
nm_remote_settings_error_quark;
nm_remote_settings_get_connection_by_path;
nm_remote_settings_get_permissions;
nm_remote_settings_get_type;
nm_remote_settings_list_connections;
nm_remote_settings_new;
nm_remote_settings_system_get_type;
nm_remote_settings_system_new;
nm_remote_settings_save_hostname;
nm_secret_agent_delete_secrets;
nm_secret_agent_error_get_type;
nm_secret_agent_error_quark;
nm_secret_agent_get_secrets;
nm_secret_agent_get_type;
nm_secret_agent_register;
nm_secret_agent_save_secrets;
nm_secret_agent_unregister;
nm_serial_device_get_bytes_received;
nm_serial_device_get_bytes_sent;
nm_serial_device_get_type;
nm_settings_connection_interface_delete;
nm_settings_connection_interface_emit_updated;
nm_settings_connection_interface_get_secrets;
nm_settings_connection_interface_get_type;
nm_settings_connection_interface_update;
nm_settings_interface_add_connection;
nm_settings_interface_error_get_type;
nm_settings_interface_error_quark;
nm_settings_interface_get_connection_by_path;
nm_settings_interface_get_type;
nm_settings_interface_list_connections;
nm_settings_service_export;
nm_settings_service_export_connection;
nm_settings_service_get_connection_by_path;
nm_settings_service_get_type;
nm_settings_system_interface_get_type;
nm_settings_system_interface_add_connection;
nm_settings_system_interface_get_permissions;
nm_settings_system_interface_save_hostname;
nm_settings_error_quark;
nm_settings_get_type;
nm_settings_list_connections;
nm_settings_signal_new_connection;
nm_ssid_get_type;
nm_string_array_get_type;
nm_uint_array_get_type;
@@ -167,17 +167,6 @@ global:
nm_vpn_connection_get_type;
nm_vpn_connection_get_vpn_state;
nm_vpn_connection_new;
nm_device_wimax_get_bsid;
nm_device_wimax_get_center_frequency;
nm_device_wimax_get_cinr;
nm_device_wimax_get_hw_address;
nm_device_wimax_get_active_nsp;
nm_device_wimax_get_nsp_by_path;
nm_device_wimax_get_nsps;
nm_device_wimax_get_rssi;
nm_device_wimax_get_tx_power;
nm_device_wimax_get_type;
nm_device_wimax_new;
nm_wimax_nsp_get_name;
nm_wimax_nsp_get_network_type;
nm_wimax_nsp_get_signal_quality;

View File

@@ -43,8 +43,6 @@ typedef struct {
gboolean disposed;
DBusGProxy *proxy;
char *service_name;
NMConnectionScope scope;
char *connection;
char *specific_object;
GPtrArray *devices;
@@ -55,7 +53,6 @@ typedef struct {
enum {
PROP_0,
PROP_SERVICE_NAME,
PROP_CONNECTION,
PROP_SPECIFIC_OBJECT,
PROP_DEVICES,
@@ -66,7 +63,6 @@ enum {
LAST_PROP
};
#define DBUS_PROP_SERVICE_NAME "ServiceName"
#define DBUS_PROP_CONNECTION "Connection"
#define DBUS_PROP_SPECIFIC_OBJECT "SpecificObject"
#define DBUS_PROP_DEVICES "Devices"
@@ -95,62 +91,6 @@ nm_active_connection_new (DBusGConnection *connection, const char *path)
NULL);
}
static NMConnectionScope
get_scope_for_service_name (const char *service_name)
{
if (service_name && !strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS))
return NM_CONNECTION_SCOPE_USER;
else if (service_name && !strcmp (service_name, NM_DBUS_SERVICE_SYSTEM_SETTINGS))
return NM_CONNECTION_SCOPE_SYSTEM;
return NM_CONNECTION_SCOPE_UNKNOWN;
}
/**
* nm_active_connection_get_service_name:
* @connection: a #NMActiveConnection
*
* Gets the service name of the active connection.
*
* Returns: the service name. This is the internal string used by the
* connection, and must not be modified.
**/
const char *
nm_active_connection_get_service_name (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->service_name) {
priv->service_name = _nm_object_get_string_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_SERVICE_NAME);
priv->scope = get_scope_for_service_name (priv->service_name);
}
return priv->service_name;
}
/**
* nm_active_connection_get_scope:
* @connection: a #NMActiveConnection
*
* Gets the scope of the active connection.
*
* Returns: the connection's scope
**/
NMConnectionScope
nm_active_connection_get_scope (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_CONNECTION_SCOPE_UNKNOWN);
/* Make sure service_name and scope are up-to-date */
nm_active_connection_get_service_name (connection);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->scope;
}
/**
* nm_active_connection_get_connection:
* @connection: a #NMActiveConnection
@@ -209,7 +149,7 @@ nm_active_connection_get_specific_object (NMActiveConnection *connection)
*
* Gets the #NMDevice<!-- -->s used for the active connections.
*
* Returns: the #GPtrArray containing #NMDevice<!-- -->s.
* Returns: (element-type NMClient.Device): the #GPtrArray containing #NMDevice<!-- -->s.
* This is the internal copy used by the connection, and must not be modified.
**/
const GPtrArray *
@@ -345,7 +285,6 @@ finalize (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
g_free (priv->service_name);
g_free (priv->connection);
g_free (priv->specific_object);
@@ -361,11 +300,8 @@ get_property (GObject *object,
NMActiveConnection *self = NM_ACTIVE_CONNECTION (object);
switch (prop_id) {
case PROP_SERVICE_NAME:
g_value_set_string (value, nm_active_connection_get_service_name (self));
break;
case PROP_CONNECTION:
g_value_set_boxed (value, nm_active_connection_get_connection (self));
g_value_set_string (value, nm_active_connection_get_connection (self));
break;
case PROP_SPECIFIC_OBJECT:
g_value_set_boxed (value, nm_active_connection_get_specific_object (self));
@@ -401,24 +337,11 @@ demarshal_devices (NMObject *object, GParamSpec *pspec, GValue *value, gpointer
return TRUE;
}
static gboolean
demarshal_service (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
if (_nm_object_demarshal_generic (object, pspec, value, field)) {
priv->scope = get_scope_for_service_name (priv->service_name);
return TRUE;
}
return FALSE;
}
static void
register_for_property_changed (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_ACTIVE_CONNECTION_SERVICE_NAME, demarshal_service, &priv->service_name },
{ NM_ACTIVE_CONNECTION_CONNECTION, _nm_object_demarshal_generic, &priv->connection },
{ NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, _nm_object_demarshal_generic, &priv->specific_object },
{ NM_ACTIVE_CONNECTION_DEVICES, demarshal_devices, &priv->devices },
@@ -475,19 +398,6 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
/* properties */
/**
* NMActiveConnection:service-name:
*
* The service name of the active connection.
**/
g_object_class_install_property
(object_class, PROP_SERVICE_NAME,
g_param_spec_string (NM_ACTIVE_CONNECTION_SERVICE_NAME,
"Service Name",
"Service Name",
NULL,
G_PARAM_READABLE));
/**
* NMActiveConnection:connection:
*

View File

@@ -39,7 +39,6 @@ G_BEGIN_DECLS
#define NM_IS_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_ACTIVE_CONNECTION))
#define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass))
#define NM_ACTIVE_CONNECTION_SERVICE_NAME "service-name"
#define NM_ACTIVE_CONNECTION_CONNECTION "connection"
#define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object"
#define NM_ACTIVE_CONNECTION_DEVICES "devices"
@@ -67,8 +66,6 @@ GType nm_active_connection_get_type (void);
GObject *nm_active_connection_new (DBusGConnection *connection, const char *path);
const char * nm_active_connection_get_service_name (NMActiveConnection *connection);
NMConnectionScope nm_active_connection_get_scope (NMActiveConnection *connection);
const char * nm_active_connection_get_connection (NMActiveConnection *connection);
const char * nm_active_connection_get_specific_object (NMActiveConnection *connection);
const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection);

View File

@@ -327,11 +327,17 @@ register_for_property_changed (NMClient *client)
property_changed_info);
}
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI "org.freedesktop.NetworkManager.enable-disable-wifi"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN "org.freedesktop.NetworkManager.enable-disable-wwan"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX "org.freedesktop.NetworkManager.enable-disable-wimax"
#define NM_AUTH_PERMISSION_USE_USER_CONNECTIONS "org.freedesktop.NetworkManager.use-user-connections"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI "org.freedesktop.NetworkManager.enable-disable-wifi"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN "org.freedesktop.NetworkManager.enable-disable-wwan"
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX "org.freedesktop.NetworkManager.enable-disable-wimax"
#define NM_AUTH_PERMISSION_SLEEP_WAKE "org.freedesktop.NetworkManager.sleep-wake"
#define NM_AUTH_PERMISSION_NETWORK_CONTROL "org.freedesktop.NetworkManager.network-control"
#define NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED "org.freedesktop.NetworkManager.wifi.share.protected"
#define NM_AUTH_PERMISSION_WIFI_SHARE_OPEN "org.freedesktop.NetworkManager.wifi.share.open"
#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM "org.freedesktop.NetworkManager.settings.modify.system"
#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN "org.freedesktop.NetworkManager.settings.modify.own"
#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME "org.freedesktop.NetworkManager.settings.modify.hostname"
static NMClientPermission
nm_permission_to_client (const char *nm)
@@ -344,8 +350,21 @@ nm_permission_to_client (const char *nm)
return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN;
else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX))
return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX;
else if (!strcmp (nm, NM_AUTH_PERMISSION_USE_USER_CONNECTIONS))
return NM_CLIENT_PERMISSION_USE_USER_CONNECTIONS;
else if (!strcmp (nm, NM_AUTH_PERMISSION_SLEEP_WAKE))
return NM_CLIENT_PERMISSION_SLEEP_WAKE;
else if (!strcmp (nm, NM_AUTH_PERMISSION_NETWORK_CONTROL))
return NM_CLIENT_PERMISSION_NETWORK_CONTROL;
else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED))
return NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED;
else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN))
return NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN;
else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM))
return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM;
else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN))
return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN;
else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME))
return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME;
return NM_CLIENT_PERMISSION_NONE;
}
@@ -504,9 +523,9 @@ constructor (GType type,
get_permissions_sync (NM_CLIENT (object));
priv->bus_proxy = dbus_g_proxy_new_for_name (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
@@ -648,7 +667,7 @@ get_property (GObject *object,
g_value_set_boolean (value, priv->manager_running);
break;
case PROP_NETWORKING_ENABLED:
g_value_set_boolean (value, priv->networking_enabled);
g_value_set_boolean (value, nm_client_networking_get_enabled (self));
break;
case PROP_WIRELESS_ENABLED:
g_value_set_boolean (value, priv->wireless_enabled);
@@ -813,6 +832,7 @@ nm_client_class_init (NMClientClass *client_class)
* NMClient::active-connections:
*
* The active connections.
* Type: GPtrArray<NMClient.ActiveConnection>
**/
g_object_class_install_property
(object_class, PROP_ACTIVE_CONNECTIONS,
@@ -827,7 +847,7 @@ nm_client_class_init (NMClientClass *client_class)
/**
* NMClient::device-added:
* @client: the client that received the signal
* @device: the new device
* @device: (type NMClient.Device): the new device
*
* Notifies that a #NMDevice is added.
**/
@@ -844,7 +864,7 @@ nm_client_class_init (NMClientClass *client_class)
/**
* NMClient::device-removed:
* @widget: the client that received the signal
* @device: the removed device
* @device: (type NMClient.Device): the removed device
*
* Notifies that a #NMDevice is removed.
**/
@@ -888,7 +908,11 @@ nm_client_new (void)
DBusGConnection *connection;
GError *err = NULL;
#ifdef LIBNM_GLIB_TEST
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
#else
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
#endif
if (!connection) {
g_warning ("Couldn't connect to system bus: %s", err->message);
g_error_free (err);
@@ -992,7 +1016,7 @@ client_device_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
*
* Gets all the detected devices.
*
* Returns: a #GPtrArray containing all the #NMDevice<!-- -->s.
* Returns: (transfer none) (element-type NMClient.Device): a #GPtrArray containing all the #NMDevice<!-- -->s.
* The returned array is owned by the client and should not be modified.
**/
const GPtrArray *
@@ -1032,7 +1056,7 @@ nm_client_get_devices (NMClient *client)
*
* Gets a #NMDevice from a #NMClient.
*
* Returns: the #NMDevice for the given @object_path or %NULL if none is found.
* Returns: (transfer none): the #NMDevice for the given @object_path or %NULL if none is found.
**/
NMDevice *
nm_client_get_device_by_path (NMClient *client, const char *object_path)
@@ -1060,7 +1084,9 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path)
}
typedef struct {
NMClientActivateDeviceFn fn;
NMClient *client;
NMClientActivateDeviceFn act_fn;
NMClientAddActivateFn add_act_fn;
gpointer user_data;
} ActivateDeviceInfo;
@@ -1072,8 +1098,8 @@ activate_cb (DBusGProxy *proxy,
{
ActivateDeviceInfo *info = (ActivateDeviceInfo *) user_data;
if (info->fn)
info->fn (info->user_data, path, error);
if (info->act_fn)
info->act_fn (info->client, path, error, info->user_data);
else if (error)
nm_warning ("Device activation failed: (%d) %s", error->code, error->message);
@@ -1083,19 +1109,17 @@ activate_cb (DBusGProxy *proxy,
/**
* nm_client_activate_connection:
* @client: a #NMClient
* @service_name: the connection's service name
* @connection_path: the connection's DBus path
* @device: the #NMDevice
* @specific_object: the device specific object (currently used only for
* activating wireless devices and should be the #NMAccessPoint<!-- -->'s path.
* @callback: the function to call when the call is done
* @callback: (scope async): the function to call when the call is done
* @user_data: user data to pass to the callback function
*
* Activates a connection with the given #NMDevice.
**/
void
nm_client_activate_connection (NMClient *client,
const char *service_name,
const char *connection_path,
NMDevice *device,
const char *specific_object,
@@ -1103,30 +1127,92 @@ nm_client_activate_connection (NMClient *client,
gpointer user_data)
{
ActivateDeviceInfo *info;
char *internal_so = (char *) specific_object;
g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (service_name != NULL);
g_return_if_fail (connection_path != NULL);
/* NULL specific object must be translated into "/" because D-Bus does
* not have any idea of NULL object paths.
*/
if (internal_so == NULL)
internal_so = "/";
info = g_slice_new (ActivateDeviceInfo);
info->fn = callback;
info->act_fn = callback;
info->user_data = user_data;
info->client = client;
org_freedesktop_NetworkManager_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->client_proxy,
service_name,
connection_path,
nm_object_get_path (NM_OBJECT (device)),
internal_so,
activate_cb,
info);
connection_path,
nm_object_get_path (NM_OBJECT (device)),
specific_object ? specific_object : "/",
activate_cb,
info);
}
static void
add_activate_cb (DBusGProxy *proxy,
char *connection_path,
char *active_path,
GError *error,
gpointer user_data)
{
ActivateDeviceInfo *info = (ActivateDeviceInfo *) user_data;
if (info->add_act_fn)
info->add_act_fn (info->client, connection_path, active_path, error, info->user_data);
else if (error)
nm_warning ("Connection add and activate failed: (%d) %s", error->code, error->message);
g_slice_free (ActivateDeviceInfo, info);
}
/**
* nm_client_add_and_activate_connection:
* @client: a #NMClient
* @partial: an #NMConnection to add; the connection may be partially filled
* and will be completed by NetworkManager using the given @device and
* @specific_object before being added
* @device: the #NMDevice
* @specific_object: (allow-none): the object path of a connection-type-specific
* object this activation should use. This parameter is currently ignored for
* wired and mobile broadband connections, and the value of NULL should be used
* (ie, no specific object). For WiFi connections, pass the object path of a
* specific AP from the card's scan list, which will be used to complete the
* details of the newly added connection.
* @callback: (scope async): the function to call when the call is done
* @user_data: (closure): user data to pass to the callback function
*
* Adds a new connection using the given details (if any) as a template
* (automatically filling in missing settings with the capabilities of the
* given device and specific object), then activate the new connection.
* Cannot be used for VPN connections at this time.
**/
void
nm_client_add_and_activate_connection (NMClient *client,
NMConnection *partial,
NMDevice *device,
const char *specific_object,
NMClientAddActivateFn callback,
gpointer user_data)
{
ActivateDeviceInfo *info;
GHashTable *hash = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_DEVICE (device));
info = g_slice_new (ActivateDeviceInfo);
info->add_act_fn = callback;
info->user_data = user_data;
info->client = client;
if (partial)
hash = nm_connection_to_hash (partial, NM_SETTING_HASH_FLAG_ALL);
else
hash = g_hash_table_new (g_str_hash, g_str_equal);
org_freedesktop_NetworkManager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->client_proxy,
hash,
nm_object_get_path (NM_OBJECT (device)),
specific_object ? specific_object : "/",
add_activate_cb,
info);
g_hash_table_unref (hash);
}
/**
@@ -1161,7 +1247,8 @@ nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active)
*
* Gets the active connections.
*
* Returns: a #GPtrArray containing all the active #NMActiveConnection<!-- -->s.
* Returns: (transfer none) (element-type NMClient.ActiveConnection): a #GPtrArray
* containing all the active #NMActiveConnection<!-- -->s.
* The returned array is owned by the client and should not be modified.
**/
const GPtrArray *

View File

@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
*/
#ifndef NM_CLIENT_H
@@ -58,10 +58,16 @@ typedef enum {
NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK = 1,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI = 2,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN = 3,
NM_CLIENT_PERMISSION_USE_USER_CONNECTIONS = 4,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX = 5,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX = 4,
NM_CLIENT_PERMISSION_SLEEP_WAKE = 5,
NM_CLIENT_PERMISSION_NETWORK_CONTROL = 6,
NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED = 7,
NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN = 8,
NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM = 9,
NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN = 10,
NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME = 11,
NM_CLIENT_PERMISSION_LAST = NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX
NM_CLIENT_PERMISSION_LAST = NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME
} NMClientPermission;
typedef enum {
@@ -82,6 +88,9 @@ typedef struct {
/* Signals */
void (*device_added) (NMClient *client, NMDevice *device);
void (*device_removed) (NMClient *client, NMDevice *device);
void (*permission_changed) (NMClient *client,
NMClientPermission permission,
NMClientPermissionResult result);
/* Padding for future expansion */
void (*_reserved1) (void);
@@ -99,15 +108,30 @@ NMClient *nm_client_new (void);
const GPtrArray *nm_client_get_devices (NMClient *client);
NMDevice *nm_client_get_device_by_path (NMClient *client, const char *object_path);
typedef void (*NMClientActivateDeviceFn) (gpointer user_data, const char *object_path, GError *error);
typedef void (*NMClientActivateDeviceFn) (NMClient *client,
const char *object_path,
GError *error,
gpointer user_data);
void nm_client_activate_connection (NMClient *client,
const char *service_name,
const char *connection_path,
NMDevice *device,
const char *specific_object,
NMClientActivateDeviceFn callback,
gpointer user_data);
const char *connection_path,
NMDevice *device,
const char *specific_object,
NMClientActivateDeviceFn callback,
gpointer user_data);
typedef void (*NMClientAddActivateFn) (NMClient *client,
const char *connection_path,
const char *active_path,
GError *error,
gpointer user_data);
void nm_client_add_and_activate_connection (NMClient *client,
NMConnection *partial,
NMDevice *device,
const char *specific_object,
NMClientAddActivateFn callback,
gpointer user_data);
void nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active);

View File

@@ -252,7 +252,7 @@ nm_device_wifi_get_capabilities (NMDeviceWifi *device)
*
* Gets the active #NMAccessPoint.
*
* Returns: the access point or %NULL if none is active
* Returns: (transfer none): the access point or %NULL if none is active
**/
NMAccessPoint *
nm_device_wifi_get_active_access_point (NMDeviceWifi *device)
@@ -302,7 +302,8 @@ nm_device_wifi_get_active_access_point (NMDeviceWifi *device)
*
* Gets all the scanned access points of the #NMDeviceWifi.
*
* Returns: a #GPtrArray containing all the scanned #NMAccessPoint<!-- -->s.
* Returns: (element-type NMClient.AccessPoint): a #GPtrArray containing all the
* scanned #NMAccessPoint<!-- -->s.
* The returned array is owned by the client and should not be modified.
**/
const GPtrArray *
@@ -342,7 +343,7 @@ nm_device_wifi_get_access_points (NMDeviceWifi *device)
*
* Gets a #NMAccessPoint by path.
*
* Returns: the access point or %NULL if none is found.
* Returns: (transfer none): the access point or %NULL if none is found.
**/
NMAccessPoint *
nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,

View File

@@ -108,12 +108,12 @@ nm_device_wimax_new (DBusGConnection *connection, const char *path)
/**
* nm_device_wimax_get_hw_address:
* @device: a #NMDeviceWimax
* @wimax: a #NMDeviceWimax
*
* Gets the hardware (MAC) address of the #NMDeviceWimax
*
* Returns: the hardware address. This is the internal string used by the
* device, and must not be modified.
* device, and must not be modified.
**/
const char *
nm_device_wimax_get_hw_address (NMDeviceWimax *wimax)
@@ -138,7 +138,7 @@ nm_device_wimax_get_hw_address (NMDeviceWimax *wimax)
*
* Gets the active #NMWimaxNsp.
*
* Returns: the access point or %NULL if none is active
* Returns: (transfer full): the access point or %NULL if none is active
**/
NMWimaxNsp *
nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax)
@@ -188,7 +188,8 @@ nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax)
*
* Gets all the scanned NSPs of the #NMDeviceWimax.
*
* Returns: a #GPtrArray containing all the scanned #NMWimaxNsp<!-- -->s.
* Returns: (element-type NMClient.WimaxNsp): a #GPtrArray containing
* all the scanned #NMWimaxNsp<!-- -->s.
* The returned array is owned by the client and should not be modified.
**/
const GPtrArray *
@@ -228,7 +229,7 @@ nm_device_wimax_get_nsps (NMDeviceWimax *wimax)
*
* Gets a #NMWimaxNsp by path.
*
* Returns: the access point or %NULL if none is found.
* Returns: (transfer none): the access point or %NULL if none is found.
**/
NMWimaxNsp *
nm_device_wimax_get_nsp_by_path (NMDeviceWimax *wimax,
@@ -339,7 +340,7 @@ clean_up_nsps (NMDeviceWimax *self, gboolean notify)
/**
* nm_device_wimax_get_center_frequency:
* @device: a #NMDeviceWimax
* @self: a #NMDeviceWimax
*
* Gets the center frequency (in KHz) of the radio channel the device is using
* to communicate with the network when connected. Has no meaning when the
@@ -348,15 +349,15 @@ clean_up_nsps (NMDeviceWimax *self, gboolean notify)
* Returns: the center frequency in KHz, or 0
**/
guint
nm_device_wimax_get_center_frequency (NMDeviceWimax *wimax)
nm_device_wimax_get_center_frequency (NMDeviceWimax *self)
{
NMDeviceWimaxPrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), 0);
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
if (!priv->center_freq) {
priv->center_freq = _nm_object_get_uint_property (NM_OBJECT (wimax),
priv->center_freq = _nm_object_get_uint_property (NM_OBJECT (self),
NM_DBUS_INTERFACE_DEVICE_WIMAX,
DBUS_PROP_CENTER_FREQUENCY);
}
@@ -365,7 +366,7 @@ nm_device_wimax_get_center_frequency (NMDeviceWimax *wimax)
/**
* nm_device_wimax_get_rssi:
* @device: a #NMDeviceWimax
* @self: a #NMDeviceWimax
*
* Gets the RSSI of the current radio link in dBm. This value indicates how
* strong the raw received RF signal from the base station is, but does not
@@ -375,15 +376,15 @@ nm_device_wimax_get_center_frequency (NMDeviceWimax *wimax)
* Returns: the RSSI in dBm, or 0
**/
gint
nm_device_wimax_get_rssi (NMDeviceWimax *wimax)
nm_device_wimax_get_rssi (NMDeviceWimax *self)
{
NMDeviceWimaxPrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), 0);
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
if (!priv->rssi) {
priv->rssi = _nm_object_get_int_property (NM_OBJECT (wimax),
priv->rssi = _nm_object_get_int_property (NM_OBJECT (self),
NM_DBUS_INTERFACE_DEVICE_WIMAX,
DBUS_PROP_RSSI);
}
@@ -392,7 +393,7 @@ nm_device_wimax_get_rssi (NMDeviceWimax *wimax)
/**
* nm_device_wimax_get_cinr:
* @device: a #NMDeviceWimax
* @self: a #NMDeviceWimax
*
* Gets the CINR (Carrier to Interference + Noise Ratio) of the current radio
* link in dB. CINR is a more accurate measure of radio link quality. Has no
@@ -401,15 +402,15 @@ nm_device_wimax_get_rssi (NMDeviceWimax *wimax)
* Returns: the CINR in dB, or 0
**/
gint
nm_device_wimax_get_cinr (NMDeviceWimax *wimax)
nm_device_wimax_get_cinr (NMDeviceWimax *self)
{
NMDeviceWimaxPrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), 0);
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
if (!priv->cinr) {
priv->cinr = _nm_object_get_int_property (NM_OBJECT (wimax),
priv->cinr = _nm_object_get_int_property (NM_OBJECT (self),
NM_DBUS_INTERFACE_DEVICE_WIMAX,
DBUS_PROP_CINR);
}
@@ -418,7 +419,7 @@ nm_device_wimax_get_cinr (NMDeviceWimax *wimax)
/**
* nm_device_wimax_get_tx_power:
* @device: a #NMDeviceWimax
* @self: a #NMDeviceWimax
*
* Average power of the last burst transmitted by the device, in units of
* 0.5 dBm. i.e. a TxPower of -11 represents an actual device TX power of
@@ -427,15 +428,15 @@ nm_device_wimax_get_cinr (NMDeviceWimax *wimax)
* Returns: the TX power in dBm, or 0
**/
gint
nm_device_wimax_get_tx_power (NMDeviceWimax *wimax)
nm_device_wimax_get_tx_power (NMDeviceWimax *self)
{
NMDeviceWimaxPrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), 0);
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
if (!priv->tx_power) {
priv->tx_power = _nm_object_get_int_property (NM_OBJECT (wimax),
priv->tx_power = _nm_object_get_int_property (NM_OBJECT (self),
NM_DBUS_INTERFACE_DEVICE_WIMAX,
DBUS_PROP_TX_POWER);
}
@@ -444,22 +445,22 @@ nm_device_wimax_get_tx_power (NMDeviceWimax *wimax)
/**
* nm_device_wimax_get_bsid:
* @device: a #NMDeviceWimax
* @self: a #NMDeviceWimax
*
* Gets the ID of the serving Base Station when the device is connected.
*
* Returns: the ID of the serving Base Station, or NULL
**/
const char *
nm_device_wimax_get_bsid (NMDeviceWimax *wimax)
nm_device_wimax_get_bsid (NMDeviceWimax *self)
{
NMDeviceWimaxPrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
if (!priv->bsid) {
priv->bsid = _nm_object_get_string_property (NM_OBJECT (wimax),
priv->bsid = _nm_object_get_string_property (NM_OBJECT (self),
NM_DBUS_INTERFACE_DEVICE_WIMAX,
DBUS_PROP_BSID);
}

View File

@@ -934,7 +934,7 @@ nm_device_get_firmware_missing (NMDevice *device)
*
* Gets the current #NMIP4Config associated with the #NMDevice.
*
* Returns: the #NMIP4Config or %NULL if the device is not activated.
* Returns: (transfer none): the #NMIP4Config or %NULL if the device is not activated.
**/
NMIP4Config *
nm_device_get_ip4_config (NMDevice *device)
@@ -968,7 +968,7 @@ nm_device_get_ip4_config (NMDevice *device)
*
* Gets the current #NMDHCP4Config associated with the #NMDevice.
*
* Returns: the #NMDHCPConfig or %NULL if the device is not activated or not
* Returns: (transfer none): the #NMDHCPConfig or %NULL if the device is not activated or not
* using DHCP.
**/
NMDHCP4Config *
@@ -1003,7 +1003,7 @@ nm_device_get_dhcp4_config (NMDevice *device)
*
* Gets the current #NMIP6Config associated with the #NMDevice.
*
* Returns: the #NMIP6Config or %NULL if the device is not activated.
* Returns: (transfer none): the #NMIP6Config or %NULL if the device is not activated.
**/
NMIP6Config *
nm_device_get_ip6_config (NMDevice *device)
@@ -1037,7 +1037,7 @@ nm_device_get_ip6_config (NMDevice *device)
*
* Gets the current #NMDHCP6Config associated with the #NMDevice.
*
* Returns: the #NMDHCPConfig or %NULL if the device is not activated or not
* Returns: (transfer none): the #NMDHCPConfig or %NULL if the device is not activated or not
* using DHCP.
**/
NMDHCP6Config *
@@ -1317,7 +1317,7 @@ deactivate_cb (DBusGProxy *proxy,
/**
* nm_device_disconnect:
* @device: a #NMDevice
* @callback: callback to be called when disconnect operation completes
* @callback: (scope async): callback to be called when disconnect operation completes
* @user_data: caller-specific data passed to @callback
*
* Disconnects the device if currently connected, and prevents the device from

View File

@@ -203,7 +203,7 @@ nm_dhcp4_config_new (DBusGConnection *connection, const char *object_path)
*
* Gets all the options contained in the configuration.
*
* Returns: the #GHashTable containing strings for keys and values.
* Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values.
* This is the internal copy used by the configuration, and must not be modified.
**/
GHashTable *

View File

@@ -203,7 +203,7 @@ nm_dhcp6_config_new (DBusGConnection *connection, const char *object_path)
*
* Gets all the options contained in the configuration.
*
* Returns: the #GHashTable containing strings for keys and values.
* Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values.
* This is the internal copy used by the configuration, and must not be modified.
**/
GHashTable *

View File

@@ -1,281 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Novell, Inc.
* (C) Copyright 2008 - 2009 Red Hat, Inc.
*/
#include <NetworkManager.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <nm-setting-connection.h>
#include "nm-exported-connection.h"
#include "nm-settings-interface.h"
#include "nm-settings-connection-interface.h"
static gboolean impl_exported_connection_get_settings (NMExportedConnection *connection,
GHashTable **settings,
GError **error);
static void impl_exported_connection_update (NMExportedConnection *connection,
GHashTable *new_settings,
DBusGMethodInvocation *context);
static void impl_exported_connection_delete (NMExportedConnection *connection,
DBusGMethodInvocation *context);
static void impl_exported_connection_get_secrets (NMExportedConnection *connection,
const gchar *setting_name,
const gchar **hints,
gboolean request_new,
DBusGMethodInvocation *context);
#include "nm-exported-connection-glue.h"
static void settings_connection_interface_init (NMSettingsConnectionInterface *class);
G_DEFINE_TYPE_EXTENDED (NMExportedConnection, nm_exported_connection, NM_TYPE_CONNECTION, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_CONNECTION_INTERFACE,
settings_connection_interface_init))
#define NM_EXPORTED_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_EXPORTED_CONNECTION, \
NMExportedConnectionPrivate))
typedef struct {
gboolean foo;
} NMExportedConnectionPrivate;
/**************************************************************/
static GHashTable *
real_get_settings (NMExportedConnection *self, GError **error)
{
NMConnection *no_secrets;
GHashTable *settings;
/* Secrets should *never* be returned by the GetSettings method, they
* get returned by the GetSecrets method which can be better
* protected against leakage of secrets to unprivileged callers.
*/
no_secrets = nm_connection_duplicate (NM_CONNECTION (self));
g_assert (no_secrets);
nm_connection_clear_secrets (no_secrets);
settings = nm_connection_to_hash (no_secrets);
g_assert (settings);
g_object_unref (no_secrets);
return settings;
}
/**************************************************************/
static gboolean
check_writable (NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
s_con = (NMSettingConnection *) nm_connection_get_setting (connection,
NM_TYPE_SETTING_CONNECTION);
if (!s_con) {
g_set_error_literal (error,
NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_INVALID_CONNECTION,
"Connection did not have required 'connection' setting");
return FALSE;
}
/* If the connection is read-only, that has to be changed at the source of
* the problem (ex a system settings plugin that can't write connections out)
* instead of over D-Bus.
*/
if (nm_setting_connection_get_read_only (s_con)) {
g_set_error_literal (error,
NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_READ_ONLY_CONNECTION,
"Connection is read-only");
return FALSE;
}
return TRUE;
}
static gboolean
impl_exported_connection_get_settings (NMExportedConnection *self,
GHashTable **settings,
GError **error)
{
/* Must always be implemented */
g_assert (NM_EXPORTED_CONNECTION_GET_CLASS (self)->get_settings);
*settings = NM_EXPORTED_CONNECTION_GET_CLASS (self)->get_settings (self, error);
return *settings ? TRUE : FALSE;
}
static gboolean
update (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceUpdateFunc callback,
gpointer user_data)
{
g_object_ref (connection);
nm_settings_connection_interface_emit_updated (connection);
callback (connection, NULL, user_data);
g_object_unref (connection);
return TRUE;
}
static void
impl_exported_connection_update (NMExportedConnection *self,
GHashTable *new_settings,
DBusGMethodInvocation *context)
{
NMConnection *tmp;
GError *error = NULL;
/* If the connection is read-only, that has to be changed at the source of
* the problem (ex a system settings plugin that can't write connections out)
* instead of over D-Bus.
*/
if (!check_writable (NM_CONNECTION (self), &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
}
/* Check if the settings are valid first */
tmp = nm_connection_new_from_hash (new_settings, &error);
if (!tmp) {
g_assert (error);
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
}
g_object_unref (tmp);
if (NM_EXPORTED_CONNECTION_GET_CLASS (self)->update)
NM_EXPORTED_CONNECTION_GET_CLASS (self)->update (self, new_settings, context);
else {
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
"%s: %s:%d update() unimplemented", __func__, __FILE__, __LINE__);
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
static gboolean
do_delete (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceDeleteFunc callback,
gpointer user_data)
{
g_object_ref (connection);
g_signal_emit_by_name (connection, "removed");
callback (connection, NULL, user_data);
g_object_unref (connection);
return TRUE;
}
static void
impl_exported_connection_delete (NMExportedConnection *self,
DBusGMethodInvocation *context)
{
GError *error = NULL;
if (!check_writable (NM_CONNECTION (self), &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
}
if (NM_EXPORTED_CONNECTION_GET_CLASS (self)->delete)
NM_EXPORTED_CONNECTION_GET_CLASS (self)->delete (self, context);
else {
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
"%s: %s:%d delete() unimplemented", __func__, __FILE__, __LINE__);
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
static void
impl_exported_connection_get_secrets (NMExportedConnection *self,
const gchar *setting_name,
const gchar **hints,
gboolean request_new,
DBusGMethodInvocation *context)
{
GError *error = NULL;
if (NM_EXPORTED_CONNECTION_GET_CLASS (self)->get_secrets)
NM_EXPORTED_CONNECTION_GET_CLASS (self)->get_secrets (self, setting_name, hints, request_new, context);
else {
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
"%s: %s:%d get_secrets() unimplemented", __func__, __FILE__, __LINE__);
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/**************************************************************/
static void
settings_connection_interface_init (NMSettingsConnectionInterface *iface)
{
iface->update = update;
iface->delete = do_delete;
}
/**
* nm_exported_connection_new:
* @scope: the Connection scope (either user or system)
*
* Creates a new object representing the remote connection.
*
* Returns: the new exported connection object on success, or %NULL on failure
**/
NMExportedConnection *
nm_exported_connection_new (NMConnectionScope scope)
{
g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
return (NMExportedConnection *) g_object_new (NM_TYPE_EXPORTED_CONNECTION,
NM_CONNECTION_SCOPE, scope,
NULL);
}
static void
nm_exported_connection_init (NMExportedConnection *self)
{
}
static void
nm_exported_connection_class_init (NMExportedConnectionClass *class)
{
g_type_class_add_private (class, sizeof (NMExportedConnectionPrivate));
/* Virtual methods */
class->get_settings = real_get_settings;
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
&dbus_glib_nm_exported_connection_object_info);
}

View File

@@ -1,75 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2009 Red Hat, Inc.
*/
#ifndef NM_EXPORTED_CONNECTION_H
#define NM_EXPORTED_CONNECTION_H
#include <nm-connection.h>
#include <dbus/dbus-glib.h>
G_BEGIN_DECLS
#define NM_TYPE_EXPORTED_CONNECTION (nm_exported_connection_get_type ())
#define NM_EXPORTED_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_EXPORTED_CONNECTION, NMExportedConnection))
#define NM_EXPORTED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_EXPORTED_CONNECTION, NMExportedConnectionClass))
#define NM_IS_EXPORTED_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_EXPORTED_CONNECTION))
#define NM_IS_EXPORTED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_EXPORTED_CONNECTION))
#define NM_EXPORTED_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_EXPORTED_CONNECTION, NMExportedConnectionClass))
typedef struct {
NMConnection parent;
} NMExportedConnection;
typedef struct {
NMConnectionClass parent;
GHashTable * (*get_settings) (NMExportedConnection *self,
GError **error);
void (*update) (NMExportedConnection *self,
GHashTable *new_settings,
DBusGMethodInvocation *context);
void (*delete) (NMExportedConnection *self,
DBusGMethodInvocation *context);
void (*get_secrets) (NMExportedConnection *self,
const gchar *setting_name,
const gchar **hints,
gboolean request_new,
DBusGMethodInvocation *context);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMExportedConnectionClass;
GType nm_exported_connection_get_type (void);
NMExportedConnection *nm_exported_connection_new (NMConnectionScope scope);
G_END_DECLS
#endif /* NM_EXPORTED_CONNECTION_H */

View File

@@ -337,8 +337,8 @@ nm_ip4_config_new (DBusGConnection *connection, const char *object_path)
*
* Gets the IP4 addresses (containing the address, prefix, and gateway).
*
* Returns: the #GSList containing #NMSettingIP4Address<!-- -->es. This is the internal copy
* used by the configuration and must not be modified.
* Returns: (element-type NetworkManager.IP4Address): the #GSList containing #NMIP4Address<!-- -->es.
* This is the internal copy used by the configuration and must not be modified.
**/
const GSList *
nm_ip4_config_get_addresses (NMIP4Config *config)
@@ -366,7 +366,7 @@ nm_ip4_config_get_addresses (NMIP4Config *config)
}
/**
* nm_ip4_config_get_hostname:
* nm_ip4_config_get_hostname: (skip):
* @config: a #NMIP4Config
*
* DEPRECATED. Don't use.
@@ -385,7 +385,7 @@ nm_ip4_config_get_hostname (NMIP4Config *config)
*
* Gets the domain name servers (DNS).
*
* Returns: the #GArray containing %guint32<!-- -->s. This is the internal copy used by the
* Returns: (element-type guint32): the #GArray containing %guint32<!-- -->s. This is the internal copy used by the
* configuration and must not be modified.
**/
const GArray *
@@ -421,7 +421,7 @@ nm_ip4_config_get_nameservers (NMIP4Config *config)
*
* Gets the domain names.
*
* Returns: the #GPtrArray containing domains as strings. This is the
* Returns: (element-type utf8): the #GPtrArray containing domains as strings. This is the
* internal copy used by the configuration, and must not be modified.
**/
const GPtrArray *
@@ -460,8 +460,8 @@ nm_ip4_config_get_domains (NMIP4Config *config)
*
* Gets the Windows Internet Name Service servers (WINS).
*
* Returns: the #GArray containing %guint32<!-- -->s. This is the internal copy used by the
* configuration and must not be modified.
* Returns: (element-type guint32): the #GArray containing %guint32<!-- -->s.
* This is the internal copy used by the configuration and must not be modified.
**/
const GArray *
nm_ip4_config_get_wins_servers (NMIP4Config *config)
@@ -496,8 +496,9 @@ nm_ip4_config_get_wins_servers (NMIP4Config *config)
*
* Gets the routes.
*
* Returns: the #GSList containing #NMSettingIP4Route<!-- -->s. This is the
* internal copy used by the configuration, and must not be modified.
* Returns: (element-type NetworkManager.IP4Route): the #GSList containing
* #NMIP4Route<!-- -->s. This is the internal copy used by the configuration,
* and must not be modified.
**/
const GSList *
nm_ip4_config_get_routes (NMIP4Config *config)

View File

@@ -146,8 +146,9 @@ register_for_property_changed (NMIP6Config *config)
*
* Gets the IP6 addresses (containing the address, prefix, and gateway).
*
* Returns: the #GSList containing #NMSettingIP6Address<!-- -->es. This is the internal copy
* used by the configuration and must not be modified.
* Returns: (element-type NetworkManager.IP6Address): the #GSList containing
* #NMIP6Address<!-- -->es. This is the internal copy used by the configuration
* and must not be modified.
**/
const GSList *
nm_ip6_config_get_addresses (NMIP6Config *config)
@@ -174,15 +175,16 @@ nm_ip6_config_get_addresses (NMIP6Config *config)
return priv->addresses;
}
/* FIXME: like in libnm_util, in6_addr is not introspectable, so skipping here */
/**
* nm_ip6_config_get_nameservers:
* nm_ip6_config_get_nameservers: (skip)
* @config: a #NMIP6Config
*
* Gets the domain name servers (DNS).
*
* Returns: a #GSList containing elements of type 'struct in6_addr' which contain
* the addresses of nameservers of the configuration. This is the internal copy
* used by the configuration and must not be modified.
* Returns: (element-type Posix.in6_addr): a #GSList containing elements of type
* 'struct in6_addr' which contain the addresses of nameservers of the configuration.
* This is the internal copy used by the configuration and must not be modified.
**/
const GSList *
nm_ip6_config_get_nameservers (NMIP6Config *config)
@@ -217,8 +219,8 @@ nm_ip6_config_get_nameservers (NMIP6Config *config)
*
* Gets the domain names.
*
* Returns: the #GPtrArray containing domains as strings. This is the
* internal copy used by the configuration, and must not be modified.
* Returns: (element-type utf8): the #GPtrArray containing domains as strings.
* This is the internal copy used by the configuration, and must not be modified.
**/
const GPtrArray *
nm_ip6_config_get_domains (NMIP6Config *config)
@@ -251,8 +253,9 @@ nm_ip6_config_get_domains (NMIP6Config *config)
*
* Gets the routes.
*
* Returns: the #GSList containing #NMSettingIP6Route<!-- -->s. This is the
* internal copy used by the configuration, and must not be modified.
* Returns: (element-type NetworkManager.IP6Route): the #GSList containing
* #NMIP6Route<!-- -->s. This is the internal copy used by the configuration,
* and must not be modified.
**/
const GSList *
nm_ip6_config_get_routes (NMIP6Config *config)

View File

@@ -223,7 +223,7 @@ nm_object_class_init (NMObjectClass *nm_object_class)
*
* Gets the #NMObject's DBusGConnection.
*
* Returns: the connection
* Returns: (transfer none): the connection
**/
DBusGConnection *
nm_object_get_connection (NMObject *object)

View File

@@ -28,7 +28,8 @@
typedef enum {
NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN = 0,
NM_REMOTE_CONNECTION_INIT_RESULT_SUCCESS,
NM_REMOTE_CONNECTION_INIT_RESULT_ERROR
NM_REMOTE_CONNECTION_INIT_RESULT_ERROR,
NM_REMOTE_CONNECTION_INIT_RESULT_INVISIBLE,
} NMRemoteConnectionInitResult;
#endif /* __NM_REMOTE_CONNECTION_PRIVATE__ */

View File

@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
*/
#include <string.h>
@@ -29,15 +29,11 @@
#include "nm-remote-connection.h"
#include "nm-remote-connection-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-exported-connection-bindings.h"
#include "nm-settings-connection-interface.h"
#include "nm-settings-connection-bindings.h"
#define NM_REMOTE_CONNECTION_BUS "bus"
static void settings_connection_interface_init (NMSettingsConnectionInterface *klass);
G_DEFINE_TYPE_EXTENDED (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_CONNECTION_INTERFACE, settings_connection_interface_init))
G_DEFINE_TYPE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION)
enum {
PROP_0,
@@ -47,10 +43,18 @@ enum {
LAST_PROP
};
enum {
UPDATED,
REMOVED,
VISIBLE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
NMRemoteConnection *self;
DBusGProxy *proxy;
DBusGProxyCall *call;
GFunc callback;
gpointer user_data;
@@ -59,10 +63,10 @@ typedef struct {
typedef struct {
DBusGConnection *bus;
DBusGProxy *proxy;
DBusGProxy *secrets_proxy;
GSList *calls;
NMRemoteConnectionInitResult init_result;
gboolean visible;
gboolean disposed;
} NMRemoteConnectionPrivate;
@@ -88,161 +92,184 @@ static void
update_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
{
RemoteCall *call = user_data;
NMSettingsConnectionInterfaceUpdateFunc func = (NMSettingsConnectionInterfaceUpdateFunc) call->callback;
NMRemoteConnectionCommitFunc func = (NMRemoteConnectionCommitFunc) call->callback;
(*func)(NM_SETTINGS_CONNECTION_INTERFACE (call->self), error, call->user_data);
(*func)(call->self, error, call->user_data);
remote_call_complete (call->self, call);
}
static gboolean
update (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceUpdateFunc callback,
gpointer user_data)
/**
* nm_remote_connection_commit_changes:
* @connection: the #NMRemoteConnection
* @callback: (scope async): a function to be called when the commit completes
* @user_data: caller-specific data to be passed to @callback
*
* Save any local changes to the settings and properties of this connection and
* save them in the settings service.
**/
void
nm_remote_connection_commit_changes (NMRemoteConnection *self,
NMRemoteConnectionCommitFunc callback,
gpointer user_data)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (connection);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
NMRemoteConnectionPrivate *priv;
GHashTable *settings = NULL;
RemoteCall *call;
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
g_return_if_fail (callback != NULL);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
call = g_malloc0 (sizeof (RemoteCall));
call->self = self;
call->callback = (GFunc) callback;
call->user_data = user_data;
call->proxy = priv->proxy;
settings = nm_connection_to_hash (NM_CONNECTION (self));
settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL);
call->call = org_freedesktop_NetworkManagerSettings_Connection_update_async (priv->proxy,
settings,
update_cb,
call);
call->call = org_freedesktop_NetworkManager_Settings_Connection_update_async (priv->proxy,
settings,
update_cb,
call);
g_assert (call->call);
priv->calls = g_slist_append (priv->calls, call);
g_hash_table_destroy (settings);
return TRUE;
}
static void
delete_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
{
RemoteCall *call = user_data;
NMSettingsConnectionInterfaceDeleteFunc func = (NMSettingsConnectionInterfaceDeleteFunc) call->callback;
NMRemoteConnectionDeleteFunc func = (NMRemoteConnectionDeleteFunc) call->callback;
(*func)(NM_SETTINGS_CONNECTION_INTERFACE (call->self), error, call->user_data);
(*func)(call->self, error, call->user_data);
remote_call_complete (call->self, call);
}
static gboolean
do_delete (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceDeleteFunc callback,
gpointer user_data)
/**
* nm_remote_connection_delete:
* @connection: the #NMRemoteConnection
* @callback: (scope async): a function to be called when the delete completes
* @user_data: caller-specific data to be passed to @callback
*
* Delete the connection.
**/
void
nm_remote_connection_delete (NMRemoteConnection *self,
NMRemoteConnectionDeleteFunc callback,
gpointer user_data)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (connection);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
NMRemoteConnectionPrivate *priv;
RemoteCall *call;
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
g_return_if_fail (callback != NULL);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
call = g_malloc0 (sizeof (RemoteCall));
call->self = self;
call->callback = (GFunc) callback;
call->user_data = user_data;
call->proxy = priv->proxy;
call->call = org_freedesktop_NetworkManagerSettings_Connection_delete_async (priv->proxy,
delete_cb,
call);
call->call = org_freedesktop_NetworkManager_Settings_Connection_delete_async (priv->proxy,
delete_cb,
call);
g_assert (call->call);
priv->calls = g_slist_append (priv->calls, call);
return TRUE;
}
static void
get_secrets_cb (DBusGProxy *proxy, GHashTable *secrets, GError *error, gpointer user_data)
{
RemoteCall *call = user_data;
NMSettingsConnectionInterfaceGetSecretsFunc func = (NMSettingsConnectionInterfaceGetSecretsFunc) call->callback;
NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback;
(*func)(NM_SETTINGS_CONNECTION_INTERFACE (call->self), error ? NULL : secrets, error, call->user_data);
(*func)(call->self, error ? NULL : secrets, error, call->user_data);
remote_call_complete (call->self, call);
}
static gboolean
get_secrets (NMSettingsConnectionInterface *connection,
const char *setting_name,
const char **hints,
gboolean request_new,
NMSettingsConnectionInterfaceGetSecretsFunc callback,
gpointer user_data)
/**
* nm_remote_connection_get_secrets:
* @connection: the #NMRemoteConnection
* @setting_name: the #NMSetting object name to get secrets for
* @callback: (scope async): a function to be called when the update completes
* @user_data: caller-specific data to be passed to @callback
*
* Request the connection's secrets.
**/
void
nm_remote_connection_get_secrets (NMRemoteConnection *self,
const char *setting_name,
NMRemoteConnectionGetSecretsFunc callback,
gpointer user_data)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (connection);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
NMRemoteConnectionPrivate *priv;
RemoteCall *call;
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
g_return_if_fail (callback != NULL);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
call = g_malloc0 (sizeof (RemoteCall));
call->self = self;
call->callback = (GFunc) callback;
call->user_data = user_data;
call->proxy = priv->secrets_proxy;
call->call = org_freedesktop_NetworkManagerSettings_Connection_Secrets_get_secrets_async (priv->secrets_proxy,
setting_name,
hints,
request_new,
get_secrets_cb,
call);
call->call = org_freedesktop_NetworkManager_Settings_Connection_get_secrets_async (priv->proxy,
setting_name,
get_secrets_cb,
call);
g_assert (call->call);
priv->calls = g_slist_append (priv->calls, call);
return TRUE;
}
/****************************************************************/
static gboolean
static void
replace_settings (NMRemoteConnection *self, GHashTable *new_settings)
{
GError *error = NULL;
if (!nm_connection_replace_settings (NM_CONNECTION (self), new_settings, &error)) {
g_warning ("%s: error updating %s connection %s settings: (%d) %s",
if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, &error))
g_signal_emit (self, signals[UPDATED], 0, new_settings);
else {
g_warning ("%s: error updating connection %s settings: (%d) %s",
__func__,
(nm_connection_get_scope (NM_CONNECTION (self)) == NM_CONNECTION_SCOPE_USER) ? "user" : "system",
nm_connection_get_path (NM_CONNECTION (self)),
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
g_clear_error (&error);
return FALSE;
}
/* Emit update irregardless to let listeners figure out what to do with
* the connection; whether to delete / ignore it or not.
*/
nm_settings_connection_interface_emit_updated (NM_SETTINGS_CONNECTION_INTERFACE (self));
return TRUE;
g_signal_emit (self, signals[REMOVED], 0);
}
}
static void
get_settings_cb (DBusGProxy *proxy,
GHashTable *new_settings,
GError *error,
gpointer user_data)
init_get_settings_cb (DBusGProxy *proxy,
GHashTable *new_settings,
GError *error,
gpointer user_data)
{
NMRemoteConnection *self = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
if (error) {
g_warning ("%s: error getting %s connection %s settings: (%d) %s",
__func__,
(nm_connection_get_scope (NM_CONNECTION (self)) == NM_CONNECTION_SCOPE_USER) ? "user" : "system",
nm_connection_get_path (NM_CONNECTION (self)),
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
g_error_free (error);
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_ERROR;
/* Connection doesn't exist, or isn't visible to this user */
if (dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.PermissionDenied"))
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_INVISIBLE;
else
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_ERROR;
g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
} else {
priv->visible = TRUE;
replace_settings (self, new_settings);
g_hash_table_destroy (new_settings);
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_SUCCESS;
@@ -251,34 +278,64 @@ get_settings_cb (DBusGProxy *proxy,
}
static void
updated_cb (DBusGProxy *proxy, GHashTable *settings, gpointer user_data)
updated_get_settings_cb (DBusGProxy *proxy,
GHashTable *new_settings,
GError *error,
gpointer user_data)
{
replace_settings (NM_REMOTE_CONNECTION (user_data), settings);
NMRemoteConnection *self = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
if (error) {
GHashTable *hash;
/* Connection is no longer visible to this user. Let the settings
* service handle this via 'visible'. The settings service will emit
* the "removed" signal for us since it handles the lifetime of this
* object.
*/
hash = g_hash_table_new (g_str_hash, g_str_equal);
nm_connection_replace_settings (NM_CONNECTION (self), hash, NULL);
g_hash_table_destroy (hash);
priv->visible = FALSE;
g_signal_emit (self, signals[VISIBLE], 0, FALSE);
} else {
replace_settings (self, new_settings);
g_hash_table_destroy (new_settings);
/* Settings service will handle announcing the connection to clients */
if (priv->visible == FALSE) {
priv->visible = TRUE;
g_signal_emit (self, signals[VISIBLE], 0, TRUE);
}
}
}
static void
updated_cb (DBusGProxy *proxy, gpointer user_data)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
/* The connection got updated; request the replacement settings */
org_freedesktop_NetworkManager_Settings_Connection_get_settings_async (priv->proxy,
updated_get_settings_cb,
self);
}
static void
removed_cb (DBusGProxy *proxy, gpointer user_data)
{
g_signal_emit_by_name (G_OBJECT (user_data), "removed");
g_signal_emit (G_OBJECT (user_data), signals[REMOVED], 0);
}
/****************************************************************/
static void
settings_connection_interface_init (NMSettingsConnectionInterface *klass)
{
/* interface implementation */
klass->update = update;
klass->delete = do_delete;
klass->get_secrets = get_secrets;
}
/**
* nm_remote_connection_new:
* @bus: a valid and connected D-Bus connection
* @scope: the Connection scope (either user or system)
* @path: the D-Bus path of the connection as exported by the settings service
* indicated by @scope
*
* Creates a new object representing the remote connection.
*
@@ -286,7 +343,6 @@ settings_connection_interface_init (NMSettingsConnectionInterface *klass)
**/
NMRemoteConnection *
nm_remote_connection_new (DBusGConnection *bus,
NMConnectionScope scope,
const char *path)
{
g_return_val_if_fail (bus != NULL, NULL);
@@ -294,7 +350,6 @@ nm_remote_connection_new (DBusGConnection *bus,
return (NMRemoteConnection *) g_object_new (NM_TYPE_REMOTE_CONNECTION,
NM_REMOTE_CONNECTION_BUS, bus,
NM_CONNECTION_SCOPE, scope,
NM_CONNECTION_PATH, path,
NULL);
}
@@ -306,7 +361,6 @@ constructor (GType type,
{
GObject *object;
NMRemoteConnectionPrivate *priv;
const char *service = NM_DBUS_SERVICE_USER_SETTINGS;
object = G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructor (type, n_construct_params, construct_params);
if (!object)
@@ -316,32 +370,22 @@ constructor (GType type,
g_assert (priv->bus);
g_assert (nm_connection_get_path (NM_CONNECTION (object)));
if (nm_connection_get_scope (NM_CONNECTION (object)) == NM_CONNECTION_SCOPE_SYSTEM)
service = NM_DBUS_SERVICE_SYSTEM_SETTINGS;
priv->proxy = dbus_g_proxy_new_for_name (priv->bus,
service,
NM_DBUS_SERVICE,
nm_connection_get_path (NM_CONNECTION (object)),
NM_DBUS_IFACE_SETTINGS_CONNECTION);
g_assert (priv->proxy);
dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT);
priv->secrets_proxy = dbus_g_proxy_new_for_name (priv->bus,
service,
nm_connection_get_path (NM_CONNECTION (object)),
NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS);
g_assert (priv->secrets_proxy);
dbus_g_proxy_set_default_timeout (priv->secrets_proxy, G_MAXINT);
dbus_g_proxy_add_signal (priv->proxy, "Updated", DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), object, NULL);
dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), object, NULL);
org_freedesktop_NetworkManagerSettings_Connection_get_settings_async (priv->proxy,
get_settings_cb,
object);
org_freedesktop_NetworkManager_Settings_Connection_get_settings_async (priv->proxy,
init_get_settings_cb,
object);
return object;
}
@@ -397,7 +441,6 @@ dispose (GObject *object)
remote_call_complete (self, priv->calls->data);
g_object_unref (priv->proxy);
g_object_unref (priv->secrets_proxy);
dbus_g_connection_unref (priv->bus);
}
@@ -435,5 +478,31 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
NM_REMOTE_CONNECTION_INIT_RESULT_ERROR,
NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
G_PARAM_READABLE));
}
/* Signals */
signals[UPDATED] =
g_signal_new (NM_REMOTE_CONNECTION_UPDATED,
G_TYPE_FROM_CLASS (remote_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMRemoteConnectionClass, updated),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[REMOVED] =
g_signal_new (NM_REMOTE_CONNECTION_REMOVED,
G_TYPE_FROM_CLASS (remote_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMRemoteConnectionClass, removed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[VISIBLE] =
g_signal_new ("visible",
G_TYPE_FROM_CLASS (remote_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}

View File

@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2009 Red Hat, Inc.
* Copyright (C) 2007 - 2011 Red Hat, Inc.
*/
#ifndef __NM_REMOTE_CONNECTION_H__
@@ -38,6 +38,9 @@ G_BEGIN_DECLS
#define NM_IS_REMOTE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_REMOTE_CONNECTION))
#define NM_REMOTE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_CONNECTION, NMRemoteConnectionClass))
#define NM_REMOTE_CONNECTION_UPDATED "updated"
#define NM_REMOTE_CONNECTION_REMOVED "removed"
typedef struct {
NMConnection parent;
} NMRemoteConnection;
@@ -45,6 +48,12 @@ typedef struct {
typedef struct {
NMConnectionClass parent_class;
/* Signals */
void (*updated) (NMRemoteConnection *connection,
GHashTable *new_settings);
void (*removed) (NMRemoteConnection *connection);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
@@ -54,11 +63,36 @@ typedef struct {
void (*_reserved6) (void);
} NMRemoteConnectionClass;
typedef void (*NMRemoteConnectionCommitFunc) (NMRemoteConnection *connection,
GError *error,
gpointer user_data);
typedef void (*NMRemoteConnectionDeleteFunc) (NMRemoteConnection *connection,
GError *error,
gpointer user_data);
typedef void (*NMRemoteConnectionGetSecretsFunc) (NMRemoteConnection *connection,
GHashTable *secrets,
GError *error,
gpointer user_data);
GType nm_remote_connection_get_type (void);
NMRemoteConnection *nm_remote_connection_new (DBusGConnection *bus,
NMConnectionScope scope,
const char *path);
void nm_remote_connection_commit_changes (NMRemoteConnection *connection,
NMRemoteConnectionCommitFunc callback,
gpointer user_data);
void nm_remote_connection_delete (NMRemoteConnection *connection,
NMRemoteConnectionDeleteFunc callback,
gpointer user_data);
void nm_remote_connection_get_secrets (NMRemoteConnection *connection,
const char *setting_name,
NMRemoteConnectionGetSecretsFunc callback,
gpointer user_data);
G_END_DECLS
#endif /* __NM_REMOTE_CONNECTION__ */

View File

@@ -1,375 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* libnm_glib -- Access network status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
*/
#include <string.h>
#include <NetworkManager.h>
#include <nm-connection.h>
#include "nm-marshal.h"
#include "nm-dbus-glib-types.h"
#include "nm-remote-settings-system.h"
#include "nm-settings-system-bindings.h"
#include "nm-settings-system-interface.h"
static void settings_system_interface_init (NMSettingsSystemInterface *klass);
G_DEFINE_TYPE_EXTENDED (NMRemoteSettingsSystem, nm_remote_settings_system, NM_TYPE_REMOTE_SETTINGS, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_SYSTEM_INTERFACE, settings_system_interface_init))
#define NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS_SYSTEM, NMRemoteSettingsSystemPrivate))
typedef struct {
DBusGProxy *proxy;
DBusGProxy *props_proxy;
char *hostname;
gboolean can_modify;
NMSettingsSystemPermissions permissions;
gboolean have_permissions;
gboolean disposed;
} NMRemoteSettingsSystemPrivate;
static void
properties_changed_cb (DBusGProxy *proxy,
GHashTable *properties,
gpointer user_data)
{
NMRemoteSettingsSystem *self = NM_REMOTE_SETTINGS_SYSTEM (user_data);
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (self);
GHashTableIter iter;
gpointer key, tmp;
g_hash_table_iter_init (&iter, properties);
while (g_hash_table_iter_next (&iter, &key, &tmp)) {
GValue *value = tmp;
if (!strcmp ((const char *) key, "Hostname")) {
g_free (priv->hostname);
priv->hostname = g_value_dup_string (value);
g_object_notify (G_OBJECT (self), NM_SETTINGS_SYSTEM_INTERFACE_HOSTNAME);
}
if (!strcmp ((const char *) key, "CanModify")) {
priv->can_modify = g_value_get_boolean (value);
g_object_notify (G_OBJECT (self), NM_SETTINGS_SYSTEM_INTERFACE_CAN_MODIFY);
}
}
}
static void
get_all_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
NMRemoteSettingsSystem *self = NM_REMOTE_SETTINGS_SYSTEM (user_data);
GHashTable *props = NULL;
GError *error = NULL;
if (!dbus_g_proxy_end_call (proxy, call, &error,
DBUS_TYPE_G_MAP_OF_VARIANT, &props,
G_TYPE_INVALID)) {
/* Don't warn when the call times out because the settings service can't
* be activated or whatever.
*/
if (!(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NO_REPLY)) {
g_warning ("%s: couldn't retrieve system settings properties: (%d) %s.",
__func__,
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
}
g_clear_error (&error);
return;
}
properties_changed_cb (NULL, props, self);
g_hash_table_destroy (props);
}
typedef struct {
NMSettingsSystemInterface *settings;
NMSettingsSystemSaveHostnameFunc callback;
gpointer callback_data;
} SaveHostnameInfo;
static void
save_hostname_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
SaveHostnameInfo *info = user_data;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
info->callback (info->settings, error, info->callback_data);
g_clear_error (&error);
}
static gboolean
save_hostname (NMSettingsSystemInterface *settings,
const char *hostname,
NMSettingsSystemSaveHostnameFunc callback,
gpointer user_data)
{
NMRemoteSettingsSystem *self = NM_REMOTE_SETTINGS_SYSTEM (settings);
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (self);
SaveHostnameInfo *info;
info = g_malloc0 (sizeof (SaveHostnameInfo));
info->settings = settings;
info->callback = callback;
info->callback_data = user_data;
dbus_g_proxy_begin_call (priv->proxy, "SaveHostname",
save_hostname_cb,
info,
g_free,
G_TYPE_STRING, hostname ? hostname : "",
G_TYPE_INVALID);
return TRUE;
}
typedef struct {
NMSettingsSystemInterface *settings;
NMSettingsSystemGetPermissionsFunc callback;
gpointer callback_data;
} GetPermissionsInfo;
static void
get_permissions_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
GetPermissionsInfo *info = user_data;
NMRemoteSettingsSystem *self = NM_REMOTE_SETTINGS_SYSTEM (info->settings);
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (self);
NMSettingsSystemPermissions permissions = NM_SETTINGS_SYSTEM_PERMISSION_NONE;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_UINT, &permissions,
G_TYPE_INVALID);
priv->permissions = permissions;
priv->have_permissions = !error;
info->callback (info->settings, permissions, error, info->callback_data);
g_clear_error (&error);
}
static gboolean
get_permissions (NMSettingsSystemInterface *settings,
NMSettingsSystemGetPermissionsFunc callback,
gpointer user_data)
{
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (settings);
GetPermissionsInfo *info;
/* Skip D-Bus if we already have permissions */
if (priv->have_permissions) {
callback (settings, priv->permissions, NULL, user_data);
return TRUE;
}
/* Otherwise fetch them from NM */
info = g_malloc0 (sizeof (GetPermissionsInfo));
info->settings = settings;
info->callback = callback;
info->callback_data = user_data;
dbus_g_proxy_begin_call (priv->proxy, "GetPermissions",
get_permissions_cb,
info,
g_free,
G_TYPE_INVALID);
return TRUE;
}
static void
check_permissions_cb (DBusGProxy *proxy, gpointer user_data)
{
NMRemoteSettingsSystem *self = NM_REMOTE_SETTINGS_SYSTEM (user_data);
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (self);
/* Permissions need to be re-fetched */
priv->have_permissions = FALSE;
g_signal_emit_by_name (self, NM_SETTINGS_SYSTEM_INTERFACE_CHECK_PERMISSIONS);
}
/****************************************************************/
static void
settings_system_interface_init (NMSettingsSystemInterface *klass)
{
/* interface implementation */
klass->save_hostname = save_hostname;
klass->get_permissions = get_permissions;
}
/**
* nm_remote_settings_system_new:
* @bus: a valid and connected D-Bus connection
*
* Creates a new object representing the remote system settings service.
*
* Returns: the new remote system settings object on success, or %NULL on failure
**/
NMRemoteSettingsSystem *
nm_remote_settings_system_new (DBusGConnection *bus)
{
g_return_val_if_fail (bus != NULL, NULL);
return (NMRemoteSettingsSystem *) g_object_new (NM_TYPE_REMOTE_SETTINGS_SYSTEM,
NM_REMOTE_SETTINGS_BUS, bus,
NM_REMOTE_SETTINGS_SCOPE, NM_CONNECTION_SCOPE_SYSTEM,
NULL);
}
static void
nm_remote_settings_system_init (NMRemoteSettingsSystem *self)
{
}
static GObject *
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
NMRemoteSettingsSystemPrivate *priv;
DBusGConnection *bus = NULL;
object = G_OBJECT_CLASS (nm_remote_settings_system_parent_class)->constructor (type, n_construct_params, construct_params);
if (!object)
return NULL;
priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (object);
g_object_get (G_OBJECT (object), NM_REMOTE_SETTINGS_BUS, &bus, NULL);
g_assert (bus);
/* D-Bus properties proxy */
priv->props_proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
NM_DBUS_PATH_SETTINGS,
"org.freedesktop.DBus.Properties");
g_assert (priv->props_proxy);
/* System settings proxy */
priv->proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
NM_DBUS_PATH_SETTINGS,
NM_DBUS_IFACE_SETTINGS_SYSTEM);
g_assert (priv->proxy);
dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT);
dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged",
DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged",
G_CALLBACK (properties_changed_cb),
object,
NULL);
/* Monitor for permissions changes */
dbus_g_proxy_add_signal (priv->proxy, "CheckPermissions", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "CheckPermissions",
G_CALLBACK (check_permissions_cb),
object,
NULL);
/* Get properties */
dbus_g_proxy_begin_call (priv->props_proxy, "GetAll",
get_all_cb,
object,
NULL,
G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS_SYSTEM,
G_TYPE_INVALID);
dbus_g_connection_unref (bus);
return object;
}
static void
dispose (GObject *object)
{
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (object);
if (priv->disposed)
return;
priv->disposed = TRUE;
g_free (priv->hostname);
g_object_unref (priv->props_proxy);
g_object_unref (priv->proxy);
G_OBJECT_CLASS (nm_remote_settings_system_parent_class)->dispose (object);
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMRemoteSettingsSystemPrivate *priv = NM_REMOTE_SETTINGS_SYSTEM_GET_PRIVATE (object);
switch (prop_id) {
case NM_SETTINGS_SYSTEM_INTERFACE_PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
break;
case NM_SETTINGS_SYSTEM_INTERFACE_PROP_CAN_MODIFY:
g_value_set_boolean (value, priv->can_modify);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_remote_settings_system_class_init (NMRemoteSettingsSystemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMRemoteSettingsSystemPrivate));
/* Virtual methods */
object_class->constructor = constructor;
object_class->get_property = get_property;
object_class->dispose = dispose;
/* Properties */
g_object_class_override_property (object_class,
NM_SETTINGS_SYSTEM_INTERFACE_PROP_HOSTNAME,
NM_SETTINGS_SYSTEM_INTERFACE_HOSTNAME);
g_object_class_override_property (object_class,
NM_SETTINGS_SYSTEM_INTERFACE_PROP_CAN_MODIFY,
NM_SETTINGS_SYSTEM_INTERFACE_CAN_MODIFY);
}

View File

@@ -1,64 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* libnm_glib -- Access network status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#ifndef NM_REMOTE_SETTINGS_SYSTEM_H
#define NM_REMOTE_SETTINGS_SYSTEM_H
#include <glib.h>
#include <dbus/dbus-glib.h>
#include "nm-remote-settings.h"
#include "nm-settings-system-interface.h"
G_BEGIN_DECLS
#define NM_TYPE_REMOTE_SETTINGS_SYSTEM (nm_remote_settings_system_get_type ())
#define NM_REMOTE_SETTINGS_SYSTEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_REMOTE_SETTINGS_SYSTEM, NMRemoteSettingsSystem))
#define NM_REMOTE_SETTINGS_SYSTEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_REMOTE_SETTINGS_SYSTEM, NMRemoteSettingsSystemClass))
#define NM_IS_REMOTE_SETTINGS_SYSTEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_REMOTE_SETTINGS_SYSTEM))
#define NM_IS_REMOTE_SETTINGS_SYSTEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_REMOTE_SETTINGS_SYSTEM))
#define NM_REMOTE_SETTINGS_SYSTEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_SETTINGS_SYSTEM, NMRemoteSettingsSystemClass))
typedef struct {
NMRemoteSettings parent;
} NMRemoteSettingsSystem;
typedef struct {
NMRemoteSettingsClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMRemoteSettingsSystemClass;
GType nm_remote_settings_system_get_type (void);
NMRemoteSettingsSystem *nm_remote_settings_system_new (DBusGConnection *bus);
G_END_DECLS
#endif /* NM_REMOTE_SETTINGS_SYSTEM_H */

View File

@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
* Copyright (C) 2009 - 2011 Red Hat, Inc.
*/
#include <string.h>
@@ -26,26 +26,30 @@
#include <nm-connection.h>
#include "nm-marshal.h"
#include "nm-dbus-glib-types.h"
#include "nm-remote-settings.h"
#include "nm-settings-bindings.h"
#include "nm-settings-interface.h"
#include "nm-remote-connection-private.h"
static void settings_interface_init (NMSettingsInterface *class);
G_DEFINE_TYPE_EXTENDED (NMRemoteSettings, nm_remote_settings, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_INTERFACE, settings_interface_init))
G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, G_TYPE_OBJECT)
#define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate))
typedef struct {
DBusGConnection *bus;
NMConnectionScope scope;
DBusGProxy *proxy;
GHashTable *connections;
GHashTable *pending; /* Connections we don't have settings for yet */
gboolean service_running;
guint32 init_left;
/* AddConnectionInfo objects that are waiting for the connection to become initialized */
GSList *add_list;
DBusGProxy *props_proxy;
char *hostname;
gboolean can_modify;
DBusGProxy *dbus_proxy;
@@ -57,15 +61,124 @@ typedef struct {
enum {
PROP_0,
PROP_BUS,
PROP_SCOPE,
PROP_SERVICE_RUNNING,
PROP_HOSTNAME,
PROP_CAN_MODIFY,
LAST_PROP
};
static NMSettingsConnectionInterface *
get_connection_by_path (NMSettingsInterface *settings, const char *path)
/* Signals */
enum {
NEW_CONNECTION,
CONNECTIONS_READ,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/**********************************************************************/
/**
* nm_remote_settings_error_quark:
*
* Registers an error quark for #NMRemoteSettings if necessary.
*
* Returns: the error quark used for #NMRemoteSettings errors.
**/
GQuark
nm_remote_settings_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-remote-settings-error-quark");
return quark;
}
/* This should really be standard. */
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
nm_remote_settings_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
ENUM_ENTRY (NM_REMOTE_SETTINGS_ERROR_UNKNOWN, "UnknownError"),
ENUM_ENTRY (NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED, "ConnectionRemoved"),
ENUM_ENTRY (NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE, "ConnectionUnavailable"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("NMRemoteSettingsError", values);
}
return etype;
}
/**********************************************************************/
typedef struct {
NMRemoteSettings *self;
NMRemoteSettingsAddConnectionFunc callback;
gpointer callback_data;
NMRemoteConnection *connection;
} AddConnectionInfo;
static AddConnectionInfo *
add_connection_info_find (NMRemoteSettings *self, NMRemoteConnection *connection)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
GSList *iter;
for (iter = priv->add_list; iter; iter = g_slist_next (iter)) {
AddConnectionInfo *info = iter->data;
if (info->connection == connection)
return info;
}
return NULL;
}
static void
add_connection_info_dispose (NMRemoteSettings *self, AddConnectionInfo *info)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
priv->add_list = g_slist_remove (priv->add_list, info);
g_free (info);
}
static void
add_connection_info_complete (NMRemoteSettings *self,
AddConnectionInfo *info,
GError *error)
{
g_return_if_fail (info != NULL);
info->callback (info->self, error ? NULL : info->connection, error, info->callback_data);
add_connection_info_dispose (self, info);
}
/**
* nm_remote_settings_get_connection_by_path:
* @settings: the %NMRemoteSettings
* @path: the D-Bus object path of the remote connection
*
* Returns the %NMRemoteConnection representing the connection at @path.
*
* Returns: (transfer none): the remote connection object on success, or NULL if the object was
* not known
**/
NMRemoteConnection *
nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const char *path)
{
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
g_return_val_if_fail (path != NULL, NULL);
return g_hash_table_lookup (NM_REMOTE_SETTINGS_GET_PRIVATE (settings)->connections, path);
}
@@ -74,13 +187,67 @@ connection_removed_cb (NMRemoteConnection *remote, gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
AddConnectionInfo *addinfo;
GError *add_error;
const char *path;
/* Might have been removed while it was waiting to be initialized */
addinfo = add_connection_info_find (self, remote);
if (addinfo) {
add_error = g_error_new_literal (NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED,
"Connection removed before it was initialized");
add_connection_info_complete (self, addinfo, add_error);
g_error_free (add_error);
}
path = nm_connection_get_path (NM_CONNECTION (remote));
g_hash_table_remove (priv->connections, path);
g_hash_table_remove (priv->pending, path);
}
static void
connection_visible_cb (NMRemoteConnection *remote,
gboolean visible,
gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
const char *path;
path = nm_connection_get_path (NM_CONNECTION (remote));
g_assert (path);
/* When a connection becomes invisible, we put it back in the pending
* hash until it becomes visible again. When it does, we move it back to
* the normal connections hash.
*/
if (visible) {
/* Connection visible to this user again */
if (g_hash_table_lookup (priv->pending, path)) {
/* Move connection from pending to visible hash; emit for clients */
g_hash_table_insert (priv->connections, g_strdup (path), g_object_ref (remote));
g_hash_table_remove (priv->pending, path);
g_signal_emit (self, signals[NEW_CONNECTION], 0, remote);
}
} else {
/* Connection now invisible to this user */
if (g_hash_table_lookup (priv->connections, path)) {
/* Move connection to pending hash and wait for it to become visible again */
g_hash_table_insert (priv->pending, g_strdup (path), g_object_ref (remote));
g_hash_table_remove (priv->connections, path);
/* Signal to clients that the connection is gone; but we have to
* block our connection removed handler so we don't destroy
* the connection when the signal is emitted.
*/
g_signal_handlers_block_by_func (remote, connection_removed_cb, self);
g_signal_emit_by_name (remote, NM_REMOTE_CONNECTION_REMOVED);
g_signal_handlers_unblock_by_func (remote, connection_removed_cb, self);
}
}
}
static void
connection_init_result_cb (NMRemoteConnection *remote,
GParamSpec *pspec,
@@ -89,7 +256,10 @@ connection_init_result_cb (NMRemoteConnection *remote,
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
guint32 init_result = NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN;
AddConnectionInfo *addinfo;
const char *path;
GError *add_error = NULL;
gboolean remove_from_pending = TRUE;
/* Disconnect from the init-result signal just to be safe */
g_signal_handlers_disconnect_matched (remote,
@@ -106,6 +276,8 @@ connection_init_result_cb (NMRemoteConnection *remote,
NM_REMOTE_CONNECTION_INIT_RESULT, &init_result,
NULL);
addinfo = add_connection_info_find (self, remote);
switch (init_result) {
case NM_REMOTE_CONNECTION_INIT_RESULT_SUCCESS:
/* ref it when adding to ->connections, since removing it from ->pending
@@ -113,36 +285,69 @@ connection_init_result_cb (NMRemoteConnection *remote,
*/
g_hash_table_insert (priv->connections, g_strdup (path), g_object_ref (remote));
/* If there's a pending AddConnection request, complete that here before
* signaling new-connection.
*/
if (addinfo)
add_connection_info_complete (self, addinfo, NULL);
/* Finally, let users know of the new connection now that it has all
* its settings and is valid.
*/
g_signal_emit_by_name (self, "new-connection", remote);
g_signal_emit (self, signals[NEW_CONNECTION], 0, remote);
break;
case NM_REMOTE_CONNECTION_INIT_RESULT_INVISIBLE:
remove_from_pending = FALSE;
/* fall through */
case NM_REMOTE_CONNECTION_INIT_RESULT_ERROR:
/* Complete pending AddConnection callbacks */
if (addinfo) {
add_error = g_error_new_literal (NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE,
"Connection not visible or not available");
add_connection_info_complete (self, addinfo, add_error);
g_error_free (add_error);
}
break;
default:
break;
}
g_hash_table_remove (priv->pending, path);
if (remove_from_pending)
g_hash_table_remove (priv->pending, path);
/* Let listeners know that all connections have been found */
if (!g_hash_table_size (priv->pending))
g_signal_emit_by_name (self, NM_SETTINGS_INTERFACE_CONNECTIONS_READ);
priv->init_left--;
if (priv->init_left == 0)
g_signal_emit (self, signals[CONNECTIONS_READ], 0);
}
static void
static NMRemoteConnection *
new_connection_cb (DBusGProxy *proxy, const char *path, gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
NMRemoteConnection *connection;
NMRemoteConnection *connection = NULL;
connection = nm_remote_connection_new (priv->bus, priv->scope, path);
/* Make double-sure we don't already have it */
connection = g_hash_table_lookup (priv->pending, path);
if (connection)
return connection;
connection = g_hash_table_lookup (priv->connections, path);
if (connection)
return connection;
/* Create a new connection object for it */
connection = nm_remote_connection_new (priv->bus, path);
if (connection) {
g_signal_connect (connection, "removed",
g_signal_connect (connection, NM_REMOTE_CONNECTION_REMOVED,
G_CALLBACK (connection_removed_cb),
self);
g_signal_connect (connection, "visible",
G_CALLBACK (connection_visible_cb),
self);
g_signal_connect (connection, "notify::" NM_REMOTE_CONNECTION_INIT_RESULT,
G_CALLBACK (connection_init_result_cb),
self);
@@ -153,6 +358,7 @@ new_connection_cb (DBusGProxy *proxy, const char *path, gpointer user_data)
*/
g_hash_table_insert (priv->pending, g_strdup (path), connection);
}
return connection;
}
static void
@@ -166,41 +372,34 @@ fetch_connections_done (DBusGProxy *proxy,
int i;
if (error) {
gboolean is_spawn_error = FALSE;
/* Don't warn if the user settings service wasn't running since that's
* just annoying when running headless.
*/
if ( g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN)
|| g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NAME_HAS_NO_OWNER))
is_spawn_error = TRUE;
if (!is_spawn_error || priv->scope == NM_CONNECTION_SCOPE_SYSTEM) {
g_warning ("%s: error fetching %s connections: (%d) %s.",
__func__,
priv->scope == NM_CONNECTION_SCOPE_USER ? "user" : "system",
/* Ignore settings service spawn errors */
if ( !g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN)
&& !g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NAME_HAS_NO_OWNER)) {
g_warning ("%s: error fetching connections: (%d) %s.",
__func__,
error->code,
error->message ? error->message : "(unknown)");
}
g_clear_error (&error);
/* We tried to read connections and failed */
g_signal_emit_by_name (self, NM_SETTINGS_INTERFACE_CONNECTIONS_READ);
g_signal_emit (self, signals[CONNECTIONS_READ], 0);
return;
}
/* Let listeners know we are done getting connections */
if (connections->len == 0) {
g_signal_emit_by_name (self, NM_SETTINGS_INTERFACE_CONNECTIONS_READ);
return;
if (connections->len == 0)
g_signal_emit (self, signals[CONNECTIONS_READ], 0);
else {
priv->init_left = connections->len;
for (i = 0; i < connections->len; i++) {
char *path = g_ptr_array_index (connections, i);
new_connection_cb (proxy, path, user_data);
g_free (path);
}
}
for (i = 0; connections && (i < connections->len); i++) {
char *path = g_ptr_array_index (connections, i);
new_connection_cb (proxy, path, user_data);
g_free (path);
}
g_ptr_array_free (connections, TRUE);
}
@@ -212,20 +411,32 @@ fetch_connections (gpointer user_data)
priv->fetch_id = 0;
org_freedesktop_NetworkManagerSettings_list_connections_async (priv->proxy,
fetch_connections_done,
self);
org_freedesktop_NetworkManager_Settings_list_connections_async (priv->proxy,
fetch_connections_done,
self);
return FALSE;
}
static GSList *
list_connections (NMSettingsInterface *settings)
/**
* nm_remote_settings_list_connections:
* @settings: the %NMRemoteSettings
*
* Returns: (transfer container) (element-type NMClient.RemoteConnection): all connections in the remote settings service, represented as
* %NMRemoteConnection instances
**/
GSList *
nm_remote_settings_list_connections (NMRemoteSettings *settings)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
NMRemoteSettingsPrivate *priv;
GSList *list = NULL;
GHashTableIter iter;
gpointer value;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, &value))
list = g_slist_prepend (list, NM_REMOTE_CONNECTION (value));
@@ -233,53 +444,76 @@ list_connections (NMSettingsInterface *settings)
return list;
}
typedef struct {
NMSettingsInterface *self;
NMSettingsAddConnectionFunc callback;
gpointer callback_data;
} AddConnectionInfo;
static void
add_connection_done (DBusGProxy *proxy,
char *path,
GError *error,
gpointer user_data)
{
AddConnectionInfo *info = user_data;
info->callback (info->self, error, info->callback_data);
g_free (info);
if (error) {
add_connection_info_complete (info->self, info, error);
} else {
info->connection = new_connection_cb (proxy, path, info->self);
g_assert (info->connection);
/* Wait until this connection is fully initialized before calling the callback */
}
g_free (path);
}
static gboolean
add_connection (NMSettingsInterface *settings,
NMConnection *connection,
NMSettingsAddConnectionFunc callback,
gpointer user_data)
/**
* nm_remote_settings_add_connection:
* @settings: the %NMRemoteSettings
* @connection: the connection to add. Note that this object's settings will be
* added, not the object itself
* @callback: (scope async): callback to be called when the add operation completes
* @user_data: caller-specific data passed to @callback
*
* Requests that the remote settings service add the given settings to a new
* connection.
*
* Returns: TRUE if the request was successful, FALSE if it failed
**/
gboolean
nm_remote_settings_add_connection (NMRemoteSettings *settings,
NMConnection *connection,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (settings);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info;
GHashTable *new_settings;
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
info = g_malloc0 (sizeof (AddConnectionInfo));
info->self = settings;
info->callback = callback;
info->callback_data = user_data;
new_settings = nm_connection_to_hash (connection);
org_freedesktop_NetworkManagerSettings_add_connection_async (priv->proxy,
new_settings,
add_connection_done,
info);
new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
org_freedesktop_NetworkManager_Settings_add_connection_async (priv->proxy,
new_settings,
add_connection_done,
info);
g_hash_table_destroy (new_settings);
priv->add_list = g_slist_append (priv->add_list, info);
return TRUE;
}
static gboolean
remove_connections (gpointer user_data)
static void
clear_one_hash (GHashTable *table)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
GHashTableIter iter;
gpointer value;
GSList *list = NULL, *list_iter;
@@ -289,18 +523,90 @@ remove_connections (gpointer user_data)
* that explicitly removes the the connection from the hash table somewhere
* else.
*/
g_hash_table_iter_init (&iter, priv->connections);
g_hash_table_iter_init (&iter, table);
while (g_hash_table_iter_next (&iter, NULL, &value))
list = g_slist_prepend (list, NM_REMOTE_CONNECTION (value));
for (list_iter = list; list_iter; list_iter = g_slist_next (list_iter))
g_signal_emit_by_name (NM_REMOTE_CONNECTION (list_iter->data), "removed");
g_signal_emit_by_name (NM_REMOTE_CONNECTION (list_iter->data), NM_REMOTE_CONNECTION_REMOVED);
g_slist_free (list);
g_hash_table_remove_all (priv->connections);
g_hash_table_remove_all (table);
}
static gboolean
remove_connections (gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
clear_one_hash (priv->pending);
clear_one_hash (priv->connections);
return FALSE;
}
typedef struct {
NMRemoteSettings *settings;
NMRemoteSettingsSaveHostnameFunc callback;
gpointer callback_data;
} SaveHostnameInfo;
static void
save_hostname_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
SaveHostnameInfo *info = user_data;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
info->callback (info->settings, error, info->callback_data);
g_clear_error (&error);
}
/**
* nm_remote_settings_save_hostname:
* @settings: the %NMRemoteSettings
* @hostname: the new persistent hostname to set, or NULL to clear any existing
* persistent hostname
* @callback: (scope async): callback to be called when the hostname operation completes
* @user_data: caller-specific data passed to @callback
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
*
* Returns: TRUE if the request was successful, FALSE if it failed
**/
gboolean
nm_remote_settings_save_hostname (NMRemoteSettings *settings,
const char *hostname,
NMRemoteSettingsSaveHostnameFunc callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
SaveHostnameInfo *info;
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (hostname != NULL, FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
info = g_malloc0 (sizeof (SaveHostnameInfo));
info->settings = settings;
info->callback = callback;
info->callback_data = user_data;
dbus_g_proxy_begin_call (priv->proxy, "SaveHostname",
save_hostname_cb,
info,
g_free,
G_TYPE_STRING, hostname ? hostname : "",
G_TYPE_INVALID);
return TRUE;
}
static void
name_owner_changed (DBusGProxy *proxy,
const char *name,
@@ -310,10 +616,7 @@ name_owner_changed (DBusGProxy *proxy,
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
const char *sname = NM_DBUS_SERVICE_USER_SETTINGS;
if (priv->scope == NM_CONNECTION_SCOPE_SYSTEM)
sname = NM_DBUS_SERVICE_SYSTEM_SETTINGS;
const char *sname = NM_DBUS_SERVICE;
if (!strcmp (name, sname)) {
if (priv->fetch_id)
@@ -330,35 +633,80 @@ name_owner_changed (DBusGProxy *proxy,
}
}
/****************************************************************/
static void
properties_changed_cb (DBusGProxy *proxy,
GHashTable *properties,
gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
GHashTableIter iter;
gpointer key, tmp;
g_hash_table_iter_init (&iter, properties);
while (g_hash_table_iter_next (&iter, &key, &tmp)) {
GValue *value = tmp;
if (!strcmp ((const char *) key, "Hostname")) {
g_free (priv->hostname);
priv->hostname = g_value_dup_string (value);
g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_HOSTNAME);
}
if (!strcmp ((const char *) key, "CanModify")) {
priv->can_modify = g_value_get_boolean (value);
g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_CAN_MODIFY);
}
}
}
static void
settings_interface_init (NMSettingsInterface *iface)
get_all_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
/* interface implementation */
iface->list_connections = list_connections;
iface->get_connection_by_path = get_connection_by_path;
iface->add_connection = add_connection;
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
GHashTable *props = NULL;
GError *error = NULL;
if (!dbus_g_proxy_end_call (proxy, call, &error,
DBUS_TYPE_G_MAP_OF_VARIANT, &props,
G_TYPE_INVALID)) {
/* Don't warn when the call times out because the settings service can't
* be activated or whatever.
*/
if (!(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NO_REPLY)) {
g_warning ("%s: couldn't retrieve system settings properties: (%d) %s.",
__func__,
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
}
g_clear_error (&error);
return;
}
properties_changed_cb (NULL, props, self);
g_hash_table_destroy (props);
}
/****************************************************************/
/**
* nm_remote_settings_new:
* @bus: a valid and connected D-Bus connection
* @scope: the settings service scope (either user or system)
* @bus: (allow-none): a valid and connected D-Bus connection
*
* Creates a new object representing the remote settings service.
*
* Returns: the new remote settings object on success, or %NULL on failure
**/
NMRemoteSettings *
nm_remote_settings_new (DBusGConnection *bus, NMConnectionScope scope)
nm_remote_settings_new (DBusGConnection *bus)
{
g_return_val_if_fail (bus != NULL, NULL);
g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
if (bus == NULL)
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
return (NMRemoteSettings *) g_object_new (NM_TYPE_REMOTE_SETTINGS,
NM_REMOTE_SETTINGS_BUS, bus,
NM_REMOTE_SETTINGS_SCOPE, scope,
NULL);
}
@@ -378,7 +726,6 @@ constructor (GType type,
{
GObject *object;
NMRemoteSettingsPrivate *priv;
const char *service = NM_DBUS_SERVICE_USER_SETTINGS;
GError *error = NULL;
object = G_OBJECT_CLASS (nm_remote_settings_parent_class)->constructor (type, n_construct_params, construct_params);
@@ -406,12 +753,8 @@ constructor (GType type,
G_CALLBACK (name_owner_changed),
object, NULL);
/* Settings service proxy */
if (priv->scope == NM_CONNECTION_SCOPE_SYSTEM)
service = NM_DBUS_SERVICE_SYSTEM_SETTINGS;
if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", &error,
G_TYPE_STRING, service,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->service_running,
G_TYPE_INVALID)) {
@@ -424,7 +767,7 @@ constructor (GType type,
}
priv->proxy = dbus_g_proxy_new_for_name (priv->bus,
service,
NM_DBUS_SERVICE,
NM_DBUS_PATH_SETTINGS,
NM_DBUS_IFACE_SETTINGS);
g_assert (priv->proxy);
@@ -440,13 +783,43 @@ constructor (GType type,
priv->fetch_id = g_idle_add (fetch_connections, object);
/* D-Bus properties proxy */
priv->props_proxy = dbus_g_proxy_new_for_name (priv->bus,
NM_DBUS_SERVICE,
NM_DBUS_PATH_SETTINGS,
"org.freedesktop.DBus.Properties");
g_assert (priv->props_proxy);
/* Monitor properties */
dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged",
DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged",
G_CALLBACK (properties_changed_cb),
object,
NULL);
/* Get properties */
dbus_g_proxy_begin_call (priv->props_proxy, "GetAll",
get_all_cb,
object,
NULL,
G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS,
G_TYPE_INVALID);
return object;
}
static void
dispose (GObject *object)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object);
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
if (priv->disposed)
return;
@@ -456,14 +829,20 @@ dispose (GObject *object)
if (priv->fetch_id)
g_source_remove (priv->fetch_id);
while (g_slist_length (priv->add_list))
add_connection_info_dispose (self, (AddConnectionInfo *) priv->add_list->data);
if (priv->connections)
g_hash_table_destroy (priv->connections);
if (priv->pending)
g_hash_table_destroy (priv->pending);
g_free (priv->hostname);
g_object_unref (priv->dbus_proxy);
g_object_unref (priv->proxy);
g_object_unref (priv->props_proxy);
dbus_g_connection_unref (priv->bus);
G_OBJECT_CLASS (nm_remote_settings_parent_class)->dispose (object);
@@ -480,9 +859,6 @@ set_property (GObject *object, guint prop_id,
/* Construct only */
priv->bus = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value));
break;
case PROP_SCOPE:
priv->scope = (NMConnectionScope) g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -499,12 +875,15 @@ get_property (GObject *object, guint prop_id,
case PROP_BUS:
g_value_set_boxed (value, priv->bus);
break;
case PROP_SCOPE:
g_value_set_uint (value, priv->scope);
break;
case PROP_SERVICE_RUNNING:
g_value_set_boolean (value, priv->service_running);
break;
case PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
break;
case PROP_CAN_MODIFY:
g_value_set_boolean (value, priv->can_modify);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -533,16 +912,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
DBUS_TYPE_G_CONNECTION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_SCOPE,
g_param_spec_uint (NM_REMOTE_SETTINGS_SCOPE,
"Scope",
"NMConnection scope",
NM_CONNECTION_SCOPE_UNKNOWN,
NM_CONNECTION_SCOPE_USER,
NM_CONNECTION_SCOPE_USER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_SERVICE_RUNNING,
g_param_spec_boolean (NM_REMOTE_SETTINGS_SERVICE_RUNNING,
@@ -550,5 +919,40 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
"Is service running",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_HOSTNAME,
g_param_spec_string (NM_REMOTE_SETTINGS_HOSTNAME,
"Hostname",
"Persistent hostname",
NULL,
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_CAN_MODIFY,
g_param_spec_boolean (NM_REMOTE_SETTINGS_CAN_MODIFY,
"CanModify",
"Can modify anything (hostname, connections, etc)",
FALSE,
G_PARAM_READABLE));
/* Signals */
signals[NEW_CONNECTION] =
g_signal_new (NM_REMOTE_SETTINGS_NEW_CONNECTION,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMRemoteSettingsClass, new_connection),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
signals[CONNECTIONS_READ] =
g_signal_new (NM_REMOTE_SETTINGS_CONNECTIONS_READ,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMRemoteSettingsClass, connections_read),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}

View File

@@ -38,17 +38,65 @@ G_BEGIN_DECLS
#define NM_IS_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_REMOTE_SETTINGS))
#define NM_REMOTE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass))
#define NM_REMOTE_SETTINGS_BUS "bus"
#define NM_REMOTE_SETTINGS_SCOPE "scope"
/**
* NMRemoteSettingsError:
* @NM_REMOTE_SETTINGS_ERROR_UNKNOWN: unknown or unclassified error
* @NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED: the #NMRemoteConnection object
* was removed before it was completely initialized
* @NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE: the #NMRemoteConnection object
* is not visible or otherwise unreadable
*
* Describes errors that may result from operations involving a #NMRemoteSettings.
*
**/
typedef enum {
NM_REMOTE_SETTINGS_ERROR_UNKNOWN = 0,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE,
} NMRemoteSettingsError;
#define NM_TYPE_REMOTE_SETTINGS_ERROR (nm_remote_settings_error_get_type ())
GType nm_remote_settings_error_get_type (void);
#define NM_REMOTE_SETTINGS_ERROR nm_remote_settings_error_quark ()
GQuark nm_remote_settings_error_quark (void);
#define NM_REMOTE_SETTINGS_BUS "bus"
#define NM_REMOTE_SETTINGS_SERVICE_RUNNING "service-running"
#define NM_REMOTE_SETTINGS_HOSTNAME "hostname"
#define NM_REMOTE_SETTINGS_CAN_MODIFY "can-modify"
typedef struct {
#define NM_REMOTE_SETTINGS_NEW_CONNECTION "new-connection"
#define NM_REMOTE_SETTINGS_CONNECTIONS_READ "connections-read"
typedef struct _NMRemoteSettings NMRemoteSettings;
typedef struct _NMRemoteSettingsClass NMRemoteSettingsClass;
typedef void (*NMRemoteSettingsAddConnectionFunc) (NMRemoteSettings *settings,
NMRemoteConnection *connection,
GError *error,
gpointer user_data);
typedef void (*NMRemoteSettingsSaveHostnameFunc) (NMRemoteSettings *settings,
GError *error,
gpointer user_data);
struct _NMRemoteSettings {
GObject parent;
} NMRemoteSettings;
};
typedef struct {
struct _NMRemoteSettingsClass {
GObjectClass parent;
/* Signals */
void (*new_connection) (NMRemoteSettings *settings,
NMRemoteConnection *connection);
void (*connections_read) (NMRemoteSettings *settings);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
@@ -56,11 +104,26 @@ typedef struct {
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMRemoteSettingsClass;
};
GType nm_remote_settings_get_type (void);
NMRemoteSettings *nm_remote_settings_new (DBusGConnection *bus, NMConnectionScope scope);
NMRemoteSettings *nm_remote_settings_new (DBusGConnection *bus);
GSList * nm_remote_settings_list_connections (NMRemoteSettings *settings);
NMRemoteConnection * nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings,
const char *path);
gboolean nm_remote_settings_add_connection (NMRemoteSettings *settings,
NMConnection *connection,
NMRemoteSettingsAddConnectionFunc callback,
gpointer user_data);
gboolean nm_remote_settings_save_hostname (NMRemoteSettings *settings,
const char *hostname,
NMRemoteSettingsSaveHostnameFunc callback,
gpointer user_data);
G_END_DECLS

View File

@@ -0,0 +1,862 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2011 Red Hat, Inc.
*/
#include <config.h>
#include <ctype.h>
#include <string.h>
#include <NetworkManager.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-secret-agent.h"
#include "nm-marshal.h"
#include "NetworkManager.h"
static void impl_secret_agent_get_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
const char *setting_name,
const char **hints,
guint32 flags,
DBusGMethodInvocation *context);
static void impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
const char *connection_path,
const char *setting_name,
DBusGMethodInvocation *context);
static void impl_secret_agent_save_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
DBusGMethodInvocation *context);
static void impl_secret_agent_delete_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
DBusGMethodInvocation *context);
#include "nm-secret-agent-glue.h"
G_DEFINE_ABSTRACT_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT)
#define NM_SECRET_AGENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_SECRET_AGENT, \
NMSecretAgentPrivate))
static gboolean auto_register_cb (gpointer user_data);
typedef struct {
gboolean registered;
DBusGConnection *bus;
DBusGProxy *dbus_proxy;
DBusGProxy *manager_proxy;
DBusGProxyCall *reg_call;
char *nm_owner;
char *identifier;
gboolean auto_register;
gboolean suppress_auto;
gboolean auto_register_id;
gboolean disposed;
} NMSecretAgentPrivate;
enum {
PROP_0,
PROP_IDENTIFIER,
PROP_AUTO_REGISTER,
LAST_PROP
};
enum {
REGISTRATION_RESULT,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/********************************************************************/
GQuark
nm_secret_agent_error_quark (void)
{
static GQuark ret = 0;
if (G_UNLIKELY (ret == 0))
ret = g_quark_from_static_string ("nm-secret-agent-error");
return ret;
}
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
nm_secret_agent_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
/* Sender is not authorized to make this request */
ENUM_ENTRY (NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, "NotAuthorized"),
/* Given connection details do not make a valid connection */
ENUM_ENTRY (NM_SECRET_AGENT_ERROR_INVALID_CONNECTION, "InvalidConnection"),
/* The request was canceled explicitly by the user */
ENUM_ENTRY (NM_SECRET_AGENT_ERROR_USER_CANCELED, "UserCanceled"),
/* The request was canceled, but not by the user */
ENUM_ENTRY (NM_SECRET_AGENT_ERROR_AGENT_CANCELED, "AgentCanceled"),
/* Some internal error prevented returning secrets */
ENUM_ENTRY (NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, "InternalError"),
/* No secrets could be found to fulfill the request */
ENUM_ENTRY (NM_SECRET_AGENT_ERROR_NO_SECRETS, "NoSecrets"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("NMSecretAgentError", values);
}
return etype;
}
/*************************************************************/
static const char *
get_nm_owner (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GError *error = NULL;
char *owner;
if (!priv->nm_owner) {
if (!dbus_g_proxy_call_with_timeout (priv->dbus_proxy,
"GetNameOwner", 2000, &error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_STRING, &owner,
G_TYPE_INVALID))
return NULL;
priv->nm_owner = g_strdup (owner);
g_free (owner);
}
return priv->nm_owner;
}
static void
_internal_unregister (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (priv->registered) {
dbus_g_connection_unregister_g_object (priv->bus, G_OBJECT (self));
priv->registered = FALSE;
}
}
static void
name_owner_changed (DBusGProxy *proxy,
const char *name,
const char *old_owner,
const char *new_owner,
gpointer user_data)
{
NMSecretAgent *self = NM_SECRET_AGENT (user_data);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
gboolean old_owner_good = (old_owner && strlen (old_owner));
gboolean new_owner_good = (new_owner && strlen (new_owner));
if (strcmp (name, NM_DBUS_SERVICE) == 0) {
g_free (priv->nm_owner);
priv->nm_owner = g_strdup (new_owner);
if (!old_owner_good && new_owner_good) {
/* NM appeared */
auto_register_cb (self);
} else if (old_owner_good && !new_owner_good) {
/* NM disappeared */
_internal_unregister (self);
} else if (old_owner_good && new_owner_good && strcmp (old_owner, new_owner)) {
/* Hmm, NM magically restarted */
_internal_unregister (self);
auto_register_cb (self);
}
}
}
static gboolean
verify_request (NMSecretAgent *self,
DBusGMethodInvocation *context,
GHashTable *connection_hash,
const char *connection_path,
NMConnection **out_connection,
GError **error)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
NMConnection *connection = NULL;
DBusConnection *bus;
char *sender;
const char *nm_owner;
DBusError dbus_error;
uid_t sender_uid = G_MAXUINT;
GError *local = NULL;
g_return_val_if_fail (context != NULL, FALSE);
/* Verify the sender's UID is 0, and that the sender is the same as
* NetworkManager's bus name owner.
*/
nm_owner = get_nm_owner (self);
if (!nm_owner) {
g_set_error_literal (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"NetworkManager bus name owner unknown.");
return FALSE;
}
bus = dbus_g_connection_get_connection (priv->bus);
if (!bus) {
g_set_error_literal (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Failed to get DBus connection.");
return FALSE;
}
sender = dbus_g_method_get_sender (context);
if (!sender) {
g_set_error_literal (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Failed to get request sender.");
return FALSE;
}
/* Check that the sender matches the current NM bus name owner */
if (strcmp (sender, nm_owner) != 0) {
g_set_error_literal (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Request sender does not match NetworkManager bus name owner.");
goto out;
}
dbus_error_init (&dbus_error);
sender_uid = dbus_bus_get_unix_user (bus, sender, &dbus_error);
if (dbus_error_is_set (&dbus_error)) {
g_set_error (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Failed to get request unix user: (%s) %s.",
dbus_error.name, dbus_error.message);
dbus_error_free (&dbus_error);
goto out;
}
if (0 != sender_uid) {
g_set_error_literal (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Request sender is not root.");
goto out;
}
/* And make sure the connection is actually valid */
if (connection_hash) {
connection = nm_connection_new_from_hash (connection_hash, &local);
if (connection && connection_path) {
nm_connection_set_path (connection, connection_path);
} else {
g_set_error (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_INVALID_CONNECTION,
"Invalid connection: (%d) %s",
local ? local->code : -1,
(local && local->message) ? local->message : "(unknown)");
g_clear_error (&local);
}
}
out:
if (out_connection)
*out_connection = connection;
g_free (sender);
return !!connection;
}
static void
get_secrets_cb (NMSecretAgent *self,
NMConnection *connection,
GHashTable *secrets,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, secrets);
}
static void
impl_secret_agent_get_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
const char *setting_name,
const char **hints,
guint32 flags,
DBusGMethodInvocation *context)
{
GError *error = NULL;
NMConnection *connection = NULL;
/* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
dbus_g_method_return_error (context, error);
g_clear_error (&error);
return;
}
NM_SECRET_AGENT_GET_CLASS (self)->get_secrets (self,
connection,
connection_path,
setting_name,
hints,
flags,
get_secrets_cb,
context);
g_object_unref (connection);
}
static void
impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
const char *connection_path,
const char *setting_name,
DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, NULL, NULL, NULL, &error)) {
dbus_g_method_return_error (context, error);
g_clear_error (&error);
} else {
NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self, connection_path, setting_name);
dbus_g_method_return (context);
}
}
static void
save_secrets_cb (NMSecretAgent *self,
NMConnection *connection,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
impl_secret_agent_save_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
DBusGMethodInvocation *context)
{
GError *error = NULL;
NMConnection *connection = NULL;
/* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
dbus_g_method_return_error (context, error);
g_clear_error (&error);
return;
}
NM_SECRET_AGENT_GET_CLASS (self)->save_secrets (self,
connection,
connection_path,
save_secrets_cb,
context);
g_object_unref (connection);
}
static void
delete_secrets_cb (NMSecretAgent *self,
NMConnection *connection,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
impl_secret_agent_delete_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
DBusGMethodInvocation *context)
{
GError *error = NULL;
NMConnection *connection = NULL;
/* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
dbus_g_method_return_error (context, error);
g_clear_error (&error);
return;
}
NM_SECRET_AGENT_GET_CLASS (self)->delete_secrets (self,
connection,
connection_path,
delete_secrets_cb,
context);
g_object_unref (connection);
}
/**************************************************************/
static void
reg_request_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
NMSecretAgent *self = NM_SECRET_AGENT (user_data);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GError *error = NULL;
priv->reg_call = NULL;
if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID))
priv->registered = TRUE;
else {
/* If registration failed we shouldn't expose ourselves on the bus */
_internal_unregister (self);
}
g_signal_emit (self, signals[REGISTRATION_RESULT], 0, error);
g_clear_error (&error);
}
/**
* nm_secret_agent_register:
*
* Registers the #NMSecretAgent with the NetworkManager secret manager,
* indicating to NetworkManager that the agent is able to provide and save
* secrets for connections on behalf of its user. Registration is an
* asynchronous operation and its success or failure is indicated via the
* 'registration-result' signal.
*
* Returns: a new %TRUE if registration was successfully requested (this does
* not mean registration itself was successful), %FALSE if registration was not
* successfully requested.
**/
gboolean
nm_secret_agent_register (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv;
NMSecretAgentClass *class;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (NM_IS_SECRET_AGENT (self), FALSE);
priv = NM_SECRET_AGENT_GET_PRIVATE (self);
g_return_val_if_fail (priv->registered == FALSE, FALSE);
g_return_val_if_fail (priv->reg_call == NULL, FALSE);
g_return_val_if_fail (priv->bus != NULL, FALSE);
g_return_val_if_fail (priv->manager_proxy != NULL, FALSE);
/* Also make sure the subclass can actually respond to secrets requests */
class = NM_SECRET_AGENT_GET_CLASS (self);
g_return_val_if_fail (class->get_secrets != NULL, FALSE);
g_return_val_if_fail (class->save_secrets != NULL, FALSE);
g_return_val_if_fail (class->delete_secrets != NULL, FALSE);
priv->suppress_auto = FALSE;
/* Export our secret agent interface before registering with the manager */
dbus_g_connection_register_g_object (priv->bus,
NM_DBUS_PATH_SECRET_AGENT,
G_OBJECT (self));
priv->reg_call = dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy,
"Register",
reg_request_cb,
self,
NULL,
5000,
G_TYPE_STRING, priv->identifier,
G_TYPE_INVALID);
return TRUE;
}
/**
* nm_secret_agent_unregister:
*
* Unregisters the #NMSecretAgent with the NetworkManager secret manager,
* indicating to NetworkManager that the agent is will no longer provide or
* store secrets on behalf of this user.
*
* Returns: a new %TRUE if unregistration was successful, %FALSE if it was not.
**/
gboolean
nm_secret_agent_unregister (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (NM_IS_SECRET_AGENT (self), FALSE);
priv = NM_SECRET_AGENT_GET_PRIVATE (self);
g_return_val_if_fail (priv->registered == TRUE, FALSE);
g_return_val_if_fail (priv->bus != NULL, FALSE);
g_return_val_if_fail (priv->manager_proxy != NULL, FALSE);
dbus_g_proxy_call_no_reply (priv->manager_proxy, "Unregister", G_TYPE_INVALID);
_internal_unregister (self);
priv->suppress_auto = TRUE;
return TRUE;
}
static gboolean
auto_register_cb (gpointer user_data)
{
NMSecretAgent *self = NM_SECRET_AGENT (user_data);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
priv->auto_register_id = 0;
if (priv->auto_register && !priv->suppress_auto && (priv->reg_call == NULL))
nm_secret_agent_register (self);
return FALSE;
}
/**************************************************************/
void
nm_secret_agent_get_secrets (NMSecretAgent *self,
NMConnection *connection,
const char *setting_name,
const char **hints,
guint32 flags,
NMSecretAgentGetSecretsFunc callback,
gpointer callback_data)
{
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_SECRET_AGENT (self));
g_return_if_fail (connection != NULL);
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (nm_connection_get_path (connection));
g_return_if_fail (setting_name != NULL);
g_return_if_fail (strlen (setting_name) > 0);
g_return_if_fail (callback != NULL);
NM_SECRET_AGENT_GET_CLASS (self)->get_secrets (self,
connection,
nm_connection_get_path (connection),
setting_name,
hints,
flags,
callback,
callback_data);
}
void
nm_secret_agent_save_secrets (NMSecretAgent *self,
NMConnection *connection,
NMSecretAgentSaveSecretsFunc callback,
gpointer callback_data)
{
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_SECRET_AGENT (self));
g_return_if_fail (connection != NULL);
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (nm_connection_get_path (connection));
NM_SECRET_AGENT_GET_CLASS (self)->save_secrets (self,
connection,
nm_connection_get_path (connection),
callback,
callback_data);
}
void
nm_secret_agent_delete_secrets (NMSecretAgent *self,
NMConnection *connection,
NMSecretAgentDeleteSecretsFunc callback,
gpointer callback_data)
{
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_SECRET_AGENT (self));
g_return_if_fail (connection != NULL);
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (nm_connection_get_path (connection));
NM_SECRET_AGENT_GET_CLASS (self)->delete_secrets (self,
connection,
nm_connection_get_path (connection),
callback,
callback_data);
}
/**************************************************************/
static gboolean
validate_identifier (const char *identifier)
{
const char *p = identifier;
size_t id_len;
/* Length between 3 and 255 characters inclusive */
id_len = strlen (identifier);
if (id_len < 3 || id_len > 255)
return FALSE;
if ((identifier[0] == '.') || (identifier[id_len - 1] == '.'))
return FALSE;
/* FIXME: do complete validation here */
while (p && *p) {
if (!isalnum (*p) && (*p != '_') && (*p != '-') && (*p != '.'))
return FALSE;
if ((*p == '.') && (*(p + 1) == '.'))
return FALSE;
p++;
}
return TRUE;
}
static void
nm_secret_agent_init (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GError *error = NULL;
priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (!priv->bus) {
g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
return;
}
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
if (!priv->dbus_proxy) {
g_warning ("Couldn't create messagebus proxy.");
return;
}
dbus_g_object_register_marshaller (_nm_marshal_VOID__STRING_STRING_STRING,
G_TYPE_NONE,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->dbus_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
self, NULL);
priv->manager_proxy = dbus_g_proxy_new_for_name (priv->bus,
NM_DBUS_SERVICE,
NM_DBUS_PATH_AGENT_MANAGER,
NM_DBUS_INTERFACE_AGENT_MANAGER);
if (!priv->manager_proxy) {
g_warning ("Couldn't create NM agent manager proxy.");
return;
}
priv->auto_register_id = g_idle_add (auto_register_cb, self);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (object);
switch (prop_id) {
case PROP_IDENTIFIER:
g_value_set_string (value, priv->identifier);
break;
case PROP_AUTO_REGISTER:
g_value_set_boolean (value, priv->auto_register);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (object);
const char *identifier;
switch (prop_id) {
case PROP_IDENTIFIER:
identifier = g_value_get_string (value);
g_return_if_fail (validate_identifier (identifier));
g_free (priv->identifier);
priv->identifier = g_strdup (identifier);
break;
case PROP_AUTO_REGISTER:
priv->auto_register = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
NMSecretAgent *self = NM_SECRET_AGENT (object);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (!priv->disposed) {
priv->disposed = TRUE;
if (priv->registered)
nm_secret_agent_unregister (self);
if (priv->auto_register_id)
g_source_remove (priv->auto_register_id);
g_free (priv->identifier);
g_free (priv->nm_owner);
if (priv->dbus_proxy)
g_object_unref (priv->dbus_proxy);
if (priv->manager_proxy)
g_object_unref (priv->manager_proxy);
if (priv->bus)
dbus_g_connection_unref (priv->bus);
}
G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object);
}
static void
nm_secret_agent_class_init (NMSecretAgentClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
g_type_class_add_private (class, sizeof (NMSecretAgentPrivate));
/* Virtual methods */
object_class->dispose = dispose;
object_class->get_property = get_property;
object_class->set_property = set_property;
/**
* NMSecretAgent:identifier:
*
* Identifies this agent; only one agent in each user session may use the
* same identifier. Identifier formatting follows the same rules as
* D-Bus bus names with the exception that the ':' character is not
* allowed. The valid set of characters is "[A-Z][a-z][0-9]_-." and the
* identifier is limited in length to 255 characters with a minimum
* of 3 characters. An example valid identifier is 'org.gnome.nm-applet'
* (without quotes).
**/
g_object_class_install_property
(object_class, PROP_IDENTIFIER,
g_param_spec_string (NM_SECRET_AGENT_IDENTIFIER,
"Identifier",
"Identifier",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* NMSecretAgent:auto-register:
*
* If TRUE, the agent will attempt to automatically register itself after
* it is created (via an idle handler) and to re-register itself if
* NetworkManager restarts. If FALSE, the agent does not automatically
* register with NetworkManager, and nm_secret_agent_register() must be
* called. If 'auto-register' is TRUE, calling nm_secret_agent_unregister()
* will suppress auto-registration until nm_secret_agent_register() is
* called, which re-enables auto-registration.
**/
g_object_class_install_property
(object_class, PROP_AUTO_REGISTER,
g_param_spec_boolean (NM_SECRET_AGENT_AUTO_REGISTER,
"Auto Register",
"Auto Register",
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* NMSecretAgent::registration-result:
* @agent: the agent that received the signal
* @error: the error, if any, that occured while registering
*
* Indicates the result of a registration request; if @error is NULL the
* request was successful.
**/
signals[REGISTRATION_RESULT] =
g_signal_new (NM_SECRET_AGENT_REGISTRATION_RESULT,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
&dbus_glib_nm_secret_agent_object_info);
dbus_g_error_domain_register (NM_SECRET_AGENT_ERROR,
NM_DBUS_INTERFACE_SECRET_AGENT,
NM_TYPE_SECRET_AGENT_ERROR);
}

View File

@@ -0,0 +1,171 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2011 Red Hat, Inc.
*/
#ifndef NM_SECRET_AGENT_H
#define NM_SECRET_AGENT_H
#include <nm-connection.h>
G_BEGIN_DECLS
#define NM_SECRET_AGENT_ERROR (nm_secret_agent_error_quark ())
#define NM_TYPE_SECRET_AGENT_ERROR (nm_secret_agent_error_get_type ())
GQuark nm_secret_agent_error_quark (void);
GType nm_secret_agent_error_get_type (void);
typedef enum {
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED = 0,
NM_SECRET_AGENT_ERROR_INVALID_CONNECTION,
NM_SECRET_AGENT_ERROR_USER_CANCELED,
NM_SECRET_AGENT_ERROR_AGENT_CANCELED,
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
NM_SECRET_AGENT_ERROR_NO_SECRETS,
} NMSecretAgentError;
enum {
NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE = 0x0,
NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION = 0x1,
NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW = 0x2
};
#define NM_TYPE_SECRET_AGENT (nm_secret_agent_get_type ())
#define NM_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgent))
#define NM_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT, NMSecretAgentClass))
#define NM_IS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT))
#define NM_IS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SECRET_AGENT))
#define NM_SECRET_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgentClass))
#define NM_SECRET_AGENT_IDENTIFIER "identifier"
#define NM_SECRET_AGENT_AUTO_REGISTER "auto-register"
#define NM_SECRET_AGENT_REGISTRATION_RESULT "registration-result"
typedef struct {
GObject parent;
} NMSecretAgent;
typedef void (*NMSecretAgentGetSecretsFunc) (NMSecretAgent *agent,
NMConnection *connection,
GHashTable *secrets,
GError *error,
gpointer user_data);
typedef void (*NMSecretAgentSaveSecretsFunc) (NMSecretAgent *agent,
NMConnection *connection,
GError *error,
gpointer user_data);
typedef void (*NMSecretAgentDeleteSecretsFunc) (NMSecretAgent *agent,
NMConnection *connection,
GError *error,
gpointer user_data);
typedef struct {
GObjectClass parent;
/* Virtual methods for subclasses */
/* Called when the subclass should retrieve and return secrets. Subclass
* must copy or reference any arguments it may require after returning from
* this method, as the arguments will freed (except for 'agent', 'callback',
* and 'callback_data' of course). If the request is canceled, the callback
* should still be called, but with the NM_SECRET_AGENT_ERROR_AGENT_CANCELED
* error.
*/
void (*get_secrets) (NMSecretAgent *agent,
NMConnection *connection,
const char *connection_path,
const char *setting_name,
const char **hints,
guint32 flags,
NMSecretAgentGetSecretsFunc callback,
gpointer callback_data);
/* Called when the subclass should cancel an outstanding request to
* get secrets for a given connection.
*/
void (*cancel_get_secrets) (NMSecretAgent *agent,
const char *connection_path,
const char *setting_name);
/* Called when the subclass should save the secrets contained in the
* connection to backing storage. Subclass must copy or reference any
* arguments it may require after returning from this method, as the
* arguments will freed (except for 'agent', 'callback', and 'callback_data'
* of course).
*/
void (*save_secrets) (NMSecretAgent *agent,
NMConnection *connection,
const char *connection_path,
NMSecretAgentSaveSecretsFunc callback,
gpointer callback_data);
/* Called when the subclass should delete the secrets contained in the
* connection from backing storage. Subclass must copy or reference any
* arguments it may require after returning from this method, as the
* arguments will freed (except for 'agent', 'callback', and 'callback_data'
* of course).
*/
void (*delete_secrets) (NMSecretAgent *agent,
NMConnection *connection,
const char *connection_path,
NMSecretAgentDeleteSecretsFunc callback,
gpointer callback_data);
/* Signals */
void (*registration_result) (NMSecretAgent *agent, GError *error);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMSecretAgentClass;
GType nm_secret_agent_get_type (void);
gboolean nm_secret_agent_register (NMSecretAgent *self);
gboolean nm_secret_agent_unregister (NMSecretAgent *self);
void nm_secret_agent_get_secrets (NMSecretAgent *self,
NMConnection *connection,
const char *setting_name,
const char **hints,
guint32 flags,
NMSecretAgentGetSecretsFunc callback,
gpointer callback_data);
void nm_secret_agent_save_secrets (NMSecretAgent *self,
NMConnection *connection,
NMSecretAgentSaveSecretsFunc callback,
gpointer callback_data);
void nm_secret_agent_delete_secrets (NMSecretAgent *self,
NMConnection *connection,
NMSecretAgentDeleteSecretsFunc callback,
gpointer callback_data);
G_END_DECLS
#endif /* NM_SECRET_AGENT_H */

View File

@@ -1,192 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2009 Red Hat, Inc.
*/
#include "nm-settings-connection-interface.h"
#include "nm-dbus-glib-types.h"
/**
* nm_settings_connection_interface_update:
* @connection: an object implementing #NMSettingsConnectionInterface
* @callback: a function to be called when the update completes
* @user_data: caller-specific data to be passed to @callback
*
* Update the connection with current settings and properties.
*
* Returns: TRUE on success, FALSE on failure
**/
gboolean
nm_settings_connection_interface_update (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceUpdateFunc callback,
gpointer user_data)
{
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
if (NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->update) {
return NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->update (connection,
callback,
user_data);
}
return FALSE;
}
/**
* nm_settings_connection_interface_delete:
* @connection: a objecting implementing #NMSettingsConnectionInterface
* @callback: a function to be called when the delete completes
* @user_data: caller-specific data to be passed to @callback
*
* Delete the connection.
*
* Returns: TRUE on success, FALSE on failure
**/
gboolean
nm_settings_connection_interface_delete (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceDeleteFunc callback,
gpointer user_data)
{
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
if (NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->delete) {
return NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->delete (connection,
callback,
user_data);
}
return FALSE;
}
/**
* nm_settings_connection_interface_get_secrets:
* @connection: a object implementing #NMSettingsConnectionInterface
* @setting_name: the #NMSetting object name to get secrets for
* @hints: #NMSetting key names to get secrets for (optional)
* @request_new: hint that new secrets (instead of cached or stored secrets)
* should be returned
* @callback: a function to be called when the update completes
* @user_data: caller-specific data to be passed to @callback
*
* Request the connection's secrets.
*
* Returns: TRUE on success, FALSE on failure
**/
gboolean
nm_settings_connection_interface_get_secrets (NMSettingsConnectionInterface *connection,
const char *setting_name,
const char **hints,
gboolean request_new,
NMSettingsConnectionInterfaceGetSecretsFunc callback,
gpointer user_data)
{
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
if (NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->get_secrets) {
return NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->get_secrets (connection,
setting_name,
hints,
request_new,
callback,
user_data);
}
return FALSE;
}
void
nm_settings_connection_interface_emit_updated (NMSettingsConnectionInterface *connection)
{
if (NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->emit_updated)
NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE (connection)->emit_updated (connection);
else {
NMConnection *tmp;
GHashTable *settings;
tmp = nm_connection_duplicate (NM_CONNECTION (connection));
nm_connection_clear_secrets (tmp);
settings = nm_connection_to_hash (tmp);
g_object_unref (tmp);
g_signal_emit_by_name (connection, NM_SETTINGS_CONNECTION_INTERFACE_UPDATED, settings);
g_hash_table_destroy (settings);
}
}
static void
nm_settings_connection_interface_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Signals */
g_signal_new (NM_SETTINGS_CONNECTION_INTERFACE_UPDATED,
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSettingsConnectionInterface, updated),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT);
g_signal_new (NM_SETTINGS_CONNECTION_INTERFACE_REMOVED,
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSettingsConnectionInterface, removed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
initialized = TRUE;
}
GType
nm_settings_connection_interface_get_type (void)
{
static GType itype = 0;
if (!itype) {
const GTypeInfo iinfo = {
sizeof (NMSettingsConnectionInterface), /* class_size */
nm_settings_connection_interface_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
itype = g_type_register_static (G_TYPE_INTERFACE,
"NMSettingsConnectionInterface",
&iinfo, 0);
g_type_interface_add_prerequisite (itype, NM_TYPE_CONNECTION);
}
return itype;
}

View File

@@ -1,116 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* libnm_glib -- Access network status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2009 Red Hat, Inc.
*/
#ifndef __NM_SETTINGS_CONNECTION_INTERFACE_H__
#define __NM_SETTINGS_CONNECTION_INTERFACE_H__
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <nm-connection.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTINGS_CONNECTION_INTERFACE (nm_settings_connection_interface_get_type ())
#define NM_SETTINGS_CONNECTION_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS_CONNECTION_INTERFACE, NMSettingsConnectionInterface))
#define NM_IS_SETTINGS_CONNECTION_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_CONNECTION_INTERFACE))
#define NM_SETTINGS_CONNECTION_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_SETTINGS_CONNECTION_INTERFACE, NMSettingsConnectionInterface))
#define NM_SETTINGS_CONNECTION_INTERFACE_UPDATED "updated"
#define NM_SETTINGS_CONNECTION_INTERFACE_REMOVED "removed"
typedef struct _NMSettingsConnectionInterface NMSettingsConnectionInterface;
typedef void (*NMSettingsConnectionInterfaceUpdateFunc) (NMSettingsConnectionInterface *connection,
GError *error,
gpointer user_data);
typedef void (*NMSettingsConnectionInterfaceDeleteFunc) (NMSettingsConnectionInterface *connection,
GError *error,
gpointer user_data);
typedef void (*NMSettingsConnectionInterfaceGetSecretsFunc) (NMSettingsConnectionInterface *connection,
GHashTable *secrets,
GError *error,
gpointer user_data);
struct _NMSettingsConnectionInterface {
GTypeInterface g_iface;
/* Methods */
gboolean (*update) (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceUpdateFunc callback,
gpointer user_data);
gboolean (*delete) (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceDeleteFunc callback,
gpointer user_data);
gboolean (*get_secrets) (NMSettingsConnectionInterface *connection,
const char *setting_name,
const char **hints,
gboolean request_new,
NMSettingsConnectionInterfaceGetSecretsFunc callback,
gpointer user_data);
void (*emit_updated) (NMSettingsConnectionInterface *connection);
/* Signals */
/* 'new_settings' hash should *not* contain secrets */
void (*updated) (NMSettingsConnectionInterface *connection,
GHashTable *new_settings);
void (*removed) (NMSettingsConnectionInterface *connection);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
};
GType nm_settings_connection_interface_get_type (void);
gboolean nm_settings_connection_interface_update (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceUpdateFunc callback,
gpointer user_data);
gboolean nm_settings_connection_interface_delete (NMSettingsConnectionInterface *connection,
NMSettingsConnectionInterfaceDeleteFunc callback,
gpointer user_data);
gboolean nm_settings_connection_interface_get_secrets (NMSettingsConnectionInterface *connection,
const char *setting_name,
const char **hints,
gboolean request_new,
NMSettingsConnectionInterfaceGetSecretsFunc callback,
gpointer user_data);
void nm_settings_connection_interface_emit_updated (NMSettingsConnectionInterface *connection);
G_END_DECLS
#endif /* __NM_SETTINGS_CONNECTION_INTERFACE_H__ */

View File

@@ -1,206 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
*/
#include "nm-settings-interface.h"
/**
* nm_settings_interface_error_quark:
*
* Setting error quark.
*
* Returns: the setting error quark
**/
GQuark
nm_settings_interface_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-settings-interface-error-quark");
return quark;
}
/* This should really be standard. */
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
nm_settings_interface_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
/* The connection was invalid. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_INVALID_CONNECTION, "InvalidConnection"),
/* The connection is read-only; modifications are not allowed. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_READ_ONLY_CONNECTION, "ReadOnlyConnection"),
/* A bug in the settings service caused the error. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR, "InternalError"),
/* Retrieval or request of secrets failed. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_SECRETS_UNAVAILABLE, "SecretsUnavailable"),
/* The request for secrets was canceled. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_SECRETS_REQUEST_CANCELED, "SecretsRequestCanceled"),
/* The request could not be completed because permission was denied. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_PERMISSION_DENIED, "PermissionDenied"),
/* The requested setting does not existing in this connection. */
ENUM_ENTRY (NM_SETTINGS_INTERFACE_ERROR_INVALID_SETTING, "InvalidSetting"),
{ 0, 0, 0 },
};
etype = g_enum_register_static ("NMSettingsInterfaceError", values);
}
return etype;
}
/**
* nm_settings_list_connections:
* @settings: a object implementing %NMSettingsInterface
*
* Returns: all connections known to the object.
**/
GSList *
nm_settings_interface_list_connections (NMSettingsInterface *settings)
{
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (NM_IS_SETTINGS_INTERFACE (settings), NULL);
if (NM_SETTINGS_INTERFACE_GET_INTERFACE (settings)->list_connections)
return NM_SETTINGS_INTERFACE_GET_INTERFACE (settings)->list_connections (settings);
return NULL;
}
/**
* nm_settings_get_connection_by_path:
* @settings: a object implementing %NMSettingsInterface
* @path: the D-Bus object path of the remote connection
*
* Returns the object implementing %NMSettingsConnectionInterface at @path.
*
* Returns: the remote connection object on success, or NULL if the object was
* not known
**/
NMSettingsConnectionInterface *
nm_settings_interface_get_connection_by_path (NMSettingsInterface *settings,
const char *path)
{
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (NM_IS_SETTINGS_INTERFACE (settings), NULL);
g_return_val_if_fail (path != NULL, NULL);
if (NM_SETTINGS_INTERFACE_GET_INTERFACE (settings)->get_connection_by_path)
return NM_SETTINGS_INTERFACE_GET_INTERFACE (settings)->get_connection_by_path (settings, path);
return NULL;
}
/**
* nm_settings_interface_add_connection:
* @settings: a object implementing %NMSettingsInterface
* @connection: the settings to add; note that this object's settings will be
* added, not the object itself
* @callback: callback to be called when the add operation completes
* @user_data: caller-specific data passed to @callback
*
* Requests that the settings service add the given settings to a new connection.
*
* Returns: TRUE if the request was successful, FALSE if it failed
**/
gboolean
nm_settings_interface_add_connection (NMSettingsInterface *settings,
NMConnection *connection,
NMSettingsAddConnectionFunc callback,
gpointer user_data)
{
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_INTERFACE (settings), FALSE);
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
if (NM_SETTINGS_INTERFACE_GET_INTERFACE (settings)->add_connection) {
return NM_SETTINGS_INTERFACE_GET_INTERFACE (settings)->add_connection (settings,
connection,
callback,
user_data);
}
return FALSE;
}
/*****************************************************************/
static void
nm_settings_interface_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Signals */
g_signal_new (NM_SETTINGS_INTERFACE_NEW_CONNECTION,
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSettingsInterface, new_connection),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
g_signal_new (NM_SETTINGS_INTERFACE_CONNECTIONS_READ,
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSettingsInterface, connections_read),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
initialized = TRUE;
}
GType
nm_settings_interface_get_type (void)
{
static GType settings_interface_type = 0;
if (!settings_interface_type) {
const GTypeInfo settings_interface_info = {
sizeof (NMSettingsInterface), /* class_size */
nm_settings_interface_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
settings_interface_type = g_type_register_static (G_TYPE_INTERFACE,
"NMSettingsInterface",
&settings_interface_info, 0);
g_type_interface_add_prerequisite (settings_interface_type, G_TYPE_OBJECT);
}
return settings_interface_type;
}

View File

@@ -1,109 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
*/
#ifndef NM_SETTINGS_INTERFACE_H
#define NM_SETTINGS_INTERFACE_H
#include <glib-object.h>
#include "NetworkManager.h"
#include "nm-settings-connection-interface.h"
G_BEGIN_DECLS
typedef enum {
NM_SETTINGS_INTERFACE_ERROR_INVALID_CONNECTION = 0,
NM_SETTINGS_INTERFACE_ERROR_READ_ONLY_CONNECTION,
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
NM_SETTINGS_INTERFACE_ERROR_SECRETS_UNAVAILABLE,
NM_SETTINGS_INTERFACE_ERROR_SECRETS_REQUEST_CANCELED,
NM_SETTINGS_INTERFACE_ERROR_PERMISSION_DENIED,
NM_SETTINGS_INTERFACE_ERROR_INVALID_SETTING,
} NMSettingsInterfaceError;
#define NM_SETTINGS_INTERFACE_ERROR (nm_settings_interface_error_quark ())
GQuark nm_settings_interface_error_quark (void);
#define NM_TYPE_SETTINGS_INTERFACE_ERROR (nm_settings_interface_error_get_type ())
GType nm_settings_interface_error_get_type (void);
#define NM_TYPE_SETTINGS_INTERFACE (nm_settings_interface_get_type ())
#define NM_SETTINGS_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS_INTERFACE, NMSettingsInterface))
#define NM_IS_SETTINGS_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_INTERFACE))
#define NM_SETTINGS_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_SETTINGS_INTERFACE, NMSettingsInterface))
#define NM_SETTINGS_INTERFACE_NEW_CONNECTION "new-connection"
#define NM_SETTINGS_INTERFACE_CONNECTIONS_READ "connections-read"
typedef struct _NMSettingsInterface NMSettingsInterface;
typedef void (*NMSettingsAddConnectionFunc) (NMSettingsInterface *settings,
GError *error,
gpointer user_data);
struct _NMSettingsInterface {
GTypeInterface g_iface;
/* Methods */
/* Returns a list of objects implementing NMSettingsConnectionInterface */
GSList * (*list_connections) (NMSettingsInterface *settings);
NMSettingsConnectionInterface * (*get_connection_by_path) (NMSettingsInterface *settings,
const char *path);
gboolean (*add_connection) (NMSettingsInterface *settings,
NMConnection *connection,
NMSettingsAddConnectionFunc callback,
gpointer user_data);
/* Signals */
void (*new_connection) (NMSettingsInterface *settings,
NMSettingsConnectionInterface *connection);
void (*connections_read) (NMSettingsInterface *settings);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
};
GType nm_settings_interface_get_type (void);
/* Returns a list of objects implementing NMSettingsConnectionInterface */
GSList *nm_settings_interface_list_connections (NMSettingsInterface *settings);
NMSettingsConnectionInterface *nm_settings_interface_get_connection_by_path (NMSettingsInterface *settings,
const char *path);
gboolean nm_settings_interface_add_connection (NMSettingsInterface *settings,
NMConnection *connection,
NMSettingsAddConnectionFunc callback,
gpointer user_data);
G_END_DECLS
#endif /* NM_SETTINGS_INTERFACE_H */

View File

@@ -1,372 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Novell, Inc.
* (C) Copyright 2008 - 2009 Red Hat, Inc.
*/
#include <string.h>
#include <NetworkManager.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-settings-service.h"
#include "nm-settings-interface.h"
#include "nm-exported-connection.h"
static gboolean impl_settings_list_connections (NMSettingsService *self,
GPtrArray **connections,
GError **error);
static void impl_settings_add_connection (NMSettingsService *self,
GHashTable *settings,
DBusGMethodInvocation *context);
#include "nm-settings-glue.h"
static void settings_interface_init (NMSettingsInterface *class);
G_DEFINE_TYPE_EXTENDED (NMSettingsService, nm_settings_service, G_TYPE_OBJECT, G_TYPE_FLAG_ABSTRACT,
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_INTERFACE, settings_interface_init))
#define NM_SETTINGS_SERVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_SETTINGS_SERVICE, \
NMSettingsServicePrivate))
typedef struct {
DBusGConnection *bus;
NMConnectionScope scope;
gboolean exported;
gboolean disposed;
} NMSettingsServicePrivate;
enum {
PROP_0,
PROP_BUS,
PROP_SCOPE,
LAST_PROP
};
/**************************************************************/
void
nm_settings_service_export (NMSettingsService *self)
{
NMSettingsServicePrivate *priv;
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_SETTINGS_SERVICE (self));
priv = NM_SETTINGS_SERVICE_GET_PRIVATE (self);
g_return_if_fail (priv->bus != NULL);
/* Don't allow exporting twice */
g_return_if_fail (priv->exported == FALSE);
dbus_g_connection_register_g_object (priv->bus,
NM_DBUS_PATH_SETTINGS,
G_OBJECT (self));
priv->exported = TRUE;
}
/**************************************************************/
static GSList *
list_connections (NMSettingsInterface *settings)
{
/* Must always be implemented */
g_assert (NM_SETTINGS_SERVICE_GET_CLASS (settings)->list_connections);
return NM_SETTINGS_SERVICE_GET_CLASS (settings)->list_connections (NM_SETTINGS_SERVICE (settings));
}
static gboolean
impl_settings_list_connections (NMSettingsService *self,
GPtrArray **connections,
GError **error)
{
GSList *list = NULL, *iter;
list = list_connections (NM_SETTINGS_INTERFACE (self));
*connections = g_ptr_array_sized_new (g_slist_length (list) + 1);
for (iter = list; iter; iter = g_slist_next (iter)) {
g_ptr_array_add (*connections,
g_strdup (nm_connection_get_path (NM_CONNECTION (iter->data))));
}
g_slist_free (list);
return TRUE;
}
static NMSettingsConnectionInterface *
get_connection_by_path (NMSettingsInterface *settings, const char *path)
{
NMExportedConnection *connection = NULL;
GSList *list = NULL, *iter;
list = list_connections (settings);
for (iter = list; iter; iter = g_slist_next (iter)) {
if (!strcmp (nm_connection_get_path (NM_CONNECTION (iter->data)), path)) {
connection = NM_EXPORTED_CONNECTION (iter->data);
break;
}
}
g_slist_free (list);
return (NMSettingsConnectionInterface *) connection;
}
NMExportedConnection *
nm_settings_service_get_connection_by_path (NMSettingsService *self,
const char *path)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (NM_IS_SETTINGS_SERVICE (self), NULL);
return (NMExportedConnection *) get_connection_by_path (NM_SETTINGS_INTERFACE (self), path);
}
static gboolean
add_connection (NMSettingsInterface *settings,
NMConnection *connection,
NMSettingsAddConnectionFunc callback,
gpointer user_data)
{
NMSettingsService *self = NM_SETTINGS_SERVICE (settings);
GError *error = NULL;
gboolean success = FALSE;
if (NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection) {
NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection (NM_SETTINGS_SERVICE (self),
connection,
NULL,
callback,
user_data);
success = TRUE;
} else {
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
"%s: %s:%d add_connection() not implemented",
__func__, __FILE__, __LINE__);
callback (settings, error, user_data);
g_error_free (error);
}
return success;
}
static void
dbus_add_connection_cb (NMSettingsInterface *settings,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
impl_settings_add_connection (NMSettingsService *self,
GHashTable *settings,
DBusGMethodInvocation *context)
{
NMConnection *tmp;
GError *error = NULL;
/* Check if the settings are valid first */
tmp = nm_connection_new_from_hash (settings, &error);
if (!tmp) {
g_assert (error);
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
}
if (NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection) {
NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection (NM_SETTINGS_SERVICE (self),
tmp,
context,
dbus_add_connection_cb,
context);
} else {
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
"%s: %s:%d add_connection() not implemented",
__func__, __FILE__, __LINE__);
dbus_g_method_return_error (context, error);
g_error_free (error);
}
g_object_unref (tmp);
}
void
nm_settings_service_export_connection (NMSettingsService *self,
NMSettingsConnectionInterface *connection)
{
NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (self);
static guint32 ec_counter = 0;
char *path;
g_return_if_fail (connection != NULL);
g_return_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection));
g_return_if_fail (priv->bus != NULL);
/* Don't allow exporting twice */
g_return_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);
path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
nm_connection_set_path (NM_CONNECTION (connection), path);
nm_connection_set_scope (NM_CONNECTION (connection), priv->scope);
dbus_g_connection_register_g_object (priv->bus, path, G_OBJECT (connection));
g_free (path);
}
/**************************************************************/
static void
settings_interface_init (NMSettingsInterface *iface)
{
/* interface implementation */
iface->list_connections = list_connections;
iface->get_connection_by_path = get_connection_by_path;
iface->add_connection = add_connection;
dbus_g_object_type_install_info (G_TYPE_FROM_INTERFACE (iface),
&dbus_glib_nm_settings_object_info);
}
static GObject *
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
object = G_OBJECT_CLASS (nm_settings_service_parent_class)->constructor (type, n_construct_params, construct_params);
if (object) {
g_assert (NM_SETTINGS_SERVICE_GET_PRIVATE (object)->scope != NM_CONNECTION_SCOPE_UNKNOWN);
}
return object;
}
static void
nm_settings_service_init (NMSettingsService *self)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (object);
DBusGConnection *bus;
switch (prop_id) {
case PROP_BUS:
/* Construct only */
bus = g_value_get_boxed (value);
if (bus)
priv->bus = dbus_g_connection_ref (bus);
break;
case PROP_SCOPE:
/* Construct only */
priv->scope = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_BUS:
g_value_set_boxed (value, priv->bus);
break;
case PROP_SCOPE:
g_value_set_uint (value, priv->scope);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (object);
if (!priv->disposed) {
priv->disposed = TRUE;
if (priv->bus)
dbus_g_connection_unref (priv->bus);
}
G_OBJECT_CLASS (nm_settings_service_parent_class)->dispose (object);
}
static void
nm_settings_service_class_init (NMSettingsServiceClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
g_type_class_add_private (class, sizeof (NMSettingsServicePrivate));
/* Virtual methods */
object_class->dispose = dispose;
object_class->constructor = constructor;
object_class->get_property = get_property;
object_class->set_property = set_property;
/**
* NMSettingsService:bus:
*
* The %DBusGConnection which this object is exported on
**/
g_object_class_install_property (object_class, PROP_BUS,
g_param_spec_boxed (NM_SETTINGS_SERVICE_BUS,
"Bus",
"Bus",
DBUS_TYPE_G_CONNECTION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* NMSettingsService:scope:
*
* The capabilities of the device.
**/
g_object_class_install_property (object_class, PROP_SCOPE,
g_param_spec_uint (NM_SETTINGS_SERVICE_SCOPE,
"Scope",
"Scope",
NM_CONNECTION_SCOPE_SYSTEM,
NM_CONNECTION_SCOPE_USER,
NM_CONNECTION_SCOPE_USER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}

View File

@@ -1,82 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2009 Red Hat, Inc.
*/
#ifndef NM_SETTINGS_SERVICE_H
#define NM_SETTINGS_SERVICE_H
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <nm-exported-connection.h>
#include <nm-settings-interface.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTINGS_SERVICE (nm_settings_service_get_type ())
#define NM_SETTINGS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS_SERVICE, NMSettingsService))
#define NM_SETTINGS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTINGS_SERVICE, NMSettingsServiceClass))
#define NM_IS_SETTINGS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_SERVICE))
#define NM_IS_SETTINGS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTINGS_SERVICE))
#define NM_SETTINGS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTINGS_SERVICE, NMSettingsServiceClass))
#define NM_SETTINGS_SERVICE_BUS "bus"
#define NM_SETTINGS_SERVICE_SCOPE "scope"
typedef struct {
GObject parent;
} NMSettingsService;
typedef struct {
GObjectClass parent;
/* Returned list must contain all NMExportedConnection objects exported
* by the settings service. The list (but not the NMExportedConnection
* objects) will be freed by caller.
*/
GSList * (*list_connections) (NMSettingsService *self);
void (*add_connection) (NMSettingsService *self,
NMConnection *connection,
DBusGMethodInvocation *context, /* Only present for D-Bus calls */
NMSettingsAddConnectionFunc callback,
gpointer user_data);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMSettingsServiceClass;
GType nm_settings_service_get_type (void);
NMExportedConnection *nm_settings_service_get_connection_by_path (NMSettingsService *self,
const char *path);
void nm_settings_service_export (NMSettingsService *self);
void nm_settings_service_export_connection (NMSettingsService *self,
NMSettingsConnectionInterface *exported);
G_END_DECLS
#endif /* NM_SETTINGS_SERVICE_H */

View File

@@ -1,150 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2008 Red Hat, Inc.
*/
#include "nm-settings-interface.h"
#include "nm-settings-system-interface.h"
/**
* nm_settings_system_interface_save_hostname:
* @settings: a object implementing %NMSettingsSystemInterface
* @hostname: the new persistent hostname to set, or NULL to clear any existing
* persistent hostname
* @callback: callback to be called when the hostname operation completes
* @user_data: caller-specific data passed to @callback
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
*
* Returns: TRUE if the request was successful, FALSE if it failed
**/
gboolean
nm_settings_system_interface_save_hostname (NMSettingsSystemInterface *settings,
const char *hostname,
NMSettingsSystemSaveHostnameFunc callback,
gpointer user_data)
{
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_SYSTEM_INTERFACE (settings), FALSE);
g_return_val_if_fail (hostname != NULL, FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
if (NM_SETTINGS_SYSTEM_INTERFACE_GET_INTERFACE (settings)->save_hostname) {
return NM_SETTINGS_SYSTEM_INTERFACE_GET_INTERFACE (settings)->save_hostname (settings,
hostname,
callback,
user_data);
}
return FALSE;
}
/**
* nm_settings_system_interface_get_permissions:
* @settings: a object implementing %NMSettingsSystemInterface
* @callback: callback to be called when the permissions operation completes
* @user_data: caller-specific data passed to @callback
*
* Requests an indication of the operations the caller is permitted to perform
* including those that may require authorization.
*
* Returns: TRUE if the request was successful, FALSE if it failed
**/
gboolean
nm_settings_system_interface_get_permissions (NMSettingsSystemInterface *settings,
NMSettingsSystemGetPermissionsFunc callback,
gpointer user_data)
{
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_SYSTEM_INTERFACE (settings), FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
if (NM_SETTINGS_SYSTEM_INTERFACE_GET_INTERFACE (settings)->get_permissions)
return NM_SETTINGS_SYSTEM_INTERFACE_GET_INTERFACE (settings)->get_permissions (settings, callback, user_data);
return FALSE;
}
static void
nm_settings_system_interface_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Properties */
g_object_interface_install_property
(g_iface,
g_param_spec_string (NM_SETTINGS_SYSTEM_INTERFACE_HOSTNAME,
"Hostname",
"Persistent hostname",
NULL,
G_PARAM_READABLE));
g_object_interface_install_property
(g_iface,
g_param_spec_boolean (NM_SETTINGS_SYSTEM_INTERFACE_CAN_MODIFY,
"CanModify",
"Can modify anything (hostname, connections, etc)",
FALSE,
G_PARAM_READABLE));
/* Signals */
g_signal_new (NM_SETTINGS_SYSTEM_INTERFACE_CHECK_PERMISSIONS,
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSettingsSystemInterface, check_permissions),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
initialized = TRUE;
}
GType
nm_settings_system_interface_get_type (void)
{
static GType itype = 0;
if (!itype) {
const GTypeInfo iinfo = {
sizeof (NMSettingsSystemInterface), /* class_size */
nm_settings_system_interface_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
itype = g_type_register_static (G_TYPE_INTERFACE,
"NMSettingsSystemInterface",
&iinfo, 0);
g_type_interface_add_prerequisite (itype, NM_TYPE_SETTINGS_INTERFACE);
}
return itype;
}

View File

@@ -1,108 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2009 Red Hat, Inc.
*/
#ifndef NM_SETTINGS_SYSTEM_INTERFACE_H
#define NM_SETTINGS_SYSTEM_INTERFACE_H
#include <glib-object.h>
#include "NetworkManager.h"
G_BEGIN_DECLS
typedef enum {
NM_SETTINGS_SYSTEM_PERMISSION_NONE = 0x0,
NM_SETTINGS_SYSTEM_PERMISSION_CONNECTION_MODIFY = 0x1,
NM_SETTINGS_SYSTEM_PERMISSION_WIFI_SHARE_PROTECTED = 0x2,
NM_SETTINGS_SYSTEM_PERMISSION_WIFI_SHARE_OPEN = 0x4,
NM_SETTINGS_SYSTEM_PERMISSION_HOSTNAME_MODIFY = 0x8
} NMSettingsSystemPermissions;
#define NM_TYPE_SETTINGS_SYSTEM_INTERFACE (nm_settings_system_interface_get_type ())
#define NM_SETTINGS_SYSTEM_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS_SYSTEM_INTERFACE, NMSettingsSystemInterface))
#define NM_IS_SETTINGS_SYSTEM_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_SYSTEM_INTERFACE))
#define NM_SETTINGS_SYSTEM_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_SETTINGS_SYSTEM_INTERFACE, NMSettingsSystemInterface))
#define NM_SETTINGS_SYSTEM_INTERFACE_HOSTNAME "hostname"
#define NM_SETTINGS_SYSTEM_INTERFACE_CAN_MODIFY "can-modify"
#define NM_SETTINGS_SYSTEM_INTERFACE_CHECK_PERMISSIONS "check-permissions"
typedef enum {
NM_SETTINGS_SYSTEM_INTERFACE_PROP_FIRST = 0x1000,
NM_SETTINGS_SYSTEM_INTERFACE_PROP_HOSTNAME = NM_SETTINGS_SYSTEM_INTERFACE_PROP_FIRST,
NM_SETTINGS_SYSTEM_INTERFACE_PROP_CAN_MODIFY
} NMSettingsSystemInterfaceProp;
typedef struct _NMSettingsSystemInterface NMSettingsSystemInterface;
typedef void (*NMSettingsSystemSaveHostnameFunc) (NMSettingsSystemInterface *settings,
GError *error,
gpointer user_data);
typedef void (*NMSettingsSystemGetPermissionsFunc) (NMSettingsSystemInterface *settings,
NMSettingsSystemPermissions permissions,
GError *error,
gpointer user_data);
struct _NMSettingsSystemInterface {
GTypeInterface g_iface;
/* Methods */
gboolean (*save_hostname) (NMSettingsSystemInterface *settings,
const char *hostname,
NMSettingsSystemSaveHostnameFunc callback,
gpointer user_data);
gboolean (*get_permissions) (NMSettingsSystemInterface *settings,
NMSettingsSystemGetPermissionsFunc callback,
gpointer user_data);
/* Signals */
void (*check_permissions) (NMSettingsSystemInterface *settings);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
};
GType nm_settings_system_interface_get_type (void);
gboolean nm_settings_system_interface_save_hostname (NMSettingsSystemInterface *settings,
const char *hostname,
NMSettingsSystemSaveHostnameFunc callback,
gpointer user_data);
gboolean nm_settings_system_interface_get_permissions (NMSettingsSystemInterface *settings,
NMSettingsSystemGetPermissionsFunc callback,
gpointer user_data);
G_END_DECLS
#endif /* NM_SETTINGS_SYSTEM_INTERFACE_H */

View File

@@ -52,7 +52,7 @@ nm_ssid_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ssid"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMSsid"),
(GBoxedCopyFunc) nm_ssid_copy,
(GBoxedFreeFunc) nm_ssid_free);
return our_type;
@@ -105,7 +105,7 @@ nm_uint_array_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-uint-array"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMUintArray"),
(GBoxedCopyFunc) nm_uint_array_copy,
(GBoxedFreeFunc) nm_uint_array_free);
return our_type;
@@ -163,7 +163,7 @@ nm_string_array_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-string-array"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMStringArray"),
(GBoxedCopyFunc) nm_string_array_copy,
(GBoxedFreeFunc) nm_string_array_free);
return our_type;
@@ -224,7 +224,7 @@ nm_object_array_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-object-array"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMObjectArray"),
(GBoxedCopyFunc) nm_object_array_copy,
(GBoxedFreeFunc) nm_object_array_free);
return our_type;
@@ -306,7 +306,7 @@ nm_ip6_address_object_array_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ip6-address-object-array"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressObjectArray"),
(GBoxedCopyFunc) nm_ip6_address_object_array_copy,
(GBoxedFreeFunc) nm_ip6_address_object_array_free);
return our_type;
@@ -348,7 +348,7 @@ nm_ip6_address_array_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ip6-address-array"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressArray"),
(GBoxedCopyFunc) nm_ip6_address_array_copy,
(GBoxedFreeFunc) nm_ip6_address_array_free);
return our_type;
@@ -415,7 +415,7 @@ nm_ip6_route_object_array_get_type (void)
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ip6-route-object-array"),
our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6RouteObjectArray"),
(GBoxedCopyFunc) nm_ip6_route_object_array_copy,
(GBoxedFreeFunc) nm_ip6_route_object_array_free);
return our_type;

View File

@@ -0,0 +1,188 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "nm-vpn-plugin-utils.h"
#include "nm-setting-private.h"
#define DATA_KEY_TAG "DATA_KEY="
#define DATA_VAL_TAG "DATA_VAL="
#define SECRET_KEY_TAG "SECRET_KEY="
#define SECRET_VAL_TAG "SECRET_VAL="
static void
free_secret (gpointer data)
{
char *secret = data;
memset (secret, 0, strlen (secret));
g_free (secret);
}
/**
* nm_vpn_plugin_utils_read_vpn_details:
* @fd: file descriptor to read from, usually stdin (0)
* @out_data: (out) (transfer full): on successful return, a hash table
* (mapping char*:char*) containing the key/value pairs of VPN data items
* @out_secrets: (out) (transfer full): on successful return, a hash table
* (mapping char*:char*) containing the key/value pairsof VPN secrets
*
* Parses key/value pairs from a file descriptor (normally stdin) passed by
* an applet when the applet calls the authentication dialog of the VPN plugin.
*
* Returns: %TRUE if reading values was successful, %FALSE if not
**/
gboolean
nm_vpn_plugin_utils_read_vpn_details (int fd,
GHashTable **out_data,
GHashTable **out_secrets)
{
GHashTable *data, *secrets;
gboolean success = FALSE;
char *key = NULL, *val = NULL;
GString *line;
gchar c;
if (out_data)
g_return_val_if_fail (*out_data == NULL, FALSE);
if (out_secrets)
g_return_val_if_fail (*out_secrets == NULL, FALSE);
data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret);
line = g_string_new (NULL);
/* Read stdin for data and secret items until we get a DONE */
while (1) {
ssize_t nr;
GHashTable *hash = NULL;
errno = 0;
nr = read (fd, &c, 1);
if (nr == -1) {
if (errno == EAGAIN) {
g_usleep (100);
continue;
}
break;
}
if (c != '\n') {
g_string_append_c (line, c);
continue;
}
/* Check for the finish marker */
if (strcmp (line->str, "DONE") == 0)
break;
/* Otherwise it's a data/secret item */
if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) {
hash = data;
key = g_strdup (line->str + strlen (DATA_KEY_TAG));
} else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) {
hash = data;
val = g_strdup (line->str + strlen (DATA_VAL_TAG));
} else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) {
hash = secrets;
key = g_strdup (line->str + strlen (SECRET_KEY_TAG));
} else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) {
hash = secrets;
val = g_strdup (line->str + strlen (SECRET_VAL_TAG));
}
g_string_truncate (line, 0);
if (key && val && hash) {
g_hash_table_insert (hash, key, val);
key = NULL;
val = NULL;
success = TRUE; /* Got at least one value */
}
}
if (success) {
if (out_data)
*out_data = data;
else
g_hash_table_destroy (data);
if (out_secrets)
*out_secrets = secrets;
else
g_hash_table_destroy (secrets);
} else {
g_hash_table_destroy (data);
g_hash_table_destroy (secrets);
}
g_string_free (line, TRUE);
return success;
}
/**
* nm_vpn_plugin_utils_get_secret_flags:
* @data: hash table containing VPN key/value pair data items
* @secret_name: VPN secret key name for which to retrieve flags for
* @out_flags: (out): on success, the flags associated with @secret_name
*
* Given a VPN secret key name, attempts to find the corresponding flags data
* item in @data. If found, converts the flags data item to
* #NMSettingSecretFlags and returns it.
*
* Returns: %TRUE if the flag data item was found and successfully converted
* to flags, %FALSE if not
**/
gboolean
nm_vpn_plugin_utils_get_secret_flags (GHashTable *data,
const char *secret_name,
NMSettingSecretFlags *out_flags)
{
char *flag_name;
const char *val;
unsigned long tmp;
gboolean success = FALSE;
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (secret_name != NULL, FALSE);
g_return_val_if_fail (out_flags != NULL, FALSE);
g_return_val_if_fail (*out_flags == NM_SETTING_SECRET_FLAG_NONE, FALSE);
flag_name = g_strdup_printf ("%s-flags", secret_name);
/* Try new flags value first */
val = g_hash_table_lookup (data, flag_name);
if (val) {
errno = 0;
tmp = strtoul (val, NULL, 10);
if (errno == 0 && tmp <= NM_SETTING_SECRET_FLAGS_ALL) {
*out_flags = (NMSettingSecretFlags) tmp;
success = TRUE;
}
}
g_free (flag_name);
return success;
}

View File

@@ -0,0 +1,39 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#ifndef NM_VPN_PLUGIN_UTILS_H
#define NM_VPN_PLUGIN_UTILS_H
#include <glib.h>
#include <nm-setting.h>
G_BEGIN_DECLS
gboolean nm_vpn_plugin_utils_read_vpn_details (int fd,
GHashTable **out_data,
GHashTable **out_secrets);
gboolean nm_vpn_plugin_utils_get_secret_flags (GHashTable *data,
const char *secret_name,
NMSettingSecretFlags *out_flags);
G_END_DECLS
#endif /* NM_VPN_PLUGIN_UTILS_H */

View File

@@ -0,0 +1,35 @@
INCLUDES = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/libnm-util \
-I$(top_srcdir)/libnm-glib
noinst_PROGRAMS = test-remote-settings-client
####### remote settings client test #######
test_remote_settings_client_SOURCES = \
test-remote-settings-client.c
test_remote_settings_client_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS)
test_remote_settings_client_LDADD = \
$(top_builddir)/libnm-util/libnm-util.la \
$(top_builddir)/libnm-glib/libnm-glib-test.la \
$(GLIB_LIBS) \
$(DBUS_LIBS)
###########################################
TEST_RSS_BIN = test-remote-settings-service.py
EXTRA_DIST = $(TEST_RSS_BIN)
if WITH_TESTS
check-local: test-remote-settings-client
$(abs_builddir)/test-remote-settings-client $(abs_srcdir) $(TEST_RSS_BIN)
endif

View File

@@ -0,0 +1,406 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, 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.
*
* Copyright (C) 2010 - 2011 Red Hat, Inc.
*
*/
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <NetworkManager.h>
#include <nm-setting-connection.h>
#include <nm-setting-wired.h>
#include <nm-utils.h>
#include "nm-remote-settings.h"
static GPid spid = 0;
static NMRemoteSettings *settings = NULL;
DBusGConnection *bus = NULL;
NMRemoteConnection *remote = NULL;
/*******************************************************************/
static void
cleanup (void)
{
if (settings)
g_object_unref (settings);
kill (spid, SIGTERM);
}
#define test_assert(condition) \
do { \
if (!G_LIKELY (condition)) \
cleanup (); \
g_assert (condition); \
} while (0)
/*******************************************************************/
static void
add_cb (NMRemoteSettings *s,
NMRemoteConnection *connection,
GError *error,
gpointer user_data)
{
if (error)
g_warning ("Add error: %s", error->message);
*((gboolean *) user_data) = TRUE;
remote = connection;
}
#define TEST_CON_ID "blahblahblah"
static void
test_add_connection (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
char *uuid;
gboolean success;
time_t start, now;
gboolean done = FALSE;
connection = nm_connection_new ();
s_con = (NMSettingConnection *) nm_setting_connection_new ();
uuid = nm_utils_uuid_generate ();
g_object_set (G_OBJECT (s_con),
NM_SETTING_CONNECTION_ID, TEST_CON_ID,
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
NULL);
g_free (uuid);
nm_connection_add_setting (connection, NM_SETTING (s_con));
s_wired = (NMSettingWired *) nm_setting_wired_new ();
nm_connection_add_setting (connection, NM_SETTING (s_wired));
success = nm_remote_settings_add_connection (settings,
connection,
add_cb,
&done);
test_assert (success == TRUE);
start = time (NULL);
do {
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((done == FALSE) && (now - start < 5));
test_assert (done == TRUE);
test_assert (remote != NULL);
/* Make sure the connection is the same as what we added */
test_assert (nm_connection_compare (connection,
NM_CONNECTION (remote),
NM_SETTING_COMPARE_FLAG_EXACT) == TRUE);
}
/*******************************************************************/
static void
set_visible_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
GError *error = NULL;
gboolean success;
success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
if (!success)
g_warning ("Failed to change connection visibility: %s", error->message);
test_assert (success == TRUE);
test_assert (error == NULL);
}
static void
invis_removed_cb (NMRemoteConnection *connection, gboolean *done)
{
*done = TRUE;
}
static void
invis_has_settings_cb (NMSetting *setting,
const char *key,
const GValue *value,
GParamFlags flags,
gpointer user_data)
{
*((gboolean *) user_data) = TRUE;
}
static void
test_make_invisible (void)
{
time_t start, now;
GSList *list, *iter;
DBusGProxy *proxy;
gboolean done = FALSE, has_settings = FALSE;
char *path;
test_assert (remote != NULL);
/* Listen for the remove event when the connection becomes invisible */
g_signal_connect (remote, "removed", G_CALLBACK (invis_removed_cb), &done);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE,
path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
test_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL,
G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID);
/* Wait for the connection to be removed */
start = time (NULL);
do {
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((done == FALSE) && (now - start < 5));
test_assert (done == TRUE);
/* Ensure NMRemoteSettings no longer has the connection */
list = nm_remote_settings_list_connections (settings);
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
test_assert ((gpointer) remote != (gpointer) candidate);
test_assert (strcmp (path, nm_connection_get_path (candidate)) != 0);
}
/* And ensure the invisible connection no longer has any settings */
nm_connection_for_each_setting_value (NM_CONNECTION (remote),
invis_has_settings_cb,
&has_settings);
test_assert (has_settings == FALSE);
g_free (path);
g_object_unref (proxy);
}
/*******************************************************************/
static void
vis_new_connection_cb (NMRemoteSettings *foo,
NMRemoteConnection *connection,
NMRemoteConnection **new)
{
*new = connection;
}
static void
test_make_visible (void)
{
time_t start, now;
GSList *list, *iter;
DBusGProxy *proxy;
gboolean found = FALSE;
char *path;
NMRemoteConnection *new = NULL;
test_assert (remote != NULL);
/* Wait for the new-connection signal when the connection is visible again */
g_signal_connect (settings, NM_REMOTE_SETTINGS_NEW_CONNECTION,
G_CALLBACK (vis_new_connection_cb), &new);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE,
path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
test_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL,
G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID);
/* Wait for the settings service to announce the connection again */
start = time (NULL);
do {
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((new == NULL) && (now - start < 5));
/* Ensure the new connection is the same as the one we made visible again */
test_assert (new == remote);
/* Ensure NMRemoteSettings has the connection */
list = nm_remote_settings_list_connections (settings);
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
if ((gpointer) remote == (gpointer) candidate) {
test_assert (strcmp (path, nm_connection_get_path (candidate)) == 0);
test_assert (strcmp (TEST_CON_ID, nm_connection_get_id (candidate)) == 0);
found = TRUE;
break;
}
}
test_assert (found == TRUE);
g_free (path);
g_object_unref (proxy);
}
/*******************************************************************/
static void
deleted_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
GError *error = NULL;
gboolean success;
success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
if (!success)
g_warning ("Failed to delete connection: %s", error->message);
test_assert (success == TRUE);
test_assert (error == NULL);
}
static void
removed_cb (NMRemoteConnection *connection, gboolean *done)
{
*done = TRUE;
}
static void
test_remove_connection (void)
{
NMRemoteConnection *connection;
time_t start, now;
GSList *list, *iter;
DBusGProxy *proxy;
gboolean done = FALSE;
char *path;
/* Find a connection to delete */
list = nm_remote_settings_list_connections (settings);
test_assert (g_slist_length (list) > 0);
connection = NM_REMOTE_CONNECTION (list->data);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
g_signal_connect (connection, "removed", G_CALLBACK (removed_cb), &done);
proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE,
path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
test_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "Delete", deleted_cb, NULL, NULL, G_TYPE_INVALID);
start = time (NULL);
do {
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((done == FALSE) && (now - start < 5));
test_assert (done == TRUE);
/* Ensure NMRemoteSettings no longer has the connection */
list = nm_remote_settings_list_connections (settings);
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
test_assert ((gpointer) connection != (gpointer) candidate);
test_assert (strcmp (path, nm_connection_get_path (candidate)) != 0);
}
g_free (path);
g_object_unref (proxy);
}
/*******************************************************************/
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
{
GTestSuite *suite;
char *service_argv[3] = { NULL, NULL, NULL };
int ret;
GError *error = NULL;
int i = 100;
g_assert (argc == 3);
g_type_init ();
g_test_init (&argc, &argv, NULL);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus) {
g_warning ("Error connecting to D-Bus: %s", error->message);
g_assert (error == NULL);
}
service_argv[0] = g_strdup_printf ("%s/%s", argv[1], argv[2]);
if (!g_spawn_async (argv[1], service_argv, NULL, 0, NULL, NULL, &spid, &error)) {
g_warning ("Error spawning %s: %s", argv[2], error->message);
g_assert (error == NULL);
}
/* Wait until the service is registered on the bus */
while (i > 0) {
g_usleep (G_USEC_PER_SEC / 50);
if (dbus_bus_name_has_owner (dbus_g_connection_get_connection (bus),
"org.freedesktop.NetworkManager",
NULL))
break;
i--;
}
test_assert (i > 0);
settings = nm_remote_settings_new (bus);
test_assert (settings != NULL);
suite = g_test_get_root ();
g_test_suite_add (suite, TESTCASE (test_add_connection, NULL));
g_test_suite_add (suite, TESTCASE (test_make_invisible, NULL));
g_test_suite_add (suite, TESTCASE (test_make_visible, NULL));
g_test_suite_add (suite, TESTCASE (test_remove_connection, NULL));
ret = g_test_run ();
cleanup ();
return ret;
}

View File

@@ -0,0 +1,131 @@
#!/bin/env python
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
import glib
import gobject
import sys
import dbus
import dbus.service
import dbus.mainloop.glib
IFACE_SETTINGS = 'org.freedesktop.NetworkManager.Settings'
IFACE_CONNECTION = 'org.freedesktop.NetworkManager.Settings.Connection'
IFACE_DBUS = 'org.freedesktop.DBus'
class UnknownInterfaceException(dbus.DBusException):
_dbus_error_name = IFACE_DBUS + '.UnknownInterface'
class UnknownPropertyException(dbus.DBusException):
_dbus_error_name = IFACE_DBUS + '.UnknownProperty'
class PermissionDeniedException(dbus.DBusException):
_dbus_error_name = IFACE_SETTINGS + '.PermissionDenied'
mainloop = gobject.MainLoop()
class Connection(dbus.service.Object):
def __init__(self, bus, object_path, settings, remove_func):
dbus.service.Object.__init__(self, bus, object_path)
self.path = object_path
self.settings = settings
self.remove_func = remove_func
self.visible = True
@dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='', out_signature='a{sa{sv}}')
def GetSettings(self):
if not self.visible:
raise PermissionDeniedException()
return self.settings
@dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='b', out_signature='')
def SetVisible(self, vis):
self.visible = vis
self.Updated()
@dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='', out_signature='')
def Delete(self):
self.remove_func(self)
self.Removed()
@dbus.service.signal(IFACE_CONNECTION, signature='')
def Removed(self):
pass
@dbus.service.signal(IFACE_CONNECTION, signature='')
def Updated(self):
pass
class Settings(dbus.service.Object):
def __init__(self, bus, object_path):
dbus.service.Object.__init__(self, bus, object_path)
self.connections = {}
self.bus = bus
self.counter = 1
self.props = {}
self.props['Hostname'] = "foobar.baz"
self.props['CanModify'] = True
@dbus.service.method(dbus_interface=IFACE_SETTINGS, in_signature='', out_signature='ao')
def ListConnections(self):
connections = []
return self.connections.keys()
@dbus.service.method(dbus_interface=IFACE_SETTINGS, in_signature='a{sa{sv}}', out_signature='o')
def AddConnection(self, settings):
path = "/org/freedesktop/NetworkManager/Settings/Connection/%d" % self.counter
self.counter = self.counter + 1
self.connections[path] = Connection(self.bus, path, settings, self.delete_connection)
print "Added connection %s" % path
return path
def delete_connection(self, connection):
del self.connections[connection.path]
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
def GetAll(self, iface):
if iface != IFACE_SETTINGS:
raise UnknownInterfaceException()
return self.props
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
def Get(self, iface, name):
if iface != IFACE_SETTINGS:
raise UnknownInterfaceException()
if not name in self.props.keys():
raise UnknownPropertyException()
return self.props[name]
@dbus.service.signal(IFACE_SETTINGS, signature='o')
def NewConnection(self, path):
pass
@dbus.service.method(IFACE_SETTINGS, in_signature='', out_signature='')
def Quit(self):
mainloop.quit()
def quit_cb(user_data):
mainloop.quit()
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = Settings(bus, "/org/freedesktop/NetworkManager/Settings")
if not bus.request_name("org.freedesktop.NetworkManager"):
sys.exit(1)
print "Service started"
gobject.timeout_add_seconds(20, quit_cb, None)
try:
mainloop.run()
except Exception, e:
pass
print "Service stopped"
sys.exit(0)
if __name__ == '__main__':
main()

View File

@@ -31,12 +31,16 @@ libnm_util_include_HEADERS = \
nm-setting-vpn.h \
nm-utils.h
libnm_util_la_SOURCES= \
crypto.c \
libnm_util_la_private_headers = \
crypto.h \
nm-param-spec-specialized.h \
nm-utils-private.h \
nm-setting-private.h
libnm_util_la_csources = \
crypto.c \
nm-connection.c \
nm-param-spec-specialized.c \
nm-param-spec-specialized.h \
nm-setting.c \
nm-setting-8021x.c \
nm-setting-bluetooth.c \
@@ -54,14 +58,16 @@ libnm_util_la_SOURCES= \
nm-setting-wireless.c \
nm-setting-wireless-security.c \
nm-setting-vpn.c \
nm-utils.c \
nm-utils-private.h \
$(libnm_util_include_HEADERS)
nm-utils.c
libnm_util_la_SOURCES = \
$(libnm_util_la_csources) \
$(libnm_util_la_private_headers)
libnm_util_la_LIBADD = $(GLIB_LIBS) $(DBUS_LIBS) $(UUID_LIBS)
libnm_util_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnm-util.ver \
-version-info "7:0:6"
-version-info "8:0:7"
if WITH_GNUTLS
libnm_util_la_SOURCES += crypto_gnutls.c
@@ -104,12 +110,36 @@ libtest_crypto_la_CPPFLAGS += $(NSS_CFLAGS)
libtest_crypto_la_LIBADD += $(NSS_LIBS)
endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnm-util.pc
DISTCLEANFILES = libnm-util.pc
CLEANFILES =
EXTRA_DIST = libnm-util.pc.in libnm-util.ver
-include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_GIRS =
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir)
INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
if HAVE_INTROSPECTION
introspection_sources = $(libnm_util_include_HEADERS) $(libnm_util_la_csources) $(top_srcdir)/include/NetworkManager.h $(top_srcdir)/include/NetworkManagerVPN.h
NetworkManager-1.0.gir: libnm-util.la
NetworkManager_1_0_gir_INCLUDES = GObject-2.0 DBusGLib-1.0
NetworkManager_1_0_gir_PACKAGES = gobject-2.0 dbus-glib-1
NetworkManager_1_0_gir_CFLAGS = $(INCLUDES) -I$(top_srcdir)/libnm-util
NetworkManager_1_0_gir_LIBS = libnm-util.la
NetworkManager_1_0_gir_FILES = $(introspection_sources)
NetworkManager_1_0_gir_SCANNERFLAGS = --warn-all --identifier-prefix=NM --symbol-prefix=nm_
INTROSPECTION_GIRS += NetworkManager-1.0.gir
girdir = $(datadir)/gir-1.0
gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = $(libdir)/girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
CLEANFILES += $(gir_DATA) $(typelib_DATA)
endif

View File

@@ -9,10 +9,11 @@ global:
nm_connection_error_get_type;
nm_connection_error_quark;
nm_connection_for_each_setting_value;
nm_connection_get_id;
nm_connection_get_path;
nm_connection_get_scope;
nm_connection_get_setting;
nm_connection_get_setting_by_name;
nm_connection_get_uuid;
nm_connection_get_type;
nm_connection_lookup_setting_type;
nm_connection_lookup_setting_type_by_quark;
@@ -22,7 +23,6 @@ global:
nm_connection_remove_setting;
nm_connection_replace_settings;
nm_connection_set_path;
nm_connection_set_scope;
nm_connection_to_hash;
nm_connection_update_secrets;
nm_connection_verify;
@@ -48,6 +48,7 @@ global:
nm_setting_802_1x_get_identity;
nm_setting_802_1x_get_num_eap_methods;
nm_setting_802_1x_get_password;
nm_setting_802_1x_get_password_flags;
nm_setting_802_1x_get_phase1_fast_provisioning;
nm_setting_802_1x_get_phase1_peaplabel;
nm_setting_802_1x_get_phase1_peapver;
@@ -71,6 +72,7 @@ global:
nm_setting_802_1x_get_phase2_private_key_format;
nm_setting_802_1x_set_phase2_private_key_from_file;
nm_setting_802_1x_get_phase2_private_key_password;
nm_setting_802_1x_get_phase2_private_key_password_flags;
nm_setting_802_1x_get_phase2_private_key_path;
nm_setting_802_1x_get_phase2_private_key_scheme;
nm_setting_802_1x_get_phase2_private_key_type;
@@ -81,11 +83,11 @@ global:
nm_setting_802_1x_get_private_key_format;
nm_setting_802_1x_set_private_key_from_file;
nm_setting_802_1x_get_private_key_password;
nm_setting_802_1x_get_private_key_password_flags;
nm_setting_802_1x_get_private_key_path;
nm_setting_802_1x_get_private_key_scheme;
nm_setting_802_1x_get_private_key_type;
nm_setting_802_1x_set_private_key;
nm_setting_802_1x_get_psk;
nm_setting_802_1x_get_system_ca_certs;
nm_setting_802_1x_get_type;
nm_setting_802_1x_new;
@@ -103,8 +105,10 @@ global:
nm_setting_cdma_get_number;
nm_setting_cdma_get_username;
nm_setting_cdma_get_password;
nm_setting_cdma_get_password_flags;
nm_setting_clear_secrets;
nm_setting_compare;
nm_setting_connection_add_permission;
nm_setting_connection_error_get_type;
nm_setting_connection_error_quark;
nm_setting_connection_get_type;
@@ -115,6 +119,10 @@ global:
nm_setting_connection_get_autoconnect;
nm_setting_connection_get_timestamp;
nm_setting_connection_get_read_only;
nm_setting_connection_get_num_permissions;
nm_setting_connection_get_permission;
nm_setting_connection_permissions_user_allowed;
nm_setting_connection_remove_permission;
nm_setting_duplicate;
nm_setting_enumerate_values;
nm_setting_error_get_type;
@@ -129,13 +137,13 @@ global:
nm_setting_gsm_get_number;
nm_setting_gsm_get_username;
nm_setting_gsm_get_password;
nm_setting_gsm_get_password_flags;
nm_setting_gsm_get_apn;
nm_setting_gsm_get_network_id;
nm_setting_gsm_get_network_type;
nm_setting_gsm_get_allowed_bands;
nm_setting_gsm_get_band;
nm_setting_gsm_get_pin;
nm_setting_gsm_get_puk;
nm_setting_gsm_get_pin_flags;
nm_setting_gsm_get_home_only;
nm_setting_ip4_config_error_get_type;
nm_setting_ip4_config_error_quark;
@@ -169,6 +177,7 @@ global:
nm_setting_ip4_config_get_dhcp_send_hostname;
nm_setting_ip4_config_get_never_default;
nm_setting_ip4_config_get_may_fail;
nm_ip6_address_get_type;
nm_ip6_address_new;
nm_ip6_address_dup;
nm_ip6_address_ref;
@@ -180,6 +189,7 @@ global:
nm_ip6_address_set_gateway;
nm_ip6_address_get_prefix;
nm_ip6_address_set_prefix;
nm_ip6_route_get_type;
nm_ip6_route_new;
nm_ip6_route_dup;
nm_ip6_route_ref;
@@ -252,6 +262,7 @@ global:
nm_setting_pppoe_get_service;
nm_setting_pppoe_get_username;
nm_setting_pppoe_get_password;
nm_setting_pppoe_get_password_flags;
nm_setting_serial_error_get_type;
nm_setting_serial_error_quark;
nm_setting_serial_get_type;
@@ -261,23 +272,25 @@ global:
nm_setting_serial_get_parity;
nm_setting_serial_get_stopbits;
nm_setting_serial_get_send_delay;
nm_setting_get_secret_flags;
nm_setting_set_secret_flags;
nm_setting_to_hash;
nm_setting_to_string;
nm_setting_update_secrets;
nm_setting_verify;
nm_setting_vpn_add_data_item;
nm_setting_vpn_add_secret;
nm_setting_vpn_error_get_type;
nm_setting_vpn_error_quark;
nm_setting_vpn_get_type;
nm_setting_vpn_new;
nm_setting_vpn_get_service_type;
nm_setting_vpn_get_user_name;
nm_setting_vpn_add_data_item;
nm_setting_vpn_foreach_data_item;
nm_setting_vpn_get_data_item;
nm_setting_vpn_remove_data_item;
nm_setting_vpn_add_secret;
nm_setting_vpn_foreach_secret;
nm_setting_vpn_get_data_item;
nm_setting_vpn_get_secret;
nm_setting_vpn_get_service_type;
nm_setting_vpn_get_type;
nm_setting_vpn_get_user_name;
nm_setting_vpn_new;
nm_setting_vpn_remove_data_item;
nm_setting_vpn_remove_secret;
nm_setting_wimax_error_get_type;
nm_setting_wimax_error_quark;
@@ -335,14 +348,17 @@ global:
nm_setting_wireless_security_get_key_mgmt;
nm_setting_wireless_security_get_leap_username;
nm_setting_wireless_security_get_leap_password;
nm_setting_wireless_security_get_leap_password_flags;
nm_setting_wireless_security_get_num_groups;
nm_setting_wireless_security_get_num_pairwise;
nm_setting_wireless_security_get_num_protos;
nm_setting_wireless_security_get_pairwise;
nm_setting_wireless_security_get_proto;
nm_setting_wireless_security_get_psk;
nm_setting_wireless_security_get_psk_flags;
nm_setting_wireless_security_get_type;
nm_setting_wireless_security_get_wep_key;
nm_setting_wireless_security_get_wep_key_flags;
nm_setting_wireless_security_get_wep_key_type;
nm_setting_wireless_security_get_wep_tx_keyidx;
nm_setting_wireless_security_new;
@@ -387,8 +403,9 @@ global:
nm_ip4_address_compare;
nm_ip4_address_dup;
nm_ip4_address_get_address;
nm_ip4_address_get_prefix;
nm_ip4_address_get_gateway;
nm_ip4_address_get_prefix;
nm_ip4_address_get_type;
nm_ip4_address_new;
nm_ip4_address_ref;
nm_ip4_address_set_address;
@@ -401,6 +418,7 @@ global:
nm_ip4_route_get_prefix;
nm_ip4_route_get_next_hop;
nm_ip4_route_get_metric;
nm_ip4_route_get_type;
nm_ip4_route_new;
nm_ip4_route_ref;
nm_ip4_route_unref;

View File

@@ -29,6 +29,7 @@
#include "nm-connection.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-8021x.h"
#include "nm-setting-bluetooth.h"
@@ -66,12 +67,6 @@
* parameters (MTU, SSID, APN, channel, rate, etc) and IP-level parameters
* (addresses, routes, addressing methods, etc).
*
* Most connections also have a %NMConnectionScope; a connection will be
* provided over D-Bus either by the user settings service
* (org.freedesktop.NetworkManagerUserSettings) running in an active user
* session, or by the system-wide system settings service
* (org.freedesktop.NetworkManagerSystemSettings) which provides connections
* for all users.
*/
/**
@@ -113,9 +108,6 @@ nm_connection_error_get_type (void)
typedef struct {
GHashTable *settings;
/* Type of the connection (system or user) */
NMConnectionScope scope;
/* D-Bus path of the connection, if any */
char *path;
} NMConnectionPrivate;
@@ -126,7 +118,6 @@ G_DEFINE_TYPE (NMConnection, nm_connection, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_SCOPE,
PROP_PATH,
LAST_PROP
@@ -234,9 +225,9 @@ register_default_settings (void)
1);
register_one_setting (NM_SETTING_BLUETOOTH_SETTING_NAME,
NM_TYPE_SETTING_BLUETOOTH,
NM_SETTING_BLUETOOTH_ERROR,
1);
NM_TYPE_SETTING_BLUETOOTH,
NM_SETTING_BLUETOOTH_ERROR,
1);
register_one_setting (NM_SETTING_WIMAX_SETTING_NAME,
NM_TYPE_SETTING_WIMAX,
@@ -359,7 +350,7 @@ nm_connection_lookup_setting_type_by_quark (GQuark error_quark)
*
* Create a new #NMSetting object of the desired type, given a setting name.
*
* Returns: the new setting object, or NULL if the setting name was unknown
* Returns: (transfer full): the new setting object, or NULL if the setting name was unknown
**/
NMSetting *
nm_connection_create_setting (const char *name)
@@ -393,7 +384,7 @@ parse_one_setting (gpointer key, gpointer value, gpointer user_data)
/**
* nm_connection_add_setting:
* @connection: a #NMConnection
* @setting: the #NMSetting to add to the connection object
* @setting: (transfer full): the #NMSetting to add to the connection object
*
* Adds a #NMSetting to the connection, replacing any previous #NMSetting of the
* same name which has previously been added to the #NMConnection. The
@@ -435,7 +426,7 @@ nm_connection_remove_setting (NMConnection *connection, GType setting_type)
* Gets the #NMSetting with the given #GType, if one has been previously added
* to the #NMConnection.
*
* Returns: the #NMSetting, or NULL if no setting of that type was previously
* Returns: (transfer none): the #NMSetting, or NULL if no setting of that type was previously
* added to the #NMConnection
**/
NMSetting *
@@ -456,7 +447,7 @@ nm_connection_get_setting (NMConnection *connection, GType setting_type)
* Gets the #NMSetting with the given name, if one has been previously added
* the the #NMConnection.
*
* Returns: the #NMSetting, or NULL if no setting with that name was previously
* Returns: (transfer none): the #NMSetting, or NULL if no setting with that name was previously
* added to the #NMConnection
**/
NMSetting *
@@ -472,10 +463,37 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name)
return type ? nm_connection_get_setting (connection, type) : NULL;
}
static gboolean
validate_permissions_type (GHashTable *hash, GError **error)
{
GHashTable *s_con;
GValue *permissions;
/* Ensure the connection::permissions item (if present) is the correct
* type, otherwise the g_object_set() will throw a warning and ignore the
* error, leaving us with no permissions.
*/
s_con = g_hash_table_lookup (hash, NM_SETTING_CONNECTION_SETTING_NAME);
if (s_con) {
permissions = g_hash_table_lookup (s_con, NM_SETTING_CONNECTION_PERMISSIONS);
if (permissions) {
if ( !G_VALUE_HOLDS (permissions, G_TYPE_STRV)
&& !G_VALUE_HOLDS (permissions, DBUS_TYPE_G_LIST_OF_STRING)) {
g_set_error_literal (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Wrong permissions property type; should be a list of strings.");
return FALSE;
}
}
}
return TRUE;
}
/**
* nm_connection_replace_settings:
* @connection: a #NMConnection
* @new_settings: a #GHashTable of settings
* @new_settings: (element-type utf8 GLib.HashTable): a #GHashTable of settings
* @error: location to store error, or %NULL
*
* Returns: %TRUE if the settings were valid and added to the connection, %FALSE
@@ -492,6 +510,9 @@ nm_connection_replace_settings (NMConnection *connection,
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
if (!validate_permissions_type (new_settings, error))
return FALSE;
g_hash_table_remove_all (NM_CONNECTION_GET_PRIVATE (connection)->settings);
g_hash_table_foreach (new_settings, parse_one_setting, connection);
@@ -630,7 +651,7 @@ nm_connection_verify (NMConnection *connection, GError **error)
* nm_connection_update_secrets:
* @connection: the #NMConnection
* @setting_name: the setting object name to which the secrets apply
* @secrets: a #GHashTable mapping string:#GValue of setting property names and
* @secrets: (element-type utf8 GObject.Value): a #GHashTable mapping string:#GValue of setting property names and
* secrets
* @error: location to store error, or %NULL
*
@@ -643,28 +664,39 @@ nm_connection_verify (NMConnection *connection, GError **error)
gboolean
nm_connection_update_secrets (NMConnection *connection,
const char *setting_name,
GHashTable *secrets,
GHashTable *all_secrets,
GError **error)
{
NMSetting *setting;
gboolean success;
GHashTable *setting_secrets;
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (setting_name != NULL, FALSE);
g_return_val_if_fail (secrets != NULL, FALSE);
g_return_val_if_fail (all_secrets != NULL, FALSE);
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
setting = nm_connection_get_setting (connection, nm_connection_lookup_setting_type (setting_name));
if (!setting) {
g_set_error (error, NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND,
"%s", setting_name);
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND,
setting_name);
return FALSE;
}
success = nm_setting_update_secrets (setting, secrets, error);
setting_secrets = g_hash_table_lookup (all_secrets, setting_name);
if (!setting_secrets) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND,
setting_name);
return FALSE;
}
success = nm_setting_update_secrets (setting, setting_secrets, error);
if (success)
g_signal_emit (connection, signals[SECRETS_UPDATED], 0, setting_name);
return success;
@@ -777,26 +809,10 @@ nm_connection_clear_secrets (NMConnection *connection)
g_hash_table_foreach (priv->settings, clear_setting_secrets, NULL);
}
static void
add_one_setting_to_hash (gpointer key, gpointer data, gpointer user_data)
{
NMSetting *setting = (NMSetting *) data;
GHashTable *connection_hash = (GHashTable *) user_data;
GHashTable *setting_hash;
g_return_if_fail (setting != NULL);
g_return_if_fail (connection_hash != NULL);
setting_hash = nm_setting_to_hash (setting);
if (setting_hash)
g_hash_table_insert (connection_hash,
g_strdup (nm_setting_get_name (setting)),
setting_hash);
}
/**
* nm_connection_to_hash:
* @connection: the #NMConnection
* @flags: hash flags, e.g. %NM_SETTING_HASH_FLAG_ALL
*
* Converts the #NMConnection into a #GHashTable describing the connection,
* suitable for marshalling over D-Bus or serializing. The hash table mapping
@@ -805,50 +821,50 @@ add_one_setting_to_hash (gpointer key, gpointer data, gpointer user_data)
* are #GHashTables mapping string:GValue, each of which represents the
* properties of the #NMSetting object.
*
* Returns: a new #GHashTable describing the connection, its settings, and
* each setting's properties. The caller owns the hash table and must unref
* the hash table with g_hash_table_unref() when it is no longer needed.
* Returns: (transfer full) (element-type utf8 GLib.HashTable): a new
* #GHashTable describing the connection, its settings, and each setting's
* properties. The caller owns the hash table and must unref the hash table
* with g_hash_table_unref() when it is no longer needed.
**/
GHashTable *
nm_connection_to_hash (NMConnection *connection)
nm_connection_to_hash (NMConnection *connection, NMSettingHashFlags flags)
{
NMConnectionPrivate *priv;
GHashTable *connection_hash;
GHashTableIter iter;
gpointer key, data;
GHashTable *ret, *setting_hash;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
connection_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_hash_table_destroy);
ret = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_hash_table_destroy);
priv = NM_CONNECTION_GET_PRIVATE (connection);
g_hash_table_foreach (priv->settings, add_one_setting_to_hash, connection_hash);
/* Don't send empty hashes */
if (g_hash_table_size (connection_hash) < 1) {
g_hash_table_destroy (connection_hash);
connection_hash = NULL;
/* Add each setting's hash to the main hash */
g_hash_table_iter_init (&iter, priv->settings);
while (g_hash_table_iter_next (&iter, &key, &data)) {
NMSetting *setting = NM_SETTING (data);
setting_hash = nm_setting_to_hash (setting, flags);
if (setting_hash)
g_hash_table_insert (ret, g_strdup (nm_setting_get_name (setting)), setting_hash);
}
return connection_hash;
}
/* Don't send empty hashes */
if (g_hash_table_size (ret) < 1) {
g_hash_table_destroy (ret);
ret = NULL;
}
typedef struct ForEachValueInfo {
NMSettingValueIterFn func;
gpointer user_data;
} ForEachValueInfo;
static void
for_each_setting (gpointer key, gpointer value, gpointer user_data)
{
ForEachValueInfo *info = (ForEachValueInfo *) user_data;
nm_setting_enumerate_values (NM_SETTING (value), info->func, info->user_data);
return ret;
}
/**
* nm_connection_for_each_setting_value:
* @connection: the #NMConnection
* @func: user-supplied function called for each setting's property
* @func: (scope call): user-supplied function called for each setting's property
* @user_data: user data passed to @func at each invocation
*
* Iterates over the properties of each #NMSetting object in the #NMConnection,
@@ -859,25 +875,15 @@ nm_connection_for_each_setting_value (NMConnection *connection,
NMSettingValueIterFn func,
gpointer user_data)
{
NMConnectionPrivate *priv;
ForEachValueInfo *info;
GHashTableIter iter;
gpointer value;
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (func != NULL);
priv = NM_CONNECTION_GET_PRIVATE (connection);
info = g_slice_new0 (ForEachValueInfo);
if (!info) {
g_warning ("Not enough memory to enumerate values.");
return;
}
info->func = func;
info->user_data = user_data;
g_hash_table_foreach (priv->settings, for_each_setting, info);
g_slice_free (ForEachValueInfo, info);
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
while (g_hash_table_iter_next (&iter, NULL, &value))
nm_setting_enumerate_values (NM_SETTING (value), func, user_data);
}
static void
@@ -906,43 +912,6 @@ nm_connection_dump (NMConnection *connection)
g_hash_table_foreach (NM_CONNECTION_GET_PRIVATE (connection)->settings, dump_setting, NULL);
}
/**
* nm_connection_set_scope:
* @connection: the #NMConnection
* @scope: the scope of the connection
*
* Sets the scope of the connection. This property is not serialized, and is
* only for the reference of the caller. A connection may have no scope
* (internal, temporary connections), "system" scope (provided by the system
* settings service), or "user" scope, provided by a user settings service. The
* creator of the #NMConnection object is responsible for setting the
* connection's scope if needed. Sets the #NMConnection:scope property.
**/
void
nm_connection_set_scope (NMConnection *connection, NMConnectionScope scope)
{
g_return_if_fail (NM_IS_CONNECTION (connection));
NM_CONNECTION_GET_PRIVATE (connection)->scope = scope;
}
/**
* nm_connection_get_scope:
* @connection: the #NMConnection
*
* Returns the connection scope.
*
* Returns: the scope of the connection, previously set by a call to
* nm_connection_set_scope().
**/
NMConnectionScope
nm_connection_get_scope (NMConnection *connection)
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), NM_CONNECTION_SCOPE_UNKNOWN);
return NM_CONNECTION_GET_PRIVATE (connection)->scope;
}
/**
* nm_connection_set_path:
* @connection: the #NMConnection
@@ -1010,7 +979,8 @@ nm_connection_new (void)
/**
* nm_connection_new_from_hash:
* @hash: the #GHashTable describing the connection
* @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing
* the connection
* @error: on unsuccessful return, an error
*
* Creates a new #NMConnection from a hash table describing the connection. See
@@ -1027,6 +997,9 @@ nm_connection_new_from_hash (GHashTable *hash, GError **error)
g_return_val_if_fail (hash != NULL, NULL);
if (!validate_permissions_type (hash, error))
return FALSE;
connection = nm_connection_new ();
g_hash_table_foreach (hash, parse_one_setting, connection);
@@ -1050,7 +1023,7 @@ duplicate_cb (gpointer key, gpointer value, gpointer user_data)
*
* Duplicates a #NMConnection.
*
* Returns: a new #NMConnection containing the same settings and properties
* Returns: (transfer full): a new #NMConnection containing the same settings and properties
* as the source #NMConnection
**/
NMConnection *
@@ -1061,13 +1034,57 @@ nm_connection_duplicate (NMConnection *connection)
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
dup = nm_connection_new ();
nm_connection_set_scope (dup, nm_connection_get_scope (connection));
nm_connection_set_path (dup, nm_connection_get_path (connection));
g_hash_table_foreach (NM_CONNECTION_GET_PRIVATE (connection)->settings, duplicate_cb, dup);
return dup;
}
/**
* nm_connection_get_uuid:
* @connection: the #NMConnection
*
* A shortcut to return the UUID from the connections #NMSettingConnection.
*
* Returns: the UUID from the connection's 'connection' setting
**/
const char *
nm_connection_get_uuid (NMConnection *connection)
{
NMSettingConnection *s_con;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
g_return_val_if_fail (s_con != NULL, NULL);
return nm_setting_connection_get_uuid (s_con);
}
/**
* nm_connection_get_uuid:
* @connection: the #NMConnection
*
* A shortcut to return the UUID from the connections #NMSettingConnection.
*
* Returns: the UUID from the connection's 'connection' setting
**/
const char *nm_connection_get_id (NMConnection *connection)
{
NMSettingConnection *s_con;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
g_return_val_if_fail (s_con != NULL, NULL);
return nm_setting_connection_get_id (s_con);
}
/*************************************************************/
static void
nm_connection_init (NMConnection *connection)
{
@@ -1098,9 +1115,6 @@ set_property (GObject *object, guint prop_id,
NMConnection *connection = NM_CONNECTION (object);
switch (prop_id) {
case PROP_SCOPE:
nm_connection_set_scope (connection, g_value_get_uint (value));
break;
case PROP_PATH:
nm_connection_set_path (connection, g_value_get_string (value));
break;
@@ -1117,9 +1131,6 @@ get_property (GObject *object, guint prop_id,
NMConnection *connection = NM_CONNECTION (object);
switch (prop_id) {
case PROP_SCOPE:
g_value_set_uint (value, nm_connection_get_scope (connection));
break;
case PROP_PATH:
g_value_set_string (value, nm_connection_get_path (connection));
break;
@@ -1143,23 +1154,6 @@ nm_connection_class_init (NMConnectionClass *klass)
/* Properties */
/**
* NMConnection:scope:
*
* The connection's scope, used only by the calling process as a record
* of which settings service the connection is provided by. One of the
* NM_CONNECTION_SCOPE_* defines.
**/
g_object_class_install_property
(object_class, PROP_SCOPE,
g_param_spec_uint (NM_CONNECTION_SCOPE,
"Scope",
"Scope",
NM_CONNECTION_SCOPE_UNKNOWN,
NM_CONNECTION_SCOPE_USER,
NM_CONNECTION_SCOPE_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* NMConnection:path:
*

View File

@@ -39,23 +39,6 @@ G_BEGIN_DECLS
#define NM_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_CONNECTION))
#define NM_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONNECTION, NMConnectionClass))
/**
* NMConnectionScope:
* @NM_CONNECTION_SCOPE_UNKNOWN: scope not known or not yet set
* @NM_CONNECTION_SCOPE_SYSTEM: connection is provided by the system settings
* service
* @NM_CONNECTION_SCOPE_USER: connection is provided by a user settings service
*
* Connection scope indicated what settings service, if any, provides the
* connection.
*
**/
typedef enum {
NM_CONNECTION_SCOPE_UNKNOWN = 0,
NM_CONNECTION_SCOPE_SYSTEM,
NM_CONNECTION_SCOPE_USER
} NMConnectionScope;
/**
* NMConnectionError:
@@ -79,7 +62,6 @@ GType nm_connection_error_get_type (void);
#define NM_CONNECTION_ERROR nm_connection_error_quark ()
GQuark nm_connection_error_quark (void);
#define NM_CONNECTION_SCOPE "scope"
#define NM_CONNECTION_PATH "path"
/**
@@ -107,8 +89,10 @@ NMConnection *nm_connection_new_from_hash (GHashTable *hash, GError **error);
NMConnection *nm_connection_duplicate (NMConnection *connection);
NMSetting *nm_connection_create_setting (const char *name);
void nm_connection_add_setting (NMConnection *connection,
NMSetting *setting);
NMSetting *setting);
void nm_connection_remove_setting (NMConnection *connection,
GType setting_type);
@@ -117,7 +101,7 @@ NMSetting *nm_connection_get_setting (NMConnection *connection,
GType setting_type);
NMSetting *nm_connection_get_setting_by_name (NMConnection *connection,
const char *name);
const char *name);
gboolean nm_connection_replace_settings (NMConnection *connection,
GHashTable *new_settings,
@@ -139,28 +123,28 @@ gboolean nm_connection_update_secrets (NMConnection *connection,
GHashTable *secrets,
GError **error);
void nm_connection_set_scope (NMConnection *connection,
NMConnectionScope scope);
void nm_connection_set_path (NMConnection *connection,
const char *path);
NMConnectionScope nm_connection_get_scope (NMConnection *connection);
void nm_connection_set_path (NMConnection *connection,
const char *path);
const char * nm_connection_get_path (NMConnection *connection);
const char * nm_connection_get_path (NMConnection *connection);
void nm_connection_for_each_setting_value (NMConnection *connection,
NMSettingValueIterFn func,
gpointer user_data);
NMSettingValueIterFn func,
gpointer user_data);
GHashTable *nm_connection_to_hash (NMConnection *connection,
NMSettingHashFlags flags);
GHashTable *nm_connection_to_hash (NMConnection *connection);
void nm_connection_dump (NMConnection *connection);
NMSetting *nm_connection_create_setting (const char *name);
GType nm_connection_lookup_setting_type (const char *name);
GType nm_connection_lookup_setting_type (const char *name);
GType nm_connection_lookup_setting_type_by_quark (GQuark error_quark);
GType nm_connection_lookup_setting_type_by_quark (GQuark error_quark);
/* Helpers */
const char * nm_connection_get_uuid (NMConnection *connection);
const char * nm_connection_get_id (NMConnection *connection);
G_END_DECLS

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -32,6 +32,7 @@
#include "nm-dbus-glib-types.h"
#include "crypto.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-8021x
@@ -125,12 +126,15 @@ typedef struct {
char *phase2_ca_path;
GByteArray *phase2_client_cert;
char *password;
NMSettingSecretFlags password_flags;
char *pin;
char *psk;
NMSettingSecretFlags pin_flags;
GByteArray *private_key;
char *private_key_password;
NMSettingSecretFlags private_key_password_flags;
GByteArray *phase2_private_key;
char *phase2_private_key_password;
NMSettingSecretFlags phase2_private_key_password_flags;
gboolean system_ca_certs;
} NMSetting8021xPrivate;
@@ -151,12 +155,15 @@ enum {
PROP_PHASE2_CA_PATH,
PROP_PHASE2_CLIENT_CERT,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
PROP_PRIVATE_KEY,
PROP_PRIVATE_KEY_PASSWORD,
PROP_PRIVATE_KEY_PASSWORD_FLAGS,
PROP_PHASE2_PRIVATE_KEY,
PROP_PHASE2_PRIVATE_KEY_PASSWORD,
PROP_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS,
PROP_PIN,
PROP_PSK,
PROP_PIN_FLAGS,
PROP_SYSTEM_CA_CERTS,
LAST_PROP
@@ -423,29 +430,6 @@ nm_setting_802_1x_get_ca_cert_blob (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->ca_cert;
}
/**
* nm_setting_802_1x_get_ca_cert:
* @setting: the #NMSetting8021x
*
* Returns the CA certificate blob if the CA certificate is stored using the
* %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme. Not all EAP methods use a
* CA certificate (LEAP for example), and those that can take advantage of the
* CA certificate allow it to be unset. Note that lack of a CA certificate
* reduces security by allowing man-in-the-middle attacks, because the identity
* of the network cannot be confirmed by the client.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_ca_cert_blob().
*
* Returns: the CA certificate data
**/
const GByteArray *
nm_setting_802_1x_get_ca_cert (NMSetting8021x *setting)
{
return nm_setting_802_1x_get_ca_cert_blob (setting);
}
/**
* nm_setting_802_1x_get_ca_cert_path:
* @setting: the #NMSetting8021x
@@ -560,61 +544,6 @@ nm_setting_802_1x_set_ca_cert (NMSetting8021x *self,
return priv->ca_cert != NULL;
}
static NMSetting8021xCKType
ck_format_to_type (NMSetting8021xCKFormat format)
{
switch (format) {
case NM_SETTING_802_1X_CK_FORMAT_X509:
return NM_SETTING_802_1X_CK_TYPE_X509;
case NM_SETTING_802_1X_CK_FORMAT_RAW_KEY:
return NM_SETTING_802_1X_CK_TYPE_RAW_KEY;
case NM_SETTING_802_1X_CK_FORMAT_PKCS12:
return NM_SETTING_802_1X_CK_TYPE_PKCS12;
default:
break;
}
return NM_SETTING_802_1X_CK_TYPE_UNKNOWN;
}
/**
* nm_setting_802_1x_set_ca_cert_from_file:
* @setting: the #NMSetting8021x
* @filename: the path of the CA certificate file (PEM or DER format). Passing
* NULL clears the CA certificate.
* @out_ck_type: on successful return, the type of the certificate added
* @error: on unsuccessful return, an error
*
* Reads a certificate from disk and sets the #NMSetting8021x:ca-cert property
* with the raw certificate data using the %NM_SETTING_802_1X_CK_SCHEME_BLOB
* scheme.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_set_ca_cert() with the
* %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
nm_setting_802_1x_set_ca_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error)
{
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_ca_cert (setting,
filename,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
error);
if (success && out_ck_type)
*out_ck_type = ck_format_to_type (format);
return success;
}
/**
* nm_setting_802_1x_get_client_cert_scheme:
* @setting: the #NMSetting8021x
@@ -656,26 +585,6 @@ nm_setting_802_1x_get_client_cert_blob (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->client_cert;
}
/**
* nm_setting_802_1x_get_client_cert:
* @setting: the #NMSetting8021x
*
* Client certificates are used to identify the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_client_cert_blob().
*
* Returns: the client certificate data
**/
const GByteArray *
nm_setting_802_1x_get_client_cert (NMSetting8021x *setting)
{
return nm_setting_802_1x_get_client_cert_blob (setting);
}
/**
* nm_setting_802_1x_get_client_cert_path:
* @setting: the #NMSetting8021x
@@ -795,48 +704,6 @@ nm_setting_802_1x_set_client_cert (NMSetting8021x *self,
return priv->client_cert != NULL;
}
/**
* nm_setting_802_1x_set_client_cert_from_file:
* @setting: the #NMSetting8021x
* @filename: the path of the client certificate file (PEM, DER, or
* PKCS#12 format). Passing NULL clears the client certificate.
* @out_ck_type: on successful return, the type of the certificate added
* @error: on unsuccessful return, an error
*
* Reads a certificate from disk and sets the #NMSetting8021x:client-cert
* property with the raw certificate data.
*
* Client certificates are used to identify the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_set_client_cert() with the
* %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
nm_setting_802_1x_set_client_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error)
{
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_client_cert (setting,
filename,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
error);
if (success && out_ck_type)
*out_ck_type = ck_format_to_type (format);
return success;
}
/**
* nm_setting_802_1x_get_phase1_peapver:
* @setting: the #NMSetting8021x
@@ -982,28 +849,6 @@ nm_setting_802_1x_get_phase2_ca_cert_blob (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_ca_cert;
}
/**
* nm_setting_802_1x_get_phase2_ca_cert:
* @setting: the #NMSetting8021x
*
* Returns the "phase 2" CA certificate blob. Not all EAP methods use
* a CA certificate (LEAP for example), and those that can take advantage of the
* CA certificate allow it to be unset. Note that lack of a CA certificate
* reduces security by allowing man-in-the-middle attacks, because the identity
* of the network cannot be confirmed by the client.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_phase2_ca_cert_blob().
*
* Returns: the "phase 2" CA certificate data
**/
const GByteArray *
nm_setting_802_1x_get_phase2_ca_cert (NMSetting8021x *setting)
{
return nm_setting_802_1x_get_phase2_ca_cert_blob (setting);
}
/**
* nm_setting_802_1x_get_phase2_ca_cert_path:
* @setting: the #NMSetting8021x
@@ -1118,44 +963,6 @@ nm_setting_802_1x_set_phase2_ca_cert (NMSetting8021x *self,
return priv->phase2_ca_cert != NULL;
}
/**
* nm_setting_802_1x_set_phase2_ca_cert_from_file:
* @setting: the #NMSetting8021x
* @filename: the path of the "phase2" CA certificate file (PEM or DER format).
* Passing NULL with any @scheme clears the "phase2" CA certificate.
* @out_ck_type: on successful return, the type of the certificate added
* @error: on unsuccessful return, an error
*
* Reads a certificate from disk and sets the #NMSetting8021x:phase2-ca-cert
* property with the raw certificate data.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_set_phase2_ca_cert().
* with the %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
nm_setting_802_1x_set_phase2_ca_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error)
{
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_phase2_ca_cert (setting,
filename,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
error);
if (success && out_ck_type)
*out_ck_type = ck_format_to_type (format);
return success;
}
/**
* nm_setting_802_1x_get_phase2_client_cert_scheme:
* @setting: the #NMSetting8021x
@@ -1199,26 +1006,6 @@ nm_setting_802_1x_get_phase2_client_cert_blob (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_client_cert;
}
/**
* nm_setting_802_1x_get_phase2_client_cert:
* @setting: the #NMSetting8021x
*
* Client certificates are used to identify the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_phase2_client_cert_blob().
*
* Returns: the "phase 2" client certificate data
**/
const GByteArray *
nm_setting_802_1x_get_phase2_client_cert (NMSetting8021x *setting)
{
return nm_setting_802_1x_get_phase2_client_cert_blob (setting);
}
/**
* nm_setting_802_1x_get_phase2_client_cert_path:
* @setting: the #NMSetting8021x
@@ -1338,48 +1125,6 @@ nm_setting_802_1x_set_phase2_client_cert (NMSetting8021x *self,
return priv->phase2_client_cert != NULL;
}
/**
* nm_setting_802_1x_set_phase2_client_cert_from_file:
* @setting: the #NMSetting8021x
* @filename: pass the path of the "phase2" client certificate file (PEM, DER,
* or PKCS#12 format). Passing NULL clears the "phase2" client certificate.
* @out_ck_type: on successful return, the type of the certificate added
* @error: on unsuccessful return, an error
*
* Reads a certificate from disk and sets the #NMSetting8021x:phase2-client-cert
* property with the raw certificate data.
*
* Client certificates are used to identify the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_set_phase2_client_cert() with the.
* %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
nm_setting_802_1x_set_phase2_client_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error)
{
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_phase2_client_cert (setting,
filename,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
error);
if (success && out_ck_type)
*out_ck_type = ck_format_to_type (format);
return success;
}
/**
* nm_setting_802_1x_get_password:
* @setting: the #NMSetting8021x
@@ -1395,6 +1140,20 @@ nm_setting_802_1x_get_password (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_802_1x_get_password_flags:
* @setting: the #NMSetting8021x
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSetting8021x:password
**/
NMSettingSecretFlags
nm_setting_802_1x_get_password_flags (NMSetting8021x *setting)
{
g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_802_1X_GET_PRIVATE (setting)->password_flags;
}
/**
* nm_setting_802_1x_get_pin:
* @setting: the #NMSetting8021x
@@ -1411,18 +1170,18 @@ nm_setting_802_1x_get_pin (NMSetting8021x *setting)
}
/**
* nm_setting_802_1x_get_psk:
* nm_setting_802_1x_get_pin_flags:
* @setting: the #NMSetting8021x
*
* Returns: the Pre-Shared-Key used by the authentication method, if any, as
* specified by the #NMSetting8021x:psk property
* Returns: the #NMSettingSecretFlags pertaining to the
* #NMSetting8021x:pin
**/
const char *
nm_setting_802_1x_get_psk (NMSetting8021x *setting)
NMSettingSecretFlags
nm_setting_802_1x_get_pin_flags (NMSetting8021x *setting)
{
g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);
g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_802_1X_GET_PRIVATE (setting)->psk;
return NM_SETTING_802_1X_GET_PRIVATE (setting)->pin_flags;
}
/**
@@ -1453,6 +1212,10 @@ nm_setting_802_1x_get_private_key_scheme (NMSetting8021x *setting)
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* WARNING: the private key property is not a "secret" property, and thus
* unencrypted private key data may be readable by unprivileged users. Private
* keys should always be encrypted with a private key password.
*
* Returns: the private key data
**/
const GByteArray *
@@ -1468,26 +1231,6 @@ nm_setting_802_1x_get_private_key_blob (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->private_key;
}
/**
* nm_setting_802_1x_get_private_key:
* @setting: the #NMSetting8021x
*
* Private keys are used to authenticate the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_private_key_blob().
*
* Returns: the private key data
**/
const GByteArray *
nm_setting_802_1x_get_private_key (NMSetting8021x *setting)
{
return nm_setting_802_1x_get_private_key_blob (setting);
}
/**
* nm_setting_802_1x_get_private_key_path:
* @setting: the #NMSetting8021x
@@ -1533,6 +1276,11 @@ nm_setting_802_1x_get_private_key_path (NMSetting8021x *setting)
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* WARNING: the private key property is not a "secret" property, and thus
* unencrypted private key data using the BLOB scheme may be readable by
* unprivileged users. Private keys should always be encrypted with a private
* key password to prevent unauthorized access to unencrypted private key data.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
@@ -1659,51 +1407,6 @@ nm_setting_802_1x_set_private_key (NMSetting8021x *self,
return priv->private_key != NULL;
}
/**
* nm_setting_802_1x_set_private_key_from_file:
* @setting: the #NMSetting8021x
* @filename: the path of the private key file (PEM, DER, or PKCS#12 format).
* Passing NULL clears the private key.
* @password: password used to decrypt the private key
* @out_ck_type: on successful return, the type of the private key added
* @error: on unsuccessful return, an error
*
* Reads a private key from disk and sets the #NMSetting8021x:private-key
* property with the raw private key data.
*
* Private keys are used to authenticate the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_set_private_key() with.
* the %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
nm_setting_802_1x_set_private_key_from_file (NMSetting8021x *setting,
const char *filename,
const char *password,
NMSetting8021xCKType *out_ck_type,
GError **error)
{
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_private_key (setting,
filename,
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
error);
if (success && out_ck_type)
*out_ck_type = ck_format_to_type (format);
return success;
}
/**
* nm_setting_802_1x_get_private_key_password:
* @setting: the #NMSetting8021x
@@ -1721,6 +1424,21 @@ nm_setting_802_1x_get_private_key_password (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->private_key_password;
}
/**
* nm_setting_802_1x_get_private_key_password_flags:
* @setting: the #NMSetting8021x
*
* Returns: the #NMSettingSecretFlags pertaining to the
* #NMSetting8021x:private-key-password
**/
NMSettingSecretFlags
nm_setting_802_1x_get_private_key_password_flags (NMSetting8021x *setting)
{
g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_802_1X_GET_PRIVATE (setting)->private_key_password_flags;
}
/**
* nm_setting_802_1x_get_private_key_format:
* @setting: the #NMSetting8021x
@@ -1763,23 +1481,6 @@ nm_setting_802_1x_get_private_key_format (NMSetting8021x *setting)
return NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
}
/**
* nm_setting_802_1x_get_private_key_type:
* @setting: the #NMSetting8021x
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_private_key_format().
*
* Returns: the data format of the private key data stored in the
* #NMSetting8021x:private-key property
**/
NMSetting8021xCKType
nm_setting_802_1x_get_private_key_type (NMSetting8021x *setting)
{
return ck_format_to_type (nm_setting_802_1x_get_private_key_format (setting));
}
/**
* nm_setting_802_1x_get_phase2_private_key_password:
* @setting: the #NMSetting8021x
@@ -1797,6 +1498,21 @@ nm_setting_802_1x_get_phase2_private_key_password (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_private_key_password;
}
/**
* nm_setting_802_1x_get_phase2_private_key_password_flags:
* @setting: the #NMSetting8021x
*
* Returns: the #NMSettingSecretFlags pertaining to the
* #NMSetting8021x:phase2-private-key-password
**/
NMSettingSecretFlags
nm_setting_802_1x_get_phase2_private_key_password_flags (NMSetting8021x *setting)
{
g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_private_key_password_flags;
}
/**
* nm_setting_802_1x_get_phase2_private_key_scheme:
* @setting: the #NMSetting8021x
@@ -1825,6 +1541,10 @@ nm_setting_802_1x_get_phase2_private_key_scheme (NMSetting8021x *setting)
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* WARNING: the phase2 private key property is not a "secret" property, and thus
* unencrypted private key data may be readable by unprivileged users. Private
* keys should always be encrypted with a private key password.
*
* Returns: the "phase 2" private key data
**/
const GByteArray *
@@ -1840,26 +1560,6 @@ nm_setting_802_1x_get_phase2_private_key_blob (NMSetting8021x *setting)
return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_private_key;
}
/**
* nm_setting_802_1x_get_phase2_private_key:
* @setting: the #NMSetting8021x
*
* Private keys are used to authenticate the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_private_key_blob().
*
* Returns: the "phase 2" private key data
**/
const GByteArray *
nm_setting_802_1x_get_phase2_private_key (NMSetting8021x *setting)
{
return nm_setting_802_1x_get_phase2_private_key_blob (setting);
}
/**
* nm_setting_802_1x_get_phase2_private_key_path:
* @setting: the #NMSetting8021x
@@ -1905,6 +1605,11 @@ nm_setting_802_1x_get_phase2_private_key_path (NMSetting8021x *setting)
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* WARNING: the phase2 private key property is not a "secret" property, and thus
* unencrypted private key data using the BLOB scheme may be readable by
* unprivileged users. Private keys should always be encrypted with a private
* key password to prevent unauthorized access to unencrypted private key data.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
@@ -2031,51 +1736,6 @@ nm_setting_802_1x_set_phase2_private_key (NMSetting8021x *self,
return priv->phase2_private_key != NULL;
}
/**
* nm_setting_802_1x_set_phase2_private_key_from_file:
* @setting: the #NMSetting8021x
* @filename: the path of the "phase2" private key file (PEM, DER, or PKCS#12
* format). Passing NULL clears the "phase2" private key.
* @password: password used to decrypt the private key
* @out_ck_type: on successful return, the type of the private key added
* @error: on unsuccessful return, an error
*
* Reads a "phase 2" private key from disk and sets the
* #NMSetting8021x:phase2-private-key property with the raw private key data.
*
* Private keys are used to authenticate the connecting client to the network
* when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
* authentication method.
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_set_phase2_private_key() with
* the %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.
*
* Returns: TRUE if the operation succeeded, FALSE if it was unsuccessful
**/
gboolean
nm_setting_802_1x_set_phase2_private_key_from_file (NMSetting8021x *setting,
const char *filename,
const char *password,
NMSetting8021xCKType *out_ck_type,
GError **error)
{
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_phase2_private_key (setting,
filename,
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
error);
if (success && out_ck_type)
*out_ck_type = ck_format_to_type (format);
return success;
}
/**
* nm_setting_802_1x_get_phase2_private_key_format:
* @setting: the #NMSetting8021x
@@ -2118,23 +1778,6 @@ nm_setting_802_1x_get_phase2_private_key_format (NMSetting8021x *setting)
return NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
}
/**
* nm_setting_802_1x_get_phase2_private_key_type:
* @setting: the #NMSetting8021x
*
* Deprecated: 0.8: This function has been deprecated and should
* not be used in newly written code. Calling this function is
* equivalent to calling nm_setting_802_1x_get_phase2_private_key_format().
*
* Returns: the data format of the private key data stored in the
* #NMSetting8021x:phase2-private-key property
**/
NMSetting8021xCKType
nm_setting_802_1x_get_phase2_private_key_type (NMSetting8021x *setting)
{
return ck_format_to_type (nm_setting_802_1x_get_phase2_private_key_format (setting));
}
static void
need_secrets_password (NMSetting8021x *self,
GPtrArray *secrets,
@@ -2204,11 +1847,6 @@ need_secrets_tls (NMSetting8021x *self,
const char *path = NULL;
if (phase2) {
if (!priv->phase2_private_key || !priv->phase2_private_key->len) {
g_ptr_array_add (secrets, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY);
return;
}
scheme = nm_setting_802_1x_get_phase2_private_key_scheme (self);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
path = nm_setting_802_1x_get_phase2_private_key_path (self);
@@ -2223,11 +1861,6 @@ need_secrets_tls (NMSetting8021x *self,
if (need_private_key_password (blob, path, priv->phase2_private_key_password))
g_ptr_array_add (secrets, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD);
} else {
if (!priv->private_key || !priv->private_key->len) {
g_ptr_array_add (secrets, NM_SETTING_802_1X_PRIVATE_KEY);
return;
}
scheme = nm_setting_802_1x_get_private_key_scheme (self);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
path = nm_setting_802_1x_get_private_key_path (self);
@@ -2264,8 +1897,23 @@ verify_tls (NMSetting8021x *self, gboolean phase2, GError **error)
return FALSE;
}
/* Private key is required for TLS */
if (!priv->phase2_private_key) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY);
return FALSE;
} else if (!priv->phase2_private_key->len) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY);
return FALSE;
}
/* If the private key is PKCS#12, check that it matches the client cert */
if (priv->phase2_private_key && crypto_is_pkcs12_data (priv->phase2_private_key)) {
if (crypto_is_pkcs12_data (priv->phase2_private_key)) {
if (priv->phase2_private_key->len != priv->phase2_client_cert->len) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
@@ -2299,8 +1947,23 @@ verify_tls (NMSetting8021x *self, gboolean phase2, GError **error)
return FALSE;
}
/* Private key is required for TLS */
if (!priv->private_key) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_PRIVATE_KEY);
return FALSE;
} else if (!priv->private_key->len) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PRIVATE_KEY);
return FALSE;
}
/* If the private key is PKCS#12, check that it matches the client cert */
if (priv->private_key && crypto_is_pkcs12_data (priv->private_key)) {
if (crypto_is_pkcs12_data (priv->private_key)) {
if (priv->private_key->len != priv->client_cert->len) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
@@ -2817,6 +2480,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
case PROP_PRIVATE_KEY:
if (priv->private_key) {
g_byte_array_free (priv->private_key, TRUE);
@@ -2833,6 +2499,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->private_key_password);
priv->private_key_password = g_value_dup_string (value);
break;
case PROP_PRIVATE_KEY_PASSWORD_FLAGS:
priv->private_key_password_flags = g_value_get_uint (value);
break;
case PROP_PHASE2_PRIVATE_KEY:
if (priv->phase2_private_key) {
g_byte_array_free (priv->phase2_private_key, TRUE);
@@ -2849,6 +2518,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->phase2_private_key_password);
priv->phase2_private_key_password = g_value_dup_string (value);
break;
case PROP_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS:
priv->phase2_private_key_password_flags = g_value_get_uint (value);
break;
case PROP_SYSTEM_CA_CERTS:
priv->system_ca_certs = g_value_get_boolean (value);
break;
@@ -2911,18 +2583,27 @@ get_property (GObject *object, guint prop_id,
case PROP_PASSWORD:
g_value_set_string (value, priv->password);
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, priv->password_flags);
break;
case PROP_PRIVATE_KEY:
g_value_set_boxed (value, priv->private_key);
break;
case PROP_PRIVATE_KEY_PASSWORD:
g_value_set_string (value, priv->private_key_password);
break;
case PROP_PRIVATE_KEY_PASSWORD_FLAGS:
g_value_set_uint (value, priv->private_key_password_flags);
break;
case PROP_PHASE2_PRIVATE_KEY:
g_value_set_boxed (value, priv->phase2_private_key);
break;
case PROP_PHASE2_PRIVATE_KEY_PASSWORD:
g_value_set_string (value, priv->phase2_private_key_password);
break;
case PROP_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS:
g_value_set_uint (value, priv->phase2_private_key_password_flags);
break;
case PROP_SYSTEM_CA_CERTS:
g_value_set_boolean (value, priv->system_ca_certs);
break;
@@ -3285,12 +2966,32 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSetting8021x:password-flags:
*
* Flags indicating how to handle #NMSetting8021x:password:.
**/
g_object_class_install_property (object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_802_1X_PASSWORD_FLAGS,
"Password Flags",
"Flags indicating how to handle the 802.1x password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSetting8021x:private-key:
*
* Contains the private key if the #NMSetting8021x:eap property is set to
* 'tls'. Setting this property directly is discouraged; use the
* nm_setting_802_1x_set_private_key() function instead.
*
* WARNING: #NMSetting8021x:private-key is not a "secret" property, and thus
* unencrypted private key data using the BLOB scheme may be readable by
* unprivileged users. Private keys should always be encrypted with a
* private key password to prevent unauthorized access to unencrypted
* private key data.
**/
g_object_class_install_property
(object_class, PROP_PRIVATE_KEY,
@@ -3301,12 +3002,17 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
"'scheme'; two are currently supported: blob and "
"path. When using the blob scheme and X.509 private "
"keys, this property should be set to the keys's "
"decrypted DER encoded data. When using X.509 "
"private keys with the path scheme, this property "
"should be set to the full UTF-8 encoded path of "
"the key, prefixed with the string 'file://' and "
"and ending with a terminating NULL byte. When "
"using PKCS#12 format private keys and the blob "
"PEM or DER encoded data; if using DER-encoded "
"data the private key must be decrypted as the "
"DER format is incomplete. Use of decrypted "
"DER-format private keys is not recommended as it "
"may allow unprivileged users access to the "
"decrypted data. When using X.509 private keys "
"with the path scheme, this property should be "
"set to the full UTF-8 encoded path of the key, "
"prefixed with the string 'file://' and ending "
"with a terminating NULL byte. When using "
"PKCS#12 format private keys and the blob "
"scheme, this property should be set to the "
"PKCS#12 data (which is encrypted) and the "
"'private-key-password' property must be set to "
@@ -3320,7 +3026,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
"be set to the password used to decode the PKCS#12 "
"private key and certificate.",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSetting8021x:private-key-password:
@@ -3343,6 +3049,21 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSetting8021x:private-key-password-flags:
*
* Flags indicating how to handle #NMSetting8021x:private-key-password:.
**/
g_object_class_install_property (object_class, PROP_PRIVATE_KEY_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS,
"Private Key Password Flags",
"Flags indicating how to handle the 802.1x private "
"key password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSetting8021x:phase2-private-key:
*
@@ -3363,12 +3084,17 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
"'scheme'; two are currently supported: blob and "
"path. When using the blob scheme and X.509 private "
"keys, this property should be set to the keys's "
"decrypted DER encoded data. When using X.509 "
"private keys with the path scheme, this property "
"should be set to the full UTF-8 encoded path of "
"the key, prefixed with the string 'file://' and "
"and ending with a terminating NULL byte. When "
"using PKCS#12 format private keys and the blob "
"PEM or DER encoded data; if using DER-encoded "
"data the private key must be decrypted as the "
"DER format is incomplete. Use of decrypted "
"DER-format private keys is not recommended as it "
"may allow unprivileged users access to the "
"decrypted data. When using X.509 private keys "
"with the path scheme, this property should be "
"set to the full UTF-8 encoded path of the key, "
"prefixed with the string 'file://' and ending "
"with a terminating NULL byte. When using "
"PKCS#12 format private keys and the blob "
"scheme, this property should be set to the "
"PKCS#12 data (which is encrypted) and the "
"'private-key-password' property must be set to "
@@ -3382,7 +3108,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
"be set to the password used to decode the PKCS#12 "
"private key and certificate.",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSetting8021x:phase2-private-key-password:
@@ -3405,6 +3131,21 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSetting8021x:phase2-private-key-password-flags:
*
* Flags indicating how to handle #NMSetting8021x:phase2-private-key-password:.
**/
g_object_class_install_property (object_class, PROP_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS,
"Phase2 Private Key Password Flags",
"Flags indicating how to handle the 802.1x phase2 "
"private key password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSetting8021x:system-ca-certs:
*

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2009 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -81,12 +81,15 @@ GQuark nm_setting_802_1x_error_quark (void);
#define NM_SETTING_802_1X_PHASE2_CA_PATH "phase2-ca-path"
#define NM_SETTING_802_1X_PHASE2_CLIENT_CERT "phase2-client-cert"
#define NM_SETTING_802_1X_PASSWORD "password"
#define NM_SETTING_802_1X_PASSWORD_FLAGS "password-flags"
#define NM_SETTING_802_1X_PRIVATE_KEY "private-key"
#define NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD "private-key-password"
#define NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS "private-key-password-flags"
#define NM_SETTING_802_1X_PHASE2_PRIVATE_KEY "phase2-private-key"
#define NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD "phase2-private-key-password"
#define NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS "phase2-private-key-password-flags"
#define NM_SETTING_802_1X_PIN "pin"
#define NM_SETTING_802_1X_PSK "psk"
#define NM_SETTING_802_1X_PIN_FLAGS "pin-flags"
#define NM_SETTING_802_1X_SYSTEM_CA_CERTS "system-ca-certs"
/* PRIVATE KEY NOTE: when setting PKCS#12 private keys directly via properties
@@ -102,15 +105,17 @@ GQuark nm_setting_802_1x_error_quark (void);
*
* When setting OpenSSL-derived "traditional" format (ie S/MIME style, not
* PKCS#8) RSA and DSA keys directly via properties with the "blob" scheme, they
* must passed to NetworkManager completely decrypted because the OpenSSL
* "traditional" format is non-standard and is not complete enough for all
* crypto libraries to use. Thus, for OpenSSL "traditional" format keys, the
* private key password is not passed to NetworkManager (because the data is
* already decrypted by the client), and the appropriate "client-cert" (or
* "phase2-client-cert") property of the NMSetting8021x object must be a valid
* client certificate. When using the "path" scheme, just set the private-key
* and client-cert properties to the paths to their respective objects, and
* set the private-key password correctly.
* should be passed to NetworkManager in PEM format with the "DEK-Info" and
* "Proc-Type" tags intact, or in decrypted binary DER format (not recommended,
* as this may allow unprivileged users to read the decrypted private key).
* When decryped keys are used (again, not recommended) the private key password
* should not be set. The recommended method for passing private keys to
* NetworkManager is via the "path" scheme with encrypted private keys, and a
* private key password.
*
* When using the "path" scheme, just set the private-key and client-cert
* properties to the paths to their respective objects, and set the private-key
* password correctly.
*/
typedef struct {
@@ -192,10 +197,10 @@ gboolean nm_setting_802_1x_set_phase2_client_cert (NMSett
GError **error);
const char * nm_setting_802_1x_get_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_password_flags (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_pin (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_psk (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_pin_flags (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_private_key_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_private_key_blob (NMSetting8021x *setting);
@@ -207,6 +212,7 @@ gboolean nm_setting_802_1x_set_private_key (NMSett
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_private_key_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_private_key_password_flags (NMSetting8021x *setting);
NMSetting8021xCKFormat nm_setting_802_1x_get_private_key_format (NMSetting8021x *setting);
@@ -220,61 +226,11 @@ gboolean nm_setting_802_1x_set_phase2_private_key (NMSett
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_phase2_private_key_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_phase2_private_key_password_flags (NMSetting8021x *setting);
NMSetting8021xCKFormat nm_setting_802_1x_get_phase2_private_key_format (NMSetting8021x *setting);
/***** DEPRECATED; anything below will be removed in version 0.9 *****/
typedef enum {
NM_SETTING_802_1X_CK_TYPE_UNKNOWN = 0,
NM_SETTING_802_1X_CK_TYPE_X509,
NM_SETTING_802_1X_CK_TYPE_RAW_KEY,
NM_SETTING_802_1X_CK_TYPE_PKCS12
} NMSetting8021xCKType;
const GByteArray *nm_setting_802_1x_get_ca_cert (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_ca_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error);
const GByteArray *nm_setting_802_1x_get_client_cert (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_client_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error);
const GByteArray *nm_setting_802_1x_get_phase2_ca_cert (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_ca_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error);
const GByteArray *nm_setting_802_1x_get_phase2_client_cert (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_client_cert_from_file (NMSetting8021x *setting,
const char *filename,
NMSetting8021xCKType *out_ck_type,
GError **error);
const GByteArray *nm_setting_802_1x_get_private_key (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_private_key_from_file (NMSetting8021x *setting,
const char *filename,
const char *password,
NMSetting8021xCKType *out_ck_type,
GError **error);
NMSetting8021xCKType nm_setting_802_1x_get_private_key_type (NMSetting8021x *setting);
const GByteArray *nm_setting_802_1x_get_phase2_private_key (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_private_key_from_file (NMSetting8021x *setting,
const char *filename,
const char *password,
NMSetting8021xCKType *out_ck_type,
GError **error);
NMSetting8021xCKType nm_setting_802_1x_get_phase2_private_key_type (NMSetting8021x *setting);
G_END_DECLS
#endif /* NM_SETTING_8021X_H */

View File

@@ -18,13 +18,14 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
*/
#include <string.h>
#include "nm-setting-cdma.h"
#include "nm-setting-serial.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-cdma
@@ -87,6 +88,7 @@ typedef struct {
char *number; /* For dialing, duh */
char *username;
char *password;
NMSettingSecretFlags password_flags;
} NMSettingCdmaPrivate;
enum {
@@ -94,6 +96,7 @@ enum {
PROP_NUMBER,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
LAST_PROP
};
@@ -153,6 +156,20 @@ nm_setting_cdma_get_password (NMSettingCdma *setting)
return NM_SETTING_CDMA_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_cdma_get_password_flags:
* @setting: the #NMSettingCdma
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingCdma:password
**/
NMSettingSecretFlags
nm_setting_cdma_get_password_flags (NMSettingCdma *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_CDMA_GET_PRIVATE (setting)->password_flags;
}
static gint
find_setting_by_name (gconstpointer a, gconstpointer b)
{
@@ -220,8 +237,10 @@ need_secrets (NMSetting *setting)
return NULL;
if (priv->username) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_CDMA_PASSWORD);
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_CDMA_PASSWORD);
}
}
return secrets;
@@ -264,6 +283,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -286,6 +308,9 @@ get_property (GObject *object, guint prop_id,
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_cdma_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_cdma_get_password_flags (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -360,4 +385,18 @@ nm_setting_cdma_class_init (NMSettingCdmaClass *setting_class)
"a password or accept any password.",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingCdma:password-flags:
*
* Flags indicating how to handle #NMSettingCdma:password:.
**/
g_object_class_install_property (object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_CDMA_PASSWORD_FLAGS,
"Password Flags",
"Flags indicating how to handle the CDMA password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
}

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -53,9 +53,10 @@ GType nm_setting_cdma_error_get_type (void);
#define NM_SETTING_CDMA_ERROR nm_setting_cdma_error_quark ()
GQuark nm_setting_cdma_error_quark (void);
#define NM_SETTING_CDMA_NUMBER "number"
#define NM_SETTING_CDMA_USERNAME "username"
#define NM_SETTING_CDMA_PASSWORD "password"
#define NM_SETTING_CDMA_NUMBER "number"
#define NM_SETTING_CDMA_USERNAME "username"
#define NM_SETTING_CDMA_PASSWORD "password"
#define NM_SETTING_CDMA_PASSWORD_FLAGS "password-flags"
typedef struct {
NMSetting parent;
@@ -77,6 +78,7 @@ NMSetting *nm_setting_cdma_new (void);
const char *nm_setting_cdma_get_number (NMSettingCdma *setting);
const char *nm_setting_cdma_get_username (NMSettingCdma *setting);
const char *nm_setting_cdma_get_password (NMSettingCdma *setting);
NMSettingSecretFlags nm_setting_cdma_get_password_flags (NMSettingCdma *setting);
G_END_DECLS

View File

@@ -19,12 +19,15 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include <ctype.h>
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-param-spec-specialized.h"
#include "nm-setting-connection.h"
/**
@@ -81,10 +84,20 @@ G_DEFINE_TYPE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING)
#define NM_SETTING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionPrivate))
typedef enum {
PERM_TYPE_USER = 0,
} PermType;
typedef struct {
guint8 ptype;
char *item;
} Permission;
typedef struct {
char *id;
char *uuid;
char *type;
GSList *permissions; /* list of Permission structs */
gboolean autoconnect;
guint64 timestamp;
gboolean read_only;
@@ -95,6 +108,7 @@ enum {
PROP_ID,
PROP_UUID,
PROP_TYPE,
PROP_PERMISSIONS,
PROP_AUTOCONNECT,
PROP_TIMESTAMP,
PROP_READ_ONLY,
@@ -102,6 +116,86 @@ enum {
LAST_PROP
};
/***********************************************************************/
#define PERM_USER_PREFIX "user:"
static Permission *
permission_new_from_str (const char *str)
{
Permission *p;
const char *last_colon;
size_t ulen = 0, i;
g_return_val_if_fail (strncmp (str, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0, NULL);
str += strlen (PERM_USER_PREFIX);
last_colon = strrchr (str, ':');
if (last_colon) {
/* Ensure that somebody didn't pass "user::" */
g_return_val_if_fail (last_colon > str, NULL);
/* Make sure we don't include detail in the username */
ulen = last_colon - str;
} else
ulen = strlen (str);
/* Sanity check the length of the username */
g_return_val_if_fail (ulen < 100, NULL);
/* Make sure there's no ':' in the username */
for (i = 0; i < ulen; i++)
g_return_val_if_fail (str[i] != ':', NULL);
/* And the username must be valid UTF-8 */
g_return_val_if_fail (g_utf8_validate (str, -1, NULL) == TRUE, NULL);
/* Yay, valid... create the new permission */
p = g_slice_new0 (Permission);
p->ptype = PERM_TYPE_USER;
if (last_colon) {
p->item = g_malloc (ulen + 1);
memcpy (p->item, str, ulen);
p->item[ulen] = '\0';
} else
p->item = g_strdup (str);
return p;
}
static Permission *
permission_new (const char *uname)
{
Permission *p;
g_return_val_if_fail (uname, NULL);
g_return_val_if_fail (uname[0] != '\0', NULL);
g_return_val_if_fail (strchr (uname, ':') == NULL, NULL);
g_return_val_if_fail (g_utf8_validate (uname, -1, NULL) == TRUE, NULL);
/* Yay, valid... create the new permission */
p = g_slice_new0 (Permission);
p->ptype = PERM_TYPE_USER;
p->item = g_strdup (uname);
return p;
}
static char *
permission_to_string (Permission *p)
{
return g_strdup_printf (PERM_USER_PREFIX "%s:", p->item);
}
static void
permission_free (Permission *p)
{
g_free (p->item);
memset (p, 0, sizeof (*p));
g_slice_free (Permission, p);
}
/***********************************************************************/
/**
* nm_setting_connection_new:
*
@@ -162,6 +256,177 @@ nm_setting_connection_get_connection_type (NMSettingConnection *setting)
return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->type;
}
/**
* nm_setting_connection_get_num_permissions:
* @setting: the #NMSettingConnection
*
* Returns the number of entires in the #NMSettingConnection:permissions
* property of this setting.
*
* Returns: the number of permissions entires
*/
guint32
nm_setting_connection_get_num_permissions (NMSettingConnection *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
return g_slist_length (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->permissions);
}
/**
* nm_setting_connection_get_permission:
* @setting: the #NMSettingConnection
* @idx: the zero-based index of the permissions entry
* @out_ptype: on return, the permission type (at this time, always "user")
* @out_pitem: on return, the permission item (formatted accoring to @ptype, see
* #NMSettingConnection:permissions for more detail
* @out_detail: on return, the permission detail (at this time, always NULL)
*
* Retrieve one of the entries of the #NMSettingConnection:permissions property
* of this setting.
*
* Returns: %TRUE if a permission was returned, %FALSE if @idx was invalid
*/
gboolean
nm_setting_connection_get_permission (NMSettingConnection *setting,
guint32 idx,
const char **out_ptype,
const char **out_pitem,
const char **out_detail)
{
NMSettingConnectionPrivate *priv;
Permission *p;
g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
g_return_val_if_fail (idx < g_slist_length (priv->permissions), FALSE);
p = g_slist_nth_data (priv->permissions, idx);
if (out_ptype)
*out_ptype = "user";
if (out_pitem)
*out_pitem = p->item;
if (out_detail)
*out_detail = NULL;
return TRUE;
}
/**
* nm_setting_connection_permissions_user_allowed:
* @setting: the #NMSettingConnection
* @uname: the user name to check permissions for
*
* Checks whether the given username is allowed to view/access this connection.
*
* Returns: %TRUE if the requested user is allowed to view this connection,
* %FALSE if the given user is not allowed to view this connection
*/
gboolean
nm_setting_connection_permissions_user_allowed (NMSettingConnection *setting,
const char *uname)
{
NMSettingConnectionPrivate *priv;
GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
g_return_val_if_fail (uname != NULL, FALSE);
g_return_val_if_fail (*uname != '\0', FALSE);
priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
/* If no permissions, visible to all */
if (priv->permissions == NULL)
return TRUE;
/* Find the username in the permissions list */
for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
Permission *p = iter->data;
if (strcmp (uname, p->item) == 0)
return TRUE;
}
return FALSE;
}
/**
* nm_setting_connection_add_permission:
* @setting: the #NMSettingConnection
* @ptype: the permission type; at this time only "user" is supported
* @pitem: the permission item formatted as required for @ptype
* @detail: unused at this time; must be %NULL
*
* Adds a permission to the connection's permission list. At this time, only
* the "user" permission type is supported, and @pitem must be a username. See
* #NMSettingConnection:permissions: for more details.
*
* Returns: TRUE if the permission was unique and was successfully added to the
* list, FALSE if @ptype or @pitem was invalid or it the permission was already
* present in the list
*/
gboolean
nm_setting_connection_add_permission (NMSettingConnection *setting,
const char *ptype,
const char *pitem,
const char *detail)
{
NMSettingConnectionPrivate *priv;
Permission *p;
GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
g_return_val_if_fail (ptype, FALSE);
g_return_val_if_fail (strlen (ptype) > 0, FALSE);
g_return_val_if_fail (detail == NULL, FALSE);
/* Only "user" for now... */
g_return_val_if_fail (strcmp (ptype, "user") == 0, FALSE);
priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
/* No dupes */
for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
p = iter->data;
if (strcmp (pitem, p->item) == 0)
return FALSE;
}
p = permission_new (pitem);
g_return_val_if_fail (p != NULL, FALSE);
priv->permissions = g_slist_append (priv->permissions, p);
return TRUE;
}
/**
* nm_setting_connection_remove_permission:
* @setting: the #NMSettingConnection
* @idx: the zero-based index of the permission to remove
*
* Removes the permission at index @idx from the connection.
*/
void
nm_setting_connection_remove_permission (NMSettingConnection *setting,
guint32 idx)
{
NMSettingConnectionPrivate *priv;
GSList *iter;
g_return_if_fail (NM_IS_SETTING_CONNECTION (setting));
priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
iter = g_slist_nth (priv->permissions, idx);
g_return_if_fail (iter != NULL);
permission_free ((Permission *) iter->data);
priv->permissions = g_slist_delete_link (priv->permissions, iter);
}
/**
* nm_setting_connection_get_autoconnect:
* @setting: the #NMSettingConnection
@@ -308,13 +573,30 @@ finalize (GObject *object)
g_free (priv->id);
g_free (priv->uuid);
g_free (priv->type);
nm_utils_slist_free (priv->permissions, (GDestroyNotify) permission_free);
G_OBJECT_CLASS (nm_setting_connection_parent_class)->finalize (object);
}
static GSList *
perm_stringlist_to_permlist (GSList *strlist)
{
GSList *list = NULL, *iter;
for (iter = strlist; iter; iter = g_slist_next (iter)) {
Permission *p;
p = permission_new_from_str ((const char *) iter->data);
if (p)
list = g_slist_append (list, p);
}
return list;
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
const GValue *value, GParamSpec *pspec)
{
NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (object);
@@ -331,6 +613,10 @@ set_property (GObject *object, guint prop_id,
g_free (priv->type);
priv->type = g_value_dup_string (value);
break;
case PROP_PERMISSIONS:
nm_utils_slist_free (priv->permissions, (GDestroyNotify) permission_free);
priv->permissions = perm_stringlist_to_permlist (g_value_get_boxed (value));
break;
case PROP_AUTOCONNECT:
priv->autoconnect = g_value_get_boolean (value);
break;
@@ -346,11 +632,22 @@ set_property (GObject *object, guint prop_id,
}
}
static GSList *
perm_permlist_to_stringlist (GSList *permlist)
{
GSList *list = NULL, *iter;
for (iter = permlist; iter; iter = g_slist_next (iter))
list = g_slist_append (list, permission_to_string ((Permission *) iter->data));
return list;
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
GValue *value, GParamSpec *pspec)
{
NMSettingConnection *setting = NM_SETTING_CONNECTION (object);
NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_ID:
@@ -362,6 +659,9 @@ get_property (GObject *object, guint prop_id,
case PROP_TYPE:
g_value_set_string (value, nm_setting_connection_get_connection_type (setting));
break;
case PROP_PERMISSIONS:
g_value_take_boxed (value, perm_permlist_to_stringlist (priv->permissions));
break;
case PROP_AUTOCONNECT:
g_value_set_boolean (value, nm_setting_connection_get_autoconnect (setting));
break;
@@ -464,6 +764,45 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingConnection:permissions:
*
* An array of strings defining what access a given user has to this
* connection. If this is NULL or empty, all users are allowed to access
* this connection. Otherwise a user is allowed to access this connection
* if and only if they are in this list. Each entry is of the form
* "[type]:[id]:[reserved]", for example:
*
* user:dcbw:blah
*
* At this time only the 'user' [type] is allowed. Any other values are
* ignored and reserved for future use. [id] is the username that this
* permission refers to, which may not contain the ':' character. Any
* [reserved] information present must be ignored and is reserved for
* future use. All of [type], [id], and [reserved] must be valid UTF-8.
*/
g_object_class_install_property
(object_class, PROP_PERMISSIONS,
_nm_param_spec_specialized (NM_SETTING_CONNECTION_PERMISSIONS,
"Permissions",
"An array of strings defining what access a given "
"user has to this connection. If this is NULL or "
"empty, all users are allowed to access this "
"connection. Otherwise a user is allowed to access "
"this connection if and only if they are in this "
"array. Each entry is of the form "
"\"[type]:[id]:[reserved]\", for example: "
"\"user:dcbw:blah\" At this time only the 'user' "
"[type] is allowed. Any other values are ignored and "
"reserved for future use. [id] is the username that "
"this permission refers to, which may not contain the "
"':' character. Any [reserved] information (if "
"present) must be ignored and is reserved for future "
"use. All of [type], [id], and [reserved] must be "
"valid UTF-8.",
DBUS_TYPE_G_LIST_OF_STRING,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingConnection:autoconnect:
*

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2010 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -74,6 +74,7 @@ GQuark nm_setting_connection_error_quark (void);
#define NM_SETTING_CONNECTION_AUTOCONNECT "autoconnect"
#define NM_SETTING_CONNECTION_TIMESTAMP "timestamp"
#define NM_SETTING_CONNECTION_READ_ONLY "read-only"
#define NM_SETTING_CONNECTION_PERMISSIONS "permissions"
/**
* NMSettingConnection:
@@ -97,13 +98,27 @@ typedef struct {
GType nm_setting_connection_get_type (void);
NMSetting * nm_setting_connection_new (void);
const char *nm_setting_connection_get_id (NMSettingConnection *setting);
const char *nm_setting_connection_get_uuid (NMSettingConnection *setting);
const char *nm_setting_connection_get_connection_type (NMSettingConnection *setting);
gboolean nm_setting_connection_get_autoconnect (NMSettingConnection *setting);
guint64 nm_setting_connection_get_timestamp (NMSettingConnection *setting);
gboolean nm_setting_connection_get_read_only (NMSettingConnection *setting);
NMSetting * nm_setting_connection_new (void);
const char *nm_setting_connection_get_id (NMSettingConnection *setting);
const char *nm_setting_connection_get_uuid (NMSettingConnection *setting);
const char *nm_setting_connection_get_connection_type (NMSettingConnection *setting);
gboolean nm_setting_connection_get_autoconnect (NMSettingConnection *setting);
guint64 nm_setting_connection_get_timestamp (NMSettingConnection *setting);
gboolean nm_setting_connection_get_read_only (NMSettingConnection *setting);
guint32 nm_setting_connection_get_num_permissions (NMSettingConnection *setting);
gboolean nm_setting_connection_get_permission (NMSettingConnection *setting,
guint32 idx,
const char **out_ptype,
const char **out_pitem,
const char **out_detail);
gboolean nm_setting_connection_permissions_user_allowed (NMSettingConnection *setting, const char *uname);
gboolean nm_setting_connection_add_permission (NMSettingConnection *setting,
const char *ptype,
const char *pitem,
const char *detail);
void nm_setting_connection_remove_permission (NMSettingConnection *setting,
guint32 idx);
G_END_DECLS

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2010 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -28,6 +28,7 @@
#include "nm-setting-gsm.h"
#include "nm-setting-serial.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
GQuark
nm_setting_gsm_error_quark (void)
@@ -73,6 +74,7 @@ typedef struct {
char *number; /* For dialing, duh */
char *username;
char *password;
NMSettingSecretFlags password_flags;
char *apn; /* NULL for dynamic */
char *network_id; /* for manual registration or NULL for automatic */
@@ -80,6 +82,7 @@ typedef struct {
guint32 allowed_bands; /* A bitfield of NM_SETTING_GSM_BAND_* */
char *pin;
NMSettingSecretFlags pin_flags;
gboolean home_only;
} NMSettingGsmPrivate;
@@ -89,12 +92,12 @@ enum {
PROP_NUMBER,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
PROP_APN,
PROP_NETWORK_ID,
PROP_NETWORK_TYPE,
PROP_BAND,
PROP_PIN,
PROP_PUK,
PROP_PIN_FLAGS,
PROP_ALLOWED_BANDS,
PROP_HOME_ONLY,
@@ -140,6 +143,20 @@ nm_setting_gsm_get_password (NMSettingGsm *setting)
return NM_SETTING_GSM_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_gsm_get_password_flags:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingGsm:password
**/
NMSettingSecretFlags
nm_setting_gsm_get_password_flags (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_GSM_GET_PRIVATE (setting)->password_flags;
}
const char *
nm_setting_gsm_get_apn (NMSettingGsm *setting)
{
@@ -164,13 +181,6 @@ nm_setting_gsm_get_network_type (NMSettingGsm *setting)
return NM_SETTING_GSM_GET_PRIVATE (setting)->network_type;
}
int
nm_setting_gsm_get_band (NMSettingGsm *setting)
{
g_warning ("Tried to get deprecated property " NM_SETTING_GSM_SETTING_NAME "/" NM_SETTING_GSM_BAND);
return -1;
}
guint32
nm_setting_gsm_get_allowed_bands (NMSettingGsm *setting)
{
@@ -187,11 +197,18 @@ nm_setting_gsm_get_pin (NMSettingGsm *setting)
return NM_SETTING_GSM_GET_PRIVATE (setting)->pin;
}
const char *
nm_setting_gsm_get_puk (NMSettingGsm *setting)
/**
* nm_setting_gsm_get_pin_flags:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingGsm:pin
**/
NMSettingSecretFlags
nm_setting_gsm_get_pin_flags (NMSettingGsm *setting)
{
g_warning ("Tried to get deprecated property " NM_SETTING_GSM_SETTING_NAME "/" NM_SETTING_GSM_PUK);
return NULL;
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_GSM_GET_PRIVATE (setting)->pin_flags;
}
gboolean
@@ -310,8 +327,10 @@ need_secrets (NMSetting *setting)
return NULL;
if (priv->username) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_GSM_PASSWORD);
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_GSM_PASSWORD);
}
}
return secrets;
@@ -343,7 +362,6 @@ set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (object);
const char *str;
char *tmp;
switch (prop_id) {
@@ -359,6 +377,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
case PROP_APN:
g_free (priv->apn);
priv->apn = NULL;
@@ -376,10 +397,6 @@ set_property (GObject *object, guint prop_id,
case PROP_NETWORK_TYPE:
priv->network_type = g_value_get_int (value);
break;
case PROP_BAND:
if (g_value_get_int (value) != -1)
g_warning ("Tried to set deprecated property " NM_SETTING_GSM_SETTING_NAME "/" NM_SETTING_GSM_BAND);
break;
case PROP_ALLOWED_BANDS:
priv->allowed_bands = g_value_get_uint (value);
break;
@@ -387,10 +404,8 @@ set_property (GObject *object, guint prop_id,
g_free (priv->pin);
priv->pin = g_value_dup_string (value);
break;
case PROP_PUK:
str = g_value_get_string (value);
if (str && strlen (str))
g_warning ("Tried to set deprecated property " NM_SETTING_GSM_SETTING_NAME "/" NM_SETTING_GSM_PUK);
case PROP_PIN_FLAGS:
priv->pin_flags = g_value_get_uint (value);
break;
case PROP_HOME_ONLY:
priv->home_only = g_value_get_boolean (value);
@@ -417,6 +432,9 @@ get_property (GObject *object, guint prop_id,
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_gsm_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_gsm_get_password_flags (setting));
break;
case PROP_APN:
g_value_set_string (value, nm_setting_gsm_get_apn (setting));
break;
@@ -432,13 +450,8 @@ get_property (GObject *object, guint prop_id,
case PROP_PIN:
g_value_set_string (value, nm_setting_gsm_get_pin (setting));
break;
case PROP_PUK:
/* deprecated */
g_value_set_string (value, NULL);
break;
case PROP_BAND:
/* deprecated */
g_value_set_int (value, -1);
case PROP_PIN_FLAGS:
g_value_set_uint (value, nm_setting_gsm_get_pin_flags (setting));
break;
case PROP_HOME_ONLY:
g_value_set_boolean (value, nm_setting_gsm_get_home_only (setting));
@@ -520,6 +533,20 @@ nm_setting_gsm_class_init (NMSettingGsmClass *setting_class)
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingGsm:password-flags:
*
* Flags indicating how to handle #NMSettingGsm:password:.
**/
g_object_class_install_property (object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_GSM_PASSWORD_FLAGS,
"Password Flags",
"Flags indicating how to handle the GSM password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingGsm:apn:
*
@@ -639,6 +666,20 @@ nm_setting_gsm_class_init (NMSettingGsmClass *setting_class)
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingGsm:pin-flags:
*
* Flags indicating how to handle #NMSettingGsm:pin:.
**/
g_object_class_install_property (object_class, PROP_PIN_FLAGS,
g_param_spec_uint (NM_SETTING_GSM_PIN_FLAGS,
"PIN Flags",
"Flags indicating how to handle the GSM SIM PIN.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingGsm:home-only:
*
@@ -654,31 +695,4 @@ nm_setting_gsm_class_init (NMSettingGsmClass *setting_class)
"not be made.",
FALSE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/* Deprecated properties */
/**
* NMSettingGsm:puk:
*
* DEPRECATED
**/
g_object_class_install_property
(object_class, PROP_PUK,
g_param_spec_string (NM_SETTING_GSM_PUK,
"PUK (DEPRECATED and UNUSED)",
"PUK (DEPRECATED and UNUSED)",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingGsm:band:
*
* DEPRECATED
**/
g_object_class_install_property
(object_class, PROP_BAND,
g_param_spec_int (NM_SETTING_GSM_BAND,
"Band (DEPRECATED and UNUSED)",
"Band (DEPRECATED and UNUSED)",
-1, 5, -1,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
}

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2010 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -53,26 +53,17 @@ GType nm_setting_gsm_error_get_type (void);
#define NM_SETTING_GSM_ERROR nm_setting_gsm_error_quark ()
GQuark nm_setting_gsm_error_quark (void);
#define NM_SETTING_GSM_NUMBER "number"
#define NM_SETTING_GSM_USERNAME "username"
#define NM_SETTING_GSM_PASSWORD "password"
#define NM_SETTING_GSM_APN "apn"
#define NM_SETTING_GSM_NETWORK_ID "network-id"
#define NM_SETTING_GSM_NETWORK_TYPE "network-type"
#define NM_SETTING_GSM_ALLOWED_BANDS "allowed-bands"
#define NM_SETTING_GSM_PIN "pin"
#define NM_SETTING_GSM_HOME_ONLY "home-only"
/* DEPRECATED & UNUSED */
#define NM_SETTING_GSM_PUK "puk"
#define NM_SETTING_GSM_BAND "band"
/* DEPRECATED, use NM_SETTING_NETWORK_TYPE_* instead */
#define NM_GSM_NETWORK_ANY NM_SETTING_GSM_NETWORK_TYPE_ANY
#define NM_GSM_NETWORK_UMTS_HSPA NM_SETTING_GSM_NETWORK_TYPE_UMTS_HSPA
#define NM_GSM_NETWORK_GPRS_EDGE NM_SETTING_GSM_NETWORK_TYPE_GPRS_EDGE
#define NM_GSM_NETWORK_PREFER_UMTS_HSPA NM_SETTING_GSM_NETWORK_TYPE_PREFER_UMTS_HSPA
#define NM_GSM_NETWORK_PREFER_GPRS_EDGE NM_SETTING_GSM_NETWORK_TYPE_PREFER_GPRS_EDGE
#define NM_SETTING_GSM_NUMBER "number"
#define NM_SETTING_GSM_USERNAME "username"
#define NM_SETTING_GSM_PASSWORD "password"
#define NM_SETTING_GSM_PASSWORD_FLAGS "password-flags"
#define NM_SETTING_GSM_APN "apn"
#define NM_SETTING_GSM_NETWORK_ID "network-id"
#define NM_SETTING_GSM_NETWORK_TYPE "network-type"
#define NM_SETTING_GSM_ALLOWED_BANDS "allowed-bands"
#define NM_SETTING_GSM_PIN "pin"
#define NM_SETTING_GSM_PIN_FLAGS "pin-flags"
#define NM_SETTING_GSM_HOME_ONLY "home-only"
typedef enum {
NM_SETTING_GSM_NETWORK_TYPE_ANY = -1,
@@ -126,9 +117,8 @@ guint32 nm_setting_gsm_get_allowed_bands (NMSettingGsm *setting);
const char *nm_setting_gsm_get_pin (NMSettingGsm *setting);
gboolean nm_setting_gsm_get_home_only (NMSettingGsm *setting);
/* DEPRECATED & UNUSED */
const char *nm_setting_gsm_get_puk (NMSettingGsm *setting);
int nm_setting_gsm_get_band (NMSettingGsm *setting);
NMSettingSecretFlags nm_setting_gsm_get_pin_flags (NMSettingGsm *setting);
NMSettingSecretFlags nm_setting_gsm_get_password_flags (NMSettingGsm *setting);
G_END_DECLS

View File

@@ -66,6 +66,8 @@ nm_setting_ip4_config_error_get_type (void)
return etype;
}
G_DEFINE_BOXED_TYPE (NMIP4Address, nm_ip4_address, nm_ip4_address_dup, nm_ip4_address_unref)
G_DEFINE_BOXED_TYPE (NMIP4Route, nm_ip4_route, nm_ip4_route_dup, nm_ip4_route_unref)
G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING)

View File

@@ -74,6 +74,8 @@ GQuark nm_setting_ip4_config_error_quark (void);
typedef struct NMIP4Address NMIP4Address;
GType nm_ip4_address_get_type (void);
NMIP4Address * nm_ip4_address_new (void);
NMIP4Address * nm_ip4_address_dup (NMIP4Address *source);
void nm_ip4_address_ref (NMIP4Address *address);
@@ -95,6 +97,8 @@ void nm_ip4_address_set_gateway (NMIP4Address *address,
typedef struct NMIP4Route NMIP4Route;
GType nm_ip4_route_get_type (void);
NMIP4Route * nm_ip4_route_new (void);
NMIP4Route * nm_ip4_route_dup (NMIP4Route *route);
void nm_ip4_route_ref (NMIP4Route *route);

View File

@@ -65,6 +65,8 @@ nm_setting_ip6_config_error_get_type (void)
return etype;
}
G_DEFINE_BOXED_TYPE (NMIP6Address, nm_ip6_address, nm_ip6_address_dup, nm_ip6_address_unref)
G_DEFINE_BOXED_TYPE (NMIP6Route, nm_ip6_route, nm_ip6_route_dup, nm_ip6_route_unref)
G_DEFINE_TYPE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING)

View File

@@ -74,6 +74,8 @@ GQuark nm_setting_ip6_config_error_quark (void);
typedef struct NMIP6Address NMIP6Address;
GType nm_ip6_address_get_type (void);
NMIP6Address * nm_ip6_address_new (void);
NMIP6Address * nm_ip6_address_dup (NMIP6Address *source);
void nm_ip6_address_ref (NMIP6Address *address);
@@ -95,6 +97,8 @@ void nm_ip6_address_set_gateway (NMIP6Address *address,
typedef struct NMIP6Route NMIP6Route;
GType nm_ip6_route_get_type (void);
NMIP6Route * nm_ip6_route_new (void);
NMIP6Route * nm_ip6_route_dup (NMIP6Route *route);
void nm_ip6_route_ref (NMIP6Route *route);

View File

@@ -19,13 +19,14 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2010 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include "nm-setting-pppoe.h"
#include "nm-setting-ppp.h"
#include "nm-setting-private.h"
GQuark
nm_setting_pppoe_error_quark (void)
@@ -71,6 +72,7 @@ typedef struct {
char *service;
char *username;
char *password;
NMSettingSecretFlags password_flags;
} NMSettingPPPOEPrivate;
enum {
@@ -78,6 +80,7 @@ enum {
PROP_SERVICE,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
LAST_PROP
};
@@ -112,6 +115,20 @@ nm_setting_pppoe_get_password (NMSettingPPPOE *setting)
return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_pppoe_get_password_flags:
* @setting: the #NMSettingPPPOE
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingPPPOE:password
**/
NMSettingSecretFlags
nm_setting_pppoe_get_password_flags (NMSettingPPPOE *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password_flags;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
@@ -146,13 +163,15 @@ static GPtrArray *
need_secrets (NMSetting *setting)
{
NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
GPtrArray *secrets;
GPtrArray *secrets = NULL;
if (priv->password)
return NULL;
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_PPPOE_PASSWORD);
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_PPPOE_PASSWORD);
}
return secrets;
}
@@ -182,6 +201,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -204,6 +226,9 @@ get_property (GObject *object, guint prop_id,
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_pppoe_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_pppoe_get_password_flags (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -271,4 +296,18 @@ nm_setting_pppoe_class_init (NMSettingPPPOEClass *setting_class)
"Password used to authenticate with the PPPoE service.",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingPPPOE:password-flags:
*
* Flags indicating how to handle #NMSettingPPPOE:password:.
**/
g_object_class_install_property (object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_PPPOE_PASSWORD_FLAGS,
"Password Flags",
"Flags indicating how to handle the PPPoE password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
}

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -53,9 +53,10 @@ GType nm_setting_pppoe_error_get_type (void);
#define NM_SETTING_PPPOE_ERROR nm_setting_pppoe_error_quark ()
GQuark nm_setting_pppoe_error_quark (void);
#define NM_SETTING_PPPOE_SERVICE "service"
#define NM_SETTING_PPPOE_USERNAME "username"
#define NM_SETTING_PPPOE_PASSWORD "password"
#define NM_SETTING_PPPOE_SERVICE "service"
#define NM_SETTING_PPPOE_USERNAME "username"
#define NM_SETTING_PPPOE_PASSWORD "password"
#define NM_SETTING_PPPOE_PASSWORD_FLAGS "password-flags"
typedef struct {
NMSetting parent;
@@ -77,6 +78,7 @@ NMSetting *nm_setting_pppoe_new (void);
const char *nm_setting_pppoe_get_service (NMSettingPPPOE *setting);
const char *nm_setting_pppoe_get_username (NMSettingPPPOE *setting);
const char *nm_setting_pppoe_get_password (NMSettingPPPOE *setting);
NMSettingSecretFlags nm_setting_pppoe_get_password_flags (NMSettingPPPOE *setting);
G_END_DECLS

View File

@@ -0,0 +1,31 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2011 Red Hat, Inc.
*/
#ifndef NM_SETTING_PRIVATE_H
#define NM_SETTING_PRIVATE_H
#define NM_SETTING_SECRET_FLAGS_ALL \
(NM_SETTING_SECRET_FLAG_NONE | \
NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
NM_SETTING_SECRET_FLAG_NOT_SAVED | \
NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
#endif /* NM_SETTING_PRIVATE_H */

View File

@@ -18,16 +18,19 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include "nm-setting-vpn.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
GQuark
nm_setting_vpn_error_quark (void)
@@ -158,9 +161,17 @@ nm_setting_vpn_remove_data_item (NMSettingVPN *setting, const char *key)
g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
/**
* nm_setting_vpn_foreach_data_item:
* @setting: a #NMSettingVPN
* @func: (scope call): an user provided function
* @user_data:
*
* Iterates all data items stored in this setting
*/
void
nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
VPNIterFunc func,
NMVPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
@@ -200,9 +211,17 @@ nm_setting_vpn_remove_secret (NMSettingVPN *setting, const char *key)
g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
}
/**
* nm_setting_vpn_foreach_secret:
* @setting: a #NMSettingVPN
* @func: (scope call): an user provided function
* @user_data:
*
* Iterates all secrets stored in this setting.
*/
void
nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
VPNIterFunc func,
NMVPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
@@ -245,34 +264,158 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
static gboolean
update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error)
update_secret_string (NMSetting *setting,
const char *key,
const char *value,
GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
char *str;
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (!G_VALUE_HOLDS_STRING (value)) {
g_set_error (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"%s", key);
return FALSE;
}
str = g_value_dup_string (value);
if (!str || !strlen (str)) {
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Secret %s was empty", key);
g_free (str);
return FALSE;
}
g_hash_table_insert (priv->secrets, g_strdup (key), str);
g_hash_table_insert (priv->secrets, g_strdup (key), g_strdup (value));
return TRUE;
}
static gboolean
update_secret_hash (NMSetting *setting,
GHashTable *secrets,
GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
GHashTableIter iter;
const char *name, *value;
g_return_val_if_fail (secrets != NULL, FALSE);
/* Make sure the items are valid */
g_hash_table_iter_init (&iter, secrets);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) {
if (!name || !strlen (name)) {
g_set_error_literal (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Secret name was empty");
return FALSE;
}
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Secret %s value was empty", name);
return FALSE;
}
}
/* Now add the items to the settings' secrets list */
g_hash_table_iter_init (&iter, secrets);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) {
if (value == NULL) {
g_warn_if_fail (value != NULL);
continue;
}
if (strlen (value) == 0) {
g_warn_if_fail (strlen (value) > 0);
continue;
}
g_hash_table_insert (priv->secrets, g_strdup (name), g_strdup (value));
}
return TRUE;
}
static gboolean
update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error)
{
gboolean success = FALSE;
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (G_VALUE_HOLDS_STRING (value)) {
/* Passing the string properties individually isn't correct, and won't
* produce the correct result, but for some reason that's how it used
* to be done. So even though it's not correct, keep the code around
* for compatibility's sake.
*/
success = update_secret_string (setting, key, g_value_get_string (value), error);
} else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_STRING)) {
if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) {
g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_SECRET,
"Property %s not a secret property", key);
} else
success = update_secret_hash (setting, g_value_get_boxed (value), error);
} else
g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, key);
return success;
}
static gboolean
get_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags *out_flags,
GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
gboolean success = FALSE;
char *flags_key;
gpointer val;
unsigned long tmp;
flags_key = g_strdup_printf ("%s-flags", secret_name);
if (g_hash_table_lookup_extended (priv->data, flags_key, NULL, &val)) {
errno = 0;
tmp = strtoul ((const char *) val, NULL, 10);
if ((errno == 0) && (tmp <= NM_SETTING_SECRET_FLAGS_ALL)) {
*out_flags = (guint32) tmp;
success = TRUE;
} else {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Failed to convert '%s' value '%s' to uint",
flags_key, (const char *) val);
}
} else {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_NOT_FOUND,
"Secret flags property '%s' not found", flags_key);
}
g_free (flags_key);
return success;
}
static gboolean
set_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags flags,
GError **error)
{
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
g_strdup_printf ("%s-flags", secret_name),
g_strdup_printf ("%u", flags));
return TRUE;
}
static GPtrArray *
need_secrets (NMSetting *setting)
{
/* Assume that VPN connections need secrets since they almost always will */
return g_ptr_array_sized_new (1);
}
static void
destroy_one_secret (gpointer data)
{
@@ -309,6 +452,8 @@ finalize (GObject *object)
static void
copy_hash (gpointer key, gpointer value, gpointer user_data)
{
g_return_if_fail (value != NULL);
g_return_if_fail (strlen (value));
g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
}
@@ -386,8 +531,12 @@ nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->verify = verify;
parent_class->update_one_secret = update_one_secret;
parent_class->get_secret_flags = get_secret_flags;
parent_class->set_secret_flags = set_secret_flags;
parent_class->need_secrets = need_secrets;
/* Properties */
/**
@@ -395,7 +544,7 @@ nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
*
* D-Bus service name of the VPN plugin that this setting uses to connect
* to its network. i.e. org.freedesktop.NetworkManager.vpnc for the vpnc
* plugin.
* plugin.
**/
g_object_class_install_property
(object_class, PROP_SERVICE_TYPE,

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -71,7 +71,9 @@ typedef struct {
void (*_reserved4) (void);
} NMSettingVPNClass;
typedef void (*VPNIterFunc) (const char *key, const char *value, gpointer user_data);
typedef void (*NMVPNIterFunc) (const char *key, const char *value, gpointer user_data);
/* For backward compatibility */
typedef NMVPNIterFunc VPNIterFunc;
GType nm_setting_vpn_get_type (void);
@@ -87,7 +89,7 @@ const char * nm_setting_vpn_get_data_item (NMSettingVPN *setting,
void nm_setting_vpn_remove_data_item (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
VPNIterFunc func,
NMVPNIterFunc func,
gpointer user_data);
void nm_setting_vpn_add_secret (NMSettingVPN *setting,
@@ -98,7 +100,7 @@ const char * nm_setting_vpn_get_secret (NMSettingVPN *setting,
void nm_setting_vpn_remove_secret (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
VPNIterFunc func,
NMVPNIterFunc func,
gpointer user_data);
G_END_DECLS

View File

@@ -16,11 +16,14 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2011 Red Hat, Inc.
* (C) Copyright 2009 Novell, Inc.
*/
#include <string.h>
#include <net/ethernet.h>
#include <dbus/dbus-glib.h>
#include "nm-setting-wimax.h"
#include "nm-param-spec-specialized.h"
@@ -111,6 +114,15 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (!strlen (priv->network_name)) {
g_set_error (error,
NM_SETTING_WIMAX_ERROR,
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY,
NM_SETTING_WIMAX_NETWORK_NAME);
return FALSE;
}
if (priv->mac_address && priv->mac_address->len != ETH_ALEN) {
g_set_error (error,
NM_SETTING_WIMAX_ERROR,

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2010 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -33,6 +33,7 @@
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
GQuark
nm_setting_wireless_security_error_quark (void)
@@ -82,19 +83,28 @@ G_DEFINE_TYPE (NMSettingWirelessSecurity, nm_setting_wireless_security, NM_TYPE_
typedef struct {
char *key_mgmt;
guint32 wep_tx_keyidx;
char *auth_alg;
GSList *proto; /* GSList of strings */
GSList *pairwise; /* GSList of strings */
GSList *group; /* GSList of strings */
/* LEAP */
char *leap_username;
char *leap_password;
NMSettingSecretFlags leap_password_flags;
/* WEP */
char *wep_key0;
char *wep_key1;
char *wep_key2;
char *wep_key3;
char *psk;
char *leap_password;
NMSettingSecretFlags wep_key_flags;
NMWepKeyType wep_key_type;
guint32 wep_tx_keyidx;
/* WPA-PSK */
char *psk;
NMSettingSecretFlags psk_flags;
} NMSettingWirelessSecurityPrivate;
enum {
@@ -110,9 +120,12 @@ enum {
PROP_WEP_KEY1,
PROP_WEP_KEY2,
PROP_WEP_KEY3,
PROP_PSK,
PROP_LEAP_PASSWORD,
PROP_WEP_KEY_FLAGS,
PROP_WEP_KEY_TYPE,
PROP_PSK,
PROP_PSK_FLAGS,
PROP_LEAP_PASSWORD,
PROP_LEAP_PASSWORD_FLAGS,
LAST_PROP
};
@@ -343,6 +356,21 @@ nm_setting_wireless_security_get_psk (NMSettingWirelessSecurity *setting)
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->psk;
}
/**
* nm_setting_wireless_security_get_psk_flags:
* @setting: the #NMSettingWirelessSecurity
*
* Returns: the #NMSettingSecretFlags pertaining to the
* #NMSettingWirelessSecurity:psk
**/
NMSettingSecretFlags
nm_setting_wireless_security_get_psk_flags (NMSettingWirelessSecurity *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->psk_flags;
}
const char *
nm_setting_wireless_security_get_leap_username (NMSettingWirelessSecurity *setting)
{
@@ -359,6 +387,21 @@ nm_setting_wireless_security_get_leap_password (NMSettingWirelessSecurity *setti
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_password;
}
/**
* nm_setting_wireless_security_get_leap_password_flags:
* @setting: the #NMSettingWirelessSecurity
*
* Returns: the #NMSettingSecretFlags pertaining to the
* #NMSettingWirelessSecurity:leap-password
**/
NMSettingSecretFlags
nm_setting_wireless_security_get_leap_password_flags (NMSettingWirelessSecurity *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_password_flags;
}
const char *
nm_setting_wireless_security_get_wep_key (NMSettingWirelessSecurity *setting, guint32 idx)
{
@@ -428,6 +471,20 @@ nm_setting_wireless_security_get_auth_alg (NMSettingWirelessSecurity *setting)
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->auth_alg;
}
/**
* nm_setting_wireless_security_get_wep_key_flags:
* @setting: the #NMSettingWirelessSecurity
*
* Returns: the #NMSettingSecretFlags pertaining to the all WEP keys
**/
NMSettingSecretFlags
nm_setting_wireless_security_get_wep_key_flags (NMSettingWirelessSecurity *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->wep_key_flags;
}
NMWepKeyType
nm_setting_wireless_security_get_wep_key_type (NMSettingWirelessSecurity *setting)
{
@@ -771,6 +828,58 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return TRUE;
}
static gboolean
get_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags *out_flags,
GError **error)
{
NMSettingClass *setting_class;
gboolean verify_override = verify_secret;
/* There's only one 'flags' property for WEP keys, so alias all the WEP key
* property names to that flags property.
*/
if ( !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)
|| !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)
|| !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)
|| !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)) {
secret_name = "wep-key";
verify_override = FALSE; /* Already know it's a secret */
}
/* Chain up to superclass with modified key name */
setting_class = NM_SETTING_CLASS (nm_setting_wireless_security_parent_class);
return setting_class->get_secret_flags (setting, secret_name, verify_override, out_flags, error);
}
static gboolean
set_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags flags,
GError **error)
{
NMSettingClass *setting_class;
gboolean verify_override = verify_secret;
/* There's only one 'flags' property for WEP keys, so alias all the WEP key
* property names to that flags property.
*/
if ( !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)
|| !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)
|| !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)
|| !g_strcmp0 (secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)) {
secret_name = "wep-key";
verify_override = FALSE; /* Already know it's a secret */
}
/* Chain up to superclass with modified key name */
setting_class = NM_SETTING_CLASS (nm_setting_wireless_security_parent_class);
return setting_class->set_secret_flags (setting, secret_name, verify_override, flags, error);
}
static void
nm_setting_wireless_security_init (NMSettingWirelessSecurity *setting)
{
@@ -852,14 +961,23 @@ set_property (GObject *object, guint prop_id,
case PROP_WEP_KEY3:
nm_setting_wireless_security_set_wep_key (setting, 3, g_value_get_string (value));
break;
case PROP_WEP_KEY_FLAGS:
priv->wep_key_flags = g_value_get_uint (value);
break;
case PROP_PSK:
g_free (priv->psk);
priv->psk = g_value_dup_string (value);
break;
case PROP_PSK_FLAGS:
priv->psk_flags = g_value_get_uint (value);
break;
case PROP_LEAP_PASSWORD:
g_free (priv->leap_password);
priv->leap_password = g_value_dup_string (value);
break;
case PROP_LEAP_PASSWORD_FLAGS:
priv->leap_password_flags = g_value_get_uint (value);
break;
case PROP_WEP_KEY_TYPE:
priv->wep_key_type = g_value_get_uint (value);
break;
@@ -910,12 +1028,21 @@ get_property (GObject *object, guint prop_id,
case PROP_WEP_KEY3:
g_value_set_string (value, priv->wep_key3);
break;
case PROP_WEP_KEY_FLAGS:
g_value_set_uint (value, priv->wep_key_flags);
break;
case PROP_PSK:
g_value_set_string (value, priv->psk);
break;
case PROP_PSK_FLAGS:
g_value_set_uint (value, priv->psk_flags);
break;
case PROP_LEAP_PASSWORD:
g_value_set_string (value, priv->leap_password);
break;
case PROP_LEAP_PASSWORD_FLAGS:
g_value_set_uint (value, priv->leap_password_flags);
break;
case PROP_WEP_KEY_TYPE:
g_value_set_uint (value, priv->wep_key_type);
break;
@@ -938,8 +1065,10 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->need_secrets = need_secrets;
parent_class->verify = verify;
parent_class->need_secrets = need_secrets;
parent_class->get_secret_flags = get_secret_flags;
parent_class->set_secret_flags = set_secret_flags;
/* Properties */
/**
@@ -1139,6 +1268,20 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingWirelessSecurity:wep-key-flags:
*
* Flags indicating how to handle #NMSettingWirelessSecurity WEP keys.
**/
g_object_class_install_property (object_class, PROP_WEP_KEY_FLAGS,
g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS,
"WEP Key Flags",
"Flags indicating how to handle the WEP keys.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingWirelessSecurity:psk:
*
@@ -1164,6 +1307,20 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingWirelessSecurity:psk-flags:
*
* Flags indicating how to handle #NMSettingWirelessSecurity:psk
**/
g_object_class_install_property (object_class, PROP_PSK_FLAGS,
g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS,
"PSK Flags",
"Flags indicating how to handle the WPA PSK key.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingWirelessSecurity:leap-password:
*
@@ -1179,6 +1336,20 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/**
* NMSettingWirelessSecurity:leap-password-flags:
*
* Flags indicating how to handle #NMSettingWirelessSecurity:leap-password.
**/
g_object_class_install_property (object_class, PROP_LEAP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS,
"LEAP Password Flags",
"Flags indicating how to handle the LEAP password.",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingWirelessSecurity:wep-key-type:
*

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -75,9 +75,12 @@ typedef enum {
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 "wep-key1"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 "wep-key2"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 "wep-key3"
#define NM_SETTING_WIRELESS_SECURITY_PSK "psk"
#define NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD "leap-password"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS "wep-key-flags"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE "wep-key-type"
#define NM_SETTING_WIRELESS_SECURITY_PSK "psk"
#define NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS "psk-flags"
#define NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD "leap-password"
#define NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS "leap-password-flags"
typedef struct {
NMSetting parent;
@@ -118,14 +121,18 @@ void nm_setting_wireless_security_remove_group (NMSettingWirelessSec
void nm_setting_wireless_security_clear_groups (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_psk (NMSettingWirelessSecurity *setting);
NMSettingSecretFlags nm_setting_wireless_security_get_psk_flags (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_leap_username (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_leap_password (NMSettingWirelessSecurity *setting);
NMSettingSecretFlags nm_setting_wireless_security_get_leap_password_flags (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_wep_key (NMSettingWirelessSecurity *setting, guint32 idx);
void nm_setting_wireless_security_set_wep_key (NMSettingWirelessSecurity *setting, guint32 idx, const char *key);
guint32 nm_setting_wireless_security_get_wep_tx_keyidx (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_auth_alg (NMSettingWirelessSecurity *setting);
NMSettingSecretFlags nm_setting_wireless_security_get_wep_key_flags (NMSettingWirelessSecurity *setting);
NMWepKeyType nm_setting_wireless_security_get_wep_key_type (NMSettingWirelessSecurity *setting);
G_END_DECLS

View File

@@ -446,7 +446,7 @@ static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
const char *valid_modes[] = { "infrastructure", "adhoc", NULL };
const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NULL };
const char *valid_bands[] = { "a", "bg", NULL };
GSList *iter;

View File

@@ -68,6 +68,9 @@ GQuark nm_setting_wireless_error_quark (void);
#define NM_SETTING_WIRELESS_SEEN_BSSIDS "seen-bssids"
#define NM_SETTING_WIRELESS_SEC "security"
#define NM_SETTING_WIRELESS_MODE_ADHOC "adhoc"
#define NM_SETTING_WIRELESS_MODE_INFRA "infrastructure"
typedef struct {
NMSetting parent;
} NMSettingWireless;

View File

@@ -19,13 +19,14 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include "nm-setting.h"
#include "nm-setting-private.h"
#include "nm-setting-connection.h"
#include "nm-utils.h"
@@ -107,21 +108,23 @@ destroy_gvalue (gpointer data)
/**
* nm_setting_to_hash:
* @setting: the #NMSetting
* @flags: hash flags, e.g. %NM_SETTING_HASH_FLAG_ALL
*
* Converts the #NMSetting into a #GHashTable mapping each setting property
* name to a GValue describing that property, suitable for marshalling over
* D-Bus or serializing. The mapping is string:GValue.
*
* Returns: a new #GHashTable describing the setting's properties
* Returns: (transfer full) (element-type utf8 GObject.Value): a new #GHashTable describing the setting's properties
**/
GHashTable *
nm_setting_to_hash (NMSetting *setting)
nm_setting_to_hash (NMSetting *setting, NMSettingHashFlags flags)
{
GHashTable *hash;
GParamSpec **property_specs;
guint n_property_specs;
guint i;
g_return_val_if_fail (setting != NULL, NULL);
g_return_val_if_fail (NM_IS_SETTING (setting), NULL);
property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting), &n_property_specs);
@@ -132,29 +135,41 @@ nm_setting_to_hash (NMSetting *setting)
}
hash = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
destroy_gvalue);
(GDestroyNotify) g_free, destroy_gvalue);
for (i = 0; i < n_property_specs; i++) {
GParamSpec *prop_spec = property_specs[i];
GValue *value;
if (prop_spec->flags & NM_SETTING_PARAM_SERIALIZE) {
GValue *value;
if (!(prop_spec->flags & NM_SETTING_PARAM_SERIALIZE))
continue;
value = g_slice_new0 (GValue);
g_value_init (value, prop_spec->value_type);
g_object_get_property (G_OBJECT (setting), prop_spec->name, value);
if ( (flags & NM_SETTING_HASH_FLAG_NO_SECRETS)
&& (prop_spec->flags & NM_SETTING_PARAM_SECRET))
continue;
/* Don't serialize values with default values */
if (!g_param_value_defaults (prop_spec, value))
g_hash_table_insert (hash, g_strdup (prop_spec->name), value);
else
destroy_gvalue (value);
}
if ( (flags & NM_SETTING_HASH_FLAG_ONLY_SECRETS)
&& !(prop_spec->flags & NM_SETTING_PARAM_SECRET))
continue;
value = g_slice_new0 (GValue);
g_value_init (value, prop_spec->value_type);
g_object_get_property (G_OBJECT (setting), prop_spec->name, value);
/* Don't serialize values with default values */
if (!g_param_value_defaults (prop_spec, value))
g_hash_table_insert (hash, g_strdup (prop_spec->name), value);
else
destroy_gvalue (value);
}
g_free (property_specs);
/* Don't return empty hashes */
if (g_hash_table_size (hash) < 1) {
g_hash_table_destroy (hash);
hash = NULL;
}
return hash;
}
@@ -254,7 +269,7 @@ duplicate_setting (NMSetting *setting,
*
* Duplicates a #NMSetting.
*
* Returns: a new #NMSetting containing the same properties and values as the
* Returns: (transfer full): a new #NMSetting containing the same properties and values as the
* source #NMSetting
**/
NMSetting *
@@ -390,7 +405,7 @@ nm_setting_compare (NMSetting *a,
/**
* nm_setting_enumerate_values:
* @setting: the #NMSetting
* @func: user-supplied function called for each property of the setting
* @func: (scope call): user-supplied function called for each property of the setting
* @user_data: user data passed to @func at each invocation
*
* Iterates over each property of the #NMSetting object, calling the supplied
@@ -465,7 +480,7 @@ nm_setting_clear_secrets (NMSetting *setting)
* guide to what secrets may be required, because in some circumstances, there
* is no way to conclusively determine exactly which secrets are needed.
*
* Returns: a #GPtrArray containing the property names of secrets of the
* Returns: (transfer full) (element-type utf8): a #GPtrArray containing the property names of secrets of the
* #NMSetting which may be required; the caller owns the array
* and must free the each array element with g_free(), as well as the array
* itself with g_ptr_array_free()
@@ -483,11 +498,6 @@ nm_setting_need_secrets (NMSetting *setting)
return secrets;
}
typedef struct {
NMSetting *setting;
GError **error;
} UpdateSecretsInfo;
static gboolean
update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error)
{
@@ -504,13 +514,9 @@ update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **
return FALSE;
}
if (!(prop_spec->flags & NM_SETTING_PARAM_SECRET)) {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_NOT_SECRET,
"%s", key);
return FALSE;
}
/* Silently ignore non-secrets */
if (!(prop_spec->flags & NM_SETTING_PARAM_SECRET))
return TRUE;
if (g_value_type_compatible (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (prop_spec))) {
g_object_set_property (G_OBJECT (setting), prop_spec->name, value);
@@ -528,17 +534,6 @@ update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **
return success;
}
static void
update_one_cb (gpointer key, gpointer val, gpointer user_data)
{
UpdateSecretsInfo *info = user_data;
const char *secret_key = (const char *) key;
GValue *secret_value = (GValue *) val;
if (*(info->error) == NULL)
NM_SETTING_GET_CLASS (info->setting)->update_one_secret (info->setting, secret_key, secret_value, info->error);
}
/**
* nm_setting_update_secrets:
* @setting: the #NMSetting
@@ -555,8 +550,9 @@ update_one_cb (gpointer key, gpointer val, gpointer user_data)
gboolean
nm_setting_update_secrets (NMSetting *setting, GHashTable *secrets, GError **error)
{
UpdateSecretsInfo *info;
gboolean success;
GHashTableIter iter;
gpointer key, data;
GError *tmp_error = NULL;
g_return_val_if_fail (setting != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
@@ -564,14 +560,137 @@ nm_setting_update_secrets (NMSetting *setting, GHashTable *secrets, GError **err
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
info = g_malloc0 (sizeof (UpdateSecretsInfo));
info->setting = setting;
info->error = error;
g_hash_table_foreach (secrets, update_one_cb, info);
success = *(info->error) ? FALSE : TRUE;
g_free (info);
g_hash_table_iter_init (&iter, secrets);
while (g_hash_table_iter_next (&iter, &key, &data)) {
const char *secret_key = (const char *) key;
GValue *secret_value = (GValue *) data;
return success;
NM_SETTING_GET_CLASS (setting)->update_one_secret (setting, secret_key, secret_value, &tmp_error);
if (tmp_error) {
g_propagate_error (error, tmp_error);
break;
}
}
return tmp_error ? FALSE : TRUE;
}
static gboolean
is_secret_prop (NMSetting *setting, const char *secret_name, GError **error)
{
GParamSpec *pspec;
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), secret_name);
if (!pspec) {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_NOT_FOUND,
"Secret %s not provided by this setting", secret_name);
return FALSE;
}
if (!(pspec->flags & NM_SETTING_PARAM_SECRET)) {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_NOT_SECRET,
"Property %s is not a secret", secret_name);
return FALSE;
}
return TRUE;
}
static gboolean
get_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags *out_flags,
GError **error)
{
char *flags_prop;
NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
if (verify_secret)
g_return_val_if_fail (is_secret_prop (setting, secret_name, error), FALSE);
flags_prop = g_strdup_printf ("%s-flags", secret_name);
g_object_get (G_OBJECT (setting), flags_prop, &flags, NULL);
g_free (flags_prop);
if (out_flags)
*out_flags = flags;
return TRUE;
}
/**
* nm_setting_get_secret_flags:
* @setting: the #NMSetting
* @secret_name: the secret key name to get flags for
* @out_flags: on success, the #NMSettingSecretFlags for the secret
* @error: location to store error, or %NULL
*
* For a given secret, retrieves the #NMSettingSecretFlags describing how to
* handle that secret.
*
* Returns: TRUE on success (if the given secret name was a valid property of
* this setting, and if that property is secret), FALSE if not
**/
gboolean
nm_setting_get_secret_flags (NMSetting *setting,
const char *secret_name,
NMSettingSecretFlags *out_flags,
GError **error)
{
g_return_val_if_fail (setting != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
g_return_val_if_fail (secret_name != NULL, FALSE);
return NM_SETTING_GET_CLASS (setting)->get_secret_flags (setting, secret_name, TRUE, out_flags, error);
}
static gboolean
set_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags flags,
GError **error)
{
char *flags_prop;
if (verify_secret)
g_return_val_if_fail (is_secret_prop (setting, secret_name, error), FALSE);
flags_prop = g_strdup_printf ("%s-flags", secret_name);
g_object_set (G_OBJECT (setting), flags_prop, flags, NULL);
g_free (flags_prop);
return TRUE;
}
/**
* nm_setting_set_secret_flags:
* @setting: the #NMSetting
* @secret_name: the secret key name to set flags for
* @flags: the #NMSettingSecretFlags for the secret
* @error: location to store error, or %NULL
*
* For a given secret, retrieves the #NMSettingSecretFlags describing how to
* handle that secret.
*
* Returns: TRUE on success (if the given secret name was a valid property of
* this setting, and if that property is secret), FALSE if not
**/
gboolean
nm_setting_set_secret_flags (NMSetting *setting,
const char *secret_name,
NMSettingSecretFlags flags,
GError **error)
{
g_return_val_if_fail (setting != NULL, FALSE);
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
g_return_val_if_fail (secret_name != NULL, FALSE);
g_return_val_if_fail (flags <= NM_SETTING_SECRET_FLAGS_ALL, FALSE);
return NM_SETTING_GET_CLASS (setting)->set_secret_flags (setting, secret_name, TRUE, flags, error);
}
/**
@@ -730,6 +849,8 @@ nm_setting_class_init (NMSettingClass *setting_class)
object_class->finalize = finalize;
setting_class->update_one_secret = update_one_secret;
setting_class->get_secret_flags = get_secret_flags;
setting_class->set_secret_flags = set_secret_flags;
/* Properties */

View File

@@ -19,7 +19,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2008 Red Hat, Inc.
* (C) Copyright 2007 - 2011 Red Hat, Inc.
* (C) Copyright 2007 - 2008 Novell, Inc.
*/
@@ -83,6 +83,34 @@ GQuark nm_setting_error_quark (void);
#define NM_SETTING_NAME "name"
/**
* NMSettingSecretFlags:
* @NM_SETTING_SECRET_FLAG_NONE: the system is responsible for providing and
* storing this secret (default)
* @NM_SETTING_SECRET_FLAG_AGENT_OWNED: a user secret agent is responsible
* for providing and storing this secret; when it is required agents will be
* asked to retrieve it
* @NM_SETTING_SECRET_FLAG_NOT_SAVED: this secret should not be saved, but
* should be requested from the user each time it is needed
* @NM_SETTING_SECRET_FLAG_NOT_REQUIRED: in situations where it cannot be
* automatically determined that the secret is required (some VPNs and PPP
* providers dont require all secrets) this flag indicates that the specific
* secret is not required
*
* These flags indicate specific behavior related to handling of a secret. Each
* secret has a corresponding set of these flags which indicate how the secret
* is to be stored and/or requested when it is needed.
*
**/
typedef enum {
NM_SETTING_SECRET_FLAG_NONE = 0x00000000,
NM_SETTING_SECRET_FLAG_AGENT_OWNED = 0x00000001,
NM_SETTING_SECRET_FLAG_NOT_SAVED = 0x00000002,
NM_SETTING_SECRET_FLAG_NOT_REQUIRED = 0x00000004
/* NOTE: if adding flags, update nm-setting-private.h as well */
} NMSettingSecretFlags;
/**
* NMSetting:
*
@@ -108,6 +136,18 @@ typedef struct {
GValue *value,
GError **error);
gboolean (*get_secret_flags) (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags *out_flags,
GError **error);
gboolean (*set_secret_flags) (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags flags,
GError **error);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
@@ -124,7 +164,25 @@ typedef void (*NMSettingValueIterFn) (NMSetting *setting,
GType nm_setting_get_type (void);
GHashTable *nm_setting_to_hash (NMSetting *setting);
/**
* NMSettingHashFlags:
* @NM_SETTING_HASH_FLAG_ALL: hash all properties (including secrets)
* @NM_SETTING_HASH_FLAG_NO_SECRETS: do not include secrets
* @NM_SETTING_HASH_FLAG_ONLY_SECRETS: only hash secrets
*
* These flags determine which properties are added to the resulting hash
* when calling nm_setting_to_hash().
*
**/
typedef enum {
NM_SETTING_HASH_FLAG_ALL = 0x00000000,
NM_SETTING_HASH_FLAG_NO_SECRETS = 0x00000001,
NM_SETTING_HASH_FLAG_ONLY_SECRETS = 0x00000002,
} NMSettingHashFlags;
GHashTable *nm_setting_to_hash (NMSetting *setting,
NMSettingHashFlags flags);
NMSetting *nm_setting_new_from_hash (GType setting_type,
GHashTable *hash);
@@ -173,6 +231,16 @@ gboolean nm_setting_update_secrets (NMSetting *setting,
GHashTable *secrets,
GError **error);
gboolean nm_setting_get_secret_flags (NMSetting *setting,
const char *secret_name,
NMSettingSecretFlags *out_flags,
GError **error);
gboolean nm_setting_set_secret_flags (NMSetting *setting,
const char *secret_name,
NMSettingSecretFlags flags,
GError **error);
G_END_DECLS
#endif /* NM_SETTING_H */

View File

@@ -487,7 +487,7 @@ value_dup (gpointer key, gpointer val, gpointer user_data)
*
* Utility function to duplicate a hash table of GValues.
*
* Returns: a newly allocated duplicated #GHashTable, caller must free the
* Returns: (transfer container) (element-type utf8 GObject.Value): a newly allocated duplicated #GHashTable, caller must free the
* returned hash with g_hash_table_unref() or g_hash_table_destroy()
**/
GHashTable *
@@ -1359,7 +1359,7 @@ nm_utils_security_valid (NMUtilsSecurityType type,
* this serialization is not guaranteed to be stable and the #GArray may be
* extended in the future.
*
* Returns: a newly allocated #GSList of #NMIP4Address objects
* Returns: (transfer full) (element-type NetworkManager.IP4Address): a newly allocated #GSList of #NMIP4Address objects
**/
GSList *
nm_utils_ip4_addresses_from_gvalue (const GValue *value)
@@ -1441,7 +1441,7 @@ nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value)
* format of this serialization is not guaranteed to be stable and may be
* extended in the future.
*
* Returns: a newly allocated #GSList of #NMIP4Route objects
* Returns: (transfer full) (element-type NetworkManager.IP4Route): a newly allocated #GSList of #NMIP4Route objects
**/
GSList *
nm_utils_ip4_routes_from_gvalue (const GValue *value)
@@ -1604,7 +1604,7 @@ nm_utils_ip4_get_default_prefix (guint32 ip)
* this serialization is not guaranteed to be stable and the #GValueArray may be
* extended in the future.
*
* Returns: a newly allocated #GSList of #NMIP6Address objects
* Returns: (transfer full) (element-type NetworkManager.IP6Address): a newly allocated #GSList of #NMIP6Address objects
**/
GSList *
nm_utils_ip6_addresses_from_gvalue (const GValue *value)
@@ -1747,7 +1747,7 @@ nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value)
* into a GSList of #NMIP6Route objects. The specific format of this serialization
* is not guaranteed to be stable and may be extended in the future.
*
* Returns: a newly allocated #GSList of #NMIP6Route objects
* Returns: (transfer full) (element-type NetworkManager.IP6Route): a newly allocated #GSList of #NMIP6Route objects
**/
GSList *
nm_utils_ip6_routes_from_gvalue (const GValue *value)
@@ -1863,6 +1863,18 @@ nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value)
g_value_take_boxed (value, routes);
}
/* FIXME: the Posix namespace does not exist, and thus neither does
the in6_addr struct. Marking (skip) for now */
/**
* nm_utils_ip6_dns_from_gvalue: (skip):
* @value: a #GValue
*
* Converts a #GValue containing a #GPtrArray of IP6 DNS, represented as
* #GByteArray<!-- -->s into a #GSList of #in6_addr<!-- -->s.
*
* Returns: (transfer full) (element-type Posix.in6_addr): a #GSList of IP6
* addresses.
*/
GSList *
nm_utils_ip6_dns_from_gvalue (const GValue *value)
{
@@ -2046,8 +2058,8 @@ utils_bin2hexstr (const char *bytes, int len, int final_len)
/**
* nm_utils_rsa_key_encrypt:
* @data: RSA private key data to be encrypted
* @in_password: existing password to use, if any
* @out_password: if @in_password was NULL, a random password will be generated
* @in_password: (allow-none): existing password to use, if any
* @out_password: (out) (allow-none): if @in_password was NULL, a random password will be generated
* and returned in this argument
* @error: detailed error information on return, if an error occurred
*
@@ -2055,7 +2067,7 @@ utils_bin2hexstr (const char *bytes, int len, int final_len)
* a password if no password was given) and converts the data to PEM format
* suitable for writing to a file.
*
* Returns: on success, PEM-formatted data suitable for writing to a PEM-formatted
* Returns: (transfer full): on success, PEM-formatted data suitable for writing to a PEM-formatted
* certificate/private key file.
**/
GByteArray *

View File

@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 - 2010 Red Hat, Inc.
* Copyright (C) 2008 - 2011 Red Hat, Inc.
*
*/
@@ -29,6 +29,7 @@
#include "nm-setting-connection.h"
#include "nm-setting-vpn.h"
#include "nm-setting-gsm.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-ip6-config.h"
#include "nm-dbus-glib-types.h"
@@ -130,6 +131,65 @@ test_setting_vpn_items (void)
g_object_unref (s_vpn);
}
static void
test_setting_vpn_update_secrets (void)
{
NMConnection *connection;
NMSettingVPN *s_vpn;
GHashTable *settings, *vpn, *secrets;
GValue val = { 0 };
gboolean success;
GError *error = NULL;
const char *tmp;
const char *key1 = "foobar";
const char *key2 = "blahblah";
const char *val1 = "value1";
const char *val2 = "value2";
connection = nm_connection_new ();
ASSERT (connection != NULL,
"vpn-update-secrets",
"error creating connection");
s_vpn = (NMSettingVPN *) nm_setting_vpn_new ();
ASSERT (s_vpn != NULL,
"vpn-update-secrets",
"error creating vpn setting");
nm_connection_add_setting (connection, NM_SETTING (s_vpn));
settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_hash_table_destroy);
vpn = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_value_unset);
g_hash_table_insert (settings, NM_SETTING_VPN_SETTING_NAME, vpn);
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
g_value_init (&val, DBUS_TYPE_G_MAP_OF_STRING);
g_value_take_boxed (&val, secrets);
g_hash_table_insert (vpn, NM_SETTING_VPN_SECRETS, &val);
/* Add some secrets */
g_hash_table_insert (secrets, (char *) key1, (char *) val1);
g_hash_table_insert (secrets, (char *) key2, (char *) val2);
success = nm_connection_update_secrets (connection, NM_SETTING_VPN_SETTING_NAME, settings, &error);
ASSERT (success == TRUE,
"vpn-update-secrets", "failed to update VPN secrets: %s", error->message);
/* Read the secrets back out */
tmp = nm_setting_vpn_get_secret (s_vpn, key1);
ASSERT (tmp != NULL,
"vpn-update-secrets", "unexpected failure getting key #1");
ASSERT (strcmp (tmp, val1) == 0,
"vpn-update-secrets", "unexpected key #1 value");
tmp = nm_setting_vpn_get_secret (s_vpn, key2);
ASSERT (tmp != NULL,
"vpn-update-secrets", "unexpected failure getting key #2");
ASSERT (strcmp (tmp, val2) == 0,
"vpn-update-secrets", "unexpected key #2 value");
g_object_unref (connection);
}
#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS))
@@ -289,6 +349,319 @@ test_setting_gsm_apn_bad_chars (void)
"gsm-apn-bad-chars", "unexpectedly valid GSM setting");
}
static NMSettingWirelessSecurity *
make_test_wsec_setting (const char *detail)
{
NMSettingWirelessSecurity *s_wsec;
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
ASSERT (s_wsec != NULL, detail, "error creating setting");
g_object_set (s_wsec,
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk",
NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, "foobarbaz",
NM_SETTING_WIRELESS_SECURITY_PSK, "random psk",
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, "aaaaaaaaaa",
NULL);
return s_wsec;
}
static void
test_setting_to_hash_all (void)
{
NMSettingWirelessSecurity *s_wsec;
GHashTable *hash;
s_wsec = make_test_wsec_setting ("setting-to-hash-all");
hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ALL);
/* Make sure all keys are there */
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME),
"setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_PSK),
"setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_PSK);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0),
"setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
g_hash_table_destroy (hash);
g_object_unref (s_wsec);
}
static void
test_setting_to_hash_no_secrets (void)
{
NMSettingWirelessSecurity *s_wsec;
GHashTable *hash;
s_wsec = make_test_wsec_setting ("setting-to-hash-no-secrets");
hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_NO_SECRETS);
/* Make sure non-secret keys are there */
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"setting-to-hash-no-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME),
"setting-to-hash-no-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME);
/* Make sure secrets are not there */
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_PSK) == NULL,
"setting-to-hash-no-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_PSK);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0) == NULL,
"setting-to-hash-no-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
g_hash_table_destroy (hash);
g_object_unref (s_wsec);
}
static void
test_setting_to_hash_only_secrets (void)
{
NMSettingWirelessSecurity *s_wsec;
GHashTable *hash;
s_wsec = make_test_wsec_setting ("setting-to-hash-only-secrets");
hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ONLY_SECRETS);
/* Make sure non-secret keys are there */
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT) == NULL,
"setting-to-hash-only-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME) == NULL,
"setting-to-hash-only-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME);
/* Make sure secrets are not there */
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_PSK),
"setting-to-hash-only-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_PSK);
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0),
"setting-to-hash-only-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
g_hash_table_destroy (hash);
g_object_unref (s_wsec);
}
static void
test_connection_to_hash_setting_name (void)
{
NMConnection *connection;
NMSettingWirelessSecurity *s_wsec;
GHashTable *hash;
connection = nm_connection_new ();
s_wsec = make_test_wsec_setting ("connection-to-hash-setting-name");
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
/* Make sure the keys of the first level hash are setting names, not
* the GType name of the setting objects.
*/
ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) != NULL,
"connection-to-hash-setting-name", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_hash_table_destroy (hash);
g_object_unref (connection);
}
static void
check_permission (NMSettingConnection *s_con,
guint32 idx,
const char *expected_uname,
const char *tag)
{
gboolean success;
const char *ptype = NULL, *pitem = NULL, *detail = NULL;
success = nm_setting_connection_get_permission (s_con, 0, &ptype, &pitem, &detail);
ASSERT (success == TRUE, tag, "unexpected failure getting added permission");
/* Permission type */
ASSERT (ptype != NULL, tag, "unexpected failure getting permission type");
ASSERT (strcmp (ptype, "user") == 0, tag, "retrieved unexpected permission type");
/* Permission item */
ASSERT (pitem != NULL, tag, "unexpected failure getting permission item");
ASSERT (strcmp (pitem, expected_uname) == 0, tag, "retrieved unexpected permission item");
ASSERT (detail == NULL, tag, "unexpected success getting permission detail");
}
#define TEST_UNAME "asdfasfasdf"
static void
test_setting_connection_permissions_helpers (void)
{
NMSettingConnection *s_con;
gboolean success;
char buf[9] = { 0x61, 0x62, 0x63, 0xff, 0xfe, 0xfd, 0x23, 0x01, 0x00 };
GSList *list = NULL;
const char *expected_perm = "user:" TEST_UNAME ":";
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
/* Ensure a bad [type] is rejected */
success = nm_setting_connection_add_permission (s_con, "foobar", "blah", NULL);
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission type #1");
/* Ensure a bad [type] is rejected */
success = nm_setting_connection_add_permission (s_con, NULL, "blah", NULL);
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission type #2");
/* Ensure a bad [item] is rejected */
success = nm_setting_connection_add_permission (s_con, "user", NULL, NULL);
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #1");
/* Ensure a bad [item] is rejected */
success = nm_setting_connection_add_permission (s_con, "user", "", NULL);
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #2");
/* Ensure an [item] with ':' is rejected */
success = nm_setting_connection_add_permission (s_con, "user", "ad:asdf", NULL);
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #3");
/* Ensure a non-UTF-8 [item] is rejected */
success = nm_setting_connection_add_permission (s_con, "user", buf, NULL);
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #4");
/* Ensure a non-NULL [detail] is rejected */
success = nm_setting_connection_add_permission (s_con, "user", "dafasdf", "asdf");
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad detail");
/* Ensure a valid call results in success */
success = nm_setting_connection_add_permission (s_con, "user", TEST_UNAME, NULL);
ASSERT (success == TRUE,
"setting-connection-permissions-helpers", "unexpected failure adding valid user permisson");
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 1,
"setting-connection-permissions-helpers", "unexpected failure getting number of permissions");
check_permission (s_con, 0, TEST_UNAME, "setting-connection-permissions-helpers");
/* Check the actual GObject property just to be paranoid */
g_object_get (G_OBJECT (s_con), NM_SETTING_CONNECTION_PERMISSIONS, &list, NULL);
ASSERT (list != NULL,
"setting-connection-permissions-helpers", "unexpected failure getting permissions list");
ASSERT (g_slist_length (list) == 1,
"setting-connection-permissions-helpers", "unexpected failure getting number of permissions in list");
ASSERT (strcmp (list->data, expected_perm) == 0,
"setting-connection-permissions-helpers", "unexpected permission property data");
/* Now remove that permission and ensure we have 0 permissions */
nm_setting_connection_remove_permission (s_con, 0);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-helpers", "unexpected failure removing permission");
g_object_unref (s_con);
}
static void
add_permission_property (NMSettingConnection *s_con,
const char *ptype,
const char *pitem,
int pitem_len,
const char *detail)
{
GString *str;
GSList *list = NULL;
str = g_string_sized_new (50);
if (ptype)
g_string_append (str, ptype);
g_string_append_c (str, ':');
if (pitem) {
if (pitem_len >= 0)
g_string_append_len (str, pitem, pitem_len);
else
g_string_append (str, pitem);
}
g_string_append_c (str, ':');
if (detail)
g_string_append (str, detail);
list = g_slist_append (list, str->str);
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_PERMISSIONS, list, NULL);
g_string_free (str, TRUE);
g_slist_free (list);
}
static void
test_setting_connection_permissions_property (void)
{
NMSettingConnection *s_con;
gboolean success;
char buf[9] = { 0x61, 0x62, 0x63, 0xff, 0xfe, 0xfd, 0x23, 0x01, 0x00 };
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
/* Ensure a bad [type] is rejected */
add_permission_property (s_con, "foobar", "blah", -1, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission type #1");
/* Ensure a bad [type] is rejected */
add_permission_property (s_con, NULL, "blah", -1, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission type #2");
/* Ensure a bad [item] is rejected */
add_permission_property (s_con, "user", NULL, -1, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #1");
/* Ensure a bad [item] is rejected */
add_permission_property (s_con, "user", "", -1, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #2");
/* Ensure an [item] with ':' in the middle is rejected */
add_permission_property (s_con, "user", "ad:asdf", -1, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #3");
/* Ensure an [item] with ':' at the end is rejected */
add_permission_property (s_con, "user", "adasdfaf:", -1, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #4");
/* Ensure a non-UTF-8 [item] is rejected */
add_permission_property (s_con, "user", buf, (int) sizeof (buf), NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #5");
/* Ensure a non-NULL [detail] is rejected */
add_permission_property (s_con, "user", "dafasdf", -1, "asdf");
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad detail");
/* Ensure a valid call results in success */
success = nm_setting_connection_add_permission (s_con, "user", TEST_UNAME, NULL);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 1,
"setting-connection-permissions-property", "unexpected failure adding valid user permisson");
check_permission (s_con, 0, TEST_UNAME, "setting-connection-permissions-property");
/* Now remove that permission and ensure we have 0 permissions */
nm_setting_connection_remove_permission (s_con, 0);
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected failure removing permission");
g_object_unref (s_con);
}
int main (int argc, char **argv)
{
GError *error = NULL;
@@ -303,9 +676,16 @@ int main (int argc, char **argv)
/* The tests */
test_setting_vpn_items ();
test_setting_vpn_update_secrets ();
test_setting_ip6_config_old_address_array ();
test_setting_gsm_apn_spaces ();
test_setting_gsm_apn_bad_chars ();
test_setting_to_hash_all ();
test_setting_to_hash_no_secrets ();
test_setting_to_hash_only_secrets ();
test_connection_to_hash_setting_name ();
test_setting_connection_permissions_helpers ();
test_setting_connection_permissions_property ();
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);

Some files were not shown because too many files have changed in this diff Show More