本文整理汇总了C++中PTR_DIFF函数的典型用法代码示例。如果您正苦于以下问题:C++ PTR_DIFF函数的具体用法?C++ PTR_DIFF怎么用?C++ PTR_DIFF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PTR_DIFF函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:49,代码来源:request.c
示例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);
}
开发者ID:AIdrifter,项目名称:samba,代码行数:24,代码来源:nmbd_sendannounce.c
示例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;
}
开发者ID:ANFS,项目名称:ANFS-kernel,代码行数:25,代码来源:tx.c
示例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;
}
开发者ID:majek,项目名称:openonload,代码行数:41,代码来源:tx_tso.c
示例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);
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:36,代码来源:nmbd_sendannounce.c
示例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);
}
}
开发者ID:ActionLuzifer,项目名称:mc,代码行数:28,代码来源:util_str.c
示例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;
}
开发者ID:DanilKorotenko,项目名称:samba,代码行数:78,代码来源:util_net.c
示例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;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:6,代码来源:charcnv.c
示例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;
}
开发者ID:urisimchoni,项目名称:samba,代码行数:67,代码来源:testsuite.c
示例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);
}
开发者ID:DanilKorotenko,项目名称:samba,代码行数:74,代码来源:clirap.c
示例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;
}
开发者ID:DanilKorotenko,项目名称:samba,代码行数:98,代码来源:clirap.c
示例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
//.........这里部分代码省略.........
开发者ID:AllardJ,项目名称:Tomato,代码行数:101,代码来源:clilist.c
示例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);
}
开发者ID:aosm,项目名称:samba,代码行数:84,代码来源:clirap.c
示例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;
}
开发者ID:aosm,项目名称:samba,代码行数:64,代码来源:clirap.c
示例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;
}
}
开发者ID:ekohl,项目名称:samba,代码行数:101,代码来源:clidfs.c
示例16: process_one
static bool process_one(struct loadparm_context *lp_ctx, struct tevent_context *ev,
struct interface *ifaces, const char *name, int nbt_port)
{
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
enum nbt_name_type node_type = NBT_NAME_CLIENT;
char *node_name, *p;
struct socket_address *all_zero_addr;
struct nbt_name_socket *nbtsock;
NTSTATUS status = NT_STATUS_OK;
bool ret = true;
if (!options.case_sensitive) {
name = strupper_talloc(tmp_ctx, name);
}
if (options.find_master) {
node_type = NBT_NAME_MASTER;
if (*name == '-' || *name == '_') {
name = "\01\02__MSBROWSE__\02";
node_type = NBT_NAME_MS;
}
}
p = strchr(name, '#');
if (p) {
node_name = talloc_strndup(tmp_ctx, name, PTR_DIFF(p,name));
node_type = (enum nbt_name_type)strtol(p+1, NULL, 16);
} else {
node_name = talloc_strdup(tmp_ctx, name);
}
nbtsock = nbt_name_socket_init(tmp_ctx, ev, lp_iconv_convenience(lp_ctx));
if (options.root_port) {
all_zero_addr = socket_address_from_strings(tmp_ctx, nbtsock->sock->backend_name,
"0.0.0.0", NBT_NAME_SERVICE_PORT);
if (!all_zero_addr) {
talloc_free(tmp_ctx);
return false;
}
status = socket_listen(nbtsock->sock, all_zero_addr, 0, 0);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to bind to local port 137 - %s\n", nt_errstr(status));
talloc_free(tmp_ctx);
return false;
}
}
if (options.lookup_by_ip) {
ret = do_node_status(nbtsock, name, nbt_port);
talloc_free(tmp_ctx);
return ret;
}
if (options.broadcast_address) {
status = do_node_query(nbtsock, options.broadcast_address, nbt_port,
node_name, node_type, true);
} else if (options.unicast_address) {
status = do_node_query(nbtsock, options.unicast_address,
nbt_port, node_name, node_type, false);
} else {
int i, num_interfaces;
num_interfaces = iface_count(ifaces);
for (i=0;i<num_interfaces;i++) {
const char *bcast = iface_n_bcast(ifaces, i);
if (bcast == NULL) continue;
status = do_node_query(nbtsock, bcast, nbt_port,
node_name, node_type, true);
if (NT_STATUS_IS_OK(status)) break;
}
}
if (!NT_STATUS_IS_OK(status)) {
printf("Lookup failed - %s\n", nt_errstr(status));
ret = false;
}
talloc_free(tmp_ctx);
return ret;
}
开发者ID:0x24bin,项目名称:winexe-1,代码行数:83,代码来源:nmblookup.c
示例17: cli_list_new
int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
void (*fn)(const char *, file_info *, const char *, void *), void *state)
{
#if 1
int max_matches = 1366; /* Match W2k - was 512. */
#else
int max_matches = 512;
#endif
int info_level;
char *p, *p2;
pstring mask;
file_info finfo;
int i;
char *dirlist = NULL;
int dirlist_len = 0;
int total_received = -1;
BOOL First = True;
int ff_searchcount=0;
int ff_eos=0;
int ff_dir_handle=0;
int loop_count = 0;
char *rparam=NULL, *rdata=NULL;
unsigned int param_len, data_len;
uint16 setup;
pstring param;
const char *mnt;
uint32 resume_key = 0;
uint32 last_name_raw_len = 0;
DATA_BLOB last_name_raw = data_blob(NULL, 2*sizeof(pstring));
/* NT uses 260, OS/2 uses 2. Both accept 1. */
info_level = (cli->capabilities&CAP_NT_SMBS)?260:1;
pstrcpy(mask,Mask);
while (ff_eos == 0) {
loop_count++;
if (loop_count > 200) {
DEBUG(0,("Error: Looping in FIND_NEXT??\n"));
break;
}
if (First) {
setup = TRANSACT2_FINDFIRST;
SSVAL(param,0,attribute); /* attribute */
SSVAL(param,2,max_matches); /* max count */
SSVAL(param,4,(FLAG_TRANS2_FIND_REQUIRE_RESUME|FLAG_TRANS2_FIND_CLOSE_IF_END)); /* resume required + close on end */
SSVAL(param,6,info_level);
SIVAL(param,8,0);
p = param+12;
p += clistr_push(cli, param+12, mask, sizeof(param)-12,
STR_TERMINATE);
} else {
setup = TRANSACT2_FINDNEXT;
SSVAL(param,0,ff_dir_handle);
SSVAL(param,2,max_matches); /* max count */
SSVAL(param,4,info_level);
/* For W2K servers serving out FAT filesystems we *must* set the
resume key. If it's not FAT then it's returned as zero. */
SIVAL(param,6,resume_key); /* ff_resume_key */
/* NB. *DON'T* use continue here. If you do it seems that W2K and bretheren
can miss filenames. Use last filename continue instead. JRA */
SSVAL(param,10,(FLAG_TRANS2_FIND_REQUIRE_RESUME|FLAG_TRANS2_FIND_CLOSE_IF_END)); /* resume required + close on end */
p = param+12;
if (last_name_raw_len && (last_name_raw_len < (sizeof(param)-12))) {
memcpy(p, last_name_raw.data, last_name_raw_len);
p += last_name_raw_len;
} else {
p += clistr_push(cli, param+12, mask, sizeof(param)-12, STR_TERMINATE);
}
}
param_len = PTR_DIFF(p, param);
if (!cli_send_trans(cli, SMBtrans2,
NULL, /* Name */
-1, 0, /* fid, flags */
&setup, 1, 0, /* setup, length, max */
param, param_len, 10, /* param, length, max */
NULL, 0,
#if 0
/* w2k value. */
MIN(16384,cli->max_xmit) /* data, length, max. */
#else
cli->max_xmit /* data, length, max. */
#endif
)) {
break;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, ¶m_len,
&rdata, &data_len) &&
cli_is_dos_error(cli)) {
/* We need to work around a Win95 bug - sometimes
it gives ERRSRV/ERRerror temprarily */
uint8 eclass;
uint32 ecode;
SAFE_FREE(rdata);
//.........这里部分代码省略.........
开发者ID:AllardJ,项目名称:Tomato,代码行数:101,代码来源:clilist.c
示例18: cli_qpathinfo
BOOL cli_qpathinfo(struct cli_state *cli, const char *fname,
time_t *change_time,
time_t *access_time,
time_t *write_time,
SMB_OFF_T *size, uint16 *mode)
{
unsigned int data_len = 0;
unsigned int param_len = 0;
unsigned int rparam_len, rdata_len;
uint16 setup = TRANSACT2_QPATHINFO;
pstring param;
char *rparam=NULL, *rdata=NULL;
int count=8;
BOOL ret;
time_t (*date_fn)(struct cli_state *, void *);
char *p;
p = param;
memset(p, 0, 6);
SSVAL(p, 0, SMB_INFO_STANDARD);
p += 6;
p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE);
param_len = PTR_DIFF(p, param);
do {
ret = (cli_send_trans(cli, SMBtrans2,
NULL, /* Name */
-1, 0, /* fid, flags */
&setup, 1, 0, /* setup, length, max */
param, param_len, 10, /* param, length, max */
NULL, data_len, cli->max_xmit /* data, length, max */
) &&
cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_len,
&rdata, &rdata_len));
if (!cli_is_dos_error(cli)) break;
if (!ret) {
/* we need to work around a Win95 bug - sometimes
it gives ERRSRV/ERRerror temprarily */
uint8 eclass;
uint32 ecode;
cli_dos_error(cli, &eclass, &ecode);
if (eclass != ERRSRV || ecode != ERRerror) break;
smb_msleep(100);
}
} while (count-- && ret==False);
if (!ret || !rdata || rdata_len < 22) {
return False;
}
if (cli->win95) {
date_fn = cli_make_unix_date;
} else {
date_fn = cli_make_unix_date2;
}
if (change_time) {
*change_time = date_fn(cli, rdata+0);
}
if (access_time) {
*access_time = date_fn(cli, rdata+4);
}
if (write_time) {
*write_time = date_fn(cli, rdata+8);
}
if (size) {
*size = IVAL(rdata, 12);
}
if (mode) {
*mode = SVAL(rdata,l1_attrFile);
}
SAFE_FREE(rdata);
SAFE_FREE(rparam);
return True;
}
开发者ID:aosm,项目名称:samba,代码行数:78,代码来源:clirap.c
示例19: cli_dfs_get_referral
BOOL cli_dfs_get_referral( struct cli_state *cli,
const char *path,
CLIENT_DFS_REFERRAL**refs,
size_t *num_refs,
uint16 *consumed)
{
unsigned int data_len = 0;
unsigned int param_len = 0;
uint16 setup = TRANSACT2_GET_DFS_REFERRAL;
char param[sizeof(pstring)+2];
pstring data;
char *rparam=NULL, *rdata=NULL;
char *p;
size_t pathlen = 2*(strlen(path)+1);
uint16 num_referrals;
CLIENT_DFS_REFERRAL *referrals = NULL;
memset(param, 0, sizeof(param));
SSVAL(param, 0, 0x03); /* max referral level */
p = ¶m[2];
p += clistr_push(cli, p, path, MIN(pathlen, sizeof(param)-2), STR_TERMINATE);
param_len = PTR_DIFF(p, param);
if (!cli_send_trans(cli, SMBtrans2,
NULL, /* name */
-1, 0, /* fid, flags */
&setup, 1, 0, /* setup, length, max */
param, param_len, 2, /* param, length, max */
(char *)&data, data_len, cli->max_xmit /* data, length, max */
)) {
return False;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, ¶m_len,
&rdata, &data_len)) {
return False;
}
*consumed = SVAL( rdata, 0 );
num_referrals = SVAL( rdata, 2 );
if ( num_referrals != 0 ) {
uint16 ref_version;
uint16 ref_size;
int i;
uint16 node_offset;
referrals = SMB_XMALLOC_ARRAY( CLIENT_DFS_REFERRAL, num_referrals );
/* start at the referrals array */
p = rdata+8;
for ( i=0; i<num_referrals; i++ ) {
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 );
clistr_pull( cli, referrals[i].dfspath, p+node_offset,
sizeof(referrals[i].dfspath), -1, STR_TERMINATE|STR_UNICODE );
p += ref_size;
}
}
*num_refs = num_referrals;
*refs = referrals;
SAFE_FREE(rdata);
SAFE_FREE(rparam);
return True;
}
开发者ID:kleopatra999,项目名称:finx,代码行数:82,代码来源:clidfs.c
示例20: cli_setpathinfo
BOOL cli_setpathinfo(struct cli_state *cli, const char *fname,
time_t create_time,
time_t access_time,
time_t write_time,
time_t change_time,
uint16 mode)
{
unsigned int data_len = 0;
unsigned int param_len = 0;
unsigned int rparam_len, rdata_len;
uint16 setup = TRANSACT2_SETPATHINFO;
pstring param;
pstring data;
char *rparam=NULL, *rdata=NULL;
int count=8;
BOOL ret;
char *p;
memset(param, 0, sizeof(param));
memset(data, 0, sizeof(data));
p = param;
/* Add the information level */
SSVAL(p, 0, SMB_FILE_BASIC_INFORMATION);
/* Skip reserved */
p += 6;
/* Add the file name */
p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE);
param_len = PTR_DIFF(p, param);
p = data;
/*
* Add the create, last access, modification, and status change times
*/
put_long_date(p, create_time);
p += 8;
put_long_date(p, access_time);
p += 8;
put_long_date(p, write_time);
p += 8;
put_long_date(p, change_time);
p += 8;
/* Add attributes */
SIVAL(p, 0, mode);
p += 4;
/* Add padding */
SIVAL(p, 0, 0);
p += 4;
data_len = PTR_DIFF(p, data);
do {
ret = (cli_send_trans(cli, SMBtrans2,
NULL, /* Name */
-1, 0, /* fid, flags */
&setup, 1, 0, /* setup, length, max */
param, param_len, 10, /* param, length, max */
data, data_len, cli->max_xmit /* data, length, max */
) &&
cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_len,
&rdata, &rdata_len));
if (!cli_is_dos_error(cli)) break;
if (!ret) {
/* we need to work around a Win95 bug - sometimes
it gives ERRSRV/ERRerror temprarily */
uint8 eclass;
uint32 ecode;
cli_dos_error(cli, &eclass, &ecode);
if (eclass != ERRSRV || ecode != ERRerror) break;
smb_msleep(100);
}
} while (count-- && ret==False);
if (!ret) {
return False;
}
SAFE_FREE(rdata);
SAFE_FREE(rparam);
return True;
}
开发者ID:aosm,项目名称:samba,代码行数:93,代码来源:clirap.c
注:本文中的PTR_DIFF函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论