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 )
40 assert( LDAP_VALID( ld ) );
42 /* check client controls */
43 rc = ldap_int_client_controls( ld, cctrls );
44 if( rc != LDAP_SUCCESS ) return rc;
46 return ldap_ld_free( ld, 1, sctrls, cctrls );
53 LDAPControl **cctrls )
55 return ldap_unbind_ext( ld, sctrls, cctrls );
59 ldap_unbind( LDAP *ld )
61 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
63 return( ldap_unbind_ext( ld, NULL, NULL ) );
72 LDAPControl **cctrls )
74 LDAPMessage *lm, *next;
75 int err = LDAP_SUCCESS;
76 LDAPRequest *lr, *nextlr;
78 /* free LDAP structure and outstanding requests/responses */
79 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
81 ldap_free_request( ld, lr );
84 /* free and unbind from all open connections */
85 while ( ld->ld_conns != NULL ) {
86 ldap_free_connection( ld, ld->ld_conns, 1, close );
89 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
95 if ( ld->ld_cache != NULL ) {
96 ldap_destroy_cache( ld );
99 #endif /* !LDAP_NOCACHE */
101 if ( ld->ld_error != NULL ) {
102 LDAP_FREE( ld->ld_error );
106 if ( ld->ld_matched != NULL ) {
107 LDAP_FREE( ld->ld_matched );
108 ld->ld_matched = NULL;
111 if ( ld->ld_abandoned != NULL ) {
112 LDAP_FREE( ld->ld_abandoned );
113 ld->ld_abandoned = NULL;
116 if ( ld->ld_selectinfo != NULL ) {
117 ldap_free_select_info( ld->ld_selectinfo );
118 ld->ld_selectinfo = NULL;
121 if ( ld->ld_options.ldo_defludp != NULL ) {
122 ldap_free_urllist( ld->ld_options.ldo_defludp );
123 ld->ld_options.ldo_defludp = NULL;
126 if ( ld->ld_options.ldo_tm_api != NULL ) {
127 LDAP_FREE( ld->ld_options.ldo_tm_api );
128 ld->ld_options.ldo_tm_api = NULL;
131 if ( ld->ld_options.ldo_tm_net != NULL ) {
132 LDAP_FREE( ld->ld_options.ldo_tm_net );
133 ld->ld_options.ldo_tm_net = NULL;
136 ber_sockbuf_free( ld->ld_sb );
138 LDAP_FREE( (char *) ld );
146 ldap_unbind_s( LDAP *ld )
148 return( ldap_unbind_ext( ld, NULL, NULL ) );
156 LDAPControl **sctrls,
157 LDAPControl **cctrls )
161 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
163 /* create a message to send */
164 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
165 return( ld->ld_errno );
169 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
170 LDAP_REQ_UNBIND ) == -1 ) {
171 ld->ld_errno = LDAP_ENCODING_ERROR;
173 return( ld->ld_errno );
176 /* Put Server Controls */
177 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
182 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
183 ld->ld_errno = LDAP_ENCODING_ERROR;
185 return( ld->ld_errno );
188 /* send the message */
189 if ( ber_flush( sb, ber, 1 ) == -1 ) {
190 ld->ld_errno = LDAP_SERVER_DOWN;
192 return( ld->ld_errno );
195 return( LDAP_SUCCESS );