parse_misc.c

来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,878 行 · 第 1/4 页

C
1,878
字号
	/* the destination UNISTR2 should never be NULL.	   if it is it is a programming error */	/* if the source UNISTR is NULL, then zero out	   the destination string and return */	ZERO_STRUCTP (to);	if ((from == NULL) || (from->buffer == NULL))		return;	/* get the length; UNISTR must be NULL terminated */	i = 0;	while ((from->buffer)[i]!='\0')		i++;	i++;	/* one more to catch the terminating NULL */		/* is this necessary -- jerry?  I need to think */	/* set up string lengths; uni_max_len is set to i+1           because we need to account for the final NULL termination */	to->uni_max_len = i;	to->offset = 0;	to->uni_str_len = i;	/* allocate the space and copy the string buffer */	to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);	if (to->buffer == NULL)		smb_panic("init_unistr2_from_unistr: malloc fail\n");	memcpy(to->buffer, from->buffer, i*sizeof(uint16));	return;}/*******************************************************************  Inits a UNISTR2 structure from a DATA_BLOB.  The length of the data_blob must count the bytes of the buffer.  Copies the blob data.********************************************************************/void init_unistr2_from_datablob(UNISTR2 *str, DATA_BLOB *blob) {	/* Allocs the unistring */	init_unistr2(str, NULL, UNI_FLAGS_NONE);		/* Sets the values */	str->uni_str_len = blob->length / sizeof(uint16);	str->uni_max_len = str->uni_str_len;	str->offset = 0;	if (blob->length) {		str->buffer = (uint16 *) memdup(blob->data, blob->length);	} else {		str->buffer = NULL;	}	if ((str->buffer == NULL) && (blob->length > 0)) {		smb_panic("init_unistr2_from_datablob: malloc fail\n");	}}/******************************************************************* UNISTR2* are a little different in that the pointer and the UNISTR2 are not necessarily read/written back to back.  So we break it up  into 2 separate functions. See SPOOL_USER_1 in include/rpc_spoolss.h for an example.********************************************************************/BOOL prs_io_unistr2_p(const char *desc, prs_struct *ps, int depth, UNISTR2 **uni2){	uint32 data_p;	/* caputure the pointer value to stream */	data_p = *uni2 ? 0xf000baaa : 0;	if ( !prs_uint32("ptr", ps, depth, &data_p ))		return False;	/* we're done if there is no data */	if ( !data_p )		return True;	if (UNMARSHALLING(ps)) {		if ( !(*uni2 = PRS_ALLOC_MEM(ps, UNISTR2, 1)) )			return False;	}	return True;}/******************************************************************* now read/write the actual UNISTR2.  Memory for the UNISTR2 (but not UNISTR2.buffer) has been allocated previously by prs_unistr2_p()********************************************************************/BOOL prs_io_unistr2(const char *desc, prs_struct *ps, int depth, UNISTR2 *uni2 ){	/* just return true if there is no pointer to deal with.	   the memory must have been previously allocated on unmarshalling	   by prs_unistr2_p() */	if ( !uni2 )		return True;	/* just pass off to smb_io_unstr2() passing the uni2 address as 	   the pointer (like you would expect) */	return smb_io_unistr2( desc, uni2, uni2 ? 1 : 0, ps, depth );}/******************************************************************* Reads or writes a UNISTR2 structure. XXXX NOTE: UNISTR2 structures need NOT be null-terminated.   the uni_str_len member tells you how long the string is;   the uni_max_len member tells you how large the buffer is.********************************************************************/BOOL smb_io_unistr2(const char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth){	if (uni2 == NULL)		return False;	if (buffer) {		prs_debug(ps, depth, desc, "smb_io_unistr2");		depth++;		if(!prs_align(ps))			return False;				if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len))			return False;		if(!prs_uint32("offset     ", ps, depth, &uni2->offset))			return False;		if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len))			return False;		/* buffer advanced by indicated length of string		   NOT by searching for null-termination */		if(!prs_unistr2(True, "buffer     ", ps, depth, uni2))			return False;	} else {		prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");		depth++;		memset((char *)uni2, '\0', sizeof(*uni2));	}	return True;}/******************************************************************* now read/write UNISTR4********************************************************************/BOOL prs_unistr4(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4){	prs_debug(ps, depth, desc, "prs_unistr4");	depth++;	if ( !prs_uint16("length", ps, depth, &uni4->length ))		return False;	if ( !prs_uint16("size", ps, depth, &uni4->size ))		return False;			if ( !prs_pointer( desc, ps, depth, (void**)&uni4->string, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )		return False;			return True;}/******************************************************************* now read/write UNISTR4 header********************************************************************/BOOL prs_unistr4_hdr(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4){	prs_debug(ps, depth, desc, "prs_unistr4_hdr");	depth++;	if ( !prs_uint16("length", ps, depth, &uni4->length) )		return False;	if ( !prs_uint16("size", ps, depth, &uni4->size) )		return False;	if ( !prs_io_unistr2_p(desc, ps, depth, &uni4->string) )		return False;			return True;}/******************************************************************* now read/write UNISTR4 string********************************************************************/BOOL prs_unistr4_str(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4){	prs_debug(ps, depth, desc, "prs_unistr4_str");	depth++;	if ( !prs_io_unistr2(desc, ps, depth, uni4->string) )		return False;			return True;}/******************************************************************* Reads or writes a UNISTR4_ARRAY structure.********************************************************************/BOOL prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRAY *array ){	unsigned int i;	prs_debug(ps, depth, desc, "prs_unistr4_array");	depth++;	if(!prs_uint32("count", ps, depth, &array->count))		return False;	if ( array->count == 0 ) 		return True;		if (UNMARSHALLING(ps)) {		if ( !(array->strings = TALLOC_ZERO_ARRAY( get_talloc_ctx(), UNISTR4, array->count)) )			return False;	}		/* write the headers and then the actual string buffer */		for ( i=0; i<array->count; i++ ) {		if ( !prs_unistr4_hdr( "string", ps, depth, &array->strings[i]) )			return False;	}	for (i=0;i<array->count;i++) {		if ( !prs_unistr4_str("string", ps, depth, &array->strings[i]) ) 			return False;	}		return True;}/********************************************************************  initialise a UNISTR_ARRAY from a char**********************************************************************/BOOL init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **strings ){	unsigned int i;	array->count = count;	if ( array->count == 0 )		return True;	/* allocate memory for the array of UNISTR4 objects */	if ( !(array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR4, count )) )		return False;	for ( i=0; i<count; i++ ) 		init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE );	return True;}BOOL smb_io_lockout_string_hdr(const char *desc, HDR_LOCKOUT_STRING *hdr_account_lockout, prs_struct *ps, int depth){	prs_debug(ps, depth, desc, "smb_io_lockout_string_hdr");	depth++;	if(!prs_align(ps))		return False;	if(!prs_uint16("size", ps, depth, &hdr_account_lockout->size))		return False;	if(!prs_uint16("length", ps, depth, &hdr_account_lockout->length))		return False;	if(!prs_uint32("buffer", ps, depth, &hdr_account_lockout->buffer))		return False;	return True;}BOOL smb_io_account_lockout_str(const char *desc, LOCKOUT_STRING *account_lockout, uint32 buffer, prs_struct *ps, int depth){	prs_debug(ps, depth, desc, "smb_io_account_lockout_string");	depth++;	if(!prs_uint32("array_size", ps, depth, &account_lockout->array_size))		return False;	if(!prs_uint32("offset", ps, depth, &account_lockout->offset))		return False;	if(!prs_uint32("length", ps, depth, &account_lockout->length))		return False;	if (!prs_uint64("lockout_duration", ps, depth, &account_lockout->lockout_duration))		return False;	if (!prs_uint64("reset_count", ps, depth, &account_lockout->reset_count))		return False;	if (!prs_uint32("bad_attempt_lockout", ps, depth, &account_lockout->bad_attempt_lockout))		return False;	if (!prs_uint32("dummy", ps, depth, &account_lockout->dummy))		return False;#if 0	if(!prs_uint16s (False, "bindata", ps, depth, &account_lockout->bindata, length))		return False;#endif	return True;}/******************************************************************* Inits a DOM_RID2 structure.********************************************************************/void init_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type, uint32 idx){	rid2->type    = type;	rid2->rid     = rid;	rid2->rid_idx = idx;}/******************************************************************* Reads or writes a DOM_RID2 structure.********************************************************************/BOOL smb_io_dom_rid2(const char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth){	if (rid2 == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_dom_rid2");	depth++;	if(!prs_align(ps))		return False;   	if(!prs_uint8("type   ", ps, depth, &rid2->type))		return False;	if(!prs_align(ps))		return False;	if(!prs_uint32("rid    ", ps, depth, &rid2->rid))		return False;	if(!prs_uint32("rid_idx", ps, depth, &rid2->rid_idx))		return False;	return True;}/*******************************************************************creates a DOM_RID3 structure.********************************************************************/void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type){    rid3->rid      = rid;    rid3->type1    = type;    rid3->ptr_type = 0x1; /* non-zero, basically. */    rid3->type2    = 0x1;    rid3->unk      = type;}/*******************************************************************reads or writes a DOM_RID3 structure.********************************************************************/BOOL smb_io_dom_rid3(const char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth){	if (rid3 == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_dom_rid3");	depth++;	if(!prs_align(ps))		return False;	if(!prs_uint32("rid     ", ps, depth, &rid3->rid))		return False;	if(!prs_uint32("type1   ", ps, depth, &rid3->type1))		return False;	if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type))		return False;	if(!prs_uint32("type2   ", ps, depth, &rid3->type2))		return False;	if(!prs_uint32("unk     ", ps, depth, &rid3->unk))		return False;	return True;}/******************************************************************* Inits a DOM_RID4 structure.********************************************************************/void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid){    rid4->unknown = unknown;    rid4->attr    = attr;    rid4->rid     = rid;}/******************************************************************* Inits a DOM_CLNT_SRV structure.********************************************************************/static void init_clnt_srv(DOM_CLNT_SRV *logcln, const char *logon_srv, const char *comp_name){	DEBUG(5,("init_clnt_srv: %d\n", __LINE__));	if (logon_srv != NULL) {		logcln->undoc_buffer = 1;		init_unistr2(&logcln->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);	} else {		logcln->undoc_buffer = 0;	}	if (comp_name != NULL) {		logcln->undoc_buffer2 = 1;		init_unistr2(&logcln->uni_comp_name, comp_name, UNI_STR_TERMINATE);	} else {		logcln->undoc_buffer2 = 0;	}}/******************************************************************* Inits or writes a DOM_CLNT_SRV structure.********************************************************************/static BOOL smb_io_clnt_srv(const char *desc, DOM_CLNT_SRV *logcln, prs_struct *ps, int depth){	if (logcln == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_clnt_srv");	depth++;	if(!prs_align(ps))		return False;		if(!prs_uint32("undoc_buffer ", ps, depth, &logcln->undoc_buffer))		return False;	if (logcln->undoc_buffer != 0) {		if(!smb_io_unistr2("unistr2", &logcln->uni_logon_srv, logcln->undoc_buffer, ps, depth))			return False;	}	if(!prs_align(ps))		return False;	if(!prs_uint32("undoc_buffer2", ps, depth, &logcln->undoc_buffer2))		return False;	if (logcln->undoc_buffer2 != 0) {		if(!smb_io_unistr2("unistr2", &logcln->uni_comp_name, logcln->undoc_buffer2, ps, depth))			return False;	}	return True;}/******************************************************************* Inits a DOM_LOG_INFO structure.********************************************************************/void init_log_info(DOM_LOG_INFO *loginfo, const char *logon_srv, const char *acct_name,		uint16 sec_chan, const char *comp_name){

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?