Re: [hackers] [ubase][PATCH 1/4] su: simplify logic

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Thu, 7 Mar 2024 19:19:36 +0100

Hi,

On Thu, Mar 07, 2024 at 02:18:28AM -0500, neeshy wrote:
> It seems that the modifications you made break the use case where su is
> called without a username. It would normally default to the root
> user, but now it invokes usage() instead. My original patch worked as
> intended. Could you rebase using the original patch instead? Thank you.
>

Sadly, I cannot rebase it as it is already in the central repository.
What do you think about adding a new change like this:


diff --git a/su.c b/su.c
index eb8bea7..8eea82b 100644
--- a/su.c
+++ b/su.c
_AT_@ -26,7 +26,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- char *usr = "root", *pass;
+ char *usr, *pass;
         char *shell, *envshell, *term;
         struct passwd *pw;
         char *newargv[3];
_AT_@ -43,9 +43,14 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if (argc != 1)
+ if (argc > 1)
                 usage();
- usr = argv[0];
+ usr = argc > 0 ? argv[0] : "root";
 
         errno = 0;
         pw = getpwnam(usr);

I think it makes it simpler while keeping the correct behaviour that I broke.

Kind Regards,
Roberto Vargas
Received on Thu Mar 07 2024 - 19:19:36 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 07 2024 - 19:24:36 CET