/** SLPFindSrvs callback routine for NetworkRqstRply. * * @param[in] errorcode - The network operation error code. * @param[in] peeraddr - The network address of the responder. * @param[in] replybuf - The response buffer from the network request. * @param[in] cookie - Callback context data from ProcessSrvReg. * * @return SLP_FALSE (to stop any iterative callbacks). * * @internal */ static SLPBoolean ProcessSrvRplyCallback(SLPError errorcode, void * peeraddr, SLPBuffer replybuf, void * cookie) { SLPMessage * replymsg; SLPBoolean result = SLP_TRUE; SLPHandleInfo * handle = (SLPHandleInfo *)cookie; #ifdef ENABLE_SLPv2_SECURITY SLPBoolean securityEnabled = SLPPropertyAsBoolean("net.slp.securityEnabled"); #endif /* Check the errorcode and bail if it is set. */ if (errorcode != SLP_OK) return CollateToSLPSrvURLCallback(handle, 0, 0, errorcode); /* parse the replybuf */ replymsg = SLPMessageAlloc(); if (replymsg) { if (!SLPMessageParseBuffer(peeraddr, 0, replybuf, replymsg)) { if (replymsg->header.functionid == SLP_FUNCT_SRVRPLY && replymsg->body.srvrply.errorcode == 0) { int i; SLPUrlEntry * urlentry = replymsg->body.srvrply.urlarray; for (i = 0; i < replymsg->body.srvrply.urlcount; i++) { #ifdef ENABLE_SLPv2_SECURITY /* Validate the service authblocks. */ if (securityEnabled && SLPAuthVerifyUrl(handle->hspi, 1, &urlentry[i])) continue; /* Authentication failed, skip this URLEntry. */ #endif result = CollateToSLPSrvURLCallback(handle, urlentry[i].url, (unsigned short)urlentry[i].lifetime, SLP_OK); if (result == SLP_FALSE) break; } } else if (replymsg->header.functionid == SLP_FUNCT_DAADVERT && replymsg->body.daadvert.errorcode == 0) { #ifdef ENABLE_SLPv2_SECURITY if (securityEnabled && SLPAuthVerifyDAAdvert(handle->hspi, 1, &replymsg->body.daadvert)) { /* Verification failed. Ignore message. */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif result = CollateToSLPSrvURLCallback(handle, replymsg->body.daadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK); } else if (replymsg->header.functionid == SLP_FUNCT_SAADVERT) { #ifdef ENABLE_SLPv2_SECURITY if (securityEnabled && SLPAuthVerifySAAdvert(handle->hspi, 1, &replymsg->body.saadvert)) { /* Verification failed. Ignore message. */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif result = CollateToSLPSrvURLCallback(handle, replymsg->body.saadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK); } } SLPMessageFree(replymsg); } return result; }
/*-------------------------------------------------------------------------*/ SLPBoolean ProcessSrvRplyCallback(SLPError errorcode, struct sockaddr_in* peerinfo, SLPBuffer replybuf, void* cookie) /*-------------------------------------------------------------------------*/ { int i; SLPUrlEntry* urlentry; SLPMessage replymsg; PSLPHandleInfo handle = (PSLPHandleInfo) cookie; SLPBoolean result = SLP_TRUE; #ifdef ENABLE_SLPv2_SECURITY int securityenabled; securityenabled = SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled")); #endif /*-------------------------------------------*/ /* Check the errorcode and bail if it is set */ /*-------------------------------------------*/ if(errorcode != SLP_OK) { return ColateSLPSrvURLCallback((SLPHandle)handle, 0, 0, errorcode, handle->params.findsrvs.cookie); } /*--------------------*/ /* Parse the replybuf */ /*--------------------*/ replymsg = SLPMessageAlloc(); if(replymsg) { if(SLPMessageParseBuffer(peerinfo,replybuf,replymsg) == 0) { if(replymsg->header.functionid == SLP_FUNCT_SRVRPLY && replymsg->body.srvrply.errorcode == 0) { urlentry = replymsg->body.srvrply.urlarray; for(i=0;i<replymsg->body.srvrply.urlcount;i++) { #ifdef ENABLE_SLPv2_SECURITY /*-------------------------------*/ /* Validate the authblocks */ /*-------------------------------*/ if(securityenabled && SLPAuthVerifyUrl(handle->hspi, 1, &(urlentry[i]))) { /* authentication failed skip this URLEntry */ continue; } #endif /*--------------------------------*/ /* Send the URL to the API caller */ /*--------------------------------*/ /* TRICKY: null terminate the url by setting the authcount to 0 */ ((char*)(urlentry[i].url))[urlentry[i].urllen] = 0; result = ColateSLPSrvURLCallback((SLPHandle)handle, urlentry[i].url, (unsigned short)urlentry[i].lifetime, SLP_OK, handle->params.findsrvs.cookie); if(result == SLP_FALSE) { break; } } } else if(replymsg->header.functionid == SLP_FUNCT_DAADVERT && replymsg->body.daadvert.errorcode == 0) { #ifdef ENABLE_SLPv2_SECURITY if(securityenabled && SLPAuthVerifyDAAdvert(handle->hspi, 1, &(replymsg->body.daadvert))) { /* Verification failed. Ignore message */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif ((char*)(replymsg->body.daadvert.url))[replymsg->body.daadvert.urllen] = 0; result = ColateSLPSrvURLCallback((SLPHandle)handle, replymsg->body.daadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK, handle->params.findsrvs.cookie); } else if(replymsg->header.functionid == SLP_FUNCT_SAADVERT) { #ifdef ENABLE_SLPv2_SECURITY if(securityenabled && SLPAuthVerifySAAdvert(handle->hspi, 1, &(replymsg->body.saadvert))) { /* Verification failed. Ignore message */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif ((char*)(replymsg->body.saadvert.url))[replymsg->body.saadvert.urllen] = 0; result = ColateSLPSrvURLCallback((SLPHandle)handle, replymsg->body.saadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK, handle->params.findsrvs.cookie); } } SLPMessageFree(replymsg); } return result; }
/** Process a general service deregistration message. * * @param[in] message - The message to process. * @param[out] sendbuf - The response buffer to fill. * @param[in] errorcode - The error code from the client request. * * @return A non-zero value if @p message should be silently dropped. * * @internal */ static int ProcessSrvDeReg(SLPMessage * message, 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 also do not process mcast srvreg or srvdereg messages */ if (errorcode || message->header.flags & SLP_FLAG_MCAST) goto RESPOND; /* make sure that we handle the scope */ if (SLPIntersectStringList(message->body.srvdereg.scopelistlen, message->body.srvdereg.scopelist, G_SlpdProperty.useScopesLen, G_SlpdProperty.useScopes)) { #ifdef ENABLE_SLPv2_SECURITY /* malidate the authblocks */ errorcode = SLPAuthVerifyUrl(G_SlpdSpiHandle, 0, &message->body.srvdereg.urlentry); if (errorcode == 0) #endif { /* remove the service from the database */ errorcode = SLPDDatabaseDeReg(message); } } else errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED; RESPOND: /* don't do anything multicast SrvDeReg (set result empty) */ if (message->header.flags & SLP_FLAG_MCAST || SLPNetIsMCast(&message->peer)) { result->end = result->start; goto FINISHED; } /* ensure the buffer is big enough to handle the whole srvack */ result = SLPBufferRealloc(result, message->header.langtaglen + 16); if (result == 0) { errorcode = SLP_ERROR_INTERNAL_ERROR; goto FINISHED; } /* Add the header */ /* version */ *result->curpos++ = 2; /* function id */ *result->curpos++ = SLP_FUNCT_SRVACK; /* length */ PutUINT24(&result->curpos, message->header.langtaglen + 16); /* flags */ PutUINT16(&result->curpos, 0); /* ext offset */ PutUINT24(&result->curpos, 0); /* xid */ PutUINT16(&result->curpos, message->header.xid); /* lang tag len */ PutUINT16(&result->curpos, message->header.langtaglen); /* lang tag */ memcpy(result->curpos, message->header.langtag, message->header.langtaglen); result->curpos += message->header.langtaglen; /* Add the errorcode */ PutUINT16(&result->curpos, errorcode); FINISHED: *sendbuf = result; return errorcode; }