Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add POSIX setgid/setuid/sticky bit support #59

Merged
merged 3 commits into from
Oct 16, 2023

Conversation

rye
Copy link
Contributor

@rye rye commented Oct 15, 2023

ISSUE #58 - Add POSIX setgid/setuid/sticky bit support

Fixes #58

Description

  • Here, I adjust the POSIX_LS_RE to account for s, S, t, and T in the "pex"-y positions, by adding them to the set of characters we scan for 9 of. Now, the following characters are included in the scan:

    -rwxsStT, where previously only -rwxs were supported. Off-hand, it appears the s was an attempt to support setuid/setgid, but it did not cover the case where the x bit is not set, which renders as a S.

    Because this regex did not previously validate for the correct ordering (i.e., refuting strange combos like rxw), I did not add them in this PR.

  • The pex parsing closure, which does some simple arithmetic to determine the "pex" value, needed some updates.

    S and T indicate the presence of a setuid/setgid bit, or a sticky bit, but without x. (If x is set, then the S instead is typically reported as s.)

    So, I added S and T as exceptions in addition to -. They will be treated the same. With this change, no information is recorded about the setuid/setgid bits, and I don't think the interpretation of them is of great importance at this time given they are interpreted locally by the operating system and they have different meanings.

Type of change

Please select relevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the contribution guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I formatted the code with cargo fmt
  • I linted my code using cargo clippy and reports no warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have introduced no C-bindings
  • I increased or maintained the code coverage for the project, compared to the previous commit

Acceptance tests

wait for a project maintainer to fulfill this section...

  • regression test: ...

As written, the regex that matches on POSIX directory listings misses
some cases that can appear, especially on more complex systems.  These
are cases where the set-user-ID on execution, set-group-ID on execution,
and saved-text (aka setuid, setgid, and "sticky" bits respectively) are
set, typically by a system administrator.

These are quite consistently represented by 's' and 't' in place of the
eXecute bit, and the uppercase alternatives ('S' and 'T') if the eXecute
bit is not set, but the corresponding setuid/setgid/sticky bit is set.

Given that the extant regex does not attempt to validate the ordering
(i.e., xwrxwrxwr is entirely valid), I chose to simply extend the set of
valid values that are accepted in the string of 9 characters following
the initial -/l/d part.

Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
Lowercase s and lowercase t indicate the presence of a setuid/setgid or
sticky bit (respectively), when the execute bit is also present. Their
uppercase counterparts indicate the presence of the bit but not the
execute bit.

Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
Copy link
Owner

@veeso veeso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks!

@veeso veeso merged commit 1e9cf06 into veeso:main Oct 16, 2023
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - POSIX setgid/setuid/sticky bits not supported
2 participants