From: Mark Wooding Date: Sat, 20 Oct 2012 12:35:21 +0000 (+0100) Subject: yaid.c: Beef up `reply' with an extra token argument. X-Git-Tag: 1.0.0~16 X-Git-Url: https://git.distorted.org.uk/~mdw/yaid/commitdiff_plain/c809f9081d5cd7692c9c8c2773e49bb831d65aba yaid.c: Beef up `reply' with an extra token argument. Eliminates the need for `proxy_line' to call `write_to_client' explicitly, duplicating functionality. --- diff --git a/yaid.c b/yaid.c index 661b984..1355019 100644 --- a/yaid.c +++ b/yaid.c @@ -202,10 +202,12 @@ static void write_to_client(struct client *c, const char *fmt, ...) } } -static void reply(struct client *c, const char *ty, const char *msg) +static void reply(struct client *c, const char *ty, + const char *tok0, const char *tok1) { - write_to_client(c, "%u,%u:%s:%s\r\n", - c->q.s[L].port, c->q.s[R].port, ty, msg); + write_to_client(c, "%u,%u:%s:%s%s%s\r\n", + c->q.s[L].port, c->q.s[R].port, ty, + tok0, tok1 ? ":" : "", tok1 ? tok1 : ""); } const char *const errtok[] = { @@ -217,7 +219,7 @@ const char *const errtok[] = { static void reply_error(struct client *c, unsigned err) { assert(err < E_LIMIT); - reply(c, "ERROR", errtok[err]); + reply(c, "ERROR", errtok[err], 0); } static void skipws(const char **pp) @@ -278,15 +280,14 @@ static void proxy_line(char *line, size_t sz, void *p) if (strcmp(buf, "ERROR") == 0) { skipws(&q); logmsg(&px->c->q, LOG_ERR, "proxy error from %s: %s", px->nat, q); - reply(px->c, "ERROR", q); + reply(px->c, "ERROR", q, 0); } else if (strcmp(buf, "USERID") == 0) { if (idtoken(&q, buf, sizeof(buf))) goto syntax; skipws(&q); if (*q != ':') goto syntax; q++; skipws(&q); logmsg(&px->c->q, LOG_ERR, "user `%s'; proxy = %s, os = %s", q, px->nat, buf); - write_to_client(px->c, "%u,%u:USERID:%s:%s\r\n", - px->c->q.s[L].port, px->c->q.s[R].port, buf, q); + reply(px->c, "USERID", buf, q); } else goto syntax; goto done; @@ -498,13 +499,13 @@ match: switch (pol->act.act) { case A_NAME: logmsg(&c->q, LOG_INFO, "user `%s' (%d)", pw->pw_name, c->q.u.uid); - reply(c, "USERID:UNIX", pw->pw_name); + reply(c, "USERID", "UNIX", pw->pw_name); break; case A_TOKEN: user_token(buf); logmsg(&c->q, LOG_INFO, "user `%s' (%d); token = %s", pw->pw_name, c->q.u.uid, buf); - reply(c, "USERID:OTHER", buf); + reply(c, "USERID", "OTHER", buf); break; case A_DENY: logmsg(&c->q, LOG_INFO, "user `%s' (%d); denying", @@ -518,7 +519,7 @@ match: case A_LIE: logmsg(&c->q, LOG_INFO, "user `%s' (%d); lie = `%s'", pw->pw_name, c->q.u.uid, pol->act.u.lie); - reply(c, "USERID:UNIX", pol->act.u.lie); + reply(c, "USERID", "UNIX", pol->act.u.lie); break; default: abort();