mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(hostdeployer): change the way fo GetLoginAccount in windows
首先,如果不是win10,并且 windowsDefaultAdminUser 置为 true,以及 Administrator 没有lock,那么使用 Administrator。 否则,优先使用第一个没有被锁定且不是 Administrator 的user,如果最后没有 符合条件的user,且Adminstrator 没有被lock,就是用 Administrator。 否则,报错。
This commit is contained in:
@@ -118,14 +118,17 @@ func (w *SWindowsRootFs) GetLoginAccount(rootFs IDiskPartition, sUser string, de
|
||||
users := tool.GetUsers()
|
||||
admin := "Administrator"
|
||||
selUsr := ""
|
||||
if w.IsWindows10() {
|
||||
delete(users, admin)
|
||||
}
|
||||
if _, ok := users[admin]; ok && windowsDefaultAdminUser {
|
||||
isWin10 := w.IsWindows10()
|
||||
// Win10 try not to use Administrator users
|
||||
if _, ok := users[admin]; ok && windowsDefaultAdminUser && !isWin10 {
|
||||
selUsr = admin
|
||||
} else {
|
||||
for user := range users {
|
||||
if user != admin && (len(selUsr) == 0 || len(selUsr) > len(user)) {
|
||||
// Looking for an unlocked user who is not an Administrator
|
||||
for user, ok := range users {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if user != admin {
|
||||
selUsr = user
|
||||
}
|
||||
}
|
||||
@@ -133,10 +136,8 @@ func (w *SWindowsRootFs) GetLoginAccount(rootFs IDiskPartition, sUser string, de
|
||||
selUsr = admin
|
||||
}
|
||||
}
|
||||
if len(selUsr) > 0 {
|
||||
if _, ok := users[selUsr]; !ok {
|
||||
tool.UnlockUser(selUsr)
|
||||
}
|
||||
if selUsr == "" {
|
||||
return "", fmt.Errorf("no unlocked user")
|
||||
}
|
||||
return selUsr, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user