lp_sam_backend
Kai Krueger
kai at kruegernetz.de
Sat Sep 7 09:55:01 GMT 2002
Hi,
This patch is a combination of patches to the sam.
1.) change sam_init() to include a domain sid as an in parameter. It is
used to tell the backend module for which domain it is responsible.
2.) implement the rest of the context_sam_* functions
3.) several style and debug cleanups
4.) change the loading routines of the sam backend parameter from
smb.conf. The format is now sam backend =
sam_moduleA[,domain_nameA][:options]
sam_moduleB[,domain_nameB][:options] [sam_moduleB,builtin_domain[:options]]
The patch compiles, but is untested so any coments are welcome.
Kai
-------------- next part --------------
Index: examples/sam/sam_skel.c
===================================================================
RCS file: /cvsroot/samba/examples/sam/sam_skel.c,v
retrieving revision 1.3
diff -u -r1.3 sam_skel.c
--- examples/sam/sam_skel.c 6 Sep 2002 13:00:37 -0000 1.3
+++ examples/sam/sam_skel.c 7 Sep 2002 09:49:26 -0000
@@ -189,7 +189,7 @@
return NT_STATUS_NOT_IMPLEMENTED;
}
-NTSTATUS sam_init(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, const char *location)
+NTSTATUS sam_init(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, const DOM_SID *domain, const char *module_params)
{
NTSTATUS nt_status;
@@ -250,8 +250,8 @@
} else DEBUG(0, ("sam_skel: Debug class number of 'sam_skel': %d\n", sam_skel_debug_level));
DEBUG(0, ("Initializing sam_skel\n"));
- if (location)
- DEBUG(10, ("Location: %s\n", location));
+ if (module_params)
+ DEBUG(10, ("Module parameters for the domain %s: %s\n", sid_string_static(domain), module_params));
return NT_STATUS_OK;
}
Index: source/include/sam.h
===================================================================
RCS file: /cvsroot/samba/source/include/sam.h,v
retrieving revision 1.6
diff -u -r1.6 sam.h
--- source/include/sam.h 6 Sep 2002 13:00:37 -0000 1.6
+++ source/include/sam.h 7 Sep 2002 09:49:27 -0000
@@ -259,13 +259,20 @@
void (*free_private_data)(void **);
} SAM_METHODS;
-typedef NTSTATUS (*sam_init_function)(const SAM_CONTEXT *, SAM_METHODS **, const char *);
+typedef NTSTATUS (*sam_init_function)(const SAM_CONTEXT *, SAM_METHODS **, const DOM_SID *domain, const char *);
struct sam_init_function_entry {
- char *name;
+ char *module_name;
/* Function to create a member of the sam_methods list */
sam_init_function init;
};
+
+typedef struct sam_backend_entry {
+ char *module_name;
+ char *module_params;
+ char *domain_name;
+ DOM_SID *domain_sid;
+} SAM_BACKEND_ENTRY;
#endif /* _SAM_H */
Index: source/sam/interface.c
===================================================================
RCS file: /cvsroot/samba/source/sam/interface.c,v
retrieving revision 1.7
diff -u -r1.7 interface.c
--- source/sam/interface.c 6 Sep 2002 13:21:54 -0000 1.7
+++ source/sam/interface.c 7 Sep 2002 09:49:30 -0000
@@ -26,6 +26,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_SAM
+extern DOM_SID global_sid_Builtin;
+
/** List of various built-in sam modules */
const struct sam_init_function_entry builtin_sam_init_functions[] = {
@@ -53,8 +55,7 @@
tmp_methods = context->methods;
- while (tmp_methods)
- {
+ while (tmp_methods) {
if (sid_equal(domainsid, &(tmp_methods->domain->private.sid)))
{
(*sam_method) = tmp_methods;
@@ -79,8 +80,7 @@
tmp_methods = context->methods;
- while (tmp_methods)
- {
+ while (tmp_methods) {
if (strcmp(domainname, tmp_methods->domain->private.name))
{
(*sam_method) = tmp_methods;
@@ -99,7 +99,7 @@
SAM_METHODS *tmp_methods;
NTSTATUS nt_status;
- DEBUG(5,("context_sam_get_sec_desc: %d\n", __LINE__));
+ DEBUG(5,("context_sam_get_sec_desc: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_methods_by_sid(context, &tmp_methods, sid))) {
DEBUG(4,("sam_get_methods_by_sid failed\n"));
@@ -112,7 +112,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_sec_desc(tmp_methods, access_token, sid, sd))) {
- DEBUG(4,("context_sam_get_sec_desc for %s in backend %s failed\n", sid_string_static(sid), tmp_methods->backendname));
+ DEBUG(4,("sam_get_sec_desc for %s in backend %s failed\n", sid_string_static(sid), tmp_methods->backendname));
return nt_status;
}
@@ -125,7 +125,7 @@
NTSTATUS nt_status;
DEBUG(5,("context_sam_set_sec_desc: %d\n", __LINE__));
-
+
if (!NT_STATUS_IS_OK(nt_status = sam_get_methods_by_sid(context, &tmp_methods, sid))) {
DEBUG(4,("sam_get_methods_by_sid failed\n"));
return nt_status;
@@ -137,7 +137,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_set_sec_desc(tmp_methods, access_token, sid, sd))) {
- DEBUG(4,("context_sam_set_sec_desc for %s in backend %s failed\n", sid_string_static(sid), tmp_methods->backendname));
+ DEBUG(4,("sam_set_sec_desc for %s in backend %s failed\n", sid_string_static(sid), tmp_methods->backendname));
return nt_status;
}
@@ -163,7 +163,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_lookup_name(tmp_methods, access_token, name, sid, type))) {
- DEBUG(4,("context_sam_lookup_name for %s\\%s in backend %s failed\n",
+ DEBUG(4,("sam_lookup_name for %s\\%s in backend %s failed\n",
tmp_methods->domain->private.name, name, tmp_methods->backendname));
return nt_status;
}
@@ -197,7 +197,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_lookup_sid(tmp_methods, access_token, sid, name, type))) {
- DEBUG(4,("context_sam_lookup_name for %s in backend %s failed\n",
+ DEBUG(4,("sam_lookup_name for %s in backend %s failed\n",
sid_string_static(sid), tmp_methods->backendname));
return nt_status;
}
@@ -238,8 +238,7 @@
tmp_methods= context->methods;
- while (tmp_methods)
- {
+ while (tmp_methods) {
(*domain_count)++;
tmp_methods= tmp_methods->next;
}
@@ -259,9 +258,7 @@
return NT_STATUS_NO_MEMORY;
}
- while (tmp_methods)
- {
-
+ 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) {
@@ -273,7 +270,6 @@
i++;
tmp_methods= tmp_methods->next;
-
}
return NT_STATUS_OK;
@@ -305,8 +301,7 @@
tmp_methods= context->methods;
- while (tmp_methods)
- {
+ while (tmp_methods) {
if (strcmp(domain, tmp_methods->domain->private.name) == 0) {
sid_copy((*domainsid), &tmp_methods->domain->private.sid);
return NT_STATUS_OK;
@@ -336,7 +331,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_domain_handle(tmp_methods, access_token, access_desired, domain))) {
- DEBUG(4,("context_sam_get_domain_by_sid for %s in backend %s failed\n",
+ DEBUG(4,("sam_get_domain_handle for %s in backend %s failed\n",
sid_string_static(domainsid), tmp_methods->backendname));
return nt_status;
}
@@ -362,7 +357,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_create_account(tmp_methods, access_token, access_desired, account_name, acct_ctrl, account))) {
- DEBUG(4,("context_sam_create_account in backend %s failed\n",
+ DEBUG(4,("sam_create_account in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -377,6 +372,8 @@
SAM_METHODS *tmp_methods;
uint32 rid;
NTSTATUS nt_status;
+
+ DEBUG(5,("context_sam_add_account: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_account_sid(account, &accountsid))) {
DEBUG(0,("Can't get account SID\n"));
@@ -400,7 +397,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_add_account(tmp_methods, account))){
- DEBUG(4,("context_sam_add_account in backend %s failed\n",
+ DEBUG(4,("sam_add_account in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -415,6 +412,8 @@
const DOM_SID *accountsid;
uint32 rid;
NTSTATUS nt_status;
+
+ DEBUG(5,("context_sam_update_account: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_account_sid(account, &accountsid))) {
DEBUG(0,("Can't get account SID\n"));
@@ -438,7 +437,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_update_account(tmp_methods, account))){
- DEBUG(4,("context_sam_update_account in backend %s failed\n",
+ DEBUG(4,("sam_update_account in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -453,6 +452,8 @@
const DOM_SID *accountsid;
uint32 rid;
NTSTATUS nt_status;
+
+ DEBUG(5,("context_sam_delete_account: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_account_sid(account, &accountsid))) {
DEBUG(0,("Can't get account SID\n"));
@@ -476,7 +477,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_delete_account(tmp_methods, account))){
- DEBUG(4,("context_sam_delete_account in backend %s failed\n",
+ DEBUG(4,("sam_delete_account in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -502,7 +503,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_enum_accounts(tmp_methods, access_token, acct_ctrl, account_count, accounts))) {
- DEBUG(4,("context_sam_enum_accounts for domain %s in backend %s failed\n",
+ DEBUG(4,("sam_enum_accounts for domain %s in backend %s failed\n",
tmp_methods->domain->private.name, tmp_methods->backendname));
return nt_status;
}
@@ -538,7 +539,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_account_by_sid(tmp_methods, access_token, access_desired, accountsid, account))) {
- DEBUG(4,("context_sam_get_account_by_sid for %s in backend %s failed\n",
+ DEBUG(4,("sam_get_account_by_sid for %s in backend %s failed\n",
sid_string_static(accountsid), tmp_methods->backendname));
return nt_status;
}
@@ -564,7 +565,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_account_by_name(tmp_methods, access_token, access_desired, name, account))) {
- DEBUG(4,("context_sam_get_account_by_name for %s\\%s in backend %s failed\n",
+ DEBUG(4,("sam_get_account_by_name for %s\\%s in backend %s failed\n",
domain, name, tmp_methods->backendname));
return nt_status;
}
@@ -590,7 +591,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_create_group(tmp_methods, access_token, access_desired, group_name, group_ctrl, group))) {
- DEBUG(4,("context_sam_create_group in backend %s failed\n",
+ DEBUG(4,("sam_create_group in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -605,6 +606,8 @@
SAM_METHODS *tmp_methods;
uint32 rid;
NTSTATUS nt_status;
+
+ DEBUG(5,("context_sam_add_group: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_group_sid(group, &groupsid))) {
DEBUG(0,("Can't get group SID\n"));
@@ -628,7 +631,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_add_group(tmp_methods, group))){
- DEBUG(4,("context_sam_add_group in backend %s failed\n",
+ DEBUG(4,("sam_add_group in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -643,6 +646,8 @@
struct sam_methods *tmp_methods;
uint32 rid;
NTSTATUS nt_status;
+
+ DEBUG(5,("context_sam_update_group: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_group_sid(group, &groupsid))) {
DEBUG(0,("Can't get group SID\n"));
@@ -666,7 +671,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_update_group(tmp_methods, group))){
- DEBUG(4,("context_sam_update_group in backend %s failed\n",
+ DEBUG(4,("sam_update_group in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -681,6 +686,8 @@
const DOM_SID *groupsid;
uint32 rid;
NTSTATUS nt_status;
+
+ DEBUG(5,("context_sam_delete_group: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(nt_status = sam_get_group_sid(group, &groupsid))) {
DEBUG(0,("Can't get group SID\n"));
@@ -704,7 +711,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_delete_group(tmp_methods, group))){
- DEBUG(4,("context_sam_delete_group in backend %s failed\n",
+ DEBUG(4,("sam_delete_group in backend %s failed\n",
tmp_methods->backendname));
return nt_status;
}
@@ -730,7 +737,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_enum_groups(tmp_methods, access_token, group_ctrl, groups_count, groups))) {
- DEBUG(4,("context_sam_enum_groups for domain %s in backend %s failed\n",
+ DEBUG(4,("sam_enum_groups for domain %s in backend %s failed\n",
tmp_methods->domain->private.name, tmp_methods->backendname));
return nt_status;
}
@@ -765,7 +772,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_group_by_sid(tmp_methods, access_token, access_desired, groupsid, group))) {
- DEBUG(4,("context_sam_get_group_by_sid for %s in backend %s failed\n",
+ DEBUG(4,("sam_get_group_by_sid for %s in backend %s failed\n",
sid_string_static(groupsid), tmp_methods->backendname));
return nt_status;
}
@@ -791,7 +798,7 @@
}
if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_group_by_name(tmp_methods, access_token, access_desired, name, group))) {
- DEBUG(4,("context_sam_get_group_by_name for %s\\%s in backend %s failed\n",
+ DEBUG(4,("sam_get_group_by_name for %s\\%s in backend %s failed\n",
domain, name, tmp_methods->backendname));
return nt_status;
}
@@ -801,21 +808,136 @@
NTSTATUS context_sam_add_member_to_group(const SAM_CONTEXT *context, const SAM_GROUP_HANDLE *group, const SAM_GROUP_MEMBER *member)
{
- return NT_STATUS_NOT_IMPLEMENTED;
+ SAM_METHODS *tmp_methods;
+ NTSTATUS nt_status;
+
+ if (!group) {
+ DEBUG(3,("context_sam_add_member_to_group: \n"));
+ return NT_STATUS_NO_SUCH_GROUP;
+ }
+
+ if ((tmp_methods = group->current_sam_methods) == NULL) {
+ DEBUG(0,("SAM_GROUP_HANDLE has invalid (NULL) SAM_METHODS struct\n"));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (!tmp_methods->sam_add_member_to_group) {
+ DEBUG(3, ("context_sam_add_member_to_group: sam_methods of the domain did not specify sam_add_member_to_group\n"));
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_add_member_to_group(tmp_methods, group, member))) {
+ DEBUG(4,("sam_add_member_to_group in backend %s failed\n", tmp_methods->backendname));
+ return nt_status;
+ }
+
+ return NT_STATUS_OK;
+
}
+
NTSTATUS context_sam_delete_member_from_group(const SAM_CONTEXT *context, const SAM_GROUP_HANDLE *group, const SAM_GROUP_MEMBER *member)
{
- return NT_STATUS_NOT_IMPLEMENTED;
+ SAM_METHODS *tmp_methods;
+ NTSTATUS nt_status;
+
+ if (!group) {
+ DEBUG(3,("context_sam_delete_member_from_group: \n"));
+ return NT_STATUS_NO_SUCH_GROUP;
+ }
+
+ if ((tmp_methods = group->current_sam_methods) == NULL) {
+ DEBUG(0,("SAM_GROUP_HANDLE has invalid (NULL) SAM_METHODS struct\n"));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (!tmp_methods->sam_delete_member_from_group) {
+ DEBUG(3, ("context_sam_delete_member_from_group: sam_methods of the domain did not specify sam_delete_member_from_group\n"));
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_delete_member_from_group(tmp_methods, group, member))) {
+ DEBUG(4,("sam_delete_member_from_group in backend %s failed\n", tmp_methods->backendname));
+ return nt_status;
+ }
+
+ return NT_STATUS_OK;
}
NTSTATUS context_sam_enum_groupmembers(const SAM_CONTEXT *context, const SAM_GROUP_HANDLE *group, uint32 *members_count, SAM_GROUP_MEMBER **members)
{
- return NT_STATUS_NOT_IMPLEMENTED;
+ SAM_METHODS *tmp_methods;
+ NTSTATUS nt_status;
+
+ if (!group) {
+ DEBUG(3,("context_sam_enum_groupmembers: \n"));
+ return NT_STATUS_NO_SUCH_GROUP;
+ }
+
+ if ((tmp_methods = group->current_sam_methods) == NULL) {
+ DEBUG(0,("SAM_GROUP_HANDLE has invalid (NULL) SAM_METHODS struct\n"));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (!tmp_methods->sam_enum_groupmembers) {
+ DEBUG(3, ("context_sam_enum_groupmembers: sam_methods of the domain did not specify sam_enum_group_members\n"));
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_enum_groupmembers(tmp_methods, group, members_count, members))) {
+ DEBUG(4,("sam_enum_groupmembers in backend %s failed\n", tmp_methods->backendname));
+ return nt_status;
+ }
+
+ return NT_STATUS_OK;
}
-NTSTATUS context_sam_get_groups_of_sid(const SAM_CONTEXT *context, const DOM_SID **sids, uint16 group_ctrl, uint32 *group_count, SAM_GROUP_ENUM **groups)
+NTSTATUS context_sam_get_groups_of_sid(const SAM_CONTEXT *context, const NT_USER_TOKEN *access_token, const DOM_SID **sids, uint16 group_ctrl, uint32 *group_count, SAM_GROUP_ENUM **groups)
{
- return NT_STATUS_NOT_IMPLEMENTED;
+ SAM_METHODS *tmp_methods;
+ NTSTATUS nt_status;
+
+ uint32 tmp_group_count;
+ SAM_GROUP_ENUM *tmp_groups;
+
+
+
+ DEBUG(5,("context_sam_get_groups_of_sid: %d\n", __LINE__));
+
+ /* invalid sam_context specified */
+ SAM_ASSERT(context && context->methods);
+
+ *group_count = 0;
+
+ *groups = NULL;
+
+ tmp_methods= context->methods;
+
+ while (tmp_methods) {
+ DEBUG(5,("getting groups from domain \n"));
+ if (!tmp_methods->sam_get_groups_of_sid) {
+ DEBUG(3, ("context_sam_get_groups_of_sid: sam_methods of domain did not specify sam_get_groups_of_sid\n"));
+ SAFE_FREE(*groups);
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ if (!NT_STATUS_IS_OK(nt_status = tmp_methods->sam_get_groups_of_sid(tmp_methods, access_token, sids, group_ctrl, &tmp_group_count, &tmp_groups))) {
+ DEBUG(4,("sam_get_groups_of_sid in backend %s failed\n", tmp_methods->backendname));
+ SAFE_FREE(*groups);
+ return nt_status;
+ }
+
+ *groups = Realloc(*groups, ((*group_count) + tmp_group_count) * sizeof(SAM_GROUP_ENUM));
+
+ memcpy(&(*groups)[*group_count], tmp_groups, tmp_group_count);
+
+ SAFE_FREE(tmp_groups);
+
+ *group_count += tmp_group_count;
+
+ tmp_methods = tmp_methods->next;
+ }
+
+ return NT_STATUS_OK;
}
@@ -828,7 +950,7 @@
{
SAM_METHODS *sam_selected = (*context)->methods;
- while (sam_selected){
+ while (sam_selected) {
if (sam_selected->free_private_data) {
sam_selected->free_private_data(&(sam_selected->private_data));
}
@@ -842,71 +964,188 @@
/******************************************************************
Make a sam_methods from scratch
*******************************************************************/
+
+static NTSTATUS make_backend_entry(SAM_BACKEND_ENTRY *backend_entry, char *sam_backend_string)
+{
+ char *tmp = NULL;
+ char *tmp_string = sam_backend_string;
+
+ if (sam_backend_string == NULL)
+ return NT_STATUS_INVALID_PARAMETER;
-NTSTATUS make_sam_context_list(SAM_CONTEXT **context, char **selected)
+ backend_entry->module_name = sam_backend_string;
+
+ if ((tmp = strchr(tmp_string, ',')) != NULL) {
+ *tmp = 0;
+ backend_entry->domain_name = tmp + 1;
+ tmp_string = tmp + 1;
+ }
+
+ if ((tmp = strchr(tmp_string, ':')) != NULL) {
+ *tmp = 0;
+ backend_entry->module_params = tmp + 1;
+ tmp_string = tmp + 1;
+ }
+
+ if (backend_entry->domain_name == NULL) {
+ DEBUG(5,("make_backend_entry: no domain was specified for sam module %s. Useing default domain %s\n",
+ backend_entry->module_name, lp_workgroup()));
+ backend_entry->domain_name = lp_workgroup();
+ }
+
+ if (!secrets_fetch_domain_sid(backend_entry->domain_name, backend_entry->domain_sid)) {
+ DEBUG(2,("make_backend_entry: There is no SID stored for domain %s. Creating a new one.\n",
+ backend_entry->domain_name));
+ /* FIXME */
+ }
+
+ DEBUG(5,("make_backend_entry: module name: %s, module parameters: %s, domain name: %s, domain sid: %s\n",
+ backend_entry->module_name, backend_entry->module_params, backend_entry->domain_name, sid_string_static(backend_entry->domain_sid)));
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS check_correct_backend_entries(SAM_BACKEND_ENTRY **backend_entries, int *nBackends)
{
- int i = 0;
- SAM_METHODS *curmethods, *tmpmethods;
- NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
+ BOOL has_builtin = False;
+ BOOL has_workgroup = False;
+ DOM_SID *global_sam_sid = get_global_sam_sid(); /* lp_workgroup doesn't play nicely with multiple domains */
+ int increase_by = 0;
+ int i, j;
+
+ for (i = 0; i < *nBackends; i++) {
+ if (sid_equal((*backend_entries)[i].domain_sid, &global_sid_Builtin))
+ has_builtin = True;
+ if (sid_equal((*backend_entries)[i].domain_sid, global_sam_sid))
+ has_workgroup = True;
+ for (j = i; j < *nBackends; j++) {
+ if (sid_equal((*backend_entries)[i].domain_sid, (*backend_entries)[j].domain_sid)) {
+ DEBUG(2,("two backend modules claim the same domain %s",
+ sid_string_static((*backend_entries)[j].domain_sid)));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ }
+ }
+
+ if (!has_workgroup) increase_by++;
+ if (!has_builtin) increase_by++;
+
+ if (increase_by > 0) {
+ *nBackends += increase_by;
- if (!NT_STATUS_IS_OK(nt_status = make_sam_context(context))) {
- return nt_status;
- }
- while (selected[i]){
- /* Try to initialise sam */
- DEBUG(5,("Trying to load: %s\n", selected[i]));
- if (!NT_STATUS_IS_OK(nt_status = make_sam_methods_name(&curmethods, *context, selected[i]))) {
- DEBUG(1, ("Loading %s failed!\n", selected[i]));
- free_sam_context(context);
- return nt_status;
+ (*backend_entries) = (SAM_BACKEND_ENTRY *)realloc((*backend_entries), sizeof(SAM_BACKEND_ENTRY) * (*nBackends));
+ if (!has_workgroup) {
+ /* should be replaced by the default sam module */
+ DEBUG(4,("There was no backend specified for domain %s useing sam_default\n",
+ lp_workgroup()));
+ (*backend_entries)[i].module_name = "sam_default";
+ (*backend_entries)[i].module_params = NULL;
+ (*backend_entries)[i].domain_name = lp_workgroup();
+ (*backend_entries)[i].domain_sid = global_sam_sid;
+ i++;
}
- curmethods->parent = *context;
- DLIST_ADD_END((*context)->methods, curmethods, tmpmethods);
- i++;
- }
- return NT_STATUS_OK;
+ if (!has_workgroup) {
+ /* should be replaced by the default sam module */
+ DEBUG(4,("There was no backend specified for domain BUILTIN useing sam_builtin\n"));
+ (*backend_entries)[i].module_name = "sam_builtin";
+ (*backend_entries)[i].module_params = NULL;
+ (*backend_entries)[i].domain_name = lp_workgroup();
+ (*backend_entries)[i].domain_sid = global_sam_sid;
+ i++;
+ }
+
+ }
+
+ return NT_STATUS_OK;
}
-NTSTATUS make_sam_methods_name(SAM_METHODS **methods, SAM_CONTEXT *context, const char *selected)
+static NTSTATUS make_sam_methods_backend_entry(SAM_CONTEXT *context, SAM_METHODS **methods, SAM_BACKEND_ENTRY *backend_entry)
{
- char *module_name = smb_xstrdup(selected);
- char *module_location = NULL, *p;
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
int i;
- p = strchr(module_name, ':');
- if (p) {
- *p = 0;
- module_location = p+1;
- trim_string(module_location, " ", " ");
- }
-
- trim_string(module_name, " ", " ");
-
- DEBUG(5,("Attempting to find an sam backend to match %s (%s)\n", selected, module_name));
- for (i = 0; builtin_sam_init_functions[i].name; i++)
+ DEBUG(5,("Attempting to find sam backend %s\n", backend_entry->module_name));
+ for (i = 0; builtin_sam_init_functions[i].module_name; i++)
{
- if (strequal(builtin_sam_init_functions[i].name, module_name))
+ if (strequal(builtin_sam_init_functions[i].module_name, backend_entry->module_name))
{
- DEBUG(5,("Found sam backend %s (at pos %d)\n", module_name, i));
- nt_status = builtin_sam_init_functions[i].init(context, methods, module_location);
+ DEBUG(5,("Found sam backend %s (at pos %d)\n", backend_entry->module_name, i));
+ nt_status = builtin_sam_init_functions[i].init(context, methods, backend_entry->domain_sid, backend_entry->module_params);
if (NT_STATUS_IS_OK(nt_status)) {
- DEBUG(5,("sam backend %s has a valid init\n", selected));
+ DEBUG(5,("sam backend %s has a valid init\n", backend_entry->module_name));
} else {
- DEBUG(0,("sam backend %s did not correctly init (error was %s)\n", selected, nt_errstr(nt_status)));
+ DEBUG(2,("sam backend %s did not correctly init (error was %s)\n",
+ backend_entry->module_name, nt_errstr(nt_status)));
}
- SAFE_FREE(module_name);
return nt_status;
break; /* unreached */
}
}
+
+ DEBUG(2,("could not find backend %s\n", backend_entry->module_name));
- /* No such backend found */
- SAFE_FREE(module_name);
return NT_STATUS_INVALID_PARAMETER;
}
+
+
+
+NTSTATUS make_sam_context_conf(SAM_CONTEXT **context)
+{
+ int i = 0;
+ SAM_METHODS *curmethods, *tmpmethods;
+ char **sam_backends_param = lp_sam_backend();
+ int nBackends = 0;
+ SAM_BACKEND_ENTRY *backends = NULL;
+ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
+
+ DEBUG(5,("make_sam_context_from_conf: %d\n", __LINE__));
+
+ if (!NT_STATUS_IS_OK(nt_status = make_sam_context(context))) {
+ DEBUG(4,("make_sam_context failed\n"));
+ return nt_status;
+ }
+
+ while (sam_backends_param[nBackends])
+ nBackends++;
+
+ DEBUG(6,("There are %d domains listed with there backends\n", nBackends));
+
+ backends = malloc(sizeof(SAM_BACKEND_ENTRY)*nBackends);
+ ZERO_STRUCT(backends);
+
+ for (i = 0; i < nBackends; i++) {
+ if (!NT_STATUS_IS_OK(nt_status = make_backend_entry(&backends[i], sam_backends_param[i]))) {
+ DEBUG(4,("make_backend_entry failed\n"));
+ SAFE_FREE(backends);
+ free_sam_context(context);
+ return nt_status;
+ }
+ }
+
+ if (!NT_STATUS_IS_OK(nt_status = check_correct_backend_entries(&backends, &nBackends))) {
+ DEBUG(4,("check_correct_backend_entries failed\n"));
+ SAFE_FREE(backends);
+ free_sam_context(context);
+ return nt_status;
+ }
+
+ for (i = 0; i < nBackends; i++) {
+ if (!NT_STATUS_IS_OK(nt_status = make_sam_methods_backend_entry(*context, &curmethods, &backends[i]))) {
+ DEBUG(4,("make_sam_methods_backend_entry failed\n"));
+ SAFE_FREE(backends);
+ free_sam_context(context);
+ return nt_status;
+ }
+ curmethods->parent = *context;
+ DLIST_ADD_END((*context)->methods, curmethods, tmpmethods);
+ }
+
+ SAFE_FREE(backends);
+ return NT_STATUS_OK;
+}
+
/******************************************************************
Make a sam_context from scratch.
*******************************************************************/
@@ -951,13 +1190,13 @@
if ((sam_context) && (reload)) {
sam_context->free_fn(&sam_context);
- if (!NT_STATUS_IS_OK(make_sam_context_list(&sam_context, lp_sam_backend()))) {
+ if (!NT_STATUS_IS_OK(make_sam_context_conf(&sam_context))) {
return NULL;
}
}
if (!sam_context) {
- if (!NT_STATUS_IS_OK(make_sam_context_list(&sam_context, lp_sam_backend()))) {
+ if (!NT_STATUS_IS_OK(make_sam_context_conf(&sam_context))) {
return NULL;
}
}
@@ -977,7 +1216,7 @@
}
-NTSTATUS make_sam_methods(TALLOC_CTX *mem_ctx, SAM_METHODS **methods)
+NTSTATUS make_sam_methods(TALLOC_CTX *mem_ctx, SAM_METHODS **methods)
{
*methods = talloc(mem_ctx, sizeof(SAM_METHODS));
Index: source/sam/sam_plugin.c
===================================================================
RCS file: /cvsroot/samba/source/sam/sam_plugin.c,v
retrieving revision 1.2
diff -u -r1.2 sam_plugin.c
--- source/sam/sam_plugin.c 29 Aug 2002 09:42:36 -0000 1.2
+++ source/sam/sam_plugin.c 7 Sep 2002 09:49:30 -0000
@@ -25,25 +25,25 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_SAM
-NTSTATUS sam_init_plugin(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, const char *location)
+NTSTATUS sam_init_plugin(const SAM_CONTEXT *sam_context, SAM_METHODS **sam_method, const DOM_SID *domain, const char *module_params)
{
- void * dl_handle;
- char *plugin_location, *plugin_name, *p;
+ void *dl_handle;
+ char *plugin_params, *plugin_name, *p;
sam_init_function plugin_init;
int (*plugin_version)(void);
- if (location == NULL) {
+ if (module_params == NULL) {
DEBUG(0, ("The plugin module needs an argument!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
- plugin_name = smb_xstrdup(location);
+ plugin_name = smb_xstrdup(module_params);
p = strchr(plugin_name, ':');
if (p) {
*p = 0;
- plugin_location = p+1;
- trim_string(plugin_location, " ", " ");
- } else plugin_location = NULL;
+ plugin_params = p+1;
+ trim_string(plugin_params, " ", " ");
+ } else plugin_params = NULL;
trim_string(plugin_name, " ", " ");
DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name));
@@ -74,6 +74,6 @@
return NT_STATUS_UNSUCCESSFUL;
}
- DEBUG(5, ("Starting sam plugin %s with location %s\n", plugin_name, plugin_location));
- return plugin_init(sam_context, sam_method, plugin_location);
+ 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);
}
More information about the samba-technical
mailing list