1*4271Srie /*
2*4271Srie * CDDL HEADER START
3*4271Srie *
4*4271Srie * The contents of this file are subject to the terms of the
5*4271Srie * Common Development and Distribution License (the "License").
6*4271Srie * You may not use this file except in compliance with the License.
7*4271Srie *
8*4271Srie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*4271Srie * or http://www.opensolaris.org/os/licensing.
10*4271Srie * See the License for the specific language governing permissions
11*4271Srie * and limitations under the License.
12*4271Srie *
13*4271Srie * When distributing Covered Code, include this CDDL HEADER in each
14*4271Srie * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*4271Srie * If applicable, add the following below this CDDL HEADER, with the
16*4271Srie * fields enclosed by brackets "[]" replaced with your own identifying
17*4271Srie * information: Portions Copyright [yyyy] [name of copyright owner]
18*4271Srie *
19*4271Srie * CDDL HEADER END
20*4271Srie */
21*4271Srie
22*4271Srie /*
23*4271Srie * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24*4271Srie * Use is subject to license terms.
25*4271Srie */
26*4271Srie
27*4271Srie #pragma ident "%Z%%M% %I% %E% SMI"
28*4271Srie
29*4271Srie #include <sys/types.h>
30*4271Srie #include <unistd.h>
31*4271Srie #include <dlfcn.h>
32*4271Srie #include "k5-int.h"
33*4271Srie
34*4271Srie #define KRB5_UID "app_krb5_user_uid"
35*4271Srie
36*4271Srie /*
37*4271Srie * mech_krb5 makes various calls to getuid(). When employed by gssd(1M) and
38*4271Srie * ktkt_warnd(1M), app_krb5_user_uid() is used to select a given user's
39*4271Srie * credential cache, rather than the id of the process.
40*4271Srie */
41*4271Srie uid_t
krb5_getuid()42*4271Srie krb5_getuid()
43*4271Srie {
44*4271Srie static uid_t (*gptr)() = NULL;
45*4271Srie void *handle;
46*4271Srie
47*4271Srie if (gptr == NULL) {
48*4271Srie /*
49*4271Srie * Specifically look for app_krb5_user_uid() in the application,
50*4271Srie * and don't fall into an exhaustive search through all of the
51*4271Srie * process dependencies. This interface is suplied from
52*4271Srie * gssd(1M) and ktkt_warnd(1M).
53*4271Srie */
54*4271Srie if (((handle = dlopen(0, (RTLD_LAZY | RTLD_FIRST))) == NULL) ||
55*4271Srie ((gptr = (uid_t (*)())dlsym(handle, KRB5_UID)) == NULL)) {
56*4271Srie /*
57*4271Srie * Fall back to the default getuid(), which is probably
58*4271Srie * libc.
59*4271Srie */
60*4271Srie gptr = &getuid;
61*4271Srie }
62*4271Srie }
63*4271Srie
64*4271Srie /*
65*4271Srie * Return the appropriate uid. Note, if a default getuid() couldn't
66*4271Srie * be found, the getuid assignment would have failed to relocate, and
67*4271Srie * hence this module would fail to load.
68*4271Srie */
69*4271Srie return ((*gptr)());
70*4271Srie }
71