Ignore:
Timestamp:
Nov 29, 2012, 1:59:04 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/smbd/open.c

    r745 r751  
    9393                        smb_fname_str_dbg(smb_fname),
    9494                        (unsigned int)*access_granted ));
     95                return NT_STATUS_OK;
     96        }
     97
     98        if (access_mask == DELETE_ACCESS &&
     99                        VALID_STAT(smb_fname->st) &&
     100                        S_ISLNK(smb_fname->st.st_ex_mode)) {
     101                /* We can always delete a symlink. */
     102                DEBUG(10,("smbd_check_open_rights: not checking ACL "
     103                        "on DELETE_ACCESS on symlink %s.\n",
     104                        smb_fname_str_dbg(smb_fname) ));
    95105                return NT_STATUS_OK;
    96106        }
     
    698708}
    699709
    700 /*******************************************************************
    701  Return True if the filename is one of the special executable types.
    702 ********************************************************************/
    703 
    704 bool is_executable(const char *fname)
    705 {
    706         if ((fname = strrchr_m(fname,'.'))) {
    707                 if (strequal(fname,".com") ||
    708                     strequal(fname,".dll") ||
    709                     strequal(fname,".exe") ||
    710                     strequal(fname,".sym")) {
    711                         return True;
    712                 }
    713         }
    714         return False;
    715 }
    716 
    717710/****************************************************************************
    718711 Check if we can open a file with a share mode.
     
    942935}
    943936
    944 static bool is_delete_request(files_struct *fsp) {
    945         return ((fsp->access_mask == DELETE_ACCESS) &&
    946                 (fsp->oplock_type == NO_OPLOCK));
    947 }
    948 
    949937/*
    950938 * Send a break message to the oplock holder and delay the open for
     
    10911079
    10921080        if (ex_entry != NULL) {
    1093                 /* Found an exclusive or batch oplock */
    1094                 bool delay_it = is_delete_request(fsp) ?
    1095                                 BATCH_OPLOCK_TYPE(ex_entry->op_type) : true;
    1096                 if (delay_it) {
    1097                         send_break_message(fsp, ex_entry, mid, oplock_request);
    1098                         return true;
    1099                 }
     1081                send_break_message(fsp, ex_entry, mid, oplock_request);
     1082                return true;
    11001083        }
    11011084        return false;
     
    13351318}
    13361319
    1337 /****************************************************************************
    1338  Open a file with a share mode - old openX method - map into NTCreate.
    1339 ****************************************************************************/
    1340 
    1341 bool map_open_params_to_ntcreate(const struct smb_filename *smb_fname,
    1342                                  int deny_mode, int open_func,
    1343                                  uint32 *paccess_mask,
    1344                                  uint32 *pshare_mode,
    1345                                  uint32 *pcreate_disposition,
    1346                                  uint32 *pcreate_options,
    1347                                  uint32_t *pprivate_flags)
    1348 {
    1349         uint32 access_mask;
    1350         uint32 share_mode;
    1351         uint32 create_disposition;
    1352         uint32 create_options = FILE_NON_DIRECTORY_FILE;
    1353         uint32_t private_flags = 0;
    1354 
    1355         DEBUG(10,("map_open_params_to_ntcreate: fname = %s, deny_mode = 0x%x, "
    1356                   "open_func = 0x%x\n",
    1357                   smb_fname_str_dbg(smb_fname), (unsigned int)deny_mode,
    1358                   (unsigned int)open_func ));
    1359 
    1360         /* Create the NT compatible access_mask. */
    1361         switch (GET_OPENX_MODE(deny_mode)) {
    1362                 case DOS_OPEN_EXEC: /* Implies read-only - used to be FILE_READ_DATA */
    1363                 case DOS_OPEN_RDONLY:
    1364                         access_mask = FILE_GENERIC_READ;
    1365                         break;
    1366                 case DOS_OPEN_WRONLY:
    1367                         access_mask = FILE_GENERIC_WRITE;
    1368                         break;
    1369                 case DOS_OPEN_RDWR:
    1370                 case DOS_OPEN_FCB:
    1371                         access_mask = FILE_GENERIC_READ|FILE_GENERIC_WRITE;
    1372                         break;
    1373                 default:
    1374                         DEBUG(10,("map_open_params_to_ntcreate: bad open mode = 0x%x\n",
    1375                                   (unsigned int)GET_OPENX_MODE(deny_mode)));
    1376                         return False;
    1377         }
    1378 
    1379         /* Create the NT compatible create_disposition. */
    1380         switch (open_func) {
    1381                 case OPENX_FILE_EXISTS_FAIL|OPENX_FILE_CREATE_IF_NOT_EXIST:
    1382                         create_disposition = FILE_CREATE;
    1383                         break;
    1384 
    1385                 case OPENX_FILE_EXISTS_OPEN:
    1386                         create_disposition = FILE_OPEN;
    1387                         break;
    1388 
    1389                 case OPENX_FILE_EXISTS_OPEN|OPENX_FILE_CREATE_IF_NOT_EXIST:
    1390                         create_disposition = FILE_OPEN_IF;
    1391                         break;
    1392 
    1393                 case OPENX_FILE_EXISTS_TRUNCATE:
    1394                         create_disposition = FILE_OVERWRITE;
    1395                         break;
    1396 
    1397                 case OPENX_FILE_EXISTS_TRUNCATE|OPENX_FILE_CREATE_IF_NOT_EXIST:
    1398                         create_disposition = FILE_OVERWRITE_IF;
    1399                         break;
    1400 
    1401                 default:
    1402                         /* From samba4 - to be confirmed. */
    1403                         if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_EXEC) {
    1404                                 create_disposition = FILE_CREATE;
    1405                                 break;
    1406                         }
    1407                         DEBUG(10,("map_open_params_to_ntcreate: bad "
    1408                                   "open_func 0x%x\n", (unsigned int)open_func));
    1409                         return False;
    1410         }
    1411 
    1412         /* Create the NT compatible share modes. */
    1413         switch (GET_DENY_MODE(deny_mode)) {
    1414                 case DENY_ALL:
    1415                         share_mode = FILE_SHARE_NONE;
    1416                         break;
    1417 
    1418                 case DENY_WRITE:
    1419                         share_mode = FILE_SHARE_READ;
    1420                         break;
    1421 
    1422                 case DENY_READ:
    1423                         share_mode = FILE_SHARE_WRITE;
    1424                         break;
    1425 
    1426                 case DENY_NONE:
    1427                         share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
    1428                         break;
    1429 
    1430                 case DENY_DOS:
    1431                         private_flags |= NTCREATEX_OPTIONS_PRIVATE_DENY_DOS;
    1432                         if (is_executable(smb_fname->base_name)) {
    1433                                 share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
    1434                         } else {
    1435                                 if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_RDONLY) {
    1436                                         share_mode = FILE_SHARE_READ;
    1437                                 } else {
    1438                                         share_mode = FILE_SHARE_NONE;
    1439                                 }
    1440                         }
    1441                         break;
    1442 
    1443                 case DENY_FCB:
    1444                         private_flags |= NTCREATEX_OPTIONS_PRIVATE_DENY_FCB;
    1445                         share_mode = FILE_SHARE_NONE;
    1446                         break;
    1447 
    1448                 default:
    1449                         DEBUG(10,("map_open_params_to_ntcreate: bad deny_mode 0x%x\n",
    1450                                 (unsigned int)GET_DENY_MODE(deny_mode) ));
    1451                         return False;
    1452         }
    1453 
    1454         DEBUG(10,("map_open_params_to_ntcreate: file %s, access_mask = 0x%x, "
    1455                   "share_mode = 0x%x, create_disposition = 0x%x, "
    1456                   "create_options = 0x%x private_flags = 0x%x\n",
    1457                   smb_fname_str_dbg(smb_fname),
    1458                   (unsigned int)access_mask,
    1459                   (unsigned int)share_mode,
    1460                   (unsigned int)create_disposition,
    1461                   (unsigned int)create_options,
    1462                   (unsigned int)private_flags));
    1463 
    1464         if (paccess_mask) {
    1465                 *paccess_mask = access_mask;
    1466         }
    1467         if (pshare_mode) {
    1468                 *pshare_mode = share_mode;
    1469         }
    1470         if (pcreate_disposition) {
    1471                 *pcreate_disposition = create_disposition;
    1472         }
    1473         if (pcreate_options) {
    1474                 *pcreate_options = create_options;
    1475         }
    1476         if (pprivate_flags) {
    1477                 *pprivate_flags = private_flags;
    1478         }
    1479 
    1480         return True;
    1481 
    1482 }
    1483 
    14841320static void schedule_defer_open(struct share_mode_lock *lck,
    14851321                                struct timeval request_time,
     
    15731409                                        smb_fname_str_dbg(smb_fname)));
    15741410                                return NT_STATUS_ACCESS_DENIED;
     1411                        }
     1412
     1413                        if (!(access_granted & DELETE_ACCESS)) {
     1414                                if (can_delete_file_in_directory(conn, smb_fname)) {
     1415                                        access_granted |= DELETE_ACCESS;
     1416                                }
    15751417                        }
    15761418
     
    17051547        ZERO_STRUCT(id);
    17061548
    1707         /* Windows allows a new file to be created and
    1708            silently removes a FILE_ATTRIBUTE_DIRECTORY
    1709            sent by the client. Do the same. */
    1710 
    1711         new_dos_attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
    1712 
    17131549        if (conn->printer) {
    17141550                /*
     
    17441580                new_dos_attributes = 0;
    17451581        } else {
     1582                /* Windows allows a new file to be created and
     1583                   silently removes a FILE_ATTRIBUTE_DIRECTORY
     1584                   sent by the client. Do the same. */
     1585
     1586                new_dos_attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
     1587
    17461588                /* We add FILE_ATTRIBUTE_ARCHIVE to this as this mode is only used if the file is
    17471589                 * created new. */
     
    17871629                        remove_deferred_open_message_smb(req->mid);
    17881630                }
    1789         }
    1790 
    1791         status = check_name(conn, smb_fname->base_name);
    1792         if (!NT_STATUS_IS_OK(status)) {
    1793                 return status;
    17941631        }
    17951632
     
    27432580        SMB_ASSERT(!is_ntfs_stream_smb_fname(smb_dname));
    27442581
    2745         /* Ensure we have a directory attribute. */
    2746         file_attributes |= FILE_ATTRIBUTE_DIRECTORY;
     2582        if (!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
     2583                /* Ensure we have a directory attribute. */
     2584                file_attributes |= FILE_ATTRIBUTE_DIRECTORY;
     2585        }
    27472586
    27482587        DEBUG(5,("open_directory: opening directory %s, access_mask = 0x%x, "
     
    29002739        fsp->share_access = share_access;
    29012740        fsp->fh->private_options = 0;
    2902         /*
    2903          * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
    2904          */
    2905         fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
    29062741        fsp->print_file = NULL;
    29072742        fsp->modified = False;
     
    29182753        mtimespec = smb_dname->st.st_ex_mtime;
    29192754
     2755        /* Temporary access mask used to open the directory fd. */
     2756        fsp->access_mask = FILE_READ_DATA | FILE_READ_ATTRIBUTES;
    29202757#ifdef O_DIRECTORY
    29212758        status = fd_open(conn, fsp, O_RDONLY|O_DIRECTORY, 0);
     
    29322769                return status;
    29332770        }
     2771
     2772        /*
     2773         * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
     2774         * Set the real access mask for later access (possibly delete).
     2775         */
     2776        fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
    29342777
    29352778        status = vfs_stat_fsp(fsp);
     
    31322975                                        const char *fname)
    31332976{
    3134         struct stream_struct *stream_info;
    3135         files_struct **streams;
     2977        struct stream_struct *stream_info = NULL;
     2978        files_struct **streams = NULL;
    31362979        int i;
    3137         unsigned int num_streams;
     2980        unsigned int num_streams = 0;
    31382981        TALLOC_CTX *frame = talloc_stackframe();
    31392982        NTSTATUS status;
    31402983
    3141         status = SMB_VFS_STREAMINFO(conn, NULL, fname, talloc_tos(),
    3142                                     &num_streams, &stream_info);
     2984        status = vfs_streaminfo(conn, NULL, fname, talloc_tos(),
     2985                                &num_streams, &stream_info);
    31432986
    31442987        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)
     
    31502993
    31512994        if (!NT_STATUS_IS_OK(status)) {
    3152                 DEBUG(10, ("SMB_VFS_STREAMINFO failed: %s\n",
     2995                DEBUG(10, ("vfs_streaminfo failed: %s\n",
    31532996                           nt_errstr(status)));
    31542997                goto fail;
     
    35173360                fsp->access_mask = FILE_GENERIC_ALL;
    35183361
    3519                 /* Convert all the generic bits. */
    3520                 security_acl_map_generic(sd->dacl, &file_generic_mapping);
    3521                 security_acl_map_generic(sd->sacl, &file_generic_mapping);
    3522 
    35233362                if (sec_info_sent & (SECINFO_OWNER|
    35243363                                        SECINFO_GROUP|
    35253364                                        SECINFO_DACL|
    35263365                                        SECINFO_SACL)) {
    3527                         status = SMB_VFS_FSET_NT_ACL(fsp, sec_info_sent, sd);
     3366                        status = set_sd(fsp, sd, sec_info_sent);
    35283367                }
    35293368
     
    38143653        }
    38153654
    3816         /* All file access must go through check_name() */
    3817 
    3818         status = check_name(conn, smb_fname->base_name);
    3819         if (!NT_STATUS_IS_OK(status)) {
    3820                 goto fail;
    3821         }
    3822 
    38233655        if (stream_name && is_ntfs_default_stream_smb_fname(smb_fname)) {
    38243656                int ret;
Note: See TracChangeset for help on using the changeset viewer.