user2netname Subroutine

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

user2netname Subroutine Exported from the libc Library

Purpose

Converts from a domain-specific user ID to a network name that is independent from the operating system.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

int user2netname ( name,  uid,  domain)
char *name;
int uid;
char *domain;

Description

The user2netname subroutine converts from a domain-specific user ID to a network name that is independent from the operating system.

This subroutine is the inverse of the netname2user subroutine.

Parameters

Item Description
name Points to the network name (or netname) of the server process owner.
uid Points to the caller's effective user ID (UID).
domain Points to the domain name.

Return Values

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

user2netname Subroutine Exported from the libnsl Library

Purpose

Converts a domain-specific user name to an operating-system-independent network name.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int user2netname( name, uid, domain)
char *name;
const uid_t uid;
const char *domain;

Description

The user2netname subroutine, which belongs to the secure remote procedure call (RPC) category, is used in applications which use the AUTH_DES authentication flavor. This subroutine is used on client side to generate a network name (or a netname) of the user.

This subroutine is the inverse of the netname2user subroutine.

Parameters

Item Description
name Represents the network name of the user after successful completion.
uid Specifies a domain-specific user name.
domain Specifies the domain.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

#include <rpc/rpc.h>
int main()
{
  char name[255]; /* contains netname of owner of server process */
  char rhost[255]; /* Remote host name on which server resides */ 
  char domain[255]; 
  rpcprog_t PROGNUM = 0x3fffffffL;
  rpcvers_t PROGVER = 0x1L;
  
  /* obtain the domainname of the host */
  if (getdomainname(domain, 255)) {
    fprintf(stderr, "\ngetdomainname() failed\n");
    exit(2);
  }

  /* Obtain network name of remote host */
  if (!user2netname(name, getuid() , domain)) 
  {
    fprintf(stderr, "\nhost2netname() failed\n");
    exit(EXIT_FAILURE);
  }

  /* Create a client handle for remote host rhost for PROGNUM & PROGVER on tcp transport */
  clnt = clnt_create(rhost, PROGNUM, PROGVER, "tcp");
  if (clnt == (CLIENT *) NULL) {
    fprintf(stderr,"client_create() error\n");
    exit(1);
  }

  clnt->cl_auth = auhdes_seccreate(name, 80, rhost, (des_block *)NULL);

  /* 
   * Make a call to clnt_call() subroutine 
   */

  /* Destroy the authentication handle */
  auth_destroy(clnt->cl_auth);
  
  /* Destroy the client handle in the end */
  clnt_destroy(clnt);

  return 0;
}