3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
13 /* An Unbind Request looks like this:
15 * UnbindRequest ::= NULL
17 * and has no response.
23 #include <ac/stdlib.h>
25 #include <ac/socket.h>
26 #include <ac/string.h>
35 LDAPControl **cctrls )
39 /* check client controls */
40 rc = ldap_int_client_controls( ld, cctrls );
41 if( rc != LDAP_SUCCESS ) return rc;
43 return ldap_ld_free( ld, 1, sctrls, cctrls );
50 LDAPControl **cctrls )
52 return ldap_unbind_ext( ld, sctrls, cctrls );
56 ldap_unbind( LDAP *ld )
58 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
60 return( ldap_unbind_ext( ld, NULL, NULL ) );
69 LDAPControl **cctrls )
71 LDAPMessage *lm, *next;
72 int err = LDAP_SUCCESS;
73 LDAPRequest *lr, *nextlr;
75 /* free LDAP structure and outstanding requests/responses */
76 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
78 ldap_free_request( ld, lr );
81 /* free and unbind from all open connections */
82 while ( ld->ld_conns != NULL ) {
83 ldap_free_connection( ld, ld->ld_conns, 1, close );
86 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
92 if ( ld->ld_cache != NULL ) {
93 ldap_destroy_cache( ld );
96 #endif /* !LDAP_NOCACHE */
98 if ( ld->ld_error != NULL ) {
99 LDAP_FREE( ld->ld_error );
103 if ( ld->ld_matched != NULL ) {
104 LDAP_FREE( ld->ld_matched );
105 ld->ld_matched = NULL;
108 if ( ld->ld_abandoned != NULL ) {
109 LDAP_FREE( ld->ld_abandoned );
110 ld->ld_abandoned = NULL;
113 if ( ld->ld_selectinfo != NULL ) {
114 ldap_free_select_info( ld->ld_selectinfo );
115 ld->ld_selectinfo = NULL;
118 if ( ld->ld_options.ldo_defludp != NULL ) {
119 ldap_free_urllist( ld->ld_options.ldo_defludp );
120 ld->ld_options.ldo_defludp = NULL;
123 if ( ld->ld_options.ldo_tm_api != NULL ) {
124 LDAP_FREE( ld->ld_options.ldo_tm_api );
125 ld->ld_options.ldo_tm_api = NULL;
128 if ( ld->ld_options.ldo_tm_net != NULL ) {
129 LDAP_FREE( ld->ld_options.ldo_tm_net );
130 ld->ld_options.ldo_tm_net = NULL;
133 ber_sockbuf_free( ld->ld_sb );
135 LDAP_FREE( (char *) ld );
143 ldap_unbind_s( LDAP *ld )
145 return( ldap_unbind_ext( ld, NULL, NULL ) );
153 LDAPControl **sctrls,
154 LDAPControl **cctrls )
158 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
160 /* create a message to send */
161 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
162 return( ld->ld_errno );
166 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
167 LDAP_REQ_UNBIND ) == -1 ) {
168 ld->ld_errno = LDAP_ENCODING_ERROR;
170 return( ld->ld_errno );
173 /* Put Server Controls */
174 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
179 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
180 ld->ld_errno = LDAP_ENCODING_ERROR;
182 return( ld->ld_errno );
185 /* send the message */
186 if ( ber_flush( sb, ber, 1 ) == -1 ) {
187 ld->ld_errno = LDAP_SERVER_DOWN;
189 return( ld->ld_errno );
192 return( LDAP_SUCCESS );