1832009 Members
2893 Online
110034 Solutions
New Discussion

pam routine problem

 
christian_derek
Regular Advisor

pam routine problem

Hi,

We have an application which calls the pam library. It works fine except for when the num_msg value > 1.

The declaration of our routine looks like:

extern int SVSWPamCallBack(int iNumMsg, struct pam_message **hMsg,
struct pam_response **hPamResponse, void *pData)

In our routine, we have debug code which displays the value of iNumMsg, hMsg, and hMsg->msg

printf("iNumMsg=%d\n",iNumMsg);
for (i = 0; i < iNumMsg; ++i)
{
printf(pContext->pLog,"hMsg[%d]=x%x\n",i,hMsg[i]);
printf(pContext->pLog,"hMsg[%d]->msg=x%x\n",i,hMsg[i]->msg);
}

When the iNumMsg > 1, we get odd values returned.

iNumMsg=2
hMsg[0]=x7fff59b0
hMsg[0]->msg=x7fff5a40
hMsg[1]=x7eff6258
hMsg[1]->msg=xffffffff

The contents of the string hMsg[0]->msg is "Password must contain at least two alphabetic characters and"

If we try to access hMsg[1]-> we get a SIGSEGV thrown.

Another example is

iNumMsg=5
hMsg[0]=x7fff5990
hMsg[0]->msg=x7fff5a40
hMsg[1]=x1


hMsg[0]->msg contains the string
"The password entered is not valid. Valid passwords must contain at least: 1 upper case character(s), 0 lower case character(s), 1 digit(s), and 1 special character(s)."

The man pages says:
The parameter num_msg is the number of messages associated with the call. The parameter msg is a pointer to an array of length num_msg of the pam_message structure.


Is there something obvious that we are doing wrong?

thanks,

4 REPLIES 4
kobylka
Valued Contributor

Re: pam routine problem

Hello Christian!

The declaration of your routine:
extern int SVSWPamCallBack(int iNumMsg, struct pam_message **hMsg, struct pam_response **hPamResponse, void *pData);

Note this:
struct pam_message **hMsg <-- pointer to pointer

Now back to your loop:
for (i = 0; i < iNumMsg; ++i)
{
printf(pContext->pLog,"hMsg[%d]=x%x\n",i,hMsg[i]);
printf(pContext->pLog,"hMsg[%d]->msg=x%x\n",i,hMsg[i]->msg);
}


The first printf takes as argument hMsg[i] which points to another pointer that points to the struct pam_message (**hMsg). So this should be:

printf(pContext->pLog,"hMsg[%d]=x%x\n",i,hMsg[i]->name_of_field);

If using pam_message structs then name_of_field should be msg_style:

printf(pContext->pLog,"hMsg[%d]=x%x\n",i,hMsg[i]->msg_style);


The second printf is correct regarding the dereferencing (hMsg[i]->msg) but fails to provide the correct format specifier:

"hMsg[%d]->msg=x%x\n"

should be

"hMsg[%d]->msg=x%s\n"

thus

printf(pContext->pLog,"hMsg[%d]->msg=x%s\n",i,hMsg[i]->msg);


Kind regards,

Kobylka
Dennis Handly
Acclaimed Contributor

Re: pam routine problem

>kobylka: printf(pContext->pLog,"hMsg[%d]=x%x\n",i,hMsg[i]->name_of_field);

The correct format for pointers is %p, not %x.
kobylka
Valued Contributor

Re: pam routine problem

Hi!


>The correct format for pointers is %p, not %x.

Correct, but hMsg[i]->name_of_field in the first printf, where name_of_field is equal to msg_style, is integral int value, not pointer (struct pam_message: man pam_start).

Kind regards,

Kobylka
Glenn L
New Member

Re: pam routine problem

Christian's post was actually based on an email from me, and I had some typos, which probably confused things.

The issue is that we are receiving invalid address values passed back in the pam callback routine. We were displaying the values of the addresses of hMsg[i] and hMsg[i]->msg to try to track down the problem.

(Yes, we should have used %p instead of %x, but the end result is similar)

In the example when iNumMsg=5, note that the address of hMsg[1] is x1.

In the example when iNumMsg=2, note that the address of hMsg[1]->msg is xffffffff

This is what I am trying to solve.

Thanks,
Glenn