Modify

Opened 13 years ago

Closed 13 years ago

#1920 closed Bug (Fixed)

Script crashes with error reported in Security.au3 at line 85

Reported by: malcolmsearle Owned by: Jon
Milestone: 3.3.7.2 Component: AutoIt
Version: 3.3.6.1 Severity: None
Keywords: Cc:

Description

My usage:
Script uses Security.au3 to get user SIDs from Active Directory. The task is to get a range of user information from Active Directory.

The failing line in my script is:

$bSid = _Security__GetAccountSid($strDomainName & "\" & $strSamid, $strLogonServer)

Problem:
Occasionally the script will crash reporting an error at line 85 of Security.au3 involving use of a subscript with a non-array variable. This code assumes _SecurityLookupAccountSid only returns an array. In fact, _SecurityLookupAccountSid can return zero (ref. ticket 1393).

Attachments (0)

Change History (6)

comment:1 follow-up: Changed 13 years ago by malcolmsearle

My initial solution is to change line 85 in Security.au3 which was:

Return _Security__StringSidToSid($aAcct[0])

to:

If IsArray($aAcct) Then Return _Security__StringSidToSid($aAcct[0])
Return ''

I have copied the two functions involved in the problem below. First is _SecurityGetAccountSid which is the function where the problem resides. The second is the _SecurityLookupAccountSid, both from Security.au3.

######################################################
REFERENCE: (Taken from Security.au3)
######################################################
; #FUNCTION# ====================================================================================================================
; Name...........: _SecurityGetAccountSid
; Description ...: Retrieves the security identifier (SID) for an account
; Syntax.........: _Security
GetAccountSid($sAccount[, $sSystem = ""])
; Parameters ....: $sAccount - Specifies the account name. Use a fully qualified string in the domain_name\user_name format to
; +ensure that the function finds the account in the desired domain.
; $sSystem - Name of the system. This string can be the name of a remote computer. If this string is blank,
; +the account name translation begins on the local system. If the name cannot be resolved on the local system,
; +this function will try to resolve the name using domain controllers trusted by the local system.
; Return values .: Success - Returns a binary SID in a byte strucutre
; Failure - 0
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......:
; Related .......: _SecurityLookupAccountSid
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _Security
GetAccountSid($sAccount, $sSystem = "")

Local $aAcct = _SecurityLookupAccountName($sAccount, $sSystem)
If @error Then Return SetError(@error, 0, 0)


Return _SecurityStringSidToSid($aAcct[0]) [original line 85]

	If IsArray($aAcct) Then Return _Security__StringSidToSid($aAcct[0])
	Return ''

EndFunc ;==>_SecurityGetAccountSid

######################################################
REFERENCE: (Taken from Security.au3)
######################################################

; #FUNCTION# ====================================================================================================================
; Name...........: _SecurityLookupAccountName
; Description ...: Retrieves a security identifier (SID) for the account and the name of the domain
; Syntax.........: _Security
LookupAccountName($sAccount[, $sSystem = ""])
; Parameters ....: $sAccount - Specifies the account name. Use a fully qualified string in the domain_name\user_name format to
; +ensure that the function finds the account in the desired domain.
; $sSystem - Name of the system. This string can be the name of a remote computer. If this string is blank,
; +the account name translation begins on the local system. If the name cannot be resolved on the local system,
; +this function will try to resolve the name using domain controllers trusted by the local system.
; Return values .: Success - Array with the following format:
; |$aAcct[0] - SID String
; |$aAcct[1] - Domain name
; |$aAcct[2] - SID type, which can be one of the following values:
; | 1 - Indicates a user SID
; | 2 - Indicates a group SID
; | 3 - Indicates a domain SID
; | 4 - Indicates an alias SID
; | 5 - Indicates a SID for a well-known group
; | 6 - Indicates a SID for a deleted account
; | 7 - Indicates an invalid SID
; | 8 - Indicates an unknown SID type
; | 9 - Indicates a SID for a computer
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......:
; Related .......: _SecurityLookupAccountSid
; Link ..........: @@MsdnLink@@ LookupAccountName
; Example .......:
; ===============================================================================================================================
Func _Security
LookupAccountName($sAccount, $sSystem = "")

Local $tData = DllStructCreate("byte SID[256]")
Local $pSID = DllStructGetPtr($tData, "SID")
Local $aResult = DllCall("advapi32.dll", "bool", "LookupAccountNameW", "wstr", $sSystem, "wstr", $sAccount, "ptr", $pSID, "dword*", 256, _

"wstr", "", "dword*", 256, "int*", 0)

If @error Then Return SetError(@error, @extended, 0)
If Not $aResult[0] Then Return 0

Local $aAcct[3]
$aAcct[0] = _SecuritySidToStringSid($pSID)
$aAcct[1] = $aResult[5] ; Domain
$aAcct[2] = $aResult[7] ; SNU
Return $aAcct

EndFunc ;==>_SecurityLookupAccountName

comment:2 in reply to: ↑ 1 Changed 13 years ago by mvg

Replying to malcolmsearle:

I have copied the two functions involved in the problem below.

Erm ... is also using code tags for that part to much to ask. (and using remarks inside the code to point to your local change(s).)

comment:3 Changed 13 years ago by malcolmsearle

"Erm ... is also using code tags for that part to much to ask."

No, of course not. Thought I'd done that. My mistake.

"(and using remarks inside the code to point to your local change(s).)"

Thought I'd done that too. My mistake again.

comment:4 Changed 13 years ago by malcolmsearle

Hope this helps :

Func _SecurityGetAccountSid($sAccount, $sSystem = "")

 Local $aAcct = _SecurityLookupAccountName($sAccount, $sSystem)
 If @error Then Return SetError(@error, 0, 0)

;~  Return _SecurityStringSidToSid($aAcct[0]) [original line 85]
; ===== Begin - My local changes =====
	If IsArray($aAcct) Then Return _Security__StringSidToSid($aAcct[0])
	Return ''
; ===== End - My local changes =====
EndFunc ;==>_SecurityGetAccountSid

comment:5 Changed 13 years ago by mvg

:-)

comment:6 Changed 13 years ago by Jon

  • Milestone set to 3.3.7.2
  • Owner set to Jon
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [5996] in version: 3.3.7.2

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.