标签: advapi32

为什么LsaAddAccountRights会返回STATUS_INVALID_PARAMETER?

这是一些实现非托管DLL的C#源代码(advapi32).

public void AddPrivileges(string account, string privilege)
{
    IntPtr pSid = GetSIDInformation(account);
    LSA_UNICODE_STRING[] privileges = new LSA_UNICODE_STRING[1];
    privileges[0] = InitLsaString(privilege);
    uint ret = Win32Sec.LsaAddAccountRights(lsaHandle, pSid, privileges, 1);
    if (ret == 0)
        return;
    if (ret == STATUS_ACCESS_DENIED)
    {
        throw new UnauthorizedAccessException();
    }
    if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY))
    {
        throw new OutOfMemoryException();
    }

    int error = Win32Sec.LsaNtStatusToWinError((int)ret);
    throw new Win32Exception(error);
}
Run Code Online (Sandbox Code Playgroud)

运行时的变量值如下:

privilege: "SeServiceLogonRight"
account: "named"
ret: 3221225485 (STATUS_INVALID_PARAMETER)
error: 87
Run Code Online (Sandbox Code Playgroud)

捕获时,Win32Exception中的消息是:"参数不正确"

代码在Windows Web Server 2008上运行.我可以验证该帐户是否存在,并且此代码在另一台服务器上正常工作......我不确定这是否可能是由Windows 2008 SP2引起的.我在想我忘记安装一些东西,但我想不出来......

代码来自: …

c# advapi32

7
推荐指数
2
解决办法
5390
查看次数

我在哪里可以找到ReportEvent函数用法的一个很好的例子?

与大多数"遗留"MSDN页面一样,ReportEvent页面的信息太少,我无法理解它.我试过搜索,但找不到一个好的,干净的,简单的函数用法示例.有谁能建议吗?

winapi advapi32

6
推荐指数
1
解决办法
6594
查看次数

我成功地从C#调用了advapi32的LsaEnumerateAccountRights().现在我如何解组它返回的LSA_UNICODE_STRING数组呢?

它是一个指向LSA_UNICODE_STRING结构数组的指针.我找到了一些反向的代码,即LSA_UNICODE_STRING从C#字符串创建一个.您可以在下面的帮助程序代码部分中看到.

LsaEnumerateAccountRights()所做的和包括呼叫似乎工作得很好.为数组指针和计数返回合理的值.

我手足无措,如何获得那些抨击字符串.请帮忙?好吗?

更新: nobugz的帮助函数在下面的答案中几乎是正确的,你只需要将长度除以UnicodeEncoding.CharSize.多亏了他,我现在可以看到数组中的FIRST字符串了.请参阅下面两个代码部分末尾的更新.

现在,我如何做地狱世界的指针运算?

更新2.5:查看功能代码的答案.我丢失了旧的"错误"代码.

c# unicode marshalling advapi32

6
推荐指数
1
解决办法
2382
查看次数

CryptAcquireContext-未解决的外部

我正在与第三方库(Poco C ++)链接,并从链接器中收到以下未解决的符号错误。它似乎找不到“ CryptAcquireContextW”,“ CryptReleaseContext”和“ CryptGenRandom”。

根据此处Microsoft信息,可以使用“ Advapi32.lib”链接这些功能。我已将其添加到链接器输入中,但符号仍未解析。

1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextW@20 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)

1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)

1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)
Run Code Online (Sandbox Code Playgroud)

我已经确认Advapi32.lib在搜索路径上,而Advapi32.dll在Windows目录中,所以我不确定该错误如何继续发生。

想法,有人吗?

谢谢!

winapi visual-c++ advapi32 poco-libraries

6
推荐指数
1
解决办法
2021
查看次数

如何冒充其他用户?

我正在开发一个ASP.net应用程序,我正在尝试冒充用户

我正在使用令牌创建一个windowsIdentity

WindowsIdentity winId = new WindowsIdenty( token );
Run Code Online (Sandbox Code Playgroud)

这个令牌是通过调用un托管代码获得的

[DllImport("advapi32.dll")]
public static extern int LogonUserA(String lpszUserName, 
    String lpszDomain,
    String lpszPassword,
    int dwLogonType, 
    int dwLogonProvider,
    ref IntPtr phToken);
Run Code Online (Sandbox Code Playgroud)

有没有其他方法来获取令牌而不使用此advapi32.dll非托管代码?

TKS

c# asp.net impersonation windows-identity advapi32

5
推荐指数
1
解决办法
5403
查看次数

是什么让这个安全描述符变坏了?

我正在尝试使用此代码读取Windows中文件和目录的访问权限(在Tim Golden建议的os.access补丁之后进行模式化以使其从Windows上的ACL读取):

from ctypes import(
    windll,
    wintypes,
    c_char_p,
    c_void_p,
    byref
    )
from win32api import GetCurrentThread
from win32security import (
    GetFileSecurity,
    DACL_SECURITY_INFORMATION,
    ImpersonateSelf,
    SecurityImpersonation,
    OpenThreadToken,
    TOKEN_ALL_ACCESS,
    MapGenericMask
    )
