2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675
17 * Mass Ave, Cambridge, MA 02139, USA.
22 BOOL global_machine_password_needs_changing = False;
24 /***************************************************************
25 Lock an fd. Abandon after waitsecs seconds.
26 ****************************************************************/
27 BOOL pw_file_lock(int fd, int type, int secs, int *plock_depth)
32 if(*plock_depth == 0) {
33 if (!do_file_lock(fd, secs, type)) {
34 DEBUG(10,("pw_file_lock: locking file failed, error = %s.\n",
45 /***************************************************************
46 Unlock an fd. Abandon after waitsecs seconds.
47 ****************************************************************/
48 BOOL pw_file_unlock(int fd, int *plock_depth)
53 ret = do_file_lock(fd, 5, F_UNLCK);
59 DEBUG(10,("pw_file_unlock: unlocking file failed, error = %s.\n",
64 /************************************************************************
65 form a key for fetching a domain trust password
66 ************************************************************************/
67 static char *trust_keystr(char *domain)
69 static fstring keystr;
70 slprintf(keystr,sizeof(keystr),"%s/%s", SECRETS_MACHINE_ACCT_PASS, domain);
75 /************************************************************************
76 Routine to delete the trust account password file for a domain.
77 ************************************************************************/
78 BOOL trust_password_delete(char *domain)
80 return secrets_delete(trust_keystr(domain));
83 /************************************************************************
84 Routine to get the trust account password for a domain.
85 The user of this function must have locked the trust password file.
86 ************************************************************************/
87 BOOL get_trust_account_password(char *domain, unsigned char *ret_pwd, time_t *pass_last_set_time)
89 struct machine_acct_pass *pass;
92 if (!(pass = secrets_fetch(trust_keystr(domain), &size)) ||
93 size != sizeof(*pass)) return False;
95 if (pass_last_set_time) *pass_last_set_time = pass->mod_time;
96 memcpy(ret_pwd, pass->hash, 16);
102 /************************************************************************
103 Routine to get the trust account password for a domain.
104 The user of this function must have locked the trust password file.
105 ************************************************************************/
106 BOOL set_trust_account_password(char *domain, unsigned char *md4_new_pwd)
108 struct machine_acct_pass pass;
110 pass.mod_time = time(NULL);
111 memcpy(pass.hash, md4_new_pwd, 16);
113 return secrets_store(trust_keystr(domain), (void *)&pass, sizeof(pass));