openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/shadow/4.6-r0/shadow-4.6/libmisc/prefix_flag.c
extern const char* process_prefix_flag(const char* short_opt, int argc,
                                       char** argv)
{
    /*
     * Parse the command line options.
     */
    int i;
    const char* prefix = NULL;

    for (i = 0; i < argc; i++)
    {
        if ((strcmp(argv[i], "--prefix") == 0) ||
            (strcmp(argv[i], short_opt) == 0))
        {
            if (NULL != prefix)
            {
                fprintf(stderr, _("%s: multiple --prefix options\n"), Prog);
                exit(E_BAD_ARG);
            }

            if (i + 1 == argc)
            {
                fprintf(stderr, _("%s: option '%s' requires an argument\n"),
                        Prog, argv[i]);
                exit(E_BAD_ARG);
            }
            prefix = argv[i + 1];
        }
    }

    if (prefix != NULL)
    {
        if (prefix[0] == '\0' || !strcmp(prefix, "/"))
            return ""; /* if prefix is "/" then we ignore the flag option */
        /* should we prevent symbolic link from being used as a prefix? */

        size_t len;
        len = strlen(prefix) + strlen(PASSWD_FILE) + 2;
        passwd_db_file = xmalloc(len);
        snprintf(passwd_db_file, len, "%s/%s", prefix, PASSWD_FILE);
        pw_setdbname(passwd_db_file);

        len = strlen(prefix) + strlen(GROUP_FILE) + 2;
        group_db_file = xmalloc(len);
        snprintf(group_db_file, len, "%s/%s", prefix, GROUP_FILE);
        gr_setdbname(group_db_file);

#ifdef SHADOWGRP
        len = strlen(prefix) + strlen(SGROUP_FILE) + 2;
        sgroup_db_file = xmalloc(len);
        snprintf(sgroup_db_file, len, "%s/%s", prefix, SGROUP_FILE);
        sgr_setdbname(sgroup_db_file);
#endif
#ifdef USE_NIS
        __setspNIS(0); /* disable NIS for now, at least until it is properly
                          supporting a "prefix" */
#endif

        len = strlen(prefix) + strlen(SHADOW_FILE) + 2;
        spw_db_file = xmalloc(len);
        snprintf(spw_db_file, len, "%s/%s", prefix, SHADOW_FILE);
        spw_setdbname(spw_db_file);

        len = strlen(prefix) + strlen("/etc/subuid") + 2;
        suid_db_file = xmalloc(len);
        snprintf(suid_db_file, len, "%s/%s", prefix, "/etc/subuid");
        sub_uid_setdbname(suid_db_file);

        len = strlen(prefix) + strlen("/etc/subgid") + 2;
        sgid_db_file = xmalloc(len);
        snprintf(sgid_db_file, len, "%s/%s", prefix, "/etc/subgid");
        sub_gid_setdbname(sgid_db_file);

        len = strlen(prefix) + strlen("/etc/login.defs") + 2;
        def_conf_file = xmalloc(len);
        snprintf(def_conf_file, len, "%s/%s", prefix, "/etc/login.defs");
        setdef_config_file(def_conf_file);
    }

    if (prefix == NULL)
        return "";
    return prefix;
}
/*
 * process_prefix_flag - prefix all paths if given the --prefix option
 *
 * This shall be called before accessing the passwd, group, shadow,
 * gshadow, useradd's default, login.defs files (non exhaustive list)
 * or authenticating the caller.
 *
 * The audit, syslog, or locale files shall be open before
 */
prefix all paths if given the --prefix option
This shall be called before accessing the passwd, group, shadow,
gshadow, useradd's default, login.defs files (non exhaustive list)
or authenticating the caller.

