]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
ITS#3846 don't give hashed passwords to SASL, it only wants cleartext.
[openldap] / servers / slapd / operation.c
1 /* operation.c - routines to deal with pending ldap operations */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/socket.h>
33
34 #include "slap.h"
35
36 #ifdef LDAP_SLAPI
37 #include "slapi/slapi.h"
38 #endif
39
40 static ldap_pvt_thread_mutex_t  slap_op_mutex;
41 static LDAP_STAILQ_HEAD(s_o, slap_op)   slap_free_ops;
42 static time_t last_time;
43 static int last_incr;
44
45 void slap_op_init(void)
46 {
47         ldap_pvt_thread_mutex_init( &slap_op_mutex );
48         LDAP_STAILQ_INIT(&slap_free_ops);
49 }
50
51 void slap_op_destroy(void)
52 {
53         Operation *o;
54
55         while ( (o = LDAP_STAILQ_FIRST( &slap_free_ops )) != NULL) {
56                 LDAP_STAILQ_REMOVE_HEAD( &slap_free_ops, o_next );
57                 LDAP_STAILQ_NEXT(o, o_next) = NULL;
58                 ch_free( o );
59         }
60         ldap_pvt_thread_mutex_destroy( &slap_op_mutex );
61 }
62
63 void
64 slap_op_free( Operation *op )
65 {
66         struct berval slap_empty_bv_dup;
67
68         assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
69
70         if ( op->o_ber != NULL ) {
71                 ber_free( op->o_ber, 1 );
72         }
73         if ( !BER_BVISNULL( &op->o_dn ) ) {
74                 free( op->o_dn.bv_val );
75         }
76         if ( !BER_BVISNULL( &op->o_ndn ) ) {
77                 free( op->o_ndn.bv_val );
78         }
79         if ( !BER_BVISNULL( &op->o_authmech ) ) {
80                 free( op->o_authmech.bv_val );
81         }
82         if ( op->o_ctrls != NULL ) {
83                 slap_free_ctrls( op, op->o_ctrls );
84         }
85
86 #ifdef LDAP_CONNECTIONLESS
87         if ( op->o_res_ber != NULL ) {
88                 ber_free( op->o_res_ber, 1 );
89         }
90 #endif
91
92         {
93                 GroupAssertion *g, *n;
94                 for ( g = op->o_groups; g; g = n ) {
95                         n = g->ga_next;
96                         slap_sl_free( g, op->o_tmpmemctx );
97                 }
98                 op->o_groups = NULL;
99         }
100
101 #if defined( LDAP_SLAPI )
102         if ( op->o_pb != NULL ) {
103                 slapi_pblock_destroy( (Slapi_PBlock *)op->o_pb );
104                 slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, op );
105         }
106 #endif /* defined( LDAP_SLAPI ) */
107
108
109         memset( op, 0, sizeof(Operation) + sizeof(Opheader) + SLAP_MAX_CIDS * sizeof(void *) );
110         op->o_hdr = (Opheader *)(op+1);
111         op->o_controls = (void **)(op->o_hdr+1);
112
113         ldap_pvt_thread_mutex_lock( &slap_op_mutex );
114         LDAP_STAILQ_INSERT_HEAD( &slap_free_ops, op, o_next );
115         ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
116 }
117
118 Operation *
119 slap_op_alloc(
120     BerElement          *ber,
121     ber_int_t   msgid,
122     ber_tag_t   tag,
123     ber_int_t   id
124 )
125 {
126         Operation       *op;
127         struct berval slap_empty_bv_dup;
128
129         ldap_pvt_thread_mutex_lock( &slap_op_mutex );
130         if ((op = LDAP_STAILQ_FIRST( &slap_free_ops ))) {
131                 LDAP_STAILQ_REMOVE_HEAD( &slap_free_ops, o_next );
132         }
133         ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
134
135         if (!op) {
136                 op = (Operation *) ch_calloc( 1, sizeof(Operation)
137                         + sizeof(Opheader) + SLAP_MAX_CIDS * sizeof(void *) );
138                 op->o_hdr = (Opheader *)(op + 1);
139                 op->o_controls = (void **)(op->o_hdr+1);
140         }
141
142         op->o_ber = ber;
143         op->o_msgid = msgid;
144         op->o_tag = tag;
145
146         op->o_time = slap_get_time();
147         if ( op->o_time == last_time ) {
148                 op->o_tincr = ++last_incr;
149         } else {
150                 last_time = op->o_time;
151                 last_incr = 0;  /* o_tincr is alredy zero */
152         }
153         op->o_opid = id;
154         op->o_res_ber = NULL;
155
156 #if defined( LDAP_SLAPI )
157         if ( slapi_plugins_used ) {
158                 op->o_pb = slapi_pblock_new();
159                 slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
160         }
161 #endif /* defined( LDAP_SLAPI ) */
162
163         return( op );
164 }