我正在创建一个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
程序(或自动按Enter),并避免此错误?
答案 0 :(得分:1)
readCreateProcess :: CreateProcess -> String -> IO String
附加String
将作为标准输入传递给命令。