iPXE
Data Structures | Macros | Enumerations | Functions | Variables
oncrpc.h File Reference

SUN ONC RPC protocol. More...

#include <stdint.h>
#include <ipxe/interface.h>
#include <ipxe/iobuf.h>

Go to the source code of this file.

Data Structures

struct  oncrpc_cred
 
struct  oncrpc_cred_sys
 
struct  oncrpc_reply
 
struct  oncrpc_session
 
union  oncrpc_field_value
 
struct  oncrpc_field
 

Macros

#define ONCRPC_VERS   2
 ONC RCP Version. More...
 
#define ONCRPC_AUTH_NONE   0
 ONC RPC Null Authentication. More...
 
#define ONCRPC_AUTH_SYS   1
 ONC RPC System Authentication (also called UNIX Authentication) More...
 
#define ONCRPC_HEADER_SIZE   ( 11 * sizeof ( uint32_t ) )
 Size of an ONC RPC header. More...
 
#define ONCRPC_FIELD(type, value)   { oncrpc_ ## type, { .type = value } }
 
#define ONCRPC_SUBFIELD(type, args...)   { oncrpc_ ## type, { .type = { args } } }
 
#define ONCRPC_FIELD_END   { oncrpc_none, { } }
 
#define oncrpc_align(size)   ( ( (size) + 3 ) & ~3 )
 Enusure that size is a multiple of four. More...
 
#define oncrpc_strlen(str)
 Calculate the length of a string, including padding bytes. More...
 

Enumerations

enum  oncrpc_field_type {
  oncrpc_none = 0, oncrpc_int32, oncrpc_int64, oncrpc_str,
  oncrpc_array, oncrpc_intarray, oncrpc_cred
}
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int oncrpc_init_cred_sys (struct oncrpc_cred_sys *auth_sys)
 Initialize an ONC RPC AUTH SYS credential structure. More...
 
void oncrpc_init_session (struct oncrpc_session *session, struct oncrpc_cred *credential, struct oncrpc_cred *verifier, uint32_t prog_name, uint32_t prog_vers)
 Prepare an ONC RPC session structure to be used by the ONC RPC layer. More...
 
int oncrpc_call (struct interface *intf, struct oncrpc_session *session, uint32_t proc_name, const struct oncrpc_field fields[])
 
size_t oncrpc_compute_size (const struct oncrpc_field fields[])
 
int oncrpc_get_reply (struct oncrpc_session *session, struct oncrpc_reply *reply, struct io_buffer *io_buf)
 

Variables

struct oncrpc_cred oncrpc_auth_none
 AUTH NONE authentication flavor. More...
 

Detailed Description

SUN ONC RPC protocol.

Definition in file oncrpc.h.

Macro Definition Documentation

◆ ONCRPC_VERS

#define ONCRPC_VERS   2

ONC RCP Version.

Definition at line 17 of file oncrpc.h.

◆ ONCRPC_AUTH_NONE

#define ONCRPC_AUTH_NONE   0

ONC RPC Null Authentication.

Definition at line 20 of file oncrpc.h.

◆ ONCRPC_AUTH_SYS

#define ONCRPC_AUTH_SYS   1

ONC RPC System Authentication (also called UNIX Authentication)

Definition at line 23 of file oncrpc.h.

◆ ONCRPC_HEADER_SIZE

#define ONCRPC_HEADER_SIZE   ( 11 * sizeof ( uint32_t ) )

Size of an ONC RPC header.

Definition at line 26 of file oncrpc.h.

◆ ONCRPC_FIELD

