- FILE *fp = NULL;
- int authorized = 1;
-
-#ifdef EMBEDDED
- struct llhead *lp;
- struct uri_auth *auth;
-
- /* Check, is this URL protected by shttpd_protect_url() */
- LL_FOREACH(&c->ctx->uri_auths, lp) {
- auth = LL_ENTRY(lp, struct uri_auth, link);
- if (!strncmp(c->uri, auth->uri, auth->uri_len)) {
- fp = fopen(auth->file_name, "r");
+ FILE *fp = NULL;
+ int len, n, authorized = 1;
+ const char *p, *s = c->ctx->options[OPT_PROTECT];
+ char protected_path[FILENAME_MAX];
+
+ FOR_EACH_WORD_IN_LIST(s, len) {
+
+ if ((p = memchr(s, '=', len)) == NULL || p >= s + len || p == s)
+ continue;
+
+ if (!memcmp(c->uri, s, p - s)) {
+
+ n = s + len - p + 1;
+ if (n > (int) sizeof(protected_path) - 1)
+ n = sizeof(protected_path) - 1;
+
+ my_strlcpy(protected_path, p + 1, n);
+
+ if ((fp = fopen(protected_path, "r")) == NULL)
+ elog(E_LOG, c, "check_auth: cannot open %s: %s",
+ protected_path, strerror(errno));