fgetspent()

QNX SDP8.0C Library ReferenceAPIDeveloper

Get an entry from the shadow password database

Synopsis:

#include <sys/types.h>
#include <shadow.h>

struct spwd* fgetspent( FILE* f );

Arguments:

f
The stream from which to read the shadow password database.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.

Note:
The fgetspent(), getspent(), and getspnam() functions share the same static buffer.

Returns:

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().

Errors:

The fgetspent() function uses the following functions, and as a result errno can be set to an error for any of these calls:

Examples:

#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 );
}

Classification:

Unix

Safety:
Cancellation pointYes
Signal handlerNo
ThreadNo
Page updated: