X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/460b9539a7c15580e41a71bbc0f47ae776238915..c00fce3ab1dc8b810a439e81e419d7b8ae1d97b9:/server/server.c diff --git a/server/server.c b/server/server.c index 89ff5ab..6ee11c9 100644 --- a/server/server.c +++ b/server/server.c @@ -69,6 +69,12 @@ int volume_left, volume_right; /* last known volume */ +/** @brief Accept all well-formed login attempts + * + * Used in debugging. + */ +int wideopen; + struct listener { const char *name; int pf; @@ -373,28 +379,30 @@ static int c_user(struct conn *c, sink_writes(ev_writer_sink(c->w), "530 authentication failure\n"); return 1; } - } + } else + strcpy(host, "local"); /* find the user */ for(n = 0; n < config->allow.n && strcmp(config->allow.s[n].s[0], vec[0]); ++n) ; /* if it's a real user check whether the response is right */ - if(n < config->allow.n) { - res = authhash(c->nonce, sizeof c->nonce, config->allow.s[n].s[1]); - if(res && !strcmp(res, vec[1])) { - c->who = vec[0]; - /* currently we only bother logging remote connections */ - if(c->l->pf != PF_UNIX) - info("S%x %s connected from %s", c->tag, vec[0], host); - sink_writes(ev_writer_sink(c->w), "230 OK\n"); - return 1; - } + if(n >= config->allow.n) { + info("S%x unknown user '%s' from %s", c->tag, vec[0], host); + sink_writes(ev_writer_sink(c->w), "530 authentication failed\n"); + return 1; + } + res = authhash(c->nonce, sizeof c->nonce, config->allow.s[n].s[1], + config->authorization_algorithm); + if(wideopen || (res && !strcmp(res, vec[1]))) { + c->who = vec[0]; + /* currently we only bother logging remote connections */ + if(c->l->pf != PF_UNIX) + info("S%x %s connected from %s", c->tag, vec[0], host); + sink_writes(ev_writer_sink(c->w), "230 OK\n"); + return 1; } /* oops, response was wrong */ - if(c->l->pf != PF_UNIX) - info("S%x authentication failure for %s from %s", c->tag, vec[0], host); - else - info("S%x authentication failure for %s", c->tag, vec[0]); + info("S%x authentication failure for %s from %s", c->tag, vec[0], host); sink_writes(ev_writer_sink(c->w), "530 authentication failed\n"); return 1; } @@ -752,6 +760,12 @@ static int c_log(struct conn *c, sink_printf(ev_writer_sink(c->w), "%"PRIxMAX" state %s\n", (uintmax_t)now, paused ? "pause" : "resume"); + if(playing) + sink_printf(ev_writer_sink(c->w), "%"PRIxMAX" state playing\n", + (uintmax_t)now); + /* Initial volume */ + sink_printf(ev_writer_sink(c->w), "%"PRIxMAX" volume %d %d\n", + (uintmax_t)now, volume_left, volume_right); c->lo = xmalloc(sizeof *c->lo); c->lo->fn = logclient; c->lo->user = c; @@ -893,6 +907,13 @@ static int c_get_global(struct conn *c, return 1; } +static int c_nop(struct conn *c, + char attribute((unused)) **vec, + int attribute((unused)) nvec) { + sink_printf(ev_writer_sink(c->w), "250 Quack\n"); + return 1; +} + #define C_AUTH 0001 /* must be authenticated */ #define C_TRUSTED 0002 /* must be trusted user */ @@ -916,6 +937,7 @@ static const struct command { { "log", 0, 0, c_log, C_AUTH }, { "move", 2, 2, c_move, C_AUTH }, { "moveafter", 1, INT_MAX, c_moveafter, C_AUTH }, + { "nop", 0, 0, c_nop, C_AUTH }, { "part", 3, 3, c_part, C_AUTH }, { "pause", 0, 0, c_pause, C_AUTH }, { "play", 1, 1, c_play, C_AUTH }, @@ -1063,7 +1085,15 @@ static int listen_callback(ev_source *ev, c->reader = reader_callback; c->l = l; gcry_randomize(c->nonce, sizeof c->nonce, GCRY_STRONG_RANDOM); - sink_printf(ev_writer_sink(c->w), "231 %s\n", hex(c->nonce, sizeof c->nonce)); + if(!strcmp(config->authorization_algorithm, "sha1") + || !strcmp(config->authorization_algorithm, "SHA1")) { + sink_printf(ev_writer_sink(c->w), "231 %s\n", + hex(c->nonce, sizeof c->nonce)); + } else { + sink_printf(ev_writer_sink(c->w), "231 %s %s\n", + config->authorization_algorithm, + hex(c->nonce, sizeof c->nonce)); + } return 0; } @@ -1102,4 +1132,3 @@ comment-column:40 fill-column:79 End: */ -/* arch-tag:eb9b30c87008880f3f53535101356ab5 */