Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
9194c721
R
runtime
项目概览
dotNET Platform
/
runtime
大约 1 年 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9194c721
编写于
3月 09, 2023
作者:
B
Badre BSAILA
提交者:
GitHub
3月 09, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
provide custom marshaller for USER_INFO_1 (#82350)
* provide custom marshaller for USER_INFO_1
上级
8a68f8a9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
2 deletion
+67
-2
src/libraries/Common/tests/TestUtilities/System/WindowsIdentityFixture.cs
...mmon/tests/TestUtilities/System/WindowsIdentityFixture.cs
+67
-2
未找到文件。
src/libraries/Common/tests/TestUtilities/System/WindowsIdentityFixture.cs
浏览文件 @
9194c721
...
...
@@ -6,6 +6,9 @@
using
System.Linq
;
using
System.Net
;
using
System.Runtime.InteropServices
;
#if NET7_0_OR_GREATER
using
System.Runtime.InteropServices.Marshalling
;
#endif
using
System.Security.Cryptography
;
using
System.Security.Principal
;
using
System.Threading.Tasks
;
...
...
@@ -118,12 +121,15 @@ private void CreateUser()
[
return
:
MarshalAs
(
UnmanagedType
.
Bool
)]
private
static
partial
bool
LogonUser
(
string
userName
,
string
domain
,
string
password
,
int
logonType
,
int
logonProvider
,
out
SafeAccessTokenHandle
safeAccessTokenHandle
);
[
Dll
Import
(
"netapi32.dll"
,
SetLastError
=
true
)]
internal
static
extern
uint
NetUserAdd
([
MarshalAs
(
UnmanagedType
.
LPWStr
)]
string
servername
,
uint
level
,
ref
USER_INFO_1
buf
,
out
uint
parm_err
);
[
Library
Import
(
"netapi32.dll"
,
SetLastError
=
true
)]
internal
static
partial
uint
NetUserAdd
([
MarshalAs
(
UnmanagedType
.
LPWStr
)]
string
servername
,
uint
level
,
ref
USER_INFO_1
buf
,
out
uint
parm_err
);
[
LibraryImport
(
"netapi32.dll"
)]
internal
static
partial
uint
NetUserDel
([
MarshalAs
(
UnmanagedType
.
LPWStr
)]
string
servername
,
[
MarshalAs
(
UnmanagedType
.
LPWStr
)]
string
username
);
#if NET7_0_OR_GREATER
[
NativeMarshalling
(
typeof
(
USER_INFO_1
.
Marshaller
))]
#endif
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Unicode
)]
internal
struct
USER_INFO_1
{
...
...
@@ -135,6 +141,65 @@ internal struct USER_INFO_1
public
string
usri1_comment
;
public
uint
usri1_flags
;
public
string
usri1_script_path
;
#if NET7_0_OR_GREATER
[
CustomMarshaller
(
typeof
(
USER_INFO_1
),
MarshalMode
.
Default
,
typeof
(
Marshaller
))]
public
static
class
Marshaller
{
public
static
USER_INFO_1Native
ConvertToUnmanaged
(
USER_INFO_1
managed
)
=>
new
(
managed
);
public
static
USER_INFO_1
ConvertToManaged
(
USER_INFO_1Native
native
)
=>
native
.
ToManaged
();
public
static
void
Free
(
USER_INFO_1Native
native
)
=>
native
.
FreeNative
();
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
USER_INFO_1Native
{
private
IntPtr
usri1_name
;
private
IntPtr
usri1_password
;
private
uint
usri1_password_age
;
private
uint
usri1_priv
;
private
IntPtr
usri1_home_dir
;
private
IntPtr
usri1_comment
;
private
uint
usri1_flags
;
private
IntPtr
usri1_script_path
;
public
USER_INFO_1Native
(
USER_INFO_1
managed
)
{
usri1_name
=
Marshal
.
StringToCoTaskMemUni
(
managed
.
usri1_name
);
usri1_password
=
Marshal
.
StringToCoTaskMemUni
(
managed
.
usri1_password
);
usri1_password_age
=
managed
.
usri1_password_age
;
usri1_priv
=
managed
.
usri1_priv
;
usri1_home_dir
=
Marshal
.
StringToCoTaskMemUni
(
managed
.
usri1_home_dir
);
usri1_comment
=
Marshal
.
StringToCoTaskMemUni
(
managed
.
usri1_comment
);
usri1_flags
=
managed
.
usri1_flags
;
usri1_script_path
=
Marshal
.
StringToCoTaskMemUni
(
managed
.
usri1_script_path
);
}
public
USER_INFO_1
ToManaged
()
{
return
new
USER_INFO_1
{
usri1_name
=
Marshal
.
PtrToStringUni
(
usri1_name
),
usri1_password
=
Marshal
.
PtrToStringUni
(
usri1_password
),
usri1_password_age
=
usri1_password_age
,
usri1_priv
=
usri1_priv
,
usri1_home_dir
=
Marshal
.
PtrToStringUni
(
usri1_home_dir
),
usri1_comment
=
Marshal
.
PtrToStringUni
(
usri1_comment
),
usri1_flags
=
usri1_flags
,
usri1_script_path
=
Marshal
.
PtrToStringUni
(
usri1_script_path
)
};
}
public
void
FreeNative
()
{
Marshal
.
FreeCoTaskMem
(
usri1_name
);
Marshal
.
FreeCoTaskMem
(
usri1_password
);
Marshal
.
FreeCoTaskMem
(
usri1_home_dir
);
Marshal
.
FreeCoTaskMem
(
usri1_comment
);
Marshal
.
FreeCoTaskMem
(
usri1_script_path
);
}
}
}
#endif
}
public
void
Dispose
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录