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 "smbd/globals.h"
25 extern struct current_user current_user;
26 extern const struct generic_mapping file_generic_mapping;
28 struct deferred_open_record {
29 bool delayed_for_oplocks;
33 static NTSTATUS create_file_unixpath(connection_struct *conn,
34 struct smb_request *req,
35 struct smb_filename *smb_fname,
37 uint32_t share_access,
38 uint32_t create_disposition,
39 uint32_t create_options,
40 uint32_t file_attributes,
41 uint32_t oplock_request,
42 uint64_t allocation_size,
43 struct security_descriptor *sd,
44 struct ea_list *ea_list,
46 files_struct **result,
49 /****************************************************************************
50 SMB1 file varient of se_access_check. Never test FILE_READ_ATTRIBUTES.
51 ****************************************************************************/
53 NTSTATUS smb1_file_se_access_check(connection_struct *conn,
54 const struct security_descriptor *sd,
55 const NT_USER_TOKEN *token,
56 uint32_t access_desired,
57 uint32_t *access_granted)
61 if (conn->server_info->utok.uid == 0 || conn->admin_user) {
62 /* I'm sorry sir, I didn't know you were root... */
63 *access_granted = access_desired;
64 if (access_desired & SEC_FLAG_MAXIMUM_ALLOWED) {
65 *access_granted |= FILE_GENERIC_ALL;
70 return se_access_check(sd,
72 (access_desired & ~FILE_READ_ATTRIBUTES),
76 /****************************************************************************
77 Check if we have open rights.
78 ****************************************************************************/
80 NTSTATUS smbd_check_open_rights(struct connection_struct *conn,
81 const struct smb_filename *smb_fname,
83 uint32_t *access_granted)
85 /* Check if we have rights to open. */
87 struct security_descriptor *sd = NULL;
89 if ((access_mask & DELETE_ACCESS) && !lp_acl_check_permissions(SNUM(conn))) {
90 *access_granted = access_mask;
92 DEBUG(10,("smbd_check_open_rights: not checking ACL "
93 "on DELETE_ACCESS on file %s. Granting 0x%x\n",
94 smb_fname_str_dbg(smb_fname),
95 (unsigned int)*access_granted ));
99 if (access_mask == DELETE_ACCESS &&
100 VALID_STAT(smb_fname->st) &&
101 S_ISLNK(smb_fname->st.st_ex_mode)) {
102 /* We can always delete a symlink. */
103 DEBUG(10,("smbd_check_open_rights: not checking ACL "
104 "on DELETE_ACCESS on symlink %s.\n",
105 smb_fname_str_dbg(smb_fname) ));
109 status = SMB_VFS_GET_NT_ACL(conn, smb_fname->base_name,
110 (OWNER_SECURITY_INFORMATION |
111 GROUP_SECURITY_INFORMATION |
112 DACL_SECURITY_INFORMATION),&sd);
114 if (!NT_STATUS_IS_OK(status)) {
115 DEBUG(10, ("smbd_check_open_rights: Could not get acl "
117 smb_fname_str_dbg(smb_fname),
122 status = smb1_file_se_access_check(conn,
124 conn->server_info->ptok,
128 DEBUG(10,("smbd_check_open_rights: file %s requesting "
129 "0x%x returning 0x%x (%s)\n",
130 smb_fname_str_dbg(smb_fname),
131 (unsigned int)access_mask,
132 (unsigned int)*access_granted,
133 nt_errstr(status) ));
135 if (!NT_STATUS_IS_OK(status)) {
136 if (DEBUGLEVEL >= 10) {
137 DEBUG(10,("smbd_check_open_rights: acl for %s is:\n",
138 smb_fname_str_dbg(smb_fname) ));
139 NDR_PRINT_DEBUG(security_descriptor, sd);
148 /****************************************************************************
149 fd support routines - attempt to do a dos_open.
150 ****************************************************************************/
152 static NTSTATUS fd_open(struct connection_struct *conn,
157 struct smb_filename *smb_fname = fsp->fsp_name;
158 NTSTATUS status = NT_STATUS_OK;
162 * Never follow symlinks on a POSIX client. The
163 * client should be doing this.
166 if (fsp->posix_open || !lp_symlinks(SNUM(conn))) {
171 fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode);
172 if (fsp->fh->fd == -1) {
173 status = map_nt_error_from_unix(errno);
174 if (errno == EMFILE) {
175 static time_t last_warned = 0L;
177 if (time((time_t *) NULL) > last_warned) {
178 DEBUG(0,("Too many open files, unable "
179 "to open more! smbd's max "
181 lp_max_open_files()));
182 last_warned = time((time_t *) NULL);
188 DEBUG(10,("fd_open: name %s, flags = 0%o mode = 0%o, fd = %d. %s\n",
189 smb_fname_str_dbg(smb_fname), flags, (int)mode, fsp->fh->fd,
190 (fsp->fh->fd == -1) ? strerror(errno) : "" ));
195 /****************************************************************************
196 Close the file associated with a fsp.
197 ****************************************************************************/
199 NTSTATUS fd_close(files_struct *fsp)
203 if (fsp->fh->fd == -1) {
204 return NT_STATUS_OK; /* What we used to call a stat open. */
206 if (fsp->fh->ref_count > 1) {
207 return NT_STATUS_OK; /* Shared handle. Only close last reference. */
210 ret = SMB_VFS_CLOSE(fsp);
213 return map_nt_error_from_unix(errno);
218 /****************************************************************************
219 Change the ownership of a file to that of the parent directory.
220 Do this by fd if possible.
221 ****************************************************************************/
223 void change_file_owner_to_parent(connection_struct *conn,
224 const char *inherit_from_dir,
227 struct smb_filename *smb_fname_parent = NULL;
231 status = create_synthetic_smb_fname(talloc_tos(), inherit_from_dir,
232 NULL, NULL, &smb_fname_parent);
233 if (!NT_STATUS_IS_OK(status)) {
237 ret = SMB_VFS_STAT(conn, smb_fname_parent);
239 DEBUG(0,("change_file_owner_to_parent: failed to stat parent "
240 "directory %s. Error was %s\n",
241 smb_fname_str_dbg(smb_fname_parent),
247 ret = SMB_VFS_FCHOWN(fsp, smb_fname_parent->st.st_ex_uid, (gid_t)-1);
250 DEBUG(0,("change_file_owner_to_parent: failed to fchown "
251 "file %s to parent directory uid %u. Error "
252 "was %s\n", fsp_str_dbg(fsp),
253 (unsigned int)smb_fname_parent->st.st_ex_uid,
256 DEBUG(10,("change_file_owner_to_parent: changed new file %s to "
257 "parent directory uid %u.\n", fsp_str_dbg(fsp),
258 (unsigned int)smb_fname_parent->st.st_ex_uid));
260 /* Ensure the uid entry is updated. */
261 fsp->fsp_name->st.st_ex_uid = smb_fname_parent->st.st_ex_uid;
264 TALLOC_FREE(smb_fname_parent);
267 NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
268 const char *inherit_from_dir,
270 SMB_STRUCT_STAT *psbuf)
272 struct smb_filename *smb_fname_parent = NULL;
273 struct smb_filename *smb_fname_cwd = NULL;
274 char *saved_dir = NULL;
275 TALLOC_CTX *ctx = talloc_tos();
276 NTSTATUS status = NT_STATUS_OK;
279 status = create_synthetic_smb_fname(ctx, inherit_from_dir, NULL, NULL,
281 if (!NT_STATUS_IS_OK(status)) {
285 ret = SMB_VFS_STAT(conn, smb_fname_parent);
287 status = map_nt_error_from_unix(errno);
288 DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
289 "directory %s. Error was %s\n",
290 smb_fname_str_dbg(smb_fname_parent),
295 /* We've already done an lstat into psbuf, and we know it's a
296 directory. If we can cd into the directory and the dev/ino
297 are the same then we can safely chown without races as
298 we're locking the directory in place by being in it. This
299 should work on any UNIX (thanks tridge :-). JRA.
302 saved_dir = vfs_GetWd(ctx,conn);
304 status = map_nt_error_from_unix(errno);
305 DEBUG(0,("change_dir_owner_to_parent: failed to get "
306 "current working directory. Error was %s\n",
311 /* Chdir into the new path. */
312 if (vfs_ChDir(conn, fname) == -1) {
313 status = map_nt_error_from_unix(errno);
314 DEBUG(0,("change_dir_owner_to_parent: failed to change "
315 "current working directory to %s. Error "
316 "was %s\n", fname, strerror(errno) ));
320 status = create_synthetic_smb_fname(ctx, ".", NULL, NULL,
322 if (!NT_STATUS_IS_OK(status)) {
326 ret = SMB_VFS_STAT(conn, smb_fname_cwd);
328 status = map_nt_error_from_unix(errno);
329 DEBUG(0,("change_dir_owner_to_parent: failed to stat "
330 "directory '.' (%s) Error was %s\n",
331 fname, strerror(errno)));
335 /* Ensure we're pointing at the same place. */
336 if (smb_fname_cwd->st.st_ex_dev != psbuf->st_ex_dev ||
337 smb_fname_cwd->st.st_ex_ino != psbuf->st_ex_ino) {
338 DEBUG(0,("change_dir_owner_to_parent: "
339 "device/inode on directory %s changed. "
340 "Refusing to chown !\n", fname ));
341 status = NT_STATUS_ACCESS_DENIED;
346 ret = SMB_VFS_CHOWN(conn, ".", smb_fname_parent->st.st_ex_uid,
350 status = map_nt_error_from_unix(errno);
351 DEBUG(10,("change_dir_owner_to_parent: failed to chown "
352 "directory %s to parent directory uid %u. "
353 "Error was %s\n", fname,
354 (unsigned int)smb_fname_parent->st.st_ex_uid,
359 DEBUG(10,("change_dir_owner_to_parent: changed ownership of new "
360 "directory %s to parent directory uid %u.\n",
361 fname, (unsigned int)smb_fname_parent->st.st_ex_uid ));
363 /* Ensure the uid entry is updated. */
364 psbuf->st_ex_uid = smb_fname_parent->st.st_ex_uid;
367 vfs_ChDir(conn,saved_dir);
369 TALLOC_FREE(smb_fname_parent);
370 TALLOC_FREE(smb_fname_cwd);
374 /****************************************************************************
376 ****************************************************************************/
378 static NTSTATUS open_file(files_struct *fsp,
379 connection_struct *conn,
380 struct smb_request *req,
381 const char *parent_dir,
384 uint32 access_mask, /* client requested access mask. */
385 uint32 open_access_mask) /* what we're actually using in the open. */
387 struct smb_filename *smb_fname = fsp->fsp_name;
388 NTSTATUS status = NT_STATUS_OK;
389 int accmode = (flags & O_ACCMODE);
390 int local_flags = flags;
391 bool file_existed = VALID_STAT(fsp->fsp_name->st);
392 bool file_created = false;
397 /* Check permissions */
400 * This code was changed after seeing a client open request
401 * containing the open mode of (DENY_WRITE/read-only) with
402 * the 'create if not exist' bit set. The previous code
403 * would fail to open the file read only on a read-only share
404 * as it was checking the flags parameter directly against O_RDONLY,
405 * this was failing as the flags parameter was set to O_RDONLY|O_CREAT.
409 if (!CAN_WRITE(conn)) {
410 /* It's a read-only share - fail if we wanted to write. */
411 if(accmode != O_RDONLY || (flags & O_TRUNC) || (flags & O_APPEND)) {
412 DEBUG(3,("Permission denied opening %s\n",
413 smb_fname_str_dbg(smb_fname)));
414 return NT_STATUS_ACCESS_DENIED;
415 } else if(flags & O_CREAT) {
416 /* We don't want to write - but we must make sure that
417 O_CREAT doesn't create the file if we have write
418 access into the directory.
420 flags &= ~(O_CREAT|O_EXCL);
421 local_flags &= ~(O_CREAT|O_EXCL);
426 * This little piece of insanity is inspired by the
427 * fact that an NT client can open a file for O_RDONLY,
428 * but set the create disposition to FILE_EXISTS_TRUNCATE.
429 * If the client *can* write to the file, then it expects to
430 * truncate the file, even though it is opening for readonly.
431 * Quicken uses this stupid trick in backup file creation...
432 * Thanks *greatly* to "David W. Chapman Jr." <dwcjr@inethouston.net>
433 * for helping track this one down. It didn't bite us in 2.0.x
434 * as we always opened files read-write in that release. JRA.
437 if ((accmode == O_RDONLY) && ((flags & O_TRUNC) == O_TRUNC)) {
438 DEBUG(10,("open_file: truncate requested on read-only open "
439 "for file %s\n", smb_fname_str_dbg(smb_fname)));
440 local_flags = (flags & ~O_ACCMODE)|O_RDWR;
443 if ((open_access_mask & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_EXECUTE)) ||
444 (!file_existed && (local_flags & O_CREAT)) ||
445 ((local_flags & O_TRUNC) == O_TRUNC) ) {
449 * We can't actually truncate here as the file may be locked.
450 * open_file_ntcreate will take care of the truncate later. JRA.
453 local_flags &= ~O_TRUNC;
455 #if defined(O_NONBLOCK) && defined(S_ISFIFO)
457 * We would block on opening a FIFO with no one else on the
458 * other end. Do what we used to do and add O_NONBLOCK to the
462 if (file_existed && S_ISFIFO(smb_fname->st.st_ex_mode)) {
463 local_flags |= O_NONBLOCK;
467 /* Don't create files with Microsoft wildcard characters. */
470 * wildcard characters are allowed in stream names
471 * only test the basefilename
473 wild = fsp->base_fsp->fsp_name->base_name;
475 wild = smb_fname->base_name;
477 if ((local_flags & O_CREAT) && !file_existed &&
479 return NT_STATUS_OBJECT_NAME_INVALID;
482 /* Actually do the open */
483 status = fd_open(conn, fsp, local_flags, unx_mode);
484 if (!NT_STATUS_IS_OK(status)) {
485 DEBUG(3,("Error opening file %s (%s) (local_flags=%d) "
486 "(flags=%d)\n", smb_fname_str_dbg(smb_fname),
487 nt_errstr(status),local_flags,flags));
491 if ((local_flags & O_CREAT) && !file_existed) {
496 fsp->fh->fd = -1; /* What we used to call a stat open. */
498 uint32_t access_granted = 0;
500 status = smbd_check_open_rights(conn,
504 if (!NT_STATUS_IS_OK(status)) {
505 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
507 * On NT_STATUS_ACCESS_DENIED, access_granted
508 * contains the denied bits.
511 if ((access_mask & FILE_WRITE_ATTRIBUTES) &&
512 (access_granted & FILE_WRITE_ATTRIBUTES) &&
513 (lp_map_readonly(SNUM(conn)) ||
514 lp_map_archive(SNUM(conn)) ||
515 lp_map_hidden(SNUM(conn)) ||
516 lp_map_system(SNUM(conn)))) {
517 access_granted &= ~FILE_WRITE_ATTRIBUTES;
519 DEBUG(10,("open_file: "
528 if ((access_mask & DELETE_ACCESS) &&
529 (access_granted & DELETE_ACCESS) &&
530 can_delete_file_in_directory(conn,
532 /* Were we trying to do a stat open
533 * for delete and didn't get DELETE
534 * access (only) ? Check if the
535 * directory allows DELETE_CHILD.
537 * http://blogs.msdn.com/oldnewthing/archive/2004/06/04/148426.aspx
540 access_granted &= ~DELETE_ACCESS;
542 DEBUG(10,("open_file: "
550 if (access_granted != 0) {
551 DEBUG(10,("open_file: Access "
558 } else if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) &&
560 S_ISLNK(smb_fname->st.st_ex_mode)) {
561 /* This is a POSIX stat open for delete
562 * or rename on a symlink that points
564 DEBUG(10,("open_file: allowing POSIX "
565 "open on bad symlink %s\n",
569 DEBUG(10,("open_file: "
570 "smbd_check_open_rights on file "
572 smb_fname_str_dbg(smb_fname),
573 nt_errstr(status) ));
583 if (fsp->fh->fd == -1) {
584 ret = SMB_VFS_STAT(conn, smb_fname);
586 ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
587 /* If we have an fd, this stat should succeed. */
589 DEBUG(0,("Error doing fstat on open file %s "
591 smb_fname_str_dbg(smb_fname),
596 /* For a non-io open, this stat failing means file not found. JRA */
598 status = map_nt_error_from_unix(errno);
604 /* Do all inheritance work after we've
605 done a successful stat call and filled
606 in the stat struct in fsp->fsp_name. */
608 /* Inherit the ACL if required */
609 if (lp_inherit_perms(SNUM(conn))) {
610 inherit_access_posix_acl(conn, parent_dir,
611 smb_fname->base_name,
615 /* Change the owner if required. */
616 if (lp_inherit_owner(SNUM(conn))) {
617 change_file_owner_to_parent(conn, parent_dir,
621 notify_fname(conn, NOTIFY_ACTION_ADDED,
622 FILE_NOTIFY_CHANGE_FILE_NAME,
623 smb_fname->base_name);
628 * POSIX allows read-only opens of directories. We don't
629 * want to do this (we use a different code path for this)
630 * so catch a directory open and return an EISDIR. JRA.
633 if(S_ISDIR(smb_fname->st.st_ex_mode)) {
636 return NT_STATUS_FILE_IS_A_DIRECTORY;
639 fsp->mode = smb_fname->st.st_ex_mode;
640 fsp->file_id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
641 fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
642 fsp->file_pid = req ? req->smbpid : 0;
643 fsp->can_lock = True;
644 fsp->can_read = (access_mask & (FILE_READ_DATA)) ? True : False;
645 if (!CAN_WRITE(conn)) {
646 fsp->can_write = False;
648 fsp->can_write = (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ?
651 fsp->print_file = False;
652 fsp->modified = False;
653 fsp->sent_oplock_break = NO_BREAK_SENT;
654 fsp->is_directory = False;
655 if (conn->aio_write_behind_list &&
656 is_in_path(smb_fname->base_name, conn->aio_write_behind_list,
657 conn->case_sensitive)) {
658 fsp->aio_write_behind = True;
661 fsp->wcp = NULL; /* Write cache pointer. */
663 DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
664 conn->server_info->unix_name,
665 smb_fname_str_dbg(smb_fname),
666 BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
667 conn->num_files_open));
673 /****************************************************************************
674 Check if we can open a file with a share mode.
675 Returns True if conflict, False if not.
676 ****************************************************************************/
678 static bool share_conflict(struct share_mode_entry *entry,
682 DEBUG(10,("share_conflict: entry->access_mask = 0x%x, "
683 "entry->share_access = 0x%x, "
684 "entry->private_options = 0x%x\n",
685 (unsigned int)entry->access_mask,
686 (unsigned int)entry->share_access,
687 (unsigned int)entry->private_options));
689 DEBUG(10,("share_conflict: access_mask = 0x%x, share_access = 0x%x\n",
690 (unsigned int)access_mask, (unsigned int)share_access));
692 if ((entry->access_mask & (FILE_WRITE_DATA|
696 DELETE_ACCESS)) == 0) {
697 DEBUG(10,("share_conflict: No conflict due to "
698 "entry->access_mask = 0x%x\n",
699 (unsigned int)entry->access_mask ));
703 if ((access_mask & (FILE_WRITE_DATA|
707 DELETE_ACCESS)) == 0) {
708 DEBUG(10,("share_conflict: No conflict due to "
709 "access_mask = 0x%x\n",
710 (unsigned int)access_mask ));
714 #if 1 /* JRA TEST - Superdebug. */
715 #define CHECK_MASK(num, am, right, sa, share) \
716 DEBUG(10,("share_conflict: [%d] am (0x%x) & right (0x%x) = 0x%x\n", \
717 (unsigned int)(num), (unsigned int)(am), \
718 (unsigned int)(right), (unsigned int)(am)&(right) )); \
719 DEBUG(10,("share_conflict: [%d] sa (0x%x) & share (0x%x) = 0x%x\n", \
720 (unsigned int)(num), (unsigned int)(sa), \
721 (unsigned int)(share), (unsigned int)(sa)&(share) )); \
722 if (((am) & (right)) && !((sa) & (share))) { \
723 DEBUG(10,("share_conflict: check %d conflict am = 0x%x, right = 0x%x, \
724 sa = 0x%x, share = 0x%x\n", (num), (unsigned int)(am), (unsigned int)(right), (unsigned int)(sa), \
725 (unsigned int)(share) )); \
729 #define CHECK_MASK(num, am, right, sa, share) \
730 if (((am) & (right)) && !((sa) & (share))) { \
731 DEBUG(10,("share_conflict: check %d conflict am = 0x%x, right = 0x%x, \
732 sa = 0x%x, share = 0x%x\n", (num), (unsigned int)(am), (unsigned int)(right), (unsigned int)(sa), \
733 (unsigned int)(share) )); \
738 CHECK_MASK(1, entry->access_mask, FILE_WRITE_DATA | FILE_APPEND_DATA,
739 share_access, FILE_SHARE_WRITE);
740 CHECK_MASK(2, access_mask, FILE_WRITE_DATA | FILE_APPEND_DATA,
741 entry->share_access, FILE_SHARE_WRITE);
743 CHECK_MASK(3, entry->access_mask, FILE_READ_DATA | FILE_EXECUTE,
744 share_access, FILE_SHARE_READ);
745 CHECK_MASK(4, access_mask, FILE_READ_DATA | FILE_EXECUTE,
746 entry->share_access, FILE_SHARE_READ);
748 CHECK_MASK(5, entry->access_mask, DELETE_ACCESS,
749 share_access, FILE_SHARE_DELETE);
750 CHECK_MASK(6, access_mask, DELETE_ACCESS,
751 entry->share_access, FILE_SHARE_DELETE);
753 DEBUG(10,("share_conflict: No conflict.\n"));
757 #if defined(DEVELOPER)
758 static void validate_my_share_entries(int num,
759 struct share_mode_entry *share_entry)
763 if (!procid_is_me(&share_entry->pid)) {
767 if (is_deferred_open_entry(share_entry) &&
768 !open_was_deferred(share_entry->op_mid)) {
769 char *str = talloc_asprintf(talloc_tos(),
770 "Got a deferred entry without a request: "
772 share_mode_str(talloc_tos(), num, share_entry));
776 if (!is_valid_share_mode_entry(share_entry)) {
780 fsp = file_find_dif(share_entry->id,
781 share_entry->share_file_id);
783 DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
784 share_mode_str(talloc_tos(), num, share_entry) ));
785 smb_panic("validate_my_share_entries: Cannot match a "
786 "share entry with an open file\n");
789 if (is_deferred_open_entry(share_entry) ||
790 is_unused_share_mode_entry(share_entry)) {
794 if ((share_entry->op_type == NO_OPLOCK) &&
795 (fsp->oplock_type == FAKE_LEVEL_II_OPLOCK)) {
796 /* Someone has already written to it, but I haven't yet
801 if (((uint16)fsp->oplock_type) != share_entry->op_type) {
810 DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
811 share_mode_str(talloc_tos(), num, share_entry) ));
812 str = talloc_asprintf(talloc_tos(),
813 "validate_my_share_entries: "
814 "file %s, oplock_type = 0x%x, op_type = 0x%x\n",
815 fsp->fsp_name->base_name,
816 (unsigned int)fsp->oplock_type,
817 (unsigned int)share_entry->op_type );
823 bool is_stat_open(uint32 access_mask)
825 return (access_mask &&
826 ((access_mask & ~(SYNCHRONIZE_ACCESS| FILE_READ_ATTRIBUTES|
827 FILE_WRITE_ATTRIBUTES))==0) &&
828 ((access_mask & (SYNCHRONIZE_ACCESS|FILE_READ_ATTRIBUTES|
829 FILE_WRITE_ATTRIBUTES)) != 0));
832 /****************************************************************************
833 Deal with share modes
834 Invarient: Share mode must be locked on entry and exit.
835 Returns -1 on error, or number of share modes on success (may be zero).
836 ****************************************************************************/
838 static NTSTATUS open_mode_check(connection_struct *conn,
839 struct share_mode_lock *lck,
842 uint32 create_options,
847 if(lck->num_share_modes == 0) {
851 *file_existed = True;
853 /* A delete on close prohibits everything */
855 if (lck->delete_on_close) {
856 return NT_STATUS_DELETE_PENDING;
859 if (is_stat_open(access_mask)) {
860 /* Stat open that doesn't trigger oplock breaks or share mode
861 * checks... ! JRA. */
866 * Check if the share modes will give us access.
869 #if defined(DEVELOPER)
870 for(i = 0; i < lck->num_share_modes; i++) {
871 validate_my_share_entries(i, &lck->share_modes[i]);
875 if (!lp_share_modes(SNUM(conn))) {
879 /* Now we check the share modes, after any oplock breaks. */
880 for(i = 0; i < lck->num_share_modes; i++) {
882 if (!is_valid_share_mode_entry(&lck->share_modes[i])) {
886 /* someone else has a share lock on it, check to see if we can
888 if (share_conflict(&lck->share_modes[i],
889 access_mask, share_access)) {
890 return NT_STATUS_SHARING_VIOLATION;
898 * Send a break message to the oplock holder and delay the open for
902 static NTSTATUS send_break_message(files_struct *fsp,
903 struct share_mode_entry *exclusive,
908 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
910 DEBUG(10, ("Sending break request to PID %s\n",
911 procid_str_static(&exclusive->pid)));
912 exclusive->op_mid = mid;
914 /* Create the message. */
915 share_mode_entry_to_message(msg, exclusive);
917 /* Add in the FORCE_OPLOCK_BREAK_TO_NONE bit in the message if set. We
918 don't want this set in the share mode struct pointed to by lck. */
920 if (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE) {
921 SSVAL(msg,6,exclusive->op_type | FORCE_OPLOCK_BREAK_TO_NONE);
924 status = messaging_send_buf(smbd_messaging_context(), exclusive->pid,
925 MSG_SMB_BREAK_REQUEST,
927 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
928 if (!NT_STATUS_IS_OK(status)) {
929 DEBUG(3, ("Could not send oplock break message: %s\n",
937 * 1) No files open at all or internal open: Grant whatever the client wants.
939 * 2) Exclusive (or batch) oplock around: If the requested access is a delete
940 * request, break if the oplock around is a batch oplock. If it's another
941 * requested access type, break.
943 * 3) Only level2 around: Grant level2 and do nothing else.
946 static bool delay_for_oplocks(struct share_mode_lock *lck,
953 struct share_mode_entry *exclusive = NULL;
954 bool valid_entry = false;
955 bool have_level2 = false;
956 bool have_a_none_oplock = false;
957 bool allow_level2 = (global_client_caps & CAP_LEVEL_II_OPLOCKS) &&
958 lp_level2_oplocks(SNUM(fsp->conn));
960 if (oplock_request & INTERNAL_OPEN_ONLY) {
961 fsp->oplock_type = NO_OPLOCK;
964 if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
968 for (i=0; i<lck->num_share_modes; i++) {
970 if (!is_valid_share_mode_entry(&lck->share_modes[i])) {
974 /* At least one entry is not an invalid or deferred entry. */
977 if (pass_number == 1) {
978 if (BATCH_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
979 SMB_ASSERT(exclusive == NULL);
980 exclusive = &lck->share_modes[i];
983 if (EXCLUSIVE_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
984 SMB_ASSERT(exclusive == NULL);
985 exclusive = &lck->share_modes[i];
989 if (LEVEL_II_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
990 SMB_ASSERT(exclusive == NULL);
994 if (lck->share_modes[i].op_type == NO_OPLOCK) {
995 have_a_none_oplock = true;
999 if (exclusive != NULL) { /* Found an exclusive oplock */
1000 SMB_ASSERT(!have_level2);
1001 send_break_message(fsp, exclusive, mid, oplock_request);
1006 * Match what was requested (fsp->oplock_type) with
1007 * what was found in the existing share modes.
1011 /* All entries are placeholders or deferred.
1012 * Directly grant whatever the client wants. */
1013 if (fsp->oplock_type == NO_OPLOCK) {
1014 /* Store a level2 oplock, but don't tell the client */
1015 fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
1017 } else if (have_a_none_oplock) {
1018 fsp->oplock_type = NO_OPLOCK;
1019 } else if (have_level2) {
1020 if (fsp->oplock_type == NO_OPLOCK ||
1021 fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
1022 /* Store a level2 oplock, but don't tell the client */
1023 fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
1025 fsp->oplock_type = LEVEL_II_OPLOCK;
1028 /* This case can never happen. */
1033 * Don't grant level2 to clients that don't want them
1034 * or if we've turned them off.
1036 if (fsp->oplock_type == LEVEL_II_OPLOCK && !allow_level2) {
1037 fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
1040 DEBUG(10,("delay_for_oplocks: oplock type 0x%x on file %s\n",
1041 fsp->oplock_type, fsp_str_dbg(fsp)));
1047 bool request_timed_out(struct timeval request_time,
1048 struct timeval timeout)
1050 struct timeval now, end_time;
1052 end_time = timeval_sum(&request_time, &timeout);
1053 return (timeval_compare(&end_time, &now) < 0);
1056 /****************************************************************************
1057 Handle the 1 second delay in returning a SHARING_VIOLATION error.
1058 ****************************************************************************/
1060 static void defer_open(struct share_mode_lock *lck,
1061 struct timeval request_time,
1062 struct timeval timeout,
1063 struct smb_request *req,
1064 struct deferred_open_record *state)
1068 /* Paranoia check */
1070 for (i=0; i<lck->num_share_modes; i++) {
1071 struct share_mode_entry *e = &lck->share_modes[i];
1073 if (!is_deferred_open_entry(e)) {
1077 if (procid_is_me(&e->pid) && (e->op_mid == req->mid)) {
1078 DEBUG(0, ("Trying to defer an already deferred "
1079 "request: mid=%d, exiting\n", req->mid));
1080 exit_server("attempt to defer a deferred request");
1084 /* End paranoia check */
1086 DEBUG(10,("defer_open_sharing_error: time [%u.%06u] adding deferred "
1087 "open entry for mid %u\n",
1088 (unsigned int)request_time.tv_sec,
1089 (unsigned int)request_time.tv_usec,
1090 (unsigned int)req->mid));
1092 if (!push_deferred_smb_message(req, request_time, timeout,
1093 (char *)state, sizeof(*state))) {
1094 exit_server("push_deferred_smb_message failed");
1096 add_deferred_open(lck, req->mid, request_time, state->id);
1100 /****************************************************************************
1101 On overwrite open ensure that the attributes match.
1102 ****************************************************************************/
1104 bool open_match_attributes(connection_struct *conn,
1105 uint32 old_dos_attr,
1106 uint32 new_dos_attr,
1107 mode_t existing_unx_mode,
1108 mode_t new_unx_mode,
1109 mode_t *returned_unx_mode)
1111 uint32 noarch_old_dos_attr, noarch_new_dos_attr;
1113 noarch_old_dos_attr = (old_dos_attr & ~FILE_ATTRIBUTE_ARCHIVE);
1114 noarch_new_dos_attr = (new_dos_attr & ~FILE_ATTRIBUTE_ARCHIVE);
1116 if((noarch_old_dos_attr == 0 && noarch_new_dos_attr != 0) ||
1117 (noarch_old_dos_attr != 0 && ((noarch_old_dos_attr & noarch_new_dos_attr) == noarch_old_dos_attr))) {
1118 *returned_unx_mode = new_unx_mode;
1120 *returned_unx_mode = (mode_t)0;
1123 DEBUG(10,("open_match_attributes: old_dos_attr = 0x%x, "
1124 "existing_unx_mode = 0%o, new_dos_attr = 0x%x "
1125 "returned_unx_mode = 0%o\n",
1126 (unsigned int)old_dos_attr,
1127 (unsigned int)existing_unx_mode,
1128 (unsigned int)new_dos_attr,
1129 (unsigned int)*returned_unx_mode ));
1131 /* If we're mapping SYSTEM and HIDDEN ensure they match. */
1132 if (lp_map_system(SNUM(conn)) || lp_store_dos_attributes(SNUM(conn))) {
1133 if ((old_dos_attr & FILE_ATTRIBUTE_SYSTEM) &&
1134 !(new_dos_attr & FILE_ATTRIBUTE_SYSTEM)) {
1138 if (lp_map_hidden(SNUM(conn)) || lp_store_dos_attributes(SNUM(conn))) {
1139 if ((old_dos_attr & FILE_ATTRIBUTE_HIDDEN) &&
1140 !(new_dos_attr & FILE_ATTRIBUTE_HIDDEN)) {
1147 /****************************************************************************
1148 Special FCB or DOS processing in the case of a sharing violation.
1149 Try and find a duplicated file handle.
1150 ****************************************************************************/
1152 NTSTATUS fcb_or_dos_open(struct smb_request *req,
1153 connection_struct *conn,
1154 files_struct *fsp_to_dup_into,
1155 const struct smb_filename *smb_fname,
1160 uint32 share_access,
1161 uint32 create_options)
1165 DEBUG(5,("fcb_or_dos_open: attempting old open semantics for "
1166 "file %s.\n", smb_fname_str_dbg(smb_fname)));
1168 for(fsp = file_find_di_first(id); fsp;
1169 fsp = file_find_di_next(fsp)) {
1171 DEBUG(10,("fcb_or_dos_open: checking file %s, fd = %d, "
1172 "vuid = %u, file_pid = %u, private_options = 0x%x "
1173 "access_mask = 0x%x\n", fsp_str_dbg(fsp),
1174 fsp->fh->fd, (unsigned int)fsp->vuid,
1175 (unsigned int)fsp->file_pid,
1176 (unsigned int)fsp->fh->private_options,
1177 (unsigned int)fsp->access_mask ));
1179 if (fsp->fh->fd != -1 &&
1180 fsp->vuid == vuid &&
1181 fsp->file_pid == file_pid &&
1182 (fsp->fh->private_options & (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS |
1183 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) &&
1184 (fsp->access_mask & FILE_WRITE_DATA) &&
1185 strequal(fsp->fsp_name->base_name, smb_fname->base_name) &&
1186 strequal(fsp->fsp_name->stream_name,
1187 smb_fname->stream_name)) {
1188 DEBUG(10,("fcb_or_dos_open: file match\n"));
1194 return NT_STATUS_NOT_FOUND;
1197 /* quite an insane set of semantics ... */
1198 if (is_executable(smb_fname->base_name) &&
1199 (fsp->fh->private_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS)) {
1200 DEBUG(10,("fcb_or_dos_open: file fail due to is_executable.\n"));
1201 return NT_STATUS_INVALID_PARAMETER;
1204 /* We need to duplicate this fsp. */
1205 return dup_file_fsp(req, fsp, access_mask, share_access,
1206 create_options, fsp_to_dup_into);
1209 static void schedule_defer_open(struct share_mode_lock *lck,
1210 struct timeval request_time,
1211 struct smb_request *req)
1213 struct deferred_open_record state;
1215 /* This is a relative time, added to the absolute
1216 request_time value to get the absolute timeout time.
1217 Note that if this is the second or greater time we enter
1218 this codepath for this particular request mid then
1219 request_time is left as the absolute time of the *first*
1220 time this request mid was processed. This is what allows
1221 the request to eventually time out. */
1223 struct timeval timeout;
1225 /* Normally the smbd we asked should respond within
1226 * OPLOCK_BREAK_TIMEOUT seconds regardless of whether
1227 * the client did, give twice the timeout as a safety
1228 * measure here in case the other smbd is stuck
1229 * somewhere else. */
1231 timeout = timeval_set(OPLOCK_BREAK_TIMEOUT*2, 0);
1233 /* Nothing actually uses state.delayed_for_oplocks
1234 but it's handy to differentiate in debug messages
1235 between a 30 second delay due to oplock break, and
1236 a 1 second delay for share mode conflicts. */
1238 state.delayed_for_oplocks = True;
1241 if (!request_timed_out(request_time, timeout)) {
1242 defer_open(lck, request_time, timeout, req, &state);
1246 /****************************************************************************
1247 Work out what access_mask to use from what the client sent us.
1248 ****************************************************************************/
1250 static NTSTATUS calculate_access_mask(connection_struct *conn,
1251 const struct smb_filename *smb_fname,
1253 uint32_t access_mask,
1254 uint32_t *access_mask_out)
1259 * Convert GENERIC bits to specific bits.
1262 se_map_generic(&access_mask, &file_generic_mapping);
1264 /* Calculate MAXIMUM_ALLOWED_ACCESS if requested. */
1265 if (access_mask & MAXIMUM_ALLOWED_ACCESS) {
1268 struct security_descriptor *sd;
1269 uint32_t access_granted = 0;
1271 status = SMB_VFS_GET_NT_ACL(conn, smb_fname->base_name,
1272 (OWNER_SECURITY_INFORMATION |
1273 GROUP_SECURITY_INFORMATION |
1274 DACL_SECURITY_INFORMATION),&sd);
1276 if (!NT_STATUS_IS_OK(status)) {
1277 DEBUG(10, ("calculate_access_mask: Could not get acl "
1279 smb_fname_str_dbg(smb_fname),
1280 nt_errstr(status)));
1281 return NT_STATUS_ACCESS_DENIED;
1284 status = smb1_file_se_access_check(conn,
1286 conn->server_info->ptok,
1292 if (!NT_STATUS_IS_OK(status)) {
1293 DEBUG(10, ("calculate_access_mask: Access denied on "
1294 "file %s: when calculating maximum access\n",
1295 smb_fname_str_dbg(smb_fname)));
1296 return NT_STATUS_ACCESS_DENIED;
1299 access_mask = access_granted;
1301 access_mask = FILE_GENERIC_ALL;
1305 *access_mask_out = access_mask;
1306 return NT_STATUS_OK;
1309 /****************************************************************************
1310 Open a file with a share mode. Passed in an already created files_struct *.
1311 ****************************************************************************/
1313 static NTSTATUS open_file_ntcreate(connection_struct *conn,
1314 struct smb_request *req,
1315 uint32 access_mask, /* access bits (FILE_READ_DATA etc.) */
1316 uint32 share_access, /* share constants (FILE_SHARE_READ etc) */
1317 uint32 create_disposition, /* FILE_OPEN_IF etc. */
1318 uint32 create_options, /* options such as delete on close. */
1319 uint32 new_dos_attributes, /* attributes used for new file. */
1320 int oplock_request, /* internal Samba oplock codes. */
1321 /* Information (FILE_EXISTS etc.) */
1325 struct smb_filename *smb_fname = fsp->fsp_name;
1328 bool file_existed = VALID_STAT(smb_fname->st);
1329 bool def_acl = False;
1330 bool posix_open = False;
1331 bool new_file_created = False;
1332 bool clear_ads = false;
1334 NTSTATUS fsp_open = NT_STATUS_ACCESS_DENIED;
1335 mode_t new_unx_mode = (mode_t)0;
1336 mode_t unx_mode = (mode_t)0;
1338 uint32 existing_dos_attributes = 0;
1339 struct pending_message_list *pml = NULL;
1340 struct timeval request_time = timeval_zero();
1341 struct share_mode_lock *lck = NULL;
1342 uint32 open_access_mask = access_mask;
1348 if (conn->printer) {
1350 * Printers are handled completely differently.
1351 * Most of the passed parameters are ignored.
1355 *pinfo = FILE_WAS_CREATED;
1358 DEBUG(10, ("open_file_ntcreate: printer open fname=%s\n",
1359 smb_fname_str_dbg(smb_fname)));
1362 DEBUG(0,("open_file_ntcreate: printer open without "
1363 "an SMB request!\n"));
1364 return NT_STATUS_INTERNAL_ERROR;
1367 return print_fsp_open(req, conn, smb_fname->base_name,
1371 if (!parent_dirname(talloc_tos(), smb_fname->base_name, &parent_dir,
1373 return NT_STATUS_NO_MEMORY;
1376 if (new_dos_attributes & FILE_FLAG_POSIX_SEMANTICS) {
1378 unx_mode = (mode_t)(new_dos_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
1379 new_dos_attributes = 0;
1381 /* Windows allows a new file to be created and
1382 silently removes a FILE_ATTRIBUTE_DIRECTORY
1383 sent by the client. Do the same. */
1385 new_dos_attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
1387 /* We add aARCH to this as this mode is only used if the file is
1389 unx_mode = unix_mode(conn, new_dos_attributes | aARCH,
1390 smb_fname, parent_dir);
1393 DEBUG(10, ("open_file_ntcreate: fname=%s, dos_attrs=0x%x "
1394 "access_mask=0x%x share_access=0x%x "
1395 "create_disposition = 0x%x create_options=0x%x "
1396 "unix mode=0%o oplock_request=%d\n",
1397 smb_fname_str_dbg(smb_fname), new_dos_attributes,
1398 access_mask, share_access, create_disposition,
1399 create_options, (unsigned int)unx_mode, oplock_request));
1401 if ((req == NULL) && ((oplock_request & INTERNAL_OPEN_ONLY) == 0)) {
1402 DEBUG(0, ("No smb request but not an internal only open!\n"));
1403 return NT_STATUS_INTERNAL_ERROR;
1407 * Only non-internal opens can be deferred at all
1411 && ((pml = get_open_deferred_message(req->mid)) != NULL)) {
1412 struct deferred_open_record *state =
1413 (struct deferred_open_record *)pml->private_data.data;
1415 /* Remember the absolute time of the original
1416 request with this mid. We'll use it later to
1417 see if this has timed out. */
1419 request_time = pml->request_time;
1421 /* Remove the deferred open entry under lock. */
1422 lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL,
1425 DEBUG(0, ("could not get share mode lock\n"));
1427 del_deferred_open_entry(lck, req->mid);
1431 /* Ensure we don't reprocess this message. */
1432 remove_deferred_open_smb_message(req->mid);
1436 new_dos_attributes &= SAMBA_ATTRIBUTES_MASK;
1438 existing_dos_attributes = dos_mode(conn, smb_fname);
1442 /* ignore any oplock requests if oplocks are disabled */
1443 if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break ||
1444 IS_VETO_OPLOCK_PATH(conn, smb_fname->base_name)) {
1445 /* Mask off everything except the private Samba bits. */
1446 oplock_request &= SAMBA_PRIVATE_OPLOCK_MASK;
1449 /* this is for OS/2 long file names - say we don't support them */
1450 if (!lp_posix_pathnames() && strstr(smb_fname->base_name,".+,;=[].")) {
1451 /* OS/2 Workplace shell fix may be main code stream in a later
1453 DEBUG(5,("open_file_ntcreate: OS/2 long filenames are not "
1455 if (use_nt_status()) {
1456 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1458 return NT_STATUS_DOS(ERRDOS, ERRcannotopen);
1461 switch( create_disposition ) {
1463 * Currently we're using FILE_SUPERSEDE as the same as
1464 * FILE_OVERWRITE_IF but they really are
1465 * different. FILE_SUPERSEDE deletes an existing file
1466 * (requiring delete access) then recreates it.
1468 case FILE_SUPERSEDE:
1469 /* If file exists replace/overwrite. If file doesn't
1471 flags2 |= (O_CREAT | O_TRUNC);
1475 case FILE_OVERWRITE_IF:
1476 /* If file exists replace/overwrite. If file doesn't
1478 flags2 |= (O_CREAT | O_TRUNC);
1483 /* If file exists open. If file doesn't exist error. */
1484 if (!file_existed) {
1485 DEBUG(5,("open_file_ntcreate: FILE_OPEN "
1486 "requested for file %s and file "
1488 smb_fname_str_dbg(smb_fname)));
1490 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1494 case FILE_OVERWRITE:
1495 /* If file exists overwrite. If file doesn't exist
1497 if (!file_existed) {
1498 DEBUG(5,("open_file_ntcreate: FILE_OVERWRITE "
1499 "requested for file %s and file "
1501 smb_fname_str_dbg(smb_fname) ));
1503 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1510 /* If file exists error. If file doesn't exist
1513 DEBUG(5,("open_file_ntcreate: FILE_CREATE "
1514 "requested for file %s and file "
1515 "already exists.\n",
1516 smb_fname_str_dbg(smb_fname)));
1517 if (S_ISDIR(smb_fname->st.st_ex_mode)) {
1522 return map_nt_error_from_unix(errno);
1524 flags2 |= (O_CREAT|O_EXCL);
1528 /* If file exists open. If file doesn't exist
1534 return NT_STATUS_INVALID_PARAMETER;
1537 /* We only care about matching attributes on file exists and
1540 if (!posix_open && file_existed && ((create_disposition == FILE_OVERWRITE) ||
1541 (create_disposition == FILE_OVERWRITE_IF))) {
1542 if (!open_match_attributes(conn, existing_dos_attributes,
1544 smb_fname->st.st_ex_mode,
1545 unx_mode, &new_unx_mode)) {
1546 DEBUG(5,("open_file_ntcreate: attributes missmatch "
1547 "for file %s (%x %x) (0%o, 0%o)\n",
1548 smb_fname_str_dbg(smb_fname),
1549 existing_dos_attributes,
1551 (unsigned int)smb_fname->st.st_ex_mode,
1552 (unsigned int)unx_mode ));
1554 return NT_STATUS_ACCESS_DENIED;
1558 status = calculate_access_mask(conn, smb_fname, file_existed,
1561 if (!NT_STATUS_IS_OK(status)) {
1562 DEBUG(10, ("open_file_ntcreate: calculate_access_mask "
1563 "on file %s returned %s\n",
1564 smb_fname_str_dbg(smb_fname), nt_errstr(status)));
1568 open_access_mask = access_mask;
1570 if ((flags2 & O_TRUNC) || (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE)) {
1571 open_access_mask |= FILE_WRITE_DATA; /* This will cause oplock breaks. */
1574 DEBUG(10, ("open_file_ntcreate: fname=%s, after mapping "
1575 "access_mask=0x%x\n", smb_fname_str_dbg(smb_fname),
1579 * Note that we ignore the append flag as append does not
1580 * mean the same thing under DOS and Unix.
1583 if ((access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ||
1584 (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE)) {
1585 /* DENY_DOS opens are always underlying read-write on the
1586 file handle, no matter what the requested access mask
1588 if ((create_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS) ||
1589 access_mask & (FILE_READ_ATTRIBUTES|FILE_READ_DATA|FILE_READ_EA|FILE_EXECUTE)) {
1599 * Currently we only look at FILE_WRITE_THROUGH for create options.
1603 if ((create_options & FILE_WRITE_THROUGH) && lp_strict_sync(SNUM(conn))) {
1608 if (posix_open && (access_mask & FILE_APPEND_DATA)) {
1612 if (!posix_open && !CAN_WRITE(conn)) {
1614 * We should really return a permission denied error if either
1615 * O_CREAT or O_TRUNC are set, but for compatibility with
1616 * older versions of Samba we just AND them out.
1618 flags2 &= ~(O_CREAT|O_TRUNC);
1622 * Ensure we can't write on a read-only share or file.
1625 if (flags != O_RDONLY && file_existed &&
1626 (!CAN_WRITE(conn) || IS_DOS_READONLY(existing_dos_attributes))) {
1627 DEBUG(5,("open_file_ntcreate: write access requested for "
1628 "file %s on read only %s\n",
1629 smb_fname_str_dbg(smb_fname),
1630 !CAN_WRITE(conn) ? "share" : "file" ));
1632 return NT_STATUS_ACCESS_DENIED;
1635 fsp->file_id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
1636 fsp->share_access = share_access;
1637 fsp->fh->private_options = create_options;
1638 fsp->access_mask = open_access_mask; /* We change this to the
1639 * requested access_mask after
1640 * the open is done. */
1641 fsp->posix_open = posix_open;
1643 /* Ensure no SAMBA_PRIVATE bits can be set. */
1644 fsp->oplock_type = (oplock_request & ~SAMBA_PRIVATE_OPLOCK_MASK);
1646 if (timeval_is_zero(&request_time)) {
1647 request_time = fsp->open_time;
1651 struct timespec old_write_time = smb_fname->st.st_ex_mtime;
1652 id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
1654 lck = get_share_mode_lock(talloc_tos(), id,
1656 smb_fname, &old_write_time);
1659 DEBUG(0, ("Could not get share mode lock\n"));
1660 return NT_STATUS_SHARING_VIOLATION;
1663 /* First pass - send break only on batch oplocks. */
1665 && delay_for_oplocks(lck, fsp, req->mid, 1,
1667 schedule_defer_open(lck, request_time, req);
1669 return NT_STATUS_SHARING_VIOLATION;
1672 /* Use the client requested access mask here, not the one we
1674 status = open_mode_check(conn, lck, access_mask, share_access,
1675 create_options, &file_existed);
1677 if (NT_STATUS_IS_OK(status)) {
1678 /* We might be going to allow this open. Check oplock
1680 /* Second pass - send break for both batch or
1681 * exclusive oplocks. */
1683 && delay_for_oplocks(lck, fsp, req->mid, 2,
1685 schedule_defer_open(lck, request_time, req);
1687 return NT_STATUS_SHARING_VIOLATION;
1691 if (NT_STATUS_EQUAL(status, NT_STATUS_DELETE_PENDING)) {
1692 /* DELETE_PENDING is not deferred for a second */
1697 if (!NT_STATUS_IS_OK(status)) {
1698 uint32 can_access_mask;
1699 bool can_access = True;
1701 SMB_ASSERT(NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION));
1703 /* Check if this can be done with the deny_dos and fcb
1705 if (create_options &
1706 (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
1707 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
1709 DEBUG(0, ("DOS open without an SMB "
1712 return NT_STATUS_INTERNAL_ERROR;
1715 /* Use the client requested access mask here,
1716 * not the one we open with. */
1717 status = fcb_or_dos_open(req,
1728 if (NT_STATUS_IS_OK(status)) {
1731 *pinfo = FILE_WAS_OPENED;
1733 return NT_STATUS_OK;
1738 * This next line is a subtlety we need for
1739 * MS-Access. If a file open will fail due to share
1740 * permissions and also for security (access) reasons,
1741 * we need to return the access failed error, not the
1742 * share error. We can't open the file due to kernel
1743 * oplock deadlock (it's possible we failed above on
1744 * the open_mode_check()) so use a userspace check.
1747 if (flags & O_RDWR) {
1748 can_access_mask = FILE_READ_DATA|FILE_WRITE_DATA;
1749 } else if (flags & O_WRONLY) {
1750 can_access_mask = FILE_WRITE_DATA;
1752 can_access_mask = FILE_READ_DATA;
1755 if (((can_access_mask & FILE_WRITE_DATA) &&
1756 !CAN_WRITE(conn)) ||
1757 !can_access_file_data(conn, smb_fname,
1763 * If we're returning a share violation, ensure we
1764 * cope with the braindead 1 second delay.
1767 if (!(oplock_request & INTERNAL_OPEN_ONLY) &&
1768 lp_defer_sharing_violations()) {
1769 struct timeval timeout;
1770 struct deferred_open_record state;
1773 /* this is a hack to speed up torture tests
1775 timeout_usecs = lp_parm_int(SNUM(conn),
1776 "smbd","sharedelay",
1777 SHARING_VIOLATION_USEC_WAIT);
1779 /* This is a relative time, added to the absolute
1780 request_time value to get the absolute timeout time.
1781 Note that if this is the second or greater time we enter
1782 this codepath for this particular request mid then
1783 request_time is left as the absolute time of the *first*
1784 time this request mid was processed. This is what allows
1785 the request to eventually time out. */
1787 timeout = timeval_set(0, timeout_usecs);
1789 /* Nothing actually uses state.delayed_for_oplocks
1790 but it's handy to differentiate in debug messages
1791 between a 30 second delay due to oplock break, and
1792 a 1 second delay for share mode conflicts. */
1794 state.delayed_for_oplocks = False;
1798 && !request_timed_out(request_time,
1800 defer_open(lck, request_time, timeout,
1808 * We have detected a sharing violation here
1809 * so return the correct error code
1811 status = NT_STATUS_SHARING_VIOLATION;
1813 status = NT_STATUS_ACCESS_DENIED;
1819 * We exit this block with the share entry *locked*.....
1823 SMB_ASSERT(!file_existed || (lck != NULL));
1826 * Ensure we pay attention to default ACLs on directories if required.
1829 if ((flags2 & O_CREAT) && lp_inherit_acls(SNUM(conn)) &&
1830 (def_acl = directory_has_default_acl(conn, parent_dir))) {
1831 unx_mode = (0777 & lp_create_mask(SNUM(conn)));
1834 DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o, "
1835 "access_mask = 0x%x, open_access_mask = 0x%x\n",
1836 (unsigned int)flags, (unsigned int)flags2,
1837 (unsigned int)unx_mode, (unsigned int)access_mask,
1838 (unsigned int)open_access_mask));
1841 * open_file strips any O_TRUNC flags itself.
1844 fsp_open = open_file(fsp, conn, req, parent_dir,
1845 flags|flags2, unx_mode, access_mask,
1848 if (!NT_STATUS_IS_OK(fsp_open)) {
1855 if (!file_existed) {
1856 struct timespec old_write_time = smb_fname->st.st_ex_mtime;
1858 * Deal with the race condition where two smbd's detect the
1859 * file doesn't exist and do the create at the same time. One
1860 * of them will win and set a share mode, the other (ie. this
1861 * one) should check if the requested share mode for this
1862 * create is allowed.
1866 * Now the file exists and fsp is successfully opened,
1867 * fsp->dev and fsp->inode are valid and should replace the
1868 * dev=0,inode=0 from a non existent file. Spotted by
1869 * Nadav Danieli <nadavd@exanet.com>. JRA.
1874 lck = get_share_mode_lock(talloc_tos(), id,
1876 smb_fname, &old_write_time);
1879 DEBUG(0, ("open_file_ntcreate: Could not get share "
1880 "mode lock for %s\n",
1881 smb_fname_str_dbg(smb_fname)));
1883 return NT_STATUS_SHARING_VIOLATION;
1886 /* First pass - send break only on batch oplocks. */
1888 && delay_for_oplocks(lck, fsp, req->mid, 1,
1890 schedule_defer_open(lck, request_time, req);
1893 return NT_STATUS_SHARING_VIOLATION;
1896 status = open_mode_check(conn, lck, access_mask, share_access,
1897 create_options, &file_existed);
1899 if (NT_STATUS_IS_OK(status)) {
1900 /* We might be going to allow this open. Check oplock
1902 /* Second pass - send break for both batch or
1903 * exclusive oplocks. */
1905 && delay_for_oplocks(lck, fsp, req->mid, 2,
1907 schedule_defer_open(lck, request_time, req);
1910 return NT_STATUS_SHARING_VIOLATION;
1914 if (!NT_STATUS_IS_OK(status)) {
1915 struct deferred_open_record state;
1919 state.delayed_for_oplocks = False;
1922 /* Do it all over again immediately. In the second
1923 * round we will find that the file existed and handle
1924 * the DELETE_PENDING and FCB cases correctly. No need
1925 * to duplicate the code here. Essentially this is a
1926 * "goto top of this function", but don't tell
1930 defer_open(lck, request_time, timeval_zero(),
1938 * We exit this block with the share entry *locked*.....
1943 SMB_ASSERT(lck != NULL);
1945 /* Delete streams if create_disposition requires it */
1946 if (file_existed && clear_ads &&
1947 !is_ntfs_stream_smb_fname(smb_fname)) {
1948 status = delete_all_streams(conn, smb_fname->base_name);
1949 if (!NT_STATUS_IS_OK(status)) {
1956 /* note that we ignore failure for the following. It is
1957 basically a hack for NFS, and NFS will never set one of
1958 these only read them. Nobody but Samba can ever set a deny
1959 mode and we have already checked our more authoritative
1960 locking database for permission to set this deny mode. If
1961 the kernel refuses the operations then the kernel is wrong.
1962 note that GPFS supports it as well - jmcd */
1964 if (fsp->fh->fd != -1) {
1966 ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, share_access, access_mask);
1967 if(ret_flock == -1 ){
1972 return NT_STATUS_SHARING_VIOLATION;
1977 * At this point onwards, we can guarentee that the share entry
1978 * is locked, whether we created the file or not, and that the
1979 * deny mode is compatible with all current opens.
1983 * If requested, truncate the file.
1986 if (flags2&O_TRUNC) {
1988 * We are modifing the file after open - update the stat
1991 if ((SMB_VFS_FTRUNCATE(fsp, 0) == -1) ||
1992 (SMB_VFS_FSTAT(fsp, &smb_fname->st)==-1)) {
1993 status = map_nt_error_from_unix(errno);
2000 /* Record the options we were opened with. */
2001 fsp->share_access = share_access;
2002 fsp->fh->private_options = create_options;
2004 * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
2006 fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
2009 /* stat opens on existing files don't get oplocks. */
2010 if (is_stat_open(open_access_mask)) {
2011 fsp->oplock_type = NO_OPLOCK;
2014 if (!(flags2 & O_TRUNC)) {
2015 info = FILE_WAS_OPENED;
2017 info = FILE_WAS_OVERWRITTEN;
2020 info = FILE_WAS_CREATED;
2028 * Setup the oplock info in both the shared memory and
2032 if (!set_file_oplock(fsp, fsp->oplock_type)) {
2033 /* Could not get the kernel oplock */
2034 fsp->oplock_type = NO_OPLOCK;
2037 if (info == FILE_WAS_OVERWRITTEN || info == FILE_WAS_CREATED || info == FILE_WAS_SUPERSEDED) {
2038 new_file_created = True;
2041 set_share_mode(lck, fsp, conn->server_info->utok.uid, 0,
2044 /* Handle strange delete on close create semantics. */
2045 if (create_options & FILE_DELETE_ON_CLOSE) {
2047 status = can_set_delete_on_close(fsp, new_dos_attributes);
2049 if (!NT_STATUS_IS_OK(status)) {
2050 /* Remember to delete the mode we just added. */
2051 del_share_mode(lck, fsp);
2056 /* Note that here we set the *inital* delete on close flag,
2057 not the regular one. The magic gets handled in close. */
2058 fsp->initial_delete_on_close = True;
2061 if (new_file_created) {
2062 /* Files should be initially set as archive */
2063 if (lp_map_archive(SNUM(conn)) ||
2064 lp_store_dos_attributes(SNUM(conn))) {
2066 if (file_set_dosmode(conn, smb_fname,
2067 new_dos_attributes | aARCH,
2068 parent_dir, true) == 0) {
2069 unx_mode = smb_fname->st.st_ex_mode;
2076 * Take care of inherited ACLs on created files - if default ACL not
2080 if (!posix_open && !file_existed && !def_acl) {
2082 int saved_errno = errno; /* We might get ENOSYS in the next
2085 if (SMB_VFS_FCHMOD_ACL(fsp, unx_mode) == -1 &&
2087 errno = saved_errno; /* Ignore ENOSYS */
2090 } else if (new_unx_mode) {
2094 /* Attributes need changing. File already existed. */
2097 int saved_errno = errno; /* We might get ENOSYS in the
2099 ret = SMB_VFS_FCHMOD_ACL(fsp, new_unx_mode);
2101 if (ret == -1 && errno == ENOSYS) {
2102 errno = saved_errno; /* Ignore ENOSYS */
2104 DEBUG(5, ("open_file_ntcreate: reset "
2105 "attributes of file %s to 0%o\n",
2106 smb_fname_str_dbg(smb_fname),
2107 (unsigned int)new_unx_mode));
2108 ret = 0; /* Don't do the fchmod below. */
2113 (SMB_VFS_FCHMOD(fsp, new_unx_mode) == -1))
2114 DEBUG(5, ("open_file_ntcreate: failed to reset "
2115 "attributes of file %s to 0%o\n",
2116 smb_fname_str_dbg(smb_fname),
2117 (unsigned int)new_unx_mode));
2120 /* If this is a successful open, we must remove any deferred open
2123 del_deferred_open_entry(lck, req->mid);
2127 return NT_STATUS_OK;
2131 /****************************************************************************
2132 Open a file for for write to ensure that we can fchmod it.
2133 ****************************************************************************/
2135 NTSTATUS open_file_fchmod(connection_struct *conn,
2136 struct smb_filename *smb_fname,
2137 files_struct **result)
2139 if (!VALID_STAT(smb_fname->st)) {
2140 return NT_STATUS_INVALID_PARAMETER;
2143 return SMB_VFS_CREATE_FILE(
2146 0, /* root_dir_fid */
2147 smb_fname, /* fname */
2148 FILE_WRITE_DATA, /* access_mask */
2149 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
2151 FILE_OPEN, /* create_disposition*/
2152 0, /* create_options */
2153 0, /* file_attributes */
2154 INTERNAL_OPEN_ONLY, /* oplock_request */
2155 0, /* allocation_size */
2158 result, /* result */
2162 static NTSTATUS mkdir_internal(connection_struct *conn,
2163 struct smb_filename *smb_dname,
2164 uint32 file_attributes)
2169 bool posix_open = false;
2170 bool need_re_stat = false;
2172 if(!CAN_WRITE(conn)) {
2173 DEBUG(5,("mkdir_internal: failing create on read-only share "
2174 "%s\n", lp_servicename(SNUM(conn))));
2175 return NT_STATUS_ACCESS_DENIED;
2178 status = check_name(conn, smb_dname->base_name);
2179 if (!NT_STATUS_IS_OK(status)) {
2183 if (!parent_dirname(talloc_tos(), smb_dname->base_name, &parent_dir,
2185 return NT_STATUS_NO_MEMORY;
2188 if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
2190 mode = (mode_t)(file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
2192 mode = unix_mode(conn, aDIR, smb_dname, parent_dir);
2195 if (SMB_VFS_MKDIR(conn, smb_dname->base_name, mode) != 0) {
2196 return map_nt_error_from_unix(errno);
2199 /* Ensure we're checking for a symlink here.... */
2200 /* We don't want to get caught by a symlink racer. */
2202 if (SMB_VFS_LSTAT(conn, smb_dname) == -1) {
2203 DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
2204 smb_fname_str_dbg(smb_dname), strerror(errno)));
2205 return map_nt_error_from_unix(errno);
2208 if (!S_ISDIR(smb_dname->st.st_ex_mode)) {
2209 DEBUG(0, ("Directory just '%s' created is not a directory\n",
2210 smb_fname_str_dbg(smb_dname)));
2211 return NT_STATUS_ACCESS_DENIED;
2214 if (lp_store_dos_attributes(SNUM(conn))) {
2216 file_set_dosmode(conn, smb_dname,
2217 file_attributes | aDIR,
2222 if (lp_inherit_perms(SNUM(conn))) {
2223 inherit_access_posix_acl(conn, parent_dir,
2224 smb_dname->base_name, mode);
2225 need_re_stat = true;
2230 * Check if high bits should have been set,
2231 * then (if bits are missing): add them.
2232 * Consider bits automagically set by UNIX, i.e. SGID bit from parent
2235 if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) &&
2236 (mode & ~smb_dname->st.st_ex_mode)) {
2237 SMB_VFS_CHMOD(conn, smb_dname->base_name,
2238 (smb_dname->st.st_ex_mode |
2239 (mode & ~smb_dname->st.st_ex_mode)));
2240 need_re_stat = true;
2244 /* Change the owner if required. */
2245 if (lp_inherit_owner(SNUM(conn))) {
2246 change_dir_owner_to_parent(conn, parent_dir,
2247 smb_dname->base_name,
2249 need_re_stat = true;
2253 if (SMB_VFS_LSTAT(conn, smb_dname) == -1) {
2254 DEBUG(2, ("Could not stat directory '%s' just created: %s\n",
2255 smb_fname_str_dbg(smb_dname), strerror(errno)));
2256 return map_nt_error_from_unix(errno);
2260 notify_fname(conn, NOTIFY_ACTION_ADDED, FILE_NOTIFY_CHANGE_DIR_NAME,
2261 smb_dname->base_name);
2263 return NT_STATUS_OK;
2266 /****************************************************************************
2267 Open a directory from an NT SMB call.
2268 ****************************************************************************/
2270 static NTSTATUS open_directory(connection_struct *conn,
2271 struct smb_request *req,
2272 struct smb_filename *smb_dname,
2274 uint32 share_access,
2275 uint32 create_disposition,
2276 uint32 create_options,
2277 uint32 file_attributes,
2279 files_struct **result)
2281 files_struct *fsp = NULL;
2282 bool dir_existed = VALID_STAT(smb_dname->st) ? True : False;
2283 struct share_mode_lock *lck = NULL;
2285 struct timespec mtimespec;
2288 SMB_ASSERT(!is_ntfs_stream_smb_fname(smb_dname));
2290 if (!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
2291 /* Ensure we have a directory attribute. */
2292 file_attributes |= FILE_ATTRIBUTE_DIRECTORY;
2295 DEBUG(5,("open_directory: opening directory %s, access_mask = 0x%x, "
2296 "share_access = 0x%x create_options = 0x%x, "
2297 "create_disposition = 0x%x, file_attributes = 0x%x\n",
2298 smb_fname_str_dbg(smb_dname),
2299 (unsigned int)access_mask,
2300 (unsigned int)share_access,
2301 (unsigned int)create_options,
2302 (unsigned int)create_disposition,
2303 (unsigned int)file_attributes));
2305 if (!(file_attributes & FILE_FLAG_POSIX_SEMANTICS) &&
2306 (conn->fs_capabilities & FILE_NAMED_STREAMS) &&
2307 is_ntfs_stream_smb_fname(smb_dname)) {
2308 DEBUG(2, ("open_directory: %s is a stream name!\n",
2309 smb_fname_str_dbg(smb_dname)));
2310 return NT_STATUS_NOT_A_DIRECTORY;
2313 status = calculate_access_mask(conn, smb_dname, dir_existed,
2314 access_mask, &access_mask);
2315 if (!NT_STATUS_IS_OK(status)) {
2316 DEBUG(10, ("open_directory: calculate_access_mask "
2317 "on file %s returned %s\n",
2318 smb_fname_str_dbg(smb_dname),
2319 nt_errstr(status)));
2323 if ((access_mask & SEC_FLAG_SYSTEM_SECURITY) &&
2324 !user_has_privileges(current_user.nt_user_token, &se_security)) {
2325 DEBUG(10, ("open_directory: open on %s "
2326 "failed - SEC_FLAG_SYSTEM_SECURITY denied.\n",
2327 smb_fname_str_dbg(smb_dname)));
2328 return NT_STATUS_PRIVILEGE_NOT_HELD;
2331 switch( create_disposition ) {
2334 info = FILE_WAS_OPENED;
2337 * We want to follow symlinks here.
2340 if (SMB_VFS_STAT(conn, smb_dname) != 0) {
2341 return map_nt_error_from_unix(errno);
2348 /* If directory exists error. If directory doesn't
2351 status = mkdir_internal(conn, smb_dname,
2354 if (!NT_STATUS_IS_OK(status)) {
2355 DEBUG(2, ("open_directory: unable to create "
2356 "%s. Error was %s\n",
2357 smb_fname_str_dbg(smb_dname),
2358 nt_errstr(status)));
2362 info = FILE_WAS_CREATED;
2367 * If directory exists open. If directory doesn't
2371 status = mkdir_internal(conn, smb_dname,
2374 if (NT_STATUS_IS_OK(status)) {
2375 info = FILE_WAS_CREATED;
2378 if (NT_STATUS_EQUAL(status,
2379 NT_STATUS_OBJECT_NAME_COLLISION)) {
2380 info = FILE_WAS_OPENED;
2381 status = NT_STATUS_OK;
2386 case FILE_SUPERSEDE:
2387 case FILE_OVERWRITE:
2388 case FILE_OVERWRITE_IF:
2390 DEBUG(5,("open_directory: invalid create_disposition "
2391 "0x%x for directory %s\n",
2392 (unsigned int)create_disposition,
2393 smb_fname_str_dbg(smb_dname)));
2394 return NT_STATUS_INVALID_PARAMETER;
2397 if(!S_ISDIR(smb_dname->st.st_ex_mode)) {
2398 DEBUG(5,("open_directory: %s is not a directory !\n",
2399 smb_fname_str_dbg(smb_dname)));
2400 return NT_STATUS_NOT_A_DIRECTORY;
2403 if (info == FILE_WAS_OPENED) {
2404 uint32_t access_granted = 0;
2405 status = smbd_check_open_rights(conn, smb_dname, access_mask,
2408 /* Were we trying to do a directory open
2409 * for delete and didn't get DELETE
2410 * access (only) ? Check if the
2411 * directory allows DELETE_CHILD.
2413 * http://blogs.msdn.com/oldnewthing/archive/2004/06/04/148426.aspx
2416 if ((NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
2417 (access_mask & DELETE_ACCESS) &&
2418 (access_granted == DELETE_ACCESS) &&
2419 can_delete_file_in_directory(conn, smb_dname))) {
2420 DEBUG(10,("open_directory: overrode ACCESS_DENIED "
2421 "on directory %s\n",
2422 smb_fname_str_dbg(smb_dname)));
2423 status = NT_STATUS_OK;
2426 if (!NT_STATUS_IS_OK(status)) {
2427 DEBUG(10, ("open_directory: smbd_check_open_rights on "
2428 "file %s failed with %s\n",
2429 smb_fname_str_dbg(smb_dname),
2430 nt_errstr(status)));
2435 status = file_new(req, conn, &fsp);
2436 if(!NT_STATUS_IS_OK(status)) {
2441 * Setup the files_struct for it.
2444 fsp->mode = smb_dname->st.st_ex_mode;
2445 fsp->file_id = vfs_file_id_from_sbuf(conn, &smb_dname->st);
2446 fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
2447 fsp->file_pid = req ? req->smbpid : 0;
2448 fsp->can_lock = False;
2449 fsp->can_read = False;
2450 fsp->can_write = False;
2452 fsp->share_access = share_access;
2453 fsp->fh->private_options = create_options;
2455 * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
2457 fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
2458 fsp->print_file = False;
2459 fsp->modified = False;
2460 fsp->oplock_type = NO_OPLOCK;
2461 fsp->sent_oplock_break = NO_BREAK_SENT;
2462 fsp->is_directory = True;
2463 fsp->posix_open = (file_attributes & FILE_FLAG_POSIX_SEMANTICS) ? True : False;
2464 status = fsp_set_smb_fname(fsp, smb_dname);
2465 if (!NT_STATUS_IS_OK(status)) {
2469 mtimespec = smb_dname->st.st_ex_mtime;
2471 lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
2472 conn->connectpath, smb_dname, &mtimespec);
2475 DEBUG(0, ("open_directory: Could not get share mode lock for "
2476 "%s\n", smb_fname_str_dbg(smb_dname)));
2477 file_free(req, fsp);
2478 return NT_STATUS_SHARING_VIOLATION;
2481 status = open_mode_check(conn, lck, access_mask, share_access,
2482 create_options, &dir_existed);
2484 if (!NT_STATUS_IS_OK(status)) {
2486 file_free(req, fsp);
2490 set_share_mode(lck, fsp, conn->server_info->utok.uid, 0, NO_OPLOCK);
2492 /* For directories the delete on close bit at open time seems
2493 always to be honored on close... See test 19 in Samba4 BASE-DELETE. */
2494 if (create_options & FILE_DELETE_ON_CLOSE) {
2495 status = can_set_delete_on_close(fsp, 0);
2496 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_DIRECTORY_NOT_EMPTY)) {
2498 file_free(req, fsp);
2502 if (NT_STATUS_IS_OK(status)) {
2503 /* Note that here we set the *inital* delete on close flag,
2504 not the regular one. The magic gets handled in close. */
2505 fsp->initial_delete_on_close = True;
2516 return NT_STATUS_OK;
2519 NTSTATUS create_directory(connection_struct *conn, struct smb_request *req,
2520 struct smb_filename *smb_dname)
2525 status = SMB_VFS_CREATE_FILE(
2528 0, /* root_dir_fid */
2529 smb_dname, /* fname */
2530 FILE_READ_ATTRIBUTES, /* access_mask */
2531 FILE_SHARE_NONE, /* share_access */
2532 FILE_CREATE, /* create_disposition*/
2533 FILE_DIRECTORY_FILE, /* create_options */
2534 FILE_ATTRIBUTE_DIRECTORY, /* file_attributes */
2535 0, /* oplock_request */
2536 0, /* allocation_size */
2542 if (NT_STATUS_IS_OK(status)) {
2543 close_file(req, fsp, NORMAL_CLOSE);
2549 /****************************************************************************
2550 Receive notification that one of our open files has been renamed by another
2552 ****************************************************************************/
2554 void msg_file_was_renamed(struct messaging_context *msg,
2557 struct server_id server_id,
2561 char *frm = (char *)data->data;
2563 const char *sharepath;
2564 const char *base_name;
2565 const char *stream_name;
2566 struct smb_filename *smb_fname = NULL;
2567 size_t sp_len, bn_len;
2570 if (data->data == NULL
2571 || data->length < MSG_FILE_RENAMED_MIN_SIZE + 2) {
2572 DEBUG(0, ("msg_file_was_renamed: Got invalid msg len %d\n",
2573 (int)data->length));
2577 /* Unpack the message. */
2578 pull_file_id_24(frm, &id);
2579 sharepath = &frm[24];
2580 sp_len = strlen(sharepath);
2581 base_name = sharepath + sp_len + 1;
2582 bn_len = strlen(base_name);
2583 stream_name = sharepath + sp_len + 1 + bn_len + 1;
2585 /* stream_name must always be NULL if there is no stream. */
2586 if (stream_name[0] == '\0') {
2590 status = create_synthetic_smb_fname(talloc_tos(), base_name,
2591 stream_name, NULL, &smb_fname);
2592 if (!NT_STATUS_IS_OK(status)) {
2596 DEBUG(10,("msg_file_was_renamed: Got rename message for sharepath %s, new name %s, "
2598 sharepath, smb_fname_str_dbg(smb_fname),
2599 file_id_string_tos(&id)));
2601 for(fsp = file_find_di_first(id); fsp; fsp = file_find_di_next(fsp)) {
2602 if (memcmp(fsp->conn->connectpath, sharepath, sp_len) == 0) {
2604 DEBUG(10,("msg_file_was_renamed: renaming file fnum %d from %s -> %s\n",
2605 fsp->fnum, fsp_str_dbg(fsp),
2606 smb_fname_str_dbg(smb_fname)));
2607 status = fsp_set_smb_fname(fsp, smb_fname);
2608 if (!NT_STATUS_IS_OK(status)) {
2613 /* Now we have the complete path we can work out if this is
2614 actually within this share and adjust newname accordingly. */
2615 DEBUG(10,("msg_file_was_renamed: share mismatch (sharepath %s "
2616 "not sharepath %s) "
2617 "fnum %d from %s -> %s\n",
2618 fsp->conn->connectpath,
2622 smb_fname_str_dbg(smb_fname)));
2626 TALLOC_FREE(smb_fname);
2631 * If a main file is opened for delete, all streams need to be checked for
2632 * !FILE_SHARE_DELETE. Do this by opening with DELETE_ACCESS.
2633 * If that works, delete them all by setting the delete on close and close.
2636 NTSTATUS open_streams_for_delete(connection_struct *conn,
2639 struct stream_struct *stream_info;
2640 files_struct **streams;
2642 unsigned int num_streams;
2643 TALLOC_CTX *frame = talloc_stackframe();
2646 status = SMB_VFS_STREAMINFO(conn, NULL, fname, talloc_tos(),
2647 &num_streams, &stream_info);
2649 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)
2650 || NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2651 DEBUG(10, ("no streams around\n"));
2653 return NT_STATUS_OK;
2656 if (!NT_STATUS_IS_OK(status)) {
2657 DEBUG(10, ("SMB_VFS_STREAMINFO failed: %s\n",
2658 nt_errstr(status)));
2662 DEBUG(10, ("open_streams_for_delete found %d streams\n",
2665 if (num_streams == 0) {
2667 return NT_STATUS_OK;
2670 streams = TALLOC_ARRAY(talloc_tos(), files_struct *, num_streams);
2671 if (streams == NULL) {
2672 DEBUG(0, ("talloc failed\n"));
2673 status = NT_STATUS_NO_MEMORY;
2677 for (i=0; i<num_streams; i++) {
2678 struct smb_filename *smb_fname = NULL;
2680 if (strequal(stream_info[i].name, "::$DATA")) {
2685 status = create_synthetic_smb_fname(talloc_tos(), fname,
2686 stream_info[i].name,
2688 if (!NT_STATUS_IS_OK(status)) {
2692 if (SMB_VFS_STAT(conn, smb_fname) == -1) {
2693 DEBUG(10, ("Unable to stat stream: %s\n",
2694 smb_fname_str_dbg(smb_fname)));
2697 status = SMB_VFS_CREATE_FILE(
2700 0, /* root_dir_fid */
2701 smb_fname, /* fname */
2702 DELETE_ACCESS, /* access_mask */
2703 (FILE_SHARE_READ | /* share_access */
2704 FILE_SHARE_WRITE | FILE_SHARE_DELETE),
2705 FILE_OPEN, /* create_disposition*/
2706 NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE, /* create_options */
2707 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
2708 0, /* oplock_request */
2709 0, /* allocation_size */
2712 &streams[i], /* result */
2715 if (!NT_STATUS_IS_OK(status)) {
2716 DEBUG(10, ("Could not open stream %s: %s\n",
2717 smb_fname_str_dbg(smb_fname),
2718 nt_errstr(status)));
2720 TALLOC_FREE(smb_fname);
2723 TALLOC_FREE(smb_fname);
2727 * don't touch the variable "status" beyond this point :-)
2730 for (i -= 1 ; i >= 0; i--) {
2731 if (streams[i] == NULL) {
2735 DEBUG(10, ("Closing stream # %d, %s\n", i,
2736 fsp_str_dbg(streams[i])));
2737 close_file(NULL, streams[i], NORMAL_CLOSE);
2746 * Wrapper around open_file_ntcreate and open_directory
2749 static NTSTATUS create_file_unixpath(connection_struct *conn,
2750 struct smb_request *req,
2751 struct smb_filename *smb_fname,
2752 uint32_t access_mask,
2753 uint32_t share_access,
2754 uint32_t create_disposition,
2755 uint32_t create_options,
2756 uint32_t file_attributes,
2757 uint32_t oplock_request,
2758 uint64_t allocation_size,
2759 struct security_descriptor *sd,
2760 struct ea_list *ea_list,
2762 files_struct **result,
2765 int info = FILE_WAS_OPENED;
2766 files_struct *base_fsp = NULL;
2767 files_struct *fsp = NULL;
2770 DEBUG(10,("create_file_unixpath: access_mask = 0x%x "
2771 "file_attributes = 0x%x, share_access = 0x%x, "
2772 "create_disposition = 0x%x create_options = 0x%x "
2773 "oplock_request = 0x%x ea_list = 0x%p, sd = 0x%p, "
2775 (unsigned int)access_mask,
2776 (unsigned int)file_attributes,
2777 (unsigned int)share_access,
2778 (unsigned int)create_disposition,
2779 (unsigned int)create_options,
2780 (unsigned int)oplock_request,
2781 ea_list, sd, smb_fname_str_dbg(smb_fname)));
2783 if (create_options & FILE_OPEN_BY_FILE_ID) {
2784 status = NT_STATUS_NOT_SUPPORTED;
2788 if (create_options & NTCREATEX_OPTIONS_INVALID_PARAM_MASK) {
2789 status = NT_STATUS_INVALID_PARAMETER;
2794 oplock_request |= INTERNAL_OPEN_ONLY;
2797 if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
2798 && (access_mask & DELETE_ACCESS)
2799 && !is_ntfs_stream_smb_fname(smb_fname)) {
2801 * We can't open a file with DELETE access if any of the
2802 * streams is open without FILE_SHARE_DELETE
2804 status = open_streams_for_delete(conn, smb_fname->base_name);
2806 if (!NT_STATUS_IS_OK(status)) {
2811 /* This is the correct thing to do (check every time) but can_delete
2812 * is expensive (it may have to read the parent directory
2813 * permissions). So for now we're not doing it unless we have a strong
2814 * hint the client is really going to delete this file. If the client
2815 * is forcing FILE_CREATE let the filesystem take care of the
2818 /* Setting FILE_SHARE_DELETE is the hint. */
2820 if ((create_disposition != FILE_CREATE)
2821 && (access_mask & DELETE_ACCESS)
2822 && (!(can_delete_file_in_directory(conn, smb_fname) ||
2823 can_access_file_acl(conn, smb_fname, DELETE_ACCESS)))) {
2824 status = NT_STATUS_ACCESS_DENIED;
2825 DEBUG(10,("create_file_unixpath: open file %s "
2826 "for delete ACCESS_DENIED\n",
2827 smb_fname_str_dbg(smb_fname)));
2831 if ((access_mask & SEC_FLAG_SYSTEM_SECURITY) &&
2832 !user_has_privileges(current_user.nt_user_token, &se_security)) {
2833 DEBUG(10, ("create_file_unixpath:: open on %s "
2834 "failed - SEC_FLAG_SYSTEM_SECURITY denied.\n",
2835 smb_fname_str_dbg(smb_fname)));
2836 status = NT_STATUS_PRIVILEGE_NOT_HELD;
2840 if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
2841 && is_ntfs_stream_smb_fname(smb_fname)
2842 && (!(create_options & NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE))) {
2843 uint32 base_create_disposition;
2844 struct smb_filename *smb_fname_base = NULL;
2846 if (create_options & FILE_DIRECTORY_FILE) {
2847 status = NT_STATUS_NOT_A_DIRECTORY;
2851 switch (create_disposition) {
2853 base_create_disposition = FILE_OPEN;
2856 base_create_disposition = FILE_OPEN_IF;
2860 /* Create an smb_filename with stream_name == NULL. */
2861 status = create_synthetic_smb_fname(talloc_tos(),
2862 smb_fname->base_name,
2865 if (!NT_STATUS_IS_OK(status)) {
2869 if (SMB_VFS_STAT(conn, smb_fname_base) == -1) {
2870 DEBUG(10, ("Unable to stat stream: %s\n",
2871 smb_fname_str_dbg(smb_fname_base)));
2874 /* Open the base file. */
2875 status = create_file_unixpath(conn, NULL, smb_fname_base, 0,
2878 | FILE_SHARE_DELETE,
2879 base_create_disposition,
2880 0, 0, 0, 0, NULL, NULL,
2882 TALLOC_FREE(smb_fname_base);
2884 if (!NT_STATUS_IS_OK(status)) {
2885 DEBUG(10, ("create_file_unixpath for base %s failed: "
2886 "%s\n", smb_fname->base_name,
2887 nt_errstr(status)));
2890 /* we don't need to low level fd */
2895 * If it's a request for a directory open, deal with it separately.
2898 if (create_options & FILE_DIRECTORY_FILE) {
2900 if (create_options & FILE_NON_DIRECTORY_FILE) {
2901 status = NT_STATUS_INVALID_PARAMETER;
2905 /* Can't open a temp directory. IFS kit test. */
2906 if (!(file_attributes & FILE_FLAG_POSIX_SEMANTICS) &&
2907 (file_attributes & FILE_ATTRIBUTE_TEMPORARY)) {
2908 status = NT_STATUS_INVALID_PARAMETER;
2913 * We will get a create directory here if the Win32
2914 * app specified a security descriptor in the
2915 * CreateDirectory() call.
2919 status = open_directory(
2920 conn, req, smb_fname, access_mask, share_access,
2921 create_disposition, create_options, file_attributes,
2926 * Ordinary file case.
2929 status = file_new(req, conn, &fsp);
2930 if(!NT_STATUS_IS_OK(status)) {
2934 status = fsp_set_smb_fname(fsp, smb_fname);
2935 if (!NT_STATUS_IS_OK(status)) {
2940 * We're opening the stream element of a base_fsp
2941 * we already opened. Set up the base_fsp pointer.
2944 fsp->base_fsp = base_fsp;
2947 status = open_file_ntcreate(conn,
2958 if(!NT_STATUS_IS_OK(status)) {
2959 file_free(req, fsp);
2963 if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
2965 /* A stream open never opens a directory */
2968 status = NT_STATUS_FILE_IS_A_DIRECTORY;
2973 * Fail the open if it was explicitly a non-directory
2977 if (create_options & FILE_NON_DIRECTORY_FILE) {
2978 status = NT_STATUS_FILE_IS_A_DIRECTORY;
2983 status = open_directory(
2984 conn, req, smb_fname, access_mask,
2985 share_access, create_disposition,
2986 create_options, file_attributes,
2991 if (!NT_STATUS_IS_OK(status)) {
2995 fsp->base_fsp = base_fsp;
2998 * According to the MS documentation, the only time the security
2999 * descriptor is applied to the opened file is iff we *created* the
3000 * file; an existing file stays the same.
3002 * Also, it seems (from observation) that you can open the file with
3003 * any access mask but you can still write the sd. We need to override
3004 * the granted access before we call set_sd
3005 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
3008 if ((sd != NULL) && (info == FILE_WAS_CREATED)
3009 && lp_nt_acl_support(SNUM(conn))) {
3011 uint32_t sec_info_sent;
3012 uint32_t saved_access_mask = fsp->access_mask;
3014 sec_info_sent = get_sec_info(sd);
3016 fsp->access_mask = FILE_GENERIC_ALL;
3018 /* Convert all the generic bits. */
3019 security_acl_map_generic(sd->dacl, &file_generic_mapping);
3020 security_acl_map_generic(sd->sacl, &file_generic_mapping);
3022 if (sec_info_sent & (OWNER_SECURITY_INFORMATION|
3023 GROUP_SECURITY_INFORMATION|
3024 DACL_SECURITY_INFORMATION|
3025 SACL_SECURITY_INFORMATION)) {
3026 status = SMB_VFS_FSET_NT_ACL(fsp, sec_info_sent, sd);
3029 fsp->access_mask = saved_access_mask;
3031 if (!NT_STATUS_IS_OK(status)) {
3036 if ((ea_list != NULL) &&
3037 ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN))) {
3038 status = set_ea(conn, fsp, fsp->fsp_name, ea_list);
3039 if (!NT_STATUS_IS_OK(status)) {
3044 if (!fsp->is_directory && S_ISDIR(fsp->fsp_name->st.st_ex_mode)) {
3045 status = NT_STATUS_ACCESS_DENIED;
3049 /* Save the requested allocation size. */
3050 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
3052 && (allocation_size > fsp->fsp_name->st.st_ex_size)) {
3053 fsp->initial_allocation_size = smb_roundup(
3054 fsp->conn, allocation_size);
3055 if (fsp->is_directory) {
3056 /* Can't set allocation size on a directory. */
3057 status = NT_STATUS_ACCESS_DENIED;
3060 if (vfs_allocate_file_space(
3061 fsp, fsp->initial_allocation_size) == -1) {
3062 status = NT_STATUS_DISK_FULL;
3066 fsp->initial_allocation_size = smb_roundup(
3067 fsp->conn, (uint64_t)fsp->fsp_name->st.st_ex_size);
3071 DEBUG(10, ("create_file_unixpath: info=%d\n", info));
3074 if (pinfo != NULL) {
3078 smb_fname->st = fsp->fsp_name->st;
3080 return NT_STATUS_OK;
3083 DEBUG(10, ("create_file_unixpath: %s\n", nt_errstr(status)));
3086 if (base_fsp && fsp->base_fsp == base_fsp) {
3088 * The close_file below will close
3093 close_file(req, fsp, ERROR_CLOSE);
3096 if (base_fsp != NULL) {
3097 close_file(req, base_fsp, ERROR_CLOSE);
3104 * Calculate the full path name given a relative fid.
3106 NTSTATUS get_relative_fid_filename(connection_struct *conn,
3107 struct smb_request *req,
3108 uint16_t root_dir_fid,
3109 const struct smb_filename *smb_fname,
3110 struct smb_filename **smb_fname_out)
3112 files_struct *dir_fsp;
3113 char *parent_fname = NULL;
3114 char *new_base_name = NULL;
3117 if (root_dir_fid == 0 || !smb_fname) {
3118 status = NT_STATUS_INTERNAL_ERROR;
3122 dir_fsp = file_fsp(req, root_dir_fid);
3124 if (dir_fsp == NULL) {
3125 status = NT_STATUS_INVALID_HANDLE;
3129 if (is_ntfs_stream_smb_fname(dir_fsp->fsp_name)) {
3130 status = NT_STATUS_INVALID_HANDLE;
3134 if (!dir_fsp->is_directory) {
3137 * Check to see if this is a mac fork of some kind.
3140 if ((conn->fs_capabilities & FILE_NAMED_STREAMS) &&
3141 is_ntfs_stream_smb_fname(smb_fname)) {
3142 status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
3147 we need to handle the case when we get a
3148 relative open relative to a file and the
3149 pathname is blank - this is a reopen!
3150 (hint from demyn plantenberg)
3153 status = NT_STATUS_INVALID_HANDLE;
3157 if (ISDOT(dir_fsp->fsp_name->base_name)) {
3159 * We're at the toplevel dir, the final file name
3160 * must not contain ./, as this is filtered out
3161 * normally by srvstr_get_path and unix_convert
3162 * explicitly rejects paths containing ./.
3164 parent_fname = talloc_strdup(talloc_tos(), "");
3165 if (parent_fname == NULL) {
3166 status = NT_STATUS_NO_MEMORY;
3170 size_t dir_name_len = strlen(dir_fsp->fsp_name->base_name);
3173 * Copy in the base directory name.
3176 parent_fname = TALLOC_ARRAY(talloc_tos(), char,
3178 if (parent_fname == NULL) {
3179 status = NT_STATUS_NO_MEMORY;
3182 memcpy(parent_fname, dir_fsp->fsp_name->base_name,
3186 * Ensure it ends in a '/'.
3187 * We used TALLOC_SIZE +2 to add space for the '/'.
3191 && (parent_fname[dir_name_len-1] != '\\')
3192 && (parent_fname[dir_name_len-1] != '/')) {
3193 parent_fname[dir_name_len] = '/';
3194 parent_fname[dir_name_len+1] = '\0';
3198 new_base_name = talloc_asprintf(talloc_tos(), "%s%s", parent_fname,
3199 smb_fname->base_name);
3200 if (new_base_name == NULL) {
3201 status = NT_STATUS_NO_MEMORY;
3205 status = filename_convert(req,
3207 req->flags2 & FLAGS2_DFS_PATHNAMES,
3212 if (!NT_STATUS_IS_OK(status)) {
3217 TALLOC_FREE(parent_fname);
3221 NTSTATUS create_file_default(connection_struct *conn,
3222 struct smb_request *req,
3223 uint16_t root_dir_fid,
3224 struct smb_filename *smb_fname,
3225 uint32_t access_mask,
3226 uint32_t share_access,
3227 uint32_t create_disposition,
3228 uint32_t create_options,
3229 uint32_t file_attributes,
3230 uint32_t oplock_request,
3231 uint64_t allocation_size,
3232 struct security_descriptor *sd,
3233 struct ea_list *ea_list,
3234 files_struct **result,
3237 int info = FILE_WAS_OPENED;
3238 files_struct *fsp = NULL;
3241 DEBUG(10,("create_file: access_mask = 0x%x "
3242 "file_attributes = 0x%x, share_access = 0x%x, "
3243 "create_disposition = 0x%x create_options = 0x%x "
3244 "oplock_request = 0x%x "
3245 "root_dir_fid = 0x%x, ea_list = 0x%p, sd = 0x%p, "
3247 (unsigned int)access_mask,
3248 (unsigned int)file_attributes,
3249 (unsigned int)share_access,
3250 (unsigned int)create_disposition,
3251 (unsigned int)create_options,
3252 (unsigned int)oplock_request,
3253 (unsigned int)root_dir_fid,
3254 ea_list, sd, smb_fname_str_dbg(smb_fname)));
3257 * Calculate the filename from the root_dir_if if necessary.
3260 if (root_dir_fid != 0) {
3261 struct smb_filename *smb_fname_out = NULL;
3262 status = get_relative_fid_filename(conn, req, root_dir_fid,
3263 smb_fname, &smb_fname_out);
3264 if (!NT_STATUS_IS_OK(status)) {
3267 smb_fname = smb_fname_out;
3271 * Check to see if this is a mac fork of some kind.
3274 if (is_ntfs_stream_smb_fname(smb_fname)) {
3275 enum FAKE_FILE_TYPE fake_file_type;
3277 fake_file_type = is_fake_file(smb_fname);
3279 if (fake_file_type != FAKE_FILE_TYPE_NONE) {
3282 * Here we go! support for changing the disk quotas
3285 * We need to fake up to open this MAGIC QUOTA file
3286 * and return a valid FID.
3288 * w2k close this file directly after openening xp
3289 * also tries a QUERY_FILE_INFO on the file and then
3292 status = open_fake_file(req, conn, req->vuid,
3293 fake_file_type, smb_fname,
3295 if (!NT_STATUS_IS_OK(status)) {
3299 ZERO_STRUCT(smb_fname->st);
3303 if (!(conn->fs_capabilities & FILE_NAMED_STREAMS)) {
3304 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
3309 status = create_file_unixpath(
3310 conn, req, smb_fname, access_mask, share_access,
3311 create_disposition, create_options, file_attributes,
3312 oplock_request, allocation_size, sd, ea_list,
3315 if (!NT_STATUS_IS_OK(status)) {
3320 DEBUG(10, ("create_file: info=%d\n", info));
3323 if (pinfo != NULL) {
3326 return NT_STATUS_OK;
3329 DEBUG(10, ("create_file: %s\n", nt_errstr(status)));
3332 close_file(req, fsp, ERROR_CLOSE);