rpc_gss_getcred Subroutine

Purpose

Gets credentials of a caller.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpcsec_gss.h>
bool_t rpc_gss_getcred(req, r_cred, u_cred, cookie)
struct svc_req *req;
rpc_gss_rawcred_t **r_cred;
rpc_gss_ucred_t **u_cred;
void **cookie;

Description

The rpc_gss_getcred subroutine is used to get credentials of a caller. You can retrieve network credentials and UNIX credentials.

Parameters

Item Description
req Points to a received service-request structure.
r_cred Points to an rpc_gss_rawcred_t structure that is returned with raw credentials. Raw credentials include the remote procedure call (RPC) version, security mechanism, quality of protection, client principal, server principal, service type, and so on. This is an output parameter. You can specify the parameter with NULL.
u_cred Points to an rpc_gss_ucred_t structure that is returned with UNIX credentials. UNIX credentials include user ID, group ID, and so on. This is an output parameter. You can specify the parameter with NULL.
cookie Represents a 4-byte entity that an application can use in any manner. This is an output parameter.

Return Values

Item Description
TRUE successful
FALSE unsuccessful

You can use the rpc_gss_get_error subroutine to retrieve the error number.

Examples

In the following example, credentials of the caller are retrieved in the dispatch routine of the server.

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

#define PROGNUM 0x3fffffffL
#define VERSNUM 0x1L
 
static void sample_dispatch(struct svc_req *, SVCXPRT *);
main()
{
    
  /* Create RPC service handle and register with RPCBIND service */

  /* Set the principal name */
   
  svc_run();
  return 1;    
} 
   
/* following is the sample dispatch routine*/
static void sample_dispatch(struct svc_req *request, SVCXPRT *xprt)
{
  rpc_gss_rawcred_t *r_cred;
  rpc_gss_ucred_t *u_cred;
    
  /* Get caller's credentials */
  if(rpc_gss_getcred(request, &r_cred, &u_cred, NULL) == FALSE)
  {
    fprintf(stderr,"\nError in rpc_gss_getcred:\n");     
    rpc_gss_get_error(&gss_error);
    fprintf(stderr,"rpc_gss_error: %d \nSystem_error: %d \n",
    gss_error.rpc_gss_error,gss_error.system_error);
    svcerr_systemerr(xprt);
    return; 
  }

  /* Send reply back to caller */
}