File: entry.c

package info (click to toggle)
openldap2.3 2.3.30-5%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 18,316 kB
  • ctags: 15,854
  • sloc: ansic: 210,071; sh: 28,305; cpp: 4,231; sql: 1,661; makefile: 1,515; perl: 870
file content (140 lines) | stat: -rw-r--r-- 3,346 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* entry.c - ldbm backend entry_release routine */
/* $OpenLDAP: pkg/ldap/servers/slapd/back-ldbm/entry.c,v 1.21.2.4 2006/01/03 22:16:19 kurt Exp $ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
 * Copyright 1998-2006 The OpenLDAP Foundation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */

#include "portable.h"

#include <stdio.h>

#include <ac/socket.h>
#include <ac/string.h>

#include "slap.h"
#include "back-ldbm.h"
#include "proto-back-ldbm.h"


int
ldbm_back_entry_release_rw(
	Operation *op,
	Entry   *e,
	int     rw
)
{
	struct ldbminfo	*li = (struct ldbminfo *) op->o_bd->be_private;

	if ( slapMode == SLAP_SERVER_MODE ) {
		/* free entry and reader or writer lock */
		cache_return_entry_rw( &li->li_cache, e, rw ); 
		/* only do_add calls here with a write lock.
		 * get_entry doesn't obtain the giant lock, because its
		 * caller has already obtained it.
		 */
		if( rw ) {
			ldap_pvt_thread_rdwr_wunlock( &li->li_giant_rwlock );
		}
#if 0
		else {
			ldap_pvt_thread_rdwr_runlock( &li->li_giant_rwlock );
		}
#endif

	} else {
		if ( e->e_private ) {
			free( e->e_private );
			e->e_private = NULL;
		}
		entry_free( e );
	}

	return 0;
}

/* return LDAP_SUCCESS IFF we can retrieve the specified entry.
 */
int ldbm_back_entry_get(
	Operation *op,
	struct berval *ndn,
	ObjectClass *oc,
	AttributeDescription *at,
	int rw,
	Entry **ent )
{
	struct ldbminfo	*li = (struct ldbminfo *) op->o_bd->be_private;
	Entry *e;
	int	rc;
	const char *at_name = at ? at->ad_cname.bv_val : "(null)";

	Debug( LDAP_DEBUG_ARGS,
		"=> ldbm_back_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 ); 
	Debug( LDAP_DEBUG_ARGS,
		"=> ldbm_back_entry_get: oc: \"%s\", at: \"%s\"\n",
		oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);

	/* don't grab the giant lock - our caller has already gotten it. */

	/* can we find entry */
	e = dn2entry_rw( op->o_bd, ndn, NULL, rw );
	if (e == NULL) {
		Debug( LDAP_DEBUG_ACL,
			"=> ldbm_back_entry_get: cannot find entry: \"%s\"\n",
				ndn->bv_val, 0, 0 ); 
		return LDAP_NO_SUCH_OBJECT; 
	}
	
	Debug( LDAP_DEBUG_ACL,
		"=> ldbm_back_entry_get: found entry: \"%s\"\n",
		ndn->bv_val, 0, 0 ); 

#ifdef BDB_ALIASES
	/* find attribute values */
	if( is_entry_alias( e ) ) {
		Debug( LDAP_DEBUG_ACL,
			"<= ldbm_back_entry_get: entry is an alias\n", 0, 0, 0 );
		rc = LDAP_ALIAS_PROBLEM;
		goto return_results;
	}
#endif

	if( is_entry_referral( e ) ) {
		Debug( LDAP_DEBUG_ACL,
			"<= ldbm_back_entry_get: entry is a referral\n", 0, 0, 0 );
		rc = LDAP_REFERRAL;
		goto return_results;
	}

	if ( oc && !is_entry_objectclass( e, oc, 0 )) {
		Debug( LDAP_DEBUG_ACL,
			"<= ldbm_back_entry_get: failed to find objectClass %s\n",
			oc->soc_cname.bv_val, 0, 0 ); 
		rc = LDAP_NO_SUCH_ATTRIBUTE;
		goto return_results;
	}

	rc = LDAP_SUCCESS;

return_results:
	if( rc != LDAP_SUCCESS ) {
		/* free entry */
		cache_return_entry_rw(&li->li_cache, e, rw);
	} else {
		*ent = e;
	}

	Debug( LDAP_DEBUG_TRACE,
		"ldbm_back_entry_get: rc=%d\n",
		rc, 0, 0 ); 
	return(rc);
}