⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 net_rpc.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (!secrets_store_domain_sid(domain_name, domain_sid)) {		DEBUG(0,("Can't store domain SID\n"));		return NT_STATUS_UNSUCCESSFUL;	}	return NT_STATUS_OK;}/**  * 'net rpc getsid' entrypoint. * @param argc  Standard main() style argc * @param argc  Standard main() style argv.  Initial components are already *              stripped **/int net_rpc_getsid(int argc, const char **argv) {	return run_rpc_command(NULL, PI_SAMR, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC, 			       rpc_getsid_internals,			       argc, argv);}/****************************************************************************//** * Basic usage function for 'net rpc user' * @param argc	Standard main() style argc. * @param argv	Standard main() style argv.  Initial components are already *		stripped. **/static int rpc_user_usage(int argc, const char **argv){	return net_help_user(argc, argv);}/**  * Add a new user to a remote RPC server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passes through.  * * @param domain_sid The domain sid acquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on completion of the function. * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return Normal NTSTATUS return. **/static NTSTATUS rpc_user_add_internals(const DOM_SID *domain_sid,				const char *domain_name, 				struct cli_state *cli,				struct rpc_pipe_client *pipe_hnd,				TALLOC_CTX *mem_ctx, 				int argc, const char **argv){		POLICY_HND connect_pol, domain_pol, user_pol;	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;	const char *acct_name;	uint16 acb_info;	uint32 unknown, user_rid;	if (argc != 1) {		d_printf("User must be specified\n");		rpc_user_usage(argc, argv);		return NT_STATUS_OK;	}	acct_name = argv[0];	/* Get sam policy handle */		result = rpccli_samr_connect(pipe_hnd, mem_ctx, MAXIMUM_ALLOWED_ACCESS, 				  &connect_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}		/* Get domain policy handle */		result = rpccli_samr_open_domain(pipe_hnd, mem_ctx, &connect_pol,				      MAXIMUM_ALLOWED_ACCESS,				      domain_sid, &domain_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Create domain user */	acb_info = ACB_NORMAL;	unknown = 0xe005000b; /* No idea what this is - a permission mask? */	result = rpccli_samr_create_dom_user(pipe_hnd, mem_ctx, &domain_pol,					  acct_name, acb_info, unknown,					  &user_pol, &user_rid);	if (!NT_STATUS_IS_OK(result)) {		goto done;	} done:	if (!NT_STATUS_IS_OK(result)) {		d_fprintf(stderr, "Failed to add user %s - %s\n", acct_name, 			 nt_errstr(result));	} else {		d_printf("Added user %s\n", acct_name);	}	return result;}/**  * Add a new user to a remote RPC server * * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return A shell status integer (0 for success) **/static int rpc_user_add(int argc, const char **argv) {	return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_add_internals,			       argc, argv);}/**  * Delete a user from a remote RPC server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passes through.  * * @param domain_sid The domain sid acquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on completion of the function. * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return Normal NTSTATUS return. **/static NTSTATUS rpc_user_del_internals(const DOM_SID *domain_sid, 					const char *domain_name, 					struct cli_state *cli, 					struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx, 					int argc,					const char **argv){	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;	POLICY_HND connect_pol, domain_pol, user_pol;	if (argc < 1) {		d_printf("User must be specified\n");		rpc_user_usage(argc, argv);		return NT_STATUS_OK;	}	/* Get sam policy and domain handles */	result = rpccli_samr_connect(pipe_hnd, mem_ctx, MAXIMUM_ALLOWED_ACCESS, 				  &connect_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	result = rpccli_samr_open_domain(pipe_hnd, mem_ctx, &connect_pol,				      MAXIMUM_ALLOWED_ACCESS,				      domain_sid, &domain_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Get handle on user */	{		uint32 *user_rids, num_rids, *name_types;		uint32 flags = 0x000003e8; /* Unknown */		result = rpccli_samr_lookup_names(pipe_hnd, mem_ctx, &domain_pol,					       flags, 1, &argv[0],					       &num_rids, &user_rids,					       &name_types);		if (!NT_STATUS_IS_OK(result)) {			goto done;		}		result = rpccli_samr_open_user(pipe_hnd, mem_ctx, &domain_pol,					    MAXIMUM_ALLOWED_ACCESS,					    user_rids[0], &user_pol);		if (!NT_STATUS_IS_OK(result)) {			goto done;		}	}	/* Delete user */	result = rpccli_samr_delete_dom_user(pipe_hnd, mem_ctx, &user_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Display results */	if (!NT_STATUS_IS_OK(result)) {		d_fprintf(stderr, "Failed to delete user account - %s\n", nt_errstr(result));	} else {		d_printf("Deleted user account\n");	} done:	return result;}/**  * Rename a user on a remote RPC server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passes through.  * * @param domain_sid The domain sid acquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on completion of the function. * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return Normal NTSTATUS return. **/static NTSTATUS rpc_user_rename_internals(const DOM_SID *domain_sid,					const char *domain_name, 					struct cli_state *cli,					struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx, 					int argc,					const char **argv){	POLICY_HND connect_pol, domain_pol, user_pol;	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;	uint32 info_level = 7;	const char *old_name, *new_name;	uint32 *user_rid;	uint32 flags = 0x000003e8; /* Unknown */	uint32 num_rids, *name_types;	uint32 num_names = 1;	const char **names;	SAM_USERINFO_CTR *user_ctr;	SAM_USERINFO_CTR ctr;	SAM_USER_INFO_7 info7;	if (argc != 2) {		d_printf("Old and new username must be specified\n");		rpc_user_usage(argc, argv);		return NT_STATUS_OK;	}	old_name = argv[0];	new_name = argv[1];	ZERO_STRUCT(ctr);	ZERO_STRUCT(user_ctr);	/* Get sam policy handle */		result = rpccli_samr_connect(pipe_hnd, mem_ctx, MAXIMUM_ALLOWED_ACCESS, 				  &connect_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}		/* Get domain policy handle */		result = rpccli_samr_open_domain(pipe_hnd, mem_ctx, &connect_pol,				      MAXIMUM_ALLOWED_ACCESS,				      domain_sid, &domain_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	names = TALLOC_ARRAY(mem_ctx, const char *, num_names);	names[0] = old_name;	result = rpccli_samr_lookup_names(pipe_hnd, mem_ctx, &domain_pol,				       flags, num_names, names,				       &num_rids, &user_rid, &name_types);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Open domain user */	result = rpccli_samr_open_user(pipe_hnd, mem_ctx, &domain_pol,				    MAXIMUM_ALLOWED_ACCESS, user_rid[0], &user_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Query user info */	result = rpccli_samr_query_userinfo(pipe_hnd, mem_ctx, &user_pol,					 info_level, &user_ctr);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	ctr.switch_value = info_level;	ctr.info.id7 = &info7;	init_sam_user_info7(&info7, new_name);	/* Set new name */	result = rpccli_samr_set_userinfo(pipe_hnd, mem_ctx, &user_pol,				       info_level, &cli->user_session_key, &ctr);	if (!NT_STATUS_IS_OK(result)) {		goto done;	} done:	if (!NT_STATUS_IS_OK(result)) {		d_fprintf(stderr, "Failed to rename user from %s to %s - %s\n", old_name, new_name, 			 nt_errstr(result));	} else {		d_printf("Renamed user from %s to %s\n", old_name, new_name);	}	return result;}/**  * Rename a user on a remote RPC server * * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return A shell status integer (0 for success) **/static int rpc_user_rename(int argc, const char **argv) {	return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_rename_internals,			       argc, argv);}/**  * Delete a user from a remote RPC server * * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return A shell status integer (0 for success) **/static int rpc_user_delete(int argc, const char **argv) {	return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_del_internals,			       argc, argv);}/**  * Set a password for a user on a remote RPC server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passes through.  * * @param domain_sid The domain sid acquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on completion of the function. * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return Normal NTSTATUS return. **/static NTSTATUS rpc_user_password_internals(const DOM_SID *domain_sid, 					const char *domain_name, 					struct cli_state *cli, 					struct rpc_pipe_client *pipe_hnd,					TALLOC_CTX *mem_ctx, 					int argc,					const char **argv){	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;	POLICY_HND connect_pol, domain_pol, user_pol;	SAM_USERINFO_CTR ctr;	SAM_USER_INFO_24 p24;	uchar pwbuf[516];	const char *user;	const char *new_password;	char *prompt = NULL;	if (argc < 1) {		d_printf("User must be specified\n");		rpc_user_usage(argc, argv);		return NT_STATUS_OK;	}		user = argv[0];	if (argv[1]) {		new_password = argv[1];	} else {		asprintf(&prompt, "Enter new password for %s:", user);		new_password = getpass(prompt);		SAFE_FREE(prompt);	}	/* Get sam policy and domain handles */	result = rpccli_samr_connect(pipe_hnd, mem_ctx, MAXIMUM_ALLOWED_ACCESS, 				  &connect_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	result = rpccli_samr_open_domain(pipe_hnd, mem_ctx, &connect_pol,				      MAXIMUM_ALLOWED_ACCESS,				      domain_sid, &domain_pol);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Get handle on user */	{		uint32 *user_rids, num_rids, *name_types;		uint32 flags = 0x000003e8; /* Unknown */		result = rpccli_samr_lookup_names(pipe_hnd, mem_ctx, &domain_pol,					       flags, 1, &user,					       &num_rids, &user_rids,					       &name_types);		if (!NT_STATUS_IS_OK(result)) {			goto done;		}		result = rpccli_samr_open_user(pipe_hnd, mem_ctx, &domain_pol,					    MAXIMUM_ALLOWED_ACCESS,					    user_rids[0], &user_pol);		if (!NT_STATUS_IS_OK(result)) {			goto done;		}	}	/* Set password on account */	ZERO_STRUCT(ctr);	ZERO_STRUCT(p24);	encode_pw_buffer(pwbuf, new_password, STR_UNICODE);	init_sam_user_info24(&p24, (char *)pwbuf,24);	ctr.switch_value = 24;	ctr.info.id24 = &p24;	result = rpccli_samr_set_userinfo(pipe_hnd, mem_ctx, &user_pol, 24, 				       &cli->user_session_key, &ctr);	if (!NT_STATUS_IS_OK(result)) {		goto done;	}	/* Display results */ done:	return result;}	/**  * Set a user's password on a remote RPC server * * @param argc  Standard main() style argc * @param argv  Standard main() style argv.  Initial components are already *              stripped * * @return A shell status integer (0 for success) **/static int rpc_user_password(int argc, const char **argv) {	return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_password_internals,			       argc, argv);}/**  * List user's groups on a remote RPC server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passes through. 

⌨️ 快捷键说明

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