My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
' Copyright (c) 2008, Symantec Corporation
' All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions are met:
'
' * Redistributions of source code must retain the above copyright notice,
' this list of conditions and the following disclaimer.
' * Redistributions in binary form must reproduce the above copyright notice,
' this list of conditions and the following disclaimer in the documentation
' and/or other materials provided with the distribution.
' * Neither the name of the Symantec Corporation nor the names of its
' contributors may be used to endorse or promote products derived from this
' software without specific prior written permission.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
' ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
' LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
' CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
' SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
' INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
' CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
' ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
' POSSIBILITY OF SUCH DAMAGE.
'
'----------------------------------------------------------------------------
'
' Run a small query passed on the command line against the console database,
' getting the console's credentials from the configuration server's COM
' object (which requires that the caller be a member of the Administrators
' group).
'
' This builds the names of the clients from the client ID codes by walking
' up the folder/view tree, gluing the shortcuts together.
'


<job id="GSS Client List Utility">

' Little helper so we can use the JavaScript run-time's understanding of
' the Web URL-escaping convention, which we really need to use to build
' sane paths out of the console's names, which don't have any kind of
' reserved characters. By default we display the names plain, but it's nice
' to be able to URLescape them - in future the Configuration Server is likely
' to use URLescaped paths for these things because of the above problem.

<script language="JScript">

function urlEscape (str) {
return escape (str);
}

</script>

<script language="VBScript">
' Some basic setup - this script requires a 32-bit execution environment

q = Chr (34)
set Shell = WScript.CreateObject ("WScript.Shell")
set Env = Shell.Environment ("Process")
arch = Env ("PROCESSOR_ARCHITECTURE")

if arch <> "x86" then
host = Replace (WScript.FullName, "System32", "SysWow64", 1, -1, 1)
if host = WScript.FullName then
WScript.Quit 1
end if

args = q & WScript.ScriptFullName & q
for each arg in WScript.Arguments
args = args & " " & q & arg & q
next

if InStr (host, "wscript") <> 0 then
Shell.Run host & " " & args, 0, true
else
' For running an inner copy of cscript, do this instead of using
' Shell.Run so that we can ensure we can route the inner StdOut to
' our StdOut properly in all circumstances.

set exec = Shell.Exec (host & " //NoLogo " & args)

do while exec.status = 0
do while not exec.StdOut.AtEndOfStream
input = exec.StdOut.ReadLine
WScript.StdOut.WriteLine input
loop
WScript.Sleep 100
loop

end if
WScript.Quit 1
end if

' Get the pattern to search for within the MAC addresses of all the clients
' in the console that are listed in the "Default" folder
'
' A possible future extension is to also allow for searches within the
' computer names.

crlf = Chr (13) & Chr (10)

if WScript.Arguments.Count > 0 then
find = WScript.Arguments (0)
else
find = InputBox ("MAC address pattern to find" & crlf & _
"hit ESC or cancel to quit", "Client finder", "-")
end if

if find = "" then
WScript.Quit (0)
end if

' Access the Configuration Server service's root COM scripting object

set server = CreateObject ("ConfigServer.Application")

' Get the database configuration object from the configuration server

dim dbInfo
on error resume next
set dbInfo = server.ConfigDatabase
on error goto 0

' Obtain the current database username and password

if not IsEmpty (dbInfo) then
user = dbInfo.Username
pass = dbinfo.Password
else
user = "dba"
pass = "sql"
end if

' Some basic setup

q = Chr (34)
set Shell = WScript.CreateObject ("WScript.Shell")

' Get the path to the dbisqlc executable - this is simpler to use than
' ADO for some things.

path = Shell.RegRead("HKLM\Software\Symantec\Symantec Ghost\InstallDirectory\dbeng")
dbisql = q & path & "\dbisqlc" & q

' Form the ODBC connection string to the database

conn = "DSN=Symantec Ghost;UID=" & user & ";PWD=" & pass

' Begin by getting a connection to the database

set adoConn = CreateObject ("ADODB.Connection")
adoConn.Open (conn)

' Associate a recordset object with the connection

set adoRecord = CreateObject ("ADODB.RecordSet")
adoRecord.ActiveConnection = adoConn

' Run a query and get the client view information into three sets of
' collections - we want to map client IDs to view IDs, view IDs to names,
' and view IDs to their parents (where they exist).

cleaned = cleanMachineViews (adoConn)

dim machines ()
dim names ()
dim parents ()
call loadMachineViews (adoRecord)

' Run a query - this one gets the MAC information, which is binary, from
' the Machine table and joins it against the MachineView table; the RootID
' being 1 restricts this to machines under the "Default" folder, since
' there can be secondary copies of machines under other root folders.

query = "select ID, Identifier " & _
"from Machine"

