X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/fe2a5dcf9de1f124ed3cfa2c6327860bd5aca820..11ad66c29764521f87f0dd399a1e592147c7af36:/server/admin.c diff --git a/server/admin.c b/server/admin.c index 0e3effb0..2d1658ee 100644 --- a/server/admin.c +++ b/server/admin.c @@ -9,19 +9,18 @@ * * This file is part of Trivial IP Encryption (TrIPE). * - * TrIPE is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * TrIPE is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your + * option) any later version. * - * TrIPE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * TrIPE is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. * * You should have received a copy of the GNU General Public License - * along with TrIPE; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with TrIPE. If not, see . */ /*----- Header files ------------------------------------------------------*/ @@ -51,7 +50,9 @@ unsigned tr_flags = 0; #endif static const trace_opt w_opts[] = { +#ifndef NTRACE { 't', AF_TRACE, "trace messages" }, +#endif { 'n', AF_NOTE, "asynchronous notifications" }, { 'w', AF_WARN, "warnings" }, { 'A', AF_ALLMSGS, "all of the above" }, @@ -235,7 +236,7 @@ static void a_flush(int fd, unsigned mode, void *v) * * Arguments: @dstr *d@ = where to leave the formatted message * @const char *fmt@ = pointer to format string - * @va_list ap@ = arguments in list + * @va_list *ap@ = arguments in list * * Returns: --- * @@ -260,17 +261,17 @@ static void a_flush(int fd, unsigned mode, void *v) * * "[!]..." ... -- @dstr_putf@-like string as single token */ -void a_vformat(dstr *d, const char *fmt, va_list ap) +void a_vformat(dstr *d, const char *fmt, va_list *ap) { dstr dd = DSTR_INIT; while (fmt) { if (*fmt == '*') { if (d->len) dstr_putc(d, ' '); - dstr_vputf(d, fmt + 1, &ap); + dstr_vputf(d, fmt + 1, ap); } else if (*fmt == '?') { if (strcmp(fmt, "?ADDR") == 0) { - const addr *a = va_arg(ap, const addr *); + const addr *a = va_arg(*ap, const addr *); switch (a->sa.sa_family) { case AF_INET: u_quotify(d, "INET"); @@ -281,8 +282,8 @@ void a_vformat(dstr *d, const char *fmt, va_list ap) abort(); } } else if (strcmp(fmt, "?B64") == 0) { - const octet *p = va_arg(ap, const octet *); - size_t n = va_arg(ap, size_t); + const octet *p = va_arg(*ap, const octet *); + size_t n = va_arg(*ap, size_t); base64_ctx b64; dstr_putc(d, ' '); base64_init(&b64); @@ -292,10 +293,10 @@ void a_vformat(dstr *d, const char *fmt, va_list ap) base64_encode(&b64, 0, 0, d); while (d->len && d->buf[d->len - 1] == '=') d->len--; } else if (strcmp(fmt, "?TOKENS") == 0) { - const char *const *av = va_arg(ap, const char *const *); + const char *const *av = va_arg(*ap, const char *const *); while (*av) u_quotify(d, *av++); } else if (strcmp(fmt, "?PEER") == 0) - u_quotify(d, p_name(va_arg(ap, peer *))); + u_quotify(d, p_name(va_arg(*ap, peer *))); else if (strcmp(fmt, "?ERRNO") == 0) { dstr_putf(d, " E%d", errno); u_quotify(d, strerror(errno)); @@ -304,11 +305,12 @@ void a_vformat(dstr *d, const char *fmt, va_list ap) } else { if (*fmt == '!') fmt++; DRESET(&dd); - dstr_vputf(&dd, fmt, &ap); + dstr_vputf(&dd, fmt, ap); u_quotify(d, dd.buf); } - fmt = va_arg(ap, const char *); + fmt = va_arg(*ap, const char *); } + dstr_putz(d); dstr_destroy(&dd); } @@ -329,7 +331,7 @@ void a_format(dstr *d, const char *fmt, ...) va_list ap; va_start(ap, fmt); - a_vformat(d, fmt, ap); + a_vformat(d, fmt, &ap); va_end(ap); } @@ -339,7 +341,7 @@ void a_format(dstr *d, const char *fmt, ...) * @const char *status@ = status code to report * @const char *tag@ = tag string, or null * @const char *fmt@ = pointer to format string - * @va_list ap@ = arguments in list + * @va_list *ap@ = arguments in list * @...@ = other arguments * * Returns: --- @@ -348,7 +350,7 @@ void a_format(dstr *d, const char *fmt, ...) */ static void a_vwrite(admin *a, const char *status, const char *tag, - const char *fmt, va_list ap) + const char *fmt, va_list *ap) { dstr d = DSTR_INIT; @@ -367,11 +369,11 @@ static void a_write(admin *a, const char *status, const char *tag, va_list ap; va_start(ap, fmt); - a_vwrite(a, status, tag, fmt, ap); + a_vwrite(a, status, tag, fmt, &ap); va_end(ap); } -/* --- @a_ok@, @a_info@, @a_fail@ --- * +/* --- @a_ok@, @a_fail@ --- * * * Arguments: @admin *a@ = connection * @const char *fmt@ = format string @@ -384,21 +386,32 @@ static void a_write(admin *a, const char *status, const char *tag, static void a_ok(admin *a) { a_write(a, "OK", 0, A_END); } -static void a_info(admin *a, const char *fmt, ...) +static void a_fail(admin *a, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - a_vwrite(a, "INFO", 0, fmt, ap); + a_vwrite(a, "FAIL", 0, fmt, &ap); va_end(ap); } -static void a_fail(admin *a, const char *fmt, ...) +/* --- @a_info@ --- * + * + * Arguments: @admin *a@ = connection + * @const char *fmt@ = format string + * @...@ = other arguments + * + * Returns: --- + * + * Use: Report information to an admin client. + */ + +void a_info(admin *a, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - a_vwrite(a, "FAIL", 0, fmt, ap); + a_vwrite(a, "INFO", 0, fmt, &ap); va_end(ap); } @@ -409,7 +422,7 @@ static void a_fail(admin *a, const char *fmt, ...) * @const char *fmt@ = pointer to format string * @const char *p@ = pointer to raw string * @size_t sz@ = size of raw string - * @va_list ap@ = arguments in list + * @va_list *ap@ = arguments in list * @...@ = other arguments * * Returns: --- @@ -443,7 +456,7 @@ static void a_rawalert(unsigned f_and, unsigned f_eq, const char *status, } static void a_valert(unsigned f_and, unsigned f_eq, const char *status, - const char *fmt, va_list ap) + const char *fmt, va_list *ap) { dstr d = DSTR_INIT; @@ -460,7 +473,7 @@ static void a_alert(unsigned f_and, unsigned f_eq, const char *status, va_list ap; va_start(ap, fmt); - a_valert(f_and, f_eq, status, fmt, ap); + a_valert(f_and, f_eq, status, fmt, &ap); va_end(ap); } @@ -480,11 +493,11 @@ void a_warn(const char *fmt, ...) va_start(ap, fmt); if (flags & F_INIT) - a_valert(0, 0, "WARN", fmt, ap); + a_valert(0, 0, "WARN", fmt, &ap); else { dstr d = DSTR_INIT; fprintf(stderr, "%s: ", QUIS); - a_vformat(&d, fmt, ap); + a_vformat(&d, fmt, &ap); dstr_putc(&d, '\n'); dstr_write(&d, stderr); dstr_destroy(&d); @@ -524,7 +537,7 @@ void a_notify(const char *fmt, ...) va_list ap; va_start(ap, fmt); - a_valert(AF_NOTE, AF_NOTE, "NOTE", fmt, ap); + a_valert(AF_NOTE, AF_NOTE, "NOTE", fmt, &ap); va_end(ap); } @@ -694,7 +707,7 @@ static void a_bginfo(admin_bgop *bg, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - a_vwrite(bg->a, "INFO", bg->tag, fmt, ap); + a_vwrite(bg->a, "INFO", bg->tag, fmt, &ap); va_end(ap); } @@ -702,7 +715,7 @@ static void a_bgfail(admin_bgop *bg, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - a_vwrite(bg->a, "FAIL", bg->tag, fmt, ap); + a_vwrite(bg->a, "FAIL", bg->tag, fmt, &ap); va_end(ap); } @@ -1011,7 +1024,7 @@ static void a_resolved(struct hostent *h, void *v) admin_resop *r = v; T( trace(T_ADMIN, "admin: resop %s resolved", BGTAG(r)); ) - TIMER; + QUICKRAND; if (!h) { a_bgfail(&r->bg, "resolve-error", "%s", r->addr, A_END); r->func(r, ARES_FAIL); @@ -1706,7 +1719,7 @@ static void acmd_algs(admin *a, unsigned ac, char *av[]) { peer *p; const kdata *kd; - const group *g; + const dhgrp *g; const algswitch *algs; if (!ac) @@ -1715,31 +1728,24 @@ static void acmd_algs(admin *a, unsigned ac, char *av[]) if ((p = a_findpeer(a, av[0])) == 0) return; kd = p->kx.kpriv; } - g = kd->g; + g = kd->grp; algs = &kd->algs; - a_info(a, - "kx-group=%s", g->ops->name, - "kx-group-order-bits=%lu", (unsigned long)mp_bits(g->r), - "kx-group-elt-bits=%lu", (unsigned long)g->nbits, - A_END); + g->ops->grpinfo(g, a); a_info(a, "hash=%s", algs->h->name, "mgf=%s", algs->mgf->name, "hash-sz=%lu", (unsigned long)algs->h->hashsz, A_END); a_info(a, - "cipher=%s", algs->c->name, - "cipher-keysz=%lu", (unsigned long)algs->cksz, - "cipher-blksz=%lu", (unsigned long)algs->c->blksz, - A_END); - a_info(a, - "cipher-data-limit=%lu", (unsigned long)algs->expsz, + "bulk-transform=%s", algs->bulk->ops->name, + "bulk-overhead=%lu", + (unsigned long)algs->bulk->ops->overhead(algs->bulk), A_END); + algs->bulk->ops->alginfo(algs->bulk, a); a_info(a, - "mac=%s", algs->m->name, - "mac-keysz=%lu", (unsigned long)algs->mksz, - "mac-tagsz=%lu", (unsigned long)algs->tagsz, + "cipher-data-limit=%lu", + (unsigned long)algs->bulk->ops->expsz(algs->bulk), A_END); a_ok(a); } @@ -1831,13 +1837,15 @@ static void acmd_peerinfo(admin *a, unsigned ac, char *av[]) { peer *p; const peerspec *ps; + const char *ptag; if ((p = a_findpeer(a, av[0])) != 0) { ps = p_spec(p); a_info(a, "tunnel=%s", ps->tops->name, A_END); a_info(a, "key=%s", p_tag(p), "current-key=%s", p->kx.kpub->tag, A_END); - a_info(a, "private-key=%s", p_privtag(p), + if ((ptag = p_privtag(p)) == 0) ptag = "(default)"; + a_info(a, "private-key=%s", ptag, "current-private-key=%s", p->kx.kpriv->tag, A_END); a_info(a, "keepalive=%lu", ps->t_ka, A_END); a_ok(a); @@ -2136,7 +2144,7 @@ static void a_line(char *p, size_t len, void *vp) char *av[16 + 1]; size_t ac; - TIMER; + QUICKRAND; if (a->f & AF_DEAD) return; if (!p) { @@ -2218,7 +2226,7 @@ static void a_accept(int fd, unsigned mode, void *v) { int nfd; struct sockaddr_un sun; - size_t sz = sizeof(sun); + socklen_t sz = sizeof(sun); if ((nfd = accept(fd, (struct sockaddr *)&sun, &sz)) < 0) { if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK &&