コード例 #1
0
ファイル: rwipautils.c プロジェクト: bbayles/netsa-pkg
char *
get_ipa_config(
    void)
{
    skstream_t *conf_stream = NULL;
    char filename[PATH_MAX];
    char line[IPA_CONFIG_LINE_LENGTH];
    char *ipa_url = NULL;
    int rv;

    /* Read in the data file */
    if (NULL == skFindFile(IPA_CONFIG_FILE, filename, sizeof(filename), 1)) {
        skAppPrintErr("Could not locate config file '%s'.",
                      IPA_CONFIG_FILE);
        return NULL;
    }

    /* open input */
    if ((rv = skStreamCreate(&conf_stream, SK_IO_READ, SK_CONTENT_TEXT))
        || (rv = skStreamBind(conf_stream, filename))
        || (rv = skStreamSetCommentStart(conf_stream, "#"))
        || (rv = skStreamOpen(conf_stream)))
    {
        skStreamPrintLastErr(conf_stream, rv, &skAppPrintErr);
        skStreamDestroy(&conf_stream);
        exit(EXIT_FAILURE);
    }
    while (skStreamGetLine(conf_stream, line, sizeof(line), NULL)
           == SKSTREAM_OK)
    {
        /* FIXME: smarter config file reading, please */
        if (strlen(line) > 0) {
            ipa_url = strdup(line);
            break;
        }
    }

    skStreamDestroy(&conf_stream);
    /* Should be free()d by the caller */
    return ipa_url;
}
コード例 #2
0
ファイル: addrtype.c プロジェクト: brettmeyers/silk
int
skAddressTypesSetup(
    const char         *map_name,
    sk_msg_fn_t         errfn)
{
    char filename[PATH_MAX];
    skPrefixMapErr_t map_error;
    int check_pwd = 1;
    int found = 0;

    if (addrtype_map) {
        return 0;
    }

    if (!map_name) {
        map_name = getenv(SK_ADDRTYPE_MAP_ENVAR);
        if (!map_name || !map_name[0]) {
            map_name = SK_ADDRTYPE_DEFAULT_MAP;
            /* don't check pwd if we use the default map name */
            check_pwd = 0;
        }
    }

    /* if name explicitly given, see if the file exists.  this will
     * support relative paths that skFindFile() does not. */
    if (check_pwd) {
        if (skFileExists(map_name)) {
            strncpy(filename, map_name, sizeof(filename));
            filename[sizeof(filename)-1] = '\0';
            found = 1;
        }
    }

    /* Locate the data file */
    if (!found
        && (NULL == skFindFile(map_name, filename, sizeof(filename), 1)))
    {
        if (errfn) {
            errfn("Could not locate AddressTypes data file '%s'",
                  map_name);
        }
        return -1;
    }

    /* Read in the data file */
    map_error = skPrefixMapLoad(&addrtype_map, filename);
    if (SKPREFIXMAP_OK != map_error) {
        if (errfn) {
            errfn("Failed to load AddressTypes data file '%s': %s",
                  filename, skPrefixMapStrerror(map_error));
        }
        return -1;
    }

    if (skPrefixMapGetContentType(addrtype_map)==SKPREFIXMAP_CONT_PROTO_PORT){
        skPrefixMapDelete(addrtype_map);
        addrtype_map = NULL;
        if (errfn) {
            errfn(("Failed to load AddressTypes data file '%s': "
                   "Map contains protocol/port pairs"),
                  filename);
        }
        return -1;
    }

    return 0;
}