Skip to content

Commit

Permalink
Ticket #47677 - Size returned by slapi_entry_size is not accurate
Browse files Browse the repository at this point in the history
Description: slapi_entry_size calculating the entry size had issues.
. To calculate the Slapi_DN size, local function slapi_dn_size was used.
  Local slapi_dn_size missed to count the raw dn length.  This patch
  replaces slapi_dn_size with (slapi_sdn_get_size - sizeof(Slapi_DN)).
. slapi_entry_size counted Slapi_RDN twice.
. slapi_entry_size did not count the size of e_virtual_lock, e_aux_attrs
  and e_extension.

https://fedorahosted.org/389/ticket/47677

Reviewed by rmeggins@redhat.com (Thank you, Rich!!)
(cherry picked from commit b1e4cdf)
  • Loading branch information
nhosoi committed Feb 11, 2014
1 parent 476a193 commit 7b08429
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 33 deletions.
10 changes: 7 additions & 3 deletions ldap/servers/slapd/dn.c
Expand Up @@ -2737,18 +2737,22 @@ sdn_dump( const Slapi_DN *sdn, const char *text)
size_t
slapi_sdn_get_size(const Slapi_DN *sdn)
{
size_t sz = sizeof(Slapi_DN);
size_t sz = 0;
/* slapi_sdn_get_ndn_len returns the normalized dn length
* if dn or ndn exists. If both does not exist, it
* normalizes udn and set it to dn and returns the length.
*/
sz += slapi_sdn_get_ndn_len(sdn);
if (NULL == sdn) {
return sz;
}
sz += slapi_sdn_get_ndn_len(sdn) + 1 /* '\0' */;
if (sdn->dn && sdn->ndn) {
sz += slapi_sdn_get_ndn_len(sdn);
sz *= 2;
}
if (sdn->udn) {
sz += strlen(sdn->udn) + 1;
}
sz += sizeof(Slapi_DN);
return sz;
}

Expand Down
47 changes: 23 additions & 24 deletions ldap/servers/slapd/entry.c
Expand Up @@ -89,8 +89,9 @@ struct attrs_in_extension attrs_in_extension[] =
{PSEUDO_ATTR_UNHASHEDUSERPASSWORD,
slapi_pw_get_entry_ext,
slapi_pw_set_entry_ext,
pw_copy_entry_ext},
{NULL, NULL, NULL}
pw_copy_entry_ext,
pw_get_ext_size},
{NULL, NULL, NULL, NULL, NULL}
};

