Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4600914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:45:04+00:00 2026-05-21T23:45:04+00:00

I have a legacy app that receives a username/password request asynchronously over the wire.

  • 0

I have a legacy app that receives a username/password request asynchronously over the wire. Since I already have the username and password stored as variables, what would be the best way to authenticate with PAM on Linux (Debian 6)?

I’ve tried writing my own conversation function, but I’m not sure of the best way of getting the password into it. I’ve considered storing it in appdata and referencing that from the pam_conv struct, but there’s almost no documentation on how to do that.

Is there a simpler way to authenticate users without the overkill of a conversation function? I’m unable to use pam_set_data successfully either, and I’m not sure that’s even appropriate.

Here’s what I’m doing:

user = guiMessage->username;
pass = guiMessage->password;

pam_handle_t* pamh = NULL;
int           pam_ret;
struct pam_conv conv = {
  my_conv,
  NULL
};

pam_start("nxs_login", user, &conv, &pamh);
pam_ret = pam_authenticate(pamh, 0);

if (pam_ret == PAM_SUCCESS)
  permissions = 0xff;

pam_end(pamh, pam_ret);

And initial attempts at the conversation function resulted in (password is hard-coded for testing):

int 
my_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *data)
{
  struct pam_response *aresp;

  if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG)
    return (PAM_CONV_ERR);
  if ((aresp = (pam_response*)calloc(num_msg, sizeof *aresp)) == NULL)
    return (PAM_BUF_ERR);
  aresp[0].resp_retcode = 0;
  aresp[0].resp = strdup("mypassword");

  *resp = aresp;
  return (PAM_SUCCESS);
}

Any help would be appreciated. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:45:05+00:00Added an answer on May 21, 2026 at 11:45 pm

    This is what I ended up doing. See the comment marked with three asterisks.

    #include <stdlib.h>
    #include <iostream>
    #include <fstream>
    #include <security/pam_appl.h>
    #include <unistd.h>
    
    // To build this:
    // g++ test.cpp -lpam -o test
    
    // if pam header files missing try:
    // sudo apt install libpam0g-dev
    
    struct pam_response *reply;
    
    //function used to get user input
    int function_conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
    {
      *resp = reply;
      return PAM_SUCCESS;
    }
    
    int main(int argc, char** argv)
    {
      if(argc != 2) {
          fprintf(stderr, "Usage: check_user <username>\n");
          exit(1);
      }
      const char *username;
      username = argv[1];
    
      const struct pam_conv local_conversation = { function_conversation, NULL };
      pam_handle_t *local_auth_handle = NULL; // this gets set by pam_start
    
      int retval;
    
      // local_auth_handle gets set based on the service
      retval = pam_start("common-auth", username, &local_conversation, &local_auth_handle);
    
      if (retval != PAM_SUCCESS)
      {
        std::cout << "pam_start returned " << retval << std::endl;
        exit(retval);
      }
    
      reply = (struct pam_response *)malloc(sizeof(struct pam_response));
    
      // *** Get the password by any method, or maybe it was passed into this function.
      reply[0].resp = getpass("Password: ");
      reply[0].resp_retcode = 0;
    
      retval = pam_authenticate(local_auth_handle, 0);
    
      if (retval != PAM_SUCCESS)
      {
        if (retval == PAM_AUTH_ERR)
        {
          std::cout << "Authentication failure." << std::endl;
        }
        else
        {
          std::cout << "pam_authenticate returned " << retval << std::endl;
        }
        exit(retval);
      }
    
      std::cout << "Authenticated." << std::endl;
    
      retval = pam_end(local_auth_handle, retval);
    
      if (retval != PAM_SUCCESS)
      {
        std::cout << "pam_end returned " << retval << std::endl;
        exit(retval);
      }
    
      return retval;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MFC legacy app that I help to maintain. I'm not quite
I have a legacy app that can display crystal reports to the user, using
I have a legacy app that was built entirely in jQuery and HTML. Does
I have a legacy app that seems to be exporting/saving files with CArchive (legacy
I have a legacy WinForms Mdi App in VB.Net 2.0 which I am adding
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I have a legacy C++ module that offers encryption/decryption using the openssl library (DES
We have some legacy code that needs to identify in the Page_Load which event
I have a legacy VB6 application that was built using MSDE. As many client's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.