Haskell - System.Process 在需要密码时给出错误
Haskell - System.Process gives an error when password is required
我正在创建一个 Haskell 程序来自动将用户添加到系统,然后将其添加到 samba,但它要求密码,我想使用相同的。我没有找到我们可以使用 smbclient
来实现这样的目标的任何参数。我能做什么?
这是我的代码:
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
参数传递给 smbclient
程序(或自动按回车),并避免这个错误吗?
readCreateProcess :: CreateProcess -> String -> IO String
额外的 String
将作为标准输入传递给命令。
我正在创建一个 Haskell 程序来自动将用户添加到系统,然后将其添加到 samba,但它要求密码,我想使用相同的。我没有找到我们可以使用 smbclient
来实现这样的目标的任何参数。我能做什么?
这是我的代码:
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
参数传递给 smbclient
程序(或自动按回车),并避免这个错误吗?
readCreateProcess :: CreateProcess -> String -> IO String
额外的 String
将作为标准输入传递给命令。