/* Structure used to store the virtual attribute cache in each entry
Expand Down Expand Up @@ -2040,40 +2041,38 @@ static size_t slapi_attrlist_size(Slapi_Attr *attrs)
return size;
}

static size_t slapi_dn_size(Slapi_DN *sdn)
{
size_t size = 0;

if (sdn == NULL) return 0;

if (slapi_sdn_get_dn(sdn)) {
size += slapi_sdn_get_ndn_len(sdn) + 1;
}
if (slapi_sdn_get_ndn(sdn)) {
size += slapi_sdn_get_ndn_len(sdn) + 1;
}

return size;
}

/* return the approximate size of an entry --
* useful for checking cache sizes, etc
*/
size_t
slapi_entry_size(Slapi_Entry *e)
{
u_long size = 0;

/* doesn't include memory used by e_extension */
size_t size = 0;

if (e->e_uniqueid) size += strlen(e->e_uniqueid) + 1;
if (e->e_dncsnset) size += csnset_size(e->e_dncsnset);
if (e->e_maxcsn) size += sizeof( CSN );
size += slapi_dn_size(&e->e_sdn);
size += slapi_rdn_get_size(&e->e_srdn);
if (e->e_virtual_lock) size += sizeof(Slapi_RWLock);
/* Slapi_DN and RDN are included in Slapi_Entry */
size += (slapi_sdn_get_size(&e->e_sdn) - sizeof(Slapi_DN));
size += (slapi_rdn_get_size(&e->e_srdn) - sizeof(Slapi_RDN));
size += slapi_attrlist_size(e->e_attrs);
if (e->e_deleted_attrs) size += slapi_attrlist_size(e->e_deleted_attrs);
size += slapi_attrlist_size(e->e_deleted_attrs);
size += slapi_attrlist_size(e->e_aux_attrs);
size += entry_vattr_size(e);
if (e->e_extension) {
struct attrs_in_extension *aiep;
int cnt;
size_t extsiz = 0;
for (aiep = attrs_in_extension, cnt = 0;
aiep && aiep->ext_type; aiep++, cnt++) {

if (LDAP_SUCCESS == aiep->ext_get_size(e, &extsiz)) {
size += extsiz;
}
}
size += cnt * sizeof(void *);
}
size += sizeof(Slapi_Entry);

return size;
Expand Down
25 changes: 25 additions & 0 deletions ldap/servers/slapd/pw.c
Expand Up @@ -2714,3 +2714,28 @@ slapi_pw_get_scheme_name(struct pw_scheme *pass_scheme)
{
return pass_scheme->pws_name;
}

int
pw_get_ext_size(Slapi_Entry *entry, size_t *size)
{
Slapi_Value **pw_entry_values;

if (NULL == size) {
return LDAP_PARAM_ERROR;
}
*size = 0;
if (NULL == entry->e_extension) {
return LDAP_SUCCESS;
}
*size += sizeof(struct slapi_pw_entry_ext);
*size += sizeof(Slapi_RWLock);
if (LDAP_SUCCESS == slapi_pw_get_entry_ext(entry, &pw_entry_values)) {
Slapi_Value *cvalue;
int idx = valuearray_first_value(pw_entry_values, &cvalue);
while (idx >= 0) {
*size += value_size(cvalue);
idx = valuearray_next_value(pw_entry_values, idx, &cvalue);
}
}
return LDAP_SUCCESS;
}
1 change: 1 addition & 0 deletions ldap/servers/slapd/slap.h
Expand Up @@ -679,6 +679,7 @@ struct attrs_in_extension {
IFP ext_get;
IFP ext_set;
IFP ext_copy;
IFP ext_get_size;
};

extern struct attrs_in_extension attrs_in_extension[];
Expand Down
1 change: 1 addition & 0 deletions ldap/servers/slapd/slapi-private.h
Expand Up @@ -1270,6 +1270,7 @@ int slapi_add_internal_attr_syntax( const char *name, const char *oid, const cha
/* pw.c */
void pw_exp_init ( void );
int pw_copy_entry_ext(Slapi_Entry *src_e, Slapi_Entry *dest_e);
int pw_get_ext_size(Slapi_Entry *e, size_t *size);

/* op_shared.c */
void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods);
Expand Down
11 changes: 5 additions & 6 deletions ldap/servers/slapd/valueset.c
Expand Up @@ -512,11 +512,11 @@ valuearray_size(Slapi_Value **va)
if(va!=NULL && va[0]!=NULL)
{
int i;
for (i = 0; va[i]; i++)
for (i = 0; va[i]; i++)
{
s += value_size(va[i]);
}
s += (i + 1) * sizeof(Slapi_Value*);
s += (i + 1) * sizeof(Slapi_Value*);
}
return s;
}
Expand Down Expand Up @@ -850,10 +850,9 @@ valueset_get_valuearray(const Slapi_ValueSet *vs)
size_t
valueset_size(const Slapi_ValueSet *vs)
{
size_t s= 0;
if(!valuearray_isempty(vs->va))
{
s= valuearray_size(vs->va);
size_t s = 0;
if (vs && !valuearray_isempty(vs->va)) {
s = valuearray_size(vs->va);
}
return s;
}
Expand Down

0 comments on commit 7b08429

Please sign in to comment.