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 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * 25 * 26 * Dispatching SMB requests. 27 */ 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 /* 32 * ALMOST EVERYTHING YOU NEED TO KNOW ABOUT A SERVER MESSAGE BLOCK 33 * 34 * Request 35 * Header 36 * Magic 0xFF 'S' 'M' 'B' 37 * smb_com a byte, the "first" command 38 * Error a 4-byte union, ignored in a request 39 * smb_flg a one byte set of eight flags 40 * smb_flg2 a two byte set of 16 flags 41 * . twelve reserved bytes, have a role 42 * in connectionless transports (IPX, UDP?) 43 * smb_tid a 16-bit tree ID, a mount point sorta, 44 * 0xFFFF is this command does not have 45 * or require a tree context 46 * smb_pid a 16-bit process ID 47 * smb_uid a 16-bit user ID, specific to this "session" 48 * and mapped to a system (bona-fide) UID 49 * smb_mid a 16-bit multiplex ID, used to differentiate 50 * multiple simultaneous requests from the same 51 * process (pid) (ref RPC "xid") 52 * 53 * Chained (AndX) commands (0 or more) 54 * smb_wct a byte, number of 16-bit words containing 55 * command parameters, min 2 for chained command 56 * andx_com a byte, the "next" command, 0xFF for none 57 * . an unused byte 58 * andx_off a 16-bit offset, byte displacement from &Magic 59 * to the smb_wct field of the "next" command, 60 * ignore if andx_com is 0xFF, s/b 0 if no next 61 * smb_vwv[] 0 or more 16-bit (sorta) parameters for 62 * "this" command (i.e. smb_com if this is the 63 * first parameters, or the andx_com of the just 64 * previous block. 65 * smb_bcc a 16-bit count of smb_data[] bytes 66 * smb_data[] 0 or more bytes, format specific to commands 67 * padding[] Optional padding 68 * 69 * Last command 70 * smb_wct a byte, number of 16-bit words containing 71 * command parameters, min 0 for chained command 72 * smb_vwv[] 0 or more 16-bit (sorta) parameters for 73 * "this" command (i.e. smb_com if this is the 74 * first parameters, or the andx_com of the just 75 * previous block. 76 * smb_bcc a 16-bit count of smb_data[] bytes 77 * smb_data[] 0 or more bytes, format specific to commands 78 * 79 * Reply 80 * Header 81 * Magic 0xFF 'S' 'M' 'B' 82 * smb_com a byte, the "first" command, corresponds 83 * to request 84 * Error a 4-byte union, coding depends on dialect in use 85 * for "DOS" errors 86 * a byte for error class 87 * an unused byte 88 * a 16-bit word for error code 89 * for "NT" errors 90 * a 32-bit error code which 91 * is a packed class and specifier 92 * for "OS/2" errors 93 * I don't know 94 * The error information is specific to the 95 * last command in the reply chain. 96 * smb_flg a one byte set of eight flags, 0x80 bit set 97 * indicating this message is a reply 98 * smb_flg2 a two byte set of 16 flags 99 * . twelve reserved bytes, have a role 100 * in connectionless transports (IPX, UDP?) 101 * smb_tid a 16-bit tree ID, a mount point sorta, 102 * should be the same as the request 103 * smb_pid a 16-bit process ID, MUST BE the same as request 104 * smb_uid a 16-bit user ID, specific to this "session" 105 * and mapped to a system (bona-fide) UID, 106 * should be the same as request 107 * smb_mid a 16-bit multiplex ID, used to differentiate 108 * multiple simultaneous requests from the same 109 * process (pid) (ref RPC "xid"), MUST BE the 110 * same as request 111 * padding[] Optional padding 112 * 113 * Chained (AndX) commands (0 or more) 114 * smb_wct a byte, number of 16-bit words containing 115 * command parameters, min 2 for chained command, 116 * andx_com a byte, the "next" command, 0xFF for none, 117 * corresponds to request, if this is the chained 118 * command that had an error set to 0xFF 119 * . an unused byte 120 * andx_off a 16-bit offset, byte displacement from &Magic 121 * to the smb_wct field of the "next" command, 122 * ignore if andx_com is 0xFF, s/b 0 if no next 123 * smb_vwv[] 0 or more 16-bit (sorta) parameters for 124 * "this" command (i.e. smb_com if this is the 125 * first parameters, or the andx_com of the just 126 * previous block. Empty if an error. 127 * smb_bcc a 16-bit count of smb_data[] bytes 128 * smb_data[] 0 or more bytes, format specific to commands 129 * empty if an error. 130 * 131 * Last command 132 * smb_wct a byte, number of 16-bit words containing 133 * command parameters, min 0 for chained command 134 * smb_vwv[] 0 or more 16-bit (sorta) parameters for 135 * "this" command (i.e. smb_com if this is the 136 * first parameters, or the andx_com of the just 137 * previous block, empty if an error. 138 * smb_bcc a 16-bit count of smb_data[] bytes 139 * smb_data[] 0 or more bytes, format specific to commands, 140 * empty if an error. 141 */ 142 143 #include <smbsrv/smb_incl.h> 144 #include <sys/sdt.h> 145 146 #define SMB_ALL_DISPATCH_STAT_INCR(stat) atomic_inc_64(&stat); 147 #define SMB_COM_NUM 256 148 149 static kstat_t *smb_dispatch_ksp = NULL; 150 static kmutex_t smb_dispatch_ksmtx; 151 152 static int is_andx_com(unsigned char); 153 static int smbsr_check_result(struct smb_request *, int, int); 154 155 static smb_dispatch_table_t dispatch[SMB_COM_NUM] = { 156 { SMB_SDT_OPS(create_directory), /* 0x00 000 */ 157 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 158 { "SmbCreateDirectory", KSTAT_DATA_UINT64 } }, 159 { SMB_SDT_OPS(delete_directory), /* 0x01 001 */ 160 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 161 { "SmbDeleteDirectory", KSTAT_DATA_UINT64 } }, 162 { SMB_SDT_OPS(open), /* 0x02 002 */ 163 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 164 { "SmbOpen", KSTAT_DATA_UINT64 } }, 165 { SMB_SDT_OPS(create), /* 0x03 003 */ 166 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 167 { "SmbCreate", KSTAT_DATA_UINT64 } }, 168 { SMB_SDT_OPS(close), /* 0x04 004 */ 169 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 170 { "SmbClose", KSTAT_DATA_UINT64 } }, 171 { SMB_SDT_OPS(flush), /* 0x05 005 */ 172 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 173 { "SmbFlush", KSTAT_DATA_UINT64 } }, 174 { SMB_SDT_OPS(delete), /* 0x06 006 */ 175 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 176 { "SmbDelete", KSTAT_DATA_UINT64 } }, 177 { SMB_SDT_OPS(rename), /* 0x07 007 */ 178 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 179 { "SmbRename", KSTAT_DATA_UINT64 } }, 180 { SMB_SDT_OPS(query_information), /* 0x08 008 */ 181 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 182 { "SmbQueryInformation", KSTAT_DATA_UINT64 } }, 183 { SMB_SDT_OPS(set_information), /* 0x09 009 */ 184 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 185 { "SmbSetInformation", KSTAT_DATA_UINT64 } }, 186 { SMB_SDT_OPS(read), /* 0x0A 010 */ 187 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 188 { "SmbRead", KSTAT_DATA_UINT64 } }, 189 { SMB_SDT_OPS(write), /* 0x0B 011 */ 190 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 191 { "SmbWrite", KSTAT_DATA_UINT64 } }, 192 { SMB_SDT_OPS(lock_byte_range), /* 0x0C 012 */ 193 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 194 { "SmbLockByteRange", KSTAT_DATA_UINT64 } }, 195 { SMB_SDT_OPS(unlock_byte_range), /* 0x0D 013 */ 196 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 197 { "SmbUnlockByteRange", KSTAT_DATA_UINT64 } }, 198 { SMB_SDT_OPS(create_temporary), /* 0x0E 014 */ 199 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 200 { "SmbCreateTemporary", KSTAT_DATA_UINT64 } }, 201 { SMB_SDT_OPS(create_new), /* 0x0F 015 */ 202 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 203 { "SmbCreateNew", KSTAT_DATA_UINT64 } }, 204 { SMB_SDT_OPS(check_directory), /* 0x10 016 */ 205 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 206 { "SmbCheckDirectory", KSTAT_DATA_UINT64 } }, 207 { SMB_SDT_OPS(process_exit), /* 0x11 017 */ 208 PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID, 209 RW_READER, 210 { "SmbProcessExit", KSTAT_DATA_UINT64 } }, 211 { SMB_SDT_OPS(seek), /* 0x12 018 */ 212 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 213 { "SmbSeek", KSTAT_DATA_UINT64 } }, 214 { SMB_SDT_OPS(lock_and_read), /* 0x13 019 */ 215 LANMAN1_0, 0, RW_READER, 216 { "SmbLockAndRead", KSTAT_DATA_UINT64 } }, 217 { SMB_SDT_OPS(write_and_unlock), /* 0x14 020 */ 218 LANMAN1_0, 0, RW_READER, 219 { "SmbWriteAndUnlock", KSTAT_DATA_UINT64 } }, 220 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x15 021 */ 221 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x16 022 */ 222 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x17 023 */ 223 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x18 024 */ 224 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x19 025 */ 225 { SMB_SDT_OPS(read_raw), /* 0x1A 026 */ 226 LANMAN1_0, 0, RW_WRITER, 227 { "SmbReadRaw", KSTAT_DATA_UINT64 } }, 228 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x1B 027 */ 229 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x1C 028 */ 230 { SMB_SDT_OPS(write_raw), /* 0x1D 029 */ 231 LANMAN1_0, 0, RW_WRITER, 232 { "SmbWriteRaw", KSTAT_DATA_UINT64 } }, 233 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x1E 030 */ 234 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x1F 031 */ 235 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x20 032 */ 236 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x21 033 */ 237 { SMB_SDT_OPS(set_information2), /* 0x22 034 */ 238 LANMAN1_0, 0, RW_READER, 239 { "SmbSetInformation2", KSTAT_DATA_UINT64 } }, 240 { SMB_SDT_OPS(query_information2), /* 0x23 035 */ 241 LANMAN1_0, 0, RW_READER, 242 { "SmbQueryInformation2", KSTAT_DATA_UINT64 } }, 243 { SMB_SDT_OPS(locking_andx), /* 0x24 036 */ 244 LANMAN1_0, 0, RW_READER, 245 { "SmbLockingX", KSTAT_DATA_UINT64 } }, 246 { SMB_SDT_OPS(transaction), /* 0x25 037 */ 247 LANMAN1_0, 0, RW_READER, 248 { "SmbTransaction", KSTAT_DATA_UINT64 } }, 249 { SMB_SDT_OPS(transaction_secondary), /* 0x26 038 */ 250 LANMAN1_0, 0, RW_READER, 251 { "SmbTransactionSecondary", KSTAT_DATA_UINT64 } }, 252 { SMB_SDT_OPS(ioctl), /* 0x27 039 */ 253 LANMAN1_0, 0, RW_READER, 254 { "SmbIoctl", KSTAT_DATA_UINT64 } }, 255 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x28 040 */ 256 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x29 041 */ 257 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x2A 042 */ 258 { SMB_SDT_OPS(echo), /* 0x2B 043 */ 259 LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID, 260 RW_READER, 261 { "SmbEcho", KSTAT_DATA_UINT64 } }, 262 { SMB_SDT_OPS(write_and_close), /* 0x2C 044 */ 263 LANMAN1_0, 0, RW_READER, 264 { "SmbWriteAndClose", KSTAT_DATA_UINT64 } }, 265 { SMB_SDT_OPS(open_andx), /* 0x2D 045 */ 266 LANMAN1_0, 0, RW_READER, 267 { "SmbOpenX", KSTAT_DATA_UINT64 } }, 268 { SMB_SDT_OPS(read_andx), /* 0x2E 046 */ 269 LANMAN1_0, 0, RW_READER, 270 { "SmbReadX", KSTAT_DATA_UINT64 } }, 271 { SMB_SDT_OPS(write_andx), /* 0x2F 047 */ 272 LANMAN1_0, 0, RW_READER, 273 { "SmbWriteX", KSTAT_DATA_UINT64 } }, 274 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x30 048 */ 275 { SMB_SDT_OPS(close_and_tree_disconnect), /* 0x31 049 */ 276 LANMAN1_0, 0, RW_READER, 277 { "SmbCloseAndTreeDisconnect", KSTAT_DATA_UINT64 } }, 278 { SMB_SDT_OPS(transaction2), /* 0x32 050 */ 279 LM1_2X002, 0, RW_READER, 280 { "SmbTransaction2", KSTAT_DATA_UINT64 } }, 281 { SMB_SDT_OPS(transaction2_secondary), /* 0x33 051 */ 282 LM1_2X002, 0, RW_READER, 283 { "SmbTransaction2Secondary", KSTAT_DATA_UINT64 } }, 284 { SMB_SDT_OPS(find_close2), /* 0x34 052 */ 285 LM1_2X002, 0, RW_READER, 286 { "SmbFindClose2", KSTAT_DATA_UINT64 } }, 287 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x35 053 */ 288 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x36 054 */ 289 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x37 055 */ 290 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x38 056 */ 291 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x39 057 */ 292 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x3A 058 */ 293 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x3B 059 */ 294 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x3C 060 */ 295 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x3D 061 */ 296 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x3E 062 */ 297 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x3F 063 */ 298 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x40 064 */ 299 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x41 065 */ 300 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x42 066 */ 301 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x43 067 */ 302 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x44 068 */ 303 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x45 069 */ 304 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x46 070 */ 305 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x47 071 */ 306 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x48 072 */ 307 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x49 073 */ 308 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x4A 074 */ 309 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x4B 075 */ 310 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x4C 076 */ 311 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x4D 077 */ 312 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x4E 078 */ 313 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x4F 079 */ 314 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x50 080 */ 315 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x51 081 */ 316 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x52 082 */ 317 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x53 083 */ 318 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x54 084 */ 319 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x55 085 */ 320 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x56 086 */ 321 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x57 087 */ 322 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x58 088 */ 323 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x59 089 */ 324 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x5A 090 */ 325 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x5B 091 */ 326 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x5C 092 */ 327 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x5D 093 */ 328 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x5E 094 */ 329 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x5F 095 */ 330 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x60 096 */ 331 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x61 097 */ 332 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x62 098 */ 333 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x63 099 */ 334 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x64 100 */ 335 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x65 101 */ 336 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x66 102 */ 337 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x67 103 */ 338 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x68 104 */ 339 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x69 105 */ 340 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x6A 106 */ 341 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x6B 107 */ 342 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x6C 108 */ 343 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x6D 109 */ 344 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x6E 110 */ 345 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x6F 111 */ 346 { SMB_SDT_OPS(tree_connect), /* 0x70 112 */ 347 PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID, RW_READER, 348 { "SmbTreeConnect", KSTAT_DATA_UINT64 } }, 349 { SMB_SDT_OPS(tree_disconnect), /* 0x71 113 */ 350 PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID, 351 RW_READER, 352 { "SmbTreeDisconnect", KSTAT_DATA_UINT64 } }, 353 { SMB_SDT_OPS(negotiate), /* 0x72 114 */ 354 PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID, 355 RW_WRITER, 356 { "SmbNegotiate", KSTAT_DATA_UINT64 } }, 357 { SMB_SDT_OPS(session_setup_andx), /* 0x73 115 */ 358 LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID, 359 RW_READER, 360 { "SmbSessionSetupX", KSTAT_DATA_UINT64 } }, 361 { SMB_SDT_OPS(logoff_andx), /* 0x74 116 */ 362 LM1_2X002, SDDF_SUPPRESS_TID, RW_READER, 363 { "SmbLogoffX", KSTAT_DATA_UINT64 } }, 364 { SMB_SDT_OPS(tree_connect_andx), /* 0x75 117 */ 365 LANMAN1_0, SDDF_SUPPRESS_TID, RW_READER, 366 { "SmbTreeConnectX", KSTAT_DATA_UINT64 } }, 367 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x76 118 */ 368 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x77 119 */ 369 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x78 120 */ 370 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x79 121 */ 371 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x7A 122 */ 372 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x7B 123 */ 373 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x7C 124 */ 374 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x7D 125 */ 375 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x7E 126 */ 376 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x7F 127 */ 377 { SMB_SDT_OPS(query_information_disk), /* 0x80 128 */ 378 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 379 { "SmbQueryInformationDisk", KSTAT_DATA_UINT64 } }, 380 { SMB_SDT_OPS(search), /* 0x81 129 */ 381 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 382 { "SmbSearch", KSTAT_DATA_UINT64 } }, 383 { SMB_SDT_OPS(find), /* 0x82 130 */ 384 LANMAN1_0, 0, RW_READER, 385 { "SmbFind", KSTAT_DATA_UINT64 } }, 386 { SMB_SDT_OPS(find_unique), /* 0x83 131 */ 387 LANMAN1_0, 0, RW_READER, 388 { "SmbFindUnique", KSTAT_DATA_UINT64 } }, 389 { SMB_SDT_OPS(find_close), /* 0x84 132 */ 390 LANMAN1_0, 0, RW_READER, 391 { "SmbFindClose", KSTAT_DATA_UINT64 } }, 392 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x85 133 */ 393 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x86 134 */ 394 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x87 135 */ 395 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x88 136 */ 396 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x89 137 */ 397 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x8A 138 */ 398 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x8B 139 */ 399 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x8C 140 */ 400 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x8D 141 */ 401 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x8E 142 */ 402 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x8F 143 */ 403 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x90 144 */ 404 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x91 145 */ 405 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x92 146 */ 406 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x93 147 */ 407 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x94 148 */ 408 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x95 149 */ 409 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x96 150 */ 410 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x97 151 */ 411 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x98 152 */ 412 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x99 153 */ 413 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x9A 154 */ 414 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x9B 155 */ 415 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x9C 156 */ 416 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x9D 157 */ 417 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x9E 158 */ 418 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0x9F 159 */ 419 { SMB_SDT_OPS(nt_transact), /* 0xA0 160 */ 420 NT_LM_0_12, 0, RW_READER, 421 { "SmbNtTransact", KSTAT_DATA_UINT64 } }, 422 { SMB_SDT_OPS(nt_transact_secondary), /* 0xA1 161 */ 423 NT_LM_0_12, 0, RW_READER, 424 { "SmbNtTransactSecondary", KSTAT_DATA_UINT64 } }, 425 { SMB_SDT_OPS(nt_create_andx), /* 0xA2 162 */ 426 NT_LM_0_12, 0, RW_READER, 427 { "SmbNtCreateX", KSTAT_DATA_UINT64 } }, 428 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xA3 163 */ 429 { SMB_SDT_OPS(nt_cancel), /* 0xA4 164 */ 430 NT_LM_0_12, 0, RW_READER, 431 { "SmbNtCancel", KSTAT_DATA_UINT64 } }, 432 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xA5 165 */ 433 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xA6 166 */ 434 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xA7 167 */ 435 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xA8 168 */ 436 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xA9 169 */ 437 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xAA 170 */ 438 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xAB 171 */ 439 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xAC 172 */ 440 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xAD 173 */ 441 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xAE 174 */ 442 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xAF 175 */ 443 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB0 176 */ 444 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB1 177 */ 445 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB2 178 */ 446 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB3 179 */ 447 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB4 180 */ 448 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB5 181 */ 449 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB6 182 */ 450 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB7 183 */ 451 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB8 184 */ 452 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xB9 185 */ 453 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xBA 186 */ 454 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xBB 187 */ 455 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xBC 188 */ 456 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xBD 189 */ 457 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xBE 190 */ 458 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xBF 191 */ 459 { SMB_SDT_OPS(open_print_file), /* 0xC0 192 */ 460 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 461 { "SmbOpenPrintFile", KSTAT_DATA_UINT64 } }, 462 { SMB_SDT_OPS(write_print_file), /* 0xC1 193 */ 463 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 464 { "SmbWritePrintFile", KSTAT_DATA_UINT64 } }, 465 { SMB_SDT_OPS(close_print_file), /* 0xC2 194 */ 466 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 467 { "SmbClosePrintFile", KSTAT_DATA_UINT64 } }, 468 { SMB_SDT_OPS(get_print_queue), /* 0xC3 195 */ 469 PC_NETWORK_PROGRAM_1_0, 0, RW_READER, 470 { "SmbGetPrintQueue", KSTAT_DATA_UINT64 } }, 471 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xC4 196 */ 472 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xC5 197 */ 473 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xC6 198 */ 474 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xC7 199 */ 475 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xC8 200 */ 476 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xC9 201 */ 477 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xCA 202 */ 478 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xCB 203 */ 479 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xCC 204 */ 480 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xCD 205 */ 481 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xCE 206 */ 482 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xCF 207 */ 483 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD0 208 */ 484 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD1 209 */ 485 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD2 210 */ 486 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD3 211 */ 487 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD4 212 */ 488 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD5 213 */ 489 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD6 214 */ 490 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD7 215 */ 491 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD8 216 */ 492 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xD9 217 */ 493 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xDA 218 */ 494 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xDB 219 */ 495 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xDC 220 */ 496 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xDD 221 */ 497 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xDE 222 */ 498 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xDF 223 */ 499 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE0 224 */ 500 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE1 225 */ 501 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE2 226 */ 502 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE3 227 */ 503 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE4 228 */ 504 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE5 229 */ 505 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE6 230 */ 506 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE7 231 */ 507 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE8 232 */ 508 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xE9 233 */ 509 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xEA 234 */ 510 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xEB 235 */ 511 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xEC 236 */ 512 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xED 237 */ 513 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xEE 238 */ 514 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xEF 239 */ 515 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF0 240 */ 516 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF1 241 */ 517 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF2 242 */ 518 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF3 243 */ 519 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF4 244 */ 520 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF5 245 */ 521 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF6 246 */ 522 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF7 247 */ 523 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF8 248 */ 524 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xF9 249 */ 525 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xFA 250 */ 526 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xFB 251 */ 527 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xFC 252 */ 528 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 }, /* 0xFD 253 */ 529 { SMB_SDT_OPS(invalid), LANMAN1_0, 0, RW_READER, /* 0xFE 254 */ 530 { "SmbInvalidCommand", KSTAT_DATA_UINT64 } }, 531 { SMB_SDT_OPS(invalid), 0, 0, RW_READER, 0 } /* 0xFF 255 */ 532 }; 533 534 /* 535 * smbsr_cleanup 536 * 537 * If any user/tree/file is used by given request then 538 * the reference count for that resource has been incremented. 539 * This function decrements the reference count and close 540 * the resource if it's needed. 541 */ 542 543 void 544 smbsr_cleanup(smb_request_t *sr) 545 { 546 ASSERT((sr->sr_state != SMB_REQ_STATE_CLEANED_UP) && 547 (sr->sr_state != SMB_REQ_STATE_COMPLETED)); 548 549 if (sr->fid_ofile) 550 smbsr_disconnect_file(sr); 551 552 if (sr->sid_odir) 553 smbsr_disconnect_dir(sr); 554 555 if (sr->r_xa) { 556 if (sr->r_xa->xa_flags & SMB_XA_FLAG_COMPLETE) 557 smb_xa_close(sr->r_xa); 558 smb_xa_rele(sr->session, sr->r_xa); 559 sr->r_xa = NULL; 560 } 561 562 /* 563 * Mark this request so we know that we've already cleaned it up. 564 * A request should only get cleaned up once so multiple calls to 565 * smbsr_cleanup for the same request indicate a bug. 566 */ 567 mutex_enter(&sr->sr_mutex); 568 if (sr->sr_state != SMB_REQ_STATE_CANCELED) 569 sr->sr_state = SMB_REQ_STATE_CLEANED_UP; 570 mutex_exit(&sr->sr_mutex); 571 } 572 573 void 574 smb_dispatch_request(struct smb_request *sr) 575 { 576 smb_sdrc_t sdrc; 577 smb_dispatch_table_t *sdd; 578 boolean_t disconnect = B_FALSE; 579 580 ASSERT(sr->tid_tree == 0); 581 ASSERT(sr->uid_user == 0); 582 ASSERT(sr->fid_ofile == 0); 583 ASSERT(sr->sid_odir == 0); 584 sr->smb_fid = (uint16_t)-1; 585 sr->smb_sid = (uint16_t)-1; 586 587 /* temporary until we identify a user */ 588 sr->user_cr = kcred; 589 sr->orig_request_hdr = sr->command.chain_offset; 590 591 /* If this connection is shutting down just kill request */ 592 if (smb_decode_mbc(&sr->command, SMB_HEADER_ED_FMT, 593 &sr->smb_com, 594 &sr->smb_rcls, 595 &sr->smb_reh, 596 &sr->smb_err, 597 &sr->smb_flg, 598 &sr->smb_flg2, 599 &sr->smb_pid_high, 600 sr->smb_sig, 601 &sr->smb_tid, 602 &sr->smb_pid, 603 &sr->smb_uid, 604 &sr->smb_mid) != 0) { 605 disconnect = B_TRUE; 606 goto drop_connection; 607 } 608 609 /* 610 * The reply "header" is filled in now even though it will, 611 * most likely, be rewritten under reply_ready below. We 612 * could reserve the space but this is convenient in case 613 * the dialect dispatcher has to send a special reply (like 614 * TRANSACT). 615 * 616 * Ensure that the 32-bit error code flag is turned off. 617 * Clients seem to set it in transact requests and they may 618 * get confused if we return success or a 16-bit SMB code. 619 */ 620 sr->smb_rcls = 0; 621 sr->smb_reh = 0; 622 sr->smb_err = 0; 623 sr->smb_flg2 &= ~SMB_FLAGS2_NT_STATUS; 624 625 (void) smb_encode_mbc(&sr->reply, SMB_HEADER_ED_FMT, 626 sr->smb_com, 627 sr->smb_rcls, 628 sr->smb_reh, 629 sr->smb_err, 630 sr->smb_flg, 631 sr->smb_flg2, 632 sr->smb_pid_high, 633 sr->smb_sig, 634 sr->smb_tid, 635 sr->smb_pid, 636 sr->smb_uid, 637 sr->smb_mid); 638 sr->first_smb_com = sr->smb_com; 639 640 /* 641 * Verify SMB signature if signing is enabled, dialect is NT LM 0.12, 642 * signing was negotiated and authentication has occurred. 643 */ 644 if (sr->session->signing.flags & SMB_SIGNING_ENABLED) { 645 if (smb_sign_check_request(sr) != 0) { 646 smbsr_error(sr, NT_STATUS_ACCESS_DENIED, 647 ERRDOS, ERROR_ACCESS_DENIED); 648 disconnect = B_TRUE; 649 smb_rwx_rwenter(&sr->session->s_lock, RW_READER); 650 goto report_error; 651 } 652 } 653 654 andx_more: 655 sdd = &dispatch[sr->smb_com]; 656 ASSERT(sdd->sdt_function); 657 658 smb_rwx_rwenter(&sr->session->s_lock, sdd->sdt_slock_mode); 659 660 if (smb_decode_mbc(&sr->command, "b", &sr->smb_wct) != 0) { 661 disconnect = B_TRUE; 662 goto report_error; 663 } 664 665 (void) MBC_SHADOW_CHAIN(&sr->smb_vwv, &sr->command, 666 sr->command.chain_offset, sr->smb_wct * 2); 667 668 if (smb_decode_mbc(&sr->command, "#.w", sr->smb_wct*2, &sr->smb_bcc)) { 669 disconnect = B_TRUE; 670 goto report_error; 671 } 672 673 (void) MBC_SHADOW_CHAIN(&sr->smb_data, &sr->command, 674 sr->command.chain_offset, sr->smb_bcc); 675 676 sr->command.chain_offset += sr->smb_bcc; 677 if (sr->command.chain_offset > sr->command.max_bytes) { 678 disconnect = B_TRUE; 679 goto report_error; 680 } 681 682 /* Store pointers for later */ 683 sr->cur_reply_offset = sr->reply.chain_offset; 684 685 if (is_andx_com(sr->smb_com)) { 686 /* Peek ahead and don't disturb vwv */ 687 if (smb_peek_mbc(&sr->smb_vwv, sr->smb_vwv.chain_offset, "b.w", 688 &sr->andx_com, &sr->andx_off) < 0) { 689 disconnect = B_TRUE; 690 goto report_error; 691 } 692 } else { 693 sr->andx_com = (unsigned char)-1; 694 } 695 696 mutex_enter(&sr->sr_mutex); 697 switch (sr->sr_state) { 698 case SMB_REQ_STATE_SUBMITTED: 699 case SMB_REQ_STATE_CLEANED_UP: 700 sr->sr_state = SMB_REQ_STATE_ACTIVE; 701 break; 702 case SMB_REQ_STATE_CANCELED: 703 break; 704 default: 705 ASSERT(0); 706 break; 707 } 708 mutex_exit(&sr->sr_mutex); 709 710 /* 711 * Setup UID and TID information (if required). Both functions 712 * will set the sr credentials. In domain mode, the user and 713 * tree credentials should be the same. In share mode, the 714 * tree credentials (defined in the share definition) should 715 * override the user credentials. 716 */ 717 if (!(sdd->sdt_flags & SDDF_SUPPRESS_UID) && (sr->uid_user == NULL)) { 718 sr->uid_user = smb_user_lookup_by_uid(sr->session, 719 &sr->user_cr, sr->smb_uid); 720 if (sr->uid_user == NULL) { 721 smbsr_error(sr, 0, ERRSRV, ERRbaduid); 722 smbsr_cleanup(sr); 723 goto report_error; 724 } 725 726 if (!(sdd->sdt_flags & SDDF_SUPPRESS_TID) && 727 (sr->tid_tree == NULL)) { 728 sr->tid_tree = smb_tree_lookup_by_tid( 729 sr->uid_user, sr->smb_tid); 730 if (sr->tid_tree == NULL) { 731 smbsr_error(sr, 0, ERRSRV, ERRinvnid); 732 smbsr_cleanup(sr); 733 goto report_error; 734 } 735 } 736 } 737 738 /* 739 * If the command is not a read raw request we can set the 740 * state of the session back to SMB_SESSION_STATE_NEGOTIATED 741 * (if the current state is SMB_SESSION_STATE_OPLOCK_BREAKING). 742 * Otherwise we let the read raw handler to deal with it. 743 */ 744 if ((sr->session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING) && 745 (sr->smb_com != SMB_COM_READ_RAW)) { 746 krw_t mode; 747 /* 748 * The lock may have to be upgraded because, at this 749 * point, we don't know how it was entered. We just 750 * know that it has to be entered in writer mode here. 751 * Whatever mode was used to enter the lock, it will 752 * be restored. 753 */ 754 mode = smb_rwx_rwupgrade(&sr->session->s_lock); 755 if (sr->session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING) 756 sr->session->s_state = SMB_SESSION_STATE_NEGOTIATED; 757 758 smb_rwx_rwdowngrade(&sr->session->s_lock, mode); 759 } 760 761 /* 762 * Increment method invocation count. This value is exposed 763 * via kstats, and it represents a count of all the dispatched 764 * requests, including the ones that have a return value, other 765 * than SDRC_SUCCESS. 766 */ 767 SMB_ALL_DISPATCH_STAT_INCR(sdd->sdt_dispatch_stats.value.ui64); 768 769 if ((sdrc = (*sdd->sdt_pre_op)(sr)) == SDRC_SUCCESS) 770 sdrc = (*sdd->sdt_function)(sr); 771 772 if (sdrc != SDRC_SUCCESS) { 773 /* 774 * Handle errors from raw write. 775 */ 776 if (sr->session->s_state == 777 SMB_SESSION_STATE_WRITE_RAW_ACTIVE) { 778 /* 779 * Set state so that the netbios session 780 * daemon will start accepting data again. 781 */ 782 sr->session->s_write_raw_status = 0; 783 sr->session->s_state = SMB_SESSION_STATE_NEGOTIATED; 784 } 785 } 786 787 (*sdd->sdt_post_op)(sr); 788 789 /* 790 * Only call smbsr_cleanup if smb->sr_keep is not set. 791 * smb_nt_transact_notify_change will set smb->sr_keep if it 792 * retains control of the request when it returns. In that 793 * case the notify change code will call smbsr_cleanup later 794 * when the request has completed. 795 */ 796 if (sr->sr_keep == 0) 797 smbsr_cleanup(sr); 798 799 switch (sdrc) { 800 case SDRC_SUCCESS: 801 break; 802 803 case SDRC_DROP_VC: 804 disconnect = B_TRUE; 805 goto drop_connection; 806 807 case SDRC_NO_REPLY: 808 smb_rwx_rwexit(&sr->session->s_lock); 809 return; 810 811 case SDRC_ERROR: 812 goto report_error; 813 814 case SDRC_NOT_IMPLEMENTED: 815 default: 816 smbsr_error(sr, 0, ERRDOS, ERRbadfunc); 817 goto report_error; 818 } 819 820 /* 821 * If there's no AndX command, we're done. 822 */ 823 if (sr->andx_com == 0xff) 824 goto reply_ready; 825 826 /* 827 * Otherwise, we have to back-patch the AndXCommand and AndXOffset 828 * and continue processing. 829 */ 830 sr->andx_prev_wct = sr->cur_reply_offset; 831 (void) smb_poke_mbc(&sr->reply, sr->andx_prev_wct + 1, "b.w", 832 sr->andx_com, MBC_LENGTH(&sr->reply)); 833 834 smb_rwx_rwexit(&sr->session->s_lock); 835 836 sr->command.chain_offset = sr->orig_request_hdr + sr->andx_off; 837 sr->smb_com = sr->andx_com; 838 goto andx_more; 839 840 report_error: 841 sr->reply.chain_offset = sr->cur_reply_offset; 842 (void) smb_encode_mbc(&sr->reply, "bw", 0, 0); 843 844 sr->smb_wct = 0; 845 sr->smb_bcc = 0; 846 847 if (sr->smb_rcls == 0 && sr->smb_reh == 0 && sr->smb_err == 0) 848 smbsr_error(sr, 0, ERRSRV, ERRerror); 849 850 reply_ready: 851 smbsr_send_reply(sr); 852 853 drop_connection: 854 if (disconnect) { 855 switch (sr->session->s_state) { 856 case SMB_SESSION_STATE_DISCONNECTED: 857 case SMB_SESSION_STATE_TERMINATED: 858 break; 859 default: 860 smb_soshutdown(sr->session->sock); 861 sr->session->s_state = SMB_SESSION_STATE_DISCONNECTED; 862 break; 863 } 864 } 865 866 smb_rwx_rwexit(&sr->session->s_lock); 867 } 868 869 int 870 smbsr_encode_empty_result(struct smb_request *sr) 871 { 872 return (smbsr_encode_result(sr, 0, 0, "bw", 0, 0)); 873 } 874 875 int 876 smbsr_encode_result(struct smb_request *sr, int wct, int bcc, char *fmt, ...) 877 { 878 va_list ap; 879 880 if (MBC_LENGTH(&sr->reply) != sr->cur_reply_offset) 881 return (-1); 882 883 va_start(ap, fmt); 884 (void) smb_mbc_encode(&sr->reply, fmt, ap); 885 va_end(ap); 886 887 sr->smb_wct = (unsigned char)wct; 888 sr->smb_bcc = (uint16_t)bcc; 889 890 if (smbsr_check_result(sr, wct, bcc) != 0) 891 return (-1); 892 893 return (0); 894 } 895 896 static int 897 smbsr_check_result(struct smb_request *sr, int wct, int bcc) 898 { 899 int offset = sr->cur_reply_offset; 900 int total_bytes; 901 unsigned char temp, temp1; 902 struct mbuf *m; 903 904 total_bytes = 0; 905 m = sr->reply.chain; 906 while (m != 0) { 907 total_bytes += m->m_len; 908 m = m->m_next; 909 } 910 911 if ((offset + 3) > total_bytes) 912 return (-1); 913 914 (void) smb_peek_mbc(&sr->reply, offset, "b", &temp); 915 if (temp != wct) 916 return (-1); 917 918 if ((offset + (wct * 2 + 1)) > total_bytes) 919 return (-1); 920 921 /* reply wct & vwv seem ok, consider data now */ 922 offset += wct * 2 + 1; 923 924 if ((offset + 2) > total_bytes) 925 return (-1); 926 927 (void) smb_peek_mbc(&sr->reply, offset, "bb", &temp, &temp1); 928 if (bcc == VAR_BCC) { 929 if ((temp != 0xFF) || (temp1 != 0xFF)) { 930 return (-1); 931 } else { 932 bcc = (total_bytes - offset) - 2; 933 (void) smb_poke_mbc(&sr->reply, offset, "bb", 934 bcc, bcc >> 8); 935 } 936 } else { 937 if ((temp != (bcc&0xFF)) || (temp1 != ((bcc>>8)&0xFF))) 938 return (-1); 939 } 940 941 offset += bcc + 2; 942 943 if (offset != total_bytes) 944 return (-1); 945 946 sr->smb_wct = (unsigned char)wct; 947 sr->smb_bcc = (uint16_t)bcc; 948 return (0); 949 } 950 951 int 952 smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...) 953 { 954 int rc; 955 va_list ap; 956 957 va_start(ap, fmt); 958 rc = smb_mbc_decode(&sr->smb_vwv, fmt, ap); 959 va_end(ap); 960 961 if (rc) 962 smbsr_error(sr, 0, ERRSRV, ERRerror); 963 return (rc); 964 } 965 966 int 967 smbsr_decode_data(struct smb_request *sr, char *fmt, ...) 968 { 969 int rc; 970 va_list ap; 971 972 va_start(ap, fmt); 973 rc = smb_mbc_decode(&sr->smb_data, fmt, ap); 974 va_end(ap); 975 976 if (rc) 977 smbsr_error(sr, 0, ERRSRV, ERRerror); 978 return (rc); 979 } 980 981 void 982 smbsr_send_reply(struct smb_request *sr) 983 { 984 if (SMB_TREE_CASE_INSENSITIVE(sr)) 985 sr->smb_flg |= SMB_FLAGS_CASE_INSENSITIVE; 986 else 987 sr->smb_flg &= ~SMB_FLAGS_CASE_INSENSITIVE; 988 989 (void) smb_poke_mbc(&sr->reply, 0, SMB_HEADER_ED_FMT, 990 sr->first_smb_com, 991 sr->smb_rcls, 992 sr->smb_reh, 993 sr->smb_err, 994 sr->smb_flg | SMB_FLAGS_REPLY, 995 sr->smb_flg2, 996 sr->smb_pid_high, 997 sr->smb_sig, 998 sr->smb_tid, 999 sr->smb_pid, 1000 sr->smb_uid, 1001 sr->smb_mid); 1002 1003 if (sr->session->signing.flags & SMB_SIGNING_ENABLED) 1004 smb_sign_reply(sr, NULL); 1005 1006 if (smb_session_send(sr->session, 0, &sr->reply) == 0) 1007 sr->reply.chain = 0; 1008 } 1009 1010 /* 1011 * Map errno values to SMB and NT status values. 1012 * Note: ESRCH is a special case to handle a streams lookup failure. 1013 */ 1014 static struct { 1015 int errnum; 1016 int errcls; 1017 int errcode; 1018 DWORD status32; 1019 } smb_errno_map[] = { 1020 { ENOSPC, ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL }, 1021 { EDQUOT, ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL }, 1022 { EPERM, ERRSRV, ERRaccess, NT_STATUS_ACCESS_DENIED }, 1023 { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND }, 1024 { EISDIR, ERRDOS, ERRbadpath, NT_STATUS_FILE_IS_A_DIRECTORY }, 1025 { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE }, 1026 { ENOTEMPTY, ERRDOS, ERROR_DIR_NOT_EMPTY, 1027 NT_STATUS_DIRECTORY_NOT_EMPTY }, 1028 { EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, 1029 { ENOMEM, ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY }, 1030 { EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR }, 1031 { EXDEV, ERRSRV, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE }, 1032 { EROFS, ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED }, 1033 { ESTALE, ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE}, 1034 { EBADF, ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE}, 1035 { EEXIST, ERRDOS, ERRfilexists, NT_STATUS_OBJECT_NAME_COLLISION}, 1036 { ENXIO, ERRSRV, ERRinvdevice, NT_STATUS_BAD_DEVICE_TYPE}, 1037 { ESRCH, ERRDOS, ERROR_FILE_NOT_FOUND, 1038 NT_STATUS_OBJECT_NAME_NOT_FOUND }, 1039 /* 1040 * It's not clear why smb_read_common effectively returns 1041 * ERRnoaccess if a range lock prevents access and smb_write_common 1042 * effectively returns ERRaccess. This table entry is used by 1043 * smb_read_common and preserves the behavior that was there before. 1044 */ 1045 { ERANGE, ERRDOS, ERRnoaccess, NT_STATUS_FILE_LOCK_CONFLICT } 1046 }; 1047 1048 void 1049 smbsr_map_errno(int errnum, smb_error_t *err) 1050 { 1051 int i; 1052 1053 for (i = 0; i < sizeof (smb_errno_map)/sizeof (smb_errno_map[0]); ++i) { 1054 if (smb_errno_map[i].errnum == errnum) { 1055 err->severity = ERROR_SEVERITY_ERROR; 1056 err->status = smb_errno_map[i].status32; 1057 err->errcls = smb_errno_map[i].errcls; 1058 err->errcode = smb_errno_map[i].errcode; 1059 return; 1060 } 1061 } 1062 1063 err->severity = ERROR_SEVERITY_ERROR; 1064 err->status = NT_STATUS_INTERNAL_ERROR; 1065 err->errcls = ERRDOS; 1066 err->errcode = ERROR_INTERNAL_ERROR; 1067 } 1068 1069 void 1070 smbsr_errno(struct smb_request *sr, int errnum) 1071 { 1072 smbsr_map_errno(errnum, &sr->smb_error); 1073 smbsr_set_error(sr, &sr->smb_error); 1074 } 1075 1076 /* 1077 * Report a request processing warning. 1078 */ 1079 void 1080 smbsr_warn(smb_request_t *sr, DWORD status, uint16_t errcls, uint16_t errcode) 1081 { 1082 sr->smb_error.severity = ERROR_SEVERITY_WARNING; 1083 sr->smb_error.status = status; 1084 sr->smb_error.errcls = errcls; 1085 sr->smb_error.errcode = errcode; 1086 1087 smbsr_set_error(sr, &sr->smb_error); 1088 } 1089 1090 /* 1091 * Report a request processing error. This function will not return. 1092 */ 1093 void 1094 smbsr_error(smb_request_t *sr, DWORD status, uint16_t errcls, uint16_t errcode) 1095 { 1096 sr->smb_error.severity = ERROR_SEVERITY_ERROR; 1097 sr->smb_error.status = status; 1098 sr->smb_error.errcls = errcls; 1099 sr->smb_error.errcode = errcode; 1100 1101 smbsr_set_error(sr, &sr->smb_error); 1102 } 1103 1104 /* 1105 * Setup a request processing error. This function can be used to 1106 * report 32-bit status codes or DOS errors. Set the status code 1107 * to 0 (NT_STATUS_SUCCESS) to explicitly report a DOS error, 1108 * regardless of the client capabilities. 1109 * 1110 * If status is non-zero and the client supports 32-bit status 1111 * codes, report the status. Otherwise, report the DOS error. 1112 */ 1113 void 1114 smbsr_set_error(smb_request_t *sr, smb_error_t *err) 1115 { 1116 uint32_t status; 1117 uint32_t severity; 1118 uint32_t capabilities; 1119 1120 ASSERT(sr); 1121 ASSERT(err); 1122 1123 status = err->status; 1124 severity = (err->severity == 0) ? ERROR_SEVERITY_ERROR : err->severity; 1125 capabilities = sr->session->capabilities; 1126 1127 if ((err->errcls == 0) && (err->errcode == 0)) { 1128 capabilities |= CAP_STATUS32; 1129 if (status == 0) 1130 status = NT_STATUS_INTERNAL_ERROR; 1131 } 1132 1133 if ((capabilities & CAP_STATUS32) && (status != 0)) { 1134 status |= severity; 1135 sr->smb_rcls = status & 0xff; 1136 sr->smb_reh = (status >> 8) & 0xff; 1137 sr->smb_err = status >> 16; 1138 sr->smb_flg2 |= SMB_FLAGS2_NT_STATUS; 1139 } else { 1140 if ((err->errcls == 0) || (err->errcode == 0)) { 1141 sr->smb_rcls = ERRSRV; 1142 sr->smb_err = ERRerror; 1143 } else { 1144 sr->smb_rcls = (uint8_t)err->errcls; 1145 sr->smb_err = (uint16_t)err->errcode; 1146 } 1147 } 1148 } 1149 1150 smb_xa_t * 1151 smbsr_lookup_xa(smb_request_t *sr) 1152 { 1153 ASSERT(sr->r_xa == 0); 1154 1155 sr->r_xa = smb_xa_find(sr->session, sr->smb_pid, sr->smb_mid); 1156 return (sr->r_xa); 1157 } 1158 1159 void 1160 smbsr_disconnect_file(smb_request_t *sr) 1161 { 1162 smb_ofile_t *of = sr->fid_ofile; 1163 1164 sr->fid_ofile = NULL; 1165 (void) smb_ofile_release(of); 1166 } 1167 1168 void 1169 smbsr_disconnect_dir(smb_request_t *sr) 1170 { 1171 smb_odir_t *od = sr->sid_odir; 1172 1173 sr->sid_odir = NULL; 1174 smb_odir_release(od); 1175 } 1176 1177 static int 1178 is_andx_com(unsigned char com) 1179 { 1180 switch (com) { 1181 case SMB_COM_LOCKING_ANDX: 1182 case SMB_COM_OPEN_ANDX: 1183 case SMB_COM_READ_ANDX: 1184 case SMB_COM_WRITE_ANDX: 1185 case SMB_COM_SESSION_SETUP_ANDX: 1186 case SMB_COM_LOGOFF_ANDX: 1187 case SMB_COM_TREE_CONNECT_ANDX: 1188 case SMB_COM_NT_CREATE_ANDX: 1189 return (1); 1190 } 1191 return (0); 1192 } 1193 1194 /* 1195 * Invalid command stubs. 1196 * 1197 * SmbWriteComplete is sent to acknowledge completion of raw write requests. 1198 * We never send raw write commands to other servers so, if we receive 1199 * SmbWriteComplete, we treat it as an error. 1200 * 1201 * The Read/Write Block Multiplexed (mpx) protocol is used to maximize 1202 * performance when reading/writing a large block of data: it can be 1203 * used in parallel with other client/server operations. The mpx sub- 1204 * protocol is not supported because we support only connection oriented 1205 * transports and NT supports mpx only over connectionless transports. 1206 */ 1207 smb_sdrc_t 1208 smb_pre_invalid(smb_request_t *sr) 1209 { 1210 DTRACE_SMB_1(op__Invalid__start, smb_request_t *, sr); 1211 return (SDRC_SUCCESS); 1212 } 1213 1214 void 1215 smb_post_invalid(smb_request_t *sr) 1216 { 1217 DTRACE_SMB_1(op__Invalid__done, smb_request_t *, sr); 1218 } 1219 1220 smb_sdrc_t 1221 smb_com_invalid(smb_request_t *sr) 1222 { 1223 smb_sdrc_t sdrc; 1224 1225 switch (sr->smb_com) { 1226 case SMB_COM_WRITE_COMPLETE: 1227 smbsr_error(sr, 0, ERRSRV, ERRerror); 1228 sdrc = SDRC_ERROR; 1229 break; 1230 1231 default: 1232 smbsr_error(sr, NT_STATUS_NOT_IMPLEMENTED, 1233 ERRDOS, ERROR_INVALID_FUNCTION); 1234 sdrc = SDRC_NOT_IMPLEMENTED; 1235 break; 1236 } 1237 1238 return (sdrc); 1239 } 1240 1241 /* 1242 * smb_dispatch_kstat_update 1243 * 1244 * This callback function updates the smb_dispatch_kstat_data when kstat 1245 * command is invoked. 1246 */ 1247 static int 1248 smb_dispatch_kstat_update(kstat_t *ksp, int rw) 1249 { 1250 smb_dispatch_table_t *sdd; 1251 kstat_named_t *ks_named; 1252 int i; 1253 1254 if (rw == KSTAT_WRITE) 1255 return (EACCES); 1256 1257 ASSERT(MUTEX_HELD(ksp->ks_lock)); 1258 1259 ks_named = ksp->ks_data; 1260 for (i = 0; i < SMB_COM_NUM; i++) { 1261 sdd = &dispatch[i]; 1262 1263 if (sdd->sdt_function != smb_com_invalid) { 1264 bcopy(&sdd->sdt_dispatch_stats, ks_named, 1265 sizeof (kstat_named_t)); 1266 ++ks_named; 1267 } 1268 } 1269 1270 return (0); 1271 } 1272 1273 /* 1274 * smb_dispatch_kstat_init 1275 * 1276 * Initialize dispatch kstats. 1277 */ 1278 void 1279 smb_dispatch_kstat_init(void) 1280 { 1281 int ks_ndata; 1282 int i; 1283 1284 for (i = 0, ks_ndata = 0; i < SMB_COM_NUM; i++) { 1285 if (dispatch[i].sdt_function != smb_com_invalid) 1286 ks_ndata++; 1287 } 1288 1289 smb_dispatch_ksp = kstat_create("smb", 0, "smb_dispatch_all", "misc", 1290 KSTAT_TYPE_NAMED, ks_ndata, 0); 1291 1292 if (smb_dispatch_ksp) { 1293 mutex_init(&smb_dispatch_ksmtx, NULL, MUTEX_DEFAULT, NULL); 1294 smb_dispatch_ksp->ks_update = smb_dispatch_kstat_update; 1295 smb_dispatch_ksp->ks_lock = &smb_dispatch_ksmtx; 1296 kstat_install(smb_dispatch_ksp); 1297 } 1298 } 1299 1300 /* 1301 * smb_dispatch_kstat_fini 1302 * 1303 * Remove dispatch kstats. 1304 */ 1305 void 1306 smb_dispatch_kstat_fini(void) 1307 { 1308 if (smb_dispatch_ksp != NULL) { 1309 kstat_delete(smb_dispatch_ksp); 1310 mutex_destroy(&smb_dispatch_ksmtx); 1311 smb_dispatch_ksp = NULL; 1312 } 1313 } 1314