/* LINTLIBRARY */
/* PROTOLIB1 */

/*
 * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
 
#pragma ident	"@(#)llib-lsldaputil	1.2	03/08/21 SMI"

#include <stdio.h>
#include <sys/types.h>
#include "ldap_bp.h"
#include "lber_bp.h"


/*
 * in abandon.c:
 */
int __BP_ldap_abandon_ext(LDAP *ld, int msgid, LDAPControl **serverctrls, LDAPControl ** clientctrls);

int __BP_ldap_abandon( LDAP *ld, int msgid );

/*
 * in add.c:
 */
int __BP_ldap_add_ext( LDAP *ld, const char *dn, LDAPMod **attrs, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp);

int __BP_ldap_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs, LDAPControl ** serverctrls, LDAPControl **clientctrls);

int __BP_ldap_add( LDAP *ld, const char *dn, LDAPMod **attrs );
int __BP_ldap_add_s( LDAP *ld, const char *dn, LDAPMod **attrs );

/*
 * in bind.c:
 */
int __BP_ldap_bind(LDAP *ld, const char *dn, const char *passwd, int authmethod);
int __BP_ldap_bind_s(LDAP *ld, const char *dn, const char *passwd, int authmethod);
void __BP_ldap_set_rebind_proc(LDAP *ld, LDAP_REBINDPROC_CALLBACK *rebindproc, void *arg);

/*
 * in sbind.c:
 */
int __BP_ldap_simple_bind( LDAP *ld, const char *dn, const char *passwd );
int __BP_ldap_simple_bind_s( LDAP *ld, const char *dn, const char *passwd );

/*
 * in saslbind.c:
 */
int __BP_ldap_sasl_bind(LDAP *ld, const char *dn, const char *mechanism, const struct berval *cred, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp);

int __BP_ldap_sasl_bind_s(LDAP *ld, const char *dn, const char *mechanism, const struct berval *cred, LDAPControl **serverctrls, LDAPControl **clientctrls, struct berval **servercredp);

/*
 * in kbind.c:
 */

/*
 * in cache.c
 */

/*
 * in compare.c:
 */
int __BP_ldap_compare_ext(LDAP *ld, const char *dn, const char *attr, const struct berval *bvalue, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp);

int __BP_ldap_compare_ext_s(LDAP *ld, const char *dn, const char *attr, const struct berval *bvalue, LDAPControl ** serverctrls, LDAPControl **clientctrls) ;

int __BP_ldap_compare( LDAP *ld, const char *dn, const char *attr, const char *value );

int __BP_ldap_compare_s( LDAP *ld, const char *dn, const char *attr, const char *value );

/*
 * in delete.c:
 */
int __BP_ldap_delete_ext(LDAP *ld, const char *dn, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp);

int __BP_ldap_delete_ext_s(LDAP *ld, const char *dn, LDAPControl **serverctrls, LDAPControl **clientctrls);

int __BP_ldap_delete( LDAP *ld, const char *dn );
int __BP_ldap_delete_s( LDAP *ld, const char *dn );

/*
 * in error.c:
 */
char *__BP_ldap_err2string( int err );
void __BP_ldap_perror(LDAP *ld, const char *s);
int __BP_ldap_result2error(LDAP *ld, LDAPMessage *r, int freeit);
int __BP_ldap_get_lderrno(LDAP *ld, char **m, char **s);
int __BP_ldap_set_lderrno(LDAP *ld, int e, char *m, char *s);

/*
 * in modify.c:
 */
int __BP_ldap_modify_ext(LDAP *ld, const char *dn, LDAPMod **mods, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp);

int __BP_ldap_modify_ext_s(LDAP *ld, const char *dn, LDAPMod **mods, LDAPControl **serverctrls, LDAPControl **clientctrls) ; 

int __BP_ldap_modify( LDAP *ld, const char *dn, LDAPMod **mods );
int ldtap_modify_s( LDAP *ld, const char *dn, LDAPMod **mods );

/*
 * in modrdn.c:
 */

/*
 * in rename.c:
 */
