src/newgrp.c: sg(1): Various source code improvements and bug fixes#1461
Open
alejandro-colomar wants to merge 22 commits intoshadow-maint:masterfrom
Open
src/newgrp.c: sg(1): Various source code improvements and bug fixes#1461alejandro-colomar wants to merge 22 commits intoshadow-maint:masterfrom
alejandro-colomar wants to merge 22 commits intoshadow-maint:masterfrom
Conversation
0e4f97b to
e4266db
Compare
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
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 <alx@kernel.org>
This makes the code more readable, by more closely matching its documentation. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
…mand This will allow some deduplication of code in a following commit. Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
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 <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
Use 'goto failure;', as we forgot to closelog(3). Also, as always, remove the redundant nearby comment. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
The usage() function already documents the syntax. Let's keep a single source of truth. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is for consistency with su(1). Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <tobias@stoeckmann.org> Suggested-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
df3bb4c to
9faab47
Compare
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
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 ]v3b