/*-------------------------------------------------------------------------*/ void ProcessDAAdvert(SLPDPeerInfo* peerinfo, SLPMessage message, SLPBuffer result) /*-------------------------------------------------------------------------*/ { /* TODO: enable the following when we link to libslp and */ /* have SLPParseSrvURL() */ #if(0) SLPSrvURL* srvurl; struct hostent* he; #endif /* DAAdverts should never be replied to. Set result buffer to empty*/ result->end = result->start; /* Do not look at DAAdverts if we are a DA */ if(G_SlpdProperty.isDA == 0) { /* Only process if errorcode is not set */ if(message->body.daadvert.errorcode == SLP_ERROR_OK) { /* TODO: enable the following when we link to libslp and */ /* have SLPParseSrvURL() */ #if(0) /* yes, we could just get the host addr from peer info. Looking */ /* it up is safer */ if(SLPParseSrvURL(message->body.daadvert.url, &srvurl) == 0) { he = gethostbyname(srvurl->s_pcHost); if(he) { /* Add the DA to a list of known DAs (ignore return)*/ SLPDKnownDAAdd((struct in_addr*)(he->h_addr_list[0]), message->body.daadvert.bootstamp, message->body.daadvert.scopelist, message->body.daadvert.scopelistlen); } SLPFree(srvurl); } #endif /* TODO: the following is allows for easy DA masquarading (unsafe) */ /* remove it when the above is fixed */ SLPDKnownDAAdd(&(peerinfo->peeraddr.sin_addr), message->body.daadvert.bootstamp, message->body.daadvert.scopelist, message->body.daadvert.scopelistlen); } /* If necessary log that we received a DAAdvert */ if(G_SlpdProperty.traceDATraffic) { SLPDLogDATrafficMsg("IN", peerinfo, message); } } }
/** Process a DAAdvert message. * * @param[in] message - The message to process. * @param[in] recvbuf - The buffer associated with @p message. * @param[out] sendbuf - The response buffer to fill. * @param[in] errorcode - The error code from the client request. * * @return Zero on success, or a non-zero SLP error on failure. * * @internal */ static int ProcessDAAdvert(SLPMessage * message, SLPBuffer recvbuf, SLPBuffer * sendbuf, int errorcode) { SLPBuffer result = *sendbuf; /* If errorcode is set, we can not be sure that message is good Go directly to send response code */ if (errorcode) goto RESPOND; /* If net.slp.passiveDADetection is turned off then we ignore DAAdverts with xid == 0 */ if(G_SlpdProperty.passiveDADetection == 0 && message->header.xid == 0) goto RESPOND; /* If net.slp.DAActiveDiscoveryInterval == 0 then we ignore DAAdverts with xid != 0 */ if (G_SlpdProperty.DAActiveDiscoveryInterval == 0 && message->header.xid != 0) goto RESPOND; /* Validate the authblocks */ #ifdef ENABLE_SLPv2_SECURITY errorcode = SLPAuthVerifyDAAdvert(G_SlpdSpiHandle, 0, &message->body.daadvert); if (errorcode == 0) #endif { /* Only process if errorcode is not set */ if (message->body.daadvert.errorcode == SLP_ERROR_OK) errorcode = SLPDKnownDAAdd(message, recvbuf); } RESPOND: /* DAAdverts should never be replied to. Set result buffer to empty*/ result->end = result->start; *sendbuf = result; return errorcode; }
/*-------------------------------------------------------------------------*/ int ProcessDAAdvert(struct sockaddr_in* peeraddr, SLPMessage message, SLPBuffer* sendbuf, int errorcode) /*-------------------------------------------------------------------------*/ { SLPDAEntry daentry; SLPBuffer result = *sendbuf; /*--------------------------------------------------------------*/ /* If errorcode is set, we can not be sure that message is good */ /* Go directly to send response code */ /*--------------------------------------------------------------*/ if(errorcode) { goto RESPOND; } /* Only process if errorcode is not set */ if(message->body.daadvert.errorcode == SLP_ERROR_OK) { /* TODO: Authentication stuff here */ daentry.langtaglen = message->header.langtaglen; daentry.langtag = message->header.langtag; daentry.bootstamp = message->body.daadvert.bootstamp; daentry.urllen = message->body.daadvert.urllen; daentry.url = message->body.daadvert.url; daentry.scopelistlen = message->body.daadvert.scopelistlen; daentry.scopelist = message->body.daadvert.scopelist; daentry.attrlistlen = message->body.daadvert.attrlistlen; daentry.attrlist = message->body.daadvert.attrlist; daentry.spilistlen = message->body.daadvert.spilistlen; daentry.spilist = message->body.daadvert.spilist; SLPDKnownDAAdd(&(peeraddr->sin_addr),&daentry); } RESPOND: /* DAAdverts should never be replied to. Set result buffer to empty*/ result->end = result->start; *sendbuf = result; return errorcode; }
/*=========================================================================*/ int SLPDKnownDAInit() /* Initializes the KnownDA list. Removes all entries and adds entries */ /* that are statically configured. */ /* */ /* returns zero on success, Non-zero on failure */ /*=========================================================================*/ { char* temp; char* tempend; char* slider1; char* slider2; struct hostent* he; struct in_addr daaddr; /* Allow us to send 3 Active DA discovery service requests */ G_SlpdProperty.activeDiscoveryAttempts = G_SlpdProperty.activeDADetection * 3; if(G_SlpdProperty.isDA) { /* TODO: some day we may put something here for DA to DA communication */ temp = 0; } else { slider1 = slider2 = temp = strdup(G_SlpdProperty.DAAddresses); } if (temp) { tempend = temp + strlen(temp); while (slider1 != tempend) { while (*slider2 && *slider2 != ',') slider2++; *slider2 = 0; he = gethostbyname(slider1); if (he) { daaddr.s_addr = *((unsigned long*)(he->h_addr_list[0])); SLPDKnownDAAdd(&daaddr, 0, G_SlpdProperty.useScopes, G_SlpdProperty.useScopesLen); // For now do not contact the DA to see if it is up. Just // assume that the statically configured DAs are available. // KnownDAConnect() will remove them if they can not be // connected to. //sock = SLPNetworkConnectStream(&peeraddr,timeout); //if(sock >= 0) //{ // result += KnownDADiscoveryRqstRply(sock, &peeraddr); // close(sock); //} } slider1 = slider2; slider2++; } free(temp); } return 0; }