@@ -5,6 +5,19 @@ module NTDS
5
5
# priv extension.
6
6
class Account
7
7
8
+ # Size of an NTDS Account Struct on the Wire
9
+ ACCOUNT_SIZE = 3948
10
+ # Size of a Date or Time Format String on the Wire
11
+ DATE_TIME_STRING_SIZE = 30
12
+ # Size of the AccountDescription Field
13
+ DESCRIPTION_SIZE = 2048
14
+ # Size of a Hash History Record
15
+ HASH_HISTORY_SIZE = 792
16
+ # Size of a Hash String
17
+ HASH_SIZE = 33
18
+ # Size of the samAccountName field
19
+ NAME_SIZE = 40
20
+
8
21
#@return [String] The AD Account Description
9
22
attr_accessor :description
10
23
#@return [Boolean] If the AD account is disabled
@@ -52,10 +65,10 @@ class Account
52
65
# @raise [ArgumentErrror] if a 3948 byte string is not supplied
53
66
def initialize ( raw_data )
54
67
raise ArgumentError , "No Data Supplied" unless raw_data . present?
55
- raise ArgumentError , "Invalid Data" unless raw_data . length == 3948
68
+ raise ArgumentError , "Invalid Data" unless raw_data . length == ACCOUNT_SIZE
56
69
data = raw_data . dup
57
- @name = get_string ( data , 40 )
58
- @description = get_string ( data , 2048 )
70
+ @name = get_string ( data , NAME_SIZE )
71
+ @description = get_string ( data , DESCRIPTION_SIZE )
59
72
@rid = get_int ( data )
60
73
@disabled = get_boolean ( data )
61
74
@locked = get_boolean ( data )
@@ -65,13 +78,13 @@ def initialize(raw_data)
65
78
@logon_count = get_int ( data )
66
79
@nt_history_count = get_int ( data )
67
80
@lm_history_count = get_int ( data )
68
- @expiry_date = get_string ( data , 30 )
69
- @logon_date = get_string ( data , 30 )
70
- @logon_time = get_string ( data , 30 )
71
- @pass_date = get_string ( data , 30 )
72
- @pass_time = get_string ( data , 30 )
73
- @lm_hash = get_string ( data , 33 )
74
- @nt_hash = get_string ( data , 33 )
81
+ @expiry_date = get_string ( data , DATE_TIME_STRING_SIZE )
82
+ @logon_date = get_string ( data , DATE_TIME_STRING_SIZE )
83
+ @logon_time = get_string ( data , DATE_TIME_STRING_SIZE )
84
+ @pass_date = get_string ( data , DATE_TIME_STRING_SIZE )
85
+ @pass_time = get_string ( data , DATE_TIME_STRING_SIZE )
86
+ @lm_hash = get_string ( data , HASH_SIZE )
87
+ @nt_hash = get_string ( data , HASH_SIZE )
75
88
@lm_history = get_hash_history ( data )
76
89
@nt_history = get_hash_history ( data )
77
90
@sid = data
@@ -113,7 +126,7 @@ def get_boolean(data)
113
126
end
114
127
115
128
def get_hash_history ( data )
116
- raw_history = data . slice! ( 0 , 792 )
129
+ raw_history = data . slice! ( 0 , HASH_HISTORY_SIZE )
117
130
split_history = raw_history . scan ( /.{1,33}/ )
118
131
split_history . map! { |hash | hash . gsub ( /\x00 / , '' ) }
119
132
split_history . reject! { |hash | hash . blank? }
0 commit comments