2 Unix SMB/CIFS implementation.
3 file opening and share modes
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 2001-2004
6 Copyright (C) Volker Lendecke 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "system/filesys.h"
25 #include "smbd/smbd.h"
26 #include "smbd/globals.h"
27 #include "fake_file.h"
28 #include "../libcli/security/security.h"
29 #include "../librpc/gen_ndr/ndr_security.h"
30 #include "../librpc/gen_ndr/open_files.h"
34 extern const struct generic_mapping file_generic_mapping
;
36 struct deferred_open_record
{
37 bool delayed_for_oplocks
;
42 /****************************************************************************
43 If the requester wanted DELETE_ACCESS and was rejected because
44 the file ACL didn't include DELETE_ACCESS, see if the parent ACL
46 ****************************************************************************/
48 static bool parent_override_delete(connection_struct
*conn
,
49 const struct smb_filename
*smb_fname
,
51 uint32_t rejected_mask
)
53 if ((access_mask
& DELETE_ACCESS
) &&
54 (rejected_mask
& DELETE_ACCESS
) &&
55 can_delete_file_in_directory(conn
, smb_fname
)) {
61 /****************************************************************************
62 Check if we have open rights.
63 ****************************************************************************/
65 NTSTATUS
smbd_check_access_rights(struct connection_struct
*conn
,
66 const struct smb_filename
*smb_fname
,
69 /* Check if we have rights to open. */
71 struct security_descriptor
*sd
= NULL
;
72 uint32_t rejected_share_access
;
73 uint32_t rejected_mask
= access_mask
;
75 rejected_share_access
= access_mask
& ~(conn
->share_access
);
77 if (rejected_share_access
) {
78 DEBUG(10, ("smbd_check_access_rights: rejected share access 0x%x "
80 (unsigned int)access_mask
,
81 smb_fname_str_dbg(smb_fname
),
82 (unsigned int)rejected_share_access
));
83 return NT_STATUS_ACCESS_DENIED
;
86 if (get_current_uid(conn
) == (uid_t
)0) {
87 /* I'm sorry sir, I didn't know you were root... */
88 DEBUG(10,("smbd_check_access_rights: root override "
89 "on %s. Granting 0x%x\n",
90 smb_fname_str_dbg(smb_fname
),
91 (unsigned int)access_mask
));
95 if ((access_mask
& DELETE_ACCESS
) && !lp_acl_check_permissions(SNUM(conn
))) {
96 DEBUG(10,("smbd_check_access_rights: not checking ACL "
97 "on DELETE_ACCESS on file %s. Granting 0x%x\n",
98 smb_fname_str_dbg(smb_fname
),
99 (unsigned int)access_mask
));
103 if (access_mask
== DELETE_ACCESS
&&
104 VALID_STAT(smb_fname
->st
) &&
105 S_ISLNK(smb_fname
->st
.st_ex_mode
)) {
106 /* We can always delete a symlink. */
107 DEBUG(10,("smbd_check_access_rights: not checking ACL "
108 "on DELETE_ACCESS on symlink %s.\n",
109 smb_fname_str_dbg(smb_fname
) ));
113 status
= SMB_VFS_GET_NT_ACL(conn
, smb_fname
->base_name
,
118 if (!NT_STATUS_IS_OK(status
)) {
119 DEBUG(10, ("smbd_check_access_rights: Could not get acl "
121 smb_fname_str_dbg(smb_fname
),
124 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
132 * Never test FILE_READ_ATTRIBUTES. se_access_check() also takes care of
133 * owner WRITE_DAC and READ_CONTROL.
135 status
= se_access_check(sd
,
136 get_current_nttok(conn
),
137 (access_mask
& ~FILE_READ_ATTRIBUTES
),
140 DEBUG(10,("smbd_check_access_rights: file %s requesting "
141 "0x%x returning 0x%x (%s)\n",
142 smb_fname_str_dbg(smb_fname
),
143 (unsigned int)access_mask
,
144 (unsigned int)rejected_mask
,
145 nt_errstr(status
) ));
147 if (!NT_STATUS_IS_OK(status
)) {
148 if (DEBUGLEVEL
>= 10) {
149 DEBUG(10,("smbd_check_access_rights: acl for %s is:\n",
150 smb_fname_str_dbg(smb_fname
) ));
151 NDR_PRINT_DEBUG(security_descriptor
, sd
);
157 if (NT_STATUS_IS_OK(status
) ||
158 !NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
162 /* Here we know status == NT_STATUS_ACCESS_DENIED. */
166 if ((access_mask
& FILE_WRITE_ATTRIBUTES
) &&
167 (rejected_mask
& FILE_WRITE_ATTRIBUTES
) &&
168 !lp_store_dos_attributes(SNUM(conn
)) &&
169 (lp_map_readonly(SNUM(conn
)) ||
170 lp_map_archive(SNUM(conn
)) ||
171 lp_map_hidden(SNUM(conn
)) ||
172 lp_map_system(SNUM(conn
)))) {
173 rejected_mask
&= ~FILE_WRITE_ATTRIBUTES
;
175 DEBUG(10,("smbd_check_access_rights: "
177 "FILE_WRITE_ATTRIBUTES "
179 smb_fname_str_dbg(smb_fname
)));
182 if (parent_override_delete(conn
,
186 /* Were we trying to do an open
187 * for delete and didn't get DELETE
188 * access (only) ? Check if the
189 * directory allows DELETE_CHILD.
191 * http://blogs.msdn.com/oldnewthing/archive/2004/06/04/148426.aspx
194 rejected_mask
&= ~DELETE_ACCESS
;
196 DEBUG(10,("smbd_check_access_rights: "
200 smb_fname_str_dbg(smb_fname
)));
203 if (rejected_mask
!= 0) {
204 return NT_STATUS_ACCESS_DENIED
;
209 static NTSTATUS
check_parent_access(struct connection_struct
*conn
,
210 struct smb_filename
*smb_fname
,
211 uint32_t access_mask
)
214 char *parent_dir
= NULL
;
215 struct security_descriptor
*parent_sd
= NULL
;
216 uint32_t access_granted
= 0;
218 if (!parent_dirname(talloc_tos(),
219 smb_fname
->base_name
,
222 return NT_STATUS_NO_MEMORY
;
225 if (get_current_uid(conn
) == (uid_t
)0) {
226 /* I'm sorry sir, I didn't know you were root... */
227 DEBUG(10,("check_parent_access: root override "
228 "on %s. Granting 0x%x\n",
229 smb_fname_str_dbg(smb_fname
),
230 (unsigned int)access_mask
));
234 status
= SMB_VFS_GET_NT_ACL(conn
,
239 if (!NT_STATUS_IS_OK(status
)) {
240 DEBUG(5,("check_parent_access: SMB_VFS_GET_NT_ACL failed for "
241 "%s with error %s\n",
248 * Never test FILE_READ_ATTRIBUTES. se_access_check() also takes care of
249 * owner WRITE_DAC and READ_CONTROL.
251 status
= se_access_check(parent_sd
,
252 get_current_nttok(conn
),
253 (access_mask
& ~FILE_READ_ATTRIBUTES
),
255 if(!NT_STATUS_IS_OK(status
)) {
256 DEBUG(5,("check_parent_access: access check "
257 "on directory %s for "
258 "path %s for mask 0x%x returned (0x%x) %s\n",
260 smb_fname
->base_name
,
263 nt_errstr(status
) ));
270 /****************************************************************************
271 fd support routines - attempt to do a dos_open.
272 ****************************************************************************/
274 static NTSTATUS
fd_open(struct connection_struct
*conn
,
279 struct smb_filename
*smb_fname
= fsp
->fsp_name
;
280 NTSTATUS status
= NT_STATUS_OK
;
284 * Never follow symlinks on a POSIX client. The
285 * client should be doing this.
288 if (fsp
->posix_open
|| !lp_symlinks(SNUM(conn
))) {
293 fsp
->fh
->fd
= SMB_VFS_OPEN(conn
, smb_fname
, fsp
, flags
, mode
);
294 if (fsp
->fh
->fd
== -1) {
295 int posix_errno
= errno
;
297 #if defined(ENOTSUP) && defined(OSF1)
298 /* handle special Tru64 errno */
299 if (errno
== ENOTSUP
) {
304 /* fix broken NetBSD errno */
305 if (errno
== EFTYPE
) {
309 /* fix broken FreeBSD errno */
310 if (errno
== EMLINK
) {
313 #endif /* O_NOFOLLOW */
314 status
= map_nt_error_from_unix(posix_errno
);
315 if (errno
== EMFILE
) {
316 static time_t last_warned
= 0L;
318 if (time((time_t *) NULL
) > last_warned
) {
319 DEBUG(0,("Too many open files, unable "
320 "to open more! smbd's max "
322 lp_max_open_files()));
323 last_warned
= time((time_t *) NULL
);
329 DEBUG(10,("fd_open: name %s, flags = 0%o mode = 0%o, fd = %d. %s\n",
330 smb_fname_str_dbg(smb_fname
), flags
, (int)mode
, fsp
->fh
->fd
,
331 (fsp
->fh
->fd
== -1) ? strerror(errno
) : "" ));
336 /****************************************************************************
337 Close the file associated with a fsp.
338 ****************************************************************************/
340 NTSTATUS
fd_close(files_struct
*fsp
)
347 if (fsp
->fh
->fd
== -1) {
348 return NT_STATUS_OK
; /* What we used to call a stat open. */
350 if (fsp
->fh
->ref_count
> 1) {
351 return NT_STATUS_OK
; /* Shared handle. Only close last reference. */
354 ret
= SMB_VFS_CLOSE(fsp
);
357 return map_nt_error_from_unix(errno
);
362 /****************************************************************************
363 Change the ownership of a file to that of the parent directory.
364 Do this by fd if possible.
365 ****************************************************************************/
367 void change_file_owner_to_parent(connection_struct
*conn
,
368 const char *inherit_from_dir
,
371 struct smb_filename
*smb_fname_parent
= NULL
;
375 status
= create_synthetic_smb_fname(talloc_tos(), inherit_from_dir
,
376 NULL
, NULL
, &smb_fname_parent
);
377 if (!NT_STATUS_IS_OK(status
)) {
381 ret
= SMB_VFS_STAT(conn
, smb_fname_parent
);
383 DEBUG(0,("change_file_owner_to_parent: failed to stat parent "
384 "directory %s. Error was %s\n",
385 smb_fname_str_dbg(smb_fname_parent
),
387 TALLOC_FREE(smb_fname_parent
);
391 if (smb_fname_parent
->st
.st_ex_uid
== fsp
->fsp_name
->st
.st_ex_uid
) {
392 /* Already this uid - no need to change. */
393 DEBUG(10,("change_file_owner_to_parent: file %s "
394 "is already owned by uid %d\n",
396 (int)fsp
->fsp_name
->st
.st_ex_uid
));
397 TALLOC_FREE(smb_fname_parent
);
402 ret
= SMB_VFS_FCHOWN(fsp
, smb_fname_parent
->st
.st_ex_uid
, (gid_t
)-1);
405 DEBUG(0,("change_file_owner_to_parent: failed to fchown "
406 "file %s to parent directory uid %u. Error "
407 "was %s\n", fsp_str_dbg(fsp
),
408 (unsigned int)smb_fname_parent
->st
.st_ex_uid
,
411 DEBUG(10,("change_file_owner_to_parent: changed new file %s to "
412 "parent directory uid %u.\n", fsp_str_dbg(fsp
),
413 (unsigned int)smb_fname_parent
->st
.st_ex_uid
));
414 /* Ensure the uid entry is updated. */
415 fsp
->fsp_name
->st
.st_ex_uid
= smb_fname_parent
->st
.st_ex_uid
;
418 TALLOC_FREE(smb_fname_parent
);
421 NTSTATUS
change_dir_owner_to_parent(connection_struct
*conn
,
422 const char *inherit_from_dir
,
424 SMB_STRUCT_STAT
*psbuf
)
426 struct smb_filename
*smb_fname_parent
= NULL
;
427 struct smb_filename
*smb_fname_cwd
= NULL
;
428 char *saved_dir
= NULL
;
429 TALLOC_CTX
*ctx
= talloc_tos();
430 NTSTATUS status
= NT_STATUS_OK
;
433 status
= create_synthetic_smb_fname(ctx
, inherit_from_dir
, NULL
, NULL
,
435 if (!NT_STATUS_IS_OK(status
)) {
439 ret
= SMB_VFS_STAT(conn
, smb_fname_parent
);
441 status
= map_nt_error_from_unix(errno
);
442 DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
443 "directory %s. Error was %s\n",
444 smb_fname_str_dbg(smb_fname_parent
),
449 /* We've already done an lstat into psbuf, and we know it's a
450 directory. If we can cd into the directory and the dev/ino
451 are the same then we can safely chown without races as
452 we're locking the directory in place by being in it. This
453 should work on any UNIX (thanks tridge :-). JRA.
456 saved_dir
= vfs_GetWd(ctx
,conn
);
458 status
= map_nt_error_from_unix(errno
);
459 DEBUG(0,("change_dir_owner_to_parent: failed to get "
460 "current working directory. Error was %s\n",
465 /* Chdir into the new path. */
466 if (vfs_ChDir(conn
, fname
) == -1) {
467 status
= map_nt_error_from_unix(errno
);
468 DEBUG(0,("change_dir_owner_to_parent: failed to change "
469 "current working directory to %s. Error "
470 "was %s\n", fname
, strerror(errno
) ));
474 status
= create_synthetic_smb_fname(ctx
, ".", NULL
, NULL
,
476 if (!NT_STATUS_IS_OK(status
)) {
480 ret
= SMB_VFS_STAT(conn
, smb_fname_cwd
);
482 status
= map_nt_error_from_unix(errno
);
483 DEBUG(0,("change_dir_owner_to_parent: failed to stat "
484 "directory '.' (%s) Error was %s\n",
485 fname
, strerror(errno
)));
489 /* Ensure we're pointing at the same place. */
490 if (smb_fname_cwd
->st
.st_ex_dev
!= psbuf
->st_ex_dev
||
491 smb_fname_cwd
->st
.st_ex_ino
!= psbuf
->st_ex_ino
) {
492 DEBUG(0,("change_dir_owner_to_parent: "
493 "device/inode on directory %s changed. "
494 "Refusing to chown !\n", fname
));
495 status
= NT_STATUS_ACCESS_DENIED
;
499 if (smb_fname_parent
->st
.st_ex_uid
== smb_fname_cwd
->st
.st_ex_uid
) {
500 /* Already this uid - no need to change. */
501 DEBUG(10,("change_dir_owner_to_parent: directory %s "
502 "is already owned by uid %d\n",
504 (int)smb_fname_cwd
->st
.st_ex_uid
));
505 status
= NT_STATUS_OK
;
510 ret
= SMB_VFS_LCHOWN(conn
, ".", smb_fname_parent
->st
.st_ex_uid
,
514 status
= map_nt_error_from_unix(errno
);
515 DEBUG(10,("change_dir_owner_to_parent: failed to chown "
516 "directory %s to parent directory uid %u. "
517 "Error was %s\n", fname
,
518 (unsigned int)smb_fname_parent
->st
.st_ex_uid
,
521 DEBUG(10,("change_dir_owner_to_parent: changed ownership of new "
522 "directory %s to parent directory uid %u.\n",
523 fname
, (unsigned int)smb_fname_parent
->st
.st_ex_uid
));
524 /* Ensure the uid entry is updated. */
525 psbuf
->st_ex_uid
= smb_fname_parent
->st
.st_ex_uid
;
529 vfs_ChDir(conn
,saved_dir
);
531 TALLOC_FREE(smb_fname_parent
);
532 TALLOC_FREE(smb_fname_cwd
);
536 /****************************************************************************
538 ****************************************************************************/
540 static NTSTATUS
open_file(files_struct
*fsp
,
541 connection_struct
*conn
,
542 struct smb_request
*req
,
543 const char *parent_dir
,
546 uint32 access_mask
, /* client requested access mask. */
547 uint32 open_access_mask
) /* what we're actually using in the open. */
549 struct smb_filename
*smb_fname
= fsp
->fsp_name
;
550 NTSTATUS status
= NT_STATUS_OK
;
551 int accmode
= (flags
& O_ACCMODE
);
552 int local_flags
= flags
;
553 bool file_existed
= VALID_STAT(fsp
->fsp_name
->st
);
554 bool file_created
= false;
559 /* Check permissions */
562 * This code was changed after seeing a client open request
563 * containing the open mode of (DENY_WRITE/read-only) with
564 * the 'create if not exist' bit set. The previous code
565 * would fail to open the file read only on a read-only share
566 * as it was checking the flags parameter directly against O_RDONLY,
567 * this was failing as the flags parameter was set to O_RDONLY|O_CREAT.
571 if (!CAN_WRITE(conn
)) {
572 /* It's a read-only share - fail if we wanted to write. */
573 if(accmode
!= O_RDONLY
|| (flags
& O_TRUNC
) || (flags
& O_APPEND
)) {
574 DEBUG(3,("Permission denied opening %s\n",
575 smb_fname_str_dbg(smb_fname
)));
576 return NT_STATUS_ACCESS_DENIED
;
577 } else if(flags
& O_CREAT
) {
578 /* We don't want to write - but we must make sure that
579 O_CREAT doesn't create the file if we have write
580 access into the directory.
582 flags
&= ~(O_CREAT
|O_EXCL
);
583 local_flags
&= ~(O_CREAT
|O_EXCL
);
588 * This little piece of insanity is inspired by the
589 * fact that an NT client can open a file for O_RDONLY,
590 * but set the create disposition to FILE_EXISTS_TRUNCATE.
591 * If the client *can* write to the file, then it expects to
592 * truncate the file, even though it is opening for readonly.
593 * Quicken uses this stupid trick in backup file creation...
594 * Thanks *greatly* to "David W. Chapman Jr." <dwcjr@inethouston.net>
595 * for helping track this one down. It didn't bite us in 2.0.x
596 * as we always opened files read-write in that release. JRA.
599 if ((accmode
== O_RDONLY
) && ((flags
& O_TRUNC
) == O_TRUNC
)) {
600 DEBUG(10,("open_file: truncate requested on read-only open "
601 "for file %s\n", smb_fname_str_dbg(smb_fname
)));
602 local_flags
= (flags
& ~O_ACCMODE
)|O_RDWR
;
605 if ((open_access_mask
& (FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
|FILE_EXECUTE
)) ||
606 (!file_existed
&& (local_flags
& O_CREAT
)) ||
607 ((local_flags
& O_TRUNC
) == O_TRUNC
) ) {
611 * We can't actually truncate here as the file may be locked.
612 * open_file_ntcreate will take care of the truncate later. JRA.
615 local_flags
&= ~O_TRUNC
;
617 #if defined(O_NONBLOCK) && defined(S_ISFIFO)
619 * We would block on opening a FIFO with no one else on the
620 * other end. Do what we used to do and add O_NONBLOCK to the
624 if (file_existed
&& S_ISFIFO(smb_fname
->st
.st_ex_mode
)) {
625 local_flags
|= O_NONBLOCK
;
629 /* Don't create files with Microsoft wildcard characters. */
632 * wildcard characters are allowed in stream names
633 * only test the basefilename
635 wild
= fsp
->base_fsp
->fsp_name
->base_name
;
637 wild
= smb_fname
->base_name
;
639 if ((local_flags
& O_CREAT
) && !file_existed
&&
641 return NT_STATUS_OBJECT_NAME_INVALID
;
644 /* Can we access this file ? */
645 if (!fsp
->base_fsp
) {
646 /* Only do this check on non-stream open. */
648 status
= smbd_check_access_rights(conn
,
651 } else if (local_flags
& O_CREAT
){
652 status
= check_parent_access(conn
,
656 /* File didn't exist and no O_CREAT. */
657 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
659 if (!NT_STATUS_IS_OK(status
)) {
660 DEBUG(10,("open_file: "
664 "smbd_check_access_rights" :
665 "check_parent_access",
666 smb_fname_str_dbg(smb_fname
),
667 nt_errstr(status
) ));
672 /* Actually do the open */
673 status
= fd_open(conn
, fsp
, local_flags
, unx_mode
);
674 if (!NT_STATUS_IS_OK(status
)) {
675 DEBUG(3,("Error opening file %s (%s) (local_flags=%d) "
676 "(flags=%d)\n", smb_fname_str_dbg(smb_fname
),
677 nt_errstr(status
),local_flags
,flags
));
681 if ((local_flags
& O_CREAT
) && !file_existed
) {
686 fsp
->fh
->fd
= -1; /* What we used to call a stat open. */
688 /* File must exist for a stat open. */
689 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
692 status
= smbd_check_access_rights(conn
,
696 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
) &&
698 S_ISLNK(smb_fname
->st
.st_ex_mode
)) {
699 /* This is a POSIX stat open for delete
700 * or rename on a symlink that points
702 DEBUG(10,("open_file: allowing POSIX "
703 "open on bad symlink %s\n",
704 smb_fname_str_dbg(smb_fname
)));
705 status
= NT_STATUS_OK
;
708 if (!NT_STATUS_IS_OK(status
)) {
709 DEBUG(10,("open_file: "
710 "smbd_check_access_rights on file "
712 smb_fname_str_dbg(smb_fname
),
713 nt_errstr(status
) ));
721 if (fsp
->fh
->fd
== -1) {
722 ret
= SMB_VFS_STAT(conn
, smb_fname
);
724 ret
= SMB_VFS_FSTAT(fsp
, &smb_fname
->st
);
725 /* If we have an fd, this stat should succeed. */
727 DEBUG(0,("Error doing fstat on open file %s "
729 smb_fname_str_dbg(smb_fname
),
734 /* For a non-io open, this stat failing means file not found. JRA */
736 status
= map_nt_error_from_unix(errno
);
742 bool need_re_stat
= false;
743 /* Do all inheritance work after we've
744 done a successful stat call and filled
745 in the stat struct in fsp->fsp_name. */
747 /* Inherit the ACL if required */
748 if (lp_inherit_perms(SNUM(conn
))) {
749 inherit_access_posix_acl(conn
, parent_dir
,
750 smb_fname
->base_name
,
755 /* Change the owner if required. */
756 if (lp_inherit_owner(SNUM(conn
))) {
757 change_file_owner_to_parent(conn
, parent_dir
,
763 if (fsp
->fh
->fd
== -1) {
764 ret
= SMB_VFS_STAT(conn
, smb_fname
);
766 ret
= SMB_VFS_FSTAT(fsp
, &smb_fname
->st
);
767 /* If we have an fd, this stat should succeed. */
769 DEBUG(0,("Error doing fstat on open file %s "
771 smb_fname_str_dbg(smb_fname
),
777 notify_fname(conn
, NOTIFY_ACTION_ADDED
,
778 FILE_NOTIFY_CHANGE_FILE_NAME
,
779 smb_fname
->base_name
);
784 * POSIX allows read-only opens of directories. We don't
785 * want to do this (we use a different code path for this)
786 * so catch a directory open and return an EISDIR. JRA.
789 if(S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
792 return NT_STATUS_FILE_IS_A_DIRECTORY
;
795 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
796 fsp
->vuid
= req
? req
->vuid
: UID_FIELD_INVALID
;
797 fsp
->file_pid
= req
? req
->smbpid
: 0;
798 fsp
->can_lock
= True
;
799 fsp
->can_read
= ((access_mask
& FILE_READ_DATA
) != 0);
802 ((access_mask
& (FILE_WRITE_DATA
| FILE_APPEND_DATA
)) != 0);
803 fsp
->print_file
= NULL
;
804 fsp
->modified
= False
;
805 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
806 fsp
->is_directory
= False
;
807 if (conn
->aio_write_behind_list
&&
808 is_in_path(smb_fname
->base_name
, conn
->aio_write_behind_list
,
809 conn
->case_sensitive
)) {
810 fsp
->aio_write_behind
= True
;
813 fsp
->wcp
= NULL
; /* Write cache pointer. */
815 DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
816 conn
->session_info
->unix_info
->unix_name
,
817 smb_fname_str_dbg(smb_fname
),
818 BOOLSTR(fsp
->can_read
), BOOLSTR(fsp
->can_write
),
819 conn
->num_files_open
));
825 /****************************************************************************
826 Check if we can open a file with a share mode.
827 Returns True if conflict, False if not.
828 ****************************************************************************/
830 static bool share_conflict(struct share_mode_entry
*entry
,
834 DEBUG(10,("share_conflict: entry->access_mask = 0x%x, "
835 "entry->share_access = 0x%x, "
836 "entry->private_options = 0x%x\n",
837 (unsigned int)entry
->access_mask
,
838 (unsigned int)entry
->share_access
,
839 (unsigned int)entry
->private_options
));
841 DEBUG(10,("share_conflict: access_mask = 0x%x, share_access = 0x%x\n",
842 (unsigned int)access_mask
, (unsigned int)share_access
));
844 if ((entry
->access_mask
& (FILE_WRITE_DATA
|
848 DELETE_ACCESS
)) == 0) {
849 DEBUG(10,("share_conflict: No conflict due to "
850 "entry->access_mask = 0x%x\n",
851 (unsigned int)entry
->access_mask
));
855 if ((access_mask
& (FILE_WRITE_DATA
|
859 DELETE_ACCESS
)) == 0) {
860 DEBUG(10,("share_conflict: No conflict due to "
861 "access_mask = 0x%x\n",
862 (unsigned int)access_mask
));
866 #if 1 /* JRA TEST - Superdebug. */
867 #define CHECK_MASK(num, am, right, sa, share) \
868 DEBUG(10,("share_conflict: [%d] am (0x%x) & right (0x%x) = 0x%x\n", \
869 (unsigned int)(num), (unsigned int)(am), \
870 (unsigned int)(right), (unsigned int)(am)&(right) )); \
871 DEBUG(10,("share_conflict: [%d] sa (0x%x) & share (0x%x) = 0x%x\n", \
872 (unsigned int)(num), (unsigned int)(sa), \
873 (unsigned int)(share), (unsigned int)(sa)&(share) )); \
874 if (((am) & (right)) && !((sa) & (share))) { \
875 DEBUG(10,("share_conflict: check %d conflict am = 0x%x, right = 0x%x, \
876 sa = 0x%x, share = 0x%x\n", (num), (unsigned int)(am), (unsigned int)(right), (unsigned int)(sa), \
877 (unsigned int)(share) )); \
881 #define CHECK_MASK(num, am, right, sa, share) \
882 if (((am) & (right)) && !((sa) & (share))) { \
883 DEBUG(10,("share_conflict: check %d conflict am = 0x%x, right = 0x%x, \
884 sa = 0x%x, share = 0x%x\n", (num), (unsigned int)(am), (unsigned int)(right), (unsigned int)(sa), \
885 (unsigned int)(share) )); \
890 CHECK_MASK(1, entry
->access_mask
, FILE_WRITE_DATA
| FILE_APPEND_DATA
,
891 share_access
, FILE_SHARE_WRITE
);
892 CHECK_MASK(2, access_mask
, FILE_WRITE_DATA
| FILE_APPEND_DATA
,
893 entry
->share_access
, FILE_SHARE_WRITE
);
895 CHECK_MASK(3, entry
->access_mask
, FILE_READ_DATA
| FILE_EXECUTE
,
896 share_access
, FILE_SHARE_READ
);
897 CHECK_MASK(4, access_mask
, FILE_READ_DATA
| FILE_EXECUTE
,
898 entry
->share_access
, FILE_SHARE_READ
);
900 CHECK_MASK(5, entry
->access_mask
, DELETE_ACCESS
,
901 share_access
, FILE_SHARE_DELETE
);
902 CHECK_MASK(6, access_mask
, DELETE_ACCESS
,
903 entry
->share_access
, FILE_SHARE_DELETE
);
905 DEBUG(10,("share_conflict: No conflict.\n"));
909 #if defined(DEVELOPER)
910 static void validate_my_share_entries(struct smbd_server_connection
*sconn
,
912 struct share_mode_entry
*share_entry
)
914 struct server_id self
= messaging_server_id(sconn
->msg_ctx
);
917 if (!serverid_equal(&self
, &share_entry
->pid
)) {
921 if (is_deferred_open_entry(share_entry
) &&
922 !open_was_deferred(sconn
, share_entry
->op_mid
)) {
923 char *str
= talloc_asprintf(talloc_tos(),
924 "Got a deferred entry without a request: "
926 share_mode_str(talloc_tos(), num
, share_entry
));
930 if (!is_valid_share_mode_entry(share_entry
)) {
934 fsp
= file_find_dif(sconn
, share_entry
->id
,
935 share_entry
->share_file_id
);
937 DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
938 share_mode_str(talloc_tos(), num
, share_entry
) ));
939 smb_panic("validate_my_share_entries: Cannot match a "
940 "share entry with an open file\n");
943 if (is_deferred_open_entry(share_entry
)) {
947 if ((share_entry
->op_type
== NO_OPLOCK
) &&
948 (fsp
->oplock_type
== FAKE_LEVEL_II_OPLOCK
)) {
949 /* Someone has already written to it, but I haven't yet
954 if (((uint16
)fsp
->oplock_type
) != share_entry
->op_type
) {
963 DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
964 share_mode_str(talloc_tos(), num
, share_entry
) ));
965 str
= talloc_asprintf(talloc_tos(),
966 "validate_my_share_entries: "
967 "file %s, oplock_type = 0x%x, op_type = 0x%x\n",
968 fsp
->fsp_name
->base_name
,
969 (unsigned int)fsp
->oplock_type
,
970 (unsigned int)share_entry
->op_type
);
976 bool is_stat_open(uint32 access_mask
)
978 return (access_mask
&&
979 ((access_mask
& ~(SYNCHRONIZE_ACCESS
| FILE_READ_ATTRIBUTES
|
980 FILE_WRITE_ATTRIBUTES
))==0) &&
981 ((access_mask
& (SYNCHRONIZE_ACCESS
|FILE_READ_ATTRIBUTES
|
982 FILE_WRITE_ATTRIBUTES
)) != 0));
985 /****************************************************************************
986 Deal with share modes
987 Invarient: Share mode must be locked on entry and exit.
988 Returns -1 on error, or number of share modes on success (may be zero).
989 ****************************************************************************/
991 static NTSTATUS
open_mode_check(connection_struct
*conn
,
992 struct share_mode_lock
*lck
,
996 uint32 create_options
,
1001 if(lck
->data
->num_share_modes
== 0) {
1002 return NT_STATUS_OK
;
1005 /* A delete on close prohibits everything */
1007 if (is_delete_on_close_set(lck
, name_hash
)) {
1009 * Check the delete on close token
1010 * is valid. It could have been left
1011 * after a server crash.
1013 for(i
= 0; i
< lck
->data
->num_share_modes
; i
++) {
1014 if (!share_mode_stale_pid(lck
->data
, i
)) {
1016 *file_existed
= true;
1018 return NT_STATUS_DELETE_PENDING
;
1021 return NT_STATUS_OK
;
1024 if (is_stat_open(access_mask
)) {
1025 /* Stat open that doesn't trigger oplock breaks or share mode
1026 * checks... ! JRA. */
1027 return NT_STATUS_OK
;
1031 * Check if the share modes will give us access.
1034 #if defined(DEVELOPER)
1035 for(i
= 0; i
< lck
->data
->num_share_modes
; i
++) {
1036 validate_my_share_entries(conn
->sconn
, i
,
1037 &lck
->data
->share_modes
[i
]);
1041 if (!lp_share_modes(SNUM(conn
))) {
1042 return NT_STATUS_OK
;
1045 /* Now we check the share modes, after any oplock breaks. */
1046 for(i
= 0; i
< lck
->data
->num_share_modes
; i
++) {
1048 if (!is_valid_share_mode_entry(&lck
->data
->share_modes
[i
])) {
1052 /* someone else has a share lock on it, check to see if we can
1054 if (share_conflict(&lck
->data
->share_modes
[i
],
1055 access_mask
, share_access
)) {
1057 if (share_mode_stale_pid(lck
->data
, i
)) {
1061 *file_existed
= true;
1063 return NT_STATUS_SHARING_VIOLATION
;
1067 if (lck
->data
->num_share_modes
!= 0) {
1068 *file_existed
= true;
1071 return NT_STATUS_OK
;
1074 static bool is_delete_request(files_struct
*fsp
) {
1075 return ((fsp
->access_mask
== DELETE_ACCESS
) &&
1076 (fsp
->oplock_type
== NO_OPLOCK
));
1080 * Send a break message to the oplock holder and delay the open for
1084 static NTSTATUS
send_break_message(files_struct
*fsp
,
1085 struct share_mode_entry
*exclusive
,
1090 char msg
[MSG_SMB_SHARE_MODE_ENTRY_SIZE
];
1092 DEBUG(10, ("Sending break request to PID %s\n",
1093 procid_str_static(&exclusive
->pid
)));
1094 exclusive
->op_mid
= mid
;
1096 /* Create the message. */
1097 share_mode_entry_to_message(msg
, exclusive
);
1099 /* Add in the FORCE_OPLOCK_BREAK_TO_NONE bit in the message if set. We
1100 don't want this set in the share mode struct pointed to by lck. */
1102 if (oplock_request
& FORCE_OPLOCK_BREAK_TO_NONE
) {
1103 SSVAL(msg
,OP_BREAK_MSG_OP_TYPE_OFFSET
,
1104 exclusive
->op_type
| FORCE_OPLOCK_BREAK_TO_NONE
);
1107 status
= messaging_send_buf(fsp
->conn
->sconn
->msg_ctx
, exclusive
->pid
,
1108 MSG_SMB_BREAK_REQUEST
,
1110 MSG_SMB_SHARE_MODE_ENTRY_SIZE
);
1111 if (!NT_STATUS_IS_OK(status
)) {
1112 DEBUG(3, ("Could not send oplock break message: %s\n",
1113 nt_errstr(status
)));
1120 * Return share_mode_entry pointers for :
1121 * 1). Batch oplock entry.
1122 * 2). Batch or exclusive oplock entry (may be identical to #1).
1123 * bool have_level2_oplock
1124 * bool have_no_oplock.
1125 * Do internal consistency checks on the share mode for a file.
1128 static void find_oplock_types(files_struct
*fsp
,
1130 const struct share_mode_lock
*lck
,
1131 struct share_mode_entry
**pp_batch
,
1132 struct share_mode_entry
**pp_ex_or_batch
,
1134 bool *got_no_oplock
)
1139 *pp_ex_or_batch
= NULL
;
1140 *got_level2
= false;
1141 *got_no_oplock
= false;
1143 /* Ignore stat or internal opens, as is done in
1144 delay_for_batch_oplocks() and
1145 delay_for_exclusive_oplocks().
1147 if ((oplock_request
& INTERNAL_OPEN_ONLY
) || is_stat_open(fsp
->access_mask
)) {
1151 for (i
=0; i
<lck
->data
->num_share_modes
; i
++) {
1152 if (!is_valid_share_mode_entry(&lck
->data
->share_modes
[i
])) {
1156 if (lck
->data
->share_modes
[i
].op_type
== NO_OPLOCK
&&
1157 is_stat_open(lck
->data
->share_modes
[i
].access_mask
)) {
1158 /* We ignore stat opens in the table - they
1159 always have NO_OPLOCK and never get or
1160 cause breaks. JRA. */
1164 if (BATCH_OPLOCK_TYPE(lck
->data
->share_modes
[i
].op_type
)) {
1165 /* batch - can only be one. */
1166 if (share_mode_stale_pid(lck
->data
, i
)) {
1167 DEBUG(10, ("Found stale batch oplock\n"));
1170 if (*pp_ex_or_batch
|| *pp_batch
|| *got_level2
|| *got_no_oplock
) {
1171 smb_panic("Bad batch oplock entry.");
1173 *pp_batch
= &lck
->data
->share_modes
[i
];
1176 if (EXCLUSIVE_OPLOCK_TYPE(lck
->data
->share_modes
[i
].op_type
)) {
1177 if (share_mode_stale_pid(lck
->data
, i
)) {
1178 DEBUG(10, ("Found stale duplicate oplock\n"));
1181 /* Exclusive or batch - can only be one. */
1182 if (*pp_ex_or_batch
|| *got_level2
|| *got_no_oplock
) {
1183 smb_panic("Bad exclusive or batch oplock entry.");
1185 *pp_ex_or_batch
= &lck
->data
->share_modes
[i
];
1188 if (LEVEL_II_OPLOCK_TYPE(lck
->data
->share_modes
[i
].op_type
)) {
1189 if (*pp_batch
|| *pp_ex_or_batch
) {
1190 if (share_mode_stale_pid(lck
->data
, i
)) {
1191 DEBUG(10, ("Found stale LevelII "
1195 smb_panic("Bad levelII oplock entry.");
1200 if (lck
->data
->share_modes
[i
].op_type
== NO_OPLOCK
) {
1201 if (*pp_batch
|| *pp_ex_or_batch
) {
1202 if (share_mode_stale_pid(lck
->data
, i
)) {
1203 DEBUG(10, ("Found stale NO_OPLOCK "
1207 smb_panic("Bad no oplock entry.");
1209 *got_no_oplock
= true;
1214 static bool delay_for_batch_oplocks(files_struct
*fsp
,
1217 struct share_mode_entry
*batch_entry
)
1219 if ((oplock_request
& INTERNAL_OPEN_ONLY
) || is_stat_open(fsp
->access_mask
)) {
1222 if (batch_entry
== NULL
) {
1226 /* Found a batch oplock */
1227 send_break_message(fsp
, batch_entry
, mid
, oplock_request
);
1231 static bool delay_for_exclusive_oplocks(files_struct
*fsp
,
1234 struct share_mode_entry
*ex_entry
)
1238 if ((oplock_request
& INTERNAL_OPEN_ONLY
) || is_stat_open(fsp
->access_mask
)) {
1241 if (ex_entry
== NULL
) {
1245 /* Found an exclusive or batch oplock */
1247 delay_it
= is_delete_request(fsp
) ?
1248 BATCH_OPLOCK_TYPE(ex_entry
->op_type
) : true;
1254 send_break_message(fsp
, ex_entry
, mid
, oplock_request
);
1258 static bool file_has_brlocks(files_struct
*fsp
)
1260 struct byte_range_lock
*br_lck
;
1262 br_lck
= brl_get_locks_readonly(fsp
);
1266 return br_lck
->num_locks
> 0 ? true : false;
1269 static void grant_fsp_oplock_type(files_struct
*fsp
,
1271 bool got_level2_oplock
,
1272 bool got_a_none_oplock
)
1274 bool allow_level2
= (global_client_caps
& CAP_LEVEL_II_OPLOCKS
) &&
1275 lp_level2_oplocks(SNUM(fsp
->conn
));
1277 /* Start by granting what the client asked for,
1278 but ensure no SAMBA_PRIVATE bits can be set. */
1279 fsp
->oplock_type
= (oplock_request
& ~SAMBA_PRIVATE_OPLOCK_MASK
);
1281 if (oplock_request
& INTERNAL_OPEN_ONLY
) {
1282 /* No oplocks on internal open. */
1283 fsp
->oplock_type
= NO_OPLOCK
;
1284 DEBUG(10,("grant_fsp_oplock_type: oplock type 0x%x on file %s\n",
1285 fsp
->oplock_type
, fsp_str_dbg(fsp
)));
1289 if (lp_locking(fsp
->conn
->params
) && file_has_brlocks(fsp
)) {
1290 DEBUG(10,("grant_fsp_oplock_type: file %s has byte range locks\n",
1292 fsp
->oplock_type
= NO_OPLOCK
;
1295 if (is_stat_open(fsp
->access_mask
)) {
1296 /* Leave the value already set. */
1297 DEBUG(10,("grant_fsp_oplock_type: oplock type 0x%x on file %s\n",
1298 fsp
->oplock_type
, fsp_str_dbg(fsp
)));
1303 * Match what was requested (fsp->oplock_type) with
1304 * what was found in the existing share modes.
1307 if (got_a_none_oplock
) {
1308 fsp
->oplock_type
= NO_OPLOCK
;
1309 } else if (got_level2_oplock
) {
1310 if (fsp
->oplock_type
== NO_OPLOCK
||
1311 fsp
->oplock_type
== FAKE_LEVEL_II_OPLOCK
) {
1312 /* Store a level2 oplock, but don't tell the client */
1313 fsp
->oplock_type
= FAKE_LEVEL_II_OPLOCK
;
1315 fsp
->oplock_type
= LEVEL_II_OPLOCK
;
1318 /* All share_mode_entries are placeholders or deferred.
1319 * Silently upgrade to fake levelII if the client didn't
1320 * ask for an oplock. */
1321 if (fsp
->oplock_type
== NO_OPLOCK
) {
1322 /* Store a level2 oplock, but don't tell the client */
1323 fsp
->oplock_type
= FAKE_LEVEL_II_OPLOCK
;
1328 * Don't grant level2 to clients that don't want them
1329 * or if we've turned them off.
1331 if (fsp
->oplock_type
== LEVEL_II_OPLOCK
&& !allow_level2
) {
1332 fsp
->oplock_type
= FAKE_LEVEL_II_OPLOCK
;
1335 DEBUG(10,("grant_fsp_oplock_type: oplock type 0x%x on file %s\n",
1336 fsp
->oplock_type
, fsp_str_dbg(fsp
)));
1339 bool request_timed_out(struct timeval request_time
,
1340 struct timeval timeout
)
1342 struct timeval now
, end_time
;
1344 end_time
= timeval_sum(&request_time
, &timeout
);
1345 return (timeval_compare(&end_time
, &now
) < 0);
1348 /****************************************************************************
1349 Handle the 1 second delay in returning a SHARING_VIOLATION error.
1350 ****************************************************************************/
1352 static void defer_open(struct share_mode_lock
*lck
,
1353 struct timeval request_time
,
1354 struct timeval timeout
,
1355 struct smb_request
*req
,
1356 struct deferred_open_record
*state
)
1358 struct server_id self
= messaging_server_id(req
->sconn
->msg_ctx
);
1360 /* Paranoia check */
1365 for (i
=0; i
<lck
->data
->num_share_modes
; i
++) {
1366 struct share_mode_entry
*e
= &lck
->data
->share_modes
[i
];
1368 if (is_deferred_open_entry(e
) &&
1369 serverid_equal(&self
, &e
->pid
) &&
1370 (e
->op_mid
== req
->mid
)) {
1371 DEBUG(0, ("Trying to defer an already deferred "
1372 "request: mid=%llu, exiting\n",
1373 (unsigned long long)req
->mid
));
1374 exit_server("attempt to defer a deferred request");
1379 /* End paranoia check */
1381 DEBUG(10,("defer_open_sharing_error: time [%u.%06u] adding deferred "
1382 "open entry for mid %llu\n",
1383 (unsigned int)request_time
.tv_sec
,
1384 (unsigned int)request_time
.tv_usec
,
1385 (unsigned long long)req
->mid
));
1387 if (!push_deferred_open_message_smb(req
, request_time
, timeout
,
1388 state
->id
, (char *)state
, sizeof(*state
))) {
1389 exit_server("push_deferred_open_message_smb failed");
1392 add_deferred_open(lck
, req
->mid
, request_time
, self
, state
->id
);
1397 /****************************************************************************
1398 On overwrite open ensure that the attributes match.
1399 ****************************************************************************/
1401 bool open_match_attributes(connection_struct
*conn
,
1402 uint32 old_dos_attr
,
1403 uint32 new_dos_attr
,
1404 mode_t existing_unx_mode
,
1405 mode_t new_unx_mode
,
1406 mode_t
*returned_unx_mode
)
1408 uint32 noarch_old_dos_attr
, noarch_new_dos_attr
;
1410 noarch_old_dos_attr
= (old_dos_attr
& ~FILE_ATTRIBUTE_ARCHIVE
);
1411 noarch_new_dos_attr
= (new_dos_attr
& ~FILE_ATTRIBUTE_ARCHIVE
);
1413 if((noarch_old_dos_attr
== 0 && noarch_new_dos_attr
!= 0) ||
1414 (noarch_old_dos_attr
!= 0 && ((noarch_old_dos_attr
& noarch_new_dos_attr
) == noarch_old_dos_attr
))) {
1415 *returned_unx_mode
= new_unx_mode
;
1417 *returned_unx_mode
= (mode_t
)0;
1420 DEBUG(10,("open_match_attributes: old_dos_attr = 0x%x, "
1421 "existing_unx_mode = 0%o, new_dos_attr = 0x%x "
1422 "returned_unx_mode = 0%o\n",
1423 (unsigned int)old_dos_attr
,
1424 (unsigned int)existing_unx_mode
,
1425 (unsigned int)new_dos_attr
,
1426 (unsigned int)*returned_unx_mode
));
1428 /* If we're mapping SYSTEM and HIDDEN ensure they match. */
1429 if (lp_map_system(SNUM(conn
)) || lp_store_dos_attributes(SNUM(conn
))) {
1430 if ((old_dos_attr
& FILE_ATTRIBUTE_SYSTEM
) &&
1431 !(new_dos_attr
& FILE_ATTRIBUTE_SYSTEM
)) {
1435 if (lp_map_hidden(SNUM(conn
)) || lp_store_dos_attributes(SNUM(conn
))) {
1436 if ((old_dos_attr
& FILE_ATTRIBUTE_HIDDEN
) &&
1437 !(new_dos_attr
& FILE_ATTRIBUTE_HIDDEN
)) {
1444 /****************************************************************************
1445 Special FCB or DOS processing in the case of a sharing violation.
1446 Try and find a duplicated file handle.
1447 ****************************************************************************/
1449 static NTSTATUS
fcb_or_dos_open(struct smb_request
*req
,
1450 connection_struct
*conn
,
1451 files_struct
*fsp_to_dup_into
,
1452 const struct smb_filename
*smb_fname
,
1457 uint32 share_access
,
1458 uint32 create_options
)
1462 DEBUG(5,("fcb_or_dos_open: attempting old open semantics for "
1463 "file %s.\n", smb_fname_str_dbg(smb_fname
)));
1465 for(fsp
= file_find_di_first(conn
->sconn
, id
); fsp
;
1466 fsp
= file_find_di_next(fsp
)) {
1468 DEBUG(10,("fcb_or_dos_open: checking file %s, fd = %d, "
1469 "vuid = %llu, file_pid = %u, private_options = 0x%x "
1470 "access_mask = 0x%x\n", fsp_str_dbg(fsp
),
1471 fsp
->fh
->fd
, (unsigned long long)fsp
->vuid
,
1472 (unsigned int)fsp
->file_pid
,
1473 (unsigned int)fsp
->fh
->private_options
,
1474 (unsigned int)fsp
->access_mask
));
1476 if (fsp
->fh
->fd
!= -1 &&
1477 fsp
->vuid
== vuid
&&
1478 fsp
->file_pid
== file_pid
&&
1479 (fsp
->fh
->private_options
& (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS
|
1480 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB
)) &&
1481 (fsp
->access_mask
& FILE_WRITE_DATA
) &&
1482 strequal(fsp
->fsp_name
->base_name
, smb_fname
->base_name
) &&
1483 strequal(fsp
->fsp_name
->stream_name
,
1484 smb_fname
->stream_name
)) {
1485 DEBUG(10,("fcb_or_dos_open: file match\n"));
1491 return NT_STATUS_NOT_FOUND
;
1494 /* quite an insane set of semantics ... */
1495 if (is_executable(smb_fname
->base_name
) &&
1496 (fsp
->fh
->private_options
& NTCREATEX_OPTIONS_PRIVATE_DENY_DOS
)) {
1497 DEBUG(10,("fcb_or_dos_open: file fail due to is_executable.\n"));
1498 return NT_STATUS_INVALID_PARAMETER
;
1501 /* We need to duplicate this fsp. */
1502 return dup_file_fsp(req
, fsp
, access_mask
, share_access
,
1503 create_options
, fsp_to_dup_into
);
1506 static void schedule_defer_open(struct share_mode_lock
*lck
,
1507 struct timeval request_time
,
1508 struct smb_request
*req
)
1510 struct deferred_open_record state
;
1512 /* This is a relative time, added to the absolute
1513 request_time value to get the absolute timeout time.
1514 Note that if this is the second or greater time we enter
1515 this codepath for this particular request mid then
1516 request_time is left as the absolute time of the *first*
1517 time this request mid was processed. This is what allows
1518 the request to eventually time out. */
1520 struct timeval timeout
;
1522 /* Normally the smbd we asked should respond within
1523 * OPLOCK_BREAK_TIMEOUT seconds regardless of whether
1524 * the client did, give twice the timeout as a safety
1525 * measure here in case the other smbd is stuck
1526 * somewhere else. */
1528 timeout
= timeval_set(OPLOCK_BREAK_TIMEOUT
*2, 0);
1530 /* Nothing actually uses state.delayed_for_oplocks
1531 but it's handy to differentiate in debug messages
1532 between a 30 second delay due to oplock break, and
1533 a 1 second delay for share mode conflicts. */
1535 state
.delayed_for_oplocks
= True
;
1536 state
.async_open
= false;
1537 state
.id
= lck
->data
->id
;
1539 if (!request_timed_out(request_time
, timeout
)) {
1540 defer_open(lck
, request_time
, timeout
, req
, &state
);
1544 /****************************************************************************
1545 Work out what access_mask to use from what the client sent us.
1546 ****************************************************************************/
1548 static NTSTATUS
smbd_calculate_maximum_allowed_access(
1549 connection_struct
*conn
,
1550 const struct smb_filename
*smb_fname
,
1551 uint32_t *p_access_mask
)
1553 struct security_descriptor
*sd
;
1554 uint32_t access_granted
;
1557 if (get_current_uid(conn
) == (uid_t
)0) {
1558 *p_access_mask
|= FILE_GENERIC_ALL
;
1559 return NT_STATUS_OK
;
1562 status
= SMB_VFS_GET_NT_ACL(conn
, smb_fname
->base_name
,
1567 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1569 * File did not exist
1571 *p_access_mask
= FILE_GENERIC_ALL
;
1572 return NT_STATUS_OK
;
1574 if (!NT_STATUS_IS_OK(status
)) {
1575 DEBUG(10,("smbd_calculate_access_mask: "
1576 "Could not get acl on file %s: %s\n",
1577 smb_fname_str_dbg(smb_fname
),
1578 nt_errstr(status
)));
1579 return NT_STATUS_ACCESS_DENIED
;
1583 * Never test FILE_READ_ATTRIBUTES. se_access_check()
1584 * also takes care of owner WRITE_DAC and READ_CONTROL.
1586 status
= se_access_check(sd
,
1587 get_current_nttok(conn
),
1588 (*p_access_mask
& ~FILE_READ_ATTRIBUTES
),
1593 if (!NT_STATUS_IS_OK(status
)) {
1594 DEBUG(10, ("smbd_calculate_access_mask: "
1595 "Access denied on file %s: "
1596 "when calculating maximum access\n",
1597 smb_fname_str_dbg(smb_fname
)));
1598 return NT_STATUS_ACCESS_DENIED
;
1600 *p_access_mask
= (access_granted
| FILE_READ_ATTRIBUTES
);
1601 return NT_STATUS_OK
;
1604 NTSTATUS
smbd_calculate_access_mask(connection_struct
*conn
,
1605 const struct smb_filename
*smb_fname
,
1606 uint32_t access_mask
,
1607 uint32_t *access_mask_out
)
1610 uint32_t orig_access_mask
= access_mask
;
1611 uint32_t rejected_share_access
;
1614 * Convert GENERIC bits to specific bits.
1617 se_map_generic(&access_mask
, &file_generic_mapping
);
1619 /* Calculate MAXIMUM_ALLOWED_ACCESS if requested. */
1620 if (access_mask
& MAXIMUM_ALLOWED_ACCESS
) {
1622 status
= smbd_calculate_maximum_allowed_access(
1623 conn
, smb_fname
, &access_mask
);
1625 if (!NT_STATUS_IS_OK(status
)) {
1629 access_mask
&= conn
->share_access
;
1632 rejected_share_access
= access_mask
& ~(conn
->share_access
);
1634 if (rejected_share_access
) {
1635 DEBUG(10, ("smbd_calculate_access_mask: Access denied on "
1636 "file %s: rejected by share access mask[0x%08X] "
1637 "orig[0x%08X] mapped[0x%08X] reject[0x%08X]\n",
1638 smb_fname_str_dbg(smb_fname
),
1640 orig_access_mask
, access_mask
,
1641 rejected_share_access
));
1642 return NT_STATUS_ACCESS_DENIED
;
1645 *access_mask_out
= access_mask
;
1646 return NT_STATUS_OK
;
1649 /****************************************************************************
1650 Remove the deferred open entry under lock.
1651 ****************************************************************************/
1653 void remove_deferred_open_entry(struct file_id id
, uint64_t mid
,
1654 struct server_id pid
)
1656 struct share_mode_lock
*lck
= get_existing_share_mode_lock(
1659 DEBUG(0, ("could not get share mode lock\n"));
1662 del_deferred_open_entry(lck
, mid
, pid
);
1666 /****************************************************************************
1667 Open a file with a share mode. Passed in an already created files_struct *.
1668 ****************************************************************************/
1670 static NTSTATUS
open_file_ntcreate(connection_struct
*conn
,
1671 struct smb_request
*req
,
1672 uint32 access_mask
, /* access bits (FILE_READ_DATA etc.) */
1673 uint32 share_access
, /* share constants (FILE_SHARE_READ etc) */
1674 uint32 create_disposition
, /* FILE_OPEN_IF etc. */
1675 uint32 create_options
, /* options such as delete on close. */
1676 uint32 new_dos_attributes
, /* attributes used for new file. */
1677 int oplock_request
, /* internal Samba oplock codes. */
1678 /* Information (FILE_EXISTS etc.) */
1679 uint32_t private_flags
, /* Samba specific flags. */
1683 struct smb_filename
*smb_fname
= fsp
->fsp_name
;
1686 bool file_existed
= VALID_STAT(smb_fname
->st
);
1687 bool def_acl
= False
;
1688 bool posix_open
= False
;
1689 bool new_file_created
= False
;
1690 bool clear_ads
= false;
1691 NTSTATUS fsp_open
= NT_STATUS_ACCESS_DENIED
;
1692 mode_t new_unx_mode
= (mode_t
)0;
1693 mode_t unx_mode
= (mode_t
)0;
1695 uint32 existing_dos_attributes
= 0;
1696 struct timeval request_time
= timeval_zero();
1697 struct share_mode_lock
*lck
= NULL
;
1698 uint32 open_access_mask
= access_mask
;
1702 if (conn
->printer
) {
1704 * Printers are handled completely differently.
1705 * Most of the passed parameters are ignored.
1709 *pinfo
= FILE_WAS_CREATED
;
1712 DEBUG(10, ("open_file_ntcreate: printer open fname=%s\n",
1713 smb_fname_str_dbg(smb_fname
)));
1716 DEBUG(0,("open_file_ntcreate: printer open without "
1717 "an SMB request!\n"));
1718 return NT_STATUS_INTERNAL_ERROR
;
1721 return print_spool_open(fsp
, smb_fname
->base_name
,
1725 if (!parent_dirname(talloc_tos(), smb_fname
->base_name
, &parent_dir
,
1727 return NT_STATUS_NO_MEMORY
;
1730 if (new_dos_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1732 unx_mode
= (mode_t
)(new_dos_attributes
& ~FILE_FLAG_POSIX_SEMANTICS
);
1733 new_dos_attributes
= 0;
1735 /* Windows allows a new file to be created and
1736 silently removes a FILE_ATTRIBUTE_DIRECTORY
1737 sent by the client. Do the same. */
1739 new_dos_attributes
&= ~FILE_ATTRIBUTE_DIRECTORY
;
1741 /* We add FILE_ATTRIBUTE_ARCHIVE to this as this mode is only used if the file is
1743 unx_mode
= unix_mode(conn
, new_dos_attributes
| FILE_ATTRIBUTE_ARCHIVE
,
1744 smb_fname
, parent_dir
);
1747 DEBUG(10, ("open_file_ntcreate: fname=%s, dos_attrs=0x%x "
1748 "access_mask=0x%x share_access=0x%x "
1749 "create_disposition = 0x%x create_options=0x%x "
1750 "unix mode=0%o oplock_request=%d private_flags = 0x%x\n",
1751 smb_fname_str_dbg(smb_fname
), new_dos_attributes
,
1752 access_mask
, share_access
, create_disposition
,
1753 create_options
, (unsigned int)unx_mode
, oplock_request
,
1754 (unsigned int)private_flags
));
1756 if ((req
== NULL
) && ((oplock_request
& INTERNAL_OPEN_ONLY
) == 0)) {
1757 DEBUG(0, ("No smb request but not an internal only open!\n"));
1758 return NT_STATUS_INTERNAL_ERROR
;
1762 * Only non-internal opens can be deferred at all
1767 if (get_deferred_open_message_state(req
,
1771 struct deferred_open_record
*state
= (struct deferred_open_record
*)ptr
;
1772 /* Remember the absolute time of the original
1773 request with this mid. We'll use it later to
1774 see if this has timed out. */
1776 /* Remove the deferred open entry under lock. */
1777 remove_deferred_open_entry(
1778 state
->id
, req
->mid
,
1779 messaging_server_id(req
->sconn
->msg_ctx
));
1781 /* Ensure we don't reprocess this message. */
1782 remove_deferred_open_message_smb(req
->sconn
, req
->mid
);
1787 new_dos_attributes
&= SAMBA_ATTRIBUTES_MASK
;
1789 existing_dos_attributes
= dos_mode(conn
, smb_fname
);
1793 /* ignore any oplock requests if oplocks are disabled */
1794 if (!lp_oplocks(SNUM(conn
)) ||
1795 IS_VETO_OPLOCK_PATH(conn
, smb_fname
->base_name
)) {
1796 /* Mask off everything except the private Samba bits. */
1797 oplock_request
&= SAMBA_PRIVATE_OPLOCK_MASK
;
1800 /* this is for OS/2 long file names - say we don't support them */
1801 if (!lp_posix_pathnames() && strstr(smb_fname
->base_name
,".+,;=[].")) {
1802 /* OS/2 Workplace shell fix may be main code stream in a later
1804 DEBUG(5,("open_file_ntcreate: OS/2 long filenames are not "
1806 if (use_nt_status()) {
1807 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1809 return NT_STATUS_DOS(ERRDOS
, ERRcannotopen
);
1812 switch( create_disposition
) {
1814 * Currently we're using FILE_SUPERSEDE as the same as
1815 * FILE_OVERWRITE_IF but they really are
1816 * different. FILE_SUPERSEDE deletes an existing file
1817 * (requiring delete access) then recreates it.
1819 case FILE_SUPERSEDE
:
1820 /* If file exists replace/overwrite. If file doesn't
1822 flags2
|= (O_CREAT
| O_TRUNC
);
1826 case FILE_OVERWRITE_IF
:
1827 /* If file exists replace/overwrite. If file doesn't
1829 flags2
|= (O_CREAT
| O_TRUNC
);
1834 /* If file exists open. If file doesn't exist error. */
1835 if (!file_existed
) {
1836 DEBUG(5,("open_file_ntcreate: FILE_OPEN "
1837 "requested for file %s and file "
1839 smb_fname_str_dbg(smb_fname
)));
1841 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1845 case FILE_OVERWRITE
:
1846 /* If file exists overwrite. If file doesn't exist
1848 if (!file_existed
) {
1849 DEBUG(5,("open_file_ntcreate: FILE_OVERWRITE "
1850 "requested for file %s and file "
1852 smb_fname_str_dbg(smb_fname
) ));
1854 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1861 /* If file exists error. If file doesn't exist
1864 DEBUG(5,("open_file_ntcreate: FILE_CREATE "
1865 "requested for file %s and file "
1866 "already exists.\n",
1867 smb_fname_str_dbg(smb_fname
)));
1868 if (S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
1873 return map_nt_error_from_unix(errno
);
1875 flags2
|= (O_CREAT
|O_EXCL
);
1879 /* If file exists open. If file doesn't exist
1885 return NT_STATUS_INVALID_PARAMETER
;
1888 /* We only care about matching attributes on file exists and
1891 if (!posix_open
&& file_existed
&& ((create_disposition
== FILE_OVERWRITE
) ||
1892 (create_disposition
== FILE_OVERWRITE_IF
))) {
1893 if (!open_match_attributes(conn
, existing_dos_attributes
,
1895 smb_fname
->st
.st_ex_mode
,
1896 unx_mode
, &new_unx_mode
)) {
1897 DEBUG(5,("open_file_ntcreate: attributes missmatch "
1898 "for file %s (%x %x) (0%o, 0%o)\n",
1899 smb_fname_str_dbg(smb_fname
),
1900 existing_dos_attributes
,
1902 (unsigned int)smb_fname
->st
.st_ex_mode
,
1903 (unsigned int)unx_mode
));
1905 return NT_STATUS_ACCESS_DENIED
;
1909 status
= smbd_calculate_access_mask(conn
, smb_fname
,
1912 if (!NT_STATUS_IS_OK(status
)) {
1913 DEBUG(10, ("open_file_ntcreate: smbd_calculate_access_mask "
1914 "on file %s returned %s\n",
1915 smb_fname_str_dbg(smb_fname
), nt_errstr(status
)));
1919 open_access_mask
= access_mask
;
1921 if ((flags2
& O_TRUNC
) || (oplock_request
& FORCE_OPLOCK_BREAK_TO_NONE
)) {
1922 open_access_mask
|= FILE_WRITE_DATA
; /* This will cause oplock breaks. */
1925 DEBUG(10, ("open_file_ntcreate: fname=%s, after mapping "
1926 "access_mask=0x%x\n", smb_fname_str_dbg(smb_fname
),
1930 * Note that we ignore the append flag as append does not
1931 * mean the same thing under DOS and Unix.
1934 if ((access_mask
& (FILE_WRITE_DATA
| FILE_APPEND_DATA
)) ||
1935 (oplock_request
& FORCE_OPLOCK_BREAK_TO_NONE
)) {
1936 /* DENY_DOS opens are always underlying read-write on the
1937 file handle, no matter what the requested access mask
1939 if ((private_flags
& NTCREATEX_OPTIONS_PRIVATE_DENY_DOS
) ||
1940 access_mask
& (FILE_READ_ATTRIBUTES
|FILE_READ_DATA
|FILE_READ_EA
|FILE_EXECUTE
)) {
1950 * Currently we only look at FILE_WRITE_THROUGH for create options.
1954 if ((create_options
& FILE_WRITE_THROUGH
) && lp_strict_sync(SNUM(conn
))) {
1959 if (posix_open
&& (access_mask
& FILE_APPEND_DATA
)) {
1963 if (!posix_open
&& !CAN_WRITE(conn
)) {
1965 * We should really return a permission denied error if either
1966 * O_CREAT or O_TRUNC are set, but for compatibility with
1967 * older versions of Samba we just AND them out.
1969 flags2
&= ~(O_CREAT
|O_TRUNC
);
1973 * Ensure we can't write on a read-only share or file.
1976 if (flags
!= O_RDONLY
&& file_existed
&&
1977 (!CAN_WRITE(conn
) || IS_DOS_READONLY(existing_dos_attributes
))) {
1978 DEBUG(5,("open_file_ntcreate: write access requested for "
1979 "file %s on read only %s\n",
1980 smb_fname_str_dbg(smb_fname
),
1981 !CAN_WRITE(conn
) ? "share" : "file" ));
1983 return NT_STATUS_ACCESS_DENIED
;
1986 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
1987 fsp
->share_access
= share_access
;
1988 fsp
->fh
->private_options
= private_flags
;
1989 fsp
->access_mask
= open_access_mask
; /* We change this to the
1990 * requested access_mask after
1991 * the open is done. */
1992 fsp
->posix_open
= posix_open
;
1994 /* Ensure no SAMBA_PRIVATE bits can be set. */
1995 fsp
->oplock_type
= (oplock_request
& ~SAMBA_PRIVATE_OPLOCK_MASK
);
1997 if (timeval_is_zero(&request_time
)) {
1998 request_time
= fsp
->open_time
;
2002 struct share_mode_entry
*batch_entry
= NULL
;
2003 struct share_mode_entry
*exclusive_entry
= NULL
;
2004 bool got_level2_oplock
= false;
2005 bool got_a_none_oplock
= false;
2008 struct timespec old_write_time
= smb_fname
->st
.st_ex_mtime
;
2009 id
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
2011 lck
= get_share_mode_lock(talloc_tos(), id
,
2013 smb_fname
, &old_write_time
);
2015 DEBUG(0, ("Could not get share mode lock\n"));
2016 return NT_STATUS_SHARING_VIOLATION
;
2019 /* Get the types we need to examine. */
2020 find_oplock_types(fsp
,
2026 &got_a_none_oplock
);
2028 /* First pass - send break only on batch oplocks. */
2029 if ((req
!= NULL
) &&
2030 delay_for_batch_oplocks(fsp
,
2034 schedule_defer_open(lck
, request_time
, req
);
2036 return NT_STATUS_SHARING_VIOLATION
;
2039 /* Use the client requested access mask here, not the one we
2041 status
= open_mode_check(conn
, lck
, fsp
->name_hash
,
2042 access_mask
, share_access
,
2043 create_options
, &file_existed
);
2045 if (NT_STATUS_IS_OK(status
)) {
2046 /* We might be going to allow this open. Check oplock
2048 /* Second pass - send break for both batch or
2049 * exclusive oplocks. */
2050 if ((req
!= NULL
) &&
2051 delay_for_exclusive_oplocks(
2056 schedule_defer_open(lck
, request_time
, req
);
2058 return NT_STATUS_SHARING_VIOLATION
;
2062 if (NT_STATUS_EQUAL(status
, NT_STATUS_DELETE_PENDING
)) {
2063 /* DELETE_PENDING is not deferred for a second */
2068 grant_fsp_oplock_type(fsp
,
2073 if (!NT_STATUS_IS_OK(status
)) {
2074 uint32 can_access_mask
;
2075 bool can_access
= True
;
2077 SMB_ASSERT(NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
));
2079 /* Check if this can be done with the deny_dos and fcb
2082 (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS
|
2083 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB
)) {
2085 DEBUG(0, ("DOS open without an SMB "
2088 return NT_STATUS_INTERNAL_ERROR
;
2091 /* Use the client requested access mask here,
2092 * not the one we open with. */
2093 status
= fcb_or_dos_open(req
,
2104 if (NT_STATUS_IS_OK(status
)) {
2107 *pinfo
= FILE_WAS_OPENED
;
2109 return NT_STATUS_OK
;
2114 * This next line is a subtlety we need for
2115 * MS-Access. If a file open will fail due to share
2116 * permissions and also for security (access) reasons,
2117 * we need to return the access failed error, not the
2118 * share error. We can't open the file due to kernel
2119 * oplock deadlock (it's possible we failed above on
2120 * the open_mode_check()) so use a userspace check.
2123 if (flags
& O_RDWR
) {
2124 can_access_mask
= FILE_READ_DATA
|FILE_WRITE_DATA
;
2125 } else if (flags
& O_WRONLY
) {
2126 can_access_mask
= FILE_WRITE_DATA
;
2128 can_access_mask
= FILE_READ_DATA
;
2131 if (((can_access_mask
& FILE_WRITE_DATA
) &&
2132 !CAN_WRITE(conn
)) ||
2133 !NT_STATUS_IS_OK(smbd_check_access_rights(conn
,
2134 smb_fname
, can_access_mask
))) {
2139 * If we're returning a share violation, ensure we
2140 * cope with the braindead 1 second delay.
2143 if (!(oplock_request
& INTERNAL_OPEN_ONLY
) &&
2144 lp_defer_sharing_violations()) {
2145 struct timeval timeout
;
2146 struct deferred_open_record state
;
2149 /* this is a hack to speed up torture tests
2151 timeout_usecs
= lp_parm_int(SNUM(conn
),
2152 "smbd","sharedelay",
2153 SHARING_VIOLATION_USEC_WAIT
);
2155 /* This is a relative time, added to the absolute
2156 request_time value to get the absolute timeout time.
2157 Note that if this is the second or greater time we enter
2158 this codepath for this particular request mid then
2159 request_time is left as the absolute time of the *first*
2160 time this request mid was processed. This is what allows
2161 the request to eventually time out. */
2163 timeout
= timeval_set(0, timeout_usecs
);
2165 /* Nothing actually uses state.delayed_for_oplocks
2166 but it's handy to differentiate in debug messages
2167 between a 30 second delay due to oplock break, and
2168 a 1 second delay for share mode conflicts. */
2170 state
.delayed_for_oplocks
= False
;
2171 state
.async_open
= false;
2175 && !request_timed_out(request_time
,
2177 defer_open(lck
, request_time
, timeout
,
2185 * We have detected a sharing violation here
2186 * so return the correct error code
2188 status
= NT_STATUS_SHARING_VIOLATION
;
2190 status
= NT_STATUS_ACCESS_DENIED
;
2196 * We exit this block with the share entry *locked*.....
2200 SMB_ASSERT(!file_existed
|| (lck
!= NULL
));
2203 * Ensure we pay attention to default ACLs on directories if required.
2206 if ((flags2
& O_CREAT
) && lp_inherit_acls(SNUM(conn
)) &&
2207 (def_acl
= directory_has_default_acl(conn
, parent_dir
))) {
2208 unx_mode
= (0777 & lp_create_mask(SNUM(conn
)));
2211 DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o, "
2212 "access_mask = 0x%x, open_access_mask = 0x%x\n",
2213 (unsigned int)flags
, (unsigned int)flags2
,
2214 (unsigned int)unx_mode
, (unsigned int)access_mask
,
2215 (unsigned int)open_access_mask
));
2218 * open_file strips any O_TRUNC flags itself.
2221 fsp_open
= open_file(fsp
, conn
, req
, parent_dir
,
2222 flags
|flags2
, unx_mode
, access_mask
,
2225 if (!NT_STATUS_IS_OK(fsp_open
)) {
2230 if (!file_existed
) {
2231 struct share_mode_entry
*batch_entry
= NULL
;
2232 struct share_mode_entry
*exclusive_entry
= NULL
;
2233 bool got_level2_oplock
= false;
2234 bool got_a_none_oplock
= false;
2235 struct timespec old_write_time
= smb_fname
->st
.st_ex_mtime
;
2238 * Deal with the race condition where two smbd's detect the
2239 * file doesn't exist and do the create at the same time. One
2240 * of them will win and set a share mode, the other (ie. this
2241 * one) should check if the requested share mode for this
2242 * create is allowed.
2246 * Now the file exists and fsp is successfully opened,
2247 * fsp->dev and fsp->inode are valid and should replace the
2248 * dev=0,inode=0 from a non existent file. Spotted by
2249 * Nadav Danieli <nadavd@exanet.com>. JRA.
2254 lck
= get_share_mode_lock(talloc_tos(), id
,
2256 smb_fname
, &old_write_time
);
2259 DEBUG(0, ("open_file_ntcreate: Could not get share "
2260 "mode lock for %s\n",
2261 smb_fname_str_dbg(smb_fname
)));
2263 return NT_STATUS_SHARING_VIOLATION
;
2266 /* Get the types we need to examine. */
2267 find_oplock_types(fsp
,
2273 &got_a_none_oplock
);
2275 /* First pass - send break only on batch oplocks. */
2276 if ((req
!= NULL
) &&
2277 delay_for_batch_oplocks(fsp
,
2281 schedule_defer_open(lck
, request_time
, req
);
2284 return NT_STATUS_SHARING_VIOLATION
;
2287 status
= open_mode_check(conn
, lck
, fsp
->name_hash
,
2288 access_mask
, share_access
,
2289 create_options
, &file_existed
);
2291 if (NT_STATUS_IS_OK(status
)) {
2292 /* We might be going to allow this open. Check oplock
2294 /* Second pass - send break for both batch or
2295 * exclusive oplocks. */
2296 if ((req
!= NULL
) &&
2297 delay_for_exclusive_oplocks(
2302 schedule_defer_open(lck
, request_time
, req
);
2305 return NT_STATUS_SHARING_VIOLATION
;
2309 if (!NT_STATUS_IS_OK(status
)) {
2310 struct deferred_open_record state
;
2312 state
.delayed_for_oplocks
= False
;
2313 state
.async_open
= false;
2316 /* Do it all over again immediately. In the second
2317 * round we will find that the file existed and handle
2318 * the DELETE_PENDING and FCB cases correctly. No need
2319 * to duplicate the code here. Essentially this is a
2320 * "goto top of this function", but don't tell
2324 defer_open(lck
, request_time
, timeval_zero(),
2332 grant_fsp_oplock_type(fsp
,
2338 * We exit this block with the share entry *locked*.....
2343 SMB_ASSERT(lck
!= NULL
);
2345 /* Delete streams if create_disposition requires it */
2346 if (file_existed
&& clear_ads
&&
2347 !is_ntfs_stream_smb_fname(smb_fname
)) {
2348 status
= delete_all_streams(conn
, smb_fname
->base_name
);
2349 if (!NT_STATUS_IS_OK(status
)) {
2356 /* note that we ignore failure for the following. It is
2357 basically a hack for NFS, and NFS will never set one of
2358 these only read them. Nobody but Samba can ever set a deny
2359 mode and we have already checked our more authoritative
2360 locking database for permission to set this deny mode. If
2361 the kernel refuses the operations then the kernel is wrong.
2362 note that GPFS supports it as well - jmcd */
2364 if (fsp
->fh
->fd
!= -1) {
2366 ret_flock
= SMB_VFS_KERNEL_FLOCK(fsp
, share_access
, access_mask
);
2367 if(ret_flock
== -1 ){
2372 return NT_STATUS_SHARING_VIOLATION
;
2377 * At this point onwards, we can guarentee that the share entry
2378 * is locked, whether we created the file or not, and that the
2379 * deny mode is compatible with all current opens.
2383 * If requested, truncate the file.
2386 if (file_existed
&& (flags2
&O_TRUNC
)) {
2388 * We are modifying the file after open - update the stat
2391 if ((SMB_VFS_FTRUNCATE(fsp
, 0) == -1) ||
2392 (SMB_VFS_FSTAT(fsp
, &smb_fname
->st
)==-1)) {
2393 status
= map_nt_error_from_unix(errno
);
2401 * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
2402 * but we don't have to store this - just ignore it on access check.
2404 if (conn
->sconn
->using_smb2
) {
2406 * SMB2 doesn't return it (according to Microsoft tests).
2407 * Test Case: TestSuite_ScenarioNo009GrantedAccessTestS0
2408 * File created with access = 0x7 (Read, Write, Delete)
2409 * Query Info on file returns 0x87 (Read, Write, Delete, Read Attributes)
2411 fsp
->access_mask
= access_mask
;
2413 /* But SMB1 does. */
2414 fsp
->access_mask
= access_mask
| FILE_READ_ATTRIBUTES
;
2418 /* stat opens on existing files don't get oplocks. */
2419 if (is_stat_open(open_access_mask
)) {
2420 fsp
->oplock_type
= NO_OPLOCK
;
2423 if (flags2
& O_TRUNC
) {
2424 info
= FILE_WAS_OVERWRITTEN
;
2426 info
= FILE_WAS_OPENED
;
2429 info
= FILE_WAS_CREATED
;
2437 * Setup the oplock info in both the shared memory and
2441 status
= set_file_oplock(fsp
, fsp
->oplock_type
);
2442 if (!NT_STATUS_IS_OK(status
)) {
2444 * Could not get the kernel oplock or there are byte-range
2445 * locks on the file.
2447 fsp
->oplock_type
= NO_OPLOCK
;
2450 set_share_mode(lck
, fsp
, get_current_uid(conn
),
2454 /* Handle strange delete on close create semantics. */
2455 if (create_options
& FILE_DELETE_ON_CLOSE
) {
2457 status
= can_set_delete_on_close(fsp
, new_dos_attributes
);
2459 if (!NT_STATUS_IS_OK(status
)) {
2460 /* Remember to delete the mode we just added. */
2461 del_share_mode(lck
, fsp
);
2466 /* Note that here we set the *inital* delete on close flag,
2467 not the regular one. The magic gets handled in close. */
2468 fsp
->initial_delete_on_close
= True
;
2471 if (info
== FILE_WAS_OVERWRITTEN
2472 || info
== FILE_WAS_CREATED
2473 || info
== FILE_WAS_SUPERSEDED
) {
2474 new_file_created
= True
;
2477 if (new_file_created
) {
2478 /* Files should be initially set as archive */
2479 if (lp_map_archive(SNUM(conn
)) ||
2480 lp_store_dos_attributes(SNUM(conn
))) {
2482 if (file_set_dosmode(conn
, smb_fname
,
2483 new_dos_attributes
| FILE_ATTRIBUTE_ARCHIVE
,
2484 parent_dir
, true) == 0) {
2485 unx_mode
= smb_fname
->st
.st_ex_mode
;
2491 /* Determine sparse flag. */
2493 /* POSIX opens are sparse by default. */
2494 fsp
->is_sparse
= true;
2496 fsp
->is_sparse
= (file_existed
&&
2497 (existing_dos_attributes
& FILE_ATTRIBUTE_SPARSE
));
2501 * Take care of inherited ACLs on created files - if default ACL not
2505 if (!posix_open
&& !file_existed
&& !def_acl
) {
2507 int saved_errno
= errno
; /* We might get ENOSYS in the next
2510 if (SMB_VFS_FCHMOD_ACL(fsp
, unx_mode
) == -1 &&
2512 errno
= saved_errno
; /* Ignore ENOSYS */
2515 } else if (new_unx_mode
) {
2519 /* Attributes need changing. File already existed. */
2522 int saved_errno
= errno
; /* We might get ENOSYS in the
2524 ret
= SMB_VFS_FCHMOD_ACL(fsp
, new_unx_mode
);
2526 if (ret
== -1 && errno
== ENOSYS
) {
2527 errno
= saved_errno
; /* Ignore ENOSYS */
2529 DEBUG(5, ("open_file_ntcreate: reset "
2530 "attributes of file %s to 0%o\n",
2531 smb_fname_str_dbg(smb_fname
),
2532 (unsigned int)new_unx_mode
));
2533 ret
= 0; /* Don't do the fchmod below. */
2538 (SMB_VFS_FCHMOD(fsp
, new_unx_mode
) == -1))
2539 DEBUG(5, ("open_file_ntcreate: failed to reset "
2540 "attributes of file %s to 0%o\n",
2541 smb_fname_str_dbg(smb_fname
),
2542 (unsigned int)new_unx_mode
));
2545 /* If this is a successful open, we must remove any deferred open
2548 del_deferred_open_entry(lck
, req
->mid
,
2549 messaging_server_id(req
->sconn
->msg_ctx
));
2553 return NT_STATUS_OK
;
2557 /****************************************************************************
2558 Open a file for for write to ensure that we can fchmod it.
2559 ****************************************************************************/
2561 NTSTATUS
open_file_fchmod(connection_struct
*conn
,
2562 struct smb_filename
*smb_fname
,
2563 files_struct
**result
)
2565 if (!VALID_STAT(smb_fname
->st
)) {
2566 return NT_STATUS_INVALID_PARAMETER
;
2569 return SMB_VFS_CREATE_FILE(
2572 0, /* root_dir_fid */
2573 smb_fname
, /* fname */
2574 FILE_WRITE_DATA
, /* access_mask */
2575 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
2577 FILE_OPEN
, /* create_disposition*/
2578 0, /* create_options */
2579 0, /* file_attributes */
2580 INTERNAL_OPEN_ONLY
, /* oplock_request */
2581 0, /* allocation_size */
2582 0, /* private_flags */
2585 result
, /* result */
2589 static NTSTATUS
mkdir_internal(connection_struct
*conn
,
2590 struct smb_filename
*smb_dname
,
2591 uint32 file_attributes
)
2594 char *parent_dir
= NULL
;
2596 bool posix_open
= false;
2597 bool need_re_stat
= false;
2598 uint32_t access_mask
= SEC_DIR_ADD_SUBDIR
;
2600 if(access_mask
& ~(conn
->share_access
)) {
2601 DEBUG(5,("mkdir_internal: failing share access "
2602 "%s\n", lp_servicename(SNUM(conn
))));
2603 return NT_STATUS_ACCESS_DENIED
;
2606 if (!parent_dirname(talloc_tos(), smb_dname
->base_name
, &parent_dir
,
2608 return NT_STATUS_NO_MEMORY
;
2611 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
2613 mode
= (mode_t
)(file_attributes
& ~FILE_FLAG_POSIX_SEMANTICS
);
2615 mode
= unix_mode(conn
, FILE_ATTRIBUTE_DIRECTORY
, smb_dname
, parent_dir
);
2618 status
= check_parent_access(conn
,
2621 if(!NT_STATUS_IS_OK(status
)) {
2622 DEBUG(5,("mkdir_internal: check_parent_access "
2623 "on directory %s for path %s returned %s\n",
2625 smb_dname
->base_name
,
2626 nt_errstr(status
) ));
2630 if (SMB_VFS_MKDIR(conn
, smb_dname
->base_name
, mode
) != 0) {
2631 return map_nt_error_from_unix(errno
);
2634 /* Ensure we're checking for a symlink here.... */
2635 /* We don't want to get caught by a symlink racer. */
2637 if (SMB_VFS_LSTAT(conn
, smb_dname
) == -1) {
2638 DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
2639 smb_fname_str_dbg(smb_dname
), strerror(errno
)));
2640 return map_nt_error_from_unix(errno
);
2643 if (!S_ISDIR(smb_dname
->st
.st_ex_mode
)) {
2644 DEBUG(0, ("Directory '%s' just created is not a directory !\n",
2645 smb_fname_str_dbg(smb_dname
)));
2646 return NT_STATUS_NOT_A_DIRECTORY
;
2649 if (lp_store_dos_attributes(SNUM(conn
))) {
2651 file_set_dosmode(conn
, smb_dname
,
2652 file_attributes
| FILE_ATTRIBUTE_DIRECTORY
,
2657 if (lp_inherit_perms(SNUM(conn
))) {
2658 inherit_access_posix_acl(conn
, parent_dir
,
2659 smb_dname
->base_name
, mode
);
2660 need_re_stat
= true;
2665 * Check if high bits should have been set,
2666 * then (if bits are missing): add them.
2667 * Consider bits automagically set by UNIX, i.e. SGID bit from parent
2670 if ((mode
& ~(S_IRWXU
|S_IRWXG
|S_IRWXO
)) &&
2671 (mode
& ~smb_dname
->st
.st_ex_mode
)) {
2672 SMB_VFS_CHMOD(conn
, smb_dname
->base_name
,
2673 (smb_dname
->st
.st_ex_mode
|
2674 (mode
& ~smb_dname
->st
.st_ex_mode
)));
2675 need_re_stat
= true;
2679 /* Change the owner if required. */
2680 if (lp_inherit_owner(SNUM(conn
))) {
2681 change_dir_owner_to_parent(conn
, parent_dir
,
2682 smb_dname
->base_name
,
2684 need_re_stat
= true;
2688 if (SMB_VFS_LSTAT(conn
, smb_dname
) == -1) {
2689 DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
2690 smb_fname_str_dbg(smb_dname
), strerror(errno
)));
2691 return map_nt_error_from_unix(errno
);
2695 notify_fname(conn
, NOTIFY_ACTION_ADDED
, FILE_NOTIFY_CHANGE_DIR_NAME
,
2696 smb_dname
->base_name
);
2698 return NT_STATUS_OK
;
2701 /****************************************************************************
2702 Ensure we didn't get symlink raced on opening a directory.
2703 ****************************************************************************/
2705 bool check_same_stat(const SMB_STRUCT_STAT
*sbuf1
,
2706 const SMB_STRUCT_STAT
*sbuf2
)
2708 if (sbuf1
->st_ex_uid
!= sbuf2
->st_ex_uid
||
2709 sbuf1
->st_ex_gid
!= sbuf2
->st_ex_gid
||
2710 sbuf1
->st_ex_dev
!= sbuf2
->st_ex_dev
||
2711 sbuf1
->st_ex_ino
!= sbuf2
->st_ex_ino
) {
2717 /****************************************************************************
2718 Open a directory from an NT SMB call.
2719 ****************************************************************************/
2721 static NTSTATUS
open_directory(connection_struct
*conn
,
2722 struct smb_request
*req
,
2723 struct smb_filename
*smb_dname
,
2725 uint32 share_access
,
2726 uint32 create_disposition
,
2727 uint32 create_options
,
2728 uint32 file_attributes
,
2730 files_struct
**result
)
2732 files_struct
*fsp
= NULL
;
2733 bool dir_existed
= VALID_STAT(smb_dname
->st
) ? True
: False
;
2734 struct share_mode_lock
*lck
= NULL
;
2736 struct timespec mtimespec
;
2739 if (is_ntfs_stream_smb_fname(smb_dname
)) {
2740 DEBUG(2, ("open_directory: %s is a stream name!\n",
2741 smb_fname_str_dbg(smb_dname
)));
2742 return NT_STATUS_NOT_A_DIRECTORY
;
2745 if (!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
)) {
2746 /* Ensure we have a directory attribute. */
2747 file_attributes
|= FILE_ATTRIBUTE_DIRECTORY
;
2750 DEBUG(5,("open_directory: opening directory %s, access_mask = 0x%x, "
2751 "share_access = 0x%x create_options = 0x%x, "
2752 "create_disposition = 0x%x, file_attributes = 0x%x\n",
2753 smb_fname_str_dbg(smb_dname
),
2754 (unsigned int)access_mask
,
2755 (unsigned int)share_access
,
2756 (unsigned int)create_options
,
2757 (unsigned int)create_disposition
,
2758 (unsigned int)file_attributes
));
2760 status
= smbd_calculate_access_mask(conn
, smb_dname
,
2761 access_mask
, &access_mask
);
2762 if (!NT_STATUS_IS_OK(status
)) {
2763 DEBUG(10, ("open_directory: smbd_calculate_access_mask "
2764 "on file %s returned %s\n",
2765 smb_fname_str_dbg(smb_dname
),
2766 nt_errstr(status
)));
2770 if ((access_mask
& SEC_FLAG_SYSTEM_SECURITY
) &&
2771 !security_token_has_privilege(get_current_nttok(conn
),
2772 SEC_PRIV_SECURITY
)) {
2773 DEBUG(10, ("open_directory: open on %s "
2774 "failed - SEC_FLAG_SYSTEM_SECURITY denied.\n",
2775 smb_fname_str_dbg(smb_dname
)));
2776 return NT_STATUS_PRIVILEGE_NOT_HELD
;
2779 switch( create_disposition
) {
2783 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2786 info
= FILE_WAS_OPENED
;
2791 /* If directory exists error. If directory doesn't
2795 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
2796 DEBUG(2, ("open_directory: unable to create "
2797 "%s. Error was %s\n",
2798 smb_fname_str_dbg(smb_dname
),
2799 nt_errstr(status
)));
2803 status
= mkdir_internal(conn
, smb_dname
,
2806 if (!NT_STATUS_IS_OK(status
)) {
2807 DEBUG(2, ("open_directory: unable to create "
2808 "%s. Error was %s\n",
2809 smb_fname_str_dbg(smb_dname
),
2810 nt_errstr(status
)));
2814 info
= FILE_WAS_CREATED
;
2819 * If directory exists open. If directory doesn't
2824 status
= NT_STATUS_OK
;
2825 info
= FILE_WAS_OPENED
;
2827 status
= mkdir_internal(conn
, smb_dname
,
2830 if (NT_STATUS_IS_OK(status
)) {
2831 info
= FILE_WAS_CREATED
;
2833 /* Cope with create race. */
2834 if (!NT_STATUS_EQUAL(status
,
2835 NT_STATUS_OBJECT_NAME_COLLISION
)) {
2836 DEBUG(2, ("open_directory: unable to create "
2837 "%s. Error was %s\n",
2838 smb_fname_str_dbg(smb_dname
),
2839 nt_errstr(status
)));
2842 info
= FILE_WAS_OPENED
;
2848 case FILE_SUPERSEDE
:
2849 case FILE_OVERWRITE
:
2850 case FILE_OVERWRITE_IF
:
2852 DEBUG(5,("open_directory: invalid create_disposition "
2853 "0x%x for directory %s\n",
2854 (unsigned int)create_disposition
,
2855 smb_fname_str_dbg(smb_dname
)));
2856 return NT_STATUS_INVALID_PARAMETER
;
2859 if(!S_ISDIR(smb_dname
->st
.st_ex_mode
)) {
2860 DEBUG(5,("open_directory: %s is not a directory !\n",
2861 smb_fname_str_dbg(smb_dname
)));
2862 return NT_STATUS_NOT_A_DIRECTORY
;
2865 if (info
== FILE_WAS_OPENED
) {
2866 status
= smbd_check_access_rights(conn
, smb_dname
, access_mask
);
2867 if (!NT_STATUS_IS_OK(status
)) {
2868 DEBUG(10, ("open_directory: smbd_check_access_rights on "
2869 "file %s failed with %s\n",
2870 smb_fname_str_dbg(smb_dname
),
2871 nt_errstr(status
)));
2876 status
= file_new(req
, conn
, &fsp
);
2877 if(!NT_STATUS_IS_OK(status
)) {
2882 * Setup the files_struct for it.
2885 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &smb_dname
->st
);
2886 fsp
->vuid
= req
? req
->vuid
: UID_FIELD_INVALID
;
2887 fsp
->file_pid
= req
? req
->smbpid
: 0;
2888 fsp
->can_lock
= False
;
2889 fsp
->can_read
= False
;
2890 fsp
->can_write
= False
;
2892 fsp
->share_access
= share_access
;
2893 fsp
->fh
->private_options
= 0;
2895 * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
2897 fsp
->access_mask
= access_mask
| FILE_READ_ATTRIBUTES
;
2898 fsp
->print_file
= NULL
;
2899 fsp
->modified
= False
;
2900 fsp
->oplock_type
= NO_OPLOCK
;
2901 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
2902 fsp
->is_directory
= True
;
2903 fsp
->posix_open
= (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) ? True
: False
;
2904 status
= fsp_set_smb_fname(fsp
, smb_dname
);
2905 if (!NT_STATUS_IS_OK(status
)) {
2906 file_free(req
, fsp
);
2910 mtimespec
= smb_dname
->st
.st_ex_mtime
;
2913 status
= fd_open(conn
, fsp
, O_RDONLY
|O_DIRECTORY
, 0);
2915 /* POSIX allows us to open a directory with O_RDONLY. */
2916 status
= fd_open(conn
, fsp
, O_RDONLY
, 0);
2918 if (!NT_STATUS_IS_OK(status
)) {
2919 DEBUG(5, ("open_directory: Could not open fd for "
2921 smb_fname_str_dbg(smb_dname
),
2922 nt_errstr(status
)));
2923 file_free(req
, fsp
);
2927 status
= vfs_stat_fsp(fsp
);
2928 if (!NT_STATUS_IS_OK(status
)) {
2930 file_free(req
, fsp
);
2934 /* Ensure there was no race condition. */
2935 if (!check_same_stat(&smb_dname
->st
, &fsp
->fsp_name
->st
)) {
2936 DEBUG(5,("open_directory: stat struct differs for "
2938 smb_fname_str_dbg(smb_dname
)));
2940 file_free(req
, fsp
);
2941 return NT_STATUS_ACCESS_DENIED
;
2944 lck
= get_share_mode_lock(talloc_tos(), fsp
->file_id
,
2945 conn
->connectpath
, smb_dname
,
2949 DEBUG(0, ("open_directory: Could not get share mode lock for "
2950 "%s\n", smb_fname_str_dbg(smb_dname
)));
2952 file_free(req
, fsp
);
2953 return NT_STATUS_SHARING_VIOLATION
;
2956 status
= open_mode_check(conn
, lck
, fsp
->name_hash
,
2957 access_mask
, share_access
,
2958 create_options
, &dir_existed
);
2960 if (!NT_STATUS_IS_OK(status
)) {
2963 file_free(req
, fsp
);
2967 set_share_mode(lck
, fsp
, get_current_uid(conn
),
2968 req
? req
->mid
: 0, NO_OPLOCK
);
2970 /* For directories the delete on close bit at open time seems
2971 always to be honored on close... See test 19 in Samba4 BASE-DELETE. */
2972 if (create_options
& FILE_DELETE_ON_CLOSE
) {
2973 status
= can_set_delete_on_close(fsp
, 0);
2974 if (!NT_STATUS_IS_OK(status
) && !NT_STATUS_EQUAL(status
, NT_STATUS_DIRECTORY_NOT_EMPTY
)) {
2977 file_free(req
, fsp
);
2981 if (NT_STATUS_IS_OK(status
)) {
2982 /* Note that here we set the *inital* delete on close flag,
2983 not the regular one. The magic gets handled in close. */
2984 fsp
->initial_delete_on_close
= True
;
2995 return NT_STATUS_OK
;
2998 NTSTATUS
create_directory(connection_struct
*conn
, struct smb_request
*req
,
2999 struct smb_filename
*smb_dname
)
3004 status
= SMB_VFS_CREATE_FILE(
3007 0, /* root_dir_fid */
3008 smb_dname
, /* fname */
3009 FILE_READ_ATTRIBUTES
, /* access_mask */
3010 FILE_SHARE_NONE
, /* share_access */
3011 FILE_CREATE
, /* create_disposition*/
3012 FILE_DIRECTORY_FILE
, /* create_options */
3013 FILE_ATTRIBUTE_DIRECTORY
, /* file_attributes */
3014 0, /* oplock_request */
3015 0, /* allocation_size */
3016 0, /* private_flags */
3022 if (NT_STATUS_IS_OK(status
)) {
3023 close_file(req
, fsp
, NORMAL_CLOSE
);
3029 /****************************************************************************
3030 Receive notification that one of our open files has been renamed by another
3032 ****************************************************************************/
3034 void msg_file_was_renamed(struct messaging_context
*msg
,
3037 struct server_id server_id
,
3041 char *frm
= (char *)data
->data
;
3043 const char *sharepath
;
3044 const char *base_name
;
3045 const char *stream_name
;
3046 struct smb_filename
*smb_fname
= NULL
;
3047 size_t sp_len
, bn_len
;
3049 struct smbd_server_connection
*sconn
=
3050 talloc_get_type_abort(private_data
,
3051 struct smbd_server_connection
);
3053 if (data
->data
== NULL
3054 || data
->length
< MSG_FILE_RENAMED_MIN_SIZE
+ 2) {
3055 DEBUG(0, ("msg_file_was_renamed: Got invalid msg len %d\n",
3056 (int)data
->length
));
3060 /* Unpack the message. */
3061 pull_file_id_24(frm
, &id
);
3062 sharepath
= &frm
[24];
3063 sp_len
= strlen(sharepath
);
3064 base_name
= sharepath
+ sp_len
+ 1;
3065 bn_len
= strlen(base_name
);
3066 stream_name
= sharepath
+ sp_len
+ 1 + bn_len
+ 1;
3068 /* stream_name must always be NULL if there is no stream. */
3069 if (stream_name
[0] == '\0') {
3073 status
= create_synthetic_smb_fname(talloc_tos(), base_name
,
3074 stream_name
, NULL
, &smb_fname
);
3075 if (!NT_STATUS_IS_OK(status
)) {
3079 DEBUG(10,("msg_file_was_renamed: Got rename message for sharepath %s, new name %s, "
3081 sharepath
, smb_fname_str_dbg(smb_fname
),
3082 file_id_string_tos(&id
)));
3084 for(fsp
= file_find_di_first(sconn
, id
); fsp
;
3085 fsp
= file_find_di_next(fsp
)) {
3086 if (memcmp(fsp
->conn
->connectpath
, sharepath
, sp_len
) == 0) {
3088 DEBUG(10,("msg_file_was_renamed: renaming file %s from %s -> %s\n",
3089 fsp_fnum_dbg(fsp
), fsp_str_dbg(fsp
),
3090 smb_fname_str_dbg(smb_fname
)));
3091 status
= fsp_set_smb_fname(fsp
, smb_fname
);
3092 if (!NT_STATUS_IS_OK(status
)) {
3097 /* Now we have the complete path we can work out if this is
3098 actually within this share and adjust newname accordingly. */
3099 DEBUG(10,("msg_file_was_renamed: share mismatch (sharepath %s "
3100 "not sharepath %s) "
3101 "%s from %s -> %s\n",
3102 fsp
->conn
->connectpath
,
3106 smb_fname_str_dbg(smb_fname
)));
3110 TALLOC_FREE(smb_fname
);
3115 * If a main file is opened for delete, all streams need to be checked for
3116 * !FILE_SHARE_DELETE. Do this by opening with DELETE_ACCESS.
3117 * If that works, delete them all by setting the delete on close and close.
3120 NTSTATUS
open_streams_for_delete(connection_struct
*conn
,
3123 struct stream_struct
*stream_info
= NULL
;
3124 files_struct
**streams
= NULL
;
3126 unsigned int num_streams
= 0;
3127 TALLOC_CTX
*frame
= talloc_stackframe();
3130 status
= vfs_streaminfo(conn
, NULL
, fname
, talloc_tos(),
3131 &num_streams
, &stream_info
);
3133 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
)
3134 || NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
3135 DEBUG(10, ("no streams around\n"));
3137 return NT_STATUS_OK
;
3140 if (!NT_STATUS_IS_OK(status
)) {
3141 DEBUG(10, ("vfs_streaminfo failed: %s\n",
3142 nt_errstr(status
)));
3146 DEBUG(10, ("open_streams_for_delete found %d streams\n",
3149 if (num_streams
== 0) {
3151 return NT_STATUS_OK
;
3154 streams
= talloc_array(talloc_tos(), files_struct
*, num_streams
);
3155 if (streams
== NULL
) {
3156 DEBUG(0, ("talloc failed\n"));
3157 status
= NT_STATUS_NO_MEMORY
;
3161 for (i
=0; i
<num_streams
; i
++) {
3162 struct smb_filename
*smb_fname
= NULL
;
3164 if (strequal(stream_info
[i
].name
, "::$DATA")) {
3169 status
= create_synthetic_smb_fname(talloc_tos(), fname
,
3170 stream_info
[i
].name
,
3172 if (!NT_STATUS_IS_OK(status
)) {
3176 if (SMB_VFS_STAT(conn
, smb_fname
) == -1) {
3177 DEBUG(10, ("Unable to stat stream: %s\n",
3178 smb_fname_str_dbg(smb_fname
)));
3181 status
= SMB_VFS_CREATE_FILE(
3184 0, /* root_dir_fid */
3185 smb_fname
, /* fname */
3186 DELETE_ACCESS
, /* access_mask */
3187 (FILE_SHARE_READ
| /* share_access */
3188 FILE_SHARE_WRITE
| FILE_SHARE_DELETE
),
3189 FILE_OPEN
, /* create_disposition*/
3190 0, /* create_options */
3191 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
3192 0, /* oplock_request */
3193 0, /* allocation_size */
3194 NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE
, /* private_flags */
3197 &streams
[i
], /* result */
3200 if (!NT_STATUS_IS_OK(status
)) {
3201 DEBUG(10, ("Could not open stream %s: %s\n",
3202 smb_fname_str_dbg(smb_fname
),
3203 nt_errstr(status
)));
3205 TALLOC_FREE(smb_fname
);
3208 TALLOC_FREE(smb_fname
);
3212 * don't touch the variable "status" beyond this point :-)
3215 for (i
-= 1 ; i
>= 0; i
--) {
3216 if (streams
[i
] == NULL
) {
3220 DEBUG(10, ("Closing stream # %d, %s\n", i
,
3221 fsp_str_dbg(streams
[i
])));
3222 close_file(NULL
, streams
[i
], NORMAL_CLOSE
);
3230 /*********************************************************************
3231 Create a default ACL by inheriting from the parent. If no inheritance
3232 from the parent available, don't set anything. This will leave the actual
3233 permissions the new file or directory already got from the filesystem
3234 as the NT ACL when read.
3235 *********************************************************************/
3237 static NTSTATUS
inherit_new_acl(files_struct
*fsp
)
3239 TALLOC_CTX
*ctx
= talloc_tos();
3240 char *parent_name
= NULL
;
3241 struct security_descriptor
*parent_desc
= NULL
;
3242 NTSTATUS status
= NT_STATUS_OK
;
3243 struct security_descriptor
*psd
= NULL
;
3244 struct dom_sid
*owner_sid
= NULL
;
3245 struct dom_sid
*group_sid
= NULL
;
3246 uint32_t security_info_sent
= (SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
);
3247 bool inherit_owner
= lp_inherit_owner(SNUM(fsp
->conn
));
3248 bool inheritable_components
= false;
3251 if (!parent_dirname(ctx
, fsp
->fsp_name
->base_name
, &parent_name
, NULL
)) {
3252 return NT_STATUS_NO_MEMORY
;
3255 status
= SMB_VFS_GET_NT_ACL(fsp
->conn
,
3257 (SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
),
3259 if (!NT_STATUS_IS_OK(status
)) {
3263 inheritable_components
= sd_has_inheritable_components(parent_desc
,
3266 if (!inheritable_components
&& !inherit_owner
) {
3267 /* Nothing to inherit and not setting owner. */
3268 return NT_STATUS_OK
;
3271 /* Create an inherited descriptor from the parent. */
3273 if (DEBUGLEVEL
>= 10) {
3274 DEBUG(10,("inherit_new_acl: parent acl for %s is:\n",
3275 fsp_str_dbg(fsp
) ));
3276 NDR_PRINT_DEBUG(security_descriptor
, parent_desc
);
3279 /* Inherit from parent descriptor if "inherit owner" set. */
3280 if (inherit_owner
) {
3281 owner_sid
= parent_desc
->owner_sid
;
3282 group_sid
= parent_desc
->group_sid
;
3285 if (owner_sid
== NULL
) {
3286 owner_sid
= &fsp
->conn
->session_info
->security_token
->sids
[PRIMARY_USER_SID_INDEX
];
3288 if (group_sid
== NULL
) {
3289 group_sid
= &fsp
->conn
->session_info
->security_token
->sids
[PRIMARY_GROUP_SID_INDEX
];
3292 status
= se_create_child_secdesc(ctx
,
3299 if (!NT_STATUS_IS_OK(status
)) {
3303 /* If inheritable_components == false,
3304 se_create_child_secdesc()
3305 creates a security desriptor with a NULL dacl
3306 entry, but with SEC_DESC_DACL_PRESENT. We need
3307 to remove that flag. */
3309 if (!inheritable_components
) {
3310 security_info_sent
&= ~SECINFO_DACL
;
3311 psd
->type
&= ~SEC_DESC_DACL_PRESENT
;
3314 if (DEBUGLEVEL
>= 10) {
3315 DEBUG(10,("inherit_new_acl: child acl for %s is:\n",
3316 fsp_str_dbg(fsp
) ));
3317 NDR_PRINT_DEBUG(security_descriptor
, psd
);
3320 if (inherit_owner
) {
3321 /* We need to be root to force this. */
3324 status
= SMB_VFS_FSET_NT_ACL(fsp
,
3327 if (inherit_owner
) {
3334 * Wrapper around open_file_ntcreate and open_directory
3337 static NTSTATUS
create_file_unixpath(connection_struct
*conn
,
3338 struct smb_request
*req
,
3339 struct smb_filename
*smb_fname
,
3340 uint32_t access_mask
,
3341 uint32_t share_access
,
3342 uint32_t create_disposition
,
3343 uint32_t create_options
,
3344 uint32_t file_attributes
,
3345 uint32_t oplock_request
,
3346 uint64_t allocation_size
,
3347 uint32_t private_flags
,
3348 struct security_descriptor
*sd
,
3349 struct ea_list
*ea_list
,
3351 files_struct
**result
,
3354 int info
= FILE_WAS_OPENED
;
3355 files_struct
*base_fsp
= NULL
;
3356 files_struct
*fsp
= NULL
;
3359 DEBUG(10,("create_file_unixpath: access_mask = 0x%x "
3360 "file_attributes = 0x%x, share_access = 0x%x, "
3361 "create_disposition = 0x%x create_options = 0x%x "
3362 "oplock_request = 0x%x private_flags = 0x%x "
3363 "ea_list = 0x%p, sd = 0x%p, "
3365 (unsigned int)access_mask
,
3366 (unsigned int)file_attributes
,
3367 (unsigned int)share_access
,
3368 (unsigned int)create_disposition
,
3369 (unsigned int)create_options
,
3370 (unsigned int)oplock_request
,
3371 (unsigned int)private_flags
,
3372 ea_list
, sd
, smb_fname_str_dbg(smb_fname
)));
3374 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
3375 status
= NT_STATUS_NOT_SUPPORTED
;
3379 if (create_options
& NTCREATEX_OPTIONS_INVALID_PARAM_MASK
) {
3380 status
= NT_STATUS_INVALID_PARAMETER
;
3385 oplock_request
|= INTERNAL_OPEN_ONLY
;
3388 if ((conn
->fs_capabilities
& FILE_NAMED_STREAMS
)
3389 && (access_mask
& DELETE_ACCESS
)
3390 && !is_ntfs_stream_smb_fname(smb_fname
)) {
3392 * We can't open a file with DELETE access if any of the
3393 * streams is open without FILE_SHARE_DELETE
3395 status
= open_streams_for_delete(conn
, smb_fname
->base_name
);
3397 if (!NT_STATUS_IS_OK(status
)) {
3402 if ((access_mask
& SEC_FLAG_SYSTEM_SECURITY
) &&
3403 !security_token_has_privilege(get_current_nttok(conn
),
3404 SEC_PRIV_SECURITY
)) {
3405 DEBUG(10, ("create_file_unixpath: open on %s "
3406 "failed - SEC_FLAG_SYSTEM_SECURITY denied.\n",
3407 smb_fname_str_dbg(smb_fname
)));
3408 status
= NT_STATUS_PRIVILEGE_NOT_HELD
;
3412 if ((conn
->fs_capabilities
& FILE_NAMED_STREAMS
)
3413 && is_ntfs_stream_smb_fname(smb_fname
)
3414 && (!(private_flags
& NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE
))) {
3415 uint32 base_create_disposition
;
3416 struct smb_filename
*smb_fname_base
= NULL
;
3418 if (create_options
& FILE_DIRECTORY_FILE
) {
3419 status
= NT_STATUS_NOT_A_DIRECTORY
;
3423 switch (create_disposition
) {
3425 base_create_disposition
= FILE_OPEN
;
3428 base_create_disposition
= FILE_OPEN_IF
;
3432 /* Create an smb_filename with stream_name == NULL. */
3433 status
= create_synthetic_smb_fname(talloc_tos(),
3434 smb_fname
->base_name
,
3437 if (!NT_STATUS_IS_OK(status
)) {
3441 if (SMB_VFS_STAT(conn
, smb_fname_base
) == -1) {
3442 DEBUG(10, ("Unable to stat stream: %s\n",
3443 smb_fname_str_dbg(smb_fname_base
)));
3446 /* Open the base file. */
3447 status
= create_file_unixpath(conn
, NULL
, smb_fname_base
, 0,
3450 | FILE_SHARE_DELETE
,
3451 base_create_disposition
,
3452 0, 0, 0, 0, 0, NULL
, NULL
,
3454 TALLOC_FREE(smb_fname_base
);
3456 if (!NT_STATUS_IS_OK(status
)) {
3457 DEBUG(10, ("create_file_unixpath for base %s failed: "
3458 "%s\n", smb_fname
->base_name
,
3459 nt_errstr(status
)));
3462 /* we don't need to low level fd */
3467 * If it's a request for a directory open, deal with it separately.
3470 if (create_options
& FILE_DIRECTORY_FILE
) {
3472 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
3473 status
= NT_STATUS_INVALID_PARAMETER
;
3477 /* Can't open a temp directory. IFS kit test. */
3478 if (!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) &&
3479 (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
)) {
3480 status
= NT_STATUS_INVALID_PARAMETER
;
3485 * We will get a create directory here if the Win32
3486 * app specified a security descriptor in the
3487 * CreateDirectory() call.
3491 status
= open_directory(
3492 conn
, req
, smb_fname
, access_mask
, share_access
,
3493 create_disposition
, create_options
, file_attributes
,
3498 * Ordinary file case.
3501 status
= file_new(req
, conn
, &fsp
);
3502 if(!NT_STATUS_IS_OK(status
)) {
3506 status
= fsp_set_smb_fname(fsp
, smb_fname
);
3507 if (!NT_STATUS_IS_OK(status
)) {
3512 * We're opening the stream element of a base_fsp
3513 * we already opened. Set up the base_fsp pointer.
3516 fsp
->base_fsp
= base_fsp
;
3519 status
= open_file_ntcreate(conn
,
3531 if(!NT_STATUS_IS_OK(status
)) {
3532 file_free(req
, fsp
);
3536 if (NT_STATUS_EQUAL(status
, NT_STATUS_FILE_IS_A_DIRECTORY
)) {
3538 /* A stream open never opens a directory */
3541 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
3546 * Fail the open if it was explicitly a non-directory
3550 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
3551 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
3556 status
= open_directory(
3557 conn
, req
, smb_fname
, access_mask
,
3558 share_access
, create_disposition
,
3559 create_options
, file_attributes
,
3564 if (!NT_STATUS_IS_OK(status
)) {
3568 fsp
->base_fsp
= base_fsp
;
3570 if ((ea_list
!= NULL
) &&
3571 ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
))) {
3572 status
= set_ea(conn
, fsp
, fsp
->fsp_name
, ea_list
);
3573 if (!NT_STATUS_IS_OK(status
)) {
3578 if (!fsp
->is_directory
&& S_ISDIR(fsp
->fsp_name
->st
.st_ex_mode
)) {
3579 status
= NT_STATUS_ACCESS_DENIED
;
3583 /* Save the requested allocation size. */
3584 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
3586 && (allocation_size
> fsp
->fsp_name
->st
.st_ex_size
)) {
3587 fsp
->initial_allocation_size
= smb_roundup(
3588 fsp
->conn
, allocation_size
);
3589 if (fsp
->is_directory
) {
3590 /* Can't set allocation size on a directory. */
3591 status
= NT_STATUS_ACCESS_DENIED
;
3594 if (vfs_allocate_file_space(
3595 fsp
, fsp
->initial_allocation_size
) == -1) {
3596 status
= NT_STATUS_DISK_FULL
;
3600 fsp
->initial_allocation_size
= smb_roundup(
3601 fsp
->conn
, (uint64_t)fsp
->fsp_name
->st
.st_ex_size
);
3605 if ((info
== FILE_WAS_CREATED
) && lp_nt_acl_support(SNUM(conn
)) &&
3606 fsp
->base_fsp
== NULL
) {
3609 * According to the MS documentation, the only time the security
3610 * descriptor is applied to the opened file is iff we *created* the
3611 * file; an existing file stays the same.
3613 * Also, it seems (from observation) that you can open the file with
3614 * any access mask but you can still write the sd. We need to override
3615 * the granted access before we call set_sd
3616 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
3619 uint32_t sec_info_sent
;
3620 uint32_t saved_access_mask
= fsp
->access_mask
;
3622 sec_info_sent
= get_sec_info(sd
);
3624 fsp
->access_mask
= FILE_GENERIC_ALL
;
3626 /* Convert all the generic bits. */
3627 security_acl_map_generic(sd
->dacl
, &file_generic_mapping
);
3628 security_acl_map_generic(sd
->sacl
, &file_generic_mapping
);
3630 if (sec_info_sent
& (SECINFO_OWNER
|
3634 status
= SMB_VFS_FSET_NT_ACL(fsp
, sec_info_sent
, sd
);
3637 fsp
->access_mask
= saved_access_mask
;
3639 if (!NT_STATUS_IS_OK(status
)) {
3642 } else if (lp_inherit_acls(SNUM(conn
))) {
3643 /* Inherit from parent. Errors here are not fatal. */
3644 status
= inherit_new_acl(fsp
);
3645 if (!NT_STATUS_IS_OK(status
)) {
3646 DEBUG(10,("inherit_new_acl: failed for %s with %s\n",
3648 nt_errstr(status
) ));
3653 DEBUG(10, ("create_file_unixpath: info=%d\n", info
));
3656 if (pinfo
!= NULL
) {
3660 smb_fname
->st
= fsp
->fsp_name
->st
;
3662 return NT_STATUS_OK
;
3665 DEBUG(10, ("create_file_unixpath: %s\n", nt_errstr(status
)));
3668 if (base_fsp
&& fsp
->base_fsp
== base_fsp
) {
3670 * The close_file below will close
3675 close_file(req
, fsp
, ERROR_CLOSE
);
3678 if (base_fsp
!= NULL
) {
3679 close_file(req
, base_fsp
, ERROR_CLOSE
);
3686 * Calculate the full path name given a relative fid.
3688 NTSTATUS
get_relative_fid_filename(connection_struct
*conn
,
3689 struct smb_request
*req
,
3690 uint16_t root_dir_fid
,
3691 const struct smb_filename
*smb_fname
,
3692 struct smb_filename
**smb_fname_out
)
3694 files_struct
*dir_fsp
;
3695 char *parent_fname
= NULL
;
3696 char *new_base_name
= NULL
;
3699 if (root_dir_fid
== 0 || !smb_fname
) {
3700 status
= NT_STATUS_INTERNAL_ERROR
;
3704 dir_fsp
= file_fsp(req
, root_dir_fid
);
3706 if (dir_fsp
== NULL
) {
3707 status
= NT_STATUS_INVALID_HANDLE
;
3711 if (is_ntfs_stream_smb_fname(dir_fsp
->fsp_name
)) {
3712 status
= NT_STATUS_INVALID_HANDLE
;
3716 if (!dir_fsp
->is_directory
) {
3719 * Check to see if this is a mac fork of some kind.
3722 if ((conn
->fs_capabilities
& FILE_NAMED_STREAMS
) &&
3723 is_ntfs_stream_smb_fname(smb_fname
)) {
3724 status
= NT_STATUS_OBJECT_PATH_NOT_FOUND
;
3729 we need to handle the case when we get a
3730 relative open relative to a file and the
3731 pathname is blank - this is a reopen!
3732 (hint from demyn plantenberg)
3735 status
= NT_STATUS_INVALID_HANDLE
;
3739 if (ISDOT(dir_fsp
->fsp_name
->base_name
)) {
3741 * We're at the toplevel dir, the final file name
3742 * must not contain ./, as this is filtered out
3743 * normally by srvstr_get_path and unix_convert
3744 * explicitly rejects paths containing ./.
3746 parent_fname
= talloc_strdup(talloc_tos(), "");
3747 if (parent_fname
== NULL
) {
3748 status
= NT_STATUS_NO_MEMORY
;
3752 size_t dir_name_len
= strlen(dir_fsp
->fsp_name
->base_name
);
3755 * Copy in the base directory name.
3758 parent_fname
= talloc_array(talloc_tos(), char,
3760 if (parent_fname
== NULL
) {
3761 status
= NT_STATUS_NO_MEMORY
;
3764 memcpy(parent_fname
, dir_fsp
->fsp_name
->base_name
,
3768 * Ensure it ends in a '/'.
3769 * We used TALLOC_SIZE +2 to add space for the '/'.
3773 && (parent_fname
[dir_name_len
-1] != '\\')
3774 && (parent_fname
[dir_name_len
-1] != '/')) {
3775 parent_fname
[dir_name_len
] = '/';
3776 parent_fname
[dir_name_len
+1] = '\0';
3780 new_base_name
= talloc_asprintf(talloc_tos(), "%s%s", parent_fname
,
3781 smb_fname
->base_name
);
3782 if (new_base_name
== NULL
) {
3783 status
= NT_STATUS_NO_MEMORY
;
3787 status
= filename_convert(req
,
3789 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
3794 if (!NT_STATUS_IS_OK(status
)) {
3799 TALLOC_FREE(parent_fname
);
3800 TALLOC_FREE(new_base_name
);
3804 NTSTATUS
create_file_default(connection_struct
*conn
,
3805 struct smb_request
*req
,
3806 uint16_t root_dir_fid
,
3807 struct smb_filename
*smb_fname
,
3808 uint32_t access_mask
,
3809 uint32_t share_access
,
3810 uint32_t create_disposition
,
3811 uint32_t create_options
,
3812 uint32_t file_attributes
,
3813 uint32_t oplock_request
,
3814 uint64_t allocation_size
,
3815 uint32_t private_flags
,
3816 struct security_descriptor
*sd
,
3817 struct ea_list
*ea_list
,
3818 files_struct
**result
,
3821 int info
= FILE_WAS_OPENED
;
3822 files_struct
*fsp
= NULL
;
3824 bool stream_name
= false;
3826 DEBUG(10,("create_file: access_mask = 0x%x "
3827 "file_attributes = 0x%x, share_access = 0x%x, "
3828 "create_disposition = 0x%x create_options = 0x%x "
3829 "oplock_request = 0x%x "
3830 "private_flags = 0x%x "
3831 "root_dir_fid = 0x%x, ea_list = 0x%p, sd = 0x%p, "
3833 (unsigned int)access_mask
,
3834 (unsigned int)file_attributes
,
3835 (unsigned int)share_access
,
3836 (unsigned int)create_disposition
,
3837 (unsigned int)create_options
,
3838 (unsigned int)oplock_request
,
3839 (unsigned int)private_flags
,
3840 (unsigned int)root_dir_fid
,
3841 ea_list
, sd
, smb_fname_str_dbg(smb_fname
)));
3844 * Calculate the filename from the root_dir_if if necessary.
3847 if (root_dir_fid
!= 0) {
3848 struct smb_filename
*smb_fname_out
= NULL
;
3849 status
= get_relative_fid_filename(conn
, req
, root_dir_fid
,
3850 smb_fname
, &smb_fname_out
);
3851 if (!NT_STATUS_IS_OK(status
)) {
3854 smb_fname
= smb_fname_out
;
3858 * Check to see if this is a mac fork of some kind.
3861 stream_name
= is_ntfs_stream_smb_fname(smb_fname
);
3863 enum FAKE_FILE_TYPE fake_file_type
;
3865 fake_file_type
= is_fake_file(smb_fname
);
3867 if (fake_file_type
!= FAKE_FILE_TYPE_NONE
) {
3870 * Here we go! support for changing the disk quotas
3873 * We need to fake up to open this MAGIC QUOTA file
3874 * and return a valid FID.
3876 * w2k close this file directly after openening xp
3877 * also tries a QUERY_FILE_INFO on the file and then
3880 status
= open_fake_file(req
, conn
, req
->vuid
,
3881 fake_file_type
, smb_fname
,
3883 if (!NT_STATUS_IS_OK(status
)) {
3887 ZERO_STRUCT(smb_fname
->st
);
3891 if (!(conn
->fs_capabilities
& FILE_NAMED_STREAMS
)) {
3892 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3897 if (is_ntfs_default_stream_smb_fname(smb_fname
)) {
3899 smb_fname
->stream_name
= NULL
;
3900 /* We have to handle this error here. */
3901 if (create_options
& FILE_DIRECTORY_FILE
) {
3902 status
= NT_STATUS_NOT_A_DIRECTORY
;
3905 if (lp_posix_pathnames()) {
3906 ret
= SMB_VFS_LSTAT(conn
, smb_fname
);
3908 ret
= SMB_VFS_STAT(conn
, smb_fname
);
3911 if (ret
== 0 && VALID_STAT_OF_DIR(smb_fname
->st
)) {
3912 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
3917 status
= create_file_unixpath(
3918 conn
, req
, smb_fname
, access_mask
, share_access
,
3919 create_disposition
, create_options
, file_attributes
,
3920 oplock_request
, allocation_size
, private_flags
,
3924 if (!NT_STATUS_IS_OK(status
)) {
3929 DEBUG(10, ("create_file: info=%d\n", info
));
3932 if (pinfo
!= NULL
) {
3935 return NT_STATUS_OK
;
3938 DEBUG(10, ("create_file: %s\n", nt_errstr(status
)));
3941 close_file(req
, fsp
, ERROR_CLOSE
);