15331Samw /*
25331Samw * CDDL HEADER START
35331Samw *
45331Samw * The contents of this file are subject to the terms of the
55331Samw * Common Development and Distribution License (the "License").
65331Samw * You may not use this file except in compliance with the License.
75331Samw *
85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw * or http://www.opensolaris.org/os/licensing.
105331Samw * See the License for the specific language governing permissions
115331Samw * and limitations under the License.
125331Samw *
135331Samw * When distributing Covered Code, include this CDDL HEADER in each
145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw * If applicable, add the following below this CDDL HEADER, with the
165331Samw * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw *
195331Samw * CDDL HEADER END
205331Samw */
215331Samw /*
22*12890SJoyce.McIntosh@Sun.COM * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
235331Samw */
245331Samw
2510966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
265331Samw #include <smbsrv/smb_vops.h>
278934SJose.Borrego@Sun.COM
288934SJose.Borrego@Sun.COM int smb_open_dsize_check = 0;
295331Samw
305331Samw /*
315331Samw * Client Request Description
325331Samw * ================================== =================================
335331Samw *
345331Samw * UCHAR WordCount; Count of parameter words = 15
355331Samw * UCHAR AndXCommand; Secondary (X) command; 0xFF =
365331Samw * none
375331Samw * UCHAR AndXReserved; Reserved (must be 0)
385331Samw * USHORT AndXOffset; Offset to next command WordCount
395331Samw * USHORT Flags; Additional information: bit set-
405331Samw * 0 - return additional info
415331Samw * 1 - exclusive oplock requested
425331Samw * 2 - batch oplock requested
435331Samw * USHORT DesiredAccess; File open mode
445331Samw * USHORT SearchAttributes;
455331Samw * USHORT FileAttributes;
465331Samw * UTIME CreationTime; Creation timestamp for file if it
475331Samw * gets created
485331Samw * USHORT OpenFunction; Action to take if file exists
495331Samw * ULONG AllocationSize; Bytes to reserve on create or
505331Samw * truncate
515331Samw * ULONG Reserved[2]; Must be 0
525331Samw * USHORT ByteCount; Count of data bytes; min = 1
535331Samw * UCHAR BufferFormat 0x04
545331Samw * STRING FileName;
555331Samw *
565331Samw * Server Response Description
575331Samw * ================================== =================================
585331Samw *
595331Samw * UCHAR WordCount; Count of parameter words = 15
605331Samw * UCHAR AndXCommand; Secondary (X) command; 0xFF =
615331Samw * none
625331Samw * UCHAR AndXReserved; Reserved (must be 0)
635331Samw * USHORT AndXOffset; Offset to next command WordCount
645331Samw * USHORT Fid; File handle
655331Samw * USHORT FileAttributes;
665331Samw * UTIME LastWriteTime;
675331Samw * ULONG DataSize; Current file size
685331Samw * USHORT GrantedAccess; Access permissions actually
695331Samw * allowed
705331Samw * USHORT FileType; Type of file opened
715331Samw * USHORT DeviceState; State of the named pipe
725331Samw * USHORT Action; Action taken
735331Samw * ULONG ServerFid; Server unique file id
745331Samw * USHORT Reserved; Reserved (must be 0)
755331Samw * USHORT ByteCount; Count of data bytes = 0
765331Samw *
775331Samw * DesiredAccess describes the access the client desires for the file (see
785331Samw * section 3.6 - Access Mode Encoding).
795331Samw *
805331Samw * OpenFunction specifies the action to be taken depending on whether or
815331Samw * not the file exists (see section 3.8 - Open Function Encoding). Action
825331Samw *
835331Samw * in the response specifies the action as a result of the Open request
845331Samw * (see section 3.9 - Open Action Encoding).
855331Samw *
865331Samw * SearchAttributes indicates the attributes that the file must have to be
875331Samw * found while searching to see if it exists. The encoding of this field
885331Samw * is described in the "File Attribute Encoding" section elsewhere in this
895331Samw * document. If SearchAttributes is zero then only normal files are
905331Samw * returned. If the system file, hidden or directory attributes are
915331Samw * specified then the search is inclusive -- both the specified type(s) of
925331Samw * files and normal files are returned.
935331Samw *
945331Samw * FileType returns the kind of resource actually opened:
955331Samw *
965331Samw * Name Value Description
975331Samw * ========================== ====== ==================================
985331Samw *
995331Samw * FileTypeDisk 0 Disk file or directory as defined
1005331Samw * in the attribute field
1015331Samw * FileTypeByteModePipe 1 Named pipe in byte mode
1025331Samw * FileTypeMessageModePipe 2 Named pipe in message mode
1035331Samw * FileTypePrinter 3 Spooled printer
1045331Samw * FileTypeUnknown 0xFFFF Unrecognized resource type
1055331Samw *
1065331Samw * If bit0 of Flags is clear, the FileAttributes, LastWriteTime, DataSize,
1075331Samw * FileType, and DeviceState have indeterminate values in the response.
1085331Samw *
1095331Samw * This SMB can request an oplock on the opened file. Oplocks are fully
1105331Samw * described in the "Oplocks" section elsewhere in this document, and there
1115331Samw * is also discussion of oplocks in the SMB_COM_LOCKING_ANDX SMB
1125331Samw * description. Bit1 and bit2 of the Flags field are used to request
1135331Samw * oplocks during open.
1145331Samw *
1155331Samw * The following SMBs may follow SMB_COM_OPEN_ANDX:
1165331Samw *
1175331Samw * SMB_COM_READ SMB_COM_READ_ANDX
1185331Samw * SMB_COM_IOCTL
1195331Samw */
1205331Samw
1215331Samw /*
1225331Samw * This message is sent to obtain a file handle for a data file. This
1235331Samw * returned Fid is used in subsequent client requests such as read, write,
1245331Samw * close, etc.
1255331Samw *
1265331Samw * Client Request Description
1275331Samw * ================================== =================================
1285331Samw *
1295331Samw * UCHAR WordCount; Count of parameter words = 2
1305331Samw * USHORT DesiredAccess; Mode - read/write/share
1315331Samw * USHORT SearchAttributes;
1325331Samw * USHORT ByteCount; Count of data bytes; min = 2
1335331Samw * UCHAR BufferFormat; 0x04
1345331Samw * STRING FileName[]; File name
1355331Samw *
1365331Samw * FileName is the fully qualified file name, relative to the root of the
1375331Samw * share specified in the Tid field of the SMB header. If Tid in the SMB
1385331Samw * header refers to a print share, this SMB creates a new file which will
1395331Samw * be spooled to the printer when closed. In this case, FileName is
1405331Samw * ignored.
1415331Samw *
1425331Samw * SearchAttributes specifies the type of file desired. The encoding is
1435331Samw * described in the "File Attribute Encoding" section.
1445331Samw *
1455331Samw * DesiredAccess controls the mode under which the file is opened, and the
1465331Samw * file will be opened only if the client has the appropriate permissions.
1475331Samw * The encoding of DesiredAccess is discussed in the section entitled
1485331Samw * "Access Mode Encoding".
1495331Samw *
1505331Samw * Server Response Description
1515331Samw * ================================== =================================
1525331Samw *
1535331Samw * UCHAR WordCount; Count of parameter words = 7
1545331Samw * USHORT Fid; File handle
1555331Samw * USHORT FileAttributes; Attributes of opened file
1565331Samw * UTIME LastWriteTime; Time file was last written
1575331Samw * ULONG DataSize; File size
1585331Samw * USHORT GrantedAccess; Access allowed
1595331Samw * USHORT ByteCount; Count of data bytes = 0
1605331Samw *
1615331Samw * Fid is the handle value which should be used for subsequent file
1625331Samw * operations.
1635331Samw *
1645331Samw * FileAttributes specifies the type of file obtained. The encoding is
1655331Samw * described in the "File Attribute Encoding" section.
1665331Samw *
1675331Samw * GrantedAccess indicates the access permissions actually allowed, and may
1685331Samw * have one of the following values:
1695331Samw *
1705331Samw * 0 read-only
1715331Samw * 1 write-only
1725331Samw * 2 read/write
1735331Samw *
1745331Samw * File Handles (Fids) are scoped per client. A Pid may reference any Fid
1755331Samw * established by itself or any other Pid on the client (so far as the
1765331Samw * server is concerned). The actual accesses allowed through the Fid
1775331Samw * depends on the open and deny modes specified when the file was opened
1785331Samw * (see below).
1795331Samw *
1805331Samw * The MS-DOS compatibility mode of file open provides exclusion at the
1815331Samw * client level. A file open in compatibility mode may be opened (also in
1825331Samw * compatibility mode) any number of times for any combination of reading
1835331Samw * and writing (subject to the user's permissions) by any Pid on the same
1845331Samw * client. If the first client has the file open for writing, then the
1855331Samw * file may not be opened in any way by any other client. If the first
1865331Samw * client has the file open only for reading, then other clients may open
1875331Samw * the file, in compatibility mode, for reading.. The above
1885331Samw * notwithstanding, if the filename has an extension of .EXE, .DLL, .SYM,
1895331Samw * or .COM other clients are permitted to open the file regardless of
1905331Samw * read/write open modes of other compatibility mode opens. However, once
1915331Samw * multiple clients have the file open for reading, no client is permitted
1925331Samw * to open the file for writing and no other client may open the file in
1935331Samw * any mode other than compatibility mode.
1945331Samw *
1955331Samw * The other file exclusion modes (Deny read/write, Deny write, Deny read,
1965331Samw * Deny none) provide exclusion at the file level. A file opened in any
1975331Samw * "Deny" mode may be opened again only for the accesses allowed by the
1985331Samw * Deny mode (subject to the user's permissions). This is true regardless
1995331Samw * of the identity of the second opener -a different client, a Pid from the
2005331Samw * same client, or the Pid that already has the file open. For example, if
2015331Samw * a file is open in "Deny write" mode a second open may only obtain read
2025331Samw * permission to the file.
2035331Samw *
2045331Samw * Although Fids are available to all Pids on a client, Pids other than the
2055331Samw * owner may not have the full access rights specified in the open mode by
2065331Samw * the Fid's creator. If the open creating the Fid specified a deny mode,
2075331Samw * then any Pid using the Fid, other than the creating Pid, will have only
2085331Samw * those access rights determined by "anding" the open mode rights and the
2095331Samw * deny mode rights, i.e., the deny mode is checked on all file accesses.
2105331Samw * For example, if a file is opened for Read/Write in Deny write mode, then
2115331Samw * other clients may only read the file and cannot write; if a file is
2125331Samw * opened for Read in Deny read mode, then the other clients can neither
2135331Samw * read nor write the file.
2145331Samw */
2155331Samw
2166030Sjb150015 smb_sdrc_t
smb_pre_open(smb_request_t * sr)2176139Sjb150015 smb_pre_open(smb_request_t *sr)
2186139Sjb150015 {
2196139Sjb150015 struct open_param *op = &sr->arg.open;
2206139Sjb150015 int rc;
2216139Sjb150015
2226139Sjb150015 bzero(op, sizeof (sr->arg.open));
2236139Sjb150015
2249343SAfshin.Ardakani@Sun.COM rc = smbsr_decode_vwv(sr, "ww", &op->omode, &op->fqi.fq_sattr);
2256139Sjb150015 if (rc == 0)
2269343SAfshin.Ardakani@Sun.COM rc = smbsr_decode_data(sr, "%S", sr, &op->fqi.fq_path.pn_path);
2276139Sjb150015
2286139Sjb150015 DTRACE_SMB_2(op__Open__start, smb_request_t *, sr,
2296139Sjb150015 struct open_param *, op);
2306139Sjb150015
2316139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
2326139Sjb150015 }
2336139Sjb150015
2346139Sjb150015 void
smb_post_open(smb_request_t * sr)2356139Sjb150015 smb_post_open(smb_request_t *sr)
2366139Sjb150015 {
2376139Sjb150015 DTRACE_SMB_1(op__Open__done, smb_request_t *, sr);
2386139Sjb150015 }
2396139Sjb150015
2406139Sjb150015 smb_sdrc_t
smb_com_open(smb_request_t * sr)2416139Sjb150015 smb_com_open(smb_request_t *sr)
2425331Samw {
2435331Samw struct open_param *op = &sr->arg.open;
2446600Sas200622 smb_node_t *node;
24510001SJoyce.McIntosh@Sun.COM smb_attr_t attr;
2465331Samw uint16_t file_attr;
2476030Sjb150015 int rc;
2485331Samw
2495331Samw op->desired_access = smb_omode_to_amask(op->omode);
2509343SAfshin.Ardakani@Sun.COM op->share_access = smb_denymode_to_sharemode(op->omode,
2519343SAfshin.Ardakani@Sun.COM op->fqi.fq_path.pn_path);
2526600Sas200622 op->crtime.tv_sec = op->crtime.tv_nsec = 0;
2535331Samw op->create_disposition = FILE_OPEN;
2547619SJose.Borrego@Sun.COM op->create_options = FILE_NON_DIRECTORY_FILE;
2557619SJose.Borrego@Sun.COM if (op->omode & SMB_DA_WRITE_THROUGH)
2567619SJose.Borrego@Sun.COM op->create_options |= FILE_WRITE_THROUGH;
2575331Samw
2585331Samw if (sr->smb_flg & SMB_FLAGS_OPLOCK) {
2598934SJose.Borrego@Sun.COM if (sr->smb_flg & SMB_FLAGS_OPLOCK_NOTIFY_ANY)
2608934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_BATCH;
2618934SJose.Borrego@Sun.COM else
2628934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
2638934SJose.Borrego@Sun.COM } else {
2648934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_NONE;
2655331Samw }
266*12890SJoyce.McIntosh@Sun.COM op->op_oplock_levelII = B_FALSE;
2675331Samw
2686030Sjb150015 if (smb_common_open(sr) != NT_STATUS_SUCCESS)
2696139Sjb150015 return (SDRC_ERROR);
2705331Samw
2718934SJose.Borrego@Sun.COM if (op->op_oplock_level == SMB_OPLOCK_NONE) {
2725331Samw sr->smb_flg &=
2735331Samw ~(SMB_FLAGS_OPLOCK | SMB_FLAGS_OPLOCK_NOTIFY_ANY);
2745331Samw }
2755331Samw
2768934SJose.Borrego@Sun.COM if (smb_open_dsize_check && op->dsize > UINT_MAX) {
2778934SJose.Borrego@Sun.COM smbsr_error(sr, 0, ERRDOS, ERRbadaccess);
2786139Sjb150015 return (SDRC_ERROR);
2796030Sjb150015 }
2805331Samw
2815331Samw file_attr = op->dattr & FILE_ATTRIBUTE_MASK;
2826600Sas200622 node = sr->fid_ofile->f_node;
28310001SJoyce.McIntosh@Sun.COM if (smb_node_getattr(sr, node, &attr) != 0) {
28410001SJoyce.McIntosh@Sun.COM smbsr_error(sr, NT_STATUS_INTERNAL_ERROR,
28510001SJoyce.McIntosh@Sun.COM ERRDOS, ERROR_INTERNAL_ERROR);
28610001SJoyce.McIntosh@Sun.COM return (SDRC_ERROR);
28710001SJoyce.McIntosh@Sun.COM }
2885331Samw
2896030Sjb150015 rc = smbsr_encode_result(sr, 7, 0, "bwwllww",
2905331Samw 7,
2915331Samw sr->smb_fid,
2925331Samw file_attr,
29310504SKeyur.Desai@Sun.COM smb_time_gmt_to_local(sr, attr.sa_vattr.va_mtime.tv_sec),
2945331Samw (uint32_t)op->dsize,
2958934SJose.Borrego@Sun.COM op->omode,
2965331Samw (uint16_t)0); /* bcc */
2975331Samw
2986139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
2995331Samw }
3005331Samw
3017619SJose.Borrego@Sun.COM /*
3027619SJose.Borrego@Sun.COM * smb_pre_open_andx
3037619SJose.Borrego@Sun.COM * For compatibility with windows servers, the search attributes
3047619SJose.Borrego@Sun.COM * specified in the request are ignored.
3057619SJose.Borrego@Sun.COM */
3066030Sjb150015 smb_sdrc_t
smb_pre_open_andx(smb_request_t * sr)3076139Sjb150015 smb_pre_open_andx(smb_request_t *sr)
3085331Samw {
3096139Sjb150015 struct open_param *op = &sr->arg.open;
3106139Sjb150015 uint16_t flags;
3116600Sas200622 uint32_t creation_time;
3127619SJose.Borrego@Sun.COM uint16_t file_attr, sattr;
3135331Samw int rc;
3145331Samw
3155331Samw bzero(op, sizeof (sr->arg.open));
3166139Sjb150015
3175331Samw rc = smbsr_decode_vwv(sr, "b.wwwwwlwll4.", &sr->andx_com,
3187619SJose.Borrego@Sun.COM &sr->andx_off, &flags, &op->omode, &sattr,
3198934SJose.Borrego@Sun.COM &file_attr, &creation_time, &op->ofun, &op->dsize, &op->timeo);
3206139Sjb150015
3216139Sjb150015 if (rc == 0) {
3229343SAfshin.Ardakani@Sun.COM rc = smbsr_decode_data(sr, "%u", sr, &op->fqi.fq_path.pn_path);
3236139Sjb150015
3246139Sjb150015 op->dattr = file_attr;
3256139Sjb150015
3266139Sjb150015 if (flags & 2)
3278934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
3286139Sjb150015 else if (flags & 4)
3298934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_BATCH;
3308934SJose.Borrego@Sun.COM else
3318934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_NONE;
3326139Sjb150015
3336600Sas200622 if ((creation_time != 0) && (creation_time != UINT_MAX))
33410504SKeyur.Desai@Sun.COM op->crtime.tv_sec =
33510504SKeyur.Desai@Sun.COM smb_time_local_to_gmt(sr, creation_time);
3366600Sas200622 op->crtime.tv_nsec = 0;
3376139Sjb150015
3388934SJose.Borrego@Sun.COM op->create_disposition = smb_ofun_to_crdisposition(op->ofun);
3396139Sjb150015 }
3405331Samw
3416139Sjb150015 DTRACE_SMB_2(op__OpenX__start, smb_request_t *, sr,
3426139Sjb150015 struct open_param *, op);
3436139Sjb150015
3446139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
3456139Sjb150015 }
3466139Sjb150015
3476139Sjb150015 void
smb_post_open_andx(smb_request_t * sr)3486139Sjb150015 smb_post_open_andx(smb_request_t *sr)
3496139Sjb150015 {
3506139Sjb150015 DTRACE_SMB_1(op__OpenX__done, smb_request_t *, sr);
3516139Sjb150015 }
3526139Sjb150015
3536139Sjb150015 smb_sdrc_t
smb_com_open_andx(smb_request_t * sr)3546139Sjb150015 smb_com_open_andx(smb_request_t *sr)
3556139Sjb150015 {
3566139Sjb150015 struct open_param *op = &sr->arg.open;
35711447Samw@Sun.COM smb_node_t *node;
3586139Sjb150015 uint16_t file_attr;
35910001SJoyce.McIntosh@Sun.COM smb_attr_t attr;
3606139Sjb150015 int rc;
3615331Samw
3625331Samw op->desired_access = smb_omode_to_amask(op->omode);
3639343SAfshin.Ardakani@Sun.COM op->share_access = smb_denymode_to_sharemode(op->omode,
3649343SAfshin.Ardakani@Sun.COM op->fqi.fq_path.pn_path);
3655331Samw
3668934SJose.Borrego@Sun.COM if (op->create_disposition > FILE_MAXIMUM_DISPOSITION) {
3678934SJose.Borrego@Sun.COM smbsr_error(sr, 0, ERRDOS, ERRbadaccess);
3686139Sjb150015 return (SDRC_ERROR);
3695331Samw }
3705331Samw
3717619SJose.Borrego@Sun.COM op->create_options = FILE_NON_DIRECTORY_FILE;
3727619SJose.Borrego@Sun.COM if (op->omode & SMB_DA_WRITE_THROUGH)
3737619SJose.Borrego@Sun.COM op->create_options |= FILE_WRITE_THROUGH;
3745331Samw
375*12890SJoyce.McIntosh@Sun.COM op->op_oplock_levelII = B_FALSE;
376*12890SJoyce.McIntosh@Sun.COM
3776030Sjb150015 if (smb_common_open(sr) != NT_STATUS_SUCCESS)
3786139Sjb150015 return (SDRC_ERROR);
3795331Samw
3808934SJose.Borrego@Sun.COM if (smb_open_dsize_check && op->dsize > UINT_MAX) {
3818934SJose.Borrego@Sun.COM smbsr_error(sr, 0, ERRDOS, ERRbadaccess);
3826139Sjb150015 return (SDRC_ERROR);
3835331Samw }
3845331Samw
3858934SJose.Borrego@Sun.COM if (op->op_oplock_level != SMB_OPLOCK_NONE)
3865331Samw op->action_taken |= SMB_OACT_LOCK;
3878934SJose.Borrego@Sun.COM else
3885331Samw op->action_taken &= ~SMB_OACT_LOCK;
3895331Samw
3905331Samw file_attr = op->dattr & FILE_ATTRIBUTE_MASK;
39110001SJoyce.McIntosh@Sun.COM
39211447Samw@Sun.COM switch (sr->tid_tree->t_res_type & STYPE_MASK) {
39311447Samw@Sun.COM case STYPE_DISKTREE:
39411447Samw@Sun.COM case STYPE_PRINTQ:
39511447Samw@Sun.COM node = sr->fid_ofile->f_node;
39610001SJoyce.McIntosh@Sun.COM if (smb_node_getattr(sr, node, &attr) != 0) {
39710001SJoyce.McIntosh@Sun.COM smbsr_error(sr, NT_STATUS_INTERNAL_ERROR,
39810001SJoyce.McIntosh@Sun.COM ERRDOS, ERROR_INTERNAL_ERROR);
39910001SJoyce.McIntosh@Sun.COM return (SDRC_ERROR);
40010001SJoyce.McIntosh@Sun.COM }
40110001SJoyce.McIntosh@Sun.COM
4026030Sjb150015 rc = smbsr_encode_result(sr, 15, 0,
4037052Samw "bb.wwwllwwwwl2.w",
4045331Samw 15,
4055331Samw sr->andx_com, VAR_BCC,
4065331Samw sr->smb_fid,
4075331Samw file_attr,
40810504SKeyur.Desai@Sun.COM smb_time_gmt_to_local(sr, attr.sa_vattr.va_mtime.tv_sec),
4095331Samw (uint32_t)op->dsize,
4108934SJose.Borrego@Sun.COM op->omode, op->ftype,
4115331Samw op->devstate,
4125331Samw op->action_taken, op->fileid,
4135331Samw 0);
41411447Samw@Sun.COM break;
41511447Samw@Sun.COM
41611447Samw@Sun.COM case STYPE_IPC:
4176030Sjb150015 rc = smbsr_encode_result(sr, 15, 0,
4187052Samw "bb.wwwllwwwwl2.w",
4195331Samw 15,
4205331Samw sr->andx_com, VAR_BCC,
4215331Samw sr->smb_fid,
4225331Samw file_attr,
4235331Samw 0L,
4245331Samw 0L,
4258934SJose.Borrego@Sun.COM op->omode, op->ftype,
4265331Samw op->devstate,
4275331Samw op->action_taken, op->fileid,
4285331Samw 0);
42911447Samw@Sun.COM break;
43011447Samw@Sun.COM
43111447Samw@Sun.COM default:
43211447Samw@Sun.COM smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
43311447Samw@Sun.COM ERRDOS, ERROR_INVALID_FUNCTION);
43411447Samw@Sun.COM return (SDRC_ERROR);
4355331Samw }
4365331Samw
4376139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
4385331Samw }
4398934SJose.Borrego@Sun.COM
4408934SJose.Borrego@Sun.COM smb_sdrc_t
smb_com_trans2_open2(smb_request_t * sr,smb_xa_t * xa)4418934SJose.Borrego@Sun.COM smb_com_trans2_open2(smb_request_t *sr, smb_xa_t *xa)
4428934SJose.Borrego@Sun.COM {
4438934SJose.Borrego@Sun.COM struct open_param *op = &sr->arg.open;
4448934SJose.Borrego@Sun.COM uint32_t creation_time;
4458934SJose.Borrego@Sun.COM uint32_t alloc_size;
4468934SJose.Borrego@Sun.COM uint16_t flags;
4478934SJose.Borrego@Sun.COM uint16_t file_attr;
4488934SJose.Borrego@Sun.COM int rc;
4498934SJose.Borrego@Sun.COM
4508934SJose.Borrego@Sun.COM bzero(op, sizeof (sr->arg.open));
4518934SJose.Borrego@Sun.COM
4528934SJose.Borrego@Sun.COM rc = smb_mbc_decodef(&xa->req_param_mb, "%wwwwlwl10.u",
4539343SAfshin.Ardakani@Sun.COM sr, &flags, &op->omode, &op->fqi.fq_sattr, &file_attr,
4549343SAfshin.Ardakani@Sun.COM &creation_time, &op->ofun, &alloc_size, &op->fqi.fq_path.pn_path);
4558934SJose.Borrego@Sun.COM if (rc != 0)
4568934SJose.Borrego@Sun.COM return (SDRC_ERROR);
4578934SJose.Borrego@Sun.COM
4588934SJose.Borrego@Sun.COM if ((creation_time != 0) && (creation_time != UINT_MAX))
45910504SKeyur.Desai@Sun.COM op->crtime.tv_sec = smb_time_local_to_gmt(sr, creation_time);
4608934SJose.Borrego@Sun.COM op->crtime.tv_nsec = 0;
4618934SJose.Borrego@Sun.COM
4628934SJose.Borrego@Sun.COM op->dattr = file_attr;
4638934SJose.Borrego@Sun.COM op->dsize = alloc_size;
4648934SJose.Borrego@Sun.COM op->create_options = FILE_NON_DIRECTORY_FILE;
4658934SJose.Borrego@Sun.COM
4668934SJose.Borrego@Sun.COM op->desired_access = smb_omode_to_amask(op->omode);
4679343SAfshin.Ardakani@Sun.COM op->share_access = smb_denymode_to_sharemode(op->omode,
4689343SAfshin.Ardakani@Sun.COM op->fqi.fq_path.pn_path);
4698934SJose.Borrego@Sun.COM
4708934SJose.Borrego@Sun.COM op->create_disposition = smb_ofun_to_crdisposition(op->ofun);
4718934SJose.Borrego@Sun.COM if (op->create_disposition > FILE_MAXIMUM_DISPOSITION)
4728934SJose.Borrego@Sun.COM op->create_disposition = FILE_CREATE;
4738934SJose.Borrego@Sun.COM
4748934SJose.Borrego@Sun.COM if (op->omode & SMB_DA_WRITE_THROUGH)
4758934SJose.Borrego@Sun.COM op->create_options |= FILE_WRITE_THROUGH;
4768934SJose.Borrego@Sun.COM
4778934SJose.Borrego@Sun.COM if (sr->smb_flg & SMB_FLAGS_OPLOCK) {
4788934SJose.Borrego@Sun.COM if (sr->smb_flg & SMB_FLAGS_OPLOCK_NOTIFY_ANY)
4798934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_BATCH;
4808934SJose.Borrego@Sun.COM else
4818934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
4828934SJose.Borrego@Sun.COM } else {
4838934SJose.Borrego@Sun.COM op->op_oplock_level = SMB_OPLOCK_NONE;
4848934SJose.Borrego@Sun.COM }
485*12890SJoyce.McIntosh@Sun.COM op->op_oplock_levelII = B_FALSE;
4868934SJose.Borrego@Sun.COM
4878934SJose.Borrego@Sun.COM if (smb_common_open(sr) != NT_STATUS_SUCCESS)
4888934SJose.Borrego@Sun.COM return (SDRC_ERROR);
4898934SJose.Borrego@Sun.COM
4908934SJose.Borrego@Sun.COM if (op->op_oplock_level != SMB_OPLOCK_NONE)
4918934SJose.Borrego@Sun.COM op->action_taken |= SMB_OACT_LOCK;
4928934SJose.Borrego@Sun.COM else
4938934SJose.Borrego@Sun.COM op->action_taken &= ~SMB_OACT_LOCK;
4948934SJose.Borrego@Sun.COM
4958934SJose.Borrego@Sun.COM file_attr = op->dattr & FILE_ATTRIBUTE_MASK;
4968934SJose.Borrego@Sun.COM
49711447Samw@Sun.COM if (STYPE_ISIPC(sr->tid_tree->t_res_type))
4988934SJose.Borrego@Sun.COM op->dsize = 0;
4998934SJose.Borrego@Sun.COM
5008934SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&xa->rep_param_mb, "wwllwwwwlwl",
5018934SJose.Borrego@Sun.COM sr->smb_fid,
5028934SJose.Borrego@Sun.COM file_attr,
5038934SJose.Borrego@Sun.COM (uint32_t)0, /* creation time */
5048934SJose.Borrego@Sun.COM (uint32_t)op->dsize,
5058934SJose.Borrego@Sun.COM op->omode,
5068934SJose.Borrego@Sun.COM op->ftype,
5078934SJose.Borrego@Sun.COM op->devstate,
5088934SJose.Borrego@Sun.COM op->action_taken,
5098934SJose.Borrego@Sun.COM op->fileid,
5108934SJose.Borrego@Sun.COM (uint16_t)0, /* EA error offset */
5118934SJose.Borrego@Sun.COM (uint32_t)0); /* EA list length */
5128934SJose.Borrego@Sun.COM
5138934SJose.Borrego@Sun.COM return (SDRC_SUCCESS);
5148934SJose.Borrego@Sun.COM }
515