Fix bug #9130 - Certain xattrs cause Windows error 0x800700FF
[Samba/vl.git] / source3 / libads / util.c
blob2e22bca02e5a58c89d218e3f236e9a508d7ca906
1 /*
2 Unix SMB/CIFS implementation.
3 krb5 set password implementation
4 Copyright (C) Remus Koos 2001 (remuskoos@yahoo.com)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "ads.h"
22 #include "secrets.h"
24 #ifdef HAVE_KRB5
26 ADS_STATUS ads_change_trust_account_password(ADS_STRUCT *ads, char *host_principal)
28 char *password;
29 char *new_password;
30 ADS_STATUS ret;
31 enum netr_SchannelType sec_channel_type;
33 if ((password = secrets_fetch_machine_password(lp_workgroup(), NULL, &sec_channel_type)) == NULL) {
34 DEBUG(1,("Failed to retrieve password for principal %s\n", host_principal));
35 return ADS_ERROR_SYSTEM(ENOENT);
38 new_password = generate_random_password(talloc_tos(),
39 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH,
40 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
42 ret = kerberos_set_password(ads->auth.kdc_server, host_principal, password, host_principal, new_password, ads->auth.time_offset);
44 if (!ADS_ERR_OK(ret)) {
45 goto failed;
48 if (!secrets_store_machine_password(new_password, lp_workgroup(), sec_channel_type)) {
49 DEBUG(1,("Failed to save machine password\n"));
50 ret = ADS_ERROR_SYSTEM(EACCES);
51 goto failed;
54 failed:
55 SAFE_FREE(password);
56 return ret;
58 #endif