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
|
# File 'lib/chef/win32/security/sid.rb', line 304
def self.admin_account_name
@admin_account_name ||= begin
admin_account_name = nil
servername = nil
level = 3
filter = FILTER_NORMAL_ACCOUNT
bufptr = FFI::MemoryPointer.new(:pointer)
prefmaxlen = MAX_PREFERRED_LENGTH
entriesread = FFI::Buffer.new(:long).write_long(0)
totalentries = FFI::Buffer.new(:long).write_long(0)
resume_handle = FFI::Buffer.new(:long).write_long(0)
status = ERROR_MORE_DATA
while status == ERROR_MORE_DATA
status = NetUserEnum(servername, level, filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle)
if [NERR_Success, ERROR_MORE_DATA].include?(status)
Array.new(entriesread.read_long) do |i|
user_info = USER_INFO_3.new(bufptr.read_pointer + i * USER_INFO_3.size)
if user_info[:usri3_user_id] == 500 && user_info[:usri3_priv] == 2
admin_account_name = user_info[:usri3_name].read_wstring
break
end
end
NetApiBufferFree(bufptr.read_pointer)
end
end
raise "Can not determine the administrator account name." if admin_account_name.nil?
admin_account_name
end
end
|