Getpwnam no such file or directory

  • Thread starter Thread starter James889
  • Start date Start date
  • Tags Tags
    File
Click For 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.
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 10 ·
Replies
10
Views
6K
  • · Replies 11 ·
Replies
11
Views
35K
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 19 ·
Replies
19
Views
4K