UTF-8 and LDAP

Andrew Bartlett abartlet at pcug.org.au
Fri Mar 1 20:20:25 GMT 2002

Juergen Hasch wrote:
> Am Freitag, 1. März 2002 02:13 schrieb Andrew Bartlett:
> > Can you look at doing these without using fstrings all over the place?
> > We are trying (slowly, painfully) to move to allocated buffers.  We have
> > some 'convert and allocate' functions that might do what you want - or
> > you could add a convert and talloc() version if that makes it easier.
> >
> Now this is somehow more a political issue than an implementation problem.
> I can use talloc() at some locations where a TALLOC_CTX is already available,
> but in other cases it seems more straightforward to use malloc() like this:
>         utf8_field=malloc(2*strlen(field));
>         push_utf8(utf8_field,field,2*strlen(field));
>         ...
>         SAFE_FREE(utf8_field);
> Alternatively I can do:
>         utf8_field=push_utf8_allocate(field);
>         ...
>         SAFE_FREE(utf8_field);

This looks the prefereable choice, but use the existing
'convert_string_allocate' function.

> Using something like this:
> char *push_utf8_allocate(const char *src)
> {
>         int src_len = strlen(src);
>         char *pb;
>         pb = malloc(2*src_len);
>         if (pb==NULL)
>                 return -1;
>         push_utf8(pb, src, 2*src_len, STR_TERMINATE);
>         return realloc(pb,strlen(pb));
> }

The existing function is a bit better with memory allocation, but thats
the basic idea.  If you want to add a 'convert_string_talloc' it would
probably be quite useful, but otherwise, malloc()/SAFE_FREE() should be

Andrew Bartlett

Andrew Bartlett                                 abartlet at pcug.org.au
Manager, Authentication Subsystems, Samba Team  abartlet at samba.org
Student Network Administrator, Hawker College   abartlet at hawkerc.net
http://samba.org     http://build.samba.org     http://hawkerc.net

More information about the samba-technical mailing list