+bool receive_request(connection_t *c) {
+ int request;
+
+ if(sscanf(c->buffer, "%d", &request) == 1) {
+ if((request < 0) || (request >= LAST) || !request_handlers[request]) {
+ ifdebug(META)
+ logger(LOG_DEBUG, "Unknown request from %s (%s): %s",
+ c->name, c->hostname, c->buffer);
+ else
+ logger(LOG_ERR, "Unknown request from %s (%s)",
+ c->name, c->hostname);
+
+ return false;
+ } else {
+ ifdebug(PROTOCOL) {
+ ifdebug(META)
+ logger(LOG_DEBUG, "Got %s from %s (%s): %s",
+ request_name[request], c->name, c->hostname,
+ c->buffer);
+ else
+ logger(LOG_DEBUG, "Got %s from %s (%s)",
+ request_name[request], c->name, c->hostname);
+ }
+ }
+
+ if((c->allow_request != ALL) && (c->allow_request != request)) {
+ logger(LOG_ERR, "Unauthorized request from %s (%s)", c->name,
+ c->hostname);
+ return false;
+ }
+
+ if(!request_handlers[request](c)) {
+ /* Something went wrong. Probably scriptkiddies. Terminate. */
+
+ logger(LOG_ERR, "Error while processing %s from %s (%s)",
+ request_name[request], c->name, c->hostname);
+ return false;
+ }
+ } else {
+ logger(LOG_ERR, "Bogus data received from %s (%s)",
+ c->name, c->hostname);
+ return false;
+ }