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

hi all,

an user can log into the cgi/perl application with username and pwd. but the script runs as user "nobody" on apache server. but in my script i need the userid and the password with which he logged in.

checked some docs on "suExec", but did not get the concept. is there any module or any way to achieve this fucntionality.

thanks
rsennat
  • Comment on get the user id and pwd who logs in to the cgi/perl application

Replies are listed 'Best First'.
Re: get the user id and pwd who logs in to the cgi/perl application
by idsfa (Vicar) on Dec 07, 2005 at 18:39 UTC

    Based on the code you currently have posted (ie, none), no, there is no way to do this.

    Please take a moment to peruse How do I post a question effectively? In particular, the part about providing example code.

    Updated: Thanks for the clarification. You probably want to look at mod_auth_pam, an Apache module which allows you to do what want.


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
Re: get the user id and pwd who logs in to the cgi/perl application
by sgifford (Prior) on Dec 07, 2005 at 21:06 UTC
    It sounds like what you want is to authenticate users against your /etc/passwd and /etc/shadow files, then have the CGI script run with their privileges.

    This is a fairly dangerous thing to do, unfortunately. It requires that you either run your Apache as root, so it will be allowed to read passwords from /etc/shadow and then switch to the appropriate user, or else have your script setuid to root, so it will acquire those privileges when it starts. Either way, a tiny bug in your script or in Apache could lead to your entire system being taken over, so unless you are very experienced with secure programming, you should try to avoid these techniques.

    A different way to accomplish the same thing is to have a small server running as root and accepting a username, password, and a limited set of commands. Your script would get input from a form, send a command to this server, then interpret and display the results. That can be a little safer, because the server can be very simple and doesn't have to interact with a Web server.

    Another way is to send username, password, and command to a local ssh server using Net::SSH; that way the ssh server handles most of the security code, and you just have to worry about getting it the right commands.

Re: get the user id and pwd who logs in to the cgi/perl application
by Kanji (Parson) on Dec 07, 2005 at 19:59 UTC

    Your question isn't entirely clear, but if you mean the CGI application is password protected and you want the user/pass of whomever logged into that, then:-


    If it's protected with htaccess...

    CGI.pm's remote_user method will give you the username.

    There's no equivalent method for passwords because most sane web servers purposely remove that information prior to running your script.

    The only way to fix that would be to reconfigure your server, which may entail changing source code and recompiling the web server.

    You should then be able to see the password somewhere in the %ENV hash. (If your web server ISN'T sane, you may already be able to find the password there.)

    If it's protected via code in the CGI itself (eg, parsing a login form)...

    Again, using CGI.pm, you can access the contents of a submitted form using the param method, so if you had fields named 'username' and 'password' in your login form, you'd access them with $q->param('username') and $q->param('password') respectively (assuming your CGI object was in $q).


    If neither of these address your problem, then I refer you to idsfa's post above so that we can more fully understand your question.

        --k.


      Yes its protected with htaccess only. So how do we need to reconfigure the appache server. Any idea??
      anyway i will post this in the apache mailing lists.

      if you have any idea, please suggest.

      thanks
Re: get the user id and pwd who logs in to the cgi/perl application
by leocharre (Priest) on Dec 07, 2005 at 19:27 UTC
    is this via http, web interface? via command line or otherwise? sounds like they are logged into a box / a linux box?
Re: get the user id and pwd who logs in to the cgi/perl application
by rsennat (Beadle) on Dec 07, 2005 at 19:55 UTC
    yes. its via http, web interface. immediately after invoking the application, it requests for the user name and password dialog box.

    As of now i dont have any code. So i need to develop now and get the user id and the password in the application.

    on the net i got some info like suExec. but not sure how far it will be useful.

    any ideas or thoughts??

    thanks