本文整理汇总了C++中pstrcpy函数的典型用法代码示例。如果您正苦于以下问题:C++ pstrcpy函数的具体用法?C++ pstrcpy怎么用?C++ pstrcpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pstrcpy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qemu_mallocz
static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *prod_name)
{
int fd = -1, ret;
USBHostDevice *dev = NULL;
struct usbdevfs_connectinfo ci;
char buf[1024];
dev = qemu_mallocz(sizeof(USBHostDevice));
if (!dev)
goto fail;
dev->bus_num = bus_num;
dev->addr = addr;
printf("husb: open device %d.%d\n", bus_num, addr);
if (!usb_host_device_path) {
perror("husb: USB Host Device Path not set");
goto fail;
}
snprintf(buf, sizeof(buf), "%s/%03d/%03d", usb_host_device_path,
bus_num, addr);
fd = open(buf, O_RDWR | O_NONBLOCK);
if (fd < 0) {
perror(buf);
goto fail;
}
dprintf("husb: opened %s\n", buf);
/* read the device description */
dev->descr_len = read(fd, dev->descr, sizeof(dev->descr));
if (dev->descr_len <= 0) {
perror("husb: reading device data failed");
goto fail;
}
#ifdef DEBUG
{
int x;
printf("=== begin dumping device descriptor data ===\n");
for (x = 0; x < dev->descr_len; x++)
printf("%02x ", dev->descr[x]);
printf("\n=== end dumping device descriptor data ===\n");
}
#endif
dev->fd = fd;
/*
* Initial configuration is -1 which makes us claim first
* available config. We used to start with 1, which does not
* always work. I've seen devices where first config starts
* with 2.
*/
if (!usb_host_claim_interfaces(dev, -1))
goto fail;
ret = ioctl(fd, USBDEVFS_CONNECTINFO, &ci);
if (ret < 0) {
perror("usb_host_device_open: USBDEVFS_CONNECTINFO");
goto fail;
}
printf("husb: grabbed usb device %d.%d\n", bus_num, addr);
ret = usb_linux_update_endp_table(dev);
if (ret)
goto fail;
if (ci.slow)
dev->dev.speed = USB_SPEED_LOW;
else
dev->dev.speed = USB_SPEED_HIGH;
dev->dev.handle_packet = usb_host_handle_packet;
dev->dev.handle_reset = usb_host_handle_reset;
dev->dev.handle_destroy = usb_host_handle_destroy;
if (!prod_name || prod_name[0] == '\0')
snprintf(dev->dev.devname, sizeof(dev->dev.devname),
"host:%d.%d", bus_num, addr);
else
pstrcpy(dev->dev.devname, sizeof(dev->dev.devname),
prod_name);
/* USB devio uses 'write' flag to check for async completions */
qemu_set_fd_handler(dev->fd, NULL, async_complete, dev);
hostdev_link(dev);
return (USBDevice *) dev;
fail:
if (dev)
qemu_free(dev);
close(fd);
return NULL;
}
示例2: inet_listen_saddr
static int inet_listen_saddr(InetSocketAddress *saddr,
int port_offset,
bool update_addr,
Error **errp)
{
struct addrinfo ai,*res,*e;
char port[33];
char uaddr[INET6_ADDRSTRLEN+1];
char uport[33];
int slisten, rc, port_min, port_max, p;
Error *err = NULL;
memset(&ai,0, sizeof(ai));
ai.ai_flags = AI_PASSIVE;
ai.ai_family = inet_ai_family_from_address(saddr, &err);
ai.ai_socktype = SOCK_STREAM;
if (err) {
error_propagate(errp, err);
return -1;
}
if (saddr->host == NULL) {
error_setg(errp, "host not specified");
return -1;
}
if (saddr->port != NULL) {
pstrcpy(port, sizeof(port), saddr->port);
} else {
port[0] = '\0';
}
/* lookup */
if (port_offset) {
unsigned long long baseport;
if (strlen(port) == 0) {
error_setg(errp, "port not specified");
return -1;
}
if (parse_uint_full(port, &baseport, 10) < 0) {
error_setg(errp, "can't convert to a number: %s", port);
return -1;
}
if (baseport > 65535 ||
baseport + port_offset > 65535) {
error_setg(errp, "port %s out of range", port);
return -1;
}
snprintf(port, sizeof(port), "%d", (int)baseport + port_offset);
}
rc = getaddrinfo(strlen(saddr->host) ? saddr->host : NULL,
strlen(port) ? port : NULL, &ai, &res);
if (rc != 0) {
error_setg(errp, "address resolution failed for %s:%s: %s",
saddr->host, port, gai_strerror(rc));
return -1;
}
/* create socket + bind */
for (e = res; e != NULL; e = e->ai_next) {
getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
uaddr,INET6_ADDRSTRLEN,uport,32,
NI_NUMERICHOST | NI_NUMERICSERV);
slisten = qemu_socket(e->ai_family, e->ai_socktype, e->ai_protocol);
if (slisten < 0) {
if (!e->ai_next) {
error_setg_errno(errp, errno, "Failed to create socket");
}
continue;
}
socket_set_fast_reuse(slisten);
#ifdef IPV6_V6ONLY
if (e->ai_family == PF_INET6) {
/* listen on both ipv4 and ipv6 */
const int off = 0;
qemu_setsockopt(slisten, IPPROTO_IPV6, IPV6_V6ONLY, &off,
sizeof(off));
}
#endif
port_min = inet_getport(e);
port_max = saddr->has_to ? saddr->to + port_offset : port_min;
for (p = port_min; p <= port_max; p++) {
inet_setport(e, p);
if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {
goto listen;
}
if (p == port_max) {
if (!e->ai_next) {
error_setg_errno(errp, errno, "Failed to bind socket");
}
}
}
closesocket(slisten);
}
freeaddrinfo(res);
return -1;
listen:
//.........这里部分代码省略.........
示例3: resolve_name
/********************************************************
Resolve a name into an IP address. Use this function if
the string is either an IP address, DNS or host name
or NetBIOS name. This uses the name switch in the
smb.conf to determine the order of name resolution.
*********************************************************/
BOOL
resolve_name (const char *name, struct in_addr * return_ip, int name_type)
{
int i;
BOOL pure_address = True;
pstring name_resolve_list;
fstring tok;
char *ptr;
if (strcmp (name, "0.0.0.0") == 0)
{
return_ip->s_addr = 0;
return True;
}
if (strcmp (name, "255.255.255.255") == 0)
{
return_ip->s_addr = 0xFFFFFFFF;
return True;
}
for (i = 0; pure_address && name[i]; i++)
if (!(isdigit ((int) name[i]) || name[i] == '.'))
pure_address = False;
/* if it's in the form of an IP address then get the lib to interpret it */
if (pure_address)
{
return_ip->s_addr = inet_addr (name);
return True;
}
pstrcpy (name_resolve_list, lp_name_resolve_order ());
if (name_resolve_list == NULL || *name_resolve_list == '\0')
pstrcpy (name_resolve_list, "host");
ptr = name_resolve_list;
while (next_token (&ptr, tok, LIST_SEP, sizeof (tok)))
{
if ((strequal (tok, "host") || strequal (tok, "hosts")))
{
if (name_type == 0x20 && resolve_hosts (name, return_ip))
{
return True;
}
}
else if (strequal (tok, "lmhosts"))
{
if (resolve_lmhosts (name, return_ip, name_type))
{
return True;
}
}
else if (strequal (tok, "wins"))
{
/* don't resolve 1D via WINS */
if (name_type != 0x1D && resolve_wins (name, return_ip, name_type))
{
return True;
}
}
else if (strequal (tok, "bcast"))
{
if (resolve_bcast (name, return_ip, name_type))
{
return True;
}
}
else
{
DEBUG (0, ("resolve_name: unknown name switch type %s\n", tok));
}
}
return False;
}
示例4: inet_listen_opts
int inet_listen_opts(QemuOpts *opts, int port_offset)
{
SockAddress** list;
SockAddress* e;
unsigned flags = SOCKET_LIST_PASSIVE;
const char *addr;
char port[33];
char uaddr[256+1];
char uport[33];
int slisten,to,try_next,nn;
#ifdef CONFIG_ANDROID
const char* socket_fd = qemu_opt_get(opts, "socket");
if (socket_fd) {
return atoi(socket_fd);
}
#endif
if ((qemu_opt_get(opts, "host") == NULL) ||
(qemu_opt_get(opts, "port") == NULL)) {
fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
return -1;
}
pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
addr = qemu_opt_get(opts, "host");
to = qemu_opt_get_number(opts, "to", 0);
if (qemu_opt_get_bool(opts, "ipv4", 0))
flags |= SOCKET_LIST_FORCE_INET;
if (qemu_opt_get_bool(opts, "ipv6", 0))
flags |= SOCKET_LIST_FORCE_IN6;
/* lookup */
if (port_offset)
snprintf(port, sizeof(port), "%d", atoi(port) + port_offset);
list = sock_address_list_create( strlen(addr) ? addr : NULL,
port,
flags );
if (list == NULL) {
fprintf(stderr,"%s: getaddrinfo(%s,%s): %s\n", __FUNCTION__,
addr, port, errno_str);
return -1;
}
/* create socket + bind */
for (nn = 0; list[nn] != NULL; nn++) {
SocketFamily family;
e = list[nn];
family = sock_address_get_family(e);
sock_address_get_numeric_info(e, uaddr, sizeof uaddr, uport, sizeof uport);
slisten = socket_create(family, SOCKET_STREAM);
if (slisten < 0) {
fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
sock_address_strfamily(e), errno_str);
continue;
}
socket_set_xreuseaddr(slisten);
#ifdef IPV6_V6ONLY
/* listen on both ipv4 and ipv6 */
if (family == SOCKET_IN6) {
socket_set_ipv6only(slisten);
}
#endif
for (;;) {
if (socket_bind(slisten, e) == 0) {
if (sockets_debug)
fprintf(stderr,"%s: bind(%s,%s,%d): OK\n", __FUNCTION__,
sock_address_strfamily(e), uaddr, sock_address_get_port(e));
goto listen;
}
socket_close(slisten);
try_next = to && (sock_address_get_port(e) <= to + port_offset);
if (!try_next || sockets_debug)
fprintf(stderr,"%s: bind(%s,%s,%d): %s\n", __FUNCTION__,
sock_address_strfamily(e), uaddr, sock_address_get_port(e),
strerror(errno));
if (try_next) {
sock_address_set_port(e, sock_address_get_port(e) + 1);
continue;
}
break;
}
}
sock_address_list_free(list);
fprintf(stderr, "%s: FAILED\n", __FUNCTION__);
return -1;
listen:
if (socket_listen(slisten,1) != 0) {
perror("listen");
socket_close(slisten);
return -1;
}
snprintf(uport, sizeof(uport), "%d", sock_address_get_port(e) - port_offset);
qemu_opt_set(opts, "host", uaddr);
//.........这里部分代码省略.........
示例5: bdrv_qed_open
static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVQEDState *s = bs->opaque;
QEDHeader le_header;
int64_t file_size;
int ret;
s->bs = bs;
QSIMPLEQ_INIT(&s->allocating_write_reqs);
ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header));
if (ret < 0) {
return ret;
}
qed_header_le_to_cpu(&le_header, &s->header);
if (s->header.magic != QED_MAGIC) {
error_setg(errp, "Image not in QED format");
return -EINVAL;
}
if (s->header.features & ~QED_FEATURE_MASK) {
/* image uses unsupported feature bits */
char buf[64];
snprintf(buf, sizeof(buf), "%" PRIx64,
s->header.features & ~QED_FEATURE_MASK);
error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
bdrv_get_device_name(bs), "QED", buf);
return -ENOTSUP;
}
if (!qed_is_cluster_size_valid(s->header.cluster_size)) {
return -EINVAL;
}
/* Round down file size to the last cluster */
file_size = bdrv_getlength(bs->file);
if (file_size < 0) {
return file_size;
}
s->file_size = qed_start_of_cluster(s, file_size);
if (!qed_is_table_size_valid(s->header.table_size)) {
return -EINVAL;
}
if (!qed_is_image_size_valid(s->header.image_size,
s->header.cluster_size,
s->header.table_size)) {
return -EINVAL;
}
if (!qed_check_table_offset(s, s->header.l1_table_offset)) {
return -EINVAL;
}
s->table_nelems = (s->header.cluster_size * s->header.table_size) /
sizeof(uint64_t);
s->l2_shift = ffs(s->header.cluster_size) - 1;
s->l2_mask = s->table_nelems - 1;
s->l1_shift = s->l2_shift + ffs(s->table_nelems) - 1;
/* Header size calculation must not overflow uint32_t */
if (s->header.header_size > UINT32_MAX / s->header.cluster_size) {
return -EINVAL;
}
if ((s->header.features & QED_F_BACKING_FILE)) {
if ((uint64_t)s->header.backing_filename_offset +
s->header.backing_filename_size >
s->header.cluster_size * s->header.header_size) {
return -EINVAL;
}
ret = qed_read_string(bs->file, s->header.backing_filename_offset,
s->header.backing_filename_size, bs->backing_file,
sizeof(bs->backing_file));
if (ret < 0) {
return ret;
}
if (s->header.features & QED_F_BACKING_FORMAT_NO_PROBE) {
pstrcpy(bs->backing_format, sizeof(bs->backing_format), "raw");
}
}
/* Reset unknown autoclear feature bits. This is a backwards
* compatibility mechanism that allows images to be opened by older
* programs, which "knock out" unknown feature bits. When an image is
* opened by a newer program again it can detect that the autoclear
* feature is no longer valid.
*/
if ((s->header.autoclear_features & ~QED_AUTOCLEAR_FEATURE_MASK) != 0 &&
!bdrv_is_read_only(bs->file) && !(flags & BDRV_O_INCOMING)) {
s->header.autoclear_features &= QED_AUTOCLEAR_FEATURE_MASK;
ret = qed_write_header_sync(s);
if (ret) {
return ret;
}
/* From here on only known autoclear feature bits are valid */
bdrv_flush(bs->file);
//.........这里部分代码省略.........
示例6: tap_open
int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int vnet_hdr_required, int mq_required)
{
int fd;
#ifdef TAPGIFNAME
struct ifreq ifr;
#else
char *dev;
struct stat s;
#endif
/* if no ifname is given, always start the search from tap0/tun0. */
int i;
char dname[100];
for (i = 0; i < 10; i++) {
if (*ifname) {
snprintf(dname, sizeof dname, "/dev/%s", ifname);
} else {
#if defined(__OpenBSD__)
snprintf(dname, sizeof dname, "/dev/tun%d", i);
#else
snprintf(dname, sizeof dname, "/dev/tap%d", i);
#endif
}
TFR(fd = open(dname, O_RDWR));
if (fd >= 0) {
break;
}
else if (errno == ENXIO || errno == ENOENT) {
break;
}
if (*ifname) {
break;
}
}
if (fd < 0) {
error_report("warning: could not open %s (%s): no virtual network emulation",
dname, strerror(errno));
return -1;
}
#ifdef TAPGIFNAME
if (ioctl(fd, TAPGIFNAME, (void *)&ifr) < 0) {
fprintf(stderr, "warning: could not get tap name: %s\n",
strerror(errno));
return -1;
}
pstrcpy(ifname, ifname_size, ifr.ifr_name);
#else
if (fstat(fd, &s) < 0) {
fprintf(stderr,
"warning: could not stat /dev/tap: no virtual network emulation: %s\n",
strerror(errno));
return -1;
}
dev = devname(s.st_rdev, S_IFCHR);
pstrcpy(ifname, ifname_size, dev);
#endif
if (*vnet_hdr) {
/* BSD doesn't have IFF_VNET_HDR */
*vnet_hdr = 0;
if (vnet_hdr_required && !*vnet_hdr) {
error_report("vnet_hdr=1 requested, but no kernel "
"support for IFF_VNET_HDR available");
close(fd);
return -1;
}
}
fcntl(fd, F_SETFL, O_NONBLOCK);
return fd;
}
示例7: init_registry_data
static BOOL init_registry_data( void )
{
pstring path, base, remaining;
fstring keyname, subkeyname;
REGSUBKEY_CTR *subkeys;
REGVAL_CTR *values;
int i;
const char *p, *p2;
UNISTR2 data;
/*
* There are potentially quite a few store operations which are all
* indiviually wrapped in tdb transactions. Wrapping them in a single
* transaction gives just a single transaction_commit() to actually do
* its fsync()s. See tdb/common/transaction.c for info about nested
* transaction behaviour.
*/
if ( tdb_transaction_start( tdb_reg ) == -1 ) {
DEBUG(0, ("init_registry_data: tdb_transaction_start "
"failed\n"));
return False;
}
/* loop over all of the predefined paths and add each component */
for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {
DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));
pstrcpy( path, builtin_registry_paths[i] );
pstrcpy( base, "" );
p = path;
while ( next_token(&p, keyname, "\\", sizeof(keyname)) ) {
/* build up the registry path from the components */
if ( *base )
pstrcat( base, "\\" );
pstrcat( base, keyname );
/* get the immediate subkeyname (if we have one ) */
*subkeyname = '\0';
if ( *p ) {
pstrcpy( remaining, p );
p2 = remaining;
if ( !next_token(&p2, subkeyname, "\\", sizeof(subkeyname)) )
fstrcpy( subkeyname, p2 );
}
DEBUG(10,("init_registry_data: Storing key [%s] with subkey [%s]\n",
base, *subkeyname ? subkeyname : "NULL"));
/* we don't really care if the lookup succeeds or not since
we are about to update the record. We just want any
subkeys already present */
if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
DEBUG(0,("talloc() failure!\n"));
goto fail;
}
regdb_fetch_keys( base, subkeys );
if ( *subkeyname )
regsubkey_ctr_addkey( subkeys, subkeyname );
if ( !regdb_store_keys( base, subkeys ))
goto fail;
TALLOC_FREE( subkeys );
}
}
/* loop over all of the predefined values and add each component */
for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
DEBUG(0,("talloc() failure!\n"));
goto fail;
}
regdb_fetch_values( builtin_registry_values[i].path, values );
/* preserve existing values across restarts. Only add new ones */
if ( !regval_ctr_key_exists( values, builtin_registry_values[i].valuename ) )
{
switch( builtin_registry_values[i].type ) {
case REG_DWORD:
regval_ctr_addvalue( values,
builtin_registry_values[i].valuename,
REG_DWORD,
(char*)&builtin_registry_values[i].data.dw_value,
sizeof(uint32) );
break;
case REG_SZ:
init_unistr2( &data, builtin_registry_values[i].data.string, UNI_STR_TERMINATE);
//.........这里部分代码省略.........
示例8: popt_common_callback
static void popt_common_callback(poptContext con,
enum poptCallbackReason reason,
const struct poptOption *opt,
const char *arg, const void *data)
{
if (reason == POPT_CALLBACK_REASON_PRE) {
set_logfile(con, dyn_LOGFILEBASE);
return;
}
switch(opt->val) {
case 'd':
if (arg) {
debug_parse_levels(arg);
AllowDebugChange = False;
}
break;
case 'V':
printf( "Version %s\n", SAMBA_VERSION_STRING);
exit(0);
break;
case 'O':
if (arg) {
pstrcpy(user_socket_options,arg);
}
break;
case 's':
if (arg) {
pstrcpy(dyn_CONFIGFILE, arg);
}
break;
case 'n':
if (arg) {
set_global_myname(arg);
}
break;
case 'l':
if (arg) {
set_logfile(con, arg);
override_logfile = True;
pstr_sprintf(dyn_LOGFILEBASE, "%s", arg);
}
break;
case 'i':
if (arg) {
set_global_scope(arg);
}
break;
case 'W':
if (arg) {
set_global_myworkgroup(arg);
}
break;
}
}
示例9: pstrcpy
static struct cli_state *do_connect( const char *server, const char *share,
BOOL show_sessetup )
{
struct cli_state *c;
struct nmb_name called, calling;
const char *server_n;
struct in_addr ip;
pstring servicename;
char *sharename;
/* make a copy so we don't modify the global string 'service' */
pstrcpy(servicename, share);
sharename = servicename;
if (*sharename == '\\') {
server = sharename+2;
sharename = strchr_m(server,'\\');
if (!sharename) return NULL;
*sharename = 0;
sharename++;
}
server_n = server;
zero_ip(&ip);
make_nmb_name(&calling, global_myname(), 0x0);
make_nmb_name(&called , server, name_type);
again:
zero_ip(&ip);
if (have_ip)
ip = dest_ip;
/* have to open a new connection */
if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) != port) ||
!cli_connect(c, server_n, &ip)) {
d_printf("Connection to %s failed\n", server_n);
return NULL;
}
c->protocol = max_protocol;
c->use_kerberos = use_kerberos;
cli_setup_signing_state(c, signing_state);
if (!cli_session_request(c, &calling, &called)) {
char *p;
d_printf("session request to %s failed (%s)\n",
called.name, cli_errstr(c));
cli_shutdown(c);
if ((p=strchr_m(called.name, '.'))) {
*p = 0;
goto again;
}
if (strcmp(called.name, "*SMBSERVER")) {
make_nmb_name(&called , "*SMBSERVER", 0x20);
goto again;
}
return NULL;
}
DEBUG(4,(" session request ok\n"));
if (!cli_negprot(c)) {
d_printf("protocol negotiation failed\n");
cli_shutdown(c);
return NULL;
}
if (!got_pass) {
char *pass = getpass("Password: ");
if (pass) {
pstrcpy(password, pass);
got_pass = 1;
}
}
if (!cli_session_setup(c, username,
password, strlen(password),
password, strlen(password),
lp_workgroup())) {
/* if a password was not supplied then try again with a null username */
if (password[0] || !username[0] || use_kerberos ||
!cli_session_setup(c, "", "", 0, "", 0, lp_workgroup())) {
d_printf("session setup failed: %s\n", cli_errstr(c));
if (NT_STATUS_V(cli_nt_error(c)) ==
NT_STATUS_V(NT_STATUS_MORE_PROCESSING_REQUIRED))
d_printf("did you forget to run kinit?\n");
cli_shutdown(c);
return NULL;
}
d_printf("Anonymous login successful\n");
}
if ( show_sessetup ) {
if (*c->server_domain) {
DEBUG(0,("Domain=[%s] OS=[%s] Server=[%s]\n",
c->server_domain,c->server_os,c->server_type));
} else if (*c->server_os || *c->server_type){
DEBUG(0,("OS=[%s] Server=[%s]\n",
//.........这里部分代码省略.........
示例10: popt_dynconfig_callback
static void popt_dynconfig_callback(poptContext con,
enum poptCallbackReason reason,
const struct poptOption *opt,
const char *arg, const void *data)
{
switch (opt->val) {
case DYN_SBINDIR:
if (arg) {
dyn_SBINDIR = SMB_STRDUP(arg);
}
break;
case DYN_BINDIR:
if (arg) {
dyn_BINDIR = SMB_STRDUP(arg);
}
break;
case DYN_SWATDIR:
if (arg) {
dyn_SWATDIR = SMB_STRDUP(arg);
}
break;
case DYN_LMHOSTSFILE:
if (arg) {
pstrcpy(dyn_LMHOSTSFILE, arg);
}
break;
case DYN_LIBDIR:
if (arg) {
pstrcpy(dyn_LIBDIR, arg);
}
break;
case DYN_SHLIBEXT:
if (arg) {
fstrcpy(dyn_SHLIBEXT, arg);
}
break;
case DYN_LOCKDIR:
if (arg) {
pstrcpy(dyn_LOCKDIR, arg);
}
break;
case DYN_PIDDIR:
if (arg) {
pstrcpy(dyn_PIDDIR, arg);
}
break;
case DYN_SMB_PASSWD_FILE:
if (arg) {
pstrcpy(dyn_SMB_PASSWD_FILE, arg);
}
break;
case DYN_PRIVATE_DIR:
if (arg) {
pstrcpy(dyn_PRIVATE_DIR, arg);
}
break;
}
}
示例11: popt_common_credentials_callback
static void popt_common_credentials_callback(poptContext con,
enum poptCallbackReason reason,
const struct poptOption *opt,
const char *arg, const void *data)
{
char *p;
if (reason == POPT_CALLBACK_REASON_PRE) {
cmdline_auth_info.use_kerberos = False;
cmdline_auth_info.got_pass = False;
cmdline_auth_info.signing_state = Undefined;
pstrcpy(cmdline_auth_info.username, "GUEST");
if (getenv("LOGNAME"))pstrcpy(cmdline_auth_info.username,getenv("LOGNAME"));
if (getenv("USER")) {
pstrcpy(cmdline_auth_info.username,getenv("USER"));
if ((p = strchr_m(cmdline_auth_info.username,'%'))) {
*p = 0;
pstrcpy(cmdline_auth_info.password,p+1);
cmdline_auth_info.got_pass = True;
memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password));
}
}
if (getenv("PASSWD")) {
pstrcpy(cmdline_auth_info.password,getenv("PASSWD"));
cmdline_auth_info.got_pass = True;
}
if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) {
get_password_file(&cmdline_auth_info);
cmdline_auth_info.got_pass = True;
}
return;
}
switch(opt->val) {
case 'U':
{
char *lp;
pstrcpy(cmdline_auth_info.username,arg);
if ((lp=strchr_m(cmdline_auth_info.username,'%'))) {
*lp = 0;
pstrcpy(cmdline_auth_info.password,lp+1);
cmdline_auth_info.got_pass = True;
memset(strchr_m(arg,'%')+1,'X',strlen(cmdline_auth_info.password));
}
}
break;
case 'A':
get_credentials_file(arg, &cmdline_auth_info);
break;
case 'k':
#ifndef HAVE_KRB5
d_printf("No kerberos support compiled in\n");
exit(1);
#else
cmdline_auth_info.use_kerberos = True;
cmdline_auth_info.got_pass = True;
#endif
break;
case 'S':
{
cmdline_auth_info.signing_state = -1;
if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false"))
cmdline_auth_info.signing_state = False;
else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") ||
strequal(arg, "auto") )
cmdline_auth_info.signing_state = True;
else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced"))
cmdline_auth_info.signing_state = Required;
else {
fprintf(stderr, "Unknown signing option %s\n", arg );
exit(1);
}
}
break;
case 'P':
{
char *opt_password = NULL;
/* it is very useful to be able to make ads queries as the
machine account for testing purposes and for domain leave */
if (!secrets_init()) {
d_printf("ERROR: Unable to open secrets database\n");
exit(1);
}
opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
if (!opt_password) {
d_printf("ERROR: Unable to fetch machine password\n");
exit(1);
//.........这里部分代码省略.........
示例12: curl_open
static int curl_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVCURLState *s = bs->opaque;
CURLState *state = NULL;
QemuOpts *opts;
Error *local_err = NULL;
const char *file;
const char *cookie;
double d;
static int inited = 0;
if (flags & BDRV_O_RDWR) {
error_setg(errp, "curl block device does not support writes");
return -EROFS;
}
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto out_noclean;
}
s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,
READ_AHEAD_DEFAULT);
if ((s->readahead_size & 0x1ff) != 0) {
error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
s->readahead_size);
goto out_noclean;
}
s->timeout = qemu_opt_get_number(opts, CURL_BLOCK_OPT_TIMEOUT,
CURL_TIMEOUT_DEFAULT);
if (s->timeout > CURL_TIMEOUT_MAX) {
error_setg(errp, "timeout parameter is too large or negative");
goto out_noclean;
}
s->sslverify = qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, true);
cookie = qemu_opt_get(opts, CURL_BLOCK_OPT_COOKIE);
s->cookie = g_strdup(cookie);
file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
if (file == NULL) {
error_setg(errp, "curl block driver requires an 'url' option");
goto out_noclean;
}
if (!inited) {
curl_global_init(CURL_GLOBAL_ALL);
inited = 1;
}
DPRINTF("CURL: Opening %s\n", file);
s->aio_context = bdrv_get_aio_context(bs);
s->url = g_strdup(file);
state = curl_init_state(bs, s);
if (!state)
goto out_noclean;
// Get file size
s->accept_range = false;
curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
curl_header_cb);
curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
if (curl_easy_perform(state->curl))
goto out;
curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
if (d)
s->len = (size_t)d;
else if(!s->len)
goto out;
if ((!strncasecmp(s->url, "http://", strlen("http://"))
|| !strncasecmp(s->url, "https://", strlen("https://")))
&& !s->accept_range) {
pstrcpy(state->errmsg, CURL_ERROR_SIZE,
"Server does not support 'range' (byte ranges).");
goto out;
}
DPRINTF("CURL: Size = %zd\n", s->len);
curl_clean_state(state);
curl_easy_cleanup(state->curl);
state->curl = NULL;
curl_attach_aio_context(bs, bdrv_get_aio_context(bs));
qemu_opts_del(opts);
return 0;
out:
error_setg(errp, "CURL: Error opening file: %s", state->errmsg);
curl_easy_cleanup(state->curl);
state->curl = NULL;
out_noclean:
//.........这里部分代码省略.........
示例13: set_share_mode
BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
{
TDB_DATA dbuf;
struct locking_data *data;
char *p=NULL;
int size;
BOOL ret = True;
/* read in the existing share modes if any */
dbuf = tdb_fetch(tdb, locking_key_fsp(fsp));
if (!dbuf.dptr) {
size_t offset;
/* we'll need to create a new record */
pstring fname;
pstrcpy(fname, fsp->conn->connectpath);
pstrcat(fname, "/");
pstrcat(fname, fsp->fsp_name);
size = sizeof(*data) + sizeof(share_mode_entry) + strlen(fname) + 1;
p = (char *)malloc(size);
if (!p)
return False;
data = (struct locking_data *)p;
data->u.num_share_mode_entries = 1;
DEBUG(10,("set_share_mode: creating entry for file %s. num_share_modes = 1\n",
fsp->fsp_name ));
offset = sizeof(*data) + sizeof(share_mode_entry);
safe_strcpy(p + offset, fname, size - offset - 1);
fill_share_mode(p + sizeof(*data), fsp, port, op_type);
dbuf.dptr = p;
dbuf.dsize = size;
if (tdb_store(tdb, locking_key_fsp(fsp), dbuf, TDB_REPLACE) == -1)
ret = False;
print_share_mode_table((struct locking_data *)p);
SAFE_FREE(p);
return ret;
}
/* we're adding to an existing entry - this is a bit fiddly */
data = (struct locking_data *)dbuf.dptr;
data->u.num_share_mode_entries++;
DEBUG(10,("set_share_mode: adding entry for file %s. new num_share_modes = %d\n",
fsp->fsp_name, data->u.num_share_mode_entries ));
size = dbuf.dsize + sizeof(share_mode_entry);
p = malloc(size);
if (!p)
return False;
memcpy(p, dbuf.dptr, sizeof(*data));
fill_share_mode(p + sizeof(*data), fsp, port, op_type);
memcpy(p + sizeof(*data) + sizeof(share_mode_entry), dbuf.dptr + sizeof(*data),
dbuf.dsize - sizeof(*data));
SAFE_FREE(dbuf.dptr);
dbuf.dptr = p;
dbuf.dsize = size;
if (tdb_store(tdb, locking_key_fsp(fsp), dbuf, TDB_REPLACE) == -1)
ret = False;
print_share_mode_table((struct locking_data *)p);
SAFE_FREE(p);
return ret;
}
示例14: tap_alloc
/*
* Allocate TAP device, returns opened fd.
* Stores dev name in the first arg(must be large enough).
*/
static int tap_alloc(char *dev, size_t dev_size)
{
int tap_fd, if_fd, ppa = -1;
static int ip_fd = 0;
char *ptr;
static int arp_fd = 0;
int ip_muxid, arp_muxid;
struct strioctl strioc_if, strioc_ppa;
int link_type = I_PLINK;;
struct lifreq ifr;
char actual_name[32] = "";
memset(&ifr, 0x0, sizeof(ifr));
if( *dev ){
ptr = dev;
while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
ppa = atoi(ptr);
}
/* Check if IP device was opened */
if( ip_fd )
close(ip_fd);
TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
if (ip_fd < 0) {
syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
return -1;
}
TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
if (tap_fd < 0) {
syslog(LOG_ERR, "Can't open /dev/tap");
return -1;
}
/* Assign a new PPA and get its unit number. */
strioc_ppa.ic_cmd = TUNNEWPPA;
strioc_ppa.ic_timout = 0;
strioc_ppa.ic_len = sizeof(ppa);
strioc_ppa.ic_dp = (char *)&ppa;
if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
syslog (LOG_ERR, "Can't assign new interface");
TFR(if_fd = open("/dev/tap", O_RDWR, 0));
if (if_fd < 0) {
syslog(LOG_ERR, "Can't open /dev/tap (2)");
return -1;
}
if(ioctl(if_fd, I_PUSH, "ip") < 0){
syslog(LOG_ERR, "Can't push IP module");
return -1;
}
if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
syslog(LOG_ERR, "Can't get flags\n");
snprintf (actual_name, 32, "tap%d", ppa);
pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
ifr.lifr_ppa = ppa;
/* Assign ppa according to the unit number returned by tun device */
if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
syslog (LOG_ERR, "Can't set PPA %d", ppa);
if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
syslog (LOG_ERR, "Can't get flags\n");
/* Push arp module to if_fd */
if (ioctl (if_fd, I_PUSH, "arp") < 0)
syslog (LOG_ERR, "Can't push ARP module (2)");
/* Push arp module to ip_fd */
if (ioctl (ip_fd, I_POP, NULL) < 0)
syslog (LOG_ERR, "I_POP failed\n");
if (ioctl (ip_fd, I_PUSH, "arp") < 0)
syslog (LOG_ERR, "Can't push ARP module (3)\n");
/* Open arp_fd */
TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
if (arp_fd < 0)
syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
/* Set ifname to arp */
strioc_if.ic_cmd = SIOCSLIFNAME;
strioc_if.ic_timout = 0;
strioc_if.ic_len = sizeof(ifr);
strioc_if.ic_dp = (char *)𝔦
if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
syslog (LOG_ERR, "Can't set ifname to arp\n");
}
if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
syslog(LOG_ERR, "Can't link TAP device to IP");
return -1;
}
//.........这里部分代码省略.........
示例15: net_init_tap
//.........这里部分代码省略.........
char *vhost_fds[MAX_TAP_QUEUES];
int nfds, nvhosts;
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
tap->has_fd) {
error_report("ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, and fd= are invalid with fds=");
return -1;
}
nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
if (tap->has_vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
if (nfds != nvhosts) {
error_report("The number of fds passed does not match the "
"number of vhostfds passed");
return -1;
}
}
for (i = 0; i < nfds; i++) {
fd = monitor_handle_fd_param(cur_mon, fds[i]);
if (fd == -1) {
return -1;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
if (i == 0) {
vnet_hdr = tap_probe_vnet_hdr(fd);
} else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
error_report("vnet_hdr not consistent across given tap fds");
return -1;
}
if (net_init_tap_one(tap, peer, "tap", name, ifname,
script, downscript,
tap->has_vhostfds ? vhost_fds[i] : NULL,
vnet_hdr, fd)) {
return -1;
}
}
} else if (tap->has_helper) {
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
tap->has_vnet_hdr || tap->has_queues || tap->has_fds) {
error_report("ifname=, script=, downscript=, and vnet_hdr= "
"queues=, and fds= are invalid with helper=");
return -1;
}
fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE);
if (fd == -1) {
return -1;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
vnet_hdr = tap_probe_vnet_hdr(fd);
if (net_init_tap_one(tap, peer, "bridge", name, ifname,
script, downscript, vhostfdname,
vnet_hdr, fd)) {
return -1;
}
} else {
script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
downscript = tap->has_downscript ? tap->downscript :
DEFAULT_NETWORK_DOWN_SCRIPT;
if (tap->has_ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);
} else {
ifname[0] = '\0';
}
for (i = 0; i < queues; i++) {
fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
ifname, sizeof ifname, queues > 1);
if (fd == -1) {
return -1;
}
if (queues > 1 && i == 0 && !tap->has_ifname) {
if (tap_fd_get_ifname(fd, ifname)) {
error_report("Fail to get ifname");
return -1;
}
}
if (net_init_tap_one(tap, peer, "tap", name, ifname,
i >= 1 ? "no" : script,
i >= 1 ? "no" : downscript,
vhostfdname, vnet_hdr, fd)) {
return -1;
}
}
}
return 0;
}