Skip to content

Commit

Permalink
configure.ac, contrib/, src/: Remove dead code
Browse files Browse the repository at this point in the history
Both glibc and musl provide getusershell(3).  It's an API from 4.3BSD,
according to the manual page, so let's assume it exists everywhere that
we would care, even if it's not in POSIX.

Reported-by: Chris Hofstaedtler <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>

f
  • Loading branch information
alejandro-colomar committed Feb 24, 2025
1 parent 22f49d8 commit 4bb6df2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dnl shadow now uses the libc's shadow implementation
AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])

AC_CHECK_FUNCS(arc4random_buf futimes \
getentropy getrandom getusershell \
getentropy getrandom \
lckpwdf lutimes \
updwtmpx innetgr \
getspnam_r \
Expand Down
5 changes: 2 additions & 3 deletions contrib/adduser.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
#define EXPIRE_VALS_SET /* If defined, 'normal' users can't change
* password expiry values (if running suid root) */

#define HAVE_GETUSERSHELL /* FIXME: Isn't this defined in config.h too? */
#define LOGGING /* If we want to log various things to syslog */
#define MAX_USRNAME 8 /* Longer usernames seem to work on my system....
* But they're probably a poor idea */
Expand Down Expand Up @@ -314,13 +313,13 @@ main (void)
{
char *sh;
int ok = 0;
#ifdef HAVE_GETUSERSHELL

setusershell ();
while ((sh = getusershell ()) != NULL)
if (streq(shell, sh))
ok = 1;
endusershell ();
#endif

if (!ok)
{
if (getuid () == 0)
Expand Down
26 changes: 1 addition & 25 deletions src/chsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ static bool shell_is_listed (const char *sh)
static bool shell_is_listed (const char *sh)
{
bool found = false;

#ifdef HAVE_GETUSERSHELL
char *cp;

setusershell ();
while ((cp = getusershell ())) {
if (streq(cp, sh)) {
Expand All @@ -207,30 +206,7 @@ static bool shell_is_listed (const char *sh)
}
}
endusershell ();
#else
char *buf = NULL;
FILE *fp;
size_t n = 0;

fp = fopen (SHELLS_FILE, "r");
if (NULL == fp) {
return false;
}

while (getline (&buf, &n, fp) != -1) {
if (buf[0] != '/') {
continue;
}

if (streq(buf, sh)) {
found = true;
break;
}
}

free(buf);
fclose (fp);
#endif
return found;
}
#endif /* with HAVE_VENDORDIR */
Expand Down

0 comments on commit 4bb6df2

Please sign in to comment.