Fixed incorrect debug.
[jra/samba/.git] / source3 / auth / auth_domain.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Authenticate against a remote domain
5    Copyright (C) Andrew Tridgell 1992-1998
6    Copyright (C) Andrew Bartlett 2001
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 extern int DEBUGLEVEL;
26
27 BOOL global_machine_password_needs_changing = False;
28
29 /****************************************************************************
30  Check for a valid username and password in security=domain mode.
31 ****************************************************************************/
32
33 uint32 check_domain_security(const auth_usersupplied_info *user_info, 
34                              auth_serversupplied_info *server_info)
35 {
36         uint32 nt_status = NT_STATUS_LOGON_FAILURE;
37         char *p, *pserver;
38         unsigned char trust_passwd[16];
39         time_t last_change_time;
40
41         if(lp_security() != SEC_DOMAIN)
42                 return NT_STATUS_LOGON_FAILURE;
43
44         become_root();
45
46         /*
47          * Get the machine account password for our primary domain
48          */
49
50         if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd, &last_change_time))
51         {
52                 DEBUG(0, ("check_domain_security: could not fetch trust account password for domain %s\n", lp_workgroup()));
53                 unbecome_root();
54                 return NT_STATUS_LOGON_FAILURE;
55         }
56
57         unbecome_root();
58
59         /* Test if machine password is expired and need to be changed */
60         if (time(NULL) > last_change_time + lp_machine_password_timeout())
61         {
62                 global_machine_password_needs_changing = True;
63         }
64
65         /*
66          * Treat each name in the 'password server =' line as a potential
67          * PDC/BDC. Contact each in turn and try and authenticate.
68          */
69
70         pserver = lp_passwordserver();
71         if (! *pserver) pserver = "*";
72         p = pserver;
73
74         nt_status = domain_client_validate(user_info, server_info, 
75                                            p, trust_passwd, last_change_time);
76
77         return nt_status;
78 }