Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Is it possible to find out the NT User Account of a user through Perl. I am currently writing a small application, and I want to be able to allow users to visit a page on our intranet and for them to be directed to the relevant content that they are allowed to see. I am currently using Apache Web server with Active State Perl on a Windows NT4 workstation.

Dose the Internet browser (which is Internet Explorer 5.5) provide the user name when requesting pages, which could be read into a Perl Script??

Hope some one can help me with this one.

Thanks,

Alistair

  • Comment on Getting Windows NT User Name using Perl

Replies are listed 'Best First'.
Re: Getting Windows NT User Name using Perl
by BrowserUk (Patriarch) on Oct 05, 2002 at 21:32 UTC

    From the CGI.pm pod

    remote_user() Return the authorization/verification name used for user verification, + if this script is protected. user_name() Attempt to obtain the remote user's name, using a variety of different + techniques. This only works with older browsers such as Mosaic. Newer browsers do +not report the user name for privacy reasons!


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
Re: Getting Windows NT User Name using Perl
by robartes (Priest) on Oct 05, 2002 at 22:55 UTC
    There is no way for the web server to get the OS user ID of the user accessing the web page (or if there is, there shouldn't be - you'd have a leak of information security hole). You could probably pursuade your script to somehow go get the NT user ID on the client's box, but that's opening a whole new can of worms security-wise. There be dragons there.

    You can however use other user ID's, such as the HTTP basic authentication user id (the one you fill in when you go to a web page that asks for your username and password with a pop up box - usually). Look to BrowserUK's post above for information on how to get that userID using the cgi module. You also have to configure your web server for basic authentication. See the Apache documentation.

    CU
    Robartes-

Re: (nrd) Getting Windows NT User Name using Perl
by newrisedesigns (Curate) on Oct 06, 2002 at 15:04 UTC

    Dear AnonyMonk,

    In your script, get the ip address or the DHCP name of the machine making a request. Pass that value to nbtstat using the correct flag (-a or -A for DHCP or IP, respectively) and capture the output.

    nbtstat will return the username, computer name and the workgroup/domain name of the computer you specified.

    Also, please sign up for Perl Monks. It's free, and it allows us to get in contact with you much more easily. If you have any further questions, sign up and post. :)

    Hope this helps, and good luck!

    John J Reiser
    newrisedesigns.com

      I know that the original post referred to Apache on NT4, however if you're running a UNIX server (and so do not have access to the nbtstat command), there is a similar program called NBTScan which compiles on both UNIX and Windows.

      It is available from http://www.inetcat.org/software/nbtscan.html. This page also links to a Perl version of the program which runs under UNIX (but requires Samba nmblookup utility to be installed).

      JJ

Re: Getting Windows NT User Name using Perl
by diotalevi (Canon) on Oct 05, 2002 at 23:25 UTC

    I recall this exact problem (or close enough) was asked on ActiveState's ActivePerl mailing list recently. In general I remember seeing some things where the MS IE client has some MS-only way of communicating it's identity to the server but only if you do some Microsoft thing. It sounds like a neat idea but I'm not familiar enough to say exactly what that was. If no one here pulls up the answer I'd suggest asking over there. I think it might have required MS client and server and the perhaps IIS + ASP or something. There was probably also a hook into ActiveDirectory but... well I just don't remember. Either I'm conflating two threads or the final solution was not possible through perl.

    __SIG__
    printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE

Re: Getting Windows NT User Name using Perl
by blm (Hermit) on Oct 06, 2002 at 13:52 UTC

    Now if you were using IIS it may be different

    /me ducks. I know...I know. ;-)

    If you use Integrated Authentication on IIS the user revealed by CGI::remote_user(); would be the OS username. Here is the code:

    #!c:\perl\bin\perl.exe -w use CGI; my $username = CGI::remote_user(); print "Content-type: text/html\n\n"; print "<h3>Hello $username</h3>";

    And here is the reply

    Hello viper\blm

    --blm--