static struct selabel_lookup_rec *lookup_best_match(struct selabel_handle *rec, const char *key, const char **aliases, int type) { size_t n, i; int best = -1; struct spec **specs; size_t prefix_len = 0; struct selabel_lookup_rec *lr = NULL; if (!aliases || !aliases[0]) return lookup(rec, key, type); for (n = 0; aliases[n]; n++) ; specs = calloc(n+1, sizeof(struct spec *)); if (!specs) return NULL; specs[0] = lookup_common(rec, key, type, false); if (specs[0]) { if (!specs[0]->hasMetaChars) { /* exact match on key */ lr = &specs[0]->lr; goto out; } best = 0; prefix_len = specs[0]->prefix_len; } for (i = 1; i <= n; i++) { specs[i] = lookup_common(rec, aliases[i-1], type, false); if (specs[i]) { if (!specs[i]->hasMetaChars) { /* exact match on alias */ lr = &specs[i]->lr; goto out; } if (specs[i]->prefix_len > prefix_len) { best = i; prefix_len = specs[i]->prefix_len; } } } if (best >= 0) { /* longest fixed prefix match on key or alias */ lr = &specs[best]->lr; } else { errno = ENOENT; } out: free(specs); return lr; }
static struct selabel_lookup_rec *lookup(struct selabel_handle *rec, const char *key, int type) { spec_t *spec; spec = lookup_common(rec, key, type, false); if (spec) return &spec->lr; return NULL; }
static char *lookup_string(struct sdtid *s, const char *name, const char *def) { char *ret = lookup_common(s, name); if (!ret && def) { ret = strdup(def); if (!ret) s->error = ERR_NO_MEMORY; } return ret; }
static int lookup_int(struct sdtid *s, const char *name, int def) { char *ret = lookup_common(s, name), *endp; long val; if (!ret) return def; val = strtol(ret, &endp, 0); if (*endp || !*ret) s->error = ERR_GENERAL; free(ret); return val; }
static int lookup_b64(struct sdtid *s, const char *name, uint8_t *out, int buf_len) { char *data = lookup_common(s, name), *p; unsigned long actual = buf_len; int len; if (!data) return -1; /* <Seed> has a bogus character at the start of the string */ p = data; if (*p && !strcmp(name, "Seed")) p++; len = base64_decode(p, strlen(p), out, &actual) == CRYPT_OK ? actual : -1; free(data); return len == buf_len ? 0 : -1; }
static int node_present(struct sdtid *s, const char *name) { char *str = s ? lookup_common(s, name) : NULL; free(str); return !!str; }
static bool partial_match(struct selabel_handle *rec, const char *key) { return lookup_common(rec, key, 0, true) ? true : false; }
int glite_jpps_fplug_lookup(glite_jp_context_t ctx,const char *uri, glite_jpps_fplug_data_t ***plugin_data) { return lookup_common(ctx,uri,NULL,plugin_data); }