~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/modules/onefs_open.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 */
34
34
 
35
35
#include "includes.h"
 
36
#include "smbd/smbd.h"
36
37
#include "onefs.h"
37
38
#include "onefs_config.h"
38
39
#include "oplock_onefs.h"
54
55
                              uint32_t file_attributes,
55
56
                              uint32_t oplock_request,
56
57
                              uint64_t allocation_size,
 
58
                              uint32_t private_flags,
57
59
                              struct security_descriptor *sd,
58
60
                              struct ea_list *ea_list,
59
61
                              files_struct **result,
312
314
                fsp->can_write = (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ?
313
315
                        True : False;
314
316
        }
315
 
        fsp->print_file = False;
 
317
        fsp->print_file = NULL;
316
318
        fsp->modified = False;
317
319
        fsp->sent_oplock_break = NO_BREAK_SENT;
318
320
        fsp->is_directory = False;
325
327
        fsp->wcp = NULL; /* Write cache pointer. */
326
328
 
327
329
        DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
328
 
                 conn->server_info->unix_name,
 
330
                 conn->session_info->unix_name,
329
331
                 smb_fname_str_dbg(smb_fname),
330
332
                 BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
331
333
                 conn->num_files_open));
357
359
 
358
360
                if (procid_is_me(&e->pid) && (e->op_mid == req->mid)) {
359
361
                        DEBUG(0, ("Trying to defer an already deferred "
360
 
                                  "request: mid=%d, exiting\n", req->mid));
 
362
                                "request: mid=%llu, exiting\n",
 
363
                                (unsigned long long)req->mid));
361
364
                        exit_server("attempt to defer a deferred request");
362
365
                }
363
366
        }
365
368
        /* End paranoia check */
366
369
 
367
370
        DEBUG(10,("defer_open_sharing_error: time [%u.%06u] adding deferred "
368
 
                  "open entry for mid %u\n",
 
371
                  "open entry for mid %llu\n",
369
372
                  (unsigned int)request_time.tv_sec,
370
373
                  (unsigned int)request_time.tv_usec,
371
 
                  (unsigned int)req->mid));
 
374
                  (unsigned long long)req->mid));
372
375
 
373
 
        if (!push_deferred_smb_message(req, request_time, timeout,
374
 
                                       (char *)state, sizeof(*state))) {
375
 
                exit_server("push_deferred_smb_message failed");
 
376
        if (!push_deferred_open_message_smb(req, request_time, timeout,
 
377
                                       state->id, (char *)state, sizeof(*state))) {
 
378
                exit_server("push_deferred_open_message_smb failed");
376
379
        }
377
380
        add_deferred_open(lck, req->mid, request_time, state->id);
378
381
}
438
441
                                  uint32 create_options,
439
442
                                  uint32 new_dos_attributes,
440
443
                                  int oplock_request,
 
444
                                  uint32_t private_flags,
441
445
                                  struct security_descriptor *sd,
442
446
                                  files_struct *fsp,
443
447
                                  int *pinfo,
455
459
        mode_t unx_mode = (mode_t)0;
456
460
        int info;
457
461
        uint32 existing_dos_attributes = 0;
458
 
        struct pending_message_list *pml = NULL;
459
462
        struct timeval request_time = timeval_zero();
460
463
        struct share_mode_lock *lck = NULL;
461
464
        uint32 open_access_mask = access_mask;
481
484
                DEBUG(10, ("onefs_open_file_ntcreate: printer open fname=%s\n",
482
485
                           smb_fname_str_dbg(smb_fname)));
483
486
 
484
 
                return print_fsp_open(req, conn, smb_fname->base_name,
485
 
                                      req->vuid, fsp);
 
487
                return print_spool_open(fsp, smb_fname->base_name,
 
488
                                        req->vuid);
486
489
        }
487
490
 
