2 Unix SMB/Netbios implementation.
5 Winbind daemon - miscellaneous other functions
7 Copyright (C) Tim Potter 2000
8 Copyright (C) Andrew Bartlett 2002
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern pstring global_myname;
29 /************************************************************************
30 Routine to get the trust account password for a domain
31 ************************************************************************/
32 static BOOL _get_trust_account_password(char *domain, unsigned char *ret_pwd,
33 time_t *pass_last_set_time)
35 if (!secrets_fetch_trust_account_password(domain, ret_pwd, pass_last_set_time)) {
42 /* Check the machine account password is valid */
44 enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *state)
46 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
47 uchar trust_passwd[16];
49 struct cli_state *cli;
50 DEBUG(3, ("[%5d]: check machine account\n", state->pid));
52 /* Get trust account password */
55 if (!_get_trust_account_password(lp_workgroup(), trust_passwd,
57 result = NT_STATUS_INTERNAL_ERROR;
61 /* This call does a cli_nt_setup_creds() which implicitly checks
62 the trust account password. */
64 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
66 if (!NT_STATUS_IS_OK(result)) {
67 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
73 /* There is a race condition between fetching the trust account
74 password and joining the domain so it's possible that the trust
75 account password has been changed on us. We are returned
76 NT_STATUS_ACCESS_DENIED if this happens. */
80 if ((num_retries < MAX_RETRIES) &&
81 NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
86 /* Pass back result code - zero for success, other values for
89 DEBUG(3, ("secret is %s\n", NT_STATUS_IS_OK(result) ?
93 state->response.data.num_entries = NT_STATUS_V(result);
98 enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
101 struct winbindd_domain *domain;
102 int total_entries = 0, extra_data_len = 0;
103 char *ted, *extra_data = NULL;
105 DEBUG(3, ("[%5d]: list trusted domains\n", state->pid));
107 /* We need to refresh the trusted domain list as the domains may
108 have changed since we last looked. There may be a sequence
109 number or something we should use but I haven't found it yet. */
113 for(domain = domain_list(); domain; domain = domain->next) {
115 /* Skip own domain */
117 if (strequal(domain->name, lp_workgroup())) continue;
119 /* Add domain to list */
122 ted = Realloc(extra_data, sizeof(fstring) *
126 DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
127 SAFE_FREE(extra_data);
128 return WINBINDD_ERROR;
132 memcpy(&extra_data[extra_data_len], domain->name,
133 strlen(domain->name));
135 extra_data_len += strlen(domain->name);
136 extra_data[extra_data_len++] = ',';
140 if (extra_data_len > 1)
141 extra_data[extra_data_len - 1] = '\0';
142 state->response.extra_data = extra_data;
143 state->response.length += extra_data_len;
149 enum winbindd_result winbindd_ping(struct winbindd_cli_state
152 DEBUG(3, ("[%5d]: ping\n", state->pid));
157 /* List various tidbits of information */
159 enum winbindd_result winbindd_info(struct winbindd_cli_state *state)
162 DEBUG(3, ("[%5d]: request misc info\n", state->pid));
164 state->response.data.info.winbind_separator = *lp_winbind_separator();
165 fstrcpy(state->response.data.info.samba_version, VERSION);
170 /* Tell the client the current interface version */
172 enum winbindd_result winbindd_interface_version(struct winbindd_cli_state *state)
175 DEBUG(3, ("[%5d]: request interface version\n", state->pid));
177 state->response.data.interface_version = WINBIND_INTERFACE_VERSION;
182 /* What domain are we a member of? */
184 enum winbindd_result winbindd_domain_name(struct winbindd_cli_state *state)
187 DEBUG(3, ("[%5d]: request domain name\n", state->pid));
189 fstrcpy(state->response.data.domain_name, lp_workgroup());