10Sstevel@tonic-gate /* 2*781Sgtb * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*781Sgtb * Use is subject to license terms. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate 60Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 70Sstevel@tonic-gate 80Sstevel@tonic-gate /* 90Sstevel@tonic-gate * lib/krb5/os/changepw.c 100Sstevel@tonic-gate * 110Sstevel@tonic-gate * Copyright 1990,1999 by the Massachusetts Institute of Technology. 120Sstevel@tonic-gate * All Rights Reserved. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * Export of this software from the United States of America may 150Sstevel@tonic-gate * require a specific license from the United States Government. 160Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating 170Sstevel@tonic-gate * export to obtain such a license before exporting. 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 200Sstevel@tonic-gate * distribute this software and its documentation for any purpose and 210Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright 220Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and 230Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that 240Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining 250Sstevel@tonic-gate * to distribution of the software without specific, written prior 260Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label 270Sstevel@tonic-gate * your software as modified software and not distribute it in such a 280Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software. 290Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of 300Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express 310Sstevel@tonic-gate * or implied warranty. 320Sstevel@tonic-gate * 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #define NEED_SOCKETS 360Sstevel@tonic-gate #include <krb5.h> 370Sstevel@tonic-gate #include <k5-int.h> 380Sstevel@tonic-gate #include <kadm5/admin.h> 390Sstevel@tonic-gate #include <client_internal.h> 400Sstevel@tonic-gate #include <gssapi/gssapi.h> 410Sstevel@tonic-gate #include <gssapi_krb5.h> 420Sstevel@tonic-gate #include <gssapiP_krb5.h> 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* #include "adm_err.h" */ 450Sstevel@tonic-gate #include <stdio.h> 460Sstevel@tonic-gate #include <errno.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate extern krb5_error_code krb5_mk_chpw_req(krb5_context context, 490Sstevel@tonic-gate krb5_auth_context auth_context, 500Sstevel@tonic-gate krb5_data *ap_req, char *passwd, 510Sstevel@tonic-gate krb5_data *packet); 520Sstevel@tonic-gate 530Sstevel@tonic-gate extern krb5_error_code krb5_rd_chpw_rep(krb5_context context, 540Sstevel@tonic-gate krb5_auth_context auth_context, 550Sstevel@tonic-gate krb5_data *packet, int *result_code, 560Sstevel@tonic-gate krb5_data *result_data); 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * _kadm5_get_kpasswd_protocol 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * returns the password change protocol value to the caller. 620Sstevel@tonic-gate * Since the 'handle' is an opaque value to higher up callers, 630Sstevel@tonic-gate * this method is needed to provide a way for them to get a peek 640Sstevel@tonic-gate * at the protocol being used without having to expose the entire 650Sstevel@tonic-gate * handle structure. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate krb5_chgpwd_prot 680Sstevel@tonic-gate _kadm5_get_kpasswd_protocol(void *handle) 690Sstevel@tonic-gate { 700Sstevel@tonic-gate kadm5_server_handle_t srvrhdl = (kadm5_server_handle_t)handle; 710Sstevel@tonic-gate 720Sstevel@tonic-gate return (srvrhdl->params.kpasswd_protocol); 730Sstevel@tonic-gate } 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * krb5_change_password 770Sstevel@tonic-gate * 780Sstevel@tonic-gate * Prepare and send a CHANGEPW request to a password server 790Sstevel@tonic-gate * using UDP datagrams. This is only used for sending to 800Sstevel@tonic-gate * non-SEAM servers which support the Marc Horowitz defined 810Sstevel@tonic-gate * protocol (1998) for password changing. 820Sstevel@tonic-gate * 83*781Sgtb * SUNW14resync - added _local as it conflicts with one in krb5.h 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate static krb5_error_code 86*781Sgtb krb5_change_password_local(context, params, creds, newpw, srvr_rsp_code, 870Sstevel@tonic-gate srvr_msg) 880Sstevel@tonic-gate krb5_context context; 890Sstevel@tonic-gate kadm5_config_params *params; 900Sstevel@tonic-gate krb5_creds *creds; 910Sstevel@tonic-gate char *newpw; 920Sstevel@tonic-gate kadm5_ret_t *srvr_rsp_code; 930Sstevel@tonic-gate krb5_data *srvr_msg; 940Sstevel@tonic-gate { 950Sstevel@tonic-gate krb5_auth_context auth_context; 960Sstevel@tonic-gate krb5_data ap_req, chpw_req, chpw_rep; 970Sstevel@tonic-gate krb5_address local_kaddr, remote_kaddr; 980Sstevel@tonic-gate krb5_error_code code = 0; 990Sstevel@tonic-gate int i, addrlen; 1000Sstevel@tonic-gate struct sockaddr *addr_p, local_addr, remote_addr, tmp_addr; 1010Sstevel@tonic-gate struct sockaddr_in *sin_p; 1020Sstevel@tonic-gate struct hostent *hp; 1030Sstevel@tonic-gate int naddr_p; 1040Sstevel@tonic-gate int cc, local_result_code, tmp_len; 1050Sstevel@tonic-gate SOCKET s1 = INVALID_SOCKET; 1060Sstevel@tonic-gate SOCKET s2 = INVALID_SOCKET; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* Initialize values so that cleanup call can safely check for NULL */ 1100Sstevel@tonic-gate auth_context = NULL; 1110Sstevel@tonic-gate addr_p = NULL; 1120Sstevel@tonic-gate memset(&chpw_req, 0, sizeof (krb5_data)); 1130Sstevel@tonic-gate memset(&chpw_rep, 0, sizeof (krb5_data)); 1140Sstevel@tonic-gate memset(&ap_req, 0, sizeof (krb5_data)); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* initialize auth_context so that we know we have to free it */ 1170Sstevel@tonic-gate if ((code = krb5_auth_con_init(context, &auth_context))) 1180Sstevel@tonic-gate goto cleanup; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate if (code = krb5_mk_req_extended(context, &auth_context, 1210Sstevel@tonic-gate AP_OPTS_USE_SUBKEY, 1220Sstevel@tonic-gate NULL, creds, &ap_req)) 1230Sstevel@tonic-gate goto cleanup; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * find the address of the kpasswd_server. 1270Sstevel@tonic-gate */ 1280Sstevel@tonic-gate addr_p = (struct sockaddr *)malloc(sizeof (struct sockaddr)); 1290Sstevel@tonic-gate if (!addr_p) 1300Sstevel@tonic-gate goto cleanup; 1310Sstevel@tonic-gate memset(addr_p, 0, sizeof (struct sockaddr)); 1320Sstevel@tonic-gate if ((hp = gethostbyname(params->kpasswd_server)) == NULL) { 1330Sstevel@tonic-gate code = KRB5_REALM_CANT_RESOLVE; 1340Sstevel@tonic-gate goto cleanup; 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate sin_p = (struct sockaddr_in *)addr_p; 1370Sstevel@tonic-gate memset((char *)sin_p, 0, sizeof (struct sockaddr)); 1380Sstevel@tonic-gate sin_p->sin_family = hp->h_addrtype; 1390Sstevel@tonic-gate sin_p->sin_port = htons(params->kpasswd_port); 1400Sstevel@tonic-gate memcpy((char *)&sin_p->sin_addr, (char *)hp->h_addr, hp->h_length); 1410Sstevel@tonic-gate naddr_p = 1; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate * this is really obscure. s1 is used for all communications. it 1460Sstevel@tonic-gate * is left unconnected in case the server is multihomed and routes 1470Sstevel@tonic-gate * are asymmetric. s2 is connected to resolve routes and get 1480Sstevel@tonic-gate * addresses. this is the *only* way to get proper addresses for 1490Sstevel@tonic-gate * multihomed hosts if routing is asymmetric. 1500Sstevel@tonic-gate * 1510Sstevel@tonic-gate * A related problem in the server, but not the client, is that 1520Sstevel@tonic-gate * many os's have no way to disconnect a connected udp socket, so 1530Sstevel@tonic-gate * the s2 socket needs to be closed and recreated for each 1540Sstevel@tonic-gate * request. The s1 socket must not be closed, or else queued 1550Sstevel@tonic-gate * requests will be lost. 1560Sstevel@tonic-gate * 1570Sstevel@tonic-gate * A "naive" client implementation (one socket, no connect, 1580Sstevel@tonic-gate * hostname resolution to get the local ip addr) will work and 1590Sstevel@tonic-gate * interoperate if the client is single-homed. 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate if ((s1 = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) 1630Sstevel@tonic-gate { 1640Sstevel@tonic-gate code = errno; 1650Sstevel@tonic-gate goto cleanup; 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if ((s2 = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) 1690Sstevel@tonic-gate { 1700Sstevel@tonic-gate code = errno; 1710Sstevel@tonic-gate goto cleanup; 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate for (i = 0; i < naddr_p; i++) 1750Sstevel@tonic-gate { 1760Sstevel@tonic-gate fd_set fdset; 1770Sstevel@tonic-gate struct timeval timeout; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate if (connect(s2, &addr_p[i], sizeof (addr_p[i])) == 1800Sstevel@tonic-gate SOCKET_ERROR) 1810Sstevel@tonic-gate { 1820Sstevel@tonic-gate if ((errno == ECONNREFUSED) || 1830Sstevel@tonic-gate (errno == EHOSTUNREACH)) 1840Sstevel@tonic-gate continue; /* try the next addr */ 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate code = errno; 1870Sstevel@tonic-gate goto cleanup; 1880Sstevel@tonic-gate } 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate addrlen = sizeof (local_addr); 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if (getsockname(s2, &local_addr, &addrlen) < 0) 1930Sstevel@tonic-gate { 1940Sstevel@tonic-gate if ((errno == ECONNREFUSED) || 1950Sstevel@tonic-gate (errno == EHOSTUNREACH)) 1960Sstevel@tonic-gate continue; /* try the next addr */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate code = errno; 1990Sstevel@tonic-gate goto cleanup; 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * some brain-dead OS's don't return useful information from 2040Sstevel@tonic-gate * the getsockname call. Namely, windows and solaris. 2050Sstevel@tonic-gate */ 2060Sstevel@tonic-gate if (((struct sockaddr_in *)&local_addr)->sin_addr.s_addr != 0) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate local_kaddr.addrtype = ADDRTYPE_INET; 2090Sstevel@tonic-gate local_kaddr.length = sizeof (((struct sockaddr_in *) 2100Sstevel@tonic-gate &local_addr)->sin_addr); 2110Sstevel@tonic-gate local_kaddr.contents = (krb5_octet *) 2120Sstevel@tonic-gate &(((struct sockaddr_in *) 2130Sstevel@tonic-gate &local_addr)->sin_addr); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate else 2160Sstevel@tonic-gate { 2170Sstevel@tonic-gate krb5_address **addrs; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate krb5_os_localaddr(context, &addrs); 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate local_kaddr.magic = addrs[0]->magic; 2220Sstevel@tonic-gate local_kaddr.addrtype = addrs[0]->addrtype; 2230Sstevel@tonic-gate local_kaddr.length = addrs[0]->length; 2240Sstevel@tonic-gate local_kaddr.contents = malloc(addrs[0]->length); 2250Sstevel@tonic-gate memcpy(local_kaddr.contents, addrs[0]->contents, 2260Sstevel@tonic-gate addrs[0]->length); 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate krb5_free_addresses(context, addrs); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate addrlen = sizeof (remote_addr); 2320Sstevel@tonic-gate if (getpeername(s2, &remote_addr, &addrlen) < 0) 2330Sstevel@tonic-gate { 2340Sstevel@tonic-gate if ((errno == ECONNREFUSED) || 2350Sstevel@tonic-gate (errno == EHOSTUNREACH)) 2360Sstevel@tonic-gate continue; /* try the next addr */ 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate code = errno; 2390Sstevel@tonic-gate goto cleanup; 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate remote_kaddr.addrtype = ADDRTYPE_INET; 2430Sstevel@tonic-gate remote_kaddr.length = sizeof (((struct sockaddr_in *) 2440Sstevel@tonic-gate &remote_addr)->sin_addr); 2450Sstevel@tonic-gate remote_kaddr.contents = (krb5_octet *) 2460Sstevel@tonic-gate &(((struct sockaddr_in *)&remote_addr)->sin_addr); 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * mk_priv requires that the local address be set. 2500Sstevel@tonic-gate * getsockname is used for this. rd_priv requires that the 2510Sstevel@tonic-gate * remote address be set. recvfrom is used for this. If 2520Sstevel@tonic-gate * rd_priv is given a local address, and the message has the 2530Sstevel@tonic-gate * recipient addr in it, this will be checked. However, there 2540Sstevel@tonic-gate * is simply no way to know ahead of time what address the 2550Sstevel@tonic-gate * message will be delivered *to*. Therefore, it is important 2560Sstevel@tonic-gate * that either no recipient address is in the messages when 2570Sstevel@tonic-gate * mk_priv is called, or that no local address is passed to 2580Sstevel@tonic-gate * rd_priv. Both is a better idea, and I have done that. In 2590Sstevel@tonic-gate * summary, when mk_priv is called, *only* a local address is 2600Sstevel@tonic-gate * specified. when rd_priv is called, *only* a remote address 2610Sstevel@tonic-gate * is specified. Are we having fun yet? 2620Sstevel@tonic-gate */ 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate if (code = krb5_auth_con_setaddrs(context, auth_context, 2650Sstevel@tonic-gate &local_kaddr, NULL)) 2660Sstevel@tonic-gate { 2670Sstevel@tonic-gate code = errno; 2680Sstevel@tonic-gate goto cleanup; 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate if (code = krb5_mk_chpw_req(context, auth_context, 2720Sstevel@tonic-gate &ap_req, newpw, &chpw_req)) 2730Sstevel@tonic-gate { 2740Sstevel@tonic-gate code = errno; 2750Sstevel@tonic-gate goto cleanup; 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate if ((cc = sendto(s1, chpw_req.data, chpw_req.length, 0, 2790Sstevel@tonic-gate (struct sockaddr *)&addr_p[i], 2800Sstevel@tonic-gate sizeof (addr_p[i]))) != chpw_req.length) 2810Sstevel@tonic-gate { 2820Sstevel@tonic-gate if ((cc < 0) && ((errno == ECONNREFUSED) || 2830Sstevel@tonic-gate (errno == EHOSTUNREACH))) 2840Sstevel@tonic-gate continue; /* try the next addr */ 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate code = (cc < 0) ? errno : ECONNABORTED; 2870Sstevel@tonic-gate goto cleanup; 2880Sstevel@tonic-gate } 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate chpw_rep.length = 1500; 2910Sstevel@tonic-gate chpw_rep.data = (char *)malloc(chpw_rep.length); 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* XXX need a timeout/retry loop here */ 2940Sstevel@tonic-gate FD_ZERO(&fdset); 2950Sstevel@tonic-gate FD_SET(s1, &fdset); 2960Sstevel@tonic-gate timeout.tv_sec = 120; 2970Sstevel@tonic-gate timeout.tv_usec = 0; 2980Sstevel@tonic-gate switch (select(s1 + 1, &fdset, 0, 0, &timeout)) { 2990Sstevel@tonic-gate case -1: 3000Sstevel@tonic-gate code = errno; 3010Sstevel@tonic-gate goto cleanup; 3020Sstevel@tonic-gate case 0: 3030Sstevel@tonic-gate code = ETIMEDOUT; 3040Sstevel@tonic-gate goto cleanup; 3050Sstevel@tonic-gate default: 3060Sstevel@tonic-gate /* fall through */ 3070Sstevel@tonic-gate ; 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate tmp_len = sizeof (tmp_addr); 3110Sstevel@tonic-gate if ((cc = recvfrom(s1, chpw_rep.data, chpw_rep.length, 3120Sstevel@tonic-gate 0, &tmp_addr, &tmp_len)) < 0) 3130Sstevel@tonic-gate { 3140Sstevel@tonic-gate code = errno; 3150Sstevel@tonic-gate goto cleanup; 3160Sstevel@tonic-gate } 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate closesocket(s1); 3190Sstevel@tonic-gate s1 = INVALID_SOCKET; 3200Sstevel@tonic-gate closesocket(s2); 3210Sstevel@tonic-gate s2 = INVALID_SOCKET; 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate chpw_rep.length = cc; 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate if (code = krb5_auth_con_setaddrs(context, auth_context, 3260Sstevel@tonic-gate NULL, &remote_kaddr)) 3270Sstevel@tonic-gate goto cleanup; 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate if (code = krb5_rd_chpw_rep(context, auth_context, &chpw_rep, 3300Sstevel@tonic-gate &local_result_code, srvr_msg)) 3310Sstevel@tonic-gate goto cleanup; 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate if (srvr_rsp_code) 3340Sstevel@tonic-gate *srvr_rsp_code = local_result_code; 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate code = 0; 3370Sstevel@tonic-gate goto cleanup; 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate code = errno; 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate cleanup: 3430Sstevel@tonic-gate if (auth_context != NULL) 3440Sstevel@tonic-gate krb5_auth_con_free(context, auth_context); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate if (addr_p != NULL) 3470Sstevel@tonic-gate krb5_xfree(addr_p); 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate if (s1 != INVALID_SOCKET) 3500Sstevel@tonic-gate closesocket(s1); 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate if (s2 != INVALID_SOCKET) 3530Sstevel@tonic-gate closesocket(s2); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate krb5_xfree(chpw_req.data); 3560Sstevel@tonic-gate krb5_xfree(chpw_rep.data); 3570Sstevel@tonic-gate krb5_xfree(ap_req.data); 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate return (code); 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate /* 3640Sstevel@tonic-gate * kadm5_chpass_principal_v2 3650Sstevel@tonic-gate * 3660Sstevel@tonic-gate * New function used to prepare to make the change password request to a 3670Sstevel@tonic-gate * non-SEAM admin server. The protocol used in this case is not based on 3680Sstevel@tonic-gate * RPCSEC_GSS, it simply makes the request to port 464 (udp and tcp). 3690Sstevel@tonic-gate * This is the same way that MIT KRB5 1.2.1 changes passwords. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate kadm5_ret_t 3720Sstevel@tonic-gate kadm5_chpass_principal_v2(void *server_handle, 3730Sstevel@tonic-gate krb5_principal princ, 3740Sstevel@tonic-gate char *newpw, 3750Sstevel@tonic-gate kadm5_ret_t *srvr_rsp_code, 3760Sstevel@tonic-gate krb5_data *srvr_msg) 3770Sstevel@tonic-gate { 3780Sstevel@tonic-gate kadm5_ret_t code; 3790Sstevel@tonic-gate kadm5_server_handle_t handle = (kadm5_server_handle_t)server_handle; 3800Sstevel@tonic-gate krb5_error_code result; 3810Sstevel@tonic-gate krb5_creds mcreds; 3820Sstevel@tonic-gate krb5_creds ncreds; 3830Sstevel@tonic-gate krb5_ccache ccache; 3840Sstevel@tonic-gate int cpwlen; 3850Sstevel@tonic-gate char *cpw_service = NULL; 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate /* 3880Sstevel@tonic-gate * The credentials have already been stored in the cache in the 3890Sstevel@tonic-gate * initialization step earlier, but we dont have direct access to it 3900Sstevel@tonic-gate * at this level. Derive the cache and fetch the credentials to use for 3910Sstevel@tonic-gate * sending the request. 3920Sstevel@tonic-gate */ 3930Sstevel@tonic-gate memset(&mcreds, 0, sizeof (krb5_creds)); 3940Sstevel@tonic-gate if ((code = krb5_cc_resolve(handle->context, handle->cache_name, 3950Sstevel@tonic-gate &ccache))) 3960Sstevel@tonic-gate return (code); 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate /* set the client principal in the credential match structure */ 3990Sstevel@tonic-gate mcreds.client = princ; 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4020Sstevel@tonic-gate * set the server principal (kadmin/changepw@REALM) in the credential 4030Sstevel@tonic-gate * match struct 4040Sstevel@tonic-gate */ 4050Sstevel@tonic-gate cpwlen = strlen(KADM5_CHANGEPW_SERVICE) + 4060Sstevel@tonic-gate strlen(handle->params.realm) + 2; 4070Sstevel@tonic-gate cpw_service = malloc(cpwlen); 4080Sstevel@tonic-gate if (cpw_service == NULL) { 4090Sstevel@tonic-gate return (ENOMEM); 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate snprintf(cpw_service, cpwlen, "%s@%s", 4130Sstevel@tonic-gate KADM5_CHANGEPW_SERVICE, handle->params.realm); 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* generate the server principal from the name string we generated */ 4160Sstevel@tonic-gate if ((code = krb5_parse_name(handle->context, cpw_service, 4170Sstevel@tonic-gate &mcreds.server))) { 4180Sstevel@tonic-gate free(cpw_service); 4190Sstevel@tonic-gate return (code); 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /* Find the credentials in the cache */ 4230Sstevel@tonic-gate if ((code = krb5_cc_retrieve_cred(handle->context, ccache, 0, &mcreds, 4240Sstevel@tonic-gate &ncreds))) { 4250Sstevel@tonic-gate free(cpw_service); 4260Sstevel@tonic-gate return (code); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate /* Now we have all we need to make the change request. */ 430*781Sgtb result = krb5_change_password_local(handle->context, &handle->params, 4310Sstevel@tonic-gate &ncreds, newpw, 4320Sstevel@tonic-gate srvr_rsp_code, 4330Sstevel@tonic-gate srvr_msg); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate free(cpw_service); 4360Sstevel@tonic-gate return (result); 4370Sstevel@tonic-gate } 438