Completed the Authtoken Validate Service changes.
This commit is contained in:
		| @@ -40,9 +40,8 @@ ROOT = ../../../.. | ||||
|  | ||||
| LIBDIR = $(ROOT)/$(LIB) | ||||
| BINDIR = $(ROOT)/$(BIN) | ||||
| #JAVA_LIBDIR = /usr/lib/jvm/java-1.5.0-sun-1.5.0_07/jre/lib/i386/server | ||||
| JAVA_LIBDIR = /usr/lib/jvm/jre-1.5.0-sun/lib/$(HOSTTYPE)/server | ||||
| JAVA_INCDIR = /usr/lib/jvm/java-1.5.0-sun/include | ||||
| JAVA_LIBDIR = /usr/lib/jvm/java-1.5.0-ibm/jre/bin | ||||
| JAVA_INCDIR = /usr/lib/jvm/java-1.5.0-ibm/include | ||||
|  | ||||
| # handle Mono secondary dependencies | ||||
| export MONO_PATH := $(MONO_PATH) | ||||
| @@ -54,13 +53,13 @@ CFILES = | ||||
| CPPFILES = server.cpp | ||||
|  | ||||
| CSFILES_CSC := | ||||
| INCLUDES = -I. -I$(ROOT)/include -I$(JAVA_INCDIR) -I$(JAVA_INCDIR)/linux | ||||
| INCLUDES = -I. -I$(ROOT)/include -I$(JAVA_INCDIR) | ||||
| RESOURCES = | ||||
| DEFINES += -Wno-format-extra-args -fno-strict-aliasing -fshort-wchar  | ||||
| DEFINES += -fno-strict-aliasing -fshort-wchar  | ||||
| CFLAGS += $(INCLUDES) $(DEFINES) | ||||
| CPPFLAGS += -fPIC $(INCLUDES) $(DEFINES) $(RPM_OPT_FLAGS) | ||||
| LIBS = -lpthread -lcasa_s_ipc -ljvm | ||||
| LDFLAGS = -L$(LIBDIR)/$(TARGET_CFG) -L$(JAVA_LIBDIR) -Xlinker -rpath -Xlinker $(JAVA_LIBDIR) | ||||
| LIBS = -lpthread -lcasa_s_ipc -ljvm -ljsig -lj9thr23 | ||||
| LDFLAGS = -L$(LIBDIR)/$(TARGET_CFG) -L$(JAVA_LIBDIR) -L$(JAVA_LIBDIR)/classic | ||||
|  | ||||
| OBJDIR = ./$(TARGET_CFG)/$(LIB) | ||||
| OBJS = $(addprefix $(OBJDIR)/, $(CFILES:%.c=%.o)) $(addprefix $(OBJDIR)/, $(CPPFILES:%.cpp=%.o)) | ||||
| @@ -74,8 +73,8 @@ all: $(OBJDIR)/$(MODULE_NAME) | ||||
| # | ||||
| # Pattern based rules. | ||||
| # | ||||
| vpath %.c $(CLIENT) $(COMMON) | ||||
| vpath %.cpp $(CLIENT) $(COMMON) | ||||
| vpath %.c . | ||||
| vpath %.cpp . | ||||
|  | ||||
| $(OBJDIR)/%.o: %.c | ||||
| 	$(CC) -c $(CFLAGS) -o $@ $< | ||||
|   | ||||
| @@ -63,10 +63,10 @@ double   numBusyThreads = 0; | ||||
| double   numPerishingThreads = 0; | ||||
|  | ||||
| // Listen Port Number | ||||
| int   listenPortNumber = 5000; | ||||
| //int   listenPortNumber = 0; | ||||
| //int   listenPortNumber = 5000; | ||||
| int   listenPortNumber = 0; | ||||
|  | ||||
| // Parameter indicating whether or not XSrv needs to run | ||||
| // Parameter indicating whether or not the server needs to run | ||||
| // as a daemon. | ||||
| bool  daemonize = false; | ||||
|  | ||||
| @@ -74,7 +74,7 @@ bool  daemonize = false; | ||||
| char  appName[] = "CasaAuthtokenValidateD"; | ||||
|  | ||||
| // Debug Level | ||||
| int   DebugLevel = 3; | ||||
| int   DebugLevel = 0; | ||||
| bool  UseSyslog = false; | ||||
|  | ||||
| // Variables for daemon auto-restart after crash feature | ||||
| @@ -92,10 +92,11 @@ bool  terminating = false; | ||||
| JavaVM   *g_jvm = NULL; | ||||
| JNIEnv   *g_env = NULL; | ||||
|  | ||||
| char  classpath[] = "-Djava.class.path=/usr/share/java/CASA/authtoken/CasaAuthToken.jar:/usr/share/java/CASA/authtoken/external/axis.jar:/usr/share/java/CASA/authtoken/external/axis-ant.jar:/usr/share/java/CASA/authtoken/external/commons-discovery-0.2.jar:/usr/share/java/CASA/authtoken/external/commons-logging-1.0.4.jar:/usr/share/java/CASA/authtoken/external/jaxrpc.jar:/usr/share/java/CASA/authtoken/external/log4j-1.2.8.jar:/usr/share/java/CASA/authtoken/external/saaj.jar:/usr/share/java/CASA/authtoken/external/wsdl4j-1.5.1.jar:/usr/share/java/CASA/authtoken/external/wss4j-1.5.0.jar:/usr/share/java/CASA/authtoken/external/xalan.jar:/usr/share/java/CASA/authtoken/external/xercesImpl.jar:/usr/share/java/CASA/authtoken/external/xml-apis.jar:/usr/share/java/CASA/authtoken/external/xmlsec-1.2.1.jar:/usr/share/java/CASA/authtoken/external:/etc/CASA/authtoken.d"; | ||||
| // Java AuthenticationToken Class and method name | ||||
| //char  authTokenClassName[] = "jtest"; | ||||
| //char  authTokenClassValidateMethodName[] = "test4"; | ||||
| char  authTokenClassName[] = "com.novell.casa.authtoksvc.AuthToken"; | ||||
| char  authTokenClassName[] = "com/novell/casa/authtoksvc/AuthToken"; | ||||
| char  authTokenClassValidateMethodName[] = "validate"; | ||||
|  | ||||
|  | ||||
| @@ -249,7 +250,9 @@ WorkerThread(void*) | ||||
|  | ||||
|    // Attach the thread to the JVM | ||||
|    JNIEnv *env; | ||||
|    if (g_jvm->AttachCurrentThread((void**) &env, NULL) >= 0) | ||||
|    JavaVMAttachArgs attachArgs = {0}; | ||||
|    attachArgs.version = JNI_VERSION_1_4; | ||||
|    if (g_jvm->AttachCurrentThread((void**) &env, &attachArgs) >= 0) | ||||
|    { | ||||
|       // We are now attached to the JVM, find the helper class that | ||||
|       // we need. | ||||
| @@ -288,26 +291,36 @@ WorkerThread(void*) | ||||
|                      { | ||||
|                         // Invoke our helper method | ||||
|                         jstring outString = (jstring) env->CallStaticObjectMethod(helperClass, mId, inString); | ||||
|                         if (outString) | ||||
|  | ||||
|                         // Check if an excption occurred | ||||
|                         if (env->ExceptionCheck() == JNI_TRUE) | ||||
|                         { | ||||
|                            // The helper method succeded, complete the request | ||||
|                            // with the data returned. | ||||
|                            const char *pOutChars = env->GetStringUTFChars(outString, NULL); | ||||
|                            if (pOutChars) | ||||
|                            { | ||||
|                               IpcServerCompleteRequest(requestId, (char*) pOutChars); | ||||
|                               env->ReleaseStringUTFChars(outString, pOutChars); | ||||
|                            } | ||||
|                            else | ||||
|                            { | ||||
|                               DbgTrace(0, "WorkerThread- Unable to get UTF characters\n", 0); | ||||
|                               IpcServerAbortRequest(requestId); | ||||
|                            } | ||||
|                            // There is a pending exception, display the info which in turn clears it. | ||||
|                            env->ExceptionDescribe(); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                            // The helper method failed, just abort the request. | ||||
|                            IpcServerAbortRequest(requestId); | ||||
|                            if (outString) | ||||
|                            { | ||||
|                               // The helper method succeded, complete the request | ||||
|                               // with the data returned. | ||||
|                               const char *pOutChars = env->GetStringUTFChars(outString, NULL); | ||||
|                               if (pOutChars) | ||||
|                               { | ||||
|                                  IpcServerCompleteRequest(requestId, (char*) pOutChars); | ||||
|                                  env->ReleaseStringUTFChars(outString, pOutChars); | ||||
|                               } | ||||
|                               else | ||||
|                               { | ||||
|                                  DbgTrace(0, "WorkerThread- Unable to get UTF characters\n", 0); | ||||
|                                  IpcServerAbortRequest(requestId); | ||||
|                               } | ||||
|                            } | ||||
|                            else | ||||
|                            { | ||||
|                               // The helper method failed, just abort the request. | ||||
|                               IpcServerAbortRequest(requestId); | ||||
|                            } | ||||
|                         } | ||||
|                      } | ||||
|                      else | ||||
| @@ -433,14 +446,17 @@ InitJavaInvoke(void) | ||||
|  | ||||
|    DbgTrace(1, "InitJavaInvoke- Start\n", 0); | ||||
|  | ||||
|    //JavaVMOption options[1]; | ||||
|    //options[0].optionString = "-Djava.class.path=."; | ||||
|    JavaVMOption options[1]; | ||||
|    options[0].optionString = "-Djava.class.path=/usr/share/java:/etc/CASA/authtoken"; | ||||
|    JavaVMOption options[6]; | ||||
|    options[0].optionString = classpath; | ||||
|    options[1].optionString = "-Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser"; | ||||
|    options[2].optionString = "-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; | ||||
|    options[3].optionString = "-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"; | ||||
|    //options[4].optionString = "-Xcheck:jni"; | ||||
|    //options[5].optionString = "-Djaxp.debug=1"; | ||||
|    JavaVMInitArgs vm_args; | ||||
|    vm_args.version = JNI_VERSION_1_4; | ||||
|    vm_args.options = options; | ||||
|    vm_args.nOptions = 1; | ||||
|    vm_args.nOptions = 4; | ||||
|    vm_args.ignoreUnrecognized = true; | ||||
|    if (JNI_CreateJavaVM(&g_jvm, (void**)&g_env, &vm_args) >= 0) | ||||
|    { | ||||
|   | ||||
| @@ -1,693 +0,0 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  Copyright (C) 2006 Novell, Inc. All Rights Reserved. | ||||
|  * | ||||
|  *  This library is free software; you can redistribute it and/or | ||||
|  *  modify it under the terms of the GNU Lesser General Public | ||||
|  *  License as published by the Free Software Foundation; version 2.1 | ||||
|  *  of the License. | ||||
|  * | ||||
|  *  This library is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
|  *  Library Lesser General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Lesser General Public | ||||
|  *  License along with this library; if not, Novell, Inc. | ||||
|  *  | ||||
|  *  To contact Novell about this file by physical or electronic mail,  | ||||
|  *  you may find current contact information at www.novell.com. | ||||
|  *  | ||||
|  *  Author: Juan Carlos Luciani <jluciani@novell.com> | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
|  | ||||
| //===[ Include files ]===================================================== | ||||
|  | ||||
| #include "internal.h" | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| // | ||||
| // Parse states | ||||
| // | ||||
| #define AWAITING_ROOT_ELEMENT_START          0x0 | ||||
| #define AWAITING_ROOT_ELEMENT_END            0x1 | ||||
| #define AWAITING_SIGNATURE_DATA              0x2 | ||||
| #define AWAITING_SIGNATURE_ELEMENT_START     0x3 | ||||
| #define AWAITING_SIGNATURE_ELEMENT_END       0x4 | ||||
| #define AWAITING_LIFETIME_DATA               0x5 | ||||
| #define AWAITING_LIFETIME_ELEMENT_START      0x6 | ||||
| #define AWAITING_LIFETIME_ELEMENT_END        0x7 | ||||
| #define AWAITING_IDENT_TOKEN_ELEMENT_START   0x8 | ||||
| #define AWAITING_IDENT_TOKEN_ELEMENT_END     0x9 | ||||
| #define AWAITING_IDENT_TOKEN_DATA            0xA | ||||
| #define AWAITING_TYPE_ELEMENT_START          0xB | ||||
| #define AWAITING_TYPE_ELEMENT_END            0xC | ||||
| #define AWAITING_TYPE_DATA                   0xD | ||||
| #define DONE_PARSING                         0xE | ||||
|  | ||||
| // | ||||
| // Authentication Token Parse Structure | ||||
| // | ||||
| typedef struct _AuthTokenParse | ||||
| { | ||||
|    XML_Parser           p; | ||||
|    int                  state; | ||||
|    int                  elementDataProcessed; | ||||
|    AuthToken            *pAuthToken; | ||||
|    CasaStatus           status; | ||||
|  | ||||
| } AuthTokenParse, *PAuthTokenParse; | ||||
|  | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| void XMLCALL | ||||
| AuthTokenStartElementHandler( | ||||
|    IN    void *pUserData, | ||||
|    IN    const XML_Char *name, | ||||
|    IN    const XML_Char **atts) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    AuthTokenParse    *pAuthTokenParse = (AuthTokenParse*) pUserData; | ||||
|  | ||||
|    DbgTrace(2, "-AuthTokenStartElementHandler- Start\n", 0); | ||||
|  | ||||
|    // Proceed based on the state | ||||
|    switch (pAuthTokenParse->state) | ||||
|    { | ||||
|       case AWAITING_ROOT_ELEMENT_START: | ||||
|  | ||||
|          // In this state, we are only expecting the Authentication | ||||
|          // Response Element. | ||||
|          if (strcmp(name, AUTH_TOKEN_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_SIGNATURE_ELEMENT_START; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenStartElementHandler- Un-expected start element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_SIGNATURE_ELEMENT_START: | ||||
|     | ||||
|          // In this state, we are only expecting the Signature Element. | ||||
|          if (strcmp(name, SIGNATURE_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_SIGNATURE_DATA; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenStartElementHandler- Un-expected start element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_LIFETIME_ELEMENT_START: | ||||
|     | ||||
|          // In this state, we are only expecting the Lifetime Element. | ||||
|          if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_LIFETIME_DATA; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenStartElementHandler- Un-expected start element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_IDENT_TOKEN_ELEMENT_START: | ||||
|     | ||||
|          // In this state, we are only expecting the Identity Token Element. | ||||
|          if (strcmp(name, IDENTITY_TOKEN_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_TYPE_ELEMENT_START; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenStartElementHandler- Un-expected start element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|     | ||||
|       case AWAITING_TYPE_ELEMENT_START: | ||||
|     | ||||
|          // In this state, we are only expecting the Type Element. | ||||
|          if (strcmp(name, TYPE_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_TYPE_DATA; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenStartElementHandler- Un-expected start element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       default: | ||||
|          DbgTrace(0, "-AuthTokenStartElementHandler- Un-expected state = %d\n", pAuthTokenParse->state); | ||||
|          XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          break; | ||||
|    } | ||||
|  | ||||
|    DbgTrace(2, "-AuthTokenStartElementHandler- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| CasaStatus | ||||
| ConsumeElementData( | ||||
|    IN    AuthTokenParse *pAuthTokenParse, | ||||
|    IN    const XML_Char *s, | ||||
|    IN    int len, | ||||
|    INOUT char **ppElementData, | ||||
|    INOUT int *pElementDataLen) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus  retStatus = CASA_STATUS_SUCCESS; | ||||
|  | ||||
|    DbgTrace(3, "-ConsumeElementData- Start\n", 0); | ||||
|  | ||||
|    // Proceed based on whether or not we have already consumed data | ||||
|    // for this element. | ||||
|    if (*ppElementData == NULL) | ||||
|    { | ||||
|       // We have not yet consumed data for this element | ||||
|       pAuthTokenParse->elementDataProcessed = len; | ||||
|  | ||||
|       // Allocate a buffer to hold this element data (null terminated). | ||||
|       *ppElementData = (char*) malloc(len + 1); | ||||
|       if (*ppElementData) | ||||
|       { | ||||
|          memset(*ppElementData, 0, len + 1); | ||||
|          memcpy(*ppElementData, s, len); | ||||
|  | ||||
|          // Return the length of the element data buffer | ||||
|          *pElementDataLen = pAuthTokenParse->elementDataProcessed + 1; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0); | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                      CASA_FACILITY_AUTHTOKEN, | ||||
|                                      CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       char  *pNewBuf; | ||||
|  | ||||
|       // We have already received token data, append this data to it. | ||||
|       pNewBuf = (char*) malloc(pAuthTokenParse->elementDataProcessed + len + 1); | ||||
|       if (pNewBuf) | ||||
|       { | ||||
|          memset(pNewBuf, | ||||
|                 0, | ||||
|                 pAuthTokenParse->elementDataProcessed + len + 1); | ||||
|          memcpy(pNewBuf, | ||||
|                 *ppElementData, | ||||
|                 pAuthTokenParse->elementDataProcessed); | ||||
|          memcpy(pNewBuf + pAuthTokenParse->elementDataProcessed, s, len); | ||||
|          pAuthTokenParse->elementDataProcessed += len; | ||||
|  | ||||
|          // Swap the buffers | ||||
|          free(*ppElementData); | ||||
|          *ppElementData = pNewBuf; | ||||
|  | ||||
|          // Return the length of the element data buffer | ||||
|          *pElementDataLen = pAuthTokenParse->elementDataProcessed + 1; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0); | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                      CASA_FACILITY_AUTHTOKEN, | ||||
|                                      CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       } | ||||
|    } | ||||
|  | ||||
|    DbgTrace(3, "-ConsumeElementData- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| void XMLCALL | ||||
| AuthTokenCharDataHandler( | ||||
|    IN    void *pUserData, | ||||
|    IN    const XML_Char *s, | ||||
|    IN    int len) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    AuthTokenParse    *pAuthTokenParse = (AuthTokenParse*) pUserData; | ||||
|  | ||||
|    DbgTrace(2, "-AuthTokenCharDataHandler- Start\n", 0); | ||||
|  | ||||
|    // Just exit if being called to process LF and CR characters | ||||
|    if (len == 1 | ||||
|        && ((*s == '\n') || (*s == '\r'))) | ||||
|    { | ||||
|       goto exit; | ||||
|    } | ||||
|  | ||||
|    // Proceed based on the state | ||||
|    switch (pAuthTokenParse->state) | ||||
|    { | ||||
|       case AWAITING_SIGNATURE_DATA: | ||||
|       case AWAITING_SIGNATURE_ELEMENT_END: | ||||
|  | ||||
|          pAuthTokenParse->status = ConsumeElementData(pAuthTokenParse, | ||||
|                                                       s, | ||||
|                                                       len, | ||||
|                                                       &pAuthTokenParse->pAuthToken->pSignature, | ||||
|                                                       &pAuthTokenParse->pAuthToken->signatureLen); | ||||
|          if (CASA_SUCCESS(pAuthTokenParse->status)) | ||||
|          { | ||||
|             // Advanced to the next state | ||||
|             pAuthTokenParse->state = AWAITING_SIGNATURE_ELEMENT_END; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_LIFETIME_DATA: | ||||
|       case AWAITING_LIFETIME_ELEMENT_END: | ||||
|     | ||||
|          // Convert the lifetime string to a numeric value | ||||
|          pAuthTokenParse->pAuthToken->tokenLifetime = dtoul((char*) s, len); | ||||
|     | ||||
|          // Advanced to the next state | ||||
|          pAuthTokenParse->state = AWAITING_LIFETIME_ELEMENT_END; | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_TYPE_DATA: | ||||
|       case AWAITING_TYPE_ELEMENT_END: | ||||
|  | ||||
|          pAuthTokenParse->status = ConsumeElementData(pAuthTokenParse, | ||||
|                                                       s, | ||||
|                                                       len, | ||||
|                                                       &pAuthTokenParse->pAuthToken->pIdenTokenType, | ||||
|                                                       &pAuthTokenParse->pAuthToken->idenTokenTypeLen); | ||||
|          if (CASA_SUCCESS(pAuthTokenParse->status)) | ||||
|          { | ||||
|             // Advanced to the next state | ||||
|             pAuthTokenParse->state = AWAITING_TYPE_ELEMENT_END; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_IDENT_TOKEN_DATA: | ||||
|       case AWAITING_IDENT_TOKEN_ELEMENT_END: | ||||
|  | ||||
|          pAuthTokenParse->status = ConsumeElementData(pAuthTokenParse, | ||||
|                                                       s, | ||||
|                                                       len, | ||||
|                                                       &pAuthTokenParse->pAuthToken->pIdenToken, | ||||
|                                                       &pAuthTokenParse->pAuthToken->idenTokenLen); | ||||
|          if (CASA_SUCCESS(pAuthTokenParse->status)) | ||||
|          { | ||||
|             // Advanced to the next state | ||||
|             pAuthTokenParse->state = AWAITING_IDENT_TOKEN_ELEMENT_END; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       default: | ||||
|          DbgTrace(0, "-AuthTokenCharDataHandler- Un-expected state = %d\n", pAuthTokenParse->state); | ||||
|          XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          break; | ||||
|    } | ||||
|  | ||||
| exit: | ||||
|  | ||||
|    DbgTrace(2, "-AuthTokenCharDataHandler- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| void XMLCALL | ||||
| AuthTokenEndElementHandler( | ||||
|    IN    void *pUserData, | ||||
|    IN    const XML_Char *name) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    AuthTokenParse    *pAuthTokenParse = (AuthTokenParse*) pUserData; | ||||
|  | ||||
|    DbgTrace(2, "-AuthTokenEndElementHandler- Start\n", 0); | ||||
|  | ||||
|    // Proceed based on the state | ||||
|    switch (pAuthTokenParse->state) | ||||
|    { | ||||
|       case AWAITING_ROOT_ELEMENT_END: | ||||
|  | ||||
|          // In this state, we are only expecting the Authentication | ||||
|          // Token Element. | ||||
|          if (strcmp(name, AUTH_TOKEN_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Done. | ||||
|             pAuthTokenParse->state = DONE_PARSING; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenEndHandler- Un-expected end element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_SIGNATURE_ELEMENT_END: | ||||
|     | ||||
|          // In this state, we are only expecting the Signature Element. | ||||
|          if (strcmp(name, SIGNATURE_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_LIFETIME_ELEMENT_START; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenEndElementHandler- Un-expected end element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|  | ||||
|       case AWAITING_LIFETIME_ELEMENT_END: | ||||
|     | ||||
|          // In this state, we are only expecting the Lifetime Element. | ||||
|          if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_IDENT_TOKEN_ELEMENT_START; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenEndElementHandler- Un-expected end element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|     | ||||
|       case AWAITING_TYPE_ELEMENT_END: | ||||
|     | ||||
|          // In this state, we are only expecting the Type Element. | ||||
|          if (strcmp(name, TYPE_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_IDENT_TOKEN_DATA; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenEndElementHandler- Un-expected end element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|     | ||||
|       case AWAITING_IDENT_TOKEN_ELEMENT_END: | ||||
|     | ||||
|          // In this state, we are only expecting the Identity Token Element. | ||||
|          if (strcmp(name, IDENTITY_TOKEN_ELEMENT_NAME) == 0) | ||||
|          { | ||||
|             // Good, advance to the next state. | ||||
|             pAuthTokenParse->state = AWAITING_ROOT_ELEMENT_END; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-AuthTokenEndElementHandler- Un-expected end element\n", 0); | ||||
|             XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          } | ||||
|          break; | ||||
|     | ||||
|       default: | ||||
|          DbgTrace(0, "-AuthTokenEndElementHandler- Un-expected state = %d\n", pAuthTokenParse->state); | ||||
|          XML_StopParser(pAuthTokenParse->p, XML_FALSE); | ||||
|          break; | ||||
|    } | ||||
|  | ||||
|    DbgTrace(2, "-AuthTokenEndElementHandler- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| CasaStatus | ||||
| CreateAuthToken( | ||||
|    IN    char *pTokenBuf, | ||||
|    IN    int tokenBufLen, | ||||
|    INOUT AuthToken **ppAuthToken) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus        retStatus = CASA_STATUS_SUCCESS; | ||||
|    AuthTokenParse    authTokenParse = {0}; | ||||
|    AuthToken         *pAuthToken; | ||||
|  | ||||
|    DbgTrace(1, "-CreateAuthToken- Start\n", 0); | ||||
|  | ||||
|    /* | ||||
|    * Authentication tokens have the following format: | ||||
|    *  | ||||
|    * <?xml version="1.0" encoding="ISO-8859-1"?> | ||||
|    * <auth_token> | ||||
|    * <signature>signature value</signature> | ||||
|    * <lifetime>lifetime value</lifetime> | ||||
|    * <ident_token><type>identity token type</type>identity token data</ident_token> | ||||
|    * </auth_token> | ||||
|    * | ||||
|    */ | ||||
|  | ||||
|    // Allocate AuthToken object | ||||
|    pAuthToken = malloc(sizeof(*pAuthToken)); | ||||
|    if (pAuthToken) | ||||
|    { | ||||
|       XML_Parser  p; | ||||
|  | ||||
|       // Initialize the AuthToken object and set it in the | ||||
|       // authentication response parse object. | ||||
|       memset(pAuthToken, 0, sizeof(*pAuthToken)); | ||||
|       authTokenParse.pAuthToken = pAuthToken; | ||||
|  | ||||
|       // Create parser | ||||
|       p = XML_ParserCreate(NULL); | ||||
|       if (p) | ||||
|       { | ||||
|          // Keep track of the parser in our parse object | ||||
|          authTokenParse.p = p; | ||||
|  | ||||
|          // Initialize the status within the parse object | ||||
|          authTokenParse.status = CASA_STATUS_SUCCESS; | ||||
|  | ||||
|          // Set the start and end element handlers | ||||
|          XML_SetElementHandler(p, | ||||
|                                AuthTokenStartElementHandler, | ||||
|                                AuthTokenEndElementHandler); | ||||
|  | ||||
|          // Set the character data handler | ||||
|          XML_SetCharacterDataHandler(p, AuthTokenCharDataHandler); | ||||
|  | ||||
|  | ||||
|          // Set our user data | ||||
|          XML_SetUserData(p, &authTokenParse); | ||||
|  | ||||
|          // Parse the document | ||||
|          if (XML_Parse(p, pTokenBuf, tokenBufLen, 1) == XML_STATUS_OK) | ||||
|          { | ||||
|             // Verify that the parse operation completed successfully | ||||
|             if (authTokenParse.state == DONE_PARSING) | ||||
|             { | ||||
|                // The parse operation succeded. | ||||
|                retStatus = CASA_STATUS_SUCCESS; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                DbgTrace(0, "-CreateAuthToken- Parse operation did not complete\n", 0); | ||||
|  | ||||
|                // Check if a status has been recorded | ||||
|                if (authTokenParse.status != CASA_STATUS_SUCCESS) | ||||
|                { | ||||
|                   retStatus = authTokenParse.status; | ||||
|                } | ||||
|                else | ||||
|                { | ||||
|                   retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                               CASA_FACILITY_AUTHTOKEN, | ||||
|                                               CASA_STATUS_PROTOCOL_ERROR); | ||||
|                } | ||||
|             } | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-CreateAuthToken- Parse error %d\n", XML_GetErrorCode(p)); | ||||
|             retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                         CASA_FACILITY_AUTHTOKEN, | ||||
|                                         CASA_STATUS_PROTOCOL_ERROR); | ||||
|          } | ||||
|  | ||||
|          // Free the parser | ||||
|          XML_ParserFree(p); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-CreateAuthToken- Parser creation error\n", 0); | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                      CASA_FACILITY_AUTHTOKEN, | ||||
|                                      CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       } | ||||
|  | ||||
|       // Return the AuthenticationResp object to the caller if necessary | ||||
|       if (CASA_SUCCESS(retStatus)) | ||||
|       { | ||||
|          *ppAuthToken = pAuthToken; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          free(pAuthToken); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-CreateAuthToken- Memory allocation error\n", 0); | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-CreateAuthToken- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| RelAuthToken( | ||||
|    IN    AuthToken *pAuthToken) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    DbgTrace(1, "-RelAuthToken- Start\n", 0); | ||||
|  | ||||
|    // Free the resources associated with the object | ||||
|    if (pAuthToken->pSignature) | ||||
|       free(pAuthToken->pSignature); | ||||
|  | ||||
|    if (pAuthToken->pIdenTokenType) | ||||
|       free(pAuthToken->pIdenTokenType); | ||||
|  | ||||
|    if (pAuthToken->pIdenToken) | ||||
|       free(pAuthToken->pIdenToken); | ||||
|  | ||||
|    free(pAuthToken); | ||||
|  | ||||
|    DbgTrace(1, "-RelAuthToken- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| CasaStatus | ||||
| CheckAuthToken( | ||||
|    IN    AuthToken *pAuthToken, | ||||
|    IN    const char *pServiceName) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L0 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus  retStatus = CASA_STATUS_SUCCESS; | ||||
|  | ||||
|    DbgTrace(1, "-CheckuthToken- Start\n", 0); | ||||
|  | ||||
|    // tbd | ||||
|  | ||||
|    DbgTrace(1, "-CheckAuthToken- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -13,7 +13,7 @@ Authentication. | ||||
| CONFIGURATION | ||||
|  | ||||
| The path to the casa_identoken plug-in is configured by placing the file | ||||
| CasaIdentityToken.conf in the /etc/opt/CASA/authtoken.d/modules.d folder. | ||||
| CasaIdentityToken.conf in the /etc/CASA/authtoken.d/modules.d folder. | ||||
|  | ||||
| PROGRAMMING NOTES | ||||
|  | ||||
|   | ||||
| @@ -10,6 +10,6 @@ | ||||
| #                                                     # | ||||
| ####################################################### | ||||
|  | ||||
| LibraryName		/opt/novell/CASA/lib/casa_iden_token.so | ||||
| LibraryName	/usr/lib/casa_iden_token.so | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -54,7 +54,7 @@ CFILES = ../identokenprovider.c \ | ||||
| CSFILES_CSC := | ||||
| INCLUDES = -I. -I.. -I../../.. -I$(CASAINCLUDE) -I../../../../../include | ||||
| RESOURCES = | ||||
| DEFINES = -Wno-format-extra-args -fno-strict-aliasing  | ||||
| DEFINES = -fno-strict-aliasing  | ||||
| CFLAGS += $(INCLUDES) $(DEFINES) | ||||
| LIBS = -lpthread -ldl -lexpat | ||||
| LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) | ||||
| @@ -62,7 +62,7 @@ LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) | ||||
| OBJDIR = ./$(TARGET_CFG)/$(LIB) | ||||
| OBJS = $(addprefix $(OBJDIR)/, $(CFILES:%.c=%.o)) | ||||
|  | ||||
| EXTRA_DIST = $(CFILES) *.h | ||||
| EXTRA_DIST = $(CFILES) *.h CasaIdentityToken.conf | ||||
|  | ||||
| CUR_DIR := $(shell pwd) | ||||
|  | ||||
|   | ||||
| @@ -81,7 +81,7 @@ GetIdenTokenProviderInterface( | ||||
|    DbgTrace(2, "-GetIdenTokenProviderInterface- Start\n", 0); | ||||
|  | ||||
|    // Get the configuration for the module | ||||
|    retStatus = GetConfigInterface("/etc/opt/novell/CASA/authtoken.d/modules.d", | ||||
|    retStatus = GetConfigInterface("/etc/CASA/authtoken.d/modules.d", | ||||
|                                   pIdenTokenTypeName, | ||||
|                                   &pModuleConfigIf); | ||||
|    if (CASA_SUCCESS(retStatus) | ||||
|   | ||||
| @@ -65,6 +65,7 @@ typedef struct _AuthToken | ||||
| //===[ Global externals ]================================================== | ||||
|  | ||||
| extern int  DebugLevel; | ||||
| extern char IpcClientLibraryPath[]; | ||||
|  | ||||
| //===[ External prototypes ]=============================================== | ||||
|  | ||||
|   | ||||
| @@ -55,9 +55,9 @@ CFILES = ../config.c \ | ||||
| CSFILES_CSC := | ||||
| INCLUDES = -I. -I.. -I$(CASAINCLUDE) -I../../../include | ||||
| RESOURCES = | ||||
| DEFINES = -Wno-format-extra-args -fno-strict-aliasing  | ||||
| DEFINES = -fno-strict-aliasing  | ||||
| CFLAGS += $(INCLUDES) $(DEFINES) | ||||
| LIBS = -lpthread -ldl -lexpat -lcasa_c_ipc | ||||
| LIBS = -lpthread -ldl -lexpat | ||||
| LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) -L$(ROOT)/lib/$(TARGET_CFG) | ||||
|  | ||||
| OBJDIR = ./$(TARGET_CFG)/$(LIB) | ||||
|   | ||||
| @@ -46,6 +46,11 @@ typedef struct _PlatformMutex | ||||
| //  | ||||
| pthread_mutex_t   g_hModuleMutex = PTHREAD_MUTEX_INITIALIZER; | ||||
|  | ||||
| // | ||||
| // Ipc client library path | ||||
| //  | ||||
| char  IpcClientLibraryPath[] = "/usr/lib/libcasa_c_ipc.so"; | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| HANDLE | ||||
|   | ||||
| @@ -26,6 +26,12 @@ | ||||
|  | ||||
| #include "internal.h" | ||||
|  | ||||
| //===[ Manifest constants ]================================================ | ||||
|  | ||||
| #define  APPLICATION_NOT_MULTI_THREADED   "CASA_APPLICATION_NOT_MULTI_THREADED" | ||||
|  | ||||
| #define DOMAIN_SOCKET_FILE_NAME "/var/lib/CASA/authtoken/validate/socket" | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
| @@ -41,10 +47,23 @@ int   DebugLevel = 0; | ||||
| static | ||||
| bool  g_moduleInitialized = false; | ||||
|  | ||||
| // | ||||
| // Configuration variables | ||||
| // | ||||
| bool  g_multiThreadedApplication = true; | ||||
|  | ||||
| // | ||||
| // IPC Client Sub-system variables | ||||
| //  | ||||
| uint32_t atvsEndPointHandle;  // Authentication Token Validation Service endpoint handle | ||||
| // | ||||
| PFN_IpcClientInit                    g_ipcInitPtr = NULL; | ||||
| PFN_IpcClientShutdown                g_ipcShutdownPtr = NULL; | ||||
| //PFN_IpcClientOpenInetRemoteEndPoint  g_ipcOpenEndPointPtr = NULL; | ||||
| PFN_IpcClientOpenUnixRemoteEndPoint  g_ipcOpenEndPointPtr = NULL; | ||||
| PFN_IpcClientCloseRemoteEndPoint     g_ipcCloseEndPointPtr = NULL; | ||||
| PFN_IpcClientSubmitReq               g_ipcSubmitReq = NULL; | ||||
|  | ||||
| uint32_t g_atvsEndPointHandle;   // Authentication Token Validation Service endpoint handle | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| CasaStatus SSCS_CALL | ||||
| @@ -131,35 +150,73 @@ ValidateAuthToken( | ||||
|                if (CASA_SUCCESS(retStatus)) | ||||
|                { | ||||
|                   // Initialize the Client Ipc Subsystem | ||||
|                   if (IpcClientInit("CASA_AuthTokenValidate", | ||||
|                                     true, | ||||
|                                     DebugLevel, | ||||
|                                     false) == 0) | ||||
|                   // | ||||
|                   // First load the library. We load it itself to keep the system | ||||
|                   // from unloading it in-case that the application unloads us. Some | ||||
|                   // applications such as PAM application will repeateadly load and | ||||
|                   // unload us. | ||||
|                   void* libHandle = OpenLibrary(IpcClientLibraryPath); | ||||
|                   if (libHandle) | ||||
|                   { | ||||
|                      // Open endpoint for the Authentication Token Validation Service | ||||
|                      if (IpcClientOpenInetRemoteEndPoint(5000, | ||||
|                                                          0x7F000001, | ||||
|                                                          0, | ||||
|                                                          &atvsEndPointHandle) == 0) | ||||
|                      // The Ipc library has been loaded, now get the symbols that we need. | ||||
|                      g_ipcInitPtr = GetFunctionPtr(libHandle, "IpcClientInit"); | ||||
|                      g_ipcShutdownPtr = GetFunctionPtr(libHandle, "IpcClientShutdown"); | ||||
|                      //g_ipcOpenEndPointPtr = GetFunctionPtr(libHandle, "IpcClientOpenInetRemoteEndPoint"); | ||||
|                      g_ipcOpenEndPointPtr = GetFunctionPtr(libHandle, "IpcClientOpenUnixRemoteEndPoint"); | ||||
|                      g_ipcCloseEndPointPtr = GetFunctionPtr(libHandle, "IpcClientCloseRemoteEndPoint"); | ||||
|                      g_ipcSubmitReq = GetFunctionPtr(libHandle, "IpcClientSubmitReq"); | ||||
|                      if (g_ipcInitPtr == NULL | ||||
|                          || g_ipcShutdownPtr == NULL | ||||
|                          || g_ipcOpenEndPointPtr == NULL | ||||
|                          || g_ipcCloseEndPointPtr == NULL | ||||
|                          || g_ipcSubmitReq == NULL) | ||||
|                      { | ||||
|                         // Success | ||||
|                         g_moduleInitialized = true; | ||||
|                      } | ||||
|                      else | ||||
|                      { | ||||
|                         DbgTrace(0, "-ValidateAuthToken- Failed to open remote endpoint\n", 0); | ||||
|                         IpcClientShutdown(); | ||||
|                         DbgTrace(0, "-ValidateAuthToken- Failed to get needed Ipc library function pointer\n", 0); | ||||
|                         IdenTokenUninit(); | ||||
|                         PrincipalIfUninit(); | ||||
|                         ConfigIfUninit(); | ||||
|                      } | ||||
|                      else | ||||
|                      { | ||||
|                         if ((g_ipcInitPtr)("CASA_AuthTokenValidate", | ||||
|                                            g_multiThreadedApplication, | ||||
|                                            DebugLevel, | ||||
|                                            false) == 0) | ||||
|                         { | ||||
|                            // Open endpoint for the Authentication Token Validation Service | ||||
|                            //if ((g_ipcOpenEndPointPtr)(5000, | ||||
|                            //                           0x7F000001, | ||||
|                            //                           0, | ||||
|                            //                           &g_atvsEndPointHandle) == 0) | ||||
|                            if ((g_ipcOpenEndPointPtr)(DOMAIN_SOCKET_FILE_NAME, | ||||
|                                                       0, | ||||
|                                                       &g_atvsEndPointHandle) == 0) | ||||
|                            { | ||||
|                               // Success | ||||
|                               g_moduleInitialized = true; | ||||
|                            } | ||||
|                            else | ||||
|                            { | ||||
|                               DbgTrace(0, "-ValidateAuthToken- Failed to open remote endpoint\n", 0); | ||||
|                               (g_ipcShutdownPtr)(); | ||||
|                               IdenTokenUninit(); | ||||
|                               PrincipalIfUninit(); | ||||
|                               ConfigIfUninit(); | ||||
|                            } | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                            DbgTrace(0, "-ValidateAuthToken- Ipc subsystem initialization failed\n", 0); | ||||
|                            (g_ipcShutdownPtr)(); | ||||
|                            IdenTokenUninit(); | ||||
|                            PrincipalIfUninit(); | ||||
|                            ConfigIfUninit(); | ||||
|                         } | ||||
|                      } | ||||
|                   } | ||||
|                   else | ||||
|                   { | ||||
|                      DbgTrace(0, "-ValidateAuthToken- Ipc subsystem initialization failed\n", 0); | ||||
|                      IdenTokenUninit(); | ||||
|                      PrincipalIfUninit(); | ||||
|                      ConfigIfUninit(); | ||||
|                      DbgTrace(0, "-ValidateAuthToken- Failed to load Ipc library, error = %d\n", dlerror()); | ||||
|                   } | ||||
|                } | ||||
|                else | ||||
| @@ -193,13 +250,18 @@ ValidateAuthToken( | ||||
|       char *pIdenTokenData; | ||||
|       int idenTokenDataLen; | ||||
|  | ||||
|       // Assume failure | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_AUTHENTICATION_FAILURE); | ||||
|  | ||||
|       // Token was decoded successfully, now submit the authentication token to the | ||||
|       // authentication token validation service. | ||||
|       if (IpcClientSubmitReq(atvsEndPointHandle, | ||||
|                              pDecodedTokenBuf, | ||||
|                              decodedTokenBufLen, | ||||
|                              &pIdenTokenData, | ||||
|                              &idenTokenDataLen) == 0) | ||||
|       if ((g_ipcSubmitReq)(g_atvsEndPointHandle, | ||||
|                            pDecodedTokenBuf, | ||||
|                            decodedTokenBufLen, | ||||
|                            &pIdenTokenData, | ||||
|                            &idenTokenDataLen) == 0) | ||||
|       { | ||||
|          // The submit succeeded, make sure that we got some identity data back. | ||||
|          if (pIdenTokenData) | ||||
| @@ -287,6 +349,51 @@ exit: | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static void __attribute__((constructor)) | ||||
| so_init() | ||||
| // | ||||
| // Arguments In:  None. | ||||
| // | ||||
| // Arguments Out: None. | ||||
| // | ||||
| // Returns:       Nothing. | ||||
| // | ||||
| // Abstract:      Library initialization routine. | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    // Check for environment variable specifying that the application is | ||||
|    // multi-threaded. | ||||
|    if (getenv(APPLICATION_NOT_MULTI_THREADED) != NULL) | ||||
|    { | ||||
|       // The parameter has been configured, remember it. | ||||
|       g_multiThreadedApplication = false; | ||||
|    } | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static void __attribute__((destructor)) | ||||
| so_fini() | ||||
| // | ||||
| // Arguments In:  None. | ||||
| // | ||||
| // Arguments Out: None. | ||||
| // | ||||
| // Returns:       Nothing. | ||||
| // | ||||
| // Abstract:      Library un-initialization routine. | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    if (g_ipcShutdownPtr) | ||||
|       (g_ipcShutdownPtr)(); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
|   | ||||
		Reference in New Issue
	
	Block a user