1 /* $OpenLDAP: pkg/ldap/servers/slapd/back-sql/operational.c,v 1.21.2.5 2008/02/11 23:26:48 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2008 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
6 * Portions Copyright 2002 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Dmitry Kovalev for inclusion
19 * by OpenLDAP Software. Additional significant contributors include
20 * Pierangelo Masarati.
26 #include <sys/types.h>
29 #include "proto-sql.h"
33 * sets the supported operational attributes (if required)
37 backsql_operational_entryUUID( backsql_info
*bi
, backsql_entryID
*id
)
40 struct berval val
, nval
;
41 AttributeDescription
*desc
= slap_schema
.si_ad_entryUUID
;
44 backsql_entryUUID( bi
, id
, &val
, NULL
);
46 rc
= (*desc
->ad_type
->sat_equality
->smr_normalize
)(
47 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
,
48 desc
->ad_type
->sat_syntax
,
49 desc
->ad_type
->sat_equality
,
51 if ( rc
!= LDAP_SUCCESS
) {
52 ber_memfree( val
.bv_val
);
56 a
= attr_alloc( desc
);
59 a
->a_vals
= (BerVarray
) ch_malloc( 2 * sizeof( struct berval
) );
61 BER_BVZERO( &a
->a_vals
[ 1 ] );
63 a
->a_nvals
= (BerVarray
) ch_malloc( 2 * sizeof( struct berval
) );
64 a
->a_nvals
[ 0 ] = nval
;
65 BER_BVZERO( &a
->a_nvals
[ 1 ] );
71 backsql_operational_entryCSN( Operation
*op
)
73 char csnbuf
[ LDAP_LUTIL_CSNSTR_BUFSIZE
];
74 struct berval entryCSN
;
77 a
= attr_alloc( slap_schema
.si_ad_entryCSN
);
79 a
->a_vals
= ch_malloc( 2 * sizeof( struct berval
) );
80 BER_BVZERO( &a
->a_vals
[ 1 ] );
82 #ifdef BACKSQL_SYNCPROV
83 if ( op
->o_sync
&& op
->o_tag
== LDAP_REQ_SEARCH
&& op
->o_private
!= NULL
) {
84 assert( op
->o_private
!= NULL
);
86 entryCSN
= *((struct berval
*)op
->o_private
);
89 #endif /* BACKSQL_SYNCPROV */
91 entryCSN
.bv_val
= csnbuf
;
92 entryCSN
.bv_len
= sizeof( csnbuf
);
93 slap_get_csn( op
, &entryCSN
, 0 );
96 ber_dupbv( &a
->a_vals
[ 0 ], &entryCSN
);
98 a
->a_nvals
= a
->a_vals
;
109 backsql_info
*bi
= (backsql_info
*)op
->o_bd
->be_private
;
110 SQLHDBC dbh
= SQL_NULL_HDBC
;
114 BACKSQL_OP_HASSUBORDINATES
= 0,
115 BACKSQL_OP_ENTRYUUID
,
120 int get_conn
= BACKSQL_OP_LAST
,
121 got
[ BACKSQL_OP_LAST
] = { 0 };
123 Debug( LDAP_DEBUG_TRACE
, "==>backsql_operational(): entry \"%s\"\n",
124 rs
->sr_entry
->e_nname
.bv_val
, 0, 0 );
126 for ( ap
= &rs
->sr_operational_attrs
; *ap
; ap
= &(*ap
)->a_next
) {
127 if ( (*ap
)->a_desc
== slap_schema
.si_ad_hasSubordinates
) {
129 got
[ BACKSQL_OP_HASSUBORDINATES
] = 1;
131 } else if ( (*ap
)->a_desc
== slap_schema
.si_ad_entryUUID
) {
133 got
[ BACKSQL_OP_ENTRYUUID
] = 1;
135 } else if ( (*ap
)->a_desc
== slap_schema
.si_ad_entryCSN
) {
137 got
[ BACKSQL_OP_ENTRYCSN
] = 1;
145 rc
= backsql_get_db_conn( op
, &dbh
);
146 if ( rc
!= LDAP_SUCCESS
) {
147 Debug( LDAP_DEBUG_TRACE
, "backsql_operational(): "
148 "could not get connection handle - exiting\n",
153 if ( ( SLAP_OPATTRS( rs
->sr_attr_flags
) || ad_inlist( slap_schema
.si_ad_hasSubordinates
, rs
->sr_attrs
) )
154 && !got
[ BACKSQL_OP_HASSUBORDINATES
]
155 && attr_find( rs
->sr_entry
->e_attrs
, slap_schema
.si_ad_hasSubordinates
) == NULL
)
157 rc
= backsql_has_children( op
, dbh
, &rs
->sr_entry
->e_nname
);
160 case LDAP_COMPARE_TRUE
:
161 case LDAP_COMPARE_FALSE
:
162 *ap
= slap_operational_hasSubordinate( rc
== LDAP_COMPARE_TRUE
);
163 assert( *ap
!= NULL
);
169 Debug( LDAP_DEBUG_TRACE
, "backsql_operational(): "
170 "has_children failed( %d)\n", rc
, 0, 0 );
175 if ( ( SLAP_OPATTRS( rs
->sr_attr_flags
) || ad_inlist( slap_schema
.si_ad_entryUUID
, rs
->sr_attrs
) )
176 && !got
[ BACKSQL_OP_ENTRYUUID
]
177 && attr_find( rs
->sr_entry
->e_attrs
, slap_schema
.si_ad_entryUUID
) == NULL
)
179 backsql_srch_info bsi
= { 0 };
181 rc
= backsql_init_search( &bsi
, &rs
->sr_entry
->e_nname
,
183 (time_t)(-1), NULL
, dbh
, op
, rs
, NULL
,
184 BACKSQL_ISF_GET_ID
);
185 if ( rc
!= LDAP_SUCCESS
) {
186 Debug( LDAP_DEBUG_TRACE
, "backsql_operational(): "
187 "could not retrieve entry ID - no such entry\n",
192 *ap
= backsql_operational_entryUUID( bi
, &bsi
.bsi_base_id
);
194 (void)backsql_free_entryID( &bsi
.bsi_base_id
, 0, op
->o_tmpmemctx
);
196 if ( bsi
.bsi_attrs
!= NULL
) {
197 op
->o_tmpfree( bsi
.bsi_attrs
, op
->o_tmpmemctx
);
201 Debug( LDAP_DEBUG_TRACE
, "backsql_operational(): "
202 "could not retrieve entryUUID\n",
210 if ( ( SLAP_OPATTRS( rs
->sr_attr_flags
) || ad_inlist( slap_schema
.si_ad_entryCSN
, rs
->sr_attrs
) )
211 && !got
[ BACKSQL_OP_ENTRYCSN
]
212 && attr_find( rs
->sr_entry
->e_attrs
, slap_schema
.si_ad_entryCSN
) == NULL
)
214 *ap
= backsql_operational_entryCSN( op
);
216 Debug( LDAP_DEBUG_TRACE
, "backsql_operational(): "
217 "could not retrieve entryCSN\n",
225 Debug( LDAP_DEBUG_TRACE
, "<==backsql_operational(%d)\n", rc
, 0, 0);