Getpwnam no such file or directory

  • Thread starter Thread starter James889
  • Start date Start date
  • Tags Tags
    File
Click For Summary

Discussion Overview

The discussion revolves around an issue encountered while developing an authentication plugin that verifies user credentials against the /etc/master.passwd file. Participants explore the behavior of the getpwnam() function and its failure to locate the specified username.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant suggests that the failure of getpwnam() is due to the username string containing a trailing newline character, which could be resolved by removing it.
  • Another participant notes that replacing the username buffer with a hardcoded username works, implying that the issue lies with how the username is being handled.
  • A different participant raises concerns about the portability of the authentication plugin, suggesting that replicating functionality from existing modules like getlogin may not be straightforward due to differences across FreeBSD systems.
  • One participant points out a discrepancy between the hashed password in master.passwd and the hash generated by the crypt() function, indicating that they do not match even when the same clear text password is used.

Areas of Agreement / Disagreement

Participants express differing views on the causes of the issues encountered, with some focusing on the handling of the username and others on the broader implications of the implementation's portability and hashing discrepancies. No consensus is reached on the overall solution.

Contextual Notes

Participants acknowledge potential limitations related to the handling of strings and the differences in system implementations, but do not resolve these issues.

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.
 

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