unicode filename in NTCreateAndX

James Peach jorgar at gmail.com
Wed Nov 29 05:10:15 GMT 2006

On 28/11/06, Alison Winters <alisonw at sgi.com> wrote:
> Hi all,
> I've been playing around with the pcap2nbench tool in Samba 3_0 and
> noticed it wasn't picking up any of the filenames my WinXP desktop was
> requesting.  A quick look at the network trace showed the filenames
> appear to be coming in UCS-2 (or similar) encoding.  The bit of code
> that grabs the filenames as it stands is:
> file_name = (const char *) (data + 51);
> where file_name is a std::string.  Which doesn't work.  After much
> futzing around yesterday and realizing wchar_t is 4 bytes (!) in Linux i
> figured the easiest way to grab that string would be to parse it back to
> a regular std::string/char * by skipping over every nul byte.  This
> kindasorta works for what i need to do with the tool, but it'd be nice
> to do this properly and submit the fix upstream.

Sounds like you ought to convert the ucs2 to utf8. You can use iconv for
that. Poke around in the Samba sources for examples. std::string isn't
multibyte-aware, so you probably want to be careful what you do with it.

> What i'm wondering is the following...
> 1. What clients send UCS-2-encoded filenames?
> 2. How do i tell from the server side what to expect?
>    (memchr(data + 51, 0, file_name_len) is kinda a lame test)
> 3. Is it possible sometimes the first byte of the UCS-2 string is
>    uninitialized?  Is this one of those weird freaky alignment things?
> 4. Is there a non-sucking way to cast a byte array input stream to a
>    proper unicode string in STL?
> Thanks,
> Alison

James Peach | jorgar at gmail.com

More information about the samba-technical mailing list