2016-04-02 21 views
0

Sisteme otomatik olarak bir kullanıcı eklemek için bir Haskell programı oluşturuyorum ve daha sonra bunu samba'ya ekliyorum, ama şifre soruyor ve ben de aynı şeyi kullanmak istiyorum. Böyle bir hedefe ulaşmak için smbclient ile kullanabileceğimiz herhangi bir parametre bulamadım. Ne yapabilirim? İşte Haskell - System.Process şifre gerektiğinde bir hata veriyor

benim kodudur:

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 

Sonuç:

-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. 

Ben pass argüman smbclient programı (veya basın otomatik Enter) kullanıcıdan alınan geçmek ve bu hatayı önlemek miyim?

+0

Konu dışı: 'shell 'yerine' proc 'kullanmalıyım - ikincisi dikkatli bir şekilde kaçmayı gerektirir ve çok kırılgan, eski argümanları alır. – chi

cevap

1

Kullanım readCreateProcess:

readCreateProcess :: CreateProcess -> String -> IO String 

ek String standart girdiye komut olarak geçirilir.