2 Unix SMB/CIFS implementation.
3 krb5 set password implementation
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Remus Koos 2001 (remuskoos@yahoo.com)
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #define DEFAULT_KPASSWD_PORT 464
27 #define KRB5_KPASSWD_VERS_CHANGEPW 1
29 #define KRB5_KPASSWD_VERS_SETPW 0xff80
30 #define KRB5_KPASSWD_VERS_SETPW_ALT 2
32 #define KRB5_KPASSWD_SUCCESS 0
33 #define KRB5_KPASSWD_MALFORMED 1
34 #define KRB5_KPASSWD_HARDERROR 2
35 #define KRB5_KPASSWD_AUTHERROR 3
36 #define KRB5_KPASSWD_SOFTERROR 4
37 #define KRB5_KPASSWD_ACCESSDENIED 5
38 #define KRB5_KPASSWD_BAD_VERSION 6
39 #define KRB5_KPASSWD_INITIAL_FLAG_NEEDED 7
41 /* Those are defined by kerberos-set-passwd-02.txt and are probably
42 * not supported by M$ implementation */
43 #define KRB5_KPASSWD_POLICY_REJECT 8
44 #define KRB5_KPASSWD_BAD_PRINCIPAL 9
45 #define KRB5_KPASSWD_ETYPE_NOSUPP 10
48 * we've got to be able to distinguish KRB_ERRORs from other
49 * requests - valid response for CHPW v2 replies.
52 #define krb5_is_krb_error(packet) \
53 ( packet && packet->length && (((char *)packet->data)[0] == 0x7e || ((char *)packet->data)[0] == 0x5e))
55 /* This implements kerberos password change protocol as specified in
56 * kerb-chg-password-02.txt and kerberos-set-passwd-02.txt
57 * as well as microsoft version of the protocol
58 * as specified in kerberos-set-passwd-00.txt
60 static DATA_BLOB
encode_krb5_setpw(const char *principal
, const char *password
)
62 char* princ_part1
= NULL
;
63 char* princ_part2
= NULL
;
72 princ
= SMB_STRDUP(principal
);
74 if ((c
= strchr_m(princ
, '/')) == NULL
) {
84 if ((c
= strchr_m(c
, '@')) != NULL
) {
89 /* We must have a realm component. */
90 return data_blob_null
;
93 memset(&req
, 0, sizeof(req
));
95 asn1_push_tag(&req
, ASN1_SEQUENCE(0));
96 asn1_push_tag(&req
, ASN1_CONTEXT(0));
97 asn1_write_OctetString(&req
, password
, strlen(password
));
100 asn1_push_tag(&req
, ASN1_CONTEXT(1));
101 asn1_push_tag(&req
, ASN1_SEQUENCE(0));
103 asn1_push_tag(&req
, ASN1_CONTEXT(0));
104 asn1_write_Integer(&req
, 1);
107 asn1_push_tag(&req
, ASN1_CONTEXT(1));
108 asn1_push_tag(&req
, ASN1_SEQUENCE(0));
111 asn1_write_GeneralString(&req
, princ_part1
);
114 asn1_write_GeneralString(&req
, princ_part2
);
120 asn1_push_tag(&req
, ASN1_CONTEXT(2));
121 asn1_write_GeneralString(&req
, realm
);
125 ret
= data_blob(req
.data
, req
.length
);
133 static krb5_error_code
build_kpasswd_request(uint16 pversion
,
134 krb5_context context
,
135 krb5_auth_context auth_context
,
144 krb5_data encoded_setpw
;
145 krb5_replay_data replay
;
148 unsigned int msg_length
;
150 ret
= krb5_auth_con_setflags(context
,
151 auth_context
,KRB5_AUTH_CONTEXT_DO_SEQUENCE
);
153 DEBUG(1,("krb5_auth_con_setflags failed (%s)\n",
154 error_message(ret
)));
158 /* handle protocol differences in chpw and setpw */
159 if (pversion
== KRB5_KPASSWD_VERS_CHANGEPW
)
160 setpw
= data_blob(passwd
, strlen(passwd
));
161 else if (pversion
== KRB5_KPASSWD_VERS_SETPW
||
162 pversion
== KRB5_KPASSWD_VERS_SETPW_ALT
)
163 setpw
= encode_krb5_setpw(princ
, passwd
);
167 if (setpw
.data
== NULL
|| setpw
.length
== 0) {
171 encoded_setpw
.data
= (char *)setpw
.data
;
172 encoded_setpw
.length
= setpw
.length
;
174 ret
= krb5_mk_priv(context
, auth_context
,
175 &encoded_setpw
, &cipherpw
, &replay
);
177 data_blob_free(&setpw
); /*from 'encode_krb5_setpw(...)' */
180 DEBUG(1,("krb5_mk_priv failed (%s)\n", error_message(ret
)));
184 packet
->data
= (char *)SMB_MALLOC(ap_req
->length
+ cipherpw
.length
+ (use_tcp
? 10 : 6 ));
190 /* see the RFC for details */
192 msg_start
= p
= ((char *)packet
->data
) + (use_tcp
? 4 : 0);
194 RSSVAL(p
, 0, pversion
);
196 RSSVAL(p
, 0, ap_req
->length
);
198 memcpy(p
, ap_req
->data
, ap_req
->length
);
200 memcpy(p
, cipherpw
.data
, cipherpw
.length
);
201 p
+= cipherpw
.length
;
202 packet
->length
= PTR_DIFF(p
,packet
->data
);
203 msg_length
= PTR_DIFF(p
,msg_start
);
206 RSIVAL(packet
->data
, 0, msg_length
);
208 RSSVAL(msg_start
, 0, msg_length
);
210 free(cipherpw
.data
); /* from 'krb5_mk_priv(...)' */
215 static const struct kpasswd_errors
{
217 const char *error_string
;
218 } kpasswd_errors
[] = {
219 {KRB5_KPASSWD_MALFORMED
, "Malformed request error"},
220 {KRB5_KPASSWD_HARDERROR
, "Server error"},
221 {KRB5_KPASSWD_AUTHERROR
, "Authentication error"},
222 {KRB5_KPASSWD_SOFTERROR
, "Password change rejected"},
223 {KRB5_KPASSWD_ACCESSDENIED
, "Client does not have proper authorization"},
224 {KRB5_KPASSWD_BAD_VERSION
, "Protocol version not supported"},
225 {KRB5_KPASSWD_INITIAL_FLAG_NEEDED
, "Authorization ticket must have initial flag set"},
226 {KRB5_KPASSWD_POLICY_REJECT
, "Password rejected due to policy requirements"},
227 {KRB5_KPASSWD_BAD_PRINCIPAL
, "Target principal does not exist"},
228 {KRB5_KPASSWD_ETYPE_NOSUPP
, "Unsupported encryption type"},
232 static krb5_error_code
setpw_result_code_string(krb5_context context
,
234 const char **code_string
)
236 unsigned int idx
= 0;
238 while (kpasswd_errors
[idx
].error_string
!= NULL
) {
239 if (kpasswd_errors
[idx
].result_code
==
241 *code_string
= kpasswd_errors
[idx
].error_string
;
246 *code_string
= "Password change failed";
250 krb5_error_code
kpasswd_err_to_krb5_err(krb5_error_code res_code
)
253 case KRB5_KPASSWD_ACCESSDENIED
:
254 return KRB5KDC_ERR_BADOPTION
;
255 case KRB5_KPASSWD_INITIAL_FLAG_NEEDED
:
256 return KRB5KDC_ERR_BADOPTION
;
257 /* return KV5M_ALT_METHOD; MIT-only define */
258 case KRB5_KPASSWD_ETYPE_NOSUPP
:
259 return KRB5KDC_ERR_ETYPE_NOSUPP
;
260 case KRB5_KPASSWD_BAD_PRINCIPAL
:
261 return KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
262 case KRB5_KPASSWD_POLICY_REJECT
:
263 case KRB5_KPASSWD_SOFTERROR
:
264 return KRB5KDC_ERR_POLICY
;
266 return KRB5KRB_ERR_GENERIC
;
269 static krb5_error_code
parse_setpw_reply(krb5_context context
,
271 krb5_auth_context auth_context
,
276 int vnum
, ret
, res_code
;
277 krb5_data cipherresult
;
278 krb5_data clearresult
;
279 krb5_ap_rep_enc_part
*ap_rep_enc
;
280 krb5_replay_data replay
;
281 unsigned int msg_length
= packet
->length
;
284 if (packet
->length
< (use_tcp
? 8 : 4)) {
285 return KRB5KRB_AP_ERR_MODIFIED
;
290 ** see if it is an error
292 if (krb5_is_krb_error(packet
)) {
294 ret
= handle_krberror_packet(context
, packet
);
304 if (RIVAL(p
, 0) != msg_length
) {
305 DEBUG(1,("Bad TCP packet length (%d/%d) from kpasswd server\n",
306 RIVAL(p
, 0), msg_length
));
307 return KRB5KRB_AP_ERR_MODIFIED
;
313 if (RSVAL(p
, 0) != msg_length
) {
314 DEBUG(1,("Bad packet length (%d/%d) from kpasswd server\n",
315 RSVAL(p
, 0), msg_length
));
316 return KRB5KRB_AP_ERR_MODIFIED
;
321 vnum
= RSVAL(p
, 0); p
+= 2;
323 /* FIXME: According to standard there is only one type of reply */
324 if (vnum
!= KRB5_KPASSWD_VERS_SETPW
&&
325 vnum
!= KRB5_KPASSWD_VERS_SETPW_ALT
&&
326 vnum
!= KRB5_KPASSWD_VERS_CHANGEPW
) {
327 DEBUG(1,("Bad vnum (%d) from kpasswd server\n", vnum
));
328 return KRB5KDC_ERR_BAD_PVNO
;
331 ap_rep
.length
= RSVAL(p
, 0); p
+= 2;
333 if (p
+ ap_rep
.length
>= (char *)packet
->data
+ packet
->length
) {
334 DEBUG(1,("ptr beyond end of packet from kpasswd server\n"));
335 return KRB5KRB_AP_ERR_MODIFIED
;
338 if (ap_rep
.length
== 0) {
339 DEBUG(1,("got unencrypted setpw result?!\n"));
340 return KRB5KRB_AP_ERR_MODIFIED
;
347 ret
= krb5_rd_rep(context
, auth_context
, &ap_rep
, &ap_rep_enc
);
349 DEBUG(1,("failed to rd setpw reply (%s)\n", error_message(ret
)));
350 return KRB5KRB_AP_ERR_MODIFIED
;
353 krb5_free_ap_rep_enc_part(context
, ap_rep_enc
);
355 cipherresult
.data
= p
;
356 cipherresult
.length
= ((char *)packet
->data
+ packet
->length
) - p
;
358 ret
= krb5_rd_priv(context
, auth_context
, &cipherresult
, &clearresult
,
361 DEBUG(1,("failed to decrypt setpw reply (%s)\n", error_message(ret
)));
362 return KRB5KRB_AP_ERR_MODIFIED
;
365 if (clearresult
.length
< 2) {
366 free(clearresult
.data
);
367 ret
= KRB5KRB_AP_ERR_MODIFIED
;
368 return KRB5KRB_AP_ERR_MODIFIED
;
371 p
= clearresult
.data
;
373 res_code
= RSVAL(p
, 0);
375 free(clearresult
.data
);
377 if ((res_code
< KRB5_KPASSWD_SUCCESS
) ||
378 (res_code
> KRB5_KPASSWD_ETYPE_NOSUPP
)) {
379 return KRB5KRB_AP_ERR_MODIFIED
;
382 if (res_code
== KRB5_KPASSWD_SUCCESS
) {
386 setpw_result_code_string(context
, res_code
, &errstr
);
387 DEBUG(1, ("Error changing password: %s (%d)\n", errstr
, res_code
));
389 return kpasswd_err_to_krb5_err(res_code
);
393 static ADS_STATUS
do_krb5_kpasswd_request(krb5_context context
,
394 const char *kdc_host
,
400 krb5_auth_context auth_context
= NULL
;
401 krb5_data ap_req
, chpw_req
, chpw_rep
;
404 struct sockaddr_storage remote_addr
, local_addr
;
405 struct sockaddr_storage addr
;
406 krb5_address local_kaddr
, remote_kaddr
;
407 bool use_tcp
= False
;
410 if (!interpret_string_addr(&addr
, kdc_host
, 0)) {
413 ret
= krb5_mk_req_extended(context
, &auth_context
, AP_OPTS_USE_SUBKEY
,
414 NULL
, credsp
, &ap_req
);
416 DEBUG(1,("krb5_mk_req_extended failed (%s)\n", error_message(ret
)));
417 return ADS_ERROR_KRB5(ret
);
424 sock
= open_udp_socket(kdc_host
, DEFAULT_KPASSWD_PORT
);
428 sock
= open_socket_out(SOCK_STREAM
, &addr
, DEFAULT_KPASSWD_PORT
,
429 LONG_CONNECT_TIMEOUT
);
434 SAFE_FREE(ap_req
.data
);
435 krb5_auth_con_free(context
, auth_context
);
436 DEBUG(1,("failed to open kpasswd socket to %s (%s)\n",
437 kdc_host
, strerror(errno
)));
438 return ADS_ERROR_SYSTEM(rc
);
440 addr_len
= sizeof(remote_addr
);
441 if (getpeername(sock
, (struct sockaddr
*)&remote_addr
, &addr_len
) != 0) {
443 SAFE_FREE(ap_req
.data
);
444 krb5_auth_con_free(context
, auth_context
);
445 DEBUG(1,("getpeername() failed (%s)\n", error_message(errno
)));
446 return ADS_ERROR_SYSTEM(errno
);
448 addr_len
= sizeof(local_addr
);
449 if (getsockname(sock
, (struct sockaddr
*)&local_addr
, &addr_len
) != 0) {
451 SAFE_FREE(ap_req
.data
);
452 krb5_auth_con_free(context
, auth_context
);
453 DEBUG(1,("getsockname() failed (%s)\n", error_message(errno
)));
454 return ADS_ERROR_SYSTEM(errno
);
456 if (!setup_kaddr(&remote_kaddr
, &remote_addr
) ||
457 !setup_kaddr(&local_kaddr
, &local_addr
)) {
458 DEBUG(1,("do_krb5_kpasswd_request: "
459 "Failed to setup addresses.\n"));
461 SAFE_FREE(ap_req
.data
);
462 krb5_auth_con_free(context
, auth_context
);
464 return ADS_ERROR_SYSTEM(EINVAL
);
467 ret
= krb5_auth_con_setaddrs(context
, auth_context
, &local_kaddr
, NULL
);
470 SAFE_FREE(ap_req
.data
);
471 krb5_auth_con_free(context
, auth_context
);
472 DEBUG(1,("krb5_auth_con_setaddrs failed (%s)\n", error_message(ret
)));
473 return ADS_ERROR_KRB5(ret
);
476 ret
= build_kpasswd_request(pversion
, context
, auth_context
, &ap_req
,
477 princ
, newpw
, use_tcp
, &chpw_req
);
480 SAFE_FREE(ap_req
.data
);
481 krb5_auth_con_free(context
, auth_context
);
482 DEBUG(1,("build_setpw_request failed (%s)\n", error_message(ret
)));
483 return ADS_ERROR_KRB5(ret
);
486 ret
= write(sock
, chpw_req
.data
, chpw_req
.length
);
488 if (ret
!= chpw_req
.length
) {
490 SAFE_FREE(chpw_req
.data
);
491 SAFE_FREE(ap_req
.data
);
492 krb5_auth_con_free(context
, auth_context
);
493 DEBUG(1,("send of chpw failed (%s)\n", strerror(errno
)));
494 return ADS_ERROR_SYSTEM(errno
);
497 SAFE_FREE(chpw_req
.data
);
499 chpw_rep
.length
= 1500;
500 chpw_rep
.data
= (char *) SMB_MALLOC(chpw_rep
.length
);
501 if (!chpw_rep
.data
) {
503 SAFE_FREE(ap_req
.data
);
504 krb5_auth_con_free(context
, auth_context
);
505 DEBUG(1,("send of chpw failed (%s)\n", strerror(errno
)));
507 return ADS_ERROR_SYSTEM(errno
);
510 ret
= read(sock
, chpw_rep
.data
, chpw_rep
.length
);
513 SAFE_FREE(chpw_rep
.data
);
514 SAFE_FREE(ap_req
.data
);
515 krb5_auth_con_free(context
, auth_context
);
516 DEBUG(1,("recv of chpw reply failed (%s)\n", strerror(errno
)));
517 return ADS_ERROR_SYSTEM(errno
);
521 chpw_rep
.length
= ret
;
523 ret
= krb5_auth_con_setaddrs(context
, auth_context
, NULL
,&remote_kaddr
);
525 SAFE_FREE(chpw_rep
.data
);
526 SAFE_FREE(ap_req
.data
);
527 krb5_auth_con_free(context
, auth_context
);
528 DEBUG(1,("krb5_auth_con_setaddrs on reply failed (%s)\n",
529 error_message(ret
)));
530 return ADS_ERROR_KRB5(ret
);
533 ret
= parse_setpw_reply(context
, use_tcp
, auth_context
, &chpw_rep
);
534 SAFE_FREE(chpw_rep
.data
);
538 if (ret
== KRB5KRB_ERR_RESPONSE_TOO_BIG
&& !use_tcp
) {
539 DEBUG(5, ("Trying setpw with TCP!!!\n"));
544 SAFE_FREE(ap_req
.data
);
545 krb5_auth_con_free(context
, auth_context
);
546 DEBUG(1,("parse_setpw_reply failed (%s)\n",
547 error_message(ret
)));
548 return ADS_ERROR_KRB5(ret
);
551 SAFE_FREE(ap_req
.data
);
552 krb5_auth_con_free(context
, auth_context
);
558 ADS_STATUS
ads_krb5_set_password(const char *kdc_host
, const char *princ
,
559 const char *newpw
, int time_offset
)
563 krb5_error_code ret
= 0;
564 krb5_context context
= NULL
;
565 krb5_principal principal
= NULL
;
566 char *princ_name
= NULL
;
568 krb5_creds creds
, *credsp
= NULL
;
569 #if KRB5_PRINC_REALM_RETURNS_REALM
570 krb5_realm orig_realm
;
572 krb5_data orig_realm
;
574 krb5_ccache ccache
= NULL
;
578 initialize_krb5_error_table();
579 ret
= krb5_init_context(&context
);
581 DEBUG(1,("Failed to init krb5 context (%s)\n", error_message(ret
)));
582 return ADS_ERROR_KRB5(ret
);
585 if (time_offset
!= 0) {
586 krb5_set_real_time(context
, time(NULL
) + time_offset
, 0);
589 ret
= krb5_cc_default(context
, &ccache
);
591 krb5_free_context(context
);
592 DEBUG(1,("Failed to get default creds (%s)\n", error_message(ret
)));
593 return ADS_ERROR_KRB5(ret
);
596 realm
= strchr_m(princ
, '@');
598 krb5_cc_close(context
, ccache
);
599 krb5_free_context(context
);
600 DEBUG(1,("Failed to get realm\n"));
601 return ADS_ERROR_KRB5(-1);
605 asprintf(&princ_name
, "kadmin/changepw@%s", realm
);
606 ret
= smb_krb5_parse_name(context
, princ_name
, &creds
.server
);
608 krb5_cc_close(context
, ccache
);
609 krb5_free_context(context
);
610 DEBUG(1,("Failed to parse kadmin/changepw (%s)\n", error_message(ret
)));
611 return ADS_ERROR_KRB5(ret
);
614 /* parse the principal we got as a function argument */
615 ret
= smb_krb5_parse_name(context
, princ
, &principal
);
617 krb5_cc_close(context
, ccache
);
618 krb5_free_principal(context
, creds
.server
);
619 krb5_free_context(context
);
620 DEBUG(1,("Failed to parse %s (%s)\n", princ_name
, error_message(ret
)));
622 return ADS_ERROR_KRB5(ret
);
627 /* The creds.server principal takes ownership of this memory.
628 Remember to set back to original value before freeing. */
629 orig_realm
= *krb5_princ_realm(context
, creds
.server
);
630 krb5_princ_set_realm(context
, creds
.server
, krb5_princ_realm(context
, principal
));
632 ret
= krb5_cc_get_principal(context
, ccache
, &creds
.client
);
634 krb5_cc_close(context
, ccache
);
635 krb5_princ_set_realm(context
, creds
.server
, &orig_realm
);
636 krb5_free_principal(context
, creds
.server
);
637 krb5_free_principal(context
, principal
);
638 krb5_free_context(context
);
639 DEBUG(1,("Failed to get principal from ccache (%s)\n",
640 error_message(ret
)));
641 return ADS_ERROR_KRB5(ret
);
644 ret
= krb5_get_credentials(context
, 0, ccache
, &creds
, &credsp
);
646 krb5_cc_close(context
, ccache
);
647 krb5_free_principal(context
, creds
.client
);
648 krb5_princ_set_realm(context
, creds
.server
, &orig_realm
);
649 krb5_free_principal(context
, creds
.server
);
650 krb5_free_principal(context
, principal
);
651 krb5_free_context(context
);
652 DEBUG(1,("krb5_get_credentials failed (%s)\n", error_message(ret
)));
653 return ADS_ERROR_KRB5(ret
);
656 /* we might have to call krb5_free_creds(...) from now on ... */
658 aret
= do_krb5_kpasswd_request(context
, kdc_host
,
659 KRB5_KPASSWD_VERS_SETPW
,
660 credsp
, princ
, newpw
);
662 krb5_free_creds(context
, credsp
);
663 krb5_free_principal(context
, creds
.client
);
664 krb5_princ_set_realm(context
, creds
.server
, &orig_realm
);
665 krb5_free_principal(context
, creds
.server
);
666 krb5_free_principal(context
, principal
);
667 krb5_cc_close(context
, ccache
);
668 krb5_free_context(context
);
674 we use a prompter to avoid a crash bug in the kerberos libs when
675 dealing with empty passwords
676 this prompter is just a string copy ...
678 static krb5_error_code
679 kerb_prompter(krb5_context ctx
, void *data
,
683 krb5_prompt prompts
[])
685 if (num_prompts
== 0) return 0;
687 memset(prompts
[0].reply
->data
, 0, prompts
[0].reply
->length
);
688 if (prompts
[0].reply
->length
> 0) {
690 strncpy(prompts
[0].reply
->data
,
692 prompts
[0].reply
->length
-1);
693 prompts
[0].reply
->length
= strlen(prompts
[0].reply
->data
);
695 prompts
[0].reply
->length
= 0;
701 static ADS_STATUS
ads_krb5_chg_password(const char *kdc_host
,
702 const char *principal
,
709 krb5_context context
= NULL
;
710 krb5_principal princ
;
711 krb5_get_init_creds_opt opts
;
713 char *chpw_princ
= NULL
, *password
;
715 initialize_krb5_error_table();
716 ret
= krb5_init_context(&context
);
718 DEBUG(1,("Failed to init krb5 context (%s)\n", error_message(ret
)));
719 return ADS_ERROR_KRB5(ret
);
722 if ((ret
= smb_krb5_parse_name(context
, principal
,
724 krb5_free_context(context
);
725 DEBUG(1,("Failed to parse %s (%s)\n", principal
, error_message(ret
)));
726 return ADS_ERROR_KRB5(ret
);
729 krb5_get_init_creds_opt_init(&opts
);
730 krb5_get_init_creds_opt_set_tkt_life(&opts
, 5*60);
731 krb5_get_init_creds_opt_set_renew_life(&opts
, 0);
732 krb5_get_init_creds_opt_set_forwardable(&opts
, 0);
733 krb5_get_init_creds_opt_set_proxiable(&opts
, 0);
735 /* We have to obtain an INITIAL changepw ticket for changing password */
736 asprintf(&chpw_princ
, "kadmin/changepw@%s",
737 (char *) krb5_princ_realm(context
, princ
));
738 password
= SMB_STRDUP(oldpw
);
739 ret
= krb5_get_init_creds_password(context
, &creds
, princ
, password
,
741 0, chpw_princ
, &opts
);
742 SAFE_FREE(chpw_princ
);
746 if (ret
== KRB5KRB_AP_ERR_BAD_INTEGRITY
)
747 DEBUG(1,("Password incorrect while getting initial ticket"));
749 DEBUG(1,("krb5_get_init_creds_password failed (%s)\n", error_message(ret
)));
751 krb5_free_principal(context
, princ
);
752 krb5_free_context(context
);
753 return ADS_ERROR_KRB5(ret
);
756 aret
= do_krb5_kpasswd_request(context
, kdc_host
,
757 KRB5_KPASSWD_VERS_CHANGEPW
,
758 &creds
, principal
, newpw
);
760 krb5_free_principal(context
, princ
);
761 krb5_free_context(context
);
767 ADS_STATUS
kerberos_set_password(const char *kpasswd_server
,
768 const char *auth_principal
, const char *auth_password
,
769 const char *target_principal
, const char *new_password
,
774 if ((ret
= kerberos_kinit_password(auth_principal
, auth_password
, time_offset
, NULL
))) {
775 DEBUG(1,("Failed kinit for principal %s (%s)\n", auth_principal
, error_message(ret
)));
776 return ADS_ERROR_KRB5(ret
);
779 if (!strcmp(auth_principal
, target_principal
))
780 return ads_krb5_chg_password(kpasswd_server
, target_principal
,
781 auth_password
, new_password
, time_offset
);
783 return ads_krb5_set_password(kpasswd_server
, target_principal
,
784 new_password
, time_offset
);
789 * Set the machine account password
790 * @param ads connection to ads server
791 * @param hostname machine whose password is being set
792 * @param password new password
793 * @return status of password change
795 ADS_STATUS
ads_set_machine_password(ADS_STRUCT
*ads
,
796 const char *machine_account
,
797 const char *password
)
800 char *principal
= NULL
;
803 we need to use the '$' form of the name here (the machine account name),
804 as otherwise the server might end up setting the password for a user
807 asprintf(&principal
, "%s@%s", machine_account
, ads
->config
.realm
);
809 status
= ads_krb5_set_password(ads
->auth
.kdc_server
, principal
,
810 password
, ads
->auth
.time_offset
);