View Issue Details

IDProjectCategoryView StatusLast Update
0000503Far ManagerSetAttrpublic2009-12-04 19:18
ReporteralexmitinAssigned Toalexy 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionunable to reproduce 
Product Version 
Target VersionFixed in Version 
Summary0000503: Access denied error while setting the file attributes
DescriptionProblem
----------------
There is an access denied error while setting the file attributes.


Steps to reproduce:
-----------------------
1) Create a file c:\111\myfile.txt and assign the following permissions to it:
  
   Administrators: Full Control
   User: Read Attributes, Write Attributes

2) Start FAR under limited user account (not administrator)
3) Presss Ctrl+A on the c:\111\myfile.txt
4) Set the following attributes:

   [x] Read only
   [x] Archive
   [x] Hidden
   [x] System
   [ ] Compressed
   [ ] Encrypted
   [x] Not Indexed
   File modification time: current time
   File modification time: current time
   File modification time: current time

5) Press "Set"


Actual result
----------------------
Error: "Access denied. Cannot set attributes for 111.txt"


Expected result
----------------------
The file attributes are set according to specification on step 4.


Same problem exists for changing folder attributes. Just repeat steps 1 to 5 for folder instead of file.


Analysis
=========================
File: setattr.cpp

int ShellSetFileAttributes(Panel *SrcPanel)
{
...
    if (SelCount==1 && (FileAttr & FA_DIREC)==0)
    {
      if(IsFileWritable(strSelName,FileAttr,TRUE,MSetAttrCannotFor) == 1) <==[bug.1]==
      {
...
  if (CheckForEsc())
    break;

  RetCode=IsFileWritable(strSelName,FileAttr,TRUE,MSetAttrCannotFor); <==[bug.1]==
  if(!RetCode)
    break;
...
}

[bug.1] The function IsFileWritable() should not be called while setting the attributes. Using this function prevents the rest of the code to function correctly.

------------------
File: setattr.cpp

static int ReadFileTime(
   int Type,
   const wchar_t *Name,
   DWORD FileAttr,
   FILETIME *FileTime,
   const wchar_t *OSrcDate,
   const wchar_t *OSrcTime
)
{
...
  HANDLE hFile= apiCreateFile(
    Name,
    GENERIC_READ, <==[bug.2]== should be FILE_READ_ATTRIBUTES
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    (FileAttr & FA_DIREC) ? FILE_FLAG_BACKUP_SEMANTICS : 0,
    NULL
  );
  if (hFile==INVALID_HANDLE_VALUE)
      return(FALSE);
...
}

[bug.2] The access right should be FILE_READ_ATTRIBUTES, not GENERIC_READ because we just need to get file times (via GetFileTime).


------------------
File: fileattr.cpp

int ESetFileTime(
  const wchar_t *Name,
  FILETIME *LastWriteTime,
  FILETIME *CreationTime,
  FILETIME *LastAccessTime,
  int FileAttr <==[bug.3]==
)
{
...
  HANDLE hFile=apiCreateFile(
    Name,
    GENERIC_WRITE, // <==[bug.4]== should be FILE_WRITE_ATTRIBUTES
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    (FileAttr & FA_DIREC) ? FILE_FLAG_BACKUP_SEMANTICS : 0,
    NULL
  );
...
  SetTime = SetFileTime(hFile,CreationTime,LastAccessTime,LastWriteTime);
...
}

[bug.3] The type of the FileAttr parameter should be DWORD (not int).

[bug.4] The access right should be FILE_WRITE_ATTRIBUTES, not GENERIC_WRITE because we need to update file times (via SetFileTime).

See http://msdn2.microsoft.com/en-us/library/aa364399(VS.85).aspx the definition of FILE_WRITE_ATTRIBUTES and GENERIC_WRITE.

-----------
int ESetFileAttributes(const wchar_t *Name,int Attr) <==[bug.5]==
{
...
}

[bug.5] The type of the Attr parameter should be DWORD (not int).

-----------

int ESetFileEncryption(const wchar_t *Name,int State,int FileAttr,int Silent) <==[bug.6]==
{
...
}

[bug.6] The type of the FileAttr parameter should be DWORD (not int).
Additional InformationFAR 1.80.0.452
TagsNo tags attached.
Build0

Activities

2008-03-20 04:33

 

fix503.diff (29,017 bytes)
fix503.diff (29,017 bytes)

alexmitin

2008-03-20 18:37

reporter   bugnote:0001392

See 0000504:0001389 in the 0000504 about the place where to set the initial permissions for the user account to test with.

alexmitin

2009-12-04 18:36

reporter   bugnote:0004671

FAR 2.0 Build 1263.

The issue is not reproducable.

Issue History

Date Modified Username Field Change
2008-03-20 03:10 alexmitin New Issue
2008-03-20 04:33 alexmitin File Added: fix503.diff
2008-03-20 18:37 alexmitin Note Added: 0001392
2009-12-04 18:36 alexmitin Note Added: 0004671
2009-12-04 18:36 alexmitin Status new => resolved
2009-12-04 19:18 alexy Build => 0
2009-12-04 19:18 alexy Status resolved => closed
2009-12-04 19:18 alexy Resolution open => unable to reproduce
2009-12-04 19:18 alexy Assigned To => alexy