summaryrefslogtreecommitdiff
path: root/libcli/auth
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-03-16 21:17:29 +1100
committerAndrew Bartlett <abartlet@samba.org>2009-04-14 14:19:40 +1000
commit8e73b652f92795dcb35cd3826c88926e8072ea31 (patch)
tree04cf7b682d95f41e10263d03e353f172abff3e10 /libcli/auth
parent9feea7fa4c36e124a2d6f8711ee849b039a22f34 (diff)
downloadsamba-8e73b652f92795dcb35cd3826c88926e8072ea31.tar.gz
samba-8e73b652f92795dcb35cd3826c88926e8072ea31.tar.bz2
samba-8e73b652f92795dcb35cd3826c88926e8072ea31.zip
Rework trivial msrpc parser to use convert_string_talloc()
Also avoid still string conversions when trying to match NTLMSSP in the header of the NTLMSSP packet. This also changes a few things to avoid const warnings. Andrew Bartlett
Diffstat (limited to 'libcli/auth')
-rw-r--r--libcli/auth/msrpc_parse.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/libcli/auth/msrpc_parse.c b/libcli/auth/msrpc_parse.c
index 969845d6c5..6c60258ad3 100644
--- a/libcli/auth/msrpc_parse.c
+++ b/libcli/auth/msrpc_parse.c
@@ -209,7 +209,7 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
{
int i;
va_list ap;
- const char **ps, *s;
+ char **ps, *s;
DATA_BLOB *b;
size_t head_ofs = 0;
uint16_t len1, len2;
@@ -228,9 +228,9 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
len2 = SVAL(blob->data, head_ofs); head_ofs += 2;
ptr = IVAL(blob->data, head_ofs); head_ofs += 4;
- ps = (const char **)va_arg(ap, char **);
+ ps = va_arg(ap, char **);
if (len1 == 0 && len2 == 0) {
- *ps = "";
+ *ps = discard_const("");
} else {
/* make sure its in the right format - be strict */
if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
@@ -249,15 +249,15 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
}
if (0 < len1) {
- pull_string(p, blob->data + ptr, p_len,
- len1, STR_UNICODE|STR_NOALIGN);
- (*ps) = talloc_strdup(mem_ctx, p);
- if (!(*ps)) {
+ size_t pull_len;
+ if (!convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
+ blob->data + ptr, len1,
+ ps, &pull_len, false)) {
ret = false;
goto cleanup;
}
} else {
- (*ps) = "";
+ (*ps) = discard_const("");
}
}
break;
@@ -267,10 +267,10 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
len2 = SVAL(blob->data, head_ofs); head_ofs += 2;
ptr = IVAL(blob->data, head_ofs); head_ofs += 4;
- ps = (const char **)va_arg(ap, char **);
+ ps = (char **)va_arg(ap, char **);
/* make sure its in the right format - be strict */
if (len1 == 0 && len2 == 0) {
- *ps = "";
+ *ps = discard_const("");
} else {
if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
ret = false;
@@ -284,15 +284,16 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
}
if (0 < len1) {
- pull_string(p, blob->data + ptr, p_len,
- len1, STR_ASCII|STR_NOALIGN);
- (*ps) = talloc_strdup(mem_ctx, p);
- if (!(*ps)) {
+ size_t pull_len;
+
+ if (!convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX,
+ blob->data + ptr, len1,
+ ps, &pull_len, false)) {
ret = false;
goto cleanup;
}
} else {
- (*ps) = "";
+ (*ps) = discard_const("");
}
}
break;
@@ -344,19 +345,18 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
s = va_arg(ap, char *);
if (blob->data + head_ofs < (uint8_t *)head_ofs ||
- blob->data + head_ofs < blob->data) {
+ blob->data + head_ofs < blob->data ||
+ (head_ofs + (strlen(s) + 1)) > blob->length) {
ret = false;
goto cleanup;
}
- head_ofs += pull_string(p,
- blob->data+head_ofs, p_len,
- blob->length - head_ofs,
- STR_ASCII|STR_TERMINATE);
- if (strcmp(s, p) != 0) {
+ if (memcmp(blob->data + head_ofs, s, strlen(s)+1) != 0) {
ret = false;
goto cleanup;
}
+ head_ofs += (strlen(s) + 1);
+
break;
}
}