openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libpam/1.3.1-r0/Linux-PAM-1.3.1/modules/pam_access/pam_access.c
static int network_netmask_match(pam_handle_t* pamh, const char* tok,
                                 const char* string, struct login_info* item)
{
    char* netmask_ptr;
    char netmask_string[MAXHOSTNAMELEN + 1];
    int addr_type;

    if (item->debug)
        pam_syslog(pamh, LOG_DEBUG, "network_netmask_match: tok=%s, item=%s",
                   tok, string);
    /* OK, check if tok is of type addr/mask */
    if ((netmask_ptr = strchr(tok, '/')) != NULL)
    {
        long netmask = 0;

        /* YES */
        *netmask_ptr = 0;
        netmask_ptr++;

        if (isipaddr(tok, &addr_type, NULL) == NO)
        { /* no netaddr */
            return NO;
        }

        /* check netmask */
        if (isipaddr(netmask_ptr, NULL, NULL) == NO)
        { /* netmask as integre value */
            char* endptr = NULL;
            netmask = strtol(netmask_ptr, &endptr, 0);
            if ((endptr == netmask_ptr) || (*endptr != '\0'))
            { /* invalid netmask value */
                return NO;
            }
            if ((netmask < 0) || (netmask >= 128))
            { /* netmask value out of range */
                return NO;
            }

            netmask_ptr = number_to_netmask(netmask, addr_type, netmask_string,
                                            MAXHOSTNAMELEN);
        }
    }
    else
        /* NO, then check if it is only an addr */
        if (isipaddr(tok, NULL, NULL) != YES)
    {
        return NO;
    }

    if (isipaddr(string, NULL, NULL) != YES)
    {
        /* Assume network/netmask with a name of a host.  */
        struct addrinfo hint;

        memset(&hint, '\0', sizeof(hint));
        hint.ai_flags = AI_CANONNAME;
        hint.ai_family = AF_UNSPEC;

        if (item->gai_rv != 0)
            return NO;
        else if (!item->res && (item->gai_rv = getaddrinfo(string, NULL, &hint,
                                                           &item->res)) != 0)
            return NO;
        else
        {
            struct addrinfo* runp = item->res;

            while (runp != NULL)
            {
                char buf[INET6_ADDRSTRLEN];

                inet_ntop(
                    runp->ai_family,
                    runp->ai_family == AF_INET
                        ? (void*)&((struct sockaddr_in*)runp->ai_addr)->sin_addr
                        : (void*)&((struct sockaddr_in6*)runp->ai_addr)
                              ->sin6_addr,
                    buf, sizeof(buf));

                if (are_addresses_equal(buf, tok, netmask_ptr))
                {
                    return YES;
                }
                runp = runp->ai_next;
            }
        }
    }
    else
        return (are_addresses_equal(string, tok, netmask_ptr));

    return NO;
}
/* network_netmask_match - match a string against one token
 * where string is a hostname or ip (v4,v6) address and tok
 * represents either a single ip (v4,v6) address or a network/netmask
 */
