static bool lowcase_table_use_unmap;
static bool valid_table_use_unmap;
-/**
- * This table says which Unicode characters are valid dos
- * characters.
- *
- * Each value is just a single bit.
- **/
-static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */
-
/**
* Destroy global objects allocated by load_case_tables()
**/
TALLOC_FREE(frame);
}
-/*
- see if a ucs2 character can be mapped correctly to a dos character
- and mapped back to the same character in ucs2
-*/
-
-int check_dos_char(smb_ucs2_t c)
-{
- lazy_initialize_conv();
-
- /* Find the right byte, and right bit within the byte; return
- * 1 or 0 */
- return (doschar_table[(c & 0xffff) / 8] & (1 << (c & 7))) != 0;
-}
-
-
static int check_dos_char_slowly(smb_ucs2_t c)
{
char buf[10];
return (c == c2);
}
-
-/**
- * Fill out doschar table the hard way, by examining each character
- **/
-
-void init_doschar_table(void)
-{
- int i, j, byteval;
-
- /* For each byte of packed table */
-
- for (i = 0; i <= 0xffff; i += 8) {
- byteval = 0;
- for (j = 0; j <= 7; j++) {
- smb_ucs2_t c;
-
- c = i + j;
-
- if (check_dos_char_slowly(c)) {
- byteval |= 1 << j;
- }
- }
- doschar_table[i/8] = byteval;
- }
-}
-
-
/**
* Load the valid character map table from <tt>valid.dat</tt> or
* create from the configured codepage.
* It might need to be regenerated if the code page changed.
* We know that we're not using a mapped file, so we can
* free() the old one. */
- if (valid_table)
- SAFE_FREE(valid_table);
+ SAFE_FREE(valid_table);
/* use free rather than unmap */
valid_table_use_unmap = False;
DEBUG(2,("creating default valid table\n"));
valid_table = (uint8 *)SMB_MALLOC(0x10000);
+ SMB_ASSERT(valid_table != NULL);
for (i=0;i<128;i++) {
valid_table[i] = isalnum(i) || strchr(allowed,i);
}
-
+
+ lazy_initialize_conv();
+
for (;i<0x10000;i++) {
smb_ucs2_t c;
SSVAL(&c, 0, i);
- valid_table[i] = check_dos_char(c);
+ valid_table[i] = check_dos_char_slowly(c);
}
}
char *rpcstr_pull_unistr2_talloc(TALLOC_CTX *ctx, const UNISTR2 *src)
{
char *dest = NULL;
- size_t dest_len = convert_string_talloc(ctx,
- CH_UTF16LE,
- CH_UNIX,
- src->buffer,
- src->uni_str_len * 2,
- (void **)&dest,
- true);
- if (dest_len == (size_t)-1) {
+ size_t dest_len;
+
+ if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src->buffer,
+ src->uni_str_len * 2, (void *)&dest,
+ &dest_len, true))
+ {
return NULL;
}
/* Converts a string from internal samba format to unicode. Always terminates.
* Actually just a wrapper round push_ucs2_talloc().
- */
+ */
int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
{
- return push_ucs2_talloc(ctx, dest, src);
+ size_t size;
+ if (push_ucs2_talloc(ctx, dest, src, &size))
+ return size;
+ else
+ return -1;
}
/*******************************************************************
pull_ucs2(NULL, dest, str->buffer, maxlen, str->uni_str_len*2, STR_NOALIGN);
}
+#if 0
/*******************************************************************
Convert a (little-endian) UNISTR3 structure to an ASCII string.
********************************************************************/
pull_ucs2(NULL, dest, str->str.buffer, maxlen, str->uni_str_len*2,
STR_NOALIGN);
}
+#endif
+
+/*******************************************************************
+ Duplicate a UNISTR2 string into a null terminated char*
+ using a talloc context.
+********************************************************************/
+
+char *unistr2_to_ascii_talloc(TALLOC_CTX *ctx, const UNISTR2 *str)
+{
+ char *s = NULL;
+
+ if (!str || !str->buffer) {
+ return NULL;
+ }
+ if (pull_ucs2_base_talloc(ctx,
+ NULL,
+ &s,
+ str->buffer,
+ str->uni_str_len*2,
+ STR_NOALIGN) == (size_t)-1) {
+ return NULL;
+ }
+ return s;
+}
/*******************************************************************
Return a string for displaying a UNISTR2. Guarentees to return a
const char *unistr2_static(const UNISTR2 *str)
{
- size_t ret = (size_t)-1;
char *dest = NULL;
if ((str == NULL) || (str->uni_str_len == 0)) {
return "";
}
- ret = pull_ucs2_base_talloc(talloc_tos(),
- NULL,
- &dest,
- str->buffer,
- str->uni_str_len*2,
- STR_NOALIGN);
- if (ret == (size_t)-1 || dest == NULL) {
+ dest = unistr2_to_ascii_talloc(talloc_tos(), str);
+ if (!dest) {
return "";
}
return dest;
}
-/*******************************************************************
- Duplicate a UNISTR2 string into a null terminated char*
- using a talloc context.
-********************************************************************/
-
-char *unistr2_tdup(TALLOC_CTX *ctx, const UNISTR2 *str)
-{
- char *s;
- int maxlen = (str->uni_str_len+1)*4;
- if (!str->buffer) {
- return NULL;
- }
- s = (char *)TALLOC(ctx, maxlen); /* convervative */
- if (!s) {
- return NULL;
- }
- pull_ucs2(NULL, s, str->buffer, maxlen, str->uni_str_len*2, STR_NOALIGN);
- return s;
-}
-
/*******************************************************************
Convert a wchar to upper case.
********************************************************************/