How to access Windows IIS User Info with Perl
From: BigNin (page.nix_at_gmail.com)
Date: 03/29/05
- Next message: sjp: "Re: YARQ - Yet another regex question"
- Previous message: John Bokma: "Re: YARQ - Yet another regex question"
- Next in thread: Ted Zlatanov: "Re: How to access Windows IIS User Info with Perl"
- Reply: Ted Zlatanov: "Re: How to access Windows IIS User Info with Perl"
- Reply: Big and Blue: "Re: How to access Windows IIS User Info with Perl"
- Reply: Thomas Kratz: "Re: How to access Windows IIS User Info with Perl"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Mar 2005 11:56:46 -0800
I have a Perl script which runs on a Unix server with Apache as the
http server. With the use of an .htaccess file, only users that login
with basic authentication are able to run the script. This script is
only available on the intranet so it's internal company use only. The
perl script compares the authenticated username with a text file which
contains groups to which certain employees belong and serves different
HTML depending on the user's group memberships.
In our IT department's infinite wisdom, they have moved us to a Windows
2003 server running IIS. I've made the modifications to my script so
that it runs, but the IIS server is configured for Windows
Authentication. The IT department states that this allows users to
login into the network when they first turn on their PC and then the
users don't have to enter any additional usernames or passwords to
authenticate with IIS and my script. My group text file has now been
converted to Windows security groups.
I have searched HotScripts.com, ActiveState.com, and Google and I can
not find any example of how to get perl to read Windows security groups
and tell me which ones the user belongs to. I'm guessing that someone
somewhere has done this before.
My administrators gave me some ASP code that supposedly can do what I
want, but that doesn't really help me do it in perl. For reference, I
have included it below:
Public Function Groups(ByVal SearchResult As
System.DirectoryServices.SearchResult) As String
Dim i As Integer
Dim tmp As String
Dim groupSid As Object
Dim sid() As Byte
Try
Dim de As DirectoryEntry = SearchResult.GetDirectoryEntry
'pull username and password from web.config file.
de.Username =
Configuration.ConfigurationSettings.AppSettings("User")
de.Password =
Configuration.ConfigurationSettings.AppSettings("Pass")
de.RefreshCache(New String() {"tokenGroups"})
'this line is sometimes necessary to get tokenGroups in the
property cache...
'loop through each sid in the tokenGroups
For Each groupSid In de.Properties("tokenGroups")
'just another way of doing a ctype.
sid = DirectCast(groupSid, Byte())
'set up the groupentry for query
'ConvertToOctetString is the important part here. This is
where the real work is.
Dim groupEntry As New
DirectoryEntry(String.Format("LDAP://", ConvertToOctetString(sid)))
Dim propcoll As PropertyCollection = groupEntry.Properties
Dim key As String
Dim values As Object
'loop through all of the properties for this record
For Each key In propcoll.PropertyNames
'loop through all the values associated with our key
For Each values In propcoll(key)
If LCase(key) = "distinguishedname" Then
Dim temp As String = values.ToString
If Not InStr(temp, "ImportedExchange") Then
Dim atemp() As String = temp.Split(",")
tmp &= Replace(atemp(0).ToString, "CN=", ",")
If Left(tmp, 1) = "," Then
tmp = Mid(tmp, 2)
End If
End If
End If
Next
Next
Next
Catch ex As Exception
'process exception
End Try
Return tmp
End Property
'overload for lazy programming
Public Overloads Shared Function ConvertToOctetString(ByVal values As
Byte()) As String
Return ConvertToOctetString(values, False, False)
End Function
'overload for lazy programming
Public Overloads Shared Function ConvertToOctetString(ByVal values As
Byte(), _
ByVal isAddBackslash As Boolean) As String
Return ConvertToOctetString(values, isAddBackslash, False)
End Function
'This is where the work really comes in. This method allows us to
convert the sid
'into a usable string that LDAP can use to search for the groups this
user belongs to.
Public Overloads Shared Function ConvertToOctetString(ByVal values As
Byte(), _
ByVal isAddBackslash As Boolean, ByVal isUpperCase As Boolean) As
String
Dim iterator As Integer
Dim builder As System.Text.StringBuilder
Dim slash As String
If isAddBackslash Then
slash = "\"
Else
slash = String.Empty
End If
Dim formatCode As String
If isUpperCase Then
formatCode = "X2"
Else
formatCode = "x2"
End If
builder = New System.Text.StringBuilder(values.Length * 2)
For iterator = 0 To values.Length - 1
builder.Append(slash)
builder.Append(values(iterator).ToString(formatCode))
Next
Return builder.ToString()
End Function
Thanks in advance to any suggestions.
- Next message: sjp: "Re: YARQ - Yet another regex question"
- Previous message: John Bokma: "Re: YARQ - Yet another regex question"
- Next in thread: Ted Zlatanov: "Re: How to access Windows IIS User Info with Perl"
- Reply: Ted Zlatanov: "Re: How to access Windows IIS User Info with Perl"
- Reply: Big and Blue: "Re: How to access Windows IIS User Info with Perl"
- Reply: Thomas Kratz: "Re: How to access Windows IIS User Info with Perl"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|