"Fossies" - the Fresh Open Source Software Archive

Member "spnegohelp/spnegoparse.h" (10 Apr 2005, 7059 Bytes) of package /linux/www/apache_httpd_modules/old/modgssapache-0.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright (C) 2002 Microsoft Corporation
    2 // All rights reserved.
    3 //
    4 // THIS CODE AND INFORMATION IS PROVIDED "AS IS"
    5 // WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
    6 // OR IMPLIED, INCLUDING BUT NOT LIMITED
    7 // TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY
    8 // AND/OR FITNESS FOR A PARTICULAR PURPOSE.
    9 //
   10 // Date    - 10/08/2002
   11 // Author  - Sanj Surati
   12 
   13 /////////////////////////////////////////////////////////////
   14 //
   15 // SPNEGOPARSE.H
   16 //
   17 // SPNEGO Token Parser Header File
   18 //
   19 // Contains the definitions required to properly parse a
   20 // SPNEGO token using ASN.1 DER helpers.
   21 //
   22 /////////////////////////////////////////////////////////////
   23 
   24 #ifndef __SPNEGOPARSE_H__
   25 #define __SPNEGOPARSE_H__
   26 
   27 // C++ Specific
   28 #if defined(__cplusplus)
   29 extern "C"
   30 {
   31 #endif
   32 
   33 // Indicates if we copy data when creating a SPNEGO_TOKEN structure or not
   34 #define SPNEGO_TOKEN_INTERNAL_COPYPTR           0
   35 #define SPNEGO_TOKEN_INTERNAL_COPYDATA          0x1
   36 
   37 // Internal flag dictates whether or not we will free the binary data when
   38 // the SPNEG_TOKEN structure is destroyed
   39 #define  SPNEGO_TOKEN_INTERNAL_FLAGS_FREEDATA   0x1
   40 
   41    //
   42 // Each SPNEGO Token Type can be broken down into a
   43 // maximum of 4 separate elements.
   44 //
   45 
   46 #define  MAX_NUM_TOKEN_ELEMENTS  4
   47 
   48 //
   49 // Element offsets in the array
   50 //
   51 
   52 // INIT elements
   53 #define  SPNEGO_INIT_MECHTYPES_ELEMENT    0
   54 #define  SPNEGO_INIT_REQFLAGS_ELEMENT     1
   55 #define  SPNEGO_INIT_MECHTOKEN_ELEMENT    2
   56 #define  SPNEGO_INIT_MECHLISTMIC_ELEMENT  3
   57 
   58 // Response elements
   59 #define  SPNEGO_TARG_NEGRESULT_ELEMENT    0
   60 #define  SPNEGO_TARG_SUPPMECH_ELEMENT     1
   61 #define  SPNEGO_TARG_RESPTOKEN_ELEMENT    2
   62 #define  SPNEGO_TARG_MECHLISTMIC_ELEMENT  3
   63 
   64 //
   65 // Defines an individual SPNEGO Token Element.
   66 //
   67 
   68 typedef struct SpnegoElement
   69 {
   70    size_t                nStructSize;        // Size of the element structure
   71    int                   iElementPresent;    // Is the field present?  Must be either
   72                                              // SPNEGO_TOKEN_ELEMENT_UNAVAILABLE or
   73                                              // SPNEGO_TOKEN_ELEMENT_AVAILABLE
   74 
   75    SPNEGO_ELEMENT_TYPE   eElementType;       // The Element Type
   76 
   77    unsigned char         type;               // Data Type
   78 
   79    unsigned char*        pbData;             // Points to actual Data
   80 
   81    unsigned long         nDatalength;        // Actual Data Length   
   82    
   83 } SPNEGO_ELEMENT;
   84 
   85 // Structure size in case we later choose to extend the structure
   86 #define  SPNEGO_ELEMENT_SIZE sizeof(SPNEGO_ELEMENT)
   87 
   88 //
   89 // Packages a SPNEGO Token Encoding.  There are two types of
   90 // encodings: NegTokenInit and NegTokenTarg.  Each encoding can
   91 // contain up to four distinct, optional elements.
   92 //
   93 
   94 typedef struct SpnegoToken
   95 {
   96    size_t            nStructSize;                              // Size of the Token structure
   97    unsigned long     ulFlags;                                  // Internal Structure Flags - Reserved!
   98    int               ucTokenType;                              // Token Type - Must be
   99                                                                // SPNEGO_TOKEN_INIT or
  100                                                                // SPNEGO_TOKEN_TARG
  101 
  102    unsigned char*    pbBinaryData;                             // Points to binary token data
  103 
  104    unsigned long     ulBinaryDataLen;                          // Length of the actual binary data
  105    int               nNumElements;                             // Number of elements
  106    SPNEGO_ELEMENT    aElementArray [MAX_NUM_TOKEN_ELEMENTS];   // Holds the elements for the token
  107 } SPNEGO_TOKEN;
  108 
  109 // Structure size in case we later choose to extend the structure
  110 #define  SPNEGO_TOKEN_SIZE sizeof(SPNEGO_TOKEN)
  111 
  112 //
  113 // Function definitions
  114 //
  115 
  116 SPNEGO_TOKEN* AllocEmptySpnegoToken( unsigned char ucCopyData, unsigned long ulFlags,
  117                                     unsigned char * pbTokenData, unsigned long ulTokenSize );
  118 void FreeSpnegoToken( SPNEGO_TOKEN* pSpnegoToken );
  119 void InitSpnegoTokenElementArray( SPNEGO_TOKEN* pSpnegoToken );
  120 int InitSpnegoTokenType( SPNEGO_TOKEN* pSpnegoToken, long* pnTokenLength,
  121                            long* pnRemainingTokenLength, unsigned char** ppbFirstElement );
  122 int InitSpnegoTokenElements( SPNEGO_TOKEN* pSpnegoToken, unsigned char* pbTokenData,
  123                            long nRemainingTokenLength  );
  124 int GetSpnegoInitTokenMechList( unsigned char* pbTokenData, int nMechListLength,
  125                                  SPNEGO_ELEMENT* pSpnegoElement );
  126 int InitSpnegoTokenElementFromBasicType( unsigned char* pbTokenData, int nElementLength,
  127                                           unsigned char ucExpectedType,
  128                                           SPNEGO_ELEMENT_TYPE spnegoElementType,
  129                                           SPNEGO_ELEMENT* pSpnegoElement );
  130 int InitSpnegoTokenElementFromOID( unsigned char* pbTokenData, int nElementLength,
  131                                    SPNEGO_ELEMENT_TYPE spnegoElementType,
  132                                    SPNEGO_ELEMENT* pSpnegoElement );
  133 int FindMechOIDInMechList( SPNEGO_ELEMENT* pSpnegoElement, SPNEGO_MECH_OID MechOID,
  134                            int * piMechTypeIndex );
  135 int ValidateMechList( unsigned char* pbMechListData, long nBoundaryLength );
  136 int CalculateMinSpnegoInitTokenSize( long nMechTokenLength, long nMechListMICLength,
  137                                     SPNEGO_MECH_OID mechOid, int nReqFlagsAvailable,
  138                                     long* plTokenSize, long* plInternalLength );
  139 int CalculateMinSpnegoTargTokenSize( SPNEGO_MECH_OID MechType, SPNEGO_NEGRESULT spnegoNegResult, 
  140                                     long nMechTokenLen,
  141                                     long nMechTokenMIC, long* pnTokenSize,
  142                                     long* pnInternalTokenLength );
  143 int CreateSpnegoInitToken( SPNEGO_MECH_OID MechType,
  144           unsigned char ucContextFlags, unsigned char* pbMechToken,
  145           unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
  146           unsigned long ulMechListMICLen, unsigned char* pbTokenData,
  147           long nTokenLength, long nInternalTokenLength );
  148 int CreateSpnegoTargToken( SPNEGO_MECH_OID MechType,
  149           SPNEGO_NEGRESULT eNegResult, unsigned char* pbMechToken,
  150           unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
  151           unsigned long ulMechListMICLen, unsigned char* pbTokenData,
  152           long nTokenLength, long nInternalTokenLength );
  153 int IsValidMechOid( SPNEGO_MECH_OID mechOid );
  154 int IsValidContextFlags( unsigned char ucContextFlags );
  155 int IsValidNegResult( SPNEGO_NEGRESULT negResult );
  156 int IsValidSpnegoToken( SPNEGO_TOKEN* pSpnegoToken );
  157 int IsValidSpnegoElement( SPNEGO_TOKEN* pSpnegoToken,SPNEGO_ELEMENT_TYPE spnegoElement );
  158 int CalculateElementArrayIndex( SPNEGO_TOKEN* pSpnegoToken,SPNEGO_ELEMENT_TYPE spnegoElement );
  159 int InitTokenFromBinary( unsigned char ucCopyData, unsigned long ulFlags,
  160                         unsigned char* pbTokenData, unsigned long ulLength,
  161                         SPNEGO_TOKEN** ppSpnegoToken );
  162 
  163    // C++ Specific
  164 #if defined(__cplusplus)
  165 }
  166 #endif
  167 
  168 #endif
  169