Creates and returns the authentication handle of a remote procedure call (RPC).
Network Services Library (libnsl.a)
#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 )
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.
| 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. | 
The authsys_create or authsys_create_default subroutine returns a pointer to an RPC-authentication handle.
#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;
}
#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;
}