*/
#include "includes.h"
+#include "system/iconv.h"
+#include "pstring.h"
+#include "lib/ldb/include/ldb.h"
/**
* @file
/**
Case insensitive string compararison
**/
-int StrCaseCmp(const char *s1, const char *s2)
+int strcasecmp_m(const char *s1, const char *s2)
{
codepoint_t c1=0, c2=0;
size_t size1, size2;
if (!s1 || !s2)
return(False);
- return StrCaseCmp(s1,s2) == 0;
+ return strcasecmp_m(s1,s2) == 0;
}
/**
psz1++;
while (isspace((int)*psz2))
psz2++;
- if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0'
+ if (toupper((unsigned char)*psz1) != toupper((unsigned char)*psz2)
+ || *psz1 == '\0'
|| *psz2 == '\0')
break;
psz1++;
if (len > maxlength) {
DEBUG(0,("ERROR: string overflow by %u (%u - %u) in safe_strcpy [%.50s]\n",
- (uint_t)(len-maxlength), len, maxlength, src));
+ (uint_t)(len-maxlength), (unsigned)len, (unsigned)maxlength, src));
len = maxlength;
}
valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"
+
**/
size_t strhex_to_str(char *p, size_t len, const char *strhex)
{
continue;
}
- if (!(p1 = strchr_m(hexchars, toupper(strhex[i]))))
+ if (!(p1 = strchr_m(hexchars, toupper((unsigned char)strhex[i]))))
break;
i++; /* next hex digit */
- if (!(p2 = strchr_m(hexchars, toupper(strhex[i]))))
+ if (!(p2 = strchr_m(hexchars, toupper((unsigned char)strhex[i]))))
break;
/* get the two nybbles */
if (strcmp(tok,s) == 0)
return(True);
} else {
- if (StrCaseCmp(tok,s) == 0)
+ if (strcasecmp_m(tok,s) == 0)
return(True);
}
}
return ret;
}
+/*
+ return True if any (multi-byte) character is lower case
+*/
+BOOL strhaslower(const char *string)
+{
+ while (*string) {
+ size_t c_size;
+ codepoint_t s;
+ codepoint_t t;
+
+ s = next_codepoint(string, &c_size);
+ string += c_size;
+
+ t = toupper_w(s);
+
+ if (s != t) {
+ return True; /* that means it has lower case chars */
+ }
+ }
+
+ return False;
+}
+
+/*
+ return True if any (multi-byte) character is upper case
+*/
+BOOL strhasupper(const char *string)
+{
+ while (*string) {
+ size_t c_size;
+ codepoint_t s;
+ codepoint_t t;
+
+ s = next_codepoint(string, &c_size);
+ string += c_size;
+
+ t = tolower_w(s);
+
+ if (s != t) {
+ return True; /* that means it has upper case chars */
+ }
+ }
+
+ return False;
+}
+
/**
Convert a string to lower case, allocated with talloc
**/
/* this takes advantage of the fact that upper/lower can't
change the length of a character by more than 1 byte */
- dest = talloc(ctx, 2*(strlen(src))+1);
+ dest = talloc_size(ctx, 2*(strlen(src))+1);
if (dest == NULL) {
return NULL;
}
{
size_t size=0;
char *dest;
+
+ if (!src) {
+ return NULL;
+ }
/* this takes advantage of the fact that upper/lower can't
change the length of a character by more than 1 byte */
- dest = talloc(ctx, 2*(strlen(src))+1);
+ dest = talloc_size(ctx, 2*(strlen(src))+1);
if (dest == NULL) {
return NULL;
}
c_size2 = push_codepoint(d, tolower_w(c));
if (c_size2 > c_size) {
DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n",
- c, tolower_w(c), c_size, c_size2));
+ c, tolower_w(c), (int)c_size, (int)c_size2));
smb_panic("codepoint expansion in strlower_m\n");
}
s += c_size;
c_size2 = push_codepoint(d, toupper_w(c));
if (c_size2 > c_size) {
DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n",
- c, toupper_w(c), c_size, c_size2));
+ c, toupper_w(c), (int)c_size, (int)c_size2));
smb_panic("codepoint expansion in strupper_m\n");
}
s += c_size;
return strlen_m(s) + 1;
}
-/**
- Return a RFC2254 binary string representation of a buffer.
- Used in LDAP filters.
- Caller must free.
-**/
-char *binary_string(char *buf, int len)
-{
- char *s;
- int i, j;
- const char *hex = "0123456789ABCDEF";
- s = malloc(len * 3 + 1);
- if (!s)
- return NULL;
- for (j=i=0;i<len;i++) {
- s[j] = '\\';
- s[j+1] = hex[((uint8_t)buf[i]) >> 4];
- s[j+2] = hex[((uint8_t)buf[i]) & 0xF];
- j += 3;
- }
- s[j] = 0;
- return s;
-}
-
/**
Unescape a URL encoded string, in place.
**/
/**
* Decode a base64 string into a DATA_BLOB - simple and slow algorithm
**/
-DATA_BLOB base64_decode_data_blob(const char *s)
+DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s)
{
- const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
- int bit_offset, byte_offset, idx, i, n;
- DATA_BLOB decoded = data_blob(s, strlen(s)+1);
- uint8_t *d = decoded.data;
- char *p;
-
- n=i=0;
-
- while (*s && (p=strchr_m(b64,*s))) {
- idx = (int)(p - b64);
- byte_offset = (i*6)/8;
- bit_offset = (i*6)%8;
- d[byte_offset] &= ~((1<<(8-bit_offset))-1);
- if (bit_offset < 3) {
- d[byte_offset] |= (idx << (2-bit_offset));
- n = byte_offset+1;
- } else {
- d[byte_offset] |= (idx >> (bit_offset-2));
- d[byte_offset+1] = 0;
- d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
- n = byte_offset+2;
- }
- s++; i++;
- }
-
- /* fix up length */
- decoded.length = n;
- return decoded;
+ DATA_BLOB ret = data_blob_talloc(mem_ctx, s, strlen(s)+1);
+ ret.length = ldb_base64_decode(ret.data);
+ return ret;
}
/**
**/
void base64_decode_inplace(char *s)
{
- DATA_BLOB decoded = base64_decode_data_blob(s);
- memcpy(s, decoded.data, decoded.length);
- data_blob_free(&decoded);
-
- /* null terminate */
- s[decoded.length] = '\0';
+ ldb_base64_decode(s);
}
/**
- * Encode a base64 string into a malloc()ed string caller to free.
- *
- *From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c with adjustments
+ * Encode a base64 string into a talloc()ed string caller to free.
**/
-char * base64_encode_data_blob(DATA_BLOB data)
+char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
{
- const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- int bits = 0;
- int char_count = 0;
- size_t out_cnt = 0;
- size_t len = data.length;
- size_t output_len = data.length * 2;
- char *result = malloc(output_len); /* get us plenty of space */
-
- while (len-- && out_cnt < (data.length * 2) - 5) {
- int c = (uint8_t) *(data.data++);
- bits += c;
- char_count++;
- if (char_count == 3) {
- result[out_cnt++] = b64[bits >> 18];
- result[out_cnt++] = b64[(bits >> 12) & 0x3f];
- result[out_cnt++] = b64[(bits >> 6) & 0x3f];
- result[out_cnt++] = b64[bits & 0x3f];
- bits = 0;
- char_count = 0;
- } else {
- bits <<= 8;
- }
- }
- if (char_count != 0) {
- bits <<= 16 - (8 * char_count);
- result[out_cnt++] = b64[bits >> 18];
- result[out_cnt++] = b64[(bits >> 12) & 0x3f];
- if (char_count == 1) {
- result[out_cnt++] = '=';
- result[out_cnt++] = '=';
- } else {
- result[out_cnt++] = b64[(bits >> 6) & 0x3f];
- result[out_cnt++] = '=';
- }
- }
- result[out_cnt] = '\0'; /* terminate */
- return result;
+ return ldb_base64_encode(mem_ctx, data.data, data.length);
}
#ifdef VALGRIND
if (!s || !*s) {
return talloc_strdup(mem_ctx, "");
}
- ret = talloc(mem_ctx, strlen(s)+2);
+ ret = talloc_size(mem_ctx, strlen(s)+2);
if (!ret) {
return ret;
}
{
char *dup_str = talloc_strdup(mem_ctx, str);
- *strings = talloc_realloc_p(mem_ctx,
+ *strings = talloc_realloc(mem_ctx,
*strings,
const char *, ((*num)+1));
{'A', FILE_ATTRIBUTE_ARCHIVE},
{'H', FILE_ATTRIBUTE_HIDDEN},
{'S', FILE_ATTRIBUTE_SYSTEM},
+ {'N', FILE_ATTRIBUTE_NORMAL},
{'R', FILE_ATTRIBUTE_READONLY},
{'d', FILE_ATTRIBUTE_DEVICE},
{'t', FILE_ATTRIBUTE_TEMPORARY},
};
char *ret;
- ret = talloc(mem_ctx, ARRAY_SIZE(attr_strs)+1);
+ ret = talloc_size(mem_ctx, ARRAY_SIZE(attr_strs)+1);
if (!ret) {
return NULL;
}
return ret;
}
-