1b819cea2SGordon Ross /*
2b819cea2SGordon Ross  * This file and its contents are supplied under the terms of the
3b819cea2SGordon Ross  * Common Development and Distribution License ("CDDL"), version 1.0.
4b819cea2SGordon Ross  * You may only use this file in accordance with the terms of version
5b819cea2SGordon Ross  * 1.0 of the CDDL.
6b819cea2SGordon Ross  *
7b819cea2SGordon Ross  * A full copy of the text of the CDDL should have accompanied this
8b819cea2SGordon Ross  * source.  A copy of the CDDL is also available via the Internet at
9b819cea2SGordon Ross  * http://www.illumos.org/license/CDDL.
10b819cea2SGordon Ross  */
11b819cea2SGordon Ross 
12b819cea2SGordon Ross /*
13*8329232eSGordon Ross  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
14f06dce2cSAndrew Stormont  * Copyright 2017 RackTop Systems.
15b819cea2SGordon Ross  */
16b819cea2SGordon Ross 
17b819cea2SGordon Ross #include <sys/types.h>
18b819cea2SGordon Ross #include <sys/time.h>
19b819cea2SGordon Ross #include <sys/thread.h>
20b819cea2SGordon Ross #include <sys/cred.h>
21*8329232eSGordon Ross #include <sys/sid.h>
22*8329232eSGordon Ross #include <strings.h>
23*8329232eSGordon Ross 
24*8329232eSGordon Ross /*
25*8329232eSGordon Ross  * This library does not implement real credentials. All contexts
26*8329232eSGordon Ross  * use an opaque cred_t object, and all activity happens in the
27*8329232eSGordon Ross  * context of the user who runs the program.
28*8329232eSGordon Ross  */
29*8329232eSGordon Ross 
30*8329232eSGordon Ross extern struct zone zone0;
31b819cea2SGordon Ross 
32b819cea2SGordon Ross struct cred {
33*8329232eSGordon Ross 	uid_t		cr_uid;
34*8329232eSGordon Ross 	ksid_t		*cr_ksid;
35b819cea2SGordon Ross 	uint32_t	pad[100];
36b819cea2SGordon Ross };
37b819cea2SGordon Ross 
38b819cea2SGordon Ross cred_t cred0;
39b819cea2SGordon Ross cred_t *kcred = &cred0;
40b819cea2SGordon Ross 
41*8329232eSGordon Ross /*
42*8329232eSGordon Ross  * Note that fksmbd uses CRED() for SMB user logons, but uses
43*8329232eSGordon Ross  * zone_kcred() for operations done internally by the server.
44*8329232eSGordon Ross  * Let CRED() (_curcred()) return &cred1, so it's different from
45*8329232eSGordon Ross  * kcred, otherwise tests like: (cred == kcred) are always true.
46*8329232eSGordon Ross  * Also, only cred1 will have a ksid (not kcred).
47*8329232eSGordon Ross  * The UID and SID are both "nobody".
48*8329232eSGordon Ross  */
49*8329232eSGordon Ross ksiddomain_t ksdom1 = {1, 5, "S-1-0", {0}};
50*8329232eSGordon Ross ksid_t ksid1 = { 60001, 0, 0, &ksdom1};
51*8329232eSGordon Ross cred_t cred1 = { 60001, &ksid1 };
52*8329232eSGordon Ross 
53b819cea2SGordon Ross cred_t *
_curcred(void)54b819cea2SGordon Ross _curcred(void)
55b819cea2SGordon Ross {
56b819cea2SGordon Ross 	/* Thread-specific data? */
57*8329232eSGordon Ross 	return (&cred1);
58b819cea2SGordon Ross }
59b819cea2SGordon Ross 
60b819cea2SGordon Ross /*ARGSUSED*/
61b819cea2SGordon Ross void
crfree(cred_t * cr)62b819cea2SGordon Ross crfree(cred_t *cr)
63b819cea2SGordon Ross {
64b819cea2SGordon Ross }
65b819cea2SGordon Ross 
66b819cea2SGordon Ross /*ARGSUSED*/
67b819cea2SGordon Ross void
crhold(cred_t * cr)68b819cea2SGordon Ross crhold(cred_t *cr)
69b819cea2SGordon Ross {
70b819cea2SGordon Ross }
71b819cea2SGordon Ross 
72b819cea2SGordon Ross /*ARGSUSED*/
73b819cea2SGordon Ross uid_t
crgetuid(const cred_t * cr)74b819cea2SGordon Ross crgetuid(const cred_t *cr)
75b819cea2SGordon Ross {
76*8329232eSGordon Ross 	return (cr->cr_uid);
77b819cea2SGordon Ross }
78b819cea2SGordon Ross 
79f06dce2cSAndrew Stormont /*ARGSUSED*/
80f06dce2cSAndrew Stormont uid_t
crgetruid(const cred_t * cr)81f06dce2cSAndrew Stormont crgetruid(const cred_t *cr)
82f06dce2cSAndrew Stormont {
83*8329232eSGordon Ross 	return (cr->cr_uid);
84f06dce2cSAndrew Stormont }
85f06dce2cSAndrew Stormont 
86f06dce2cSAndrew Stormont /*ARGSUSED*/
87f06dce2cSAndrew Stormont uid_t
crgetgid(const cred_t * cr)88f06dce2cSAndrew Stormont crgetgid(const cred_t *cr)
89f06dce2cSAndrew Stormont {
90f06dce2cSAndrew Stormont 	return (0);
91f06dce2cSAndrew Stormont }
92f06dce2cSAndrew Stormont 
93f06dce2cSAndrew Stormont /*ARGSUSED*/
94f06dce2cSAndrew Stormont int
crgetngroups(const cred_t * cr)95f06dce2cSAndrew Stormont crgetngroups(const cred_t *cr)
96f06dce2cSAndrew Stormont {
97f06dce2cSAndrew Stormont 	return (0);
98f06dce2cSAndrew Stormont }
99f06dce2cSAndrew Stormont 
100f06dce2cSAndrew Stormont /*ARGSUSED*/
101f06dce2cSAndrew Stormont const gid_t *
crgetgroups(const cred_t * cr)102f06dce2cSAndrew Stormont crgetgroups(const cred_t *cr)
103f06dce2cSAndrew Stormont {
104f06dce2cSAndrew Stormont 	return (NULL);
105f06dce2cSAndrew Stormont }
106f06dce2cSAndrew Stormont 
107*8329232eSGordon Ross /*ARGSUSED*/
108*8329232eSGordon Ross zoneid_t
crgetzoneid(const cred_t * cr)109*8329232eSGordon Ross crgetzoneid(const cred_t *cr)
110*8329232eSGordon Ross {
111*8329232eSGordon Ross 	return (GLOBAL_ZONEID);
112*8329232eSGordon Ross }
113*8329232eSGordon Ross 
114*8329232eSGordon Ross /*ARGSUSED*/
115*8329232eSGordon Ross struct zone *
crgetzone(const cred_t * cr)116*8329232eSGordon Ross crgetzone(const cred_t *cr)
117*8329232eSGordon Ross {
118*8329232eSGordon Ross 	return (&zone0);
119*8329232eSGordon Ross }
120*8329232eSGordon Ross 
121b819cea2SGordon Ross cred_t *
zone_kcred(void)122b819cea2SGordon Ross zone_kcred(void)
123b819cea2SGordon Ross {
124b819cea2SGordon Ross 	return (kcred);
125b819cea2SGordon Ross }
126*8329232eSGordon Ross 
127*8329232eSGordon Ross /*ARGSUSED*/
128*8329232eSGordon Ross ksid_t *
crgetsid(const cred_t * cr,int i)129*8329232eSGordon Ross crgetsid(const cred_t *cr, int i)
130*8329232eSGordon Ross {
131*8329232eSGordon Ross 	return (cr->cr_ksid);
132*8329232eSGordon Ross }
133*8329232eSGordon Ross 
134*8329232eSGordon Ross cred_t *
ddi_get_cred(void)135*8329232eSGordon Ross ddi_get_cred(void)
136*8329232eSGordon Ross {
137*8329232eSGordon Ross 	return (_curcred());
138*8329232eSGordon Ross }
139