summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-03-31 16:50:26 +0200
committerJiří Klimeš <jklimes@redhat.com>2014-03-31 16:53:28 +0200
commitbd2a5e11477a66373386d3bb1ebba2d206f8c858 (patch)
tree9a0f7deeaf4a7b885247c2c2a444b1aba4c77981
parent70f32fe3f30527e6cb91b22d87a68c13d3a59546 (diff)
downloadNetworkManager-bd2a5e11477a66373386d3bb1ebba2d206f8c858.tar.gz
ifcfg-rh: use nm_utils_file_set_contents() in ifcfg-rh's plugin_set_hostname()
-rw-r--r--src/settings/plugins/ifcfg-rh/plugin.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c
index 317c1bfdc9..2c1406e623 100644
--- a/src/settings/plugins/ifcfg-rh/plugin.c
+++ b/src/settings/plugins/ifcfg-rh/plugin.c
@@ -27,8 +27,6 @@
#include <errno.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <gmodule.h>
#include <glib-object.h>
@@ -39,10 +37,6 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#ifdef HAVE_SELINUX
-#include <selinux/selinux.h>
-#endif
-
#include <nm-setting-connection.h>
#include "common.h"
@@ -58,6 +52,7 @@
#include "reader.h"
#include "writer.h"
#include "utils.h"
+#include "NetworkManagerUtils.h"
#define DBUS_SERVICE_NAME "com.redhat.ifcfgrh1"
#define DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1"
@@ -674,30 +669,9 @@ plugin_set_hostname (SCPluginIfcfg *plugin, const char *hostname)
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
shvarFile *network;
char *hostname_eol;
- gboolean ret;
-#if HAVE_SELINUX
- security_context_t se_ctx_prev, se_ctx = NULL;
- struct stat file_stat = { .st_mode = 0 };
-
- /* Get default context for HOSTNAME_FILE and set it for fscreate */
- stat (HOSTNAME_FILE, &file_stat);
- matchpathcon (HOSTNAME_FILE, file_stat.st_mode, &se_ctx);
- matchpathcon_fini ();
- getfscreatecon (&se_ctx_prev);
- setfscreatecon (se_ctx);
-#endif
hostname_eol = g_strdup_printf ("%s\n", hostname);
- ret = g_file_set_contents (HOSTNAME_FILE, hostname_eol, -1, NULL);
-
-#if HAVE_SELINUX
- /* Restore previous context and cleanup */
- setfscreatecon (se_ctx_prev);
- freecon (se_ctx);
- freecon (se_ctx_prev);
-#endif
-
- if (!ret) {
+ if (!nm_utils_file_set_contents (HOSTNAME_FILE, hostname_eol, -1, NULL)) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Could not save hostname: failed to create/open " HOSTNAME_FILE);
g_free (hostname_eol);
return FALSE;