@@ -129,9 +129,13 @@ def run
129
129
ldap_connect do |ldap |
130
130
validate_bind_success! ( ldap )
131
131
132
- fail_with ( Failure ::UnexpectedReply , "Couldn't discover base DN!" ) unless ldap . base_dn
133
- base_dn = ldap . base_dn
134
- print_status ( "#{ ldap . peerinfo } Discovered base DN: #{ base_dn } " )
132
+ if datastore [ 'BASE_DN' ] . blank?
133
+ fail_with ( Failure ::UnexpectedReply , "Couldn't discover base DN!" ) unless ldap . base_dn
134
+ base_dn = ldap . base_dn
135
+ print_status ( "#{ ldap . peerinfo } Discovered base DN: #{ base_dn } " )
136
+ else
137
+ base_dn = datastore [ 'BASE_DN' ]
138
+ end
135
139
136
140
schema_dn = ldap . schema_dn
137
141
case action . name
@@ -149,22 +153,21 @@ def run
149
153
run_queries_from_file ( ldap , parsed_queries , schema_dn , datastore [ 'OUTPUT_FORMAT' ] )
150
154
return
151
155
when 'RUN_SINGLE_QUERY'
152
- unless datastore [ 'QUERY_FILTER' ] && datastore [ 'QUERY_ATTRIBUTES' ]
153
- fail_with ( Failure ::BadConfig , 'When using the RUN_SINGLE_QUERY action, one must supply the QUERY_FILTER and QUERY_ATTRIBUTE datastore options !' )
156
+ unless datastore [ 'QUERY_FILTER' ]
157
+ fail_with ( Failure ::BadConfig , 'When using the RUN_SINGLE_QUERY action, one must supply the QUERY_FILTER datastore option !' )
154
158
end
155
159
156
160
print_status ( "Sending single query #{ datastore [ 'QUERY_FILTER' ] } to the LDAP server..." )
157
- attributes = datastore [ 'QUERY_ATTRIBUTES' ]
158
- if attributes . empty?
159
- fail_with ( Failure ::BadConfig , 'Attributes list is empty as we could not find at least one attribute to filter on!' )
161
+ if datastore [ 'QUERY_ATTRIBUTES' ] . present?
162
+ # Split attributes string into an array of attributes, splitting on the comma character.
163
+ # Also downcase for consistency with rest of the code since LDAP searches aren't case sensitive.
164
+ attributes = datastore [ 'QUERY_ATTRIBUTES' ] . downcase . split ( ',' )
165
+
166
+ # Strip out leading and trailing whitespace from the attributes before using them.
167
+ attributes . map ( &:strip! )
168
+ else
169
+ attributes = nil
160
170
end
161
-
162
- # Split attributes string into an array of attributes, splitting on the comma character.
163
- # Also downcase for consistency with rest of the code since LDAP searches aren't case sensitive.
164
- attributes = attributes . downcase . split ( ',' )
165
-
166
- # Strip out leading and trailing whitespace from the attributes before using them.
167
- attributes . map ( &:strip! )
168
171
filter_string = datastore [ 'QUERY_FILTER' ]
169
172
query_base = base_dn
170
173
else
0 commit comments