aboutsummaryrefslogtreecommitdiff
path: root/src/ctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ctl.c')
-rw-r--r--src/ctl.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 46038a2..22aecb8 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -16,7 +16,6 @@
#include "pies.h"
#include "prog.h"
-#include "xvasprintf.h"
#include "identity.h"
#include "base64.h"
#include "json.h"
@@ -55,11 +54,14 @@ ctlbuf_free (struct ctlbuf *buf)
static void
ctlbuf_alloc (struct ctlbuf *buf, size_t s)
{
- while (buf->level + s >= buf->size)
+ size_t minsize = buf->level + s;
+ while (minsize >= buf->size)
{
if (buf->size == 0)
buf->size = CTLBUFSIZE;
- buf->base = x2realloc (buf->base, &buf->size);
+ else
+ buf->size *= CTLBUFSIZE;
+ buf->base = grecs_realloc (buf->base, buf->size);
}
}
@@ -415,7 +417,8 @@ output_set_header (struct output *out, char const *name, char const *fmt, ...)
int install = 1;
struct http_header key, *ret;
va_list ap;
-
+ size_t len = 0;
+
key.name = (char *) name;
key.value = NULL;
ret = grecs_symtab_lookup_or_install (out->headers, &key, &install);
@@ -428,7 +431,8 @@ output_set_header (struct output *out, char const *name, char const *fmt, ...)
if (!install)
free (ret->value);
va_start (ap, fmt);
- ret->value = xvasprintf (fmt, ap);
+ ret->value = NULL;
+ grecs_vasprintf (&ret->value, &len, fmt, ap);
va_end (ap);
return 0;
}
@@ -444,13 +448,14 @@ json_object_set_string (struct json_value *obj,
char const *name, char const *fmt, ...)
{
va_list ap;
- char *s;
+ char *s = NULL;
+ size_t l = 0;
va_start (ap, fmt);
- s = xvasprintf (fmt, ap);
+ grecs_vasprintf (&s, &l, fmt, ap);
va_end (ap);
json_object_set (obj, name, json_new_string (s));
- free (s);
+ grecs_free (s);
}
static void
@@ -486,7 +491,7 @@ ctlio_create (void)
{
struct ctlio *io;
- io = xmalloc (sizeof (*io));
+ io = grecs_malloc (sizeof (*io));
input_init (&io->input);
output_init (&io->output);
io->state = identity_provider_list ? CTL_INITIAL_STATE : CTL_ADMIN_STATE;
@@ -581,14 +586,15 @@ ctlio_reply (struct ctlio *io, int code, const char *fmt, ...)
if (fmt)
{
va_list ap;
- char *str;
-
+ char *str = NULL;
+ size_t len = 0;
+
va_start (ap, fmt);
- str = xvasprintf (fmt, ap);
+ grecs_vasprintf (&str, &len, fmt, ap);
va_end (ap);
io->output.reply = json_error_reply_create (str);
- free (str);
+ grecs_free (str);
}
else
io->output.reply = json_error_reply_create (http_text (code));
@@ -604,10 +610,11 @@ static void
ctlio_printf (struct ctlio *io, const char *fmt, ...)
{
va_list ap;
- char *str;
+ char *str = NULL;
+ size_t len = 0;
va_start (ap, fmt);
- str = xvasprintf (fmt, ap);
+ grecs_vasprintf (&str, &len, fmt, ap);
va_end (ap);
ctlio_print (io, str);
free (str);
@@ -733,6 +740,13 @@ do_auth (struct ctlio *io, char const *name, char const *pass)
struct grecs_list_entry *ep;
pies_identity_t id = pies_identity_create (name);
int new_state = CTL_INITIAL_STATE;
+
+ if (!id)
+ {
+ logmsg (LOG_AUTH, _("%s: can't authenticate: %s"),
+ name, strerror (errno));
+ return -1;
+ }
for (ep = identity_provider_list->head; ep; ep = ep->next)
{
@@ -815,11 +829,11 @@ ctlio_authenticate (struct ctlio *io)
char *passwd;
size_t s = p - data;
- user = xmalloc (s + 1);
+ user = grecs_malloc (s + 1);
memcpy (user, data, s);
user[s] = 0;
- passwd = xmalloc (datalen - s);
+ passwd = grecs_malloc (datalen - s);
memcpy (passwd, p + 1, datalen - s - 1);
passwd[datalen - s - 1] = 0;

Return to:

Send suggestions and report system problems to the System administrator.