Skip to content

UnixMode on files and directories does not display the SUID/SGID bit when execute is not set and the S is uppercase #20278

@coderjoe

Description

@coderjoe

Prerequisites

Steps to reproduce

I am experiencing a problem with the UnixMode parameter when dealing with suid/sgid bits.
It does not appear to properly display the S flag.

The UnixFileMode parameter, on the other hand, does properly identify SetGroup as being set.

Starting everything with a directory with mode u=rwx,g=rw,o=rx and everything works as expected.
But if we add the sgid flag UnixFileMode works as expected, but UnixMode does not output the S (see the actual below)
If we finally add the execute bit to the directory, then both UnixFileMode and UnixMode operate as expected and the s is output

PS /tmp> chmod g+x /tmp/bugexample/
PS /tmp> ls -alhd /tmp/bugexample
drwxrwsr-x 2 root root 4.0K Sep 14 16:50 /tmp/bugexample
PS /tmp> (Get-Item /tmp/bugexample/).UnixFileMode
OtherExecute, OtherRead, GroupExecute, GroupWrite, GroupRead, UserExecute, UserWrite, UserRead, SetGroup
PS /tmp> (Get-Item /tmp/bugexample/).UnixMode
drwxrwsr-x

I would prefer either

  1. That UnixMode output the uppercase S if suid/sgid is set but the file is not executable
  2. It is made clear that special bits are not displayed in UnixMode and that UnixFileMode should be used instead.

Expected behavior

PS /tmp> mkdir /tmp/testsgid
PS /tmp> chmod u=rwx,g=rw /tmp/testsgid
PS /tmp> chmod g+s /tmp/testsgid
PS /tmp> ls -alhd /tmp/testsgid/
drwxrwSr-x 2 root root 4.0K Sep 14 17:10 /tmp/testsgid/
PS /tmp> (Get-Item /tmp/testsgid/).UnixFileMode
OtherExecute, OtherRead, GroupWrite, GroupRead, UserExecute, UserWrite, UserRead, SetGroup
PS /tmp> (Get-Item /tmp/testsgid/).UnixMode
drwxrwSr-x

Actual behavior

PS /tmp> mkdir /tmp/testsgid
PS /tmp> chmod u=rwx,g=rw /tmp/testsgid
PS /tmp> chmod g+s /tmp/testsgid
PS /tmp> ls -alhd /tmp/testsgid/
drwxrwSr-x 2 root root 4.0K Sep 14 17:10 /tmp/testsgid/
PS /tmp> (Get-Item /tmp/testsgid/).UnixFileMode
OtherExecute, OtherRead, GroupWrite, GroupRead, UserExecute, UserWrite, UserRead, SetGroup
PS /tmp> (Get-Item /tmp/testsgid/).UnixMode
drwxrw-r-x

Error details

No response

Environment data

PS /tmp> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Linux 5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productWG-Interactive-Consolethe console experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions