Example #1
0
static bool KNSProxiesHttpProxyInitFromKfg ( KNSProxies * self,
                                             const KConfig * kfg )
{
    bool fromKfg = false;

    const KConfigNode * proxy;
    rc_t rc = KConfigOpenNodeRead ( kfg, & proxy, "/http/proxy" );
    if ( rc == 0 ) {
        const KConfigNode * proxy_path;
        rc = KConfigNodeOpenNodeRead ( proxy, & proxy_path, "path" );
        if ( rc == 0 ) {
            String * path;
            rc = KConfigNodeReadString ( proxy_path, & path );
            if ( rc == 0 ) {
                DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ),
                    ( "Loading proxy '%S' from configuration\n", path ) );
                rc = KNSProxiesAddHTTPProxyPath ( self, "%S", path );
                if ( rc == 0 )
                    fromKfg = true;

                StringWhack ( path );
            }

            KConfigNodeRelease ( proxy_path );
        }

        KConfigNodeRelease ( proxy );
    }

    return fromKfg;
}
Example #2
0
static
bool map_typename ( const ctx_t *ctx, const char *sub_node, const char *in, char *out, char *schema_src, size_t size )
{
    FUNC_ENTRY ( ctx );

    rc_t rc;
    const KConfigNode *n;
    size_t num_read, remaining;

    typename_to_config_path ( in, out );

    rc = KConfigOpenNodeRead ( ctx -> caps -> cfg, & n, "sra-sort/%s/%s", sub_node, out );
    if ( rc != 0 )
        return map_typename_builtin ( ctx, sub_node, in, out, schema_src, size );

    rc = KConfigNodeRead ( n, 0, out, size - 1, & num_read, & remaining );
    if ( rc != 0 )
        ERROR ( rc, "KConfigNodeRead failed" );
    else if ( remaining != 0 )
    {
        rc = RC ( rcExe, rcNode, rcReading, rcBuffer, rcInsufficient );
        ERROR ( rc, "type map of '%s' is too long", in );
    }
    else
    {
        out [ num_read ] = 0;
        typename_to_config_path ( out, schema_src );

        KConfigNodeRelease ( n );
        rc = KConfigOpenNodeRead ( ctx -> caps -> cfg, & n, "sra-sort/schema-src/%s", schema_src );
        if ( rc != 0 )
            ERROR ( rc, "KConfigOpenNodeRead - failed to find entry 'sra-sort/schema-src/%s'", schema_src );
        else
        {
            rc = KConfigNodeRead ( n, 0, schema_src, size - 1, & num_read, & remaining );
            if ( rc != 0 )
                ERROR ( rc, "KConfigNodeRead failed" );
            else if ( remaining != 0 )
            {
                rc = RC ( rcExe, rcNode, rcReading, rcBuffer, rcInsufficient );
                ERROR ( rc, "type map of '%s' is too long", in );
            }
            else
            {
                schema_src [ num_read ] = 0;
            }
        }
    }

    KConfigNodeRelease ( n );
    return true;
}
Example #3
0
/* RemoteRepositories
 *  retrieve all remote repositories in a Vector
 */
LIB_EXPORT rc_t CC KRepositoryMgrRemoteRepositories ( const KRepositoryMgr *self,
    KRepositoryVector *remote_repositories )
{
    rc_t rc;

    if ( remote_repositories == NULL )
        rc = RC ( rcKFG, rcMgr, rcAccessing, rcParam, rcNull );
    else
    {
        VectorInit ( remote_repositories, 0, 8 );

        if ( self == NULL )
            rc = RC ( rcKFG, rcMgr, rcAccessing, rcSelf, rcNull );
        else
        {
            const KConfig *kfg = KRepositoryMgrGetROKConfig ( self );

            const KConfigNode *remote;
            rc = KConfigOpenNodeRead ( kfg, & remote, "/repository/remote" );
            if ( rc == 0 )
            {
                rc = KRepositoryMgrCategoryRepositories ( remote, krepRemoteCategory, remote_repositories );
                KConfigNodeRelease ( remote );
                if ( rc == 0 )
                    VectorReorder ( remote_repositories, KRepositorySort, NULL );
            }

            if ( rc != 0 )
                KRepositoryVectorWhack ( remote_repositories );
        }
    }

    return rc;
}
Example #4
0
/* Whack
 */
