-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathzcleanup_password_hash_valuesx.prog.abap
1359 lines (1115 loc) · 45.7 KB
/
zcleanup_password_hash_valuesx.prog.abap
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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*&---------------------------------------------------------------------*
*& Report ZCLEANUP_PASSWORD_HASH_VALUESX
*&
*&---------------------------------------------------------------------*
*& Extended version of the program to remove all weak password hash values in user master data, change documents and password history
*& Use it on your own risk!
*&
*& 20.07.2022 Initial version
*& 28.07.2022 Typos corrected
*& Interpret BCODE and PASSCODE with code versions space, A, D, X as redundant
*& Correction: only selected entries for USH02 and USRPWDHISTORY are deleted (not all of that selected user)
*& 24.08.2022 Correction in showing the profile parameter values on the report selection screen
*& 22.12.2022 Correction of the PWDSALTEDHASH icon for USH02
*&---------------------------------------------------------------------*
REPORT zcleanup_password_hash_valuesx
LINE-SIZE 132.
CONSTANTS: c_program_version(30) TYPE c VALUE '22.12.2022 OQL'.
"INCLUDE <color>.
"INCLUDE <icon>.
"INCLUDE <symbol>.
TABLES: usr02, ush02, usrpwdhistory.
TYPES:
BEGIN OF ts_result,
tabname TYPE tabname, " Table name
mandt TYPE mandt, " Client
bname TYPE xubname, " User
modda TYPE xumoddate, " Modification date in USH02 and USRPWDHISTORY
modti TYPE xumodtime, " Modification time in USH02 and USRPWDHISTORY
class TYPE xuclass, " Group
ustyp TYPE xuustyp, " Type
uflag TYPE xuuflag, " Lock
gltgv TYPE xugltgv, " From date
gltgb TYPE xugltgb , " To date
zbvmaster TYPE xuzbvflag, " CUA flag
trdat TYPE xuldate, " Login date
ltime TYPE xultime, " Login time
user_status TYPE text15, " status 'inactive'
codvn TYPE xucodever2, " Code version
xbcode TYPE icon_d, " BCODE
xpasscode TYPE icon_d, " PASSCODE
xpwdsaltedhash TYPE icon_d, " PWDSALTEDHASH
comment TYPE text132, " Comment
t_color TYPE lvc_t_scol, " ALV color of row
timestamp type TIMESTAMP, " Time stamp in USRPWDHISTORY (hidden, converted to MODDA, MODTI)
END OF ts_result.
DATA:
ls_result TYPE ts_result,
lt_result TYPE TABLE OF ts_result,
ls_usr02 TYPE usr02,
ls_ush02 TYPE ush02,
ls_usrpwdhistory TYPE usrpwdhistory.
CONSTANTS:
empty_bcode LIKE usr02-bcode VALUE 0,
empty_passcode LIKE usr02-passcode VALUE 0.
*------------------------------------------------------------------------*
* Selection screen
*------------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK usr WITH FRAME TITLE text001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) ss_mandt FOR FIELD mandt.
SELECT-OPTIONS mandt FOR usr02-mandt DEFAULT sy-mandt.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) ss_bname FOR FIELD bname.
SELECT-OPTIONS bname FOR usr02-bname.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) ss_codvn FOR FIELD codvn.
SELECT-OPTIONS codvn FOR usr02-codvn.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_usr02 AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(79) ss_usr02 FOR FIELD s_usr02.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_ush02 AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(79) ss_ush02 FOR FIELD s_ush02.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_hist AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 2(79) ss_hist FOR FIELD s_hist.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK usr.
SELECTION-SCREEN BEGIN OF BLOCK lgn WITH FRAME TITLE text002.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) ss_class FOR FIELD class.
SELECT-OPTIONS class FOR usr02-class.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) ss_ustyp FOR FIELD ustyp.
SELECT-OPTIONS ustyp FOR usr02-ustyp.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) ss_uflag FOR FIELD uflag.
SELECT-OPTIONS uflag FOR usr02-uflag.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_lvl1 RADIOBUTTON GROUP lvl DEFAULT 'X'.
SELECTION-SCREEN COMMENT 2(79) ss_lvl1 FOR FIELD s_lvl1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_lvl2 RADIOBUTTON GROUP lvl.
SELECTION-SCREEN COMMENT 2(79) ss_lvl2 FOR FIELD s_lvl2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_lvl3 RADIOBUTTON GROUP lvl.
SELECTION-SCREEN COMMENT 2(79) ss_lvl3 FOR FIELD s_lvl3.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK lgn.
SELECTION-SCREEN BEGIN OF BLOCK par WITH FRAME TITLE text003.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par01.
SELECTION-SCREEN COMMENT 44(8) s_par01.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par02.
SELECTION-SCREEN COMMENT 44(8) s_par02.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par03.
SELECTION-SCREEN COMMENT 44(8) s_par03.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par04.
SELECTION-SCREEN COMMENT 44(8) s_par04.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par05.
SELECTION-SCREEN COMMENT 44(8) s_par05.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par06.
SELECTION-SCREEN COMMENT 44(8) s_par06.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(43) ss_par07.
SELECTION-SCREEN COMMENT 44(8) s_par07.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK par.
* Layout of ALV output
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) ps_lout FOR FIELD p_layout.
PARAMETERS p_layout TYPE disvariant-variant.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN COMMENT 1(60) ss_vers.
*----------------------------------------------------------------------*
DATA: gs_alv_lout_variant TYPE disvariant.
*----------------------------------------------------------------------*
INITIALIZATION.
text001 = 'User selection'.
ss_mandt = 'Client'.
ss_bname = 'User'.
ss_usr02 = 'Logon data (USR02)'.
ss_ush02 = 'Change documents (USH02)'.
ss_hist = 'Password history (USRPWDHISTORY)'.
text002 = 'Additional selection for logon data (USR02)'.
ss_class = 'User group'.
ss_ustyp = 'User type'.
ss_uflag = 'Lock status'.
ss_codvn = 'Code version of password hash'.
ss_lvl1 = 'Show and process redundant password hashes only (safe)'.
ss_lvl2 = 'Show and process weak password hashes of inactive users, too (critical!)'.
ss_lvl3 = 'Show and process weak password hashes of active users, too (danger!)'.
text003 = 'Profile parameter'.
ss_par01 = 'login/password_downwards_compatibility'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par01 ID 'VALUE' FIELD s_par01.
ss_par02 = 'login/password_compliance_to_current_policy'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par02 ID 'VALUE' FIELD s_par02.
ss_par03 = 'login/min_password_lng'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par03 ID 'VALUE' FIELD s_par03.
ss_par04 = 'login/min_password_lowercase'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par04 ID 'VALUE' FIELD s_par04.
ss_par05 = 'login/min_password_uppercase'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par05 ID 'VALUE' FIELD s_par05.
ss_par06 = 'login/min_password_digits'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par06 ID 'VALUE' FIELD s_par06.
ss_par07 = 'login/min_password_specials'.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD ss_par07 ID 'VALUE' FIELD s_par07.
ps_lout = 'Layout'.
CONCATENATE 'Program version:'(VER) c_program_version INTO ss_vers
SEPARATED BY space.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON p_layout
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON p_layout.
CHECK NOT p_layout IS INITIAL.
PERFORM handle_at_selscr_on_p_layout USING p_layout sy-repid 'A'.
*
FORM handle_at_selscr_on_p_layout
USING id_varname TYPE disvariant-variant
id_repid TYPE sy-repid
id_save TYPE c.
DATA: ls_variant TYPE disvariant.
ls_variant-report = id_repid.
ls_variant-variant = id_varname.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = id_save
CHANGING
cs_variant = ls_variant
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Selected layout variant is not found
MESSAGE e204(0k).
ENDIF.
gs_alv_lout_variant-report = id_repid.
gs_alv_lout_variant-variant = id_varname.
ENDFORM. " handle_at_selscr_on_p_layout
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout. " ( Note 890141 )
PERFORM handle_at_selscr_f4_p_layout USING sy-repid 'A'
CHANGING p_layout.
*
FORM handle_at_selscr_f4_p_layout
USING id_repid TYPE sy-repid
id_save TYPE c
CHANGING ed_varname TYPE disvariant-variant.
gs_alv_lout_variant-report = id_repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = gs_alv_lout_variant
i_save = id_save
IMPORTING
es_variant = gs_alv_lout_variant
EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 0.
ed_varname = gs_alv_lout_variant-variant.
ELSE.
MESSAGE s073(0k).
* Keine Anzeigevariante(n) vorhanden
ENDIF.
ENDFORM. " handle_at_selscr_f4_p_layout
*----------------------------------------------------------------------*
START-OF-SELECTION.
*------------------------------------------------------------------------*
* Check usage boundaries for cross-client operation
*------------------------------------------------------------------------*
FORMAT RESET.
AUTHORITY-CHECK OBJECT 'S_TABU_CLI' ID 'CLIIDMAINT' FIELD 'X'.
IF sy-subrc <> 0.
WRITE: / 'You do not have authorizations for cross-client operations (S_TABU_CLI)' COLOR COL_NEGATIVE.
RETURN.
ENDIF.
DATA flag_ok TYPE abap_bool.
flag_ok = abap_true.
PERFORM check_table_authorization USING 'USR02' CHANGING flag_ok.
PERFORM check_table_authorization USING 'USH02' CHANGING flag_ok.
PERFORM check_table_authorization USING 'USRPWDHISTORY' CHANGING flag_ok.
IF flag_ok <> abap_true.
WRITE: / 'You do not have authorizations for table operations (S_TABU_DIS/S_TABU_NAM)' COLOR COL_NEGATIVE.
RETURN.
ENDIF.
" AUW Report &A started
CALL FUNCTION 'RSLG_WRITE_SYSLOG_ENTRY'
EXPORTING
data_word1 = 'ZCLEANUP_PASSWORD_HASH_VALUESX'
sl_message_area = 'AU'
sl_message_subid = 'W'
EXCEPTIONS
OTHERS = 0. "ignore
*------------------------------------------------------------------------*
* Do it
*------------------------------------------------------------------------*
PERFORM load_data.
PERFORM show_result.
*------------------------------------------------------------------------*
FORM check_table_authorization USING name TYPE string CHANGING flag_ok TYPE abap_bool.
DATA: l_name TYPE dd25v-viewname,
l_errormessage TYPE string.
l_name = name.
CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
EXPORTING
view_action = 'U'
view_name = l_name
no_warning_for_clientindep = 'X'
EXCEPTIONS
invalid_action = 1
no_authority = 2
no_clientindependent_authority = 3
table_not_found = 4
OTHERS = 5.
IF sy-subrc = 2 OR sy-subrc = 3.
l_errormessage = 'You are not authorizated to update table $TABNAME$ (S_TABU_DIS / S_TABU_NAM)'(E03).
REPLACE '$TABNAME$' IN l_errormessage WITH name.
WRITE: / l_errormessage.
flag_ok = abap_false.
ENDIF.
ENDFORM. "check_table_authorization
*------------------------------------------------------------------------*
* Load data
*------------------------------------------------------------------------*
FORM load_data.
* ALV Color of entry
DATA: lt_color TYPE lvc_t_scol,
ls_color TYPE lvc_s_scol.
IF s_usr02 = 'X'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 25
text = 'Load user data'.
CLEAR ls_result.
ls_result-tabname = 'USR02'.
SELECT
u~mandt
u~bname
u~class
u~ustyp
u~uflag
u~gltgv
u~gltgb
u~zbvmaster
u~trdat
u~ltime
u~codvn
u~bcode
u~passcode
u~pwdsaltedhash
FROM usr02 AS u
CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF ls_usr02
WHERE u~mandt IN mandt
AND u~bname IN bname
AND u~class IN class
AND u~ustyp IN ustyp
AND u~uflag IN uflag
AND u~codvn IN codvn
AND ( u~bcode NE empty_bcode
OR u~passcode NE empty_passcode )
ORDER BY u~mandt u~bname.
MOVE-CORRESPONDING ls_usr02 TO ls_result.
" ICON_INCOMPLETE ICON_FAILURE ICON_POSITIVE ICON_NEGATIVE ICON_MESSAGE_ERROR ICON_MESSAGE_CRITICAL ICON_LED_RED
" ICON_MESSAGE_CRITICAL_SMALL ICON_MESSAGE_WARNING_SMALL
" ICON_ALERT ICON_WARNING
CLEAR: ls_result-xbcode, ls_result-xpasscode, ls_result-xpwdsaltedhash.
IF ls_usr02-bcode IS NOT INITIAL. ls_result-xbcode = icon_incomplete. ENDIF.
IF ls_usr02-passcode IS NOT INITIAL. ls_result-xpasscode = icon_incomplete. ENDIF.
IF ls_usr02-pwdsaltedhash IS NOT INITIAL. ls_result-xpwdsaltedhash = icon_checked. ENDIF.
IF ls_usr02-uflag IS NOT INITIAL
OR ( ls_usr02-gltgv IS NOT INITIAL AND ls_usr02-gltgv > sy-datum )
OR ( ls_usr02-gltgb IS NOT INITIAL AND ls_usr02-gltgb < sy-datum )
OR ls_usr02-zbvmaster IS NOT INITIAL
"or usr02-TRDAT is not initial " caution: active job users do not update this field
.
ls_result-user_status = 'inactive'.
ELSE.
ls_result-user_status = space.
ENDIF.
CLEAR: ls_color, lt_color.
ls_color-fname = 'COMMENT'.
ls_result-comment = space.
CASE ls_usr02-codvn.
WHEN 'A'. " Code Version A (Obsolete)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'B'. " BCODE Code Version B (MD5-Based, 8 Characters, Upper-Case, ASCII)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_negative.
WHEN 'D'. " Code Version D (MD5-Based, 8 Characters, Upper-Case, UTF-8)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'E'. " Code Version E (Corrected Code Version D)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_negative.
WHEN 'F'. " Code Version F (SHA1, 40 Characters, Case-Sensitive, UTF-8)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_negative.
WHEN 'G'. " Code Version G = Code Vers. F + Code Vers. B (2 Hash Values)
ls_result-comment = 'redundant and weak password hash'.
ls_color-color-col = col_negative.
WHEN 'H'. " PWDSALTEDHASH Code Version H (Generic Hash Procedure)
ls_result-comment = 'ok'.
ls_color-color-col = col_positive.
WHEN 'I'. " Code Version I = Code Versions H + F + B (Three Hash Values)
ls_result-comment = 'redundant and weak password hashes'.
ls_color-color-col = col_group.
WHEN 'X'. " Password Deactivated
ls_result-comment = 'no password'.
ls_color-color-col = col_positive.
WHEN OTHERS.
ls_result-comment = 'unknown hash version'.
ls_color-color-col = col_total.
ENDCASE.
APPEND ls_color TO lt_color.
ls_result-t_color = lt_color.
IF ( s_lvl1 = 'X' AND ( ls_result-codvn CA ' ADGIX' ) )
OR ( s_lvl2 = 'X' AND ( ls_result-codvn CA ' ADGIX' OR ls_result-user_status IS NOT INITIAL ) )
OR ( s_lvl3 = 'X' ).
APPEND ls_result TO lt_result.
ENDIF.
ENDSELECT.
ENDIF.
IF s_ush02 = 'X'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 50
text = 'Load change documents'.
CLEAR ls_result.
ls_result-tabname = 'USH02'.
SELECT
h~mandt
h~bname
h~modda
h~modti
h~modbe
h~tcode
h~repid
h~bcode
h~gltgv
h~gltgb
h~ustyp
h~class
h~uflag
h~accnt
h~passcode
h~codvn
h~pwdinitial
h~pwdsaltedhash
h~security_policy
FROM ush02 AS h
CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF ls_ush02
WHERE h~mandt IN mandt
AND h~bname IN bname
AND h~codvn IN codvn
AND ( h~bcode NE empty_bcode
OR h~passcode NE empty_passcode )
ORDER BY h~mandt h~bname h~modbe DESCENDING h~modti DESCENDING.
" Do we know this user already?
IF ls_ush02-mandt NE ls_result-mandt
OR ls_ush02-bname NE ls_result-bname.
SELECT SINGLE mandt bname
FROM usr02
CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF ls_result
WHERE mandt = ls_ush02-mandt
AND bname = ls_ush02-bname
.
IF sy-subrc = 0.
ls_result-user_status = ''.
ELSE.
ls_result-user_status = 'deleted'.
ENDIF.
ENDIF.
MOVE-CORRESPONDING ls_ush02 TO ls_result.
CLEAR: ls_result-xbcode, ls_result-xpasscode, ls_result-xpwdsaltedhash.
IF ls_ush02-bcode IS NOT INITIAL. ls_result-xbcode = icon_incomplete. ENDIF.
IF ls_ush02-passcode IS NOT INITIAL. ls_result-xpasscode = icon_incomplete. ENDIF.
IF ls_ush02-pwdsaltedhash IS NOT INITIAL. ls_result-xpwdsaltedhash = icon_checked. ENDIF.
CLEAR: ls_color, lt_color.
ls_color-fname = 'COMMENT'.
ls_result-comment = space.
CASE ls_ush02-codvn.
WHEN 'A'. " Code Version A (Obsolete)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'B'. " BCODE Code Version B (MD5-Based, 8 Characters, Upper-Case, ASCII)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'D'. " Code Version D (MD5-Based, 8 Characters, Upper-Case, UTF-8)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'E'. " Code Version E (Corrected Code Version D)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'F'. " Code Version F (SHA1, 40 Characters, Case-Sensitive, UTF-8)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'G'. " Code Version G = Code Vers. F + Code Vers. B (2 Hash Values)
ls_result-comment = 'redundant and weak password hash'.
ls_color-color-col = col_total.
WHEN 'H'. " PWDSALTEDHASH Code Version H (Generic Hash Procedure)
ls_result-comment = 'ok'.
ls_color-color-col = col_positive.
WHEN 'I'. " Code Version I = Code Versions H + F + B (Three Hash Values)
ls_result-comment = 'redundant and weak password hashes'.
ls_color-color-col = col_group.
WHEN 'X'. " Password Deactivated
ls_result-comment = 'no password'.
ls_color-color-col = col_positive.
WHEN OTHERS.
ls_result-comment = 'unknown hash version'.
ls_color-color-col = col_total.
ENDCASE.
APPEND ls_color TO lt_color.
ls_result-t_color = lt_color.
APPEND ls_result TO lt_result.
ENDSELECT.
ENDIF.
IF s_hist = 'X'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 75
text = 'Load password history'.
CLEAR ls_result.
ls_result-tabname = 'USRPWDHISTORY'.
SELECT
h~mandt
h~bname
h~timestamp
h~passcode
h~bcode
h~codvn
h~pwdsaltedhash
FROM usrpwdhistory AS h
CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF ls_usrpwdhistory
WHERE h~mandt IN mandt
AND h~bname IN bname
AND h~codvn IN codvn
AND ( h~bcode NE empty_bcode
OR h~passcode NE empty_passcode )
ORDER BY h~mandt h~bname h~timestamp DESCENDING.
MOVE-CORRESPONDING ls_usrpwdhistory TO ls_result.
CLEAR: ls_result-xbcode, ls_result-xpasscode, ls_result-xpwdsaltedhash.
IF ls_usrpwdhistory-bcode IS NOT INITIAL. ls_result-xbcode = icon_incomplete. ENDIF.
IF ls_usrpwdhistory-passcode IS NOT INITIAL. ls_result-xpasscode = icon_incomplete. ENDIF.
IF ls_usrpwdhistory-pwdsaltedhash IS NOT INITIAL. ls_result-xpwdsaltedhash = icon_checked. ENDIF.
DATA tz TYPE systzonlo.
CONVERT TIME STAMP ls_usrpwdhistory-timestamp TIME ZONE tz INTO DATE ls_result-modda TIME ls_result-modti.
CLEAR: ls_color, lt_color.
ls_color-fname = 'COMMENT'.
ls_result-comment = space.
CASE ls_usrpwdhistory-codvn.
WHEN 'A'. " Code Version A (Obsolete)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'B'. " BCODE Code Version B (MD5-Based, 8 Characters, Upper-Case, ASCII)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'D'. " Code Version D (MD5-Based, 8 Characters, Upper-Case, UTF-8)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'E'. " Code Version E (Corrected Code Version D)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'F'. " Code Version F (SHA1, 40 Characters, Case-Sensitive, UTF-8)
ls_result-comment = 'weak password hash'.
ls_color-color-col = col_total.
WHEN 'G'. " Code Version G = Code Vers. F + Code Vers. B (2 Hash Values)
ls_result-comment = 'weak and outdated password hash'.
ls_color-color-col = col_total.
WHEN 'H'. " PWDSALTEDHASH Code Version H (Generic Hash Procedure)
ls_result-comment = 'ok'.
ls_color-color-col = col_positive.
WHEN 'I'. " Code Version I = Code Versions H + F + B (Three Hash Values)
ls_result-comment = 'weak password hashes'.
ls_color-color-col = col_group.
WHEN 'X'. " Password Deactivated
ls_result-comment = 'no password'.
ls_color-color-col = col_positive.
WHEN OTHERS.
ls_result-comment = 'unknown hash version'.
ls_color-color-col = col_total.
ENDCASE.
APPEND ls_color TO lt_color.
ls_result-t_color = lt_color.
APPEND ls_result TO lt_result.
ENDSELECT.
ENDIF.
ENDFORM.
*------------------------------------------------------------------------*
* Show result
*------------------------------------------------------------------------*
*---------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*---------------------------------------------------------------------*
* define a local class for handling events of cl_salv_table
*---------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function,
on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
* on_single_click for event link_click of cl_salv_events_table
* importing row column.
PRIVATE SECTION.
DATA: dialogbox_status TYPE c. "'X': does exist, SPACE: does not ex.
ENDCLASS. "lcl_handle_events DEFINITION
* main data table
DATA: gr_alv_table TYPE REF TO cl_salv_table.
* for handling the events of cl_salv_table
DATA: gr_alv_events TYPE REF TO lcl_handle_events.
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
* implement the events for handling the events of cl_salv_table
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.
* importing e_salv_function
DATA: ls_result TYPE ts_result,
lr_selections TYPE REF TO cl_salv_selections,
ls_cell TYPE salv_s_cell,
lt_seleced_rows TYPE salv_t_row,
l_row TYPE i.
" Get selected item
lr_selections = gr_alv_table->get_selections( ).
ls_cell = lr_selections->get_current_cell( ).
lt_seleced_rows = lr_selections->get_selected_rows( ).
CASE e_salv_function.
WHEN 'PICK'. " Double click
IF ls_cell-row > 0.
CLEAR ls_result.
READ TABLE lt_result INTO ls_result INDEX ls_cell-row.
IF sy-subrc = 0.
"...
ENDIF.
ENDIF.
WHEN 'NOTE'.
" Show note in browser
CALL FUNCTION 'OCS_CALL_BROWSER_WITH_NOTE'
EXPORTING
iv_note = '1458262'
EXCEPTIONS
OTHERS = 0. "don't care
" WHEN 'SU01'.
" " Show user (in current client only)
" IF ls_cell-row > 0.
" CLEAR ls_result.
" READ TABLE lt_result INTO ls_result INDEX ls_cell-row.
" IF ls_result-mandt = sy-mandt
" AND ls_result-bname IS NOT INITIAL.
" CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
" EXPORTING
" tcode = 'SU01'
" EXCEPTIONS
" ok = 0
" not_ok = 2
" OTHERS = 3.
" IF sy-subrc = 0.
" CALL FUNCTION 'SUID_IDENTITY_MAINT'
" EXPORTING
" i_username = ls_result-bname
" i_tcode_mode = 1
" i_su01_display = 'X'.
" ENDIF.
" ENDIF.
" ENDIF.
WHEN 'REMOVE'.
" Delete weak password hashes
READ TABLE lt_seleced_rows INTO l_row INDEX 1.
CHECK sy-subrc = 0.
" Ask user for confirmation
DATA: l_sel_cnt TYPE i,
l_textline1(132),
l_textline2(132),
l_textline3(132),
l_answer(8).
l_textline1 = 'Do you really want to remove weak password hashes?'.
DESCRIBE TABLE lt_seleced_rows LINES l_sel_cnt.
IF l_sel_cnt = 1.
l_textline2 = '1 entry selected'.
ELSEIF l_sel_cnt > 1.
l_answer = l_sel_cnt.
CONCATENATE l_answer 'entries selected'
INTO l_textline2 SEPARATED BY space.
ELSE.
RETURN. "nothing selected
ENDIF.
CLEAR l_answer.
CALL FUNCTION 'POPUP_TO_DECIDE' ##FM_OLDED
EXPORTING
defaultoption = '2'
textline1 = l_textline1
textline2 = l_textline2
textline3 = l_textline3
text_option1 = 'Remove'
text_option2 = 'Cancel'
icon_text_option1 = 'ICON_DELETE'
icon_text_option2 = 'ICON_CANCEL'
titel = 'Remove weak password hashes'
* START_COLUMN = 25
* START_ROW = 6
cancel_display = space "'X'
IMPORTING
answer = l_answer.
IF l_answer <> '1'.
RETURN.
ENDIF.
" do it !
FIELD-SYMBOLS <fs_result> TYPE ts_result.
LOOP AT lt_seleced_rows INTO l_row.
CLEAR ls_result.
READ TABLE lt_result ASSIGNING <fs_result> INDEX l_row.
CHECK sy-subrc = 0 AND <fs_result>-tabname IS NOT INITIAL.
CASE <fs_result>-tabname.
WHEN 'USR02'.
IF ( s_lvl1 = 'X' AND ( <fs_result>-codvn CA ' ADIX' ) )
OR ( s_lvl2 = 'X' AND ( <fs_result>-codvn CA ' ADIX' OR <fs_result>-user_status IS NOT INITIAL ) )
OR ( s_lvl3 = 'X' ).
" remove BCODE and PASSCODE
CLEAR: <fs_result>-xbcode, <fs_result>-xpasscode.
<fs_result>-comment = 'removed'.
UPDATE usr02 CLIENT SPECIFIED
SET bcode = empty_bcode
ocod1 = empty_bcode
ocod2 = empty_bcode
ocod3 = empty_bcode
ocod4 = empty_bcode
ocod5 = empty_bcode
passcode = empty_passcode
WHERE mandt = <fs_result>-mandt
AND bname = <fs_result>-bname.
ELSE.
" remove BCODE only
CLEAR: <fs_result>-xbcode.
<fs_result>-comment = 'weak password hash removed'.
UPDATE usr02 CLIENT SPECIFIED
SET bcode = empty_bcode
ocod1 = empty_bcode
ocod2 = empty_bcode
ocod3 = empty_bcode
ocod4 = empty_bcode
ocod5 = empty_bcode
"passcode = empty_passcode
WHERE mandt = <fs_result>-mandt
AND bname = <fs_result>-bname.
ENDIF.
WHEN 'USH02'.
CLEAR: <fs_result>-xbcode, <fs_result>-xpasscode.
<fs_result>-comment = 'weak password hash removed'.
UPDATE ush02 CLIENT SPECIFIED
SET bcode = empty_bcode
passcode = empty_passcode
WHERE mandt = <fs_result>-mandt
AND bname = <fs_result>-bname
AND modda = <fs_result>-modda
AND modti = <fs_result>-modti.
WHEN 'USRPWDHISTORY'.
CLEAR: <fs_result>-xbcode, <fs_result>-xpasscode.
<fs_result>-comment = 'weak password hash removed'.
UPDATE usrpwdhistory CLIENT SPECIFIED
SET bcode = empty_bcode
passcode = empty_passcode
WHERE mandt = <fs_result>-mandt
AND bname = <fs_result>-bname
AND timestamp = <fs_result>-timestamp.
ENDCASE.
ENDLOOP.
* Update ALV list
IF sy-subrc = 0.
gr_alv_table->refresh( refresh_mode = if_salv_c_refresh=>soft ).
ENDIF.
ENDCASE.
ENDMETHOD. "on_user_command
METHOD on_double_click.
* importing row column
DATA: ls_result TYPE ts_result.
* DATA: lr_Selections type ref to cl_Salv_selections,
* ls_cell type salv_s_cell.
* Get selected item
* lr_selections = gr_ALV_TABLE->get_selections( ).
* ls_cell = lr_selections->get_current_cell( ).
" " Show user (in current client only)
" IF row > 0.
" CLEAR ls_result.
" READ TABLE lt_result INTO ls_result INDEX row.
" IF ls_result-mandt = sy-mandt
" AND ls_result-bname IS NOT INITIAL.
" CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
" EXPORTING
" tcode = 'SU01'
" EXCEPTIONS
" ok = 0
" not_ok = 2
" OTHERS = 3.
" IF sy-subrc = 0.
" CALL FUNCTION 'SUID_IDENTITY_MAINT'
" EXPORTING
" i_username = ls_result-bname
" i_tcode_mode = 1
" i_su01_display = 'X'.
" ENDIF.
" ENDIF.
" ENDIF.
ENDMETHOD. "on_double_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
FORM show_result.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 100
text = 'Show result'.
* reference to ALV objects
DATA: lr_functions_list TYPE REF TO cl_salv_functions_list,
* lr_functions TYPE REF TO cl_salv_functions,
lr_selections TYPE REF TO cl_salv_selections,
lr_columns TYPE REF TO cl_salv_columns_table,
* lr_column TYPE REF TO cl_salv_column_table,
* lr_sorts TYPE REF TO cl_salv_sorts.
lr_events TYPE REF TO cl_salv_events_table,
lr_functional_settings TYPE REF TO cl_salv_functional_settings,
lr_hyperlinks TYPE REF TO cl_salv_hyperlinks,
lr_tooltips TYPE REF TO cl_salv_tooltips,
lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
* lr_content TYPE REF TO cl_salv_form_element,
lr_grid_header TYPE REF TO cl_salv_form_layout_grid,
lr_grid_footer TYPE REF TO cl_salv_form_layout_grid,
lr_display_settings TYPE REF TO cl_salv_display_settings.
DATA: lr_exception TYPE REF TO cx_salv_error,