/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* 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
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Functions for managing thread-local storage for LDAP, and in particular
* for managing storage of the LDAP error state.
*/
#include <ldap.h>
#include <pthread.h>
#include <errno.h>
#include <note.h>
#include <syslog.h>
#include <string.h>
#include "solaris-int.h" /* This is a libladp5 private include file */
/* which has the defintion for */
/* struct ldap_extra_thread_fns */
#include "adutils_impl.h"
struct adutils_lderrno {
int le_errno;
char *le_matched;
char *le_errmsg;
};
static void *adutils_mutex_alloc(void);
static void adutils_mutex_free(void *mutexp);
static int adutils_get_errno(void);
static void adutils_set_errno(int err);
void *dummy);
static void adutils_lderrno_destructor(void *tsd);
.ltf_mutex_lock = (int (*)(void *)) pthread_mutex_lock,
.ltf_mutex_unlock = (int (*)(void *)) pthread_mutex_unlock,
};
.ltf_threadid_fn = (void * (*)(void))pthread_self
};
/*
* Set up thread management functions for the specified LDAP session.
* Returns either LDAP_SUCCESS or -1.
*/
int
{
int rc;
if (adutils_lderrno_key == PTHREAD_ONCE_KEY_NP) {
adutils_lderrno_destructor)) != 0) {
"pthread_key_create_once_np failed (%s)",
rc = -1;
return (rc);
}
}
&thread_fns);
if (rc != LDAP_SUCCESS) {
"ldap_set_option LDAP_OPT_THREAD_FN_PTRS failed");
return (rc);
}
if (rc != LDAP_SUCCESS) {
"ldap_set_option LDAP_OPT_EXTRA_THREAD_FN_PTRS failed");
return (rc);
}
return (rc);
}
/*
* Allocate a mutex.
*/
static
void *
adutils_mutex_alloc(void)
{
int rc;
"adutils_mutex_alloc: malloc failed (%s)",
return (NULL);
}
if (rc != 0) {
"adutils_mutex_alloc: "
"pthread_mutex_init failed (%s)",
return (NULL);
}
return (mutexp);
}
/*
* Free a mutex.
*/
static
void
{
}
/*
* Get the thread's local errno.
*/
static
int
adutils_get_errno(void)
{
return (errno);
}
/*
* Set the thread's local errno.
*/
static
void
{
}
/*
* Get a pointer to the thread's local LDAP error state structure.
* Lazily allocate the thread-local storage, so that we don't need
* initialization when each thread starts.
*/
static
struct adutils_lderrno *
{
int rc;
"adutils_get_lderrno_struct: calloc failed (%s)",
return (NULL);
}
if (rc != 0) {
"adutils_get_lderrno_struct: "
"pthread_setspecific failed (%s)",
return (NULL);
}
}
return (le);
}
/*
* Store an error report in the thread's local LDAP error state structure.
*/
static
void
{
struct adutils_lderrno *le;
}
}
/*
* Retrieve an error report from the thread's local LDAP error state structure.
*/
static
int
{
struct adutils_lderrno *le;
}
/*
* Free the thread's local LDAP error state structure.
*/
static
void
{
return;
}
}
}