summaryrefslogtreecommitdiffabout
path: root/src/ctl.c
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 13:31:17 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-08 14:17:35 (GMT)
commit489432d354d88049afe4af54c29965d382d67f7a (patch) (side-by-side diff)
tree84725496a92564824f75f0a2edd5a595411ffab2 /src/ctl.c
parent3325fed2895f079486b88c65409c73153fec306f (diff)
downloadpies-489432d354d88049afe4af54c29965d382d67f7a.tar.gz
pies-489432d354d88049afe4af54c29965d382d67f7a.tar.bz2
Uniformly use grecs memory management functions.
* gnulib.modules: Remove unneded modules. * ident/ident.h: Remove xalloc.h, include errno.h * ident/ident.c: Use standard allocation functions instead of x* * ident/pam.c: Remove. * ident/provider.c: Remove. * ident/system.c: Remove. * src/meta.c: Remove. * src/Makefile.am: Remove meta.c * src/progman.c: Use grecs_* allocation functions instead of x*. (notify): Use wordsplit to expand variables within message. Rename variables: program-name to program_name; canonical-program-name to canonical_program_name. * doc/pies.texi: Update. * src/depmap.c: Use grecs_* allocation functions instead of x*. (depmap_end): New function. * src/diag.c (logmsg_vprintf): Use grecs_txtacc instead of obstack. * src/pies.h (depmap_end): New proto. Remove unused includes. * src/acl.c: Use grecs_* allocation functions instead of x*. * src/ctl.c: Likewise. * src/inetd.c: Likewise. * src/limits.c: Likewise. * src/meta1gram.y: Likewise. * src/meta1lex.l: Likewise. * src/pies.c: Likewise. * src/socket.c: Likewise. * src/sysvinit.c: Likewise. * src/userprivs.c: Likewise.
Diffstat (limited to 'src/ctl.c') (more/less context) (ignore whitespace changes)
-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.