I have see that's possible to use the Terminal/Shell program "security" and with this program add a new item in the Keychain, but the question is:
- Is this the best-correct-efficent way to do this job with PureBasic ?
For now I have write a partial code using RunProgram and the security command, but I don't have a Cocoamessage "alternative way" to do the same thing.
I have used this code with an old Applescript Studio program, to permit to smb printers network connections (SMB://printserver.domain.com/PRINTERNAME) to read authentication data in the Keychain and send automatically the username and password to print/AD server every time a network user needs to print something.
Thank you for any information you can give me.
Code: Select all
domain$="DOMAIN"
username$="User"
password$="Password"
printserver$="PSERV"
Result = RunProgram("security", "add-internet-password -a" + Chr(32) + domain$ + ";" + username$ + Chr(32) + "-s" + Chr(32) + printserver$ + Chr(32) + "-r" + Chr(32) + Chr(34) + "smb" + Chr(32) + Chr(34) + Chr(32) + "-w" + Chr(32) + password$ + Chr(32) + "-D" + Chr(32) + Chr(34) + "Network Password" + Chr(34) + Chr(32) + "-T /System/Library/CoreServices/NetAuthAgent.app","", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
Output$ = ""
If Result
While ProgramRunning(Result)
If AvailableProgramOutput(Result)
Output$ + ReadProgramString(Result) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(ProgramExitCode(Result))
Output$ + Chr(13) + Chr(13)
Output$ + "Extended error message: " + ReadProgramError(Result)
CloseProgram(Result) ; Close the connection to the program
EndIf
MessageRequester("Output", Output$)
