X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprotocol.c;h=20a2fc3552a7d8d8ccd4c3b2c5479e8da34af3e3;hp=d52fd541f7ae441ddc3724bc3f7ac64bb99a6eb2;hb=c78a204f06182f50b0812c8e4fef6163e82097bf;hpb=2c412009e5805f04c650889b19fcb38531f2aa50 diff --git a/src/protocol.c b/src/protocol.c index d52fd541..20a2fc35 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28.4.35 2000/09/22 16:20:07 guus Exp $ + $Id: protocol.c,v 1.28.4.36 2000/09/26 14:06:06 guus Exp $ */ #include "config.h" @@ -43,6 +43,7 @@ #include "net.h" #include "netutl.h" #include "protocol.h" +#include "meta.h" #include "system.h" @@ -61,7 +62,7 @@ int check_id(char *id) return 1; } -/* Generic outgoing request routine - takes care of logging and error detection as well */ +/* Generic request routines - takes care of logging and error detection as well */ int send_request(conn_list_t *cl, const char *format, int request, /*args*/ ...) { @@ -89,37 +90,38 @@ cp return send_meta(cl, buffer, length); } - -int send_meta(conn_list_t *cl, const char *buffer, int length) +int receive_request(conn_list_t *cl) { -cp - if(debug_lvl >= DEBUG_META) - syslog(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s): %s"), int length, - cl->name, cl->hostname, buffer); - - if(cl->status.encryptin) + int request; +cp + if(sscanf(cl->buffer, "%d", &request) == 1) { - /* FIXME: Do encryption */ + if((request < 0) || (request > 255) || (request_handlers[request] == NULL)) + { + syslog(LOG_ERR, _("Unknown request from %s (%s)"), + cl->name, cl->hostname); + return -1; + } + else + { + if(debug_lvl > DEBUG_PROTOCOL) + syslog(LOG_DEBUG, _("Got %s from %s (%s)"), + request_name[request], cl->name, cl->hostname); + } + if(request_handlers[request](cl)) + /* Something went wrong. Probably scriptkiddies. Terminate. */ + { + syslog(LOG_ERR, _("Error while processing %s from %s (%s)"), + request_name[request], cl->name, cl->hostname); + return -1; + } } - - if(write(cl->meta_socket, buffer, length) < 0) + else { - syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %m"), cl->name, cl->hostname); + syslog(LOG_ERR, _("Bogus data received from %s (%s)"), + cl->name, cl->hostname); return -1; } -cp - return 0; -} - -int broadcast_meta(conn_list_t *cl, const char *buffer, int length) -{ - conn_list_t *p; -cp - for(p = conn_list; p != NULL; p = p->next) - if(p != cl && p->status.meta && p->status.active) - send_meta(p, buffer, length); -cp - return 0; } /* Connection protocol: