From Keith.White@site.uottawa.ca  Wed Apr 30 08:20:44 2003
Return-Path: <Keith.White@site.uottawa.ca>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 27E6137B401
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Apr 2003 08:20:44 -0700 (PDT)
Received: from mail.site.uottawa.ca (mailn.site.uottawa.ca [137.122.89.142])
	by mx1.FreeBSD.org (Postfix) with ESMTP id AD23243F3F
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Apr 2003 08:20:40 -0700 (PDT)
	(envelope-from Keith.White@site.uottawa.ca)
Received: from admin16.site.uottawa.ca (admin16.site.uottawa.ca [137.122.90.250])
	by mail.site.uottawa.ca (8.9.3/8.9.3) with ESMTP id LAA52899
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Apr 2003 11:20:39 -0400 (EDT)
Received: from admin16.site.uottawa.ca (localhost [127.0.0.1])
	by admin16.site.uottawa.ca (8.12.9/8.12.9) with ESMTP id h3UFKdW5029291
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Apr 2003 11:20:39 -0400 (EDT)
	(envelope-from kwhite@admin16.site.uottawa.ca)
Received: (from kwhite@localhost)
	by admin16.site.uottawa.ca (8.12.9/8.12.9/Submit) id h3UFKd9R029290;
	Wed, 30 Apr 2003 11:20:39 -0400 (EDT)
Message-Id: <200304301520.h3UFKd9R029290@admin16.site.uottawa.ca>
Date: Wed, 30 Apr 2003 11:20:39 -0400 (EDT)
From: Keith White <Keith.White@site.uottawa.ca>
Reply-To: Keith White <Keith.White@site.uottawa.ca>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ypmatch doesn't match keys in legacy NIS servers
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         51628
>Category:       bin
>Synopsis:       [nis] ypmatch doesn't match keys in legacy NIS servers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 30 08:30:06 PDT 2003
>Closed-Date:    
>Last-Modified:  Sun Sep 12 00:22:17 GMT 2004
>Originator:     Keith White
>Release:        FreeBSD 4.8-STABLE i386
>Organization:
SITE, University of Ottawa
>Environment:
System: FreeBSD admin16.site.uottawa.ca 4.8-STABLE FreeBSD 4.8-STABLE #32: Mon Apr 28 13:44:12 EDT 2003 kwhite@admin16.site.uottawa.ca:/usr/obj/usr/src/sys/XBAT i386

>Description:
ypmatch does not match keys in NIS databases that include the NULL
in the key field.

Databases that started out on SunOS 4.X, say, include NULL in both
the key and data fields.  This makes it impossible to use ypmatch
to check for the existence of keys since the terminating NULL
is removed prior to calling yp_match().

Try this against a SunOS 4.x NIS server: 
  $ ypmatch @ aliases
  ypmatch: can't match key @ in map mail.aliases. reason: No such key in map

Try it at the same time on a Solaris host:
  $ ypmatch @ aliases
  @

(FWIW the '@' key is used to signify that the NIS aliases database is
up-to-date.  When it doesn't exist the aliases database is in the
process of being updated.)

>How-To-Repeat:
>Fix:

The following patch will do another yp_match() call including the
terminating NULL in the key if the first call failed.

--- ypmatch.c.orig	Wed Apr 30 10:02:54 2003
+++ ypmatch.c	Wed Apr 30 10:04:55 2003
@@ -29,7 +29,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/ypmatch/ypmatch.c,v 1.7.2.2 2002/02/15 00:46:56 des Exp $";
+  "$FreeBSD: src/usr.bin/ypmatch/ypmatch.c,v 1.7.2.X 2002/02/15 00:46:56 des Exp $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -117,6 +117,18 @@
 
 		r = yp_match(domainname, inmap, inkey,
 			strlen(inkey), &outbuf, &outbuflen);
+/*
+	If we failed, try again including the terminating NULL in the key.
+	Some NIS servers include the NULL, notably SunOS 4.X.
+*/
+		if (r != 0 && r != YPERR_YPBIND) {
+			r = yp_match(domainname, inmap, inkey,
+				strlen(inkey)+1, &outbuf, &outbuflen);
+			if (r == 0 && outbuf[outbuflen-1] == '\0')  {
+/* since we added a NULL, let's remove it from the result */
+				--outbuflen;
+			}
+		}
 		switch (r) {
 		case 0:
 			if (key)
>Release-Note:
>Audit-Trail:
>Unformatted:
