| Updated: October 28, 2024 |
Get an entry from the shadow password database
#include <sys/types.h> #include <shadow.h> struct spwd* fgetspent( FILE* f );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The fgetspent() works like the getspent() function but it assumes that it's reading from a file formatted like a shadow password database file. This function uses a static buffer that's overwritten by each call.
A pointer to a struct spwd object containing the next entry from the password database. For more information about this structure, see putspent().
In addition to the errno settings listed above, a call to fgetspent() can result in errno being set by any of the following functions:
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <shadow.h>
/*
* This program reads entries from a file that is formatted like
* a shadow password file. Each loop iteration reads the next
* shadow password entry.
*/
int main( int argc, char** argv )
{
FILE* fp;
struct spwd* sp;
if (argc < 2) {
printf("%s filename \n", argv[0]);
return(EXIT_FAILURE);
}
if (!(fp = fopen(argv[1], "r"))) {
fprintf(stderr, "Can't open file %s \n", argv[1]);
return(EXIT_FAILURE);
}
while( (sp = fgetspent(fp)) != (struct spwd *) 0 ) {
printf( "Username: %s\n", sp->sp_namp );
printf( "Password: %s\n", sp->sp_pwdp );
}
fclose(fp);
return(EXIT_SUCCESS);
}
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |