2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A * Log a message to the appropriate place. 2N/A * Only log LOG_INFO priority if 'verbose' is on, or if 2N/A * msgtype is MSG_ALWAYS. 2N/A /* Make sure we don't log the same message too often */ 2N/A * If the last character in 'fmt' wasn't a '\n', write one 2N/A "%s: pthread_setspecific() => %d",
2N/A * Allocate zero-initialized memory of the specified 'size'. If the 2N/A * allocation fails, log a message and return NULL. Allocation of 2N/A * zero bytes is legal, and returns a NULL pointer. 2N/A * Return the length of a string, just like strlen(), but don't croak 2N/A * on a NULL pointer. 2N/A * If allocate==0, return 'str'; othewise, duplicate the string just 2N/A * like strdup(), but don't die if 'str' is a NULL pointer. 2N/A * Concatenate strings like strcat(), but don't expire if passed a 2N/A * NULL pointer or two. If deallocate!=0, free() the input strings. 2N/A * Counters for memory errors. Note that we don't protect access, 2N/A * so the values aren't entirely reliable in an MT application. 2N/A/* free() the input, but don't pass away if it's NULL */ 2N/A /* NULL pointer OK */ 2N/A * For use in the debugger, when we need to detect free of a 2N/A * All addresses returned by malloc() and friends are "suitably 2N/A * aligned for any use", so they should fall on eight-byte boundaries. 2N/A if (((
unsigned long)
ptr %
8) != 0) {
2N/A * Malloc:ed memory should have the length (four bytes), starting 2N/A * eight bytes before the block, and with the least-significant 2N/A#
endif /* NISDB_LDAP_DEBUG */ 2N/A /* Finally, we believe it's OK to free() the pointer */ 2N/A * If a __nis_single_value_t represents a string, the length count may or may 2N/A * not include a concluding NUL. Hence this function, which returns the last 2N/A * non-NUL character of the value. 2N/A const char *
myself =
"appendString2SingleVal";
2N/A * If 'str' is NULL or empty, just return NULL so that the caller 2N/A /* Caller does nothing; let's hope for the best... */ 2N/A * Do the equivalent of a strcmp() between a string and a string-valued 2N/A * __nis_single_value_t. 2N/A * Do the equivalent of a strcasecmp() between a string and a string-valued 2N/A * __nis_single_value_t. 2N/A * vsprintf the 'fmt' and 'ap' to a buffer, then concatenate the 2N/A /* Find out how large the new buffer needs to be */ 2N/A /* Don't count the NUL. This enables us to concatenate correctly */ 2N/A/* Generic print buffer */ 2N/A/* sprintf to the generic __nis_buffer_t */ 2N/A/* sprintf to the specified __nis_buffer_t */ 2N/A/* Copy 'buf' to the specified __nis_buffer_t */ 2N/A * Make buffer one byte larger than the lengths indicate. This 2N/A * gives us room to append a NUL, so that we can mix string and 2N/A * non-string copies into the buffer, and still end up with 2N/A * something that can be sent to printf(), strcat(), etc. 2N/A /* Put a NUL at the end, just in case we printf() */ 2N/A/* Like bc2buf(), but remove any trailing NUL bytes */ 2N/A /* Snip off trailing NULs */ 2N/A/* Copy 'buf' to the generic __nis_buffer_t */ 2N/A/* Like c2buf(), but remove trailing NUL bytes */ 2N/A/* How many times we try write(2) if it fails */ 2N/A/* Output the generic __nis_buffer_t to stdout */ 2N/A * Determine if the given string is an IP address (IPv4 or IPv6). 2N/A * If so, it converts it to the format as required by rfc2307bis 2N/A * and *newaddr will point to the new Address. 2N/A * Returns -2 : error 2N/A * -1 : not an IP address 2N/A * 0 : IP address not supported by rfc2307bis 2N/A /* skip leading whitespaces */ 2N/A /* skip trailing whitespaces */ 2N/A for (e =
len -
1; (e > s) && (
addr[e] ==
' ' ||
addr[e] ==
'\t'); e--);
2N/A * IPv4-compatible IPv6 address and IPv4-mapped 2N/A * IPv6 addresses not allowed by rfc2307bis 2N/A * Does the following: 2N/A * - Trims leading and trailing whitespaces 2N/A * - Collapses two or more whitespaces into one space 2N/A * - Converts all whitespaces into spaces 2N/A * - At entrance, *len contains length of str 2N/A * - At exit, *len will contain length of the return string 2N/A * - In case of mem alloc failure, *len should be ignored 2N/A /* Skip leading whitespaces */ 2N/A for (i = 0; i < *
len && (
str[i] ==
' ' ||
str[i] ==
'\t'); i++);
2N/A /* Collapse multiple whitespaces into one */ 2N/A /* Handle the trailing whitespace if any */ 2N/A * Escapes special characters in DN using the list from RFC 2253 2N/A /* Assume val is always non NULL */ 2N/A * Count the special characters in value to determine 2N/A * the length for the new value 2N/A if (*s ==
'#' || *s ==
',' || *s ==
'+' || *s ==
'"' ||
2N/A *s ==
'\\' || *s ==
'<' || *s ==
'>' || *s ==
';')
2N/A /* Escape the special characters using '\\' */ 2N/A if (*s ==
'#' || *s ==
',' || *s ==
'+' || *s ==
'"' ||
2N/A *s ==
'\\' || *s ==
'<' || *s ==
'>' || *s ==
';')
2N/A * Remove escape characters from DN returned by LDAP server 2N/A * This function is called frequently and for most entries 2N/A * there will be no escapes. Process rapidly up to first escape. 2N/A for (d = s; s <
end; s++, d++) {
2N/A * Reached the end, in which case will not go into loop, 2N/A * or found an escape and now have to start moving data. 2N/A * Next character gets coppied without being