Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ypbind Abstract out some of the handling of the yps...
details: https://anonhg.NetBSD.org/src/rev/27cc2aef1b24
branches: trunk
changeset: 765300:27cc2aef1b24
user: dholland <dholland%NetBSD.org@localhost>
date: Tue May 24 06:57:30 2011 +0000
description:
Abstract out some of the handling of the ypservers file.
diffstat:
usr.sbin/ypbind/ypbind.c | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
diffs (87 lines):
diff -r 3b2c8babe279 -r 27cc2aef1b24 usr.sbin/ypbind/ypbind.c
--- a/usr.sbin/ypbind/ypbind.c Tue May 24 06:57:04 2011 +0000
+++ b/usr.sbin/ypbind/ypbind.c Tue May 24 06:57:30 2011 +0000
@@ -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 <deraadt%fsa.ca@localhost>
@@ -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);
Home |
Main Index |
Thread Index |
Old Index