-
Notifications
You must be signed in to change notification settings - Fork 254
src/newgrp.c: sg(1): Various source code improvements and bug fixes #1461
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
Open
alejandro-colomar
wants to merge
22
commits into
shadow-maint:master
Choose a base branch
from
alejandro-colomar:sg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This way, the code is better self-documented, in the way that '-c' is pretty much independent of the actual command, except that if it is specified, a command is required, but is otherwise skipped when parsing the command line. It also reduces indentation, which is another way of saying it reduces complexity of the code and thus improves readability. Signed-off-by: Alejandro Colomar <[email protected]>
It does the same, and avoids having to update both argc and argv, which is prone to mistakes. Unname 'argc' to avoid diagnostics about the unused argument. Signed-off-by: Alejandro Colomar <[email protected]>
This makes the code more readable, by more closely matching its documentation. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Both sg(1) and newgrp(1) reject any flags after the optional '-l'/'-'. Do the check once in the common path. Also, remove some comments that are getting less correct. BTW, in one path we were doing the check with manual byte operations, and in the other with strprefix(). Let's unify with neither of them; strspn(3) is standard, and better (it allows multi-character search in a single call, which we need elsewhere, which is why I'll unify the entire project with strspn(3) in a future commit). Also BTW, in the case of sg(1), we were exiting early, without 'goto failure;'. I presume that was an accident. The only difference is the audit code, which I don't see a reason to skip. Signed-off-by: Alejandro Colomar <[email protected]>
…mand This will allow some deduplication of code in a following commit. Signed-off-by: Alejandro Colomar <[email protected]>
Both sg(1) and newgrp(1) handle the group name in the same way if it exists. They differ in how they handle the absence of it. Reflect that in the source code. Use a block to avoid changing the indentation. This will make the diff easier to review. A future patch will clean up the indentation. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This comment has several incorrections: - '-l'/'-' is now exclusive of newgrp(1); it works in sg(1) too. - The group name is mandatory in sg(1). - 'Any remaining arguments' are not used to execute a command. Only the first one is used, and everything else was silently being ignored, until in last commit I made it fail hard. Signed-off-by: Alejandro Colomar <[email protected]>
Everywhere else we were failing that way. I don't see any reason to avoid the audit code here. It probably was a mistake. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Also, align the arguments more consistently with the call above. Fixes: 8dfe21f (2025-03-03; "src/: update group audit messages") Signed-off-by: Alejandro Colomar <[email protected]>
Use 'goto failure;', as we forgot to closelog(3). Also, as always, remove the redundant nearby comment. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
The usage() function already documents the syntax. Let's keep a single source of truth. Signed-off-by: Alejandro Colomar <[email protected]>
0e4f97b to
e4266db
Compare
This is for consistency with su(1). Reported-by: Tobias Stoeckmann <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
is_valid_group_name() already fails if the name starts with '-'. This changes the diagnostic message, but other than that it's fine. Let's prefer the simpler code. Reported-by: Tobias Stoeckmann <[email protected]> Suggested-by: Tobias Stoeckmann <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cc: @stoeckmann , @ikerexxe
Revisions:
v2
argc.v3
-land-in the same command, for consistency with su(1). [@stoeckmann ]