SafeGuard Enterprise API



  • So, there were some shortcomings in SGE which I wanted fixed (automatic AD sync for example). I knew there was API. I also knew that the server was running as a site in IIS. Armed with this knowledge I decided to take a look in the API, excepting some webservice or REST interface.

    I opened a sample script. Uh, VBscript... I took a very quick look over it and thought it looked a bit weird... I decided to open the API documentation. Okay, it's .NET library, sounds good. But that's where it stops...

    There was 3 classes if I remember right: Base, UMA and Directory. I think sample is the best way to show the odd design choices.... Getting all users of all machines:

    Option Explicit
    

    Dim Scripting
    Dim ScriptingUma
    Dim ScriptingDirectory
    Dim result
    Dim count
    Dim i
    Dim p
    Dim computer
    Dim computerUser
    Dim user
    Dim userCount
    Dim userFound

    Dim msoName = "foo"
    Dim sgnPassword = "bar"

    Set Scripting = WScript.CreateObject("Utimaco.SafeGuard.AdministrationConsole.Scripting.Base")
    wscript.Echo("Created Base Object")

    Set ScriptingUMA = Scripting.CreateUMAClassInstance()
    Set ScriptingDirectory = Scripting.CreateDirectoryClassInstance()

    wscript.Echo("Created Uma Object")

    result = Scripting.Initialize()
    wscript.Echo("API init " & result)

    result = Scripting.AuthenticateOfficer(msoName, sgnPassword, "")
    WScript.Echo("Authenticate : " & result)
    result = ScriptingDirectory.Initialize()
    wscript.Echo("Init Directory: " & result)

    result = ScriptingUMA.Initialize()

    'Search for all computers in the directory
    result = ScriptingDirectory.GetObjectInitialize("*", "", 1, count)

    For i = 0 to count-1
    result = ScriptingDirectory.GetObjectByIndex(i, computer, result)
    result = ScriptingUMA.GetUMAOfMachineInitialize(computer, userCount)
    wscript.Echo("Computer: " & computer)
    For p = 0 to userCount-1
    result = ScriptingUMA.GetUMAOfMachineByIndex(p, computerUser)
    wscript.Echo(" User: " & computerUser)
    Next
    result = ScriptingUMA.GetUMAOfMachineFinalize()
    Next
    result = ScriptingDirectory.GetObjectFinalize()

    result = ScriptingUma.FreeResources()
    result = ScriptingDirectory.FreeResources()
    result = Scripting.FreeResources()

    So:

    • You need to call Initialize() seprately for each object
    • While it's not completly obivous in the example, all functions return int value of the result. Oh, and there is of course GetLastError() method in the Base class which applies to errors in other classes as well
    • Direct array access? What's that? (GetObjectInitialize, GetObjectByIndex)
    • Automatic cleanup? That's stupid!
    • Putting the actual return value (usually string) in one of the parameters
    • For some reason, it feels like I'm coding C in VBscript... Fortunally I only had to make two scripts for it...


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.