예제 #1
0
static struct addrinfo *alloc_entry(const struct addrinfo *hints,
				struct in_addr ip,
				unsigned short port)
{
	struct sockaddr_in *psin = NULL;
	struct addrinfo *ai = SMB_MALLOC(sizeof(*ai));

	if (!ai) {
		return NULL;
	}
	memset(ai, '\0', sizeof(*ai));

	psin = SMB_MALLOC(sizeof(*psin));
	if (!psin) {
		free(ai);
		return NULL;
	}

	memset(psin, '\0', sizeof(*psin));

	psin->sin_family = AF_INET;
	psin->sin_port = htons(port);
	psin->sin_addr = ip;

	ai->ai_flags = 0;
	ai->ai_family = AF_INET;
	ai->ai_socktype = hints->ai_socktype;
	ai->ai_protocol = hints->ai_protocol;
	ai->ai_addrlen = sizeof(*psin);
	ai->ai_addr = (struct sockaddr *) psin;
	ai->ai_canonname = NULL;
	ai->ai_next = NULL;

	return ai;
}
예제 #2
0
파일: onefs_dir.c 프로젝트: gojdic/samba
/**
 * Initialize the global readdirplus buffers.
 *
 * These same buffers are used for all calls into readdirplus.
 *
 * @return 0 on success, errno value on failure
 */
