0
我正在創建一個Haskell程序來自動將用戶添加到系統中,然後將其添加到samba,但它要求輸入密碼,並且我想要使用相同的密碼。我沒有找到任何參數,我們可以使用來實現這樣的目標。我能做什麼?Haskell - 當需要密碼時System.Process會給出錯誤
這裏是我的代碼:
import System.Environment(getArgs)
import System.Process (createProcess, shell)
main = do
(user:pass:_) <- getArgs
putStrLn $ "Creating user " ++ user ++ " " ++ pass ++ "..."
callCommand $ "useradd " ++ user
callCommand $ "echo \"" ++ user ++ "\":\"" ++ pass ++ "\" | chpasswd"
putStrLn $ "User Created. Adding it to samba..."
callCommand $ "smbpasswd -a " ++ user
callCommand = createProcess . shell
結果:
-bash# runghc test.hs testUser 12345
Creating user testUser 12345...
User Created. Adding it to samba...
chpasswd: (user testUser) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user testUser) password not changed
-bash# New SMB password:
Retype new SMB password:
Failed to add entry for user testUser.
我可以通過從用戶接收到程序(或按自動輸入)的pass
說法,並避免這個錯誤?
偏題:我會使用'proc'而不是'shell' - 後者需要小心逃避並且非常脆弱,前者只是採用參數。 – chi