diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2002-09-24 20:18:39 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2002-09-24 20:18:39 +0000 |
commit | 2cd64003e3b127ca5a204b801155fcb4a7447a48 (patch) | |
tree | da3a9ee54c445fdb3c8ebf79bb925de118d49a4b | |
parent | 28947d6cd12040de37e3dfb29eeb1163cc429f32 (diff) | |
download | samba-2cd64003e3b127ca5a204b801155fcb4a7447a48.tar.gz samba-2cd64003e3b127ca5a204b801155fcb4a7447a48.tar.bz2 samba-2cd64003e3b127ca5a204b801155fcb4a7447a48.zip |
- Don't put pointer to sam_domain_handle in sam_methods but single domainsid and domainname
- Allocate sam_methods, set domain_sid, domain_name and backend_name in make_sam_methods_backend_entry instead of in the backend
- Remove sam_context and domain_sid pointers from the sam_init_function - we don't need those arguments anymore since they're
available in sam_methods as well
(This used to be commit 50d2527eed0eb26c16f2f7e28badbf08d771380e)
-rw-r--r-- | examples/sam/sam_skel.c | 114 | ||||
-rw-r--r-- | source3/include/sam.h | 5 | ||||
-rw-r--r-- | source3/sam/interface.c | 39 | ||||
-rw-r--r-- | source3/sam/sam_plugin.c | 6 | ||||
-rw-r--r-- | source3/torture/cmd_sam.c | 102 | ||||
-rw-r--r-- | source3/torture/samtest.c | 22 | ||||
-rw-r--r-- | source3/torture/samtest.h | 9 |
7 files changed, 156 insertions, 141 deletions
diff --git a/examples/sam/sam_skel.c b/examples/sam/sam_skel.c index a3b8f13391..da3a375894 100644 --- a/examples/sam/sam_skel.c +++ b/examples/sam/sam_skel.c @@ -3,6 +3,7 @@ this is a skeleton for SAM backend modules. Copyright (C) Stefan (metze) Metzmacher 2002 + Copyright (C) Jelmer Vernooij 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,29 +30,28 @@ static int sam_skel_debug_level = DBGC_SAM; /* define the version of the SAM interface */ SAM_MODULE_VERSIONING_MAGIC - /* General API */ -NTSTATUS sam_skel_get_sec_desc(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, const DOM_SID *sid, SEC_DESC **sd) +NTSTATUS sam_skel_get_sec_desc(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, const DOM_SID *sid, SEC_DESC **sd) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_set_sec_desc(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, const DOM_SID *sid, const SEC_DESC *sd) +NTSTATUS sam_skel_set_sec_desc(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, const DOM_SID *sid, const SEC_DESC *sd) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_lookup_sid(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, const DOM_SID *sid, char **name, uint32 *type) +NTSTATUS sam_skel_lookup_sid(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, const DOM_SID *sid, char **name, uint32 *type) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_lookup_name(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, const char *name, DOM_SID **sid, uint32 *type) +NTSTATUS sam_skel_lookup_name(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, const char *name, DOM_SID **sid, uint32 *type) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; @@ -60,13 +60,13 @@ NTSTATUS sam_skel_lookup_name(const SAM_METHODS *sam_method, const NT_USER_TOKEN /* Domain API */ -NTSTATUS sam_skel_update_domain(const SAM_METHODS *sam_method, const SAM_DOMAIN_HANDLE *domain) +NTSTATUS sam_skel_update_domain(const SAM_METHODS *sam_methods, const SAM_DOMAIN_HANDLE *domain) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_get_domain_handle(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, SAM_DOMAIN_HANDLE **domain) +NTSTATUS sam_skel_get_domain_handle(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, SAM_DOMAIN_HANDLE **domain) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; @@ -75,44 +75,44 @@ NTSTATUS sam_skel_get_domain_handle(const SAM_METHODS *sam_method, const NT_USER /* Account API */ -NTSTATUS sam_skel_create_account(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *group_name, uint16 acct_ctrl, SAM_ACCOUNT_HANDLE **account) +NTSTATUS sam_skel_create_account(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *group_name, uint16 acct_ctrl, SAM_ACCOUNT_HANDLE **account) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_add_account(const SAM_METHODS *sam_method, const SAM_ACCOUNT_HANDLE *account) +NTSTATUS sam_skel_add_account(const SAM_METHODS *sam_methods, const SAM_ACCOUNT_HANDLE *account) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_update_account(const SAM_METHODS *sam_method, const SAM_ACCOUNT_HANDLE *account) +NTSTATUS sam_skel_update_account(const SAM_METHODS *sam_methods, const SAM_ACCOUNT_HANDLE *account) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_delete_account(const SAM_METHODS *sam_method, const SAM_ACCOUNT_HANDLE *account) +NTSTATUS sam_skel_delete_account(const SAM_METHODS *sam_methods, const SAM_ACCOUNT_HANDLE *account) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_enum_accounts(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint16 acct_ctrl, uint32 *account_count, SAM_ACCOUNT_ENUM **accounts) +NTSTATUS sam_skel_enum_accounts(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint16 acct_ctrl, uint32 *account_count, SAM_ACCOUNT_ENUM **accounts) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_get_account_by_sid(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID *accountsid, SAM_ACCOUNT_HANDLE **account) +NTSTATUS sam_skel_get_account_by_sid(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID *accountsid, SAM_ACCOUNT_HANDLE **account) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_get_account_by_name(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *name, SAM_ACCOUNT_HANDLE **account) +NTSTATUS sam_skel_get_account_by_name(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *name, SAM_ACCOUNT_HANDLE **account) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; @@ -121,126 +121,118 @@ NTSTATUS sam_skel_get_account_by_name(const SAM_METHODS *sam_method, const NT_US /* Group API */ -NTSTATUS sam_skel_create_group(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *account_name, uint16 group_ctrl, SAM_GROUP_HANDLE **group) +NTSTATUS sam_skel_create_group(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *account_name, uint16 group_ctrl, SAM_GROUP_HANDLE **group) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_add_group(const SAM_METHODS *sam_method, const SAM_GROUP_HANDLE *group) +NTSTATUS sam_skel_add_group(const SAM_METHODS *sam_methods, const SAM_GROUP_HANDLE *group) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_update_group(const SAM_METHODS *sam_method, const SAM_GROUP_HANDLE *group) +NTSTATUS sam_skel_update_group(const SAM_METHODS *sam_methods, const SAM_GROUP_HANDLE *group) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_delete_group(const SAM_METHODS *sam_method, const SAM_GROUP_HANDLE *group) +NTSTATUS sam_skel_delete_group(const SAM_METHODS *sam_methods, const SAM_GROUP_HANDLE *group) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_enum_groups(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint16 group_ctrl, uint32 *groups_count, SAM_GROUP_ENUM **groups) +NTSTATUS sam_skel_enum_groups(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint16 group_ctrl, uint32 *groups_count, SAM_GROUP_ENUM **groups) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_get_group_by_sid(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID *groupsid, SAM_GROUP_HANDLE **group) +NTSTATUS sam_skel_get_group_by_sid(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID *groupsid, SAM_GROUP_HANDLE **group) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_get_group_by_name(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *name, SAM_GROUP_HANDLE **group) +NTSTATUS sam_skel_get_group_by_name(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, uint32 access_desired, const char *name, SAM_GROUP_HANDLE **group) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_add_member_to_group(const SAM_METHODS *sam_method, const SAM_GROUP_HANDLE *group, const SAM_GROUP_MEMBER *member) +NTSTATUS sam_skel_add_member_to_group(const SAM_METHODS *sam_methods, const SAM_GROUP_HANDLE *group, const SAM_GROUP_MEMBER *member) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_delete_member_from_group(const SAM_METHODS *sam_method, const SAM_GROUP_HANDLE *group, const SAM_GROUP_MEMBER *member) +NTSTATUS sam_skel_delete_member_from_group(const SAM_METHODS *sam_methods, const SAM_GROUP_HANDLE *group, const SAM_GROUP_MEMBER *member) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_enum_groupmembers(const SAM_METHODS *sam_method, const SAM_GROUP_HANDLE *group, uint32 *members_count, SAM_GROUP_MEMBER **members) +NTSTATUS sam_skel_enum_groupmembers(const SAM_METHODS *sam_methods, const SAM_GROUP_HANDLE *group, uint32 *members_count, SAM_GROUP_MEMBER **members) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_skel_get_groups_of_sid(const SAM_METHODS *sam_method, const NT_USER_TOKEN *access_token, const DOM_SID **sids, uint16 group_ctrl, uint32 *group_count, SAM_GROUP_ENUM **groups) +NTSTATUS sam_skel_get_groups_of_sid(const SAM_METHODS *sam_methods, const NT_USER_TOKEN *access_token, const DOM_SID **sids, uint16 group_ctrl, uint32 *group_count, SAM_GROUP_ENUM **groups) { DEBUG(0,("sam_skel: %s was called!\n",__FUNCTION__)); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS sam_init(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, const DOM_SID *domain, const char *module_params) +NTSTATUS sam_init(SAM_METHODS *sam_methods, const char *module_params) { - NTSTATUS nt_status; - - if (!NT_STATUS_IS_OK(nt_status = make_sam_methods(sam_context->mem_ctx, sam_method))) { - return nt_status; - } - - (*sam_method)->backendname = "sam_skel"; - /* Functions your SAM module doesn't provide should be set * to NULL */ - (*sam_method)->sam_get_sec_desc = sam_skel_get_sec_desc; - (*sam_method)->sam_set_sec_desc = sam_skel_set_sec_desc; + sam_methods->sam_get_sec_desc = sam_skel_get_sec_desc; + sam_methods->sam_set_sec_desc = sam_skel_set_sec_desc; - (*sam_method)->sam_lookup_sid = sam_skel_lookup_sid; - (*sam_method)->sam_lookup_name = sam_skel_lookup_name; + sam_methods->sam_lookup_sid = sam_skel_lookup_sid; + sam_methods->sam_lookup_name = sam_skel_lookup_name; /* Domain API */ - (*sam_method)->sam_update_domain = sam_skel_update_domain; - (*sam_method)->sam_get_domain_handle = sam_skel_get_domain_handle; + sam_methods->sam_update_domain = sam_skel_update_domain; + sam_methods->sam_get_domain_handle = sam_skel_get_domain_handle; /* Account API */ - (*sam_method)->sam_create_account = sam_skel_create_account; - (*sam_method)->sam_add_account = sam_skel_add_account; - (*sam_method)->sam_update_account = sam_skel_update_account; - (*sam_method)->sam_delete_account = sam_skel_delete_account; - (*sam_method)->sam_enum_accounts = sam_skel_enum_accounts; + sam_methods->sam_create_account = sam_skel_create_account; + sam_methods->sam_add_account = sam_skel_add_account; + sam_methods->sam_update_account = sam_skel_update_account; + sam_methods->sam_delete_account = sam_skel_delete_account; + sam_methods->sam_enum_accounts = sam_skel_enum_accounts; - (*sam_method)->sam_get_account_by_sid = sam_skel_get_account_by_sid; - (*sam_method)->sam_get_account_by_name = sam_skel_get_account_by_name; + sam_methods->sam_get_account_by_sid = sam_skel_get_account_by_sid; + sam_methods->sam_get_account_by_name = sam_skel_get_account_by_name; /* Group API */ - (*sam_method)->sam_create_group = sam_skel_create_group; - (*sam_method)->sam_add_group = sam_skel_add_group; - (*sam_method)->sam_update_group = sam_skel_update_group; - (*sam_method)->sam_delete_group = sam_skel_delete_group; - (*sam_method)->sam_enum_groups = sam_skel_enum_groups; - (*sam_method)->sam_get_group_by_sid = sam_skel_get_group_by_sid; - (*sam_method)->sam_get_group_by_name = sam_skel_get_group_by_name; + sam_methods->sam_create_group = sam_skel_create_group; + sam_methods->sam_add_group = sam_skel_add_group; + sam_methods->sam_update_group = sam_skel_update_group; + sam_methods->sam_delete_group = sam_skel_delete_group; + sam_methods->sam_enum_groups = sam_skel_enum_groups; + sam_methods->sam_get_group_by_sid = sam_skel_get_group_by_sid; + sam_methods->sam_get_group_by_name = sam_skel_get_group_by_name; - (*sam_method)->sam_add_member_to_group = sam_skel_add_member_to_group; - (*sam_method)->sam_delete_member_from_group = sam_skel_delete_member_from_group; - (*sam_method)->sam_enum_groupmembers = sam_skel_enum_groupmembers; + sam_methods->sam_add_member_to_group = sam_skel_add_member_to_group; + sam_methods->sam_delete_member_from_group = sam_skel_delete_member_from_group; + sam_methods->sam_enum_groupmembers = sam_skel_enum_groupmembers; - (*sam_method)->sam_get_groups_of_sid = sam_skel_get_groups_of_sid; + sam_methods->sam_get_groups_of_sid = sam_skel_get_groups_of_sid; - (*sam_method)->free_private_data = NULL; + sam_methods->free_private_data = NULL; sam_skel_debug_level = debug_add_class("sam_skel"); @@ -250,9 +242,9 @@ NTSTATUS sam_init(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, cons } else DEBUG(2, ("sam_skel: Debug class number of 'sam_skel': %d\n", sam_skel_debug_level)); if(module_params) - DEBUG(0, ("Starting 'sam_skel' with parameters '%s' for domain %s\n", module_params, sid_string_static(domain))); + DEBUG(0, ("Starting 'sam_skel' with parameters '%s' for domain %s\n", module_params, sam_methods->domain_name)); else - DEBUG(0, ("Starting 'sam_skel' for domain %s without paramters\n", sid_string_static(domain))); + DEBUG(0, ("Starting 'sam_skel' for domain %s without paramters\n", sam_methods->domain_name)); return NT_STATUS_OK; } diff --git a/source3/include/sam.h b/source3/include/sam.h index ca1a84fd97..4d18ec61b9 100644 --- a/source3/include/sam.h +++ b/source3/include/sam.h @@ -216,7 +216,8 @@ typedef struct sam_methods struct sam_methods *next; struct sam_methods *prev; const char *backendname; - struct sam_domain_handle *domain; + const char *domain_name; + DOM_SID domain_sid; void *private_data; /* General API */ @@ -262,7 +263,7 @@ typedef struct sam_methods void (*free_private_data)(void **); } SAM_METHODS; -typedef NTSTATUS (*sam_init_function)(const SAM_CONTEXT *, SAM_METHODS **, const DOM_SID *domain, const char *); +typedef NTSTATUS (*sam_init_function)(SAM_METHODS *, const char *); struct sam_init_function_entry { char *module_name; diff --git a/source3/sam/interface.c b/source3/sam/interface.c index 6668e3848d..6e6902ab3c 100644 --- a/source3/sam/interface.c +++ b/source3/sam/interface.c @@ -54,7 +54,7 @@ NTSTATUS sam_get_methods_by_sid(const SAM_CONTEXT *context, SAM_METHODS **sam_me tmp_methods = context->methods; while (tmp_methods) { - if (sid_equal(domainsid, &(tmp_methods->domain->private.sid))) + if (sid_equal(domainsid, &(tmp_methods->domain_sid))) { (*sam_method) = tmp_methods; return NT_STATUS_OK; @@ -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->private.name)) + if (strcmp(domainname, tmp_methods->domain_name)) { (*sam_method) = tmp_methods; return NT_STATUS_OK; @@ -162,7 +162,7 @@ NTSTATUS context_sam_lookup_name(const SAM_CONTEXT *context, const NT_USER_TOKEN if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_lookup_name(tmp_methods, access_token, name, sid, type))) { DEBUG(4,("sam_lookup_name for %s\\%s in backend %s failed\n", - tmp_methods->domain->private.name, name, tmp_methods->backendname)); + tmp_methods->domain_name, name, tmp_methods->backendname)); return nt_status; } @@ -278,9 +278,9 @@ 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->private.name, sid_string_static(&tmp_methods->domain->private.sid))); - sid_copy(domains[i],&tmp_methods->domain->private.sid); - if(asprintf(&(*domain_names[i]),"%s",tmp_methods->domain->private.name) < 0) { + 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)); @@ -321,8 +321,8 @@ NTSTATUS context_sam_lookup_domain(const SAM_CONTEXT *context, const NT_USER_TOK tmp_methods= context->methods; while (tmp_methods) { - if (strcmp(domain, tmp_methods->domain->private.name) == 0) { - sid_copy((*domainsid), &tmp_methods->domain->private.sid); + if (strcmp(domain, tmp_methods->domain_name) == 0) { + sid_copy((*domainsid), &tmp_methods->domain_sid); return NT_STATUS_OK; } tmp_methods= tmp_methods->next; @@ -495,7 +495,7 @@ NTSTATUS context_sam_enum_accounts(const SAM_CONTEXT *context, const NT_USER_TOK if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_enum_accounts(tmp_methods, access_token, acct_ctrl, account_count, accounts))) { DEBUG(4,("sam_enum_accounts for domain %s in backend %s failed\n", - tmp_methods->domain->private.name, tmp_methods->backendname)); + tmp_methods->domain_name, tmp_methods->backendname)); return nt_status; } @@ -701,7 +701,7 @@ NTSTATUS context_sam_enum_groups(const SAM_CONTEXT *context, const NT_USER_TOKEN if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_enum_groups(tmp_methods, access_token, group_ctrl, groups_count, groups))) { DEBUG(4,("sam_enum_groups for domain %s in backend %s failed\n", - tmp_methods->domain->private.name, tmp_methods->backendname)); + tmp_methods->domain_name, tmp_methods->backendname)); return nt_status; } @@ -969,13 +969,23 @@ static NTSTATUS make_backend_entry(SAM_BACKEND_ENTRY *backend_entry, char *sam_b create sam_methods struct based on sam_backend_entry *****************************************************************/ -static NTSTATUS make_sam_methods_backend_entry(SAM_CONTEXT *context, SAM_METHODS **methods, SAM_BACKEND_ENTRY *backend_entry) +static NTSTATUS make_sam_methods_backend_entry(SAM_CONTEXT *context, SAM_METHODS **methods_ptr, SAM_BACKEND_ENTRY *backend_entry) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + SAM_METHODS *methods; int i; - + DEBUG(5,("make_sam_methods_backend_entry: %d\n", __LINE__)); + if (!NT_STATUS_IS_OK(nt_status = make_sam_methods(context->mem_ctx, methods_ptr))) { + return nt_status; + } + + methods = *methods_ptr; + methods->backendname = talloc_strdup(context->mem_ctx, backend_entry->module_name); + methods->domain_name = talloc_strdup(context->mem_ctx, backend_entry->domain_name); + sid_copy(&methods->domain_sid, backend_entry->domain_sid); + methods->parent = context; DEBUG(5,("Attempting to find sam backend %s\n", backend_entry->module_name)); for (i = 0; builtin_sam_init_functions[i].module_name; i++) @@ -984,7 +994,7 @@ static NTSTATUS make_sam_methods_backend_entry(SAM_CONTEXT *context, SAM_METHODS { DEBUG(5,("Found sam backend %s (at pos %d)\n", backend_entry->module_name, i)); DEBUGADD(5,("initialising it with options=%s for domain %s\n", backend_entry->module_params, sid_string_static(backend_entry->domain_sid))); - nt_status = builtin_sam_init_functions[i].init(context, methods, backend_entry->domain_sid, backend_entry->module_params); + nt_status = builtin_sam_init_functions[i].init(methods, backend_entry->module_params); if (NT_STATUS_IS_OK(nt_status)) { DEBUG(5,("sam backend %s has a valid init\n", backend_entry->module_name)); } else { @@ -1030,7 +1040,6 @@ static NTSTATUS sam_context_check_default_backends(SAM_CONTEXT *context) return ntstatus; } - methods->parent = context; DLIST_ADD_END(context->methods, methods, tmpmethods); } else if (!NT_STATUS_IS_OK(ntstatus)) { @@ -1056,7 +1065,6 @@ static NTSTATUS sam_context_check_default_backends(SAM_CONTEXT *context) return ntstatus; } - methods->parent = context; DLIST_ADD_END(context->methods, methods, tmpmethods); } else if (!NT_STATUS_IS_OK(ntstatus)) { DEBUG(2, ("sam_get_methods_by_sid failed for BUILTIN\n")); @@ -1138,7 +1146,6 @@ NTSTATUS make_sam_context_list(SAM_CONTEXT **context, char **sam_backends_param) free_sam_context(context); return nt_status; } - curmethods->parent = *context; DLIST_ADD_END((*context)->methods, curmethods, tmpmethods); } diff --git a/source3/sam/sam_plugin.c b/source3/sam/sam_plugin.c index 9d2ee937ef..fd26c4b8d3 100644 --- a/source3/sam/sam_plugin.c +++ b/source3/sam/sam_plugin.c @@ -25,7 +25,7 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_SAM -NTSTATUS sam_init_plugin(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, const DOM_SID *domain, const char *module_params) +NTSTATUS sam_init_plugin(SAM_METHODS *sam_methods, const char *module_params) { void *dl_handle; char *plugin_params, *plugin_name, *p; @@ -74,6 +74,6 @@ NTSTATUS sam_init_plugin(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_metho return NT_STATUS_UNSUCCESSFUL; } - DEBUG(5, ("Starting sam plugin %s with parameters %s for domain %s\n", plugin_name, plugin_params, sid_string_static(domain))); - return plugin_init(sam_context, sam_method, domain, plugin_params); + DEBUG(5, ("Starting sam plugin %s with parameters %s for domain %s\n", plugin_name, plugin_params, sam_methods->domain_name)); + return plugin_init(sam_methods, plugin_params); } diff --git a/source3/torture/cmd_sam.c b/source3/torture/cmd_sam.c index a2835ed69a..2b4c21e501 100644 --- a/source3/torture/cmd_sam.c +++ b/source3/torture/cmd_sam.c @@ -22,27 +22,7 @@ #include "includes.h" #include "samtest.h" -#if 0 -static struct cmd_popt_user_opts [] = { - { NULL, 0, POPT_ARG_CALLBACK, cmd_parse_user_opts }, - {"username", 'u', POPT_ARG_STRING, NULL, 1, "Username to use"}, -}; - -static void cmd_parse_user_opts(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) -{ - SAM_ACCOUNT_HANDLE *account = (SAM_ACCOUNT_HANDLE *)data; - switch(opt->val) { - case 'u': - sam_set_account_username(account, arg); - break; - } -} -#endif - -static NTSTATUS cmd_load_module(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_load_module(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { char *plugin_arg[2]; NTSTATUS status; @@ -54,132 +34,158 @@ static NTSTATUS cmd_load_module(struct sam_context *c, TALLOC_CTX *mem_ctx, int asprintf(&plugin_arg[0], "plugin:%s", argv[1]); plugin_arg[1] = NULL; - if(!NT_STATUS_IS_OK(status = make_sam_context_list(&c, plugin_arg))) - { + if(!NT_STATUS_IS_OK(status = make_sam_context_list(&st->context, plugin_arg))) { + free(plugin_arg[0]); return status; } + + free(plugin_arg[0]); + printf("load: ok\n"); return NT_STATUS_OK; } -static NTSTATUS cmd_get_sec_desc(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_get_sec_desc(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_set_sec_desc(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_set_sec_desc(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_sid(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { - return NT_STATUS_NOT_IMPLEMENTED; + char *name; + uint32 type; + NTSTATUS status; + DOM_SID sid; + if(argc != 2) { + printf("Usage: lookup_sid <sid>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!string_to_sid(&sid, argv[1])){ + printf("Unparseable SID specified!\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + 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; + } + + return NT_STATUS_OK; } -static NTSTATUS cmd_lookup_name(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +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"); + return NT_STATUS_INVALID_PARAMETER; + } return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_update_domain(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_update_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_show_domain(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_show_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_create_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_create_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_update_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_update_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_delete_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_delete_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_enum_accounts(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_enum_accounts(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_account_sid(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_account_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_account_name(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_account_name(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_create_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_create_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_update_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_update_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_delete_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_delete_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_enum_groups(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_enum_groups(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_group_sid(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_group_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_lookup_group_name(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_lookup_group_name(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_group_add_member(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_group_add_member(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_group_del_member(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_group_del_member(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_group_enum(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_group_enum(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } -static NTSTATUS cmd_get_sid_groups(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_get_sid_groups(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { return NT_STATUS_NOT_IMPLEMENTED; } diff --git a/source3/torture/samtest.c b/source3/torture/samtest.c index 0275e0f002..e68ff5a0bf 100644 --- a/source3/torture/samtest.c +++ b/source3/torture/samtest.c @@ -54,7 +54,7 @@ static char* next_command (char** cmdstr) } /* Display help on commands */ -static NTSTATUS cmd_help(struct sam_context *sam, TALLOC_CTX *mem_ctx, +static NTSTATUS cmd_help(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { struct cmd_list *tmp; @@ -112,7 +112,7 @@ static NTSTATUS cmd_help(struct sam_context *sam, TALLOC_CTX *mem_ctx, } /* Change the debug level */ -static NTSTATUS cmd_debuglevel(struct sam_context *sam, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_debuglevel(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { if (argc > 2) { printf("Usage: %s [debuglevel]\n", argv[0]); @@ -128,7 +128,7 @@ static NTSTATUS cmd_debuglevel(struct sam_context *sam, TALLOC_CTX *mem_ctx, int return NT_STATUS_OK; } -static NTSTATUS cmd_quit(struct sam_context *sam, TALLOC_CTX *mem_ctx, int argc, char **argv) +static NTSTATUS cmd_quit(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) { /* Cleanup */ talloc_destroy(mem_ctx); @@ -185,7 +185,7 @@ static void add_command_set(struct cmd_set *cmd_set) DLIST_ADD(cmd_list, entry); } -static NTSTATUS do_cmd(struct sam_context *sam, struct cmd_set *cmd_entry, char *cmd) +static NTSTATUS do_cmd(struct samtest_state *st, struct cmd_set *cmd_entry, char *cmd) { char *p = cmd, **argv = NULL; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -237,7 +237,7 @@ static NTSTATUS do_cmd(struct sam_context *sam, struct cmd_set *cmd_entry, char } /* Run command */ - result = cmd_entry->fn(sam, mem_ctx, argc, argv); + result = cmd_entry->fn(st, mem_ctx, argc, argv); } else { fprintf (stderr, "Invalid command\n"); @@ -259,7 +259,7 @@ static NTSTATUS do_cmd(struct sam_context *sam, struct cmd_set *cmd_entry, char } /* Process a command entered at the prompt or as part of -c */ -static NTSTATUS process_cmd(struct sam_context *sam, char *cmd) +static NTSTATUS process_cmd(struct samtest_state *st, char *cmd) { struct cmd_list *temp_list; BOOL found = False; @@ -288,7 +288,7 @@ static NTSTATUS process_cmd(struct sam_context *sam, char *cmd) while(temp_set->name) { if (strequal(buf, temp_set->name)) { found = True; - result = do_cmd(sam, temp_set, cmd); + result = do_cmd(st, temp_set, cmd); goto done; } @@ -339,7 +339,7 @@ int main(int argc, char *argv[]) pstring logfile; struct cmd_set **cmd_set; extern BOOL AllowDebugChange; - static struct sam_context sam; + struct samtest_state st; /* make sure the vars that get altered (4th field) are in @@ -353,6 +353,8 @@ int main(int argc, char *argv[]) { 0, 0, 0, 0} }; + ZERO_STRUCT(st); + setlinebuf(stdout); DEBUGLEVEL = 1; @@ -397,7 +399,7 @@ int main(int argc, char *argv[]) char *p = cmdstr; while((cmd=next_command(&p)) != NULL) { - process_cmd(&sam, cmd); + process_cmd(&st, cmd); } return 0; @@ -417,7 +419,7 @@ int main(int argc, char *argv[]) break; if (line[0] != '\n') - process_cmd(&sam, line); + process_cmd(&st, line); } return 0; diff --git a/source3/torture/samtest.h b/source3/torture/samtest.h index 2a8516cfc3..a136ab191e 100644 --- a/source3/torture/samtest.h +++ b/source3/torture/samtest.h @@ -22,10 +22,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +struct samtest_state { + SAM_CONTEXT *context; + NT_USER_TOKEN *token; +}; + struct cmd_set { char *name; - NTSTATUS (*fn)(struct sam_context *sam, TALLOC_CTX *mem_ctx, int argc, + NTSTATUS (*fn)(struct samtest_state *sam, TALLOC_CTX *mem_ctx, int argc, char **argv); char *description; char *usage; }; + + |