aboutsummaryrefslogtreecommitdiff
path: root/src/ping903.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ping903.c')
-rw-r--r--src/ping903.c88
1 files changed, 20 insertions, 68 deletions
diff --git a/src/ping903.c b/src/ping903.c
index 3aee44a..3e5aadd 100644
--- a/src/ping903.c
+++ b/src/ping903.c
@@ -530,70 +530,6 @@ ept_ip_match(struct MHD_Connection *conn,
return ret;
}
-static void
-argv_free(int ac, char **av)
-{
- int i;
- for (i = 0; i < ac; i++)
- free(av[i]);
- free(av);
-}
-
-static char **
-strsplit(char const *str, int max, int *ret_n)
-{
- char **av;
- int ac;
- char const *p;
- int inword;
-
- av = calloc(max+1, sizeof(*av));
- if (!av)
- return NULL;
- ac = 0;
-
-#define ISWS(c) ((c)==' '||(c)=='\t')
-
- inword = !ISWS(*str);
- p = str;
- for (;;) {
- if (inword) {
- if (*p == 0 || (ac < max-1 && ISWS(*p))) {
- size_t len;
-
- if (ac == max-1) {
- while (p > str && ISWS(*p))
- p--;
- if (p == str)
- break;
- }
- len = p - str;
- av[ac] = malloc(len + 1);
- if (!av[ac])
- goto err;
- memcpy(av[ac], str, len);
- av[ac][len] = 0;
- ac++;
- if (ac == max || *p == 0)
- break;
- inword = 0;
- }
- } else if (*p == 0) {
- break;
- } else if (!ISWS(*p)) {
- str = p;
- inword = 1;
- }
- p++;
- }
- av[ac] = NULL;
- *ret_n = ac;
- return av;
-err:
- argv_free(ac, av);
- return NULL;
-}
-
struct auth_location {
char *url;
size_t ulen;
@@ -611,6 +547,7 @@ cf_auth(int mode, union cf_callback_arg *arg, void *data)
{
int ac;
char **av;
+ char *endp;
struct auth_location *loc;
if (mode != CF_PARSE)
@@ -618,24 +555,39 @@ cf_auth(int mode, union cf_callback_arg *arg, void *data)
// auth basic METHOD URL [FILE [REALM]]
enum { i_type, i_method, i_url, i_file, i_realm };
-
- av = strsplit(arg->input.val, 5, &ac);
- if (!av)
+
+ switch (strsplit(arg->input.val, 5, &ac, &av, &endp)) {
+ case STRSPLIT_OK:
+ if (!*endp)
+ break;
+ /* fall through */
+ case STRSPLIT_ERR:
+ error("%s:%d: syntax error near %s",
+ arg->input.file, arg->input.line, endp);
+ argcv_free(ac, av);
+ return CF_RET_FAIL;
+
+ case STRSPLIT_NOMEM:
emalloc_die();
+ }
+
if (ac < 3) {
error("%s:%d: syntax error",
arg->input.file, arg->input.line);
+ argcv_free(ac, av);
return CF_RET_FAIL;
}
if (!auth_head && ac < 5) {
error("%s:%d: realm or password file name missing",
arg->input.file, arg->input.line);
+ argcv_free(ac, av);
return CF_RET_FAIL;
}
if (strcmp(av[i_type], "basic")) {
error("%s:%d: unsupported authentication method",
arg->input.file, arg->input.line);
+ argcv_free(ac, av);
return CF_RET_FAIL;
}
@@ -656,7 +608,7 @@ cf_auth(int mode, union cf_callback_arg *arg, void *data)
/* All elements except 1st were transferred to loc, hence 1 as the
value of the first parameter. */
- argv_free(1, av);
+ argcv_free(1, av);
return CF_RET_OK;
}

Return to:

Send suggestions and report system problems to the System administrator.