Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/close.c

    r414 r740  
    2121
    2222#include "includes.h"
    23 
    24 extern struct current_user current_user;
     23#include "system/filesys.h"
     24#include "printing.h"
     25#include "smbd/smbd.h"
     26#include "smbd/globals.h"
     27#include "fake_file.h"
     28#include "transfer_file.h"
     29#include "auth.h"
     30#include "messages.h"
    2531
    2632/****************************************************************************
     
    154160****************************************************************************/
    155161
    156 static void notify_deferred_opens(struct share_mode_lock *lck)
     162static void notify_deferred_opens(struct messaging_context *msg_ctx,
     163                                  struct share_mode_lock *lck)
    157164{
    158165        int i;
     
    176183                         * zero.
    177184                         */
    178                         schedule_deferred_open_smb_message(e->op_mid);
     185                        schedule_deferred_open_message_smb(e->op_mid);
    179186                } else {
    180187                        char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
     
    182189                        share_mode_entry_to_message(msg, e);
    183190
    184                         messaging_send_buf(smbd_messaging_context(),
    185                                            e->pid, MSG_SMB_OPEN_RETRY,
     191                        messaging_send_buf(msg_ctx, e->pid, MSG_SMB_OPEN_RETRY,
    186192                                           (uint8 *)msg,
    187193                                           MSG_SMB_SHARE_MODE_ENTRY_SIZE);
     
    274280        NTSTATUS tmp_status;
    275281        struct file_id id;
     282        const struct security_unix_token *del_token = NULL;
    276283
    277284        /* Ensure any pending write time updates are done. */
     
    327334        }
    328335
    329         if (fsp->initial_delete_on_close && (lck->delete_token == NULL)) {
     336        if (fsp->initial_delete_on_close &&
     337                        !is_delete_on_close_set(lck, fsp->name_hash)) {
    330338                bool became_user = False;
    331339
     
    333341                 * wrote a real delete on close. */
    334342
    335                 if (current_user.vuid != fsp->vuid) {
     343                if (get_current_vuid(conn) != fsp->vuid) {
    336344                        become_user(conn, fsp->vuid);
    337345                        became_user = True;
    338346                }
    339347                fsp->delete_on_close = true;
    340                 set_delete_on_close_lck(lck, True, &current_user.ut);
     348                set_delete_on_close_lck(fsp, lck, True, get_current_utok(conn));
    341349                if (became_user) {
    342350                        unbecome_user();
     
    344352        }
    345353
    346         delete_file = lck->delete_on_close;
     354        delete_file = is_delete_on_close_set(lck, fsp->name_hash);
    347355
    348356        if (delete_file) {
    349357                int i;
    350                 /* See if others still have the file open. If this is the
    351                  * case, then don't delete. If all opens are POSIX delete now. */
     358                /* See if others still have the file open via this pathname.
     359                   If this is the case, then don't delete. If all opens are
     360                   POSIX delete now. */
    352361                for (i=0; i<lck->num_share_modes; i++) {
    353362                        struct share_mode_entry *e = &lck->share_modes[i];
    354                         if (is_valid_share_mode_entry(e)) {
     363                        if (is_valid_share_mode_entry(e) &&
     364                                        e->name_hash == fsp->name_hash) {
    355365                                if (fsp->posix_open && (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
    356366                                        continue;
     
    363373
    364374        /* Notify any deferred opens waiting on this close. */
    365         notify_deferred_opens(lck);
     375        notify_deferred_opens(conn->sconn->msg_ctx, lck);
    366376        reply_to_oplock_break_requests(fsp);
    367377
     
    371381         */
    372382
    373         if (!(close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE)
    374             || !delete_file
    375             || (lck->delete_token == NULL)) {
     383        if (!(close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) ||
     384                        !delete_file) {
    376385                TALLOC_FREE(lck);
    377386                return NT_STATUS_OK;
     
    390399        fsp->update_write_time_on_close = false;
    391400
    392         if (!unix_token_equal(lck->delete_token, &current_user.ut)) {
     401        del_token = get_delete_on_close_token(lck, fsp->name_hash);
     402        SMB_ASSERT(del_token != NULL);
     403
     404        if (!unix_token_equal(del_token, get_current_utok(conn))) {
    393405                /* Become the user who requested the delete. */
    394406
     
    396408                        "Change user to uid %u\n",
    397409                        fsp_str_dbg(fsp),
    398                         (unsigned int)lck->delete_token->uid));
     410                        (unsigned int)del_token->uid));
    399411
    400412                if (!push_sec_ctx()) {
     
    403415                }
    404416
    405                 set_sec_ctx(lck->delete_token->uid,
    406                             lck->delete_token->gid,
    407                             lck->delete_token->ngroups,
    408                             lck->delete_token->groups,
     417                set_sec_ctx(del_token->uid,
     418                            del_token->gid,
     419                            del_token->ngroups,
     420                            del_token->groups,
    409421                            NULL);
    410422
     
    472484        }
    473485
    474         notify_fname(conn, NOTIFY_ACTION_REMOVED,
    475                      FILE_NOTIFY_CHANGE_FILE_NAME,
    476                      fsp->fsp_name->base_name);
    477 
    478486        /* As we now have POSIX opens which can unlink
    479487         * with other open files we may have taken
     
    484492
    485493        fsp->delete_on_close = false;
    486         set_delete_on_close_lck(lck, False, NULL);
     494        set_delete_on_close_lck(fsp, lck, false, NULL);
    487495
    488496 done:
     
    494502
    495503        TALLOC_FREE(lck);
     504
     505        if (delete_file) {
     506                /*
     507                 * Do the notification after we released the share
     508                 * mode lock. Inside notify_fname we take out another
     509                 * tdb lock. With ctdb also accessing our databases,
     510                 * this can lead to deadlocks. Putting this notify
     511                 * after the TALLOC_FREE(lck) above we avoid locking
     512                 * two records simultaneously. Notifies are async and
     513                 * informational only, so calling the notify_fname
     514                 * without holding the share mode lock should not do
     515                 * any harm.
     516                 */
     517                notify_fname(conn, NOTIFY_ACTION_REMOVED,
     518                             FILE_NOTIFY_CHANGE_FILE_NAME,
     519                             fsp->fsp_name->base_name);
     520        }
     521
    496522        return status;
    497523}
     
    551577
    552578        ft.mtime = fsp->close_write_time;
    553         status = smb_set_file_time(fsp->conn, fsp, fsp->fsp_name, &ft, false);
     579        /* We must use NULL for the fsp handle here, as smb_set_file_time()
     580           checks the fsp access_mask, which may not include FILE_WRITE_ATTRIBUTES.
     581           As this is a close based update, we are not directly changing the
     582           file attributes from a client call, but indirectly from a write. */
     583        status = smb_set_file_time(fsp->conn, NULL, fsp->fsp_name, &ft, false);
    554584        if (!NT_STATUS_IS_OK(status)) {
     585                DEBUG(10,("update_write_time_on_close: smb_set_file_time "
     586                        "on file %s returned %s\n",
     587                        fsp_str_dbg(fsp),
     588                        nt_errstr(status)));
    555589                return status;
    556590        }
     
    582616        connection_struct *conn = fsp->conn;
    583617
    584         if (fsp->aio_write_behind) {
     618        if (close_type == ERROR_CLOSE) {
     619                cancel_aio_by_fsp(fsp);
     620        } else {
    585621                /*
    586                  * If we're finishing write behind on a close we can get a write
     622                 * If we're finishing async io on a close we can get a write
    587623                 * error here, we must remember this.
    588624                 */
     
    592628                                status, map_nt_error_from_unix(ret));
    593629                }
    594         } else {
    595                 cancel_aio_by_fsp(fsp);
    596         }
    597  
     630        }
     631
    598632        /*
    599633         * If we're flushing on a close we can get a write
     
    605639
    606640        if (fsp->print_file) {
    607                 print_fsp_end(fsp, close_type);
     641                /* FIXME: return spool errors */
     642                print_spool_end(fsp, close_type);
    608643                file_free(req, fsp);
    609644                return NT_STATUS_OK;
     
    625660        }
    626661
    627         locking_close_file(smbd_messaging_context(), fsp);
     662        locking_close_file(conn->sconn->msg_ctx, fsp, close_type);
    628663
    629664        tmp = fd_close(fsp);
     
    652687
    653688        DEBUG(2,("%s closed file %s (numopen=%d) %s\n",
    654                 conn->server_info->unix_name, fsp_str_dbg(fsp),
     689                conn->session_info->unix_name, fsp_str_dbg(fsp),
    655690                conn->num_files_open - 1,
    656691                nt_errstr(status) ));
     
    928963        NTSTATUS status = NT_STATUS_OK;
    929964        NTSTATUS status1 = NT_STATUS_OK;
     965        const struct security_unix_token *del_token = NULL;
    930966
    931967        /*
     
    956992                 * wrote a real delete on close. */
    957993
    958                 if (current_user.vuid != fsp->vuid) {
     994                if (get_current_vuid(fsp->conn) != fsp->vuid) {
    959995                        become_user(fsp->conn, fsp->vuid);
    960996                        became_user = True;
    961997                }
    962                 send_stat_cache_delete_message(fsp->fsp_name->base_name);
    963                 set_delete_on_close_lck(lck, True, &current_user.ut);
     998                send_stat_cache_delete_message(fsp->conn->sconn->msg_ctx,
     999                                               fsp->fsp_name->base_name);
     1000                set_delete_on_close_lck(fsp, lck, true,
     1001                                get_current_utok(fsp->conn));
    9641002                fsp->delete_on_close = true;
    9651003                if (became_user) {
     
    9681006        }
    9691007
    970         delete_dir = lck->delete_on_close;
     1008        del_token = get_delete_on_close_token(lck, fsp->name_hash);
     1009        delete_dir = (del_token != NULL);
    9711010
    9721011        if (delete_dir) {
     
    9761015                for (i=0; i<lck->num_share_modes; i++) {
    9771016                        struct share_mode_entry *e = &lck->share_modes[i];
    978                         if (is_valid_share_mode_entry(e)) {
     1017                        if (is_valid_share_mode_entry(e) &&
     1018                                        e->name_hash == fsp->name_hash) {
    9791019                                if (fsp->posix_open && (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
    9801020                                        continue;
     
    9871027
    9881028        if ((close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) &&
    989                                 delete_dir &&
    990                                 lck->delete_token) {
     1029                                delete_dir) {
    9911030       
    9921031                /* Become the user who requested the delete. */
     
    9961035                }
    9971036
    998                 set_sec_ctx(lck->delete_token->uid,
    999                                 lck->delete_token->gid,
    1000                                 lck->delete_token->ngroups,
    1001                                 lck->delete_token->groups,
     1037                set_sec_ctx(del_token->uid,
     1038                                del_token->gid,
     1039                                del_token->ngroups,
     1040                                del_token->groups,
    10021041                                NULL);
    10031042
     
    10331072                          fsp_str_dbg(fsp), fsp->fh->fd, errno,
    10341073                          strerror(errno)));
    1035         }
    1036 
    1037         if (fsp->dptr) {
    1038                 dptr_CloseDir(fsp->dptr);
    10391074        }
    10401075
     
    11001135                        DATA_BLOB *data)
    11011136{
     1137        struct smbd_server_connection *sconn;
    11021138        files_struct *fsp = NULL;
    11031139        struct share_mode_entry e;
     1140
     1141        sconn = msg_ctx_to_sconn(msg_ctx);
     1142        if (sconn == NULL) {
     1143                DEBUG(1, ("could not find sconn\n"));
     1144                return;
     1145        }
    11041146
    11051147        message_to_share_mode_entry(&e, (char *)data->data);
     
    11151157        }
    11161158
    1117         fsp = file_find_dif(e.id, e.share_file_id);
     1159        fsp = file_find_dif(sconn, e.id, e.share_file_id);
    11181160        if (!fsp) {
    11191161                DEBUG(10,("msg_close_file: failed to find file.\n"));
Note: See TracChangeset for help on using the changeset viewer.