Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "includes.h"
#include "winbindd.h"
#undef DBGC_CLASS
case SEC_ADS: {
extern struct winbindd_methods ads_methods;
/* always obey the lp_security parameter for our domain */
- if ( strequal(lp_realm(), domain->alt_name) || strequal(lp_workgroup(), domain->name) ) {
+ if (domain->primary) {
domain->backend = &ads_methods;
break;
}
+ /* only use ADS for native modes at the momment.
+ The problem is the correct detection of mixed
+ mode domains from NT4 BDC's --jerry */
+
if ( domain->native_mode ) {
+ DEBUG(5,("get_cache: Setting ADS methods for domain %s\n",
+ domain->name));
domain->backend = &ads_methods;
break;
}
}
#endif
default:
+ DEBUG(5,("get_cache: Setting MS-RPC methods for domain %s\n",
+ domain->name));
domain->backend = &msrpc_methods;
}
}
if (ret)
return ret;
- ret = smb_xmalloc(sizeof(*ret));
+ ret = SMB_XMALLOC_P(struct winbind_cache);
ZERO_STRUCTP(ret);
wcache = ret;
smb_panic("centry_string");
}
- ret = talloc(mem_ctx, len+1);
+ ret = TALLOC(mem_ctx, len+1);
if (!ret) {
smb_panic("centry_string out of memory\n");
}
DOM_SID *sid;
char *sid_string;
- sid = talloc(mem_ctx, sizeof(*sid));
+ sid = TALLOC_P(mem_ctx, DOM_SID);
if (!sid)
return NULL;
domain->sequence_number = IVAL(data.dptr, 0);
domain->last_seq_check = IVAL(data.dptr, 4);
+ SAFE_FREE(data.dptr);
+
/* have we expired? */
time_diff = now - domain->last_seq_check;
get_cache( domain );
+#if 0 /* JERRY -- disable as the default cache time is now 5 minutes */
/* trying to reconnect is expensive, don't do it too often */
if (domain->sequence_number == DOM_SEQUENCE_NONE) {
cache_time *= 8;
}
+#endif
time_diff = t - domain->last_seq_check;
if ( NT_STATUS_IS_OK(status) )
goto done;
+ /* important! make sure that we know if this is a native
+ mode domain or not */
+
+ if ( !domain->initialized )
+ set_dc_type_and_flags( domain );
+
status = domain->backend->sequence_number(domain, &domain->sequence_number);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
- centry = smb_xmalloc(sizeof(*centry));
+ centry = SMB_XMALLOC_P(struct cache_entry);
centry->data = (unsigned char *)data.dptr;
centry->len = data.dsize;
centry->ofs = 0;
if (centry->len - centry->ofs >= len)
return;
centry->len *= 2;
- p = realloc(centry->data, centry->len);
+ p = SMB_REALLOC(centry->data, centry->len);
if (!p) {
DEBUG(0,("out of memory: needed %d bytes in centry_expand\n", centry->len));
smb_panic("out of memory in centry_expand");
if (!wcache->tdb)
return NULL;
- centry = smb_xmalloc(sizeof(*centry));
+ centry = SMB_XMALLOC_P(struct cache_entry);
centry->len = 8192; /* reasonable default */
- centry->data = smb_xmalloc(centry->len);
+ centry->data = SMB_XMALLOC_ARRAY(char, centry->len);
centry->ofs = 0;
centry->sequence_number = domain->sequence_number;
centry_put_uint32(centry, NT_STATUS_V(status));
}
static void wcache_save_name_to_sid(struct winbindd_domain *domain,
- NTSTATUS status,
- const char *name, DOM_SID *sid,
+ NTSTATUS status, const char *domain_name,
+ const char *name, const DOM_SID *sid,
enum SID_NAME_USE type)
{
struct cache_entry *centry;
fstring uname;
- fstring sid_string;
centry = centry_start(domain, status);
if (!centry)
return;
+ centry_put_uint32(centry, type);
centry_put_sid(centry, sid);
fstrcpy(uname, name);
strupper_m(uname);
- centry_end(centry, "NS/%s", sid_to_string(sid_string, sid));
- DEBUG(10,("wcache_save_name_to_sid: %s -> %s\n", uname, sid_string));
+ centry_end(centry, "NS/%s/%s", domain_name, uname);
+ DEBUG(10,("wcache_save_name_to_sid: %s -> %s\n", uname,
+ sid_string_static(sid)));
centry_free(centry);
}
static void wcache_save_sid_to_name(struct winbindd_domain *domain, NTSTATUS status,
- DOM_SID *sid, const char *name, enum SID_NAME_USE type)
+ const DOM_SID *sid, const char *domain_name, const char *name, enum SID_NAME_USE type)
{
struct cache_entry *centry;
fstring sid_string;
return;
if (NT_STATUS_IS_OK(status)) {
centry_put_uint32(centry, type);
+ centry_put_string(centry, domain_name);
centry_put_string(centry, name);
}
centry_end(centry, "SN/%s", sid_to_string(sid_string, sid));
if (*num_entries == 0)
goto do_cached;
- (*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+ (*info) = TALLOC_ARRAY(mem_ctx, WINBIND_USERINFO, *num_entries);
if (! (*info))
smb_panic("query_user_list out of memory");
for (i=0; i<(*num_entries); i++) {
if (domain->backend->consistent) {
/* when the backend is consistent we can pre-prime some mappings */
wcache_save_name_to_sid(domain, NT_STATUS_OK,
+ domain->name,
(*info)[i].acct_name,
(*info)[i].user_sid,
SID_NAME_USER);
wcache_save_sid_to_name(domain, NT_STATUS_OK,
(*info)[i].user_sid,
+ domain->name,
(*info)[i].acct_name,
SID_NAME_USER);
wcache_save_user(domain, NT_STATUS_OK, &(*info)[i]);
if (*num_entries == 0)
goto do_cached;
- (*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+ (*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
if (! (*info))
smb_panic("enum_dom_groups out of memory");
for (i=0; i<(*num_entries); i++) {
if (*num_entries == 0)
goto do_cached;
- (*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+ (*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
if (! (*info))
smb_panic("enum_dom_groups out of memory");
for (i=0; i<(*num_entries); i++) {
/* convert a single name to a sid in a domain */
static NTSTATUS name_to_sid(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
+ const char *domain_name,
const char *name,
DOM_SID *sid,
enum SID_NAME_USE *type)
fstrcpy(uname, name);
strupper_m(uname);
- centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, uname);
+ centry = wcache_fetch(cache, domain, "NS/%s/%s", domain_name, uname);
if (!centry)
goto do_query;
*type = (enum SID_NAME_USE)centry_uint32(centry);
DEBUG(10,("name_to_sid: [Cached] - doing backend query for name for domain %s\n",
domain->name ));
- status = domain->backend->name_to_sid(domain, mem_ctx, name, sid, type);
+ status = domain->backend->name_to_sid(domain, mem_ctx, domain_name, name, sid, type);
/* and save it */
- wcache_save_name_to_sid(domain, status, name, sid, *type);
+ wcache_save_name_to_sid(domain, status, domain_name, name, sid, *type);
/* We can't save the sid to name mapping as we don't know the
correct case of the name without looking it up */
given */
static NTSTATUS sid_to_name(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
- DOM_SID *sid,
+ const DOM_SID *sid,
+ char **domain_name,
char **name,
enum SID_NAME_USE *type)
{
goto do_query;
if (NT_STATUS_IS_OK(centry->status)) {
*type = (enum SID_NAME_USE)centry_uint32(centry);
+ *domain_name = centry_string(centry, mem_ctx);
*name = centry_string(centry, mem_ctx);
}
status = centry->status;
do_query:
*name = NULL;
+ *domain_name = NULL;
/* If the seq number check indicated that there is a problem
* with this DC, then return that status... except for
DEBUG(10,("sid_to_name: [Cached] - doing backend query for name for domain %s\n",
domain->name ));
- status = domain->backend->sid_to_name(domain, mem_ctx, sid, name, type);
+ status = domain->backend->sid_to_name(domain, mem_ctx, sid, domain_name, name, type);
/* and save it */
refresh_sequence_number(domain, False);
- wcache_save_sid_to_name(domain, status, sid, *name, *type);
- wcache_save_name_to_sid(domain, status, *name, sid, *type);
+ wcache_save_sid_to_name(domain, status, sid, *domain_name, *name, *type);
+
+ /* We can't save the name to sid mapping here, as with sid history a
+ * later name2sid would give the wrong sid. */
return status;
}
/* Lookup user information from a rid */
static NTSTATUS query_user(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
- DOM_SID *user_sid,
+ const DOM_SID *user_sid,
WINBIND_USERINFO *info)
{
struct winbind_cache *cache = get_cache(domain);
/* Lookup groups a user is a member of. */
static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
- DOM_SID *user_sid,
+ const DOM_SID *user_sid,
uint32 *num_groups, DOM_SID ***user_gids)
{
struct winbind_cache *cache = get_cache(domain);
if (*num_groups == 0)
goto do_cached;
- (*user_gids) = talloc(mem_ctx, sizeof(**user_gids) * (*num_groups));
+ (*user_gids) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_groups);
if (! (*user_gids))
smb_panic("lookup_usergroups out of memory");
for (i=0; i<(*num_groups); i++) {
static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
- DOM_SID *group_sid, uint32 *num_names,
+ const DOM_SID *group_sid, uint32 *num_names,
DOM_SID ***sid_mem, char ***names,
uint32 **name_types)
{
if (*num_names == 0)
goto do_cached;
- (*sid_mem) = talloc(mem_ctx, sizeof(**sid_mem) * (*num_names));
- (*names) = talloc(mem_ctx, sizeof(**names) * (*num_names));
- (*name_types) = talloc(mem_ctx, sizeof(**name_types) * (*num_names));
+ (*sid_mem) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_names);
+ (*names) = TALLOC_ARRAY(mem_ctx, char *, *num_names);
+ (*name_types) = TALLOC_ARRAY(mem_ctx, uint32, *num_names);
if (! (*sid_mem) || ! (*names) || ! (*name_types)) {
smb_panic("lookup_groupmem out of memory");