X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/5b9f3d3788bafcba79c893b1afc6a1c77bc77d20..cb2c2bfcff87c4d6959fe3ccf47a4b509f933e9c:/server/admin.c diff --git a/server/admin.c b/server/admin.c index eb965c1c..aafe0b9c 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 ------------------------------------------------------*/ @@ -285,14 +284,11 @@ void a_vformat(dstr *d, const char *fmt, va_list *ap) } else if (strcmp(fmt, "?B64") == 0) { const octet *p = va_arg(*ap, const octet *); size_t n = va_arg(*ap, size_t); - base64_ctx b64; + codec *b64 = base64_class.encoder(CDCF_NOEQPAD, "", 0); dstr_putc(d, ' '); - base64_init(&b64); - b64.indent = ""; - b64.maxline = 0; - base64_encode(&b64, p, n, d); - base64_encode(&b64, 0, 0, d); - while (d->len && d->buf[d->len - 1] == '=') d->len--; + b64->ops->code(b64, p, n, d); + b64->ops->code(b64, 0, 0, d); + b64->ops->destroy(b64); } else if (strcmp(fmt, "?TOKENS") == 0) { const char *const *av = va_arg(*ap, const char *const *); while (*av) u_quotify(d, *av++); @@ -1114,7 +1110,6 @@ static void a_resolve(admin *a, admin_resop *r, const char *tag, goto fail; } r->sa.sin.sin_family = AF_INET; - r->sasz = sizeof(r->sa.sin); r->addr = xstrdup(av[i]); if (!av[i + 1]) pt = TRIPE_PORT; @@ -1227,7 +1222,6 @@ static void a_doadd(admin_resop *r, int rc) T( trace(T_ADMIN, "admin: done add op %s", BGTAG(add)); ) if (rc == ARES_OK) { - add->peer.sasz = add->r.sasz; add->peer.sa = add->r.sa; if (p_findbyaddr(&add->r.sa)) a_bgfail(&add->r.bg, "peer-addr-exists", "?ADDR", &add->r.sa, A_END); @@ -1240,6 +1234,7 @@ static void a_doadd(admin_resop *r, int rc) } if (add->peer.tag) xfree(add->peer.tag); + if (add->peer.privtag) xfree(add->peer.privtag); xfree(add->peer.name); } @@ -1289,14 +1284,12 @@ static void acmd_add(admin *a, unsigned ac, char *av[]) OPTTIME("-keepalive", t, { add->peer.t_ka = t; }) OPT("-cork", { add->peer.f |= KXF_CORK; }) OPTARG("-key", arg, { - if (add->peer.tag) - xfree(add->peer.tag); + if (add->peer.tag) xfree(add->peer.tag); add->peer.tag = xstrdup(arg); }) OPT("-mobile", { add->peer.f |= PSF_MOBILE; }) OPTARG("-priv", arg, { - if (add->peer.privtag) - xfree(add->peer.privtag); + if (add->peer.privtag) xfree(add->peer.privtag); add->peer.privtag = xstrdup(arg); }) }); @@ -1790,35 +1783,43 @@ static void acmd_getchal(admin *a, unsigned ac, char *av[]) static void acmd_checkchal(admin *a, unsigned ac, char *av[]) { - base64_ctx b64; + codec *b64 = base64_class.decoder(CDCF_NOEQPAD); + int err; buf b; dstr d = DSTR_INIT; - base64_init(&b64); - base64_decode(&b64, av[0], strlen(av[0]), &d); - base64_decode(&b64, 0, 0, &d); - buf_init(&b, d.buf, d.len); - if (c_check(&b) || BBAD(&b) || BLEFT(&b)) - a_fail(a, "invalid-challenge", A_END); - else - a_ok(a); + if ((err = b64->ops->code(b64, av[0], strlen(av[0]), &d)) != 0 || + (err = b64->ops->code(b64, 0, 0, &d)) != 0) + a_fail(a, "bad-base64", "%s", codec_strerror(err), A_END); + else { + buf_init(&b, d.buf, d.len); + if (c_check(&b) || BBAD(&b) || BLEFT(&b)) + a_fail(a, "invalid-challenge", A_END); + else + a_ok(a); + } + b64->ops->destroy(b64); dstr_destroy(&d); } static void acmd_greet(admin *a, unsigned ac, char *av[]) { peer *p; - base64_ctx b64; + int err; + codec *b64; dstr d = DSTR_INIT; - if ((p = a_findpeer(a, av[0])) != 0) { - base64_init(&b64); - base64_decode(&b64, av[1], strlen(av[1]), &d); - base64_decode(&b64, 0, 0, &d); + if ((p = a_findpeer(a, av[0])) == 0) return; + b64 = base64_class.decoder(CDCF_NOEQPAD); + if ((err = b64->ops->code(b64, av[1], strlen(av[1]), &d)) != 0 || + (err = b64->ops->code(b64, 0, 0, &d)) != 0) + a_fail(a, "bad-base64", "%s", codec_strerror(err), A_END); + else { p_greet(p, d.buf, d.len); - dstr_destroy(&d); a_ok(a); } + b64->ops->destroy(b64); + dstr_destroy(&d); } static void acmd_addr(admin *a, unsigned ac, char *av[]) @@ -1849,6 +1850,9 @@ static void acmd_peerinfo(admin *a, unsigned ac, char *av[]) 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_info(a, "corked=%s", BOOL(p->kx.f&KXF_CORK), + "mobile=%s", BOOL(ps->f&PSF_MOBILE), + A_END); a_ok(a); } } @@ -1978,6 +1982,7 @@ static const acmd acmdtab[] = { { "reload", 0, 0, 0, acmd_reload }, { "servinfo", 0, 0, 0, acmd_servinfo }, { "setifname", "PEER NEW-NAME", 2, 2, acmd_setifname }, + { "stats", "PEER", 1, 1, acmd_stats }, { "svcclaim", "SERVICE VERSION", 2, 2, acmd_svcclaim }, { "svcensure", "SERVICE [VERSION]", 1, 2, acmd_svcensure }, { "svcfail", "JOBID TOKENS...", 1, 0xffff, acmd_svcfail }, @@ -1988,7 +1993,6 @@ static const acmd acmdtab[] = { { "svcrelease", "SERVICE", 1, 1, acmd_svcrelease }, { "svcsubmit", "[OPTIONS] SERVICE TOKENS...", 2, 0xffff, acmd_svcsubmit }, - { "stats", "PEER", 1, 1, acmd_stats }, #ifndef NTRACE { "trace", "[OPTIONS]", 0, 1, acmd_trace }, #endif