int __BP_ldap_rename(LDAP *ld, const char *dn, const char *newrdn, const char *newparent, int deleteoldrdn, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp);

int __BP_ldap_rename_s(LDAP *ld, const char *dn, const char *newrdn, const char *newparent, int deleteoldrdn, LDAPControl ** serverctrls, LDAPControl **clientctrls);

int __BP_ldap_modrdn(LDAP *ld, const char *dn, const char *newrdn);
int __BP_ldap_modrdn_s(LDAP *ld, const char *dn, const char *newrdn);
int __BP_ldap_modrdn2(LDAP *ld, const char *dn, const char *newrdn, int deleteoldrdn);

int __BP_ldap_modrdn2_s(LDAP *ld, const char *dn, const char *newrdn, int deleteoldrdn);

/*
 * in open.c:
 */
LDAP *__BP_ldap_init( const char *defhost, int defport );
LDAP *__BP_ldap_open(const char *host, int port);
int __BP_ldap_version(LDAPVersion *ver);

/*
 * in getentry.c:
 */
LDAPMessage *__BP_ldap_first_entry( LDAP *ld, LDAPMessage *res );
LDAPMessage *__BP_ldap_next_entry( LDAP *ld, LDAPMessage *entry );
int __BP_ldap_count_entries( LDAP *ld, LDAPMessage *res );
int __BP_ldap_get_entry_controls(LDAP *ld, LDAPMessage *entry, LDAPControl ***serverctrlsp);

/*
 * in getmsg.c:
 */
LDAPMessage *__BP_ldap_first_message( LDAP *ld, LDAPMessage *res );
LDAPMessage *__BP_ldap_next_message( LDAP *ld, LDAPMessage *msg );
int __BP_ldap_count_messages( LDAP *ld, LDAPMessage *res );

/*
 * in getref.c:
 */
LDAPMessage *__BP_ldap_first_reference( LDAP *ld, LDAPMessage *res );
LDAPMessage *__BP_ldap_next_reference( LDAP *ld, LDAPMessage *entry );
int __BP_ldap_count_references( LDAP *ld, LDAPMessage *res );

/*
 * in getdn.c
 */
char *__BP_ldap_get_dn( LDAP *ld, LDAPMessage *entry );
char **__BP_ldap_explode_dn( const char *dn, const int notypes );
char ** __BP_ldap_explode_rdn( const char *rdn, const int notypes );
char *__BP_ldap_dn2ufn( const char *dn );
char **__BP_ldap_explode_dns( const char *dn );
int __BP_ldap_is_dns_dn( const char *dn );
char *__BP_ldap_dns_to_dn(char *dns_name, int *nameparts);

/*
 * in getattr.c
 */
char *__BP_ldap_first_attribute( LDAP *ld, LDAPMessage *entry,
	BerElement **ber );

char *__BP_ldap_next_attribute( LDAP *ld, LDAPMessage *entry,
	BerElement *ber );

void __BP_ldap_memfree(void *p);

/*
 * in getvalues.c
 */
char **__BP_ldap_get_values( LDAP *ld, LDAPMessage *entry, const char *target );
int __BP_ldap_count_values( char **vals );
int __BP_ldap_count_values_len( struct berval **vals );
void __BP_ldap_value_free( char **vals );
void __BP_ldap_value_free_len( struct berval **vals );

struct berval **__BP_ldap_get_values_len(LDAP *ld, LDAPMessage *entry, const char *target);

char **__BP_ldap_get_lang_values(LDAP *ld, LDAPMessage *entry, const char *target, char **type);

struct berval **__BP_ldap_get_lang_values_len(LDAP *ld, LDAPMessage *entry, const char *target, char **type);

/*
 * in referral.c:
 */
int __BP_ldap_parse_reference(LDAP *ld, LDAPMessage *ref,
        char ***referralsp, LDAPControl ***serverctrlsp, int freeit);
char ** __BP_ldap_get_reference_urls(LDAP *ld, LDAPMessage *res);

/*
 * in result.c:
 */
int __BP_ldap_result( LDAP *ld, int msgid, int all,
	struct timeval *timeout, LDAPMessage **result );

