logo

skeud

Simple and portable utilities to deal with user accounts (su, login)
commit: ef20f83ba2ab372efadde76b116d262fc573d0ca
parent 95b80fffe91cf37a48ec064efad5910e41d0d30e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  9 Oct 2022 04:08:39 +0200

login: Add support for standalone username argument

Diffstat:

Mlogin.c40+++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/login.c b/login.c @@ -66,15 +66,29 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - (void)argv; - if((opt_f && argc > 0) || (argc > 1)) + if(!opt_f) { - fprintf(stderr, "login: Too many arguments given.\n"); - return 1; + if(argc == 1) + { + username = argv[0]; + } + else if(argc > 1) + { + fprintf(stderr, "login: Too many arguments given.\n"); + return 1; + } + } + else + { + if(argc > 0) + { + fprintf(stderr, "login: Too many arguments given.\n"); + return 1; + } } - if((username == NULL) && (argc == 0)) + if(username == NULL) { size_t len = 0; @@ -90,15 +104,13 @@ main(int argc, char *argv[]) username[got - 1] = 0; } - if(username != NULL) - { - errno = 0; - pwent = getpwnam(username); + assert(username != NULL); - if(errno != 0) - { - perror("getpwnam"); - } + errno = 0; + pwent = getpwnam(username); + if(errno != 0) + { + perror("getpwnam"); } if(!opt_f) @@ -153,8 +165,6 @@ main(int argc, char *argv[]) if(pwent != NULL) { - assert(username != NULL); - if(setgid(pwent->pw_gid) < 0) { perror("setgid");