Managing DNs in libads only in utf8
simo
idra at samba.org
Tue Feb 27 14:13:41 GMT 2007
On Tue, 2007-02-27 at 15:02 +0100, Volker Lendecke wrote:
> On Tue, Feb 27, 2007 at 08:54:29AM -0500, simo wrote:
> > I proposed "#define smb_utf8_t char" in another mail, but I like your
> > proposal as well, even more.
> > If everybody agrees I will proceed in converting the code to use
> > something like:
> > #typedef struct { char * dn } smb_utf8_dn;
> >
> > This should make it really hard to leak any utf8 string by mistake, and
> > should keep everybody happy the boundary is very well defined.
>
> Have you seen my second mail, with the start of a patch?
Sorry, no I read the text and didn;t notice the patch, now I have read
it.
> Two things with "typedef struct { char * dn } smb_utf8_dn;":
>
> First, it makes it necessary to allocate two talloc contexts
> per string, with twice the overhead. If we have many
> strings, this might be significant and I would like to avoid
> it if it is easily possible.
Uhm not really, I was thinking to use a way to allocate it very similar
to yours:
example:
smb_utf8_dn *utf8_dn_talloc(TALLOC_CTX *ctx, char *utf8_dn) {
smb_utf8_dn *a_dn;
int len = strlen(utf8_dn);
a_dn = talloc(sizeof(smb_utf8_dn) + len + 1);
if (a_dn == NULL) return NULL;
a_dn->dn = (char *)(&a_dn[1]);
memcopy(a_dn->dn, utf8_dn, len + 1);
return a_dn;
}
Do you see any problem with this?
We keep one allocation.
> Second, why the typedef? And, why do you restrict its name to
> "_dn"? I could imagine other uses than just the LDAP DNs.
Yes, I was concentrating just on the DN change, but we can of course
make it generic.
Simo.
--
Simo Sorce
Samba Team GPL Compliance Officer
email: idra at samba.org
http://samba.org
More information about the samba-technical
mailing list