Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Authentication Problem - "Logon failure: unknown user name or bad password"

by B-Man (Acolyte)
on Mar 08, 2013 at 14:57 UTC ( #1022440=perlquestion: print w/ replies, xml ) Need Help??
B-Man has asked for the wisdom of the Perl Monks concerning the following question:

Hello, this is my first post here at perlmonks.org. I'm glad to be a part of the community.

So I'm working on building a spider in perl. This spider is supposed to crawl my company's intranet. The goal is to grab all the links from a page and add them to an array called @foundLinks. After populating the array with said links, it will go back through those found links and get the links on each page. The ultimate goal is to find .doc and .docx files on the intranet so that those can be converted into PDF documents. The actual conversion is going to be handled by some VBScript. The intranet spider is going to work in conjunction with another spider that will dig through physical disk paths for the same .doc and .docx files.

Now that you have some background, let's get to the actual problem that I'm having with this spider. There is a server on our intranet that is requesting authentication. My script has no idea what to do, so it gets a 401 (Unauthorized) error message. What I'm trying to do is to get rid of this problem

In an attempt to rectify the issue, I did some digging and came across some code that's supposed to create a Win32::API module known as LogonUser.

use Win32::API; ############################################################## # Add cleanup before using this in production Win32::API->Import('advapi32', 'int LogonUser( LPTSTR lpszUsername, LPTSTR lpszDomain, LPTSTR, lpszPassword, DWORD dwLogon, DWORD dwLogonProvider, PHANDLE phToken )' ) or die "Win32::API->import for LogonUser failed: $^E"; my $ph = ' ' x 4; # Required, but we do not use it #############################################################

This module is supposed to be called in the spider. I'm filtering out links with a decision tree with some regular expressions. The code I have set up will only try to call the LogonUser module when the server that requires authentication is found. The code in the spider subroutine is as follows:

if ( $linkList->[$x] =~ [pattern of the server that needs +authentication] ) { print("You're in the LogonUser block!"); LogonUser( '[username goes here]', '', '', 0x000003, 0 +x000000, $ph ) or die $^E; # ImpersonateLoggedOnUser($ph); }

When I run the .pl file through a batch file, I manage to do some indexing until I hit the server asking authentication. Then I get this message:

Logon failure: unknown user name or bad password

I've even tried passing it on to my supervisor to see if it wasn't the credentials I was providing for the first three arguments (Username, Domain, Password - respectively) He's told me that he has many more permissions on that server than I do. Now, he's busy with the workload of someone out of the office, so he can't review the problem more. By the way, yes I've entered all three credentials before.

Any ideas on what's wrong? I'm curious if there's something wrong with the fourth and fifth parameters I'm passing it. These are the logon type and logon provider parameters. These apparently have more documented constants, but I don't know how to use them without getting an error saying they're not "numeric." This means that, or at least according to the starter code I found, I have to name them with 0x000000, 0x000001 ... etc.

There are 21 possible combinations of these parameters. Out of these combinations, do you guys think there's any particular one that'd be correct? Would it help if I gathered information about what kind of software or hardware is being used to authenticate users? If a particular software is being used (i.e. Kerberos), would it be wiser to use a different module or approach?

Details about the LogonUser module can be found here: LogonUser function (Windows). Details about the possible logon types and logon providers are kept there

Thanks again for your time. I'm pretty new to perl, and while I've gotten a decent grasp of the basics. More complex things like this however are currently beyond my grasp. Any help is appreciated greatly.

Note: Updates below the break. We've resolved the issue.

Update: I checked my username after unlocking my machine to make sure it was correct. I saw that I was missing the domain name (minus the .com part) in my original tries. I put in the correct username, along with the domain and password. It's still failing, but now it taking a few seconds after telling me it's in the LogonUser block before it fails. It's gotta be processing something, right? Note that it only delays before failing if I include the domain, despite it being "optional" according to the LogonUser documentation link above.

Update (3/19/2013): We solved our issues! Apparently our server wants us to use digest authentication. Our lead programmer was able to build something that works! Now I just have to set things up so that or spider can invoke the code to overcome any kind of 401 error we get.

Comment on Authentication Problem - "Logon failure: unknown user name or bad password"
Select or Download Code
Re: Authentication Problem - "Logon failure: unknown user name or bad password"
by B-Man (Acolyte) on Mar 08, 2013 at 20:20 UTC

    So guess what? Trying to authenticate remotely was a bad idea. I mean, it could work in theory, but in practice there's a simpler solution. We tried running the script directly on the server, and it worked! We had to comment out the block of code that was trying to log us in, but as soon as we did that, we had a waterfall of links being spidered.

    Now I just have to wait for my supervisor to give me access to that server. Until then, I'll have to work on the VBScript side of things. The VBScript is basically done, but I have some issues that need to be refined - one of which popped up after building classes to group similar variables and methods.

    Once I get to work on the spider again, it looks like I have to refine it to only stay on our intranet. It got a bit carried away and started spidering some external links. It's possible it may have spidered a better portion of the Internet if we let it.

Re: Authentication Problem - "Logon failure: unknown user name or bad password"
by Anonymous Monk on Mar 09, 2013 at 01:52 UTC

      I'll check them out. I didn't consider when I posted last week that we have to isolate our test environment from our live environment. We don't have the necessary resources or time to set up a virtual version of our server, so getting authentication would be nice. It'd also allow the code to work in another location instead of just "on the server."

      Yeah, I'll take some of those modules and test them in a small script until one works. I'll integrate anything that works into my spider. Thanks for the feedback!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1022440]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-09-21 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls