gpt4 book ai didi

registry - 使用 Chef 访问另一个用户的注册表

转载 作者:行者123 更新时间:2023-12-01 12:42:33 25 4
gpt4 key购买 nike

是否可以使用 Chef 访问其他用户的注册表?我有 chef-client 作为系统运行,我想修改 User1 的注册表?有没有办法做到这一点?

registry_key资源提供了一种访问 HKEY_Users 的方法,但我看不到将用户名映射到 SID 的方法。

最佳答案

这最终变得温和令人费解,看着它让我感到畏缩。但它似乎有效!

我想通过注册表修改另一个用户的环境变量,如 this Server Fault answer 中所述,但我也想用 Chef 创建用户。那么问题是 Windows 不会为用户创建注册表配置单元,直到他们登录。

如果相关用户确实存在,您可以跳到修改用户的注册表项

强制 Windows 创建用户注册表配置单元

Chef 内置的 executebatch 资源似乎不支持提供密码,所以它看起来不像是 user任何一个的属性都可以在 Windows 上使用。但是the official Chef Windows cookbook包含一个 windows_task 资源,该资源确实包含一个用于指定用户密码的属性。

现在的问题是授予相关用户“作为批处理作业登录”的本地安全策略权限。为此,我们可以使用 SecEdit .

确保您的 Recipe 依赖于官方的 Chef Windows Recipe ;在您的 Recipe 的 metadata.rb 文件中添加:

depends "windows"

这是 Chef Recipe 代码:

group "BatchJobUsers" do
append true
members ["AnotherUser"]
action :create
end

cookbook_file "BatchJobUsers-AddBatchLogonRight.inf" do
path "#{ENV['TEMP']}\\BatchJobUsers-AddBatchLogonRight.inf"
action :create_if_missing
end

execute "secedit" do
cwd "#{ENV['TEMP']}"
command "secedit /configure /db secedit.sdb /cfg BatchJobUsers-AddBatchLogonRight.inf"
end

windows_task "force-creation-of-AnotherUser-user-registry-hive" do
command "echo Force creation of AnotherUser user registry hive"
user "AnotherUser"
password "password-for-another-user"
action [:create, :run]
end

windows_task "force-creation-of-AnotherUser-user-registry-hive" do
action :delete
end

您需要向 COOKBOOK/files/default 目录添加一个名为 BatchJobUsers-AddBatchLogonRight.inf 的文件;它应该包含以下内容:

[Unicode]
Unicode=yes
[Version]
signature="$CHICAGO$"
Revision=1
[Privilege Rights]
SeBatchLogonRight = "BatchJobUsers"

修改用户的注册表项

确保您的 Recipe 依赖于官方的 Chef Windows Recipe ;在您的 Recipe 的 metadata.rb 文件中添加:

depends "windows"

在您的 Recipe 中,添加以下行:

::Chef::Recipe.send(:include, Windows::RegistryHelper)

然后您可以像这样在您的配方中使用函数 resolve_user_to_sid:

get_user_sid = lambda { resolve_user_to_sid("USER_NAME") }

registry_key "Create environment variable registry keys" do
key lazy { "HKEY_USERS\\#{ get_user_sid.call }\\Environment"
values [{
:name => "Variable",
:type => :string,
:data => "variable_data"
}]
recursive true
action :create
end

必须延迟评估 key 属性(即在 Chef 运行配方的收敛阶段评估)以处理不存在的用户。

关于registry - 使用 Chef 访问另一个用户的注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22945786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com