1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
26 */
27
28 #ifndef _SMB_TOKEN_H
29 #define _SMB_TOKEN_H
30
31 #include <smbsrv/smb_inet.h>
32 #include <smbsrv/smb_privilege.h>
33 #include <smbsrv/smb_sid.h>
34
35 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
36 #include <c2/audit.h>
37 #else
38 #include <bsm/audit.h>
39 #endif
40
41 /*
42 * Don't want <smbsrv/netrauth.h> in here, but
43 * uts/common/fs/smbsrv/smb_authenticate.c
44 * wants this. Todo: cleanup
45 */
46 #define NETR_NETWORK_LOGON 0x02
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /*
53 * 32-bit opaque buffer (non-null terminated strings)
54 * See also: smb_buf32_xdr()
55 */
56 typedef struct smb_buf32 {
57 uint32_t len;
58 uint8_t *val;
59 } smb_buf32_t;
60
61 /*
62 * Access Token
63 *
64 * An access token identifies a user, the user's privileges and the
65 * list of groups of which the user is a member. This information is
66 * used when access is requested to an object by comparing this
67 * information with the DACL in the object's security descriptor.
68 *
69 * There should be one unique token per user per session per client.
70 *
71 * Access Token Flags
72 *
73 * SMB_ATF_GUEST Token belongs to guest user
74 * SMB_ATF_ANON Token belongs to anonymous user
75 * and it's only good for IPC Connection.
76 * SMB_ATF_POWERUSER Token belongs to a Power User member
77 * SMB_ATF_BACKUPOP Token belongs to a Power User member
78 * SMB_ATF_ADMIN Token belongs to a Domain Admins member
79 */
80 #define SMB_ATF_ANON 0x00000001
81 #define SMB_ATF_GUEST 0x00000002
82 #define SMB_ATF_POWERUSER 0x00000004
83 #define SMB_ATF_BACKUPOP 0x00000008
84 #define SMB_ATF_ADMIN 0x00000010
85
86 #define SMB_POSIX_GRPS_SIZE(n) \
87 (sizeof (smb_posix_grps_t) + (n - 1) * sizeof (gid_t))
88 /*
89 * It consists of the primary and supplementary POSIX groups.
90 * See also: smb_posix_grps_xdr()
91 */
92 typedef struct smb_posix_grps {
93 uint32_t pg_ngrps;
94 gid_t pg_grps[ANY_SIZE_ARRAY];
95 } smb_posix_grps_t;
96
97 /*
98 * An NT-style logon "token" (NT terminology)
99 * See also: smb_token_xdr()
100 */
101 typedef struct smb_token {
102 smb_id_t tkn_user;
103 smb_id_t tkn_owner;
104 smb_id_t tkn_primary_grp;
105 smb_ids_t tkn_win_grps;
106 smb_privset_t *tkn_privileges;
107 char *tkn_account_name;
108 char *tkn_domain_name;
109 uint32_t tkn_flags;
110 uint32_t tkn_audit_sid;
111 smb_buf32_t tkn_ssnkey;
112 smb_posix_grps_t *tkn_posix_grps;
113 au_id_t tkn_auid;
114 au_mask_t tkn_amask;
115 au_asid_t tkn_asid;
116 } smb_token_t;
117
118 /*
119 * Details required to authenticate a user.
120 * See also: smb_logon_xdr()
121 */
122 typedef struct smb_logon {
123 uint16_t lg_level;
124 char *lg_username; /* requested username */
125 char *lg_domain; /* requested domain */
126 char *lg_e_username; /* effective username */
127 char *lg_e_domain; /* effective domain */
128 char *lg_workstation;
129 smb_inaddr_t lg_clnt_ipaddr;
130 smb_inaddr_t lg_local_ipaddr;
131 uint16_t lg_local_port;
132 smb_buf32_t lg_challenge_key;
133 smb_buf32_t lg_nt_password;
134 smb_buf32_t lg_lm_password;
135 uint32_t lg_ntlm_flags;
136 int lg_native_os;
137 int lg_native_lm;
138 uint32_t lg_flags;
139 uint32_t lg_logon_id; /* filled in user space */
140 uint32_t lg_domain_type; /* filled in user space */
141 uint32_t lg_secmode; /* filled in user space */
142 uint32_t lg_status; /* filled in user space */
143 } smb_logon_t;
144
145 /*
146 * This is the name of the local (AF_UNIX) socket
147 * where the SMB auth. service listens.
148 */
149 #define SMB_AUTHSVC_SOCKNAME "/var/smb/lipc/smbauth"
150
151 /*
152 * Maximum number of authentcation conversations at one time.
153 * Note this is _NOT_ the max. number of logged on users,
154 * which can be much larger.
155 */
156 #define SMB_AUTHSVC_MAXTHREAD 256
157
158 /*
159 * Messages to and from the local security authority
160 * Type codes:
161 */
162 typedef enum smb_lsa_mtype {
163 /* reply types */
164 LSA_MTYPE_OK = 0,
165 LSA_MTYPE_ERROR,
166 LSA_MTYPE_ES_DONE, /* ext. sec: authenticated */
167 LSA_MTYPE_ES_CONT, /* more processing required */
168 LSA_MTYPE_TOKEN, /* smb_token_t */
169
170 /* request types */
171 LSA_MTYPE_OLDREQ, /* non-ext. sec. session setup */
172 LSA_MTYPE_CLINFO, /* client info sent at start of ES */
173 LSA_MTYPE_ESFIRST, /* spnego initial message */
174 LSA_MTYPE_ESNEXT, /* spnego continuation */
175 LSA_MTYPE_GETTOK /* after ES auth, get token */
176 } smb_lsa_mtype_t;
177
178 /*
179 * msg: header common to all message types
180 */
181 typedef struct smb_lsa_msg_hdr {
182 uint32_t lmh_msgtype; /* smb_lsa_mtype_t */
183 uint32_t lmh_msglen; /* size of what follows */
184 } smb_lsa_msg_hdr_t;
185
186 /*
187 * eresp: error response
188 * msgtype: LSA_MTYPE_ERESP
189 */
190 typedef struct smb_lsa_eresp {
191 uint32_t ler_ntstatus;
192 uint16_t ler_errclass;
193 uint16_t ler_errcode;
194 } smb_lsa_eresp_t;
195
196 /*
197 * Message for LSA_MTYPE_CLINFO
198 */
199 typedef struct smb_lsa_clinfo {
200 smb_inaddr_t lci_clnt_ipaddr;
201 unsigned char lci_challenge_key[8];
202 int lci_native_os;
203 int lci_native_lm;
204 } smb_lsa_clinfo_t;
205
206 struct XDR;
207 int smb_logon_xdr(struct XDR *, smb_logon_t *);
208 int smb_token_xdr(struct XDR *, smb_token_t *);
209
210 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
211 void smb_token_free(smb_token_t *);
212 #else /* _KERNEL */
213 smb_token_t *smb_logon(smb_logon_t *);
214 void smb_logon_abort(void);
215 void smb_token_destroy(smb_token_t *);
216 uint8_t *smb_token_encode(smb_token_t *, uint32_t *);
217 void smb_token_log(smb_token_t *);
218 smb_logon_t *smb_logon_decode(uint8_t *, uint32_t);
219 void smb_logon_free(smb_logon_t *);
220 #endif /* _KERNEL */
221
222 int smb_token_query_privilege(smb_token_t *token, int priv_id);
223 boolean_t smb_token_valid(smb_token_t *);
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif /* _SMB_TOKEN_H */