cli_reg.c

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

C
732
字号
	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_get_key_sec(&in, hnd, sec_info, *sec_buf_size, sec_buf);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_GET_KEY_SEC, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_get_key_sec,	            reg_io_r_get_key_sec, 	            WERR_GENERAL_FAILURE );		    	/* this might be able to return WERR_MORE_DATA, I'm not sure */		if ( !W_ERROR_IS_OK( out.status ) )		return out.status;		sec_buf       = out.data;	*sec_buf_size = out.data->len;			return out.status;	}/****************************************************************************do a REG Delete Value****************************************************************************/WERROR rpccli_reg_delete_val(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                            POLICY_HND *hnd, char *val_name){	REG_Q_DELETE_VALUE in;	REG_R_DELETE_VALUE out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_delete_val(&in, hnd, val_name);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_DELETE_VALUE, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_delete_value,	            reg_io_r_delete_value, 	            WERR_GENERAL_FAILURE );		return out.status;}/****************************************************************************do a REG Delete Key****************************************************************************/WERROR rpccli_reg_delete_key(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                            POLICY_HND *hnd, char *key_name){	REG_Q_DELETE_KEY in;	REG_R_DELETE_KEY out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_delete_key(&in, hnd, key_name);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_DELETE_KEY, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_delete_key,	            reg_io_r_delete_key, 	            WERR_GENERAL_FAILURE );		return out.status;}/****************************************************************************do a REG Create Key****************************************************************************/WERROR rpccli_reg_create_key_ex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                            POLICY_HND *hnd, char *key_name, char *key_class,                            uint32 access_desired, POLICY_HND *key){	REG_Q_CREATE_KEY_EX in;	REG_R_CREATE_KEY_EX out;	prs_struct qbuf, rbuf;	SEC_DESC *sec;	SEC_DESC_BUF *sec_buf;	size_t sec_len;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		if ( !(sec = make_sec_desc(mem_ctx, 1, SEC_DESC_SELF_RELATIVE,		NULL, NULL, NULL, NULL, &sec_len)) ) {		return WERR_GENERAL_FAILURE;	}				 	if ( !(sec_buf = make_sec_desc_buf(mem_ctx, sec_len, sec)) )		return WERR_GENERAL_FAILURE;	init_reg_q_create_key_ex(&in, hnd, key_name, key_class, access_desired, sec_buf);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_CREATE_KEY_EX, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_create_key_ex,	            reg_io_r_create_key_ex, 	            WERR_GENERAL_FAILURE );		    	if ( !W_ERROR_IS_OK( out.status ) )		return out.status;		memcpy( key, &out.handle, sizeof(POLICY_HND) );		return out.status;}/****************************************************************************do a REG Enum Key****************************************************************************/WERROR rpccli_reg_enum_key(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                          POLICY_HND *hnd, int key_index, fstring key_name,                          fstring class_name, time_t *mod_time){	REG_Q_ENUM_KEY in;	REG_R_ENUM_KEY out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_enum_key(&in, hnd, key_index);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_ENUM_KEY, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_enum_key,	            reg_io_r_enum_key, 	            WERR_GENERAL_FAILURE );	if ( !W_ERROR_IS_OK(out.status) )		return out.status;	if ( out.keyname.string )		rpcstr_pull( key_name, out.keyname.string->buffer, sizeof(fstring), -1, STR_TERMINATE );	else		fstrcpy( key_name, "(Default)" );	if ( out.classname && out.classname->string )		rpcstr_pull( class_name, out.classname->string->buffer, sizeof(fstring), -1, STR_TERMINATE );	else		fstrcpy( class_name, "" );	*mod_time   = nt_time_to_unix(out.time);	return out.status;}/****************************************************************************do a REG Create Value****************************************************************************/WERROR rpccli_reg_set_val(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                            POLICY_HND *hnd, char *val_name, uint32 type,                            RPC_DATA_BLOB *data){	REG_Q_SET_VALUE in;	REG_R_SET_VALUE out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_set_val(&in, hnd, val_name, type, data);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_SET_VALUE, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_set_value,	            reg_io_r_set_value, 	            WERR_GENERAL_FAILURE );	return out.status;}/****************************************************************************do a REG Enum Value****************************************************************************/WERROR rpccli_reg_enum_val(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                          POLICY_HND *hnd, int idx,                          fstring val_name, uint32 *type, REGVAL_BUFFER *value){	REG_Q_ENUM_VALUE in;	REG_R_ENUM_VALUE out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_enum_val(&in, hnd, idx, 0x0100, 0x1000);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_ENUM_VALUE, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_enum_val,	            reg_io_r_enum_val, 	            WERR_GENERAL_FAILURE );	if ( W_ERROR_EQUAL(out.status, WERR_MORE_DATA) ) {		ZERO_STRUCT (in);		init_reg_q_enum_val(&in, hnd, idx, 0x0100, *out.buffer_len1);		ZERO_STRUCT (out);		CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_ENUM_VALUE, 		            in, out, 		            qbuf, rbuf,		            reg_io_q_enum_val,		            reg_io_r_enum_val, 		            WERR_GENERAL_FAILURE );	}	if ( !W_ERROR_IS_OK(out.status) )		return out.status;	unistr2_to_ascii(val_name, out.name.string, sizeof(fstring)-1);	*type      = *out.type;	*value     = *out.value;		return out.status;}/********************************************************************************************************************************************************/WERROR rpccli_reg_open_entry(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                            POLICY_HND *hnd, char *key_name,                            uint32 access_desired, POLICY_HND *key_hnd){	REG_Q_OPEN_ENTRY in;	REG_R_OPEN_ENTRY out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_open_entry(&in, hnd, key_name, access_desired);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_OPEN_ENTRY, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_open_entry,	            reg_io_r_open_entry, 	            WERR_GENERAL_FAILURE );	if ( !W_ERROR_IS_OK( out.status ) )		return out.status;	memcpy( key_hnd, &out.handle, sizeof(POLICY_HND) );		return out.status;}/********************************************************************************************************************************************************/WERROR rpccli_reg_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                       POLICY_HND *hnd){	REG_Q_CLOSE in;	REG_R_CLOSE out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_close(&in, hnd);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_CLOSE, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_close,	            reg_io_r_close, 	            WERR_GENERAL_FAILURE );		return out.status;}/****************************************************************************do a REG Query Info****************************************************************************/WERROR rpccli_reg_save_key(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                         POLICY_HND *hnd, const char *filename ){	REG_Q_SAVE_KEY in;	REG_R_SAVE_KEY out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_q_reg_save_key( &in, hnd, filename );	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_SAVE_KEY, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_save_key,	            reg_io_r_save_key,	            WERR_GENERAL_FAILURE );	return out.status;}/*  #################################################################  Utility functions ################################################################# *//***************************************************************** Splits out the start of the key (HKLM or HKU) and the rest of the key.*****************************************************************/  BOOL reg_split_hive(const char *full_keyname, uint32 *reg_type, pstring key_name){	pstring tmp;	if (!next_token(&full_keyname, tmp, "\\", sizeof(tmp)))		return False;	(*reg_type) = 0;	DEBUG(10, ("reg_split_key: hive %s\n", tmp));	if (strequal(tmp, "HKLM") || strequal(tmp, "HKEY_LOCAL_MACHINE"))		(*reg_type) = HKEY_LOCAL_MACHINE;	else if (strequal(tmp, "HKCR") || strequal(tmp, "HKEY_CLASSES_ROOT"))		(*reg_type) = HKEY_CLASSES_ROOT;	else if (strequal(tmp, "HKU") || strequal(tmp, "HKEY_USERS"))		(*reg_type) = HKEY_USERS;	else if (strequal(tmp, "HKPD")||strequal(tmp, "HKEY_PERFORMANCE_DATA"))		(*reg_type) = HKEY_PERFORMANCE_DATA;	else {		DEBUG(10,("reg_split_key: unrecognised hive key %s\n", tmp));		return False;	}		if (next_token(&full_keyname, tmp, "\n\r", sizeof(tmp)))		pstrcpy(key_name, tmp);	else		key_name[0] = 0;	DEBUG(10, ("reg_split_key: name %s\n", key_name));	return True;}

⌨️ 快捷键说明

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