summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2002-09-24 21:18:22 +0000
committerJelmer Vernooij <jelmer@samba.org>2002-09-24 21:18:22 +0000
commit529848e988fb28b54303408f31e21051ae0b94a6 (patch)
treed0d6e65463c97a8f4a6d8625b86f6138724c0cb1 /source3
parent2cd64003e3b127ca5a204b801155fcb4a7447a48 (diff)
downloadsamba-529848e988fb28b54303408f31e21051ae0b94a6.tar.gz
samba-529848e988fb28b54303408f31e21051ae0b94a6.tar.bz2
samba-529848e988fb28b54303408f31e21051ae0b94a6.zip
Fix bug in get_methods_by_name
Fix bug in enum_domains Add samtest commands: - lookup_sid - lookup_name - enum_domains - lookup_domain (This used to be commit 0c01219850e5d9b77b3b2c0b4b87aa3c82e3292b)
Diffstat (limited to 'source3')
-rw-r--r--source3/sam/interface.c19
-rw-r--r--source3/torture/cmd_sam.c80
2 files changed, 80 insertions, 19 deletions
diff --git a/source3/sam/interface.c b/source3/sam/interface.c
index 6e6902ab3c..e129604ca3 100644
--- a/source3/sam/interface.c
+++ b/source3/sam/interface.c
@@ -79,7 +79,7 @@ NTSTATUS sam_get_methods_by_name(const SAM_CONTEXT *context, SAM_METHODS **sam_m
tmp_methods = context->methods;
while (tmp_methods) {
- if (strcmp(domainname, tmp_methods->domain_name))
+ if (!strcmp(domainname, tmp_methods->domain_name))
{
(*sam_method) = tmp_methods;
return NT_STATUS_OK;
@@ -256,6 +256,7 @@ NTSTATUS context_sam_enum_domains(const SAM_CONTEXT *context, const NT_USER_TOKE
}
tmp_methods= context->methods;
+ *domain_count = 0;
while (tmp_methods) {
(*domain_count)++;
@@ -264,15 +265,19 @@ NTSTATUS context_sam_enum_domains(const SAM_CONTEXT *context, const NT_USER_TOKE
DEBUG(6,("context_sam_enum_domains: enumerating %d domains\n", (*domain_count)));
+ if (*domain_count == 0) {
+ return NT_STATUS_OK;
+ }
+
tmp_methods = context->methods;
if (((*domains) = malloc( sizeof(DOM_SID) * (*domain_count))) == NULL) {
- DEBUG(0,("context_sam_enum_domains: Out of memory allocating domain list\n"));
+ DEBUG(0,("context_sam_enum_domains: Out of memory allocating domain SID list\n"));
return NT_STATUS_NO_MEMORY;
}
if (((*domain_names) = malloc( sizeof(char*) * (*domain_count))) == NULL) {
- DEBUG(0,("context_sam_enum_domains: Out of memory allocating domain list\n"));
+ DEBUG(0,("context_sam_enum_domains: Out of memory allocating domain name list\n"));
SAFE_FREE((*domains));
return NT_STATUS_NO_MEMORY;
}
@@ -280,13 +285,7 @@ NTSTATUS context_sam_enum_domains(const SAM_CONTEXT *context, const NT_USER_TOKE
while (tmp_methods) {
DEBUGADD(7,(" [%d] %s: %s\n", i, tmp_methods->domain_name, sid_string_static(&tmp_methods->domain_sid)));
sid_copy(domains[i],&tmp_methods->domain_sid);
- if(asprintf(&(*domain_names[i]),"%s",tmp_methods->domain_name) < 0) {
- DEBUG(0,("context_sam_enum_domains: asprintf failed"));
- SAFE_FREE((*domains));
- SAFE_FREE((*domain_names));
- return NT_STATUS_NO_MEMORY;
- }
-
+ *domain_names[i] = smb_xstrdup(tmp_methods->domain_name);
i++;
tmp_methods= tmp_methods->next;
}
diff --git a/source3/torture/cmd_sam.c b/source3/torture/cmd_sam.c
index 2b4c21e501..3ebf91434e 100644
--- a/source3/torture/cmd_sam.c
+++ b/source3/torture/cmd_sam.c
@@ -26,12 +26,16 @@ static NTSTATUS cmd_load_module(struct samtest_state *st, TALLOC_CTX *mem_ctx, i
{
char *plugin_arg[2];
NTSTATUS status;
- if (argc != 2) {
- printf("Usage: load <module path>\n");
+ if (argc != 2 && argc != 3) {
+ printf("Usage: load <module path> [domain-sid]\n");
return NT_STATUS_OK;
}
- asprintf(&plugin_arg[0], "plugin:%s", argv[1]);
+ if (argc == 3)
+ asprintf(&plugin_arg[0], "%s|plugin:%s", argv[2], argv[1]);
+ else
+ asprintf(&plugin_arg[0], "plugin:%s", argv[1]);
+
plugin_arg[1] = NULL;
if(!NT_STATUS_IS_OK(status = make_sam_context_list(&st->context, plugin_arg))) {
@@ -61,7 +65,7 @@ static NTSTATUS cmd_lookup_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, in
uint32 type;
NTSTATUS status;
DOM_SID sid;
- if(argc != 2) {
+ if (argc != 2) {
printf("Usage: lookup_sid <sid>\n");
return NT_STATUS_INVALID_PARAMETER;
}
@@ -71,21 +75,36 @@ static NTSTATUS cmd_lookup_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, in
return NT_STATUS_INVALID_PARAMETER;
}
- if(!NT_STATUS_IS_OK(status = context_sam_lookup_sid(st->context, st->token, &sid, &name, &type))) {
+ if (!NT_STATUS_IS_OK(status = context_sam_lookup_sid(st->context, st->token, &sid, &name, &type))) {
printf("context_sam_lookup_sid failed!\n");
return status;
}
+ printf("Name: %s\n", name);
+ printf("Type: %d\n", type); /* FIXME: What kind of an integer is type ? */
+
return NT_STATUS_OK;
}
static NTSTATUS cmd_lookup_name(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- if(argc != 2) {
- printf("Usage: lookup_name <name>\n");
+ DOM_SID *sid;
+ uint32 type;
+ NTSTATUS status;
+ if (argc != 3) {
+ printf("Usage: lookup_name <domain> <name>\n");
return NT_STATUS_INVALID_PARAMETER;
}
- return NT_STATUS_NOT_IMPLEMENTED;
+
+ if (!NT_STATUS_IS_OK(status = context_sam_lookup_name(st->context, st->token, argv[1], argv[2], &sid, &type))) {
+ printf("context_sam_lookup_name failed!\n");
+ return status;
+ }
+
+ printf("SID: %s\n", sid_string_static(sid));
+ printf("Type: %d\n", type);
+
+ return NT_STATUS_OK;
}
static NTSTATUS cmd_lookup_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv)
@@ -98,6 +117,47 @@ static NTSTATUS cmd_lookup_group(struct samtest_state *st, TALLOC_CTX *mem_ctx,
return NT_STATUS_NOT_IMPLEMENTED;
}
+static NTSTATUS cmd_lookup_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv)
+{
+ DOM_SID *sid;
+ NTSTATUS status;
+ if (argc != 2) {
+ printf("Usage: lookup_domain <domain>\n");
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (!NT_STATUS_IS_OK(status = context_sam_lookup_domain(st->context, st->token, argv[1], &sid))) {
+ printf("context_sam_lookup_name failed!\n");
+ return status;
+ }
+
+ printf("SID: %s\n", sid_string_static(sid));
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS cmd_enum_domains(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv)
+{
+ int32 domain_count, i;
+ DOM_SID *domain_sids;
+ char **domain_names;
+ NTSTATUS status;
+
+ if (!NT_STATUS_IS_OK(status = context_sam_enum_domains(st->context, st->token, &domain_count, &domain_sids, &domain_names))) {
+ printf("context_sam_enum_domains failed!\n");
+ return status;
+ }
+
+ for (i = 0; i < domain_count; i++) {
+ printf("%s %s\n", domain_names[i], sid_string_static(&domain_sids[i]));
+ }
+
+ SAFE_FREE(domain_sids);
+ SAFE_FREE(domain_names);
+
+ return NT_STATUS_OK;
+}
+
static NTSTATUS cmd_update_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
return NT_STATUS_NOT_IMPLEMENTED;
@@ -194,7 +254,7 @@ struct cmd_set sam_general_commands[] = {
{ "General SAM Commands" },
- { "load", cmd_load_module, "Load a module", "load <module.so>" },
+ { "load", cmd_load_module, "Load a module", "load <module.so> [domain-sid]" },
{ "get_sec_desc", cmd_get_sec_desc, "Get security descriptor info", "get_sec_desc <access-token> <sid>" },
{ "set_sec_desc", cmd_set_sec_desc, "Set security descriptor info", "set_sec_desc <access-token> <sid>" },
{ "lookup_sid", cmd_lookup_sid, "Lookup type of specified SID", "lookup_sid <sid>" },
@@ -206,6 +266,8 @@ struct cmd_set sam_domain_commands[] = {
{ "Domain Commands" },
{ "update_domain", cmd_update_domain, "Update domain information", "update_domain [domain-options] domain-name | domain-sid" },
{ "show_domain", cmd_show_domain, "Show domain information", "show_domain domain-sid | domain-name" },
+ { "enum_domains", cmd_enum_domains, "Enumerate all domains", "enum_domains <token> <acct-ctrl>" },
+ { "lookup_domain", cmd_lookup_domain, "Lookup a domain by name", "lookup_domain domain-name" },
{ NULL }
};