static int
rdp_init(struct rdp_dir_state *dsp)
{
	/* Unfortunately, there is no good way to free these buffers.  If we
	 * allocated and freed for every DIR handle performance would be
	 * adversely affected.  For now these buffers will be leaked and only
	 * freed when the smbd process dies. */
	if (!rdp_direntries) {
		rdp_direntries = SMB_MALLOC(RDP_DIRENTRIES_SIZE);
		if (!rdp_direntries)
			return ENOMEM;
	}

	if (!rdp_stats) {
		rdp_stats =
		    SMB_MALLOC(RDP_BATCH_SIZE * sizeof(SMB_STRUCT_STAT));
		if (!rdp_stats)
			return ENOMEM;
	}

	if (!rdp_cookies) {
		rdp_cookies = SMB_MALLOC(RDP_BATCH_SIZE * sizeof(uint64_t));
		if (!rdp_cookies)
			return ENOMEM;
	}

	dsp->direntries_cursor = rdp_direntries + RDP_DIRENTRIES_SIZE;
	dsp->stat_count = RDP_BATCH_SIZE;
	dsp->stat_cursor = RDP_BATCH_SIZE;
	dsp->resume_cookie = RDP_RESUME_KEY_START;
	dsp->location = 0;

	return 0;
}
예제 #3
0
파일: vfs_aixacl.c 프로젝트: gojdic/samba
SMB_ACL_T aixacl_sys_acl_get_file(vfs_handle_struct *handle,
				    const char *path_p,
				    SMB_ACL_TYPE_T type)
{
	struct acl *file_acl = (struct acl *)NULL;
	struct smb_acl_t *result = (struct smb_acl_t *)NULL;
	
	int rc = 0;
	uid_t user_id;

	/* AIX has no DEFAULT */
	if  ( type == SMB_ACL_TYPE_DEFAULT )
		return NULL;

	/* Get the acl using statacl */
 
	DEBUG(10,("Entering AIX sys_acl_get_file\n"));
	DEBUG(10,("path_p is %s\n",path_p));

	file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 
	if(file_acl == NULL) {
		errno=ENOMEM;
		DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
		return(NULL);
	}

	memset(file_acl,0,BUFSIZ);

	rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
	if( (rc == -1) && (errno == ENOSPC)) {
		struct acl *new_acl = SMB_MALLOC(file_acl->acl_len + sizeof(struct acl));
		if( new_acl == NULL) {
			SAFE_FREE(file_acl);
			errno = ENOMEM;
			return NULL;
		}
		file_acl = new_acl;
		rc = statacl((char *)path_p,0,file_acl,file_acl->acl_len+sizeof(struct acl));
		if( rc == -1) {
			DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
			SAFE_FREE(file_acl);
			return(NULL);
		}
	}

	DEBUG(10,("Got facl and returned it\n"));

	
	result = aixacl_to_smbacl(file_acl);
	SAFE_FREE(file_acl);
	return result;
	
	/*errno = ENOTSUP;
	return NULL;*/
}
예제 #4
0
static BOOL cli_set_ea(struct cli_state *cli, uint16 setup, char *param, unsigned int param_len,
			const char *ea_name, const char *ea_val, size_t ea_len)
{	
	unsigned int data_len = 0;
	char *data = NULL;
	char *rparam=NULL, *rdata=NULL;
	char *p;
	size_t ea_namelen = strlen(ea_name);

	if (ea_namelen == 0 && ea_len == 0) {
		data_len = 4;
		data = SMB_MALLOC(data_len);
		if (!data) {
			return False;
		}
		p = data;
		SIVAL(p,0,data_len);
	} else {
		data_len = 4 + 4 + ea_namelen + 1 + ea_len;
		data = SMB_MALLOC(data_len);
		if (!data) {
			return False;
		}
		p = data;
		SIVAL(p,0,data_len);
		p += 4;
		SCVAL(p, 0, 0); /* EA flags. */
		SCVAL(p, 1, ea_namelen);
		SSVAL(p, 2, ea_len);
		memcpy(p+4, ea_name, ea_namelen+1); /* Copy in the name. */
		memcpy(p+4+ea_namelen+1, ea_val, ea_len);
	}

	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 */
		data,  data_len, cli->max_xmit /* data, length, max */
		)) {
			return False;
	}

	if (!cli_receive_trans(cli, SMBtrans2,
		&rparam, &param_len,
		&rdata, &data_len)) {
			return False;
	}

	SAFE_FREE(data);
	SAFE_FREE(rdata);
	SAFE_FREE(rparam);

	return True;
}
예제 #5
0
static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
			      int argc, const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	uint32 size, i;
	NTSTATUS status;
	uint8_t *in_data = NULL, *out_data = NULL;

	if (argc != 2) {
		printf("Usage: %s num\n", argv[0]);
		return NT_STATUS_OK;
	}

	size = atoi(argv[1]);
	if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
		printf("Failure to allocate buff of %d bytes\n",
		       size);
		status = NT_STATUS_NO_MEMORY;
		goto done;
	}
	if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
		printf("Failure to allocate buff of %d bytes\n",
		       size);
		status = NT_STATUS_NO_MEMORY;
		goto done;
	}

	for (i = 0; i < size; i++) {
		in_data[i] = i & 0xff;
	}

	status = dcerpc_echo_EchoData(b, mem_ctx, size, in_data, out_data);
	if (!NT_STATUS_IS_OK(status)) {
		goto done;
	}

	for (i = 0; i < size; i++) {
		if (in_data[i] != out_data[i]) {
			printf("mismatch at offset %d, %d != %d\n",
			       i, in_data[i], out_data[i]);
			status = NT_STATUS_UNSUCCESSFUL;
		}
	}