static
rc_t KRepositoryWhack ( KRepository *self )
{
    KConfigNodeRelease ( self -> node );
    free ( self );
    return 0;
}
Example #5
0
/* Config
 *  configure an existing path manager
 */
static
rc_t SRAPathConfigValue ( const KConfig *kfg, const char *node_path,
    char *value, size_t value_size, const char *dflt )
{
    const KConfigNode *node;
    rc_t rc = KConfigOpenNodeRead ( kfg, & node, node_path );
    if ( rc == 0 )
    {
        size_t num_read, remaining;
        rc = KConfigNodeRead ( node, 0, value, value_size - 1, & num_read,  & remaining );
        if ( rc == 0 )
        {
            if ( remaining != 0 )
                rc = RC ( rcSRA, rcMgr, rcConstructing, rcString, rcExcessive );
            else
                value [ num_read ] = 0;
        }

        KConfigNodeRelease ( node );
    }

    if ( rc != 0 )
    {
        if ( dflt != NULL && dflt [ 0 ] != 0 )
        {
            size_t num_read = string_copy_measure ( value, value_size, dflt );
            rc = 0;
            if ( num_read == value_size )
                rc = RC ( rcSRA, rcMgr, rcConstructing, rcString, rcExcessive );
        }
        else
	    	value[0] = 0;     
    }
    return rc;
}
Example #6
0
extern
void add_aws_nodes ( KConfig *self )
{
    char home [ 4096 ] = "";

    size_t num_writ;
    char path [ 4096 ];
    rc_t rc;

    check_env ( self, home, sizeof home );
    /* if home environtment is found, create AWS root node */

    if ( home [ 0 ] != 0 )
    {
        rc = string_printf ( path, sizeof path, &num_writ, "%s/.aws", home );
        if ( rc == 0 && num_writ != 0 )
        {
            KConfigNode *aws_node;
            
            /* create aws node */
            rc = KConfigOpenNodeUpdate ( self, &aws_node, "AWS", NULL );
            if ( rc == 0 )
                rc = aws_find_nodes ( aws_node, path );
            
            rc = KConfigNodeRelease ( aws_node );
        }
    }
}
Example #7
0
/* UserRepositories
 *  retrieve all user repositories in a Vector
 */
