void buildSmbNtlmAuthResponse(tSmbNtlmAuthChallenge *challenge, tSmbNtlmAuthResponse *response, char *user, char *password) { uint8 lmRespData[24]; uint8 ntRespData[24]; char *d = strdup(GetUnicodeString(challenge,uDomain)); char *domain = d; char *u = strdup(user); char *p = strchr(u,'@'); if (p) { domain = p+1; *p = '\0'; } SMBencrypt(password, challenge->challengeData, lmRespData); SMBNTencrypt(password, challenge->challengeData, ntRespData); response->bufIndex = 0; memcpy(response->ident,"NTLMSSP\0\0\0",8); SIVAL(&response->msgType,0,3); AddBytes(response,lmResponse,lmRespData,24); AddBytes(response,ntResponse,ntRespData,24); AddUnicodeString(response,uDomain,domain); AddUnicodeString(response,uUser,u); AddUnicodeString(response,uWks,u); AddString(response,sessionKey,NULL); response->flags = challenge->flags; free(d); free(u); }
static void buildSmbNtlmAuthResponse_userlen (tSmbNtlmAuthChallenge * challenge, tSmbNtlmAuthResponse * response, const char *user, size_t user_len, const char *domain, const char *password) { //uint8 lmRespData[8] = {0}; uint8 ntRespData[24] = {0}; uint8 romkey[8] = {0}; uint8 endKey[8] = {0};//0x86, 0x1B, 0xFE, 0x6A, 0xC4, 0xC2, 0x66, 0x49}; uint8 romKey[24] = {0}; //memcpy(romKey, ntlm_romKey, 8); ntlm_create_romkey(romkey); memcpy(romKey, romkey, 8); ntlm_create_endkey(romkey ,challenge->challengeData, endKey); ntlm_smb_nt_encrypt (password, endKey, ntRespData); response->bufIndex = 0; memcpy (response->ident, "NTLMSSP\0\0\0", 8); response->msgType = UI32LE (3); memcpy(response->buffer, "\x05\x02\xCE\x0E\x00\x00\x00\x0F", 8); response->bufIndex += 8; AddUnicodeString (response, uDomain, ""); AddUnicodeStringLen (response, uUser, user, user_len); /* TODO just a dummy value for workstation */ AddUnicodeString(response, uWks, domain); AddBytes (response, sessionKey, romKey, 24); AddBytes (response, lmResponse, ntRespData, 24); AddString (response, uRc4, NULL); response->flags = UI32LE(0xA2888205); }
EFI_STATUS EFIAPI UnixBusDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) /*++ Routine Description: Arguments: Returns: None --*/ { EFI_STATUS Status; EFI_STATUS InstallStatus; EFI_UNIX_THUNK_PROTOCOL *UnixThunk; EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; UNIX_BUS_DEVICE *UnixBusDevice; UNIX_IO_DEVICE *UnixDevice; UINTN Index; CHAR16 *StartString; CHAR16 *SubString; UINT16 Count; UINTN StringSize; UINT16 ComponentName[MAX_UNIX_ENVIRNMENT_VARIABLE_LENGTH]; UNIX_VENDOR_DEVICE_PATH_NODE *Node; BOOLEAN CreateDevice; CHAR16 *TempStr; CHAR16 *PcdTempStr; UINTN TempStrSize; Status = EFI_UNSUPPORTED; // // Grab the protocols we need // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiDevicePathProtocolGuid, (VOID **)&ParentDevicePath, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { return Status; } Status = gBS->OpenProtocol ( ControllerHandle, &gEfiUnixThunkProtocolGuid, (VOID **)&UnixThunk, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { return Status; } if (Status != EFI_ALREADY_STARTED) { Status = gBS->AllocatePool ( EfiBootServicesData, sizeof (UNIX_BUS_DEVICE), (VOID *) &UnixBusDevice ); if (EFI_ERROR (Status)) { return Status; } UnixBusDevice->Signature = UNIX_BUS_DEVICE_SIGNATURE; UnixBusDevice->ControllerNameTable = NULL; AddUnicodeString ( "eng", gUnixBusDriverComponentName.SupportedLanguages, &UnixBusDevice->ControllerNameTable, L"Unix Bus Controller" ); Status = gBS->InstallMultipleProtocolInterfaces ( &ControllerHandle, &gUnixBusDriverGuid, UnixBusDevice, NULL ); if (EFI_ERROR (Status)) { FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable); gBS->FreePool (UnixBusDevice); return Status; } } // // Loop on the Variable list. Parse each variable to produce a set of handles that // represent virtual hardware devices. // InstallStatus = EFI_NOT_FOUND; for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) { PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token); ASSERT (PcdTempStr != NULL); TempStrSize = StrLen (PcdTempStr); TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1); StrCpy (TempStr, PcdTempStr); StartString = TempStr; // // Parse the environment variable into sub strings using '!' as a delimator. // Each substring needs it's own handle to be added to the system. This code // does not understand the sub string. Thats the device drivers job. // Count = 0; while (*StartString != '\0') { // // Find the end of the sub string // SubString = StartString; while (*SubString != '\0' && *SubString != '!') { SubString++; } if (*SubString == '!') { // // Replace token with '\0' to make sub strings. If this is the end // of the string SubString will already point to NULL. // *SubString = '\0'; SubString++; } CreateDevice = TRUE; if (RemainingDevicePath != NULL) { CreateDevice = FALSE; // // Check if RemainingDevicePath is the End of Device Path Node, // if yes, don't create any child device // if (!IsDevicePathEnd (RemainingDevicePath)) { // // If RemainingDevicePath isn't the End of Device Path Node, // check its validation // Node = (UNIX_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath; if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH && Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP && DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (UNIX_VENDOR_DEVICE_PATH_NODE) ) { if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) && Node->Instance == Count ) { CreateDevice = TRUE; } } } } if (CreateDevice) { // // Allocate instance structure, and fill in parent information. // UnixDevice = AllocateMemory (sizeof (UNIX_IO_DEVICE)); if (UnixDevice == NULL) { return EFI_OUT_OF_RESOURCES; } UnixDevice->Handle = NULL; UnixDevice->ControllerHandle = ControllerHandle; UnixDevice->ParentDevicePath = ParentDevicePath; UnixDevice->UnixIo.UnixThunk = UnixThunk; // // Plus 2 to account for the NULL at the end of the Unicode string // StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16); UnixDevice->UnixIo.EnvString = AllocateMemory (StringSize); if (UnixDevice->UnixIo.EnvString != NULL) { CopyMem (UnixDevice->UnixIo.EnvString, StartString, StringSize); } UnixDevice->ControllerNameTable = NULL; // FIXME: check size StrCpy(ComponentName, UnixDevice->UnixIo.EnvString); UnixDevice->DevicePath = UnixBusCreateDevicePath ( ParentDevicePath, mPcdEnvironment[Index].DevicePathGuid, Count ); if (UnixDevice->DevicePath == NULL) { gBS->FreePool (UnixDevice); return EFI_OUT_OF_RESOURCES; } AddUnicodeString ( "eng", gUnixBusDriverComponentName.SupportedLanguages, &UnixDevice->ControllerNameTable, ComponentName ); UnixDevice->UnixIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid; UnixDevice->UnixIo.InstanceNumber = Count; UnixDevice->Signature = UNIX_IO_DEVICE_SIGNATURE; Status = gBS->InstallMultipleProtocolInterfaces ( &UnixDevice->Handle, &gEfiDevicePathProtocolGuid, UnixDevice->DevicePath, &gEfiUnixIoProtocolGuid, &UnixDevice->UnixIo, NULL ); if (EFI_ERROR (Status)) { FreeUnicodeStringTable (UnixDevice->ControllerNameTable); gBS->FreePool (UnixDevice); } else { // // Open For Child Device // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiUnixThunkProtocolGuid, (VOID **)&UnixThunk, This->DriverBindingHandle, UnixDevice->Handle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (!EFI_ERROR (Status)) { InstallStatus = EFI_SUCCESS; } } } // // Parse Next sub string. This will point to '\0' if we are at the end. // Count++; StartString = SubString; } gBS->FreePool (TempStr); } return EFI_SUCCESS; }
EFI_STATUS EFIAPI UnixGopDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) /*++ Routine Description: Arguments: Returns: None --*/ // TODO: This - add argument and description to function comment // TODO: Handle - add argument and description to function comment // TODO: RemainingDevicePath - add argument and description to function comment // TODO: EFI_UNSUPPORTED - add return value to function comment { EFI_UNIX_IO_PROTOCOL *UnixIo; EFI_STATUS Status; GOP_PRIVATE_DATA *Private; // // Grab the protocols we need // Status = gBS->OpenProtocol ( Handle, &gEfiUnixIoProtocolGuid, (VOID **)&UnixIo, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } // // Allocate Private context data for SGO inteface. // Private = NULL; Status = gBS->AllocatePool ( EfiBootServicesData, sizeof (GOP_PRIVATE_DATA), (VOID **)&Private ); if (EFI_ERROR (Status)) { goto Done; } // // Set up context record // Private->Signature = GOP_PRIVATE_DATA_SIGNATURE; Private->Handle = Handle; Private->UnixThunk = UnixIo->UnixThunk; Private->ControllerNameTable = NULL; AddUnicodeString ( "eng", gUnixGopComponentName.SupportedLanguages, &Private->ControllerNameTable, UnixIo->EnvString ); AddUnicodeString2 ( "en", gUnixGopComponentName2.SupportedLanguages, &Private->ControllerNameTable, UnixIo->EnvString, FALSE ); Private->WindowName = UnixIo->EnvString; Status = UnixGopConstructor (Private); if (EFI_ERROR (Status)) { goto Done; } // // Publish the Gop interface to the world // Status = gBS->InstallMultipleProtocolInterfaces ( &Private->Handle, &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput, &gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn, &gEfiSimplePointerProtocolGuid, &Private->SimplePointer, // &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx, NULL ); Done: if (EFI_ERROR (Status)) { gBS->CloseProtocol ( Handle, &gEfiUnixIoProtocolGuid, This->DriverBindingHandle, Handle ); if (Private != NULL) { // // On Error Free back private data // if (Private->ControllerNameTable != NULL) { FreeUnicodeStringTable (Private->ControllerNameTable); } if (Private->SimpleTextIn.WaitForKey != NULL) { gBS->CloseEvent (Private->SimpleTextIn.WaitForKey); } if (Private->SimpleTextInEx.WaitForKeyEx != NULL) { gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx); } FreeNotifyList (&Private->NotifyList); gBS->FreePool (Private); } } return Status; }