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 *
54 _curcred(void)
55 {
56 return (&cred1);
57 }
58
59 /*ARGSUSED*/
60 void
61 crfree(cred_t *cr)
62 {
63 }
64
65 /*ARGSUSED*/
66 void
67 crhold(cred_t *cr)
68 {
69 }
70
71 /*ARGSUSED*/
72 uid_t
73 crgetuid(const cred_t *cr)
74 {
75 return (cr->cr_uid);
76 }
77
78 /*ARGSUSED*/
79 uid_t
80 crgetruid(const cred_t *cr)
81 {
82 return (cr->cr_uid);
83 }
84
85 /*ARGSUSED*/
86 uid_t
87 crgetgid(const cred_t *cr)
88 {
89 return (0);
90 }
91
92 /*ARGSUSED*/
93 int
94 crgetngroups(const cred_t *cr)
95 {
96 return (0);
97 }
98
99 /*ARGSUSED*/
100 const gid_t *
101 crgetgroups(const cred_t *cr)
102 {
103 return (NULL);
104 }
105
106 /*ARGSUSED*/
107 zoneid_t
108 crgetzoneid(const cred_t *cr)
109 {
110 return (GLOBAL_ZONEID);
111 }
112
113 /*ARGSUSED*/
114 struct zone *
115 crgetzone(const cred_t *cr)
116 {
117 return (&zone0);
118 }
119
120 cred_t *
121 zone_kcred(void)
122 {
123 return (kcred);
124 }
125
126 /*ARGSUSED*/
127 ksid_t *
128 crgetsid(const cred_t *cr, int i)
129 {
130 return (cr->cr_ksid);
131 }
132
133 cred_t *
134 ddi_get_cred(void)
135 {
136 return (_curcred());
137 }