authsys_create or authsys_create_default Subroutine

Purpose

Creates and returns the authentication handle of a remote procedure call (RPC).

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
AUTH * authsys_create( hostname, user_id, group_id, length, aup_gids)
const char *hostname;
const uid_t user_id;
const gid_t group_id;
const int length;
const gid_t *aup_gids;
AUTH *authsys_create_default( void )

Description

The authsys_create and authsys_create_default subroutines belong to the secure-RPC category. The authsys_create or authsys_create_default subroutine creates and returns an RPC-authentication handle. The authentication information that is passed to the server on each RPC is the AUTH_SYS authentication information.

The authsys_create_default subroutine , which is basically a wrapper around the authsys_create subroutine, calls the authsys_create subroutine with appropriate parameters.

Note: Application programs assign the RPC authentication handle to the cl_auth field of the client handle.

Parameters

Item Description
hostname Specifies the host name of the server where the authentication information is created.
user_id Specifies the user ID.
group_id Specifies the current group ID of the user.
length Specifies the number of groups to which the user belongs, that is, the length of the aup_gids parameter.
aup_gids Specifies an array of groups to which the user belongs.

Return Values

The authsys_create or authsys_create_default subroutine returns a pointer to an RPC-authentication handle.

Examples

  1. In the following example, the authsys_create subroutine is called after a client handle is created. An authentication handle is returned and assigned to the cl_auth field of the client handle. Then, after a successful client call, the auth_destroy macro destroys the authentication information associated with the cl_auth field.
    #include <stdlib.h>
    #include <rpc/rpc.h>
    
    int main()
    {
        rpcprog_t PROGNUM = 0x3fffffffL;
        rpcvers_t PROGVER = 0x1L;
        char *nettype = ="visible";
        char hostname[255];      /* The name of remote hostname */
        AUTH *auth;
        gid_t gids[100];
        int length ;
    
        /* Set the number of groups to which the user belongs. 
         *This value is passed to authsys_create() 
         */
        if ((length = getgroups(NGROUPS_MAX, gids)) < 0) {
            printf("failed in getgroups()\n");
            exit(2);
        } else
            length = (length > 16) ? 16 : length;
    
        if ((cl=clnt_create( hostname, PROGNUM, PROGVER, nettype)) == NULL)
        {
            fprintf(stdout, "clnt_create : failed.\n");
            exit(EXIT_FAILURE);
        }
    
        /* Set the AUTH structure using AUTH_SYS authentication flavor */
        auth = authsys_create(hostname, getuid(), getgid(), length, gids);
        cl->cl_auth = auth;
    
        /* 
         * Make a CLNT_CALL 
         */
    
        /* Destroy the authentication information */
        auth_destroy(cl->cl_auth);
    
        /* Destroy the client handle */
        clnt_destroy(cl);
     
        return 0;
    
    }
  2. In the following example, the authsys_create_default subroutine is called after a client handle is created. An authentication handle is returned and assigned to the cl_auth field of the client handle. Then, after a successful client call, the auth_destroy macro destroys the authentication information associated with the cl_auth field.
    #include <stdlib.h>
    #include <rpc/rpc.h>
    int main()
    {
        rpcprog_t PROGNUM = 0x3fffffffL;
        rpcvers_t PROGVER = 0x1L;
        char *nettype = "visible";
        char hostname[255];      /* The name of remote host */
        AUTH *auth
        
        if ((cl=clnt_create( hostname, PROGNUM, PROGVER, nettype)) == NULL)
        {
            fprintf(stdout, "clnt_create : failed.\n");
            exit(EXIT_FAILURE);
        }
    
        /* Set the AUTH structure using AUTH_SYS authentication flavor */
        auth = authsys_create_default();
        cl->cl_auth = auth;
    
        /* 
         * Make a CLNT_CALL 
        */
    
        /* Destroy the authentication information */
        auth_destroy(cl->cl_auth);
    
        /* Destroy the client handle */
        clnt_destroy(cl);
     
        return 0;
    }