From db22c0c5f94ecc12339efbd3950fe1c5648fde76 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 19 Dec 2003 03:59:27 +0000 Subject: added a bunch of alias functions in samr.idl based on work by Kai. (This used to be commit f740b02ac36780740700909da2bcdf672cb146cb) --- source4/torture/rpc/samr.c | 341 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 327 insertions(+), 14 deletions(-) (limited to 'source4/torture') diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c index 2678f38254..9f50d0ff06 100644 --- a/source4/torture/rpc/samr.c +++ b/source4/torture/rpc/samr.c @@ -23,12 +23,17 @@ #include "includes.h" #define TEST_USERNAME "samrtorturetest" +#define TEST_ALIASNAME "samrtorturetestalias" #define TEST_MACHINENAME "samrtorturetestmach$" #define TEST_DOMAINNAME "samrtorturetestdom$" + static BOOL test_QueryUserInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle); +static BOOL test_QueryAliasInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle); + static void init_samr_Name(struct samr_Name *name, const char *s) { name->name = s; @@ -188,14 +193,83 @@ static BOOL test_SetUserInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, TEST_USERINFO_INT(4, logon_hours.bitmap[3], 5, logon_hours.bitmap[3], __LINE__); TEST_USERINFO_INT(4, logon_hours.bitmap[3], 21, logon_hours.bitmap[3], __LINE__); +#if 0 + /* these fail with win2003 - it appears you can't set the primary gid? + the set succeeds, but the gid isn't changed. Very weird! */ TEST_USERINFO_INT(9, primary_gid, 1, primary_gid, 513); TEST_USERINFO_INT(9, primary_gid, 3, primary_gid, 513); TEST_USERINFO_INT(9, primary_gid, 5, primary_gid, 513); TEST_USERINFO_INT(9, primary_gid, 21, primary_gid, 513); +#endif + return ret; +} + +static BOOL test_SetAliasInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle) +{ + NTSTATUS status; + struct samr_SetAliasInfo r; + struct samr_QueryAliasInfo q; + uint16 levels[] = {2, 3}; + int i; + BOOL ret = True; + + /* Ignoring switch level 1, as that includes the number of members for the alias + * and setting this to a wrong value might have negative consequences + */ + + for (i=0;iname); + + status = dcerpc_samr_CreateDomAlias(p, mem_ctx, &r); + + if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { + printf("Server refused create of '%s'\n", r.in.aliasname->name); + return True; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_ALIAS_EXISTS)) { + if (!test_DeleteAlias_byname(p, mem_ctx, domain_handle, r.in.aliasname->name)) { + return False; + } + status = dcerpc_samr_CreateDomAlias(p, mem_ctx, &r); + } + + if (!NT_STATUS_IS_OK(status)) { + printf("CreateAlias failed - %s\n", nt_errstr(status)); + return False; + } + + if (!test_alias_ops(p, mem_ctx, alias_handle, domain_handle)) { + ret = False; + } + + return ret; +} static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle) + struct policy_handle *domain_handle, struct policy_handle *user_handle) { NTSTATUS status; struct samr_CreateUser r; struct samr_QueryUserInfo q; - struct samr_DeleteUser d; - struct policy_handle acct_handle; uint32 rid; /* This call creates a 'normal' account - check that it really does */ @@ -303,10 +559,10 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, init_samr_Name(&name, TEST_USERNAME); - r.in.handle = handle; + r.in.handle = domain_handle; r.in.username = &name; r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED; - r.out.acct_handle = &acct_handle; + r.out.acct_handle = user_handle; r.out.rid = &rid; printf("Testing CreateUser(%s)\n", r.in.username->name); @@ -315,11 +571,12 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { printf("Server refused create of '%s'\n", r.in.username->name); + ZERO_STRUCTP(user_handle); return True; } if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { - if (!test_DeleteUser_byname(p, mem_ctx, handle, r.in.username->name)) { + if (!test_DeleteUser_byname(p, mem_ctx, domain_handle, r.in.username->name)) { return False; } status = dcerpc_samr_CreateUser(p, mem_ctx, &r); @@ -330,7 +587,7 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, } - q.in.handle = &acct_handle; + q.in.handle = user_handle; q.in.level = 16; status = dcerpc_samr_QueryUserInfo(p, mem_ctx, &q); @@ -347,14 +604,25 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, } } - if (!test_user_ops(p, mem_ctx, &acct_handle)) { + if (!test_user_ops(p, mem_ctx, user_handle)) { ret = False; } + return ret; +} + + +static BOOL test_DeleteUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *user_handle) +{ + struct samr_DeleteUser d; + NTSTATUS status; + BOOL ret; + printf("Testing DeleteUser\n"); - d.in.handle = &acct_handle; - d.out.handle = &acct_handle; + d.in.handle = user_handle; + d.out.handle = user_handle; status = dcerpc_samr_DeleteUser(p, mem_ctx, &d); if (!NT_STATUS_IS_OK(status)) { @@ -366,7 +634,7 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, } static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle) + struct policy_handle *handle) { NTSTATUS status; struct samr_CreateUser2 r; @@ -457,7 +725,7 @@ static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, ret = False; } - printf("Testing DeleteUser\n"); + printf("Testing DeleteUser (createuser2 test)\n"); d.in.handle = &acct_handle; d.out.handle = &acct_handle; @@ -585,6 +853,10 @@ static BOOL test_OpenUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, ret = False; } + if (!test_GetGroupsForUser(p,mem_ctx, &acct_handle)) { + ret = False; + } + if (!test_Close(p, mem_ctx, &acct_handle)) { ret = False; } @@ -657,6 +929,10 @@ static BOOL test_OpenAlias(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, ret = False; } + if (!test_GetMembersInAlias(p, mem_ctx, &acct_handle)) { + ret = False; + } + if (!test_Close(p, mem_ctx, &acct_handle)) { ret = False; } @@ -865,8 +1141,13 @@ static BOOL test_OpenDomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, NTSTATUS status; struct samr_OpenDomain r; struct policy_handle domain_handle; + struct policy_handle user_handle; + struct policy_handle alias_handle; BOOL ret = True; + ZERO_STRUCT(user_handle); + ZERO_STRUCT(alias_handle); + printf("Testing OpenDomain\n"); r.in.handle = handle; @@ -880,11 +1161,15 @@ static BOOL test_OpenDomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, return False; } - if (!test_CreateUser(p, mem_ctx, &domain_handle)) { + if (!test_CreateUser2(p, mem_ctx, &domain_handle)) { ret = False; } - if (!test_CreateUser2(p, mem_ctx, &domain_handle)) { + if (!test_CreateUser(p, mem_ctx, &domain_handle, &user_handle)) { + ret = False; + } + + if (!test_CreateAlias(p, mem_ctx, &domain_handle, &alias_handle)) { ret = False; } @@ -912,6 +1197,16 @@ static BOOL test_OpenDomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, ret = False; } + if (!policy_handle_empty(&user_handle) && + !test_DeleteUser(p, mem_ctx, &user_handle)) { + ret = False; + } + + if (!policy_handle_empty(&alias_handle) && + !test_DeleteAlias(p,mem_ctx, &alias_handle)) { + ret = False; + } + if (!test_Close(p, mem_ctx, &domain_handle)) { ret = False; } @@ -986,6 +1281,7 @@ static BOOL test_Connect(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct samr_Connect r; struct samr_Connect2 r2; struct samr_Connect4 r4; + struct samr_Connect5 r5; BOOL ret = True; r.in.system_name = 0; @@ -1019,6 +1315,23 @@ static BOOL test_Connect(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, ret = False; } + r5.in.system_name = ""; + r5.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED; + r5.in.unknown0 = 1; /*Magic values I took from a WinXP pro workstation */ + r5.in.unknown1 = 1; /*tests failed with NT_STATUS_NET_WRITE_FAULT if */ + r5.in.unknown2 = 3; /*unknown0 and unknown1 where something other than 1 */ + r5.in.unknown3 = 0; /*unkown2 and unknown3 could be varied and had no effect */ + r5.out.handle = handle; + + status = dcerpc_samr_Connect5(p, mem_ctx, &r5); + if (!NT_STATUS_IS_OK(status)) { + /*This fails for a Win2000pro machine, but succeeds for + WinXPpro -- Kai + */ + printf("Connect5 failed - %s\n", nt_errstr(status)); + /*ret = False; Should this test fail? */ + } + return ret; } -- cgit