2008-08-12 18:39:03 +00:00
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2008-11-03 16:05:11 +00:00
/* NetworkManager system settings service - keyfile plugin
*
* 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 of the License , 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 ) 2008 Novell , Inc .
2013-11-12 15:04:15 +01:00
* Copyright ( C ) 2008 - 2013 Red Hat , Inc .
2008-11-03 16:05:11 +00:00
*/
2008-04-22 14:48:02 +00:00
2014-11-13 10:07:02 -05:00
# include "config.h"
2008-04-22 14:48:02 +00:00
# include <sys/stat.h>
# include <unistd.h>
# include <sys/types.h>
2008-08-27 03:09:14 +00:00
# include <string.h>
2009-08-20 13:00:37 -05:00
2008-04-22 14:48:02 +00:00
# include <gmodule.h>
# include <glib/gstdio.h>
2009-08-20 13:00:37 -05:00
2008-04-22 14:48:02 +00:00
# include <nm-connection.h>
# include <nm-setting.h>
# include <nm-setting-connection.h>
2013-02-12 18:00:48 -05:00
# include <nm-utils.h>
2015-07-17 15:21:14 +02:00
# include "nm-config.h"
2015-07-17 14:38:54 +02:00
# include "nm-default.h"
2014-07-27 23:55:55 +02:00
# include "nm-core-internal.h"
2008-04-22 14:48:02 +00:00
# include "plugin.h"
2015-04-16 08:52:20 -04:00
# include "nm-settings-plugin.h"
2008-05-07 09:48:12 +00:00
# include "nm-keyfile-connection.h"
2008-04-22 14:48:02 +00:00
# include "writer.h"
2010-11-10 16:21:25 +01:00
# include "utils.h"
2008-04-22 14:48:02 +00:00
core: fix interface type names
A GObject interface, like a class, has two different C types
associated with it; the type of the "class" struct (eg, GObjectClass,
GFileIface), and the type of instances of that class/interface (eg,
GObject, GFile).
NetworkManager was doing this wrong though, and using the same C type
to point to both the interface's class struct and to instances of the
interface. This ends up not actually breaking anything, since for
interface types, the instance type is a non-dereferenceable dummy type
anyway. But it's wrong, since if, eg, NMDeviceFactory is a struct type
containing members "start", "device_added", etc, then you should not
be using an NMDeviceFactory* to point to an object that does not
contain those members.
Fix this by splitting NMDeviceFactory into NMDeviceFactoryInterface
and NMDeviceFactory; by splitting NMConnectionProvider into
NMConnectionProviderInterface and NMConnectionProvider; and by
splitting NMSettingsPlugin into NMSettingsPluginInterface and
NMSettingsPlugin; and then use the right types in the right places.
As a bonus, this also lets us now use G_DEFINE_INTERFACE.
2015-04-16 09:05:49 -04:00
static void settings_plugin_interface_init ( NMSettingsPluginInterface * plugin_iface ) ;
2008-04-22 14:48:02 +00:00
2015-04-16 08:52:20 -04:00
G_DEFINE_TYPE_EXTENDED ( SettingsPluginKeyfile , settings_plugin_keyfile , G_TYPE_OBJECT , 0 ,
core: fix interface type names
A GObject interface, like a class, has two different C types
associated with it; the type of the "class" struct (eg, GObjectClass,
GFileIface), and the type of instances of that class/interface (eg,
GObject, GFile).
NetworkManager was doing this wrong though, and using the same C type
to point to both the interface's class struct and to instances of the
interface. This ends up not actually breaking anything, since for
interface types, the instance type is a non-dereferenceable dummy type
anyway. But it's wrong, since if, eg, NMDeviceFactory is a struct type
containing members "start", "device_added", etc, then you should not
be using an NMDeviceFactory* to point to an object that does not
contain those members.
Fix this by splitting NMDeviceFactory into NMDeviceFactoryInterface
and NMDeviceFactory; by splitting NMConnectionProvider into
NMConnectionProviderInterface and NMConnectionProvider; and by
splitting NMSettingsPlugin into NMSettingsPluginInterface and
NMSettingsPlugin; and then use the right types in the right places.
As a bonus, this also lets us now use G_DEFINE_INTERFACE.
2015-04-16 09:05:49 -04:00
G_IMPLEMENT_INTERFACE ( NM_TYPE_SETTINGS_PLUGIN ,
settings_plugin_interface_init ) )
2008-04-22 14:48:02 +00:00
2015-04-16 08:52:20 -04:00
# define SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfilePrivate))
2008-04-22 14:48:02 +00:00
typedef struct {
2013-04-18 13:54:36 -05:00
GHashTable * connections ; /* uuid::connection */
2008-04-22 14:48:02 +00:00
2013-04-18 13:54:36 -05:00
gboolean initialized ;
2008-04-22 14:48:02 +00:00
GFileMonitor * monitor ;
2016-01-04 10:29:06 +01:00
gulong monitor_id ;
2008-04-22 14:48:02 +00:00
2015-06-05 23:13:12 +02:00
NMConfig * config ;
2015-04-16 08:52:20 -04:00
} SettingsPluginKeyfilePrivate ;
2008-04-22 14:48:02 +00:00
2013-08-08 15:54:32 -05:00
static void
connection_removed_cb ( NMSettingsConnection * obj , gpointer user_data )
{
2015-04-16 08:52:20 -04:00
g_hash_table_remove ( SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( user_data ) - > connections ,
2013-08-08 15:54:32 -05:00
nm_connection_get_uuid ( NM_CONNECTION ( obj ) ) ) ;
}
2008-04-22 14:48:02 +00:00
/* Monitoring */
2010-09-16 15:43:22 -05:00
static void
2015-04-16 08:52:20 -04:00
remove_connection ( SettingsPluginKeyfile * self , NMKeyfileConnection * connection )
2010-09-16 15:43:22 -05:00
{
2014-06-11 13:24:10 -05:00
gboolean removed ;
2010-09-16 15:43:22 -05:00
g_return_if_fail ( connection ! = NULL ) ;
2014-12-09 12:15:18 +01:00
nm_log_info ( LOGD_SETTINGS , " keyfile: removed " NM_KEYFILE_CONNECTION_LOG_FMT , NM_KEYFILE_CONNECTION_LOG_ARG ( connection ) ) ;
2013-05-23 19:05:40 -03:00
2010-09-16 15:43:22 -05:00
/* Removing from the hash table should drop the last reference */
g_object_ref ( connection ) ;
2014-06-11 13:24:10 -05:00
g_signal_handlers_disconnect_by_func ( connection , connection_removed_cb , self ) ;
2015-04-16 08:52:20 -04:00
removed = g_hash_table_remove ( SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( self ) - > connections ,
2014-06-11 13:24:10 -05:00
nm_connection_get_uuid ( NM_CONNECTION ( connection ) ) ) ;
2011-02-11 21:29:41 -06:00
nm_settings_connection_signal_remove ( NM_SETTINGS_CONNECTION ( connection ) ) ;
2010-09-16 15:43:22 -05:00
g_object_unref ( connection ) ;
2014-06-11 13:24:10 -05:00
g_return_if_fail ( removed ) ;
2010-09-16 15:43:22 -05:00
}
2014-12-08 21:11:52 +01:00
static NMKeyfileConnection *
2015-04-16 08:52:20 -04:00
find_by_path ( SettingsPluginKeyfile * self , const char * path )
2014-12-08 21:11:52 +01:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( self ) ;
2014-12-08 21:11:52 +01:00
GHashTableIter iter ;
NMSettingsConnection * candidate = NULL ;
g_return_val_if_fail ( path ! = NULL , NULL ) ;
g_hash_table_iter_init ( & iter , priv - > connections ) ;
while ( g_hash_table_iter_next ( & iter , NULL , ( gpointer ) & candidate ) ) {
if ( g_strcmp0 ( path , nm_settings_connection_get_filename ( candidate ) ) = = 0 )
return NM_KEYFILE_CONNECTION ( candidate ) ;
}
return NULL ;
}
2014-12-08 21:53:24 +01:00
/* update_connection:
* @ self : the plugin instance
2014-12-10 11:23:20 +01:00
* @ source : if % NULL , this re - reads the connection from @ full_path
* and updates it . When passing @ source , this adds a connection from
* memory .
2014-12-08 21:53:24 +01:00
* @ full_path : the filename of the keyfile to be loaded
* @ connection : an existing connection that might be updated .
* If given , @ connection must be an existing connection that is currently
* owned by the plugin .
2014-12-10 11:23:20 +01:00
* @ protect_existing_connection : if % TRUE , and ! @ connection , we don ' t allow updating
* an existing connection with the same UUID .
* If % TRUE and @ connection , allow updating only if the reload would modify
* @ connection ( without changing its UUID ) or if we would create a new connection .
* In other words , if this paramter is % TRUE , we only allow creating a
* new connection ( with an unseen UUID ) or updating the passed in @ connection
* ( whereas the UUID cannot change ) .
* Note , that this allows for @ connection to be replaced by a new connection .
2014-12-09 13:50:05 +01:00
* @ protected_connections : ( allow - none ) : if given , we only update an
* existing connection if it is not contained in this hash .
2014-12-10 11:23:20 +01:00
* @ error : error in case of failure
2014-12-08 21:53:24 +01:00
*
* Loads a connection from file @ full_path . This can both be used to
* load a connection initially or to update an existing connection .
*
* If you pass in an existing connection and the reloaded file happens
* to have a different UUID , the connection is deleted .
* Beware , that means that after the function , you have a dangling pointer
* if the returned connection is different from @ connection .
*
* Returns : the updated connection .
* */
static NMKeyfileConnection *
2015-04-16 08:52:20 -04:00
update_connection ( SettingsPluginKeyfile * self ,
2014-12-10 11:23:20 +01:00
NMConnection * source ,
2014-12-08 21:53:24 +01:00
const char * full_path ,
2014-12-09 13:50:05 +01:00
NMKeyfileConnection * connection ,
2014-12-10 11:23:20 +01:00
gboolean protect_existing_connection ,
GHashTable * protected_connections ,
GError * * error )
2013-05-23 19:05:40 -03:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( self ) ;
2014-12-08 21:53:24 +01:00
NMKeyfileConnection * connection_new ;
NMKeyfileConnection * connection_by_uuid ;
2014-12-10 11:23:20 +01:00
GError * local = NULL ;
2014-12-08 21:53:24 +01:00
const char * uuid ;
2013-05-23 19:05:40 -03:00
2014-12-10 11:23:20 +01:00
g_return_val_if_fail ( ! source | | NM_IS_CONNECTION ( source ) , NULL ) ;
g_return_val_if_fail ( full_path | | source , NULL ) ;
if ( full_path )
nm_log_dbg ( LOGD_SETTINGS , " keyfile: loading from file \" %s \" ... " , full_path ) ;
connection_new = nm_keyfile_connection_new ( source , full_path , & local ) ;
2014-12-08 21:53:24 +01:00
if ( ! connection_new ) {
2013-05-23 19:05:40 -03:00
/* Error; remove the connection */
2014-12-10 11:23:20 +01:00
if ( source )
nm_log_warn ( LOGD_SETTINGS , " keyfile: error creating connection %s: %s " , nm_connection_get_uuid ( source ) , local - > message ) ;
else
nm_log_warn ( LOGD_SETTINGS , " keyfile: error loading connection from file %s: %s " , full_path , local - > message ) ;
if ( connection
& & ! protect_existing_connection
& & ( ! protected_connections | | ! g_hash_table_contains ( protected_connections , connection ) ) )
2014-12-08 21:53:24 +01:00
remove_connection ( self , connection ) ;
2014-12-10 11:23:20 +01:00
g_propagate_error ( error , local ) ;
2014-12-08 21:53:24 +01:00
return NULL ;
2013-05-23 19:05:40 -03:00
}
2014-12-08 21:53:24 +01:00
uuid = nm_connection_get_uuid ( NM_CONNECTION ( connection_new ) ) ;
connection_by_uuid = g_hash_table_lookup ( priv - > connections , uuid ) ;
2013-05-23 19:05:40 -03:00
2014-12-08 21:53:24 +01:00
if ( connection
& & connection ! = connection_by_uuid ) {
2014-12-10 11:23:20 +01:00
if ( ( protect_existing_connection & & connection_by_uuid ! = NULL )
| | ( protected_connections & & g_hash_table_contains ( protected_connections , connection ) ) ) {
NMKeyfileConnection * conflicting = ( protect_existing_connection & & connection_by_uuid ! = NULL ) ? connection_by_uuid : connection ;
if ( source )
nm_log_warn ( LOGD_SETTINGS , " keyfile: cannot update protected " NM_KEYFILE_CONNECTION_LOG_FMT " connection due to conflicting UUID %s " , NM_KEYFILE_CONNECTION_LOG_ARG ( conflicting ) , uuid ) ;
else
nm_log_warn ( LOGD_SETTINGS , " keyfile: cannot load %s due to conflicting UUID for " NM_KEYFILE_CONNECTION_LOG_FMT , full_path , NM_KEYFILE_CONNECTION_LOG_ARG ( conflicting ) ) ;
g_object_unref ( connection_new ) ;
g_set_error_literal ( error , NM_SETTINGS_ERROR , NM_SETTINGS_ERROR_FAILED ,
" Cannot update protected connection due to conflicting UUID " ) ;
return NULL ;
}
2014-12-08 21:53:24 +01:00
/* The new connection has a different UUID then the original one.
* Remove @ connection . */
remove_connection ( self , connection ) ;
}
2013-05-23 19:05:40 -03:00
2014-12-09 13:50:05 +01:00
if ( connection_by_uuid
2014-12-10 11:23:20 +01:00
& & ( ( ! connection & & protect_existing_connection )
| | ( protected_connections & & g_hash_table_contains ( protected_connections , connection_by_uuid ) ) ) ) {
if ( source )
nm_log_warn ( LOGD_SETTINGS , " keyfile: cannot update connection due to conflicting UUID for " NM_KEYFILE_CONNECTION_LOG_FMT , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_by_uuid ) ) ;
else
nm_log_warn ( LOGD_SETTINGS , " keyfile: cannot load %s due to conflicting UUID for " NM_KEYFILE_CONNECTION_LOG_FMT , full_path , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_by_uuid ) ) ;
2014-12-09 13:50:05 +01:00
g_object_unref ( connection_new ) ;
2014-12-10 11:23:20 +01:00
g_set_error_literal ( error , NM_SETTINGS_ERROR , NM_SETTINGS_ERROR_FAILED ,
" Skip updating protected connection during reload " ) ;
2014-12-09 13:50:05 +01:00
return NULL ;
}
2014-12-08 21:53:24 +01:00
if ( connection_by_uuid ) {
2014-12-09 12:15:18 +01:00
const char * old_path ;
old_path = nm_settings_connection_get_filename ( NM_SETTINGS_CONNECTION ( connection_by_uuid ) ) ;
2014-12-10 11:23:20 +01:00
if ( nm_connection_compare ( NM_CONNECTION ( connection_by_uuid ) ,
NM_CONNECTION ( connection_new ) ,
NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS |
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS ) ) {
/* Nothing to do... except updating the path. */
if ( old_path & & g_strcmp0 ( old_path , full_path ) ! = 0 )
nm_log_info ( LOGD_SETTINGS , " keyfile: rename \" %s \" to " NM_KEYFILE_CONNECTION_LOG_FMT " without other changes " , old_path , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) ) ;
} else {
/* An existing connection changed. */
if ( source )
nm_log_info ( LOGD_SETTINGS , " keyfile: update " NM_KEYFILE_CONNECTION_LOG_FMT " from %s " , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) , NM_KEYFILE_CONNECTION_LOG_PATH ( old_path ) ) ;
else if ( ! g_strcmp0 ( old_path , nm_settings_connection_get_filename ( NM_SETTINGS_CONNECTION ( connection_new ) ) ) )
nm_log_info ( LOGD_SETTINGS , " keyfile: update " NM_KEYFILE_CONNECTION_LOG_FMT , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) ) ;
else if ( old_path )
nm_log_info ( LOGD_SETTINGS , " keyfile: rename \" %s \" to " NM_KEYFILE_CONNECTION_LOG_FMT , old_path , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) ) ;
else
nm_log_info ( LOGD_SETTINGS , " keyfile: update and persist " NM_KEYFILE_CONNECTION_LOG_FMT , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) ) ;
if ( ! nm_settings_connection_replace_settings ( NM_SETTINGS_CONNECTION ( connection_by_uuid ) ,
NM_CONNECTION ( connection_new ) ,
FALSE , /* don't set Unsaved */
" keyfile-update " ,
& local ) ) {
2014-12-08 19:02:19 +01:00
/* Shouldn't ever get here as 'connection_new' was verified by the reader already
* and the UUID did not change . */
2014-12-10 11:23:20 +01:00
g_assert_not_reached ( ) ;
}
g_assert_no_error ( local ) ;
2013-05-23 19:05:40 -03:00
}
2014-12-08 21:53:24 +01:00
nm_settings_connection_set_filename ( NM_SETTINGS_CONNECTION ( connection_by_uuid ) , full_path ) ;
g_object_unref ( connection_new ) ;
return connection_by_uuid ;
2013-05-23 19:05:40 -03:00
} else {
2014-12-10 11:23:20 +01:00
if ( source )
nm_log_info ( LOGD_SETTINGS , " keyfile: add connection " NM_KEYFILE_CONNECTION_LOG_FMT , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) ) ;
else
nm_log_info ( LOGD_SETTINGS , " keyfile: new connection " NM_KEYFILE_CONNECTION_LOG_FMT , NM_KEYFILE_CONNECTION_LOG_ARG ( connection_new ) ) ;
2014-12-08 21:53:24 +01:00
g_hash_table_insert ( priv - > connections , g_strdup ( uuid ) , connection_new ) ;
2013-08-08 15:54:32 -05:00
2014-12-08 21:53:24 +01:00
g_signal_connect ( connection_new , NM_SETTINGS_CONNECTION_REMOVED ,
2013-08-08 15:54:32 -05:00
G_CALLBACK ( connection_removed_cb ) ,
self ) ;
2014-12-08 21:53:24 +01:00
2014-12-10 11:23:20 +01:00
if ( ! source ) {
/* Only raise the signal if we were called without source, i.e. if we read the connection from file.
* Otherwise , we were called by add_connection ( ) which does not expect the signal . */
2015-04-16 08:52:20 -04:00
g_signal_emit_by_name ( self , NM_SETTINGS_PLUGIN_CONNECTION_ADDED , connection_new ) ;
2014-12-10 11:23:20 +01:00
}
2014-12-08 21:53:24 +01:00
return connection_new ;
2013-05-23 19:05:40 -03:00
}
}
2008-04-22 14:48:02 +00:00
static void
dir_changed ( GFileMonitor * monitor ,
2010-09-16 15:43:22 -05:00
GFile * file ,
GFile * other_file ,
GFileMonitorEvent event_type ,
gpointer user_data )
2008-04-22 14:48:02 +00:00
{
2015-04-16 08:52:20 -04:00
NMSettingsPlugin * config = NM_SETTINGS_PLUGIN ( user_data ) ;
SettingsPluginKeyfile * self = SETTINGS_PLUGIN_KEYFILE ( config ) ;
2013-05-23 19:05:40 -03:00
NMKeyfileConnection * connection ;
2010-10-29 14:34:33 -05:00
char * full_path ;
2015-01-13 14:09:23 +01:00
gboolean exists ;
2008-04-22 14:48:02 +00:00
2010-10-29 14:34:33 -05:00
full_path = g_file_get_path ( file ) ;
2011-02-04 15:59:45 -06:00
if ( nm_keyfile_plugin_utils_should_ignore_file ( full_path ) ) {
2010-11-16 18:08:48 -06:00
g_free ( full_path ) ;
2010-11-10 16:21:25 +01:00
return ;
}
2015-01-13 14:09:23 +01:00
exists = g_file_test ( full_path , G_FILE_TEST_EXISTS ) ;
2010-11-10 16:21:25 +01:00
2015-01-13 14:09:23 +01:00
nm_log_dbg ( LOGD_SETTINGS , " dir_changed(%s) = %d; file %s " , full_path , event_type , exists ? " exists " : " does not exist " ) ;
2014-12-10 11:23:20 +01:00
2013-04-18 13:54:36 -05:00
connection = find_by_path ( self , full_path ) ;
2008-04-22 14:48:02 +00:00
switch ( event_type ) {
case G_FILE_MONITOR_EVENT_DELETED :
2015-01-13 14:09:23 +01:00
if ( ! exists & & connection )
2015-04-16 08:52:20 -04:00
remove_connection ( SETTINGS_PLUGIN_KEYFILE ( config ) , connection ) ;
2008-04-22 14:48:02 +00:00
break ;
2008-05-09 06:33:30 +00:00
case G_FILE_MONITOR_EVENT_CREATED :
2008-04-22 14:48:02 +00:00
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT :
2015-01-13 14:09:23 +01:00
if ( exists )
2015-04-16 08:52:20 -04:00
update_connection ( SETTINGS_PLUGIN_KEYFILE ( config ) , NULL , full_path , connection , TRUE , NULL , NULL ) ;
2008-04-22 14:48:02 +00:00
break ;
default :
break ;
}
2010-10-29 14:34:33 -05:00
g_free ( full_path ) ;
2008-04-22 14:48:02 +00:00
}
2008-09-24 15:03:33 +00:00
static void
2015-06-05 23:13:12 +02:00
config_changed_cb ( NMConfig * config ,
NMConfigData * config_data ,
NMConfigChangeFlags changes ,
NMConfigData * old_data ,
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfile * self )
2008-09-24 15:03:33 +00:00
{
2015-06-05 23:13:12 +02:00
gs_free char * old_value = NULL , * new_value = NULL ;
2008-09-24 15:03:33 +00:00
2015-12-08 11:47:56 +01:00
old_value = nm_config_data_get_value ( old_data , NM_CONFIG_KEYFILE_GROUP_KEYFILE , NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES , NM_CONFIG_GET_VALUE_TYPE_SPEC ) ;
new_value = nm_config_data_get_value ( config_data , NM_CONFIG_KEYFILE_GROUP_KEYFILE , NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES , NM_CONFIG_GET_VALUE_TYPE_SPEC ) ;
2015-06-05 23:13:12 +02:00
if ( g_strcmp0 ( old_value , new_value ) ! = 0 )
2015-04-16 08:52:20 -04:00
g_signal_emit_by_name ( self , NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED ) ;
2008-09-24 15:03:33 +00:00
}
2008-04-22 14:48:02 +00:00
static void
2015-04-16 08:52:20 -04:00
setup_monitoring ( NMSettingsPlugin * config )
2008-04-22 14:48:02 +00:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( config ) ;
2008-04-22 14:48:02 +00:00
GFile * file ;
GFileMonitor * monitor ;
2013-05-23 19:05:40 -03:00
if ( nm_config_get_monitor_connection_files ( nm_config_get ( ) ) ) {
2015-10-09 18:16:42 +02:00
file = g_file_new_for_path ( nm_keyfile_plugin_get_path ( ) ) ;
2013-05-23 19:05:40 -03:00
monitor = g_file_monitor_directory ( file , G_FILE_MONITOR_NONE , NULL , NULL ) ;
g_object_unref ( file ) ;
2008-04-22 14:48:02 +00:00
2013-05-23 19:05:40 -03:00
if ( monitor ) {
priv - > monitor_id = g_signal_connect ( monitor , " changed " , G_CALLBACK ( dir_changed ) , config ) ;
priv - > monitor = monitor ;
}
2008-04-22 14:48:02 +00:00
}
2008-09-24 15:03:33 +00:00
2015-06-05 23:13:12 +02:00
g_signal_connect ( G_OBJECT ( priv - > config ) ,
NM_CONFIG_SIGNAL_CONFIG_CHANGED ,
G_CALLBACK ( config_changed_cb ) ,
config ) ;
2008-04-22 14:48:02 +00:00
}
2014-12-09 13:50:05 +01:00
static GHashTable *
_paths_from_connections ( GHashTable * connections )
{
GHashTableIter iter ;
NMKeyfileConnection * connection ;
GHashTable * paths = g_hash_table_new ( g_str_hash , g_str_equal ) ;
g_hash_table_iter_init ( & iter , connections ) ;
while ( g_hash_table_iter_next ( & iter , NULL , ( gpointer * ) & connection ) ) {
const char * path = nm_settings_connection_get_filename ( NM_SETTINGS_CONNECTION ( connection ) ) ;
if ( path )
g_hash_table_add ( paths , ( void * ) path ) ;
}
return paths ;
}
static int
_sort_paths ( const char * * f1 , const char * * f2 , GHashTable * paths )
{
struct stat st ;
gboolean c1 , c2 ;
gint64 m1 , m2 ;
c1 = ! ! g_hash_table_contains ( paths , * f1 ) ;
c2 = ! ! g_hash_table_contains ( paths , * f2 ) ;
if ( c1 ! = c2 )
return c1 ? - 1 : 1 ;
m1 = stat ( * f1 , & st ) = = 0 ? ( gint64 ) st . st_mtime : G_MININT64 ;
m2 = stat ( * f2 , & st ) = = 0 ? ( gint64 ) st . st_mtime : G_MININT64 ;
if ( m1 ! = m2 )
return m1 > m2 ? - 1 : 1 ;
return strcmp ( * f1 , * f2 ) ;
}
2013-05-23 19:05:40 -03:00
static void
2015-04-16 08:52:20 -04:00
read_connections ( NMSettingsPlugin * config )
2013-05-23 19:05:40 -03:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfile * self = SETTINGS_PLUGIN_KEYFILE ( config ) ;
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( self ) ;
2013-05-23 19:05:40 -03:00
GDir * dir ;
GError * error = NULL ;
const char * item ;
2014-12-08 21:53:24 +01:00
GHashTable * alive_connections ;
2013-05-23 19:05:40 -03:00
GHashTableIter iter ;
2014-12-08 21:53:24 +01:00
NMKeyfileConnection * connection ;
GPtrArray * dead_connections = NULL ;
guint i ;
2014-12-09 13:50:05 +01:00
GPtrArray * filenames ;
GHashTable * paths ;
2013-05-23 19:05:40 -03:00
2015-10-09 18:16:42 +02:00
dir = g_dir_open ( nm_keyfile_plugin_get_path ( ) , 0 , & error ) ;
2013-05-23 19:05:40 -03:00
if ( ! dir ) {
2014-12-09 12:15:18 +01:00
nm_log_warn ( LOGD_SETTINGS , " keyfile: cannot read directory '%s': (%d) %s " ,
2015-10-09 18:16:42 +02:00
nm_keyfile_plugin_get_path ( ) ,
2013-05-23 19:05:40 -03:00
error ? error - > code : - 1 ,
error & & error - > message ? error - > message : " (unknown) " ) ;
g_clear_error ( & error ) ;
return ;
}
2014-12-08 21:53:24 +01:00
alive_connections = g_hash_table_new ( NULL , NULL ) ;
2013-05-23 19:05:40 -03:00
2014-12-09 13:50:05 +01:00
filenames = g_ptr_array_new_with_free_func ( g_free ) ;
2013-05-23 19:05:40 -03:00
while ( ( item = g_dir_read_name ( dir ) ) ) {
if ( nm_keyfile_plugin_utils_should_ignore_file ( item ) )
continue ;
2015-10-09 18:16:42 +02:00
g_ptr_array_add ( filenames , g_build_filename ( nm_keyfile_plugin_get_path ( ) , item , NULL ) ) ;
2014-12-09 13:50:05 +01:00
}
g_dir_close ( dir ) ;
2013-05-23 19:05:40 -03:00
2014-12-09 13:50:05 +01:00
/* While reloading, we don't replace connections that we already loaded while
* iterating over the files .
*
* To have sensible , reproducible behavior , sort the paths by last modification
* time prefering older files .
*/
paths = _paths_from_connections ( priv - > connections ) ;
g_ptr_array_sort_with_data ( filenames , ( GCompareDataFunc ) _sort_paths , paths ) ;
g_hash_table_destroy ( paths ) ;
for ( i = 0 ; i < filenames - > len ; i + + ) {
2014-12-10 11:23:20 +01:00
connection = update_connection ( self , NULL , filenames - > pdata [ i ] , NULL , FALSE , alive_connections , NULL ) ;
2014-12-08 21:53:24 +01:00
if ( connection )
g_hash_table_add ( alive_connections , connection ) ;
2013-05-23 19:05:40 -03:00
}
2014-12-09 13:50:05 +01:00
g_ptr_array_free ( filenames , TRUE ) ;
2013-05-23 19:05:40 -03:00
2014-12-08 21:53:24 +01:00
g_hash_table_iter_init ( & iter , priv - > connections ) ;
while ( g_hash_table_iter_next ( & iter , NULL , ( gpointer * ) & connection ) ) {
if ( ! g_hash_table_contains ( alive_connections , connection )
& & nm_settings_connection_get_filename ( NM_SETTINGS_CONNECTION ( connection ) ) ) {
if ( ! dead_connections )
dead_connections = g_ptr_array_new ( ) ;
g_ptr_array_add ( dead_connections , connection ) ;
}
}
g_hash_table_destroy ( alive_connections ) ;
if ( dead_connections ) {
for ( i = 0 ; i < dead_connections - > len ; i + + )
remove_connection ( self , dead_connections - > pdata [ i ] ) ;
g_ptr_array_free ( dead_connections , TRUE ) ;
2013-05-23 19:05:40 -03:00
}
}
2008-04-22 14:48:02 +00:00
/* Plugin */
static GSList *
2015-04-16 08:52:20 -04:00
get_connections ( NMSettingsPlugin * config )
2008-04-22 14:48:02 +00:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( config ) ;
2008-04-22 14:48:02 +00:00
2013-04-18 13:54:36 -05:00
if ( ! priv - > initialized ) {
2008-04-22 14:48:02 +00:00
setup_monitoring ( config ) ;
read_connections ( config ) ;
2013-04-18 13:54:36 -05:00
priv - > initialized = TRUE ;
2008-04-22 14:48:02 +00:00
}
2014-07-27 23:55:55 +02:00
return _nm_utils_hash_values_to_slist ( priv - > connections ) ;
2008-04-22 14:48:02 +00:00
}
2013-10-31 15:17:33 -04:00
static gboolean
2015-04-16 08:52:20 -04:00
load_connection ( NMSettingsPlugin * config ,
2013-10-31 15:17:33 -04:00
const char * filename )
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfile * self = SETTINGS_PLUGIN_KEYFILE ( config ) ;
2013-10-31 15:17:33 -04:00
NMKeyfileConnection * connection ;
2015-10-09 18:16:42 +02:00
int dir_len = strlen ( nm_keyfile_plugin_get_path ( ) ) ;
2013-10-31 15:17:33 -04:00
2015-10-09 18:16:42 +02:00
if ( strncmp ( filename , nm_keyfile_plugin_get_path ( ) , dir_len ) ! = 0
2013-10-31 15:17:33 -04:00
| | filename [ dir_len ] ! = ' / '
| | strchr ( filename + dir_len + 1 , ' / ' ) ! = NULL )
return FALSE ;
if ( nm_keyfile_plugin_utils_should_ignore_file ( filename + dir_len + 1 ) )
return FALSE ;
2014-12-10 11:23:20 +01:00
connection = update_connection ( self , NULL , filename , find_by_path ( self , filename ) , TRUE , NULL , NULL ) ;
2013-10-31 15:17:33 -04:00
return ( connection ! = NULL ) ;
}
2013-05-23 19:05:40 -03:00
static void
2015-04-16 08:52:20 -04:00
reload_connections ( NMSettingsPlugin * config )
2013-05-23 19:05:40 -03:00
{
read_connections ( config ) ;
}
2011-01-26 11:38:12 -06:00
static NMSettingsConnection *
2015-04-16 08:52:20 -04:00
add_connection ( NMSettingsPlugin * config ,
2008-08-12 18:39:03 +00:00
NMConnection * connection ,
2013-04-12 16:09:29 -05:00
gboolean save_to_disk ,
2008-08-12 18:39:03 +00:00
GError * * error )
2008-04-22 14:48:02 +00:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfile * self = SETTINGS_PLUGIN_KEYFILE ( config ) ;
2014-12-10 11:23:20 +01:00
gs_free char * path = NULL ;
2010-10-29 14:34:33 -05:00
2013-04-12 16:09:29 -05:00
if ( save_to_disk ) {
2015-07-17 10:34:10 +02:00
if ( ! nm_keyfile_plugin_write_connection ( connection , NULL , FALSE , & path , error ) )
2013-04-12 16:09:29 -05:00
return NULL ;
2010-10-29 14:34:33 -05:00
}
2014-12-10 11:23:20 +01:00
return NM_SETTINGS_CONNECTION ( update_connection ( self , connection , path , NULL , FALSE , NULL , error ) ) ;
2008-04-22 14:48:02 +00:00
}
2008-09-24 15:03:33 +00:00
static GSList *
2015-04-16 08:52:20 -04:00
get_unmanaged_specs ( NMSettingsPlugin * config )
2008-09-24 15:03:33 +00:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( config ) ;
2015-06-05 23:13:12 +02:00
gs_free char * value = NULL ;
2013-03-06 14:00:41 -05:00
2015-12-08 11:47:56 +01:00
value = nm_config_data_get_value ( nm_config_get_data ( priv - > config ) ,
NM_CONFIG_KEYFILE_GROUP_KEYFILE ,
NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES ,
NM_CONFIG_GET_VALUE_TYPE_SPEC ) ;
2015-06-05 23:13:12 +02:00
return nm_match_spec_split ( value ) ;
2008-09-24 15:03:33 +00:00
}
2008-04-22 14:48:02 +00:00
/* GObject */
static void
2015-04-16 08:52:20 -04:00
settings_plugin_keyfile_init ( SettingsPluginKeyfile * plugin )
2008-04-22 14:48:02 +00:00
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( plugin ) ;
2013-04-18 13:54:36 -05:00
2014-06-11 13:24:10 -05:00
priv - > connections = g_hash_table_new_full ( g_str_hash , g_str_equal , g_free , g_object_unref ) ;
2008-04-22 14:48:02 +00:00
}
static void
get_property ( GObject * object , guint prop_id ,
GValue * value , GParamSpec * pspec )
{
switch ( prop_id ) {
2015-04-16 08:52:20 -04:00
case NM_SETTINGS_PLUGIN_PROP_NAME :
2008-04-22 14:48:02 +00:00
g_value_set_string ( value , KEYFILE_PLUGIN_NAME ) ;
break ;
2015-04-16 08:52:20 -04:00
case NM_SETTINGS_PLUGIN_PROP_INFO :
2008-04-22 14:48:02 +00:00
g_value_set_string ( value , KEYFILE_PLUGIN_INFO ) ;
break ;
2015-04-16 08:52:20 -04:00
case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES :
g_value_set_uint ( value , NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS ) ;
2008-09-24 15:03:33 +00:00
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 )
{
switch ( prop_id ) {
2008-04-22 14:48:02 +00:00
default :
G_OBJECT_WARN_INVALID_PROPERTY_ID ( object , prop_id , pspec ) ;
break ;
}
}
2015-08-11 10:43:46 +02:00
static void
constructed ( GObject * object )
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( object ) ;
2015-08-11 10:43:46 +02:00
priv - > config = g_object_ref ( nm_config_get ( ) ) ;
if ( nm_config_data_has_value ( nm_config_get_data_orig ( priv - > config ) ,
2015-12-08 11:47:56 +01:00
NM_CONFIG_KEYFILE_GROUP_KEYFILE ,
NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME ,
2015-08-11 10:43:46 +02:00
NM_CONFIG_GET_VALUE_RAW ) )
nm_log_warn ( LOGD_SETTINGS , " keyfile: 'hostname' option is deprecated and has no effect " ) ;
}
2008-04-22 14:48:02 +00:00
static void
dispose ( GObject * object )
{
2015-04-16 08:52:20 -04:00
SettingsPluginKeyfilePrivate * priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ( object ) ;
2008-04-22 14:48:02 +00:00
if ( priv - > monitor ) {
2016-01-04 10:35:11 +01:00
nm_clear_g_signal_handler ( priv - > monitor , & priv - > monitor_id ) ;
2008-04-22 14:48:02 +00:00
g_file_monitor_cancel ( priv - > monitor ) ;
2015-06-05 22:59:48 +02:00
g_clear_object ( & priv - > monitor ) ;
2008-04-22 14:48:02 +00:00
}
2013-04-18 13:54:36 -05:00
if ( priv - > connections ) {
g_hash_table_destroy ( priv - > connections ) ;
priv - > connections = NULL ;
}
2008-04-22 14:48:02 +00:00
2015-06-05 23:13:12 +02:00
if ( priv - > config ) {
g_signal_handlers_disconnect_by_func ( priv - > config , config_changed_cb , object ) ;
g_clear_object ( & priv - > config ) ;
}
2015-04-16 08:52:20 -04:00
G_OBJECT_CLASS ( settings_plugin_keyfile_parent_class ) - > dispose ( object ) ;
2008-04-22 14:48:02 +00:00
}
static void
2015-04-16 08:52:20 -04:00
settings_plugin_keyfile_class_init ( SettingsPluginKeyfileClass * req_class )
2008-04-22 14:48:02 +00:00
{
GObjectClass * object_class = G_OBJECT_CLASS ( req_class ) ;
2015-04-16 08:52:20 -04:00
g_type_class_add_private ( req_class , sizeof ( SettingsPluginKeyfilePrivate ) ) ;
2008-04-22 14:48:02 +00:00
2015-08-11 10:43:46 +02:00
object_class - > constructed = constructed ;
2008-04-22 14:48:02 +00:00
object_class - > dispose = dispose ;
object_class - > get_property = get_property ;
2008-09-24 15:03:33 +00:00
object_class - > set_property = set_property ;
2008-04-22 14:48:02 +00:00
g_object_class_override_property ( object_class ,
2015-04-16 08:52:20 -04:00
NM_SETTINGS_PLUGIN_PROP_NAME ,
NM_SETTINGS_PLUGIN_NAME ) ;
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
g_object_class_override_property ( object_class ,
2015-04-16 08:52:20 -04:00
NM_SETTINGS_PLUGIN_PROP_INFO ,
NM_SETTINGS_PLUGIN_INFO ) ;
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
g_object_class_override_property ( object_class ,
2015-04-16 08:52:20 -04:00
NM_SETTINGS_PLUGIN_PROP_CAPABILITIES ,
NM_SETTINGS_PLUGIN_CAPABILITIES ) ;
2008-04-22 14:48:02 +00:00
}
static void
core: fix interface type names
A GObject interface, like a class, has two different C types
associated with it; the type of the "class" struct (eg, GObjectClass,
GFileIface), and the type of instances of that class/interface (eg,
GObject, GFile).
NetworkManager was doing this wrong though, and using the same C type
to point to both the interface's class struct and to instances of the
interface. This ends up not actually breaking anything, since for
interface types, the instance type is a non-dereferenceable dummy type
anyway. But it's wrong, since if, eg, NMDeviceFactory is a struct type
containing members "start", "device_added", etc, then you should not
be using an NMDeviceFactory* to point to an object that does not
contain those members.
Fix this by splitting NMDeviceFactory into NMDeviceFactoryInterface
and NMDeviceFactory; by splitting NMConnectionProvider into
NMConnectionProviderInterface and NMConnectionProvider; and by
splitting NMSettingsPlugin into NMSettingsPluginInterface and
NMSettingsPlugin; and then use the right types in the right places.
As a bonus, this also lets us now use G_DEFINE_INTERFACE.
2015-04-16 09:05:49 -04:00
settings_plugin_interface_init ( NMSettingsPluginInterface * plugin_iface )
2008-04-22 14:48:02 +00:00
{
/* interface implementation */
core: fix interface type names
A GObject interface, like a class, has two different C types
associated with it; the type of the "class" struct (eg, GObjectClass,
GFileIface), and the type of instances of that class/interface (eg,
GObject, GFile).
NetworkManager was doing this wrong though, and using the same C type
to point to both the interface's class struct and to instances of the
interface. This ends up not actually breaking anything, since for
interface types, the instance type is a non-dereferenceable dummy type
anyway. But it's wrong, since if, eg, NMDeviceFactory is a struct type
containing members "start", "device_added", etc, then you should not
be using an NMDeviceFactory* to point to an object that does not
contain those members.
Fix this by splitting NMDeviceFactory into NMDeviceFactoryInterface
and NMDeviceFactory; by splitting NMConnectionProvider into
NMConnectionProviderInterface and NMConnectionProvider; and by
splitting NMSettingsPlugin into NMSettingsPluginInterface and
NMSettingsPlugin; and then use the right types in the right places.
As a bonus, this also lets us now use G_DEFINE_INTERFACE.
2015-04-16 09:05:49 -04:00
plugin_iface - > get_connections = get_connections ;
plugin_iface - > load_connection = load_connection ;
plugin_iface - > reload_connections = reload_connections ;
plugin_iface - > add_connection = add_connection ;
plugin_iface - > get_unmanaged_specs = get_unmanaged_specs ;
2008-04-22 14:48:02 +00:00
}
2011-01-12 18:12:23 -06:00
GObject *
2013-03-12 11:11:54 -04:00
nm_settings_keyfile_plugin_new ( void )
2008-04-22 14:48:02 +00:00
{
2015-04-16 08:52:20 -04:00
return g_object_new ( SETTINGS_TYPE_PLUGIN_KEYFILE , NULL ) ;
2008-04-22 14:48:02 +00:00
}