int process_request (CTL_MSG * msg, struct sockaddr_in *sa_in, CTL_RESPONSE * rp) { CTL_MSG *ptr; if (debug) { print_request ("process_request", msg); } if (acl_match (msg, sa_in)) { syslog (LOG_NOTICE, "dropping request: %s@%s", msg->l_name, inet_ntoa (sa_in->sin_addr)); return 1; } rp->vers = TALK_VERSION; rp->type = msg->type; rp->id_num = htonl (0); if (msg->vers != TALK_VERSION) { syslog (LOG_ERR, "Bad protocol version %d", msg->vers); rp->answer = BADVERSION; return 0; } msg->id_num = ntohl (msg->id_num); msg->addr.sa_family = ntohs (msg->addr.sa_family); if (msg->addr.sa_family != AF_INET) { syslog (LOG_ERR, "Bad address, family %d", msg->addr.sa_family); rp->answer = BADADDR; return 0; } msg->ctl_addr.sa_family = ntohs (msg->ctl_addr.sa_family); if (msg->ctl_addr.sa_family != AF_INET) { syslog (LOG_WARNING, "Bad control address, family %d", msg->ctl_addr.sa_family); rp->answer = BADCTLADDR; return 0; } /* FIXME: compare address and sa_in? */ msg->pid = ntohl (msg->pid); switch (msg->type) { case ANNOUNCE: do_announce (msg, rp); break; case LEAVE_INVITE: ptr = find_request (msg); if (ptr) { rp->id_num = htonl (ptr->id_num); rp->answer = SUCCESS; } else insert_table (msg, rp); break; case LOOK_UP: ptr = find_match (msg); if (ptr) { rp->id_num = htonl (ptr->id_num); rp->addr = ptr->addr; rp->addr.sa_family = htons (ptr->addr.sa_family); rp->answer = SUCCESS; } else rp->answer = NOT_HERE; break; case DELETE: rp->answer = delete_invite (msg->id_num); break; default: rp->answer = UNKNOWN_REQUEST; break; } if (debug) print_response ("process_request response", rp); return 0; }
void process_request(CTL_MSG *mp, CTL_RESPONSE *rp) { CTL_MSG *ptr; char *s; rp->vers = TALK_VERSION; rp->type = mp->type; rp->id_num = htonl(0); if (mp->vers != TALK_VERSION) { syslog(LOG_WARNING, "bad protocol version %d", mp->vers); rp->answer = BADVERSION; return; } mp->id_num = ntohl(mp->id_num); mp->addr.sa_family = ntohs(mp->addr.sa_family); if (mp->addr.sa_family != AF_INET) { syslog(LOG_WARNING, "bad address, family %d", mp->addr.sa_family); rp->answer = BADADDR; return; } mp->ctl_addr.sa_family = ntohs(mp->ctl_addr.sa_family); if (mp->ctl_addr.sa_family != AF_INET) { syslog(LOG_WARNING, "bad control address, family %d", mp->ctl_addr.sa_family); rp->answer = BADCTLADDR; return; } for (s = mp->l_name; *s; s++) if (!isprint(*s)) { syslog(LOG_NOTICE, "illegal user name. Aborting"); rp->answer = FAILED; return; } mp->pid = ntohl(mp->pid); if (debug) print_request("process_request", mp); switch (mp->type) { case ANNOUNCE: do_announce(mp, rp); break; case LEAVE_INVITE: ptr = find_request(mp); if (ptr != NULL) { rp->id_num = htonl(ptr->id_num); rp->answer = SUCCESS; } else insert_table(mp, rp); break; case LOOK_UP: ptr = find_match(mp); if (ptr != NULL) { rp->id_num = htonl(ptr->id_num); rp->addr = ptr->addr; rp->addr.sa_family = htons(ptr->addr.sa_family); rp->answer = SUCCESS; } else rp->answer = NOT_HERE; break; case DELETE: rp->answer = delete_invite(mp->id_num); break; default: rp->answer = UNKNOWN_REQUEST; break; } if (debug) print_response("process_request", rp); }
void process_request(CTL_MSG *mp, CTL_RESPONSE *rp) { CTL_MSG *ptr; char *s; rp->vers = TALK_VERSION; rp->type = mp->type; rp->id_num = htonl(0); if (mp->vers != TALK_VERSION) { syslog(LOG_WARNING, "Bad protocol version %d", mp->vers); rp->answer = BADVERSION; return; } mp->id_num = ntohl(mp->id_num); if (ntohs(mp->addr.sa_family) != AF_INET) { syslog(LOG_WARNING, "Bad address, family %d", ntohs(mp->addr.sa_family)); rp->answer = BADADDR; return; } if (ntohs(mp->ctl_addr.sa_family) != AF_INET) { syslog(LOG_WARNING, "Bad control address, family %d", ntohs(mp->ctl_addr.sa_family)); rp->answer = BADCTLADDR; return; } for (s = mp->l_name; *s; s++) if (!isprint((unsigned char)*s)) { syslog(LOG_NOTICE, "Illegal user name. Aborting"); rp->answer = FAILED; return; } if (memcmp(&satosin(&rp->addr)->sin_addr, &satosin(&mp->ctl_addr)->sin_addr, sizeof(struct in_addr))) { char buf1[32], buf2[32]; strlcpy(buf1, inet_ntoa(satosin(&rp->addr)->sin_addr), sizeof(buf1)); strlcpy(buf2, inet_ntoa(satosin(&mp->ctl_addr)->sin_addr), sizeof(buf2)); syslog(LOG_WARNING, "addresses are different, %s != %s", buf1, buf2); } rp->addr.sa_family = 0; mp->pid = ntohl(mp->pid); if (debug) print_request("process_request", mp); switch (mp->type) { case ANNOUNCE: do_announce(mp, rp); break; case LEAVE_INVITE: ptr = find_request(mp); if (ptr != (CTL_MSG *)0) { rp->id_num = htonl(ptr->id_num); rp->answer = SUCCESS; } else insert_table(mp, rp); break; case LOOK_UP: ptr = find_match(mp); if (ptr != (CTL_MSG *)0) { rp->id_num = htonl(ptr->id_num); rp->addr = ptr->addr; rp->addr.sa_family = ptr->addr.sa_family; rp->answer = SUCCESS; } else rp->answer = NOT_HERE; break; case DELETE: rp->answer = delete_invite(mp->id_num); break; default: rp->answer = UNKNOWN_REQUEST; break; } if (debug) print_response("process_request", rp); }