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