Beispiel #1
0
/**
  Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.

  @param[in] VariableName           Name of the variable.
  @param[in] VendorGuid             Variable vendor GUID.
  @param[in] Data                   Data pointer.
  @param[in] DataSize               Size of Data.
  @param[in] Attributes             Attribute value of the variable.

  @retval EFI_SUCCESS               The firmware has successfully stored the variable and its data as
                                    defined by the Attributes.
  @retval EFI_INVALID_PARAMETER     Invalid parameter.
  @retval EFI_WRITE_PROTECTED       Variable is write-protected.
  @retval EFI_OUT_OF_RESOURCES      There is not enough resource.
  @retval EFI_SECURITY_VIOLATION    The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
                                    or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS
                                    set, but the AuthInfo does NOT pass the validation
                                    check carried out by the firmware.
  @retval EFI_UNSUPPORTED           Unsupported to process authenticated variable.

**/
EFI_STATUS
EFIAPI
AuthVariableLibProcessVariable (
  IN CHAR16         *VariableName,
  IN EFI_GUID       *VendorGuid,
  IN VOID           *Data,
  IN UINTN          DataSize,
  IN UINT32         Attributes
  )
{
  EFI_STATUS        Status;

  if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_PLATFORM_KEY_NAME) == 0)){
    Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, Attributes, TRUE);
  } else if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_KEY_EXCHANGE_KEY_NAME) == 0)) {
    Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, Attributes, FALSE);
  } else if (CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid) &&
             ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE)  == 0) ||
              (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0) ||
              (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2) == 0)
             )) {
    Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, Attributes, FALSE);
    if (EFI_ERROR (Status)) {
      Status = ProcessVarWithKek (VariableName, VendorGuid, Data, DataSize, Attributes);
    }
  } else {
    Status = ProcessVariable (VariableName, VendorGuid, Data, DataSize, Attributes);
  }

  return Status;
}
	void SettingsFile::ProcessLine(const std::string& line, const std::string& file_name, const unsigned int& line_number)
	{
		// Is the line empty?
		if(line.empty() == true)
		{
			return;
		}
		// If the line is only 1 character long, then that one character must be whitespace. Otherwise
		// the line is malformed.
		if(line.length() == 1)
		{
			if(isspace(line[0]) == 0)
			{
				throw SettingsFile::SyntaxError(SettingsFile::SyntaxError::BAD_VARIABLE_NAME, file_name, line_number);
			}
		}
		// Otherwise there are at least 2 characters.
		else
		{
			// Is this line a comment?
			if(line[0] == '/' && line[1] == '/')
			{
				return;
			}
			// Otherwise this line isn't a comment.
			else
			{
				ProcessVariable(line, file_name, line_number);
			}
		}
	}
