无法实现密码过滤器

Cannot implement password filter

本文关键字:过滤器 密码 实现      更新时间:2023-10-16

我尝试实现密码过滤器,所以我写了一个简单的密码过滤器。我遵循了 MSDN 中的文档,并确保正确声明了函数。我在VS 2010中编译。


.def 文件:

LIBRARY myFilt
EXPORTS
   InitializeChangeNotify
   PasswordFilter
   PasswordChangeNotify

.cpp文件:

#include <windows.h>
#include <stdio.h>
#include <ntsecapi.h>
void writeToLog(const char* szString)
{
    FILE* pFile = fopen("c:\work\logFile.txt", "a+");
    if (NULL == pFile)
    {
        return;
    }
    fprintf(pFile, "%srn", szString);
    fclose(pFile);
    return;
}
// Default DllMain implementation
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    OutputDebugString(L"DllMain");
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}
BOOLEAN __stdcall InitializeChangeNotify(void)
{
    OutputDebugString(L"InitializeChangeNotify");
    writeToLog("InitializeChangeNotify()");
    return TRUE;
}
BOOLEAN __stdcall PasswordFilter(
  PUNICODE_STRING AccountName,
  PUNICODE_STRING FullName,
  PUNICODE_STRING Password,
  BOOLEAN SetOperation
)
{
    OutputDebugString(L"PasswordFilter");
    return TRUE;
}
NTSTATUS __stdcall PasswordChangeNotify(
  PUNICODE_STRING UserName,
  ULONG RelativeId,
  PUNICODE_STRING NewPassword
)
{
    OutputDebugString(L"PasswordChangeNotify");
    writeToLog("PasswordChangeNotify()");
    return 0;
}

我把myFilt.dll放在%windir%system32,将"myFilt"添加到注册表中的"通知包"中,重新启动计算机,更改密码,什么也没发生。

我打开了依赖项.exe并看到功能正确:

InitializeChangeNotify
PasswordChangeNotify
PasswordFilter

错误在哪里??

谢谢。

我发现了问题!我将运行时库从多线程调试 DLL (/MDd) 更改为多线程调试 (/MTd),它非常完美!:)

– user1375970 五月 5 在 10:38

通知包指定在设置或更改密码时加载或调用的动态链接库 (DLL)。要指定多个文件,请在每个文件名之间按 Enter 键,将文件名一一列出。

在另一个之上!