488
491
        if (!parent_dirname(talloc_tos(), smb_fname->base_name, &parent_dir,
495
498
                unx_mode = (mode_t)(new_dos_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
496
499
                new_dos_attributes = 0;
497
500
        } else {
498
 
                /* We add aARCH to this as this mode is only used if the file is
 
501
                /* We add FILE_ATTRIBUTE_ARCHIVE to this as this mode is only used if the file is
499
502
                 * created new. */
500
 
                unx_mode = unix_mode(conn, new_dos_attributes | aARCH,
 
503
                unx_mode = unix_mode(conn, new_dos_attributes | FILE_ATTRIBUTE_ARCHIVE,
501
504
                                     smb_fname, parent_dir);
502
505
        }
503
506
 
540
543
         * Only non-internal opens can be deferred at all
541
544
         */
542
545
 
543
 
        if ((req != NULL)
544
 
            && ((pml = get_open_deferred_message(req->mid)) != NULL)) {
545
 
                struct deferred_open_record *state =
546
 
                        (struct deferred_open_record *)pml->private_data.data;
547
 
 
548
 
                /* Remember the absolute time of the original
549
 
                   request with this mid. We'll use it later to
550
 
                   see if this has timed out. */
551
 
 
552
 
                request_time = pml->request_time;
553
 
 
554
 
                /* Remove the deferred open entry under lock. */
555
 
                lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL,
556
 
                                          NULL);
557
 
                if (lck == NULL) {
558
 
                        DEBUG(0, ("could not get share mode lock\n"));
559
 
                } else {
560
 
                        del_deferred_open_entry(lck, req->mid);
561
 
                        TALLOC_FREE(lck);
562
 
                }
563
 
 
564
 
                /* Ensure we don't reprocess this message. */
565
 
                remove_deferred_open_smb_message(req->mid);
566
 
 
567
 
                /*
568
 
                 * When receiving a semlock_async_failure message, the
569
 
                 * deferred open will be marked as "failed". Returning
570
 
                 * INTERNAL_ERROR.
571
 
                 */
572
 
                if (state->failed) {
573
 
                        DEBUG(0, ("onefs_open_file_ntcreate: "
574
 
                                  "semlock_async_failure detected!\n"));
575
 
                        return NT_STATUS_INTERNAL_ERROR;
 
546
        if (req) {
 
547
                void *ptr;
 
548
                if (get_deferred_open_message_state(req,
 
549
                                &request_time,
 
550
                                &ptr)) {
 
551
                        struct deferred_open_record *state = (struct deferred_open_record *)ptr;
 
552
 
 
553
                        /* Remember the absolute time of the original
 
554
                           request with this mid. We'll use it later to
 
555
                           see if this has timed out. */
 
556
 
 
557
                        /* Remove the deferred open entry under lock. */
 
558
                        remove_deferred_open_entry(state->id, req->mid);
 
559
 
 
560
                        /* Ensure we don't reprocess this message. */
 
561
                        remove_deferred_open_message_smb(req->mid);
 
562
 
 
563
                        /*
 
564
                         * When receiving a semlock_async_failure message, the
 
565
                         * deferred open will be marked as "failed". Returning
 
566
                         * INTERNAL_ERROR.
 
567
                         */
 
568
                        if (state->failed) {
 
569
                                DEBUG(0, ("onefs_open_file_ntcreate: "
 
570
                                          "semlock_async_failure detected!\n"));
 
571
                                return NT_STATUS_INTERNAL_ERROR;
 
572
                        }
576
573
                }
577
574
        }
578
575
 
590
587
 
591
588
        /* Setup dos_attributes to be set by ifs_createfile */
592
589
        if (lp_store_dos_attributes(SNUM(conn))) {
593
 
                createfile_attributes = (new_dos_attributes | aARCH) &
 
590
                createfile_attributes = (new_dos_attributes | FILE_ATTRIBUTE_ARCHIVE) &
594
591
                    ~(FILE_ATTRIBUTE_NONINDEXED | FILE_ATTRIBUTE_COMPRESSED);
595
592
        }
596
593
 
597
594
        /* Ignore oplock requests if oplocks are disabled. */
598
 
        if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break ||
 
595
        if (!lp_oplocks(SNUM(conn)) ||
599
596
            IS_VETO_OPLOCK_PATH(conn, smb_fname->base_name)) {
600
597
                /* Mask off everything except the private Samba bits. */
601
598
                oplock_request &= SAMBA_PRIVATE_OPLOCK_MASK;
818
815
        DEBUG(10, ("fsp = %p\n", fsp));
819
816
 
820
817
        fsp->share_access = share_access;
821
 
        fsp->fh->private_options = create_options;
 
818
        fsp->fh->private_options = private_flags;
822
819
        fsp->access_mask = open_access_mask; /* We change this to the
823
820
                                              * requested access_mask after
824
821
                                              * the open is done. */
992
989
                         * calls. */
993
990
 
994
991
                        /* Try to find dup fsp if possible. */
995
 
                        if (create_options &
 
992
                        if (private_flags &
996
993
                            (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
997
994
                             NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
998
995
 
1261
1258
         * deny mode is compatible with all current opens.
1262
1259
         */
1263
1260
 
1264
 
        /* Record the options we were opened with. */
1265
 
        fsp->share_access = share_access;
1266
 
        fsp->fh->private_options = create_options;
1267
1261
        /*
1268
1262
         * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
1269
1263
         */
1316
1310
                new_file_created = True;
1317
1311
        }
1318
1312
 
1319
 
        set_share_mode(lck, fsp, conn->server_info->utok.uid, 0,
 
1313
        set_share_mode(lck, fsp, get_current_uid(conn),
 
1314
                        req ? req->mid : 0,
1320
1315
                       fsp->oplock_type);
1321
1316
 
1322
1317
        /* Handle strange delete on close create semantics. */
1488
1483
                mode = (mode_t)(file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
1489
1484
                file_attributes = 0;
1490
1485
        } else {
1491
 
                mode = unix_mode(conn, aDIR, smb_dname, parent_dir);
 
1486
                mode = unix_mode(conn, FILE_ATTRIBUTE_DIRECTORY, smb_dname, parent_dir);
1492
1487
        }
1493
1488
 
1494
1489
        /*
1629
1624
        fsp->can_write = False;
1630
1625
 
1631
1626
        fsp->share_access = share_access;
1632
 
        fsp->fh->private_options = create_options;
 
1627
        fsp->fh->private_options = 0;
1633
1628
        /*
1634
1629
         * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
1635
1630
         */
1636
1631
        fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
1637
 
        fsp->print_file = False;
 
1632
        fsp->print_file = NULL;
1638
1633
        fsp->modified = False;
1639
1634
        fsp->oplock_type = NO_OPLOCK;
1640
1635
        fsp->sent_oplock_break = NO_BREAK_SENT;
1672
1667
                return NT_STATUS_DELETE_PENDING;
1673
1668
        }
1674
1669
 
1675
 
        set_share_mode(lck, fsp, conn->server_info->utok.uid, 0, NO_OPLOCK);
 
1670
        set_share_mode(lck, fsp, get_current_uid(conn),
 
1671
                req ? req->mid : 0, NO_OPLOCK);
1676
1672
 
1677
1673
        /*
1678
1674
         * For directories the delete on close bit at open time seems
1718
1714
                                           uint32_t file_attributes,
1719
1715
                                           uint32_t oplock_request,
1720
1716
                                           uint64_t allocation_size,
 
1717
                                           uint32_t private_flags,
1721
1718
                                           struct security_descriptor *sd,
1722
1719
                                           struct ea_list *ea_list,
1723
1720
                                           files_struct **result,
1732
1729
        DEBUG(10,("onefs_create_file_unixpath: access_mask = 0x%x "
1733
1730
                  "file_attributes = 0x%x, share_access = 0x%x, "
1734
1731
                  "create_disposition = 0x%x create_options = 0x%x "
1735
 
                  "oplock_request = 0x%x ea_list = 0x%p, sd = 0x%p, "
 
1732
                  "oplock_request = 0x%x private_flags = 0x%x "
 
1733
                  "ea_list = 0x%p, sd = 0x%p, "
1736
1734
                  "fname = %s\n",
1737
1735
                  (unsigned int)access_mask,
1738
1736
                  (unsigned int)file_attributes,
1740
1738
                  (unsigned int)create_disposition,
1741
1739
                  (unsigned int)create_options,
1742
1740
                  (unsigned int)oplock_request,
 
1741
                  (unsigned int)private_flags,
1743
1742
                  ea_list, sd, smb_fname_str_dbg(smb_fname)));
1744
1743
 
1745
1744
        if (create_options & FILE_OPEN_BY_FILE_ID) {
1823
1822
                        file_attributes,                /* file_attributes */
1824
1823
                        NO_OPLOCK,                      /* oplock_request */
1825
1824
                        0,                              /* allocation_size */
 
1825
                        0,                              /* private_flags */
1826
1826
                        NULL,                           /* sd */
1827
1827
                        NULL,                           /* ea_list */
1828
1828
                        &base_fsp,                      /* result */
2066
2066
                           uint32_t file_attributes,
2067
2067
                           uint32_t oplock_request,
2068
2068
                           uint64_t allocation_size,
 
2069
                           uint32_t private_flags,
2069
2070
                           struct security_descriptor *sd,
2070
2071
                           struct ea_list *ea_list,
2071
2072
                           files_struct **result,
2080
2081
        DEBUG(10,("onefs_create_file: access_mask = 0x%x "
2081
2082
                  "file_attributes = 0x%x, share_access = 0x%x, "
2082
2083
                  "create_disposition = 0x%x create_options = 0x%x "
2083
 
                  "oplock_request = 0x%x "
 
2084
                  "oplock_request = 0x%x private_flags = 0x%x"
2084
2085
                  "root_dir_fid = 0x%x, ea_list = 0x%p, sd = 0x%p, "
2085
2086
                  "fname = %s\n",
2086
2087
                  (unsigned int)access_mask,
2089
2090
                  (unsigned int)create_disposition,
2090
2091
                  (unsigned int)create_options,
2091
2092
                  (unsigned int)oplock_request,
 
2093
                  (unsigned int)private_flags,
2092
2094
                  (unsigned int)root_dir_fid,
2093
2095
                  ea_list, sd, smb_fname_str_dbg(smb_fname)));
2094
2096
 
2109
2111
                goto fail;
2110
2112
        }
2111
2113
 
 
2114
        if (is_ntfs_stream_smb_fname(smb_fname)) {
 
2115
                if (!(conn->fs_capabilities & FILE_NAMED_STREAMS)) {
 
2116
                        status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 
2117
                        goto fail;
 
2118
                }
 
2119
 
 
2120
                if (is_ntfs_default_stream_smb_fname(smb_fname)) {
 
2121
                        int ret;
 
2122
                        smb_fname->stream_name = NULL;
 
2123
                        /* We have to handle this error here. */
 
2124
                        if (create_options & FILE_DIRECTORY_FILE) {
 
2125
                                status = NT_STATUS_NOT_A_DIRECTORY;
 
2126
                                goto fail;
 
2127
                        }
 
2128
                        if (lp_posix_pathnames()) {
 
2129
                                ret = SMB_VFS_LSTAT(conn, smb_fname);
 
2130
                        } else {
 
2131
                                ret = SMB_VFS_STAT(conn, smb_fname);
 
2132
                        }
 
2133
 
 
2134
                        if (ret == 0 && VALID_STAT_OF_DIR(smb_fname->st)) {
 
2135
                                status = NT_STATUS_FILE_IS_A_DIRECTORY;
 
2136
                                goto fail;
 
2137
                        }
 
2138
                }
 
2139
        }
 
2140
 
2112
2141
        status = onefs_create_file_unixpath(
2113
2142
                conn,                                   /* conn */
2114
2143
                req,                                    /* req */
2120
2149
                file_attributes,                        /* file_attributes */
2121
2150
                oplock_request,                         /* oplock_request */
2122
2151
                allocation_size,                        /* allocation_size */
 
2152
                private_flags,
2123
2153
                sd,                                     /* sd */
2124
2154
                ea_list,                                /* ea_list */
2125
2155
                &fsp,                                   /* result */