Path: blob/main/crypto/heimdal/lib/gssapi/krb5/pname_to_uid.c
34923 views
/*1* Copyright (c) 2011, PADL Software Pty Ltd.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* 3. Neither the name of PADL Software nor the names of its contributors16* may be used to endorse or promote products derived from this software17* without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/3132#include "gsskrb5_locl.h"3334OM_uint32 GSSAPI_CALLCONV35_gsskrb5_pname_to_uid(OM_uint32 *minor_status,36const gss_name_t pname,37const gss_OID mech_type,38uid_t *uidp)39{40#ifdef NO_LOCALNAME41*minor_status = KRB5_NO_LOCALNAME;42return GSS_S_FAILURE;43#else44krb5_error_code ret;45krb5_context context;46krb5_const_principal princ = (krb5_const_principal)pname;47char localname[256];48#ifdef POSIX_GETPWNAM_R49char pwbuf[2048];50struct passwd pw, *pwd;51#else52struct passwd *pwd;53#endif5455GSSAPI_KRB5_INIT(&context);5657*minor_status = 0;5859ret = krb5_aname_to_localname(context, princ,60sizeof(localname), localname);61if (ret != 0) {62*minor_status = ret;63return GSS_S_FAILURE;64}6566#ifdef POSIX_GETPWNAM_R67if (getpwnam_r(localname, &pw, pwbuf, sizeof(pwbuf), &pwd) != 0) {68*minor_status = KRB5_NO_LOCALNAME;69return GSS_S_FAILURE;70}71#else72pwd = getpwnam(localname);73#endif7475if (pwd == NULL) {76*minor_status = KRB5_NO_LOCALNAME;77return GSS_S_FAILURE;78}7980*uidp = pwd->pw_uid;8182return GSS_S_COMPLETE;83#endif /* NO_LOCALNAME */84}858687