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

Since:

BlackBerry 10.0.0

Arguments:

name
The name of the user.
result
(getspnam_r() only) A pointer to a spwd structure where the function can store the entry. For more information about this structure, see putspent().
buffer
(getspnam_r() only) A block of memory that the function can use to allocate storage referenced by the spwd structure. You can determine the maximum size needed for this buffer by calling sysconf() with an argument of _SC_GETPW_R_SIZE_MAX.
bufsize
(getspnam_r() only) The size of the block that buffer points to, in characters.

Library:

libc

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

Description:

The getspnam() and getspnam_r() functions allow a process to gain more knowledge about a user name. The getspnam() function uses a static buffer that's overwritten by each call.

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, or NULL if an error occurred or the function couldn't find a matching entry.

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:

Unix

Table 1. getspnam()
Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread No
Table 2. getspnam_r()
Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus