drsuapi.c

来自「samba最新软件」· C语言 代码 · 共 784 行 · 第 1/2 页

C
784
字号
	ZERO_STRUCT(null_guid);	ZERO_STRUCT(null_sid);	r.in.bind_handle	= &priv->bind_handle;	for (i=0; i < ARRAY_SIZE(array); i++) {		printf("testing DsReplicaSync level %d\n",			array[i].level);		r.in.level = array[i].level;		switch(r.in.level) {		case 1:			nc.guid					= null_guid;			nc.sid					= null_sid;			nc.dn					= priv->domain_obj_dn?priv->domain_obj_dn:"";			r.in.req.req1.naming_context		= &nc;			r.in.req.req1.source_dsa_guid		= priv->dcinfo.ntds_guid;			r.in.req.req1.other_info		= NULL;			r.in.req.req1.options			= 16;			break;		}		status = dcerpc_drsuapi_DsReplicaSync(p, tctx, &r);		if (!NT_STATUS_IS_OK(status)) {			const char *errstr = nt_errstr(status);			if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {				errstr = dcerpc_errstr(tctx, p->last_fault_code);			}			printf("dcerpc_drsuapi_DsReplicaSync failed - %s\n", errstr);			ret = false;		} else if (!W_ERROR_IS_OK(r.out.result)) {			printf("DsReplicaSync failed - %s\n", win_errstr(r.out.result));			ret = false;		}	}	return ret;}static bool test_DsReplicaUpdateRefs(struct dcerpc_pipe *p, struct torture_context *tctx,			struct DsPrivate *priv){	NTSTATUS status;	bool ret = true;	int i;	struct drsuapi_DsReplicaUpdateRefs r;	struct drsuapi_DsReplicaObjectIdentifier nc;	struct GUID null_guid;	struct dom_sid null_sid;	struct {		int32_t level;	} array[] = {		{				1		}	};	if (torture_setting_bool(tctx, "samba4", false)) {		printf("skipping DsReplicaUpdateRefs test against Samba4\n");		return true;	}	ZERO_STRUCT(null_guid);	ZERO_STRUCT(null_sid);	r.in.bind_handle	= &priv->bind_handle;	for (i=0; i < ARRAY_SIZE(array); i++) {		printf("testing DsReplicaUpdateRefs level %d\n",			array[i].level);		r.in.level = array[i].level;		switch(r.in.level) {		case 1:			nc.guid				= null_guid;			nc.sid				= null_sid;			nc.dn				= priv->domain_obj_dn?priv->domain_obj_dn:"";			r.in.req.req1.naming_context	= &nc;			r.in.req.req1.dest_dsa_dns_name	= talloc_asprintf(tctx, "__some_dest_dsa_guid_string._msdn.%s",										priv->domain_dns_name);			r.in.req.req1.dest_dsa_guid	= null_guid;			r.in.req.req1.options		= 0;			break;		}		status = dcerpc_drsuapi_DsReplicaUpdateRefs(p, tctx, &r);		if (!NT_STATUS_IS_OK(status)) {			const char *errstr = nt_errstr(status);			if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {				errstr = dcerpc_errstr(tctx, p->last_fault_code);			}			printf("dcerpc_drsuapi_DsReplicaUpdateRefs failed - %s\n", errstr);			ret = false;		} else if (!W_ERROR_IS_OK(r.out.result)) {			printf("DsReplicaUpdateRefs failed - %s\n", win_errstr(r.out.result));			ret = false;		}	}	return ret;}static bool test_DsGetNCChanges(struct dcerpc_pipe *p, struct torture_context *tctx, 			struct DsPrivate *priv){	NTSTATUS status;	bool ret = true;	int i;	struct drsuapi_DsGetNCChanges r;	struct drsuapi_DsReplicaObjectIdentifier nc;	struct GUID null_guid;	struct dom_sid null_sid;	struct {		int32_t level;	} array[] = {		{				5		},		{				8		}	};	if (torture_setting_bool(tctx, "samba4", false)) {		printf("skipping DsGetNCChanges test against Samba4\n");		return true;	}	ZERO_STRUCT(null_guid);	ZERO_STRUCT(null_sid);	for (i=0; i < ARRAY_SIZE(array); i++) {		printf("testing DsGetNCChanges level %d\n",			array[i].level);		r.in.bind_handle	= &priv->bind_handle;		r.in.level		= &array[i].level;		switch (*r.in.level) {		case 5:			nc.guid	= null_guid;			nc.sid	= null_sid;			nc.dn	= priv->domain_obj_dn?priv->domain_obj_dn:"";			r.in.req.req5.destination_dsa_guid		= GUID_random();			r.in.req.req5.source_dsa_invocation_id		= null_guid;			r.in.req.req5.naming_context			= &nc;			r.in.req.req5.highwatermark.tmp_highest_usn	= 0;			r.in.req.req5.highwatermark.reserved_usn	= 0;			r.in.req.req5.highwatermark.highest_usn		= 0;			r.in.req.req5.uptodateness_vector		= NULL;			r.in.req.req5.replica_flags			= 0;			if (lp_parm_bool(tctx->lp_ctx, NULL, "drsuapi","compression", false)) {				r.in.req.req5.replica_flags		|= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;			}			r.in.req.req5.max_object_count			= 0;			r.in.req.req5.max_ndr_size			= 0;			r.in.req.req5.unknown4				= 0;			r.in.req.req5.h1				= 0;			break;		case 8:			nc.guid	= null_guid;			nc.sid	= null_sid;			nc.dn	= priv->domain_obj_dn?priv->domain_obj_dn:"";			r.in.req.req8.destination_dsa_guid		= GUID_random();			r.in.req.req8.source_dsa_invocation_id		= null_guid;			r.in.req.req8.naming_context			= &nc;			r.in.req.req8.highwatermark.tmp_highest_usn	= 0;			r.in.req.req8.highwatermark.reserved_usn	= 0;			r.in.req.req8.highwatermark.highest_usn		= 0;			r.in.req.req8.uptodateness_vector		= NULL;			r.in.req.req8.replica_flags			= 0;			if (lp_parm_bool(tctx->lp_ctx, NULL, "drsuapi", "compression", false)) {				r.in.req.req8.replica_flags		|= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;			}			if (lp_parm_bool(tctx->lp_ctx, NULL, "drsuapi", "neighbour_writeable", true)) {				r.in.req.req8.replica_flags		|= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;			}			r.in.req.req8.replica_flags			|= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP									| DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS									| DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS									| DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED									;			r.in.req.req8.max_object_count			= 402;			r.in.req.req8.max_ndr_size			= 402116;			r.in.req.req8.unknown4				= 0;			r.in.req.req8.h1				= 0;			r.in.req.req8.unique_ptr1			= 0;			r.in.req.req8.unique_ptr2			= 0;			r.in.req.req8.mapping_ctr.num_mappings		= 0;			r.in.req.req8.mapping_ctr.mappings		= NULL;			break;		}		status = dcerpc_drsuapi_DsGetNCChanges(p, tctx, &r);		if (!NT_STATUS_IS_OK(status)) {			const char *errstr = nt_errstr(status);			if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {				errstr = dcerpc_errstr(tctx, p->last_fault_code);			}			printf("dcerpc_drsuapi_DsGetNCChanges failed - %s\n", errstr);			ret = false;		} else if (!W_ERROR_IS_OK(r.out.result)) {			printf("DsGetNCChanges failed - %s\n", win_errstr(r.out.result));			ret = false;		}	}	return ret;}bool test_QuerySitesByCost(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,			   struct DsPrivate *priv){	NTSTATUS status;	struct drsuapi_QuerySitesByCost r;	bool ret = true;	const char *my_site = "Default-First-Site-Name";	const char *remote_site1 = "smbtorture-nonexisting-site1";	const char *remote_site2 = "smbtorture-nonexisting-site2";	r.in.bind_handle = &priv->bind_handle;	r.in.level = 1;	r.in.req.req1.site_from = talloc_strdup(mem_ctx, my_site);	r.in.req.req1.num_req = 2;	r.in.req.req1.site_to = talloc_zero_array(mem_ctx, const char *, r.in.req.req1.num_req);	r.in.req.req1.site_to[0] = talloc_strdup(mem_ctx, remote_site1);	r.in.req.req1.site_to[1] = talloc_strdup(mem_ctx, remote_site2);	r.in.req.req1.flags = 0;	status = dcerpc_drsuapi_QuerySitesByCost(p, mem_ctx, &r);	if (!NT_STATUS_IS_OK(status)) {		const char *errstr = nt_errstr(status);		if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {			errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);		}		printf("drsuapi_QuerySitesByCost - %s\n", errstr);		ret = false;	} else if (!W_ERROR_IS_OK(r.out.result)) {		printf("QuerySitesByCost failed - %s\n", win_errstr(r.out.result));		ret = false;	}	if (W_ERROR_IS_OK(r.out.result)) {		if (!W_ERROR_EQUAL(r.out.ctr.ctr1.info[0].error_code, WERR_DS_OBJ_NOT_FOUND) ||		    !W_ERROR_EQUAL(r.out.ctr.ctr1.info[1].error_code, WERR_DS_OBJ_NOT_FOUND)) {				printf("expected error_code WERR_DS_OBJ_NOT_FOUND, got %s\n", 				win_errstr(r.out.ctr.ctr1.info[0].error_code));			ret = false;		}		if ((r.out.ctr.ctr1.info[0].site_cost != (uint32_t) -1) ||		    (r.out.ctr.ctr1.info[1].site_cost != (uint32_t) -1)) {			printf("expected site_cost %d, got %d\n", 				(uint32_t) -1, r.out.ctr.ctr1.info[0].site_cost);			ret = false;		}	}	return ret;}bool test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 		   struct DsPrivate *priv){	NTSTATUS status;	struct drsuapi_DsUnbind r;	bool ret = true;	r.in.bind_handle = &priv->bind_handle;	r.out.bind_handle = &priv->bind_handle;	printf("testing DsUnbind\n");	status = dcerpc_drsuapi_DsUnbind(p, mem_ctx, &r);	if (!NT_STATUS_IS_OK(status)) {		const char *errstr = nt_errstr(status);		if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {			errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);		}		printf("dcerpc_drsuapi_DsUnbind failed - %s\n", errstr);		ret = false;	} else if (!W_ERROR_IS_OK(r.out.result)) {		printf("DsBind failed - %s\n", win_errstr(r.out.result));		ret = false;	}	return ret;}bool torture_rpc_drsuapi(struct torture_context *torture){        NTSTATUS status;        struct dcerpc_pipe *p;	bool ret = true;	struct DsPrivate priv;	struct cli_credentials *machine_credentials;	ZERO_STRUCT(priv);	priv.join = torture_join_domain(torture, TEST_MACHINE_NAME, ACB_SVRTRUST, 				       &machine_credentials);	if (!priv.join) {		torture_fail(torture, "Failed to join as BDC");	}	status = torture_rpc_connection(torture, 					&p, 					&ndr_table_drsuapi);	if (!NT_STATUS_IS_OK(status)) {		torture_leave_domain(priv.join);		torture_fail(torture, "Unable to connect to DRSUAPI pipe");	}	ret &= test_DsBind(p, torture, &priv);#if 0	ret &= test_QuerySitesByCost(p, torture, &priv);#endif	ret &= test_DsGetDomainControllerInfo(p, torture, &priv);	ret &= test_DsCrackNames(torture, p, torture, &priv);	ret &= test_DsWriteAccountSpn(p, torture, &priv);	ret &= test_DsReplicaGetInfo(p, torture, &priv);	ret &= test_DsReplicaSync(p, torture, &priv);	ret &= test_DsReplicaUpdateRefs(p, torture, &priv);	ret &= test_DsGetNCChanges(p, torture, &priv);	ret &= test_DsUnbind(p, torture, &priv);	torture_leave_domain(priv.join);	return ret;}bool torture_rpc_drsuapi_cracknames(struct torture_context *torture){        NTSTATUS status;        struct dcerpc_pipe *p;	bool ret = true;	struct DsPrivate priv;	struct cli_credentials *machine_credentials;	torture_comment(torture, "Connected to DRSUAPI pipe\n");	ZERO_STRUCT(priv);	priv.join = torture_join_domain(torture, TEST_MACHINE_NAME, ACB_SVRTRUST, 				       &machine_credentials);	if (!priv.join) {		torture_fail(torture, "Failed to join as BDC\n");	}	status = torture_rpc_connection(torture, 					&p, 					&ndr_table_drsuapi);	if (!NT_STATUS_IS_OK(status)) {		torture_leave_domain(priv.join);		torture_fail(torture, "Unable to connect to DRSUAPI pipe");	}	ret &= test_DsBind(p, torture, &priv);	if (ret) {		/* We don't care if this fails, we just need some info from it */		test_DsGetDomainControllerInfo(p, torture, &priv);				ret &= test_DsCrackNames(torture, p, torture, &priv);				ret &= test_DsUnbind(p, torture, &priv);	}	torture_leave_domain(priv.join);	return ret;}

⌨️ 快捷键说明

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