LIB_EXPORT rc_t CC KRepositoryMgrUserRepositories ( const KRepositoryMgr *self,
    KRepositoryVector *user_repositories )
{
    rc_t rc;

    if ( user_repositories == NULL )
        rc = RC ( rcKFG, rcMgr, rcAccessing, rcParam, rcNull );
    else
    {
        VectorInit ( user_repositories, 0, 8 );

        if ( self == NULL )
            rc = RC ( rcKFG, rcMgr, rcAccessing, rcSelf, rcNull );
        else
        {
            const KConfig *kfg = KRepositoryMgrGetROKConfig ( self );

            const KConfigNode *user;
            rc = KConfigOpenNodeRead ( kfg, & user, "/repository/user" );
            if ( rc == 0 )
            {
                rc = KRepositoryMgrCategoryRepositories ( user, krepUserCategory, user_repositories );
                KConfigNodeRelease ( user );
                if ( rc == 0 )
                    VectorReorder ( user_repositories, KRepositorySort, NULL );
            }

            if ( rc != 0 )
                KRepositoryVectorWhack ( user_repositories );
        }
    }

    return rc;
}
Example #8
0
static
void KNSManagerHttpProxyInit ( KNSManager * self )
{
    const KConfigNode * proxy;
    rc_t rc = KConfigOpenNodeRead ( self -> kfg, & proxy, "http/proxy" );
    if ( rc == 0 )
    {
        const KConfigNode * proxy_path;
        rc = KConfigNodeOpenNodeRead ( proxy, & proxy_path, "path" );
        if ( rc == 0 )
        {
            String * path;
            rc = KConfigNodeReadString ( proxy_path, & path );
            if ( rc == 0 )
            {
                rc = KNSManagerSetHTTPProxyPath ( self, "%S", path );
                if ( rc == 0 )
                {
                    const KConfigNode * proxy_enabled;
                    rc = KConfigNodeOpenNodeRead ( proxy, & proxy_enabled, "enabled" );
                    if ( rc == 0 )
                    {
                        rc = KConfigNodeReadBool ( proxy_enabled, & self -> http_proxy_enabled );
                        KConfigNodeRelease ( proxy_enabled );
                    }
                    else if ( GetRCState ( rc ) == rcNotFound )
                    {
                        rc = 0;
                    }

                    if ( rc != 0 )
                    {
                        KNSManagerSetHTTPProxyPath ( self, NULL );
                        assert ( self -> http_proxy_enabled == false );
                    }
                }

                StringWhack ( path );
            }

            KConfigNodeRelease ( proxy_path );
        }

        KConfigNodeRelease ( proxy );
    }
}
Example #9
0
static
rc_t ConfigRepoSet(DLList* repos, KConfig * kfg, const char* kfgPath, const char *dflt, uint8_t type)
{
    const KConfigNode *node;

    rc_t rc = KConfigOpenNodeRead ( kfg, & node, kfgPath );
    if ( rc == 0 )
    {
        KNamelist* children;
        rc = KConfigNodeListChild ( node, &children );
        if ( rc == 0 )
        {
            uint32_t count;
            rc = KNamelistCount ( children, &count );
            if ( rc == 0 )
            {
                uint32_t i;
                for (i = 0; i < count; ++i)
                {
                    const char* name;
                    rc = KNamelistGet ( children, i, &name );
                    if ( rc == 0 )
                    {
                        #define BufSize 4096
                        char buf[ BufSize ];
                        size_t bSize = string_size(kfgPath);
                        string_copy(buf, BufSize, kfgPath, bSize);
                        if (bSize + string_size(name) < sizeof(buf))
                        {
                            NCBIRepository* repo;
                            string_copy(buf + bSize, sizeof(buf) - bSize, name, string_size(name) + 1);
                            rc = ConfigRepo( kfg, dflt, buf, buf, type, &repo );
                            DLListPushTail( repos, (DLNode*) repo );
                        }
                        #undef BufSize
                    }
                    else
                    {
                        rc = RC ( rcSRA, rcMgr, rcConstructing, rcString, rcExcessive );
                    }
                    if ( rc != 0 )
                    {
                        break;
                    }
                }
            }
            KNamelistRelease ( children );
        }

        KConfigNodeRelease ( node );
    }
    if (GetRCState(rc) == rcNotFound)
    {
        return 0;
    }
    return rc;
}
Example #10
0
static
rc_t aws_KConfigNodeUpdateChild ( KConfigNode *self, String *name, String *value )
{
    KConfigNode * child;
    rc_t rc = KConfigNodeOpenNodeUpdate ( self, & child, "%S", name );
    if ( rc == 0 )
    {
        rc = KConfigNodeWrite ( child, value -> addr, value -> size );
        KConfigNodeRelease ( child );
    }

    return rc;
}
Example #11
0
/* CacheEnabled
 *  discover whether the repository supports caching
 */