done:
	SAFE_FREE(in_data);
	SAFE_FREE(out_data);

	return status;
}
예제 #6
0
파일: vfs_aixacl.c 프로젝트: gojdic/samba
SMB_ACL_T aixacl_sys_acl_get_fd(vfs_handle_struct *handle,
				files_struct *fsp)
{

	struct acl *file_acl = (struct acl *)NULL;
	struct smb_acl_t *result = (struct smb_acl_t *)NULL;
	
	int rc = 0;
	uid_t user_id;

	/* Get the acl using fstatacl */
   
	DEBUG(10,("Entering AIX sys_acl_get_fd\n"));
	DEBUG(10,("fd is %d\n",fsp->fh->fd));
	file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);

	if(file_acl == NULL) {
		errno=ENOMEM;
		DEBUG(0,("Error in AIX sys_acl_get_fd is %d\n",errno));
		return(NULL);
	}

	memset(file_acl,0,BUFSIZ);

	rc = fstatacl(fsp->fh->fd,0,file_acl,BUFSIZ);
	if( (rc == -1) && (errno == ENOSPC)) {
		struct acl *new_acl = SMB_MALLOC(file_acl->acl_len + sizeof(struct acl));
		if( new_acl == NULL) {
			SAFE_FREE(file_acl);
			errno = ENOMEM;
			return NULL;
		}
		file_acl = new_acl;
		rc = fstatacl(fsp->fh->fd,0,file_acl,file_acl->acl_len + sizeof(struct acl));
		if( rc == -1) {
			DEBUG(0,("fstatacl returned %d with errno %d\n",rc,errno));
			SAFE_FREE(file_acl);
			return(NULL);
		}
	}

	DEBUG(10,("Got facl and returned it\n"));

	result = aixacl_to_smbacl(file_acl);
	SAFE_FREE(file_acl);
	return result;
	
	/*errno = ENOTSUP;
	return NULL;*/
}
예제 #7
0
char *fd_load(int fd, size_t *psize, size_t maxsize)
{
    SMB_STRUCT_STAT sbuf;
    size_t size;
    char *p;

    if (sys_fstat(fd, &sbuf) != 0) {
        return NULL;
    }

    size = sbuf.st_size;
    if (maxsize) {
        size = MIN(size, maxsize);
    }

    p = (char *)SMB_MALLOC(size+1);
    if (!p) {
        return NULL;
    }

    if (read(fd, p, size) != size) {
        SAFE_FREE(p);
        return NULL;
    }
    p[size] = 0;

    if (psize) {
        *psize = size;
    }

    return p;
}
예제 #8
0
파일: cmd_echo.c 프로젝트: gojdic/samba
static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
				   int argc, const char **argv)
{
	uint32 size, i;
	NTSTATUS result;
	uint8_t *in_data = NULL;

	if (argc != 2) {
		printf("Usage: %s num\n", argv[0]);
		return NT_STATUS_OK;
	}

	size = atoi(argv[1]);
	if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
		printf("Failure to allocate buff of %d bytes\n",
		       size);
		result = NT_STATUS_NO_MEMORY;
		goto done;		
	}

	for (i = 0; i < size; i++)
		in_data[i] = i & 0xff;

	result = rpccli_echo_SinkData(cli, mem_ctx, size, in_data);

	if (!NT_STATUS_IS_OK(result))
		goto done;

done:
	SAFE_FREE(in_data);

	return result;
}
예제 #9
0
bool prs_grow(prs_struct *ps, uint32 extra_space)
{
	uint32 new_size;

	ps->grow_size = MAX(ps->grow_size, ps->data_offset + extra_space);

	if(ps->data_offset + extra_space <= ps->buffer_size)
		return True;

	/*
	 * We cannot grow the buffer if we're not reading
	 * into the prs_struct, or if we don't own the memory.
	 */

	if(UNMARSHALLING(ps) || !ps->is_dynamic) {
		DEBUG(0,("prs_grow: Buffer overflow - unable to expand buffer by %u bytes.\n",
				(unsigned int)extra_space));
		return False;
	}
	
	/*
	 * Decide how much extra space we really need.
	 */

	extra_space -= (ps->buffer_size - ps->data_offset);
	if(ps->buffer_size == 0) {

		/*
		 * Start with 128 bytes (arbitrary value), enough for small rpc
		 * requests
		 */
		new_size = MAX(128, extra_space);

		if((ps->data_p = (char *)SMB_MALLOC(new_size)) == NULL) {
			DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
			return False;
		}
		memset(ps->data_p, '\0', (size_t)new_size );
	} else {
		/*
		 * If the current buffer size is bigger than the space needed,
		 * just double it, else add extra_space. Always keep 64 bytes
		 * more, so that after we added a large blob we don't have to
		 * realloc immediately again.
		 */
		new_size = MAX(ps->buffer_size*2,
			       ps->buffer_size + extra_space + 64);

		if ((ps->data_p = (char *)SMB_REALLOC(ps->data_p, new_size)) == NULL) {
			DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
				(unsigned int)new_size));
			return False;
		}

		memset(&ps->data_p[ps->buffer_size], '\0', (size_t)(new_size - ps->buffer_size));
	}
	ps->buffer_size = new_size;

	return True;
}
예제 #10
0
bool prs_init(prs_struct *ps, uint32 size, TALLOC_CTX *ctx, bool io)
{
	ZERO_STRUCTP(ps);
	ps->io = io;
	ps->bigendian_data = RPC_LITTLE_ENDIAN;
	ps->align = RPC_PARSE_ALIGN;
	ps->is_dynamic = False;
	ps->data_offset = 0;
	ps->buffer_size = 0;
	ps->data_p = NULL;
	ps->mem_ctx = ctx;

	if (size != 0) {
		ps->buffer_size = size;
		if((ps->data_p = (char *)SMB_MALLOC((size_t)size)) == NULL) {
			DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
			return False;
		}
		memset(ps->data_p, '\0', (size_t)size);
		ps->is_dynamic = True; /* We own this memory. */
	} else if (MARSHALLING(ps)) {
		/* If size is zero and we're marshalling we should allocate memory on demand. */
		ps->is_dynamic = True;
	}

	return True;
}
예제 #11
0
파일: vfs_dirsort.c 프로젝트: Arkhont/samba
static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
				       const char *fname, const char *mask,
				       uint32 attr)
{
	struct dirsort_privates *data = NULL;

	/* set up our private data about this directory */
	data = (struct dirsort_privates *)SMB_MALLOC(
		sizeof(struct dirsort_privates));

	if (!data) {
		return NULL;
	}

	data->directory_list = NULL;
	data->pos = 0;

	/* Open the underlying directory and count the number of entries */
	data->source_directory = SMB_VFS_NEXT_OPENDIR(handle, fname, mask,
						      attr);

	data->fd = dirfd(data->source_directory);

	SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
				struct dirsort_privates, return NULL);

	if (!open_and_sort_dir(handle)) {
		SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
		return NULL;
	}

	return data->source_directory;
}
예제 #12
0
static struct group *nss_getgrgid(gid_t gid)
{
	NSS_STATUS (*_nss_getgrgid_r)(gid_t , struct group *, char *, 
				      size_t , int *) = find_fn("getgrgid_r");
	static struct group grp;
	static char *buf;
	static int buflen = 1000;
	NSS_STATUS status;
	
