svc_auth_reg Subroutine

Purpose

Registers an authentication routine with the dispatch mechanism.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int svc_auth_reg(cr_flavor, auth_handler);
const int cr_flavor;
enum auth_stat(*auth_handler)(struct svc_req *, struct rpc_msg *);

Description

The svc_auth_reg subroutine registers an authentication routine with the dispatch mechanism so that service requests from clients can be authenticated with the specified authentication type. With the subroutine, you can add new authentication types to applications without changing the existing library. Call the svc_auth_reg subroutine after the service registration and before calling the svc_run subroutine. When remote procedure call (RPC) credentials are checked, the corresponding authentication handler is invoked. When registered, the authentication handler cannot be changed or deleted.

Parameters

Item Description
cr_flavor Specifies the authentication type.
auth_handler Specifies the authentication handler that has two parameters and returns a valid value of the auth_stat type.

Return Values

Item Description
0 The subroutine completed successfully.
1 An authentication handler has already registered for the specified authentication type.
-1 An error occurred.

Examples

#include <stdlib.h>
#include <rpc/rpc.h>

#define PROG 0x3fffffffL
#define VERS 0x1L

static void sample_dispatch();
enum auth_stat auth_handler(struct  svc_req  *rqst, struct  rpc_msg  *msg);

main()
{
      char *nettype;
      int no_of_handles,cr_flavor;

      /* Specify transport type */
      nettype = "tcp";
             

      /* Create RPC service handle and register with RPCBIND service */
      if((no_of_handles = svc_create(sample_dispatch, PROG, VERS,nettype)) == 0)
      {
              fprintf(stdout,"Error in svc_create!");
              exit(EXIT_FAILURE);
      }
  
      /* select desired cr_flavor */
      cr_flavor = AUTH_NONE;               

      /* Register an authentication routine with the dispatch mechanism */
      if(svc_auth_reg(cr_flavor, auth_handler) == -1)
      {
              fprintf(stdout,"Error in svc_auth_reg!");
              exit(EXIT_FAILURE);
       }

       svc_run();
       return 0;
} 

       /* following is the sample dispatch routine*/
       static void sample_dispatch(struct svc_req *request, SVCXPRT *xprt)
       {
    
              /*  dispatch routine code  */

       } 

/*following is the sample authentication handler */ 
enum auth_stat auth_handler(struct  svc_req  *rqst, struct  rpc_msg  *msg)
{ 
       fprintf(stdout, "Entering authentication handler\n");
       return AUTH_OK;  /* auth_stat value */
}