LIB_EXPORT bool CC KRepositoryCacheEnabled ( const KRepository *self )
{
    if ( self != NULL )
    {
        const KConfigNode *node;
        rc_t rc = KConfigNodeOpenNodeRead ( self -> node, & node, "cache-enabled" );
        if ( rc == 0 )
        {
            bool enabled = false;
            rc = KConfigNodeReadBool ( node, & enabled );
            KConfigNodeRelease ( node );
            if ( rc == 0 )
                return enabled;
        }
    }

    return false;
}
Example #12
0
static
uint64_t KConfigGetNodeU64 ( const ctx_t *ctx, const char *path, bool *found )
{
    rc_t rc;
    uint64_t val = 0;
    const KConfigNode *n;

    bool dummy;
    if ( found == NULL )
        found = & dummy;

    rc = KConfigOpenNodeRead ( ctx -> caps -> cfg, & n, "sra-sort/map_file_bsize" );
    if ( rc == 0 )
    {
        char buff [ 256 ];
        size_t num_read, remaining;

        rc = KConfigNodeRead ( n, 0, buff, sizeof buff - 1, & num_read, & remaining );
        if ( rc != 0 )
            ERROR ( rc, "failed to read KConfig node '%s'", path );
        else if ( remaining != 0 )
        {
            rc = RC ( rcExe, rcNode, rcReading, rcBuffer, rcInsufficient );
            ERROR ( rc, "failed to read KConfig node '%s'", path );
        }
        else
        {
            char *end;
            buff [ num_read ] = 0;
            val = strtou64 ( buff, & end, 0 );
            if ( end [ 0 ] != 0 )
            {
                rc = RC ( rcExe, rcNode, rcReading, rcNumeral, rcIncorrect );
                ERROR ( rc, "bad '%s' config value: '%s'", path, buff );
            }
        }

        KConfigNodeRelease ( n );
    }

    return val;
}
Example #13
0
static
rc_t KRepositoryMgrCategoryRepositories ( const KConfigNode *cat,
    KRepCategory category, KRepositoryVector *repositories )
{
    KNamelist *sub_names;
    rc_t rc = KConfigNodeListChildren ( cat, & sub_names );
    if ( rc == 0 )
    {
        uint32_t i, count;
        rc = KNamelistCount ( sub_names, & count );
        for ( i = 0; i < count && rc == 0; ++ i )
        {
            const char *sub_name;
            rc = KNamelistGet ( sub_names, i, & sub_name );
            if ( rc == 0 )
            {
                KRepSubCategory subcategory = krepBadSubCategory;
                if ( strcmp ( "main", sub_name ) == 0 )
                    subcategory = krepMainSubCategory;
                else if ( strcmp ( "aux", sub_name ) == 0 )
                    subcategory = krepAuxSubCategory;
                else if ( strcmp ( "protected", sub_name ) == 0 )
                    subcategory = krepProtectedSubCategory;

                if ( subcategory != krepBadSubCategory )
                {
                    const KConfigNode *sub;
                    rc = KConfigNodeOpenNodeRead ( cat, & sub, sub_name );
                    if ( rc == 0 )
                    {
                        rc = KRepositoryMgrSubCategoryRepositories ( sub, category, subcategory, repositories );
                        KConfigNodeRelease ( sub );
                    }
                }
            }
        }

        KNamelistRelease ( sub_names );
    }

    return rc;
}
Example #14
0
static rc_t check_if_schema_exists( KDirectory * dir, const char * schema_name )
{
    KConfig * cfg;
    rc_t rc = KConfigMake ( &cfg, NULL );
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "check_if_schema_exists:KConfigMake() failed" );
    }
    else
    {
        const KConfigNode *node;
        rc = KConfigOpenNodeRead ( cfg, &node, "vdb/schema/paths" );
        if ( rc !=  0 )
        {
            LOGERR( klogErr, rc, "check_if_schema_exists:KConfigOpenNodeRead( 'vdb/schema/paths' ) failed" );
        }
        else
        {
            char buffer[ 1024 ];
            size_t num_read;
            rc = KConfigNodeRead ( node, 0, buffer, sizeof buffer, &num_read, NULL );
            if ( rc != 0 )
            {
                LOGERR( klogErr, rc, "check_if_schema_exists:KConfigNodeRead() failed" );
            }
            else
            {
                uint32_t path_type;
                buffer[ num_read ] = 0;
                path_type = KDirectoryPathType ( dir, "%s/%s", buffer, schema_name );
                if ( ( path_type & kptFile ) == 0 )
                {
                    rc = RC( rcExe, rcFile, rcConstructing, rcParam, rcInvalid );
                }
            }
            KConfigNodeRelease ( node );
        }
        KConfigRelease ( cfg );
    }
    return rc;
}
Example #15
0
static
rc_t RefSeqMgr_ConfigValue ( const KConfig *kfg, const char *node_path, char *value, size_t value_size )
{
    const KConfigNode *node;
    rc_t rc = KConfigOpenNodeRead ( kfg, & node, "%s", node_path );
    if ( rc == 0 )
    {
        size_t num_read, remaining;
        rc = KConfigNodeRead ( node, 0, value, value_size - 1, & num_read,  & remaining );
        if ( rc == 0 )
        {
            if ( remaining != 0 )
                rc = RC ( rcSRA, rcMgr, rcConstructing, rcString, rcExcessive );
            else
                value [ num_read ] = 0;
        }
        
        KConfigNodeRelease ( node );
    }
    return rc;
}
Example #16
0
static
void check_env ( const KConfig *self, char *path, size_t path_size )
{
    size_t num_read;
    const char *home;
    
    const KConfigNode *home_node;
    
    /* Check to see if home node exists */
    rc_t rc = KConfigOpenNodeRead ( self, &home_node, "HOME" );
    if ( home_node == NULL )
    {
        /* just grab the HOME env variable */
        home = getenv ( "HOME" );
        if ( home != NULL )
        {
            num_read = string_copy_measure ( path, path_size, home );
            if ( num_read >= path_size )
                path [ 0 ] = 0;
        }
    }
    else
    {
        /* if it exists check for a path */
        rc = KConfigNodeRead ( home_node, 0, path, path_size, &num_read, NULL );
        if ( rc != 0 )
        {
            home = getenv ( "HOME" );
            if ( home != NULL )
            {
                num_read = string_copy_measure ( path, path_size, home );
                if ( num_read >= path_size )
                    path [ 0 ] = 0;
            }

        }
        
        rc = KConfigNodeRelease ( home_node );
    }
}
Example #17
0
static
rc_t RefSeqMgr_KfgReadStr(const KConfig* kfg, const char* path, char* value, size_t value_sz)
{
    rc_t rc = 0;
    const KConfigNode *node;
    
    if ( (rc = KConfigOpenNodeRead(kfg, &node, "%s", path)) == 0 ) {
        size_t num_read, remaining;
        if( (rc = KConfigNodeRead(node, 0, value, value_sz - 1, &num_read, &remaining)) == 0 ) {
            if( remaining != 0 ) {
                rc = RC(rcAlign, rcIndex, rcConstructing, rcString, rcTooLong);
            } else {
                value[num_read] = '\0';
            }
        }
        KConfigNodeRelease(node);
    } else if( GetRCState(rc) == rcNotFound ) {
        rc = 0;
        value[0] = '\0';
    }
    return rc;
}
Example #18
0
static
rc_t KRepositoryMgrSubCategoryRepositories ( const KConfigNode *sub,
    KRepCategory category, KRepSubCategory subcategory, KRepositoryVector *repositories )
{
    KNamelist *repo_names;
    rc_t rc = KConfigNodeListChildren ( sub, & repo_names );
    if ( rc == 0 )
    {
        uint32_t i, count;
        rc = KNamelistCount ( repo_names, & count );
        for ( i = 0; i < count && rc == 0; ++ i )
        {
            const char *repo_name;
            rc = KNamelistGet ( repo_names, i, & repo_name );
            if ( rc == 0 )
            {
                const KConfigNode *node;
                rc = KConfigNodeOpenNodeRead ( sub, & node, repo_name );
                if ( rc == 0 )
                {
                    KRepository *repo;
                    rc = KRepositoryMake ( & repo, node, repo_name, category, subcategory );
                    if ( rc == 0 )
                    {
                        rc = VectorAppend ( repositories, NULL, repo );
                        if ( rc != 0 )
                            KRepositoryWhack ( repo );
                    }

                    KConfigNodeRelease ( node );
                }
            }
        }

        KNamelistRelease ( repo_names );
    }

    return rc;
}
Example #19
0
/* DisplayName
 *  get the repository display name,
 *  if different from its actual name
 *
 *  attempts to copy NUL-terminated name into provided buffer
 *
 *  "buffer" [ OUT ] and "bsize" [ IN ] - name output parameter
 *
 *  "name_size" [ OUT, NULL OKAY ] - returns the name size in
 *  bytes, excluding any NUL termination.
 */
