1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-30 19:42:05 +03:00

This fixes security=domain, which has been broke since the big charset

changeover.  For my own sainity I have created a new function to fill out both
the header and buffer for a string in an RPC struct.  This DOES NOT take a
length argument, only the actual string to be placed.

The RPC code is currently littered with code that does init_uni_hdr() followed
immidiatly by init_unistr2(), and often the length argument is wrong.  (It was
for the code I changed, even before the charset stuff).  Another bug where we
made strings AT LEAST MAX_UNICODE_LEN long hid this bug.

This works for loopback connections to Samba, and can't be any more broke than
it was before :-).  (We had double and revese conversions, fun...).

In particular this makes us multibyte complient.

In any case, if there are no objections I will slowly convert other bits of
code to the same system.
This commit is contained in:
Andrew Bartlett
-
parent 22ea0770d8
commit cf1d1cd9d6
3 changed files with 60 additions and 20 deletions

View File

@ -5,6 +5,7 @@
* Copyright (C) Andrew Tridgell 1992-1997,
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
* Copyright (C) Paul Ashton 1997.
* Copyright (C) Andrew Bartlett 2001.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -920,6 +921,59 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
}
/*******************************************************************
Inits a UNIHDR and UNISTR2 structure at one time.
********************************************************************/
void init_unistr2_and_hdr(UNISTR2 *str, UNIHDR *hdr, const char *buf )
{
size_t convbuf_len_bytes, len_bytes;
int len;
uint16 *conversion_buffer;
if (buf == NULL) {
str->buffer = NULL;
hdr->uni_str_len = 0;
hdr->uni_max_len = 0;
hdr->buffer = 0;
return;
}
convbuf_len_bytes = (sizeof(uint16)*(strlen(buf) + 1));
/* Our strings cannot expand from internal to unicode by more
than a factor of 2 */
conversion_buffer = malloc(convbuf_len_bytes);
if (conversion_buffer == NULL)
smb_panic("init_unistr: malloc fail\n");
/* Check this */
len_bytes = rpcstr_push(conversion_buffer, buf, convbuf_len_bytes, STR_TERMINATE);
len = len_bytes/sizeof(uint16);
if (len > MAX_UNISTRLEN) {
len = MAX_UNISTRLEN;
}
str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len*sizeof(uint16));
if (str->buffer == NULL)
smb_panic("init_unistr: talloc fail\n");
hdr->uni_str_len = len;
hdr->uni_max_len = len;
hdr->buffer = 1;
str->uni_str_len = len;
str->uni_max_len = len;
memcpy(str->buffer, conversion_buffer, len*sizeof(uint16));
free(conversion_buffer);
}
/*******************************************************************
Inits a UNISTR2 structure from a UNISTR
********************************************************************/