netname2user Subroutine

Important: The subroutine is exported from both the libc and the libnsl libraries.

netname2user Subroutine Exported from the libc Library

Purpose

Converts from an operating-system-independent network name to a domain-specific user number (UID).

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

netname2user (name, uidp, gidp, gidlenp, gidlist)
char * name;
int * uidp;
int * gidp;
int * gidlenp;
int * gidlist;

Description

The netname2user subroutine converts from an operating-system-independent network name to a domain-specific UID. This subroutine is the inverse of the user2netname subroutine.

Parameters

Item Description
name Points to the network name (or netname) of the server process owner. The name parameter can be either the host name derived from the host2netname subroutine or the user name derived from the user2netname subroutine.
uidp Points to the user ID.
gidp Points to the group ID.
gidlenp Points to the size of the group ID.
gidlist Points to the group list.

Return Values

Upon successful completion, this subroutine returns a value of 1. If unsuccessful, it returns a value of 0.

netname2user Subroutine Exported from the libnsl Library

Purpose

Converts from an operating-system-independent network name to a domain-specific user number (UID).

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int netname2user(name, uidp, gidp, gidlenp, gidlist)
const char *name;
uid_t *uidp;
gid_t *gidp;
int gidlenp;
gid_t gidlist[NGRPS];

Description

The netname2user subroutine, which belongs to the secure remote procedure call (RPC) category, is used in applications that use AUTH_DES authentication flavor. This subroutine is usually used on the server side to convert the network name of a user tothe domain-specific user-ID.
Note: This subroutine is the inverse of the user2netname subroutine.

Parameters

Item Description
name Specifies the network name of the host.
uidp Specifies the effective user ID (UID) of the caller.
gidp Specifies the effective group ID (GID) of the caller.
gidlenp Specifies the length of array of groups to which the user belongs.
gidlist Points to the group array.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

#include <rpc/rpc.h>
static void dispatch(struct svc_req *, SVCXPRT *);

main()
{
  rpcprog_t RPROGNUM = 0x3fffffffL;
  rpcvers_t RPROGVER = 0x1L;
  
  /* Create service handle for RPROGNUM, RPROGVER and tcp transport */
  if(!svc_create( dispatch, RPROGNUM, RPROGVER, "tcp")) {
    fprintf(stderr,"\nsvc_create() failed\n");
    exit(EXIT_FAILURE);
  }
  svc_run();
}

/* The server dispatch function */
static void dispatch(struct svc_req *rqstp, SVCXPRT *transp)
{
  struct authdes_cred *des_cred;
  uid_t uid;
  gid_t gid;
  int gidlen;
  gid_t gidlist[10];

  switch (rqstp->rq_cred.oa_flavor) {

    case AUTH_DES :
    /* AUTH_DES Authentication flavor */
    des_cred = (struct authdes_cred *) rqstp->rq_clntcred;
    if (!netname2user(des_cred->adc_fullname.name, &uid, &gid, &gidlist, gidlist)) 
    {
      svcerr_systemerr(transp);
      return;
    }
    break;
    default :
    /* Other Authentication flavor */
    break;
  }
  /* The Dispatch Routine code continues .. */
}