wldap32: Copy embedded berval structures too.

This commit is contained in:
Hans Leidekker 2005-12-31 13:13:05 +01:00 committed by Alexandre Julliard
parent 42bf104b0d
commit ef387ae87c
1 changed files with 137 additions and 17 deletions

View File

@ -237,6 +237,59 @@ static inline void strarrayfreeU( char **strarray )
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
static inline struct berval *bvdup( struct berval *bv )
{
struct berval *berval;
DWORD size = sizeof(struct berval) + bv->bv_len;
berval = HeapAlloc( GetProcessHeap(), 0, size );
if (berval)
{
char *val = (char *)berval + sizeof(struct berval);
berval->bv_len = bv->bv_len;
berval->bv_val = val;
memcpy( val, bv->bv_val, bv->bv_len );
}
return berval;
}
static inline DWORD bvarraylen( struct berval **bv )
{
struct berval **p = bv;
while (*p) p++;
return p - bv;
}
static inline struct berval **bvarraydup( struct berval **bv )
{
struct berval **berval = NULL;
DWORD size;
if (bv)
{
size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
berval = HeapAlloc( GetProcessHeap(), 0, size );
if (berval)
{
struct berval **p = bv;
struct berval **q = berval;
while (*p) *q++ = bvdup( *p++ );
*q = NULL;
}
}
return berval;
}
static inline void bvarrayfree( struct berval **bv )
{
struct berval **p = bv;
while (*p) HeapFree( GetProcessHeap(), 0, *p++ );
HeapFree( GetProcessHeap(), 0, bv );
}
static inline LDAPModW *modAtoW( LDAPModA *mod ) static inline LDAPModW *modAtoW( LDAPModA *mod )
{ {
LDAPModW *modW; LDAPModW *modW;
@ -248,7 +301,7 @@ static inline LDAPModW *modAtoW( LDAPModA *mod )
modW->mod_type = strAtoW( mod->mod_type ); modW->mod_type = strAtoW( mod->mod_type );
if (mod->mod_op & LDAP_MOD_BVALUES) if (mod->mod_op & LDAP_MOD_BVALUES)
modW->mod_vals.modv_bvals = mod->mod_vals.modv_bvals; modW->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
else else
modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals ); modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
} }
@ -266,7 +319,7 @@ static inline LDAPMod *modWtoU( LDAPModW *mod )
modU->mod_type = strWtoU( mod->mod_type ); modU->mod_type = strWtoU( mod->mod_type );
if (mod->mod_op & LDAP_MOD_BVALUES) if (mod->mod_op & LDAP_MOD_BVALUES)
modU->mod_vals.modv_bvals = mod->mod_vals.modv_bvals; modU->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
else else
modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals ); modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
} }
@ -275,14 +328,18 @@ static inline LDAPMod *modWtoU( LDAPModW *mod )
static inline void modfreeW( LDAPModW *mod ) static inline void modfreeW( LDAPModW *mod )
{ {
if (!(mod->mod_op & LDAP_MOD_BVALUES)) if (mod->mod_op & LDAP_MOD_BVALUES)
bvarrayfree( mod->mod_vals.modv_bvals );
else
strarrayfreeW( mod->mod_vals.modv_strvals ); strarrayfreeW( mod->mod_vals.modv_strvals );
HeapFree( GetProcessHeap(), 0, mod ); HeapFree( GetProcessHeap(), 0, mod );
} }
static inline void modfreeU( LDAPMod *mod ) static inline void modfreeU( LDAPMod *mod )
{ {
if (!(mod->mod_op & LDAP_MOD_BVALUES)) if (mod->mod_op & LDAP_MOD_BVALUES)
bvarrayfree( mod->mod_vals.modv_bvals );
else
strarrayfreeU( mod->mod_vals.modv_strvals ); strarrayfreeU( mod->mod_vals.modv_strvals );
HeapFree( GetProcessHeap(), 0, mod ); HeapFree( GetProcessHeap(), 0, mod );
} }
@ -368,52 +425,112 @@ static inline void modarrayfreeU( LDAPMod **modarray )
static inline LDAPControlW *controlAtoW( LDAPControlA *control ) static inline LDAPControlW *controlAtoW( LDAPControlA *control )
{ {
LDAPControlW *controlW; LDAPControlW *controlW;
DWORD len = control->ldctl_value.bv_len;
char *val = NULL;
if (control->ldctl_value.bv_val)
{
val = HeapAlloc( GetProcessHeap(), 0, len );
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len );
}
controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) ); controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
if (controlW) if (!controlW)
{ {
memcpy( controlW, control, sizeof(LDAPControlW) ); HeapFree( GetProcessHeap(), 0, val );
controlW->ldctl_oid = strAtoW( control->ldctl_oid ); return NULL;
} }
controlW->ldctl_oid = strAtoW( control->ldctl_oid );
controlW->ldctl_value.bv_len = len;
controlW->ldctl_value.bv_val = val;
controlW->ldctl_iscritical = control->ldctl_iscritical;
return controlW; return controlW;
} }
static inline LDAPControlA *controlWtoA( LDAPControlW *control ) static inline LDAPControlA *controlWtoA( LDAPControlW *control )
{ {
LDAPControlA *controlA; LDAPControlA *controlA;
DWORD len = control->ldctl_value.bv_len;
char *val = NULL;
controlA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) ); if (control->ldctl_value.bv_val)
if (controlA)
{ {
memcpy( controlA, control, sizeof(LDAPControlA) ); val = HeapAlloc( GetProcessHeap(), 0, len );
controlA->ldctl_oid = strWtoA( control->ldctl_oid ); if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len );
} }
controlA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlA) );
if (!controlA)
{
HeapFree( GetProcessHeap(), 0, val );
return NULL;
}
controlA->ldctl_oid = strWtoA( control->ldctl_oid );
controlA->ldctl_value.bv_len = len;
controlA->ldctl_value.bv_val = val;
controlA->ldctl_iscritical = control->ldctl_iscritical;
return controlA; return controlA;
} }
static inline LDAPControl *controlWtoU( LDAPControlW *control ) static inline LDAPControl *controlWtoU( LDAPControlW *control )
{ {
LDAPControl *controlU; LDAPControl *controlU;
DWORD len = control->ldctl_value.bv_len;
char *val = NULL;
if (control->ldctl_value.bv_val)
{
val = HeapAlloc( GetProcessHeap(), 0, len );
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len );
}
controlU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) ); controlU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) );
if (controlU) if (!controlU)
{ {
memcpy( controlU, control, sizeof(LDAPControl) ); HeapFree( GetProcessHeap(), 0, val );
controlU->ldctl_oid = strWtoU( control->ldctl_oid ); return NULL;
} }
controlU->ldctl_oid = strWtoU( control->ldctl_oid );
controlU->ldctl_value.bv_len = len;
controlU->ldctl_value.bv_val = val;
controlU->ldctl_iscritical = control->ldctl_iscritical;
return controlU; return controlU;
} }
static inline LDAPControlW *controlUtoW( LDAPControl *control ) static inline LDAPControlW *controlUtoW( LDAPControl *control )
{ {
LDAPControlW *controlW; LDAPControlW *controlW;
DWORD len = control->ldctl_value.bv_len;
char *val = NULL;
if (control->ldctl_value.bv_val)
{
val = HeapAlloc( GetProcessHeap(), 0, len );
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len );
}
controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) ); controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
if (controlW) if (!controlW)
{ {
memcpy( controlW, control, sizeof(LDAPControlW) ); HeapFree( GetProcessHeap(), 0, val );
controlW->ldctl_oid = strUtoW( control->ldctl_oid ); return NULL;
} }
controlW->ldctl_oid = strUtoW( control->ldctl_oid );
controlW->ldctl_value.bv_len = len;
controlW->ldctl_value.bv_val = val;
controlW->ldctl_iscritical = control->ldctl_iscritical;
return controlW; return controlW;
} }
@ -422,6 +539,7 @@ static inline void controlfreeA( LDAPControlA *control )
if (control) if (control)
{ {
strfreeA( control->ldctl_oid ); strfreeA( control->ldctl_oid );
HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
HeapFree( GetProcessHeap(), 0, control ); HeapFree( GetProcessHeap(), 0, control );
} }
} }
@ -431,6 +549,7 @@ static inline void controlfreeW( LDAPControlW *control )
if (control) if (control)
{ {
strfreeW( control->ldctl_oid ); strfreeW( control->ldctl_oid );
HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
HeapFree( GetProcessHeap(), 0, control ); HeapFree( GetProcessHeap(), 0, control );
} }
} }
@ -440,6 +559,7 @@ static inline void controlfreeU( LDAPControl *control )
if (control) if (control)
{ {
strfreeU( control->ldctl_oid ); strfreeU( control->ldctl_oid );
HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
HeapFree( GetProcessHeap(), 0, control ); HeapFree( GetProcessHeap(), 0, control );
} }
} }