aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-05 16:17:38 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-05 16:20:24 +0200
commit6ac0f1e8e19922c63a1542740a7c88116989bb7c (patch)
tree6124aaa6dbd729deab5de7550f6603056e39b4b3 /src
parentf937fa90807400e87aa64cd03f2c8470093129d7 (diff)
downloadpies-6ac0f1e8e19922c63a1542740a7c88116989bb7c.tar.gz
pies-6ac0f1e8e19922c63a1542740a7c88116989bb7c.tar.bz2
Minor changes.
* src/ctl.c (ctlio_authenticate): Configurable realm name. (ctlio_do_command): Check the Accept header. * src/inetd.c (inetd_conf_file): Change line_no type. * src/pies.c (control_keywords): New keyword: realm. * src/pies.h (control) <realm>: New member.
Diffstat (limited to 'src')
-rw-r--r--src/ctl.c71
-rw-r--r--src/inetd.c4
-rw-r--r--src/pies.c7
-rw-r--r--src/pies.h1
4 files changed, 70 insertions, 13 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 6145d39..cdb9b6c 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -662,7 +662,6 @@ ctlio_finalize_reply (struct ctlio *io)
/* nothing */;
else if (strcasecmp (val, "close") == 0)
io->state = CTL_END_STATE;
- //FIXME: else?
}
if (io->state == CTL_END_STATE || io->state == CTL_ACTION_STATE)
@@ -840,7 +839,8 @@ ctlio_authenticate (struct ctlio *io)
else
{
output_set_header (&io->output, "WWW-Authenticate",
- "Basic realm=\"%s\"", "pies"); //FIXME: Configurable realm
+ "Basic realm=\"%s\"",
+ control.realm ? control.realm : "pies");
ctlio_reply (io, 401, NULL);
}
return 1;
@@ -957,6 +957,62 @@ delim_count (char const *str, int delim)
return i;
}
+static int
+check_accepted_media (struct ctlio *io, char const *type, char const *subtype)
+{
+ char const *val;
+ struct wordsplit ws;
+ int rc = 1;
+ size_t i;
+
+ val = http_get_header (io->input.headers, "Accept");
+ if (!val)
+ return 0;
+
+ ws.ws_delim = ",";
+ if (wordsplit (val, &ws,
+ WRDSF_NOCMD | WRDSF_NOVAR | WRDSF_DELIM | WRDSF_WS
+ | WRDSF_DQUOTE))
+ {
+ logmsg (LOG_ERR, "wordsplit: %s", wordsplit_strerror (&ws));
+ ctlio_reply (io, 500, NULL);
+ return -1;
+ }
+
+ for (i = 0; i < ws.ws_wordc; i++)
+ {
+ char *p = strchr (ws.ws_wordv[i], ';');
+ if (p)
+ {
+ while (p > ws.ws_wordv[i] && ISWS (p[-1]))
+ --p;
+ *p = 0;
+ }
+
+ p = strchr (ws.ws_wordv[i], '/');
+ if (!p)
+ continue;
+
+ *p++ = 0;
+
+ if ((strcmp (ws.ws_wordv[i], "*") == 0
+ || strcmp (ws.ws_wordv[i], type) == 0)
+ && (strcmp (p, "*") == 0
+ || strcmp (p, subtype) == 0))
+ {
+ rc = 0;
+ break;
+ }
+ }
+
+ wordsplit_free (&ws);
+
+ if (rc)
+ ctlio_reply (io, 406, NULL);
+
+ return rc;
+}
+
static void
ctlio_do_command (struct ctlio *io)
{
@@ -984,14 +1040,8 @@ ctlio_do_command (struct ctlio *io)
}
}
-#if 0
- FIXME
- if (check_accept(io, "application/json"))
- {
- ctlio_reply (io, 406, NULL);
- return;
- }
-#endif
+ if (check_accepted_media (io, "application", "json"))
+ return;
method = method_decode (io->input.input_method);
if (method == METH_INVALID)
@@ -1043,7 +1093,6 @@ ctlio_do_command (struct ctlio *io)
if (!json)
{
ctlio_reply (io, 400, "JSON error: %s", json_err_diag);
- //FIXME: Reply json
return;
}
}
diff --git a/src/inetd.c b/src/inetd.c
index 858178d..4a55ad5 100644
--- a/src/inetd.c
+++ b/src/inetd.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2009, 2010, 2011, 2013 Sergey Poznyakoff
+ Copyright (C) 2009-2011, 2013, 2016 Sergey Poznyakoff
GNU Pies is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -81,7 +81,7 @@ inetd_conf_file (const char *file)
FILE *fp;
size_t size = 0;
char *buf = NULL;
- size_t line_no = 0;
+ unsigned long line_no = 0;
struct wordsplit ws;
char *dfl_address = NULL;
int wsflags;
diff --git a/src/pies.c b/src/pies.c
index e7c1a22..f069552 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1488,6 +1488,13 @@ struct grecs_keyword control_keywords[] = {
&control.idle_timeout, 0,
NULL,
},
+ {"realm",
+ N_("name"),
+ N_("Authentication realm name"),
+ grecs_type_string, GRECS_DFLT,
+ &control.realm, 0,
+ NULL,
+ },
{ NULL }
};
diff --git a/src/pies.h b/src/pies.h
index 34f1250..7c5e6d7 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -541,6 +541,7 @@ struct control
pies_acl_t adm_acl; /* Administrative ACL */
pies_acl_t usr_acl; /* User ACL */
unsigned int idle_timeout; /* Session idle timeout */
+ char *realm; /* Authentication realm */
};
extern struct control control;

Return to:

Send suggestions and report system problems to the System administrator.