s3: Add some const to find_oplock_types
[kai/samba.git] / source3 / smbd / open.c
index ee0ba082f88aa539786cc1d0dbcc4fd34ff944e0..8b7b47b7ebc46d9fa251bbdd1babdb50f41c031b 100644 (file)
@@ -99,6 +99,14 @@ NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
                return NT_STATUS_OK;
        }
 
+       if (access_mask == DELETE_ACCESS && S_ISLNK(smb_fname->st.st_ex_mode)) {
+               /* We can always delete a symlink. */
+               DEBUG(10,("smbd_check_access_rights: not checking ACL "
+                       "on DELETE_ACCESS on symlink %s.\n",
+                       smb_fname_str_dbg(smb_fname) ));
+               return NT_STATUS_OK;
+       }
+
        status = SMB_VFS_GET_NT_ACL(conn, smb_fname->base_name,
                        (SECINFO_OWNER |
                        SECINFO_GROUP |
@@ -911,8 +919,7 @@ static void validate_my_share_entries(struct smbd_server_connection *sconn,
                          "share entry with an open file\n");
        }
 
-       if (is_deferred_open_entry(share_entry) ||
-           is_unused_share_mode_entry(share_entry)) {
+       if (is_deferred_open_entry(share_entry)) {
                goto panic;
        }
 
@@ -1077,7 +1084,7 @@ static NTSTATUS send_break_message(files_struct *fsp,
 
 static void find_oplock_types(files_struct *fsp,
                                int oplock_request,
-                               struct share_mode_lock *lck,
+                               const struct share_mode_lock *lck,
                                struct share_mode_entry **pp_batch,
                                struct share_mode_entry **pp_ex_or_batch,
                                bool *got_level2,
@@ -1151,13 +1158,13 @@ static bool delay_for_batch_oplocks(files_struct *fsp,
        if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
                return false;
        }
-
-       if (batch_entry != NULL) {
-               /* Found a batch oplock */
-               send_break_message(fsp, batch_entry, mid, oplock_request);
-               return true;
+       if (batch_entry == NULL) {
+               return false;
        }
-       return false;
+
+       /* Found a batch oplock */
+       send_break_message(fsp, batch_entry, mid, oplock_request);
+       return true;
 }
 
 static bool delay_for_exclusive_oplocks(files_struct *fsp,
@@ -1165,20 +1172,26 @@ static bool delay_for_exclusive_oplocks(files_struct *fsp,
                                        int oplock_request,
                                        struct share_mode_entry *ex_entry)
 {
+       bool delay_it;
+
        if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
                return false;
        }
+       if (ex_entry == NULL) {
+               return false;
+       }
 
-       if (ex_entry != NULL) {
-               /* Found an exclusive or batch oplock */
-               bool delay_it = is_delete_request(fsp) ?
-                               BATCH_OPLOCK_TYPE(ex_entry->op_type) : true;
-               if (delay_it) {
-                       send_break_message(fsp, ex_entry, mid, oplock_request);
-                       return true;
-               }
+       /* Found an exclusive or batch oplock */
+
+       delay_it = is_delete_request(fsp) ?
+               BATCH_OPLOCK_TYPE(ex_entry->op_type) : true;
+
+       if (!delay_it) {
+               return false;
        }
-       return false;
+
+       send_break_message(fsp, ex_entry, mid, oplock_request);
+       return true;
 }
 
 static void grant_fsp_oplock_type(files_struct *fsp,
@@ -1276,11 +1289,9 @@ static void defer_open(struct share_mode_lock *lck,
        for (i=0; i<lck->num_share_modes; i++) {
                struct share_mode_entry *e = &lck->share_modes[i];
 
-               if (!is_deferred_open_entry(e)) {
-                       continue;
-               }
-
-               if (procid_is_me(&e->pid) && (e->op_mid == req->mid)) {
+               if (is_deferred_open_entry(e) &&
+                   procid_is_me(&e->pid) &&
+                   (e->op_mid == req->mid)) {
                        DEBUG(0, ("Trying to defer an already deferred "
                                "request: mid=%llu, exiting\n",
                                (unsigned long long)req->mid));
@@ -1628,7 +1639,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
        bool posix_open = False;
        bool new_file_created = False;
        bool clear_ads = false;
-       struct file_id id;
        NTSTATUS fsp_open = NT_STATUS_ACCESS_DENIED;
        mode_t new_unx_mode = (mode_t)0;
        mode_t unx_mode = (mode_t)0;
@@ -1640,8 +1650,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
        NTSTATUS status;
        char *parent_dir;
 
-       ZERO_STRUCT(id);
-
        if (conn->printer) {
                /*
                 * Printers are handled completely differently.
@@ -1726,11 +1734,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                }
        }
 
-       status = check_name(conn, smb_fname->base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
        if (!posix_open) {
                new_dos_attributes &= SAMBA_ATTRIBUTES_MASK;
                if (file_existed) {
@@ -1952,6 +1955,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                struct share_mode_entry *exclusive_entry = NULL;
                bool got_level2_oplock = false;
                bool got_a_none_oplock = false;
+               struct file_id id;
 
                struct timespec old_write_time = smb_fname->st.st_ex_mtime;
                id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
@@ -2185,6 +2189,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                bool got_level2_oplock = false;
                bool got_a_none_oplock = false;
                struct timespec old_write_time = smb_fname->st.st_ex_mtime;
+               struct file_id id;
                /*
                 * Deal with the race condition where two smbd's detect the
                 * file doesn't exist and do the create at the same time. One
@@ -2370,10 +2375,10 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                        fsp->oplock_type = NO_OPLOCK;
                }
 
-               if (!(flags2 & O_TRUNC)) {
-                       info = FILE_WAS_OPENED;
-               } else {
+               if (flags2 & O_TRUNC) {
                        info = FILE_WAS_OVERWRITTEN;
+               } else {
+                       info = FILE_WAS_OPENED;
                }
        } else {
                info = FILE_WAS_CREATED;
@@ -2396,10 +2401,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                fsp->oplock_type = NO_OPLOCK;
        }
 
-       if (info == FILE_WAS_OVERWRITTEN || info == FILE_WAS_CREATED || info == FILE_WAS_SUPERSEDED) {
-               new_file_created = True;
-       }
-
        set_share_mode(lck, fsp, get_current_uid(conn),
                        req ? req->mid : 0,
                       fsp->oplock_type);
@@ -2421,6 +2422,12 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                fsp->initial_delete_on_close = True;
        }
 
+       if (info == FILE_WAS_OVERWRITTEN
+           || info == FILE_WAS_CREATED
+           || info == FILE_WAS_SUPERSEDED) {
+               new_file_created = True;
+       }
+
        if (new_file_created) {
                /* Files should be initially set as archive */
                if (lp_map_archive(SNUM(conn)) ||
@@ -3002,13 +3009,9 @@ void msg_file_was_renamed(struct messaging_context *msg,
        size_t sp_len, bn_len;
        NTSTATUS status;
        struct smbd_server_connection *sconn =
-               talloc_get_type(private_data,
+               talloc_get_type_abort(private_data,
                struct smbd_server_connection);
 
-       if (sconn == NULL) {
-               return;
-       }
-
        if (data->data == NULL
            || data->length < MSG_FILE_RENAMED_MIN_SIZE + 2) {
                 DEBUG(0, ("msg_file_was_renamed: Got invalid msg len %d\n",
@@ -3853,13 +3856,6 @@ NTSTATUS create_file_default(connection_struct *conn,
                }
        }
 
-       /* All file access must go through check_name() */
-
-       status = check_name(conn, smb_fname->base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
-       }
-
        if (stream_name && is_ntfs_default_stream_smb_fname(smb_fname)) {
                int ret;
                smb_fname->stream_name = NULL;