1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

Solve some of the conflict between Samba3 and Samba4 push_string

This renames push_string in Samba3 into push_string_base and
push_string_check for the two different use cases.

This should allow push_string to be imported from Samba4, using it's
calling conventions.
This commit is contained in:
Andrew Bartlett 2009-03-17 14:04:43 +11:00
parent 41e4f12c48
commit 4786a493f7
8 changed files with 86 additions and 53 deletions

View File

@ -391,10 +391,13 @@ bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
size_t *converted_size);
bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
size_t *converted_size);
size_t push_string_fn(const char *function, unsigned int line,
const void *base_ptr, uint16 flags2,
void *dest, const char *src,
size_t dest_len, int flags);
size_t push_string_check_fn(const char *function, unsigned int line,
void *dest, const char *src,
size_t dest_len, int flags);
size_t push_string_base(const char *function, unsigned int line,
const char *base, uint16 flags2,
void *dest, const char *src,
size_t dest_len, int flags);
size_t pull_string_fn(const char *function,
unsigned int line,
const void *base_ptr,

View File

@ -130,13 +130,9 @@ size_t __unsafe_string_function_usage_here_char__(void);
safe_strcat_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
dest,src,maxlength)
#define push_string(base_ptr, dest, src, dest_len, flags) \
push_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
base_ptr, 0, dest, src, dest_len, flags)
#define pull_string(base_ptr, smb_flags2, dest, src, dest_len, src_len, flags) \
pull_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
base_ptr, smb_flags2, dest, src, dest_len, src_len, flags)
#define push_string_check(dest, src, dest_len, flags) \
push_string_check_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
dest, src, dest_len, flags)
#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
pull_string_talloc_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
@ -182,15 +178,10 @@ size_t __unsafe_string_function_usage_here_char__(void);
? __unsafe_string_function_usage_here__() \
: safe_strcat_fn(fn_name, fn_line, (d), (s), (max_len)))
#define push_string_fn2(fn_name, fn_line, base_ptr, flags2, dest, src, dest_len, flags) \
#define push_string_check_fn2(fn_name, fn_line, dest, src, dest_len, flags) \
(CHECK_STRING_SIZE(dest, dest_len) \
? __unsafe_string_function_usage_here_size_t__() \
: push_string_fn(fn_name, fn_line, base_ptr, flags2, dest, src, dest_len, flags))
#define pull_string_fn2(fn_name, fn_line, base_ptr, smb_flags2, dest, src, dest_len, src_len, flags) \
(CHECK_STRING_SIZE(dest, dest_len) \
? __unsafe_string_function_usage_here_size_t__() \
: pull_string_fn(fn_name, fn_line, base_ptr, smb_flags2, dest, src, dest_len, src_len, flags))
: push_string_check_fn(fn_name, fn_line, dest, src, dest_len, flags))
#define pull_string_talloc_fn2(fn_name, fn_line, ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
pull_string_talloc_fn(fn_name, fn_line, ctx, base_ptr, smb_flags2, dest, src, src_len, flags)
@ -214,8 +205,7 @@ size_t __unsafe_string_function_usage_here_char__(void);
#define safe_strcpy_fn2 safe_strcpy_fn
#define safe_strcat_fn2 safe_strcat_fn
#define push_string_fn2 push_string_fn
#define pull_string_fn2 pull_string_fn
#define push_string_check_fn2 push_string_check_fn
#define pull_string_talloc_fn2 pull_string_talloc_fn
#define clistr_push_fn2 clistr_push_fn
#define clistr_pull_fn2 clistr_pull_fn

View File

