cli_reg.c

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

C
732
字号
/*    Unix SMB/CIFS implementation.   RPC Pipe client    Copyright (C) Andrew Tridgell              1992-2000,   Copyright (C) Jeremy Allison                    1999 - 2005   Copyright (C) Simo Sorce                        2001   Copyright (C) Jeremy Cooper                     2004   Copyright (C) Gerald (Jerry) Carter             2005      This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "includes.h"#include "rpc_client.h"/* Shutdown a server *//******************************************************************* internal connect to a registry hive root (open a registry policy)*******************************************************************/static WERROR rpccli_reg_open_hive_int(struct rpc_pipe_client *cli,                                      TALLOC_CTX *mem_ctx, uint16 op_code,                                      const char *op_name,                                      uint32 access_mask, POLICY_HND *hnd){	REG_Q_OPEN_HIVE in;	REG_R_OPEN_HIVE out;	prs_struct qbuf, rbuf;	ZERO_STRUCT(in);	ZERO_STRUCT(out);	init_reg_q_open_hive(&in, access_mask);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, op_code, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_open_hive,	            reg_io_r_open_hive, 	            WERR_GENERAL_FAILURE );	if ( !W_ERROR_IS_OK( out.status ) )		return out.status;	memcpy( hnd, &out.pol, sizeof(POLICY_HND) );	return out.status;}/******************************************************************* connect to a registry hive root (open a registry policy)*******************************************************************/WERROR rpccli_reg_connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                         uint32 reg_type, uint32 access_mask,                         POLICY_HND *reg_hnd){	uint16 op_code;	const char *op_name;	ZERO_STRUCTP(reg_hnd);	switch (reg_type)	{	case HKEY_CLASSES_ROOT:		op_code = REG_OPEN_HKCR;		op_name = "REG_OPEN_HKCR";		break;	case HKEY_LOCAL_MACHINE:		op_code = REG_OPEN_HKLM;		op_name = "REG_OPEN_HKLM";		break;	case HKEY_USERS:		op_code = REG_OPEN_HKU;		op_name = "REG_OPEN_HKU";		break;	case HKEY_PERFORMANCE_DATA:		op_code = REG_OPEN_HKPD;		op_name = "REG_OPEN_HKPD";		break;	default:		return WERR_INVALID_PARAM;	}	return rpccli_reg_open_hive_int(cli, mem_ctx, op_code, op_name,                                     access_mask, reg_hnd);}/**************************************************************************************************************************************/WERROR rpccli_reg_shutdown(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                          const char *msg, uint32 timeout, BOOL do_reboot,			  BOOL force){	REG_Q_SHUTDOWN in;	REG_R_SHUTDOWN out;	prs_struct qbuf, rbuf;	if (msg == NULL) 		return WERR_INVALID_PARAM;	ZERO_STRUCT (in);	ZERO_STRUCT (out);	/* Marshall data and send request */	init_reg_q_shutdown(&in, msg, timeout, do_reboot, force);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_SHUTDOWN, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_shutdown,	            reg_io_r_shutdown, 	            WERR_GENERAL_FAILURE );	return out.status;}/**************************************************************************************************************************************/WERROR rpccli_reg_abort_shutdown(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx){	REG_Q_ABORT_SHUTDOWN in;	REG_R_ABORT_SHUTDOWN out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_ABORT_SHUTDOWN, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_abort_shutdown,	            reg_io_r_abort_shutdown, 	            WERR_GENERAL_FAILURE );	return out.status;	}/****************************************************************************do a REG Unknown 0xB command.  sent after a create key or create value.this might be some sort of "sync" or "refresh" command, sent aftermodification of the registry...****************************************************************************/WERROR rpccli_reg_flush_key(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                           POLICY_HND *hnd){	REG_Q_FLUSH_KEY in;	REG_R_FLUSH_KEY out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_flush_key(&in, hnd);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_FLUSH_KEY, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_flush_key,	            reg_io_r_flush_key, 	            WERR_GENERAL_FAILURE );		    	return out.status;}/****************************************************************************do a REG Query Key****************************************************************************/WERROR rpccli_reg_query_key(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                           POLICY_HND *hnd,                           char *key_class, uint32 *class_len,                           uint32 *num_subkeys, uint32 *max_subkeylen,                           uint32 *max_classlen, uint32 *num_values,                           uint32 *max_valnamelen, uint32 *max_valbufsize,                           uint32 *sec_desc, NTTIME *mod_time){	REG_Q_QUERY_KEY in;	REG_R_QUERY_KEY out;	prs_struct qbuf, rbuf;	uint32 saved_class_len = *class_len;	ZERO_STRUCT (in);	ZERO_STRUCT (out);	init_reg_q_query_key( &in, hnd, key_class );	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_QUERY_KEY, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_query_key,	            reg_io_r_query_key, 	            WERR_GENERAL_FAILURE );	if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {		ZERO_STRUCT (in);		*class_len = out.key_class.string->uni_max_len;		if ( *class_len > saved_class_len )			return out.status;					/* set a string of spaces and NULL terminate */		memset( key_class, (int)' ', *class_len );		key_class[*class_len] = '\0';				init_reg_q_query_key( &in, hnd, key_class );		ZERO_STRUCT (out);		CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_QUERY_KEY, 		            in, out, 		            qbuf, rbuf,		            reg_io_q_query_key,		            reg_io_r_query_key, 		            WERR_GENERAL_FAILURE );	}		if ( !W_ERROR_IS_OK( out.status ) )		return out.status;	*class_len      = out.key_class.string->uni_max_len;	unistr2_to_ascii(key_class, out.key_class.string, saved_class_len-1);	*num_subkeys    = out.num_subkeys   ;	*max_subkeylen  = out.max_subkeylen ;	*num_values     = out.num_values    ;	*max_valnamelen = out.max_valnamelen;	*max_valbufsize = out.max_valbufsize;	*sec_desc       = out.sec_desc      ;	*mod_time       = out.mod_time      ;	/* Maybe: *max_classlen = out.reserved; */	return out.status;}/********************************************************************************************************************************************************/WERROR rpccli_reg_getversion(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                            POLICY_HND *hnd, uint32 *version){	REG_Q_GETVERSION in;	REG_R_GETVERSION out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_getversion(&in, hnd);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_GETVERSION, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_getversion,	            reg_io_r_getversion, 	            WERR_GENERAL_FAILURE );		    	if ( !W_ERROR_IS_OK( out.status ) )		return out.status;			*version = out.win_version;	return out.status;}/****************************************************************************do a REG Query Info****************************************************************************/WERROR rpccli_reg_query_value(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                           POLICY_HND *hnd, const char *val_name,                           uint32 *type, REGVAL_BUFFER *buffer){	REG_Q_QUERY_VALUE in;	REG_R_QUERY_VALUE out;	prs_struct qbuf, rbuf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		init_reg_q_query_value(&in, hnd, val_name, buffer);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_QUERY_VALUE, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_query_value,	            reg_io_r_query_value, 	            WERR_GENERAL_FAILURE );		    	if ( !W_ERROR_IS_OK( out.status ) )		return out.status;			*type   = *out.type;	*buffer = *out.value;	return out.status;}/****************************************************************************do a REG Set Key Security ****************************************************************************/WERROR rpccli_reg_set_key_sec(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                             POLICY_HND *hnd, uint32 sec_info,                             size_t secdesc_size, SEC_DESC *sec_desc){	REG_Q_SET_KEY_SEC in;	REG_R_SET_KEY_SEC out;	prs_struct qbuf, rbuf;	SEC_DESC_BUF *sec_desc_buf;	ZERO_STRUCT (in);	ZERO_STRUCT (out);		/* Flatten the security descriptor */		if ( !(sec_desc_buf = make_sec_desc_buf(mem_ctx, secdesc_size, sec_desc)) )		return WERR_GENERAL_FAILURE;			init_reg_q_set_key_sec(&in, hnd, sec_info, sec_desc_buf);	CLI_DO_RPC_WERR( cli, mem_ctx, PI_WINREG, REG_SET_KEY_SEC, 	            in, out, 	            qbuf, rbuf,	            reg_io_q_set_key_sec,	            reg_io_r_set_key_sec, 	            WERR_GENERAL_FAILURE );		    	return out.status;}/****************************************************************************do a REG Query Key Security ****************************************************************************/WERROR rpccli_reg_get_key_sec(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,                             POLICY_HND *hnd, uint32 sec_info,                             uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf){	REG_Q_GET_KEY_SEC in;	REG_R_GET_KEY_SEC out;	prs_struct qbuf, rbuf;

⌨️ 快捷键说明

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