	if (!_nss_getgrgid_r)
		return NULL;

	if (!buf) 
		buf = SMB_MALLOC(buflen);

again:	
	status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno);
	if (status == NSS_STATUS_TRYAGAIN) {
		buflen *= 2;
		buf = SMB_REALLOC(buf, buflen);
		if (!buf) {
			return NULL;
		}
		goto again;
	}
	if (status == NSS_STATUS_NOTFOUND) {
		return NULL;
	}
	if (status != NSS_STATUS_SUCCESS) {
		report_nss_error("getgrgid", status);
		return NULL;
	}
	return &grp;
}
예제 #13
0
/* Must return a pointer than can be freed by SAFE_FREE */
static char *python_realpath(vfs_handle_struct *handle,  const char *path)
{
	/*
	 * TODO I don't think this is really correct, it just returns every path
	 * as if it were valid. It seems to work in practice but we could pass it
	 * up to Python to compress the path? Or should we just call stat?
	 */
#define FAKE_REALPATH "/"
	char *p;
	int offset = 0;
	int bufsz = sizeof(FAKE_REALPATH) + strlen(path); 

	p = SMB_MALLOC(bufsz);
	if (!p) {
		errno = ENOMEM;
		return NULL;
	}
	strncpy(p, FAKE_REALPATH, bufsz);

	if (strcmp(path, ".") == 0) return p;

	if (path[0] == '/') offset = 1;

	strncpy(p + sizeof(FAKE_REALPATH) - 1, path + offset, bufsz - sizeof(FAKE_REALPATH) - 1);
	p[bufsz - 1] = '\0';
	return p;
}
예제 #14
0
파일: util_file.c 프로젝트: hajuuk/R7000
char *fd_load(int fd, size_t *size)
{
	SMB_STRUCT_STAT sbuf;
	char *p;

	if (sys_fstat(fd, &sbuf) != 0) {
		return NULL;
	}

	p = (char *)SMB_MALLOC(sbuf.st_size+1);
	if (!p) {
		return NULL;
	}

	if (read(fd, p, sbuf.st_size) != sbuf.st_size) {
		SAFE_FREE(p);
		return NULL;
	}
	p[sbuf.st_size] = 0;

	if (size) {
		*size = sbuf.st_size;
	}

	return p;
}
예제 #15
0
REGISTRY_HOOK* reghook_cache_find( char *keyname )
{
	char *key;
	int len;
	REGISTRY_HOOK *hook;
	
	if ( !keyname )
		return NULL;
	
	/* prepend the string with a '\' character */
	
	len = strlen( keyname );
	if ( !(key = SMB_MALLOC( len + 2 )) ) {
		DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n",
			keyname));
		return NULL;
	}

	*key = '\\';
	strncpy( key+1, keyname, len+1);
	
	/* swap to a form understood by the SORTED_TREE */

	string_sub( key, "\\", "/", 0 );
		
	DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key));
	
	hook = pathtree_find( cache_tree, key ) ;
	
	SAFE_FREE( key );
	
	return hook;
}
예제 #16
0
파일: dprintf.c 프로젝트: 0x24bin/winexe-1
 int d_vfprintf(FILE *f, const char *format, va_list ap)
{
	char *p = NULL, *p2 = NULL;
	int ret, maxlen, clen;
	const char *msgstr;
	va_list ap2;

	va_copy(ap2, ap);

	/* do any message translations */
	msgstr = lang_msg(format);
	if (!msgstr) {
		ret = -1;
		goto out;
	}

	ret = vasprintf(&p, msgstr, ap2);

	lang_msg_free(msgstr);

	if (ret <= 0) {
		ret = -1;
		goto out;
	}

	/* now we have the string in unix format, convert it to the display
	   charset, but beware of it growing */
	maxlen = ret*2;
again:
	p2 = (char *)SMB_MALLOC(maxlen);
	if (!p2) {
		ret = -1;
		goto out;
	}

	clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen, True);
	if (clen == -1) {
		ret = -1;
		goto out;
	}

	if (clen >= maxlen) {
		/* it didn't fit - try a larger buffer */
		maxlen *= 2;
		SAFE_FREE(p2);
		goto again;
	}

	/* good, its converted OK */
	ret = fwrite(p2, 1, clen, f);