int __BP_ldap_msgfree( LDAPMessage *lm );
int __BP_ldap_msgtype( LDAPMessage *res );
int __BP_ldap_msgid( LDAPMessage *res );
int __BP_ldap_parse_result(LDAP *ld, LDAPMessage *res, int *errcodep, char **matcheddnp, char **errmsgp, char ***referralsp, LDAPControl ***serverctrlsp, int freeit) ;

int __BP_ldap_parse_sasl_bind_result(LDAP *ld, LDAPMessage *res, struct berval **servercredp, int freeit);

int __BP_ldap_parse_extended_result(LDAP *ld, LDAPMessage *res, char **resultoidp, struct berval **resultdata, int freeit); 

/*
 * in search.c:
 */
int __BP_ldap_search_ext(LDAP *ld, const char *base, int scope, const char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit, int *msgidp);

int __BP_ldap_search_ext_s(LDAP *ld, const char *base, int scope, const char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit, LDAPMessage **res);

int __BP_ldap_search( LDAP *ld, const char *base, int scope, const char *filter,
	char **attrs, int attrsonly );

int __BP_ldap_search_s( LDAP *ld, const char *base, int scope, const char *filter,
	char **attrs, int attrsonly, LDAPMessage **res );

int __BP_ldap_search_st( LDAP *ld, const char *base, int scope, const char *filter,
    char **attrs, int attrsonly, struct timeval *timeout, LDAPMessage **res );

/*
 * in ufn.c
 */
int __BP_ldap_ufn_search_c( LDAP *ld, char *ufn, char **attrs,
	int attrsonly, LDAPMessage **res, LDAP_CANCELPROC_CALLBACK cancelproc,
	void *cancelparm );

int __BP_ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs,
	int attrsonly, LDAPMessage **res, LDAP_CANCELPROC_CALLBACK cancelproc,
	void *cancelparm, char *tag1, char *tag2, char *tag3 );

int __BP_ldap_ufn_search_s( LDAP *ld, char *ufn, char **attrs,
	int attrsonly, LDAPMessage **res );

LDAPFiltDesc *__BP_ldap_ufn_setfilter( LDAP *ld, char *fname );
void __BP_ldap_ufn_setprefix( LDAP *ld, char *prefix );
int __BP_ldap_ufn_timeout( void *tvparam );


/*
 * in unbind.c
 */
int __BP_ldap_unbind( LDAP *ld );
int __BP_ldap_unbind_s( LDAP *ld );
int __BP_ldap_unbind_ext(LDAP *ld, LDAPControl **serverctrls, LDAPControl **clientctrls);


/*
 * in getfilter.c
 */
LDAPFiltDesc *__BP_ldap_init_getfilter( char *fname );
LDAPFiltDesc *__BP_ldap_init_getfilter_buf( char *buf, ssize_t buflen );
LDAPFiltInfo *__BP_ldap_getfirstfilter( LDAPFiltDesc *lfdp, char *tagpat,
	char *value );

LDAPFiltInfo *__BP_ldap_getnextfilter( LDAPFiltDesc *lfdp );
void __BP_ldap_setfilteraffixes( LDAPFiltDesc *lfdp, char *prefix, char *suffix );
void __BP_ldap_build_filter( char *filtbuf, size_t buflen,
	char *pattern, char *prefix, char *suffix, char *attr,
	char *value, char **valwords );

int __BP_ldap_create_filter(char *buf, unsigned long buflen, char *pattern, char *prefix, char *suffix, char *attr, char *value, char **valwords);

/*
 * in free.c
 */
void __BP_ldap_getfilter_free( LDAPFiltDesc *lfdp );
void __BP_ldap_mods_free( LDAPMod **mods, int freemods );
void ldap___BP_ber_free(BerElement *ber, int freebuf);

/*
 * in friendly.c
 */
char *__BP_ldap_friendly_name( char *filename, char *uname,
	FriendlyMap *map );

void __BP_ldap_free_friendlymap( FriendlyMap *map );


/*
 * in cldap.c
 */


/*
 * in sort.c
 */
