Updated: October 28, 2024 |
Get an entry from the shadow password database
#include <sys/types.h> #include <shadow.h> struct spwd* getspent( void ); struct spwd* getspent_r( struct spwd* result, char* buffer, int buflen );
These arguments apply only to getspent_r():
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The getspent() and getspent_r() functions return the next entry from the shadow password database. The getspent() function uses a static buffer that's overwritten by each call.
The getspent() function returns a pointer to a struct spwd object containing the next entry from the shadow password database. When getspent() is first called, the database is opened, and it remains open until either a NULL is returned to signify end-of-file, or endspent() is called.
In addition to the errno settings listed above, a call to getspent() 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 login names from standard input and * checks to see if each is a valid name. If not, the entire * contents of the password database are printed. */ int main(int argc, char** argv) { struct spwd* sp; char buf[80]; setpwent(); while( gets( buf ) != NULL ) { if( ( sp = getspnam( buf ) ) != ( struct spwd * )0 ) { printf( "Valid login name is: %s\n", sp->sp_namp ); } else { setspent(); while( ( sp=getspent( ) ) != ( struct spwd * )0 ) printf( "%s\n", sp->sp_namp ); } } endspent(); return(EXIT_SUCCESS); }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | No |
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |