1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | krb5 set password implementation
|
---|
4 | Copyright (C) Remus Koos 2001 (remuskoos@yahoo.com)
|
---|
5 |
|
---|
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 2 of the License, or
|
---|
9 | (at your option) any later version.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with this program; if not, write to the Free Software
|
---|
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 |
|
---|
23 | #ifdef HAVE_KRB5
|
---|
24 |
|
---|
25 | ADS_STATUS ads_change_trust_account_password(ADS_STRUCT *ads, char *host_principal)
|
---|
26 | {
|
---|
27 | char *password;
|
---|
28 | char *new_password;
|
---|
29 | ADS_STATUS ret;
|
---|
30 | uint32 sec_channel_type;
|
---|
31 |
|
---|
32 | if ((password = secrets_fetch_machine_password(lp_workgroup(), NULL, &sec_channel_type)) == NULL) {
|
---|
33 | DEBUG(1,("Failed to retrieve password for principal %s\n", host_principal));
|
---|
34 | return ADS_ERROR_SYSTEM(ENOENT);
|
---|
35 | }
|
---|
36 |
|
---|
37 | new_password = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
|
---|
38 |
|
---|
39 | ret = kerberos_set_password(ads->auth.kdc_server, host_principal, password, host_principal, new_password, ads->auth.time_offset);
|
---|
40 |
|
---|
41 | if (!ADS_ERR_OK(ret)) {
|
---|
42 | goto failed;
|
---|
43 | }
|
---|
44 |
|
---|
45 | if (!secrets_store_machine_password(new_password, lp_workgroup(), sec_channel_type)) {
|
---|
46 | DEBUG(1,("Failed to save machine password\n"));
|
---|
47 | ret = ADS_ERROR_SYSTEM(EACCES);
|
---|
48 | goto failed;
|
---|
49 | }
|
---|
50 |
|
---|
51 | failed:
|
---|
52 | SAFE_FREE(password);
|
---|
53 | return ret;
|
---|
54 | }
|
---|
55 |
|
---|
56 | ADS_STATUS ads_guess_service_principal(ADS_STRUCT *ads,
|
---|
57 | char **returned_principal)
|
---|
58 | {
|
---|
59 | char *princ = NULL;
|
---|
60 |
|
---|
61 | if (ads->server.realm && ads->server.ldap_server) {
|
---|
62 | char *server, *server_realm;
|
---|
63 |
|
---|
64 | server = SMB_STRDUP(ads->server.ldap_server);
|
---|
65 | server_realm = SMB_STRDUP(ads->server.realm);
|
---|
66 |
|
---|
67 | if (!server || !server_realm) {
|
---|
68 | return ADS_ERROR(LDAP_NO_MEMORY);
|
---|
69 | }
|
---|
70 |
|
---|
71 | strlower_m(server);
|
---|
72 | strupper_m(server_realm);
|
---|
73 | asprintf(&princ, "ldap/%s@%s", server, server_realm);
|
---|
74 |
|
---|
75 | SAFE_FREE(server);
|
---|
76 | SAFE_FREE(server_realm);
|
---|
77 |
|
---|
78 | if (!princ) {
|
---|
79 | return ADS_ERROR(LDAP_NO_MEMORY);
|
---|
80 | }
|
---|
81 | } else if (ads->config.realm && ads->config.ldap_server_name) {
|
---|
82 | char *server, *server_realm;
|
---|
83 |
|
---|
84 | server = SMB_STRDUP(ads->config.ldap_server_name);
|
---|
85 | server_realm = SMB_STRDUP(ads->config.realm);
|
---|
86 |
|
---|
87 | if (!server || !server_realm) {
|
---|
88 | return ADS_ERROR(LDAP_NO_MEMORY);
|
---|
89 | }
|
---|
90 |
|
---|
91 | strlower_m(server);
|
---|
92 | strupper_m(server_realm);
|
---|
93 | asprintf(&princ, "ldap/%s@%s", server, server_realm);
|
---|
94 |
|
---|
95 | SAFE_FREE(server);
|
---|
96 | SAFE_FREE(server_realm);
|
---|
97 |
|
---|
98 | if (!princ) {
|
---|
99 | return ADS_ERROR(LDAP_NO_MEMORY);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (!princ) {
|
---|
104 | return ADS_ERROR(LDAP_PARAM_ERROR);
|
---|
105 | }
|
---|
106 |
|
---|
107 | *returned_principal = princ;
|
---|
108 |
|
---|
109 | return ADS_SUCCESS;
|
---|
110 | }
|
---|
111 |
|
---|
112 | #endif
|
---|