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 remote_addr
, local_addr
;
405 struct in_addr
*addr
= interpret_addr2(kdc_host
);
406 krb5_address local_kaddr
, remote_kaddr
;
407 BOOL use_tcp
= False
;
410 ret
= krb5_mk_req_extended(context
, &auth_context
, AP_OPTS_USE_SUBKEY
,
411 NULL
, credsp
, &ap_req
);
413 DEBUG(1,("krb5_mk_req_extended failed (%s)\n", error_message(ret
)));
414 return ADS_ERROR_KRB5(ret
);
421 sock
= open_udp_socket(kdc_host
, DEFAULT_KPASSWD_PORT
);
425 sock
= open_socket_out(SOCK_STREAM
, addr
, DEFAULT_KPASSWD_PORT
,
426 LONG_CONNECT_TIMEOUT
);
431 SAFE_FREE(ap_req
.data
);
432 krb5_auth_con_free(context
, auth_context
);
433 DEBUG(1,("failed to open kpasswd socket to %s (%s)\n",
434 kdc_host
, strerror(errno
)));
435 return ADS_ERROR_SYSTEM(rc
);
438 addr_len
= sizeof(remote_addr
);
439 getpeername(sock
, &remote_addr
, &addr_len
);
440 addr_len
= sizeof(local_addr
);
441 getsockname(sock
, &local_addr
, &addr_len
);
443 setup_kaddr(&remote_kaddr
, &remote_addr
);
444 setup_kaddr(&local_kaddr
, &local_addr
);
446 ret
= krb5_auth_con_setaddrs(context
, auth_context
, &local_kaddr
, NULL
);
449 SAFE_FREE(ap_req
.data
);
450 krb5_auth_con_free(context
, auth_context
);
451 DEBUG(1,("krb5_auth_con_setaddrs failed (%s)\n", error_message(ret
)));
452 return ADS_ERROR_KRB5(ret
);
455 ret
= build_kpasswd_request(pversion
, context
, auth_context
, &ap_req
,
456 princ
, newpw
, use_tcp
, &chpw_req
);
459 SAFE_FREE(ap_req
.data
);
460 krb5_auth_con_free(context
, auth_context
);
461 DEBUG(1,("build_setpw_request failed (%s)\n", error_message(ret
)));
462 return ADS_ERROR_KRB5(ret
);
465 ret
= write(sock
, chpw_req
.data
, chpw_req
.length
);
467 if (ret
!= chpw_req
.length
) {
469 SAFE_FREE(chpw_req
.data
);
470 SAFE_FREE(ap_req
.data
);
471 krb5_auth_con_free(context
, auth_context
);
472 DEBUG(1,("send of chpw failed (%s)\n", strerror(errno
)));
473 return ADS_ERROR_SYSTEM(errno
);
476 SAFE_FREE(chpw_req
.data
);
478 chpw_rep
.length
= 1500;
479 chpw_rep
.data
= (char *) SMB_MALLOC(chpw_rep
.length
);
480 if (!chpw_rep
.data
) {
482 SAFE_FREE(ap_req
.data
);
483 krb5_auth_con_free(context
, auth_context
);
484 DEBUG(1,("send of chpw failed (%s)\n", strerror(errno
)));
486 return ADS_ERROR_SYSTEM(errno
);
489 ret
= read(sock
, chpw_rep
.data
, chpw_rep
.length
);
492 SAFE_FREE(chpw_rep
.data
);
493 SAFE_FREE(ap_req
.data
);
494 krb5_auth_con_free(context
, auth_context
);
495 DEBUG(1,("recv of chpw reply failed (%s)\n", strerror(errno
)));
496 return ADS_ERROR_SYSTEM(errno
);
500 chpw_rep
.length
= ret
;
502 ret
= krb5_auth_con_setaddrs(context
, auth_context
, NULL
,&remote_kaddr
);
504 SAFE_FREE(chpw_rep
.data
);
505 SAFE_FREE(ap_req
.data
);
506 krb5_auth_con_free(context
, auth_context
);
507 DEBUG(1,("krb5_auth_con_setaddrs on reply failed (%s)\n",
508 error_message(ret
)));
509 return ADS_ERROR_KRB5(ret
);
512 ret
= parse_setpw_reply(context
, use_tcp
, auth_context
, &chpw_rep
);
513 SAFE_FREE(chpw_rep
.data
);
517 if (ret
== KRB5KRB_ERR_RESPONSE_TOO_BIG
&& !use_tcp
) {
518 DEBUG(5, ("Trying setpw with TCP!!!\n"));
523 SAFE_FREE(ap_req
.data
);
524 krb5_auth_con_free(context
, auth_context
);
525 DEBUG(1,("parse_setpw_reply failed (%s)\n",
526 error_message(ret
)));
527 return ADS_ERROR_KRB5(ret
);
530 SAFE_FREE(ap_req
.data
);
531 krb5_auth_con_free(context
, auth_context
);
537 ADS_STATUS
ads_krb5_set_password(const char *kdc_host
, const char *princ
,
538 const char *newpw
, int time_offset
)
542 krb5_error_code ret
= 0;
543 krb5_context context
= NULL
;
544 krb5_principal principal
= NULL
;
545 char *princ_name
= NULL
;
547 krb5_creds creds
, *credsp
= NULL
;
548 #if KRB5_PRINC_REALM_RETURNS_REALM
549 krb5_realm orig_realm
;
551 krb5_data orig_realm
;
553 krb5_ccache ccache
= NULL
;
557 initialize_krb5_error_table();
558 ret
= krb5_init_context(&context
);
560 DEBUG(1,("Failed to init krb5 context (%s)\n", error_message(ret
)));
561 return ADS_ERROR_KRB5(ret
);
564 if (time_offset
!= 0) {
565 krb5_set_real_time(context
, time(NULL
) + time_offset
, 0);
568 ret
= krb5_cc_default(context
, &ccache
);
570 krb5_free_context(context
);
571 DEBUG(1,("Failed to get default creds (%s)\n", error_message(ret
)));
572 return ADS_ERROR_KRB5(ret
);
575 realm
= strchr_m(princ
, '@');
577 krb5_cc_close(context
, ccache
);
578 krb5_free_context(context
);
579 DEBUG(1,("Failed to get realm\n"));
580 return ADS_ERROR_KRB5(-1);
584 asprintf(&princ_name
, "kadmin/changepw@%s", realm
);
585 ret
= smb_krb5_parse_name(context
, princ_name
, &creds
.server
);
587 krb5_cc_close(context
, ccache
);
588 krb5_free_context(context
);
589 DEBUG(1,("Failed to parse kadmin/changepw (%s)\n", error_message(ret
)));
590 return ADS_ERROR_KRB5(ret
);
593 /* parse the principal we got as a function argument */
594 ret
= smb_krb5_parse_name(context
, princ
, &principal
);
596 krb5_cc_close(context
, ccache
);
597 krb5_free_principal(context
, creds
.server
);
598 krb5_free_context(context
);
599 DEBUG(1,("Failed to parse %s (%s)\n", princ_name
, error_message(ret
)));
601 return ADS_ERROR_KRB5(ret
);
606 /* The creds.server principal takes ownership of this memory.
607 Remember to set back to original value before freeing. */
608 orig_realm
= *krb5_princ_realm(context
, creds
.server
);
609 krb5_princ_set_realm(context
, creds
.server
, krb5_princ_realm(context
, principal
));
611 ret
= krb5_cc_get_principal(context
, ccache
, &creds
.client
);
613 krb5_cc_close(context
, ccache
);
614 krb5_princ_set_realm(context
, creds
.server
, &orig_realm
);
615 krb5_free_principal(context
, creds
.server
);
616 krb5_free_principal(context
, principal
);
617 krb5_free_context(context
);
618 DEBUG(1,("Failed to get principal from ccache (%s)\n",
619 error_message(ret
)));
620 return ADS_ERROR_KRB5(ret
);
623 ret
= krb5_get_credentials(context
, 0, ccache
, &creds
, &credsp
);
625 krb5_cc_close(context
, ccache
);
626 krb5_free_principal(context
, creds
.client
);
627 krb5_princ_set_realm(context
, creds
.server
, &orig_realm
);
628 krb5_free_principal(context
, creds
.server
);
629 krb5_free_principal(context
, principal
);
630 krb5_free_context(context
);
631 DEBUG(1,("krb5_get_credentials failed (%s)\n", error_message(ret
)));
632 return ADS_ERROR_KRB5(ret
);
635 /* we might have to call krb5_free_creds(...) from now on ... */
637 aret
= do_krb5_kpasswd_request(context
, kdc_host
,
638 KRB5_KPASSWD_VERS_SETPW
,
639 credsp
, princ
, newpw
);
641 krb5_free_creds(context
, credsp
);
642 krb5_free_principal(context
, creds
.client
);
643 krb5_princ_set_realm(context
, creds
.server
, &orig_realm
);
644 krb5_free_principal(context
, creds
.server
);
645 krb5_free_principal(context
, principal
);
646 krb5_cc_close(context
, ccache
);
647 krb5_free_context(context
);
653 we use a prompter to avoid a crash bug in the kerberos libs when
654 dealing with empty passwords
655 this prompter is just a string copy ...
657 static krb5_error_code
658 kerb_prompter(krb5_context ctx
, void *data
,
662 krb5_prompt prompts
[])
664 if (num_prompts
== 0) return 0;
666 memset(prompts
[0].reply
->data
, 0, prompts
[0].reply
->length
);
667 if (prompts
[0].reply
->length
> 0) {
669 strncpy(prompts
[0].reply
->data
,
671 prompts
[0].reply
->length
-1);
672 prompts
[0].reply
->length
= strlen(prompts
[0].reply
->data
);
674 prompts
[0].reply
->length
= 0;
680 static ADS_STATUS
ads_krb5_chg_password(const char *kdc_host
,
681 const char *principal
,
688 krb5_context context
= NULL
;
689 krb5_principal princ
;
690 krb5_get_init_creds_opt opts
;
692 char *chpw_princ
= NULL
, *password
;
694 initialize_krb5_error_table();
695 ret
= krb5_init_context(&context
);
697 DEBUG(1,("Failed to init krb5 context (%s)\n", error_message(ret
)));
698 return ADS_ERROR_KRB5(ret
);
701 if ((ret
= smb_krb5_parse_name(context
, principal
,
703 krb5_free_context(context
);
704 DEBUG(1,("Failed to parse %s (%s)\n", principal
, error_message(ret
)));
705 return ADS_ERROR_KRB5(ret
);
708 krb5_get_init_creds_opt_init(&opts
);
709 krb5_get_init_creds_opt_set_tkt_life(&opts
, 5*60);
710 krb5_get_init_creds_opt_set_renew_life(&opts
, 0);
711 krb5_get_init_creds_opt_set_forwardable(&opts
, 0);
712 krb5_get_init_creds_opt_set_proxiable(&opts
, 0);
714 /* We have to obtain an INITIAL changepw ticket for changing password */
715 asprintf(&chpw_princ
, "kadmin/changepw@%s",
716 (char *) krb5_princ_realm(context
, princ
));
717 password
= SMB_STRDUP(oldpw
);
718 ret
= krb5_get_init_creds_password(context
, &creds
, princ
, password
,
720 0, chpw_princ
, &opts
);
721 SAFE_FREE(chpw_princ
);
725 if (ret
== KRB5KRB_AP_ERR_BAD_INTEGRITY
)
726 DEBUG(1,("Password incorrect while getting initial ticket"));
728 DEBUG(1,("krb5_get_init_creds_password failed (%s)\n", error_message(ret
)));
730 krb5_free_principal(context
, princ
);
731 krb5_free_context(context
);
732 return ADS_ERROR_KRB5(ret
);
735 aret
= do_krb5_kpasswd_request(context
, kdc_host
,
736 KRB5_KPASSWD_VERS_CHANGEPW
,
737 &creds
, principal
, newpw
);
739 krb5_free_principal(context
, princ
);
740 krb5_free_context(context
);
746 ADS_STATUS
kerberos_set_password(const char *kpasswd_server
,
747 const char *auth_principal
, const char *auth_password
,
748 const char *target_principal
, const char *new_password
,
753 if ((ret
= kerberos_kinit_password(auth_principal
, auth_password
, time_offset
, NULL
))) {
754 DEBUG(1,("Failed kinit for principal %s (%s)\n", auth_principal
, error_message(ret
)));
755 return ADS_ERROR_KRB5(ret
);
758 if (!strcmp(auth_principal
, target_principal
))
759 return ads_krb5_chg_password(kpasswd_server
, target_principal
,
760 auth_password
, new_password
, time_offset
);
762 return ads_krb5_set_password(kpasswd_server
, target_principal
,
763 new_password
, time_offset
);
768 * Set the machine account password
769 * @param ads connection to ads server
770 * @param hostname machine whose password is being set
771 * @param password new password
772 * @return status of password change
774 ADS_STATUS
ads_set_machine_password(ADS_STRUCT
*ads
,
775 const char *machine_account
,
776 const char *password
)
779 char *principal
= NULL
;
782 we need to use the '$' form of the name here (the machine account name),
783 as otherwise the server might end up setting the password for a user
786 asprintf(&principal
, "%s@%s", machine_account
, ads
->config
.realm
);
788 status
= ads_krb5_set_password(ads
->auth
.kdc_server
, principal
,
789 password
, ads
->auth
.time_offset
);