本文整理汇总了C++中PTR_DIFF函数的典型用法代码示例。如果您正苦于以下问题:C++ PTR_DIFF函数的具体用法?C++ PTR_DIFF怎么用?C++ PTR_DIFF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PTR_DIFF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: request
/**
pull a ascii string from a request packet, returning a talloced string
the string length is limited by the 3 things:
- the data size in the request (end of packet)
- the passed 'byte_len' if it is not -1
- the end of string (null termination)
Note that 'byte_len' is the number of bytes in the packet
on failure zero is returned and *dest is set to NULL, otherwise the number
of bytes consumed in the packet is returned
*/
static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, unsigned int flags)
{
int src_len, src_len2;
bool ret;
char *dest2;
size_t converted_size = 0;
if (flags & STR_NO_RANGE_CHECK) {
src_len = byte_len;
} else {
src_len = bufinfo->data_size - PTR_DIFF(src, bufinfo->data);
if (src_len < 0) {
*dest = NULL;
return 0;
}
if (byte_len != -1 && src_len > byte_len) {
src_len = byte_len;
}
}
src_len2 = strnlen((const char *)src, src_len);
if (src_len2 <= src_len - 1) {
/* include the termination if we didn't reach the end of the packet */
src_len2++;
}
ret = convert_string_talloc(bufinfo->mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2, &converted_size);
if (!ret) {
*dest = NULL;
return 0;
}
*dest = dest2;
return src_len2;
}
示例2: send_lm_announcement
static void send_lm_announcement(struct subnet_record *subrec, int announce_type,
char *from_name, char *to_name, int to_type, struct in_addr to_ip,
time_t announce_interval,
char *server_name, int server_type, char *server_comment)
{
char outbuf[1024];
char *p=outbuf;
memset(outbuf,'\0',sizeof(outbuf));
SSVAL(p,0,announce_type);
SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY);
SCVAL(p,6,SAMBA_MAJOR_NBT_ANNOUNCE_VERSION); /* Major version. */
SCVAL(p,7,SAMBA_MINOR_NBT_ANNOUNCE_VERSION); /* Minor version. */
SSVAL(p,8,announce_interval); /* In seconds - according to spec. */
p += 10;
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,
DGRAM_PORT);
}
示例3: tso_start
/* Parse the SKB header and initialise state. */
static void tso_start(struct tso_state *st, const struct sk_buff *skb)
{
/* All ethernet/IP/TCP headers combined size is TCP header size
* plus offset of TCP header relative to start of packet.
*/
st->header_len = ((tcp_hdr(skb)->doff << 2u)
+ PTR_DIFF(tcp_hdr(skb), skb->data));
st->full_packet_size = st->header_len + skb_shinfo(skb)->gso_size;
if (st->protocol == htons(ETH_P_IP))
st->ipv4_id = ntohs(ip_hdr(skb)->id);
else
st->ipv4_id = 0;
st->seqnum = ntohl(tcp_hdr(skb)->seq);
EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg);
EFX_BUG_ON_PARANOID(tcp_hdr(skb)->syn);
EFX_BUG_ON_PARANOID(tcp_hdr(skb)->rst);
st->packet_space = st->full_packet_size;
st->out_len = skb->len - st->header_len;
st->unmap_len = 0;
st->unmap_single = false;
}
示例4: efx_tso_check_protocol
/*
* Verify that our various assumptions about sk_buffs and the conditions
* under which TSO will be attempted hold true. Also determine and fill
* in the protocol number through the provided pointer.
*/
static int efx_tso_check_protocol(struct sk_buff *skb, __be16 *protocol)
{
*protocol = skb->protocol;
if (((struct ethhdr *)skb->data)->h_proto != *protocol)
return -EINVAL;
#if !defined(EFX_USE_KCOMPAT) || defined(EFX_USE_NETDEV_VLAN_FEATURES) || defined(NETIF_F_VLAN_TSO)
if (*protocol == htons(ETH_P_8021Q)) {
struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
*protocol = veh->h_vlan_encapsulated_proto;
}
#endif
/* For SW TSO or TSOv1 we can only deal with TCP in IPv4 or IPv6 */
if (*protocol == htons(ETH_P_IP)) {
if (ip_hdr(skb)->protocol != IPPROTO_TCP)
return -EINVAL;
} else if (*protocol == htons(ETH_P_IPV6)) {
if (ipv6_hdr(skb)->nexthdr != NEXTHDR_TCP)
return -EINVAL;
} else {
return -EINVAL;
}
/* All headers (incl. TCP header) must be in linear data area. This
* should always be the case, so warn if not.
*/
if (WARN_ON((PTR_DIFF(tcp_hdr(skb), skb->data) +
(tcp_hdr(skb)->doff << 2u)) >
skb_headlen(skb)))
return -EINVAL;
return 0;
}
示例5: send_announcement
static void send_announcement(struct subnet_record *subrec, int announce_type,
const char *from_name, const char *to_name, int to_type, struct in_addr to_ip,
time_t announce_interval,
const char *server_name, int server_type, const char *server_comment)
{
char outbuf[PSTRING_LEN];
unstring upper_server_name;
char *p;
memset(outbuf,'\0',sizeof(outbuf));
p = outbuf+1;
SCVAL(outbuf,0,announce_type);
/* Announcement parameters. */
SCVAL(p,0,updatecount);
SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */
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);
SCVAL(p,21,lp_major_announce_version()); /* Major version. */
SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */
SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY);
/* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */
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);
send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
from_name, 0x0, to_name, to_type, to_ip, subrec->myip,
DGRAM_PORT);
}
示例6: string_sub
/****************************************************************************
similar to string_sub() but allows for any character to be substituted.
Use with caution!
****************************************************************************/
void
all_string_sub (char *s, const char *pattern, const char *insert)
{
char *p;
size_t ls, lp, li;
if (!insert || !pattern || !s)
return;
ls = strlen (s);
lp = strlen (pattern);
li = strlen (insert);
if (!*pattern)
return;
while (lp <= ls && (p = strstr (s, pattern)))
{
memmove (p + li, p + lp, ls + 1 - (PTR_DIFF (p, s) + lp));
memcpy (p, insert, li);
s = p + li;
ls += (li - lp);
}
}
示例7: is_ipaddress_v6
bool is_ipaddress_v6(const char *str)
{
#if defined(HAVE_IPV6)
int ret = -1;
char *p = NULL;
p = strchr_m(str, ':');
if (p == NULL) {
return is_ipv6_literal(str);
} else {
char buf[INET6_ADDRSTRLEN] = { 0, };
size_t len;
const char *addr = str;
const char *idxs = NULL;
unsigned int idx = 0;
struct in6_addr ip6;
p = strchr_m(str, '%');
if (p && (p > str)) {
len = PTR_DIFF(p, str);
idxs = p + 1;
} else {
len = strlen(str);
}
if (len >= sizeof(buf)) {
return false;
}
if (idxs != NULL) {
strncpy(buf, str, len);
addr = buf;
}
/*
* Cope with link-local.
* This is IP:v6:addr%ifidx.
*/
if (idxs != NULL) {
char c;
ret = sscanf(idxs, "%5u%c", &idx, &c);
if (ret != 1) {
idx = 0;
}
if (idx > 0 && idx < UINT16_MAX) {
/* a valid index */
idxs = NULL;
}
}
/*
* Cope with link-local.
* This is IP:v6:addr%ifname.
*/
if (idxs != NULL) {
idx = if_nametoindex(idxs);
if (idx > 0) {
/* a valid index */
idxs = NULL;
}
}
if (idxs != NULL) {
return false;
}
ret = inet_pton(AF_INET6, addr, &ip6);
if (ret <= 0) {
return false;
}
return true;
}
#endif
return false;
}
示例8: ucs2_align
static size_t ucs2_align(const void *base_ptr, const void *p, int flags)
{
if (flags & (STR_NOALIGN|STR_ASCII))
return 0;
return PTR_DIFF(p, base_ptr) & 1;
}
示例9: test_pool_steal
static bool test_pool_steal(void)
{
void *root;
void *pool;
void *p1, *p2;
void *p1_2, *p2_2;
size_t hdr;
size_t ofs1, ofs2;
root = talloc_new(NULL);
pool = talloc_pool(root, 1024);
p1 = talloc_size(pool, 4 * 16);
torture_assert("pool allocate 4 * 16", p1 != NULL, "failed ");
memset(p1, 0x11, talloc_get_size(p1));
p2 = talloc_size(pool, 4 * 16);
torture_assert("pool allocate 4 * 16", p2 > p1, "failed: !(p2 > p1) ");
memset(p2, 0x11, talloc_get_size(p2));
ofs1 = PTR_DIFF(p2, p1);
hdr = ofs1 - talloc_get_size(p1);
talloc_steal(root, p1);
talloc_steal(root, p2);
talloc_free(pool);
p1_2 = p1;
#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
p1_2 = talloc_realloc_size(root, p1, 5 * 16);
torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed");
memset(p1_2, 0x11, talloc_get_size(p1_2));
ofs1 = PTR_DIFF(p1_2, p2);
ofs2 = talloc_get_size(p2) + hdr;
torture_assert("pool realloc ", ofs1 == ofs2, "failed: pointer offset unexpected");
p2_2 = talloc_realloc_size(root, p2, 3 * 16);
torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed");
memset(p2_2, 0x11, talloc_get_size(p2_2));
#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
talloc_free(p1_2);
p2_2 = p2;
#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
/* now we should reclaim the full pool */
p2_2 = talloc_realloc_size(root, p2, 8 * 16);
torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected");
p2 = p2_2;
memset(p2_2, 0x11, talloc_get_size(p2_2));
/* now we malloc and free the full pool space */
p2_2 = talloc_realloc_size(root, p2, 2 * 1024);
torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected");
memset(p2_2, 0x11, talloc_get_size(p2_2));
#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
talloc_free(p2_2);
talloc_free(root);
return true;
}
示例10: cli_oem_change_password
bool cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
const char *old_password)
{
char param[1024];
unsigned char data[532];
char *p = param;
unsigned char old_pw_hash[16];
unsigned char new_pw_hash[16];
unsigned int data_len;
unsigned int param_len = 0;
char *rparam = NULL;
char *rdata = NULL;
unsigned int rprcnt, rdrcnt;
if (strlen(user) >= sizeof(fstring)-1) {
DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
return False;
}
SSVAL(p,0,214); /* SamOEMChangePassword command. */
p += 2;
strlcpy(p, "zsT", sizeof(param)-PTR_DIFF(p,param));
p = skip_string(param,sizeof(param),p);
strlcpy(p, "B516B16", sizeof(param)-PTR_DIFF(p,param));
p = skip_string(param,sizeof(param),p);
strlcpy(p,user, sizeof(param)-PTR_DIFF(p,param));
p = skip_string(param,sizeof(param),p);
SSVAL(p,0,532);
p += 2;
param_len = PTR_DIFF(p,param);
/*
* Get the Lanman hash of the old password, we
* use this as the key to make_oem_passwd_hash().
*/
E_deshash(old_password, old_pw_hash);
encode_pw_buffer(data, new_password, STR_ASCII);
#ifdef DEBUG_PASSWORD
DEBUG(100,("make_oem_passwd_hash\n"));
dump_data(100, data, 516);
#endif
arcfour_crypt( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
/*
* Now place the old password hash in the data.
*/
E_deshash(new_password, new_pw_hash);
E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
data_len = 532;
if (!cli_api(cli,
param, param_len, 4, /* param, length, max */
(char *)data, data_len, 0, /* data, length, max */
&rparam, &rprcnt,
&rdata, &rdrcnt)) {
DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
user ));
return False;
}
if (rparam) {
cli->rap_error = SVAL(rparam,0);
}
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return (cli->rap_error == 0);
}
示例11: cli_RNetShareEnum
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32_t, const char *, void *), void *state)
{
char *rparam = NULL;
char *rdata = NULL;
char *p;
unsigned int rdrcnt,rprcnt;
char param[1024];
int count = -1;
/* now send a SMBtrans command with api RNetShareEnum */
p = param;
SSVAL(p,0,0); /* api number */
p += 2;
strlcpy(p,"WrLeh",sizeof(param)-PTR_DIFF(p,param));
p = skip_string(param,sizeof(param),p);
strlcpy(p,"B13BWz",sizeof(param)-PTR_DIFF(p,param));
p = skip_string(param,sizeof(param),p);
SSVAL(p,0,1);
/*
* Win2k needs a *smaller* buffer than 0xFFFF here -
* it returns "out of server memory" with 0xFFFF !!! JRA.
*/
SSVAL(p,2,0xFFE0);
p += 4;
if (cli_api(cli,
param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
NULL, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
&rparam, &rprcnt, /* return params, length */
&rdata, &rdrcnt)) /* return data, length */
{
int res = rparam? SVAL(rparam,0) : -1;
if (res == 0 || res == ERRmoredata) {
int converter=SVAL(rparam,2);
int i;
char *rdata_end = rdata + rdrcnt;
count=SVAL(rparam,4);
p = rdata;
for (i=0;i<count;i++,p+=20) {
char *sname;
int type;
int comment_offset;
const char *cmnt;
const char *p1;
char *s1, *s2;
size_t len;
TALLOC_CTX *frame = talloc_stackframe();
if (p + 20 > rdata_end) {
TALLOC_FREE(frame);
break;
}
sname = p;
type = SVAL(p,14);
comment_offset = (IVAL(p,16) & 0xFFFF) - converter;
if (comment_offset < 0 ||
comment_offset > (int)rdrcnt) {
TALLOC_FREE(frame);
break;
}
cmnt = comment_offset?(rdata+comment_offset):"";
/* Work out the comment length. */
for (p1 = cmnt, len = 0; *p1 &&
p1 < rdata_end; len++)
p1++;
if (!*p1) {
len++;
}
pull_string_talloc(frame,rdata,0,
&s1,sname,14,STR_ASCII);
pull_string_talloc(frame,rdata,0,
&s2,cmnt,len,STR_ASCII);
if (!s1 || !s2) {
TALLOC_FREE(frame);
continue;
}
fn(s1, type, s2, state);
TALLOC_FREE(frame);
}
} else {
DEBUG(4,("NetShareEnum res=%d\n", res));
}
} else {
DEBUG(4,("NetShareEnum failed\n"));
}
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return count;
}
示例12: interpret_long_filename
static size_t interpret_long_filename(struct cli_state *cli, int level,char *p,file_info *finfo,
uint32 *p_resume_key, DATA_BLOB *p_last_name_raw, uint32 *p_last_name_raw_len)
{
file_info finfo2;
int len;
char *base = p;
if (!finfo) {
finfo = &finfo2;
}
if (p_resume_key) {
*p_resume_key = 0;
}
memcpy(finfo,&def_finfo,sizeof(*finfo));
finfo->cli = cli;
switch (level) {
case 1: /* OS/2 understands this */
/* these dates are converted to GMT by
make_unix_date */
finfo->ctime_ts = convert_time_t_to_timespec(cli_make_unix_date2(cli, p+4));
finfo->atime_ts = convert_time_t_to_timespec(cli_make_unix_date2(cli, p+8));
finfo->mtime_ts = convert_time_t_to_timespec(cli_make_unix_date2(cli, p+12));
finfo->size = IVAL(p,16);
finfo->mode = CVAL(p,24);
len = CVAL(p, 26);
p += 27;
p += clistr_align_in(cli, p, 0);
/* the len+2 below looks strange but it is
important to cope with the differences
between win2000 and win9x for this call
(tridge) */
p += clistr_pull(cli, finfo->name, p,
sizeof(finfo->name),
len+2,
STR_TERMINATE);
return PTR_DIFF(p, base);
case 2: /* this is what OS/2 uses mostly */
/* these dates are converted to GMT by
make_unix_date */
finfo->ctime_ts = convert_time_t_to_timespec(cli_make_unix_date2(cli, p+4));
finfo->atime_ts = convert_time_t_to_timespec(cli_make_unix_date2(cli, p+8));
finfo->mtime_ts = convert_time_t_to_timespec(cli_make_unix_date2(cli, p+12));
finfo->size = IVAL(p,16);
finfo->mode = CVAL(p,24);
len = CVAL(p, 30);
p += 31;
/* check for unisys! */
p += clistr_pull(cli, finfo->name, p,
sizeof(finfo->name),
len,
STR_NOALIGN);
return PTR_DIFF(p, base) + 1;
case 260: /* NT uses this, but also accepts 2 */
{
size_t namelen, slen;
p += 4; /* next entry offset */
if (p_resume_key) {
*p_resume_key = IVAL(p,0);
}
p += 4; /* fileindex */
/* Offset zero is "create time", not "change time". */
p += 8;
finfo->atime_ts = interpret_long_date(p);
p += 8;
finfo->mtime_ts = interpret_long_date(p);
p += 8;
finfo->ctime_ts = interpret_long_date(p);
p += 8;
finfo->size = IVAL2_TO_SMB_BIG_UINT(p,0);
p += 8;
p += 8; /* alloc size */
finfo->mode = CVAL(p,0);
p += 4;
namelen = IVAL(p,0);
p += 4;
p += 4; /* EA size */
slen = SVAL(p, 0);
p += 2;
{
/* stupid NT bugs. grr */
int flags = 0;
if (p[1] == 0 && namelen > 1) flags |= STR_UNICODE;
clistr_pull(cli, finfo->short_name, p,
sizeof(finfo->short_name),
slen, flags);
}
p += 24; /* short name? */
clistr_pull(cli, finfo->name, p,
sizeof(finfo->name),
namelen, 0);
/* To be robust in the face of unicode conversion failures
we need to copy the raw bytes of the last name seen here.
Namelen doesn't include the terminating unicode null, so
//.........这里部分代码省略.........
示例13: cli_oem_change_password
BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
const char *old_password)
{
pstring param;
unsigned char data[532];
char *p = param;
unsigned char old_pw_hash[16];
unsigned char new_pw_hash[16];
unsigned int data_len;
unsigned int param_len = 0;
char *rparam = NULL;
char *rdata = NULL;
unsigned int rprcnt, rdrcnt;
if (strlen(user) >= sizeof(fstring)-1) {
DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
return False;
}
SSVAL(p,0,214); /* SamOEMChangePassword command. */
p += 2;
pstrcpy_base(p, "zsT", param);
p = skip_string(param,sizeof(param),p);
pstrcpy_base(p, "B516B16", param);
p = skip_string(param,sizeof(param),p);
pstrcpy_base(p,user, param);
p = skip_string(param,sizeof(param),p);
SSVAL(p,0,532);
p += 2;
param_len = PTR_DIFF(p,param);
/*
* Get the Lanman hash of the old password, we
* use this as the key to make_oem_passwd_hash().
*/
E_deshash(old_password, old_pw_hash);
encode_pw_buffer(data, new_password, STR_ASCII);
#ifdef DEBUG_PASSWORD
DEBUG(100,("make_oem_passwd_hash\n"));
dump_data(100, (char *)data, 516);
#endif
SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
/*
* Now place the old password hash in the data.
*/
E_deshash(new_password, new_pw_hash);
E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
data_len = 532;
if (cli_send_trans(cli,SMBtrans,
PIPE_LANMAN, /* name */
0,0, /* fid, flags */
NULL,0,0, /* setup, length, max */
param,param_len,2, /* param, length, max */
(char *)data,data_len,0 /* data, length, max */
) == False) {
DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
user ));
return False;
}
if (!cli_receive_trans(cli,SMBtrans,
&rparam, &rprcnt,
&rdata, &rdrcnt)) {
DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
user ));
return False;
}
if (rparam) {
cli->rap_error = SVAL(rparam,0);
}
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return (cli->rap_error == 0);
}
示例14: cli_RNetShareEnum
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
{
char *rparam = NULL;
char *rdata = NULL;
char *p;
unsigned int rdrcnt,rprcnt;
pstring param;
int count = -1;
/* now send a SMBtrans command with api RNetShareEnum */
p = param;
SSVAL(p,0,0); /* api number */
p += 2;
pstrcpy_base(p,"WrLeh",param);
p = skip_string(param,sizeof(param),p);
pstrcpy_base(p,"B13BWz",param);
p = skip_string(param,sizeof(param),p);
SSVAL(p,0,1);
/*
* Win2k needs a *smaller* buffer than 0xFFFF here -
* it returns "out of server memory" with 0xFFFF !!! JRA.
*/
SSVAL(p,2,0xFFE0);
p += 4;
if (cli_api(cli,
param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
NULL, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
&rparam, &rprcnt, /* return params, length */
&rdata, &rdrcnt)) /* return data, length */
{
int res = rparam? SVAL(rparam,0) : -1;
if (res == 0 || res == ERRmoredata) {
int converter=SVAL(rparam,2);
int i;
count=SVAL(rparam,4);
p = rdata;
for (i=0;i<count;i++,p+=20) {
char *sname = p;
int type = SVAL(p,14);
int comment_offset = IVAL(p,16) & 0xFFFF;
const char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
pstring s1, s2;
pull_ascii_pstring(s1, sname);
pull_ascii_pstring(s2, cmnt);
fn(s1, type, s2, state);
}
} else {
DEBUG(4,("NetShareEnum res=%d\n", res));
}
} else {
DEBUG(4,("NetShareEnum failed\n"));
}
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return count;
}
示例15: cli_dfs_get_referral
//.........这里部分代码省略.........
NULL, 0xffff, 0, 0,
setup, 1, 0,
param, param_len, 2,
NULL, 0, CLI_BUFFER_SIZE,
&recv_flags2,
NULL, 0, NULL, /* rsetup */
NULL, 0, NULL,
&rdata, 4, &data_len);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
endp = (char *)rdata + data_len;
consumed_ucs = SVAL(rdata, 0);
num_referrals = SVAL(rdata, 2);
/* consumed_ucs is the number of bytes
* of the UCS2 path consumed not counting any
* terminating null. We need to convert
* back to unix charset and count again
* to get the number of bytes consumed from
* the incoming path. */
errno = 0;
if (pull_string_talloc(talloc_tos(),
NULL,
0,
&consumed_path,
path_ucs,
consumed_ucs,
STR_UNICODE) == 0) {
if (errno != 0) {
status = map_nt_error_from_unix(errno);
} else {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
}
goto out;
}
if (consumed_path == NULL) {
status = map_nt_error_from_unix(errno);
goto out;
}
*consumed = strlen(consumed_path);
if (num_referrals != 0) {
uint16 ref_version;
uint16 ref_size;
int i;
uint16 node_offset;
referrals = talloc_array(ctx, struct client_dfs_referral,
num_referrals);
if (!referrals) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
/* start at the referrals array */
p = (char *)rdata+8;
for (i=0; i<num_referrals && p < endp; i++) {
if (p + 18 > endp) {
goto out;
}
ref_version = SVAL(p, 0);
ref_size = SVAL(p, 2);
node_offset = SVAL(p, 16);
if (ref_version != 3) {
p += ref_size;
continue;
}
referrals[i].proximity = SVAL(p, 8);
referrals[i].ttl = SVAL(p, 10);
if (p + node_offset > endp) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
clistr_pull_talloc(referrals,
(const char *)rdata,
recv_flags2,
&referrals[i].dfspath,
p+node_offset,
PTR_DIFF(endp, p+node_offset),
STR_TERMINATE|STR_UNICODE);
if (!referrals[i].dfspath) {
status = map_nt_error_from_unix(errno);
goto out;
}
p += ref_size;
}
if (i < num_referrals) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
}