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 )
37 return ldap_ld_free( ld, 1, sctrls, cctrls );
44 LDAPControl **cctrls )
46 return ldap_unbind_ext( ld, sctrls, cctrls );
50 ldap_unbind( LDAP *ld )
52 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
54 return( ldap_unbind_ext( ld, NULL, NULL ) );
63 LDAPControl **cctrls )
65 LDAPMessage *lm, *next;
66 int err = LDAP_SUCCESS;
67 LDAPRequest *lr, *nextlr;
69 /* free LDAP structure and outstanding requests/responses */
70 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
72 ldap_free_request( ld, lr );
75 /* free and unbind from all open connections */
76 while ( ld->ld_conns != NULL ) {
77 ldap_free_connection( ld, ld->ld_conns, 1, close );
80 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
86 if ( ld->ld_cache != NULL ) {
87 ldap_destroy_cache( ld );
90 #endif /* !LDAP_NOCACHE */
92 if ( ld->ld_error != NULL ) {
93 LDAP_FREE( ld->ld_error );
97 if ( ld->ld_matched != NULL ) {
98 LDAP_FREE( ld->ld_matched );
99 ld->ld_matched = NULL;
102 if ( ld->ld_host != NULL ) {
103 LDAP_FREE( ld->ld_host );
107 if ( ld->ld_abandoned != NULL ) {
108 LDAP_FREE( ld->ld_abandoned );
109 ld->ld_abandoned = NULL;
112 if ( ld->ld_selectinfo != NULL ) {
113 ldap_free_select_info( ld->ld_selectinfo );
114 ld->ld_selectinfo = NULL;
117 if ( ld->ld_options.ldo_defludp != NULL ) {
118 ldap_free_urllist( ld->ld_options.ldo_defludp );
119 ld->ld_options.ldo_defludp = NULL;
122 if ( ld->ld_options.ldo_tm_api != NULL ) {
123 LDAP_FREE( ld->ld_options.ldo_tm_api );
124 ld->ld_options.ldo_tm_api = NULL;
127 if ( ld->ld_options.ldo_tm_net != NULL ) {
128 LDAP_FREE( ld->ld_options.ldo_tm_net );
129 ld->ld_options.ldo_tm_net = NULL;
132 ber_sockbuf_free( ld->ld_sb );
134 LDAP_FREE( (char *) ld );
142 ldap_unbind_s( LDAP *ld )
144 return( ldap_unbind_ext( ld, NULL, NULL ) );
152 LDAPControl **sctrls,
153 LDAPControl **cctrls )
157 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
159 /* create a message to send */
160 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
161 return( ld->ld_errno );
165 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
166 LDAP_REQ_UNBIND ) == -1 ) {
167 ld->ld_errno = LDAP_ENCODING_ERROR;
169 return( ld->ld_errno );
172 /* Put Server Controls */
173 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
178 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
179 ld->ld_errno = LDAP_ENCODING_ERROR;
181 return( ld->ld_errno );
184 /* send the message */
185 if ( ber_flush( sb, ber, 1 ) == -1 ) {
186 ld->ld_errno = LDAP_SERVER_DOWN;
188 return( ld->ld_errno );
191 return( LDAP_SUCCESS );