ldap-int.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef _LDAPINT_H
#define _LDAPINT_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
#ifdef hpux
#include <strings.h>
#endif /* hpux */
#ifdef _WINDOWS
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#include "ldap-macos.h"
#include <os2sock.h>
#else /* _WINDOWS */
# include <netdb.h>
#endif /* !defined(hpux) and others */
#endif /* _WINDOWS */
#if defined(IRIX)
#include <bstring.h>
#endif /* IRIX */
#define NSLBERI_LBER_INT_FRIEND
#ifdef macintosh
#include "lber-int.h"
#elif defined(_SOLARIS_SDK)
#include "../ber/lber-int.h"
#else /* _SOLARIS_SDK */
#include "../liblber/lber-int.h"
#endif /* macintosh */
#include "ldap.h"
#include "ldaprot.h"
#include "ldaplog.h"
#include "portable.h"
#include "regex.h"
#ifdef LDAP_ASYNC_IO
#ifdef NEED_FILIO
#else /* NEED_FILIO */
#endif /* _WINDOWS && macintosh */
#endif /* NEED_FILIO */
#endif /* LDAP_ASYNC_IO */
#ifdef USE_SYSCONF
# include <unistd.h>
#endif /* USE_SYSCONF */
#ifdef _SOLARIS_SDK
#include <libintl.h>
#endif
#ifdef LDAP_SASLIO_HOOKS
#define SASL_MAX_BUFF_SIZE 65536
#define SASL_MIN_BUFF_SIZE 4096
#endif
#define NSLDAPI_HAVE_POLL 1
#endif
/* SSL version, or 0 if not built with SSL */
#if defined(NET_SSL)
# define SSL_VERSION 3
#else
# define SSL_VERSION 0
#endif
#define LDAP_URL_URLCOLON "URL:"
#define LDAP_URL_URLCOLON_LEN 4
#define LDAP_LDAP_REF_STR LDAP_URL_PREFIX
#define LDAP_LDAPS_REF_STR LDAPS_URL_PREFIX
/* default limit on nesting of referrals */
#define LDAP_DEFAULT_REFHOPLIMIT 5
#ifdef LDAP_DNS
#define LDAP_DX_REF_STR "dx://"
#define LDAP_DX_REF_STR_LEN 5
#endif /* LDAP_DNS */
typedef enum {
LDAP_IOSTATUS_LOCK, /* serializes access to ld->ld_iostatus */
#ifdef LDAP_SASLIO_HOOKS
#endif
} LDAPLock;
/*
* This structure represents both ldap messages and ldap responses.
* These are really the same, except in the case of search responses,
* where a response has multiple messages.
*/
struct ldapmsg {
int lm_msgid; /* the message id */
int lm_msgtype; /* the message type */
int lm_fromcache; /* memcache: origin of message */
};
/*
* structure for tracking LDAP server host, ports, DNs, etc.
*/
typedef struct ldap_server {
char *lsrv_host;
char *lsrv_dn; /* if NULL, use default */
int lsrv_port;
unsigned long lsrv_options; /* boolean options */
#define LDAP_SRV_OPT_SECURE 0x01
struct ldap_server *lsrv_next;
} LDAPServer;
/*
* structure for representing an LDAP server connection
*/
typedef struct ldap_conn {
int lconn_version; /* LDAP protocol version */
int lconn_refcnt;
unsigned long lconn_lastused; /* time */
int lconn_status;
#define LDAP_CONNST_NEEDSOCKET 1
#define LDAP_CONNST_CONNECTING 2
#define LDAP_CONNST_CONNECTED 3
#define LDAP_CONNST_DEAD 4
char *lconn_binddn; /* DN of last successful bind */
int lconn_bound; /* has a bind been done? */
char *lconn_krbinstance;
struct ldap_conn *lconn_next;
} LDAPConn;
/*
* structure used to track outstanding requests
*/
typedef struct ldapreq {
int lr_msgid; /* the message id */
int lr_status; /* status of request */
#define LDAP_REQST_INPROGRESS 1
#define LDAP_REQST_CHASINGREFS 2
#define LDAP_REQST_NOTCONNECTED 3
#define LDAP_REQST_WRITING 4
int lr_outrefcnt; /* count of outstanding referrals */
int lr_origid; /* original request's message id */
int lr_parentcnt; /* count of parent requests */
int lr_res_msgtype; /* result message type */
int lr_res_errno; /* result LDAP errno */
char *lr_res_error; /* result error string */
char *lr_res_matched;/* result matched DN string */
char *lr_binddn; /* request is a bind for this DN */
} LDAPRequest;
typedef struct ldappend {
void *lp_sema; /* semaphore to post */
int lp_msgid; /* message id */
} LDAPPend;
/*
* forward declaration for I/O status structure (defined in os-ip.c)
*/
typedef struct nsldapi_iostatus_info NSLDAPIIOStatus;
/*
* old extended IO structure (before writev callback was added)
*/
struct ldap_x_ext_io_fns_rev0 {
int lextiof_size;
void *lextiof_session_arg;
};
#define LDAP_X_EXTIO_FNS_SIZE_REV0 sizeof(struct ldap_x_ext_io_fns_rev0)
/*
* structure representing an ldap connection
*/
struct ldap {
char *ld_host;
int ld_version; /* LDAP protocol version */
char ld_lberoptions;
int ld_deref;
int ld_timelimit;
int ld_sizelimit;
char *ld_ufnprefix; /* for incomplete ufn's */
int ld_errno;
char *ld_error;
char *ld_matched;
int ld_msgid;
/* do not mess with these */
int *ld_abandoned; /* array of abandoned requests */
char *ld_cldapdn; /* DN used in connectionless search */
/* it is OK to change these next four values directly */
int ld_cldaptries; /* connectionless search retry count */
int ld_cldaptimeout;/* time between retries */
int ld_refhoplimit; /* limit on referral nesting */
unsigned long ld_options; /* boolean options */
#define LDAP_BITOPT_REFERRALS 0x80000000
#define LDAP_BITOPT_SSL 0x40000000
#define LDAP_BITOPT_DNS 0x20000000
#define LDAP_BITOPT_RESTART 0x10000000
#define LDAP_BITOPT_RECONNECT 0x08000000
#define LDAP_BITOPT_ASYNC 0x04000000
/* do not mess with the rest though */
char *ld_defhost; /* full name of default server */
int ld_defport; /* port of default server */
void *ld_rebind_arg;
/* function pointers, etc. for extended I/O */
struct ldap_x_ext_io_fns ld_ext_io_fns;
/* allocated pointer for older I/O functions */
struct ldap_io_fns *ld_io_fns_ptr;
/* function pointers, etc. for DNS */
struct ldap_dns_fns ld_dnsfn;
/* function pointers, etc. for threading */
struct ldap_thread_fns ld_thread;
void **ld_mutex;
/* function pointers, etc. for caching */
int ld_cache_on;
int ld_cache_strategy;
struct ldap_cache_fns ld_cache;
#if 0
#endif
/* ldapv3 controls */
/* Preferred language */
char *ld_preferred_language;
/* MemCache */
/* Pending results */
/* extra thread function pointers */
struct ldap_extra_thread_fns ld_thread2;
/* With the 4.0 version of the LDAP SDK */
/* the extra thread functions except for */
/* the ld_threadid_fn has been disabled */
/* Look at the release notes for the full */
/* explanation */
/* extra data for mutex handling in referrals */
void *ld_mutex_threadid[LDAP_MAX_LOCK];
unsigned long ld_mutex_refcnt[LDAP_MAX_LOCK];
/* connect timeout value (milliseconds) */
int ld_connect_timeout;
#ifdef LDAP_SASLIO_HOOKS
/* SASL default option settings */
char *ld_def_sasl_mech;
char *ld_def_sasl_realm;
char *ld_def_sasl_authcid;
char *ld_def_sasl_authzid;
/* SASL Security properties */
/* prldap shadow io functions */
struct ldap_x_ext_io_fns ld_sasl_io_fns;
#endif
};
#define LDAP_MUTEX_ALLOC( ld ) \
#define LDAP_MUTEX_FREE( ld, m ) \
(ld)->ld_mutex_free_fn( m ); \
}
/*
* The locks assume that the locks are thread safe. XXXmcs: which means???
*
* Note that we test for both ld_mutex_lock_fn != NULL AND ld_mutex != NULL.
* This is necessary because there is a window in ldap_init() between the
* time we set the ld_mutex_lock_fn pointer and the time we allocate the
* mutexes in which external code COULD be called which COULD make a call to
* something like ldap_get_option(), which uses LDAP_MUTEX_LOCK(). The
* libprldap code does this in its newhandle callback (prldap_newhandle).
*/
} else { \
} \
} else { \
} \
}
} \
} \
} else { \
} \
}
/* Backward compatibility locks */
#define LDAP_MUTEX_BC_LOCK( ld, i ) \
/* the ld_mutex_trylock_fn is always set to NULL */ \
/* in setoption.c as the extra thread functions were */ \
/* turned off in the 4.0 SDK. This check will */ \
/* always be true */ \
LDAP_MUTEX_LOCK( ld, i ) ; \
}
#define LDAP_MUTEX_BC_UNLOCK( ld, i ) \
/* the ld_mutex_trylock_fn is always set to NULL */ \
/* in setoption.c as the extra thread functions were */ \
/* turned off in the 4.0 SDK. This check will */ \
/* always be true */ \
LDAP_MUTEX_UNLOCK( ld, i ) ; \
}
#define LDAP_SEMA_ALLOC( ld ) \
#define LDAP_SEMA_FREE( ld, m ) \
(ld)->ld_sema_free_fn( m ); \
}
}
}
/* the ld_mutex_trylock_fn is always set to NULL */ \
/* in setoption.c as the extra thread functions were */ \
/* turned off in the 4.0 SDK. This check will */ \
/* always be false */ \
nsldapi_post_result( ld, y, z ); \
}
#ifndef macintosh
#define LDAP_SET_ERRNO( ld, e ) \
(ld)->ld_set_errno_fn( e ); \
} else { \
errno = e; \
}
#define LDAP_GET_ERRNO( ld ) \
#else /* macintosh */
#define LDAP_SET_ERRNO( ld, e ) \
(ld)->ld_set_errno_fn( e ); \
}
#define LDAP_GET_ERRNO( ld ) \
(ld)->ld_get_errno_fn() : 0)
#endif
/*
* your standard "mimimum of two values" macro
*/
#define NSLDAPI_MIN(a, b) (((a) < (b)) ? (a) : (b))
/*
* handy macro to check whether LDAP struct is set up for CLDAP or not
*/
/*
* handy macro to check errno "e" for an "in progress" sort of error
*/
#else
#ifdef EAGAIN
#define NSLDAPI_ERRNO_IO_INPROGRESS( e ) ((e) == EWOULDBLOCK || (e) == EINPROGRESS || (e) == EAGAIN)
#else /* EAGAIN */
#endif /* EAGAIN */
#endif /* macintosh || _WINDOWS*/
/*
* macro to return the LDAP protocol version we are using
*/
(ld)->ld_version : \
/*
* Structures used for handling client filter lists.
*/
#define LDAP_FILT_MAXSIZ 1024
struct ldap_filt_list {
char *lfl_tag;
char *lfl_pattern;
char *lfl_delims;
struct ldap_filt_info *lfl_ilist;
struct ldap_filt_list *lfl_next;
};
struct ldap_filt_desc {
char lfd_filter[ LDAP_FILT_MAXSIZ ];
char *lfd_curval;
char *lfd_curvalcopy;
char **lfd_curvalwords;
char *lfd_filtprefix;
char *lfd_filtsuffix;
};
/*
* "internal" globals used to track defaults and memory allocation callbacks:
* (the actual definitions are in open.c)
*/
extern struct ldap nsldapi_ld_defaults;
extern struct ldap_memalloc_fns nsldapi_memalloc_fns;
extern int nsldapi_initialized;
/*
* Memory allocation done in liblber should all go through one of the
* following macros. This is so we can plug-in alternative memory
* allocators, etc. as the need arises.
*/
/*
* macros used to check validity of data structures and parameters
*/
#define NSLDAPI_VALID_LDAP_POINTER( ld ) \
#define NSLDAPI_VALID_LDAPMESSAGE_POINTER( lm ) \
#define NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( lm ) \
#define NSLDAPI_VALID_LDAPMESSAGE_REFERENCE_POINTER( lm ) \
#define NSLDAPI_VALID_LDAPMESSAGE_BINDRESULT_POINTER( lm ) \
#define NSLDAPI_VALID_LDAPMESSAGE_EXRESULT_POINTER( lm ) \
#define NSLDAPI_VALID_LDAPMOD_ARRAY( mods ) \
#define NSLDAPI_VALID_NONEMPTY_LDAPMOD_ARRAY( mods ) \
#define NSLDAPI_IS_SEARCH_ENTRY( code ) \
((code) == LDAP_RES_SEARCH_ENTRY)
#define NSLDAPI_IS_SEARCH_RESULT( code ) \
((code) == LDAP_RES_SEARCH_RESULT)
#define NSLDAPI_SEARCH_RELATED_RESULT( code ) \
/*
* in bind.c
*/
/*
* in cache.c
*/
/*
* in dsparse.c
*/
void ldap_free_strarray( char **sap );
/*
* in error.c
*/
LDAPControl ***serverctrlsp );
/*
* in open.c
*/
void nsldapi_initialize_defaults( void );
char *nsldapi_strdup( const char *s ); /* if s is NULL, returns NULL */
/*
* in os-ip.c
*/
/*
* if referral.c
*/
LDAPControl ***serverctrlsp );
/*
* in result.c
*/
LDAPMessage **result );
/*
* in request.c
*/
int async );
int *totalcountp, int *chasingcountp );
/*
* in search.c
*/
/*
* in unbind.c
*/
LDAPControl **clientctrls );
#ifdef LDAP_DNS
/*
* in getdxbyname.c
*/
char **nsldapi_getdxbyname( char *domain );
#endif /* LDAP_DNS */
/*
* in unescape.c
*/
void nsldapi_hex_unescape( char *s );
/*
* in reslist.c
*/
/*
* in compat.c
*/
#ifdef hpux
#endif /* hpux */
/*
* in control.c
*/
BerElement *ber );
LDAPControl **newctrls );
/*
* in url.c
*/
int dn_required );
/*
*/
void ber_err_print( char *data );
#ifdef _SOLARIS_SDK
/*
* in ../prldap/ldappr-dns.c
*/
/*
* in ../prldap/ldappr-threads.c
*/
void prldap_nspr_init(void);
#endif
/*
* in ../prldap/ldappr-public.c
*/
int
int
int
#ifndef _SOLARIS_SDK
/*
* in charset.c
*
* If we ever want to expose character set translation functionality to
* users of libldap, all of these prototypes will need to be moved to ldap.h
*
* These are moved to ldap.h in the Solaris version of the library
*
*/
#ifdef STR_TRANSLATION
unsigned long *lenp, int free_input );
unsigned long *lenp, int free_input );
int enable );
#ifdef LDAP_CHARSET_8859
int free_input );
int free_input );
#endif /* LDAP_CHARSET_8859 */
#endif /* STR_TRANSLATION */
#endif /* _SOLARIS_SDK */
/*
* in memcache.h
*/
unsigned long *keyp );
const char *basedn );
#endif /* _LDAPINT_H */