Re: NIS API changes

On Thu, 2008-08-07 at 16:53 -0400, Dan Williams wrote:
> Hi,
> Specifically, the "nis-domainname" and "nis-servers" properties have
> been removed from the NMIP4Config object as exported over D-Bus and from
> libnm-glib.  I've removed any code dealing with NIS from NM itself; this
> is better handled through dispatcher scripts.
> The NIS information in reality only comes via DHCP, and thus doesn't
> need to be composited with anything.  I've attached a compile-tested
> dispatcher script that moves the code that was previously in
> NetworkManagerSuSE.c into a standalone helper.  To enable this, I
> earlier committed functionality in the dispatcher to dump available DHCP
> options into the dispatcher script environment.

This time with the attachment...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#include "shvar.h"

#define SYSCONFDIR "/etc"

static void
update_nis (void)
	shvarFile *file;
	char *nis_domain, *buf, *tmp, *name;

	nis_domain = getenv ("DHCP4_NIS_DOMAIN");

	name = g_strdup_printf (SYSCONFDIR"/sysconfig/network/dhcp");
	file = svNewFile (name);
	g_free (name);
	if (!file)

	buf = svGetValue (file, "DHCLIENT_SET_DOMAINNAME");
	if (!buf)
		goto out_close;

	if ((!strcmp (buf, "yes")) && nis_domain && (setdomainname (nis_domain, strlen (nis_domain)) < 0))
			g_warning ("Could not set nis domain name.");
	free (buf);

	buf = svGetValue (file, "DHCLIENT_MODIFY_NIS_CONF");
	if (!buf)
		goto out_close;

	if (strcmp (buf, "yes"))
		goto out_free_buf;

	tmp = getenv ("DHCP4_NIS_SERVERS");
	if (tmp && strlen (tmp)) {
		char **nis_servers, **p;
		struct stat sb;
		FILE *ypconf = NULL;

		nis_servers = g_strsplit (tmp, " ", 0);

		/* write out yp.conf and restart the daemon */
		ypconf = fopen ("/etc/yp.conf", "w");
		if (ypconf) {
			fprintf (ypconf, "# generated by NetworkManager, do not edit!\n\n");
			for (p = nis_servers; *p; p++) {
				struct in_addr temp_addr;
				char addr_buf[INET_ADDRSTRLEN+1];

				if (inet_pton (AF_INET, *p, &temp_addr) > 0)
					fprintf (ypconf, "domain %s server %s\n", nis_domain, *p);
					g_warning ("%s: error validating IP4 address %s", __func__, *p);
			fprintf (ypconf, "\n");
			fclose (ypconf);
		} else
			g_warning ("Could not commit NIS changes to /etc/yp.conf.");

		g_strfreev (nis_servers);

		if (stat ("/usr/sbin/rcautofs", &sb) != -1) {
			g_message ("Restarting autofs.");
			system ("/usr/sbin/rcautofs reload");

	free (buf);

	svCloseFile (file);

int main (int argc, char *argv[])
	const char *iface;
	const char *action;

	if (argc < 3)
		return 1;

	iface = argv[1];
	action = argv[2];
	if (strcmp (action, "up"))
		update_nis ();

	return 0;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]