LIB_EXPORT rc_t CC KRepositoryDisplayName ( const KRepository *self,
    char *buffer, size_t bsize, size_t *name_size )
{
    rc_t rc;

    if ( self == NULL )
        rc = RC ( rcKFG, rcNode, rcAccessing, rcSelf, rcNull );
    else
    {
        const KConfigNode *node;

        if ( name_size != NULL )
            * name_size = 0;

        rc = KConfigNodeOpenNodeRead ( self -> node, & node, "display-name" );
        if ( rc != 0 )
            rc = KRepositoryName ( self, buffer, bsize, name_size );
        else
        {
            size_t num_read, remaining;
            rc = KConfigNodeRead ( node, 0, buffer, bsize, & num_read, & remaining );
            KConfigNodeRelease ( node );

            if ( rc == 0 )
            {
                if ( name_size != NULL )
                    * name_size = num_read + remaining;

                if ( remaining != 0 )
                    rc = RC ( rcKFG, rcNode, rcAccessing, rcBuffer, rcInsufficient );
                else if ( num_read < bsize )
                    buffer [ num_read ] = 0;
            }
        }
    }

    return rc;
}
Example #20
0
/* EncryptionKeyFile
 *  return path to any associated encryption key file
 *
 *  attempts to copy NUL-terminated path into provided buffer
 *
 *  "buffer" [ OUT ] and "bsize" [ IN ] - key file path output parameter
 *
 *  "path_size" [ OUT, NULL OKAY ] - returns the path size in
 *  bytes, excluding any NUL termination.
 */
