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

  • SEARCH
  • Home
  • 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 8085337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:04:56+00:00 2026-06-05T18:04:56+00:00

I have program written in C. It takes 2 arguments username/password and try to

  • 0

I have program written in C. It takes 2 arguments username/password and try to authenticate this user using PAM. It works fine when I’m root. When I’m ‘normal’ user, it works for this user, but not for another one. I think, it’s due to using shadow passwords..

As service I’m using:

retval = pam_start("test", username, &local_conversation, &local_auth_handle);

I add this to the /etc/pam.d/test

#%PAM-1.0
auth    required    pam_unix.so shadow nullok
account required    pam_unix.so
session required    pam_unix.so

Could you help me, please?
Thanks a lot!

  • 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-06-05T18:04:58+00:00Added an answer on June 5, 2026 at 6:04 pm

    The application needed to be able to read /etc/shadow.

    See my post for one way to do this.

    EDIT:
    Add post from above link in case the link ever breaks

    I wrote authentication module in C++ which alows to check
    username/password through PAM in Linux (I’m using Fedora Linux). I
    would like to share with you, what I made 🙂 . So, let’s go 🙂

    Prerequisities:

    Install package pam-devel
    (This step is necessary when you use shadow password) Create new Linux user and group. Set this group as default for this user. Then
    

    follow with these steps:
    Go to /etc
    Log in as root (su)
    Change group to the new one for file shadow (chgrp new_group shadow)
    Set ‘read’ privilage for this group (chmod 0440 shadow)

    Write this code: (authModule.c) view plaincopy to clipboardprint?

    #include <stdio.h>  
    #include <security/pam_appl.h>  
    #include <unistd.h>  
    #include <stdlib.h>  
    #include <string.h>  
    
    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 authenticate_system(const char *username, const char *password)   
    {  
        const struct pam_conv local_conversation = { function_conversation, NULL };  
        pam_handle_t *local_auth_handle = NULL; // this gets set by pam_start  
    
        int retval;  
        retval = pam_start("su", username, &local_conversation, &local_auth_handle);  
    
        if (retval != PAM_SUCCESS)  
        {  
                printf("pam_start returned: %d\n ", retval);  
                return 0;  
        }  
    
        reply = (struct pam_response *)malloc(sizeof(struct pam_response));  
    
        reply[0].resp = strdup(password);  
        reply[0].resp_retcode = 0;  
        retval = pam_authenticate(local_auth_handle, 0);  
    
        if (retval != PAM_SUCCESS)  
        {  
                if (retval == PAM_AUTH_ERR)  
                {  
                        printf("Authentication failure.\n");  
                }  
                else  
                {  
                    printf("pam_authenticate returned %d\n", retval);  
                }  
                return 0;  
        }  
    
        printf("Authenticated.\n");  
        retval = pam_end(local_auth_handle, retval);  
    
        if (retval != PAM_SUCCESS)  
        {  
                printf("pam_end returned\n");  
                return 0;  
        }  
    
        return 1;  
    }  
    
    int main(int argc, char** argv)  
    {  
        char* login;  
        char* password;  
    
        printf("Authentication module\n");  
    
        if (argc != 3)  
        {  
            printf("Invalid count of arguments %d.\n", argc);  
            printf("./authModule <username> <password>");  
            return 1;  
        }  
    
        login = argv[1];  
        password = argv[2];  
    
        if (authenticate_system(login, password) == 1)  
        {  
            printf("Authenticate with %s - %s through system\n", login, password);  
            return 0;  
        }     
    
        printf("Authentication failed!\n");  
        return 1;  
    }  
    

    Compile code:

    gcc -o authModule authModule.c -lpam  
    

    Run code (as the new user!):

    ./authModule user password  
    

    That’s all!! 🙂 Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program written in C using ncurses. It let user input and
I have written a program that uses qhttp to get a webpage. This works
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written a python console based program. It takes few arguments (like file
I have a really short program written in boost::xpressive #include <iostream> #include <boost/xpressive/xpressive.hpp> using
I have written a program which takes a file as input and whenever it
I have written a small program using Borland's C++ builder, and along the way,
I have written a program that takes the filename from argv[1] and do operations
I have a program written for text simplification in python language, I need this
So right now I have written a python program which takes the path name

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.