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
30extern struct zone zone0;
31
32struct cred {
33	uid_t		cr_uid;
34	ksid_t		*cr_ksid;
35	uint32_t	pad[100];
36};
37
38cred_t cred0;
39cred_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 */
49ksiddomain_t ksdom1 = {1, 5, "S-1-0", {0}};
50ksid_t ksid1 = { 60001, 0, 0, &ksdom1};
51cred_t cred1 = { 60001, &ksid1 };
52
53cred_t *
54_curcred(void)
55{
56	/* Thread-specific data? */
57	return (&cred1);
58}
59
60/*ARGSUSED*/
61void
62crfree(cred_t *cr)
63{
64}
65
66/*ARGSUSED*/
67void
68crhold(cred_t *cr)
69{
70}
71
72/*ARGSUSED*/
73uid_t
74crgetuid(const cred_t *cr)
75{
76	return (cr->cr_uid);
77}
78
79/*ARGSUSED*/
80uid_t
81crgetruid(const cred_t *cr)
82{
83	return (cr->cr_uid);
84}
85
86/*ARGSUSED*/
87uid_t
88crgetgid(const cred_t *cr)
89{
90	return (0);
91}
92
93/*ARGSUSED*/
94int
95crgetngroups(const cred_t *cr)
96{
97	return (0);
98}
99
100/*ARGSUSED*/
101const gid_t *
102crgetgroups(const cred_t *cr)
103{
104	return (NULL);
105}
106
107/*ARGSUSED*/
108zoneid_t
109crgetzoneid(const cred_t *cr)
110{
111	return (GLOBAL_ZONEID);
112}
113
114/*ARGSUSED*/
115struct zone *
116crgetzone(const cred_t *cr)
117{
118	return (&zone0);
119}
120
121cred_t *
122zone_kcred(void)
123{
124	return (kcred);
125}
126
127/*ARGSUSED*/
128ksid_t *
129crgetsid(const cred_t *cr, int i)
130{
131	return (cr->cr_ksid);
132}
133
134cred_t *
135ddi_get_cred(void)
136{
137	return (_curcred());
138}
139