⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slpd_process.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 4 页
字号:
        errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED;    }    RESPOND:    /*---------------------------------------------------------*/    /* don't do anything multicast SrvDeReg (set result empty) */    /*---------------------------------------------------------*/    if (message->header.flags & SLP_FLAG_MCAST ||        ISMCAST(message->peer.sin_addr))    {        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->start)       = 2;    /*function id*/    *(result->start + 1)   = SLP_FUNCT_SRVACK;    /*length*/    ToUINT24(result->start + 2,message->header.langtaglen + 16);    /*flags*/    ToUINT16(result->start + 5,0);    /*ext offset*/    ToUINT24(result->start + 7,0);    /*xid*/    ToUINT16(result->start + 10,message->header.xid);    /*lang tag len*/    ToUINT16(result->start + 12,message->header.langtaglen);    /*lang tag*/    memcpy(result->start + 14,           message->header.langtag,           message->header.langtaglen);    /*-------------------*/    /* Add the errorcode */    /*-------------------*/    ToUINT16(result->start + 14 + message->header.langtaglen, errorcode);    FINISHED:    *sendbuf = result;    return errorcode;}/*-------------------------------------------------------------------------*/int ProcessSrvAck(SLPMessage message,                  SLPBuffer* sendbuf,                  int errorcode)/*-------------------------------------------------------------------------*/{    /* Ignore SrvAck.  Just return errorcode to caller */    SLPBuffer result = *sendbuf;    result->end = result->start;    return 0;}/*-------------------------------------------------------------------------*/int ProcessAttrRqst(SLPMessage message,                    SLPBuffer* sendbuf,                    int errorcode)/*-------------------------------------------------------------------------*/{    SLPDDatabaseAttrRqstResult* db              = 0;    int                         size            = 0;    SLPBuffer                   result          = *sendbuf;#ifdef ENABLE_SLPv2_SECURITY    int               i;    unsigned char*    generatedauth       = 0;    int               generatedauthlen    = 0;    unsigned char*    opaqueauth          = 0;    int               opaqueauthlen       = 0;#endif    /*--------------------------------------------------------------*/    /* If errorcode is set, we can not be sure that message is good */    /* Go directly to send response code                            */    /*--------------------------------------------------------------*/    if (errorcode)    {        goto RESPOND;    }    /*-------------------------------------------------*/    /* Check for one of our IP addresses in the prlist */    /*-------------------------------------------------*/    if (SLPIntersectStringList(message->body.attrrqst.prlistlen,                               message->body.attrrqst.prlist,                               G_SlpdProperty.interfacesLen,                               G_SlpdProperty.interfaces))    {        /* Silently ignore */        result->end = result->start;        goto FINISHED;    }    /*------------------------------------*/    /* Make sure that we handle the scope */    /*------ -----------------------------*/    if (SLPIntersectStringList(message->body.attrrqst.scopelistlen,                               message->body.attrrqst.scopelist,                               G_SlpdProperty.useScopesLen,                               G_SlpdProperty.useScopes))    {        /*------------------------------------------------------------------*/        /* Make sure that we handle at least verify registrations made with */        /* the requested SPI.  If we can't then have to return an error     */        /* because there is no way we can return URL entries that ares      */        /* signed in a way the requester can understand                     */        /*------------------------------------------------------------------*/#ifdef ENABLE_SLPv2_SECURITY        if (G_SlpdProperty.securityEnabled)        {            if (message->body.attrrqst.taglistlen == 0)            {                /* We can send back entire attribute strings without */                /* generating a new attribute authentication block   */                /* we just use the one sent by the registering agent */                /* which we have to have been able to verify         */                if (SLPSpiCanVerify(G_SlpdSpiHandle,                                    message->body.attrrqst.spistrlen,                                    message->body.attrrqst.spistr) == 0)                {                    errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN;                    goto RESPOND;                }            }            else            {                /* We have to be able to *generate* (sign) authentication */                /* blocks for attrrqst with taglists since it is possible */                /* that the returned attributes are a subset of what the  */                /* original registering agent sent                        */                if (SLPSpiCanSign(G_SlpdSpiHandle,                                  message->body.attrrqst.spistrlen,                                  message->body.attrrqst.spistr) == 0)                {                    errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN;                    goto RESPOND;                }            }        }        else        {            if (message->body.attrrqst.spistrlen)            {                errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN;                goto RESPOND;            }        }#else        if (message->body.attrrqst.spistrlen)        {            errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN;            goto RESPOND;        }#endif        /*---------------------------------*/        /* Find attributes in the database */        /*---------------------------------*/        errorcode = SLPDDatabaseAttrRqstStart(message,&db);    }    else    {        errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED;    }    RESPOND:    /*----------------------------------------------------------------*/    /* Do not send error codes or empty replies to multicast requests */    /*----------------------------------------------------------------*/    if (errorcode != 0 || db->attrlistlen == 0)    {        if (message->header.flags & SLP_FLAG_MCAST ||            ISMCAST(message->peer.sin_addr))        {            result->end = result->start;            goto FINISHED;          }    }    /*--------------------------------------------------------------*/    /* ensure the buffer is big enough to handle the whole attrrply */    /*--------------------------------------------------------------*/    size = message->header.langtaglen + 19; /* 14 bytes for header     */                                            /*  2 bytes for error code */                                            /*  2 bytes for attr-list len */                                            /*  1 byte for the authcount */     if(errorcode == 0)    {        size += db->attrlistlen;        #ifdef ENABLE_SLPv2_SECURITY            /*------------------------------------------------------------------*/        /* Generate authblock if necessary or just use the one was included */        /* by registering agent.  Reserve sufficent space for either case.  */        /*------------------------------------------------------------------*/        if (G_SlpdProperty.securityEnabled &&            message->body.attrrqst.spistrlen )        {            if (message->body.attrrqst.taglistlen == 0)            {                for (i=0; i<db->authcount;i++)                {                    if (SLPCompareString(db->autharray[i].spistrlen,                                         db->autharray[i].spistr,                                         message->body.attrrqst.spistrlen,                                         message->body.attrrqst.spistr) == 0)                    {                        opaqueauth = db->autharray[i].opaque;                        opaqueauthlen = db->autharray[i].opaquelen;                        break;                    }                }            }            else            {                errorcode = SLPAuthSignString(G_SlpdSpiHandle,                                              message->body.attrrqst.spistrlen,                                              message->body.attrrqst.spistr,                                              db->attrlistlen,                                              db->attrlist,                                              &generatedauthlen,                                              &generatedauth);                opaqueauthlen = generatedauthlen;                opaqueauth = generatedauth;            }            size += opaqueauthlen;        }    #endif    }    /*-------------------*/    /* Alloc the  buffer */    /*-------------------*/    result = SLPBufferRealloc(result,size);    if (result == 0)    {        errorcode = SLP_ERROR_INTERNAL_ERROR;        goto FINISHED;    }    /*----------------*/    /* Add the header */    /*----------------*/    /*version*/    *(result->start)       = 2;    /*function id*/    *(result->start + 1)   = SLP_FUNCT_ATTRRPLY;    /*length*/    ToUINT24(result->start + 2,size);    /*flags*/    ToUINT16(result->start + 5,             (size > SLP_MAX_DATAGRAM_SIZE ? SLP_FLAG_OVERFLOW : 0));    /*ext offset*/    ToUINT24(result->start + 7,0);    /*xid*/    ToUINT16(result->start + 10,message->header.xid);    /*lang tag len*/    ToUINT16(result->start + 12,message->header.langtaglen);    /*lang tag*/    memcpy(result->start + 14,           message->header.langtag,           message->header.langtaglen);    /*--------------------------*/    /* Add rest of the AttrRqst */    /*--------------------------*/    result->curpos = result->start + 14 + message->header.langtaglen;    /* error code*/    ToUINT16(result->curpos, errorcode);    result->curpos = result->curpos + 2;    if (errorcode == 0)    {        /* attr-list len */        ToUINT16(result->curpos, db->attrlistlen);        result->curpos = result->curpos + 2;        if (db->attrlistlen)        {            memcpy(result->curpos, db->attrlist, db->attrlistlen);        }        result->curpos = result->curpos + db->attrlistlen;        /* authentication block */#ifdef ENABLE_SLPv2_SECURITY        if (opaqueauth)        {            /* authcount */            *(result->curpos) = 1;            result->curpos = result->curpos + 1;            memcpy(result->curpos,                   opaqueauth,                   opaqueauthlen);            result->curpos = result->curpos + opaqueauthlen;        }        else#endif        {            /* authcount */            *(result->curpos) = 0;            result->curpos = result->curpos + 1;        }    }    FINISHED:#ifdef ENABLE_SLPv2_SECURITY        /* free the generated authblock if any */    if (generatedauth) xfree(generatedauth);#endif    if (db) SLPDDatabaseAttrRqstEnd(db);    *sendbuf = result;    return errorcode;}        /*-------------------------------------------------------------------------*/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)    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -