简体   繁体   English

Linux 上 .NET Core 中的 Windows 用户模拟?

[英]Windows User Impersonation in .NET Core on Linux?

I'm writing a .NET Core application in C# that will run on a Linux server, but I need to impersonate a Windows user in order to access some remote resources on a Windows Server.我正在用 C# 编写一个将在 Linux 服务器上运行的 .NET Core 应用程序,但我需要模拟 Windows 用户才能访问 Windows 服务器上的某些远程资源。 I have credentials to authenticate there, but all the implementations I see rely on the "Advanced Windows 32 Base API" (advapi32.dll), which is a shared Windows library not available on Linux.我有在那里进行身份验证的凭据,但我看到的所有实现都依赖于“高级 Windows 32 基础 API”(advapi32.dll),这是一个在 Linux 上不可用的共享 Windows 库。

How do I make this work?我如何使这项工作?

I was able to get a solution by thinking outside the box a bit.我能够通过跳出框框思考来获得解决方案。 I discovered that I could use SharpCifs.Core for CIFS access and the Microsoft PowerShell SDK to gain a remote PowerShell session, and get environment variables.我发现我可以使用SharpCifs.Core进行 CIFS 访问,并使用Microsoft PowerShell SDK来获取远程 PowerShell 会话并获取环境变量。 I do wish that Microsoft would write some better cross-platform tooling.我确实希望微软能够编写一些更好的跨平台工具。

Mono project has a kind of wrapper of several linux commands, one of them is seteuid (the linux command used for impersonation). Mono 项目有一种对多个 linux 命令的封装,其中之一是 seteuid(用于模拟的 linux 命令)。 It could be worth having a look to the NuGet package Mono.Posix.NETStandard .值得一看 NuGet 包Mono.Posix.NETStandard It seems is going to be revamped in the new .Net 5 version.它似乎将在新的 .Net 5 版本中进行改进。 I'm not sure if it can fit your needs...不知道能不能满足你的需求...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM