#include "includes.h"
-/*
- this makes the debug code display the right thing
-*/
static void init_lsa_Name(struct lsa_Name *name, const char *s)
{
name->name = s;
- name->name_len = strlen_m(s)*2;
- name->name_size = name->name_len;
}
static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
return True;
}
+static BOOL test_Delete(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct lsa_Delete r;
+
+ printf("\ntesting Delete\n");
+
+ r.in.handle = handle;
+ status = dcerpc_lsa_Delete(p, mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Delete failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ printf("\n");
+
+ return True;
+}
+
+
+static BOOL find_domain_sid(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle,
+ struct dom_sid2 **sid)
+{
+ struct lsa_QueryInfoPolicy r;
+ NTSTATUS status;
+
+ r.in.handle = handle;
+ r.in.level = LSA_POLICY_INFO_DOMAIN;
+
+ status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("LSA_POLICY_INFO_DOMAIN failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ *sid = r.out.info->domain.sid;
+
+ return True;
+}
+
+static struct dom_sid *sid_add_auth(TALLOC_CTX *mem_ctx,
+ const struct dom_sid *sid,
+ uint32 sub_auth)
+{
+ struct dom_sid *ret;
+
+ ret = talloc_p(mem_ctx, struct dom_sid);
+ if (!ret) {
+ return NULL;
+ }
+
+ *ret = *sid;
+
+ ret->sub_auths = talloc_array_p(mem_ctx, uint32, ret->num_auths+1);
+ if (!ret->sub_auths) {
+ return NULL;
+ }
+
+ memcpy(ret->sub_auths, sid->sub_auths,
+ ret->num_auths * sizeof(sid->sub_auths[0]));
+ ret->sub_auths[ret->num_auths] = sub_auth;
+ ret->num_auths++;
+
+ return ret;
+}
+
+static BOOL test_CreateAccount(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct lsa_CreateAccount r;
+ struct dom_sid2 *domsid, *newsid;
+ struct policy_handle acct_handle;
+
+ if (!find_domain_sid(p, mem_ctx, handle, &domsid)) {
+ return False;
+ }
+
+ newsid = sid_add_auth(mem_ctx, domsid, 0x1234abcd);
+ if (!newsid) {
+ printf("Failed to create newsid\n");
+ return False;
+ }
+
+ printf("Testing CreateAccount\n");
+
+ r.in.handle = handle;
+ r.in.sid = newsid;
+ r.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
+ r.out.acct_handle = &acct_handle;
+
+ status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("CreateAccount failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ if (!test_Delete(p, mem_ctx, &acct_handle)) {
+ return False;
+ }
+
+ return True;
+}
+
+
+static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct lsa_CreateTrustedDomain r;
+ struct lsa_TrustInformation trustinfo;
+ struct dom_sid *domsid;
+ struct policy_handle dom_handle;
+
+ printf("Testing CreateTrustedDomain\n");
+
+ if (!find_domain_sid(p, mem_ctx, handle, &domsid)) {
+ return False;
+ }
+
+ domsid->sub_auths[domsid->num_auths-1] ^= 0xF0F0F0F0;
+
+ trustinfo.sid = domsid;
+ init_lsa_Name(&trustinfo.name, "torturedomain");
+
+ r.in.handle = handle;
+ r.in.info = &trustinfo;
+ r.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
+ r.out.dom_handle = &dom_handle;
+
+ status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ if (!test_Delete(p, mem_ctx, &dom_handle)) {
+ return False;
+ }
+
+ return True;
+}
+
+static BOOL test_CreateSecret(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct lsa_CreateSecret r;
+ struct lsa_OpenSecret r2;
+ struct policy_handle sec_handle, sec_handle2;
+ struct lsa_Delete d;
+
+ printf("Testing CreateSecret\n");
+
+ init_lsa_Name(&r.in.name, "torturesecret");
+
+ r.in.handle = handle;
+ r.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
+ r.out.sec_handle = &sec_handle;
+
+ status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("CreateSecret failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ r2.in.handle = handle;
+ r2.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
+ init_lsa_Name(&r2.in.name, "torturesecret");
+ r2.out.sec_handle = &sec_handle2;
+
+ printf("Testing OpenSecret\n");
+
+ status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("OpenSecret failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ if (!test_Delete(p, mem_ctx, &sec_handle)) {
+ return False;
+ }
+
+ d.in.handle = &sec_handle2;
+ status = dcerpc_lsa_Delete(p, mem_ctx, &d);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
+ printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ return True;
+}
+
static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
TALLOC_CTX *mem_ctx,
struct policy_handle *acct_handle,
NTSTATUS status;
int i;
BOOL ret = True;
-
printf("\nTesting QueryInfoPolicy\n");
for (i=1;i<13;i++) {
status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
- if ((i == 9 || i == 10) &&
+ if ((i == 9 || i == 10 || i == 11) &&
NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
+ printf("server failed level %u (OK)\n", i);
continue;
}
return ret;
}
-static BOOL test_Delete(struct dcerpc_pipe *p,
- TALLOC_CTX *mem_ctx,
- struct policy_handle *handle)
-{
- NTSTATUS status;
- struct lsa_Delete r;
-
- printf("\ntesting Delete - but what does it do?\n");
-
- r.in.handle = handle;
- status = dcerpc_lsa_Delete(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status)) {
- printf("Delete failed - %s\n", nt_errstr(status));
- return False;
- }
-
- printf("\n");
-
- return True;
-}
-
static BOOL test_Close(struct dcerpc_pipe *p,
TALLOC_CTX *mem_ctx,
struct policy_handle *handle)
if (!NT_STATUS_IS_OK(status)) {
return False;
}
-
- p->flags |= DCERPC_DEBUG_PRINT_BOTH;
if (!test_OpenPolicy(p, mem_ctx)) {
ret = False;
ret = False;
}
+ if (!test_CreateAccount(p, mem_ctx, &handle)) {
+ ret = False;
+ }
+
+ if (!test_CreateSecret(p, mem_ctx, &handle)) {
+ ret = False;
+ }
+
+ if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
+ ret = False;
+ }
+
if (!test_EnumAccounts(p, mem_ctx, &handle)) {
ret = False;
}
ret = False;
}
+ talloc_destroy(mem_ctx);
+
torture_rpc_close(p);
return ret;