📄 slpd_process.c
字号:
/**************************************************************************//* *//* Project: OpenSLP - OpenSource implementation of Service Location *//* Protocol Version 2 *//* *//* File: slpd_process.c *//* *//* Abstract: Processes incoming SLP messages *//* *//*-------------------------------------------------------------------------*//* *//* Please submit patches to http://www.openslp.org *//* *//*-------------------------------------------------------------------------*//* *//* Copyright (C) 2000 Caldera Systems, Inc *//* All rights reserved. *//* *//* Redistribution and use in source and binary forms, with or without *//* modification, are permitted provided that the following conditions are *//* met: */ /* *//* Redistributions of source code must retain the above copyright *//* notice, this list of conditions and the following disclaimer. *//* *//* Redistributions in binary form must reproduce the above copyright *//* notice, this list of conditions and the following disclaimer in *//* the documentation and/or other materials provided with the *//* distribution. *//* *//* Neither the name of Caldera Systems nor the names of its *//* contributors may be used to endorse or promote products derived *//* from this software without specific prior written permission. *//* *//* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *//* `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *//* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *//* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA *//* SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *//* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *//* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *//* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *//* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *//* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *//* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* *//***************************************************************************//*=========================================================================*//* slpd includes *//*=========================================================================*/#include "slpd_process.h"#include "slpd_property.h"#include "slpd_database.h"#include "slpd_knownda.h"#include "slpd_log.h"#ifdef ENABLE_SLPv2_SECURITY #include "slpd_spi.h"#endif/*=========================================================================*//* common code includes *//*=========================================================================*/#include "slp_xmalloc.h"#include "slp_message.h"#include "slp_compare.h"#ifdef ENABLE_SLPv2_SECURITY #include "slp_auth.h"#endif/*-------------------------------------------------------------------------*/int ProcessSASrvRqst(SLPMessage message, SLPBuffer* sendbuf, int errorcode)/*-------------------------------------------------------------------------*/{ int size = 0; SLPBuffer result = *sendbuf; if (message->body.srvrqst.scopelistlen == 0 || SLPIntersectStringList(message->body.srvrqst.scopelistlen, message->body.srvrqst.scopelist, G_SlpdProperty.useScopesLen, G_SlpdProperty.useScopes) != 0) { /*----------------------*/ /* Send back a SAAdvert */ /*----------------------*/ /*--------------------------------------------------------------*/ /* ensure the buffer is big enough to handle the whole SAAdvert */ /*--------------------------------------------------------------*/ size = message->header.langtaglen + 21; /* 14 bytes for header */ /* 2 bytes for url count */ /* 2 bytes for scope list len */ /* 2 bytes for attr list len */ /* 1 byte for authblock count */ size += G_SlpdProperty.myUrlLen; size += G_SlpdProperty.useScopesLen; /* TODO: size += G_SlpdProperty.SAAttributes */ result = SLPBufferRealloc(result,size); if (result == 0) { /* TODO: out of memory, what should we do here! */ errorcode = SLP_ERROR_INTERNAL_ERROR; goto FINISHED; } /*----------------*/ /* Add the header */ /*----------------*/ /*version*/ *(result->start) = 2; /*function id*/ *(result->start + 1) = SLP_FUNCT_SAADVERT; /*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 SAAdvert */ /*--------------------------*/ result->curpos = result->start + 14 + message->header.langtaglen; /* url len */ ToUINT16(result->curpos, G_SlpdProperty.myUrlLen); result->curpos = result->curpos + 2; /* url */ memcpy(result->curpos,G_SlpdProperty.myUrl,G_SlpdProperty.myUrlLen); result->curpos = result->curpos + G_SlpdProperty.myUrlLen; /* scope list len */ ToUINT16(result->curpos, G_SlpdProperty.useScopesLen); result->curpos = result->curpos + 2; /* scope list */ memcpy(result->curpos,G_SlpdProperty.useScopes,G_SlpdProperty.useScopesLen); result->curpos = result->curpos + G_SlpdProperty.useScopesLen; /* attr list len */ /* ToUINT16(result->curpos,G_SlpdProperty.SAAttributesLen) */ ToUINT16(result->curpos, 0); result->curpos = result->curpos + 2; /* attr list */ /* memcpy(result->start,G_SlpdProperty.SAAttributes,G_SlpdProperty.SAAttributesLen) */ /* authblock count */ *(result->curpos) = 0; } else { errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED; } FINISHED: *sendbuf = result; return errorcode;}/*-------------------------------------------------------------------------*/int ProcessDASrvRqst(SLPMessage message, SLPBuffer* sendbuf, int errorcode)/*-------------------------------------------------------------------------*/{ SLPBuffer tmp = 0; SLPMessage msg = 0; void* eh = 0; /*---------------------------------------------------------------------*/ /* Special case for when libslp asks slpd (through the loopback) about */ /* a known DAs. Fill sendbuf with DAAdverts from all known DAs. */ /*---------------------------------------------------------------------*/ if (ISLOCAL(message->peer.sin_addr)) { /* TODO: be smarter about how much memory is allocated here! */ /* 4096 may not be big enough to handle all DAAdverts */ *sendbuf = SLPBufferRealloc(*sendbuf, 4096); if (*sendbuf == 0) { return SLP_ERROR_INTERNAL_ERROR; } if (errorcode == 0) { /* Note: The weird *sendbuf code is making a single SLPBuffer */ /* that contains multiple DAAdverts. This is a special */ /* process that only happens for the DA SrvRqst through */ /* loopback to the SLPAPI */ eh = SLPDKnownDAEnumStart(); if (eh) { while (1) { if (SLPDKnownDAEnum(eh, &msg, &tmp) == 0) { break; } if (((*sendbuf)->curpos) + (tmp->end - tmp->start) > (*sendbuf)->end) { break; } /* TRICKY: fix up the xid */ tmp->curpos = tmp->start + 10; ToUINT16(tmp->curpos, message->header.xid); memcpy((*sendbuf)->curpos, tmp->start, tmp->end - tmp->start); (*sendbuf)->curpos = ((*sendbuf)->curpos) + (tmp->end - tmp->start); } SLPDKnownDAEnumEnd(eh); } /* Tack on a "terminator" DAAdvert */ SLPDKnownDAGenerateMyDAAdvert(SLP_ERROR_INTERNAL_ERROR, 0, message->header.xid, &tmp); if (((*sendbuf)->curpos) + (tmp->end - tmp->start) <= (*sendbuf)->end) { memcpy((*sendbuf)->curpos, tmp->start, tmp->end - tmp->start); (*sendbuf)->curpos = ((*sendbuf)->curpos) + (tmp->end - tmp->start); } /* mark the end of the sendbuf */ (*sendbuf)->end = (*sendbuf)->curpos; if (tmp) { SLPBufferFree(tmp); } } return errorcode; } /*---------------------------------------------------------------------*/ /* Normal case where a remote Agent asks for a DA */ /*---------------------------------------------------------------------*/ *sendbuf = SLPBufferRealloc(*sendbuf, SLP_MAX_DATAGRAM_SIZE); if (*sendbuf == 0) { return SLP_ERROR_INTERNAL_ERROR; } if (G_SlpdProperty.isDA) { if (message->body.srvrqst.scopelistlen == 0 || SLPIntersectStringList(message->body.srvrqst.scopelistlen, message->body.srvrqst.scopelist, G_SlpdProperty.useScopesLen, G_SlpdProperty.useScopes)) { errorcode = SLPDKnownDAGenerateMyDAAdvert(errorcode, 0, message->header.xid, sendbuf); } else { errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED; } } else { errorcode = SLP_ERROR_MESSAGE_NOT_SUPPORTED; } /*-----------------------------------------------*/ /* don't return errorcodes to multicast messages */ /*-----------------------------------------------*/ if (errorcode != 0) { if (message->header.flags & SLP_FLAG_MCAST || ISMCAST(message->peer.sin_addr)) { (*sendbuf)->end = (*sendbuf)->start; } } return errorcode;}/*-------------------------------------------------------------------------*/int ProcessSrvRqst(SLPMessage message, SLPBuffer* sendbuf, int errorcode)/*-------------------------------------------------------------------------*/{ int i; SLPUrlEntry* urlentry; SLPDDatabaseSrvRqstResult* db = 0; int size = 0; SLPBuffer result = *sendbuf;#ifdef ENABLE_SLPv2_SECURITY SLPAuthBlock* authblock = 0; int j;#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.srvrqst.prlistlen, message->body.srvrqst.prlist, G_SlpdProperty.interfacesLen, G_SlpdProperty.interfaces) ) { /* silently ignore */ result->end = result->start; goto FINISHED; } /*------------------------------------------------------------------*/ /* 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 (SLPSpiCanVerify(G_SlpdSpiHandle, message->body.srvrqst.spistrlen, message->body.srvrqst.spistr) == 0) { errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN; goto RESPOND; } } else if (message->body.srvrqst.spistrlen) { errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN; goto RESPOND; }#else if (message->body.srvrqst.spistrlen) { errorcode = SLP_ERROR_AUTHENTICATION_UNKNOWN; goto RESPOND; }#endif /*------------------------------------------------*/ /* Check to to see if a this is a special SrvRqst */ /*------------------------------------------------*/ if (SLPCompareString(message->body.srvrqst.srvtypelen, message->body.srvrqst.srvtype, 23,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -