Skip to content

Commit 58e332c

Browse files
committed
only fail if the group sids fail to resolve and we actually have to add a user
1 parent 0d17e94 commit 58e332c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

modules/post/windows/manage/enable_rdp.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ def enabletssrv(cleanup_rc)
107107
end
108108
end
109109

110-
111-
112110
def addrdpusr(username, password,cleanup_rc)
113-
rdu = resolve_sid("S-1-5-32-555")[:name]
114-
admin = resolve_sid("S-1-5-32-544")[:name]
115-
116111
print_status "Setting user account for logon"
117112
print_status "\tAdding User: #{username} with Password: #{password}"
118113
begin
@@ -121,6 +116,19 @@ def addrdpusr(username, password,cleanup_rc)
121116
return
122117
end
123118

119+
rdu_sid = resolve_sid("S-1-5-32-555")
120+
admin_sid = resolve_sid("S-1-5-32-544")
121+
122+
if !rdu_sid[:mapped] || !admin_sid[:mapped]
123+
print_error("\tThe Remote Desktop Users group is not mapped") if !rdu_sid[:mapped]
124+
print_error("\tThe Administrators group is not mapped") if !admin_sid[:mapped]
125+
print_error("\tNot adding user #{username}")
126+
return
127+
end
128+
129+
rdu = rdu_sid[:name]
130+
admin = admin_sid[:name]
131+
124132
user_added = false
125133
addusr_out = cmd_exec("cmd.exe", "/c net user #{username} #{password} /add")
126134

0 commit comments

Comments
 (0)