@ -1763,6 +1763,44 @@ bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
(void **)dest, converted_size, True);
}
/**
Copy a string from a char* src to a unicode or ascii
dos codepage destination choosing unicode or ascii based on the
flags supplied
Return the number of bytes occupied by the string in the destination.
flags can have:
STR_TERMINATE means include the null termination.
STR_UPPER means uppercase in the destination.
STR_ASCII use ascii even with unicode packet.
STR_NOALIGN means don't do alignment.
dest_len is the maximum length allowed in the destination. If dest_len
is -1 then no maxiumum is used.
**/
size_t push_string_check_fn(const char *function, unsigned int line,
void *dest, const char *src,
size_t dest_len, int flags)
{
#ifdef DEVELOPER
/* We really need to zero fill here, not clobber
* region, as we want to ensure that valgrind thinks
* all of the outgoing buffer has been written to
* so a send() or write() won't trap an error.
* JRA.
*/
#if 0
clobber_region(function, line, dest, dest_len);
#else
memset(dest, '\0', dest_len);
#endif
#endif
if (!(flags & STR_ASCII) && (flags & STR_UNICODE)) {
return push_ucs2(NULL, dest, src, dest_len, flags);
}
return push_ascii(dest, src, dest_len, flags);
}
/**
Copy a string from a char* src to a unicode or ascii
dos codepage destination choosing unicode or ascii based on the
@ -1777,10 +1815,10 @@ bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
is -1 then no maxiumum is used.
**/
size_t push_string_fn(const char *function, unsigned int line,
const void *base_ptr, uint16 flags2,
void *dest, const char *src,
size_t dest_len, int flags)
size_t push_string_base(const char *function, unsigned int line,
const char *base, uint16 flags2,
void *dest, const char *src,
size_t dest_len, int flags)
{
#ifdef DEVELOPER
/* We really need to zero fill here, not clobber
@ -1799,7 +1837,7 @@ size_t push_string_fn(const char *function, unsigned int line,
if (!(flags & STR_ASCII) && \
((flags & STR_UNICODE || \
(flags2 & FLAGS2_UNICODE_STRINGS)))) {
return push_ucs2(base_ptr, dest, src, dest_len, flags);
return push_ucs2(base, dest, src, dest_len, flags);
}
return push_ascii(dest, src, dest_len, flags);
}

View File

@ -32,21 +32,23 @@ size_t clistr_push_fn(const char *function,
if (dest_len == -1) {
if (((ptrdiff_t)dest < (ptrdiff_t)cli->outbuf) || (buf_used > cli->bufsize)) {
DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n"));
return push_string_fn(function, line,
cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, -1, flags);
return push_string_base(function, line,
cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, -1, flags);
}
return push_string_fn(function, line, cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, cli->bufsize - buf_used,
flags);
return push_string_base(function, line,
cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, cli->bufsize - buf_used,
flags);
}
/* 'normal' push into size-specified buffer */
return push_string_fn(function, line, cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, dest_len, flags);
return push_string_base(function, line,
cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, dest_len, flags);
}
size_t clistr_pull_fn(const char *function,

View File

@ -106,8 +106,8 @@ bool msrpc_gen(DATA_BLOB *blob,
SSVAL(blob->data, head_ofs, n*2); head_ofs += 2;
SSVAL(blob->data, head_ofs, n*2); head_ofs += 2;
SIVAL(blob->data, head_ofs, data_ofs); head_ofs += 4;
push_string(NULL, blob->data+data_ofs,
s, n*2, STR_UNICODE|STR_NOALIGN);
push_string_check(blob->data+data_ofs,
s, n*2, STR_UNICODE|STR_NOALIGN);
data_ofs += n*2;
break;
case 'A':
@ -116,8 +116,8 @@ bool msrpc_gen(DATA_BLOB *blob,
SSVAL(blob->data, head_ofs, n); head_ofs += 2;
SSVAL(blob->data, head_ofs, n); head_ofs += 2;
SIVAL(blob->data, head_ofs, data_ofs); head_ofs += 4;
push_string(NULL, blob->data+data_ofs,
s, n, STR_ASCII|STR_NOALIGN);
push_string_check(blob->data+data_ofs,
s, n, STR_ASCII|STR_NOALIGN);
data_ofs += n;
break;
case 'a':
@ -127,7 +127,7 @@ bool msrpc_gen(DATA_BLOB *blob,
n = str_charnum(s);
SSVAL(blob->data, data_ofs, n*2); data_ofs += 2;
if (0 < n) {
push_string(NULL, blob->data+data_ofs, s, n*2,
push_string_check(blob->data+data_ofs, s, n*2,
STR_UNICODE|STR_NOALIGN);
}
data_ofs += n*2;
@ -156,8 +156,8 @@ bool msrpc_gen(DATA_BLOB *blob,
case 'C':
s = va_arg(ap, char *);
n = str_charnum(s) + 1;
head_ofs += push_string(NULL, blob->data+head_ofs, s, n,
STR_ASCII|STR_TERMINATE);
head_ofs += push_string_check(blob->data+head_ofs, s, n,
STR_ASCII|STR_TERMINATE);
break;
}
}

View File

@ -499,9 +499,9 @@ bool encode_pw_buffer(uint8 buffer[516], const char *password, int string_flags)
/* the incoming buffer can be any alignment. */
string_flags |= STR_NOALIGN;
new_pw_len = push_string(NULL, new_pw,
password,
sizeof(new_pw), string_flags);
new_pw_len = push_string_check(new_pw,
password,
sizeof(new_pw), string_flags);
memcpy(&buffer[512 - new_pw_len], new_pw, new_pw_len);

View File

@ -74,7 +74,7 @@ to subnet %s\n", work->work_group, subrec->subnet_name));
SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */
p++;
p += push_string(NULL, p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
p += push_string_check(p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
global_myname(), 0x0, work->work_group,0x1e, subrec->bcast_ip,
@ -105,7 +105,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type,
safe_strcpy(upper_server_name, server_name, sizeof(upper_server_name)-1);
strupper_m(upper_server_name);
push_string(NULL, p+5, upper_server_name, 16, STR_ASCII|STR_TERMINATE);
push_string_check(p+5, upper_server_name, 16, STR_ASCII|STR_TERMINATE);
SCVAL(p,21,lp_major_announce_version()); /* Major version. */
SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */
@ -115,7 +115,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type,
SSVAL(p,27,BROWSER_ELECTION_VERSION);
SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */
p += 31 + push_string(NULL, p+31, server_comment, sizeof(outbuf) - (p + 31 - outbuf), STR_ASCII|STR_TERMINATE);
p += 31 + push_string_check(p+31, server_comment, sizeof(outbuf) - (p + 31 - outbuf), STR_ASCII|STR_TERMINATE);
send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
from_name, 0x0, to_name, to_type, to_ip, subrec->myip,
@ -143,8 +143,8 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type
SSVAL(p,8,announce_interval); /* In seconds - according to spec. */
p += 10;
p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
p += push_string(NULL, p, server_comment, sizeof(outbuf)- (p - outbuf), STR_ASCII|STR_UPPER|STR_TERMINATE);
p += push_string_check(p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
p += push_string_check(p, server_comment, sizeof(outbuf)- (p - outbuf), STR_ASCII|STR_UPPER|STR_TERMINATE);
send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
from_name, 0x0, to_name, to_type, to_ip, subrec->myip,

View File

@ -32,8 +32,8 @@ size_t srvstr_push_fn(const char *function, unsigned int line,
}
/* 'normal' push into size-specified buffer */
return push_string_fn(function, line, base_ptr, smb_flags2, dest, src,
dest_len, flags);
return push_string_base(function, line, base_ptr, smb_flags2, dest, src,
dest_len, flags);
}
/*******************************************************************