adoRecord.Open (query)

find = UCase (find)

' Look in all the returned rows for the pattern the user asked for, in
' the MAC address list after we've converted it to a printable form

count = 0

do while not adoRecord.EOF
value = MAClist (adoRecord ("Identifier"))

if InStr (value, find) > 0 then
count = count + 1
if count > 19 then
WScript.Echo result
count = 0
result = ""
end if

path = getPath (adoRecord ("ID"), false)
result = result & path & " [" & value & "]" & crlf
end if

adoRecord.MoveNext
loop

adoRecord.Close

' If we cleaned things up, notify the Config server asap

if cleaned then
server.RefreshDatabase
end if

if Len (result) > 0 then
WScript.echo result
else
WScript.echo "No matches found"
end if

' This converts the binary-encoded list of MAC addresses we store in the
' Machine.Identifier column into a text string

function MAClist (value)
' The first three characters of a marshalled MAC address list should be
' the following fixed value

if LeftB (value, 3) <> ChrB (33) & ChrB (0) & ChrB (0) then
exit function
end if
value = MidB (value, 4)

' Loop over individual MAC addresses, each of which starts with the fixed
' two-byte tag below

dim str
str = ""

do while LenB (value) > 0
if LeftB (value, 2) <> ChrB (32) & ChrB (6) then
exit do
end if

value = MidB (value, 3)

dim i
for i = 1 to 6
if i > 1 then
str = str & "-"
end if

str = str & Right ("00" & Hex (AscB (value)), 2)
value = MidB (value, 2)
next

if LenB (value) > 4 then
str = str & " "
end if
loop

MAClist = str
end function

' Attempt to clean up a client record which exists in the Machine table
' but for which no View records exist (making them invisible in the
' console). Done as a nested loop rather than a subquery because ADO
' joins in subqueries can be too much for the provider.

function cleanMachineViews (adoConnection)
dim query
query = "select Machine.ID as x " & _
"from Machine left join MachineView " & _
"on machine.id = machineView.machineId " & _
"where machineView.machineId is NULL"

dim rs
set rs = adoConnection.execute (query, rows, 1)

dim cmd
set cmd = CreateObject ("ADODB.Command")
cmd.ActiveConnection = adoConnection
cmd.CommandText = "delete from Machine where Id = ?"
cmd.CommandType = 1
cmd.Parameters.refresh

do while not rs.EOF
cleanMachineViews = true

cmd.Parameters(0).value = rs.fields.item("x").value
cmd.execute
rs.MoveNext
loop

rs.Close
end function

' Run a query and get the client view information into three sets of
' collections - we want to map client IDs to view IDs, view IDs to names,
' and view IDs to their parents (where they exist).

sub loadMachineViews (adoRecord)
maxMachine = 0
maxView = 0

' Run a query and get the client view information into three sets of
' collections - we want to map client IDs to view IDs, view IDs to names,
' and view IDs to their parents (where they exist).

dim query
query = "select ID, Description, MachineID, ParentID " & _
"from MachineView order by ID desc"

adoRecord.Open (query)

do while not adoRecord.EOF
dim machineId
machineId = adoRecord ("MachineID")

dim id
id = adoRecord ("ID")

if IsEmpty (names) or id > maxView then
maxView = id
redim preserve names (id)
redim preserve parents (id)
end if

names (id) = adoRecord ("Description")
parents (id) = adoRecord ("ParentID")

if Not IsNull (machineId) then
if machineId > maxMachine then
maxMachine = machineId
redim preserve machines (machineId)
end if

machines (machineId) = id
end if
adoRecord.MoveNext
loop

adoRecord.Close
end sub

' Use the machines, names, and parents arrays to builds a pathname right-to-left

function getPath (id, escape)
dim viewId
viewId = machines (id)

if viewId = "" then
getPath = ""
exit function
end if

dim str
str = names (viewId)
if escape then
str = urlEscape (str)
end if

do while Not IsNull (parents (viewId))
viewId = parents (viewId)

dim parent
parent = names (viewId)
if escape then
parent = urlEscape (parent)
end if

str = parent & "\" & str
loop

getPath = str
end function

</script>

</job>

Change log

r15 by nigel.bree on Aug 28, 2009   Diff
As I've not heard any reports of problems
with the Vista branch of the tools (and no
reports about Windows 7, although I
haven't yet had time to personally re-test
everything with Win7), it's past time that
I reintegrated the changes into the trunk
and prepared a fresh download.
Go to: 
Project members, sign in to write a code review

Older revisions

r2 by nigel.bree on Apr 3, 2008   Diff
Initial checkin transferring the basic
scripts from my personal repository
with a BSD license attached.
All revisions of this file

File info

Size: 10615 bytes, 380 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting