Updated: April 19, 2023 |
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 an object of type struct spwd containing the next entry from the password database. For more information about this structure, see putspent().
The fgetspent() function uses the following functions, and as a result errno can be set to an error for any of these calls:
#include <stdio.h> #include <stdlib.h> #include <pwd.h> #include <shadow.h> /* * This program loops, reading a entries from a file * (which is formatted in the shadow password way) * reading the next shadow password entry. * For example this_file /etc/shadow */ 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 |