int __BP_ldap_sort_entries( LDAP *ld, LDAPMessage **chain, char *attr,
	int (*cmp)() );

int __BP_ldap_sort_values( LDAP *ld, char **vals, int (*cmp)() );
int __BP_ldap_sort_strcasecmp( const char **a, const char **b );
int __BP_ldap_multisort_entries(LDAP *ld, LDAPMessage **chain, char **attr, LDAP_CMP_CALLBACK *cmp);


/*
 * in url.c
 */
int __BP_ldap_is_ldap_url( const char *url );
int __BP_ldap_url_parse( const char *url, LDAPURLDesc **ludpp );
int __BP_ldap_url_parse_nodn(const char *url, LDAPURLDesc **ludpp);
void __BP_ldap_free_urldesc( LDAPURLDesc *ludp );
int __BP_ldap_url_search( LDAP *ld, const char *url, int attrsonly );
int __BP_ldap_url_search_s( LDAP *ld, const char *url, int attrsonly,
	LDAPMessage **res );

int __BP_ldap_url_search_st( LDAP *ld, const char *url, int attrsonly,
	struct timeval *timeout, LDAPMessage **res );

char *__BP_ldap_dns_to_url(LDAP *ld, char *dns_name, char *attrs,
char *scope, char *filter);
char *__BP_ldap_dn_to_url(LDAP *ld, char *dn, int nameparts);


/*
 * in charset.c
 */
void __BP_ldap_set_string_translators( LDAP *ld,
	BERTranslateProc encode_proc, BERTranslateProc decode_proc );

int __BP_ldap_translate_from_t61( LDAP *ld, char **bufp,
	unsigned int *lenp, int free_input );

int __BP_ldap_translate_to_t61( LDAP *ld, char **bufp,
	unsigned int *lenp, int free_input );

void __BP_ldap_enable_translation( LDAP *ld, LDAPMessage *entry,
	int enable );

int ldap_t61_to_8859(char **bufp, unsigned long *buflenp,
        int free_input);

int ldap_8859_to_t61(char **bufp, unsigned long *buflenp,
        int free_input);


/*
 * in io.c
 */
BerElement *__BP_ber_alloc_t(int options);
int __BP_ber_flatten(BerElement *ber, struct berval **bvPtr);
void __BP_ber_free(BerElement *ber, int freebuf);
BerElement *__BP_ber_alloc(void);
BerElement *__BP_ber_init(const struct berval *bv);

/*
 * in decode.c
 */
struct berval *__BP_ber_bvdup(const struct berval *bv);
void __BP_ber_bvecfree(struct berval **bv);
void __BP_ber_bvfree(struct berval *bv);
ber_tag_t __BP_ber_first_element(BerElement *ber, unsigned int *len, char **last);
ber_tag_t __BP_ber_next_element(BerElement *ber, ber_tag_t *len, char *last);
ber_tag_t __BP_ber_peek_tag(BerElement *ber, ber_tag_t *len);
ber_tag_t __BP_ber_scanf(BerElement *ber, const char *fmt, ...);
ber_tag_t __BP_ber_skip_tag(BerElement *ber, ber_tag_t *len);
ber_tag_t __BP_ber_get_int(BerElement *ber, ber_int_t *num);

/*
 * in encode.c
 */
int __BP_ber_printf(BerElement *ber, const char *fmt, ...);

/*
 * in control.c
 */
void __BP_ldap_control_free (LDAPControl *ctrl);
void __BP_ldap_controls_free (LDAPControl **ctrls);

/*
 * in spagectrl.c
 */
int __BP_ldap_create_page_control(LDAP *ld, unsigned int pagesize, struct berval *cookie, char isCritical, LDAPControl **output);

int __BP_ldap_parse_page_control(LDAP *ld, LDAPControl **controls, unsigned int *totalcount, struct berval **cookie);

/*
 * in tmplout.c
 */
int __BP_ldap_entry2html(LDAP *ld, char *buf, LDAPMessage *entry, struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals, writeptype writeproc, void *writeparm, char *eol, int rdncount, unsigned long opts, char *urlprefix, char *base);

