Re: lp_sam_backend
Here comes version 3: 1.) change lp_sam_backend syntax to sam backend = plugin[|domain_name][:options] this was needed as ',' is a list seperator. The syntax is probably going to change again soon, but not tonight 2.) Added some DEBUG(). They are still in a total mess though 3.) I've actually tested the parsing code now and fixed (hopefully) all of the sig_segv. i.e. it should work now To compile this patch via bin/samtest, you need a change in the Makefile so that samtest includes passdb/secrets.o and passdb/machine_sid.c Kai > Here comes the next version with the following changes: > > 1.) use SAM_ASSERT() some more > 2.) implement context_sam_update_domain I forgot last time > 3.) change the way context_sam_update_* and context_sam_delete_* find > their sam_methods. Use current_sam_methods from the handle > > Kai > > >> 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 > 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 - 1.3 +++ examples/sam/sam_skel.c 7 Sep 2002 23:08:19 - @@ -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.h6 Sep 2002 13:00:37 - 1.6 +++ source/include/sam.h7 Sep 2002 23:08:20 - @@ -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 - 1.7 +++ source/sam/interface.c 7 Sep 2002 23:08:22 - @@ -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;
Re: lp_sam_backend
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. **
re: lp_sam_backend
mpting 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)
lp_sam_backend
Hi Jelmer, Hi Andrew, Hi Stefan I've started to code up some functions to parse the lp_sam_backend list and create a sam_context from it. In contrast to the current implementation, these functions can take a domain name per backend and pass it down to the apropriate sam_init(). To create a maximum of flexibility, the domain name is prefixed with "D-" and the module_params are prefixed with "O-". This allows to leave either of the two away or swapp them arround. The smb.conf entery could look something like this: sam backend = sam_moduleA:D-domainA:O-options_for_sam_moduleA sam_moduleB:O-options_for_sam_moduleB:sup_options:D-domainB or sam backend = sam_moduleA Currently the entire checking for correctnes is still missing apart from many other points. In addition the style is still terrible, but I wanted to know if this is the right direction before I continue to put effort into it. So any comments are welcome. Kai typedef struct sam_backend_entry { char*module_name; char*module_params; char*domain_name; DOM_SID *domain_sid; } SAM_BACKEND_ENTRY; static NTSTATUS make_backend_entry(SAM_BACKEND_ENTRY *backend_entry, char *sam_backend_string) { char *tmp = NULL; char *tmp_string = sam_backend_string; BOOL allow_intermediate_colon = False; if (sam_backend_string == NULL) return NT_STATUS_INVALID_PARAMETER; backend_entry->module_name = sam_backend_string; while ((tmp = strchr(tmp_string,':')) != NULL) { if (tmp[2] == '-') { switch (tmp[1]) { case 'D': { *tmp = 0; backend_entry->domain_name = tmp + 3; allow_intermediate_colon = False; break; } case 'O': { *tmp = 0; backend_entry->module_params = tmp + 3; allow_intermediate_colon = True; break; } default: if (!allow_intermediate_colon) { DEBUG(2,("make_backend_entry: Error\n")); return NT_STATUS_INVALID_PARAMETER; } } } else if (!allow_intermediate_colon) { DEBUG(2,("make_backend_entry: Error\n")); return NT_STATUS_INVALID_PARAMETER; } 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 */ } return NT_STATUS_OK; } static NTSTATUS make_sam_methods_backend_entry(SAM_METHODS **methods, SAM_CONTEXT *context, SAM_BACKEND_ENTRY *sam_backend_entry) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int 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].module_name, backend_entry->module_name)) { 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", backend_entry->module_name)); } else { DEBUG(2,("sam backend %s did not correctly init (error was %s)\n", backend_entry->module_name, nt_errstr(nt_status))); } return nt_status; break; /* unreached */ } } DEBUG(2,("could not find backen