mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 20:40:06 +01:00
2005-06-10 Dan Williams <dcbw@redhat.com>
* src/backends/NetworkManagerRedHat.c - (get_current_profile_name): new function, grab current network profile name from /etc/sysconfig/network - (set_ip4_config_from_resolv_conf): new function, parse a resolv.conf and update an IP4 Config structure's settings from it - (nm_system_device_get_system_config): if we're using static IP on this device, get DNS info from current network profile git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@661 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
b3bcfac619
commit
34b9824214
2 changed files with 125 additions and 0 deletions
10
ChangeLog
10
ChangeLog
|
|
@ -1,3 +1,13 @@
|
|||
2005-06-10 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/backends/NetworkManagerRedHat.c
|
||||
- (get_current_profile_name): new function, grab current network profile name from
|
||||
/etc/sysconfig/network
|
||||
- (set_ip4_config_from_resolv_conf): new function, parse a resolv.conf and
|
||||
update an IP4 Config structure's settings from it
|
||||
- (nm_system_device_get_system_config): if we're using static IP on this device,
|
||||
get DNS info from current network profile
|
||||
|
||||
2005-06-09 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
Patch from Robert Love:
|
||||
|
|
|
|||
|
|
@ -355,6 +355,106 @@ typedef struct RHSystemConfigData
|
|||
gboolean use_dhcp;
|
||||
} RHSystemConfigData;
|
||||
|
||||
|
||||
/*
|
||||
* get_current_profile_name
|
||||
*
|
||||
* Retrieve the current network profile, if any
|
||||
*
|
||||
*/
|
||||
static char *get_current_profile_name (void)
|
||||
{
|
||||
shvarFile * file;
|
||||
char * buf;
|
||||
|
||||
if (!(file = svNewFile (SYSCONFDIR"/sysconfig/network")))
|
||||
return NULL;
|
||||
|
||||
buf = svGetValue (file, "CURRENT_PROFILE");
|
||||
if (!buf)
|
||||
buf = strdup ("default");
|
||||
svCloseFile (file);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set_ip4_config_from_resolv_conf
|
||||
*
|
||||
* Add nameservers and search names from a resolv.conf format file.
|
||||
*
|
||||
*/
|
||||
static void set_ip4_config_from_resolv_conf (const char *filename, NMIP4Config *ip4_config)
|
||||
{
|
||||
char * contents = NULL;
|
||||
char ** split_contents = NULL;
|
||||
int i, len;
|
||||
|
||||
g_return_if_fail (filename != NULL);
|
||||
g_return_if_fail (ip4_config != NULL);
|
||||
|
||||
if (!g_file_get_contents (filename, &contents, NULL, NULL) || (contents == NULL))
|
||||
return;
|
||||
|
||||
if (!(split_contents = g_strsplit (contents, "\n", 0)))
|
||||
goto out;
|
||||
|
||||
len = g_strv_length (split_contents);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
char *line = split_contents[i];
|
||||
|
||||
/* Ignore comments */
|
||||
if (!line || (line[0] == ';'))
|
||||
continue;
|
||||
|
||||
line = g_strstrip (line);
|
||||
if ((strncmp (line, "search", 6) == 0) && (strlen (line) > 6))
|
||||
{
|
||||
char *searches = g_strdup (line + 7);
|
||||
char **split_searches = NULL;
|
||||
|
||||
if (!searches || !strlen (searches))
|
||||
continue;
|
||||
|
||||
/* Allow space-separated search domains */
|
||||
if (split_searches == g_strsplit (searches, " ", 0))
|
||||
{
|
||||
int m, srch_len;
|
||||
|
||||
srch_len = g_strv_length (split_searches);
|
||||
for (m = 0; m < srch_len; m++)
|
||||
{
|
||||
if (split_searches[m])
|
||||
nm_ip4_config_add_domain (ip4_config, split_searches[m]);
|
||||
}
|
||||
g_strfreev (split_searches);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Only 1 item, add the whole line */
|
||||
nm_ip4_config_add_domain (ip4_config, searches);
|
||||
}
|
||||
|
||||
g_free (searches);
|
||||
}
|
||||
else if ((strncmp (line, "nameserver", 10) == 0) && (strlen (line) > 10))
|
||||
{
|
||||
guint32 addr = (guint32) (inet_addr (line + 11));
|
||||
|
||||
if (addr != (guint32) -1)
|
||||
nm_ip4_config_add_nameserver (ip4_config, addr);
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (split_contents);
|
||||
|
||||
out:
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_system_device_get_system_config
|
||||
*
|
||||
|
|
@ -466,6 +566,21 @@ void *nm_system_device_get_system_config (NMDevice *dev)
|
|||
}
|
||||
}
|
||||
|
||||
/* If we're using Static IP, grab DNS servers from the profile's config file */
|
||||
if (!sys_data->use_dhcp)
|
||||
{
|
||||
char * cur_profile_name = get_current_profile_name ();
|
||||
|
||||
if (cur_profile_name)
|
||||
{
|
||||
char *filename = g_strdup_printf (SYSCONFDIR"/sysconfig/networking/profiles/%s/resolv.conf", cur_profile_name);
|
||||
|
||||
set_ip4_config_from_resolv_conf (filename, sys_data->config);
|
||||
g_free (filename);
|
||||
g_free (cur_profile_name);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
|
||||
nm_debug (" DHCP=%d\n", sys_data->use_dhcp);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue