[Previous] [Contents] [Next]

getspnam(), getspnam_r()

Get information about a user with a given name

Synopsis:

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

struct spwd* getspnam( char* name );

struct spwd* getspnam_r( const char* name, 
                         struct spwd* result, 
                         char* buffer, 
                         size_t bufsize );

Library:

libc

Description:

The getspnam() and getspnam_r() functions allow a process to gain more knowledge about a user name. They use 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 an entry from the group database with a matching name. A NULL pointer is returned on error or failure to find a entry with a matching name.

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <shadow.h>

/*
 * Print information from the password entry
 * about the user name given as argv[1].
 */

int main( int argc, char** argv ) 
{
    struct spwd* sp;

        if (argc < 2) {
                printf("%s username \n", argv[0]);
                return(EXIT_FAILURE);
        }

    if( ( sp = getspnam( argv[1] ) ) == (struct spwd*)0) {
      fprintf( stderr, "getspnam: unknown %s\n",
        argv[1] );
      return( EXIT_FAILURE );
    }
    printf( "login name  %s\n", sp->sp_namp );
    printf( "password    %s\n", sp->sp_pwdp );
    return( EXIT_SUCCESS );
}

Classification:

getspnam() is POSIX 1003.1; getspnam_r() is Unix

getspnam()

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread No

getspnam_r()

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

fgetspent(), getlogin(), getspent(), getpwuid()


[Previous] [Contents] [Next]