equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 */ |
|
4 |
|
5 #include <sys/types.h> |
|
6 #include <unistd.h> |
|
7 #include <dlfcn.h> |
|
8 #include "k5-int.h" |
|
9 |
|
10 #define KRB5_UID "app_krb5_user_uid" |
|
11 |
|
12 /* |
|
13 * mech_krb5 makes various calls to getuid(). When employed by gssd(1M) and |
|
14 * ktkt_warnd(1M), app_krb5_user_uid() is used to select a given user's |
|
15 * credential cache, rather than the id of the process. |
|
16 */ |
|
17 uid_t |
|
18 krb5_getuid() |
|
19 { |
|
20 static uid_t (*gptr)() = NULL; |
|
21 void *handle; |
|
22 |
|
23 if (gptr == NULL) { |
|
24 /* |
|
25 * Specifically look for app_krb5_user_uid() in the application, |
|
26 * and don't fall into an exhaustive search through all of the |
|
27 * process dependencies. This interface is suplied from |
|
28 * gssd(1M) and ktkt_warnd(1M). |
|
29 */ |
|
30 if (((handle = dlopen(0, (RTLD_LAZY | RTLD_FIRST))) == NULL) || |
|
31 ((gptr = (uid_t (*)())dlsym(handle, KRB5_UID)) == NULL)) { |
|
32 /* |
|
33 * Fall back to the default getuid(), which is probably |
|
34 * libc. |
|
35 */ |
|
36 gptr = &getuid; |
|
37 } |
|
38 } |
|
39 |
|
40 /* |
|
41 * Return the appropriate uid. Note, if a default getuid() couldn't |
|
42 * be found, the getuid assignment would have failed to relocate, and |
|
43 * hence this module would fail to load. |
|
44 */ |
|
45 return ((*gptr)()); |
|
46 } |