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
;
54 fstrcpy(dos_domain
, domain
);
55 unix_to_dos(dos_domain
, True
);
57 if (!(pass
= secrets_fetch(trust_keystr(dos_domain
), &size
)) ||
58 size
!= sizeof(*pass
)) return False
;
60 if (pass_last_set_time
) *pass_last_set_time
= pass
->mod_time
;
61 memcpy(ret_pwd
, pass
->hash
, 16);
66 /* Check the machine account password is valid */
68 enum winbindd_result
winbindd_check_machine_acct(
69 struct winbindd_cli_state
*state
)
71 int result
= WINBINDD_ERROR
;
72 uchar trust_passwd
[16];
73 struct in_addr
*ip_list
= NULL
;
75 uint16 validation_level
;
76 fstring controller
, trust_account
;
78 DEBUG(3, ("[%5d]: check machine account\n", state
->pid
));
80 /* Get trust account password */
82 if (!_get_trust_account_password(lp_workgroup(), trust_passwd
, NULL
)) {
83 result
= NT_STATUS_INTERNAL_ERROR
;
87 /* Get domain controller */
89 if (!get_dc_list(True
, lp_workgroup(), &ip_list
, &count
) ||
90 !lookup_pdc_name(global_myname
, lp_workgroup(), &ip_list
[0],
92 DEBUG(0, ("could not find domain controller for "
93 "domain %s\n", lp_workgroup()));
94 result
= NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
98 DEBUG(3, ("contacting controller %s to check secret\n", controller
));
100 /* Contact domain controller to check secret */
102 slprintf(trust_account
, sizeof(trust_account
) - 1, "%s$",
106 result
= cli_nt_setup_creds(controller
, lp_workgroup(), global_myname
,
107 trust_account
, trust_passwd
,
108 SEC_CHAN_WKSTA
, &validation_level
);
111 /* Pass back result code - zero for success, other values for
112 specific failures. */
114 DEBUG(3, ("secret is %s\n", (result
== NT_STATUS_NOPROBLEMO
) ?
118 state
->response
.data
.num_entries
= result
;
122 enum winbindd_result
winbindd_list_trusted_domains(struct winbindd_cli_state
125 struct winbindd_domain
*domain
;
126 int total_entries
= 0, extra_data_len
= 0;
127 char *extra_data
= NULL
;
129 DEBUG(3, ("[%5d]: list trusted domains\n", state
->pid
));
131 for(domain
= domain_list
; domain
; domain
= domain
->next
) {
133 /* Skip own domain */
135 if (strequal(domain
->name
, lp_workgroup())) continue;
137 /* Add domain to list */
140 extra_data
= Realloc(extra_data
, sizeof(fstring
) *
143 if (!extra_data
) return WINBINDD_ERROR
;
145 memcpy(&extra_data
[extra_data_len
], domain
->name
,
146 strlen(domain
->name
));
148 extra_data_len
+= strlen(domain
->name
);
149 extra_data
[extra_data_len
++] = ',';
153 if (extra_data_len
> 1) extra_data
[extra_data_len
- 1] = '\0';
154 state
->response
.extra_data
= extra_data
;
155 state
->response
.length
+= extra_data_len
;