Wraps some common functions for automating Network Simplicity's OpenSSH.
Function CreateOsshUser(sUserName, SamLocation)
' Creates OpenSSH user
' for remote domains, username should have space and
' domain embedded in it at the end:
' "username remotedomainname"
Dim Sh, CmdHead, Param, CmdTail, SaveDir
CreateOsshUser = False
Set Sh = CreateObject("WScript.Shell")
' Save current directory, then switch
SaveDir = Sh.CurrentDirectory
On Error Resume Next
Err.Clear
Sh.CurrentDirectory = nsOsshPath
If Err.Number <> 0 Then Exit Function
On Error GoTo 0
CmdHead = "mkpasswd "
CmdTail = " -u " & sUserName & ">> ..\etc\passwd"
Select Case LCase(SamLocation)
Case "local"
Param = "-l"
Case "domain"
Param = "-d"
Case Else
Exit Function
End Select
WScript.Echo CmdHead & Param & CmdTail
CreateOsshUser = True
Sh.CurrentDirectory = SaveDir
End Function
Function nsOsshEtcPath
' Returns the path to the /etc directory for a Network Simplicity
' OpenSSH install.
' Useful for finding executable root to wrap access to user saetup
' and other similar functionality
Dim SshKey, SshValueName, Sh
SshKey = "HKLM\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/etc"
SshValueName = "Native"
Set Sh = CreateObject("WScript.Shell")
nsOsshEtcPath = Sh.RegRead(SshKey & "\" & SshValueName)
End Function
Function nsOsshPath
' Returns the path to the /ssh directory for a Network Simplicity
' OpenSSH install.
' Useful for finding executable root to wrap access to user saetup
' and other similar functionality
Dim SshKey, SshValueName, Sh
SshKey = "HKLM\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/ssh"
SshValueName = "Native"
Set Sh = CreateObject("WScript.Shell")
nsOsshPath = Sh.RegRead(SshKey & "\" & SshValueName)
End Function
Function OsshGids
' Returns Dictionary array containing group names
' and GIDs - key is the name, value is the GID
Dim folEtc, filGroups, sGroupData, aGroups, aTmp, i, Dct
Set OsshGids = CreateObject("Scripting.Dictionary")
folEtc = nsOsshEtcPath
filGroups = folEtc & "\group"
sGroupData = Chomp(fRead(filGroups))
aGroups = Split(sGroupData, vbLf)
For i = 0 To UBound(aGroups)
aTmp = Split(aGroups(i), ":")
OsshGids.Add aTmp(0), aTmp(2)
Next
End Function
Function OsshUsers
' Returns Dictionary array containing group names
' and GIDs - key is the name, value is the GID
Dim folEtc, filUsers, sUserData, aUsers, aTmp, i, Dct
Set OsshUsers = CreateObject("Scripting.Dictionary")
folEtc = nsOsshEtcPath
filUsers = folEtc & "\passwd"
sUserData = Chomp(fRead(filUsers))
aUsers = Split(sUserData, vbLf)
For i = 0 To UBound(aUsers)
aTmp = Split(aUsers(i), ":")
OsshUsers.Add aTmp(0), aTmp(2)
Next
End Function