]> git.sur5r.net Git - openldap/blob - libraries/libldap/unbind.c
Coverted LDAP_LOG macro to use subsystem ID int values instead of string values
[openldap] / libraries / libldap / unbind.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*  Portions
7  *  Copyright (c) 1990 Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  unbind.c
11  */
12
13 /* An Unbind Request looks like this:
14  *
15  *      UnbindRequest ::= NULL
16  *
17  * and has no response.
18  */
19
20 #include "portable.h"
21
22 #include <stdio.h>
23 #include <ac/stdlib.h>
24
25 #include <ac/socket.h>
26 #include <ac/string.h>
27 #include <ac/time.h>
28
29 #include "ldap-int.h"
30
31 int
32 ldap_unbind_ext(
33         LDAP *ld,
34         LDAPControl **sctrls,
35         LDAPControl **cctrls )
36 {
37         int rc;
38
39         assert( ld != NULL );
40         assert( LDAP_VALID( ld ) );
41
42         /* check client controls */
43         rc = ldap_int_client_controls( ld, cctrls );
44         if( rc != LDAP_SUCCESS ) return rc;
45
46         return ldap_ld_free( ld, 1, sctrls, cctrls );
47 }
48
49 int
50 ldap_unbind_ext_s(
51         LDAP *ld,
52         LDAPControl **sctrls,
53         LDAPControl **cctrls )
54 {
55         return ldap_unbind_ext( ld, sctrls, cctrls );
56 }
57
58 int
59 ldap_unbind( LDAP *ld )
60 {
61 #ifdef NEW_LOGGING
62         LDAP_LOG ( OPERATION, ENTRY, "ldap_unbind\n", 0, 0, 0 );
63 #else
64         Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
65 #endif
66
67         return( ldap_unbind_ext( ld, NULL, NULL ) );
68 }
69
70
71 int
72 ldap_ld_free(
73         LDAP *ld,
74         int close,
75         LDAPControl **sctrls,
76         LDAPControl **cctrls )
77 {
78         LDAPMessage     *lm, *next;
79         int             err = LDAP_SUCCESS;
80
81         /* free LDAP structure and outstanding requests/responses */
82         while ( ld->ld_requests != NULL ) {
83                 ldap_free_request( ld, ld->ld_requests );
84         }
85
86         /* free and unbind from all open connections */
87         while ( ld->ld_conns != NULL ) {
88                 ldap_free_connection( ld, ld->ld_conns, 1, close );
89         }
90
91         for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
92                 next = lm->lm_next;
93                 ldap_msgfree( lm );
94         }
95
96 #ifndef LDAP_NOCACHE
97         if ( ld->ld_cache != NULL ) {
98                 ldap_destroy_cache( ld );
99                 ld->ld_cache = NULL;
100         }
101 #endif /* !LDAP_NOCACHE */
102
103         if ( ld->ld_error != NULL ) {
104                 LDAP_FREE( ld->ld_error );
105                 ld->ld_error = NULL;
106         }
107
108         if ( ld->ld_matched != NULL ) {
109                 LDAP_FREE( ld->ld_matched );
110                 ld->ld_matched = NULL;
111         }
112
113         if ( ld->ld_abandoned != NULL ) {
114                 LDAP_FREE( ld->ld_abandoned );
115                 ld->ld_abandoned = NULL;
116         }
117
118         if ( ld->ld_selectinfo != NULL ) {
119                 ldap_free_select_info( ld->ld_selectinfo );
120                 ld->ld_selectinfo = NULL;
121         }
122
123         if ( ld->ld_options.ldo_defludp != NULL ) {
124                 ldap_free_urllist( ld->ld_options.ldo_defludp );
125                 ld->ld_options.ldo_defludp = NULL;
126         }
127
128         if ( ld->ld_options.ldo_tm_api != NULL ) {
129                 LDAP_FREE( ld->ld_options.ldo_tm_api );
130                 ld->ld_options.ldo_tm_api = NULL;
131         }
132
133         if ( ld->ld_options.ldo_tm_net != NULL ) {
134                 LDAP_FREE( ld->ld_options.ldo_tm_net );
135                 ld->ld_options.ldo_tm_net = NULL;
136         }
137
138 #ifdef HAVE_CYRUS_SASL
139         if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
140                 LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );
141                 ld->ld_options.ldo_def_sasl_mech = NULL;
142         }
143
144         if ( ld->ld_options.ldo_def_sasl_realm != NULL ) {
145                 LDAP_FREE( ld->ld_options.ldo_def_sasl_realm );
146                 ld->ld_options.ldo_def_sasl_realm = NULL;
147         }
148
149         if ( ld->ld_options.ldo_def_sasl_authcid != NULL ) {
150                 LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
151                 ld->ld_options.ldo_def_sasl_authcid = NULL;
152         }
153
154         if ( ld->ld_options.ldo_def_sasl_authzid != NULL ) {
155                 LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
156                 ld->ld_options.ldo_def_sasl_authzid = NULL;
157         }
158 #endif
159
160         ber_sockbuf_free( ld->ld_sb );   
161    
162         LDAP_FREE( (char *) ld );
163    
164         return( err );
165 }
166
167 int
168 ldap_unbind_s( LDAP *ld )
169 {
170         return( ldap_unbind_ext( ld, NULL, NULL ) );
171 }
172
173
174 int
175 ldap_send_unbind(
176         LDAP *ld,
177         Sockbuf *sb,
178         LDAPControl **sctrls,
179         LDAPControl **cctrls )
180 {
181         BerElement      *ber;
182
183 #ifdef NEW_LOGGING
184         LDAP_LOG ( OPERATION, ENTRY, "ldap_send_unbind\n", 0, 0, 0 );
185 #else
186         Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
187 #endif
188
189 #ifdef LDAP_CONNECTIONLESS
190         if (LDAP_IS_UDP(ld))
191                 return LDAP_SUCCESS;
192 #endif
193         /* create a message to send */
194         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
195                 return( ld->ld_errno );
196         }
197
198         /* fill it in */
199         if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
200             LDAP_REQ_UNBIND ) == -1 ) {
201                 ld->ld_errno = LDAP_ENCODING_ERROR;
202                 ber_free( ber, 1 );
203                 return( ld->ld_errno );
204         }
205
206         /* Put Server Controls */
207         if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
208                 ber_free( ber, 1 );
209                 return ld->ld_errno;
210         }
211
212         if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
213                 ld->ld_errno = LDAP_ENCODING_ERROR;
214                 ber_free( ber, 1 );
215                 return( ld->ld_errno );
216         }
217
218         /* send the message */
219         if ( ber_flush( sb, ber, 1 ) == -1 ) {
220                 ld->ld_errno = LDAP_SERVER_DOWN;
221                 ber_free( ber, 1 );
222                 return( ld->ld_errno );
223         }
224
225         return( LDAP_SUCCESS );
226 }