-/*
- dispatch any incoming meta requests
-*/
-int handle_incoming_meta_data(conn_list_t *cl)
-{
- int x, l = sizeof(x);
- int request, oldlen, i;
- int lenin = 0;
-cp
- if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
- {
- syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m"), __FILE__, __LINE__, cl->meta_socket);
- return -1;
- }
- if(x)
- {
- syslog(LOG_ERR, _("Metadata socket error: %s"), sys_errlist[x]);
- return -1;
- }
-
- if(cl->buflen >= MAXBUFSIZE)
- {
- syslog(LOG_ERR, _("Metadata read buffer overflow!"));
- return -1;
- }
-
- lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE-cl->buflen);
-
- if(lenin<=0)
- {
- syslog(LOG_ERR, _("Metadata socket read error: %m"));
- return -1;
- }
-
- oldlen = cl->buflen;
- cl->buflen += lenin;
-
- for(;;)
- {
- cl->reqlen = 0;
-
- for(i = oldlen; i < cl->buflen; i++)
- {
- if(cl->buffer[i] == '\n')
- {
- cl->buffer[i] = 0; /* replace end-of-line by end-of-string so we can use sscanf */
- cl->reqlen = i + 1;
- break;
- }
- }
-
- if(cl->reqlen)
- {
- if(debug_lvl > 2)
- syslog(LOG_DEBUG, _("Got request from " IP_ADDR_S " (" IP_ADDR_S "): %s"),
- IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip), cl->buffer);
- if(sscanf(cl->buffer, "%d", &request) == 1)
- {
- if((request < 0) || (request > 255) || (request_handlers[request] == NULL))
- {
- syslog(LOG_ERR, _("Unknown request from " IP_ADDR_S " (" IP_ADDR_S ")"),
- IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
- return -1;
- }
-
- if(request_handlers[request](cl)) /* Something went wrong. Probably scriptkiddies. Terminate. */
- {
- syslog(LOG_ERR, _("Error while processing request from " IP_ADDR_S " (" IP_ADDR_S ")"),
- IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
- return -1;
- }
- }
- else
- {
- syslog(LOG_ERR, _("Bogus data received from " IP_ADDR_S " (" IP_ADDR_S ")"),
- IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
- return -1;
- }
-
- cl->buflen -= cl->reqlen;
- memmove(cl->buffer, cl->buffer + cl->reqlen, cl->buflen);
- oldlen = 0;
- }
- else
- {
- break;
- }
- }
-
- cl->last_ping_time = time(NULL);
- cl->want_ping = 0;
-cp
- return 0;
-}
-