/*
Unix SMB/CIFS implementation.
Winbind daemon for ntdom nss module
Copyright (C) Tim Potter 2000-2001
Copyright (C) 2001 by Martin Pool <mbp@samba.org>
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "winbindd.h"
#include "secrets.h"
#include "../libcli/security/security.h"
#include "../libcli/auth/pam_errors.h"
#include "passdb/machine_sid.h"
#include "passdb.h"
#include "source4/lib/messaging/messaging.h"
#include "librpc/gen_ndr/ndr_lsa.h"
#include "auth/credentials/credentials.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
extern struct winbindd_methods cache_methods;
/**
* @file winbindd_util.c
*
* Winbind daemon for NT domain authentication nss module.
**/
/* The list of trusted domains. Note that the list can be deleted and
recreated using the init_domain_list() function so pointers to
individual winbindd_domain structures cannot be made. Keep a copy of
the domain name instead. */
static struct winbindd_domain *_domain_list = NULL;
struct winbindd_domain *domain_list(void)
{
/* Initialise list */
if ((!_domain_list) && (!init_domain_list())) {
smb_panic("Init_domain_list failed");
}
return _domain_list;
}
/* Free all entries in the trusted domain list */
static void free_domain_list(void)
{
struct winbindd_domain *domain = _domain_list;
while(domain) {
struct winbindd_domain *next = domain->next;
DLIST_REMOVE(_domain_list, domain);
TALLOC_FREE(domain);
domain = next;
}
}
/**
* Iterator for winbindd's domain list.
* To be used (e.g.) in tevent based loops.
*/
struct winbindd_domain *wb_next_domain(struct winbindd_domain *domain)
{
if (domain == NULL) {
domain = domain_list();
} else {
domain = domain->next;
}
if ((domain != NULL) &&
(lp_server_role() != ROLE_ACTIVE_DIRECTORY_DC) &&
sid_check_is_our_sam(&domain->sid))
{
domain = domain->next;
}
return domain;
}
static bool is_internal_domain(const struct dom_sid *sid)
{
if (sid == NULL)
return False;
return (sid_check_is_our_sam(sid) || sid_check_is_builtin(sid));
}
static bool is_in_internal_domain(const struct dom_sid *sid)
{
if (sid == NULL)
return False;
return (sid_check_is_in_our_sam(sid) || sid_check_is_in_builtin(sid));
}
/* Add a trusted domain to our list of domains.
If the domain already exists in the list,
return it and don't re-initialize. */
static struct winbindd_domain *add_trusted_domain(const char *domain_name, const char *alt_name,
stru