int __BP_ldap_entry2html_search(LDAP *ld, char *dn, char *base, LDAPMessage *entry, struct ldap_disptmpl*tmpllist, char **defattrs, char ***defvals, writeptype writeproc, void *writeparm, char *eol,int rdncount, unsigned long opts, char *urlprefix);

int __BP_ldap_entry2text(LDAP *ld, char *buf, LDAPMessage *entry, struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals, writeptype writeproc, void *writeparm, char *eol, int rdncount, unsigned long opts);

int __BP_ldap_entry2text_search(LDAP *ld,char *dn, char *base, LDAPMessage *entry, struct ldap_disptmpl*tmpllist, char **defattrs, char ***defvals, writeptype writeproc, void *writeparm, char *eol,int rdncount, unsigned long opts);

int __BP_ldap_vals2html(LDAP *ld, char *buf, char **vals, char *label, int labelwidth, unsigned long syntaxid, writeptype writeproc, void *writeparm, char *eol, int rdncount, char *urlprefix);

int __BP_ldap_vals2text(LDAP *ld, char *buf, char **vals, char *label, int labelwidth, unsigned long syntaxid, writeptype writeproc, void *writeparm, char *eol, int rdncount);

/*
 * in extendop.c
 */
int __BP_ldap_extended_operation(LDAP *ld, const char *requestoid, const struct berval *requestdata, LDAPControl **serverctrls, LDAPControl**clientctrls, int *msgidp);

int __BP_ldap_extended_operation_s(LDAP *ld, const char *requestoid, const struct berval *requestdata, LDAPControl **serverctrls, LDAPControl **clientctrls, char **retoidp, struct berval **retdatap);

/*
 * in disptmpl.c
 */
struct ldap_disptmpl *__BP_ldap_first_disptmpl(struct ldap_disptmpl *tmpllist);
struct ldap_tmplitem *__BP_ldap_first_tmplcol(struct ldap_disptmpl *tmpl,struct ldap_tmplitem *row);

struct ldap_tmplitem *__BP_ldap_first_tmplrow(struct ldap_disptmpl *tmpl);
void __BP_ldap_free_templates(struct ldap_disptmpl *tmpllist);
int __BP_ldap_init_templates(char *file, struct ldap_disptmpl **tmpllistp);

int __BP_ldap_init_templates_buf(char *buf, long buflen, struct ldap_disptmpl **tmpllistp);

struct ldap_disptmpl *__BP_ldap_next_disptmpl(struct ldap_disptmpl *tmpllist, struct ldap_disptmpl *tmpl);

struct ldap_tmplitem *__BP_ldap_next_tmplcol(struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row, struct ldap_tmplitem *col);

struct ldap_tmplitem *__BP_ldap_next_tmplrow(struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row);

struct ldap_disptmpl *__BP_ldap_oc2template(char **oclist, struct ldap_disptmpl *tmpllist);

char **__BP_ldap_tmplattrs(struct ldap_disptmpl *tmpl, char **includeattrs, int exclude, unsigned long syntaxmask);

struct ldap_disptmpl *__BP_ldap_name2template(char *name, struct ldap_disptmpl *tmpllist);

/*
 * in cram_md5.c
 */
int __BP_ldap_sasl_cram_md5_bind_s(LDAP *ld, char *dn, struct berval *cred, LDAPControl **serverctrls, LDAPControl **clientctrls);

/*
 * in setoption.c
 */ 
int __BP_ldap_set_option (LDAP *ld, int option, const void *optdata);

/*
 * in log.c
 */
void __BP_ldaplogconfigf(FILE *fd);

/*
 * in line64.c
 */
char *__BP_ldif_type_and_value(char *type, char *val, int vlen);
char *__BP_str_getline(char **next);
int __BP_str_parse_line(char *line, char **type, char **value, int *vlen);

/*
 * in sortctrl.c
 */
int __BP_ldap_create_sort_control (LDAP *ld, LDAPsortkey **sortKeyList, const char ctl_iscritical, LDAPControl **ctrlp);

