Пример #1
0
/** Process a general service registration 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 A non-zero value if @p message should be silently dropped.
 *
 * @internal
 */
static int ProcessSrvReg(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  also do not process mcast
      srvreg or srvdereg messages
    */
   if (errorcode || message->header.flags & SLP_FLAG_MCAST 
         || SLPNetIsMCast(&(message->peer)))
      goto RESPOND;

   /* make sure that we handle the scope */
   if (SLPIntersectStringList(message->body.srvreg.scopelistlen, 
         message->body.srvreg.scopelist, G_SlpdProperty.useScopesLen,
         G_SlpdProperty.useScopes))
   {

#ifdef ENABLE_SLPv2_SECURITY

      /* Validate the authblocks       */
      errorcode = SLPAuthVerifyUrl(G_SlpdSpiHandle, 0,
            &message->body.srvreg.urlentry);
      if (errorcode == 0)
      {
         errorcode = SLPAuthVerifyString(G_SlpdSpiHandle, 0,
               message->body.srvreg.attrlistlen, 
               message->body.srvreg.attrlist,
               message->body.srvreg.authcount,
               message->body.srvreg.autharray);
      }
      if (errorcode == 0)
#endif
      {
         /* Put the registration in the database. */

         /* TRICKY: Remember the recvbuf was duplicated back in
          * SLPDProcessMessage 
          */
         if (SLPNetIsLoopback(&(message->peer)))
            message->body.srvreg.source= SLP_REG_SOURCE_LOCAL;
         else
            message->body.srvreg.source = SLP_REG_SOURCE_REMOTE;

         errorcode = SLPDDatabaseReg(message, recvbuf);
      }
   }
   else
      errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED;

RESPOND:    

   /* don't send back reply anything multicast SrvReg (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;
}
Пример #2
0
/*-------------------------------------------------------------------------*/
SLPBoolean ProcessAttrRplyCallback(SLPError errorcode,
                                   struct sockaddr_in* peerinfo,
                                   SLPBuffer replybuf,
                                   void* cookie)
/*-------------------------------------------------------------------------*/
{
    SLPMessage      replymsg;
    SLPAttrRply*    attrrply;
    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)
    {
        handle->params.findattrs.callback((SLPHandle)handle,
                                          0,
                                          errorcode,
                                          handle->params.findattrs.cookie);
        return SLP_FALSE;
    }

    /*--------------------*/
    /* Parse the replybuf */
    /*--------------------*/
    replymsg = SLPMessageAlloc();
    if(replymsg)
    {
        if(SLPMessageParseBuffer(peerinfo,replybuf,replymsg) == 0 &&
                replymsg->header.functionid == SLP_FUNCT_ATTRRPLY &&
                replymsg->body.attrrply.errorcode == 0)
        {
            attrrply = &(replymsg->body.attrrply);

            if(attrrply->attrlistlen)
            {

#ifdef ENABLE_SLPv2_SECURITY
                /*-------------------------------*/
                /* Validate the authblocks       */
                /*-------------------------------*/
                if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled")) &&
                        SLPAuthVerifyString(handle->hspi,
                                            1,
                                            attrrply->attrlistlen,
                                            attrrply->attrlist,
                                            attrrply->authcount,
                                            attrrply->autharray))
                {
                    /* Could not verify the attr auth block */
                    SLPMessageFree(replymsg);
                    return result;
                }
#endif
                /*---------------------------------------*/
                /* Send the attribute list to the caller */
                /*---------------------------------------*/
                /* TRICKY: null terminate the attrlist by setting the authcount to 0 */
                ((char*)(attrrply->attrlist))[attrrply->attrlistlen] = 0;

                /* Call the callback function */
                result = handle->params.findattrs.callback((SLPHandle)handle,
                         attrrply->attrlist,
                         attrrply->errorcode * -1,
                         handle->params.findattrs.cookie);
            }
        }

        SLPMessageFree(replymsg);
    }

    return result;
}