-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathwuapis.py
672 lines (487 loc) · 22.2 KB
/
wuapis.py
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
import sqlite3
import logging, logging.handlers
import globs
import BamLogger
from db.bam_analysis_db import prodvgtebyname
from support.utils import verifyhex
_wulogger = logging.getLogger("BAM.wuapis")
def db_logconfig(queue):
global _wulogger
qh = logging.handlers.QueueHandler(queue)
_wulogger.addHandler(qh)
_wulogger.setLevel(logging.DEBUG)
def getsupersededfromfiledigest(filedigest):
'''
Lists all superseded updates
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getsupersededfromfile")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT * FROM SUSDB.dbo.tbFileForRevision as ffr '
'JOIN SUSDB.dbo.tbBundleDependency tbd ON tbd.BundledRevisionID = ffr.RevisionID '
'JOIN SUSDB.dbo.tbRevisionSupersedesUpdate rsu ON rsu.RevisionID = tbd.RevisionID '
'JOIN SUSDB.dbo.tbUpdate u ON u.UpdateID = rsu.SupersededUpdateID '
'WHERE ffr.FileDigest = {}').format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getsupersededfromfile")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getsupersededfromfile (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getsupersededfromfiledigest_custom(filedigest):
'''
File to superseded updates; Determines if Digest is superseding (list all superseded updates for file if any)
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getsupersededfromfile")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;'
'DECLARE @supersededupdates table '
'(FileDigest varbinary(max), RevisionID INT, FileName varchar(max), '
'LegacyName varchar(max), SupersededUpdateID uniqueidentifier);'
'INSERT INTO @supersededupdates (FileDigest, RevisionID, FileName, LegacyName, SupersededUpdateID) '
'SELECT ffr.FileDigest, ffr.RevisionID, f.FileName, u.LegacyName, rsu.SupersededUpdateID '
'FROM SUSDB.dbo.tbFileForRevision as ffr '
'JOIN SUSDB.dbo.tbBundleDependency tbd ON tbd.BundledRevisionID = ffr.RevisionID '
'JOIN SUSDB.dbo.tbRevisionSupersedesUpdate rsu ON rsu.RevisionID = tbd.RevisionID '
'JOIN SUSDB.dbo.tbUpdate u ON u.UpdateID = rsu.SupersededUpdateID '
'JOIN SUSDB.dbo.tbFile f ON f.FileDigest = ffr.FileDigest '
'WHERE ffr.FileDigest = {};'
'SELECT * FROM @supersededupdates').format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getsupersededfromfile")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getsupersededfromfile (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getsupersedingfromfile(filedigest):
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getsupersedingfromfile")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = (''
'SET NOCOUNT ON;DECLARE @supersedingupdates table (FileDigest varbinary(max), RevisionID INT, '
'LegacyName varchar(max), SuperRevisionID int);'
'INSERT INTO @supersedingupdates (FileDigest, RevisionID, LegacyName, SuperRevisionID) '
' SELECT ffr.FileDigest, ffr.RevisionID, u.LegacyName, rsu.RevisionID FROM SUSDB.dbo.tbFileForRevision as ffr'
' JOIN SUSDB.dbo.tbBundleDependency tbd ON tbd.BundledRevisionID = ffr.RevisionID'
' JOIN SUSDB.dbo.tbRevision r ON r.RevisionID = tbd.RevisionID'
' JOIN SUSDB.dbo.tbUpdate u ON u.LocalUpdateID = r.LocalUpdateID'
' JOIN SUSDB.dbo.tbRevisionSupersedesUpdate rsu ON rsu.SupersededUpdateID = u.UpdateID'
' WHERE ffr.FileDigest = {};'
'SELECT * FROM tbUpdate WHERE LocalUpdateID IN (SELECT LocalUpdateID FROM tbRevision'
' WHERE RevisionID IN (SELECT SuperRevisionID FROM @supersedingupdates));').format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getsupersedingfromfile")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getsupersedingfromfile (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getfiledigestbattributeswodu(filedigest):
'''
Digest (cab/exe) to KB (file to KB) with other WSUS information (Bundled)
without DefinitionUpdates
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getfiledigestbattributeswodu")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT * FROM SUSDB.dbo.tbFileForRevision AS ffr '
'JOIN SUSDB.dbo.tbBundleDependency tbd ON tbd.BundledRevisionID = ffr.RevisionID '
'JOIN SUSDB.dbo.tbRevision r ON r.RevisionID = tbd.RevisionID '
'JOIN SUSDB.dbo.tbUpdate u ON u.LocalUpdateID = r.LocalUpdateID '
'JOIN SUSDB.PUBLIC_VIEWS.vUpdate vu ON vu.UpdateId = u.UpdateID '
"WHERE ffr.FileDigest = {} AND ClassificationId != 'E0789628-CE08-4437-BE74-2495B842F43B'").format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getfiledigestbattributeswodu")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getfiledigestbattributeswodu (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getfiledigestbattributes(filedigest):
'''
Digest (cab/exe) to KB (file to KB) with other WSUS information (Bundled)
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getfiledigestbattributes")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT * FROM SUSDB.dbo.tbFileForRevision AS ffr '
'JOIN SUSDB.dbo.tbBundleDependency tbd ON tbd.BundledRevisionID = ffr.RevisionID '
'JOIN SUSDB.dbo.tbRevision r ON r.RevisionID = tbd.RevisionID '
'JOIN SUSDB.dbo.tbUpdate u ON u.LocalUpdateID = r.LocalUpdateID '
'JOIN SUSDB.PUBLIC_VIEWS.vUpdate vu ON vu.UpdateId = u.UpdateID '
' WHERE ffr.FileDigest = {}').format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getfiledigestbattributes")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getfiledigestbattributes (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getfiledigestattributeswodu(filedigest):
'''
Digest (cab/exe) to KB (file to KB) with other WSUS information
without DefinitionUpdates.
May return multiple results.
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getfiledigestattributeswodu")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT * FROM SUSDB.dbo.tbFileForRevision AS ffr'
' JOIN SUSDB.dbo.tbRevision r ON r.RevisionID = ffr.RevisionID'
' JOIN SUSDB.dbo.tbUpdate u ON u.LocalUpdateID = r.LocalUpdateID'
' JOIN SUSDB.PUBLIC_VIEWS.vUpdate vu ON vu.UpdateId = u.UpdateID'
" WHERE ffr.FileDigest = {} AND ClassificationId != 'E0789628-CE08-4437-BE74-2495B842F43B'").format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getfiledigestattributeswodu")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getfiledigestattributeswodu (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getfiledigestattributes(filedigest):
'''
Digest (cab/exe) to KB (file to KB) with other WSUS information.
May return multiple results.
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getfiledigestattributes")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT * FROM SUSDB.dbo.tbFileForRevision AS ffr'
' JOIN SUSDB.dbo.tbRevision r ON r.RevisionID = ffr.RevisionID'
' JOIN SUSDB.dbo.tbUpdate u ON u.LocalUpdateID = r.LocalUpdateID'
' JOIN SUSDB.PUBLIC_VIEWS.vUpdate vu ON vu.UpdateId = u.UpdateID'
' WHERE ffr.FileDigest = {}').format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getfiledigestattributes")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getfiledigestattributes (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getfileattrbyfnprodv(filename, prodversion):
bamcursor = globs.DBCONN.cursor()
wsuscursor = globs.DBWSUSCONN.cursor()
filelist = prodvgtebyname(bamcursor, filename, prodversion)
hashlist = []
for row in filelist:
for column in row.keys():
if column == 'UpdateId':
result = findupdate(row[column])
if len(result) == 0:
continue
hexfiledigest = verifyhex("0x" + row[column])
if hexfiledigest is None:
_wulogger.log(logging.DEBUG,
"[WUAPIS] {} not valid hex: getfileattrbyfnprodv".format(row[column]))
continue
hashlist.append(hexfiledigest)
fileattrlist = []
for hash in hashlist:
r = getfiledigestbattributes(hash)
if len(r) == 0:
continue
fileattrlist.append(r)
bamcursor.close()
wsuscursor.close()
return fileattrlist
def findupdate(updateid):
global _wulogger
result = []
if not isinstance(updateid, str):
return result
wsuscursor = globs.DBWSUSCONN.cursor()
bamcursor = globs.DBCONN.cursor()
utbname = globs.UPDATEFILESDBNAME
check = bamcursor.execute("SELECT FileName FROM {} WHERE FileName = '{}'".format(utbname, updateid))
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from findupdate")
bamcursor.close()
wsuscursor.close()
return result
result = bamcursor.fetchall()
bamcursor.close()
wsuscursor.close()
return result
def getKBoffiledigest(filedigest):
'''
Digest (cab/exe) to KB (file to KB)
'''
global _wulogger
result = []
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getKBoffiledigest")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT * FROM SUSDB.dbo.tbFileForRevision as ffr '
'JOIN SUSDB.dbo.tbBundleDependency tbd ON ffr.RevisionID = tbd.BundledRevisionID '
'JOIN SUSDB.dbo.tbKBArticleForRevision kbfr ON kbfr.RevisionID = tbd.RevisionID '
'WHERE ffr.FileDigest = {}').format(hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getKBoffiledigest")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getKBoffiledigest (" + str(filedigest) + ")")
wsuscursor.close()
return result
def getKBtofiledigest(kbarticle):
'''
KB to file(s) without matching platform
'''
global _wulogger
result = []
try:
kbarticleint = int(kbarticle)
except ValueError:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid int: getKBtofiledigest")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT f.FileDigest, f.FileName, kbafr.KBArticleID '
'FROM SUSDB.dbo.tbKBArticleForRevision kbafr '
'JOIN SUSDB.dbo.tbBundleDependency bd ON kbafr.RevisionID = bd.RevisionID '
'JOIN SUSDB.dbo.tbFileForRevision ffr ON ffr.RevisionID = bd.BundledRevisionID '
'JOIN SUSDB.dbo.tbFile f ON f.FileDigest = ffr.FileDigest '
'WHERE kbafr.KBArticleID = {} ORDER BY FileDigest').format(str(kbarticle))
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getKBtofiledigest")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getKBtofiledigest (" + str(kbarticle) + ")")
wsuscursor.close()
return result
def getKBtoufiledigest(kbarticle, filedigest):
'''
KB to filedigest with matching platform
'''
global _wulogger
result = []
try:
kbarticleint = int(kbarticle)
except ValueError:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid int: getKBtofiledigest")
return result
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: getKBoffiledigest")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ('SET NOCOUNT ON;SELECT f.FileDigest, f.FileName, kbafr.KBArticleID '
'FROM SUSDB.dbo.tbKBArticleForRevision kbafr '
'JOIN SUSDB.dbo.tbBundleDependency bd ON kbafr.RevisionID = bd.RevisionID '
'JOIN SUSDB.dbo.tbFileForRevision ffr ON ffr.RevisionID = bd.BundledRevisionID '
'JOIN SUSDB.dbo.tbFile f ON f.FileDigest = ffr.FileDigest '
'WHERE kbafr.KBArticleID = {} AND ffr.FileDigest = {} '
'').format(str(kbarticle), hexfiledigest)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from getKBtofiledigest")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from getKBtofiledigest (" + str(kbarticle) + ")")
wsuscursor.close()
return result
def findfileswithkb(kbarticle):
'''
find files that have a filename with KB number in it. May not guarantee to capture all related files.
'''
global _wulogger
result = []
try:
kbarticleint = int(kbarticle)
except ValueError:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid int: findfileswithkb")
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ("SET NOCOUNT ON;SELECT FileName, FileDigest FROM SUSDB.dbo.tbFile "
"WHERE FileName collate SQL_Latin1_General_CP1_CI_AS LIKE '%{}%'").format(str(kbarticle))
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from findfileswithkb")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from findfileswithkb (" + str(kbarticle) + ")")
wsuscursor.close()
return result
def findupdateinfo(updateid):
global _wulogger
result = []
if not isinstance(updateid, str):
return result
wsuscursor = globs.DBWSUSCONN.cursor()
tsql = ("SET NOCOUNT ON;SELECT * FROM SUSDB.PUBLIC_VIEWS.vUpdate "
"WHERE UpdateId = CAST('{}' as uniqueidentifier)").format(updateid)
check = wsuscursor.execute(tsql)
if check is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] Did not find entries from findupdateinfo")
wsuscursor.close()
return result
result = wsuscursor.fetchall()
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from findupdateinfo" + "(" + str(updateid) +")")
wsuscursor.close()
return result
def kbtosupersedingkb(kbarticle, filedigest):
global _wulogger
result = []
try:
kbarticleint = int(kbarticle)
except ValueError:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid int: kbtosupersedingkb" + "(" + str(kbarticle) + ")")
return result
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: kbtosupersedingkb")
return result
updateinfo = []
fdlist = getKBtoufiledigest(kbarticle, hexfiledigest)
if len(fdlist) == 0:
return result
for filed in fdlist:
superfiles = getsupersedingfromfile(filed[0])
if len(superfiles) == 0:
continue
for superfile in superfiles:
uinfo = findupdateinfo(superfile[1])
if len(uinfo) == 0:
continue
if uinfo[0][13] is not None:
updateinfo.append(uinfo[0][13])
kbsorted = []
if len(updateinfo) != 0:
kbsorted = list(sorted(set(updateinfo)))
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from kbtosupersedingkb (" + str(kbarticle) + ")")
return kbsorted
def kbtosupersededkb(kbarticle, filedigest):
global _wulogger
result = []
try:
kbarticleint = int(kbarticle)
except ValueError:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid int: kbtosupersededkb")
return result
hexfiledigest = verifyhex(filedigest)
if hexfiledigest is None:
_wulogger.log(logging.DEBUG, "[WUAPIS] argument not valid hex: kbtosupersededkb")
return result
updateinfo = []
fdlist = getKBtoufiledigest(kbarticle, hexfiledigest)
if len(fdlist) == 0:
return result
for filed in fdlist:
superfiles = getsupersededfromfiledigest(filed[0])
if len(superfiles) == 0:
continue
for superfile in superfiles:
uinfo = findupdateinfo(superfile[6])
if len(uinfo) == 0:
continue
if uinfo[0][13] is not None:
updateinfo.append(uinfo[0][13])
kbsorted = []
if len(updateinfo) != 0:
kbsorted = list(sorted(set(updateinfo)))
_wulogger.log(logging.DEBUG, "[WUAPIS] Found entries from kbtosupersededkb (" + str(kbarticle) + ")")
return kbsorted
def updatewuentrysecedenceinfo():
bamcursor = globs.DBCONN.cursor()
bamcursor.execute("SELECT SHA1 FROM " + globs.UPDATEFILESDBNAME + " WHERE Seceding = '' OR SecededBy = ''")
result = bamcursor.fetchall()
count = 0
bamcursor.execute("BEGIN TRANSACTION")
for row in result:
for column in row.keys():
if str(row[column]) != 'None':
fattrs = getfiledigestbattributeswodu(row[column])
kbarticle = None
if len(fattrs) == 0: # Update is not part of a bundle
fattrs = getfiledigestattributeswodu(row[column])
if len(fattrs) == 0:
_wulogger.log(logging.DEBUG, "[WUAPIS] Possibly a DefinitionUpdate. Skipping...")
continue
kbarticle = fattrs[0][42]
else:
kbarticle = fattrs[0][44]
# check if file has an assoicated KB number
if kbarticle is not None:
superseding = kbtosupersedingkb(kbarticle, row[column])
superseded = kbtosupersededkb(kbarticle, row[column])
secededlist = ""
secedinglist = ""
if len(superseding) == 0 and len(superseded) == 0:
pass
elif len(superseding) == 0:
secededlist = ','.join(superseded)
bamcursor.execute(("UPDATE UpdateFiles"
" SET Seceding = "
"'{}' WHERE SHA1 = '{}'").format(secededlist, row[column]))
elif len(superseded) == 0:
secedinglist = ",".join(superseding)
bamcursor.execute(("UPDATE UpdateFiles"
" SET SecededBy = "
"'{}' WHERE SHA1 = '{}'").format(secedinglist, row[column]))
else:
bamcursor.execute(("UPDATE UpdateFiles"
" SET Seceding = "
"'{}' WHERE SHA1 = '{}'").format(secededlist, row[column]))
bamcursor.execute(("UPDATE UpdateFiles"
" SET SecededBy = "
"'{}' WHERE SHA1 = '{}'").format(secedinglist, row[column]))
count = count + 1
if count % 5000 == 0:
bamcursor.execute("END TRANSACTION")
bamcursor.execute("BEGIN TRANSACTION")
else:
_wulogger.log(logging.DEBUG, "[WUAPIS] Skipping no KB...")
bamcursor.execute("END TRANSACTION")
bamcursor.close()
return result