LIB_EXPORT rc_t CC KRepositoryEncryptionKeyFile ( const KRepository *self,
    char *buffer, size_t bsize, size_t *path_size )
{
    rc_t rc;

    if ( self == NULL )
        rc = RC ( rcKFG, rcNode, rcAccessing, rcSelf, rcNull );
    else
    {
        const KConfigNode *node;

        if ( path_size != NULL )
            * path_size = 0;

        rc = KConfigNodeOpenNodeRead ( self -> node, & node, "encryption-key-path" );
        if ( rc == 0 )
        {
            size_t num_read, remaining;
            rc = KConfigNodeRead ( node, 0, buffer, bsize, & num_read, & remaining );
            KConfigNodeRelease ( node );

            if ( rc == 0 )
            {
                if ( path_size != NULL )
                    * path_size = num_read + remaining;

                if ( remaining != 0 )
                    rc = RC ( rcKFG, rcNode, rcAccessing, rcBuffer, rcInsufficient );
                else if ( num_read < bsize )
                    buffer [ num_read ] = 0;
            }
        }
    }

    return rc;
}
Example #21
0
static
rc_t RefSeqMgr_KfgReadRepositories(const KConfig* kfg, char* paths, size_t paths_sz)
{
    /* servers are children of refseq/repository, e.g.:             /refseq/repository/main="..." */
    /* volumes are in refseq/repository/<serverName>/volumes, e.g.: /refseq/repository/main/volumes="..." */
    /* all server/volume combinations are returned in paths separated by ':' */
    
    rc_t rc = 0;
    const KConfigNode *node;
#define KFG_PATH "/refseq/repository/"
    paths[0] = 0;
    
    rc = KConfigOpenNodeRead ( kfg, & node, KFG_PATH );
    if ( rc == 0 )
    {
        KNamelist* children;
        rc = KConfigNodeListChild ( node, &children );
        if ( rc == 0 )
        {
            uint32_t count;
            rc = KNamelistCount ( children, &count );
            if ( rc == 0 )
            {
                uint32_t i;
                for (i = 0; i < count; ++i) /* for all servers */
                {
                    const char* name;
                    rc = KNamelistGet ( children, i, &name );
                    if ( rc == 0 )
                    {
#define BufSize 4096
                        char server[ BufSize ];
                        char buf[ BufSize ];
                        size_t num_writ;
                        
                        rc = string_printf(buf, BufSize, &num_writ, KFG_PATH "%s", name);
                        if (rc == 0)
                        {
                            rc = RefSeqMgr_ConfigValue ( kfg, buf, server, sizeof(server) );
                            if (rc == 0)
                            {
                                rc = string_printf(buf, BufSize, &num_writ, KFG_PATH "%s/volumes", name);
                                if (rc == 0)
                                {
                                    char volumes[ BufSize ];
                                    rc = RefSeqMgr_ConfigValue ( kfg, buf, volumes, sizeof(volumes) );
                                    if (rc == 0)
                                    {   /* create a server/volume pair for every combination, append to paths, ':' - separate */
                                        char *vol_rem = volumes;
                                        char *vol_sep;
                                        
                                        do {
                                            char const *volume = vol_rem;
                                            vol_sep = string_chr(volume, string_size(volume), ':');
                                            if(vol_sep) {
                                                vol_rem = vol_sep + 1;
                                                *vol_sep = 0;
                                            }
                                            string_copy(paths + string_size(paths), paths_sz - string_size(paths), server, string_size(server));
                                            if (paths[string_size(paths)-1] != '/')
                                            {
                                                string_copy(paths + string_size(paths), paths_sz - string_size(paths), "/", 1);
                                            }
                                            string_copy(paths + string_size(paths), paths_sz - string_size(paths), volume, string_size(volume));
                                            string_copy(paths + string_size(paths), paths_sz - string_size(paths), ":", 1);
                                        } while(vol_sep);
                                    }
                                }
                            }
                        }
#undef BufSize
                    }
                    if ( rc != 0 )
                    {
                        break;
                    }
                }
            }
            KNamelistRelease ( children );
        }
        
        KConfigNodeRelease ( node );
    }
    if (GetRCState(rc) == rcNotFound)
    {
        paths[0] = '\0';
        return 0;
    }
    return 0;
}
Example #22
0
/* EncryptionKey
 *  return any associated encryption key
 *
 *  attempts to copy NUL-terminated key into provided buffer
 *
 *  "buffer" [ OUT ] and "bsize" [ IN ] - encryption key output parameter
 *
 *  "key_size" [ OUT, NULL OKAY ] - returns the key size in
 *  bytes, excluding any NUL termination.
 */
