Getpwnam no such file or directory

  • Thread starter Thread starter James889
  • Start date Start date
  • Tags Tags
    File
AI Thread Summary
The discussion revolves around creating a simple authentication plugin that checks user credentials against the /etc/master.passwd file. The main issue encountered is the failure of the getpwnam() function, which returns 'no such file or directory'. The problem is identified as a trailing newline character in the username string, which can be resolved by removing it. Additionally, there are insights about the complexity of replicating functionality provided by existing modules like getlogin, particularly in FreeBSD, where PAM modules can vary significantly across systems, affecting portability. The conversation emphasizes the importance of reviewing FreeBSD source code for better understanding and suggests leveraging existing open-source solutions rather than attempting to build from scratch. Furthermore, there is a mention of discrepancies between the hashed passwords in master.passwd and those generated by the crypt() function, despite using the same clear text password.
James889
Messages
190
Reaction score
1
Hi,

I'm trying to write a simple authentication plugin which authenticates a user against /etc/master.passwd.
The problem is the call to getpwnam() which fails with 'no such file or directory'

Relevant code below
Code:
char username[10];
memset(username,0,sizeof(username));

/* Read the username */
        printf("Username:");
        fgets(username,sizeof(username),stdin);        /* Read the password */
        crypt_set_format("sha512");
        char *pass;
        pass = getpass("password:");
        char *p = (char *)calloc(strlen(pass),sizeof(char));         strlcpy(p,crypt(pass,salt),sizeof(p));
         struct passwd *local_pass = getpwnam(username);
                if( local_pass == NULL){
                printf("%s",strerror(errno));
                exit(1);
        }

Replacing the reference to the username buffer with "<actual username>" works.
Any ideas?
 
Technology news on Phys.org
Your username string has a trailing '\n' remove it and your call will work.
 
Duh, silly newbie mistake :)
 
Well, it looks like you are trying to duplicate what the getlogin modules already do. That is not an easy to duplicate: FreeBSD pam modules are going to be different from box to box, so this will have zero portability. Any-hoo, get and read the FreeBSD source before attempting something like this, just so you no longer think this is a slam dunk if nothing else. It is okay to pilfer and use what hundreds of programmers have already worked on for years, and tried to perfect. That is the whole idea of opensource.
 
There seems to be a similar situation with the hashed password found in master.password and the hash generated by crypt(),
they are different, despite hashing being done on the same clear text password. In this case there are no trailing newlines.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top