update copyright notice since it we are now almost 4 months into 2003
[Samba.git] / source / nsswitch / winbindd_misc.c
blobec7b21dac8cce1408a7bea43da2c5ea7d490e47f
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind daemon - miscellaneous other functions
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Andrew Bartlett 2002
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.
24 #include "winbindd.h"
26 extern pstring global_myname;
28 /* Check the machine account password is valid */
30 enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *state)
32 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
33 uchar trust_passwd[16];
34 int num_retries = 0;
35 struct cli_state *cli;
36 DEBUG(3, ("[%5d]: check machine account\n", state->pid));
38 /* Get trust account password */
40 again:
41 if (!secrets_fetch_trust_account_password(
42 lp_workgroup(), trust_passwd, NULL)) {
43 result = NT_STATUS_INTERNAL_ERROR;
44 DEBUG(3, ("could not retrieve trust account pw for %s\n", lp_workgroup()));
45 goto done;
48 /* This call does a cli_nt_setup_creds() which implicitly checks
49 the trust account password. */
51 /* Don't shut this down - it belongs to the connection cache code */
52 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
54 if (!NT_STATUS_IS_OK(result)) {
55 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
56 goto done;
59 /* There is a race condition between fetching the trust account
60 password and the periodic machine password change. So it's
61 possible that the trust account password has been changed on us.
62 We are returned NT_STATUS_ACCESS_DENIED if this happens. */
64 #define MAX_RETRIES 8
66 if ((num_retries < MAX_RETRIES) &&
67 NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
68 num_retries++;
69 goto again;
72 /* Pass back result code - zero for success, other values for
73 specific failures. */
75 DEBUG(3, ("secret is %s\n", NT_STATUS_IS_OK(result) ?
76 "good" : "bad"));
78 done:
79 state->response.data.auth.nt_status = NT_STATUS_V(result);
80 fstrcpy(state->response.data.auth.nt_status_string, get_nt_error_msg(result));
81 fstrcpy(state->response.data.auth.error_string, get_nt_error_msg(result));
82 /*state->response.data.auth.pam_error = nt_status_to_pam(result);*/
84 return WINBINDD_OK;
87 enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
88 *state)
90 struct winbindd_domain *domain;
91 int total_entries = 0, extra_data_len = 0;
92 char *ted, *extra_data = NULL;
94 DEBUG(3, ("[%5d]: list trusted domains\n", state->pid));
96 /* We need to refresh the trusted domain list as the domains may
97 have changed since we last looked. There may be a sequence
98 number or something we should use but I haven't found it yet. */
100 init_domain_list();
102 for(domain = domain_list(); domain; domain = domain->next) {
104 /* Skip own domain */
106 if (strequal(domain->name, lp_workgroup())) continue;
108 /* Add domain to list */
110 total_entries++;
111 ted = Realloc(extra_data, sizeof(fstring) *
112 total_entries);
114 if (!ted) {
115 DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
116 SAFE_FREE(extra_data);
117 return WINBINDD_ERROR;
118 } else
119 extra_data = ted;
121 memcpy(&extra_data[extra_data_len], domain->name,
122 strlen(domain->name));
124 extra_data_len += strlen(domain->name);
125 extra_data[extra_data_len++] = ',';
128 if (extra_data) {
129 if (extra_data_len > 1)
130 extra_data[extra_data_len - 1] = '\0';
131 state->response.extra_data = extra_data;
132 state->response.length += extra_data_len;
135 return WINBINDD_OK;
139 enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state)
141 struct winbindd_domain *domain;
142 char *extra_data = NULL;
144 DEBUG(3, ("[%5d]: show sequence\n", state->pid));
146 extra_data = strdup("");
148 /* this makes for a very simple data format, and is easily parsable as well
149 if that is ever needed */
150 for (domain = domain_list(); domain; domain = domain->next) {
151 char *s;
153 domain->methods->sequence_number(domain, &domain->sequence_number);
155 if (DOM_SEQUENCE_NONE == (unsigned)domain->sequence_number) {
156 asprintf(&s,"%s%s : DISCONNECTED\n", extra_data,
157 domain->name);
158 } else {
159 asprintf(&s,"%s%s : %u\n", extra_data,
160 domain->name, (unsigned)domain->sequence_number);
162 free(extra_data);
163 extra_data = s;
166 state->response.extra_data = extra_data;
167 /* must add one to length to copy the 0 for string termination */
168 state->response.length += strlen(extra_data) + 1;
170 return WINBINDD_OK;
173 enum winbindd_result winbindd_ping(struct winbindd_cli_state
174 *state)
176 DEBUG(3, ("[%5d]: ping\n", state->pid));
178 return WINBINDD_OK;
181 /* List various tidbits of information */
183 enum winbindd_result winbindd_info(struct winbindd_cli_state *state)
186 DEBUG(3, ("[%5d]: request misc info\n", state->pid));
188 state->response.data.info.winbind_separator = *lp_winbind_separator();
189 fstrcpy(state->response.data.info.samba_version, VERSION);
191 return WINBINDD_OK;
194 /* Tell the client the current interface version */
196 enum winbindd_result winbindd_interface_version(struct winbindd_cli_state *state)
199 DEBUG(3, ("[%5d]: request interface version\n", state->pid));
201 state->response.data.interface_version = WINBIND_INTERFACE_VERSION;
203 return WINBINDD_OK;
206 /* What domain are we a member of? */
208 enum winbindd_result winbindd_domain_name(struct winbindd_cli_state *state)
211 DEBUG(3, ("[%5d]: request domain name\n", state->pid));
213 fstrcpy(state->response.data.domain_name, lp_workgroup());
215 return WINBINDD_OK;