1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 /*
29 * krb5 mechanism specific routine for pname_to_uid
30 */
31
32 #include <gssapiP_krb5.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <pwd.h>
36
37 /*
38 * This functions supplements the gsscred table.
39 *
40 * First, it provides the mapping for root principal
41 * entries. The uid mapping returned is that of 0.
42 * The name must be of the form root/... or root@...
43 * or host/... (no host@... mapped to 0 cuz host could
44 * be the name of a normal user)
45 * or in Kerberos terms, the first component must be root or host.
46 *
47 * Second, it provides the mapping for normal user principals
48 * using the passwd tbl. Thus, the gsscred table is not normally
49 * needed for the krb5 mech (though libgss will use it if this
50 * routine fails).
51 *
52 * GSS_S_COMPLETE is returned on success.
53 * GSS_S_FAILURE is returned on failure.
54 */
55 OM_uint32
krb5_pname_to_uid(minor,pname,uidOut)56 krb5_pname_to_uid(minor, pname, uidOut)
57 OM_uint32 *minor;
58 const gss_name_t pname;
59 uid_t *uidOut;
60 {
61 krb5_context context;
62 char lname[256];
63 struct passwd *pw;
64 krb5_error_code stat;
65
66 if (! kg_validate_name(pname))
67 {
68 *minor = (OM_uint32) G_VALIDATE_FAILED;
69 return (GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
70 }
71
72 stat = krb5_init_context(&context);
73 if (stat) {
74 *minor = stat;
75 return (GSS_S_FAILURE);
76 }
77
78 stat = krb5_aname_to_localname(context, (krb5_principal) pname,
79 sizeof (lname), lname);
80 krb5_free_context(context);
81 context = NULL;
82 if (stat)
83 return (GSS_S_FAILURE);
84
85 /* get the uid from the passwd tbl */
86 if (pw = getpwnam(lname))
87 {
88 *uidOut = pw->pw_uid;
89 return (GSS_S_COMPLETE);
90 }
91
92 return (GSS_S_FAILURE);
93 } /* krb5_pname_to_uid */
94