2 Unix SMB/Netbios implementation.
5 Winbind daemon - miscellaneous other functions
7 Copyright (C) Tim Potter 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 extern pstring global_myname;
28 /* Some routines to fetch the trust account password from a HEAD
29 version of Samba. Yuck. )-: */
31 /************************************************************************
32 form a key for fetching a domain trust password from
33 ************************************************************************/
34 static char *trust_keystr(char *domain)
36 static fstring keystr;
38 snprintf(keystr,sizeof(keystr),"%s/%s", SECRETS_MACHINE_ACCT_PASS,
44 /************************************************************************
45 Routine to get the trust account password for a domain
46 ************************************************************************/
47 BOOL _get_trust_account_password(char *domain, unsigned char *ret_pwd,
48 time_t *pass_last_set_time)
50 struct machine_acct_pass *pass;
53 if (!(pass = secrets_fetch(trust_keystr(domain), &size)) ||
54 size != sizeof(*pass)) return False;
56 if (pass_last_set_time) *pass_last_set_time = pass->mod_time;
57 memcpy(ret_pwd, pass->hash, 16);
62 /* Check the machine account password is valid */
64 enum winbindd_result winbindd_check_machine_acct(
65 struct winbindd_cli_state *state)
67 int result = WINBINDD_ERROR;
68 uchar trust_passwd[16];
69 struct in_addr *ip_list = NULL;
71 uint16 validation_level;
72 fstring controller, trust_account;
75 DEBUG(3, ("[%5d]: check machine account\n", state->pid));
77 /* Get trust account password */
80 if (!_get_trust_account_password(lp_workgroup(), trust_passwd,
82 result = NT_STATUS_INTERNAL_ERROR;
86 /* Get domain controller */
88 if (!get_dc_list(True, lp_workgroup(), &ip_list, &count) ||
89 !lookup_pdc_name(global_myname, lp_workgroup(), &ip_list[0],
91 DEBUG(0, ("could not find domain controller for "
92 "domain %s\n", lp_workgroup()));
93 result = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
97 DEBUG(3, ("contacting controller %s to check secret\n", controller));
99 /* Contact domain controller to check secret */
101 slprintf(trust_account, sizeof(trust_account) - 1, "%s$",
105 result = cli_nt_setup_creds(controller, lp_workgroup(), global_myname,
106 trust_account, trust_passwd,
107 SEC_CHAN_WKSTA, &validation_level);
110 /* There is a race condition between fetching the trust account
111 password and joining the domain so it's possible that the trust
112 account password has been changed on us. We are returned
113 NT_STATUS_ACCESS_DENIED if this happens. */
115 #define MAX_RETRIES 8
117 if ((num_retries < MAX_RETRIES) &&
118 result == NT_STATUS_ACCESS_DENIED) {
123 /* Pass back result code - zero for success, other values for
124 specific failures. */
126 DEBUG(3, ("secret is %s\n", (result == NT_STATUS_NOPROBLEMO) ?
130 state->response.data.num_entries = result;
134 enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
137 struct winbindd_domain *domain;
138 int total_entries = 0, extra_data_len = 0;
139 char *ted, *extra_data = NULL;
141 DEBUG(3, ("[%5d]: list trusted domains\n", state->pid));
143 for(domain = domain_list; domain; domain = domain->next) {
145 /* Skip own domain */
147 if (strequal(domain->name, lp_workgroup())) continue;
149 /* Add domain to list */
152 ted = Realloc(extra_data, sizeof(fstring) *
156 DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
157 if (extra_data) free(extra_data);
158 return WINBINDD_ERROR;
160 else extra_data = ted;
162 memcpy(&extra_data[extra_data_len], domain->name,
163 strlen(domain->name));
165 extra_data_len += strlen(domain->name);
166 extra_data[extra_data_len++] = ',';
170 if (extra_data_len > 1) extra_data[extra_data_len - 1] = '\0';
171 state->response.extra_data = extra_data;
172 state->response.length += extra_data_len;