LCOV - code coverage report
Current view: top level - source4/ntvfs/posix - pvfs_fileinfo.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 56 75 74.7 %
Date: 2023-11-21 12:31:41 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    POSIX NTVFS backend - 
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2004
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "vfs_posix.h"
      24             : #include "lib/util/time.h"
      25             : 
      26             : /****************************************************************************
      27             :  Change a unix mode to a dos mode.
      28             : ****************************************************************************/
      29      805989 : static uint32_t dos_mode_from_stat(struct pvfs_state *pvfs, struct stat *st)
      30             : {
      31      805989 :         int result = 0;
      32             : 
      33      805989 :         if ((st->st_mode & S_IWUSR) == 0)
      34           0 :                 result |= FILE_ATTRIBUTE_READONLY;
      35             :         
      36      805989 :         if ((pvfs->flags & PVFS_FLAG_MAP_ARCHIVE) && ((st->st_mode & S_IXUSR) != 0))
      37      366306 :                 result |= FILE_ATTRIBUTE_ARCHIVE;
      38             :         
      39      805989 :         if ((pvfs->flags & PVFS_FLAG_MAP_SYSTEM) && ((st->st_mode & S_IXGRP) != 0))
      40           0 :                 result |= FILE_ATTRIBUTE_SYSTEM;
      41             :         
      42      805989 :         if ((pvfs->flags & PVFS_FLAG_MAP_HIDDEN) && ((st->st_mode & S_IXOTH) != 0))
      43           0 :                 result |= FILE_ATTRIBUTE_HIDDEN;
      44             :   
      45      805989 :         if (S_ISDIR(st->st_mode))
      46      366229 :                 result = FILE_ATTRIBUTE_DIRECTORY | (result & FILE_ATTRIBUTE_READONLY);
      47             : 
      48      805989 :         return result;
      49             : }
      50             : 
      51             : 
      52             : 
      53             : /*
      54             :   fill in the dos file attributes for a file
      55             : */
      56      805989 : NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name,
      57             :                             unsigned int flags, int fd)
      58             : {
      59           0 :         NTSTATUS status;
      60           0 :         DATA_BLOB lkey;
      61           0 :         NTTIME write_time;
      62             : 
      63             :         /* make directories appear as size 0 with 1 link */
      64      805989 :         if (S_ISDIR(name->st.st_mode)) {
      65      366229 :                 name->st.st_size = 0;
      66      366229 :                 name->st.st_nlink = 1;
      67      439760 :         } else if (name->stream_id == 0) {
      68      439237 :                 name->stream_name = NULL;
      69             :         }
      70             : 
      71             :         /* for now just use the simple samba mapping */
      72      805989 :         unix_to_nt_time(&name->dos.create_time, name->st.st_ctime);
      73      805989 :         unix_to_nt_time(&name->dos.access_time, name->st.st_atime);
      74      805989 :         unix_to_nt_time(&name->dos.write_time,  name->st.st_mtime);
      75      805989 :         unix_to_nt_time(&name->dos.change_time, name->st.st_ctime);
      76      805989 :         name->dos.create_time += get_ctimensec(&name->st) / 100;
      77      805989 :         name->dos.access_time += get_atimensec(&name->st) / 100;
      78      805989 :         name->dos.write_time  += get_mtimensec(&name->st) / 100;
      79      805989 :         name->dos.change_time += get_ctimensec(&name->st) / 100;
      80      805989 :         name->dos.attrib = dos_mode_from_stat(pvfs, &name->st);
      81      805989 :         name->dos.alloc_size = pvfs_round_alloc_size(pvfs, name->st.st_size);
      82      805989 :         name->dos.nlink = name->st.st_nlink;
      83      805989 :         name->dos.ea_size = 4;  /* TODO: Fill this in without hitting the stream bad in pvfs_doseas_load() */
      84      805989 :         if (pvfs->ntvfs->ctx->protocol >= PROTOCOL_SMB2_02) {
      85             :                 /* SMB2 represents a null EA with zero bytes */
      86      476917 :                 name->dos.ea_size = 0;
      87             :         }
      88             :         
      89      805989 :         name->dos.file_id = (((uint64_t)name->st.st_dev)<<32) | name->st.st_ino;
      90      805989 :         name->dos.flags = 0;
      91             : 
      92      805989 :         status = pvfs_dosattrib_load(pvfs, name, fd);
      93      805989 :         NT_STATUS_NOT_OK_RETURN(status);
      94             : 
      95      805989 :         if (flags & PVFS_RESOLVE_NO_OPENDB) {
      96      444759 :                 return NT_STATUS_OK;
      97             :         }
      98             : 
      99      361230 :         status = pvfs_locking_key(name, name, &lkey);
     100      361230 :         NT_STATUS_NOT_OK_RETURN(status);
     101             : 
     102      361230 :         status = odb_get_file_infos(pvfs->odb_context, &lkey,
     103             :                                     NULL, &write_time);
     104      361230 :         data_blob_free(&lkey);
     105      361230 :         if (!NT_STATUS_IS_OK(status)) {
     106           0 :                 DEBUG(1,("WARNING: odb_get_file_infos: %s\n", nt_errstr(status)));
     107           0 :                 return status;
     108             :         }
     109             : 
     110      361230 :         if (!null_time(write_time)) {
     111       18412 :                 name->dos.write_time = write_time;
     112             :         }
     113             : 
     114      361230 :         return NT_STATUS_OK;
     115             : }
     116             : 
     117             : 
     118             : /*
     119             :   return a set of unix file permissions for a new file or directory
     120             : */
     121      105918 : mode_t pvfs_fileperms(struct pvfs_state *pvfs, uint32_t attrib)
     122             : {
     123      105918 :         mode_t mode = (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH);
     124             : 
     125      105918 :         if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE) &&
     126           0 :             (attrib & FILE_ATTRIBUTE_READONLY)) {
     127           0 :                 mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
     128             :         }
     129             : 
     130      105918 :         if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
     131           0 :                 if ((attrib & FILE_ATTRIBUTE_ARCHIVE) &&
     132           0 :                     (pvfs->flags & PVFS_FLAG_MAP_ARCHIVE)) {
     133           0 :                         mode |= S_IXUSR;
     134             :                 }
     135           0 :                 if ((attrib & FILE_ATTRIBUTE_SYSTEM) &&
     136           0 :                     (pvfs->flags & PVFS_FLAG_MAP_SYSTEM)) {
     137           0 :                         mode |= S_IXGRP;
     138             :                 }
     139           0 :                 if ((attrib & FILE_ATTRIBUTE_HIDDEN) &&
     140           0 :                     (pvfs->flags & PVFS_FLAG_MAP_HIDDEN)) {
     141           0 :                         mode |= S_IXOTH;
     142             :                 }
     143             :         }
     144             : 
     145      105918 :         if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
     146        7256 :                 mode |= (S_IFDIR | S_IWUSR);
     147        7256 :                 mode |= (S_IXUSR | S_IXGRP | S_IXOTH);                 
     148        7256 :                 mode &= pvfs->options.dir_mask;
     149        7256 :                 mode |= pvfs->options.force_dir_mode;
     150             :         } else {
     151       98662 :                 mode &= pvfs->options.create_mask;
     152       98662 :                 mode |= pvfs->options.force_create_mode;
     153             :         }
     154             : 
     155      105918 :         return mode;
     156             : }
     157             : 
     158             : 

Generated by: LCOV version 1.14