iPXE
Macros | Functions | Variables
oncrpc.c File Reference

SUN ONC RPC protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/socket.h>
#include <ipxe/tcpip.h>
#include <ipxe/in.h>
#include <ipxe/iobuf.h>
#include <ipxe/dhcp.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <ipxe/features.h>
#include <ipxe/oncrpc.h>
#include <ipxe/oncrpc_iob.h>
#include <ipxe/init.h>
#include <ipxe/settings.h>
#include <ipxe/version.h>

Go to the source code of this file.

Macros

#define SET_LAST_FRAME(x)   ( (x) | 1 << 31 )
 Set most significant bit to 1. More...
 
#define GET_FRAME_SIZE(x)   ( (x) & ~( 1 << 31 ) )
 
#define ONCRPC_CALL   0
 
#define ONCRPC_REPLY   1
 

Functions

const struct setting uid_setting __setting (SETTING_AUTH, uid)
 
const struct setting gid_setting __setting (SETTING_AUTH, gid)
 
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 __unused, struct oncrpc_reply *reply, struct io_buffer *io_buf)
 Parse an I/O buffer to extract a ONC RPC REPLY. More...
 

Variables

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

Detailed Description

SUN ONC RPC protocol.

Definition in file oncrpc.c.

Macro Definition Documentation

◆ SET_LAST_FRAME

#define SET_LAST_FRAME (   x)    ( (x) | 1 << 31 )

Set most significant bit to 1.

Definition at line 49 of file oncrpc.c.

◆ GET_FRAME_SIZE

#define GET_FRAME_SIZE (   x)    ( (x) & ~( 1 << 31 ) )

Definition at line 50 of file oncrpc.c.

◆ ONCRPC_CALL

#define ONCRPC_CALL   0

Definition at line 52 of file oncrpc.c.

◆ ONCRPC_REPLY

#define ONCRPC_REPLY   1

Definition at line 53 of file oncrpc.c.

Function Documentation

◆ __setting() [1/2]

const struct setting uid_setting __setting ( SETTING_AUTH  ,
uid   
)

◆ __setting() [2/2]

const struct setting gid_setting __setting ( SETTING_AUTH  ,
gid   
)

◆ 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:76
#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:873
uint32_t flavor
Definition: oncrpc.h:47
char * strdup(const char *src)
Duplicate string.
Definition: string.c:380
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:1068
uint32_t stamp
Definition: oncrpc.h:53
uint32_t length
Definition: oncrpc.h:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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:255
#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:129
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
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:33

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
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
uint32_t type
Operating system type.
Definition: ena.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  __unused,
struct oncrpc_reply reply,
struct io_buffer io_buf 
)

Parse an I/O buffer to extract a ONC RPC REPLY.

Parameters
sessionONC RPC session
replyReply structure where data will be saved
io_bufI/O buffer

Definition at line 215 of file oncrpc.c.

216  {
217  if ( ! reply || ! io_buf )
218  return -EINVAL;
219 
220  reply->frame_size = GET_FRAME_SIZE ( oncrpc_iob_get_int ( io_buf ) );
221  reply->rpc_id = oncrpc_iob_get_int ( io_buf );
222 
223  /* iPXE has no support for handling ONC RPC call */
224  if ( oncrpc_iob_get_int ( io_buf ) != ONCRPC_REPLY )
225  return -ENOSYS;
226 
227  reply->reply_state = oncrpc_iob_get_int ( io_buf );
228 
229  if ( reply->reply_state == 0 )
230  {
231  /* verifier.flavor */
232  oncrpc_iob_get_int ( io_buf );
233  /* verifier.length */
234  iob_pull ( io_buf, oncrpc_iob_get_int ( io_buf ));
235 
236  /* We don't use the verifier in iPXE, let it be an empty
237  verifier. */
238  reply->verifier = &oncrpc_auth_none;
239  }
240 
241  reply->accept_state = oncrpc_iob_get_int ( io_buf );
242  reply->data = io_buf;
243 
244  return 0;
245 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct oncrpc_cred * verifier
Definition: oncrpc.h:63
uint32_t accept_state
Definition: oncrpc.h:66
uint32_t rpc_id
Definition: oncrpc.h:64
#define ONCRPC_REPLY
Definition: oncrpc.c:53
#define oncrpc_iob_get_int(buf)
Get a 32 bits integer from the beginning of an I/O buffer.
Definition: oncrpc_iob.h:38
uint32_t frame_size
Definition: oncrpc.h:67
struct oncrpc_cred oncrpc_auth_none
AUTH NONE authentication flavor.
Definition: oncrpc.c:56
uint32_t reply_state
Definition: oncrpc.h:65
#define GET_FRAME_SIZE(x)
Definition: oncrpc.c:50
#define ENOSYS
Function not implemented.
Definition: errno.h:564
struct io_buffer * data
Definition: oncrpc.h:68

References oncrpc_reply::accept_state, oncrpc_reply::data, EINVAL, ENOSYS, oncrpc_reply::frame_size, GET_FRAME_SIZE, iob_pull, oncrpc_auth_none, oncrpc_iob_get_int, ONCRPC_REPLY, oncrpc_reply::reply_state, oncrpc_reply::rpc_id, and oncrpc_reply::verifier.

Referenced by nfs_deliver(), nfs_mount_deliver(), and nfs_pm_deliver().

Variable Documentation

◆ oncrpc_auth_none

struct oncrpc_cred oncrpc_auth_none
Initial value:
= {
.flavor = ONCRPC_AUTH_NONE,
.length = 0
}
#define ONCRPC_AUTH_NONE
ONC RPC Null Authentication.
Definition: oncrpc.h:20

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().