The audit, syslog, or locale files shall be open before
prefix all paths if given the -- prefix option This shall be called before accessing the passwd group shadow gshadow useradd ' s default login . defs files ( non exhaustive list ) or authenticating the caller . The audit syslog or locale files shall be open before
extern const char* process_prefix_flag(const char* short_opt, int argc,
                                       char** argv)
{
    int i;
    const char* prefix = NULL;
    for (i = 0; i < argc; i++)
    {
        if ((strcmp(argv[i], "--prefix") == 0) ||
            (strcmp(argv[i], short_opt) == 0))
        {
            if (NULL != prefix)
            {
                fprintf(stderr, _("%s: multiple --prefix options\n"), Prog);
                exit(E_BAD_ARG);
            }
            if (i + 1 == argc)
            {
                fprintf(stderr, _("%s: option '%s' requires an argument\n"),
                        Prog, argv[i]);
                exit(E_BAD_ARG);
            }
            prefix = argv[i + 1];
        }
    }
    if (prefix != NULL)
    {
        if (prefix[0] == '\0' || !strcmp(prefix, "/"))
            return ""; 
        size_t len;
        len = strlen(prefix) + strlen(PASSWD_FILE) + 2;
        passwd_db_file = xmalloc(len);
        snprintf(passwd_db_file, len, "%s/%s", prefix, PASSWD_FILE);
        pw_setdbname(passwd_db_file);
        len = strlen(prefix) + strlen(GROUP_FILE) + 2;
        group_db_file = xmalloc(len);
        snprintf(group_db_file, len, "%s/%s", prefix, GROUP_FILE);
        gr_setdbname(group_db_file);
#ifdef SHADOWGRP
        len = strlen(prefix) + strlen(SGROUP_FILE) + 2;
        sgroup_db_file = xmalloc(len);
        snprintf(sgroup_db_file, len, "%s/%s", prefix, SGROUP_FILE);
        sgr_setdbname(sgroup_db_file);
#endif
#ifdef USE_NIS
        __setspNIS(0); 
#endif
        len = strlen(prefix) + strlen(SHADOW_FILE) + 2;
        spw_db_file = xmalloc(len);
        snprintf(spw_db_file, len, "%s/%s", prefix, SHADOW_FILE);
        spw_setdbname(spw_db_file);
        len = strlen(prefix) + strlen("/etc/subuid") + 2;
        suid_db_file = xmalloc(len);
        snprintf(suid_db_file, len, "%s/%s", prefix, "/etc/subuid");
        sub_uid_setdbname(suid_db_file);
        len = strlen(prefix) + strlen("/etc/subgid") + 2;
        sgid_db_file = xmalloc(len);
        snprintf(sgid_db_file, len, "%s/%s", prefix, "/etc/subgid");
        sub_gid_setdbname(sgid_db_file);
        len = strlen(prefix) + strlen("/etc/login.defs") + 2;
        def_conf_file = xmalloc(len);
        snprintf(def_conf_file, len, "%s/%s", prefix, "/etc/login.defs");
        setdef_config_file(def_conf_file);
    }
    if (prefix == NULL)
        return "";
    return prefix;
}
extern const char * process_prefix_flag ( const char * short_opt , int argc , char * * argv ) { int i ; const char * prefix = NULL ; for ( i = 0 ; i < argc ; i ++ ) { if ( ( strcmp ( argv [ i ] , " " ) == 0 ) || ( strcmp ( argv [ i ] , short_opt ) == 0 ) ) { if ( NULL != prefix ) { fprintf ( stderr , _ ( " \n " ) , Prog ) ; exit ( E_BAD_ARG ) ; } if ( i + 1 == argc ) { fprintf ( stderr , _ ( " \n " ) , Prog , argv [ i ] ) ; exit ( E_BAD_ARG ) ; } prefix = argv [ i + 1 ] ; } } if ( prefix != NULL ) { if ( prefix [ 0 ] == ' \0 ' || ! strcmp ( prefix , " " ) ) return " " ; size_t len ; len = strlen ( prefix ) + strlen ( PASSWD_FILE ) + 2 ; passwd_db_file = xmalloc ( len ) ; snprintf ( passwd_db_file , len , " " , prefix , PASSWD_FILE ) ; pw_setdbname ( passwd_db_file ) ; len = strlen ( prefix ) + strlen ( GROUP_FILE ) + 2 ; group_db_file = xmalloc ( len ) ; snprintf ( group_db_file , len , " " , prefix , GROUP_FILE ) ; gr_setdbname ( group_db_file ) ; #ifdef SHADOWGRP len = strlen ( prefix ) + strlen ( SGROUP_FILE ) + 2 ; sgroup_db_file = xmalloc ( len ) ; snprintf ( sgroup_db_file , len , " " , prefix , SGROUP_FILE ) ; sgr_setdbname ( sgroup_db_file ) ; #endif #ifdef USE_NIS __setspNIS ( 0 ) ; #endif len = strlen ( prefix ) + strlen ( SHADOW_FILE ) + 2 ; spw_db_file = xmalloc ( len ) ; snprintf ( spw_db_file , len , " " , prefix , SHADOW_FILE ) ; spw_setdbname ( spw_db_file ) ; len = strlen ( prefix ) + strlen ( " " ) + 2 ; suid_db_file = xmalloc ( len ) ; snprintf ( suid_db_file , len , " " , prefix , " " ) ; sub_uid_setdbname ( suid_db_file ) ; len = strlen ( prefix ) + strlen ( " " ) + 2 ; sgid_db_file = xmalloc ( len ) ; snprintf ( sgid_db_file , len , " " , prefix , " " ) ; sub_gid_setdbname ( sgid_db_file ) ; len = strlen ( prefix ) + strlen ( " " ) + 2 ; def_conf_file = xmalloc ( len ) ; snprintf ( def_conf_file , len , " " , prefix , " " ) ; setdef_config_file ( def_conf_file ) ; } if ( prefix == NULL ) return " " ; return prefix ; }
process_prefix_flag - prefix all paths if given the --prefix option
 This shall be called before accessing the passwd, group, shadow,
 gshadow, useradd's default, login.defs files (non exhaustive list)
 or authenticating the caller.
process_prefix_flag - prefix all paths if given the -- prefix option This shall be called before accessing the passwd group shadow gshadow useradd ' s default login . defs files ( non exhaustive list ) or authenticating the caller .
/*
     * Parse the command line options.
     */ /* if prefix is "/" then we ignore the flag option */ /* should we prevent symbolic link from being used as a prefix? */ /* disable NIS for now, at least until it is properly
                          supporting a "prefix" */