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