from ntsecuritycon import (
    FILE_READ_DATA,
    FILE_WRITE_DATA,
    FILE_EXECUTE,
    FILE_ALL_ACCESS
    )
import pywintypes
import winnt

TRUE = 1

def CheckAccess(path,AccessDesired):
    result = wintypes.BOOL()
    granted = wintypes.DWORD(0)
    privsetlength = wintypes.DWORD(0)

    fileSD = GetFileSecurity(path, DACL_SECURITY_INFORMATION)
    if not fileSD.IsValid():
        raise Exception("Invalid security descriptor")

    ImpersonateSelf(SecurityImpersonation)
    token = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE)
    mapping = wintypes.DWORD(MapGenericMask(AccessDesired,
        (FILE_READ_DATA, FILE_WRITE_DATA, FILE_EXECUTE, FILE_ALL_ACCESS))) …
Run Code Online (Sandbox Code Playgroud)

python ctypes pywin32 advapi32

5
推荐指数
1
解决办法
1009
查看次数

在C#上登录后注销

我使用advapi32.dll的logonuser方法通过我们的网络访问数据.
我知道它将线程的用户改为我给它的信息,但我想知道是否有办法扭转它.
我想访问数据,然后返回本地用户凭据.

.net c# impersonation dllimport advapi32

5
推荐指数
1
解决办法
1350
查看次数

如何配置用 Go 编写的 Windows 服务的失败操作?

我正在使用该包在 Go 中编写 Windows 服务golang.org/x/sys/windows/svc

到目前为止,一切都很顺利,而且很容易上手,我喜欢它。

我已经编写了一些自动更新功能,我希望该服务在完成更新后自行重新启动。

我尝试生成一个进程,该进程将使用 重新启动服务SCM,但它记录了一条错误消息,这似乎与在作为本地系统运行时尝试控制服务有关。

The service process could not connect to the service controller. 
Run Code Online (Sandbox Code Playgroud)

更好/更简单的方法似乎是将os.Exit(1)服务Failure Actions设置为Restart on Failure,效果非常好!

唯一的麻烦是,似乎没有使用 Go 以编程方式配置这些选项的功能。

我做了一些挖掘,看起来它们是通过将结构传递给ChangeServiceConfig2in advapi32.dll- How to create service which restarts on crash 来配置的

golang/sys/blob/master/windows/svc/mgr/config.go中-func updateDescription(handle windows.Handle, desc string) error

代码已经调用了windows.ChangeServiceConfig2DLL 调用的链接。

SERVICE_FAILURE_ACTIONS结构的 Microsoft 文档位于此处

我无法弄清楚如何使用 Go 构建和传递该结构 - 有人有任何见解吗?

windows service go advapi32

5
推荐指数
1
解决办法
2381
查看次数

什么是RevertToSelf()? - C#.net

我不明白RevertToSelf().net应用程序中有什么用.检查MSDN定义,它将定义读取为

The RevertToSelf function terminates the impersonation of a client application.
Run Code Online (Sandbox Code Playgroud)

那么,通过停止客户端的上下文,当前用户上下文是否会更改为sysadmin上下文?通过调用RevertToSelf(),我的代码将在sys管理模式下运行吗?

更新

好的,如果我在ASP.NET应用程序中调用RevertToSelf()会发生什么?让我们考虑一下我不会开始任何模仿.所以如果我调用RevertToSelf()它会恢复到应用程序池标识吗?

.net c# impersonation advapi32

4
推荐指数
1
解决办法
5941
查看次数

Inno Setup Service登录为

您能建议我如何获取特定Windows服务的“登录身份”参数吗?我需要在升级项目中重新注册服务,并且该服务必须使用与最初设置相同的帐户运行。我在返回的结构中的lpServiceStartName中找到了advapi32.dll中的QueryServiceConfig,但是我无法从Inno Setup中使它正常工作。

configuration windows-services inno-setup advapi32

4
推荐指数
1
解决办法
1512
查看次数

我需要从 GetNamedSecurityInfo API 中释放哪些返回参数?

当我调用GetNamedSecurityInfo API 并且成功时,MSDN 指出我需要调用LocalFreeppSecurityDescriptor但是 和ppDaclppSacl

c++ winapi advapi32

3
推荐指数
1
解决办法
496
查看次数

执行某些命令(如“prune”)时,Wincred 无法与 Git Bash(Git for Windows)正常工作

我已经在 Windows 7 64 位中很好地设置了 GitforWindows,并将凭据管理器设置为“Wincred”。

然而,当我运行一些命令(例如git remote prune origin在 GitBash 中)时,它会在控制台中给出以下错误,但运行命令:

Failed to load advapi32.dll
Run Code Online (Sandbox Code Playgroud)

这是为什么 ?如果需要对凭据管理器设置进行某些操作,那么我需要完整解释如何进行这些设置以及每个设置的含义。

注意:我仅在某些命令上遇到此问题,其他命令运行正常,没有任何错误。

git advapi32 git-bash credential-manager git-for-windows

1
推荐指数
1
解决办法
4275
查看次数