int __BP_ldap_parse_sort_control(LDAP *ld, LDAPControl **ctrlp, unsigned long *result, char **attribute);

int __BP_ldap_create_sort_keylist(LDAPsortkey ***sortKeyList, const char *string_rep);

void __BP_ldap_free_sort_keylist(LDAPsortkey **sortKeyList);

/*
 * in vlistctrl.c
 */
int __BP_ldap_create_virtuallist_control(LDAP *ld, LDAPVirtualList *ldvlistp, LDAPControl **ctrlp);

int __BP_ldap_parse_virtuallist_control(LDAP *ld, LDAPControl **ctrls, unsigned long *target_posp, unsigned long *list_sizep, int *errcodep);

/*
 * in ldapsinit.c
 */
LDAP * __BP_ldapssl_init( const char *defhost, int defport, int defsecure );
int __BP_ldapssl_install_routines( LDAP *ld );
int __BP_ldapssl_enable_clientauth( LDAP *ld, char *keynickname, char *keypasswd, char *certnickname );

/*
 * in clientinit.c
 */
int __BP_ldapssl_client_init( const char *certdbpath, void *certdbhandle);
int __BP_ldapssl_clientauth_init(const char *certdbpath, void *certdbhandle, const int needkeydb, const char *keydbpath, void *keydbhandle);

int __BP_ldapssl_advclientauth_init( const char *certdbpath, void *certdbhandle, const int needkeydb, const char *keydbpath, void *keydbhandle, const int needsecmoddb, const char *secmoddbpath, const int sslstrength );

int __BP_ldapssl_pkcs_init( const struct ldapssl_pkcs_fns *pfns);

/*
 * in errormap.c
 */
const char * __BP_ldapssl_err2string( const int prerrno );

/*
 * in psearch.c
 */
int __BP_ldap_create_persistentsearch_control(LDAP *ld, int changetypes, int changesonly, int return_echg_ctls, char ctl_iscritical, LDAPControl **ctrlp);

int __BP_ldap_parse_entrychange_control(LDAP *ld, LDAPControl **ctrls, int *chgtypep, char **prevdnp, int *chgnumpresentp, ber_int_t *chgnump);

/*
 * in proxyauthctrl.c
 */
int __BP_ldap_create_proxyauth_control(LDAP *ld, const char *dn, const char ctl_iscritical, LDAPControl **ctrlp);

int __BP_ldap_create_proxiedauth_control(LDAP *ld, const char *authzid, LDAPControl **ctrlp);

/*
 * in srchpref.c
 */
struct __BP_ldap_searchobj *__BP_ldap_first_searchobj(struct __BP_ldap_searchobj *solist);
void __BP_ldap_free_searchprefs(struct __BP_ldap_searchobj *solist);
int __BP_ldap_init_searchprefs(char *file, struct __BP_ldap_searchobj **solistp);
int __BP_ldap_init_searchprefs_buf(char *buf, long buflen, struct __BP_ldap_searchobj **solistp);

struct __BP_ldap_searchobj *__BP_ldap_next_searchobj(struct __BP_ldap_searchobj *solist, struct __BP_ldap_searchobj *so);

/*
 * in getoption.c
 */
int __BP_ldap_get_option (LDAP *ld, int option, void *outvalue);

/*
 * in memcache.c
 */
int __BP_ldap_memcache_init(unsigned long ttl, unsigned long size, char **baseDNs, struct ldap_thread_fns *thread_fns, LDAPMemCache **cachep);

int __BP_ldap_memcache_set(LDAP *ld, LDAPMemCache *cache);
int __BP_ldap_memcache_get(LDAP *ld, LDAPMemCache **cachep);
void __BP_ldap_memcache_flush(LDAPMemCache *cache, char *dn, int scope);
void __BP_ldap_memcache_destroy(LDAPMemCache *cache);
void __BP_ldap_memcache_update(LDAPMemCache *cache);

/*
 * in digest_md5.c
 */
int __BP_ldap_x_sasl_digest_md5_bind_s(LDAP *ld, char *dn, struct berval *cred, LDAPControl **serverctrls, LDAPControl **clientctrls);
