openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/shadow/4.6-r0/shadow-4.6/src/chsh.c
static bool shell_is_listed(const char* sh)
{
    char* cp;
    bool found = false;

#ifndef HAVE_GETUSERSHELL
    char buf[BUFSIZ];
    FILE* fp;
#endif

#ifdef HAVE_GETUSERSHELL
    setusershell();
    while ((cp = getusershell()))
    {
        if (strcmp(cp, sh) == 0)
        {
            found = true;
            break;
        }
    }
    endusershell();
#else
    fp = fopen(SHELLS_FILE, "r");
    if (NULL == fp)
    {
        return false;
    }

    while (fgets(buf, sizeof(buf), fp) == buf)
    {
        cp = strrchr(buf, '\n');
        if (NULL != cp)
        {
            *cp = '\0';
        }

        if (buf[0] == '#')
        {
            continue;
        }

        if (strcmp(buf, sh) == 0)
        {
            found = true;
            break;
        }
    }
    fclose(fp);
#endif
    return found;
}
/*
 * shell_is_listed - see if the user's login shell is listed in /etc/shells
 *
 * The /etc/shells file is read for valid names of login shells.  If the
 * /etc/shells file does not exist the user cannot set any shell unless
 * they are root.
 *
 * If getusershell() is available (Linux, *BSD, possibly others), use it
 * instead of re-implementing it.
 */
see if the user's login shell is listed in /etc/shells
The /etc/shells file is read for valid names of login shells.  If the
/etc/shells file does not exist the user cannot set any shell unless
they are root.

If getusershell() is available (Linux, *BSD, possibly others), use it
instead of re-implementing it.
see if the user ' s login shell is listed in / etc / shells The / etc / shells file is read for valid names of login shells . If the / etc / shells file does not exist the user cannot set any shell unless they are root . If getusershell () is available ( Linux * BSD possibly others ) use it instead of re - implementing it .
static bool shell_is_listed(const char* sh)
{
    char* cp;
    bool found = false;
#ifndef HAVE_GETUSERSHELL
    char buf[BUFSIZ];
    FILE* fp;
#endif
#ifdef HAVE_GETUSERSHELL
    setusershell();
    while ((cp = getusershell()))
    {
        if (strcmp(cp, sh) == 0)
        {
            found = true;
            break;
        }
    }
    endusershell();
#else
    fp = fopen(SHELLS_FILE, "r");
    if (NULL == fp)
    {
        return false;
    }
    while (fgets(buf, sizeof(buf), fp) == buf)
    {
        cp = strrchr(buf, '\n');
        if (NULL != cp)
        {
            *cp = '\0';
        }
        if (buf[0] == '#')
        {
            continue;
        }
        if (strcmp(buf, sh) == 0)
        {
            found = true;
            break;
        }
    }
    fclose(fp);
#endif
    return found;
}
static bool shell_is_listed ( const char * sh ) { char * cp ; bool found = false ; #ifndef HAVE_GETUSERSHELL char buf [ BUFSIZ ] ; FILE * fp ; #endif #ifdef HAVE_GETUSERSHELL setusershell ( ) ; while ( ( cp = getusershell ( ) ) ) { if ( strcmp ( cp , sh ) == 0 ) { found = true ; break ; } } endusershell ( ) ; #else fp = fopen ( SHELLS_FILE , " " ) ; if ( NULL == fp ) { return false ; } while ( fgets ( buf , sizeof ( buf ) , fp ) == buf ) { cp = strrchr ( buf , ' \n ' ) ; if ( NULL != cp ) { * cp = ' \0 ' ; } if ( buf [ 0 ] == ' ' ) { continue ; } if ( strcmp ( buf , sh ) == 0 ) { found = true ; break ; } } fclose ( fp ) ; #endif return found ; }
shell_is_listed - see if the user's login shell is listed in /etc/shells
 The /etc/shells file is read for valid names of login shells.
shell_is_listed - see if the user ' s login shell is listed in / etc / shells The / etc / shells file is read for valid names of login shells .