xref: /onnv-gate/usr/src/uts/common/smbsrv/smb_token.h (revision 5331:3047ad28a67b)
1*5331Samw /*
2*5331Samw  * CDDL HEADER START
3*5331Samw  *
4*5331Samw  * The contents of this file are subject to the terms of the
5*5331Samw  * Common Development and Distribution License (the "License").
6*5331Samw  * You may not use this file except in compliance with the License.
7*5331Samw  *
8*5331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5331Samw  * or http://www.opensolaris.org/os/licensing.
10*5331Samw  * See the License for the specific language governing permissions
11*5331Samw  * and limitations under the License.
12*5331Samw  *
13*5331Samw  * When distributing Covered Code, include this CDDL HEADER in each
14*5331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5331Samw  * If applicable, add the following below this CDDL HEADER, with the
16*5331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
17*5331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5331Samw  *
19*5331Samw  * CDDL HEADER END
20*5331Samw  */
21*5331Samw /*
22*5331Samw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*5331Samw  * Use is subject to license terms.
24*5331Samw  */
25*5331Samw 
26*5331Samw #ifndef _SMB_TOKEN_H
27*5331Samw #define	_SMB_TOKEN_H
28*5331Samw 
29*5331Samw #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*5331Samw 
31*5331Samw #include <smbsrv/netrauth.h>
32*5331Samw #include <smbsrv/smb_privilege.h>
33*5331Samw 
34*5331Samw #ifdef __cplusplus
35*5331Samw extern "C" {
36*5331Samw #endif
37*5331Samw 
38*5331Samw /*
39*5331Samw  * User Session Key
40*5331Samw  *
41*5331Samw  * This is part of the MAC key which is required for signing SMB messages.
42*5331Samw  */
43*5331Samw typedef struct smb_session_key {
44*5331Samw 	uint8_t data[16];
45*5331Samw } smb_session_key_t;
46*5331Samw 
47*5331Samw /*
48*5331Samw  * Access Token
49*5331Samw  *
50*5331Samw  * An access token identifies a user, the user's privileges and the
51*5331Samw  * list of groups of which the user is a member. This information is
52*5331Samw  * used when access is requested to an object by comparing this
53*5331Samw  * information with the DACL in the object's security descriptor.
54*5331Samw  *
55*5331Samw  * Only group attributes are defined. No user attributes defined.
56*5331Samw  */
57*5331Samw 
58*5331Samw #define	SE_GROUP_MANDATORY		0x00000001
59*5331Samw #define	SE_GROUP_ENABLED_BY_DEFAULT	0x00000002
60*5331Samw #define	SE_GROUP_ENABLED		0x00000004
61*5331Samw #define	SE_GROUP_OWNER			0x00000008
62*5331Samw #define	SE_GROUP_USE_FOR_DENY_ONLY	0x00000010
63*5331Samw #define	SE_GROUP_LOGON_ID		0xC0000000
64*5331Samw 
65*5331Samw typedef struct smb_sid_attrs {
66*5331Samw 	uint32_t attrs;
67*5331Samw 	nt_sid_t *sid;
68*5331Samw } smb_sid_attrs_t;
69*5331Samw 
70*5331Samw /*
71*5331Samw  * smb_id_t consists of both the Windows security identifier
72*5331Samw  * and its corresponding POSIX/ephemeral ID.
73*5331Samw  */
74*5331Samw typedef struct smb_id {
75*5331Samw 	smb_sid_attrs_t i_sidattr;
76*5331Samw 	uid_t i_id;
77*5331Samw } smb_id_t;
78*5331Samw 
79*5331Samw /*
80*5331Samw  * Windows groups (each group SID is associated with a POSIX/ephemeral
81*5331Samw  * gid.
82*5331Samw  */
83*5331Samw typedef struct smb_win_grps {
84*5331Samw 	uint16_t wg_count;
85*5331Samw 	smb_id_t wg_groups[ANY_SIZE_ARRAY];
86*5331Samw } smb_win_grps_t;
87*5331Samw 
88*5331Samw /*
89*5331Samw  * Access Token Flags
90*5331Samw  *
91*5331Samw  * SMB_ATF_GUEST	Token belongs to guest user
92*5331Samw  * SMB_ATF_ANON		Token belongs to anonymous user
93*5331Samw  * 			and it's only good for IPC Connection.
94*5331Samw  * SMB_ATF_POWERUSER	Token belongs to a Power User member
95*5331Samw  * SMB_ATF_BACKUPOP	Token belongs to a Power User member
96*5331Samw  * SMB_ATF_ADMIN	Token belongs to a Domain Admins member
97*5331Samw  */
98*5331Samw #define	SMB_ATF_GUEST		0x00000001
99*5331Samw #define	SMB_ATF_ANON		0x00000002
100*5331Samw #define	SMB_ATF_POWERUSER	0x00000004
101*5331Samw #define	SMB_ATF_BACKUPOP	0x00000008
102*5331Samw #define	SMB_ATF_ADMIN		0x00000010
103*5331Samw 
104*5331Samw #define	SMB_POSIX_GRPS_SIZE(n) \
105*5331Samw 	(sizeof (smb_posix_grps_t) + (n - 1) * sizeof (gid_t))
106*5331Samw /*
107*5331Samw  * It consists of the primary and supplementary POSIX groups.
108*5331Samw  */
109*5331Samw typedef struct smb_posix_grps {
110*5331Samw 	uint32_t pg_ngrps;
111*5331Samw 	gid_t pg_grps[ANY_SIZE_ARRAY];
112*5331Samw } smb_posix_grps_t;
113*5331Samw 
114*5331Samw /*
115*5331Samw  * Token Structure.
116*5331Samw  *
117*5331Samw  * This structure contains information of a user. There should be one
118*5331Samw  * unique token per user per session per client. The information
119*5331Samw  * provided will either give or deny access to shares, files or folders.
120*5331Samw  */
121*5331Samw typedef struct smb_token {
122*5331Samw 	smb_id_t *tkn_user;
123*5331Samw 	smb_id_t *tkn_owner;
124*5331Samw 	smb_id_t *tkn_primary_grp;
125*5331Samw 	smb_win_grps_t *tkn_win_grps;
126*5331Samw 	smb_privset_t *tkn_privileges;
127*5331Samw 	char *tkn_account_name;
128*5331Samw 	char *tkn_domain_name;
129*5331Samw 	uint32_t tkn_flags;
130*5331Samw 	uint32_t tkn_audit_sid;
131*5331Samw 	smb_session_key_t *tkn_session_key;
132*5331Samw 	smb_posix_grps_t *tkn_posix_grps;
133*5331Samw } smb_token_t;
134*5331Samw 
135*5331Samw /*
136*5331Samw  * This is the max buffer length for holding certain fields of
137*5331Samw  * any access token: domain, account, workstation, and IP with the
138*5331Samw  * format as show below:
139*5331Samw  * [domain name]\[user account] [workstation] (IP)
140*5331Samw  *
141*5331Samw  * This is not meant to be the maximum buffer length for holding
142*5331Samw  * the entire context of a token.
143*5331Samw  */
144*5331Samw #define	NTTOKEN_BASIC_INFO_MAXLEN (SMB_PI_MAX_DOMAIN + SMB_PI_MAX_USERNAME \
145*5331Samw 					+ SMB_PI_MAX_HOST + INET_ADDRSTRLEN + 8)
146*5331Samw 
147*5331Samw /*
148*5331Samw  * Information returned by an RPC call is allocated on an internal heap
149*5331Samw  * which is deallocated before returning from the interface call. The
150*5331Samw  * smb_userinfo structure provides a useful common mechanism to get the
151*5331Samw  * information back to the caller. It's like a compact access token but
152*5331Samw  * only parts of it are filled in by each RPC so the content is call
153*5331Samw  * specific.
154*5331Samw  */
155*5331Samw typedef struct smb_rid_attrs {
156*5331Samw 	uint32_t rid;
157*5331Samw 	uint32_t attributes;
158*5331Samw } smb_rid_attrs_t;
159*5331Samw 
160*5331Samw #define	SMB_UINFO_FLAG_ANON	0x01
161*5331Samw #define	SMB_UINFO_FLAG_LADMIN	0x02	/* Local admin */
162*5331Samw #define	SMB_UINFO_FLAG_DADMIN	0x04	/* Domain admin */
163*5331Samw #define	SMB_UINFO_FLAG_ADMIN	(SMB_UINFO_FLAG_LADMIN | SMB_UINFO_FLAG_DADMIN)
164*5331Samw 
165*5331Samw /*
166*5331Samw  * This structure is mainly used where there's some
167*5331Samw  * kind of user related interaction with a domain
168*5331Samw  * controller via different RPC calls.
169*5331Samw  */
170*5331Samw typedef struct smb_userinfo {
171*5331Samw 	uint16_t sid_name_use;
172*5331Samw 	uint32_t rid;
173*5331Samw 	uint32_t primary_group_rid;
174*5331Samw 	char *name;
175*5331Samw 	char *domain_name;
176*5331Samw 	nt_sid_t *domain_sid;
177*5331Samw 	uint32_t n_groups;
178*5331Samw 	smb_rid_attrs_t *groups;
179*5331Samw 	uint32_t n_other_grps;
180*5331Samw 	smb_sid_attrs_t *other_grps;
181*5331Samw 	smb_session_key_t *session_key;
182*5331Samw 
183*5331Samw 	nt_sid_t *user_sid;
184*5331Samw 	nt_sid_t *pgrp_sid;
185*5331Samw 	uint32_t flags;
186*5331Samw } smb_userinfo_t;
187*5331Samw 
188*5331Samw /* XDR routines */
189*5331Samw extern bool_t xdr_smb_session_key_t();
190*5331Samw extern bool_t xdr_netr_client_t();
191*5331Samw extern bool_t xdr_nt_sid_t();
192*5331Samw extern bool_t xdr_smb_sid_attrs_t();
193*5331Samw extern bool_t xdr_smb_id_t();
194*5331Samw extern bool_t xdr_smb_win_grps_t();
195*5331Samw extern bool_t xdr_smb_posix_grps_t();
196*5331Samw extern bool_t xdr_smb_token_t();
197*5331Samw 
198*5331Samw 
199*5331Samw #ifndef _KERNEL
200*5331Samw smb_token_t *smb_logon(netr_client_t *clnt);
201*5331Samw void smb_token_destroy(smb_token_t *token);
202*5331Samw uint8_t *smb_token_mkselfrel(smb_token_t *obj, uint32_t *len);
203*5331Samw netr_client_t *netr_client_mkabsolute(uint8_t *buf, uint32_t len);
204*5331Samw #else /* _KERNEL */
205*5331Samw smb_token_t *smb_token_mkabsolute(uint8_t *buf, uint32_t len);
206*5331Samw void smb_token_free(smb_token_t *token);
207*5331Samw uint8_t *netr_client_mkselfrel(netr_client_t *obj, uint32_t *len);
208*5331Samw #endif /* _KERNEL */
209*5331Samw 
210*5331Samw int smb_token_query_privilege(smb_token_t *token, int priv_id);
211*5331Samw /*
212*5331Samw  * Diagnostic routines:
213*5331Samw  * smb_token_print: write the contents of a token to the log.
214*5331Samw  * smb_token_log: log message is prefixed with token basic info.
215*5331Samw  */
216*5331Samw void smb_token_print(smb_token_t *token);
217*5331Samw void smb_token_log(int level, smb_dr_user_ctx_t *user_ctx, char *fmt, ...);
218*5331Samw 
219*5331Samw #ifdef __cplusplus
220*5331Samw }
221*5331Samw #endif
222*5331Samw 
223*5331Samw 
224*5331Samw #endif /* _SMB_TOKEN_H */
225