2 Unix SMB/CIFS implementation.
3 SMB transaction2 handling
4 Copyright (C) Jeremy Allison 1994-2007
5 Copyright (C) Stefan (metze) Metzmacher 2003
6 Copyright (C) Volker Lendecke 2005-2007
7 Copyright (C) Steve French 2005
8 Copyright (C) James Peach 2006-2007
10 Extensively modified by Andrew Tridgell, 1995
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "smbd/globals.h"
29 #include "../libcli/auth/libcli_auth.h"
31 extern enum protocol_types Protocol;
33 #define DIR_ENTRY_SAFETY_MARGIN 4096
35 static char *store_file_unix_basic(connection_struct *conn,
38 const SMB_STRUCT_STAT *psbuf);
40 static char *store_file_unix_basic_info2(connection_struct *conn,
43 const SMB_STRUCT_STAT *psbuf);
45 /********************************************************************
46 Roundup a value to the nearest allocation roundup size boundary.
47 Only do this for Windows clients.
48 ********************************************************************/
50 uint64_t smb_roundup(connection_struct *conn, uint64_t val)
52 uint64_t rval = lp_allocation_roundup_size(SNUM(conn));
54 /* Only roundup for Windows clients. */
55 enum remote_arch_types ra_type = get_remote_arch();
56 if (rval && (ra_type != RA_SAMBA) && (ra_type != RA_CIFSFS)) {
57 val = SMB_ROUNDUP(val,rval);
62 /****************************************************************************
63 Utility functions for dealing with extended attributes.
64 ****************************************************************************/
66 /****************************************************************************
67 Refuse to allow clients to overwrite our private xattrs.
68 ****************************************************************************/
70 static bool samba_private_attr_name(const char *unix_ea_name)
72 static const char * const prohibited_ea_names[] = {
73 SAMBA_POSIX_INHERITANCE_EA_NAME,
74 SAMBA_XATTR_DOS_ATTRIB,
80 for (i = 0; prohibited_ea_names[i]; i++) {
81 if (strequal( prohibited_ea_names[i], unix_ea_name))
84 if (StrnCaseCmp(unix_ea_name, SAMBA_XATTR_DOSSTREAM_PREFIX,
85 strlen(SAMBA_XATTR_DOSSTREAM_PREFIX)) == 0) {
91 /****************************************************************************
92 Get one EA value. Fill in a struct ea_struct.
93 ****************************************************************************/
95 NTSTATUS get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn,
96 files_struct *fsp, const char *fname,
97 const char *ea_name, struct ea_struct *pea)
99 /* Get the value of this xattr. Max size is 64k. */
100 size_t attr_size = 256;
106 val = TALLOC_REALLOC_ARRAY(mem_ctx, val, char, attr_size);
108 return NT_STATUS_NO_MEMORY;
111 if (fsp && fsp->fh->fd != -1) {
112 sizeret = SMB_VFS_FGETXATTR(fsp, ea_name, val, attr_size);
114 sizeret = SMB_VFS_GETXATTR(conn, fname, ea_name, val, attr_size);
117 if (sizeret == -1 && errno == ERANGE && attr_size != 65536) {
123 return map_nt_error_from_unix(errno);
126 DEBUG(10,("get_ea_value: EA %s is of length %u\n", ea_name, (unsigned int)sizeret));
127 dump_data(10, (uint8 *)val, sizeret);
130 if (strnequal(ea_name, "user.", 5)) {
131 pea->name = talloc_strdup(mem_ctx, &ea_name[5]);
133 pea->name = talloc_strdup(mem_ctx, ea_name);
135 if (pea->name == NULL) {
137 return NT_STATUS_NO_MEMORY;
139 pea->value.data = (unsigned char *)val;
140 pea->value.length = (size_t)sizeret;
144 NTSTATUS get_ea_names_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn,
145 files_struct *fsp, const char *fname,
146 char ***pnames, size_t *pnum_names)
148 /* Get a list of all xattrs. Max namesize is 64k. */
149 size_t ea_namelist_size = 1024;
150 char *ea_namelist = NULL;
155 ssize_t sizeret = -1;
157 if (!lp_ea_support(SNUM(conn))) {
164 * TALLOC the result early to get the talloc hierarchy right.
167 names = TALLOC_ARRAY(mem_ctx, char *, 1);
169 DEBUG(0, ("talloc failed\n"));
170 return NT_STATUS_NO_MEMORY;
173 while (ea_namelist_size <= 65536) {
175 ea_namelist = TALLOC_REALLOC_ARRAY(
176 names, ea_namelist, char, ea_namelist_size);
177 if (ea_namelist == NULL) {
178 DEBUG(0, ("talloc failed\n"));
180 return NT_STATUS_NO_MEMORY;
183 if (fsp && fsp->fh->fd != -1) {
184 sizeret = SMB_VFS_FLISTXATTR(fsp, ea_namelist,
187 sizeret = SMB_VFS_LISTXATTR(conn, fname, ea_namelist,
191 if ((sizeret == -1) && (errno == ERANGE)) {
192 ea_namelist_size *= 2;
201 return map_nt_error_from_unix(errno);
204 DEBUG(10, ("get_ea_list_from_file: ea_namelist size = %u\n",
205 (unsigned int)sizeret));
215 * Ensure the result is 0-terminated
218 if (ea_namelist[sizeret-1] != '\0') {
220 return NT_STATUS_INTERNAL_ERROR;
228 for (p = ea_namelist; p - ea_namelist < sizeret; p += strlen(p)+1) {
232 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, names, char *, num_names);
234 DEBUG(0, ("talloc failed\n"));
236 return NT_STATUS_NO_MEMORY;
242 for (p = ea_namelist; p - ea_namelist < sizeret; p += strlen(p)+1) {
243 names[num_names++] = p;
247 *pnum_names = num_names;
251 /****************************************************************************
252 Return a linked list of the total EA's. Plus the total size
253 ****************************************************************************/
255 static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp,
256 const char *fname, size_t *pea_total_len)
258 /* Get a list of all xattrs. Max namesize is 64k. */
261 struct ea_list *ea_list_head = NULL;
266 if (!lp_ea_support(SNUM(conn))) {
270 status = get_ea_names_from_file(talloc_tos(), conn, fsp, fname,
273 if (!NT_STATUS_IS_OK(status) || (num_names == 0)) {
277 for (i=0; i<num_names; i++) {
278 struct ea_list *listp;
281 if (strnequal(names[i], "system.", 7)
282 || samba_private_attr_name(names[i]))
285 listp = TALLOC_P(mem_ctx, struct ea_list);
290 if (!NT_STATUS_IS_OK(get_ea_value(mem_ctx, conn, fsp,
296 push_ascii_fstring(dos_ea_name, listp->ea.name);
299 4 + strlen(dos_ea_name) + 1 + listp->ea.value.length;
301 DEBUG(10,("get_ea_list_from_file: total_len = %u, %s, val len "
302 "= %u\n", (unsigned int)*pea_total_len, dos_ea_name,
303 (unsigned int)listp->ea.value.length));
305 DLIST_ADD_END(ea_list_head, listp, struct ea_list *);
309 /* Add on 4 for total length. */
310 if (*pea_total_len) {
314 DEBUG(10, ("get_ea_list_from_file: total_len = %u\n",
315 (unsigned int)*pea_total_len));
320 /****************************************************************************
321 Fill a qfilepathinfo buffer with EA's. Returns the length of the buffer
323 ****************************************************************************/
325 static unsigned int fill_ea_buffer(TALLOC_CTX *mem_ctx, char *pdata, unsigned int total_data_size,
326 connection_struct *conn, struct ea_list *ea_list)
328 unsigned int ret_data_size = 4;
331 SMB_ASSERT(total_data_size >= 4);
333 if (!lp_ea_support(SNUM(conn))) {
338 for (p = pdata + 4; ea_list; ea_list = ea_list->next) {
341 push_ascii_fstring(dos_ea_name, ea_list->ea.name);
342 dos_namelen = strlen(dos_ea_name);
343 if (dos_namelen > 255 || dos_namelen == 0) {
346 if (ea_list->ea.value.length > 65535) {
349 if (4 + dos_namelen + 1 + ea_list->ea.value.length > total_data_size) {
353 /* We know we have room. */
354 SCVAL(p,0,ea_list->ea.flags);
355 SCVAL(p,1,dos_namelen);
356 SSVAL(p,2,ea_list->ea.value.length);
357 fstrcpy(p+4, dos_ea_name);
358 memcpy( p + 4 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
360 total_data_size -= 4 + dos_namelen + 1 + ea_list->ea.value.length;
361 p += 4 + dos_namelen + 1 + ea_list->ea.value.length;
364 ret_data_size = PTR_DIFF(p, pdata);
365 DEBUG(10,("fill_ea_buffer: data_size = %u\n", ret_data_size ));
366 SIVAL(pdata,0,ret_data_size);
367 return ret_data_size;
370 static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp, const char *fname)
372 size_t total_ea_len = 0;
373 TALLOC_CTX *mem_ctx = NULL;
375 if (!lp_ea_support(SNUM(conn))) {
378 mem_ctx = talloc_tos();
379 (void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
383 /****************************************************************************
384 Ensure the EA name is case insensitive by matching any existing EA name.
385 ****************************************************************************/
387 static void canonicalize_ea_name(connection_struct *conn, files_struct *fsp, const char *fname, fstring unix_ea_name)
390 TALLOC_CTX *mem_ctx = talloc_tos();
391 struct ea_list *ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
393 for (; ea_list; ea_list = ea_list->next) {
394 if (strequal(&unix_ea_name[5], ea_list->ea.name)) {
395 DEBUG(10,("canonicalize_ea_name: %s -> %s\n",
396 &unix_ea_name[5], ea_list->ea.name));
397 safe_strcpy(&unix_ea_name[5], ea_list->ea.name, sizeof(fstring)-6);
403 /****************************************************************************
404 Set or delete an extended attribute.
405 ****************************************************************************/
407 NTSTATUS set_ea(connection_struct *conn, files_struct *fsp,
408 const struct smb_filename *smb_fname, struct ea_list *ea_list)
413 if (!lp_ea_support(SNUM(conn))) {
414 return NT_STATUS_EAS_NOT_SUPPORTED;
417 status = get_full_smb_filename(talloc_tos(), smb_fname,
419 if (!NT_STATUS_IS_OK(status)) {
423 for (;ea_list; ea_list = ea_list->next) {
425 fstring unix_ea_name;
427 fstrcpy(unix_ea_name, "user."); /* All EA's must start with user. */
428 fstrcat(unix_ea_name, ea_list->ea.name);
430 canonicalize_ea_name(conn, fsp, fname, unix_ea_name);
432 DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name, (unsigned int)ea_list->ea.value.length));
434 if (samba_private_attr_name(unix_ea_name)) {
435 DEBUG(10,("set_ea: ea name %s is a private Samba name.\n", unix_ea_name));
436 return NT_STATUS_ACCESS_DENIED;
439 if (ea_list->ea.value.length == 0) {
440 /* Remove the attribute. */
441 if (fsp && (fsp->fh->fd != -1)) {
442 DEBUG(10,("set_ea: deleting ea name %s on file %s by file descriptor.\n",
443 unix_ea_name, fsp->fsp_name));
444 ret = SMB_VFS_FREMOVEXATTR(fsp, unix_ea_name);
446 DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
447 unix_ea_name, fname));
448 ret = SMB_VFS_REMOVEXATTR(conn, fname, unix_ea_name);
451 /* Removing a non existent attribute always succeeds. */
452 if (ret == -1 && errno == ENOATTR) {
453 DEBUG(10,("set_ea: deleting ea name %s didn't exist - succeeding by default.\n",
459 if (fsp && (fsp->fh->fd != -1)) {
460 DEBUG(10,("set_ea: setting ea name %s on file %s by file descriptor.\n",
461 unix_ea_name, fsp->fsp_name));
462 ret = SMB_VFS_FSETXATTR(fsp, unix_ea_name,
463 ea_list->ea.value.data, ea_list->ea.value.length, 0);
465 DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
466 unix_ea_name, fname));
467 ret = SMB_VFS_SETXATTR(conn, fname, unix_ea_name,
468 ea_list->ea.value.data, ea_list->ea.value.length, 0);
474 if (errno == ENOTSUP) {
475 return NT_STATUS_EAS_NOT_SUPPORTED;
478 return map_nt_error_from_unix(errno);
484 /****************************************************************************
485 Read a list of EA names from an incoming data buffer. Create an ea_list with them.
486 ****************************************************************************/
488 static struct ea_list *read_ea_name_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
490 struct ea_list *ea_list_head = NULL;
491 size_t converted_size, offset = 0;
493 while (offset + 2 < data_size) {
494 struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);
495 unsigned int namelen = CVAL(pdata,offset);
497 offset++; /* Go past the namelen byte. */
499 /* integer wrap paranioa. */
500 if ((offset + namelen < offset) || (offset + namelen < namelen) ||
501 (offset > data_size) || (namelen > data_size) ||
502 (offset + namelen >= data_size)) {
505 /* Ensure the name is null terminated. */
506 if (pdata[offset + namelen] != '\0') {
509 if (!pull_ascii_talloc(ctx, &eal->ea.name, &pdata[offset],
511 DEBUG(0,("read_ea_name_list: pull_ascii_talloc "
512 "failed: %s", strerror(errno)));
518 offset += (namelen + 1); /* Go past the name + terminating zero. */
519 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
520 DEBUG(10,("read_ea_name_list: read ea name %s\n", eal->ea.name));
526 /****************************************************************************
527 Read one EA list entry from the buffer.
528 ****************************************************************************/
530 struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used)
532 struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);
534 unsigned int namelen;
535 size_t converted_size;
545 eal->ea.flags = CVAL(pdata,0);
546 namelen = CVAL(pdata,1);
547 val_len = SVAL(pdata,2);
549 if (4 + namelen + 1 + val_len > data_size) {
553 /* Ensure the name is null terminated. */
554 if (pdata[namelen + 4] != '\0') {
557 if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) {
558 DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s",
565 eal->ea.value = data_blob_talloc(eal, NULL, (size_t)val_len + 1);
566 if (!eal->ea.value.data) {
570 memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);
572 /* Ensure we're null terminated just in case we print the value. */
573 eal->ea.value.data[val_len] = '\0';
574 /* But don't count the null. */
575 eal->ea.value.length--;
578 *pbytes_used = 4 + namelen + 1 + val_len;
581 DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));
582 dump_data(10, eal->ea.value.data, eal->ea.value.length);
587 /****************************************************************************
588 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
589 ****************************************************************************/
591 static struct ea_list *read_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
593 struct ea_list *ea_list_head = NULL;
595 size_t bytes_used = 0;
597 while (offset < data_size) {
598 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset, data_size - offset, &bytes_used);
604 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
605 offset += bytes_used;
611 /****************************************************************************
612 Count the total EA size needed.
613 ****************************************************************************/
615 static size_t ea_list_size(struct ea_list *ealist)
618 struct ea_list *listp;
621 for (listp = ealist; listp; listp = listp->next) {
622 push_ascii_fstring(dos_ea_name, listp->ea.name);
623 ret += 4 + strlen(dos_ea_name) + 1 + listp->ea.value.length;
625 /* Add on 4 for total length. */
633 /****************************************************************************
634 Return a union of EA's from a file list and a list of names.
635 The TALLOC context for the two lists *MUST* be identical as we steal
636 memory from one list to add to another. JRA.
637 ****************************************************************************/
639 static struct ea_list *ea_list_union(struct ea_list *name_list, struct ea_list *file_list, size_t *total_ea_len)
641 struct ea_list *nlistp, *flistp;
643 for (nlistp = name_list; nlistp; nlistp = nlistp->next) {
644 for (flistp = file_list; flistp; flistp = flistp->next) {
645 if (strequal(nlistp->ea.name, flistp->ea.name)) {
651 /* Copy the data from this entry. */
652 nlistp->ea.flags = flistp->ea.flags;
653 nlistp->ea.value = flistp->ea.value;
656 nlistp->ea.flags = 0;
657 ZERO_STRUCT(nlistp->ea.value);
661 *total_ea_len = ea_list_size(name_list);
665 /****************************************************************************
666 Send the required number of replies back.
667 We assume all fields other than the data fields are
668 set correctly for the type of call.
669 HACK ! Always assumes smb_setup field is zero.
670 ****************************************************************************/
672 void send_trans2_replies(connection_struct *conn,
673 struct smb_request *req,
680 /* As we are using a protocol > LANMAN1 then the max_send
681 variable must have been set in the sessetupX call.
682 This takes precedence over the max_xmit field in the
683 global struct. These different max_xmit variables should
684 be merged as this is now too confusing */
686 int data_to_send = datasize;
687 int params_to_send = paramsize;
689 const char *pp = params;
690 const char *pd = pdata;
691 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
692 int alignment_offset = 1; /* JRA. This used to be 3. Set to 1 to make netmon parse ok. */
693 int data_alignment_offset = 0;
694 bool overflow = False;
695 struct smbd_server_connection *sconn = smbd_server_conn;
696 int max_send = sconn->smb1.sessions.max_send;
698 /* Modify the data_to_send and datasize and set the error if
699 we're trying to send more than max_data_bytes. We still send
700 the part of the packet(s) that fit. Strange, but needed
703 if (max_data_bytes > 0 && datasize > max_data_bytes) {
704 DEBUG(5,("send_trans2_replies: max_data_bytes %d exceeded by data %d\n",
705 max_data_bytes, datasize ));
706 datasize = data_to_send = max_data_bytes;
710 /* If there genuinely are no parameters or data to send just send the empty packet */
712 if(params_to_send == 0 && data_to_send == 0) {
713 reply_outbuf(req, 10, 0);
714 show_msg((char *)req->outbuf);
715 if (!srv_send_smb(smbd_server_fd(),
718 IS_CONN_ENCRYPTED(conn),
720 exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
722 TALLOC_FREE(req->outbuf);
726 /* When sending params and data ensure that both are nicely aligned */
727 /* Only do this alignment when there is also data to send - else
728 can cause NT redirector problems. */
730 if (((params_to_send % 4) != 0) && (data_to_send != 0))
731 data_alignment_offset = 4 - (params_to_send % 4);
733 /* Space is bufsize minus Netbios over TCP header minus SMB header */
734 /* The alignment_offset is to align the param bytes on an even byte
735 boundary. NT 4.0 Beta needs this to work correctly. */
737 useable_space = max_send - (smb_size
740 + data_alignment_offset);
742 if (useable_space < 0) {
743 DEBUG(0, ("send_trans2_replies failed sanity useable_space "
744 "= %d!!!", useable_space));
745 exit_server_cleanly("send_trans2_replies: Not enough space");
748 while (params_to_send || data_to_send) {
749 /* Calculate whether we will totally or partially fill this packet */
751 total_sent_thistime = params_to_send + data_to_send;
753 /* We can never send more than useable_space */
755 * Note that 'useable_space' does not include the alignment offsets,
756 * but we must include the alignment offsets in the calculation of
757 * the length of the data we send over the wire, as the alignment offsets
758 * are sent here. Fix from Marc_Jacobsen@hp.com.
761 total_sent_thistime = MIN(total_sent_thistime, useable_space);
763 reply_outbuf(req, 10, total_sent_thistime + alignment_offset
764 + data_alignment_offset);
767 * We might have SMBtrans2s in req which was transferred to
768 * the outbuf, fix that.
770 SCVAL(req->outbuf, smb_com, SMBtrans2);
772 /* Set total params and data to be sent */
773 SSVAL(req->outbuf,smb_tprcnt,paramsize);
774 SSVAL(req->outbuf,smb_tdrcnt,datasize);
776 /* Calculate how many parameters and data we can fit into
777 * this packet. Parameters get precedence
780 params_sent_thistime = MIN(params_to_send,useable_space);
781 data_sent_thistime = useable_space - params_sent_thistime;
782 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
784 SSVAL(req->outbuf,smb_prcnt, params_sent_thistime);
786 /* smb_proff is the offset from the start of the SMB header to the
787 parameter bytes, however the first 4 bytes of outbuf are
788 the Netbios over TCP header. Thus use smb_base() to subtract
789 them from the calculation */
791 SSVAL(req->outbuf,smb_proff,
792 ((smb_buf(req->outbuf)+alignment_offset)
793 - smb_base(req->outbuf)));
795 if(params_sent_thistime == 0)
796 SSVAL(req->outbuf,smb_prdisp,0);
798 /* Absolute displacement of param bytes sent in this packet */
799 SSVAL(req->outbuf,smb_prdisp,pp - params);
801 SSVAL(req->outbuf,smb_drcnt, data_sent_thistime);
802 if(data_sent_thistime == 0) {
803 SSVAL(req->outbuf,smb_droff,0);
804 SSVAL(req->outbuf,smb_drdisp, 0);
806 /* The offset of the data bytes is the offset of the
807 parameter bytes plus the number of parameters being sent this time */
808 SSVAL(req->outbuf, smb_droff,
809 ((smb_buf(req->outbuf)+alignment_offset)
810 - smb_base(req->outbuf))
811 + params_sent_thistime + data_alignment_offset);
812 SSVAL(req->outbuf,smb_drdisp, pd - pdata);
815 /* Initialize the padding for alignment */
817 if (alignment_offset != 0) {
818 memset(smb_buf(req->outbuf), 0, alignment_offset);
821 /* Copy the param bytes into the packet */
823 if(params_sent_thistime) {
824 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
825 params_sent_thistime);
828 /* Copy in the data bytes */
829 if(data_sent_thistime) {
830 if (data_alignment_offset != 0) {
831 memset((smb_buf(req->outbuf)+alignment_offset+
832 params_sent_thistime), 0,
833 data_alignment_offset);
835 memcpy(smb_buf(req->outbuf)+alignment_offset
836 +params_sent_thistime+data_alignment_offset,
837 pd,data_sent_thistime);
840 DEBUG(9,("t2_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
841 params_sent_thistime, data_sent_thistime, useable_space));
842 DEBUG(9,("t2_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
843 params_to_send, data_to_send, paramsize, datasize));
846 error_packet_set((char *)req->outbuf,
847 ERRDOS,ERRbufferoverflow,
848 STATUS_BUFFER_OVERFLOW,
852 /* Send the packet */
853 show_msg((char *)req->outbuf);
854 if (!srv_send_smb(smbd_server_fd(),
857 IS_CONN_ENCRYPTED(conn),
859 exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
861 TALLOC_FREE(req->outbuf);
863 pp += params_sent_thistime;
864 pd += data_sent_thistime;
866 params_to_send -= params_sent_thistime;
867 data_to_send -= data_sent_thistime;
870 if(params_to_send < 0 || data_to_send < 0) {
871 DEBUG(0,("send_trans2_replies failed sanity check pts = %d, dts = %d\n!!!",
872 params_to_send, data_to_send));
880 /****************************************************************************
881 Reply to a TRANSACT2_OPEN.
882 ****************************************************************************/
884 static void call_trans2open(connection_struct *conn,
885 struct smb_request *req,
886 char **pparams, int total_params,
887 char **ppdata, int total_data,
888 unsigned int max_data_bytes)
890 struct smb_filename *smb_fname = NULL;
891 char *params = *pparams;
892 char *pdata = *ppdata;
897 bool return_additional_info;
910 struct ea_list *ea_list = NULL;
915 uint32 create_disposition;
916 uint32 create_options = 0;
917 TALLOC_CTX *ctx = talloc_tos();
920 * Ensure we have enough parameters to perform the operation.
923 if (total_params < 29) {
924 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
928 flags = SVAL(params, 0);
929 deny_mode = SVAL(params, 2);
930 open_attr = SVAL(params,6);
931 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
932 if (oplock_request) {
933 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
937 return_additional_info = BITSETW(params,0);
938 open_sattr = SVAL(params, 4);
939 open_time = make_unix_date3(params+8);
941 open_ofun = SVAL(params,12);
942 open_size = IVAL(params,14);
946 reply_doserror(req, ERRSRV, ERRaccess);
950 srvstr_get_path(ctx, params, req->flags2, &fname, pname,
951 total_params - 28, STR_TERMINATE,
953 if (!NT_STATUS_IS_OK(status)) {
954 reply_nterror(req, status);
958 DEBUG(3,("call_trans2open %s deny_mode=0x%x attr=%d ofun=0x%x size=%d\n",
959 fname, (unsigned int)deny_mode, (unsigned int)open_attr,
960 (unsigned int)open_ofun, open_size));
962 status = filename_convert(ctx,
964 req->flags2 & FLAGS2_DFS_PATHNAMES,
968 if (!NT_STATUS_IS_OK(status)) {
969 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
971 NT_STATUS_PATH_NOT_COVERED,
975 reply_nterror(req, status);
979 if (open_ofun == 0) {
980 reply_nterror(req, NT_STATUS_OBJECT_NAME_COLLISION);
984 if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
990 reply_doserror(req, ERRDOS, ERRbadaccess);
994 /* Any data in this call is an EA list. */
995 if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
996 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
1000 if (total_data != 4) {
1001 if (total_data < 10) {
1002 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1006 if (IVAL(pdata,0) > total_data) {
1007 DEBUG(10,("call_trans2open: bad total data size (%u) > %u\n",
1008 IVAL(pdata,0), (unsigned int)total_data));
1009 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1013 ea_list = read_ea_list(talloc_tos(), pdata + 4,
1016 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1019 } else if (IVAL(pdata,0) != 4) {
1020 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1024 status = SMB_VFS_CREATE_FILE(
1027 0, /* root_dir_fid */
1028 smb_fname, /* fname */
1029 access_mask, /* access_mask */
1030 share_mode, /* share_access */
1031 create_disposition, /* create_disposition*/
1032 create_options, /* create_options */
1033 open_attr, /* file_attributes */
1034 oplock_request, /* oplock_request */
1035 open_size, /* allocation_size */
1037 ea_list, /* ea_list */
1039 &smb_action); /* psbuf */
1041 if (!NT_STATUS_IS_OK(status)) {
1042 if (open_was_deferred(req->mid)) {
1043 /* We have re-scheduled this call. */
1046 reply_openerror(req, status);
1050 size = get_file_size_stat(&smb_fname->st);
1051 fattr = dos_mode(conn, smb_fname);
1052 mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
1053 inode = smb_fname->st.st_ex_ino;
1055 close_file(req, fsp, ERROR_CLOSE);
1056 reply_doserror(req, ERRDOS,ERRnoaccess);
1060 /* Realloc the size of parameters and data we will return */
1061 *pparams = (char *)SMB_REALLOC(*pparams, 30);
1062 if(*pparams == NULL ) {
1063 reply_nterror(req, NT_STATUS_NO_MEMORY);
1068 SSVAL(params,0,fsp->fnum);
1069 SSVAL(params,2,fattr);
1070 srv_put_dos_date2(params,4, mtime);
1071 SIVAL(params,8, (uint32)size);
1072 SSVAL(params,12,deny_mode);
1073 SSVAL(params,14,0); /* open_type - file or directory. */
1074 SSVAL(params,16,0); /* open_state - only valid for IPC device. */
1076 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1077 smb_action |= EXTENDED_OPLOCK_GRANTED;
1080 SSVAL(params,18,smb_action);
1083 * WARNING - this may need to be changed if SMB_INO_T <> 4 bytes.
1085 SIVAL(params,20,inode);
1086 SSVAL(params,24,0); /* Padding. */
1088 uint32 ea_size = estimate_ea_size(conn, fsp, fsp->fsp_name);
1089 SIVAL(params, 26, ea_size);
1091 SIVAL(params, 26, 0);
1094 /* Send the required number of replies */
1095 send_trans2_replies(conn, req, params, 30, *ppdata, 0, max_data_bytes);
1097 TALLOC_FREE(smb_fname);
1100 /*********************************************************
1101 Routine to check if a given string matches exactly.
1102 as a special case a mask of "." does NOT match. That
1103 is required for correct wildcard semantics
1104 Case can be significant or not.
1105 **********************************************************/
1107 static bool exact_match(connection_struct *conn,
1111 if (mask[0] == '.' && mask[1] == 0)
1113 if (dptr_has_wild(conn->dirptr)) {
1116 if (conn->case_sensitive)
1117 return strcmp(str,mask)==0;
1119 return StrCaseCmp(str,mask) == 0;
1122 /****************************************************************************
1123 Return the filetype for UNIX extensions.
1124 ****************************************************************************/
1126 static uint32 unix_filetype(mode_t mode)
1129 return UNIX_TYPE_FILE;
1130 else if(S_ISDIR(mode))
1131 return UNIX_TYPE_DIR;
1133 else if(S_ISLNK(mode))
1134 return UNIX_TYPE_SYMLINK;
1137 else if(S_ISCHR(mode))
1138 return UNIX_TYPE_CHARDEV;
1141 else if(S_ISBLK(mode))
1142 return UNIX_TYPE_BLKDEV;
1145 else if(S_ISFIFO(mode))
1146 return UNIX_TYPE_FIFO;
1149 else if(S_ISSOCK(mode))
1150 return UNIX_TYPE_SOCKET;
1153 DEBUG(0,("unix_filetype: unknown filetype %u\n", (unsigned)mode));
1154 return UNIX_TYPE_UNKNOWN;
1157 /****************************************************************************
1158 Map wire perms onto standard UNIX permissions. Obey share restrictions.
1159 ****************************************************************************/
1161 enum perm_type { PERM_NEW_FILE, PERM_NEW_DIR, PERM_EXISTING_FILE, PERM_EXISTING_DIR};
1163 static NTSTATUS unix_perms_from_wire( connection_struct *conn,
1164 const SMB_STRUCT_STAT *psbuf,
1166 enum perm_type ptype,
1171 if (perms == SMB_MODE_NO_CHANGE) {
1172 if (!VALID_STAT(*psbuf)) {
1173 return NT_STATUS_INVALID_PARAMETER;
1175 *ret_perms = psbuf->st_ex_mode;
1176 return NT_STATUS_OK;
1180 ret |= ((perms & UNIX_X_OTH ) ? S_IXOTH : 0);
1181 ret |= ((perms & UNIX_W_OTH ) ? S_IWOTH : 0);
1182 ret |= ((perms & UNIX_R_OTH ) ? S_IROTH : 0);
1183 ret |= ((perms & UNIX_X_GRP ) ? S_IXGRP : 0);
1184 ret |= ((perms & UNIX_W_GRP ) ? S_IWGRP : 0);
1185 ret |= ((perms & UNIX_R_GRP ) ? S_IRGRP : 0);
1186 ret |= ((perms & UNIX_X_USR ) ? S_IXUSR : 0);
1187 ret |= ((perms & UNIX_W_USR ) ? S_IWUSR : 0);
1188 ret |= ((perms & UNIX_R_USR ) ? S_IRUSR : 0);
1190 ret |= ((perms & UNIX_STICKY ) ? S_ISVTX : 0);
1193 ret |= ((perms & UNIX_SET_GID ) ? S_ISGID : 0);
1196 ret |= ((perms & UNIX_SET_UID ) ? S_ISUID : 0);
1201 /* Apply mode mask */
1202 ret &= lp_create_mask(SNUM(conn));
1203 /* Add in force bits */
1204 ret |= lp_force_create_mode(SNUM(conn));
1207 ret &= lp_dir_mask(SNUM(conn));
1208 /* Add in force bits */
1209 ret |= lp_force_dir_mode(SNUM(conn));
1211 case PERM_EXISTING_FILE:
1212 /* Apply mode mask */
1213 ret &= lp_security_mask(SNUM(conn));
1214 /* Add in force bits */
1215 ret |= lp_force_security_mode(SNUM(conn));
1217 case PERM_EXISTING_DIR:
1218 /* Apply mode mask */
1219 ret &= lp_dir_security_mask(SNUM(conn));
1220 /* Add in force bits */
1221 ret |= lp_force_dir_security_mode(SNUM(conn));
1226 return NT_STATUS_OK;
1229 /****************************************************************************
1230 Needed to show the msdfs symlinks as directories. Modifies psbuf
1231 to be a directory if it's a msdfs link.
1232 ****************************************************************************/
1234 static bool check_msdfs_link(connection_struct *conn,
1235 const char *pathname,
1236 SMB_STRUCT_STAT *psbuf)
1238 int saved_errno = errno;
1239 if(lp_host_msdfs() &&
1240 lp_msdfs_root(SNUM(conn)) &&
1241 is_msdfs_link(conn, pathname, psbuf)) {
1243 DEBUG(5,("check_msdfs_link: Masquerading msdfs link %s "
1246 psbuf->st_ex_mode = (psbuf->st_ex_mode & 0xFFF) | S_IFDIR;
1247 errno = saved_errno;
1250 errno = saved_errno;
1255 /****************************************************************************
1256 Get a level dependent lanman2 dir entry.
1257 ****************************************************************************/
1259 static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
1260 connection_struct *conn,
1262 const char *path_mask,
1265 int requires_resume_key,
1271 int space_remaining,
1273 bool *got_exact_match,
1274 int *last_entry_off,
1275 struct ea_list *name_list)
1279 SMB_STRUCT_STAT sbuf;
1280 const char *mask = NULL;
1281 char *pathreal = NULL;
1283 char *p, *q, *pdata = *ppdata;
1287 SMB_OFF_T file_size = 0;
1288 uint64_t allocation_size = 0;
1290 struct timespec mdate_ts, adate_ts, create_date_ts;
1291 time_t mdate = (time_t)0, adate = (time_t)0, create_date = (time_t)0;
1293 char *last_entry_ptr;
1295 uint32 nt_extmode; /* Used for NT connections instead of mode */
1296 bool needslash = ( conn->dirpath[strlen(conn->dirpath) -1] != '/');
1297 bool check_mangled_names = lp_manglednames(conn->params);
1298 char mangled_name[13]; /* mangled 8.3 name. */
1300 *out_of_space = False;
1301 *got_exact_match = False;
1303 ZERO_STRUCT(mdate_ts);
1304 ZERO_STRUCT(adate_ts);
1305 ZERO_STRUCT(create_date_ts);
1307 if (!conn->dirptr) {
1311 p = strrchr_m(path_mask,'/');
1314 mask = talloc_strdup(ctx,"*.*");
1324 bool ms_dfs_link = False;
1326 /* Needed if we run out of space */
1327 long curr_dirpos = prev_dirpos = dptr_TellDir(conn->dirptr);
1328 dname = dptr_ReadDirName(ctx,conn->dirptr,&curr_dirpos,&sbuf);
1331 * Due to bugs in NT client redirectors we are not using
1332 * resume keys any more - set them to zero.
1333 * Check out the related comments in findfirst/findnext.
1339 DEBUG(8,("get_lanman2_dir_entry:readdir on dirptr 0x%lx now at offset %ld\n",
1340 (long)conn->dirptr,curr_dirpos));
1347 * fname may get mangled, dname is never mangled.
1348 * Whenever we're accessing the filesystem we use
1349 * pathreal which is composed from dname.
1355 /* Mangle fname if it's an illegal name. */
1356 if (mangle_must_mangle(dname,conn->params)) {
1357 if (!name_to_8_3(dname,mangled_name,True,conn->params)) {
1359 continue; /* Error - couldn't mangle. */
1361 fname = talloc_strdup(ctx, mangled_name);
1367 if(!(got_match = *got_exact_match = exact_match(conn, fname, mask))) {
1368 got_match = mask_match(fname, mask, conn->case_sensitive);
1371 if(!got_match && check_mangled_names &&
1372 !mangle_is_8_3(fname, False, conn->params)) {
1374 * It turns out that NT matches wildcards against
1375 * both long *and* short names. This may explain some
1376 * of the wildcard wierdness from old DOS clients
1377 * that some people have been seeing.... JRA.
1379 /* Force the mangling into 8.3. */
1380 if (!name_to_8_3( fname, mangled_name, False, conn->params)) {
1382 continue; /* Error - couldn't mangle. */
1385 if(!(got_match = *got_exact_match = exact_match(conn, mangled_name, mask))) {
1386 got_match = mask_match(mangled_name, mask, conn->case_sensitive);
1391 bool isdots = (ISDOT(dname) || ISDOTDOT(dname));
1392 struct smb_filename *smb_fname = NULL;
1395 if (dont_descend && !isdots) {
1402 pathreal = talloc_asprintf(ctx,
1407 pathreal = talloc_asprintf(ctx,
1418 /* A dirent from dptr_ReadDirName isn't a stream. */
1419 status = create_synthetic_smb_fname(ctx, pathreal,
1422 if (!NT_STATUS_IS_OK(status)) {
1427 if (INFO_LEVEL_IS_UNIX(info_level)) {
1428 if (SMB_VFS_LSTAT(conn, smb_fname) != 0) {
1429 DEBUG(5,("get_lanman2_dir_entry: "
1430 "Couldn't lstat [%s] (%s)\n",
1431 smb_fname_str_dbg(smb_fname),
1433 TALLOC_FREE(smb_fname);
1434 TALLOC_FREE(pathreal);
1438 } else if (!VALID_STAT(smb_fname->st) &&
1439 SMB_VFS_STAT(conn, smb_fname) != 0) {
1440 /* Needed to show the msdfs symlinks as
1444 check_msdfs_link(conn,
1445 smb_fname->base_name,
1448 DEBUG(5,("get_lanman2_dir_entry: "
1449 "Couldn't stat [%s] (%s)\n",
1450 smb_fname_str_dbg(smb_fname),
1452 TALLOC_FREE(smb_fname);
1453 TALLOC_FREE(pathreal);
1460 mode = dos_mode_msdfs(conn, smb_fname);
1462 mode = dos_mode(conn, smb_fname);
1465 if (!dir_check_ftype(conn,mode,dirtype)) {
1466 DEBUG(5,("get_lanman2_dir_entry: [%s] attribs didn't match %x\n",fname,dirtype));
1467 TALLOC_FREE(smb_fname);
1468 TALLOC_FREE(pathreal);
1473 if (!(mode & aDIR)) {
1474 file_size = get_file_size_stat(&smb_fname->st);
1477 SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
1479 if (ask_sharemode) {
1480 struct timespec write_time_ts;
1481 struct file_id fileid;
1483 ZERO_STRUCT(write_time_ts);
1484 fileid = vfs_file_id_from_sbuf(conn,
1486 get_file_infos(fileid, NULL, &write_time_ts);
1487 if (!null_timespec(write_time_ts)) {
1488 update_stat_ex_mtime(&smb_fname->st,
1493 mdate_ts = smb_fname->st.st_ex_mtime;
1494 adate_ts = smb_fname->st.st_ex_atime;
1495 create_date_ts = smb_fname->st.st_ex_btime;
1497 if (lp_dos_filetime_resolution(SNUM(conn))) {
1498 dos_filetime_timespec(&create_date_ts);
1499 dos_filetime_timespec(&mdate_ts);
1500 dos_filetime_timespec(&adate_ts);
1503 create_date = convert_timespec_to_time_t(create_date_ts);
1504 mdate = convert_timespec_to_time_t(mdate_ts);
1505 adate = convert_timespec_to_time_t(adate_ts);
1507 DEBUG(5,("get_lanman2_dir_entry: found %s fname=%s\n",
1508 smb_fname_str_dbg(smb_fname), fname));
1512 dptr_DirCacheAdd(conn->dirptr, dname, curr_dirpos);
1513 sbuf = smb_fname->st;
1515 TALLOC_FREE(smb_fname);
1525 nt_extmode = mode ? mode : FILE_ATTRIBUTE_NORMAL;
1527 switch (info_level) {
1528 case SMB_FIND_INFO_STANDARD:
1529 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_INFO_STANDARD\n"));
1530 if(requires_resume_key) {
1534 srv_put_dos_date2(p,0,create_date);
1535 srv_put_dos_date2(p,4,adate);
1536 srv_put_dos_date2(p,8,mdate);
1537 SIVAL(p,12,(uint32)file_size);
1538 SIVAL(p,16,(uint32)allocation_size);
1542 if (flags2 & FLAGS2_UNICODE_STRINGS) {
1543 p += ucs2_align(base_data, p, 0);
1545 len = srvstr_push(base_data, flags2, p,
1546 fname, PTR_DIFF(end_data, p),
1548 if (flags2 & FLAGS2_UNICODE_STRINGS) {
1550 SCVAL(nameptr, -1, len - 2);
1552 SCVAL(nameptr, -1, 0);
1556 SCVAL(nameptr, -1, len - 1);
1558 SCVAL(nameptr, -1, 0);
1564 case SMB_FIND_EA_SIZE:
1565 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_SIZE\n"));
1566 if(requires_resume_key) {
1570 srv_put_dos_date2(p,0,create_date);
1571 srv_put_dos_date2(p,4,adate);
1572 srv_put_dos_date2(p,8,mdate);
1573 SIVAL(p,12,(uint32)file_size);
1574 SIVAL(p,16,(uint32)allocation_size);
1577 unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
1578 SIVAL(p,22,ea_size); /* Extended attributes */
1582 len = srvstr_push(base_data, flags2,
1583 p, fname, PTR_DIFF(end_data, p),
1584 STR_TERMINATE | STR_NOALIGN);
1585 if (flags2 & FLAGS2_UNICODE_STRINGS) {
1598 SCVAL(nameptr,0,len);
1600 SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
1603 case SMB_FIND_EA_LIST:
1605 struct ea_list *file_list = NULL;
1608 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_LIST\n"));
1612 if(requires_resume_key) {
1616 srv_put_dos_date2(p,0,create_date);
1617 srv_put_dos_date2(p,4,adate);
1618 srv_put_dos_date2(p,8,mdate);
1619 SIVAL(p,12,(uint32)file_size);
1620 SIVAL(p,16,(uint32)allocation_size);
1622 p += 22; /* p now points to the EA area. */
1624 file_list = get_ea_list_from_file(ctx, conn, NULL, pathreal, &ea_len);
1625 name_list = ea_list_union(name_list, file_list, &ea_len);
1627 /* We need to determine if this entry will fit in the space available. */
1628 /* Max string size is 255 bytes. */
1629 if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
1630 /* Move the dirptr back to prev_dirpos */
1631 dptr_SeekDir(conn->dirptr, prev_dirpos);
1632 *out_of_space = True;
1633 DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
1634 return False; /* Not finished - just out of space */
1637 /* Push the ea_data followed by the name. */
1638 p += fill_ea_buffer(ctx, p, space_remaining, conn, name_list);
1640 len = srvstr_push(base_data, flags2,
1641 p + 1, fname, PTR_DIFF(end_data, p+1),
1642 STR_TERMINATE | STR_NOALIGN);
1643 if (flags2 & FLAGS2_UNICODE_STRINGS) {
1656 SCVAL(nameptr,0,len);
1658 SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
1662 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
1663 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
1664 was_8_3 = mangle_is_8_3(fname, True, conn->params);
1666 SIVAL(p,0,reskey); p += 4;
1667 put_long_date_timespec(p,create_date_ts); p += 8;
1668 put_long_date_timespec(p,adate_ts); p += 8;
1669 put_long_date_timespec(p,mdate_ts); p += 8;
1670 put_long_date_timespec(p,mdate_ts); p += 8;
1671 SOFF_T(p,0,file_size); p += 8;
1672 SOFF_T(p,0,allocation_size); p += 8;
1673 SIVAL(p,0,nt_extmode); p += 4;
1674 q = p; p += 4; /* q is placeholder for name length. */
1676 unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
1677 SIVAL(p,0,ea_size); /* Extended attributes */
1680 /* Clear the short name buffer. This is
1681 * IMPORTANT as not doing so will trigger
1682 * a Win2k client bug. JRA.
1684 if (!was_8_3 && check_mangled_names) {
1685 if (!name_to_8_3(fname,mangled_name,True,
1687 /* Error - mangle failed ! */
1688 memset(mangled_name,'\0',12);
1690 mangled_name[12] = 0;
1691 len = srvstr_push(base_data, flags2,
1692 p+2, mangled_name, 24,
1693 STR_UPPER|STR_UNICODE);
1695 memset(p + 2 + len,'\0',24 - len);
1702 len = srvstr_push(base_data, flags2, p,
1703 fname, PTR_DIFF(end_data, p),
1704 STR_TERMINATE_ASCII);
1707 SIVAL(p,0,0); /* Ensure any padding is null. */
1708 len = PTR_DIFF(p, pdata);
1709 len = (len + 3) & ~3;
1714 case SMB_FIND_FILE_DIRECTORY_INFO:
1715 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_DIRECTORY_INFO\n"));
1717 SIVAL(p,0,reskey); p += 4;
1718 put_long_date_timespec(p,create_date_ts); p += 8;
1719 put_long_date_timespec(p,adate_ts); p += 8;
1720 put_long_date_timespec(p,mdate_ts); p += 8;
1721 put_long_date_timespec(p,mdate_ts); p += 8;
1722 SOFF_T(p,0,file_size); p += 8;
1723 SOFF_T(p,0,allocation_size); p += 8;
1724 SIVAL(p,0,nt_extmode); p += 4;
1725 len = srvstr_push(base_data, flags2,
1726 p + 4, fname, PTR_DIFF(end_data, p+4),
1727 STR_TERMINATE_ASCII);
1730 SIVAL(p,0,0); /* Ensure any padding is null. */
1731 len = PTR_DIFF(p, pdata);
1732 len = (len + 3) & ~3;
1737 case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
1738 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_FULL_DIRECTORY_INFO\n"));
1740 SIVAL(p,0,reskey); p += 4;
1741 put_long_date_timespec(p,create_date_ts); p += 8;
1742 put_long_date_timespec(p,adate_ts); p += 8;
1743 put_long_date_timespec(p,mdate_ts); p += 8;
1744 put_long_date_timespec(p,mdate_ts); p += 8;
1745 SOFF_T(p,0,file_size); p += 8;
1746 SOFF_T(p,0,allocation_size); p += 8;
1747 SIVAL(p,0,nt_extmode); p += 4;
1748 q = p; p += 4; /* q is placeholder for name length. */
1750 unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
1751 SIVAL(p,0,ea_size); /* Extended attributes */
1754 len = srvstr_push(base_data, flags2, p,
1755 fname, PTR_DIFF(end_data, p),
1756 STR_TERMINATE_ASCII);
1760 SIVAL(p,0,0); /* Ensure any padding is null. */
1761 len = PTR_DIFF(p, pdata);
1762 len = (len + 3) & ~3;
1767 case SMB_FIND_FILE_NAMES_INFO:
1768 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_NAMES_INFO\n"));
1770 SIVAL(p,0,reskey); p += 4;
1772 /* this must *not* be null terminated or w2k gets in a loop trying to set an
1773 acl on a dir (tridge) */
1774 len = srvstr_push(base_data, flags2, p,
1775 fname, PTR_DIFF(end_data, p),
1776 STR_TERMINATE_ASCII);
1779 SIVAL(p,0,0); /* Ensure any padding is null. */
1780 len = PTR_DIFF(p, pdata);
1781 len = (len + 3) & ~3;
1786 case SMB_FIND_ID_FULL_DIRECTORY_INFO:
1787 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_FULL_DIRECTORY_INFO\n"));
1789 SIVAL(p,0,reskey); p += 4;
1790 put_long_date_timespec(p,create_date_ts); p += 8;
1791 put_long_date_timespec(p,adate_ts); p += 8;
1792 put_long_date_timespec(p,mdate_ts); p += 8;
1793 put_long_date_timespec(p,mdate_ts); p += 8;
1794 SOFF_T(p,0,file_size); p += 8;
1795 SOFF_T(p,0,allocation_size); p += 8;
1796 SIVAL(p,0,nt_extmode); p += 4;
1797 q = p; p += 4; /* q is placeholder for name length. */
1799 unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
1800 SIVAL(p,0,ea_size); /* Extended attributes */
1803 SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
1804 SIVAL(p,0,sbuf.st_ex_ino); p += 4; /* FileIndexLow */
1805 SIVAL(p,0,sbuf.st_ex_dev); p += 4; /* FileIndexHigh */
1806 len = srvstr_push(base_data, flags2, p,
1807 fname, PTR_DIFF(end_data, p),
1808 STR_TERMINATE_ASCII);
1811 SIVAL(p,0,0); /* Ensure any padding is null. */
1812 len = PTR_DIFF(p, pdata);
1813 len = (len + 3) & ~3;
1818 case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
1819 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
1820 was_8_3 = mangle_is_8_3(fname, True, conn->params);
1822 SIVAL(p,0,reskey); p += 4;
1823 put_long_date_timespec(p,create_date_ts); p += 8;
1824 put_long_date_timespec(p,adate_ts); p += 8;
1825 put_long_date_timespec(p,mdate_ts); p += 8;
1826 put_long_date_timespec(p,mdate_ts); p += 8;
1827 SOFF_T(p,0,file_size); p += 8;
1828 SOFF_T(p,0,allocation_size); p += 8;
1829 SIVAL(p,0,nt_extmode); p += 4;
1830 q = p; p += 4; /* q is placeholder for name length */
1832 unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
1833 SIVAL(p,0,ea_size); /* Extended attributes */
1836 /* Clear the short name buffer. This is
1837 * IMPORTANT as not doing so will trigger
1838 * a Win2k client bug. JRA.
1840 if (!was_8_3 && check_mangled_names) {
1841 if (!name_to_8_3(fname,mangled_name,True,
1843 /* Error - mangle failed ! */
1844 memset(mangled_name,'\0',12);
1846 mangled_name[12] = 0;
1847 len = srvstr_push(base_data, flags2,
1848 p+2, mangled_name, 24,
1849 STR_UPPER|STR_UNICODE);
1852 memset(p + 2 + len,'\0',24 - len);
1859 SSVAL(p,0,0); p += 2; /* Reserved ? */
1860 SIVAL(p,0,sbuf.st_ex_ino); p += 4; /* FileIndexLow */
1861 SIVAL(p,0,sbuf.st_ex_dev); p += 4; /* FileIndexHigh */
1862 len = srvstr_push(base_data, flags2, p,
1863 fname, PTR_DIFF(end_data, p),
1864 STR_TERMINATE_ASCII);
1867 SIVAL(p,0,0); /* Ensure any padding is null. */
1868 len = PTR_DIFF(p, pdata);
1869 len = (len + 3) & ~3;
1874 /* CIFS UNIX Extension. */
1876 case SMB_FIND_FILE_UNIX:
1877 case SMB_FIND_FILE_UNIX_INFO2:
1879 SIVAL(p,0,reskey); p+= 4; /* Used for continuing search. */
1881 /* Begin of SMB_QUERY_FILE_UNIX_BASIC */
1883 if (info_level == SMB_FIND_FILE_UNIX) {
1884 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX\n"));
1885 p = store_file_unix_basic(conn, p,
1887 len = srvstr_push(base_data, flags2, p,
1888 fname, PTR_DIFF(end_data, p),
1891 DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
1892 p = store_file_unix_basic_info2(conn, p,
1896 len = srvstr_push(base_data, flags2, p, fname,
1897 PTR_DIFF(end_data, p), 0);
1898 SIVAL(nameptr, 0, len);
1902 SIVAL(p,0,0); /* Ensure any padding is null. */
1904 len = PTR_DIFF(p, pdata);
1905 len = (len + 3) & ~3;
1906 SIVAL(pdata,0,len); /* Offset from this structure to the beginning of the next one */
1908 /* End of SMB_QUERY_FILE_UNIX_BASIC */
1918 if (PTR_DIFF(p,pdata) > space_remaining) {
1919 /* Move the dirptr back to prev_dirpos */
1920 dptr_SeekDir(conn->dirptr, prev_dirpos);
1921 *out_of_space = True;
1922 DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
1923 return False; /* Not finished - just out of space */
1926 /* Setup the last entry pointer, as an offset from base_data */
1927 *last_entry_off = PTR_DIFF(last_entry_ptr,base_data);
1928 /* Advance the data pointer to the next slot */
1934 /****************************************************************************
1935 Reply to a TRANS2_FINDFIRST.
1936 ****************************************************************************/
1938 static void call_trans2findfirst(connection_struct *conn,
1939 struct smb_request *req,
1940 char **pparams, int total_params,
1941 char **ppdata, int total_data,
1942 unsigned int max_data_bytes)
1944 /* We must be careful here that we don't return more than the
1945 allowed number of data bytes. If this means returning fewer than
1946 maxentries then so be it. We assume that the redirector has
1947 enough room for the fixed number of parameter bytes it has
1949 struct smb_filename *smb_dname = NULL;
1950 char *params = *pparams;
1951 char *pdata = *ppdata;
1955 uint16 findfirst_flags;
1956 bool close_after_first;
1958 bool requires_resume_key;
1960 char *directory = NULL;
1963 int last_entry_off=0;
1967 bool finished = False;
1968 bool dont_descend = False;
1969 bool out_of_space = False;
1970 int space_remaining;
1971 bool mask_contains_wcard = False;
1972 struct ea_list *ea_list = NULL;
1973 NTSTATUS ntstatus = NT_STATUS_OK;
1974 bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
1975 TALLOC_CTX *ctx = talloc_tos();
1977 if (total_params < 13) {
1978 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1982 dirtype = SVAL(params,0);
1983 maxentries = SVAL(params,2);
1984 findfirst_flags = SVAL(params,4);
1985 close_after_first = (findfirst_flags & FLAG_TRANS2_FIND_CLOSE);
1986 close_if_end = (findfirst_flags & FLAG_TRANS2_FIND_CLOSE_IF_END);
1987 requires_resume_key = (findfirst_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME);
1988 info_level = SVAL(params,6);
1990 DEBUG(3,("call_trans2findfirst: dirtype = %x, maxentries = %d, close_after_first=%d, \
1991 close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
1992 (unsigned int)dirtype, maxentries, close_after_first, close_if_end, requires_resume_key,
1993 info_level, max_data_bytes));
1996 /* W2K3 seems to treat zero as 1. */
2000 switch (info_level) {
2001 case SMB_FIND_INFO_STANDARD:
2002 case SMB_FIND_EA_SIZE:
2003 case SMB_FIND_EA_LIST:
2004 case SMB_FIND_FILE_DIRECTORY_INFO:
2005 case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
2006 case SMB_FIND_FILE_NAMES_INFO:
2007 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
2008 case SMB_FIND_ID_FULL_DIRECTORY_INFO:
2009 case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
2011 case SMB_FIND_FILE_UNIX:
2012 case SMB_FIND_FILE_UNIX_INFO2:
2013 /* Always use filesystem for UNIX mtime query. */
2014 ask_sharemode = false;
2015 if (!lp_unix_extensions()) {
2016 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2021 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2025 srvstr_get_path_wcard(ctx, params, req->flags2, &directory,
2026 params+12, total_params - 12,
2027 STR_TERMINATE, &ntstatus, &mask_contains_wcard);
2028 if (!NT_STATUS_IS_OK(ntstatus)) {
2029 reply_nterror(req, ntstatus);
2033 ntstatus = resolve_dfspath_wcard(ctx, conn,
2034 req->flags2 & FLAGS2_DFS_PATHNAMES,
2037 &mask_contains_wcard);
2038 if (!NT_STATUS_IS_OK(ntstatus)) {
2039 if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_PATH_NOT_COVERED)) {
2040 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
2041 ERRSRV, ERRbadpath);
2044 reply_nterror(req, ntstatus);
2048 ntstatus = unix_convert(ctx, conn, directory, &smb_dname,
2049 (UCF_SAVE_LCOMP | UCF_ALLOW_WCARD_LCOMP));
2050 if (!NT_STATUS_IS_OK(ntstatus)) {
2051 reply_nterror(req, ntstatus);
2055 mask = smb_dname->original_lcomp;
2057 ntstatus = get_full_smb_filename(ctx, smb_dname, &directory);
2058 TALLOC_FREE(smb_dname);
2059 if (!NT_STATUS_IS_OK(ntstatus)) {
2060 reply_nterror(req, ntstatus);
2064 ntstatus = check_name(conn, directory);
2065 if (!NT_STATUS_IS_OK(ntstatus)) {
2066 reply_nterror(req, ntstatus);
2070 p = strrchr_m(directory,'/');
2072 /* Windows and OS/2 systems treat search on the root '\' as if it were '\*' */
2073 if((directory[0] == '.') && (directory[1] == '\0')) {
2074 mask = talloc_strdup(ctx,"*");
2076 reply_nterror(req, NT_STATUS_NO_MEMORY);
2079 mask_contains_wcard = True;
2081 directory = talloc_strdup(talloc_tos(), "./");
2083 reply_nterror(req, NT_STATUS_NO_MEMORY);
2090 DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
2092 if (info_level == SMB_FIND_EA_LIST) {
2095 if (total_data < 4) {
2096 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2100 ea_size = IVAL(pdata,0);
2101 if (ea_size != total_data) {
2102 DEBUG(4,("call_trans2findfirst: Rejecting EA request with incorrect \
2103 total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
2104 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2108 if (!lp_ea_support(SNUM(conn))) {
2109 reply_doserror(req, ERRDOS, ERReasnotsupported);
2113 /* Pull out the list of names. */
2114 ea_list = read_ea_name_list(ctx, pdata + 4, ea_size - 4);
2116 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2121 *ppdata = (char *)SMB_REALLOC(
2122 *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
2123 if(*ppdata == NULL ) {
2124 reply_nterror(req, NT_STATUS_NO_MEMORY);
2128 data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
2130 /* Realloc the params space */
2131 *pparams = (char *)SMB_REALLOC(*pparams, 10);
2132 if (*pparams == NULL) {
2133 reply_nterror(req, NT_STATUS_NO_MEMORY);
2138 /* Save the wildcard match and attribs we are using on this directory -
2139 needed as lanman2 assumes these are being saved between calls */
2141 ntstatus = dptr_create(conn,
2147 mask_contains_wcard,
2151 if (!NT_STATUS_IS_OK(ntstatus)) {
2152 reply_nterror(req, ntstatus);
2156 dptr_num = dptr_dnum(conn->dirptr);
2157 DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype));
2159 /* Initialize per TRANS2_FIND_FIRST operation data */
2160 dptr_init_search_op(conn->dirptr);
2162 /* We don't need to check for VOL here as this is returned by
2163 a different TRANS2 call. */
2165 DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", conn->dirpath,lp_dontdescend(SNUM(conn))));
2166 if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
2167 dont_descend = True;
2170 space_remaining = max_data_bytes;
2171 out_of_space = False;
2173 for (i=0;(i<maxentries) && !finished && !out_of_space;i++) {
2174 bool got_exact_match = False;
2176 /* this is a heuristic to avoid seeking the dirptr except when
2177 absolutely necessary. It allows for a filename of about 40 chars */
2178 if (space_remaining < DIRLEN_GUESS && numentries > 0) {
2179 out_of_space = True;
2182 finished = !get_lanman2_dir_entry(ctx,
2185 mask,dirtype,info_level,
2186 requires_resume_key,dont_descend,
2189 space_remaining, &out_of_space,
2191 &last_entry_off, ea_list);
2194 if (finished && out_of_space)
2197 if (!finished && !out_of_space)
2201 * As an optimisation if we know we aren't looking
2202 * for a wildcard name (ie. the name matches the wildcard exactly)
2203 * then we can finish on any (first) match.
2204 * This speeds up large directory searches. JRA.
2210 /* Ensure space_remaining never goes -ve. */
2211 if (PTR_DIFF(p,pdata) > max_data_bytes) {
2212 space_remaining = 0;
2213 out_of_space = true;
2215 space_remaining = max_data_bytes - PTR_DIFF(p,pdata);
2219 /* Check if we can close the dirptr */
2220 if(close_after_first || (finished && close_if_end)) {
2221 DEBUG(5,("call_trans2findfirst - (2) closing dptr_num %d\n", dptr_num));
2222 dptr_close(&dptr_num);
2226 * If there are no matching entries we must return ERRDOS/ERRbadfile -
2227 * from observation of NT. NB. This changes to ERRDOS,ERRnofiles if
2228 * the protocol level is less than NT1. Tested with smbclient. JRA.
2229 * This should fix the OS/2 client bug #2335.
2232 if(numentries == 0) {
2233 dptr_close(&dptr_num);
2234 if (Protocol < PROTOCOL_NT1) {
2235 reply_doserror(req, ERRDOS, ERRnofiles);
2238 reply_botherror(req, NT_STATUS_NO_SUCH_FILE,
2239 ERRDOS, ERRbadfile);
2244 /* At this point pdata points to numentries directory entries. */
2246 /* Set up the return parameter block */
2247 SSVAL(params,0,dptr_num);
2248 SSVAL(params,2,numentries);
2249 SSVAL(params,4,finished);
2250 SSVAL(params,6,0); /* Never an EA error */
2251 SSVAL(params,8,last_entry_off);
2253 send_trans2_replies(conn, req, params, 10, pdata, PTR_DIFF(p,pdata),
2256 if ((! *directory) && dptr_path(dptr_num)) {
2257 directory = talloc_strdup(talloc_tos(),dptr_path(dptr_num));
2259 reply_nterror(req, NT_STATUS_NO_MEMORY);
2263 DEBUG( 4, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n",
2264 smb_fn_name(req->cmd),
2265 mask, directory, dirtype, numentries ) );
2268 * Force a name mangle here to ensure that the
2269 * mask as an 8.3 name is top of the mangled cache.
2270 * The reasons for this are subtle. Don't remove
2271 * this code unless you know what you are doing
2272 * (see PR#13758). JRA.
2275 if(!mangle_is_8_3_wildcards( mask, False, conn->params)) {
2276 char mangled_name[13];
2277 name_to_8_3(mask, mangled_name, True, conn->params);
2283 /****************************************************************************
2284 Reply to a TRANS2_FINDNEXT.
2285 ****************************************************************************/
2287 static void call_trans2findnext(connection_struct *conn,
2288 struct smb_request *req,
2289 char **pparams, int total_params,
2290 char **ppdata, int total_data,
2291 unsigned int max_data_bytes)
2293 /* We must be careful here that we don't return more than the
2294 allowed number of data bytes. If this means returning fewer than
2295 maxentries then so be it. We assume that the redirector has
2296 enough room for the fixed number of parameter bytes it has
2298 char *params = *pparams;
2299 char *pdata = *ppdata;
2305 uint16 findnext_flags;
2306 bool close_after_request;
2308 bool requires_resume_key;
2310 bool mask_contains_wcard = False;
2311 char *resume_name = NULL;
2312 const char *mask = NULL;
2313 const char *directory = NULL;
2317 int i, last_entry_off=0;
2318 bool finished = False;
2319 bool dont_descend = False;
2320 bool out_of_space = False;
2321 int space_remaining;
2322 struct ea_list *ea_list = NULL;
2323 NTSTATUS ntstatus = NT_STATUS_OK;
2324 bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
2325 TALLOC_CTX *ctx = talloc_tos();
2327 if (total_params < 13) {
2328 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2332 dptr_num = SVAL(params,0);
2333 maxentries = SVAL(params,2);
2334 info_level = SVAL(params,4);
2335 resume_key = IVAL(params,6);
2336 findnext_flags = SVAL(params,10);
2337 close_after_request = (findnext_flags & FLAG_TRANS2_FIND_CLOSE);
2338 close_if_end = (findnext_flags & FLAG_TRANS2_FIND_CLOSE_IF_END);
2339 requires_resume_key = (findnext_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME);
2340 continue_bit = (findnext_flags & FLAG_TRANS2_FIND_CONTINUE);
2342 srvstr_get_path_wcard(ctx, params, req->flags2, &resume_name,
2344 total_params - 12, STR_TERMINATE, &ntstatus,
2345 &mask_contains_wcard);
2346 if (!NT_STATUS_IS_OK(ntstatus)) {
2347 /* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to
2348 complain (it thinks we're asking for the directory above the shared
2349 path or an invalid name). Catch this as the resume name is only compared, never used in
2350 a file access. JRA. */
2351 srvstr_pull_talloc(ctx, params, req->flags2,
2352 &resume_name, params+12,
2356 if (!resume_name || !(ISDOT(resume_name) || ISDOTDOT(resume_name))) {
2357 reply_nterror(req, ntstatus);
2362 DEBUG(3,("call_trans2findnext: dirhandle = %d, max_data_bytes = %d, maxentries = %d, \
2363 close_after_request=%d, close_if_end = %d requires_resume_key = %d \
2364 resume_key = %d resume name = %s continue=%d level = %d\n",
2365 dptr_num, max_data_bytes, maxentries, close_after_request, close_if_end,
2366 requires_resume_key, resume_key, resume_name, continue_bit, info_level));
2369 /* W2K3 seems to treat zero as 1. */
2373 switch (info_level) {
2374 case SMB_FIND_INFO_STANDARD:
2375 case SMB_FIND_EA_SIZE:
2376 case SMB_FIND_EA_LIST:
2377 case SMB_FIND_FILE_DIRECTORY_INFO:
2378 case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
2379 case SMB_FIND_FILE_NAMES_INFO:
2380 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
2381 case SMB_FIND_ID_FULL_DIRECTORY_INFO:
2382 case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
2384 case SMB_FIND_FILE_UNIX:
2385 case SMB_FIND_FILE_UNIX_INFO2:
2386 /* Always use filesystem for UNIX mtime query. */
2387 ask_sharemode = false;
2388 if (!lp_unix_extensions()) {
2389 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2394 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2398 if (info_level == SMB_FIND_EA_LIST) {
2401 if (total_data < 4) {
2402 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2406 ea_size = IVAL(pdata,0);
2407 if (ea_size != total_data) {
2408 DEBUG(4,("call_trans2findnext: Rejecting EA request with incorrect \
2409 total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
2410 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2414 if (!lp_ea_support(SNUM(conn))) {
2415 reply_doserror(req, ERRDOS, ERReasnotsupported);
2419 /* Pull out the list of names. */
2420 ea_list = read_ea_name_list(ctx, pdata + 4, ea_size - 4);
2422 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2427 *ppdata = (char *)SMB_REALLOC(
2428 *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
2429 if(*ppdata == NULL) {
2430 reply_nterror(req, NT_STATUS_NO_MEMORY);
2435 data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
2437 /* Realloc the params space */
2438 *pparams = (char *)SMB_REALLOC(*pparams, 6*SIZEOFWORD);
2439 if(*pparams == NULL ) {
2440 reply_nterror(req, NT_STATUS_NO_MEMORY);
2446 /* Check that the dptr is valid */
2447 if(!(conn->dirptr = dptr_fetch_lanman2(dptr_num))) {
2448 reply_doserror(req, ERRDOS, ERRnofiles);
2452 string_set(&conn->dirpath,dptr_path(dptr_num));
2454 /* Get the wildcard mask from the dptr */
2455 if((p = dptr_wcard(dptr_num))== NULL) {
2456 DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num));
2457 reply_doserror(req, ERRDOS, ERRnofiles);
2462 directory = conn->dirpath;
2464 /* Get the attr mask from the dptr */
2465 dirtype = dptr_attr(dptr_num);
2467 DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld)\n",
2468 dptr_num, mask, dirtype,
2470 dptr_TellDir(conn->dirptr)));
2472 /* Initialize per TRANS2_FIND_NEXT operation data */
2473 dptr_init_search_op(conn->dirptr);
2475 /* We don't need to check for VOL here as this is returned by
2476 a different TRANS2 call. */
2478 DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",conn->dirpath,lp_dontdescend(SNUM(conn))));
2479 if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
2480 dont_descend = True;
2483 space_remaining = max_data_bytes;
2484 out_of_space = False;
2487 * Seek to the correct position. We no longer use the resume key but
2488 * depend on the last file name instead.
2491 if(*resume_name && !continue_bit) {
2494 long current_pos = 0;
2496 * Remember, name_to_8_3 is called by
2497 * get_lanman2_dir_entry(), so the resume name
2498 * could be mangled. Ensure we check the unmangled name.
2501 if (mangle_is_mangled(resume_name, conn->params)) {
2502 char *new_resume_name = NULL;
2503 mangle_lookup_name_from_8_3(ctx,
2507 if (new_resume_name) {
2508 resume_name = new_resume_name;
2513 * Fix for NT redirector problem triggered by resume key indexes
2514 * changing between directory scans. We now return a resume key of 0
2515 * and instead look for the filename to continue from (also given
2516 * to us by NT/95/smbfs/smbclient). If no other scans have been done between the
2517 * findfirst/findnext (as is usual) then the directory pointer
2518 * should already be at the correct place.
2521 finished = !dptr_SearchDir(conn->dirptr, resume_name, ¤t_pos, &st);
2522 } /* end if resume_name && !continue_bit */
2524 for (i=0;(i<(int)maxentries) && !finished && !out_of_space ;i++) {
2525 bool got_exact_match = False;
2527 /* this is a heuristic to avoid seeking the dirptr except when
2528 absolutely necessary. It allows for a filename of about 40 chars */
2529 if (space_remaining < DIRLEN_GUESS && numentries > 0) {
2530 out_of_space = True;
2533 finished = !get_lanman2_dir_entry(ctx,
2536 mask,dirtype,info_level,
2537 requires_resume_key,dont_descend,
2540 space_remaining, &out_of_space,
2542 &last_entry_off, ea_list);
2545 if (finished && out_of_space)
2548 if (!finished && !out_of_space)
2552 * As an optimisation if we know we aren't looking
2553 * for a wildcard name (ie. the name matches the wildcard exactly)
2554 * then we can finish on any (first) match.
2555 * This speeds up large directory searches. JRA.
2561 space_remaining = max_data_bytes - PTR_DIFF(p,pdata);
2564 DEBUG( 3, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n",
2565 smb_fn_name(req->cmd),
2566 mask, directory, dirtype, numentries ) );
2568 /* Check if we can close the dirptr */
2569 if(close_after_request || (finished && close_if_end)) {
2570 DEBUG(5,("call_trans2findnext: closing dptr_num = %d\n", dptr_num));
2571 dptr_close(&dptr_num); /* This frees up the saved mask */
2574 /* Set up the return parameter block */
2575 SSVAL(params,0,numentries);
2576 SSVAL(params,2,finished);
2577 SSVAL(params,4,0); /* Never an EA error */
2578 SSVAL(params,6,last_entry_off);
2580 send_trans2_replies(conn, req, params, 8, pdata, PTR_DIFF(p,pdata),
2586 unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16])
2588 E_md4hash(lp_servicename(SNUM(conn)),objid);
2592 static void samba_extended_info_version(struct smb_extended_info *extended_info)
2594 SMB_ASSERT(extended_info != NULL);
2596 extended_info->samba_magic = SAMBA_EXTENDED_INFO_MAGIC;
2597 extended_info->samba_version = ((SAMBA_VERSION_MAJOR & 0xff) << 24)
2598 | ((SAMBA_VERSION_MINOR & 0xff) << 16)
2599 | ((SAMBA_VERSION_RELEASE & 0xff) << 8);
2600 #ifdef SAMBA_VERSION_REVISION
2601 extended_info->samba_version |= (tolower(*SAMBA_VERSION_REVISION) - 'a' + 1) & 0xff;
2603 extended_info->samba_subversion = 0;
2604 #ifdef SAMBA_VERSION_RC_RELEASE
2605 extended_info->samba_subversion |= (SAMBA_VERSION_RC_RELEASE & 0xff) << 24;
2607 #ifdef SAMBA_VERSION_PRE_RELEASE
2608 extended_info->samba_subversion |= (SAMBA_VERSION_PRE_RELEASE & 0xff) << 16;
2611 #ifdef SAMBA_VERSION_VENDOR_PATCH
2612 extended_info->samba_subversion |= (SAMBA_VERSION_VENDOR_PATCH & 0xffff);
2614 extended_info->samba_gitcommitdate = 0;
2615 #ifdef SAMBA_VERSION_GIT_COMMIT_TIME
2616 unix_to_nt_time(&extended_info->samba_gitcommitdate, SAMBA_VERSION_GIT_COMMIT_TIME);
2619 memset(extended_info->samba_version_string, 0,
2620 sizeof(extended_info->samba_version_string));
2622 snprintf (extended_info->samba_version_string,
2623 sizeof(extended_info->samba_version_string),
2624 "%s", samba_version_string());
2627 /****************************************************************************
2628 Reply to a TRANS2_QFSINFO (query filesystem info).
2629 ****************************************************************************/
2631 static void call_trans2qfsinfo(connection_struct *conn,
2632 struct smb_request *req,
2633 char **pparams, int total_params,
2634 char **ppdata, int total_data,
2635 unsigned int max_data_bytes)
2637 char *pdata, *end_data;
2638 char *params = *pparams;
2642 const char *vname = volume_label(SNUM(conn));
2643 int snum = SNUM(conn);
2644 char *fstype = lp_fstype(SNUM(conn));
2645 uint32 additional_flags = 0;
2647 if (total_params < 2) {
2648 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2652 info_level = SVAL(params,0);
2655 if (info_level != SMB_QUERY_CIFS_UNIX_INFO) {
2656 DEBUG(0,("call_trans2qfsinfo: not an allowed "
2657 "info level (0x%x) on IPC$.\n",
2658 (unsigned int)info_level));
2659 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
2664 if (ENCRYPTION_REQUIRED(conn) && !req->encrypted) {
2665 if (info_level != SMB_QUERY_CIFS_UNIX_INFO) {
2666 DEBUG(0,("call_trans2qfsinfo: encryption required "
2667 "and info level 0x%x sent.\n",
2668 (unsigned int)info_level));
2669 exit_server_cleanly("encryption required "
2675 DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level));
2677 if(vfs_stat_smb_fname(conn,".",&st)!=0) {
2678 DEBUG(2,("call_trans2qfsinfo: stat of . failed (%s)\n", strerror(errno)));
2679 reply_doserror(req, ERRSRV, ERRinvdevice);
2683 *ppdata = (char *)SMB_REALLOC(
2684 *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
2685 if (*ppdata == NULL ) {
2686 reply_nterror(req, NT_STATUS_NO_MEMORY);
2691 memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
2692 end_data = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
2694 switch (info_level) {
2695 case SMB_INFO_ALLOCATION:
2697 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
2699 if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
2700 reply_nterror(req, map_nt_error_from_unix(errno));
2704 block_size = lp_block_size(snum);
2705 if (bsize < block_size) {
2706 uint64_t factor = block_size/bsize;
2711 if (bsize > block_size) {
2712 uint64_t factor = bsize/block_size;
2717 bytes_per_sector = 512;
2718 sectors_per_unit = bsize/bytes_per_sector;
2720 DEBUG(5,("call_trans2qfsinfo : SMB_INFO_ALLOCATION id=%x, bsize=%u, cSectorUnit=%u, \
2721 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_ex_dev, (unsigned int)bsize, (unsigned int)sectors_per_unit,
2722 (unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
2724 SIVAL(pdata,l1_idFileSystem,st.st_ex_dev);
2725 SIVAL(pdata,l1_cSectorUnit,sectors_per_unit);
2726 SIVAL(pdata,l1_cUnit,dsize);
2727 SIVAL(pdata,l1_cUnitAvail,dfree);
2728 SSVAL(pdata,l1_cbSector,bytes_per_sector);
2732 case SMB_INFO_VOLUME:
2733 /* Return volume name */
2735 * Add volume serial number - hash of a combination of
2736 * the called hostname and the service name.
2738 SIVAL(pdata,0,str_checksum(lp_servicename(snum)) ^ (str_checksum(get_local_machine_name())<<16) );
2740 * Win2k3 and previous mess this up by sending a name length
2741 * one byte short. I believe only older clients (OS/2 Win9x) use
2742 * this call so try fixing this by adding a terminating null to
2743 * the pushed string. The change here was adding the STR_TERMINATE. JRA.
2747 pdata+l2_vol_szVolLabel, vname,
2748 PTR_DIFF(end_data, pdata+l2_vol_szVolLabel),
2749 STR_NOALIGN|STR_TERMINATE);
2750 SCVAL(pdata,l2_vol_cch,len);
2751 data_len = l2_vol_szVolLabel + len;
2752 DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n",
2753 (unsigned)convert_timespec_to_time_t(st.st_ex_ctime),
2757 case SMB_QUERY_FS_ATTRIBUTE_INFO:
2758 case SMB_FS_ATTRIBUTE_INFORMATION:
2760 additional_flags = 0;
2761 #if defined(HAVE_SYS_QUOTAS)
2762 additional_flags |= FILE_VOLUME_QUOTAS;
2765 if(lp_nt_acl_support(SNUM(conn))) {
2766 additional_flags |= FILE_PERSISTENT_ACLS;
2769 /* Capabilities are filled in at connection time through STATVFS call */
2770 additional_flags |= conn->fs_capabilities;
2772 SIVAL(pdata,0,FILE_CASE_PRESERVED_NAMES|FILE_CASE_SENSITIVE_SEARCH|
2773 FILE_SUPPORTS_OBJECT_IDS|FILE_UNICODE_ON_DISK|
2774 additional_flags); /* FS ATTRIBUTES */
2776 SIVAL(pdata,4,255); /* Max filename component length */
2777 /* NOTE! the fstype must *not* be null terminated or win98 won't recognise it
2778 and will think we can't do long filenames */
2779 len = srvstr_push(pdata, req->flags2, pdata+12, fstype,
2780 PTR_DIFF(end_data, pdata+12),
2783 data_len = 12 + len;
2786 case SMB_QUERY_FS_LABEL_INFO:
2787 case SMB_FS_LABEL_INFORMATION:
2788 len = srvstr_push(pdata, req->flags2, pdata+4, vname,
2789 PTR_DIFF(end_data, pdata+4), 0);
2794 case SMB_QUERY_FS_VOLUME_INFO:
2795 case SMB_FS_VOLUME_INFORMATION:
2798 * Add volume serial number - hash of a combination of
2799 * the called hostname and the service name.
2801 SIVAL(pdata,8,str_checksum(lp_servicename(snum)) ^
2802 (str_checksum(get_local_machine_name())<<16));
2804 /* Max label len is 32 characters. */
2805 len = srvstr_push(pdata, req->flags2, pdata+18, vname,
2806 PTR_DIFF(end_data, pdata+18),
2808 SIVAL(pdata,12,len);
2811 DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
2812 (int)strlen(vname),vname, lp_servicename(snum)));
2815 case SMB_QUERY_FS_SIZE_INFO:
2816 case SMB_FS_SIZE_INFORMATION:
2818 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
2820 if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
2821 reply_nterror(req, map_nt_error_from_unix(errno));
2824 block_size = lp_block_size(snum);
2825 if (bsize < block_size) {
2826 uint64_t factor = block_size/bsize;
2831 if (bsize > block_size) {
2832 uint64_t factor = bsize/block_size;
2837 bytes_per_sector = 512;
2838 sectors_per_unit = bsize/bytes_per_sector;
2839 DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_SIZE_INFO bsize=%u, cSectorUnit=%u, \
2840 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned int)sectors_per_unit,
2841 (unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
2842 SBIG_UINT(pdata,0,dsize);
2843 SBIG_UINT(pdata,8,dfree);
2844 SIVAL(pdata,16,sectors_per_unit);
2845 SIVAL(pdata,20,bytes_per_sector);
2849 case SMB_FS_FULL_SIZE_INFORMATION:
2851 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
2853 if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
2854 reply_nterror(req, map_nt_error_from_unix(errno));
2857 block_size = lp_block_size(snum);
2858 if (bsize < block_size) {
2859 uint64_t factor = block_size/bsize;
2864 if (bsize > block_size) {
2865 uint64_t factor = bsize/block_size;
2870 bytes_per_sector = 512;
2871 sectors_per_unit = bsize/bytes_per_sector;
2872 DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO bsize=%u, cSectorUnit=%u, \
2873 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned int)sectors_per_unit,
2874 (unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
2875 SBIG_UINT(pdata,0,dsize); /* Total Allocation units. */
2876 SBIG_UINT(pdata,8,dfree); /* Caller available allocation units. */
2877 SBIG_UINT(pdata,16,dfree); /* Actual available allocation units. */
2878 SIVAL(pdata,24,sectors_per_unit); /* Sectors per allocation unit. */
2879 SIVAL(pdata,28,bytes_per_sector); /* Bytes per sector. */
2883 case SMB_QUERY_FS_DEVICE_INFO:
2884 case SMB_FS_DEVICE_INFORMATION:
2886 SIVAL(pdata,0,0); /* dev type */
2887 SIVAL(pdata,4,0); /* characteristics */
2890 #ifdef HAVE_SYS_QUOTAS
2891 case SMB_FS_QUOTA_INFORMATION:
2893 * what we have to send --metze:
2895 * Unknown1: 24 NULL bytes
2896 * Soft Quota Treshold: 8 bytes seems like uint64_t or so
2897 * Hard Quota Limit: 8 bytes seems like uint64_t or so
2898 * Quota Flags: 2 byte :
2899 * Unknown3: 6 NULL bytes
2903 * details for Quota Flags:
2905 * 0x0020 Log Limit: log if the user exceeds his Hard Quota
2906 * 0x0010 Log Warn: log if the user exceeds his Soft Quota
2907 * 0x0002 Deny Disk: deny disk access when the user exceeds his Hard Quota
2908 * 0x0001 Enable Quotas: enable quota for this fs
2912 /* we need to fake up a fsp here,
2913 * because its not send in this call
2916 SMB_NTQUOTA_STRUCT quotas;
2919 ZERO_STRUCT(quotas);
2925 if (conn->server_info->utok.uid != 0) {
2926 DEBUG(0,("set_user_quota: access_denied "
2927 "service [%s] user [%s]\n",
2928 lp_servicename(SNUM(conn)),
2929 conn->server_info->unix_name));
2930 reply_doserror(req, ERRDOS, ERRnoaccess);
2934 if (vfs_get_ntquota(&fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {
2935 DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
2936 reply_doserror(req, ERRSRV, ERRerror);
2942 DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",lp_servicename(SNUM(conn))));
2944 /* Unknown1 24 NULL bytes*/
2945 SBIG_UINT(pdata,0,(uint64_t)0);
2946 SBIG_UINT(pdata,8,(uint64_t)0);
2947 SBIG_UINT(pdata,16,(uint64_t)0);
2949 /* Default Soft Quota 8 bytes */
2950 SBIG_UINT(pdata,24,quotas.softlim);
2952 /* Default Hard Quota 8 bytes */
2953 SBIG_UINT(pdata,32,quotas.hardlim);
2955 /* Quota flag 2 bytes */
2956 SSVAL(pdata,40,quotas.qflags);
2958 /* Unknown3 6 NULL bytes */
2964 #endif /* HAVE_SYS_QUOTAS */
2965 case SMB_FS_OBJECTID_INFORMATION:
2967 unsigned char objid[16];
2968 struct smb_extended_info extended_info;
2969 memcpy(pdata,create_volume_objectid(conn, objid),16);
2970 samba_extended_info_version (&extended_info);
2971 SIVAL(pdata,16,extended_info.samba_magic);
2972 SIVAL(pdata,20,extended_info.samba_version);
2973 SIVAL(pdata,24,extended_info.samba_subversion);
2974 SBIG_UINT(pdata,28,extended_info.samba_gitcommitdate);
2975 memcpy(pdata+36,extended_info.samba_version_string,28);
2981 * Query the version and capabilities of the CIFS UNIX extensions
2985 case SMB_QUERY_CIFS_UNIX_INFO:
2987 bool large_write = lp_min_receive_file_size() &&
2988 !srv_is_signing_active(smbd_server_conn);
2989 bool large_read = !srv_is_signing_active(smbd_server_conn);
2990 int encrypt_caps = 0;
2992 if (!lp_unix_extensions()) {
2993 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2997 switch (conn->encrypt_level) {
3003 encrypt_caps = CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP;
3006 encrypt_caps = CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP|
3007 CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP;
3008 large_write = false;
3014 SSVAL(pdata,0,CIFS_UNIX_MAJOR_VERSION);
3015 SSVAL(pdata,2,CIFS_UNIX_MINOR_VERSION);
3017 /* We have POSIX ACLs, pathname, encryption,
3018 * large read/write, and locking capability. */
3020 SBIG_UINT(pdata,4,((uint64_t)(
3021 CIFS_UNIX_POSIX_ACLS_CAP|
3022 CIFS_UNIX_POSIX_PATHNAMES_CAP|
3023 CIFS_UNIX_FCNTL_LOCKS_CAP|
3024 CIFS_UNIX_EXTATTR_CAP|
3025 CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP|
3027 (large_read ? CIFS_UNIX_LARGE_READ_CAP : 0) |
3029 CIFS_UNIX_LARGE_WRITE_CAP : 0))));
3033 case SMB_QUERY_POSIX_FS_INFO:
3036 vfs_statvfs_struct svfs;
3038 if (!lp_unix_extensions()) {
3039 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3043 rc = SMB_VFS_STATVFS(conn, ".", &svfs);
3047 SIVAL(pdata,0,svfs.OptimalTransferSize);
3048 SIVAL(pdata,4,svfs.BlockSize);
3049 SBIG_UINT(pdata,8,svfs.TotalBlocks);
3050 SBIG_UINT(pdata,16,svfs.BlocksAvail);
3051 SBIG_UINT(pdata,24,svfs.UserBlocksAvail);
3052 SBIG_UINT(pdata,32,svfs.TotalFileNodes);
3053 SBIG_UINT(pdata,40,svfs.FreeFileNodes);
3054 SBIG_UINT(pdata,48,svfs.FsIdentifier);
3055 DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_POSIX_FS_INFO succsessful\n"));
3057 } else if (rc == EOPNOTSUPP) {
3058 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3060 #endif /* EOPNOTSUPP */
3062 DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(SNUM(conn))));
3063 reply_doserror(req, ERRSRV, ERRerror);
3069 case SMB_QUERY_POSIX_WHOAMI:
3075 if (!lp_unix_extensions()) {
3076 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3080 if (max_data_bytes < 40) {
3081 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
3085 /* We ARE guest if global_sid_Builtin_Guests is
3086 * in our list of SIDs.
3088 if (nt_token_check_sid(&global_sid_Builtin_Guests,
3089 conn->server_info->ptok)) {
3090 flags |= SMB_WHOAMI_GUEST;
3093 /* We are NOT guest if global_sid_Authenticated_Users
3094 * is in our list of SIDs.
3096 if (nt_token_check_sid(&global_sid_Authenticated_Users,
3097 conn->server_info->ptok)) {
3098 flags &= ~SMB_WHOAMI_GUEST;
3101 /* NOTE: 8 bytes for UID/GID, irrespective of native
3102 * platform size. This matches
3103 * SMB_QUERY_FILE_UNIX_BASIC and friends.
3105 data_len = 4 /* flags */
3112 + 4 /* pad/reserved */
3113 + (conn->server_info->utok.ngroups * 8)
3115 + (conn->server_info->ptok->num_sids *
3119 SIVAL(pdata, 0, flags);
3120 SIVAL(pdata, 4, SMB_WHOAMI_MASK);
3122 (uint64_t)conn->server_info->utok.uid);
3123 SBIG_UINT(pdata, 16,
3124 (uint64_t)conn->server_info->utok.gid);
3127 if (data_len >= max_data_bytes) {
3128 /* Potential overflow, skip the GIDs and SIDs. */
3130 SIVAL(pdata, 24, 0); /* num_groups */
3131 SIVAL(pdata, 28, 0); /* num_sids */
3132 SIVAL(pdata, 32, 0); /* num_sid_bytes */
3133 SIVAL(pdata, 36, 0); /* reserved */
3139 SIVAL(pdata, 24, conn->server_info->utok.ngroups);
3140 SIVAL(pdata, 28, conn->server_info->num_sids);
3142 /* We walk the SID list twice, but this call is fairly
3143 * infrequent, and I don't expect that it's performance
3144 * sensitive -- jpeach
3146 for (i = 0, sid_bytes = 0;
3147 i < conn->server_info->ptok->num_sids; ++i) {
3148 sid_bytes += ndr_size_dom_sid(
3149 &conn->server_info->ptok->user_sids[i],
3154 /* SID list byte count */
3155 SIVAL(pdata, 32, sid_bytes);
3157 /* 4 bytes pad/reserved - must be zero */
3158 SIVAL(pdata, 36, 0);
3162 for (i = 0; i < conn->server_info->utok.ngroups; ++i) {
3163 SBIG_UINT(pdata, data_len,
3164 (uint64_t)conn->server_info->utok.groups[i]);
3170 i < conn->server_info->ptok->num_sids; ++i) {
3171 int sid_len = ndr_size_dom_sid(
3172 &conn->server_info->ptok->user_sids[i],
3176 sid_linearize(pdata + data_len, sid_len,
3177 &conn->server_info->ptok->user_sids[i]);
3178 data_len += sid_len;
3184 case SMB_MAC_QUERY_FS_INFO:
3186 * Thursby MAC extension... ONLY on NTFS filesystems
3187 * once we do streams then we don't need this
3189 if (strequal(lp_fstype(SNUM(conn)),"NTFS")) {
3191 SIVAL(pdata,84,0x100); /* Don't support mac... */
3196 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3201 send_trans2_replies(conn, req, params, 0, pdata, data_len,
3204 DEBUG( 4, ( "%s info_level = %d\n",
3205 smb_fn_name(req->cmd), info_level) );
3210 /****************************************************************************
3211 Reply to a TRANS2_SETFSINFO (set filesystem info).
3212 ****************************************************************************/
3214 static void call_trans2setfsinfo(connection_struct *conn,
3215 struct smb_request *req,
3216 char **pparams, int total_params,
3217 char **ppdata, int total_data,
3218 unsigned int max_data_bytes)
3220 char *pdata = *ppdata;
3221 char *params = *pparams;
3224 DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",lp_servicename(SNUM(conn))));
3227 if (total_params < 4) {
3228 DEBUG(0,("call_trans2setfsinfo: requires total_params(%d) >= 4 bytes!\n",
3230 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3234 info_level = SVAL(params,2);
3237 if (info_level != SMB_REQUEST_TRANSPORT_ENCRYPTION &&
3238 info_level != SMB_SET_CIFS_UNIX_INFO) {
3239 DEBUG(0,("call_trans2setfsinfo: not an allowed "
3240 "info level (0x%x) on IPC$.\n",
3241 (unsigned int)info_level));
3242 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
3247 if (ENCRYPTION_REQUIRED(conn) && !req->encrypted) {
3248 if (info_level != SMB_REQUEST_TRANSPORT_ENCRYPTION) {
3249 DEBUG(0,("call_trans2setfsinfo: encryption required "
3250 "and info level 0x%x sent.\n",
3251 (unsigned int)info_level));
3252 exit_server_cleanly("encryption required "
3258 switch(info_level) {
3259 case SMB_SET_CIFS_UNIX_INFO:
3261 uint16 client_unix_major;
3262 uint16 client_unix_minor;
3263 uint32 client_unix_cap_low;
3264 uint32 client_unix_cap_high;
3266 if (!lp_unix_extensions()) {
3268 NT_STATUS_INVALID_LEVEL);
3272 /* There should be 12 bytes of capabilities set. */
3273 if (total_data < 8) {
3276 NT_STATUS_INVALID_PARAMETER);
3279 client_unix_major = SVAL(pdata,0);
3280 client_unix_minor = SVAL(pdata,2);
3281 client_unix_cap_low = IVAL(pdata,4);
3282 client_unix_cap_high = IVAL(pdata,8);
3283 /* Just print these values for now. */
3284 DEBUG(10,("call_trans2setfsinfo: set unix info. major = %u, minor = %u \
3285 cap_low = 0x%x, cap_high = 0x%x\n",
3286 (unsigned int)client_unix_major,
3287 (unsigned int)client_unix_minor,
3288 (unsigned int)client_unix_cap_low,
3289 (unsigned int)client_unix_cap_high ));
3291 /* Here is where we must switch to posix pathname processing... */
3292 if (client_unix_cap_low & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
3293 lp_set_posix_pathnames();
3294 mangle_change_to_posix();
3297 if ((client_unix_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) &&
3298 !(client_unix_cap_low & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)) {
3299 /* Client that knows how to do posix locks,
3300 * but not posix open/mkdir operations. Set a
3301 * default type for read/write checks. */
3303 lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK);
3309 case SMB_REQUEST_TRANSPORT_ENCRYPTION:
3312 size_t param_len = 0;
3313 size_t data_len = total_data;
3315 if (!lp_unix_extensions()) {
3318 NT_STATUS_INVALID_LEVEL);
3322 if (lp_smb_encrypt(SNUM(conn)) == false) {
3325 NT_STATUS_NOT_SUPPORTED);
3329 DEBUG( 4,("call_trans2setfsinfo: "
3330 "request transport encryption.\n"));
3332 status = srv_request_encryption_setup(conn,
3333 (unsigned char **)ppdata,
3335 (unsigned char **)pparams,
3338 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) &&
3339 !NT_STATUS_IS_OK(status)) {
3340 reply_nterror(req, status);
3344 send_trans2_replies(conn, req,
3351 if (NT_STATUS_IS_OK(status)) {
3352 /* Server-side transport
3353 * encryption is now *on*. */
3354 status = srv_encryption_start(conn);
3355 if (!NT_STATUS_IS_OK(status)) {
3356 exit_server_cleanly(
3357 "Failure in setting "
3358 "up encrypted transport");
3364 case SMB_FS_QUOTA_INFORMATION:
3366 files_struct *fsp = NULL;
3367 SMB_NTQUOTA_STRUCT quotas;
3369 ZERO_STRUCT(quotas);
3372 if ((conn->server_info->utok.uid != 0)
3373 ||!CAN_WRITE(conn)) {
3374 DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
3375 lp_servicename(SNUM(conn)),
3376 conn->server_info->unix_name));
3377 reply_doserror(req, ERRSRV, ERRaccess);
3381 /* note: normaly there're 48 bytes,
3382 * but we didn't use the last 6 bytes for now
3385 fsp = file_fsp(req, SVAL(params,0));
3387 if (!check_fsp_ntquota_handle(conn, req,
3389 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
3391 req, NT_STATUS_INVALID_HANDLE);
3395 if (total_data < 42) {
3396 DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
3400 NT_STATUS_INVALID_PARAMETER);
3404 /* unknown_1 24 NULL bytes in pdata*/
3406 /* the soft quotas 8 bytes (uint64_t)*/
3407 quotas.softlim = (uint64_t)IVAL(pdata,24);
3408 #ifdef LARGE_SMB_OFF_T
3409 quotas.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
3410 #else /* LARGE_SMB_OFF_T */
3411 if ((IVAL(pdata,28) != 0)&&
3412 ((quotas.softlim != 0xFFFFFFFF)||
3413 (IVAL(pdata,28)!=0xFFFFFFFF))) {
3414 /* more than 32 bits? */
3417 NT_STATUS_INVALID_PARAMETER);
3420 #endif /* LARGE_SMB_OFF_T */
3422 /* the hard quotas 8 bytes (uint64_t)*/
3423 quotas.hardlim = (uint64_t)IVAL(pdata,32);
3424 #ifdef LARGE_SMB_OFF_T
3425 quotas.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
3426 #else /* LARGE_SMB_OFF_T */
3427 if ((IVAL(pdata,36) != 0)&&
3428 ((quotas.hardlim != 0xFFFFFFFF)||
3429 (IVAL(pdata,36)!=0xFFFFFFFF))) {
3430 /* more than 32 bits? */
3433 NT_STATUS_INVALID_PARAMETER);
3436 #endif /* LARGE_SMB_OFF_T */
3438 /* quota_flags 2 bytes **/
3439 quotas.qflags = SVAL(pdata,40);
3441 /* unknown_2 6 NULL bytes follow*/
3443 /* now set the quotas */
3444 if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {
3445 DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
3446 reply_doserror(req, ERRSRV, ERRerror);
3453 DEBUG(3,("call_trans2setfsinfo: unknown level (0x%X) not implemented yet.\n",
3455 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3461 * sending this reply works fine,
3462 * but I'm not sure it's the same
3463 * like windows do...
3466 reply_outbuf(req, 10, 0);
3469 #if defined(HAVE_POSIX_ACLS)
3470 /****************************************************************************
3471 Utility function to count the number of entries in a POSIX acl.
3472 ****************************************************************************/
3474 static unsigned int count_acl_entries(connection_struct *conn, SMB_ACL_T posix_acl)
3476 unsigned int ace_count = 0;
3477 int entry_id = SMB_ACL_FIRST_ENTRY;
3478 SMB_ACL_ENTRY_T entry;
3480 while ( posix_acl && (SMB_VFS_SYS_ACL_GET_ENTRY(conn, posix_acl, entry_id, &entry) == 1)) {
3482 if (entry_id == SMB_ACL_FIRST_ENTRY) {
3483 entry_id = SMB_ACL_NEXT_ENTRY;
3490 /****************************************************************************
3491 Utility function to marshall a POSIX acl into wire format.
3492 ****************************************************************************/
3494 static bool marshall_posix_acl(connection_struct *conn, char *pdata, SMB_STRUCT_STAT *pst, SMB_ACL_T posix_acl)
3496 int entry_id = SMB_ACL_FIRST_ENTRY;
3497 SMB_ACL_ENTRY_T entry;
3499 while ( posix_acl && (SMB_VFS_SYS_ACL_GET_ENTRY(conn, posix_acl, entry_id, &entry) == 1)) {
3500 SMB_ACL_TAG_T tagtype;
3501 SMB_ACL_PERMSET_T permset;
3502 unsigned char perms = 0;
3503 unsigned int own_grp;
3506 if (entry_id == SMB_ACL_FIRST_ENTRY) {
3507 entry_id = SMB_ACL_NEXT_ENTRY;
3510 if (SMB_VFS_SYS_ACL_GET_TAG_TYPE(conn, entry, &tagtype) == -1) {
3511 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_TAG_TYPE failed.\n"));
3515 if (SMB_VFS_SYS_ACL_GET_PERMSET(conn, entry, &permset) == -1) {
3516 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_PERMSET failed.\n"));
3520 perms |= (SMB_VFS_SYS_ACL_GET_PERM(conn, permset, SMB_ACL_READ) ? SMB_POSIX_ACL_READ : 0);
3521 perms |= (SMB_VFS_SYS_ACL_GET_PERM(conn, permset, SMB_ACL_WRITE) ? SMB_POSIX_ACL_WRITE : 0);
3522 perms |= (SMB_VFS_SYS_ACL_GET_PERM(conn, permset, SMB_ACL_EXECUTE) ? SMB_POSIX_ACL_EXECUTE : 0);
3524 SCVAL(pdata,1,perms);
3527 case SMB_ACL_USER_OBJ:
3528 SCVAL(pdata,0,SMB_POSIX_ACL_USER_OBJ);
3529 own_grp = (unsigned int)pst->st_ex_uid;
3530 SIVAL(pdata,2,own_grp);
3535 uid_t *puid = (uid_t *)SMB_VFS_SYS_ACL_GET_QUALIFIER(conn, entry);
3537 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n"));
3540 own_grp = (unsigned int)*puid;
3541 SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn, (void *)puid,tagtype);
3542 SCVAL(pdata,0,SMB_POSIX_ACL_USER);
3543 SIVAL(pdata,2,own_grp);
3547 case SMB_ACL_GROUP_OBJ:
3548 SCVAL(pdata,0,SMB_POSIX_ACL_GROUP_OBJ);
3549 own_grp = (unsigned int)pst->st_ex_gid;
3550 SIVAL(pdata,2,own_grp);
3555 gid_t *pgid= (gid_t *)SMB_VFS_SYS_ACL_GET_QUALIFIER(conn, entry);
3557 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n"));
3560 own_grp = (unsigned int)*pgid;
3561 SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn, (void *)pgid,tagtype);
3562 SCVAL(pdata,0,SMB_POSIX_ACL_GROUP);
3563 SIVAL(pdata,2,own_grp);
3568 SCVAL(pdata,0,SMB_POSIX_ACL_MASK);
3569 SIVAL(pdata,2,0xFFFFFFFF);
3570 SIVAL(pdata,6,0xFFFFFFFF);
3573 SCVAL(pdata,0,SMB_POSIX_ACL_OTHER);
3574 SIVAL(pdata,2,0xFFFFFFFF);
3575 SIVAL(pdata,6,0xFFFFFFFF);
3578 DEBUG(0,("marshall_posix_acl: unknown tagtype.\n"));
3581 pdata += SMB_POSIX_ACL_ENTRY_SIZE;
3588 /****************************************************************************
3589 Store the FILE_UNIX_BASIC info.
3590 ****************************************************************************/
3592 static char *store_file_unix_basic(connection_struct *conn,
3595 const SMB_STRUCT_STAT *psbuf)
3597 DEBUG(10,("store_file_unix_basic: SMB_QUERY_FILE_UNIX_BASIC\n"));
3598 DEBUG(4,("store_file_unix_basic: st_mode=%o\n",(int)psbuf->st_ex_mode));
3600 SOFF_T(pdata,0,get_file_size_stat(psbuf)); /* File size 64 Bit */
3603 SOFF_T(pdata,0,SMB_VFS_GET_ALLOC_SIZE(conn,fsp,psbuf)); /* Number of bytes used on disk - 64 Bit */
3606 put_long_date_timespec(pdata, psbuf->st_ex_ctime); /* Change Time 64 Bit */
3607 put_long_date_timespec(pdata+8, psbuf->st_ex_atime); /* Last access time 64 Bit */
3608 put_long_date_timespec(pdata+16, psbuf->st_ex_mtime); /* Last modification time 64 Bit */
3611 SIVAL(pdata,0,psbuf->st_ex_uid); /* user id for the owner */
3615 SIVAL(pdata,0,psbuf->st_ex_gid); /* group id of owner */
3619 SIVAL(pdata,0,unix_filetype(psbuf->st_ex_mode));
3622 SIVAL(pdata,0,unix_dev_major(psbuf->st_ex_rdev)); /* Major device number if type is device */
3626 SIVAL(pdata,0,unix_dev_minor(psbuf->st_ex_rdev)); /* Minor device number if type is device */
3630 SINO_T_VAL(pdata,0,(SMB_INO_T)psbuf->st_ex_ino); /* inode number */
3633 SIVAL(pdata,0, unix_perms_to_wire(psbuf->st_ex_mode)); /* Standard UNIX file permissions */
3637 SIVAL(pdata,0,psbuf->st_ex_nlink); /* number of hard links */
3644 /* Forward and reverse mappings from the UNIX_INFO2 file flags field and
3645 * the chflags(2) (or equivalent) flags.
3647 * XXX: this really should be behind the VFS interface. To do this, we would
3648 * need to alter SMB_STRUCT_STAT so that it included a flags and a mask field.
3649 * Each VFS module could then implement its own mapping as appropriate for the
3650 * platform. We would then pass the SMB flags into SMB_VFS_CHFLAGS.
3652 static const struct {unsigned stat_fflag; unsigned smb_fflag;}
3656 { UF_NODUMP, EXT_DO_NOT_BACKUP },
3660 { UF_IMMUTABLE, EXT_IMMUTABLE },
3664 { UF_APPEND, EXT_OPEN_APPEND_ONLY },
3668 { UF_HIDDEN, EXT_HIDDEN },
3671 /* Do not remove. We need to guarantee that this array has at least one
3672 * entry to build on HP-UX.
3678 static void map_info2_flags_from_sbuf(const SMB_STRUCT_STAT *psbuf,
3679 uint32 *smb_fflags, uint32 *smb_fmask)
3683 for (i = 0; i < ARRAY_SIZE(info2_flags_map); ++i) {
3684 *smb_fmask |= info2_flags_map[i].smb_fflag;
3685 if (psbuf->st_ex_flags & info2_flags_map[i].stat_fflag) {
3686 *smb_fflags |= info2_flags_map[i].smb_fflag;
3691 static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf,
3692 const uint32 smb_fflags,
3693 const uint32 smb_fmask,
3696 uint32 max_fmask = 0;
3699 *stat_fflags = psbuf->st_ex_flags;
3701 /* For each flags requested in smb_fmask, check the state of the
3702 * corresponding flag in smb_fflags and set or clear the matching
3706 for (i = 0; i < ARRAY_SIZE(info2_flags_map); ++i) {
3707 max_fmask |= info2_flags_map[i].smb_fflag;
3708 if (smb_fmask & info2_flags_map[i].smb_fflag) {
3709 if (smb_fflags & info2_flags_map[i].smb_fflag) {
3710 *stat_fflags |= info2_flags_map[i].stat_fflag;
3712 *stat_fflags &= ~info2_flags_map[i].stat_fflag;
3717 /* If smb_fmask is asking to set any bits that are not supported by
3718 * our flag mappings, we should fail.
3720 if ((smb_fmask & max_fmask) != smb_fmask) {
3728 /* Just like SMB_QUERY_FILE_UNIX_BASIC, but with the addition
3729 * of file flags and birth (create) time.
3731 static char *store_file_unix_basic_info2(connection_struct *conn,
3734 const SMB_STRUCT_STAT *psbuf)
3736 uint32 file_flags = 0;
3737 uint32 flags_mask = 0;
3739 pdata = store_file_unix_basic(conn, pdata, fsp, psbuf);
3741 /* Create (birth) time 64 bit */
3742 put_long_date_timespec(pdata, psbuf->st_ex_btime);
3745 map_info2_flags_from_sbuf(psbuf, &file_flags, &flags_mask);
3746 SIVAL(pdata, 0, file_flags); /* flags */
3747 SIVAL(pdata, 4, flags_mask); /* mask */
3753 static NTSTATUS marshall_stream_info(unsigned int num_streams,
3754 const struct stream_struct *streams,
3756 unsigned int max_data_bytes,
3757 unsigned int *data_size)
3760 unsigned int ofs = 0;
3762 for (i = 0; i < num_streams && ofs <= max_data_bytes; i++) {
3763 unsigned int next_offset;
3765 smb_ucs2_t *namebuf;
3767 if (!push_ucs2_talloc(talloc_tos(), &namebuf,
3768 streams[i].name, &namelen) ||
3771 return NT_STATUS_INVALID_PARAMETER;
3775 * name_buf is now null-terminated, we need to marshall as not
3781 SIVAL(data, ofs+4, namelen);
3782 SOFF_T(data, ofs+8, streams[i].size);
3783 SOFF_T(data, ofs+16, streams[i].alloc_size);
3784 memcpy(data+ofs+24, namebuf, namelen);
3785 TALLOC_FREE(namebuf);
3787 next_offset = ofs + 24 + namelen;
3789 if (i == num_streams-1) {
3790 SIVAL(data, ofs, 0);
3793 unsigned int align = ndr_align_size(next_offset, 8);
3795 memset(data+next_offset, 0, align);
3796 next_offset += align;
3798 SIVAL(data, ofs, next_offset - ofs);
3807 return NT_STATUS_OK;
3810 /****************************************************************************
3811 Reply to a TRANSACT2_QFILEINFO on a PIPE !
3812 ****************************************************************************/
3814 static void call_trans2qpipeinfo(connection_struct *conn,
3815 struct smb_request *req,
3816 unsigned int tran_call,
3817 char **pparams, int total_params,
3818 char **ppdata, int total_data,
3819 unsigned int max_data_bytes)
3821 char *params = *pparams;
3822 char *pdata = *ppdata;
3823 unsigned int data_size = 0;
3824 unsigned int param_size = 2;
3829 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3833 if (total_params < 4) {
3834 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3838 fsp = file_fsp(req, SVAL(params,0));
3839 if (!fsp_is_np(fsp)) {
3840 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
3844 info_level = SVAL(params,2);
3846 *pparams = (char *)SMB_REALLOC(*pparams,2);
3847 if (*pparams == NULL) {
3848 reply_nterror(req, NT_STATUS_NO_MEMORY);
3853 data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
3854 *ppdata = (char *)SMB_REALLOC(*ppdata, data_size);
3855 if (*ppdata == NULL ) {
3856 reply_nterror(req, NT_STATUS_NO_MEMORY);
3861 switch (info_level) {
3862 case SMB_FILE_STANDARD_INFORMATION:
3864 SOFF_T(pdata,0,4096LL);
3871 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3875 send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,
3881 static NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
3882 TALLOC_CTX *mem_ctx,
3883 uint16_t info_level,
3885 const struct smb_filename *smb_fname,
3886 bool delete_pending,
3887 struct timespec write_time_ts,
3889 struct ea_list *ea_list,
3890 int lock_data_count,
3893 unsigned int max_data_bytes,
3895 unsigned int *pdata_size)
3897 char *pdata = *ppdata;
3898 char *dstart, *dend;
3899 unsigned int data_size;
3900 struct timespec create_time_ts, mtime_ts, atime_ts;
3901 time_t create_time, mtime, atime;
3902 SMB_STRUCT_STAT sbuf;
3910 uint64_t file_size = 0;
3912 uint64_t allocation_size = 0;
3914 sbuf = smb_fname->st;
3916 if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
3917 return NT_STATUS_INVALID_LEVEL;
3920 status = get_full_smb_filename(mem_ctx, smb_fname, &fname);
3921 if (!NT_STATUS_IS_OK(status)) {
3925 DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n",
3926 fname, fsp ? fsp->fnum : -1, info_level, max_data_bytes));
3929 mode = dos_mode_msdfs(conn, smb_fname);
3931 mode = dos_mode(conn, smb_fname);
3934 mode = FILE_ATTRIBUTE_NORMAL;
3936 nlink = sbuf.st_ex_nlink;
3938 if (nlink && (mode&aDIR)) {
3942 if ((nlink > 0) && delete_pending) {
3946 data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
3947 *ppdata = (char *)SMB_REALLOC(*ppdata, data_size);
3948 if (*ppdata == NULL) {
3949 return NT_STATUS_NO_MEMORY;
3953 dend = dstart + data_size - 1;
3955 if (!null_timespec(write_time_ts) && !INFO_LEVEL_IS_UNIX(info_level)) {
3956 update_stat_ex_mtime(&sbuf, write_time_ts);
3959 create_time_ts = sbuf.st_ex_btime;
3960 mtime_ts = sbuf.st_ex_mtime;
3961 atime_ts = sbuf.st_ex_atime;
3963 if (lp_dos_filetime_resolution(SNUM(conn))) {
3964 dos_filetime_timespec(&create_time_ts);
3965 dos_filetime_timespec(&mtime_ts);
3966 dos_filetime_timespec(&atime_ts);
3969 create_time = convert_timespec_to_time_t(create_time_ts);
3970 mtime = convert_timespec_to_time_t(mtime_ts);
3971 atime = convert_timespec_to_time_t(atime_ts);
3973 p = strrchr_m(smb_fname->base_name,'/');
3975 base_name = smb_fname->base_name;
3979 /* NT expects the name to be in an exact form of the *full*
3980 filename. See the trans2 torture test */
3981 if (ISDOT(base_name)) {
3982 dos_fname = talloc_strdup(mem_ctx, "\\");
3984 return NT_STATUS_NO_MEMORY;
3987 dos_fname = talloc_asprintf(mem_ctx,
3991 return NT_STATUS_NO_MEMORY;
3993 string_replace(dos_fname, '/', '\\');
3996 allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &sbuf);
3999 /* Do we have this path open ? */
4001 struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf);
4002 fsp1 = file_find_di_first(fileid);
4003 if (fsp1 && fsp1->initial_allocation_size) {
4004 allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, &sbuf);
4008 if (!(mode & aDIR)) {
4009 file_size = get_file_size_stat(&sbuf);
4012 if (fsp && fsp->fh) {
4013 pos = fsp->fh->position_information;
4016 switch (info_level) {
4017 case SMB_INFO_STANDARD:
4018 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_STANDARD\n"));
4020 srv_put_dos_date2(pdata,l1_fdateCreation,create_time);
4021 srv_put_dos_date2(pdata,l1_fdateLastAccess,atime);
4022 srv_put_dos_date2(pdata,l1_fdateLastWrite,mtime); /* write time */
4023 SIVAL(pdata,l1_cbFile,(uint32)file_size);
4024 SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
4025 SSVAL(pdata,l1_attrFile,mode);
4028 case SMB_INFO_QUERY_EA_SIZE:
4030 unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
4031 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
4033 srv_put_dos_date2(pdata,0,create_time);
4034 srv_put_dos_date2(pdata,4,atime);
4035 srv_put_dos_date2(pdata,8,mtime); /* write time */
4036 SIVAL(pdata,12,(uint32)file_size);
4037 SIVAL(pdata,16,(uint32)allocation_size);
4038 SSVAL(pdata,20,mode);
4039 SIVAL(pdata,22,ea_size);
4043 case SMB_INFO_IS_NAME_VALID:
4044 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_IS_NAME_VALID\n"));
4046 /* os/2 needs this ? really ?*/
4047 return NT_STATUS_DOS(ERRDOS, ERRbadfunc);
4049 /* This is only reached for qpathinfo */
4053 case SMB_INFO_QUERY_EAS_FROM_LIST:
4055 size_t total_ea_len = 0;
4056 struct ea_list *ea_file_list = NULL;
4058 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
4060 ea_file_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
4061 ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len);
4063 if (!ea_list || (total_ea_len > data_size)) {
4065 SIVAL(pdata,0,4); /* EA List Length must be set to 4 if no EA's. */
4069 data_size = fill_ea_buffer(mem_ctx, pdata, data_size, conn, ea_list);
4073 case SMB_INFO_QUERY_ALL_EAS:
4075 /* We have data_size bytes to put EA's into. */
4076 size_t total_ea_len = 0;
4078 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
4080 ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
4081 if (!ea_list || (total_ea_len > data_size)) {
4083 SIVAL(pdata,0,4); /* EA List Length must be set to 4 if no EA's. */
4087 data_size = fill_ea_buffer(mem_ctx, pdata, data_size, conn, ea_list);
4091 case SMB_FILE_BASIC_INFORMATION:
4092 case SMB_QUERY_FILE_BASIC_INFO:
4094 if (info_level == SMB_QUERY_FILE_BASIC_INFO) {
4095 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_BASIC_INFO\n"));
4096 data_size = 36; /* w95 returns 40 bytes not 36 - why ?. */
4098 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_BASIC_INFORMATION\n"));
4102 put_long_date_timespec(pdata,create_time_ts);
4103 put_long_date_timespec(pdata+8,atime_ts);
4104 put_long_date_timespec(pdata+16,mtime_ts); /* write time */
4105 put_long_date_timespec(pdata+24,mtime_ts); /* change time */
4106 SIVAL(pdata,32,mode);
4108 DEBUG(5,("SMB_QFBI - "));
4109 DEBUG(5,("create: %s ", ctime(&create_time)));
4110 DEBUG(5,("access: %s ", ctime(&atime)));
4111 DEBUG(5,("write: %s ", ctime(&mtime)));
4112 DEBUG(5,("change: %s ", ctime(&mtime)));
4113 DEBUG(5,("mode: %x\n", mode));
4116 case SMB_FILE_STANDARD_INFORMATION:
4117 case SMB_QUERY_FILE_STANDARD_INFO:
4119 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_STANDARD_INFORMATION\n"));
4121 SOFF_T(pdata,0,allocation_size);
4122 SOFF_T(pdata,8,file_size);
4123 SIVAL(pdata,16,nlink);
4124 SCVAL(pdata,20,delete_pending?1:0);
4125 SCVAL(pdata,21,(mode&aDIR)?1:0);
4126 SSVAL(pdata,22,0); /* Padding. */
4129 case SMB_FILE_EA_INFORMATION:
4130 case SMB_QUERY_FILE_EA_INFO:
4132 unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
4133 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
4135 SIVAL(pdata,0,ea_size);
4139 /* Get the 8.3 name - used if NT SMB was negotiated. */
4140 case SMB_QUERY_FILE_ALT_NAME_INFO:
4141 case SMB_FILE_ALTERNATE_NAME_INFORMATION:
4144 char mangled_name[13];
4145 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
4146 if (!name_to_8_3(base_name,mangled_name,
4147 True,conn->params)) {
4148 return NT_STATUS_NO_MEMORY;
4150 len = srvstr_push(dstart, flags2,
4151 pdata+4, mangled_name,
4152 PTR_DIFF(dend, pdata+4),
4154 data_size = 4 + len;
4159 case SMB_QUERY_FILE_NAME_INFO:
4163 this must be *exactly* right for ACLs on mapped drives to work
4165 len = srvstr_push(dstart, flags2,
4167 PTR_DIFF(dend, pdata+4),
4169 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
4170 data_size = 4 + len;
4175 case SMB_FILE_ALLOCATION_INFORMATION:
4176 case SMB_QUERY_FILE_ALLOCATION_INFO:
4177 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALLOCATION_INFORMATION\n"));
4179 SOFF_T(pdata,0,allocation_size);
4182 case SMB_FILE_END_OF_FILE_INFORMATION:
4183 case SMB_QUERY_FILE_END_OF_FILEINFO:
4184 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_END_OF_FILE_INFORMATION\n"));
4186 SOFF_T(pdata,0,file_size);
4189 case SMB_QUERY_FILE_ALL_INFO:
4190 case SMB_FILE_ALL_INFORMATION:
4193 unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
4194 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
4195 put_long_date_timespec(pdata,create_time_ts);
4196 put_long_date_timespec(pdata+8,atime_ts);
4197 put_long_date_timespec(pdata+16,mtime_ts); /* write time */
4198 put_long_date_timespec(pdata+24,mtime_ts); /* change time */
4199 SIVAL(pdata,32,mode);
4200 SIVAL(pdata,36,0); /* padding. */
4202 SOFF_T(pdata,0,allocation_size);
4203 SOFF_T(pdata,8,file_size);
4204 SIVAL(pdata,16,nlink);
4205 SCVAL(pdata,20,delete_pending);
4206 SCVAL(pdata,21,(mode&aDIR)?1:0);
4209 SIVAL(pdata,0,ea_size);
4210 pdata += 4; /* EA info */
4211 len = srvstr_push(dstart, flags2,
4213 PTR_DIFF(dend, pdata+4),
4217 data_size = PTR_DIFF(pdata,(*ppdata));
4220 case SMB_FILE_INTERNAL_INFORMATION:
4221 /* This should be an index number - looks like
4224 I think this causes us to fail the IFSKIT
4225 BasicFileInformationTest. -tpot */
4227 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
4228 SIVAL(pdata,0,sbuf.st_ex_ino); /* FileIndexLow */
4229 SIVAL(pdata,4,sbuf.st_ex_dev); /* FileIndexHigh */
4233 case SMB_FILE_ACCESS_INFORMATION:
4234 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
4236 SIVAL(pdata,0,fsp->access_mask);
4238 /* GENERIC_EXECUTE mapping from Windows */
4239 SIVAL(pdata,0,0x12019F);
4244 case SMB_FILE_NAME_INFORMATION:
4245 /* Pathname with leading '\'. */
4248 byte_len = dos_PutUniCode(pdata+4,dos_fname,(size_t)max_data_bytes,False);
4249 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NAME_INFORMATION\n"));
4250 SIVAL(pdata,0,byte_len);
4251 data_size = 4 + byte_len;
4255 case SMB_FILE_DISPOSITION_INFORMATION:
4256 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_DISPOSITION_INFORMATION\n"));
4258 SCVAL(pdata,0,delete_pending);
4261 case SMB_FILE_POSITION_INFORMATION:
4262 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_POSITION_INFORMATION\n"));
4264 SOFF_T(pdata,0,pos);
4267 case SMB_FILE_MODE_INFORMATION:
4268 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_MODE_INFORMATION\n"));
4269 SIVAL(pdata,0,mode);
4273 case SMB_FILE_ALIGNMENT_INFORMATION:
4274 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALIGNMENT_INFORMATION\n"));
4275 SIVAL(pdata,0,0); /* No alignment needed. */
4280 * NT4 server just returns "invalid query" to this - if we try
4281 * to answer it then NTws gets a BSOD! (tridge). W2K seems to
4284 /* The first statement above is false - verified using Thursby
4285 * client against NT4 -- gcolley.
4287 case SMB_QUERY_FILE_STREAM_INFO:
4288 case SMB_FILE_STREAM_INFORMATION: {
4289 unsigned int num_streams;
4290 struct stream_struct *streams;
4292 DEBUG(10,("smbd_do_qfilepathinfo: "
4293 "SMB_FILE_STREAM_INFORMATION\n"));
4295 status = SMB_VFS_STREAMINFO(
4296 conn, fsp, fname, talloc_tos(),
4297 &num_streams, &streams);
4299 if (!NT_STATUS_IS_OK(status)) {
4300 DEBUG(10, ("could not get stream info: %s\n",
4301 nt_errstr(status)));
4305 status = marshall_stream_info(num_streams, streams,
4306 pdata, max_data_bytes,
4309 if (!NT_STATUS_IS_OK(status)) {
4310 DEBUG(10, ("marshall_stream_info failed: %s\n",
4311 nt_errstr(status)));
4315 TALLOC_FREE(streams);
4319 case SMB_QUERY_COMPRESSION_INFO:
4320 case SMB_FILE_COMPRESSION_INFORMATION:
4321 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_COMPRESSION_INFORMATION\n"));
4322 SOFF_T(pdata,0,file_size);
4323 SIVAL(pdata,8,0); /* ??? */
4324 SIVAL(pdata,12,0); /* ??? */
4328 case SMB_FILE_NETWORK_OPEN_INFORMATION:
4329 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NETWORK_OPEN_INFORMATION\n"));
4330 put_long_date_timespec(pdata,create_time_ts);
4331 put_long_date_timespec(pdata+8,atime_ts);
4332 put_long_date_timespec(pdata+16,mtime_ts); /* write time */
4333 put_long_date_timespec(pdata+24,mtime_ts); /* change time */
4334 SOFF_T(pdata,32,allocation_size);
4335 SOFF_T(pdata,40,file_size);
4336 SIVAL(pdata,48,mode);
4337 SIVAL(pdata,52,0); /* ??? */
4341 case SMB_FILE_ATTRIBUTE_TAG_INFORMATION:
4342 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ATTRIBUTE_TAG_INFORMATION\n"));
4343 SIVAL(pdata,0,mode);
4349 * CIFS UNIX Extensions.
4352 case SMB_QUERY_FILE_UNIX_BASIC:
4354 pdata = store_file_unix_basic(conn, pdata, fsp, &sbuf);
4355 data_size = PTR_DIFF(pdata,(*ppdata));
4359 DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
4361 for (i=0; i<100; i++)
4362 DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
4368 case SMB_QUERY_FILE_UNIX_INFO2:
4370 pdata = store_file_unix_basic_info2(conn, pdata, fsp, &sbuf);
4371 data_size = PTR_DIFF(pdata,(*ppdata));
4375 DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
4377 for (i=0; i<100; i++)
4378 DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
4384 case SMB_QUERY_FILE_UNIX_LINK:
4387 char *buffer = TALLOC_ARRAY(mem_ctx, char, PATH_MAX+1);
4390 return NT_STATUS_NO_MEMORY;
4393 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
4395 if(!S_ISLNK(sbuf.st_ex_mode)) {
4396 return NT_STATUS_DOS(ERRSRV, ERRbadlink);
4399 return NT_STATUS_DOS(ERRDOS, ERRbadlink);
4401 len = SMB_VFS_READLINK(conn,fname,
4404 return map_nt_error_from_unix(errno);
4407 len = srvstr_push(dstart, flags2,
4409 PTR_DIFF(dend, pdata),
4412 data_size = PTR_DIFF(pdata,(*ppdata));
4417 #if defined(HAVE_POSIX_ACLS)
4418 case SMB_QUERY_POSIX_ACL:
4420 SMB_ACL_T file_acl = NULL;
4421 SMB_ACL_T def_acl = NULL;
4422 uint16 num_file_acls = 0;
4423 uint16 num_def_acls = 0;
4425 if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
4426 file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
4428 file_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_ACCESS);
4431 if (file_acl == NULL && no_acl_syscall_error(errno)) {
4432 DEBUG(5,("smbd_do_qfilepathinfo: ACLs not implemented on filesystem containing %s\n",
4434 return NT_STATUS_NOT_IMPLEMENTED;
4437 if (S_ISDIR(sbuf.st_ex_mode)) {
4438 if (fsp && fsp->is_directory) {
4439 def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fsp->fsp_name, SMB_ACL_TYPE_DEFAULT);
4441 def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_DEFAULT);
4443 def_acl = free_empty_sys_acl(conn, def_acl);
4446 num_file_acls = count_acl_entries(conn, file_acl);
4447 num_def_acls = count_acl_entries(conn, def_acl);
4449 if ( data_size < (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE) {
4450 DEBUG(5,("smbd_do_qfilepathinfo: data_size too small (%u) need %u\n",
4452 (unsigned int)((num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE +
4453 SMB_POSIX_ACL_HEADER_SIZE) ));
4455 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
4458 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
4460 return NT_STATUS_BUFFER_TOO_SMALL;
4463 SSVAL(pdata,0,SMB_POSIX_ACL_VERSION);
4464 SSVAL(pdata,2,num_file_acls);
4465 SSVAL(pdata,4,num_def_acls);
4466 if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE, &sbuf, file_acl)) {
4468 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
4471 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
4473 return NT_STATUS_INTERNAL_ERROR;
4475 if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE + (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE), &sbuf, def_acl)) {
4477 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
4480 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
4482 return NT_STATUS_INTERNAL_ERROR;
4486 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
4489 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
4491 data_size = (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE;
4497 case SMB_QUERY_POSIX_LOCK:
4502 enum brl_type lock_type;
4504 if (lock_data_count != POSIX_LOCK_DATA_SIZE) {
4505 return NT_STATUS_INVALID_PARAMETER;
4508 switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
4509 case POSIX_LOCK_TYPE_READ:
4510 lock_type = READ_LOCK;
4512 case POSIX_LOCK_TYPE_WRITE:
4513 lock_type = WRITE_LOCK;
4515 case POSIX_LOCK_TYPE_UNLOCK:
4517 /* There's no point in asking for an unlock... */
4518 return NT_STATUS_INVALID_PARAMETER;
4521 lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
4522 #if defined(HAVE_LONGLONG)
4523 offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
4524 ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
4525 count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
4526 ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
4527 #else /* HAVE_LONGLONG */
4528 offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);
4529 count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
4530 #endif /* HAVE_LONGLONG */
4532 status = query_lock(fsp,
4539 if (ERROR_WAS_LOCK_DENIED(status)) {
4540 /* Here we need to report who has it locked... */
4541 data_size = POSIX_LOCK_DATA_SIZE;
4543 SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, lock_type);
4544 SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0);
4545 SIVAL(pdata, POSIX_LOCK_PID_OFFSET, lock_pid);
4546 #if defined(HAVE_LONGLONG)
4547 SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF));
4548 SIVAL(pdata, POSIX_LOCK_START_OFFSET + 4, (uint32)((offset >> 32) & 0xFFFFFFFF));
4549 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, (uint32)(count & 0xFFFFFFFF));
4550 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET + 4, (uint32)((count >> 32) & 0xFFFFFFFF));
4551 #else /* HAVE_LONGLONG */
4552 SIVAL(pdata, POSIX_LOCK_START_OFFSET, offset);
4553 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, count);
4554 #endif /* HAVE_LONGLONG */
4556 } else if (NT_STATUS_IS_OK(status)) {
4557 /* For success we just return a copy of what we sent
4558 with the lock type set to POSIX_LOCK_TYPE_UNLOCK. */
4559 data_size = POSIX_LOCK_DATA_SIZE;
4560 memcpy(pdata, lock_data, POSIX_LOCK_DATA_SIZE);
4561 SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_UNLOCK);
4569 return NT_STATUS_INVALID_LEVEL;
4572 *pdata_size = data_size;
4573 return NT_STATUS_OK;
4576 /****************************************************************************
4577 Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
4578 file name or file id).
4579 ****************************************************************************/
4581 static void call_trans2qfilepathinfo(connection_struct *conn,
4582 struct smb_request *req,
4583 unsigned int tran_call,
4584 char **pparams, int total_params,
4585 char **ppdata, int total_data,
4586 unsigned int max_data_bytes)
4588 char *params = *pparams;
4589 char *pdata = *ppdata;
4591 unsigned int data_size = 0;
4592 unsigned int param_size = 2;
4594 struct smb_filename *smb_fname = NULL;
4595 bool delete_pending = False;
4596 struct timespec write_time_ts;
4597 files_struct *fsp = NULL;
4598 struct file_id fileid;
4599 struct ea_list *ea_list = NULL;
4600 int lock_data_count = 0;
4601 char *lock_data = NULL;
4602 bool ms_dfs_link = false;
4603 NTSTATUS status = NT_STATUS_OK;
4606 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
4610 ZERO_STRUCT(write_time_ts);
4612 if (tran_call == TRANSACT2_QFILEINFO) {
4613 if (total_params < 4) {
4614 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
4619 call_trans2qpipeinfo(conn, req, tran_call,
4620 pparams, total_params,
4626 fsp = file_fsp(req, SVAL(params,0));
4627 info_level = SVAL(params,2);
4629 DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
4631 if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
4632 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
4636 /* Initial check for valid fsp ptr. */
4637 if (!check_fsp_open(conn, req, fsp)) {
4641 fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
4643 reply_nterror(req, NT_STATUS_NO_MEMORY);
4647 status = create_synthetic_smb_fname_split(talloc_tos(), fname,
4649 if (!NT_STATUS_IS_OK(status)) {
4650 reply_nterror(req, status);
4654 if(fsp->fake_file_handle) {
4656 * This is actually for the QUOTA_FAKE_FILE --metze
4659 /* We know this name is ok, it's already passed the checks. */
4661 } else if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
4663 * This is actually a QFILEINFO on a directory
4664 * handle (returned from an NT SMB). NT5.0 seems
4665 * to do this call. JRA.
4668 if (INFO_LEVEL_IS_UNIX(info_level)) {
4669 /* Always do lstat for UNIX calls. */
4670 if (SMB_VFS_LSTAT(conn, smb_fname)) {
4671 DEBUG(3,("call_trans2qfilepathinfo: "
4672 "SMB_VFS_LSTAT of %s failed "
4674 smb_fname_str_dbg(smb_fname),
4677 map_nt_error_from_unix(errno));
4680 } else if (SMB_VFS_STAT(conn, smb_fname)) {
4681 DEBUG(3,("call_trans2qfilepathinfo: "
4682 "SMB_VFS_STAT of %s failed (%s)\n",
4683 smb_fname_str_dbg(smb_fname),
4686 map_nt_error_from_unix(errno));
4690 fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
4691 get_file_infos(fileid, &delete_pending, &write_time_ts);
4694 * Original code - this is an open file.
4696 if (!check_fsp(conn, req, fsp)) {
4700 if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
4701 DEBUG(3, ("fstat of fnum %d failed (%s)\n",
4702 fsp->fnum, strerror(errno)));
4704 map_nt_error_from_unix(errno));
4707 fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
4708 get_file_infos(fileid, &delete_pending, &write_time_ts);
4713 if (total_params < 7) {
4714 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
4718 info_level = SVAL(params,0);
4720 DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
4722 if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
4723 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
4727 srvstr_get_path(req, params, req->flags2, &fname, ¶ms[6],
4729 STR_TERMINATE, &status);
4730 if (!NT_STATUS_IS_OK(status)) {
4731 reply_nterror(req, status);
4735 status = filename_convert(req,
4737 req->flags2 & FLAGS2_DFS_PATHNAMES,
4741 if (!NT_STATUS_IS_OK(status)) {
4742 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
4743 reply_botherror(req,
4744 NT_STATUS_PATH_NOT_COVERED,
4745 ERRSRV, ERRbadpath);
4748 reply_nterror(req, status);
4752 /* If this is a stream, check if there is a delete_pending. */
4753 if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
4754 && is_ntfs_stream_smb_fname(smb_fname)) {
4755 struct smb_filename *smb_fname_base = NULL;
4757 /* Create an smb_filename with stream_name == NULL. */
4759 create_synthetic_smb_fname(talloc_tos(),
4760 smb_fname->base_name,
4763 if (!NT_STATUS_IS_OK(status)) {
4764 reply_nterror(req, status);
4768 if (INFO_LEVEL_IS_UNIX(info_level)) {
4769 /* Always do lstat for UNIX calls. */
4770 if (SMB_VFS_LSTAT(conn, smb_fname_base) != 0) {
4771 DEBUG(3,("call_trans2qfilepathinfo: "
4772 "SMB_VFS_LSTAT of %s failed "
4774 smb_fname_str_dbg(smb_fname_base),
4776 TALLOC_FREE(smb_fname_base);
4778 map_nt_error_from_unix(errno));
4782 if (SMB_VFS_STAT(conn, smb_fname_base) != 0) {
4783 DEBUG(3,("call_trans2qfilepathinfo: "
4784 "fileinfo of %s failed "
4786 smb_fname_str_dbg(smb_fname_base),
4788 TALLOC_FREE(smb_fname_base);
4790 map_nt_error_from_unix(errno));
4795 fileid = vfs_file_id_from_sbuf(conn,
4796 &smb_fname_base->st);
4797 TALLOC_FREE(smb_fname_base);
4798 get_file_infos(fileid, &delete_pending, NULL);
4799 if (delete_pending) {
4800 reply_nterror(req, NT_STATUS_DELETE_PENDING);
4805 if (INFO_LEVEL_IS_UNIX(info_level)) {
4806 /* Always do lstat for UNIX calls. */
4807 if (SMB_VFS_LSTAT(conn, smb_fname)) {
4808 DEBUG(3,("call_trans2qfilepathinfo: "
4809 "SMB_VFS_LSTAT of %s failed (%s)\n",
4810 smb_fname_str_dbg(smb_fname),
4813 map_nt_error_from_unix(errno));
4817 } else if (!VALID_STAT(smb_fname->st) &&
4818 SMB_VFS_STAT(conn, smb_fname) &&
4819 (info_level != SMB_INFO_IS_NAME_VALID)) {
4820 ms_dfs_link = check_msdfs_link(conn, fname,
4824 DEBUG(3,("call_trans2qfilepathinfo: "
4825 "SMB_VFS_STAT of %s failed (%s)\n",
4826 smb_fname_str_dbg(smb_fname),
4829 map_nt_error_from_unix(errno));
4834 fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
4835 get_file_infos(fileid, &delete_pending, &write_time_ts);
4836 if (delete_pending) {
4837 reply_nterror(req, NT_STATUS_DELETE_PENDING);
4842 DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d total_data=%d\n",
4843 fname,fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
4845 /* Pull out any data sent here before we realloc. */
4846 switch (info_level) {
4847 case SMB_INFO_QUERY_EAS_FROM_LIST:
4849 /* Pull any EA list from the data portion. */
4852 if (total_data < 4) {
4854 req, NT_STATUS_INVALID_PARAMETER);
4857 ea_size = IVAL(pdata,0);
4859 if (total_data > 0 && ea_size != total_data) {
4860 DEBUG(4,("call_trans2qfilepathinfo: Rejecting EA request with incorrect \
4861 total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
4863 req, NT_STATUS_INVALID_PARAMETER);
4867 if (!lp_ea_support(SNUM(conn))) {
4868 reply_doserror(req, ERRDOS,
4869 ERReasnotsupported);
4873 /* Pull out the list of names. */
4874 ea_list = read_ea_name_list(req, pdata + 4, ea_size - 4);
4877 req, NT_STATUS_INVALID_PARAMETER);
4883 case SMB_QUERY_POSIX_LOCK:
4885 if (fsp == NULL || fsp->fh->fd == -1) {
4886 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
4890 if (total_data != POSIX_LOCK_DATA_SIZE) {
4892 req, NT_STATUS_INVALID_PARAMETER);
4896 /* Copy the lock range data. */
4897 lock_data = (char *)TALLOC_MEMDUP(
4898 req, pdata, total_data);
4900 reply_nterror(req, NT_STATUS_NO_MEMORY);
4903 lock_data_count = total_data;
4909 *pparams = (char *)SMB_REALLOC(*pparams,2);
4910 if (*pparams == NULL) {
4911 reply_nterror(req, NT_STATUS_NO_MEMORY);
4918 * draft-leach-cifs-v1-spec-02.txt
4919 * 4.2.14 TRANS2_QUERY_PATH_INFORMATION: Get File Attributes given Path
4922 * The requested information is placed in the Data portion of the
4923 * transaction response. For the information levels greater than 0x100,
4924 * the transaction response has 1 parameter word which should be
4925 * ignored by the client.
4927 * However Windows only follows this rule for the IS_NAME_VALID call.
4929 switch (info_level) {
4930 case SMB_INFO_IS_NAME_VALID:
4935 status = smbd_do_qfilepathinfo(conn, req, info_level,
4937 delete_pending, write_time_ts,
4938 ms_dfs_link, ea_list,
4939 lock_data_count, lock_data,
4940 req->flags2, max_data_bytes,
4941 ppdata, &data_size);
4942 if (!NT_STATUS_IS_OK(status)) {
4943 reply_nterror(req, status);
4947 send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,
4953 /****************************************************************************
4954 Set a hard link (called by UNIX extensions and by NT rename with HARD link
4956 ****************************************************************************/
4958 NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
4959 connection_struct *conn,
4960 const struct smb_filename *smb_fname_old,
4961 const struct smb_filename *smb_fname_new)
4963 char *oldname = NULL;
4964 char *newname = NULL;
4965 NTSTATUS status = NT_STATUS_OK;
4967 /* source must already exist. */
4968 if (!VALID_STAT(smb_fname_old->st)) {
4969 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4972 /* Disallow if newname already exists. */
4973 if (VALID_STAT(smb_fname_new->st)) {
4974 return NT_STATUS_OBJECT_NAME_COLLISION;
4977 /* No links from a directory. */
4978 if (S_ISDIR(smb_fname_old->st.st_ex_mode)) {
4979 return NT_STATUS_FILE_IS_A_DIRECTORY;
4982 status = get_full_smb_filename(ctx, smb_fname_new, &newname);
4983 if (!NT_STATUS_IS_OK(status)) {
4986 status = get_full_smb_filename(ctx, smb_fname_old, &oldname);
4987 if (!NT_STATUS_IS_OK(status)) {
4991 DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n", newname, oldname ));
4993 if (SMB_VFS_LINK(conn,oldname,newname) != 0) {
4994 status = map_nt_error_from_unix(errno);
4995 DEBUG(3,("hardlink_internals: Error %s hard link %s -> %s\n",
4996 nt_errstr(status), newname, oldname));
4999 TALLOC_FREE(newname);
5000 TALLOC_FREE(oldname);
5004 /****************************************************************************
5005 Deal with setting the time from any of the setfilepathinfo functions.
5006 ****************************************************************************/
5008 NTSTATUS smb_set_file_time(connection_struct *conn,
5010 const struct smb_filename *smb_fname,
5011 struct smb_file_time *ft,
5012 bool setting_write_time)
5014 struct smb_filename *smb_fname_base = NULL;
5016 FILE_NOTIFY_CHANGE_LAST_ACCESS
5017 |FILE_NOTIFY_CHANGE_LAST_WRITE;
5020 if (!VALID_STAT(smb_fname->st)) {
5021 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5024 /* get some defaults (no modifications) if any info is zero or -1. */
5025 if (null_timespec(ft->atime)) {
5026 ft->atime= smb_fname->st.st_ex_atime;
5027 action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
5030 if (null_timespec(ft->mtime)) {
5031 ft->mtime = smb_fname->st.st_ex_mtime;
5032 action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
5035 if (!setting_write_time) {
5036 /* ft->mtime comes from change time, not write time. */
5037 action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
5040 DEBUG(5,("smb_set_filetime: actime: %s\n ",
5041 time_to_asc(convert_timespec_to_time_t(ft->atime))));
5042 DEBUG(5,("smb_set_filetime: modtime: %s\n ",
5043 time_to_asc(convert_timespec_to_time_t(ft->mtime))));
5044 if (!null_timespec(ft->create_time)) {
5045 DEBUG(5,("smb_set_file_time: createtime: %s\n ",
5046 time_to_asc(convert_timespec_to_time_t(ft->create_time))));
5050 * Try and set the times of this file if
5051 * they are different from the current values.
5055 struct timespec mts = smb_fname->st.st_ex_mtime;
5056 struct timespec ats = smb_fname->st.st_ex_atime;
5057 if ((timespec_compare(&ft->atime, &ats) == 0) &&
5058 (timespec_compare(&ft->mtime, &mts) == 0)) {
5059 return NT_STATUS_OK;
5063 if (setting_write_time) {
5065 * This was a Windows setfileinfo on an open file.
5066 * NT does this a lot. We also need to
5067 * set the time here, as it can be read by
5068 * FindFirst/FindNext and with the patch for bug #2045
5069 * in smbd/fileio.c it ensures that this timestamp is
5070 * kept sticky even after a write. We save the request
5071 * away and will set it on file close and after a write. JRA.
5074 DEBUG(10,("smb_set_file_time: setting pending modtime to %s\n",
5075 time_to_asc(convert_timespec_to_time_t(ft->mtime))));
5078 if (fsp->base_fsp) {
5079 set_sticky_write_time_fsp(fsp->base_fsp,
5082 set_sticky_write_time_fsp(fsp, ft->mtime);
5085 set_sticky_write_time_path(
5086 vfs_file_id_from_sbuf(conn, &smb_fname->st),
5091 DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
5093 /* Always call ntimes on the base, even if a stream was passed in. */
5094 status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
5095 NULL, &smb_fname->st,
5097 if (!NT_STATUS_IS_OK(status)) {
5101 if(file_ntimes(conn, smb_fname_base, ft)!=0) {
5102 TALLOC_FREE(smb_fname_base);
5103 return map_nt_error_from_unix(errno);
5105 TALLOC_FREE(smb_fname_base);
5107 notify_fname(conn, NOTIFY_ACTION_MODIFIED, action,
5108 smb_fname->base_name);
5109 return NT_STATUS_OK;
5112 /****************************************************************************
5113 Deal with setting the dosmode from any of the setfilepathinfo functions.
5114 ****************************************************************************/
5116 static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
5117 const struct smb_filename *smb_fname,
5120 struct smb_filename *smb_fname_base = NULL;
5123 if (!VALID_STAT(smb_fname->st)) {
5124 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5127 /* Always operate on the base_name, even if a stream was passed in. */
5128 status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
5129 NULL, &smb_fname->st,
5131 if (!NT_STATUS_IS_OK(status)) {
5136 if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
5143 DEBUG(6,("smb_set_file_dosmode: dosmode: 0x%x\n", (unsigned int)dosmode));
5145 /* check the mode isn't different, before changing it */
5146 if ((dosmode != 0) && (dosmode != dos_mode(conn, smb_fname_base))) {
5147 DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode "
5148 "0x%x\n", smb_fname_str_dbg(smb_fname_base),
5149 (unsigned int)dosmode));
5151 if(file_set_dosmode(conn, smb_fname_base, dosmode, NULL,
5153 DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of "
5155 smb_fname_str_dbg(smb_fname_base),
5157 status = map_nt_error_from_unix(errno);
5161 status = NT_STATUS_OK;
5163 TALLOC_FREE(smb_fname_base);
5167 /****************************************************************************
5168 Deal with setting the size from any of the setfilepathinfo functions.
5169 ****************************************************************************/
5171 static NTSTATUS smb_set_file_size(connection_struct *conn,
5172 struct smb_request *req,
5174 const struct smb_filename *smb_fname,
5175 const SMB_STRUCT_STAT *psbuf,
5178 NTSTATUS status = NT_STATUS_OK;
5179 struct smb_filename *smb_fname_tmp = NULL;
5180 files_struct *new_fsp = NULL;
5182 if (!VALID_STAT(*psbuf)) {
5183 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5186 DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size));
5188 if (size == get_file_size_stat(psbuf)) {
5189 return NT_STATUS_OK;
5192 DEBUG(10,("smb_set_file_size: file %s : setting new size to %.0f\n",
5193 smb_fname_str_dbg(smb_fname), (double)size));
5195 if (fsp && fsp->fh->fd != -1) {
5196 /* Handle based call. */
5197 if (vfs_set_filelen(fsp, size) == -1) {
5198 return map_nt_error_from_unix(errno);
5200 trigger_write_time_update_immediate(fsp);
5201 return NT_STATUS_OK;
5204 status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
5205 if (!NT_STATUS_IS_OK(status)) {
5209 smb_fname_tmp->st = *psbuf;
5211 status = SMB_VFS_CREATE_FILE(
5214 0, /* root_dir_fid */
5215 smb_fname_tmp, /* fname */
5216 FILE_WRITE_ATTRIBUTES, /* access_mask */
5217 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
5219 FILE_OPEN, /* create_disposition*/
5220 0, /* create_options */
5221 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
5222 FORCE_OPLOCK_BREAK_TO_NONE, /* oplock_request */
5223 0, /* allocation_size */
5226 &new_fsp, /* result */
5229 TALLOC_FREE(smb_fname_tmp);
5231 if (!NT_STATUS_IS_OK(status)) {
5232 /* NB. We check for open_was_deferred in the caller. */
5236 if (vfs_set_filelen(new_fsp, size) == -1) {
5237 status = map_nt_error_from_unix(errno);
5238 close_file(req, new_fsp,NORMAL_CLOSE);
5242 trigger_write_time_update_immediate(new_fsp);
5243 close_file(req, new_fsp,NORMAL_CLOSE);
5244 return NT_STATUS_OK;
5247 /****************************************************************************
5248 Deal with SMB_INFO_SET_EA.
5249 ****************************************************************************/
5251 static NTSTATUS smb_info_set_ea(connection_struct *conn,
5255 const struct smb_filename *smb_fname)
5257 struct ea_list *ea_list = NULL;
5258 TALLOC_CTX *ctx = NULL;
5259 NTSTATUS status = NT_STATUS_OK;
5261 if (total_data < 10) {
5263 /* OS/2 workplace shell seems to send SET_EA requests of "null"
5264 length. They seem to have no effect. Bug #3212. JRA */
5266 if ((total_data == 4) && (IVAL(pdata,0) == 4)) {
5267 /* We're done. We only get EA info in this call. */
5268 return NT_STATUS_OK;
5271 return NT_STATUS_INVALID_PARAMETER;
5274 if (IVAL(pdata,0) > total_data) {
5275 DEBUG(10,("smb_info_set_ea: bad total data size (%u) > %u\n",
5276 IVAL(pdata,0), (unsigned int)total_data));
5277 return NT_STATUS_INVALID_PARAMETER;
5281 ea_list = read_ea_list(ctx, pdata + 4, total_data - 4);
5283 return NT_STATUS_INVALID_PARAMETER;
5285 status = set_ea(conn, fsp, smb_fname, ea_list);
5290 /****************************************************************************
5291 Deal with SMB_SET_FILE_DISPOSITION_INFO.
5292 ****************************************************************************/
5294 static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
5298 const struct smb_filename *smb_fname)
5300 NTSTATUS status = NT_STATUS_OK;
5301 bool delete_on_close;
5304 if (total_data < 1) {
5305 return NT_STATUS_INVALID_PARAMETER;
5309 return NT_STATUS_INVALID_HANDLE;
5312 delete_on_close = (CVAL(pdata,0) ? True : False);
5313 dosmode = dos_mode(conn, smb_fname);
5315 DEBUG(10,("smb_set_file_disposition_info: file %s, dosmode = %u, "
5316 "delete_on_close = %u\n",
5317 smb_fname_str_dbg(smb_fname),
5318 (unsigned int)dosmode,
5319 (unsigned int)delete_on_close ));
5321 status = can_set_delete_on_close(fsp, delete_on_close, dosmode);
5323 if (!NT_STATUS_IS_OK(status)) {
5327 /* The set is across all open files on this dev/inode pair. */
5328 if (!set_delete_on_close(fsp, delete_on_close,
5329 &conn->server_info->utok)) {
5330 return NT_STATUS_ACCESS_DENIED;
5332 return NT_STATUS_OK;
5335 /****************************************************************************
5336 Deal with SMB_FILE_POSITION_INFORMATION.
5337 ****************************************************************************/
5339 static NTSTATUS smb_file_position_information(connection_struct *conn,
5344 uint64_t position_information;
5346 if (total_data < 8) {
5347 return NT_STATUS_INVALID_PARAMETER;
5351 /* Ignore on pathname based set. */
5352 return NT_STATUS_OK;
5355 position_information = (uint64_t)IVAL(pdata,0);
5356 #ifdef LARGE_SMB_OFF_T
5357 position_information |= (((uint64_t)IVAL(pdata,4)) << 32);
5358 #else /* LARGE_SMB_OFF_T */
5359 if (IVAL(pdata,4) != 0) {
5360 /* more than 32 bits? */
5361 return NT_STATUS_INVALID_PARAMETER;
5363 #endif /* LARGE_SMB_OFF_T */
5365 DEBUG(10,("smb_file_position_information: Set file position information for file %s to %.0f\n",
5366 fsp->fsp_name, (double)position_information ));
5367 fsp->fh->position_information = position_information;
5368 return NT_STATUS_OK;
5371 /****************************************************************************
5372 Deal with SMB_FILE_MODE_INFORMATION.
5373 ****************************************************************************/
5375 static NTSTATUS smb_file_mode_information(connection_struct *conn,
5381 if (total_data < 4) {
5382 return NT_STATUS_INVALID_PARAMETER;
5384 mode = IVAL(pdata,0);
5385 if (mode != 0 && mode != 2 && mode != 4 && mode != 6) {
5386 return NT_STATUS_INVALID_PARAMETER;
5388 return NT_STATUS_OK;
5391 /****************************************************************************
5392 Deal with SMB_SET_FILE_UNIX_LINK (create a UNIX symlink).
5393 ****************************************************************************/
5395 static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
5396 struct smb_request *req,
5401 char *link_target = NULL;
5402 const char *newname = fname;
5403 NTSTATUS status = NT_STATUS_OK;
5404 TALLOC_CTX *ctx = talloc_tos();
5406 /* Set a symbolic link. */
5407 /* Don't allow this if follow links is false. */
5409 if (total_data == 0) {
5410 return NT_STATUS_INVALID_PARAMETER;
5413 if (!lp_symlinks(SNUM(conn))) {
5414 return NT_STATUS_ACCESS_DENIED;
5417 srvstr_pull_talloc(ctx, pdata, req->flags2, &link_target, pdata,
5418 total_data, STR_TERMINATE);
5421 return NT_STATUS_INVALID_PARAMETER;
5424 /* !widelinks forces the target path to be within the share. */
5425 /* This means we can interpret the target as a pathname. */
5426 if (!lp_widelinks(SNUM(conn))) {
5427 char *rel_name = NULL;
5428 char *last_dirp = NULL;
5430 if (*link_target == '/') {
5431 /* No absolute paths allowed. */
5432 return NT_STATUS_ACCESS_DENIED;
5434 rel_name = talloc_strdup(ctx,newname);
5436 return NT_STATUS_NO_MEMORY;
5438 last_dirp = strrchr_m(rel_name, '/');
5440 last_dirp[1] = '\0';
5442 rel_name = talloc_strdup(ctx,"./");
5444 return NT_STATUS_NO_MEMORY;
5447 rel_name = talloc_asprintf_append(rel_name,
5451 return NT_STATUS_NO_MEMORY;
5454 status = check_name(conn, rel_name);
5455 if (!NT_STATUS_IS_OK(status)) {
5460 DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
5461 newname, link_target ));
5463 if (SMB_VFS_SYMLINK(conn,link_target,newname) != 0) {
5464 return map_nt_error_from_unix(errno);
5467 return NT_STATUS_OK;
5470 /****************************************************************************
5471 Deal with SMB_SET_FILE_UNIX_HLINK (create a UNIX hard link).
5472 ****************************************************************************/
5474 static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
5475 struct smb_request *req,
5476 const char *pdata, int total_data,
5477 const struct smb_filename *smb_fname_new)
5479 char *oldname = NULL;
5480 struct smb_filename *smb_fname_old = NULL;
5481 TALLOC_CTX *ctx = talloc_tos();
5482 NTSTATUS status = NT_STATUS_OK;
5484 /* Set a hard link. */
5485 if (total_data == 0) {
5486 return NT_STATUS_INVALID_PARAMETER;
5489 srvstr_get_path(ctx, pdata, req->flags2, &oldname, pdata,
5490 total_data, STR_TERMINATE, &status);
5491 if (!NT_STATUS_IS_OK(status)) {
5495 DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
5496 smb_fname_str_dbg(smb_fname_new), oldname));
5498 status = filename_convert(ctx,
5500 req->flags2 & FLAGS2_DFS_PATHNAMES,
5504 if (!NT_STATUS_IS_OK(status)) {
5508 return hardlink_internals(ctx, conn, smb_fname_old, smb_fname_new);
5511 /****************************************************************************
5512 Deal with SMB_FILE_RENAME_INFORMATION.
5513 ****************************************************************************/
5515 static NTSTATUS smb_file_rename_information(connection_struct *conn,
5516 struct smb_request *req,
5525 char *newname = NULL;
5526 char *base_name = NULL;
5527 struct smb_filename *smb_fname = NULL;
5528 bool dest_has_wcard = False;
5529 NTSTATUS status = NT_STATUS_OK;
5531 TALLOC_CTX *ctx = talloc_tos();
5533 if (total_data < 13) {
5534 return NT_STATUS_INVALID_PARAMETER;
5537 overwrite = (CVAL(pdata,0) ? True : False);
5538 root_fid = IVAL(pdata,4);
5539 len = IVAL(pdata,8);
5541 if (len > (total_data - 12) || (len == 0) || (root_fid != 0)) {
5542 return NT_STATUS_INVALID_PARAMETER;
5545 srvstr_get_path_wcard(ctx, pdata, req->flags2, &newname, &pdata[12],
5548 if (!NT_STATUS_IS_OK(status)) {
5552 DEBUG(10,("smb_file_rename_information: got name |%s|\n",
5555 status = resolve_dfspath_wcard(ctx, conn,
5556 req->flags2 & FLAGS2_DFS_PATHNAMES,
5560 if (!NT_STATUS_IS_OK(status)) {
5564 /* Check the new name has no '/' characters. */
5565 if (strchr_m(newname, '/')) {
5566 return NT_STATUS_NOT_SUPPORTED;
5569 if (fsp && fsp->base_fsp) {
5570 /* newname must be a stream name. */
5571 if (newname[0] != ':') {
5572 return NT_STATUS_NOT_SUPPORTED;
5575 /* Create an smb_fname to call rename_internals_fsp() with. */
5576 status = create_synthetic_smb_fname(talloc_tos(),
5577 fsp->base_fsp->fsp_name,
5578 newname, NULL, &smb_fname);
5579 if (!NT_STATUS_IS_OK(status)) {
5584 * Set the original last component, since
5585 * rename_internals_fsp() requires it.
5587 smb_fname->original_lcomp = talloc_strdup(smb_fname, newname);
5588 if (smb_fname->original_lcomp == NULL) {
5589 status = NT_STATUS_NO_MEMORY;
5593 /* Create a char * to call rename_internals() with. */
5594 base_name = talloc_asprintf(ctx, "%s%s",
5595 fsp->base_fsp->fsp_name,
5598 status = NT_STATUS_NO_MEMORY;
5602 /* newname must *not* be a stream name. */
5603 if (newname[0] == ':') {
5604 return NT_STATUS_NOT_SUPPORTED;
5607 /* Create the base directory. */
5608 base_name = talloc_strdup(ctx, fname);
5610 return NT_STATUS_NO_MEMORY;
5612 p = strrchr_m(base_name, '/');
5616 base_name = talloc_strdup(ctx, "./");
5618 return NT_STATUS_NO_MEMORY;
5621 /* Append the new name. */
5622 base_name = talloc_asprintf_append(base_name,
5626 return NT_STATUS_NO_MEMORY;
5629 status = unix_convert(ctx, conn, base_name, &smb_fname,
5632 /* If an error we expect this to be
5633 * NT_STATUS_OBJECT_PATH_NOT_FOUND */
5635 if (!NT_STATUS_IS_OK(status)) {
5636 if(!NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
5640 /* Create an smb_fname to call rename_internals_fsp() */
5641 status = create_synthetic_smb_fname(talloc_tos(),
5644 if (!NT_STATUS_IS_OK(status)) {
5652 DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
5653 fsp->fnum, fsp->fsp_name, base_name ));
5654 status = rename_internals_fsp(conn, fsp, smb_fname, 0,
5657 DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
5658 fname, base_name ));
5659 status = rename_internals(ctx, conn, req, fname, base_name, 0,
5660 overwrite, False, dest_has_wcard,
5661 FILE_WRITE_ATTRIBUTES);
5664 TALLOC_FREE(smb_fname);
5668 /****************************************************************************
5669 Deal with SMB_SET_POSIX_ACL.
5670 ****************************************************************************/
5672 #if defined(HAVE_POSIX_ACLS)
5673 static NTSTATUS smb_set_posix_acl(connection_struct *conn,
5678 SMB_STRUCT_STAT *psbuf)
5680 uint16 posix_acl_version;
5681 uint16 num_file_acls;
5682 uint16 num_def_acls;
5683 bool valid_file_acls = True;
5684 bool valid_def_acls = True;
5686 if (total_data < SMB_POSIX_ACL_HEADER_SIZE) {
5687 return NT_STATUS_INVALID_PARAMETER;
5689 posix_acl_version = SVAL(pdata,0);
5690 num_file_acls = SVAL(pdata,2);
5691 num_def_acls = SVAL(pdata,4);
5693 if (num_file_acls == SMB_POSIX_IGNORE_ACE_ENTRIES) {
5694 valid_file_acls = False;
5698 if (num_def_acls == SMB_POSIX_IGNORE_ACE_ENTRIES) {
5699 valid_def_acls = False;
5703 if (posix_acl_version != SMB_POSIX_ACL_VERSION) {
5704 return NT_STATUS_INVALID_PARAMETER;
5707 if (total_data < SMB_POSIX_ACL_HEADER_SIZE +
5708 (num_file_acls+num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE) {
5709 return NT_STATUS_INVALID_PARAMETER;
5712 DEBUG(10,("smb_set_posix_acl: file %s num_file_acls = %u, num_def_acls = %u\n",
5713 fname ? fname : fsp->fsp_name,
5714 (unsigned int)num_file_acls,
5715 (unsigned int)num_def_acls));
5717 if (valid_file_acls && !set_unix_posix_acl(conn, fsp, fname, num_file_acls,
5718 pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
5719 return map_nt_error_from_unix(errno);
5722 if (valid_def_acls && !set_unix_posix_default_acl(conn, fname, psbuf, num_def_acls,
5723 pdata + SMB_POSIX_ACL_HEADER_SIZE +
5724 (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE))) {
5725 return map_nt_error_from_unix(errno);
5727 return NT_STATUS_OK;
5731 /****************************************************************************
5732 Deal with SMB_SET_POSIX_LOCK.
5733 ****************************************************************************/
5735 static NTSTATUS smb_set_posix_lock(connection_struct *conn,
5736 struct smb_request *req,
5744 bool blocking_lock = False;
5745 enum brl_type lock_type;
5747 NTSTATUS status = NT_STATUS_OK;
5749 if (fsp == NULL || fsp->fh->fd == -1) {
5750 return NT_STATUS_INVALID_HANDLE;
5753 if (total_data != POSIX_LOCK_DATA_SIZE) {
5754 return NT_STATUS_INVALID_PARAMETER;
5757 switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
5758 case POSIX_LOCK_TYPE_READ:
5759 lock_type = READ_LOCK;
5761 case POSIX_LOCK_TYPE_WRITE:
5762 /* Return the right POSIX-mappable error code for files opened read-only. */
5763 if (!fsp->can_write) {
5764 return NT_STATUS_INVALID_HANDLE;
5766 lock_type = WRITE_LOCK;
5768 case POSIX_LOCK_TYPE_UNLOCK:
5769 lock_type = UNLOCK_LOCK;
5772 return NT_STATUS_INVALID_PARAMETER;
5775 if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_NOWAIT) {
5776 blocking_lock = False;
5777 } else if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_WAIT) {
5778 blocking_lock = True;
5780 return NT_STATUS_INVALID_PARAMETER;
5783 if (!lp_blocking_locks(SNUM(conn))) {
5784 blocking_lock = False;
5787 lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
5788 #if defined(HAVE_LONGLONG)
5789 offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
5790 ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
5791 count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
5792 ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
5793 #else /* HAVE_LONGLONG */
5794 offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);
5795 count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
5796 #endif /* HAVE_LONGLONG */
5798 DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
5799 "lock_pid = %u, count = %.0f, offset = %.0f\n",
5801 (unsigned int)lock_type,
5802 (unsigned int)lock_pid,
5806 if (lock_type == UNLOCK_LOCK) {
5807 status = do_unlock(smbd_messaging_context(),
5814 uint32 block_smbpid;
5816 struct byte_range_lock *br_lck = do_lock(smbd_messaging_context(),
5828 if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
5830 * A blocking lock was requested. Package up
5831 * this smb into a queued request and push it
5832 * onto the blocking lock queue.
5834 if(push_blocking_lock_request(br_lck,
5837 -1, /* infinite timeout. */
5845 TALLOC_FREE(br_lck);
5849 TALLOC_FREE(br_lck);
5855 /****************************************************************************
5856 Deal with SMB_INFO_STANDARD.
5857 ****************************************************************************/
5859 static NTSTATUS smb_set_info_standard(connection_struct *conn,
5863 const struct smb_filename *smb_fname)
5865 struct smb_file_time ft;
5868 if (total_data < 12) {
5869 return NT_STATUS_INVALID_PARAMETER;
5873 ft.create_time = interpret_long_date(pdata);
5876 ft.atime = interpret_long_date(pdata + 8);
5879 ft.mtime = interpret_long_date(pdata + 16);
5881 DEBUG(10,("smb_set_info_standard: file %s\n",
5882 smb_fname_str_dbg(smb_fname)));
5884 return smb_set_file_time(conn, fsp, smb_fname, &ft, true);
5887 /****************************************************************************
5888 Deal with SMB_SET_FILE_BASIC_INFO.
5889 ****************************************************************************/
5891 static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
5895 const struct smb_filename *smb_fname)
5897 /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
5898 struct timespec write_time;
5899 struct timespec changed_time;
5900 struct smb_file_time ft;
5902 NTSTATUS status = NT_STATUS_OK;
5903 bool setting_write_time = true;
5907 if (total_data < 36) {
5908 return NT_STATUS_INVALID_PARAMETER;
5911 /* Set the attributes */
5912 dosmode = IVAL(pdata,32);
5913 status = smb_set_file_dosmode(conn, smb_fname, dosmode);
5914 if (!NT_STATUS_IS_OK(status)) {
5919 ft.atime = interpret_long_date(pdata+8);
5921 write_time = interpret_long_date(pdata+16);
5922 changed_time = interpret_long_date(pdata+24);
5925 ft.mtime = timespec_min(&write_time, &changed_time);
5928 ft.create_time = interpret_long_date(pdata);
5930 if ((timespec_compare(&write_time, &ft.mtime) == 1) &&
5931 !null_timespec(write_time)) {
5932 ft.mtime = write_time;
5935 /* Prefer a defined time to an undefined one. */
5936 if (null_timespec(ft.mtime)) {
5937 if (null_timespec(write_time)) {
5938 ft.mtime = changed_time;
5939 setting_write_time = false;
5941 ft.mtime = write_time;
5945 DEBUG(10, ("smb_set_file_basic_info: file %s\n",
5946 smb_fname_str_dbg(smb_fname)));
5948 return smb_set_file_time(conn, fsp, smb_fname, &ft,
5949 setting_write_time);
5952 /****************************************************************************
5953 Deal with SMB_SET_FILE_ALLOCATION_INFO.
5954 ****************************************************************************/
5956 static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
5957 struct smb_request *req,
5961 struct smb_filename *smb_fname)
5963 uint64_t allocation_size = 0;
5964 NTSTATUS status = NT_STATUS_OK;
5965 files_struct *new_fsp = NULL;
5967 if (!VALID_STAT(smb_fname->st)) {
5968 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5971 if (total_data < 8) {
5972 return NT_STATUS_INVALID_PARAMETER;
5975 allocation_size = (uint64_t)IVAL(pdata,0);
5976 #ifdef LARGE_SMB_OFF_T
5977 allocation_size |= (((uint64_t)IVAL(pdata,4)) << 32);
5978 #else /* LARGE_SMB_OFF_T */
5979 if (IVAL(pdata,4) != 0) {
5980 /* more than 32 bits? */
5981 return NT_STATUS_INVALID_PARAMETER;
5983 #endif /* LARGE_SMB_OFF_T */
5985 DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for "
5986 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
5987 (double)allocation_size));
5989 if (allocation_size) {
5990 allocation_size = smb_roundup(conn, allocation_size);
5993 DEBUG(10,("smb_set_file_allocation_info: file %s : setting new "
5994 "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname),
5995 (double)allocation_size));
5997 if (fsp && fsp->fh->fd != -1) {
5998 /* Open file handle. */
5999 /* Only change if needed. */
6000 if (allocation_size != get_file_size_stat(&smb_fname->st)) {
6001 if (vfs_allocate_file_space(fsp, allocation_size) == -1) {
6002 return map_nt_error_from_unix(errno);
6005 /* But always update the time. */
6007 * This is equivalent to a write. Ensure it's seen immediately
6008 * if there are no pending writes.
6010 trigger_write_time_update_immediate(fsp);
6011 return NT_STATUS_OK;
6014 /* Pathname or stat or directory file. */
6015 status = SMB_VFS_CREATE_FILE(
6018 0, /* root_dir_fid */
6019 smb_fname, /* fname */
6020 FILE_WRITE_DATA, /* access_mask */
6021 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
6023 FILE_OPEN, /* create_disposition*/
6024 0, /* create_options */
6025 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
6026 FORCE_OPLOCK_BREAK_TO_NONE, /* oplock_request */
6027 0, /* allocation_size */
6030 &new_fsp, /* result */
6033 if (!NT_STATUS_IS_OK(status)) {
6034 /* NB. We check for open_was_deferred in the caller. */
6038 /* Only change if needed. */
6039 if (allocation_size != get_file_size_stat(&smb_fname->st)) {
6040 if (vfs_allocate_file_space(new_fsp, allocation_size) == -1) {
6041 status = map_nt_error_from_unix(errno);
6042 close_file(req, new_fsp, NORMAL_CLOSE);
6047 /* Changing the allocation size should set the last mod time. */
6049 * This is equivalent to a write. Ensure it's seen immediately
6050 * if there are no pending writes.
6052 trigger_write_time_update_immediate(new_fsp);
6054 close_file(req, new_fsp, NORMAL_CLOSE);
6055 return NT_STATUS_OK;
6058 /****************************************************************************
6059 Deal with SMB_SET_FILE_END_OF_FILE_INFO.
6060 ****************************************************************************/
6062 static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
6063 struct smb_request *req,
6067 const struct smb_filename *smb_fname)
6071 if (total_data < 8) {
6072 return NT_STATUS_INVALID_PARAMETER;
6075 size = IVAL(pdata,0);
6076 #ifdef LARGE_SMB_OFF_T
6077 size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
6078 #else /* LARGE_SMB_OFF_T */
6079 if (IVAL(pdata,4) != 0) {
6080 /* more than 32 bits? */
6081 return NT_STATUS_INVALID_PARAMETER;
6083 #endif /* LARGE_SMB_OFF_T */
6084 DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for "
6085 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
6088 return smb_set_file_size(conn, req,
6095 /****************************************************************************
6096 Allow a UNIX info mknod.
6097 ****************************************************************************/
6099 static NTSTATUS smb_unix_mknod(connection_struct *conn,
6102 const struct smb_filename *smb_fname)
6104 uint32 file_type = IVAL(pdata,56);
6105 #if defined(HAVE_MAKEDEV)
6106 uint32 dev_major = IVAL(pdata,60);
6107 uint32 dev_minor = IVAL(pdata,68);
6109 SMB_DEV_T dev = (SMB_DEV_T)0;
6110 uint32 raw_unixmode = IVAL(pdata,84);
6114 if (total_data < 100) {
6115 return NT_STATUS_INVALID_PARAMETER;
6118 status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
6119 PERM_NEW_FILE, &unixmode);
6120 if (!NT_STATUS_IS_OK(status)) {
6124 #if defined(HAVE_MAKEDEV)
6125 dev = makedev(dev_major, dev_minor);
6128 switch (file_type) {
6129 #if defined(S_IFIFO)
6130 case UNIX_TYPE_FIFO:
6131 unixmode |= S_IFIFO;
6134 #if defined(S_IFSOCK)
6135 case UNIX_TYPE_SOCKET:
6136 unixmode |= S_IFSOCK;
6139 #if defined(S_IFCHR)
6140 case UNIX_TYPE_CHARDEV:
6141 unixmode |= S_IFCHR;
6144 #if defined(S_IFBLK)
6145 case UNIX_TYPE_BLKDEV:
6146 unixmode |= S_IFBLK;
6150 return NT_STATUS_INVALID_PARAMETER;
6153 DEBUG(10,("smb_unix_mknod: SMB_SET_FILE_UNIX_BASIC doing mknod dev "
6154 "%.0f mode 0%o for file %s\n", (double)dev,
6155 (unsigned int)unixmode, smb_fname_str_dbg(smb_fname)));
6157 /* Ok - do the mknod. */
6158 if (SMB_VFS_MKNOD(conn, smb_fname->base_name, unixmode, dev) != 0) {
6159 return map_nt_error_from_unix(errno);
6162 /* If any of the other "set" calls fail we
6163 * don't want to end up with a half-constructed mknod.
6166 if (lp_inherit_perms(SNUM(conn))) {
6168 if (!parent_dirname(talloc_tos(), smb_fname->base_name,
6170 return NT_STATUS_NO_MEMORY;
6172 inherit_access_posix_acl(conn, parent, smb_fname->base_name,
6174 TALLOC_FREE(parent);
6177 return NT_STATUS_OK;
6180 /****************************************************************************
6181 Deal with SMB_SET_FILE_UNIX_BASIC.
6182 ****************************************************************************/
6184 static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
6185 struct smb_request *req,
6189 const struct smb_filename *smb_fname)
6191 struct smb_file_time ft;
6192 uint32 raw_unixmode;
6195 uid_t set_owner = (uid_t)SMB_UID_NO_CHANGE;
6196 gid_t set_grp = (uid_t)SMB_GID_NO_CHANGE;
6197 NTSTATUS status = NT_STATUS_OK;
6198 bool delete_on_fail = False;
6199 enum perm_type ptype;
6200 files_struct *all_fsps = NULL;
6201 bool modify_mtime = true;
6203 SMB_STRUCT_STAT sbuf;
6207 if (total_data < 100) {
6208 return NT_STATUS_INVALID_PARAMETER;
6211 if(IVAL(pdata, 0) != SMB_SIZE_NO_CHANGE_LO &&
6212 IVAL(pdata, 4) != SMB_SIZE_NO_CHANGE_HI) {
6213 size=IVAL(pdata,0); /* first 8 Bytes are size */
6214 #ifdef LARGE_SMB_OFF_T
6215 size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
6216 #else /* LARGE_SMB_OFF_T */
6217 if (IVAL(pdata,4) != 0) {
6218 /* more than 32 bits? */
6219 return NT_STATUS_INVALID_PARAMETER;
6221 #endif /* LARGE_SMB_OFF_T */
6224 ft.atime = interpret_long_date(pdata+24); /* access_time */
6225 ft.mtime = interpret_long_date(pdata+32); /* modification_time */
6226 set_owner = (uid_t)IVAL(pdata,40);
6227 set_grp = (gid_t)IVAL(pdata,48);
6228 raw_unixmode = IVAL(pdata,84);
6230 if (VALID_STAT(smb_fname->st)) {
6231 if (S_ISDIR(smb_fname->st.st_ex_mode)) {
6232 ptype = PERM_EXISTING_DIR;
6234 ptype = PERM_EXISTING_FILE;
6237 ptype = PERM_NEW_FILE;
6240 status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
6242 if (!NT_STATUS_IS_OK(status)) {
6246 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC: name = "
6247 "%s size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
6248 smb_fname_str_dbg(smb_fname), (double)size,
6249 (unsigned int)set_owner, (unsigned int)set_grp,
6250 (int)raw_unixmode));
6252 sbuf = smb_fname->st;
6254 if (!VALID_STAT(sbuf)) {
6255 struct smb_filename *smb_fname_tmp = NULL;
6257 * The only valid use of this is to create character and block
6258 * devices, and named pipes. This is deprecated (IMHO) and
6259 * a new info level should be used for mknod. JRA.
6262 status = smb_unix_mknod(conn,
6266 if (!NT_STATUS_IS_OK(status)) {
6270 status = copy_smb_filename(talloc_tos(), smb_fname,
6272 if (!NT_STATUS_IS_OK(status)) {
6276 if (SMB_VFS_STAT(conn, smb_fname_tmp) != 0) {
6277 status = map_nt_error_from_unix(errno);
6278 TALLOC_FREE(smb_fname_tmp);
6279 SMB_VFS_UNLINK(conn, smb_fname);
6283 sbuf = smb_fname_tmp->st;
6284 TALLOC_FREE(smb_fname_tmp);
6286 /* Ensure we don't try and change anything else. */
6287 raw_unixmode = SMB_MODE_NO_CHANGE;
6288 size = get_file_size_stat(&sbuf);
6289 ft.atime = sbuf.st_ex_atime;
6290 ft.mtime = sbuf.st_ex_mtime;
6292 * We continue here as we might want to change the
6295 delete_on_fail = True;
6299 /* Horrible backwards compatibility hack as an old server bug
6300 * allowed a CIFS client bug to remain unnoticed :-(. JRA.
6304 size = get_file_size_stat(&sbuf);
6309 * Deal with the UNIX specific mode set.
6312 if (raw_unixmode != SMB_MODE_NO_CHANGE) {
6313 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
6314 "setting mode 0%o for file %s\n",
6315 (unsigned int)unixmode,
6316 smb_fname_str_dbg(smb_fname)));
6317 if (SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode) != 0) {
6318 return map_nt_error_from_unix(errno);
6323 * Deal with the UNIX specific uid set.
6326 if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) &&
6327 (sbuf.st_ex_uid != set_owner)) {
6330 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
6331 "changing owner %u for path %s\n",
6332 (unsigned int)set_owner,
6333 smb_fname_str_dbg(smb_fname)));
6335 if (S_ISLNK(sbuf.st_ex_mode)) {
6336 ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name,
6337 set_owner, (gid_t)-1);
6339 ret = SMB_VFS_CHOWN(conn, smb_fname->base_name,
6340 set_owner, (gid_t)-1);
6344 status = map_nt_error_from_unix(errno);
6345 if (delete_on_fail) {
6346 SMB_VFS_UNLINK(conn, smb_fname);
6353 * Deal with the UNIX specific gid set.
6356 if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) &&
6357 (sbuf.st_ex_gid != set_grp)) {
6358 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
6359 "changing group %u for file %s\n",
6360 (unsigned int)set_owner,
6361 smb_fname_str_dbg(smb_fname)));
6362 if (SMB_VFS_CHOWN(conn, smb_fname->base_name, (uid_t)-1,
6364 status = map_nt_error_from_unix(errno);
6365 if (delete_on_fail) {
6366 SMB_VFS_UNLINK(conn, smb_fname);
6372 /* Deal with any size changes. */
6374 status = smb_set_file_size(conn, req,
6379 if (!NT_STATUS_IS_OK(status)) {
6383 /* Deal with any time changes. */
6384 if (null_timespec(ft.mtime) && null_timespec(ft.atime)) {
6385 /* No change, don't cancel anything. */
6389 id = vfs_file_id_from_sbuf(conn, &sbuf);
6390 for(all_fsps = file_find_di_first(id); all_fsps;
6391 all_fsps = file_find_di_next(all_fsps)) {
6393 * We're setting the time explicitly for UNIX.
6394 * Cancel any pending changes over all handles.
6396 all_fsps->update_write_time_on_close = false;
6397 TALLOC_FREE(all_fsps->update_write_time_event);
6401 * Override the "setting_write_time"
6402 * parameter here as it almost does what
6403 * we need. Just remember if we modified
6404 * mtime and send the notify ourselves.
6406 if (null_timespec(ft.mtime)) {
6407 modify_mtime = false;
6410 status = smb_set_file_time(conn,
6416 notify_fname(conn, NOTIFY_ACTION_MODIFIED,
6417 FILE_NOTIFY_CHANGE_LAST_WRITE, smb_fname->base_name);
6422 /****************************************************************************
6423 Deal with SMB_SET_FILE_UNIX_INFO2.
6424 ****************************************************************************/
6426 static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
6427 struct smb_request *req,
6431 const struct smb_filename *smb_fname)
6437 if (total_data < 116) {
6438 return NT_STATUS_INVALID_PARAMETER;
6441 /* Start by setting all the fields that are common between UNIX_BASIC
6444 status = smb_set_file_unix_basic(conn, req, pdata, total_data,
6446 if (!NT_STATUS_IS_OK(status)) {
6450 smb_fflags = IVAL(pdata, 108);
6451 smb_fmask = IVAL(pdata, 112);
6453 /* NB: We should only attempt to alter the file flags if the client
6454 * sends a non-zero mask.
6456 if (smb_fmask != 0) {
6457 int stat_fflags = 0;
6459 if (!map_info2_flags_to_sbuf(&smb_fname->st, smb_fflags,
6460 smb_fmask, &stat_fflags)) {
6461 /* Client asked to alter a flag we don't understand. */
6462 return NT_STATUS_INVALID_PARAMETER;
6465 if (fsp && fsp->fh->fd != -1) {
6466 /* XXX: we should be using SMB_VFS_FCHFLAGS here. */
6467 return NT_STATUS_NOT_SUPPORTED;
6469 if (SMB_VFS_CHFLAGS(conn, smb_fname->base_name,
6470 stat_fflags) != 0) {
6471 return map_nt_error_from_unix(errno);
6476 /* XXX: need to add support for changing the create_time here. You
6477 * can do this for paths on Darwin with setattrlist(2). The right way
6478 * to hook this up is probably by extending the VFS utimes interface.
6481 return NT_STATUS_OK;
6484 /****************************************************************************
6485 Create a directory with POSIX semantics.
6486 ****************************************************************************/
6488 static NTSTATUS smb_posix_mkdir(connection_struct *conn,
6489 struct smb_request *req,
6493 SMB_STRUCT_STAT *psbuf,
6494 int *pdata_return_size)
6496 struct smb_filename *smb_fname;
6497 NTSTATUS status = NT_STATUS_OK;
6498 uint32 raw_unixmode = 0;
6499 uint32 mod_unixmode = 0;
6500 mode_t unixmode = (mode_t)0;
6501 files_struct *fsp = NULL;
6502 uint16 info_level_return = 0;
6504 char *pdata = *ppdata;
6506 if (total_data < 18) {
6507 return NT_STATUS_INVALID_PARAMETER;
6510 raw_unixmode = IVAL(pdata,8);
6511 /* Next 4 bytes are not yet defined. */
6513 status = unix_perms_from_wire(conn, psbuf, raw_unixmode, PERM_NEW_DIR, &unixmode);
6514 if (!NT_STATUS_IS_OK(status)) {
6518 mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
6520 DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
6521 fname, (unsigned int)unixmode ));
6523 status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
6525 if (!NT_STATUS_IS_OK(status)) {
6529 status = SMB_VFS_CREATE_FILE(
6532 0, /* root_dir_fid */
6533 smb_fname, /* fname */
6534 FILE_READ_ATTRIBUTES, /* access_mask */
6535 FILE_SHARE_NONE, /* share_access */
6536 FILE_CREATE, /* create_disposition*/
6537 FILE_DIRECTORY_FILE, /* create_options */
6538 mod_unixmode, /* file_attributes */
6539 0, /* oplock_request */
6540 0, /* allocation_size */
6546 *psbuf = smb_fname->st;
6547 TALLOC_FREE(smb_fname);
6549 if (NT_STATUS_IS_OK(status)) {
6550 close_file(req, fsp, NORMAL_CLOSE);
6553 info_level_return = SVAL(pdata,16);
6555 if (info_level_return == SMB_QUERY_FILE_UNIX_BASIC) {
6556 *pdata_return_size = 12 + SMB_FILE_UNIX_BASIC_SIZE;
6557 } else if (info_level_return == SMB_QUERY_FILE_UNIX_INFO2) {
6558 *pdata_return_size = 12 + SMB_FILE_UNIX_INFO2_SIZE;
6560 *pdata_return_size = 12;
6563 /* Realloc the data size */
6564 *ppdata = (char *)SMB_REALLOC(*ppdata,*pdata_return_size);
6565 if (*ppdata == NULL) {
6566 *pdata_return_size = 0;
6567 return NT_STATUS_NO_MEMORY;
6571 SSVAL(pdata,0,NO_OPLOCK_RETURN);
6572 SSVAL(pdata,2,0); /* No fnum. */
6573 SIVAL(pdata,4,info); /* Was directory created. */
6575 switch (info_level_return) {
6576 case SMB_QUERY_FILE_UNIX_BASIC:
6577 SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_BASIC);
6578 SSVAL(pdata,10,0); /* Padding. */
6579 store_file_unix_basic(conn, pdata + 12, fsp, psbuf);
6581 case SMB_QUERY_FILE_UNIX_INFO2:
6582 SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_INFO2);
6583 SSVAL(pdata,10,0); /* Padding. */
6584 store_file_unix_basic_info2(conn, pdata + 12, fsp, psbuf);
6587 SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
6588 SSVAL(pdata,10,0); /* Padding. */
6595 /****************************************************************************
6596 Open/Create a file with POSIX semantics.
6597 ****************************************************************************/
6599 static NTSTATUS smb_posix_open(connection_struct *conn,
6600 struct smb_request *req,
6604 SMB_STRUCT_STAT *psbuf,
6605 int *pdata_return_size)
6607 struct smb_filename *smb_fname = NULL;
6608 bool extended_oplock_granted = False;
6609 char *pdata = *ppdata;
6611 uint32 wire_open_mode = 0;
6612 uint32 raw_unixmode = 0;
6613 uint32 mod_unixmode = 0;
6614 uint32 create_disp = 0;
6615 uint32 access_mask = 0;
6616 uint32 create_options = 0;
6617 NTSTATUS status = NT_STATUS_OK;
6618 mode_t unixmode = (mode_t)0;
6619 files_struct *fsp = NULL;
6620 int oplock_request = 0;
6622 uint16 info_level_return = 0;
6624 if (total_data < 18) {
6625 return NT_STATUS_INVALID_PARAMETER;
6628 flags = IVAL(pdata,0);
6629 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
6630 if (oplock_request) {
6631 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
6634 wire_open_mode = IVAL(pdata,4);
6636 if (wire_open_mode == (SMB_O_CREAT|SMB_O_DIRECTORY)) {
6637 return smb_posix_mkdir(conn, req,
6645 switch (wire_open_mode & SMB_ACCMODE) {
6647 access_mask = FILE_READ_DATA;
6650 access_mask = FILE_WRITE_DATA;
6653 access_mask = FILE_READ_DATA|FILE_WRITE_DATA;
6656 DEBUG(5,("smb_posix_open: invalid open mode 0x%x\n",
6657 (unsigned int)wire_open_mode ));
6658 return NT_STATUS_INVALID_PARAMETER;
6661 wire_open_mode &= ~SMB_ACCMODE;
6663 if((wire_open_mode & (SMB_O_CREAT | SMB_O_EXCL)) == (SMB_O_CREAT | SMB_O_EXCL)) {
6664 create_disp = FILE_CREATE;
6665 } else if((wire_open_mode & (SMB_O_CREAT | SMB_O_TRUNC)) == (SMB_O_CREAT | SMB_O_TRUNC)) {
6666 create_disp = FILE_OVERWRITE_IF;
6667 } else if((wire_open_mode & SMB_O_CREAT) == SMB_O_CREAT) {
6668 create_disp = FILE_OPEN_IF;
6669 } else if ((wire_open_mode & (SMB_O_CREAT | SMB_O_EXCL | SMB_O_TRUNC)) == 0) {
6670 create_disp = FILE_OPEN;
6672 DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
6673 (unsigned int)wire_open_mode ));
6674 return NT_STATUS_INVALID_PARAMETER;
6677 raw_unixmode = IVAL(pdata,8);
6678 /* Next 4 bytes are not yet defined. */
6680 status = unix_perms_from_wire(conn,
6683 VALID_STAT(*psbuf) ? PERM_EXISTING_FILE : PERM_NEW_FILE,
6686 if (!NT_STATUS_IS_OK(status)) {
6690 mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
6692 if (wire_open_mode & SMB_O_SYNC) {
6693 create_options |= FILE_WRITE_THROUGH;
6695 if (wire_open_mode & SMB_O_APPEND) {
6696 access_mask |= FILE_APPEND_DATA;
6698 if (wire_open_mode & SMB_O_DIRECT) {
6699 mod_unixmode |= FILE_FLAG_NO_BUFFERING;
6702 DEBUG(10,("smb_posix_open: file %s, smb_posix_flags = %u, mode 0%o\n",
6704 (unsigned int)wire_open_mode,
6705 (unsigned int)unixmode ));
6707 status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
6709 if (!NT_STATUS_IS_OK(status)) {
6713 status = SMB_VFS_CREATE_FILE(
6716 0, /* root_dir_fid */
6717 smb_fname, /* fname */
6718 access_mask, /* access_mask */
6719 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
6721 create_disp, /* create_disposition*/
6722 FILE_NON_DIRECTORY_FILE, /* create_options */
6723 mod_unixmode, /* file_attributes */
6724 oplock_request, /* oplock_request */
6725 0, /* allocation_size */
6731 *psbuf = smb_fname->st;
6732 TALLOC_FREE(smb_fname);
6734 if (!NT_STATUS_IS_OK(status)) {
6738 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
6739 extended_oplock_granted = True;
6742 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
6743 extended_oplock_granted = True;
6746 info_level_return = SVAL(pdata,16);
6748 /* Allocate the correct return size. */
6750 if (info_level_return == SMB_QUERY_FILE_UNIX_BASIC) {
6751 *pdata_return_size = 12 + SMB_FILE_UNIX_BASIC_SIZE;
6752 } else if (info_level_return == SMB_QUERY_FILE_UNIX_INFO2) {
6753 *pdata_return_size = 12 + SMB_FILE_UNIX_INFO2_SIZE;
6755 *pdata_return_size = 12;
6758 /* Realloc the data size */
6759 *ppdata = (char *)SMB_REALLOC(*ppdata,*pdata_return_size);
6760 if (*ppdata == NULL) {
6761 close_file(req, fsp, ERROR_CLOSE);
6762 *pdata_return_size = 0;
6763 return NT_STATUS_NO_MEMORY;
6767 if (extended_oplock_granted) {
6768 if (flags & REQUEST_BATCH_OPLOCK) {
6769 SSVAL(pdata,0, BATCH_OPLOCK_RETURN);
6771 SSVAL(pdata,0, EXCLUSIVE_OPLOCK_RETURN);
6773 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
6774 SSVAL(pdata,0, LEVEL_II_OPLOCK_RETURN);
6776 SSVAL(pdata,0,NO_OPLOCK_RETURN);
6779 SSVAL(pdata,2,fsp->fnum);
6780 SIVAL(pdata,4,info); /* Was file created etc. */
6782 switch (info_level_return) {
6783 case SMB_QUERY_FILE_UNIX_BASIC:
6784 SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_BASIC);
6785 SSVAL(pdata,10,0); /* padding. */
6786 store_file_unix_basic(conn, pdata + 12, fsp, psbuf);
6788 case SMB_QUERY_FILE_UNIX_INFO2:
6789 SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_INFO2);
6790 SSVAL(pdata,10,0); /* padding. */
6791 store_file_unix_basic_info2(conn, pdata + 12, fsp, psbuf);
6794 SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
6795 SSVAL(pdata,10,0); /* padding. */
6798 return NT_STATUS_OK;
6801 /****************************************************************************
6802 Delete a file with POSIX semantics.
6803 ****************************************************************************/
6805 static NTSTATUS smb_posix_unlink(connection_struct *conn,
6806 struct smb_request *req,
6809 struct smb_filename *smb_fname)
6811 NTSTATUS status = NT_STATUS_OK;
6812 files_struct *fsp = NULL;
6816 int create_options = 0;
6818 struct share_mode_lock *lck = NULL;
6820 if (total_data < 2) {
6821 return NT_STATUS_INVALID_PARAMETER;
6824 flags = SVAL(pdata,0);
6826 if (!VALID_STAT(smb_fname->st)) {
6827 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
6830 if ((flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) &&
6831 !VALID_STAT_OF_DIR(smb_fname->st)) {
6832 return NT_STATUS_NOT_A_DIRECTORY;
6835 DEBUG(10,("smb_posix_unlink: %s %s\n",
6836 (flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) ? "directory" : "file",
6837 smb_fname_str_dbg(smb_fname)));
6839 if (VALID_STAT_OF_DIR(smb_fname->st)) {
6840 create_options |= FILE_DIRECTORY_FILE;
6843 status = SMB_VFS_CREATE_FILE(
6846 0, /* root_dir_fid */
6847 smb_fname, /* fname */
6848 DELETE_ACCESS, /* access_mask */
6849 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
6851 FILE_OPEN, /* create_disposition*/
6852 create_options, /* create_options */
6853 FILE_FLAG_POSIX_SEMANTICS|0777, /* file_attributes */
6854 0, /* oplock_request */
6855 0, /* allocation_size */
6861 if (!NT_STATUS_IS_OK(status)) {
6866 * Don't lie to client. If we can't really delete due to
6867 * non-POSIX opens return SHARING_VIOLATION.
6870 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
6873 DEBUG(0, ("smb_posix_unlink: Could not get share mode "
6874 "lock for file %s\n", fsp->fsp_name));
6875 close_file(req, fsp, NORMAL_CLOSE);
6876 return NT_STATUS_INVALID_PARAMETER;
6880 * See if others still have the file open. If this is the case, then
6881 * don't delete. If all opens are POSIX delete we can set the delete
6882 * on close disposition.
6884 for (i=0; i<lck->num_share_modes; i++) {
6885 struct share_mode_entry *e = &lck->share_modes[i];
6886 if (is_valid_share_mode_entry(e)) {
6887 if (e->flags & SHARE_MODE_FLAG_POSIX_OPEN) {
6890 /* Fail with sharing violation. */
6891 close_file(req, fsp, NORMAL_CLOSE);
6893 return NT_STATUS_SHARING_VIOLATION;
6898 * Set the delete on close.
6900 status = smb_set_file_disposition_info(conn,
6906 if (!NT_STATUS_IS_OK(status)) {
6907 close_file(req, fsp, NORMAL_CLOSE);
6912 return close_file(req, fsp, NORMAL_CLOSE);
6915 /****************************************************************************
6916 Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
6917 ****************************************************************************/
6919 static void call_trans2setfilepathinfo(connection_struct *conn,
6920 struct smb_request *req,
6921 unsigned int tran_call,
6922 char **pparams, int total_params,
6923 char **ppdata, int total_data,
6924 unsigned int max_data_bytes)
6926 char *params = *pparams;
6927 char *pdata = *ppdata;
6929 SMB_STRUCT_STAT sbuf;
6931 struct smb_filename *smb_fname = NULL;
6932 files_struct *fsp = NULL;
6933 NTSTATUS status = NT_STATUS_OK;
6934 int data_return_size = 0;
6935 TALLOC_CTX *ctx = talloc_tos();
6938 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
6942 if (tran_call == TRANSACT2_SETFILEINFO) {
6943 if (total_params < 4) {
6944 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
6948 fsp = file_fsp(req, SVAL(params,0));
6949 /* Basic check for non-null fsp. */
6950 if (!check_fsp_open(conn, req, fsp)) {
6953 info_level = SVAL(params,2);
6955 fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
6957 reply_nterror(req, NT_STATUS_NO_MEMORY);
6961 status = create_synthetic_smb_fname_split(talloc_tos(), fname,
6963 if (!NT_STATUS_IS_OK(status)) {
6964 reply_nterror(req, status);
6968 if(fsp->is_directory || fsp->fh->fd == -1) {
6970 * This is actually a SETFILEINFO on a directory
6971 * handle (returned from an NT SMB). NT5.0 seems
6972 * to do this call. JRA.
6974 if (INFO_LEVEL_IS_UNIX(info_level)) {
6975 /* Always do lstat for UNIX calls. */
6976 if (SMB_VFS_LSTAT(conn, smb_fname)) {
6977 DEBUG(3,("call_trans2setfilepathinfo: "
6978 "SMB_VFS_LSTAT of %s failed "
6980 smb_fname_str_dbg(smb_fname),
6982 reply_nterror(req, map_nt_error_from_unix(errno));
6986 if (SMB_VFS_STAT(conn, smb_fname) != 0) {
6987 DEBUG(3,("call_trans2setfilepathinfo: "
6988 "fileinfo of %s failed (%s)\n",
6989 smb_fname_str_dbg(smb_fname),
6991 reply_nterror(req, map_nt_error_from_unix(errno));
6995 } else if (fsp->print_file) {
6997 * Doing a DELETE_ON_CLOSE should cancel a print job.
6999 if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
7000 fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
7002 DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
7005 send_trans2_replies(conn, req, params, 2,
7010 reply_doserror(req, ERRDOS, ERRbadpath);
7015 * Original code - this is an open file.
7017 if (!check_fsp(conn, req, fsp)) {
7021 if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
7022 DEBUG(3,("call_trans2setfilepathinfo: fstat "
7023 "of fnum %d failed (%s)\n", fsp->fnum,
7025 reply_nterror(req, map_nt_error_from_unix(errno));
7031 if (total_params < 7) {
7032 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7036 info_level = SVAL(params,0);
7037 srvstr_get_path(ctx, params, req->flags2, &fname, ¶ms[6],
7038 total_params - 6, STR_TERMINATE,
7040 if (!NT_STATUS_IS_OK(status)) {
7041 reply_nterror(req, status);
7045 status = filename_convert(ctx, conn,
7046 req->flags2 & FLAGS2_DFS_PATHNAMES,
7050 if (!NT_STATUS_IS_OK(status)) {
7051 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
7052 reply_botherror(req,
7053 NT_STATUS_PATH_NOT_COVERED,
7054 ERRSRV, ERRbadpath);
7057 reply_nterror(req, status);
7061 if (INFO_LEVEL_IS_UNIX(info_level)) {
7063 * For CIFS UNIX extensions the target name may not exist.
7066 /* Always do lstat for UNIX calls. */
7067 SMB_VFS_LSTAT(conn, smb_fname);
7069 } else if (!VALID_STAT(smb_fname->st) &&
7070 SMB_VFS_STAT(conn, smb_fname)) {
7071 DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_STAT of "
7073 smb_fname_str_dbg(smb_fname),
7075 reply_nterror(req, map_nt_error_from_unix(errno));
7080 /* Set sbuf for use below. */
7081 sbuf = smb_fname->st;
7083 if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
7084 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7088 if (!CAN_WRITE(conn)) {
7089 /* Allow POSIX opens. The open path will deny
7090 * any non-readonly opens. */
7091 if (info_level != SMB_POSIX_PATH_OPEN) {
7092 reply_doserror(req, ERRSRV, ERRaccess);
7097 DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d totdata=%d\n",
7098 tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
7100 /* Realloc the parameter size */
7101 *pparams = (char *)SMB_REALLOC(*pparams,2);
7102 if (*pparams == NULL) {
7103 reply_nterror(req, NT_STATUS_NO_MEMORY);
7110 switch (info_level) {
7112 case SMB_INFO_STANDARD:
7114 status = smb_set_info_standard(conn,
7122 case SMB_INFO_SET_EA:
7124 status = smb_info_set_ea(conn,
7132 case SMB_SET_FILE_BASIC_INFO:
7133 case SMB_FILE_BASIC_INFORMATION:
7135 status = smb_set_file_basic_info(conn,
7143 case SMB_FILE_ALLOCATION_INFORMATION:
7144 case SMB_SET_FILE_ALLOCATION_INFO:
7146 status = smb_set_file_allocation_info(conn, req,
7154 case SMB_FILE_END_OF_FILE_INFORMATION:
7155 case SMB_SET_FILE_END_OF_FILE_INFO:
7157 status = smb_set_file_end_of_file_info(conn, req,
7165 case SMB_FILE_DISPOSITION_INFORMATION:
7166 case SMB_SET_FILE_DISPOSITION_INFO: /* Set delete on close for open file. */
7169 /* JRA - We used to just ignore this on a path ?
7170 * Shouldn't this be invalid level on a pathname
7173 if (tran_call != TRANSACT2_SETFILEINFO) {
7174 return ERROR_NT(NT_STATUS_INVALID_LEVEL);
7177 status = smb_set_file_disposition_info(conn,
7185 case SMB_FILE_POSITION_INFORMATION:
7187 status = smb_file_position_information(conn,
7194 /* From tridge Samba4 :
7195 * MODE_INFORMATION in setfileinfo (I have no
7196 * idea what "mode information" on a file is - it takes a value of 0,
7197 * 2, 4 or 6. What could it be?).
7200 case SMB_FILE_MODE_INFORMATION:
7202 status = smb_file_mode_information(conn,
7209 * CIFS UNIX extensions.
7212 case SMB_SET_FILE_UNIX_BASIC:
7214 status = smb_set_file_unix_basic(conn, req,
7222 case SMB_SET_FILE_UNIX_INFO2:
7224 status = smb_set_file_unix_info2(conn, req,
7232 case SMB_SET_FILE_UNIX_LINK:
7234 if (tran_call != TRANSACT2_SETPATHINFO) {
7235 /* We must have a pathname for this. */
7236 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7239 status = smb_set_file_unix_link(conn, req, pdata,
7244 case SMB_SET_FILE_UNIX_HLINK:
7246 if (tran_call != TRANSACT2_SETPATHINFO || smb_fname == NULL) {
7247 /* We must have a pathname for this. */
7248 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7251 status = smb_set_file_unix_hlink(conn, req,
7257 case SMB_FILE_RENAME_INFORMATION:
7259 status = smb_file_rename_information(conn, req,
7265 #if defined(HAVE_POSIX_ACLS)
7266 case SMB_SET_POSIX_ACL:
7268 status = smb_set_posix_acl(conn,
7278 case SMB_SET_POSIX_LOCK:
7280 if (tran_call != TRANSACT2_SETFILEINFO) {
7281 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7284 status = smb_set_posix_lock(conn, req,
7285 pdata, total_data, fsp);
7289 case SMB_POSIX_PATH_OPEN:
7291 if (tran_call != TRANSACT2_SETPATHINFO) {
7292 /* We must have a pathname for this. */
7293 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7297 status = smb_posix_open(conn, req,
7306 case SMB_POSIX_PATH_UNLINK:
7308 if (tran_call != TRANSACT2_SETPATHINFO) {
7309 /* We must have a pathname for this. */
7310 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7314 status = smb_posix_unlink(conn, req,
7322 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7326 if (!NT_STATUS_IS_OK(status)) {
7327 if (open_was_deferred(req->mid)) {
7328 /* We have re-scheduled this call. */
7331 if (blocking_lock_was_deferred(req->mid)) {
7332 /* We have re-scheduled this call. */
7335 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
7336 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
7337 ERRSRV, ERRbadpath);
7340 if (info_level == SMB_POSIX_PATH_OPEN) {
7341 reply_openerror(req, status);
7345 reply_nterror(req, status);
7350 send_trans2_replies(conn, req, params, 2, *ppdata, data_return_size,
7356 /****************************************************************************
7357 Reply to a TRANS2_MKDIR (make directory with extended attributes).
7358 ****************************************************************************/
7360 static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
7361 char **pparams, int total_params,
7362 char **ppdata, int total_data,
7363 unsigned int max_data_bytes)
7365 struct smb_filename *smb_dname = NULL;
7366 char *params = *pparams;
7367 char *pdata = *ppdata;
7368 char *directory = NULL;
7369 NTSTATUS status = NT_STATUS_OK;
7370 struct ea_list *ea_list = NULL;
7371 TALLOC_CTX *ctx = talloc_tos();
7373 if (!CAN_WRITE(conn)) {
7374 reply_doserror(req, ERRSRV, ERRaccess);
7378 if (total_params < 5) {
7379 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7383 srvstr_get_path(ctx, params, req->flags2, &directory, ¶ms[4],
7384 total_params - 4, STR_TERMINATE,
7386 if (!NT_STATUS_IS_OK(status)) {
7387 reply_nterror(req, status);
7391 DEBUG(3,("call_trans2mkdir : name = %s\n", directory));
7393 status = filename_convert(ctx,
7395 req->flags2 & FLAGS2_DFS_PATHNAMES,
7400 if (!NT_STATUS_IS_OK(status)) {
7401 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
7402 reply_botherror(req,
7403 NT_STATUS_PATH_NOT_COVERED,
7404 ERRSRV, ERRbadpath);
7407 reply_nterror(req, status);
7411 /* Any data in this call is an EA list. */
7412 if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
7413 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
7418 * OS/2 workplace shell seems to send SET_EA requests of "null"
7419 * length (4 bytes containing IVAL 4).
7420 * They seem to have no effect. Bug #3212. JRA.
7423 if (total_data != 4) {
7424 if (total_data < 10) {
7425 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7429 if (IVAL(pdata,0) > total_data) {
7430 DEBUG(10,("call_trans2mkdir: bad total data size (%u) > %u\n",
7431 IVAL(pdata,0), (unsigned int)total_data));
7432 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7436 ea_list = read_ea_list(talloc_tos(), pdata + 4,
7439 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7443 /* If total_data == 4 Windows doesn't care what values
7444 * are placed in that field, it just ignores them.
7445 * The System i QNTC IBM SMB client puts bad values here,
7446 * so ignore them. */
7448 status = create_directory(conn, req, smb_dname);
7450 if (!NT_STATUS_IS_OK(status)) {
7451 reply_nterror(req, status);
7455 /* Try and set any given EA. */
7457 status = set_ea(conn, NULL, smb_dname, ea_list);
7458 if (!NT_STATUS_IS_OK(status)) {
7459 reply_nterror(req, status);
7464 /* Realloc the parameter and data sizes */
7465 *pparams = (char *)SMB_REALLOC(*pparams,2);
7466 if(*pparams == NULL) {
7467 reply_nterror(req, NT_STATUS_NO_MEMORY);
7474 send_trans2_replies(conn, req, params, 2, *ppdata, 0, max_data_bytes);
7477 TALLOC_FREE(smb_dname);
7481 /****************************************************************************
7482 Reply to a TRANS2_FINDNOTIFYFIRST (start monitoring a directory for changes).
7483 We don't actually do this - we just send a null response.
7484 ****************************************************************************/
7486 static void call_trans2findnotifyfirst(connection_struct *conn,
7487 struct smb_request *req,
7488 char **pparams, int total_params,
7489 char **ppdata, int total_data,
7490 unsigned int max_data_bytes)
7492 char *params = *pparams;
7495 if (total_params < 6) {
7496 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7500 info_level = SVAL(params,4);
7501 DEBUG(3,("call_trans2findnotifyfirst - info_level %d\n", info_level));
7503 switch (info_level) {
7508 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
7512 /* Realloc the parameter and data sizes */
7513 *pparams = (char *)SMB_REALLOC(*pparams,6);
7514 if (*pparams == NULL) {
7515 reply_nterror(req, NT_STATUS_NO_MEMORY);
7520 SSVAL(params,0,fnf_handle);
7521 SSVAL(params,2,0); /* No changes */
7522 SSVAL(params,4,0); /* No EA errors */
7529 send_trans2_replies(conn, req, params, 6, *ppdata, 0, max_data_bytes);
7534 /****************************************************************************
7535 Reply to a TRANS2_FINDNOTIFYNEXT (continue monitoring a directory for
7536 changes). Currently this does nothing.
7537 ****************************************************************************/
7539 static void call_trans2findnotifynext(connection_struct *conn,
7540 struct smb_request *req,
7541 char **pparams, int total_params,
7542 char **ppdata, int total_data,
7543 unsigned int max_data_bytes)
7545 char *params = *pparams;
7547 DEBUG(3,("call_trans2findnotifynext\n"));
7549 /* Realloc the parameter and data sizes */
7550 *pparams = (char *)SMB_REALLOC(*pparams,4);
7551 if (*pparams == NULL) {
7552 reply_nterror(req, NT_STATUS_NO_MEMORY);
7557 SSVAL(params,0,0); /* No changes */
7558 SSVAL(params,2,0); /* No EA errors */
7560 send_trans2_replies(conn, req, params, 4, *ppdata, 0, max_data_bytes);
7565 /****************************************************************************
7566 Reply to a TRANS2_GET_DFS_REFERRAL - Shirish Kalele <kalele@veritas.com>.
7567 ****************************************************************************/
7569 static void call_trans2getdfsreferral(connection_struct *conn,
7570 struct smb_request *req,
7571 char **pparams, int total_params,
7572 char **ppdata, int total_data,
7573 unsigned int max_data_bytes)
7575 char *params = *pparams;
7576 char *pathname = NULL;
7578 int max_referral_level;
7579 NTSTATUS status = NT_STATUS_OK;
7580 TALLOC_CTX *ctx = talloc_tos();
7582 DEBUG(10,("call_trans2getdfsreferral\n"));
7584 if (total_params < 3) {
7585 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7589 max_referral_level = SVAL(params,0);
7591 if(!lp_host_msdfs()) {
7592 reply_doserror(req, ERRDOS, ERRbadfunc);
7596 srvstr_pull_talloc(ctx, params, req->flags2, &pathname, ¶ms[2],
7597 total_params - 2, STR_TERMINATE);
7599 reply_nterror(req, NT_STATUS_NOT_FOUND);
7602 if((reply_size = setup_dfs_referral(conn, pathname, max_referral_level,
7603 ppdata,&status)) < 0) {
7604 reply_nterror(req, status);
7608 SSVAL(req->inbuf, smb_flg2,
7609 SVAL(req->inbuf,smb_flg2) | FLAGS2_DFS_PATHNAMES);
7610 send_trans2_replies(conn, req,0,0,*ppdata,reply_size, max_data_bytes);
7615 #define LMCAT_SPL 0x53
7616 #define LMFUNC_GETJOBID 0x60
7618 /****************************************************************************
7619 Reply to a TRANS2_IOCTL - used for OS/2 printing.
7620 ****************************************************************************/
7622 static void call_trans2ioctl(connection_struct *conn,
7623 struct smb_request *req,
7624 char **pparams, int total_params,
7625 char **ppdata, int total_data,
7626 unsigned int max_data_bytes)
7628 char *pdata = *ppdata;
7629 files_struct *fsp = file_fsp(req, SVAL(req->vwv+15, 0));
7631 /* check for an invalid fid before proceeding */
7634 reply_doserror(req, ERRDOS, ERRbadfid);
7638 if ((SVAL(req->vwv+16, 0) == LMCAT_SPL)
7639 && (SVAL(req->vwv+17, 0) == LMFUNC_GETJOBID)) {
7640 *ppdata = (char *)SMB_REALLOC(*ppdata, 32);
7641 if (*ppdata == NULL) {
7642 reply_nterror(req, NT_STATUS_NO_MEMORY);
7647 /* NOTE - THIS IS ASCII ONLY AT THE MOMENT - NOT SURE IF OS/2
7648 CAN ACCEPT THIS IN UNICODE. JRA. */
7650 SSVAL(pdata,0,fsp->rap_print_jobid); /* Job number */
7651 srvstr_push(pdata, req->flags2, pdata + 2,
7652 global_myname(), 15,
7653 STR_ASCII|STR_TERMINATE); /* Our NetBIOS name */
7654 srvstr_push(pdata, req->flags2, pdata+18,
7655 lp_servicename(SNUM(conn)), 13,
7656 STR_ASCII|STR_TERMINATE); /* Service name */
7657 send_trans2_replies(conn, req, *pparams, 0, *ppdata, 32,
7662 DEBUG(2,("Unknown TRANS2_IOCTL\n"));
7663 reply_doserror(req, ERRSRV, ERRerror);
7666 /****************************************************************************
7667 Reply to a SMBfindclose (stop trans2 directory search).
7668 ****************************************************************************/
7670 void reply_findclose(struct smb_request *req)
7674 START_PROFILE(SMBfindclose);
7677 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7678 END_PROFILE(SMBfindclose);
7682 dptr_num = SVALS(req->vwv+0, 0);
7684 DEBUG(3,("reply_findclose, dptr_num = %d\n", dptr_num));
7686 dptr_close(&dptr_num);
7688 reply_outbuf(req, 0, 0);
7690 DEBUG(3,("SMBfindclose dptr_num = %d\n", dptr_num));
7692 END_PROFILE(SMBfindclose);
7696 /****************************************************************************
7697 Reply to a SMBfindnclose (stop FINDNOTIFYFIRST directory search).
7698 ****************************************************************************/
7700 void reply_findnclose(struct smb_request *req)
7704 START_PROFILE(SMBfindnclose);
7707 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7708 END_PROFILE(SMBfindnclose);
7712 dptr_num = SVAL(req->vwv+0, 0);
7714 DEBUG(3,("reply_findnclose, dptr_num = %d\n", dptr_num));
7716 /* We never give out valid handles for a
7717 findnotifyfirst - so any dptr_num is ok here.
7720 reply_outbuf(req, 0, 0);
7722 DEBUG(3,("SMB_findnclose dptr_num = %d\n", dptr_num));
7724 END_PROFILE(SMBfindnclose);
7728 static void handle_trans2(connection_struct *conn, struct smb_request *req,
7729 struct trans_state *state)
7731 if (Protocol >= PROTOCOL_NT1) {
7732 req->flags2 |= 0x40; /* IS_LONG_NAME */
7733 SSVAL(req->inbuf,smb_flg2,req->flags2);
7736 if (conn->encrypt_level == Required && !req->encrypted) {
7737 if (state->call != TRANSACT2_QFSINFO &&
7738 state->call != TRANSACT2_SETFSINFO) {
7739 DEBUG(0,("handle_trans2: encryption required "
7741 (unsigned int)state->call));
7742 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
7747 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
7749 /* Now we must call the relevant TRANS2 function */
7750 switch(state->call) {
7751 case TRANSACT2_OPEN:
7753 START_PROFILE(Trans2_open);
7754 call_trans2open(conn, req,
7755 &state->param, state->total_param,
7756 &state->data, state->total_data,
7757 state->max_data_return);
7758 END_PROFILE(Trans2_open);
7762 case TRANSACT2_FINDFIRST:
7764 START_PROFILE(Trans2_findfirst);
7765 call_trans2findfirst(conn, req,
7766 &state->param, state->total_param,
7767 &state->data, state->total_data,
7768 state->max_data_return);
7769 END_PROFILE(Trans2_findfirst);
7773 case TRANSACT2_FINDNEXT:
7775 START_PROFILE(Trans2_findnext);
7776 call_trans2findnext(conn, req,
7777 &state->param, state->total_param,
7778 &state->data, state->total_data,
7779 state->max_data_return);
7780 END_PROFILE(Trans2_findnext);
7784 case TRANSACT2_QFSINFO:
7786 START_PROFILE(Trans2_qfsinfo);
7787 call_trans2qfsinfo(conn, req,
7788 &state->param, state->total_param,
7789 &state->data, state->total_data,
7790 state->max_data_return);
7791 END_PROFILE(Trans2_qfsinfo);
7795 case TRANSACT2_SETFSINFO:
7797 START_PROFILE(Trans2_setfsinfo);
7798 call_trans2setfsinfo(conn, req,
7799 &state->param, state->total_param,
7800 &state->data, state->total_data,
7801 state->max_data_return);
7802 END_PROFILE(Trans2_setfsinfo);
7806 case TRANSACT2_QPATHINFO:
7807 case TRANSACT2_QFILEINFO:
7809 START_PROFILE(Trans2_qpathinfo);
7810 call_trans2qfilepathinfo(conn, req, state->call,
7811 &state->param, state->total_param,
7812 &state->data, state->total_data,
7813 state->max_data_return);
7814 END_PROFILE(Trans2_qpathinfo);
7818 case TRANSACT2_SETPATHINFO:
7819 case TRANSACT2_SETFILEINFO:
7821 START_PROFILE(Trans2_setpathinfo);
7822 call_trans2setfilepathinfo(conn, req, state->call,
7823 &state->param, state->total_param,
7824 &state->data, state->total_data,
7825 state->max_data_return);
7826 END_PROFILE(Trans2_setpathinfo);
7830 case TRANSACT2_FINDNOTIFYFIRST:
7832 START_PROFILE(Trans2_findnotifyfirst);
7833 call_trans2findnotifyfirst(conn, req,
7834 &state->param, state->total_param,
7835 &state->data, state->total_data,
7836 state->max_data_return);
7837 END_PROFILE(Trans2_findnotifyfirst);
7841 case TRANSACT2_FINDNOTIFYNEXT:
7843 START_PROFILE(Trans2_findnotifynext);
7844 call_trans2findnotifynext(conn, req,
7845 &state->param, state->total_param,
7846 &state->data, state->total_data,
7847 state->max_data_return);
7848 END_PROFILE(Trans2_findnotifynext);
7852 case TRANSACT2_MKDIR:
7854 START_PROFILE(Trans2_mkdir);
7855 call_trans2mkdir(conn, req,
7856 &state->param, state->total_param,
7857 &state->data, state->total_data,
7858 state->max_data_return);
7859 END_PROFILE(Trans2_mkdir);
7863 case TRANSACT2_GET_DFS_REFERRAL:
7865 START_PROFILE(Trans2_get_dfs_referral);
7866 call_trans2getdfsreferral(conn, req,
7867 &state->param, state->total_param,
7868 &state->data, state->total_data,
7869 state->max_data_return);
7870 END_PROFILE(Trans2_get_dfs_referral);
7874 case TRANSACT2_IOCTL:
7876 START_PROFILE(Trans2_ioctl);
7877 call_trans2ioctl(conn, req,
7878 &state->param, state->total_param,
7879 &state->data, state->total_data,
7880 state->max_data_return);
7881 END_PROFILE(Trans2_ioctl);
7886 /* Error in request */
7887 DEBUG(2,("Unknown request %d in trans2 call\n", state->call));
7888 reply_doserror(req, ERRSRV,ERRerror);
7892 /****************************************************************************
7893 Reply to a SMBtrans2.
7894 ****************************************************************************/
7896 void reply_trans2(struct smb_request *req)
7898 connection_struct *conn = req->conn;
7903 unsigned int tran_call;
7904 struct trans_state *state;
7907 START_PROFILE(SMBtrans2);
7909 if (req->wct < 14) {
7910 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7911 END_PROFILE(SMBtrans2);
7915 dsoff = SVAL(req->vwv+12, 0);
7916 dscnt = SVAL(req->vwv+11, 0);
7917 psoff = SVAL(req->vwv+10, 0);
7918 pscnt = SVAL(req->vwv+9, 0);
7919 tran_call = SVAL(req->vwv+14, 0);
7921 result = allow_new_trans(conn->pending_trans, req->mid);
7922 if (!NT_STATUS_IS_OK(result)) {
7923 DEBUG(2, ("Got invalid trans2 request: %s\n",
7924 nt_errstr(result)));
7925 reply_nterror(req, result);
7926 END_PROFILE(SMBtrans2);
7931 switch (tran_call) {
7932 /* List the allowed trans2 calls on IPC$ */
7933 case TRANSACT2_OPEN:
7934 case TRANSACT2_GET_DFS_REFERRAL:
7935 case TRANSACT2_QFILEINFO:
7936 case TRANSACT2_QFSINFO:
7937 case TRANSACT2_SETFSINFO:
7940 reply_doserror(req, ERRSRV, ERRaccess);
7941 END_PROFILE(SMBtrans2);
7946 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
7947 DEBUG(0, ("talloc failed\n"));
7948 reply_nterror(req, NT_STATUS_NO_MEMORY);
7949 END_PROFILE(SMBtrans2);
7953 state->cmd = SMBtrans2;
7955 state->mid = req->mid;
7956 state->vuid = req->vuid;
7957 state->setup_count = SVAL(req->vwv+13, 0);
7958 state->setup = NULL;
7959 state->total_param = SVAL(req->vwv+0, 0);
7960 state->param = NULL;
7961 state->total_data = SVAL(req->vwv+1, 0);
7963 state->max_param_return = SVAL(req->vwv+2, 0);
7964 state->max_data_return = SVAL(req->vwv+3, 0);
7965 state->max_setup_return = SVAL(req->vwv+4, 0);
7966 state->close_on_completion = BITSETW(req->vwv+5, 0);
7967 state->one_way = BITSETW(req->vwv+5, 1);
7969 state->call = tran_call;
7971 /* All trans2 messages we handle have smb_sucnt == 1 - ensure this
7972 is so as a sanity check */
7973 if (state->setup_count != 1) {
7975 * Need to have rc=0 for ioctl to get job id for OS/2.
7976 * Network printing will fail if function is not successful.
7977 * Similar function in reply.c will be used if protocol
7978 * is LANMAN1.0 instead of LM1.2X002.
7979 * Until DosPrintSetJobInfo with PRJINFO3 is supported,
7980 * outbuf doesn't have to be set(only job id is used).
7982 if ( (state->setup_count == 4)
7983 && (tran_call == TRANSACT2_IOCTL)
7984 && (SVAL(req->vwv+16, 0) == LMCAT_SPL)
7985 && (SVAL(req->vwv+17, 0) == LMFUNC_GETJOBID)) {
7986 DEBUG(2,("Got Trans2 DevIOctl jobid\n"));
7988 DEBUG(2,("Invalid smb_sucnt in trans2 call(%u)\n",state->setup_count));
7989 DEBUG(2,("Transaction is %d\n",tran_call));
7991 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
7992 END_PROFILE(SMBtrans2);
7997 if ((dscnt > state->total_data) || (pscnt > state->total_param))
8000 if (state->total_data) {
8002 if (trans_oob(state->total_data, 0, dscnt)
8003 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
8007 /* Can't use talloc here, the core routines do realloc on the
8008 * params and data. */
8009 state->data = (char *)SMB_MALLOC(state->total_data);
8010 if (state->data == NULL) {
8011 DEBUG(0,("reply_trans2: data malloc fail for %u "
8012 "bytes !\n", (unsigned int)state->total_data));
8014 reply_nterror(req, NT_STATUS_NO_MEMORY);
8015 END_PROFILE(SMBtrans2);
8019 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
8022 if (state->total_param) {
8024 if (trans_oob(state->total_param, 0, pscnt)
8025 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
8029 /* Can't use talloc here, the core routines do realloc on the
8030 * params and data. */
8031 state->param = (char *)SMB_MALLOC(state->total_param);
8032 if (state->param == NULL) {
8033 DEBUG(0,("reply_trans: param malloc fail for %u "
8034 "bytes !\n", (unsigned int)state->total_param));
8035 SAFE_FREE(state->data);
8037 reply_nterror(req, NT_STATUS_NO_MEMORY);
8038 END_PROFILE(SMBtrans2);
8042 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
8045 state->received_data = dscnt;
8046 state->received_param = pscnt;
8048 if ((state->received_param == state->total_param) &&
8049 (state->received_data == state->total_data)) {
8051 handle_trans2(conn, req, state);
8053 SAFE_FREE(state->data);
8054 SAFE_FREE(state->param);
8056 END_PROFILE(SMBtrans2);
8060 DLIST_ADD(conn->pending_trans, state);
8062 /* We need to send an interim response then receive the rest
8063 of the parameter/data bytes */
8064 reply_outbuf(req, 0, 0);
8065 show_msg((char *)req->outbuf);
8066 END_PROFILE(SMBtrans2);
8071 DEBUG(0,("reply_trans2: invalid trans parameters\n"));
8072 SAFE_FREE(state->data);
8073 SAFE_FREE(state->param);
8075 END_PROFILE(SMBtrans2);
8076 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
8080 /****************************************************************************
8081 Reply to a SMBtranss2
8082 ****************************************************************************/
8084 void reply_transs2(struct smb_request *req)
8086 connection_struct *conn = req->conn;
8087 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
8088 struct trans_state *state;
8090 START_PROFILE(SMBtranss2);
8092 show_msg((char *)req->inbuf);
8095 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
8096 END_PROFILE(SMBtranss2);
8100 for (state = conn->pending_trans; state != NULL;
8101 state = state->next) {
8102 if (state->mid == req->mid) {
8107 if ((state == NULL) || (state->cmd != SMBtrans2)) {
8108 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
8109 END_PROFILE(SMBtranss2);
8113 /* Revise state->total_param and state->total_data in case they have
8114 changed downwards */
8116 if (SVAL(req->vwv+0, 0) < state->total_param)
8117 state->total_param = SVAL(req->vwv+0, 0);
8118 if (SVAL(req->vwv+1, 0) < state->total_data)
8119 state->total_data = SVAL(req->vwv+1, 0);
8121 pcnt = SVAL(req->vwv+2, 0);
8122 poff = SVAL(req->vwv+3, 0);
8123 pdisp = SVAL(req->vwv+4, 0);
8125 dcnt = SVAL(req->vwv+5, 0);
8126 doff = SVAL(req->vwv+6, 0);
8127 ddisp = SVAL(req->vwv+7, 0);
8129 state->received_param += pcnt;
8130 state->received_data += dcnt;
8132 if ((state->received_data > state->total_data) ||
8133 (state->received_param > state->total_param))
8137 if (trans_oob(state->total_param, pdisp, pcnt)
8138 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
8141 memcpy(state->param+pdisp,smb_base(req->inbuf)+poff,pcnt);
8145 if (trans_oob(state->total_data, ddisp, dcnt)
8146 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
8149 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
8152 if ((state->received_param < state->total_param) ||
8153 (state->received_data < state->total_data)) {
8154 END_PROFILE(SMBtranss2);
8158 handle_trans2(conn, req, state);
8160 DLIST_REMOVE(conn->pending_trans, state);
8161 SAFE_FREE(state->data);
8162 SAFE_FREE(state->param);
8165 END_PROFILE(SMBtranss2);
8170 DEBUG(0,("reply_transs2: invalid trans parameters\n"));
8171 DLIST_REMOVE(conn->pending_trans, state);
8172 SAFE_FREE(state->data);
8173 SAFE_FREE(state->param);
8175 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
8176 END_PROFILE(SMBtranss2);