out:

	SAFE_FREE(p);
	SAFE_FREE(p2);
	va_end(ap2);

	return ret;
}
예제 #17
0
static HPUX_ACL_T hpux_acl_init(int count)
{
	HPUX_ACL_T hpux_acl = 
		(HPUX_ACL_T)SMB_MALLOC(sizeof(HPUX_ACE_T) * count);
	if (hpux_acl == NULL) {
		errno = ENOMEM;
	}
	return hpux_acl;
}
static SOLARIS_ACL_T solaris_acl_init(int count)
{
	SOLARIS_ACL_T solaris_acl = 
		(SOLARIS_ACL_T)SMB_MALLOC(sizeof(aclent_t) * count);
	if (solaris_acl == NULL) {
		errno = ENOMEM;
	}
	return solaris_acl;
}
예제 #19
0
static DIR *python_opendir(vfs_handle_struct *handle,  const char *fname, const char *mask, uint32 attr)
{
	struct my_dir *de;
	long entries, i;
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;

	pArgs = PyTuple_New(1);
	if (!pArgs) {
		errno = E_INTERNAL;
		return NULL;
	}

	if (!(pValue = PyString_FromString(fname))) {
		Py_DECREF(pArgs);
		errno = E_INTERNAL;
		return NULL;
	}
	PyTuple_SetItem(pArgs, 0, pValue);

	PY_CALL_WITH_ARGS_RET(GetDir, NULL);

	if (!PySequence_Check(pRet)) {
		DEBUG(1, ("vfs_python: getdir() did not return a sequence object!\n"));
		errno = E_INTERNAL;
		return NULL;
	}

	entries = PySequence_Length(pRet);
	if (NULL == (de = SMB_MALLOC(
		sizeof(*de) + (sizeof(de->entry[0]) * (entries - 1))
	))) {
		Py_DECREF(pRet);
		errno = ENOMEM;
		return NULL;
	}
	de->offset = 0;
	de->entries = entries;

	for (i = 0; i < entries; i++) {
		memset(&de->entry[i], 0, sizeof(de->entry[0]));
		de->entry[i].d_ino = 1;
		pArgs = PySequence_GetItem(pRet, i);
		if (!pArgs) {
			Py_DECREF(pRet);
			SAFE_FREE(de);
			errno = E_INTERNAL;
			return NULL;
		}
		strncpy(de->entry[i].d_name, PyString_AsString(pArgs), sizeof(de->entry[0].d_name));
		de->entry[i].d_name[sizeof(de->entry[0].d_name) - 1] = '\0';
		Py_DECREF(pArgs);
	}
	Py_DECREF(pRet);

	return (DIR *) de;
}
예제 #20
0
NTSTATUS gpo_copy_file(TALLOC_CTX *mem_ctx,
		       struct cli_state *cli,
		       const char *nt_path,
		       const char *unix_path)
{
	NTSTATUS result;
	int fnum;
	int fd = 0;
	char *data = NULL;
	static int io_bufsize = 64512;
	int read_size = io_bufsize;
	off_t start = 0;
	off_t nread = 0;

	if ((fnum = cli_open(cli, nt_path, O_RDONLY, DENY_NONE)) == -1) {
		result = NT_STATUS_NO_SUCH_FILE;
		goto out;
	}

	if ((fd = sys_open(unix_path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
		result = map_nt_error_from_unix(errno);
		goto out;
	}
	 
	if ((data = (char *)SMB_MALLOC(read_size)) == NULL) {
		result = NT_STATUS_NO_MEMORY;
		goto out;
	}

	while (1) {

		int n = cli_read(cli, fnum, data, nread + start, read_size);

		if (n <= 0)
			break;

		if (write(fd, data, n) != n) {
			break;
		}

		nread += n;
	}

	result = NT_STATUS_OK;

 out:
	SAFE_FREE(data);
	if (fnum) {
		cli_close(cli, fnum);
	}
	if (fd) {
		close(fd);
	}

	return result;
}
예제 #21
0
파일: ldap_escape.c 프로젝트: hajuuk/R7000
char *escape_ldap_string_alloc(const char *s)
{
	size_t len = strlen(s)+1;
	char *output = SMB_MALLOC(len);
	char *output_tmp;
	const char *sub;
	int i = 0;
	char *p = output;
	
	while (*s)
	{
		switch (*s)
		{
		case '*':
			sub = "\\2a";
			break;
		case '(':
			sub = "\\28";
			break;
		case ')':
			sub = "\\29";
			break;
		case '\\':
			sub = "\\5c";
			break;
		default:
			sub = NULL;
			break;
		}
		
		if (sub) {
			len = len + 3;
			output_tmp = SMB_REALLOC(output, len);
			if (!output_tmp) { 
				SAFE_FREE(output);
				return NULL;
			}
			output = output_tmp;
			
			p = &output[i];
			strncpy (p, sub, 3);
			p += 3;
			i += 3;

		} else {
			*p = *s;
			p++;
			i++;
		}
		s++;
	}
	
	*p = '\0';
	return output;
}
예제 #22
0
파일: gencache.c 프로젝트: hajuuk/R7000
BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
{
	TDB_DATA keybuf, databuf;

	/* fail completely if get null pointers passed */
	SMB_ASSERT(keystr);

	if (!gencache_init())
		return False;
	
	keybuf.dptr = SMB_STRDUP(keystr);
	keybuf.dsize = strlen(keystr)+1;
	databuf = tdb_fetch(cache, keybuf);
	SAFE_FREE(keybuf.dptr);
	
	if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) {
		char* entry_buf = SMB_STRNDUP(databuf.dptr, databuf.dsize);
		char *v;
		time_t t;

		v = SMB_MALLOC(databuf.dsize - TIMEOUT_LEN);
				
		SAFE_FREE(databuf.dptr);
		sscanf(entry_buf, CACHE_DATA_FMT, (int*)&t, v);
		SAFE_FREE(entry_buf);

		DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, "
			   "timeout = %s\n", t > time(NULL) ? "valid" :
			   "expired", keystr, v, ctime(&t)));

		if (valstr)
			*valstr = v;
		else
			SAFE_FREE(v);

		if (timeout)
			*timeout = t;

		return t > time(NULL);

	} else {
		SAFE_FREE(databuf.dptr);

		if (valstr)
			*valstr = NULL;

		if (timeout)
			timeout = NULL;

		DEBUG(10, ("Cache entry with key = %s couldn't be found\n", 
			   keystr));

		return False;
	}
}
예제 #23
0
static char * realloc_expand_env_var(char *str, char *p)
{
	char *envname;
	char *envval;
	char *q, *r;
	int copylen;

	if (p[0] != '%' || p[1] != '$' || p[2] != '(') {
		return str;
	}

	/*
	 * Look for the terminating ')'.
	 */

	if ((q = strchr_m(p,')')) == NULL) {
		DEBUG(0,("expand_env_var: Unterminated environment variable [%s]\n", p));
		return str;
	}

	/*
	 * Extract the name from within the %$(NAME) string.
	 */

	r = p + 3;
	copylen = q - r;
	
	/* reserve space for use later add %$() chars */
	if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
		return NULL;
	}
	
	strncpy(envname,r,copylen);
	envname[copylen] = '\0';

	if ((envval = getenv(envname)) == NULL) {
		DEBUG(0,("expand_env_var: Environment variable [%s] not set\n", envname));
		SAFE_FREE(envname);
		return str;
	}

	/*
	 * Copy the full %$(NAME) into envname so it
	 * can be replaced.
	 */

	copylen = q + 1 - p;
	strncpy(envname,p,copylen);
	envname[copylen] = '\0';
	r = realloc_string_sub(str, envname, envval);
	SAFE_FREE(envname);
		
	return r;
}
예제 #24
0
파일: util_sid.c 프로젝트: gojdic/samba
char *sid_binstring_hex(const DOM_SID *sid)
{
	char *buf, *s;
	int len = ndr_size_dom_sid(sid, NULL, 0);
	buf = (char *)SMB_MALLOC(len);
	if (!buf)
		return NULL;
	sid_linearize(buf, len, sid);
	s = binary_string(buf, len);
	free(buf);
	return s;
}
예제 #25
0
파일: util_sid.c 프로젝트: aosm/samba
char *sid_binstring(const DOM_SID *sid)
{
	char *buf, *s;
	int len = sid_size(sid);
	buf = (char *)SMB_MALLOC(len);
	if (!buf)
		return NULL;
	sid_linearize(buf, len, sid);
	s = binary_string_rfc2254(buf, len);
	free(buf);
	return s;
}
예제 #26
0
파일: lang_tdb.c 프로젝트: hajuuk/R7000
/* translate a msgid to a message string in the current language 
   returns a string that must be freed by calling lang_msg_free()
*/
const char *lang_msg(const char *msgid)
{
	TDB_DATA key, data;
	const char *p;
	char *q, *msgid_quoted;
	int count;

	lang_tdb_init(NULL);

	if (!tdb) return msgid;

	/* Due to the way quotes in msgids are escaped in the msg file we
	   must replace " with \" before doing a lookup in the tdb. */

	count = 0;

	for(p = msgid; *p; p++) {
		if (*p == '\"')
			count++;
	}

	if (!(msgid_quoted = SMB_MALLOC(strlen(msgid) + count + 1)))
		return msgid;

	/* string_sub() is unsuitable here as it replaces some punctuation
	   chars with underscores. */

	for(p = msgid, q = msgid_quoted; *p; p++) {
		if (*p == '\"') {
			*q = '\\';
			q++;
		}
		*q = *p;
		q++;
	}

	*q = 0;

	key.dptr = (char *)msgid_quoted;
	key.dsize = strlen(msgid_quoted)+1;
	
	data = tdb_fetch(tdb, key);

	free(msgid_quoted);

	/* if the message isn't found then we still need to return a pointer
	   that can be freed. Pity. */
	if (!data.dptr)
		return SMB_STRDUP(msgid);

	return (const char *)data.dptr;
}
예제 #27
0
 char *strdup(const char *s)
{
	size_t len;
	char *ret;

	if (!s) return(NULL);

	len = strlen(s)+1;
	ret = (char *)SMB_MALLOC(len);
	if (!ret) return(NULL);
	memcpy(ret,s,len);
	return(ret);
}
예제 #28
0
static int vfs_my_module_create_dir(vfs_handle_struct *handle, const char *dname, const struct smb_filename *smb_fname)
{
	size_t len;
	mode_t mode;
	char *new_dir = NULL;
	char *tmp_str = NULL;
	char *token;
	char *tok_str;
	bool ret = False;
	char *saveptr;
    int i = 0;
	mode = vfs_my_module_directory_mode(handle);

	tmp_str = SMB_STRDUP(dname);
	ALLOC_CHECK(tmp_str, done);
	tok_str = tmp_str;

	len = strlen(dname)+1;
	new_dir = (char *)SMB_MALLOC(len + 1);
	ALLOC_CHECK(new_dir, done);
	*new_dir = '\0';
	if (dname[0] == '/') {
		/* Absolute path. */
		safe_strcat(new_dir,"/",len);
	}

	/* Create directory tree if neccessary */
	for(token = strtok_r(tok_str, "/", &saveptr); token;
	    token = strtok_r(NULL, "/", &saveptr)) {
		safe_strcat(new_dir, token, len);
		if (vfs_my_module_directory_exist(handle, new_dir))
			DEBUG(10, ("CREATE DIR: dir %s already exists\n", new_dir));
		else {
			DEBUG(1, ("CREATE DIR: creating new dir %s\n", new_dir));
			if (SMB_VFS_NEXT_MKDIR(handle, new_dir,mode) != 0) {
				DEBUG(1,("CREATE DIR: failed for %s with error: %s\n", new_dir, strerror(errno)));
				ret = False;
			}

		}
		safe_strcat(new_dir, "/", len);
		mode = vfs_my_module_subdir_mode(handle);
	i++;
	DEBUG(1,("CREATE DIR COUNTER: %d\n", i));
	ret = True;
	}
done:
	SAFE_FREE(tmp_str);
	SAFE_FREE(new_dir);
	return i;
}
예제 #29
0
파일: talloc.c 프로젝트: hajuuk/R7000
/** Create a new talloc context. **/
static TALLOC_CTX *talloc_init_internal(void)
{
	TALLOC_CTX *t;

	t = (TALLOC_CTX *)SMB_MALLOC(sizeof(TALLOC_CTX));
	if (t) {
		t->list = NULL;
		t->total_alloc_size = 0;
		t->name = NULL;
		talloc_enroll(t);
	}

	return t;
}
예제 #30
0
파일: gencache.c 프로젝트: hajuuk/R7000
void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
                      void* data, const char* keystr_pattern)
{
	TDB_LIST_NODE *node, *first_node;
	TDB_DATA databuf;
	char *keystr = NULL, *valstr = NULL, *entry = NULL;
	time_t timeout = 0;

	/* fail completely if get null pointers passed */
	SMB_ASSERT(fn && keystr_pattern);

	if (!gencache_init()) return;

	DEBUG(5, ("Searching cache keys with pattern %s\n", keystr_pattern));
	node = tdb_search_keys(cache, keystr_pattern);
	first_node = node;
	
	while (node) {
		/* ensure null termination of the key string */
		keystr = SMB_STRNDUP(node->node_key.dptr, node->node_key.dsize);
		
		/* 
		 * We don't use gencache_get function, because we need to iterate through
		 * all of the entries. Validity verification is up to fn routine.
		 */
		databuf = tdb_fetch(cache, node->node_key);
		if (!databuf.dptr || databuf.dsize <= TIMEOUT_LEN) {
			SAFE_FREE(databuf.dptr);
			SAFE_FREE(keystr);
			node = node->next;
			continue;
		}
		entry = SMB_STRNDUP(databuf.dptr, databuf.dsize);
		SAFE_FREE(databuf.dptr);
		valstr = SMB_MALLOC(databuf.dsize - TIMEOUT_LEN);
		sscanf(entry, CACHE_DATA_FMT, (int*)(&timeout), valstr);
		
		DEBUG(10, ("Calling function with arguments (key = %s, value = %s, timeout = %s)\n",
		           keystr, valstr, ctime(&timeout)));
		fn(keystr, valstr, timeout, data);
		
		SAFE_FREE(valstr);
		SAFE_FREE(entry);
		SAFE_FREE(keystr);
		node = node->next;
	}
	
	tdb_search_list_free(first_node);
}