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/locking/locking.c

    r414 r740  
    3737
    3838#include "includes.h"
     39#include "system/filesys.h"
     40#include "locking/proto.h"
     41#include "smbd/globals.h"
     42#include "dbwrap.h"
     43#include "../libcli/security/security.h"
     44#include "serverid.h"
     45#include "messages.h"
     46#include "util_tdb.h"
    3947
    4048#undef DBGC_CLASS
     
    7785
    7886void init_strict_lock_struct(files_struct *fsp,
    79                                 uint32 smbpid,
     87                                uint64_t smblctx,
    8088                                br_off start,
    8189                                br_off size,
     
    8593        SMB_ASSERT(lock_type == READ_LOCK || lock_type == WRITE_LOCK);
    8694
    87         plock->context.smbpid = smbpid;
     95        plock->context.smblctx = smblctx;
    8896        plock->context.tid = fsp->conn->cnum;
    89         plock->context.pid = procid_self();
     97        plock->context.pid = sconn_server_id(fsp->conn->sconn);
    9098        plock->start = start;
    9199        plock->size = size;
     
    124132                        }
    125133                        ret = brl_locktest(br_lck,
    126                                         plock->context.smbpid,
     134                                        plock->context.smblctx,
    127135                                        plock->context.pid,
    128136                                        plock->start,
     
    139147                }
    140148                ret = brl_locktest(br_lck,
    141                                 plock->context.smbpid,
     149                                plock->context.smblctx,
    142150                                plock->context.pid,
    143151                                plock->start,
     
    166174
    167175NTSTATUS query_lock(files_struct *fsp,
    168                         uint32 *psmbpid,
     176                        uint64_t *psmblctx,
    169177                        uint64_t *pcount,
    170178                        uint64_t *poffset,
     
    188196
    189197        return brl_lockquery(br_lck,
    190                         psmbpid,
    191                         procid_self(),
     198                        psmblctx,
     199                        sconn_server_id(fsp->conn->sconn),
    192200                        poffset,
    193201                        pcount,
     
    230238struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
    231239                        files_struct *fsp,
    232                         uint32 lock_pid,
     240                        uint64_t smblctx,
    233241                        uint64_t count,
    234242                        uint64_t offset,
     
    237245                        bool blocking_lock,
    238246                        NTSTATUS *perr,
    239                         uint32 *plock_pid,
     247                        uint64_t *psmblctx,
    240248                        struct blocking_lock_record *blr)
    241249{
    242250        struct byte_range_lock *br_lck = NULL;
     251
     252        /* silently return ok on print files as we don't do locking there */
     253        if (fsp->print_file) {
     254                *perr = NT_STATUS_OK;
     255                return NULL;
     256        }
    243257
    244258        if (!fsp->can_lock) {
     
    268282        *perr = brl_lock(msg_ctx,
    269283                        br_lck,
    270                         lock_pid,
    271                         procid_self(),
     284                        smblctx,
     285                        sconn_server_id(fsp->conn->sconn),
    272286                        offset,
    273                         count, 
     287                        count,
    274288                        lock_type,
    275289                        lock_flav,
    276290                        blocking_lock,
    277                         plock_pid,
     291                        psmblctx,
    278292                        blr);
    279293
     
    290304NTSTATUS do_unlock(struct messaging_context *msg_ctx,
    291305                        files_struct *fsp,
    292                         uint32 lock_pid,
     306                        uint64_t smblctx,
    293307                        uint64_t count,
    294308                        uint64_t offset,
     
    317331        ok = brl_unlock(msg_ctx,
    318332                        br_lck,
    319                         lock_pid,
    320                         procid_self(),
     333                        smblctx,
     334                        sconn_server_id(fsp->conn->sconn),
    321335                        offset,
    322336                        count,
     
    339353
    340354NTSTATUS do_lock_cancel(files_struct *fsp,
    341                         uint32 lock_pid,
     355                        uint64 smblctx,
    342356                        uint64_t count,
    343357                        uint64_t offset,
     
    367381
    368382        ok = brl_lock_cancel(br_lck,
    369                         lock_pid,
    370                         procid_self(),
     383                        smblctx,
     384                        sconn_server_id(fsp->conn->sconn),
    371385                        offset,
    372386                        count,
     
    390404
    391405void locking_close_file(struct messaging_context *msg_ctx,
    392                         files_struct *fsp)
     406                        files_struct *fsp,
     407                        enum file_close_type close_type)
    393408{
    394409        struct byte_range_lock *br_lck;
     
    409424
    410425        if (br_lck) {
    411                 cancel_pending_lock_requests_by_fid(fsp, br_lck);
     426                cancel_pending_lock_requests_by_fid(fsp, br_lck, close_type);
    412427                brl_close_fnum(msg_ctx, br_lck);
    413428                TALLOC_FREE(br_lck);
     
    428443        lock_db = db_open(NULL, lock_path("locking.tdb"),
    429444                          lp_open_files_db_hash_size(),
    430                           TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST,
     445                          TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
    431446                          read_only?O_RDONLY:O_RDWR|O_CREAT, 0644);
    432447
     
    481496        return talloc_asprintf(ctx, "share_mode_entry[%d]: %s "
    482497                 "pid = %s, share_access = 0x%x, private_options = 0x%x, "
    483                  "access_mask = 0x%x, mid = 0x%x, type= 0x%x, gen_id = %lu, "
    484                  "uid = %u, flags = %u, file_id %s",
     498                 "access_mask = 0x%x, mid = 0x%llx, type= 0x%x, gen_id = %lu, "
     499                 "uid = %u, flags = %u, file_id %s, name_hash = 0x%x",
    485500                 num,
    486501                 e->op_type == UNUSED_SHARE_MODE_ENTRY ? "UNUSED" : "",
    487502                 procid_str_static(&e->pid),
    488503                 e->share_access, e->private_options,
    489                  e->access_mask, e->op_mid, e->op_type, e->share_file_id,
     504                 e->access_mask, (unsigned long long)e->op_mid,
     505                 e->op_type, e->share_file_id,
    490506                 (unsigned int)e->uid, (unsigned int)e->flags,
    491                  file_id_string_tos(&e->id));
     507                 file_id_string_tos(&e->id),
     508                 (unsigned int)e->name_hash);
    492509}
    493510
     
    521538}
    522539
     540static int parse_delete_tokens_list(struct share_mode_lock *lck,
     541                struct locking_data *pdata,
     542                const TDB_DATA dbuf)
     543{
     544        uint8_t *p = dbuf.dptr + sizeof(struct locking_data) +
     545                        (lck->num_share_modes *
     546                        sizeof(struct share_mode_entry));
     547        uint8_t *end_ptr = dbuf.dptr + (dbuf.dsize - 2);
     548        int delete_tokens_size = 0;
     549        int i;
     550
     551        lck->delete_tokens = NULL;
     552
     553        for (i = 0; i < pdata->u.s.num_delete_token_entries; i++) {
     554                uint32_t token_len;
     555                struct delete_token_list *pdtl;
     556
     557                if (end_ptr - p < (sizeof(uint32_t) + sizeof(uint32_t) +
     558                                        sizeof(uid_t) + sizeof(gid_t))) {
     559                        DEBUG(0,("parse_delete_tokens_list: "
     560                                "corrupt token list (%u)",
     561                                (unsigned int)(end_ptr - p)));
     562                        smb_panic("corrupt token list");
     563                        return -1;
     564                }
     565
     566                memcpy(&token_len, p, sizeof(token_len));
     567                delete_tokens_size += token_len;
     568
     569                if (p + token_len > end_ptr || token_len < sizeof(token_len) +
     570                                                sizeof(pdtl->name_hash) +
     571                                                sizeof(uid_t) +
     572                                                sizeof(gid_t)) {
     573                        DEBUG(0,("parse_delete_tokens_list: "
     574                                "invalid token length (%u)\n",
     575                                (unsigned int)token_len ));
     576                        smb_panic("invalid token length");
     577                        return -1;
     578                }
     579
     580                p += sizeof(token_len);
     581
     582                pdtl = TALLOC_ZERO_P(lck, struct delete_token_list);
     583                if (pdtl == NULL) {
     584                        DEBUG(0,("parse_delete_tokens_list: talloc failed"));
     585                        return -1;
     586                }
     587                /* Copy out the name_hash. */
     588                memcpy(&pdtl->name_hash, p, sizeof(pdtl->name_hash));
     589                p += sizeof(pdtl->name_hash);
     590
     591                pdtl->delete_token = TALLOC_ZERO_P(pdtl, struct security_unix_token);
     592                if (pdtl->delete_token == NULL) {
     593                        DEBUG(0,("parse_delete_tokens_list: talloc failed"));
     594                        return -1;
     595                }
     596
     597                /* Copy out the uid and gid. */
     598                memcpy(&pdtl->delete_token->uid, p, sizeof(uid_t));
     599                p += sizeof(uid_t);
     600                memcpy(&pdtl->delete_token->gid, p, sizeof(gid_t));
     601                p += sizeof(gid_t);
     602
     603                token_len -= (sizeof(token_len) + sizeof(pdtl->name_hash) +
     604                                sizeof(uid_t) + sizeof(gid_t));
     605
     606                /* Any supplementary groups ? */
     607                if (token_len) {
     608                        int j;
     609
     610                        if (token_len % sizeof(gid_t) != 0) {
     611                                DEBUG(0,("parse_delete_tokens_list: "
     612                                        "corrupt group list (%u)",
     613                                        (unsigned int)(token_len % sizeof(gid_t)) ));
     614                                smb_panic("corrupt group list");
     615                                return -1;
     616                        }
     617
     618                        pdtl->delete_token->ngroups = token_len / sizeof(gid_t);
     619                        pdtl->delete_token->groups = TALLOC_ARRAY(pdtl->delete_token, gid_t,
     620                                                pdtl->delete_token->ngroups);
     621                        if (pdtl->delete_token->groups == NULL) {
     622                                DEBUG(0,("parse_delete_tokens_list: talloc failed"));
     623                                return -1;
     624                        }
     625
     626                        for (j = 0; j < pdtl->delete_token->ngroups; j++) {
     627                                memcpy(&pdtl->delete_token->groups[j], p, sizeof(gid_t));
     628                                p += sizeof(gid_t);
     629                        }
     630                }
     631                /* Add to the list. */
     632                DLIST_ADD(lck->delete_tokens, pdtl);
     633        }
     634
     635        return delete_tokens_size;
     636}
     637
    523638/*******************************************************************
    524639 Get all share mode entries for a dev/inode pair.
     
    528643{
    529644        struct locking_data data;
     645        int delete_tokens_size;
    530646        int i;
    531647
     
    536652        memcpy(&data, dbuf.dptr, sizeof(data));
    537653
    538         lck->delete_on_close = data.u.s.delete_on_close;
    539654        lck->old_write_time = data.u.s.old_write_time;
    540655        lck->changed_write_time = data.u.s.changed_write_time;
    541656        lck->num_share_modes = data.u.s.num_share_mode_entries;
    542657
    543         DEBUG(10, ("parse_share_modes: delete_on_close: %d, owrt: %s, "
    544                    "cwrt: %s, tok: %u, num_share_modes: %d\n",
    545                    lck->delete_on_close,
     658        DEBUG(10, ("parse_share_modes: owrt: %s, "
     659                   "cwrt: %s, ntok: %u, num_share_modes: %d\n",
    546660                   timestring(talloc_tos(),
    547661                              convert_timespec_to_time_t(lck->old_write_time)),
     
    549663                              convert_timespec_to_time_t(
    550664                                      lck->changed_write_time)),
    551                    (unsigned int)data.u.s.delete_token_size,
     665                   (unsigned int)data.u.s.num_delete_token_entries,
    552666                   lck->num_share_modes));
    553667
     
    579693        }
    580694
    581         /* Get any delete token. */
    582         if (data.u.s.delete_token_size) {
    583                 uint8 *p = dbuf.dptr + sizeof(struct locking_data) +
    584                                 (lck->num_share_modes *
    585                                 sizeof(struct share_mode_entry));
    586 
    587                 if ((data.u.s.delete_token_size < sizeof(uid_t) + sizeof(gid_t)) ||
    588                                 ((data.u.s.delete_token_size - sizeof(uid_t)) % sizeof(gid_t)) != 0) {
    589                         DEBUG(0, ("parse_share_modes: invalid token size %d\n",
    590                                 data.u.s.delete_token_size));
    591                         smb_panic("parse_share_modes: invalid token size");
    592                 }
    593 
    594                 lck->delete_token = TALLOC_P(lck, UNIX_USER_TOKEN);
    595                 if (!lck->delete_token) {
    596                         smb_panic("parse_share_modes: talloc failed");
    597                 }
    598 
    599                 /* Copy out the uid and gid. */
    600                 memcpy(&lck->delete_token->uid, p, sizeof(uid_t));
    601                 p += sizeof(uid_t);
    602                 memcpy(&lck->delete_token->gid, p, sizeof(gid_t));
    603                 p += sizeof(gid_t);
    604 
    605                 /* Any supplementary groups ? */
    606                 lck->delete_token->ngroups = (data.u.s.delete_token_size > (sizeof(uid_t) + sizeof(gid_t))) ?
    607                                         ((data.u.s.delete_token_size -
    608                                                 (sizeof(uid_t) + sizeof(gid_t)))/sizeof(gid_t)) : 0;
    609 
    610                 if (lck->delete_token->ngroups) {
    611                         /* Make this a talloc child of lck->delete_token. */
    612                         lck->delete_token->groups = TALLOC_ARRAY(lck->delete_token, gid_t,
    613                                                         lck->delete_token->ngroups);
    614                         if (!lck->delete_token) {
    615                                 smb_panic("parse_share_modes: talloc failed");
    616                         }
    617 
    618                         for (i = 0; i < lck->delete_token->ngroups; i++) {
    619                                 memcpy(&lck->delete_token->groups[i], p, sizeof(gid_t));
    620                                 p += sizeof(gid_t);
    621                         }
    622                 }
    623 
    624         } else {
    625                 lck->delete_token = NULL;
     695        /* Get any delete tokens. */
     696        delete_tokens_size = parse_delete_tokens_list(lck, &data, dbuf);
     697        if (delete_tokens_size < 0) {
     698                smb_panic("parse_share_modes: parse_delete_tokens_list failed");
    626699        }
    627700
     
    629702        lck->servicepath = (const char *)dbuf.dptr + sizeof(struct locking_data) +
    630703                (lck->num_share_modes * sizeof(struct share_mode_entry)) +
    631                 data.u.s.delete_token_size;
     704                delete_tokens_size;
    632705
    633706        lck->base_name = (const char *)dbuf.dptr + sizeof(struct locking_data) +
    634707                (lck->num_share_modes * sizeof(struct share_mode_entry)) +
    635                 data.u.s.delete_token_size +
     708                delete_tokens_size +
    636709                strlen(lck->servicepath) + 1;
    637710
    638711        lck->stream_name = (const char *)dbuf.dptr + sizeof(struct locking_data) +
    639712                (lck->num_share_modes * sizeof(struct share_mode_entry)) +
    640                 data.u.s.delete_token_size +
     713                delete_tokens_size +
    641714                strlen(lck->servicepath) + 1 +
    642715                strlen(lck->base_name) + 1;
     
    654727                DEBUG(10,("parse_share_modes: %s\n",
    655728                        str ? str : ""));
    656                 if (!process_exists(entry_p->pid)) {
     729                if (!serverid_exists(&entry_p->pid)) {
    657730                        DEBUG(10,("parse_share_modes: deleted %s\n",
    658731                                str ? str : ""));
     
    674747        ssize_t offset;
    675748        ssize_t sp_len, bn_len, sn_len;
    676         uint32 delete_token_size;
     749        uint32_t delete_tokens_size = 0;
     750        struct delete_token_list *pdtl = NULL;
     751        uint32_t num_delete_token_entries = 0;
    677752
    678753        result.dptr = NULL;
     
    693768        sn_len = lck->stream_name != NULL ? strlen(lck->stream_name) : 0;
    694769
    695         delete_token_size = (lck->delete_token ?
    696                         (sizeof(uid_t) + sizeof(gid_t) + (lck->delete_token->ngroups*sizeof(gid_t))) : 0);
     770        for (pdtl = lck->delete_tokens; pdtl; pdtl = pdtl->next) {
     771                num_delete_token_entries++;
     772                delete_tokens_size += (sizeof(uint32_t) +
     773                                sizeof(uint32_t) +
     774                                sizeof(uid_t) +
     775                                sizeof(gid_t) +
     776                                pdtl->delete_token->ngroups*sizeof(gid_t));
     777        }
    697778
    698779        result.dsize = sizeof(*data) +
    699780                lck->num_share_modes * sizeof(struct share_mode_entry) +
    700                 delete_token_size +
     781                delete_tokens_size +
    701782                sp_len + 1 +
    702783                bn_len + 1 +
     
    711792        ZERO_STRUCTP(data);
    712793        data->u.s.num_share_mode_entries = lck->num_share_modes;
    713         data->u.s.delete_on_close = lck->delete_on_close;
    714794        data->u.s.old_write_time = lck->old_write_time;
    715795        data->u.s.changed_write_time = lck->changed_write_time;
    716         data->u.s.delete_token_size = delete_token_size;
    717 
    718         DEBUG(10,("unparse_share_modes: del: %d, owrt: %s cwrt: %s, tok: %u, "
    719                   "num: %d\n", data->u.s.delete_on_close,
     796        data->u.s.num_delete_token_entries = num_delete_token_entries;
     797
     798        DEBUG(10,("unparse_share_modes: owrt: %s cwrt: %s, ntok: %u, "
     799                  "num: %d\n",
    720800                  timestring(talloc_tos(),
    721801                             convert_timespec_to_time_t(lck->old_write_time)),
     
    723803                             convert_timespec_to_time_t(
    724804                                     lck->changed_write_time)),
    725                   (unsigned int)data->u.s.delete_token_size,
     805                  (unsigned int)data->u.s.num_delete_token_entries,
    726806                  data->u.s.num_share_mode_entries));
    727807
     
    731811                sizeof(struct share_mode_entry)*lck->num_share_modes;
    732812
    733         /* Store any delete on close token. */
    734         if (lck->delete_token) {
    735                 uint8 *p = result.dptr + offset;
    736 
    737                 memcpy(p, &lck->delete_token->uid, sizeof(uid_t));
     813        /* Store any delete on close tokens. */
     814        for (pdtl = lck->delete_tokens; pdtl; pdtl = pdtl->next) {
     815                struct security_unix_token *pdt = pdtl->delete_token;
     816                uint32_t token_size = sizeof(uint32_t) +
     817                                        sizeof(uint32_t) +
     818                                        sizeof(uid_t) +
     819                                        sizeof(gid_t) +
     820                                        (pdt->ngroups * sizeof(gid_t));
     821                uint8_t *p = result.dptr + offset;
     822
     823                memcpy(p, &token_size, sizeof(uint32_t));
     824                p += sizeof(uint32_t);
     825
     826                memcpy(p, &pdtl->name_hash, sizeof(uint32_t));
     827                p += sizeof(uint32_t);
     828
     829                memcpy(p, &pdt->uid, sizeof(uid_t));
    738830                p += sizeof(uid_t);
    739831
    740                 memcpy(p, &lck->delete_token->gid, sizeof(gid_t));
     832                memcpy(p, &pdt->gid, sizeof(gid_t));
    741833                p += sizeof(gid_t);
    742834
    743                 for (i = 0; i < lck->delete_token->ngroups; i++) {
    744                         memcpy(p, &lck->delete_token->groups[i], sizeof(gid_t));
     835                for (i = 0; i < pdt->ngroups; i++) {
     836                        memcpy(p, &pdt->groups[i], sizeof(gid_t));
    745837                        p += sizeof(gid_t);
    746838                }
    747                 offset = p - result.dptr;
     839                offset += token_size;
    748840        }
    749841
     
    832924        lck->num_share_modes = 0;
    833925        lck->share_modes = NULL;
    834         lck->delete_token = NULL;
    835         lck->delete_on_close = False;
     926        lck->delete_tokens = NULL;
    836927        ZERO_STRUCT(lck->old_write_time);
    837928        ZERO_STRUCT(lck->changed_write_time);
     
    9421033                        struct share_mode_lock *lck,
    9431034                        const char *servicepath,
     1035                        uint32_t orig_name_hash,
     1036                        uint32_t new_name_hash,
    9441037                        const struct smb_filename *smb_fname_dst)
    9451038{
     
    10071100                        continue;
    10081101                }
     1102
     1103                /* If this is a hardlink to the inode
     1104                   with a different name, skip this. */
     1105                if (se->name_hash != orig_name_hash) {
     1106                        continue;
     1107                }
     1108
     1109                se->name_hash = new_name_hash;
     1110
    10091111                /* But not to ourselves... */
    10101112                if (procid_is_me(&se->pid)) {
     
    10281130
    10291131void get_file_infos(struct file_id id,
     1132                    uint32_t name_hash,
    10301133                    bool *delete_on_close,
    10311134                    struct timespec *write_time)
     
    10461149
    10471150        if (delete_on_close) {
    1048                 *delete_on_close = lck->delete_on_close;
     1151                *delete_on_close = is_delete_on_close_set(lck, name_hash);
    10491152        }
    10501153
     
    10991202static void fill_share_mode_entry(struct share_mode_entry *e,
    11001203                                  files_struct *fsp,
    1101                                   uid_t uid, uint16 mid, uint16 op_type)
     1204                                  uid_t uid, uint64_t mid, uint16 op_type)
    11021205{
    11031206        ZERO_STRUCTP(e);
    1104         e->pid = procid_self();
     1207        e->pid = sconn_server_id(fsp->conn->sconn);
    11051208        e->share_access = fsp->share_access;
    11061209        e->private_options = fsp->fh->private_options;
     
    11141217        e->uid = (uint32)uid;
    11151218        e->flags = fsp->posix_open ? SHARE_MODE_FLAG_POSIX_OPEN : 0;
     1219        e->name_hash = fsp->name_hash;
    11161220}
    11171221
    11181222static void fill_deferred_open_entry(struct share_mode_entry *e,
    11191223                                     const struct timeval request_time,
    1120                                      struct file_id id, uint16 mid)
     1224                                     struct file_id id,
     1225                                     struct server_id pid,
     1226                                     uint64_t mid)
    11211227{
    11221228        ZERO_STRUCTP(e);
    1123         e->pid = procid_self();
     1229        e->pid = pid;
    11241230        e->op_mid = mid;
    11251231        e->op_type = DEFERRED_OPEN_ENTRY;
     
    11531259
    11541260void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
    1155                     uid_t uid, uint16 mid, uint16 op_type)
     1261                    uid_t uid, uint64_t mid, uint16 op_type)
    11561262{
    11571263        struct share_mode_entry entry;
     
    11601266}
    11611267
    1162 void add_deferred_open(struct share_mode_lock *lck, uint16 mid,
     1268void add_deferred_open(struct share_mode_lock *lck, uint64_t mid,
    11631269                       struct timeval request_time,
    1164                        struct file_id id)
     1270                       struct server_id pid, struct file_id id)
    11651271{
    11661272        struct share_mode_entry entry;
    1167         fill_deferred_open_entry(&entry, request_time, id, mid);
     1273        fill_deferred_open_entry(&entry, request_time, id, pid, mid);
    11681274        add_share_mode_entry(lck, &entry);
    11691275}
     
    12391345}
    12401346
    1241 void del_deferred_open_entry(struct share_mode_lock *lck, uint16 mid)
     1347void del_deferred_open_entry(struct share_mode_lock *lck, uint64_t mid,
     1348                             struct server_id pid)
    12421349{
    12431350        struct share_mode_entry entry, *e;
    12441351
    12451352        fill_deferred_open_entry(&entry, timeval_zero(),
    1246                                  lck->id, mid);
     1353                                 lck->id, pid, mid);
    12471354
    12481355        e = find_share_mode_entry(lck, &entry);
     
    12711378        }
    12721379
    1273         e->op_mid = 0;
    1274         if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
     1380        if (EXCLUSIVE_OPLOCK_TYPE(e->op_type)) {
    12751381                /*
    12761382                 * Going from exclusive or batch,
     
    12781384                 * first.
    12791385                 */
     1386                if (!EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
     1387                        smb_panic("remove_share_oplock: logic error");
     1388                }
    12801389                e->op_type = FAKE_LEVEL_II_OPLOCK;
    12811390        } else {
     
    13171426         */
    13181427
    1319         if ((dosmode & aRONLY) &&
     1428        if ((dosmode & FILE_ATTRIBUTE_READONLY) &&
    13201429            !lp_delete_readonly(SNUM(fsp->conn))) {
    13211430                DEBUG(10,("can_set_delete_on_close: file %s delete on close "
     
    13591468
    13601469/*************************************************************************
    1361  Return a talloced copy of a UNIX_USER_TOKEN. NULL on fail.
     1470 Return a talloced copy of a struct security_unix_token. NULL on fail.
    13621471 (Should this be in locking.c.... ?).
    13631472*************************************************************************/
    13641473
    1365 static UNIX_USER_TOKEN *copy_unix_token(TALLOC_CTX *ctx, const UNIX_USER_TOKEN *tok)
    1366 {
    1367         UNIX_USER_TOKEN *cpy;
    1368 
    1369         if (tok == NULL) {
    1370                 return NULL;
    1371         }
    1372 
    1373         cpy = TALLOC_P(ctx, UNIX_USER_TOKEN);
     1474static struct security_unix_token *copy_unix_token(TALLOC_CTX *ctx, const struct security_unix_token *tok)
     1475{
     1476        struct security_unix_token *cpy;
     1477
     1478        cpy = TALLOC_P(ctx, struct security_unix_token);
    13741479        if (!cpy) {
    13751480                return NULL;
     
    13911496
    13921497/****************************************************************************
    1393  Replace the delete on close token.
     1498 Adds a delete on close token.
    13941499****************************************************************************/
    13951500
    1396 void set_delete_on_close_token(struct share_mode_lock *lck, const UNIX_USER_TOKEN *tok)
    1397 {
    1398         TALLOC_FREE(lck->delete_token); /* Also deletes groups... */
    1399 
    1400         /* Copy the new token (can be NULL). */
    1401         lck->delete_token = copy_unix_token(lck, tok);
    1402         lck->modified = True;
     1501static bool add_delete_on_close_token(struct share_mode_lock *lck,
     1502                        uint32_t name_hash,
     1503                        const struct security_unix_token *tok)
     1504{
     1505        struct delete_token_list *dtl;
     1506
     1507        dtl = TALLOC_ZERO_P(lck, struct delete_token_list);
     1508        if (dtl == NULL) {
     1509                return false;
     1510        }
     1511
     1512        dtl->name_hash = name_hash;
     1513        dtl->delete_token = copy_unix_token(lck, tok);
     1514        if (dtl->delete_token == NULL) {
     1515                TALLOC_FREE(dtl);
     1516                return false;
     1517        }
     1518        DLIST_ADD(lck->delete_tokens, dtl);
     1519        lck->modified = true;
     1520        return true;
    14031521}
    14041522
     
    14101528 in the close code, the last closer will delete the file
    14111529 if flag is set.
    1412  This makes a copy of any UNIX_USER_TOKEN into the
     1530 This makes a copy of any struct security_unix_token into the
    14131531 lck entry. This function is used when the lock is already granted.
    14141532****************************************************************************/
    14151533
    1416 void set_delete_on_close_lck(struct share_mode_lock *lck, bool delete_on_close, const UNIX_USER_TOKEN *tok)
    1417 {
    1418         if (lck->delete_on_close != delete_on_close) {
    1419                 set_delete_on_close_token(lck, tok);
    1420                 lck->delete_on_close = delete_on_close;
    1421                 if (delete_on_close) {
    1422                         SMB_ASSERT(lck->delete_token != NULL);
    1423                 }
    1424                 lck->modified = True;
    1425         }
    1426 }
    1427 
    1428 bool set_delete_on_close(files_struct *fsp, bool delete_on_close, const UNIX_USER_TOKEN *tok)
    1429 {
    1430         UNIX_USER_TOKEN *tok_copy = NULL;
     1534void set_delete_on_close_lck(files_struct *fsp,
     1535                        struct share_mode_lock *lck,
     1536                        bool delete_on_close,
     1537                        const struct security_unix_token *tok)
     1538{
     1539        struct delete_token_list *dtl;
     1540        bool ret;
     1541
     1542        if (delete_on_close) {
     1543                SMB_ASSERT(tok != NULL);
     1544        } else {
     1545                SMB_ASSERT(tok == NULL);
     1546        }
     1547
     1548        for (dtl = lck->delete_tokens; dtl; dtl = dtl->next) {
     1549                if (dtl->name_hash == fsp->name_hash) {
     1550                        lck->modified = true;
     1551                        if (delete_on_close == false) {
     1552                                /* Delete this entry. */
     1553                                DLIST_REMOVE(lck->delete_tokens, dtl);
     1554                                TALLOC_FREE(dtl);
     1555                                return;
     1556                        }
     1557                        /* Replace this token with the
     1558                           given tok. */
     1559                        TALLOC_FREE(dtl->delete_token);
     1560                        dtl->delete_token = copy_unix_token(dtl, tok);
     1561                        SMB_ASSERT(dtl->delete_token != NULL);
     1562                }
     1563        }
     1564
     1565        if (!delete_on_close) {
     1566                /* Nothing to delete - not found. */
     1567                return;
     1568        }
     1569
     1570        ret = add_delete_on_close_token(lck, fsp->name_hash, tok);
     1571        SMB_ASSERT(ret);
     1572}
     1573
     1574bool set_delete_on_close(files_struct *fsp, bool delete_on_close, const struct security_unix_token *tok)
     1575{
    14311576        struct share_mode_lock *lck;
    14321577       
     
    14421587        }
    14431588
    1444         if (fsp->conn->admin_user) {
    1445                 tok_copy = copy_unix_token(lck, tok);
    1446                 if (tok_copy == NULL) {
    1447                         TALLOC_FREE(lck);
    1448                         return false;
    1449                 }
    1450                 tok_copy->uid = (uid_t)0;
    1451                 tok = tok_copy;
    1452         }
    1453 
    1454         set_delete_on_close_lck(lck, delete_on_close, tok);
     1589        set_delete_on_close_lck(fsp, lck, delete_on_close,
     1590                        delete_on_close ? tok : NULL);
    14551591
    14561592        if (fsp->is_directory) {
    14571593                SMB_ASSERT(!is_ntfs_stream_smb_fname(fsp->fsp_name));
    1458                 send_stat_cache_delete_message(fsp->fsp_name->base_name);
     1594                send_stat_cache_delete_message(fsp->conn->sconn->msg_ctx,
     1595                                               fsp->fsp_name->base_name);
    14591596        }
    14601597
     
    14641601
    14651602        return True;
     1603}
     1604
     1605const struct security_unix_token *get_delete_on_close_token(struct share_mode_lock *lck, uint32_t name_hash)
     1606{
     1607        struct delete_token_list *dtl;
     1608
     1609        DEBUG(10,("get_delete_on_close_token: name_hash = 0x%x\n",
     1610                        (unsigned int)name_hash ));
     1611
     1612        for (dtl = lck->delete_tokens; dtl; dtl = dtl->next) {
     1613                DEBUG(10,("get_delete_on_close_token: dtl->name_hash = 0x%x\n",
     1614                                (unsigned int)dtl->name_hash ));
     1615                if (dtl->name_hash == name_hash) {
     1616                        return dtl->delete_token;
     1617                }
     1618        }
     1619        return NULL;
     1620}
     1621
     1622bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash)
     1623{
     1624        return (get_delete_on_close_token(lck, name_hash) != NULL);
    14661625}
    14671626
     
    15281687        const char *sharepath;
    15291688        const char *fname;
     1689        const char *del_tokens;
     1690        uint32_t total_del_token_size = 0;
    15301691        int i;
    15311692
     
    15361697        data = (struct locking_data *)rec->value.dptr;
    15371698        shares = (struct share_mode_entry *)(rec->value.dptr + sizeof(*data));
     1699        del_tokens = (const char *)rec->value.dptr + sizeof(*data) +
     1700                data->u.s.num_share_mode_entries*sizeof(*shares);
     1701
     1702        for (i = 0; i < data->u.s.num_delete_token_entries; i++) {
     1703                uint32_t del_token_size;
     1704                memcpy(&del_token_size, del_tokens, sizeof(uint32_t));
     1705                total_del_token_size += del_token_size;
     1706                del_tokens += del_token_size;
     1707        }
     1708
    15381709        sharepath = (const char *)rec->value.dptr + sizeof(*data) +
    15391710                data->u.s.num_share_mode_entries*sizeof(*shares) +
    1540                 data->u.s.delete_token_size;
     1711                total_del_token_size;
    15411712        fname = (const char *)rec->value.dptr + sizeof(*data) +
    15421713                data->u.s.num_share_mode_entries*sizeof(*shares) +
    1543                 data->u.s.delete_token_size +
     1714                total_del_token_size +
    15441715                strlen(sharepath) + 1;
    15451716
Note: See TracChangeset for help on using the changeset viewer.