Example #1
0
UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src)
{
	size_t len;

	if (!src) {
		return NULL;
	}

	len = strlen_w(src);
	
	/* allocate UNISTR2 destination if not given */
	if (!dst) {
		dst = TALLOC_P(ctx, UNISTR2);
		if (!dst)
			return NULL;
	}
	if (!dst->buffer) {
		dst->buffer = TALLOC_ARRAY(ctx, uint16, len + 1);
		if (!dst->buffer)
			return NULL;
	}
	
	/* set UNISTR2 parameters */
	dst->uni_max_len = len + 1;
	dst->offset = 0;
	dst->uni_str_len = len;
	
	/* copy the actual unicode string */
	strncpy_w(dst->buffer, src, dst->uni_max_len);
	
	return dst;
}
Example #2
0
void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
{
	uint32 len = buf ? strlen_w(buf) : 0;

	ZERO_STRUCTP(str);

	/* set up string lengths. */
	str->uni_max_len = len;
	str->offset = 0;
	str->uni_str_len = len;

	str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1);
	if (str->buffer == NULL) {
		smb_panic("init_unistr2_w: talloc fail\n");
		return;
	}
	
	/*
	 * don't move this test above ! The UNISTR2 must be initialized !!!
	 * jfm, 7/7/2001.
	 */
	if (buf==NULL)
		return;
	
	/* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
           long as the buffer above is talloc()ed correctly then this
           is the correct thing to do */
	strncpy_w(str->buffer, buf, len + 1);
}
Example #3
0
BOOL secrets_store_trusted_domain_password(const char* domain, smb_ucs2_t *uni_dom_name,
                                           size_t uni_name_len, const char* pwd,
                                           DOM_SID sid)
{	
	/* packing structures */
	pstring pass_buf;
	int pass_len = 0;
	int pass_buf_len = sizeof(pass_buf);
	
	struct trusted_dom_pass pass;
	ZERO_STRUCT(pass);
	
	/* unicode domain name and its length */
	if (!uni_dom_name)
		return False;
		
	strncpy_w(pass.uni_name, uni_dom_name, sizeof(pass.uni_name) - 1);
	pass.uni_name_len = uni_name_len;

	/* last change time */
	pass.mod_time = time(NULL);

	/* password of the trust */
	pass.pass_len = strlen(pwd);
	fstrcpy(pass.pass, pwd);

	/* domain sid */
	sid_copy(&pass.domain_sid, &sid);
	
	pass_len = tdb_trusted_dom_pass_pack(pass_buf, pass_buf_len, &pass);

	return secrets_store(trustdom_keystr(domain), (void *)&pass_buf, pass_len);
}
Example #4
0
bool secrets_store_trusted_domain_password(const char* domain, const char* pwd,
                                           const DOM_SID *sid)
{
	smb_ucs2_t *uni_dom_name;
	bool ret;

	/* packing structures */
	uint8 *pass_buf = NULL;
	int pass_len = 0;

	struct trusted_dom_pass pass;
	ZERO_STRUCT(pass);

	if (push_ucs2_allocate(&uni_dom_name, domain) == (size_t)-1) {
		DEBUG(0, ("Could not convert domain name %s to unicode\n",
			  domain));
		return False;
	}

	strncpy_w(pass.uni_name, uni_dom_name, sizeof(pass.uni_name) - 1);
	pass.uni_name_len = strlen_w(uni_dom_name)+1;
	SAFE_FREE(uni_dom_name);

	/* last change time */
	pass.mod_time = time(NULL);

	/* password of the trust */
	pass.pass_len = strlen(pwd);
	fstrcpy(pass.pass, pwd);

	/* domain sid */
	sid_copy(&pass.domain_sid, sid);

	/* Calculate the length. */
	pass_len = tdb_trusted_dom_pass_pack(NULL, 0, &pass);
	pass_buf = SMB_MALLOC_ARRAY(uint8, pass_len);
	if (!pass_buf) {
		return false;
	}
	pass_len = tdb_trusted_dom_pass_pack(pass_buf, pass_len, &pass);
	ret = secrets_store(trustdom_keystr(domain), (void *)pass_buf,
			pass_len);
	SAFE_FREE(pass_buf);
	return ret;
}