From: Narasimha S. <nsh...@us...> - 2012-06-25 17:27:25
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "SFCB - Small Footprint CIM Broker". The branch, master has been updated via 7ec7ffe9ddfd787c1a9df94aecf6a7f529bffe91 (commit) from 8423c96e7c9a04236a0d4becef70bdb64d3669c0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7ec7ffe9ddfd787c1a9df94aecf6a7f529bffe91 Author: Narasimha Sharoff <nsh...@us...> Date: Mon Jun 25 10:25:18 2012 -0700 [ 3534977 ] sfcb custom library and hostname ----------------------------------------------------------------------- Summary of changes: diff --git a/ChangeLog b/ChangeLog index 162c9be..6321ae0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-06-25 Narasimha Sharoff <nsh...@us...> + + * cimslpCMPI.c, cimXmlGen.c, cimXmlGen.h, cimXmlRequest.c, + control.c, Makefile.am, providerMgr.h, sfcb.cfg.pre.in, + sfcBroker.c, sfcCustomLib.c, support.c: + [ 3534977 ] sfcb custom library and hostname + 2012-06-15 Chris Buccella <buc...@li...> * cimXmlParser.c: diff --git a/Makefile.am b/Makefile.am index f4dd810..8ebf6e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -92,11 +92,7 @@ HTTP_ADAPTER_LIBS = libsfcHttpAdapter.la HTTP_ADAPTER_LIBS_LINK = -lsfcHttpAdapter endif -if SLP_HOSTNAME_LIB -SLP_HOSTNAME_LIBS = libsfcSlpHostname.la -else -SLP_HOSTNAME_LIBS = -endif +SFC_CUSTOM_LIB = libsfcCustomLib.la if QUALREP QUALREP_LIBS = libsfcQualifierProvider.la @@ -150,7 +146,7 @@ sfcblib_LTLIBRARIES = \ $(QUALREP_LIBS) \ $(INDICATION_LIBS) \ $(PAM_LIBS) \ - $(SLP_HOSTNAME_LIBS) \ + $(SFC_CUSTOM_LIB) \ $(ACCOUNT_PASSTHRU_LIBS) if TEST_ENABLED @@ -244,10 +240,8 @@ libsfcHttpAdapter_la_LIBADD=-lsfcBrokerCore $(CIMXMLCODEC_LIBS_LINK) libsfcHttpAdapter_la_DEPENDENCIES=libsfcBrokerCore.la $(CIMXMLCODEC_LIBS) endif -#if SLP_HOSTNAME_LIB -libsfcSlpHostname_la_SOURCES = \ - sfcSlpHostname.c -#endif +libsfcCustomLib_la_SOURCES = \ + sfcCustomLib.c libsfcBasicAuthentication_la_SOURCES = \ sfcBasicAuthentication.c diff --git a/NEWS b/NEWS index 5509fca..de21215 100644 --- a/NEWS +++ b/NEWS @@ -101,6 +101,7 @@ New Features: - 3513390 Enforce LD and subscription limits - 3527920 RI and http responsecodes - 3534659 Match SfcbLocal to sfcc update +- 3534977 sfcb custom library and hostname Bugs Fixed: - 3514627 unsupported sfcb.cfg param - use exit call diff --git a/cimRequest.c b/cimRequest.c index 58a0ac6..bd8dbdb 100644 --- a/cimRequest.c +++ b/cimRequest.c @@ -505,11 +505,14 @@ genEnumResponses(BinRequestContext * binCtx, sb = UtilFactory->newStrinBuffer(1024); if (binCtx->oHdr->type == OPS_EnumerateClassNames) - enum2xml(enm, sb, binCtx->type, XML_asClassName, binCtx->bHdr->flags); + enum2xml(enm, sb, binCtx->type, XML_asClassName, binCtx->bHdr->flags, + binCtx->httpHost); else if (binCtx->oHdr->type == OPS_EnumerateClasses) - enum2xml(enm, sb, binCtx->type, XML_asClass, binCtx->bHdr->flags); + enum2xml(enm, sb, binCtx->type, XML_asClass, binCtx->bHdr->flags, + binCtx->httpHost); else - enum2xml(enm, sb, binCtx->type, binCtx->xmlAs, binCtx->bHdr->flags); + enum2xml(enm, sb, binCtx->type, binCtx->xmlAs, binCtx->bHdr->flags, + binCtx->httpHost); _SFCB_RETURN(sb); } @@ -599,7 +602,7 @@ genFirstChunkResponses(BinRequestContext * binCtx, UtilStringBuffer *sb; RespSegments rs; - _SFCB_ENTER(TRACE_CIMXMLPROC, "genResponses"); + _SFCB_ENTER(TRACE_CIMXMLPROC, "genFirstChunkResponses"); sb = genEnumResponses(binCtx, resp, arrlen); @@ -635,7 +638,7 @@ genLastChunkResponses(BinRequestContext * binCtx, UtilStringBuffer *sb; RespSegments rs; - _SFCB_ENTER(TRACE_CIMXMLPROC, "genResponses"); + _SFCB_ENTER(TRACE_CIMXMLPROC, "genLastChunkResponses"); sb = genEnumResponses(binCtx, resp, arrlen); @@ -786,6 +789,7 @@ enumClassNames(CimRequestContext * ctx, RequestHdr * hdr) _SFCB_ENTER(TRACE_CIMXMLPROC, "enumClassNames"); hdr->binCtx->commHndl = ctx->commHndl; + hdr->binCtx->httpHost = ctx->host; _SFCB_TRACE(1, ("--- Getting Provider context")); irc = getProviderContext(hdr->binCtx); @@ -831,6 +835,7 @@ enumClasses(CimRequestContext * ctx, RequestHdr * hdr) hdr->binCtx->commHndl = ctx->commHndl; hdr->binCtx->chunkFncs = ctx->chunkFncs; + hdr->binCtx->httpHost = ctx->host; _SFCB_TRACE(1, ("--- Getting Provider context")); irc = getProviderContext(hdr->binCtx); @@ -1046,6 +1051,7 @@ enumInstanceNames(CimRequestContext * ctx, RequestHdr * hdr) RespSegments rs; _SFCB_TRACE(1, ("--- Getting Provider context")); + hdr->binCtx->httpHost = ctx->host; irc = getProviderContext(hdr->binCtx); _SFCB_TRACE(1, ("--- Provider context gotten")); @@ -1092,6 +1098,7 @@ enumInstances(CimRequestContext * ctx, RequestHdr * hdr) hdr->binCtx->commHndl = ctx->commHndl; hdr->binCtx->chunkFncs = ctx->chunkFncs; + hdr->binCtx->httpHost = ctx->host; _SFCB_TRACE(1, ("--- Getting Provider context")); irc = getProviderContext(hdr->binCtx); @@ -1141,6 +1148,7 @@ execQuery(CimRequestContext * ctx, RequestHdr * hdr) hdr->binCtx->commHndl = ctx->commHndl; hdr->binCtx->chunkFncs = ctx->chunkFncs; + hdr->binCtx->httpHost = ctx->host; if (ctx->teTrailers == 0) hdr->chunkedMode = hdr->binCtx->chunkedMode = 0; @@ -1197,6 +1205,7 @@ associatorNames(CimRequestContext * ctx, RequestHdr * hdr) hdr->binCtx->commHndl = ctx->commHndl; hdr->binCtx->chunkFncs = ctx->chunkFncs; hdr->chunkedMode = hdr->binCtx->chunkedMode = 0; + hdr->binCtx->httpHost = ctx->host; _SFCB_TRACE(1, ("--- Getting Provider context")); irc = getProviderContext(hdr->binCtx); @@ -1238,6 +1247,7 @@ associators(CimRequestContext * ctx, RequestHdr * hdr) hdr->binCtx->commHndl = ctx->commHndl; hdr->binCtx->chunkFncs = ctx->chunkFncs; + hdr->binCtx->httpHost = ctx->host; if (ctx->teTrailers == 0) hdr->chunkedMode = hdr->binCtx->chunkedMode = 0; @@ -1295,6 +1305,7 @@ referenceNames(CimRequestContext * ctx, RequestHdr * hdr) BinResponseHdr **resp; hdr->binCtx->commHndl = ctx->commHndl; + hdr->binCtx->httpHost = ctx->host; _SFCB_TRACE(1, ("--- Getting Provider context")); irc = getProviderContext(hdr->binCtx); @@ -1336,6 +1347,7 @@ references(CimRequestContext * ctx, RequestHdr * hdr) hdr->binCtx->commHndl = ctx->commHndl; hdr->binCtx->chunkFncs = ctx->chunkFncs; + hdr->binCtx->httpHost = ctx->host; if (ctx->teTrailers == 0) hdr->chunkedMode = hdr->binCtx->chunkedMode = 0; diff --git a/cimXmlGen.c b/cimXmlGen.c index 46f056a..95ebed7 100644 --- a/cimXmlGen.c +++ b/cimXmlGen.c @@ -51,6 +51,7 @@ extern CMPIData opGetKeyCharsAt(CMPIObjectPath * cop, unsigned int index, extern CMPIData __ift_internal_getPropertyAt(const CMPIInstance *ci, CMPICount i, char **name, CMPIStatus *rc, int readonly); +extern int getCustomHostname(char *httpHost, char **hn, unsigned int len); const char *opGetClassNameChars(CMPIObjectPath * cop); @@ -620,7 +621,7 @@ lnsPath2xml(CMPIObjectPath * ci, UtilStringBuffer * sb) } static int -nsPath2xml(CMPIObjectPath * ci, UtilStringBuffer * sb) +nsPath2xml(CMPIObjectPath * ci, UtilStringBuffer * sb, char *httpHost) { _SFCB_ENTER(TRACE_CIMXMLPROC, "nsPath2xml"); char *hn = CMGetCharPtr(CMGetHostname(ci, NULL)); @@ -632,13 +633,9 @@ nsPath2xml(CMPIObjectPath * ci, UtilStringBuffer * sb) sb->ft->appendChars(sb, hn); } else { // get the hostname - hn = malloc(HOST_NAME_MAX); - if (gethostname(hn, HOST_NAME_MAX) == 0) { - sb->ft->appendChars(sb, hn); - } else { - // Using localhost - SFCB_APPENDCHARS_BLOCK(sb, "localhost"); - } + hn = calloc(1,HOST_NAME_MAX); + getCustomHostname(httpHost, &hn, HOST_NAME_MAX); + sb->ft->appendChars(sb, hn); free(hn); } SFCB_APPENDCHARS_BLOCK(sb, "</HOST>\n"); @@ -672,7 +669,7 @@ refValue2xml(CMPIObjectPath * ci, UtilStringBuffer * sb) char *hn = CMGetCharPtr(CMGetHostname(ci, NULL)); if (hn && *hn && ns && *ns) { SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n"); - nsPath2xml(ci, sb); + nsPath2xml(ci, sb, NULL); } else if (ns && *ns) { SFCB_APPENDCHARS_BLOCK(sb, "<LOCALINSTANCEPATH>\n"); lnsPath2xml(ci, sb); @@ -1148,7 +1145,7 @@ className2xml(CMPIObjectPath * op, UtilStringBuffer * sb) int enum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb, CMPIType type, - int xmlAs, unsigned int flags) + int xmlAs, unsigned int flags, char *httpHost) { CMPIObjectPath *cop; CMPIInstance *ci; @@ -1164,7 +1161,7 @@ enum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb, CMPIType type, else if (xmlAs == XML_asObjectPath) { SFCB_APPENDCHARS_BLOCK(sb, "<OBJECTPATH>\n"); SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n"); - nsPath2xml(cop, sb); + nsPath2xml(cop, sb, httpHost); instanceName2xml(cop, sb); SFCB_APPENDCHARS_BLOCK(sb, "</INSTANCEPATH>\n"); SFCB_APPENDCHARS_BLOCK(sb, "</OBJECTPATH>\n"); @@ -1179,7 +1176,7 @@ enum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb, CMPIType type, if (xmlAs == XML_asObj) { SFCB_APPENDCHARS_BLOCK(sb, "<VALUE.OBJECTWITHPATH>\n"); SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n"); - nsPath2xml(cop, sb); + nsPath2xml(cop, sb, httpHost); } else SFCB_APPENDCHARS_BLOCK(sb, "<VALUE.NAMEDINSTANCE>\n"); instanceName2xml(cop, sb); diff --git a/cimXmlGen.h b/cimXmlGen.h index fb76691..3580f44 100644 --- a/cimXmlGen.h +++ b/cimXmlGen.h @@ -50,7 +50,8 @@ extern int instance2xml(CMPIInstance *ci, UtilStringBuffer * sb, unsigned int flags); extern int args2xml(CMPIArgs * args, UtilStringBuffer * sb); extern int enum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb, - CMPIType type, int xmlAs, unsigned int flags); + CMPIType type, int xmlAs, unsigned int flags, + char *httpHost); extern int qualiEnum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb); extern CMPIValue union2CMPIValue(CMPIType type, char *val, XtokValueArray * arr); diff --git a/cimslpCMPI.c b/cimslpCMPI.c index b974efb..ad16cf0 100644 --- a/cimslpCMPI.c +++ b/cimslpCMPI.c @@ -38,6 +38,8 @@ extern void libraryName(const char *dir, const char *location, extern char *configfile; CMPIContext *prepareUpcall(const CMPIContext *ctx); +extern int getCustomSlpHostname(char **hn) + // helper function ... until better solution is found to get to the // interop Namespace char ** @@ -249,28 +251,6 @@ getSLPData(cimomConfig cfg, const CMPIBroker *_broker, // to the calling function char *sn; -#ifdef SLP_HOSTNAME_LIB - static void *hostnameLib = NULL; - static getSlpHostname gethostname; - char *ln; - char dlName[512]; - int err; - - err = 1; - if (getControlChars("slpHostnamelib", &ln) == 0) { - libraryName(NULL, ln, dlName, 512); - if ((hostnameLib = dlopen(dlName, RTLD_LAZY))) { - gethostname = dlsym(hostnameLib, "_sfcGetSlpHostname"); - if (gethostname) - err = 0; - } - } - if (err) - mlogf(M_ERROR, M_SHOW, - "--- SLP Hostname exit %s not found. Defaulting to system hostname.\n", - dlName); -#endif - _SFCB_ENTER(TRACE_SLP, "getSLPData"); memset(&rs, 0, sizeof(cimSLPService)); @@ -290,17 +270,7 @@ getSLPData(cimomConfig cfg, const CMPIBroker *_broker, sn = myGetProperty(ci[0], "SystemName"); #ifdef SLP_HOSTNAME_LIB - if (!err) { - char *tmp; - if ((err = gethostname(&tmp))) { - free(sn); - sn = tmp; - } else { - printf - ("-#- SLP call to %s for hostname failed. Defaulting to system hostname.\n", - dlName); - } - } + getCustomSlpHostname(char **sn); #endif rs.url_syntax = getUrlSyntax(sn, cfg.commScheme, cfg.port); rs.service_hi_name = myGetProperty(ci[0], "ElementName"); diff --git a/control.c b/control.c index d89f4c3..ff3903b 100644 --- a/control.c +++ b/control.c @@ -71,9 +71,9 @@ Control init[] = { #ifdef HAVE_SLP {"enableSlp", 2, "true"}, {"slpRefreshInterval", 1, "600"}, - {"slpHostnameLib", 0, "sfcSlpHostname"}, #endif {"provProcs", 1, "32"}, + {"sfcbCustomLib", 0, "sfcCustomLib"}, {"basicAuthLib", 0, "sfcBasicAuthentication"}, {"basicAuthEntry", 0, "_sfcBasicAuthenticate"}, {"doBasicAuth", 2, "false"}, diff --git a/providerMgr.h b/providerMgr.h index 1c4d91a..53244de 100644 --- a/providerMgr.h +++ b/providerMgr.h @@ -139,6 +139,7 @@ typedef struct binRequestContext { CMPIType type; ProvAddr provA; ProvAddr *pAs; + char *httpHost; unsigned long pCount, pDone; unsigned long rCount; diff --git a/sfcBroker.c b/sfcBroker.c index 7d2e4b7..e293b89 100644 --- a/sfcBroker.c +++ b/sfcBroker.c @@ -73,6 +73,9 @@ extern void uninitSocketPairs(); extern void sunsetControl(); extern void uninitGarbageCollector(); +extern int loadHostnameLib(); +extern void unloadHostnameLib(); + extern TraceId traceIds[]; extern unsigned long exFlags; @@ -255,6 +258,8 @@ stopBroker(void *p) _SFCB_TRACE_STOP(); + unloadHostnameLib(); + if (restartBroker) { char *emsg = strerror(errno); execvp("sfcbd", restartArgv); @@ -865,6 +870,11 @@ main(int argc, char *argv[]) startHttp = 1; } + if (loadHostnameLib() == -1) { + printf("--- Failed to load sfcCustomLib. Exiting\n"); + exit(1); + } + initSem(pSockets); initProvProcCtl(pSockets); init_sfcBroker(); diff --git a/sfcb.cfg.pre.in b/sfcb.cfg.pre.in index e3c55a1..545a779 100644 --- a/sfcb.cfg.pre.in +++ b/sfcb.cfg.pre.in @@ -56,6 +56,10 @@ useChunking: true ## Default is 100000000 #httpMaxContentLength: 100000000 +## Customization library - user can modify the logic of one or more routine(s) +## But, do not remove any functions or change the function signature. +sfcbCustomLib: sfcCustomLib + ## Enable basic authentication for HTTP and HTTPS connections ## Default is false doBasicAuth: false @@ -253,13 +257,6 @@ sslCiphers: ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH ## Default is 600 #slpRefreshInterval: 600 -## Name of the library that will return the hostname to use in the SLP -## useful if current system hostname is not valid for advertisment. -## You probably don't need this. See example, sfcSlpHostname.c. -## Only applies if configured with --enable-slp-hostname-lib. -## Default is sfcSlpHostname -#slpHostnameLib: sfcSlpHostname - ##------------------------------------ Trace ---------------------------------- diff --git a/support.c b/support.c index 4eb69f1..e9ba2d4 100644 --- a/support.c +++ b/support.c @@ -37,6 +37,7 @@ #include "native.h" #include "trace.h" #include "config.h" +#include "control.h" #include <pthread.h> #ifdef SFCB_IX86 @@ -1088,6 +1089,71 @@ sfcb_snprintf(const char *fmt, ...) va_end(ap); return str; } + +/* If config hostnameLib=true, get custom hostname */ +extern void libraryName(const char *dir, const char *location, + const char *fullName, int buf_size); +typedef int (*getSfcbHostname)(char *httpHost, char **hostname, + unsigned int len); +typedef int (*getSfcbSlpHostname)(char **hostname); +static void *hostnameLib; +static getSfcbHostname sfcbHostname; +static getSfcbSlpHostname sfcbSlpHostname; +int loadHostnameLib() +{ + char *ln; + char dlName[512]; + char *err; + + hostnameLib = NULL; + if (getControlChars("sfcbCustomLib", &ln) == 0) { + libraryName(NULL, ln, dlName, 512); + if ((hostnameLib = dlopen(dlName, RTLD_LAZY))) { + dlerror(); + sfcbHostname = dlsym(hostnameLib, "_sfcbGetResponseHostname"); + if ((err = dlerror()) != NULL) { + printf("dlsym failed for _sfcbGetResponseHostname: %s\n", err); + dlclose(hostnameLib); + return -1; + } + dlerror(); + sfcbSlpHostname = dlsym(hostnameLib, "_sfcGetSlpHostname"); + if ((err = dlerror()) != NULL) { + printf("dlsym failed for _sfcbGetSlpHostname: %s\n", err); + dlclose(hostnameLib); + return -1; + } + } + else { + printf("dlopen failed for sfcbCustomLib\n"); + return -1; + } + } + else { + printf("Cannot find the libary to open: %s\n", ln); + return -1; + } + + return 0; +} + +int getCustomHostname(char *httpHost, char **hn, unsigned int len) +{ + if (sfcbHostname) return(sfcbHostname(httpHost, hn, len)); + return -1; +} + +int getCustomSlpHostname(char **hn) +{ + if (sfcbSlpHostname) return(sfcbSlpHostname(hn)); +} + +void unloadHostnameLib() +{ + if (hostnameLib) dlclose(hostnameLib); + return; +} + /* MODELINES */ /* DO NOT EDIT BELOW THIS COMMENT */ /* Modelines are added by 'make pretty' */ hooks/post-receive -- SFCB - Small Footprint CIM Broker |