Hi folks,

I'm trying to use PAM to authenticate a web application. I tested this code on the command line, and it works just fine but for some reason it's not working in a CGI context (I'm not getting errors, but I'm getting an Authentication failure) I know there is something I'm doing wrong, but I just can't figure it out.

Here's the command line code:

#!/usr/bin/perl # # testing pam for authentication # use strict; use Authen::PAM; my $service = "passwd"; my $username = "foo"; my $passwd = "bar"; my $pamh = new Authen::PAM($service,$username, \&conv_func); ref($pamh) || die "Problems!\n"; my $res = $pamh->pam_authenticate(); print $pamh->pam_strerror($res),"\n" unless $res == PAM_SUCCESS(); print "ending...\n"; sub conv_func { my @res; while ( @_ ) { my $code = shift; my $msg = shift; my $ans = ""; $ans = $username if ($code == PAM_PROMPT_ECHO_ON() ); if ($code == PAM_PROMPT_ECHO_OFF() ) { $ans = $passwd; } push @res, (PAM_SUCCESS(),$ans); } push @res, PAM_SUCCESS(); return @res; }

Here's the web code snippets
if ((!$login_id)||($login_id ne $query{id})) { #no cookie of the right name or the cookie does not match the id s +ent in the query # make them authenticate my $username = $query{username}; my $passwd = $query{password}; # Use PAM to authenticate my $service = "passwd"; my $pamh = new Authen::PAM($service,$username,\&conv_func); # use +the conversation function # so it +doesn't have to be interactive ref($pamh) || graceful_exit("Problems with PAM authentication",$pam +h->pam_strerror($pamh),"v"); my $res = $pamh->pam_authenticate(); my $id; if (!$res == PAM_SUCCESS()) { # they aren't authentic graceful_exit("Nope. Not even close", $pamh->pam_strerror($res),"v +"); } else { # yay! they are authentic - let's look for them in our ma +pping table } } sub conv_func { my $username; my $passwd; my @res; while ( @_ ) { my $code = shift; my $msg = shift; my $ans = ""; $ans = $username if ($code == PAM_PROMPT_ECHO_ON() ); if ($code == PAM_PROMPT_ECHO_OFF() ) { $ans = $passwd; } push @res, (PAM_SUCCESS(),$ans); } push @res, PAM_SUCCESS(); return @res; }

Any suggestions? Thanks!


In reply to Authen::PAM by michellem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.