match a string against one token
where string is a hostname or ip (v4,v6) address and tok
represents either a single ip (v4,v6) address or a network/netmask
match a string against one token where string is a hostname or ip ( v4 v6 ) address and tok represents either a single ip ( v4 v6 ) address or a network / netmask
static int network_netmask_match(pam_handle_t* pamh, const char* tok,
                                 const char* string, struct login_info* item)
{
    char* netmask_ptr;
    char netmask_string[MAXHOSTNAMELEN + 1];
    int addr_type;
    if (item->debug)
        pam_syslog(pamh, LOG_DEBUG, "network_netmask_match: tok=%s, item=%s",
                   tok, string);
    if ((netmask_ptr = strchr(tok, '/')) != NULL)
    {
        long netmask = 0;
        *netmask_ptr = 0;
        netmask_ptr++;
        if (isipaddr(tok, &addr_type, NULL) == NO)
        { 
            return NO;
        }
        if (isipaddr(netmask_ptr, NULL, NULL) == NO)
        { 
            char* endptr = NULL;
            netmask = strtol(netmask_ptr, &endptr, 0);
            if ((endptr == netmask_ptr) || (*endptr != '\0'))
            { 
                return NO;
            }
            if ((netmask < 0) || (netmask >= 128))
            { 
                return NO;
            }
            netmask_ptr = number_to_netmask(netmask, addr_type, netmask_string,
                                            MAXHOSTNAMELEN);
        }
    }
    else
        if (isipaddr(tok, NULL, NULL) != YES)
    {
        return NO;
    }
    if (isipaddr(string, NULL, NULL) != YES)
    {
        struct addrinfo hint;
        memset(&hint, '\0', sizeof(hint));
        hint.ai_flags = AI_CANONNAME;
        hint.ai_family = AF_UNSPEC;
        if (item->gai_rv != 0)
            return NO;
        else if (!item->res && (item->gai_rv = getaddrinfo(string, NULL, &hint,
                                                           &item->res)) != 0)
            return NO;
        else
        {
            struct addrinfo* runp = item->res;
            while (runp != NULL)
            {
                char buf[INET6_ADDRSTRLEN];
                inet_ntop(
                    runp->ai_family,
                    runp->ai_family == AF_INET
                        ? (void*)&((struct sockaddr_in*)runp->ai_addr)->sin_addr
                        : (void*)&((struct sockaddr_in6*)runp->ai_addr)
                              ->sin6_addr,
                    buf, sizeof(buf));
                if (are_addresses_equal(buf, tok, netmask_ptr))
                {
                    return YES;
                }
                runp = runp->ai_next;
            }
        }
    }
    else
        return (are_addresses_equal(string, tok, netmask_ptr));
    return NO;
}
static int network_netmask_match ( pam_handle_t * pamh , const char * tok , const char * string , struct login_info * item ) { char * netmask_ptr ; char netmask_string [ MAXHOSTNAMELEN + 1 ] ; int addr_type ; if ( item -> debug ) pam_syslog ( pamh , LOG_DEBUG , " " , tok , string ) ; if ( ( netmask_ptr = strchr ( tok , ' ' ) ) != NULL ) { long netmask = 0 ; * netmask_ptr = 0 ; netmask_ptr ++ ; if ( isipaddr ( tok , & addr_type , NULL ) == NO ) { return NO ; } if ( isipaddr ( netmask_ptr , NULL , NULL ) == NO ) { char * endptr = NULL ; netmask = strtol ( netmask_ptr , & endptr , 0 ) ; if ( ( endptr == netmask_ptr ) || ( * endptr != ' \0 ' ) ) { return NO ; } if ( ( netmask < 0 ) || ( netmask >= 128 ) ) { return NO ; } netmask_ptr = number_to_netmask ( netmask , addr_type , netmask_string , MAXHOSTNAMELEN ) ; } } else if ( isipaddr ( tok , NULL , NULL ) != YES ) { return NO ; } if ( isipaddr ( string , NULL , NULL ) != YES ) { struct addrinfo hint ; memset ( & hint , ' \0 ' , sizeof ( hint ) ) ; hint . ai_flags = AI_CANONNAME ; hint . ai_family = AF_UNSPEC ; if ( item -> gai_rv != 0 ) return NO ; else if ( ! item -> res && ( item -> gai_rv = getaddrinfo ( string , NULL , & hint , & item -> res ) ) != 0 ) return NO ; else { struct addrinfo * runp = item -> res ; while ( runp != NULL ) { char buf [ INET6_ADDRSTRLEN ] ; inet_ntop ( runp -> ai_family , runp -> ai_family == AF_INET ? ( void * ) & ( ( struct sockaddr_in * ) runp -> ai_addr ) -> sin_addr : ( void * ) & ( ( struct sockaddr_in6 * ) runp -> ai_addr ) -> sin6_addr , buf , sizeof ( buf ) ) ; if ( are_addresses_equal ( buf , tok , netmask_ptr ) ) { return YES ; } runp = runp -> ai_next ; } } } else return ( are_addresses_equal ( string , tok , netmask_ptr ) ) ; return NO ; }
network_netmask_match - match a string against one token
 where string is a hostname or ip (v4,v6) address and tok
 represents either a single ip (v4,v6) address or a network/netmask
network_netmask_match - match a string against one token where string is a hostname or ip ( v4 v6 ) address and tok represents either a single ip ( v4 v6 ) address or a network / netmask
/* OK, check if tok is of type addr/mask */ /* YES */ /* no netaddr */ /* check netmask */ /* netmask as integre value */ /* invalid netmask value */ /* netmask value out of range */ /* NO, then check if it is only an addr */ /* Assume network/netmask with a name of a host.  */