changeset 13174:317a09ef2c51

6861238 N2L: ypserv doesn't store hostnames in lowercase in the key-column in hosts.byname
author Ben Chang <Benjamin.Chang@Oracle.COM>
date Wed, 18 Aug 2010 10:13:15 -0700
parents f04a293f3233
children 9747db92c2e8
files usr/src/lib/libnisdb/yptol/dit_access.c usr/src/lib/libnisdb/yptol/dit_access_utils.c usr/src/lib/libnisdb/yptol/dit_access_utils.h
diffstat 3 files changed, 71 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/lib/libnisdb/yptol/dit_access.c	Tue Aug 17 14:37:41 2010 -0700
+++ b/usr/src/lib/libnisdb/yptol/dit_access.c	Wed Aug 18 10:13:15 2010 -0700
@@ -19,12 +19,9 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * DESCRIPTION: Contains top level functions to read/write to the DIT. These
  *		are the API between the shim and the mapping system.
@@ -615,6 +612,16 @@
 	int			next_print = PRINT_FREQ;
 	int			search_flag = SUCCESS;
 
+	int			m;
+
+	/* list of maps whose keys will be transliterated to lowercase */
+	char			*xlate_to_lcase_maps[] = {
+		"hosts.byname",
+		"ipnodes.byname",
+		NULL
+	};
+	bool_t			xlate_to_lcase = FALSE;
+
 	if (!map || !map->map_name || !map->domain) {
 		return (FAILURE);
 	}
@@ -692,6 +699,20 @@
 		return (FAILURE);
 	}
 
+	/*
+	 * set xlate_to_lcase to TRUE if map_name is found in
+	 * xlate_to_lcase_maps[]
+	 */
+	m = 0;
+	while (xlate_to_lcase_maps[m] != NULL) {
+		if (strncmp(map->map_name, xlate_to_lcase_maps[m],
+			strlen(xlate_to_lcase_maps[m])) == 0) {
+			xlate_to_lcase = TRUE;
+			break;
+		}
+		++m;
+	}
+
 	/* Try each mapping for the map */
 	for (flag = 0; t != 0 && search_flag != FAILURE; t = t->next) {
 
@@ -802,7 +823,7 @@
 
 				/* Obtain the datum for key */
 				datkey = getKeyFromRuleValue(t, &rv[i],
-						&nv, &statP);
+				    &nv, &statP, xlate_to_lcase);
 				if (datkey == 0) {
 					logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 						"%s: Unable to obtain NIS "
--- a/usr/src/lib/libnisdb/yptol/dit_access_utils.c	Tue Aug 17 14:37:41 2010 -0700
+++ b/usr/src/lib/libnisdb/yptol/dit_access_utils.c	Wed Aug 18 10:13:15 2010 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,9 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * DESCRIPTION:	Contains dit_access interface support functions.
  */
@@ -55,6 +51,9 @@
 #include "yptol.h"
 #include "dit_access_utils.h"
 
+#define	YPMULTI		"YP_MULTI_"
+#define	YPMULTISZ	9		/* == strlen(YPMULTI) */
+
 /*
  * Returns 'map,domain.'
  */
@@ -852,8 +851,9 @@
 
 datum *
 getKeyFromRuleValue(__nis_table_mapping_t *t, __nis_rule_value_t *rv, int *nv,
-					int *statP) {
-	int	i, j;
+    int *statP, bool_t xlate_to_lcase)
+{
+	int	i, j, k;
 	datum	*key = 0;
 	char	*str;
 	char	*myself = "getKeyFromRuleValue";
@@ -868,7 +868,7 @@
 		if (rv->colName[i] == 0)
 			continue;
 		if (strcasecmp(N2LKEY, rv->colName[i]) == 0 ||
-				strcasecmp(N2LIPKEY, rv->colName[i]) == 0) {
+		    strcasecmp(N2LIPKEY, rv->colName[i]) == 0) {
 			if ((*nv = rv->colVal[i].numVals) == 0)
 				return (0);
 			if ((key = am(myself, sizeof (key[0]) * *nv)) == 0) {
@@ -881,15 +881,15 @@
 					key[j].dptr = 0;
 				} else {
 					if (verifyIndexMatch(t, 0, 0,
-							rv->colName[i],
-								str) == 0) {
+					    rv->colName[i], str) == 0) {
 						key[j].dsize = 0;
 						key[j].dptr = 0;
 						continue;
 					}
+
 					key[j].dsize = strlen(str);
 					key[j].dptr = am(myself,
-							key[j].dsize + 1);
+					    key[j].dsize + 1);
 					if (key[j].dptr == 0) {
 						*statP = MAP_NO_MEMORY;
 						for (--j; j >= 0; j--)
@@ -897,7 +897,33 @@
 						sfree(key);
 						return (0);
 					}
-					bcopy(str, key[j].dptr, key[j].dsize);
+
+					/* transliterate key to lowercase */
+					if (xlate_to_lcase == TRUE) {
+
+						/*
+						 * For multi-homed
+						 * entries, skip over
+						 * "YP_MULTI_" prefix.
+						 */
+						k = 0;
+						if (strncmp(YPMULTI, str,
+						    YPMULTISZ) == 0) {
+							k = YPMULTISZ;
+							bcopy(str, key[j].dptr,
+							    YPMULTISZ);
+						}
+						while (k < key[j].dsize) {
+							key[j].dptr[k] =
+							    (char)tolower(
+							    (int)(uchar_t)
+							    str[k]);
+							k++;
+						}
+					} else {
+						bcopy(str, key[j].dptr,
+						    key[j].dsize);
+					}
 				}
 			}
 			return (key);
--- a/usr/src/lib/libnisdb/yptol/dit_access_utils.h	Tue Aug 17 14:37:41 2010 -0700
+++ b/usr/src/lib/libnisdb/yptol/dit_access_utils.h	Wed Aug 18 10:13:15 2010 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,15 +19,12 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 #ifndef _DIT_ACCESS_UTILS_H
 #define	_DIT_ACCESS_UTILS_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -73,7 +69,8 @@
 extern datum			*ruleValueToDatum(__nis_table_mapping_t *t,
 				__nis_rule_value_t *rv, int *statP);
 extern datum 			*getKeyFromRuleValue(__nis_table_mapping_t *t,
-				__nis_rule_value_t *rv, int *nv, int *statP);
+				__nis_rule_value_t *rv, int *nv, int *statP,
+				bool_t xlate_to_lcase);
 extern const char		*getObjectClass(char *rdn);
 extern suc_code			makeNISObject(char *domain, char *dn);
 extern suc_code			addNISObject(char *domain, char *dn,