#define ONCRPC_FIELD (   type,
  value 
)    { oncrpc_ ## type, { .type = value } }

Definition at line 28 of file oncrpc.h.

◆ ONCRPC_SUBFIELD

#define ONCRPC_SUBFIELD (   type,
  args... 
)    { oncrpc_ ## type, { .type = { args } } }

Definition at line 29 of file oncrpc.h.

◆ ONCRPC_FIELD_END

#define ONCRPC_FIELD_END   { oncrpc_none, { } }

Definition at line 32 of file oncrpc.h.

◆ oncrpc_align

#define oncrpc_align (   size)    ( ( (size) + 3 ) & ~3 )

Enusure that size is a multiple of four.

Definition at line 35 of file oncrpc.h.

◆ oncrpc_strlen

#define oncrpc_strlen (   str)
Value:
( oncrpc_align ( strlen ( str ) ) + \
sizeof ( uint32_t ) )
#define oncrpc_align(size)
Enusure that size is a multiple of four.
Definition: oncrpc.h:35
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
unsigned int uint32_t
Definition: stdint.h:12

Calculate the length of a string, including padding bytes.

Parameters
strString
Return values
sizeLength of the padded string

Definition at line 43 of file oncrpc.h.

Enumeration Type Documentation

◆ oncrpc_field_type

Enumerator
oncrpc_none 
oncrpc_int32 
oncrpc_int64 
oncrpc_str 
oncrpc_array 
oncrpc_intarray 
oncrpc_cred 

Definition at line 80 of file oncrpc.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ oncrpc_init_cred_sys()

int oncrpc_init_cred_sys ( struct oncrpc_cred_sys auth_sys)

Initialize an ONC RPC AUTH SYS credential structure.

Parameters
auth_sysThe structure to initialize

The hostname field is filled with the value of the hostname setting, if the hostname setting is empty, PRODUCT_SHORT_NAME (usually "iPXE") is used instead.

Definition at line 84 of file oncrpc.c.

84  {
85  if ( ! auth_sys )
86  return -EINVAL;
87 
88  fetch_string_setting_copy ( NULL, &hostname_setting,
89  &auth_sys->hostname );
90  if ( ! auth_sys->hostname )
91  if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
92  return -ENOMEM;
93 
94  auth_sys->uid = fetch_uintz_setting ( NULL, &uid_setting );
95  auth_sys->gid = fetch_uintz_setting ( NULL, &uid_setting );
96  auth_sys->aux_gid_len = 0;
97  auth_sys->stamp = 0;
98 
99  auth_sys->credential.flavor = ONCRPC_AUTH_SYS;
100  auth_sys->credential.length = 16 +
101  oncrpc_strlen ( auth_sys->hostname );
102 
103  return 0;
104 }
const char product_short_name[]
Product short name string.
Definition: version.c:75
#define EINVAL
Invalid argument.
Definition: errno.h:428
uint32_t uid
Definition: oncrpc.h:55
#define ONCRPC_AUTH_SYS
ONC RPC System Authentication (also called UNIX Authentication)
Definition: oncrpc.h:23
#define oncrpc_strlen(str)
Calculate the length of a string, including padding bytes.
Definition: oncrpc.h:43
uint32_t gid
Definition: oncrpc.h:56
uint32_t aux_gid_len
Definition: oncrpc.h:57
#define ENOMEM
Not enough space.
Definition: errno.h:534
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:877
uint32_t flavor
Definition: oncrpc.h:47
char * strdup(const char *src)
Duplicate string.
Definition: string.c:365
char * hostname
Definition: oncrpc.h:54
unsigned long fetch_uintz_setting(struct settings *settings, const struct setting *setting)
Fetch value of unsigned integer setting, or zero.
Definition: settings.c:1072
uint32_t stamp
Definition: oncrpc.h:53
uint32_t length
Definition: oncrpc.h:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct oncrpc_cred credential
Definition: oncrpc.h:52

References oncrpc_cred_sys::aux_gid_len, oncrpc_cred_sys::credential, EINVAL, ENOMEM, fetch_string_setting_copy(), fetch_uintz_setting(), oncrpc_cred::flavor, oncrpc_cred_sys::gid, oncrpc_cred_sys::hostname, oncrpc_cred::length, NULL, ONCRPC_AUTH_SYS, oncrpc_strlen, product_short_name, oncrpc_cred_sys::stamp, strdup(), and oncrpc_cred_sys::uid.

Referenced by nfs_open().

◆ oncrpc_init_session()

void oncrpc_init_session ( struct oncrpc_session session,
struct oncrpc_cred credential,
struct oncrpc_cred verifier,
uint32_t  prog_name,
uint32_t  prog_vers 
)

Prepare an ONC RPC session structure to be used by the ONC RPC layer.

Parameters
sessionONC RPC session
credentialCredential structure pointer
verifierVerifier structure pointer
prog_nameONC RPC program number
prog_versONC RPC program version number

Definition at line 115 of file oncrpc.c.

118  {
119  if ( ! session )
120  return;
121 
122  session->rpc_id = rand();
123  session->credential = credential;
124  session->verifier = verifier;
125  session->prog_name = prog_name;
126  session->prog_vers = prog_vers;
127 }
static int rand(void)
Definition: stdlib.h:59
struct ntlm_data session
Session key.
Definition: ntlm.h:24

References rand(), and session.

Referenced by mount_init_session(), nfs_init_session(), and portmap_init_session().

◆ oncrpc_call()

int oncrpc_call ( struct interface intf,
struct oncrpc_session session,
uint32_t  proc_name,
const struct oncrpc_field  fields[] 
)

Definition at line 129 of file oncrpc.c.

130  {
131  size_t frame_size;
132  struct io_buffer *io_buf;
133 
134  if ( ! session )
135  return -EINVAL;
136 
137  struct oncrpc_field header[] = {
138  ONCRPC_FIELD ( int32, 0 ),
139  ONCRPC_FIELD ( int32, ++session->rpc_id ),
142  ONCRPC_FIELD ( int32, session->prog_name ),
143  ONCRPC_FIELD ( int32, session->prog_vers ),
144  ONCRPC_FIELD ( int32, proc_name ),
145  ONCRPC_FIELD ( cred, session->credential ),
146  ONCRPC_FIELD ( cred, session->verifier ),
148  };
149 
150  frame_size = oncrpc_compute_size ( header );
151  frame_size += oncrpc_compute_size ( fields );
152 
153  io_buf = alloc_iob ( frame_size );
154  if ( ! io_buf )
155  return -ENOBUFS;
156 
157  header[0].value.int32 = SET_LAST_FRAME ( frame_size -
158  sizeof ( uint32_t ) );
159 
160  oncrpc_iob_add_fields ( io_buf, header );
161  oncrpc_iob_add_fields ( io_buf, fields );
162 
163  return xfer_deliver_iob ( intf, iob_disown ( io_buf ) );
164 }
#define ONCRPC_FIELD(type, value)
Definition: oncrpc.h:28
size_t oncrpc_iob_add_fields(struct io_buffer *io_buf, const struct oncrpc_field fields[])
Definition: oncrpc_iob.c:44
#define EINVAL
Invalid argument.
Definition: errno.h:428
#define ONCRPC_VERS
ONC RCP Version.
Definition: oncrpc.h:17
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:254
#define SET_LAST_FRAME(x)
Set most significant bit to 1.
Definition: oncrpc.c:49
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
int32_t int32
Definition: stdint.h:31
struct ntlm_data session
Session key.
Definition: ntlm.h:24
size_t oncrpc_compute_size(const struct oncrpc_field fields[])
Definition: oncrpc.c:166
unsigned int uint32_t
Definition: stdint.h:12
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define ONCRPC_FIELD_END
Definition: oncrpc.h:32
struct ena_aq_header header
Header.
Definition: ena.h:12
#define ONCRPC_CALL
Definition: oncrpc.c:52
A persistent I/O buffer.
Definition: iobuf.h:32

References alloc_iob(), EINVAL, ENOBUFS, header, iob_disown, ONCRPC_CALL, oncrpc_compute_size(), ONCRPC_FIELD, ONCRPC_FIELD_END, oncrpc_iob_add_fields(), ONCRPC_VERS, session, SET_LAST_FRAME, and xfer_deliver_iob().

Referenced by mount_mnt(), mount_umnt(), nfs_lookup(), nfs_read(), nfs_readlink(), and portmap_getport().

◆ oncrpc_compute_size()

size_t oncrpc_compute_size ( const struct oncrpc_field  fields[])

Definition at line 166 of file oncrpc.c.

166  {
167 
168  size_t i;
169  size_t size = 0;
170 
171  for ( i = 0; fields[i].type != oncrpc_none; i++ ) {
172  switch ( fields[i].type ) {
173  case oncrpc_int32:
174  size += sizeof ( uint32_t );
175  break;
176 
177  case oncrpc_int64:
178  size += sizeof ( uint64_t );
179  break;
180 
181  case oncrpc_str:
182  size += oncrpc_strlen ( fields[i].value.str );
183  break;
184 
185  case oncrpc_array:
186  size += oncrpc_align ( fields[i].value.array.length );
187  size += sizeof ( uint32_t );
188  break;
189 
190  case oncrpc_intarray:
191  size += sizeof ( uint32_t ) *
192  fields[i].value.intarray.length;
193  size += sizeof ( uint32_t );
194  break;
195 
196  case oncrpc_cred:
197  size += fields[i].value.cred->length;
198  size += 2 * sizeof ( uint32_t );
199  break;
200 
201  default:
202  return size;
203  }
204  }
205 
206  return size;
207 }
#define oncrpc_strlen(str)
Calculate the length of a string, including padding bytes.
Definition: oncrpc.h:43
#define oncrpc_align(size)
Enusure that size is a multiple of four.
Definition: oncrpc.h:35
uint8_t type
Type.
Definition: ena.h:16
unsigned long long uint64_t
Definition: stdint.h:13
union oncrpc_field_value value
Definition: oncrpc.h:109
enum oncrpc_field_type type
Definition: oncrpc.h:108
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned int uint32_t
Definition: stdint.h:12
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
uint32_t length
Definition: oncrpc.h:48
const struct oncrpc_cred * cred
Definition: oncrpc.h:104

References oncrpc_field_value::cred, oncrpc_cred::length, oncrpc_align, oncrpc_array, oncrpc_cred, oncrpc_int32, oncrpc_int64, oncrpc_intarray, oncrpc_none, oncrpc_str, oncrpc_strlen, size, type, oncrpc_field::type, value, and oncrpc_field::value.

Referenced by oncrpc_call().

◆ oncrpc_get_reply()

int oncrpc_get_reply ( struct oncrpc_session session,
struct oncrpc_reply reply,
struct io_buffer io_buf 
)

Variable Documentation

◆ oncrpc_auth_none

struct oncrpc_cred oncrpc_auth_none

AUTH NONE authentication flavor.

Definition at line 56 of file oncrpc.c.

Referenced by mount_init_session(), nfs_init_session(), oncrpc_get_reply(), and portmap_init_session().