LIB_EXPORT rc_t CC KRepositoryEncryptionKey ( const KRepository *self,
    char *buffer, size_t bsize, size_t *key_size )
{
    rc_t rc;

    if ( self == NULL )
        rc = RC ( rcKFG, rcNode, rcAccessing, rcSelf, rcNull );
    else
    {
        const KConfigNode *node;

        if ( key_size != NULL )
            * key_size = 0;

        rc = KConfigNodeOpenNodeRead ( self -> node, & node, "encryption-key" );
        if ( rc == 0 )
        {
            size_t num_read, remaining;
            rc = KConfigNodeRead ( node, 0, buffer, bsize, & num_read, & remaining );
            KConfigNodeRelease ( node );

            if ( rc == 0 )
            {
                if ( key_size != NULL )
                    * key_size = num_read + remaining;

                if ( remaining != 0 )
                    rc = RC ( rcKFG, rcNode, rcAccessing, rcBuffer, rcInsufficient );
                else if ( num_read < bsize )
                    memset ( & buffer [ num_read ], 0, bsize - num_read );
            }
        }
        else if ( GetRCState ( rc ) == rcNotFound )
        {
            char path [ 4096 ];
            rc_t rc2 = KRepositoryEncryptionKeyFile ( self, path, sizeof path, NULL );
            if ( rc2 == 0 )
            {
                KDirectory *wd;
                rc2 = KDirectoryNativeDir ( & wd );
                if ( rc2 == 0 )
                {
                    const KFile *keyFile;
                    rc2 = KDirectoryOpenFileRead ( wd, & keyFile, path );
                    KDirectoryRelease ( wd );
                    if ( rc2 == 0 )
                    {
                        size_t num_read;
                        rc = KFileReadAll ( keyFile, 0, buffer, bsize, & num_read );
                        if ( rc == 0 )
                        {
                            if ( num_read == bsize )
                            {
                                uint64_t eof;
                                rc = KFileSize ( keyFile, & eof );
                                if ( rc == 0 )
                                    num_read = ( size_t ) eof;
                                else
                                    num_read = 0;

                                rc = RC ( rcKFG, rcFile, rcReading, rcBuffer, rcInsufficient );
                                memset ( buffer, 0, bsize );
                            }
                            else if ( num_read == 0 )
                            {
                                rc = RC ( rcKFG, rcFile, rcReading, rcFile, rcEmpty );
                                memset ( buffer, 0, bsize );
                            }
                            else
                            {
                                char *eoln = string_chr ( buffer, num_read, '\n' );
                                if ( eoln != NULL )
                                {
                                    if ( eoln == buffer )
                                        num_read = 0;
                                    else if ( eoln [ -1 ] == '\r' )
                                        num_read = eoln - buffer - 1;
                                    else
                                        num_read = eoln - buffer;
                                }

                                if ( key_size != NULL )
                                    * key_size = num_read;

                                memset ( & buffer [ num_read ], 0, bsize - num_read );
                            }
                        }

                        KFileRelease ( keyFile );
                    }
                }
            }
        }
    }

    return rc;
}
Example #23
0
static
void KNSManagerLoadAWS ( struct KNSManager *self )
{
    rc_t rc;

    const KConfigNode *aws_node;
    const KConfig *kfg = self -> kfg;

    if ( self == NULL )
        return;

    rc = KConfigOpenNodeRead ( kfg, &aws_node, "AWS" );
    if ( rc == 0 )
    {
        do
        {
            String *access_key_id = NULL, *secret_access_key = NULL, *region = NULL, *output = NULL;
            const KConfigNode *access_key_id_node, *secret_access_key_node, *region_node, *output_node;

            rc = KConfigNodeOpenNodeRead ( aws_node, &access_key_id_node, "aws_access_key_id" );
            if ( rc == 0 )
            {
                rc = KConfigNodeReadString ( access_key_id_node, &access_key_id );

                KConfigNodeRelease ( access_key_id_node );

                if( rc != 0 )
                    break;
            }


            rc = KConfigNodeOpenNodeRead ( aws_node, &secret_access_key_node, "aws_secret_access_key" );
            if ( rc == 0 )
            {
                rc = KConfigNodeReadString ( secret_access_key_node, &secret_access_key );

                KConfigNodeRelease ( secret_access_key_node );

                if ( rc != 0 )
                    break;
            }
        
            rc = KConfigNodeOpenNodeRead ( aws_node, &region_node, "region" );
            if ( rc == 0 )
            {
                rc = KConfigNodeReadString ( region_node, &region );

                KConfigNodeRelease ( region_node );

                if ( rc != 0 )
                    break;
            }

            rc = KConfigNodeOpenNodeRead ( aws_node, &output_node, "output" );
            if ( rc == 0 )
            {
                rc = KConfigNodeReadString ( output_node, &output );

                KConfigNodeRelease ( output_node );
                
                if ( rc != 0 )
                    break;
            }

            self -> aws_access_key_id = access_key_id;
            self -> aws_secret_access_key = secret_access_key;
            self -> aws_region = region;
            self -> aws_output = output;

        } while ( 0 );

        KConfigNodeRelease ( aws_node );
    }
}