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

📄 netlogon.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 4 页
字号:
	torture_comment(tctx, "Testing second ServerPasswordSet2 on machine account\n");	torture_comment(tctx, "Changing machine account password to '%s'\n", password);	creds_client_authenticator(creds, &r.in.credential);	status = dcerpc_netr_ServerPasswordSet2(p, tctx, &r);	torture_assert_ntstatus_ok(tctx, status, "ServerPasswordSet2 (2)");	if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {		torture_comment(tctx, "Credential chaining failed\n");	}	/* by changing the machine password twice we test the	   credentials chaining fully, and we verify that the server	   allows the password to be set to the same value twice in a	   row (match win2k3) */	torture_comment(tctx, 		"Testing a second ServerPasswordSet2 on machine account\n");	torture_comment(tctx, 		"Changing machine account password to '%s' (same as previous run)\n", password);	creds_client_authenticator(creds, &r.in.credential);	status = dcerpc_netr_ServerPasswordSet2(p, tctx, &r);	torture_assert_ntstatus_ok(tctx, status, "ServerPasswordSet (3)");	if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {		torture_comment(tctx, "Credential chaining failed\n");	}	cli_credentials_set_password(machine_credentials, password, CRED_SPECIFIED);	torture_assert (tctx, 		test_SetupCredentials(p, tctx, machine_credentials, &creds), 		"ServerPasswordSet failed to actually change the password");	return true;}static bool test_GetPassword(struct torture_context *tctx,			     struct dcerpc_pipe *p,			     struct cli_credentials *machine_credentials){	struct netr_ServerPasswordGet r;	struct creds_CredentialState *creds;	struct netr_Authenticator credential;	NTSTATUS status;	struct netr_Authenticator return_authenticator;	struct samr_Password password;	if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) {		return false;	}	creds_client_authenticator(creds, &credential);	r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME);	r.in.secure_channel_type = SEC_CHAN_BDC;	r.in.computer_name = TEST_MACHINE_NAME;	r.in.credential = &credential;	r.out.return_authenticator = &return_authenticator;	r.out.password = &password;	status = dcerpc_netr_ServerPasswordGet(p, tctx, &r);	torture_assert_ntstatus_ok(tctx, status, "ServerPasswordGet");	return true;}static bool test_GetTrustPasswords(struct torture_context *tctx,				   struct dcerpc_pipe *p,				   struct cli_credentials *machine_credentials){	struct netr_ServerTrustPasswordsGet r;	struct creds_CredentialState *creds;	struct netr_Authenticator credential;	NTSTATUS status;	struct netr_Authenticator return_authenticator;	struct samr_Password password, password2;	if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) {		return false;	}	creds_client_authenticator(creds, &credential);	r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME);	r.in.secure_channel_type = SEC_CHAN_BDC;	r.in.computer_name = TEST_MACHINE_NAME;	r.in.credential = &credential;	r.out.return_authenticator = &return_authenticator;	r.out.password = &password;	r.out.password2 = &password2;	status = dcerpc_netr_ServerTrustPasswordsGet(p, tctx, &r);	torture_assert_ntstatus_ok(tctx, status, "ServerTrustPasswordsGet");	return true;}/*  try a netlogon SamLogon*/bool test_netlogon_ops(struct dcerpc_pipe *p, struct torture_context *tctx,			      struct cli_credentials *credentials, 			      struct creds_CredentialState *creds){	NTSTATUS status;	struct netr_LogonSamLogon r;	struct netr_Authenticator auth, auth2;	struct netr_NetworkInfo ninfo;	DATA_BLOB names_blob, chal, lm_resp, nt_resp;	int i;	int flags = CLI_CRED_NTLM_AUTH;	if (lp_client_lanman_auth(tctx->lp_ctx)) {		flags |= CLI_CRED_LANMAN_AUTH;	}	if (lp_client_ntlmv2_auth(tctx->lp_ctx)) {		flags |= CLI_CRED_NTLMv2_AUTH;	}	cli_credentials_get_ntlm_username_domain(cmdline_credentials, tctx, 						 &ninfo.identity_info.account_name.string,						 &ninfo.identity_info.domain_name.string);		generate_random_buffer(ninfo.challenge, 			       sizeof(ninfo.challenge));	chal = data_blob_const(ninfo.challenge, 			       sizeof(ninfo.challenge));	names_blob = NTLMv2_generate_names_blob(tctx, lp_iconv_convenience(tctx->lp_ctx), cli_credentials_get_workstation(credentials), 						cli_credentials_get_domain(credentials));	status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx, 						   &flags, 						   chal,						   names_blob,						   &lm_resp, &nt_resp,						   NULL, NULL);	torture_assert_ntstatus_ok(tctx, status, "cli_credentials_get_ntlm_response failed");	ninfo.lm.data = lm_resp.data;	ninfo.lm.length = lm_resp.length;	ninfo.nt.data = nt_resp.data;	ninfo.nt.length = nt_resp.length;	ninfo.identity_info.parameter_control = 0;	ninfo.identity_info.logon_id_low = 0;	ninfo.identity_info.logon_id_high = 0;	ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);	r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.computer_name = cli_credentials_get_workstation(credentials);	r.in.credential = &auth;	r.in.return_authenticator = &auth2;	r.in.logon_level = 2;	r.in.logon.network = &ninfo;	d_printf("Testing LogonSamLogon with name %s\n", ninfo.identity_info.account_name.string);		for (i=2;i<3;i++) {		ZERO_STRUCT(auth2);		creds_client_authenticator(creds, &auth);				r.in.validation_level = i;				status = dcerpc_netr_LogonSamLogon(p, tctx, &r);		torture_assert_ntstatus_ok(tctx, status, "LogonSamLogon failed");				torture_assert(tctx, creds_client_check(creds, &r.out.return_authenticator->cred), 			"Credential chaining failed");	}	r.in.credential = NULL;	for (i=2;i<=3;i++) {		r.in.validation_level = i;		torture_comment(tctx, "Testing SamLogon with validation level %d and a NULL credential\n", i);		status = dcerpc_netr_LogonSamLogon(p, tctx, &r);		torture_assert_ntstatus_equal(tctx, status, NT_STATUS_INVALID_PARAMETER, 			"LogonSamLogon expected INVALID_PARAMETER");	}	return true;}/*  try a netlogon SamLogon*/static bool test_SamLogon(struct torture_context *tctx, 			  struct dcerpc_pipe *p,			  struct cli_credentials *credentials){	struct creds_CredentialState *creds;	if (!test_SetupCredentials(p, tctx, credentials, &creds)) {		return false;	}	return test_netlogon_ops(p, tctx, credentials, creds);}/* we remember the sequence numbers so we can easily do a DatabaseDelta */static uint64_t sequence_nums[3];/*  try a netlogon DatabaseSync*/static bool test_DatabaseSync(struct torture_context *tctx, 			      struct dcerpc_pipe *p,			      struct cli_credentials *machine_credentials){	NTSTATUS status;	struct netr_DatabaseSync r;	struct creds_CredentialState *creds;	const uint32_t database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS}; 	int i;	if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) {		return false;	}	r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.computername = TEST_MACHINE_NAME;	r.in.preferredmaximumlength = (uint32_t)-1;	ZERO_STRUCT(r.in.return_authenticator);	for (i=0;i<ARRAY_SIZE(database_ids);i++) {		r.in.sync_context = 0;		r.in.database_id = database_ids[i];		torture_comment(tctx, "Testing DatabaseSync of id %d\n", r.in.database_id);		do {			creds_client_authenticator(creds, &r.in.credential);			status = dcerpc_netr_DatabaseSync(p, tctx, &r);			if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES))			    break;			/* Native mode servers don't do this */			if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {				return true;			}			torture_assert_ntstatus_ok(tctx, status, "DatabaseSync");			if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {				torture_comment(tctx, "Credential chaining failed\n");			}			r.in.sync_context = r.out.sync_context;			if (r.out.delta_enum_array &&			    r.out.delta_enum_array->num_deltas > 0 &&			    r.out.delta_enum_array->delta_enum[0].delta_type == NETR_DELTA_DOMAIN &&			    r.out.delta_enum_array->delta_enum[0].delta_union.domain) {				sequence_nums[r.in.database_id] = 					r.out.delta_enum_array->delta_enum[0].delta_union.domain->sequence_num;				torture_comment(tctx, "\tsequence_nums[%d]=%llu\n",				       r.in.database_id, 				       (unsigned long long)sequence_nums[r.in.database_id]);			}		} while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));	}	return true;}/*  try a netlogon DatabaseDeltas*/static bool test_DatabaseDeltas(struct torture_context *tctx, 				struct dcerpc_pipe *p,				struct cli_credentials *machine_credentials){	NTSTATUS status;	struct netr_DatabaseDeltas r;	struct creds_CredentialState *creds;	const uint32_t database_ids[] = {0, 1, 2}; 	int i;	if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) {		return false;	}	r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.computername = TEST_MACHINE_NAME;	r.in.preferredmaximumlength = (uint32_t)-1;	ZERO_STRUCT(r.in.return_authenticator);	for (i=0;i<ARRAY_SIZE(database_ids);i++) {		r.in.database_id = database_ids[i];		r.in.sequence_num = sequence_nums[r.in.database_id];		if (r.in.sequence_num == 0) continue;		r.in.sequence_num -= 1;		torture_comment(tctx, "Testing DatabaseDeltas of id %d at %llu\n", 		       r.in.database_id, (unsigned long long)r.in.sequence_num);		do {			creds_client_authenticator(creds, &r.in.credential);			status = dcerpc_netr_DatabaseDeltas(p, tctx, &r);			if (NT_STATUS_EQUAL(status, 					     NT_STATUS_SYNCHRONIZATION_REQUIRED)) {				torture_comment(tctx, "not considering %s to be an error\n",				       nt_errstr(status));				return true;			}			if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) 			    break;			torture_assert_ntstatus_ok(tctx, status, "DatabaseDeltas");			if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {				torture_comment(tctx, "Credential chaining failed\n");			}			r.in.sequence_num++;		} while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));	}	return true;}/*  try a netlogon AccountDeltas*/static bool test_AccountDeltas(struct torture_context *tctx, 			       struct dcerpc_pipe *p,			       struct cli_credentials *machine_credentials){	NTSTATUS status;	struct netr_AccountDeltas r;	struct creds_CredentialState *creds;	if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) {		return false;	}	r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.computername = TEST_MACHINE_NAME;	ZERO_STRUCT(r.in.return_authenticator);	creds_client_authenticator(creds, &r.in.credential);	ZERO_STRUCT(r.in.uas);	r.in.count=10;	r.in.level=0;	r.in.buffersize=100;	/* w2k3 returns "NOT IMPLEMENTED" for this call */	status = dcerpc_netr_AccountDeltas(p, tctx, &r);	torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NOT_IMPLEMENTED, "AccountDeltas");	return true;}/*  try a netlogon AccountSync*/static bool test_AccountSync(struct torture_context *tctx, struct dcerpc_pipe *p, 			     struct cli_credentials *machine_credentials){	NTSTATUS status;	struct netr_AccountSync r;	struct creds_CredentialState *creds;	if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) {		return false;	}	r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));	r.in.computername = TEST_MACHINE_NAME;	ZERO_STRUCT(r.in.return_authenticator);	creds_client_authenticator(creds, &r.in.credential);	ZERO_STRUCT(r.in.recordid);	r.in.reference=0;	r.in.level=0;	r.in.buffersize=100;	/* w2k3 returns "NOT IMPLEMENTED" for this call */	status = dcerpc_netr_AccountSync(p, tctx, &r);	torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NOT_IMPLEMENTED, "AccountSync");	return true;}/*  try a netlogon GetDcName*/

⌨️ 快捷键说明

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