18f55a568SDoug Rabson /*- 28f55a568SDoug Rabson * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 38f55a568SDoug Rabson * Authors: Doug Rabson <dfr@rabson.org> 48f55a568SDoug Rabson * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 58f55a568SDoug Rabson * 68f55a568SDoug Rabson * Redistribution and use in source and binary forms, with or without 78f55a568SDoug Rabson * modification, are permitted provided that the following conditions 88f55a568SDoug Rabson * are met: 98f55a568SDoug Rabson * 1. Redistributions of source code must retain the above copyright 108f55a568SDoug Rabson * notice, this list of conditions and the following disclaimer. 118f55a568SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 128f55a568SDoug Rabson * notice, this list of conditions and the following disclaimer in the 138f55a568SDoug Rabson * documentation and/or other materials provided with the distribution. 148f55a568SDoug Rabson * 158f55a568SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168f55a568SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178f55a568SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188f55a568SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 198f55a568SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208f55a568SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218f55a568SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228f55a568SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238f55a568SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248f55a568SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258f55a568SDoug Rabson * SUCH DAMAGE. 268f55a568SDoug Rabson */ 278f55a568SDoug Rabson /* $FreeBSD$ */ 288f55a568SDoug Rabson 298f55a568SDoug Rabson #include <pwd.h> 308f55a568SDoug Rabson 318f55a568SDoug Rabson #include "krb5/gsskrb5_locl.h" 328f55a568SDoug Rabson 338f55a568SDoug Rabson OM_uint32 348f55a568SDoug Rabson _gsskrb5_pname_to_uid(OM_uint32 *minor_status, const gss_name_t pname, 358f55a568SDoug Rabson const gss_OID mech, uid_t *uidp) 368f55a568SDoug Rabson { 378f55a568SDoug Rabson krb5_context context; 388f55a568SDoug Rabson krb5_const_principal name = (krb5_const_principal) pname; 398f55a568SDoug Rabson krb5_error_code kret; 408f55a568SDoug Rabson char lname[MAXLOGNAME + 1], buf[128]; 418f55a568SDoug Rabson struct passwd pwd, *pw; 428f55a568SDoug Rabson 438f55a568SDoug Rabson GSSAPI_KRB5_INIT (&context); 448f55a568SDoug Rabson 458f55a568SDoug Rabson kret = krb5_aname_to_localname(context, name, sizeof(lname), lname); 468f55a568SDoug Rabson if (kret) { 478f55a568SDoug Rabson *minor_status = kret; 488f55a568SDoug Rabson return (GSS_S_FAILURE); 498f55a568SDoug Rabson } 508f55a568SDoug Rabson 518f55a568SDoug Rabson *minor_status = 0; 528f55a568SDoug Rabson getpwnam_r(lname, &pwd, buf, sizeof(buf), &pw); 538f55a568SDoug Rabson if (pw) { 548f55a568SDoug Rabson *uidp = pw->pw_uid; 558f55a568SDoug Rabson return (GSS_S_COMPLETE); 568f55a568SDoug Rabson } else { 578f55a568SDoug Rabson return (GSS_S_FAILURE); 588f55a568SDoug Rabson } 598f55a568SDoug Rabson } 60