Beispiel #3
0
/**
  Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.

  @param[in] VariableName           Name of the variable.
  @param[in] VendorGuid             Variable vendor GUID.
  @param[in] Data                   Data pointer.
  @param[in] DataSize               Size of Data.
  @param[in] Attributes             Attribute value of the variable.

  @retval EFI_SUCCESS               The firmware has successfully stored the variable and its data as
                                    defined by the Attributes.
  @retval EFI_INVALID_PARAMETER     Invalid parameter.
  @retval EFI_WRITE_PROTECTED       Variable is write-protected.
  @retval EFI_OUT_OF_RESOURCES      There is not enough resource.
  @retval EFI_SECURITY_VIOLATION    The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
                                    or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS
                                    set, but the AuthInfo does NOT pass the validation
                                    check carried out by the firmware.
  @retval EFI_UNSUPPORTED           Unsupported to process authenticated variable.

**/
EFI_STATUS
EFIAPI
AuthVariableLibProcessVariable (
  IN CHAR16         *VariableName,
  IN EFI_GUID       *VendorGuid,
  IN VOID           *Data,
  IN UINTN          DataSize,
  IN UINT32         Attributes
  )
{
  EFI_STATUS        Status;

  //
  // Process PK, KEK, Sigdb, AuditMode, DeployedMode separately.
  //
  if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_PLATFORM_KEY_NAME) == 0)){
    Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, Attributes, TRUE);
  } else if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_KEY_EXCHANGE_KEY_NAME) == 0)) {
    Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, Attributes, FALSE);
  } else if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) 
          && (StrCmp (VariableName, EFI_AUDIT_MODE_NAME) == 0 || StrCmp (VariableName, EFI_DEPLOYED_MODE_NAME) == 0)) {
    Status = ProcessSecureBootModeVar(VariableName, VendorGuid, Data, DataSize, Attributes);
  } else if (CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid) &&
             ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE)  == 0) ||
              (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0) ||
              (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2) == 0)
             )) {
    Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, Attributes, FALSE);
    if (EFI_ERROR (Status)) {
      Status = ProcessVarWithKek (VariableName, VendorGuid, Data, DataSize, Attributes);
    }
  } else {
    Status = ProcessVariable (VariableName, VendorGuid, Data, DataSize, Attributes);
  }

  return Status;
}
Beispiel #4
0
// This is where the program first starts
void main(int argc, char *argv[])
{
    // the pipe name to use ... default is rrpipe but can be changed in RR interface
    LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\rrpipe");
    // holds the variable name being sent by RR
    char varName[MAX_VARNAME_SIZE];
    // holds the received and prehaps processed image data
    char varData[DATA_BUFFER];
    // used to hold return value of number of bytes read from pipe
    unsigned long bytes;
    // variables data length
    int varLen;

    struct ImageDataType imageData;

    memset(&imageData, 0, sizeof(imageData));

    HANDLE hPipe;

    if (argc>1)
    {
        printf("Started with \"");
        int i;
        for (i=1; i<argc; i++)
        {
            if (i>1) printf(" ");
            printf("%s", argv[i]);
        }
        printf("\"\n");
    }
    else
        printf("Started.\n");


    // Create the pipe used to communicate with RR
    hPipe = CreateNamedPipe(
                lpszPipename,             // pipe name
                PIPE_ACCESS_DUPLEX,       // read/write access
                PIPE_TYPE_MESSAGE |       // message type pipe
                PIPE_READMODE_MESSAGE |   // message-read mode
                PIPE_WAIT,                // blocking mode
                PIPE_UNLIMITED_INSTANCES, // max. instances
                PIPE_BUFFER_SIZE,         // output buffer size
                PIPE_BUFFER_SIZE,         // input buffer size
                NMPWAIT_USE_DEFAULT_WAIT, // client time-out
                NULL);                    // default security attribute

    if (hPipe == INVALID_HANDLE_VALUE)
    {
        printf("CreatePipe failed");
        exit(0);
    }

    while (true)
    {
        printf("Waiting ...\n");

        if (!ConnectNamedPipe(hPipe, NULL)? TRUE:(GetLastError() == ERROR_PIPE_CONNECTED))
        {
            printf("ConnectNamedPipe failed");
            continue;
        }

        printf("Connected.\n");

        imageData.count=0;

        int len=0;

        while (true)
        {
            imageData.count++;

            printf("Processing %d\r", imageData.count);

            while (true)
            {
                // read in variable length
                ReadFile(hPipe, &len, sizeof(len), &bytes, NULL);
                // if length <=0 on the variable name then we're done
                if (len<=0) break;
                // read in variable name but if the name is longer than 64 characters
                // then grab the first 64 chars only
                if (len<MAX_VARNAME_SIZE)
                {
                    ReadFile(hPipe, varName, len, &bytes, NULL);
                }
                else
                {
                    // read in first 64 chars
                    ReadFile(hPipe, varName, MAX_VARNAME_SIZE-1, &bytes, NULL);
                    // skip over remaining chars
                    SetFilePointer(hPipe, len-MAX_VARNAME_SIZE+1, 0, FILE_CURRENT);
                }
                // don't forget to terminate this string with a zero
                varName[bytes]=0;

                // read in the variable's data length
                ReadFile(hPipe, &varLen, sizeof(varLen), &bytes, NULL);
                // if the data is less than 1024 read it in now ..
                if (varLen<sizeof(varData))
                {
                    ReadFile(hPipe, varData, varLen, &bytes, NULL);
                }

                // handle this variable
                ProcessVariable(hPipe, &imageData, varName, varData, varLen);
            }

            // termination signal -1 on attribute length
            if (len==-1) break;

            // process image
            ProcessImage(&imageData);

            // Write out the processed image back to RoboRealm using stdout.
            // You can also write back any other variables to use in
            // other parts of the program.
            // The format is the same as the input.
            ReturnBytesVariable(hPipe, "image", imageData.pixels, imageData.width*imageData.height*3);

            // Send back the count as an example of how to feed back variables into RoboRealm
            ReturnIntVariable(hPipe, "count", imageData.count);

            // write out end of message
            len = 0;
            WriteFile(hPipe, &len, sizeof(int), &bytes, NULL);
            if (bytes==0) break;

            // continue by waiting for next image request
        }

        printf("\nDisconnected.\n");

        DisconnectNamedPipe(hPipe);

        if (len==-1) break;
    }

    printf("Exiting\n");

    // free alloced array now that we're done
    free(imageData.pixels);

    CloseHandle(hPipe);
}
Beispiel #5
0
static HRESULT ProcessInterface(__in FILE *fp, __in TYPEINFO_ITEM *lpTypeInfoItem, __in SIZE_T nPass)
{
  ITYPEINFO_LIST cTypeInfoList;
  CAutoTypeAttr cTypeAttr, cTypeAttr2;
  CNktStringW cStrTempW;
  WORD i;
  HRESULT hRes;
  SIZE_T k1;
  BOOL b;

  if (nPass == 1)
  {
    WRITEANSI_AND_CHECK(fp, "\r\n");
    WRITEANSI_AND_CHECK(fp, "typedef struct ");
    WRITEWIDE_AND_CHECK(fp, (LPWSTR)(lpTypeInfoItem->szNameW));
    WRITEANSI_AND_CHECK(fp, " ");
    WRITEWIDE_AND_CHECK(fp, (LPWSTR)(lpTypeInfoItem->szNameW));
    WRITEANSI_AND_CHECK(fp, ";\r\n");
    return S_OK;
  }
  //second pass
  hRes = cTypeAttr.Set(lpTypeInfoItem->cTypeInfo);
  EXIT_ON_ERROR(hRes);
  //typedef struct IUnknown IUnknown;
  WRITEANSI_AND_CHECK(fp, "\r\n");
  WRITEANSI_AND_CHECK(fp, "typedef struct ");
  WRITEWIDE_AND_CHECK(fp, (LPWSTR)(lpTypeInfoItem->szNameW));
  WRITEANSI_AND_CHECK(fp, "Vtbl {\r\n");
  //build parents
  hRes = BuildInterfaceBaseList(cTypeInfoList, lpTypeInfoItem->cTypeInfo);
  EXIT_ON_ERROR(hRes);
  for (k1=0; k1<cTypeInfoList.GetCount(); k1++)
  {
    hRes = cTypeAttr2.Set(cTypeInfoList[k1]);
    EXIT_ON_ERROR(hRes);
    for (i=0; i<cTypeAttr2->cFuncs; i++)
    {
      hRes = ProcessFunction(fp, i, cTypeAttr2.Get(), cTypeInfoList[k1], 1, lpTypeInfoItem->szNameW);
      EXIT_ON_ERROR(hRes);
      b = TRUE;
    }
  }
  for (k1=0; k1<cTypeInfoList.GetCount(); k1++)
  {
    hRes = cTypeAttr2.Set(cTypeInfoList[k1]);
    EXIT_ON_ERROR(hRes);
    for (i=0; i<cTypeAttr2->cVars; i++)
    {
      if (b != FALSE)
      {
        WRITEANSI_AND_CHECK(fp, "\r\n");
        b = FALSE;
      }
      hRes = ProcessVariable(fp, i, cTypeAttr2.Get(), cTypeInfoList[k1], 1);
      EXIT_ON_ERROR(hRes);
    }
  }
  WRITEANSI_AND_CHECK(fp, "};\r\n\r\n");
  //----
  WRITEANSI_AND_CHECK(fp, "struct ");
  WRITEWIDE_AND_CHECK(fp, (LPWSTR)(lpTypeInfoItem->szNameW));
  WRITEANSI_AND_CHECK(fp, " {\r\n");
  WRITEINDENT_AND_CHECK(fp, 1);
  WRITEANSI_AND_CHECK(fp, "struct ");
  WRITEWIDE_AND_CHECK(fp, (LPWSTR)(lpTypeInfoItem->szNameW));
  WRITEANSI_AND_CHECK(fp, "Vtbl *lpVtbl;\r\n");
  WRITEANSI_AND_CHECK(fp, "};\r\n");
  return S_OK;
}
Beispiel #6
0
static HRESULT ProcessTypedef(__in FILE *fp, __in TYPEINFO_ITEM *lpTypeInfoItem)
{
  CAutoTypeAttr cTypeAttr;
  CNktStringW cStrTempW;
  WORD i;
  HRESULT hRes;

  hRes = cTypeAttr.Set(lpTypeInfoItem->cTypeInfo);
  EXIT_ON_ERROR(hRes);
  //write file
  WRITEANSI_AND_CHECK(fp, "\r\n");
  WRITEANSI_AND_CHECK(fp, "typedef ");
  switch (cTypeAttr->typekind)
  {
    case TKIND_RECORD:
      WRITEANSI_AND_CHECK(fp, "struct {\r\n");
      break;
    case TKIND_UNION:
      WRITEANSI_AND_CHECK(fp, "union {\r\n");
      break;
    case TKIND_ALIAS: //typedef
      cStrTempW.Empty();
      hRes = TypeDescToString(cStrTempW, &(cTypeAttr->tdescAlias), lpTypeInfoItem->cTypeInfo, FALSE);
      EXIT_ON_ERROR(hRes);
      WRITEWIDE_AND_CHECK(fp, (LPWSTR)cStrTempW);
      WRITEANSI_AND_CHECK(fp, " ");
      break;
    case TKIND_ENUM:
      WRITEANSI_AND_CHECK(fp, "enum {\r\n");
      break;
  }
  switch (cTypeAttr->typekind)
  {
    case TKIND_RECORD:
    case TKIND_UNION:
      for (i=0; i<cTypeAttr->cVars; i++)
      {
        hRes = ProcessVariable(fp, i, cTypeAttr.Get(), lpTypeInfoItem->cTypeInfo, 1);
        EXIT_ON_ERROR(hRes);
      }
      WRITEANSI_AND_CHECK(fp, "} ");
      break;

    case TKIND_ENUM:
      for (i=0; i<cTypeAttr->cVars; i++)
      {
        hRes = ProcessConst(fp, i, cTypeAttr.Get(), lpTypeInfoItem->cTypeInfo, 1, FALSE);
        EXIT_ON_ERROR(hRes);
        if (i < cTypeAttr->cVars-1)
        {
          WRITEANSI_AND_CHECK(fp, ",");
        }
        WRITEANSI_AND_CHECK(fp, "\r\n");
      }
      WRITEANSI_AND_CHECK(fp, "} ");
      break;
  }
  WRITEWIDE_AND_CHECK(fp, (LPWSTR)(lpTypeInfoItem->szNameW));
  WRITEANSI_AND_CHECK(fp, ";\r\n");
  return S_OK;
}
Beispiel #7
0
static int GetVariables(
  void *theEnv,
  struct lhsParseNode *thePattern,
  int patternHeadType,
  struct nandFrame *theNandFrames)
  {
   struct lhsParseNode *patternHead = thePattern;
   struct lhsParseNode *multifieldHeader = NULL;

   /*======================================================*/
   /* Loop through all the fields/slots found in a pattern */
   /* looking for binding instances of variables.          */
   /*======================================================*/

   while (thePattern != NULL)
     {
      /*================================================*/
      /* A multifield slot contains a sublist of fields */
      /* that must be traversed and checked.            */
      /*================================================*/

      if (thePattern->multifieldSlot)
        {
         multifieldHeader = thePattern;
         thePattern = thePattern->bottom;
        }

      /*==================================================*/
      /* Propagate the binding occurences of single field */
      /* variables, multifield variables, and fact        */
      /* addresses to other occurences of the variable.   */
      /* If an error is encountered, return TRUE.         */
      /*==================================================*/

      if (thePattern != NULL)
        {
         if ((thePattern->type == SF_VARIABLE) ||
             (thePattern->type == MF_VARIABLE) ||
             ((thePattern->type == PATTERN_CE) && (thePattern->value != NULL)))
           {
            if (ProcessVariable(theEnv,thePattern,multifieldHeader,patternHead,patternHeadType,theNandFrames))
              { return(TRUE); }
           }
         else
           {
            if (ProcessField(theEnv,thePattern,multifieldHeader,patternHead,patternHeadType,theNandFrames))
              { return(TRUE); }
           }
        }

      /*===============================================*/
      /* Move on to the next field/slot in the pattern */
      /* or to the next field in a multifield slot.    */
      /*===============================================*/

      if (thePattern == NULL)
        { thePattern = multifieldHeader; }
      else if ((thePattern->right == NULL) && (multifieldHeader != NULL))
        {
         thePattern = multifieldHeader;
         multifieldHeader = NULL;
        }

      thePattern = thePattern->right;
     }

   /*===============================*/
   /* Return FALSE to indicate that */
   /* no errors were detected.      */
   /*===============================*/

   return(FALSE);
  }