/* -*-c-*-
*
- * $Id$
- *
* Admin interface for configuration
*
* (c) 2001 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Trivial IP Encryption (TrIPE).
*
* 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 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.
/*----- Utility functions -------------------------------------------------*/
-/* --- @quotify@ --- *
- *
- * Arguments: @dstr *d@ = where to write the answer
- * @const char *p@ = string to quotify
- *
- * Returns: ---
- *
- * Use: Quotes the given string if necessary, according to our
- * quoting rules.
- */
-
-static void quotify(dstr *d, const char *p)
-{
- if (d->len)
- dstr_putc(d, ' ');
- if (*p && !p[strcspn(p, "\"' \t\n\v")])
- dstr_puts(d, p);
- else {
- dstr_putc(d, '\"');
- while (*p) {
- if (*p == '\\' || *p == '\"')
- dstr_putc(d, '\\');
- dstr_putc(d, *p++);
- }
- dstr_putc(d, '\"');
- }
-}
-
/* --- @a_vformat@ --- *
*
* Arguments: @dstr *d@ = where to leave the formatted message
const addr *a = va_arg(ap, const addr *);
switch (a->sa.sa_family) {
case AF_INET:
- quotify(d, "INET");
- quotify(d, inet_ntoa(a->sin.sin_addr));
+ u_quotify(d, "INET");
+ u_quotify(d, inet_ntoa(a->sin.sin_addr));
dstr_putf(d, " %u", (unsigned)ntohs(a->sin.sin_port));
break;
default:
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 *);
- while (*av) quotify(d, *av++);
+ while (*av) u_quotify(d, *av++);
} else if (strcmp(fmt, "?PEER") == 0)
- 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);
- quotify(d, strerror(errno));
+ u_quotify(d, strerror(errno));
} else
abort();
} else {
if (*fmt == '!') fmt++;
DRESET(&dd);
dstr_vputf(&dd, fmt, &ap);
- quotify(d, dd.buf);
+ u_quotify(d, dd.buf);
}
fmt = va_arg(ap, const char *);
}
if (tag) dstr_puts(&d, "BG");
dstr_puts(&d, status);
- if (tag) quotify(&d, tag);
+ if (tag) u_quotify(&d, tag);
a_vformat(&d, fmt, ap);
dstr_putc(&d, '\n');
dosend(a, d.buf, d.len);
{
admin *a, *aa;
dstr d = DSTR_INIT;
-
+
if (!(flags & F_INIT))
return;
dstr_puts(&d, status);
case 'h': t *= 60;
case 'm': t *= 60;
case 's': if (q[1] != 0)
- default: t = -1;
+ default: t = -1;
case 0: break;
}
- return (t);
+ return (t);
}
/* --- @a_findpeer@ --- *
sel_rmtimer(&r->t);
xfree(r->addr);
a_bgrelease(&r->bg);
-}
+}
/* --- @a_restimer@ --- *
*
r->addr = 0;
r->func = func;
if (mystrieq(av[i], "inet")) i++;
- if (ac - i != 2) {
- a_fail(a, "bad-addr-syntax", "[inet] ADDRESS PORT", A_END);
+ if (ac - i != 1 && ac - i != 2) {
+ a_fail(a, "bad-addr-syntax", "[inet] ADDRESS [PORT]", A_END);
goto fail;
}
r->sa.sin.sin_family = AF_INET;
r->sasz = sizeof(r->sa.sin);
r->addr = xstrdup(av[i]);
- pt = strtoul(av[i + 1], &p, 0);
- if (*p) {
- struct servent *s = getservbyname(av[i + 1], "udp");
- if (!s) {
- a_fail(a, "unknown-service", "%s", av[i + 1], A_END);
- goto fail;
+ if (!av[i + i])
+ pt = TRIPE_PORT;
+ else {
+ pt = strtoul(av[i + 1], &p, 0);
+ if (*p) {
+ struct servent *s = getservbyname(av[i + 1], "udp");
+ if (!s) {
+ a_fail(a, "unknown-service", "%s", av[i + 1], A_END);
+ goto fail;
+ }
+ pt = ntohs(s->s_port);
}
- pt = ntohs(s->s_port);
}
if (pt == 0 || pt >= 65536) {
a_fail(a, "invalid-port", "%lu", pt, A_END);
a->seq, BGTAG(r), r->addr); )
/* --- If the name is numeric, do it the easy way --- */
-
+
if (inet_aton(av[i], &r->sa.sin.sin_addr)) {
T( trace(T_ADMIN, "admin: resop %s done the easy way", BGTAG(r)); )
func(r, ARES_OK);
add->peer.name = 0;
add->peer.t_ka = 0;
add->peer.tops = tun_default;
+ add->peer.kxf = 0;
/* --- Parse options --- */
}
})
OPTTIME("-keepalive", t, { add->peer.t_ka = t; })
+ OPT("-cork", { add->peer.kxf |= KXF_CORK; })
});
/* --- Make sure someone's not got there already --- */
- if (!*av)
+ if (!av[0] || !av[1])
goto bad_syntax;
if (p_find(*av)) {
a_fail(a, "peer-exists", "%s", *av, A_END);
a_bgrelease(&pg->bg);
}
return;
-
+
bad_syntax:
a_fail(a, "bad-syntax", "%s", cmd, "[OPTIONS] PEER", cmd, A_END);
fail:
}
a_fail(a, "bad-%s-option", what, "%c", *p, A_END);
return (0);
- tropt_ok:;
+ tropt_ok:;
break;
}
p++;
a_notify("DAEMON", A_END);
if (a_stdin)
a_destroy(a_stdin);
- if (u_daemon())
+ if (daemonize())
a_fail(a, "daemon-error", "?ERRNO", A_END);
else {
flags |= F_DAEMON;
a_notify("NEWIFNAME", "?PEER", p, "%s", p_ifname(p), "%s", av[1], A_END);
p_setifname(p, av[1]);
a_ok(a);
- }
+ }
}
static void acmd_getchal(admin *a, unsigned ac, char *av[])
"ip-bytes-in=%lu", st->sz_ipin,
A_END);
a_info(a,
- "ip-packets-out=%lu", st->n_ipout,
+ "ip-packets-out=%lu", st->n_ipout,
"ip-bytes-out=%lu", st->sz_ipout,
A_END);
a_info(a, "rejected-packets=%lu", st->n_reject, A_END);
{ "tunnels", 0, 0, 0, acmd_tunnels },
{ "version", 0, 0, 0, acmd_version },
{ "warn", "MESSAGE ...", 1, 0xffff, acmd_warn },
- { "watch", "[OPTIONS]", 0, 1, acmd_watch },
+ { "watch", "[OPTIONS]", 0, 1, acmd_watch },
{ 0, 0, 0, 0, 0 }
};
for (c = acmdtab; c->name; c++) {
if (c->help)
a_info(a, "%s", c->name, "*%s", c->help, A_END);
- else
+ else
a_info(a, "%s", c->name, A_END);
}
a_ok(a);
if (c->argmin > ac || ac > c->argmax) {
if (!c->help)
a_fail(a, "bad-syntax", "%s", c->name, "", A_END);
- else
+ else
a_fail(a, "bad-syntax", "%s", c->name, "%s", c->help, A_END);
} else
c->func(a, ac, av + 1);