コード例 #1
0
ファイル: slpd_process.c プロジェクト: Distrotech/openslp
/** 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;
}
コード例 #2
0
ファイル: libslp_findsrvs.c プロジェクト: ncultra/openslp
/*-------------------------------------------------------------------------*/
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;
}
コード例 #3
0
ファイル: libslp_findsrvs.c プロジェクト: Distrotech/openslp
/** 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;
}