Module Name:    src
Committed By:   dholland
Date:           Tue May 24 06:57:30 UTC 2011

Modified Files:
        src/usr.sbin/ypbind: ypbind.c

Log Message:
Abstract out some of the handling of the ypservers file.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.sbin/ypbind/ypbind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.70 src/usr.sbin/ypbind/ypbind.c:1.71
--- src/usr.sbin/ypbind/ypbind.c:1.70	Tue May 24 06:57:04 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:57:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.70 2011/05/24 06:57:04 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.71 2011/05/24 06:57:30 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <[email protected]>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef LINT
-__RCSID("$NetBSD: ypbind.c,v 1.70 2011/05/24 06:57:04 dholland Exp $");
+__RCSID("$NetBSD: ypbind.c,v 1.71 2011/05/24 06:57:30 dholland Exp $");
 #endif
 
 #include <sys/types.h>
@@ -151,6 +151,23 @@
 }
 
 ////////////////////////////////////////////////////////////
+// ypservers file
+
+/*
+ * Get pathname for the ypservers file for a given domain
+ * (/var/yp/binding/DOMAIN.ypservers)
+ */
+static const char *
+ypservers_filename(const char *domain)
+{
+	static char ret[PATH_MAX];
+
+	(void)snprintf(ret, sizeof(ret), "%s/%s%s",
+			BINDINGDIR, domain, YPSERVERSSUFF);
+	return ret;
+}
+
+////////////////////////////////////////////////////////////
 // struct _dom_binding
 
 static struct _dom_binding *
@@ -612,8 +629,14 @@
 static int
 direct(char *buf, int outlen)
 {
+	/*
+	 * XXX I don't see how this can work if we're binding multiple domains.
+	 * Also, what if someone's editor unlinks and replaces the file?
+	 */
 	static FILE *df;
 	static char ypservers_path[MAXPATHLEN];
+
+	const char *path;
 	char line[_POSIX2_LINE_MAX];
 	char *p;
 	struct hostent *hp;
@@ -623,8 +646,8 @@
 	if (df)
 		rewind(df);
 	else {
-		(void)snprintf(ypservers_path, sizeof(ypservers_path),
-		    "%s/%s%s", BINDINGDIR, domainname, YPSERVERSSUFF);
+		path = ypservers_filename(domainname);
+		strcpy(ypservers_path, path);
 		df = fopen(ypservers_path, "r");
 		if (df == NULL) {
 			yp_log(LOG_ERR, "%s: ", ypservers_path);
@@ -1053,7 +1076,7 @@
 	fd_set fdsr;
 	int width, lockfd;
 	int evil = 0, one;
-	char pathname[MAXPATHLEN];
+	const char *pathname;
 	struct stat st;
 
 	setprogname(argv[0]);
@@ -1070,8 +1093,7 @@
 	 * Note that we can still override direct mode by passing
 	 * the -broadcast flag.
 	 */
-	(void)snprintf(pathname, sizeof(pathname), "%s/%s%s", BINDINGDIR,
-	    domainname, YPSERVERSSUFF);
+	pathname = ypservers_filename(domainname);
 	if (stat(pathname, &st) < 0) {
 		DPRINTF("%s does not exist, defaulting to broadcast\n",
 			pathname);

Reply via email to