aboutsummaryrefslogtreecommitdiff
path: root/src/ctl.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 15:31:17 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 16:17:35 +0200
commit489432d354d88049afe4af54c29965d382d67f7a (patch)
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')
-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
@@ -13,13 +13,12 @@
You should have received a copy of the GNU General Public License
along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
#include "pies.h"
#include "prog.h"
-#include "xvasprintf.h"
#include "identity.h"
#include "base64.h"
#include "json.h"
struct control control;
@@ -52,17 +51,20 @@ ctlbuf_free (struct ctlbuf *buf)
free (buf->base);
}
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);
}
}
static void
ctlbuf_write (struct ctlbuf *buf, char const *str, size_t n)
{
@@ -412,26 +414,28 @@ output_reset (struct output *out)
static int
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);
if (!ret)
{
logmsg (LOG_ERR, _("cannot install output header: %s"),
strerror (errno));
return 1;
}
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;
}
static struct json_value *
json_reply_create (void)
@@ -441,19 +445,20 @@ json_reply_create (void)
static void
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
json_object_set_number (struct json_value *obj, char const *name, double val)
{
json_object_set (obj, name, json_new_number (val));
@@ -483,13 +488,13 @@ struct ctlio
static struct ctlio *
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;
io->action = ACTION_CONT;
ctlbuf_init (&io->obuf);
return io;
@@ -578,20 +583,21 @@ static void
ctlio_reply (struct ctlio *io, int code, const char *fmt, ...)
{
io->code = code;
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));
}
static void
@@ -601,16 +607,17 @@ ctlio_print (struct ctlio *io, const char *text)
}
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);
}
static void
@@ -730,12 +737,19 @@ try_auth (struct prog *prog, void *data)
static int
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)
{
pies_identity_provider_t provider = ep->data;
char const *pname = pies_identity_provider_name (provider);
@@ -812,17 +826,17 @@ ctlio_authenticate (struct ctlio *io)
{
int result;
char *user;
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;
free(data);
result = do_auth (io, user, passwd);

Return to:

Send suggestions and report system problems to the System administrator.