mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 04:24:34 +08:00
RPC(3): Import from FreeBSD
This commit is contained in:
parent
68d406b3b8
commit
60b1d40751
5
freebsd/include/gssapi.h
Normal file
5
freebsd/include/gssapi.h
Normal file
@ -0,0 +1,5 @@
|
||||
/* $FreeBSD$ */
|
||||
#ifdef __GNUC__
|
||||
#warning "this file includes <gssapi.h> which is deprecated, use <gssapi/gssapi.h> instead"
|
||||
#endif
|
||||
#include <gssapi/gssapi.h>
|
851
freebsd/include/gssapi/gssapi.h
Normal file
851
freebsd/include/gssapi/gssapi.h
Normal file
@ -0,0 +1,851 @@
|
||||
/*
|
||||
* Copyright (C) The Internet Society (2000). All Rights Reserved.
|
||||
*
|
||||
* This document and translations of it may be copied and furnished to
|
||||
* others, and derivative works that comment on or otherwise explain it
|
||||
* or assist in its implementation may be prepared, copied, published
|
||||
* and distributed, in whole or in part, without restriction of any
|
||||
* kind, provided that the above copyright notice and this paragraph are
|
||||
* included on all such copies and derivative works. However, this
|
||||
* document itself may not be modified in any way, such as by removing
|
||||
* the copyright notice or references to the Internet Society or other
|
||||
* Internet organizations, except as needed for the purpose of
|
||||
* developing Internet standards in which case the procedures for
|
||||
* copyrights defined in the Internet Standards process must be
|
||||
* followed, or as required to translate it into languages other than
|
||||
* English.
|
||||
*
|
||||
* The limited permissions granted above are perpetual and will not be
|
||||
* revoked by the Internet Society or its successors or assigns.
|
||||
*
|
||||
* This document and the information contained herein is provided on an
|
||||
* "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
|
||||
* TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
|
||||
* HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _GSSAPI_GSSAPI_H_
|
||||
#define _GSSAPI_GSSAPI_H_
|
||||
|
||||
/*
|
||||
* First, include stddef.h to get size_t defined.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* Include stdint.h to get explicitly sized data types.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _SSIZE_T_DECLARED
|
||||
typedef __ssize_t ssize_t;
|
||||
#define _SSIZE_T_DECLARED
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* If the platform supports the xom.h header file, it should be
|
||||
* included here.
|
||||
*/
|
||||
#include <xom.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Now define the three implementation-dependent types.
|
||||
*/
|
||||
typedef struct _gss_ctx_id_t *gss_ctx_id_t;
|
||||
typedef struct _gss_cred_id_t *gss_cred_id_t;
|
||||
typedef struct _gss_name_t *gss_name_t;
|
||||
|
||||
/*
|
||||
* The following type must be defined as the smallest natural
|
||||
* unsigned integer supported by the platform that has at least
|
||||
* 32 bits of precision.
|
||||
*/
|
||||
typedef uint32_t gss_uint32;
|
||||
|
||||
|
||||
#ifdef OM_STRING
|
||||
/*
|
||||
* We have included the xom.h header file. Verify that OM_uint32
|
||||
* is defined correctly.
|
||||
*/
|
||||
|
||||
#if sizeof(gss_uint32) != sizeof(OM_uint32)
|
||||
#error Incompatible definition of OM_uint32 from xom.h
|
||||
#endif
|
||||
|
||||
typedef OM_object_identifier gss_OID_desc, *gss_OID;
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* We can't use X/Open definitions, so roll our own.
|
||||
*/
|
||||
|
||||
typedef gss_uint32 OM_uint32;
|
||||
typedef uint64_t OM_uint64;
|
||||
|
||||
typedef struct gss_OID_desc_struct {
|
||||
OM_uint32 length;
|
||||
void *elements;
|
||||
} gss_OID_desc, *gss_OID;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct gss_OID_set_desc_struct {
|
||||
size_t count;
|
||||
gss_OID elements;
|
||||
} gss_OID_set_desc, *gss_OID_set;
|
||||
|
||||
typedef struct gss_buffer_desc_struct {
|
||||
size_t length;
|
||||
void *value;
|
||||
} gss_buffer_desc, *gss_buffer_t;
|
||||
|
||||
typedef struct gss_channel_bindings_struct {
|
||||
OM_uint32 initiator_addrtype;
|
||||
gss_buffer_desc initiator_address;
|
||||
OM_uint32 acceptor_addrtype;
|
||||
gss_buffer_desc acceptor_address;
|
||||
gss_buffer_desc application_data;
|
||||
} *gss_channel_bindings_t;
|
||||
|
||||
/*
|
||||
* For now, define a QOP-type as an OM_uint32
|
||||
*/
|
||||
typedef OM_uint32 gss_qop_t;
|
||||
|
||||
typedef int gss_cred_usage_t;
|
||||
|
||||
/*
|
||||
* Flag bits for context-level services.
|
||||
*/
|
||||
#define GSS_C_DELEG_FLAG 1
|
||||
#define GSS_C_MUTUAL_FLAG 2
|
||||
#define GSS_C_REPLAY_FLAG 4
|
||||
#define GSS_C_SEQUENCE_FLAG 8
|
||||
#define GSS_C_CONF_FLAG 16
|
||||
#define GSS_C_INTEG_FLAG 32
|
||||
#define GSS_C_ANON_FLAG 64
|
||||
#define GSS_C_PROT_READY_FLAG 128
|
||||
#define GSS_C_TRANS_FLAG 256
|
||||
|
||||
/*
|
||||
* Credential usage options
|
||||
*/
|
||||
#define GSS_C_BOTH 0
|
||||
#define GSS_C_INITIATE 1
|
||||
#define GSS_C_ACCEPT 2
|
||||
|
||||
/*
|
||||
* Status code types for gss_display_status
|
||||
*/
|
||||
#define GSS_C_GSS_CODE 1
|
||||
#define GSS_C_MECH_CODE 2
|
||||
|
||||
/*
|
||||
* The constant definitions for channel-bindings address families
|
||||
*/
|
||||
#define GSS_C_AF_UNSPEC 0
|
||||
#define GSS_C_AF_LOCAL 1
|
||||
#define GSS_C_AF_INET 2
|
||||
#define GSS_C_AF_IMPLINK 3
|
||||
#define GSS_C_AF_PUP 4
|
||||
#define GSS_C_AF_CHAOS 5
|
||||
#define GSS_C_AF_NS 6
|
||||
#define GSS_C_AF_NBS 7
|
||||
#define GSS_C_AF_ECMA 8
|
||||
#define GSS_C_AF_DATAKIT 9
|
||||
#define GSS_C_AF_CCITT 10
|
||||
#define GSS_C_AF_SNA 11
|
||||
#define GSS_C_AF_DECnet 12
|
||||
#define GSS_C_AF_DLI 13
|
||||
#define GSS_C_AF_LAT 14
|
||||
#define GSS_C_AF_HYLINK 15
|
||||
#define GSS_C_AF_APPLETALK 16
|
||||
#define GSS_C_AF_BSC 17
|
||||
#define GSS_C_AF_DSS 18
|
||||
#define GSS_C_AF_OSI 19
|
||||
#define GSS_C_AF_X25 21
|
||||
#define GSS_C_AF_NULLADDR 255
|
||||
|
||||
/*
|
||||
* Various Null values
|
||||
*/
|
||||
#define GSS_C_NO_NAME ((gss_name_t) 0)
|
||||
#define GSS_C_NO_BUFFER ((gss_buffer_t) 0)
|
||||
#define GSS_C_NO_OID ((gss_OID) 0)
|
||||
#define GSS_C_NO_OID_SET ((gss_OID_set) 0)
|
||||
#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0)
|
||||
#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0)
|
||||
#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0)
|
||||
#define GSS_C_EMPTY_BUFFER {0, NULL}
|
||||
|
||||
/*
|
||||
* Some alternate names for a couple of the above
|
||||
* values. These are defined for V1 compatibility.
|
||||
*/
|
||||
#define GSS_C_NULL_OID GSS_C_NO_OID
|
||||
#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET
|
||||
|
||||
/*
|
||||
* Define the default Quality of Protection for per-message
|
||||
* services. Note that an implementation that offers multiple
|
||||
* levels of QOP may define GSS_C_QOP_DEFAULT to be either zero
|
||||
* (as done here) to mean "default protection", or to a specific
|
||||
* explicit QOP value. However, a value of 0 should always be
|
||||
* interpreted by a GSS-API implementation as a request for the
|
||||
* default protection level.
|
||||
*/
|
||||
#define GSS_C_QOP_DEFAULT 0
|
||||
|
||||
/*
|
||||
* Expiration time of 2^32-1 seconds means infinite lifetime for a
|
||||
* credential or security context
|
||||
*/
|
||||
#define GSS_C_INDEFINITE 0xfffffffful
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x01"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) user_name(1)}. The constant
|
||||
* GSS_C_NT_USER_NAME should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_USER_NAME;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x02"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) machine_uid_name(2)}.
|
||||
* The constant GSS_C_NT_MACHINE_UID_NAME should be
|
||||
* initialized to point to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_MACHINE_UID_NAME;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x03"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) string_uid_name(3)}.
|
||||
* The constant GSS_C_NT_STRING_UID_NAME should be
|
||||
* initialized to point to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_STRING_UID_NAME;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\x01\x05\x06\x02"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) org(3) dod(6) internet(1) security(5)
|
||||
* nametypes(6) gss-host-based-services(2)). The constant
|
||||
* GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point
|
||||
* to that gss_OID_desc. This is a deprecated OID value, and
|
||||
* implementations wishing to support hostbased-service names
|
||||
* should instead use the GSS_C_NT_HOSTBASED_SERVICE OID,
|
||||
* defined below, to identify such names;
|
||||
* GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym
|
||||
* for GSS_C_NT_HOSTBASED_SERVICE when presented as an input
|
||||
* parameter, but should not be emitted by GSS-API
|
||||
* implementations
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x04"}, corresponding to an
|
||||
* object-identifier value of {iso(1) member-body(2)
|
||||
* Unites States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) service_name(4)}. The constant
|
||||
* GSS_C_NT_HOSTBASED_SERVICE should be initialized
|
||||
* to point to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_HOSTBASED_SERVICE;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\01\x05\x06\x03"},
|
||||
* corresponding to an object identifier value of
|
||||
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
|
||||
* 6(nametypes), 3(gss-anonymous-name)}. The constant
|
||||
* and GSS_C_NT_ANONYMOUS should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_ANONYMOUS;
|
||||
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\x01\x05\x06\x04"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
|
||||
* 6(nametypes), 4(gss-api-exported-name)}. The constant
|
||||
* GSS_C_NT_EXPORT_NAME should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_EXPORT_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* krb5(2) krb5_name(1)}. The recommended symbolic name for this type
|
||||
* is "GSS_KRB5_NT_PRINCIPAL_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_PRINCIPAL_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) user_name(1)}. The recommended symbolic name for this
|
||||
* type is "GSS_KRB5_NT_USER_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_USER_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) machine_uid_name(2)}. The recommended symbolic name for
|
||||
* this type is "GSS_KRB5_NT_MACHINE_UID_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_MACHINE_UID_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) string_uid_name(3)}. The recommended symbolic name for
|
||||
* this type is "GSS_KRB5_NT_STRING_UID_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_STRING_UID_NAME;
|
||||
|
||||
/* Major status codes */
|
||||
|
||||
#define GSS_S_COMPLETE 0
|
||||
|
||||
/*
|
||||
* Some "helper" definitions to make the status code macros obvious.
|
||||
*/
|
||||
#define GSS_C_CALLING_ERROR_OFFSET 24
|
||||
#define GSS_C_ROUTINE_ERROR_OFFSET 16
|
||||
#define GSS_C_SUPPLEMENTARY_OFFSET 0
|
||||
#define GSS_C_CALLING_ERROR_MASK 0377ul
|
||||
#define GSS_C_ROUTINE_ERROR_MASK 0377ul
|
||||
#define GSS_C_SUPPLEMENTARY_MASK 0177777ul
|
||||
|
||||
/*
|
||||
* The macros that test status codes for error conditions.
|
||||
* Note that the GSS_ERROR() macro has changed slightly from
|
||||
* the V1 GSS-API so that it now evaluates its argument
|
||||
* only once.
|
||||
*/
|
||||
#define GSS_CALLING_ERROR(x) \
|
||||
(x & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET))
|
||||
#define GSS_ROUTINE_ERROR(x) \
|
||||
(x & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))
|
||||
#define GSS_SUPPLEMENTARY_INFO(x) \
|
||||
(x & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET))
|
||||
#define GSS_ERROR(x) \
|
||||
(x & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \
|
||||
(GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)))
|
||||
|
||||
/*
|
||||
* Now the actual status code definitions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calling errors:
|
||||
*/
|
||||
#define GSS_S_CALL_INACCESSIBLE_READ \
|
||||
(1ul << GSS_C_CALLING_ERROR_OFFSET)
|
||||
#define GSS_S_CALL_INACCESSIBLE_WRITE \
|
||||
(2ul << GSS_C_CALLING_ERROR_OFFSET)
|
||||
#define GSS_S_CALL_BAD_STRUCTURE \
|
||||
(3ul << GSS_C_CALLING_ERROR_OFFSET)
|
||||
|
||||
/*
|
||||
* Routine errors:
|
||||
*/
|
||||
#define GSS_S_BAD_MECH (1ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_NAME (2ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_NAMETYPE (3ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_BINDINGS (4ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_STATUS (5ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_SIG (6ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_MIC GSS_S_BAD_SIG
|
||||
#define GSS_S_NO_CRED (7ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_NO_CONTEXT (8ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_DEFECTIVE_TOKEN (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_DEFECTIVE_CREDENTIAL (10ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_CREDENTIALS_EXPIRED (11ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_CONTEXT_EXPIRED (12ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_FAILURE (13ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_QOP (14ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_UNAUTHORIZED (15ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_UNAVAILABLE (16ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_DUPLICATE_ELEMENT (17ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_NAME_NOT_MN (18ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
|
||||
/*
|
||||
* Supplementary info bits:
|
||||
*/
|
||||
#define GSS_S_CONTINUE_NEEDED \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 0))
|
||||
#define GSS_S_DUPLICATE_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 1))
|
||||
#define GSS_S_OLD_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 2))
|
||||
#define GSS_S_UNSEQ_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 3))
|
||||
#define GSS_S_GAP_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 4))
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Finally, function prototypes for the GSS-API routines.
|
||||
*/
|
||||
OM_uint32 gss_acquire_cred
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* desired_name */
|
||||
OM_uint32, /* time_req */
|
||||
const gss_OID_set, /* desired_mechs */
|
||||
gss_cred_usage_t, /* cred_usage */
|
||||
gss_cred_id_t *, /* output_cred_handle */
|
||||
gss_OID_set *, /* actual_mechs */
|
||||
OM_uint32 * /* time_rec */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_cred
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_cred_id_t * /* cred_handle */
|
||||
);
|
||||
|
||||
OM_uint32 gss_init_sec_context
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_cred_id_t, /* initiator_cred_handle */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
const gss_name_t, /* target_name */
|
||||
const gss_OID, /* mech_type */
|
||||
OM_uint32, /* req_flags */
|
||||
OM_uint32, /* time_req */
|
||||
const gss_channel_bindings_t,
|
||||
/* input_chan_bindings */
|
||||
const gss_buffer_t, /* input_token */
|
||||
gss_OID *, /* actual_mech_type */
|
||||
gss_buffer_t, /* output_token */
|
||||
OM_uint32 *, /* ret_flags */
|
||||
OM_uint32 * /* time_rec */
|
||||
);
|
||||
|
||||
OM_uint32 gss_accept_sec_context
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
const gss_cred_id_t, /* acceptor_cred_handle */
|
||||
const gss_buffer_t, /* input_token_buffer */
|
||||
const gss_channel_bindings_t,
|
||||
/* input_chan_bindings */
|
||||
gss_name_t *, /* src_name */
|
||||
gss_OID *, /* mech_type */
|
||||
gss_buffer_t, /* output_token */
|
||||
OM_uint32 *, /* ret_flags */
|
||||
OM_uint32 *, /* time_rec */
|
||||
gss_cred_id_t * /* delegated_cred_handle */
|
||||
);
|
||||
|
||||
OM_uint32 gss_process_context_token
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
const gss_buffer_t /* token_buffer */
|
||||
);
|
||||
|
||||
OM_uint32 gss_delete_sec_context
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
gss_buffer_t /* output_token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_context_time
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
OM_uint32 * /* time_rec */
|
||||
);
|
||||
|
||||
OM_uint32 gss_get_mic
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
gss_qop_t, /* qop_req */
|
||||
const gss_buffer_t, /* message_buffer */
|
||||
gss_buffer_t /* message_token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_verify_mic
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
const gss_buffer_t, /* message_buffer */
|
||||
const gss_buffer_t, /* token_buffer */
|
||||
gss_qop_t * /* qop_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_wrap
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
int, /* conf_req_flag */
|
||||
gss_qop_t, /* qop_req */
|
||||
const gss_buffer_t, /* input_message_buffer */
|
||||
int *, /* conf_state */
|
||||
gss_buffer_t /* output_message_buffer */
|
||||
);
|
||||
|
||||
OM_uint32 gss_unwrap
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
const gss_buffer_t, /* input_message_buffer */
|
||||
gss_buffer_t, /* output_message_buffer */
|
||||
int *, /* conf_state */
|
||||
gss_qop_t * /* qop_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_display_status
|
||||
(OM_uint32 *, /* minor_status */
|
||||
OM_uint32, /* status_value */
|
||||
int, /* status_type */
|
||||
const gss_OID, /* mech_type */
|
||||
OM_uint32 *, /* message_context */
|
||||
gss_buffer_t /* status_string */
|
||||
);
|
||||
|
||||
OM_uint32 gss_indicate_mechs
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_OID_set * /* mech_set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_compare_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* name1 */
|
||||
const gss_name_t, /* name2 */
|
||||
int * /* name_equal */
|
||||
);
|
||||
|
||||
OM_uint32 gss_display_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* input_name */
|
||||
gss_buffer_t, /* output_name_buffer */
|
||||
gss_OID * /* output_name_type */
|
||||
);
|
||||
|
||||
OM_uint32 gss_import_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_buffer_t, /* input_name_buffer */
|
||||
const gss_OID, /* input_name_type */
|
||||
gss_name_t * /* output_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_export_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* input_name */
|
||||
gss_buffer_t /* exported_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_name_t * /* input_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_buffer
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_buffer_t /* buffer */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_oid_set
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_OID_set * /* set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_cred
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_cred_id_t, /* cred_handle */
|
||||
gss_name_t *, /* name */
|
||||
OM_uint32 *, /* lifetime */
|
||||
gss_cred_usage_t *, /* cred_usage */
|
||||
gss_OID_set * /* mechanisms */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_context (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
gss_name_t *, /* src_name */
|
||||
gss_name_t *, /* targ_name */
|
||||
OM_uint32 *, /* lifetime_rec */
|
||||
gss_OID *, /* mech_type */
|
||||
OM_uint32 *, /* ctx_flags */
|
||||
int *, /* locally_initiated */
|
||||
int * /* open */
|
||||
);
|
||||
|
||||
OM_uint32 gss_wrap_size_limit (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
int, /* conf_req_flag */
|
||||
gss_qop_t, /* qop_req */
|
||||
OM_uint32, /* req_output_size */
|
||||
OM_uint32 * /* max_input_size */
|
||||
);
|
||||
|
||||
OM_uint32 gss_add_cred (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_cred_id_t, /* input_cred_handle */
|
||||
const gss_name_t, /* desired_name */
|
||||
const gss_OID, /* desired_mech */
|
||||
gss_cred_usage_t, /* cred_usage */
|
||||
OM_uint32, /* initiator_time_req */
|
||||
OM_uint32, /* acceptor_time_req */
|
||||
gss_cred_id_t *, /* output_cred_handle */
|
||||
gss_OID_set *, /* actual_mechs */
|
||||
OM_uint32 *, /* initiator_time_rec */
|
||||
OM_uint32 * /* acceptor_time_rec */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_cred_by_mech (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_cred_id_t, /* cred_handle */
|
||||
const gss_OID, /* mech_type */
|
||||
gss_name_t *, /* name */
|
||||
OM_uint32 *, /* initiator_lifetime */
|
||||
OM_uint32 *, /* acceptor_lifetime */
|
||||
gss_cred_usage_t * /* cred_usage */
|
||||
);
|
||||
|
||||
OM_uint32 gss_export_sec_context (
|
||||
OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
gss_buffer_t /* interprocess_token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_import_sec_context (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_buffer_t, /* interprocess_token */
|
||||
gss_ctx_id_t * /* context_handle */
|
||||
);
|
||||
|
||||
OM_uint32 gss_create_empty_oid_set (
|
||||
OM_uint32 *, /* minor_status */
|
||||
gss_OID_set * /* oid_set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_add_oid_set_member (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_OID, /* member_oid */
|
||||
gss_OID_set * /* oid_set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_test_oid_set_member (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_OID, /* member */
|
||||
const gss_OID_set, /* set */
|
||||
int * /* present */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_names_for_mech (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_OID, /* mechanism */
|
||||
gss_OID_set * /* name_types */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_mechs_for_name (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* input_name */
|
||||
gss_OID_set * /* mech_types */
|
||||
);
|
||||
|
||||
OM_uint32 gss_canonicalize_name (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* input_name */
|
||||
const gss_OID, /* mech_type */
|
||||
gss_name_t * /* output_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_duplicate_name (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* src_name */
|
||||
gss_name_t * /* dest_name */
|
||||
);
|
||||
|
||||
/*
|
||||
* The following routines are obsolete variants of gss_get_mic,
|
||||
* gss_verify_mic, gss_wrap and gss_unwrap. They should be
|
||||
* provided by GSS-API V2 implementations for backwards
|
||||
* compatibility with V1 applications. Distinct entrypoints
|
||||
* (as opposed to #defines) should be provided, both to allow
|
||||
* GSS-API V1 applications to link against GSS-API V2 implementations,
|
||||
* and to retain the slight parameter type differences between the
|
||||
* obsolete versions of these routines and their current forms.
|
||||
*/
|
||||
|
||||
OM_uint32 gss_sign
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t, /* context_handle */
|
||||
int, /* qop_req */
|
||||
gss_buffer_t, /* message_buffer */
|
||||
gss_buffer_t /* message_token */
|
||||
);
|
||||
|
||||
|
||||
OM_uint32 gss_verify
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t, /* context_handle */
|
||||
gss_buffer_t, /* message_buffer */
|
||||
gss_buffer_t, /* token_buffer */
|
||||
int * /* qop_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_seal
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t, /* context_handle */
|
||||
int, /* conf_req_flag */
|
||||
int, /* qop_req */
|
||||
gss_buffer_t, /* input_message_buffer */
|
||||
int *, /* conf_state */
|
||||
gss_buffer_t /* output_message_buffer */
|
||||
);
|
||||
|
||||
|
||||
OM_uint32 gss_unseal
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t, /* context_handle */
|
||||
gss_buffer_t, /* input_message_buffer */
|
||||
gss_buffer_t, /* output_message_buffer */
|
||||
int *, /* conf_state */
|
||||
int * /* qop_state */
|
||||
);
|
||||
|
||||
/*
|
||||
* Other extensions and helper functions.
|
||||
*/
|
||||
|
||||
int gss_oid_equal
|
||||
(const gss_OID, /* first OID to compare */
|
||||
const gss_OID /* second OID to compare */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_oid
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_OID * /* oid to free */
|
||||
);
|
||||
|
||||
OM_uint32 gss_decapsulate_token
|
||||
(const gss_buffer_t, /* mechanism independent token */
|
||||
gss_OID, /* desired mechanism */
|
||||
gss_buffer_t /* decapsulated mechanism dependant token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_encapsulate_token
|
||||
(const gss_buffer_t, /* mechanism dependant token */
|
||||
gss_OID, /* desired mechanism */
|
||||
gss_buffer_t /* encapsulated mechanism independent token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_duplicate_oid
|
||||
(OM_uint32 *, /* minor status */
|
||||
const gss_OID, /* oid to copy */
|
||||
gss_OID * /* result */
|
||||
);
|
||||
|
||||
OM_uint32 gss_oid_to_str
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_OID, /* oid to convert */
|
||||
gss_buffer_t /* buffer to contain string */
|
||||
);
|
||||
|
||||
typedef struct gss_buffer_set_desc_struct {
|
||||
size_t count;
|
||||
gss_buffer_desc *elements;
|
||||
} gss_buffer_set_desc, *gss_buffer_set_t;
|
||||
|
||||
#define GSS_C_NO_BUFFER_SET ((gss_buffer_set_t) 0)
|
||||
|
||||
OM_uint32 gss_create_empty_buffer_set
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_buffer_set_t * /* location for new buffer set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_add_buffer_set_member
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_buffer_t, /* buffer to add */
|
||||
gss_buffer_set_t * /* set to add to */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_buffer_set
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_buffer_set_t * /* set to release */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_sec_context_by_oid
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
const gss_OID, /* desired_object */
|
||||
gss_buffer_set_t * /* result */
|
||||
);
|
||||
|
||||
OM_uint32 gss_inquire_cred_by_oid
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_cred_id_t, /* cred_handle */
|
||||
const gss_OID, /* desired_object */
|
||||
gss_buffer_set_t * /* result */
|
||||
);
|
||||
|
||||
OM_uint32 gss_set_sec_context_option
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_ctx_id_t *, /* context */
|
||||
const gss_OID, /* option to set */
|
||||
const gss_buffer_t /* option value */
|
||||
);
|
||||
|
||||
OM_uint32 gss_set_cred_option
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_cred_id_t *, /* cred */
|
||||
const gss_OID, /* option to set */
|
||||
const gss_buffer_t /* option value */
|
||||
);
|
||||
|
||||
OM_uint32 gss_pseudo_random
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_ctx_id_t, /* context handle */
|
||||
int prf_key, /* XXX */
|
||||
const gss_buffer_t, /* data to seed generator */
|
||||
ssize_t, /* amount of data required */
|
||||
gss_buffer_t /* buffer for result */
|
||||
);
|
||||
|
||||
#ifdef _UID_T_DECLARED
|
||||
OM_uint32 gss_pname_to_uid
|
||||
(OM_uint32 *, /* minor status */
|
||||
const gss_name_t pname, /* principal name */
|
||||
const gss_OID mech, /* mechanism to query */
|
||||
uid_t *uidp /* pointer to UID for result */
|
||||
);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _GSSAPI_GSSAPI_H_ */
|
140
freebsd/include/rpc/auth_kerb.h
Normal file
140
freebsd/include/rpc/auth_kerb.h
Normal file
@ -0,0 +1,140 @@
|
||||
/* $FreeBSD$ */
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* auth_kerb.h, Protocol for Kerberos style authentication for RPC
|
||||
*
|
||||
* Copyright (C) 1986, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _RPC_AUTH_KERB_H
|
||||
#define _RPC_AUTH_KERB_H
|
||||
|
||||
#ifdef KERBEROS
|
||||
|
||||
#include <kerberos/krb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/t_kuser.h>
|
||||
#include <netinet/in.h>
|
||||
#include <rpc/svc.h>
|
||||
|
||||
/*
|
||||
* There are two kinds of "names": fullnames and nicknames
|
||||
*/
|
||||
enum authkerb_namekind {
|
||||
AKN_FULLNAME,
|
||||
AKN_NICKNAME
|
||||
};
|
||||
/*
|
||||
* A fullname contains the ticket and the window
|
||||
*/
|
||||
struct authkerb_fullname {
|
||||
KTEXT_ST ticket;
|
||||
u_long window; /* associated window */
|
||||
};
|
||||
|
||||
/*
|
||||
* cooked credential stored in rq_clntcred
|
||||
*/
|
||||
struct authkerb_clnt_cred {
|
||||
/* start of AUTH_DAT */
|
||||
unsigned char k_flags; /* Flags from ticket */
|
||||
char pname[ANAME_SZ]; /* Principal's name */
|
||||
char pinst[INST_SZ]; /* His Instance */
|
||||
char prealm[REALM_SZ]; /* His Realm */
|
||||
unsigned long checksum; /* Data checksum (opt) */
|
||||
C_Block session; /* Session Key */
|
||||
int life; /* Life of ticket */
|
||||
unsigned long time_sec; /* Time ticket issued */
|
||||
unsigned long address; /* Address in ticket */
|
||||
/* KTEXT_ST reply; Auth reply (opt) */
|
||||
/* end of AUTH_DAT */
|
||||
unsigned long expiry; /* time the ticket is expiring */
|
||||
u_long nickname; /* Nickname into cache */
|
||||
u_long window; /* associated window */
|
||||
};
|
||||
|
||||
typedef struct authkerb_clnt_cred authkerb_clnt_cred;
|
||||
|
||||
/*
|
||||
* A credential
|
||||
*/
|
||||
struct authkerb_cred {
|
||||
enum authkerb_namekind akc_namekind;
|
||||
struct authkerb_fullname akc_fullname;
|
||||
u_long akc_nickname;
|
||||
};
|
||||
|
||||
/*
|
||||
* A kerb authentication verifier
|
||||
*/
|
||||
struct authkerb_verf {
|
||||
union {
|
||||
struct timeval akv_ctime; /* clear time */
|
||||
des_block akv_xtime; /* crypt time */
|
||||
} akv_time_u;
|
||||
u_long akv_int_u;
|
||||
};
|
||||
|
||||
/*
|
||||
* des authentication verifier: client variety
|
||||
*
|
||||
* akv_timestamp is the current time.
|
||||
* akv_winverf is the credential window + 1.
|
||||
* Both are encrypted using the conversation key.
|
||||
*/
|
||||
#ifndef akv_timestamp
|
||||
#define akv_timestamp akv_time_u.akv_ctime
|
||||
#define akv_xtimestamp akv_time_u.akv_xtime
|
||||
#define akv_winverf akv_int_u
|
||||
#endif
|
||||
/*
|
||||
* des authentication verifier: server variety
|
||||
*
|
||||
* akv_timeverf is the client's timestamp + client's window
|
||||
* akv_nickname is the server's nickname for the client.
|
||||
* akv_timeverf is encrypted using the conversation key.
|
||||
*/
|
||||
#ifndef akv_timeverf
|
||||
#define akv_timeverf akv_time_u.akv_ctime
|
||||
#define akv_xtimeverf akv_time_u.akv_xtime
|
||||
#define akv_nickname akv_int_u
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Register the service name, instance and realm.
|
||||
*/
|
||||
extern int authkerb_create(char *, char *, char *, u_int,
|
||||
struct netbuf *, int *, dev_t, int, AUTH **);
|
||||
extern bool_t xdr_authkerb_cred(XDR *, struct authkerb_cred *);
|
||||
extern bool_t xdr_authkerb_verf(XDR *, struct authkerb_verf *);
|
||||
extern int svc_kerb_reg(SVCXPRT *, char *, char *, char *);
|
||||
extern enum auth_stat _svcauth_kerb(struct svc_req *, struct rpc_msg *);
|
||||
|
||||
#endif /* KERBEROS */
|
||||
#endif /* !_RPC_AUTH_KERB_H */
|
82
freebsd/include/rpc/des.h
Normal file
82
freebsd/include/rpc/des.h
Normal file
@ -0,0 +1,82 @@
|
||||
/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
|
||||
/* $FreeBSD$ */
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Generic DES driver interface
|
||||
* Keep this file hardware independent!
|
||||
* Copyright (c) 1986 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
|
||||
#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
|
||||
|
||||
enum desdir { ENCRYPT, DECRYPT };
|
||||
enum desmode { CBC, ECB };
|
||||
|
||||
/*
|
||||
* parameters to ioctl call
|
||||
*/
|
||||
struct desparams {
|
||||
u_char des_key[8]; /* key (with low bit parity) */
|
||||
enum desdir des_dir; /* direction */
|
||||
enum desmode des_mode; /* mode */
|
||||
u_char des_ivec[8]; /* input vector */
|
||||
unsigned des_len; /* number of bytes to crypt */
|
||||
union {
|
||||
u_char UDES_data[DES_QUICKLEN];
|
||||
u_char *UDES_buf;
|
||||
} UDES;
|
||||
# define des_data UDES.UDES_data /* direct data here if quick */
|
||||
# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
|
||||
};
|
||||
|
||||
#ifdef notdef
|
||||
|
||||
/*
|
||||
* These ioctls are only implemented in SunOS. Maybe someday
|
||||
* if somebody writes a driver for DES hardware that works
|
||||
* with FreeBSD, we can being that back.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Encrypt an arbitrary sized buffer
|
||||
*/
|
||||
#define DESIOCBLOCK _IOWR('d', 6, struct desparams)
|
||||
|
||||
/*
|
||||
* Encrypt of small amount of data, quickly
|
||||
*/
|
||||
#define DESIOCQUICK _IOWR('d', 7, struct desparams)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Software DES.
|
||||
*/
|
||||
extern int _des_crypt( char *, int, struct desparams * );
|
105
freebsd/include/rpc/des_crypt.h
Normal file
105
freebsd/include/rpc/des_crypt.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* @(#)des_crypt.h 2.1 88/08/11 4.0 RPCSRC; from 1.4 88/02/08 (C) 1986 SMI
|
||||
* $FreeBSD$
|
||||
*
|
||||
* des_crypt.h, des library routine interface
|
||||
* Copyright (C) 1986, Sun Microsystems, Inc.
|
||||
*/
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* des_crypt.h, des library routine interface
|
||||
*/
|
||||
|
||||
#ifndef _DES_DES_CRYPT_H
|
||||
#define _DES_DES_CRYPT_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#define DES_MAXDATA 8192 /* max bytes encrypted in one call */
|
||||
#define DES_DIRMASK (1 << 0)
|
||||
#define DES_ENCRYPT (0*DES_DIRMASK) /* Encrypt */
|
||||
#define DES_DECRYPT (1*DES_DIRMASK) /* Decrypt */
|
||||
|
||||
|
||||
#define DES_DEVMASK (1 << 1)
|
||||
#define DES_HW (0*DES_DEVMASK) /* Use hardware device */
|
||||
#define DES_SW (1*DES_DEVMASK) /* Use software device */
|
||||
|
||||
|
||||
#define DESERR_NONE 0 /* succeeded */
|
||||
#define DESERR_NOHWDEVICE 1 /* succeeded, but hw device not available */
|
||||
#define DESERR_HWERROR 2 /* failed, hardware/driver error */
|
||||
#define DESERR_BADPARAM 3 /* failed, bad parameter to call */
|
||||
|
||||
#define DES_FAILED(err) \
|
||||
((err) > DESERR_NOHWDEVICE)
|
||||
|
||||
/*
|
||||
* cbc_crypt()
|
||||
* ecb_crypt()
|
||||
*
|
||||
* Encrypt (or decrypt) len bytes of a buffer buf.
|
||||
* The length must be a multiple of eight.
|
||||
* The key should have odd parity in the low bit of each byte.
|
||||
* ivec is the input vector, and is updated to the new one (cbc only).
|
||||
* The mode is created by oring together the appropriate parameters.
|
||||
* DESERR_NOHWDEVICE is returned if DES_HW was specified but
|
||||
* there was no hardware to do it on (the data will still be
|
||||
* encrypted though, in software).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Cipher Block Chaining mode
|
||||
*/
|
||||
__BEGIN_DECLS
|
||||
int cbc_crypt( char *, char *, unsigned int, unsigned int, char *);
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
* Electronic Code Book mode
|
||||
*/
|
||||
__BEGIN_DECLS
|
||||
int ecb_crypt( char *, char *, unsigned int, unsigned int );
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
* Set des parity for a key.
|
||||
* DES parity is odd and in the low bit of each byte
|
||||
*/
|
||||
__BEGIN_DECLS
|
||||
void des_setparity( char *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _DES_DES_CRYPT_H */
|
263
freebsd/include/rpc/key_prot.h
Normal file
263
freebsd/include/rpc/key_prot.h
Normal file
@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _KEY_PROT_H_RPCGEN
|
||||
#define _KEY_PROT_H_RPCGEN
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
/* From: #pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI" */
|
||||
/* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Compiled from key_prot.x using rpcgen.
|
||||
* DO NOT EDIT THIS FILE!
|
||||
* This is NOT source code!
|
||||
*/
|
||||
#define PROOT 3
|
||||
#define HEXMODULUS "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b"
|
||||
#define HEXKEYBYTES 48
|
||||
#define KEYSIZE 192
|
||||
#define KEYBYTES 24
|
||||
#define KEYCHECKSUMSIZE 16
|
||||
|
||||
enum keystatus {
|
||||
KEY_SUCCESS = 0,
|
||||
KEY_NOSECRET = 1,
|
||||
KEY_UNKNOWN = 2,
|
||||
KEY_SYSTEMERR = 3,
|
||||
};
|
||||
typedef enum keystatus keystatus;
|
||||
|
||||
typedef char keybuf[HEXKEYBYTES];
|
||||
|
||||
typedef char *netnamestr;
|
||||
|
||||
struct cryptkeyarg {
|
||||
netnamestr remotename;
|
||||
des_block deskey;
|
||||
};
|
||||
typedef struct cryptkeyarg cryptkeyarg;
|
||||
|
||||
struct cryptkeyarg2 {
|
||||
netnamestr remotename;
|
||||
netobj remotekey;
|
||||
des_block deskey;
|
||||
};
|
||||
typedef struct cryptkeyarg2 cryptkeyarg2;
|
||||
|
||||
struct cryptkeyres {
|
||||
keystatus status;
|
||||
union {
|
||||
des_block deskey;
|
||||
} cryptkeyres_u;
|
||||
};
|
||||
typedef struct cryptkeyres cryptkeyres;
|
||||
#define MAXGIDS 16
|
||||
|
||||
struct unixcred {
|
||||
u_int uid;
|
||||
u_int gid;
|
||||
struct {
|
||||
u_int gids_len;
|
||||
u_int *gids_val;
|
||||
} gids;
|
||||
};
|
||||
typedef struct unixcred unixcred;
|
||||
|
||||
struct getcredres {
|
||||
keystatus status;
|
||||
union {
|
||||
unixcred cred;
|
||||
} getcredres_u;
|
||||
};
|
||||
typedef struct getcredres getcredres;
|
||||
|
||||
struct key_netstarg {
|
||||
keybuf st_priv_key;
|
||||
keybuf st_pub_key;
|
||||
netnamestr st_netname;
|
||||
};
|
||||
typedef struct key_netstarg key_netstarg;
|
||||
|
||||
struct key_netstres {
|
||||
keystatus status;
|
||||
union {
|
||||
key_netstarg knet;
|
||||
} key_netstres_u;
|
||||
};
|
||||
typedef struct key_netstres key_netstres;
|
||||
|
||||
#ifndef opaque
|
||||
#define opaque char
|
||||
#endif
|
||||
|
||||
|
||||
#define KEY_PROG 100029
|
||||
#define KEY_VERS 1
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define KEY_SET 1
|
||||
extern keystatus * key_set_1(char *, CLIENT *);
|
||||
extern keystatus * key_set_1_svc(char *, struct svc_req *);
|
||||
#define KEY_ENCRYPT 2
|
||||
extern cryptkeyres * key_encrypt_1(cryptkeyarg *, CLIENT *);
|
||||
extern cryptkeyres * key_encrypt_1_svc(cryptkeyarg *, struct svc_req *);
|
||||
#define KEY_DECRYPT 3
|
||||
extern cryptkeyres * key_decrypt_1(cryptkeyarg *, CLIENT *);
|
||||
extern cryptkeyres * key_decrypt_1_svc(cryptkeyarg *, struct svc_req *);
|
||||
#define KEY_GEN 4
|
||||
extern des_block * key_gen_1(void *, CLIENT *);
|
||||
extern des_block * key_gen_1_svc(void *, struct svc_req *);
|
||||
#define KEY_GETCRED 5
|
||||
extern getcredres * key_getcred_1(netnamestr *, CLIENT *);
|
||||
extern getcredres * key_getcred_1_svc(netnamestr *, struct svc_req *);
|
||||
extern int key_prog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
|
||||
|
||||
#else /* K&R C */
|
||||
#define KEY_SET 1
|
||||
extern keystatus * key_set_1();
|
||||
extern keystatus * key_set_1_svc();
|
||||
#define KEY_ENCRYPT 2
|
||||
extern cryptkeyres * key_encrypt_1();
|
||||
extern cryptkeyres * key_encrypt_1_svc();
|
||||
#define KEY_DECRYPT 3
|
||||
extern cryptkeyres * key_decrypt_1();
|
||||
extern cryptkeyres * key_decrypt_1_svc();
|
||||
#define KEY_GEN 4
|
||||
extern des_block * key_gen_1();
|
||||
extern des_block * key_gen_1_svc();
|
||||
#define KEY_GETCRED 5
|
||||
extern getcredres * key_getcred_1();
|
||||
extern getcredres * key_getcred_1_svc();
|
||||
extern int key_prog_1_freeresult ();
|
||||
#endif /* K&R C */
|
||||
#define KEY_VERS2 2
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
extern keystatus * key_set_2(char *, CLIENT *);
|
||||
extern keystatus * key_set_2_svc(char *, struct svc_req *);
|
||||
extern cryptkeyres * key_encrypt_2(cryptkeyarg *, CLIENT *);
|
||||
extern cryptkeyres * key_encrypt_2_svc(cryptkeyarg *, struct svc_req *);
|
||||
extern cryptkeyres * key_decrypt_2(cryptkeyarg *, CLIENT *);
|
||||
extern cryptkeyres * key_decrypt_2_svc(cryptkeyarg *, struct svc_req *);
|
||||
extern des_block * key_gen_2(void *, CLIENT *);
|
||||
extern des_block * key_gen_2_svc(void *, struct svc_req *);
|
||||
extern getcredres * key_getcred_2(netnamestr *, CLIENT *);
|
||||
extern getcredres * key_getcred_2_svc(netnamestr *, struct svc_req *);
|
||||
#define KEY_ENCRYPT_PK 6
|
||||
extern cryptkeyres * key_encrypt_pk_2(cryptkeyarg2 *, CLIENT *);
|
||||
extern cryptkeyres * key_encrypt_pk_2_svc(cryptkeyarg2 *, struct svc_req *);
|
||||
#define KEY_DECRYPT_PK 7
|
||||
extern cryptkeyres * key_decrypt_pk_2(cryptkeyarg2 *, CLIENT *);
|
||||
extern cryptkeyres * key_decrypt_pk_2_svc(cryptkeyarg2 *, struct svc_req *);
|
||||
#define KEY_NET_PUT 8
|
||||
extern keystatus * key_net_put_2(key_netstarg *, CLIENT *);
|
||||
extern keystatus * key_net_put_2_svc(key_netstarg *, struct svc_req *);
|
||||
#define KEY_NET_GET 9
|
||||
extern key_netstres * key_net_get_2(void *, CLIENT *);
|
||||
extern key_netstres * key_net_get_2_svc(void *, struct svc_req *);
|
||||
#define KEY_GET_CONV 10
|
||||
extern cryptkeyres * key_get_conv_2(char *, CLIENT *);
|
||||
extern cryptkeyres * key_get_conv_2_svc(char *, struct svc_req *);
|
||||
extern int key_prog_2_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
|
||||
|
||||
#else /* K&R C */
|
||||
extern keystatus * key_set_2();
|
||||
extern keystatus * key_set_2_svc();
|
||||
extern cryptkeyres * key_encrypt_2();
|
||||
extern cryptkeyres * key_encrypt_2_svc();
|
||||
extern cryptkeyres * key_decrypt_2();
|
||||
extern cryptkeyres * key_decrypt_2_svc();
|
||||
extern des_block * key_gen_2();
|
||||
extern des_block * key_gen_2_svc();
|
||||
extern getcredres * key_getcred_2();
|
||||
extern getcredres * key_getcred_2_svc();
|
||||
#define KEY_ENCRYPT_PK 6
|
||||
extern cryptkeyres * key_encrypt_pk_2();
|
||||
extern cryptkeyres * key_encrypt_pk_2_svc();
|
||||
#define KEY_DECRYPT_PK 7
|
||||
extern cryptkeyres * key_decrypt_pk_2();
|
||||
extern cryptkeyres * key_decrypt_pk_2_svc();
|
||||
#define KEY_NET_PUT 8
|
||||
extern keystatus * key_net_put_2();
|
||||
extern keystatus * key_net_put_2_svc();
|
||||
#define KEY_NET_GET 9
|
||||
extern key_netstres * key_net_get_2();
|
||||
extern key_netstres * key_net_get_2_svc();
|
||||
#define KEY_GET_CONV 10
|
||||
extern cryptkeyres * key_get_conv_2();
|
||||
extern cryptkeyres * key_get_conv_2_svc();
|
||||
extern int key_prog_2_freeresult ();
|
||||
#endif /* K&R C */
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
extern bool_t xdr_keystatus (XDR *, keystatus*);
|
||||
extern bool_t xdr_keybuf (XDR *, keybuf);
|
||||
extern bool_t xdr_netnamestr (XDR *, netnamestr*);
|
||||
extern bool_t xdr_cryptkeyarg (XDR *, cryptkeyarg*);
|
||||
extern bool_t xdr_cryptkeyarg2 (XDR *, cryptkeyarg2*);
|
||||
extern bool_t xdr_cryptkeyres (XDR *, cryptkeyres*);
|
||||
extern bool_t xdr_unixcred (XDR *, unixcred*);
|
||||
extern bool_t xdr_getcredres (XDR *, getcredres*);
|
||||
extern bool_t xdr_key_netstarg (XDR *, key_netstarg*);
|
||||
extern bool_t xdr_key_netstres (XDR *, key_netstres*);
|
||||
|
||||
#else /* K&R C */
|
||||
extern bool_t xdr_keystatus ();
|
||||
extern bool_t xdr_keybuf ();
|
||||
extern bool_t xdr_netnamestr ();
|
||||
extern bool_t xdr_cryptkeyarg ();
|
||||
extern bool_t xdr_cryptkeyarg2 ();
|
||||
extern bool_t xdr_cryptkeyres ();
|
||||
extern bool_t xdr_unixcred ();
|
||||
extern bool_t xdr_getcredres ();
|
||||
extern bool_t xdr_key_netstarg ();
|
||||
extern bool_t xdr_key_netstres ();
|
||||
|
||||
#endif /* K&R C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_KEY_PROT_H_RPCGEN */
|
63
freebsd/include/rpc/nettype.h
Normal file
63
freebsd/include/rpc/nettype.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* $NetBSD: nettype.h,v 1.2 2000/07/06 03:17:19 christos Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* nettype.h, Nettype definitions.
|
||||
* All for the topmost layer of rpc
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RPC_NETTYPE_H
|
||||
#define _RPC_NETTYPE_H
|
||||
|
||||
#include <netconfig.h>
|
||||
|
||||
#define _RPC_NONE 0
|
||||
#define _RPC_NETPATH 1
|
||||
#define _RPC_VISIBLE 2
|
||||
#define _RPC_CIRCUIT_V 3
|
||||
#define _RPC_DATAGRAM_V 4
|
||||
#define _RPC_CIRCUIT_N 5
|
||||
#define _RPC_DATAGRAM_N 6
|
||||
#define _RPC_TCP 7
|
||||
#define _RPC_UDP 8
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern void *__rpc_setconf(const char *);
|
||||
extern void __rpc_endconf(void *);
|
||||
extern struct netconfig *__rpc_getconf(void *);
|
||||
extern struct netconfig *__rpc_getconfip(const char *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RPC_NETTYPE_H */
|
64
freebsd/include/rpc/pmap_rmt.h
Normal file
64
freebsd/include/rpc/pmap_rmt.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* $NetBSD: pmap_rmt.h,v 1.7 1998/02/11 23:01:23 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)pmap_rmt.h 1.2 88/02/08 SMI
|
||||
* from: @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Structures and XDR routines for parameters to and replies from
|
||||
* the portmapper remote-call-service.
|
||||
*
|
||||
* Copyright (C) 1986, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _RPC_PMAP_RMT_H
|
||||
#define _RPC_PMAP_RMT_H
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
struct rmtcallargs {
|
||||
u_long prog, vers, proc, arglen;
|
||||
caddr_t args_ptr;
|
||||
xdrproc_t xdr_args;
|
||||
};
|
||||
|
||||
struct rmtcallres {
|
||||
u_long *port_ptr;
|
||||
u_long resultslen;
|
||||
caddr_t results_ptr;
|
||||
xdrproc_t xdr_results;
|
||||
};
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern bool_t xdr_rmtcall_args(XDR *, struct rmtcallargs *);
|
||||
extern bool_t xdr_rmtcallres(XDR *, struct rmtcallres *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RPC_PMAP_RMT_H */
|
57
freebsd/include/rpc/raw.h
Normal file
57
freebsd/include/rpc/raw.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* $NetBSD: raw.h,v 1.1 2000/06/02 22:57:56 fvdl Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _RPC_RAW_H
|
||||
#define _RPC_RAW_H
|
||||
|
||||
/* from: @(#)raw.h 1.11 94/04/25 SMI */
|
||||
/* from: @(#)raw.h 1.2 88/10/25 SMI */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* raw.h
|
||||
*
|
||||
* Raw interface
|
||||
* The common memory area over which they will communicate
|
||||
*/
|
||||
extern char *__rpc_rawcombuf;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RPC_RAW_H */
|
82
freebsd/include/rpc/rpc_com.h
Normal file
82
freebsd/include/rpc/rpc_com.h
Normal file
@ -0,0 +1,82 @@
|
||||
/* $NetBSD: rpc_com.h,v 1.3 2000/12/10 04:10:08 christos Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* rpc_com.h, Common definitions for both the server and client side.
|
||||
* All for the topmost layer of rpc
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RPC_RPCCOM_H
|
||||
#define _RPC_RPCCOM_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/* #pragma ident "@(#)rpc_com.h 1.11 93/07/05 SMI" */
|
||||
|
||||
/*
|
||||
* The max size of the transport, if the size cannot be determined
|
||||
* by other means.
|
||||
*/
|
||||
#define RPC_MAXDATASIZE 9000
|
||||
#define RPC_MAXADDRSIZE 1024
|
||||
|
||||
#define __RPC_GETXID(now) ((u_int32_t)getpid() ^ (u_int32_t)(now)->tv_sec ^ \
|
||||
(u_int32_t)(now)->tv_usec)
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern u_int __rpc_get_a_size(int);
|
||||
extern int __rpc_dtbsize(void);
|
||||
extern int _rpc_dtablesize(void);
|
||||
extern struct netconfig * __rpcgettp(int);
|
||||
extern int __rpc_get_default_domain(char **);
|
||||
|
||||
char *__rpc_taddr2uaddr_af(int, const struct netbuf *);
|
||||
struct netbuf *__rpc_uaddr2taddr_af(int, const char *);
|
||||
int __rpc_fixup_addr(struct netbuf *, const struct netbuf *);
|
||||
int __rpc_sockinfo2netid(struct __rpc_sockinfo *, const char **);
|
||||
int __rpc_seman2socktype(int);
|
||||
int __rpc_socktype2seman(int);
|
||||
void *rpc_nullproc(CLIENT *);
|
||||
int __rpc_sockisbound(int);
|
||||
|
||||
struct netbuf *__rpcb_findaddr(rpcprog_t, rpcvers_t, const struct netconfig *,
|
||||
const char *, CLIENT **);
|
||||
bool_t rpc_control(int,void *);
|
||||
|
||||
char *_get_next_token(char *, int);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _RPC_RPCCOM_H */
|
179
freebsd/include/rpc/rpcsec_gss.h
Normal file
179
freebsd/include/rpc/rpcsec_gss.h
Normal file
@ -0,0 +1,179 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Doug Rabson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _RPCSEC_GSS_H
|
||||
#define _RPCSEC_GSS_H
|
||||
|
||||
#include <gssapi/gssapi.h>
|
||||
|
||||
#ifndef MAX_GSS_MECH
|
||||
#define MAX_GSS_MECH 64
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define the types of security service required for rpc_gss_seccreate().
|
||||
*/
|
||||
typedef enum {
|
||||
rpc_gss_svc_default = 0,
|
||||
rpc_gss_svc_none = 1,
|
||||
rpc_gss_svc_integrity = 2,
|
||||
rpc_gss_svc_privacy = 3
|
||||
} rpc_gss_service_t;
|
||||
|
||||
/*
|
||||
* Structure containing options for rpc_gss_seccreate().
|
||||
*/
|
||||
typedef struct {
|
||||
int req_flags; /* GSS request bits */
|
||||
int time_req; /* requested credential lifetime */
|
||||
gss_cred_id_t my_cred; /* GSS credential */
|
||||
gss_channel_bindings_t input_channel_bindings;
|
||||
} rpc_gss_options_req_t;
|
||||
|
||||
/*
|
||||
* Structure containing options returned by rpc_gss_seccreate().
|
||||
*/
|
||||
typedef struct {
|
||||
int major_status;
|
||||
int minor_status;
|
||||
u_int rpcsec_version;
|
||||
int ret_flags;
|
||||
int time_req;
|
||||
gss_ctx_id_t gss_context;
|
||||
char actual_mechanism[MAX_GSS_MECH];
|
||||
} rpc_gss_options_ret_t;
|
||||
|
||||
/*
|
||||
* Client principal type. Used as an argument to
|
||||
* rpc_gss_get_principal_name(). Also referenced by the
|
||||
* rpc_gss_rawcred_t structure.
|
||||
*/
|
||||
typedef struct {
|
||||
int len;
|
||||
char name[1];
|
||||
} *rpc_gss_principal_t;
|
||||
|
||||
/*
|
||||
* Structure for raw credentials used by rpc_gss_getcred() and
|
||||
* rpc_gss_set_callback().
|
||||
*/
|
||||
typedef struct {
|
||||
u_int version; /* RPC version number */
|
||||
const char *mechanism; /* security mechanism */
|
||||
const char *qop; /* quality of protection */
|
||||
rpc_gss_principal_t client_principal; /* client name */
|
||||
const char *svc_principal; /* server name */
|
||||
rpc_gss_service_t service; /* service type */
|
||||
} rpc_gss_rawcred_t;
|
||||
|
||||
/*
|
||||
* Unix credentials derived from raw credentials. Returned by
|
||||
* rpc_gss_getcred().
|
||||
*/
|
||||
typedef struct {
|
||||
uid_t uid; /* user ID */
|
||||
gid_t gid; /* group ID */
|
||||
short gidlen;
|
||||
gid_t *gidlist; /* list of groups */
|
||||
} rpc_gss_ucred_t;
|
||||
|
||||
/*
|
||||
* Structure used to enforce a particular QOP and service.
|
||||
*/
|
||||
typedef struct {
|
||||
bool_t locked;
|
||||
rpc_gss_rawcred_t *raw_cred;
|
||||
} rpc_gss_lock_t;
|
||||
|
||||
/*
|
||||
* Callback structure used by rpc_gss_set_callback().
|
||||
*/
|
||||
typedef struct {
|
||||
u_int program; /* RPC program number */
|
||||
u_int version; /* RPC version number */
|
||||
/* user defined callback */
|
||||
bool_t (*callback)(struct svc_req *req,
|
||||
gss_cred_id_t deleg,
|
||||
gss_ctx_id_t gss_context,
|
||||
rpc_gss_lock_t *lock,
|
||||
void **cookie);
|
||||
} rpc_gss_callback_t;
|
||||
|
||||
/*
|
||||
* Structure used to return error information by rpc_gss_get_error()
|
||||
*/
|
||||
typedef struct {
|
||||
int rpc_gss_error;
|
||||
int system_error; /* same as errno */
|
||||
} rpc_gss_error_t;
|
||||
|
||||
/*
|
||||
* Values for rpc_gss_error
|
||||
*/
|
||||
#define RPC_GSS_ER_SUCCESS 0 /* no error */
|
||||
#define RPC_GSS_ER_SYSTEMERROR 1 /* system error */
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
AUTH *rpc_gss_seccreate(CLIENT *clnt, const char *principal,
|
||||
const char *mechanism, rpc_gss_service_t service, const char *qop,
|
||||
rpc_gss_options_req_t *options_req, rpc_gss_options_ret_t *options_ret);
|
||||
bool_t rpc_gss_set_defaults(AUTH *auth, rpc_gss_service_t service,
|
||||
const char *qop);
|
||||
int rpc_gss_max_data_length(AUTH *handle, int max_tp_unit_len);
|
||||
void rpc_gss_get_error(rpc_gss_error_t *error);
|
||||
|
||||
bool_t rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret);
|
||||
bool_t rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret);
|
||||
bool_t rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret);
|
||||
const char **rpc_gss_get_mechanisms(void);
|
||||
const char **rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service);
|
||||
bool_t rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo);
|
||||
bool_t rpc_gss_is_installed(const char *mech);
|
||||
|
||||
bool_t rpc_gss_set_svc_name(const char *principal, const char *mechanism,
|
||||
u_int req_time, u_int program, u_int version);
|
||||
bool_t rpc_gss_getcred(struct svc_req *req, rpc_gss_rawcred_t **rcred,
|
||||
rpc_gss_ucred_t **ucred, void **cookie);
|
||||
bool_t rpc_gss_set_callback(rpc_gss_callback_t *cb);
|
||||
bool_t rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
|
||||
const char *mech, const char *name, const char *node, const char *domain);
|
||||
int rpc_gss_svc_max_data_length(struct svc_req *req, int max_tp_unit_len);
|
||||
|
||||
/*
|
||||
* Internal interface from the RPC implementation.
|
||||
*/
|
||||
bool_t __rpc_gss_wrap(AUTH *auth, void *header, size_t headerlen,
|
||||
XDR* xdrs, xdrproc_t xdr_args, void *args_ptr);
|
||||
bool_t __rpc_gss_unwrap(AUTH *auth, XDR* xdrs, xdrproc_t xdr_args,
|
||||
void *args_ptr);
|
||||
bool_t __rpc_gss_set_error(int rpc_gss_error, int system_error);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RPCSEC_GSS_H */
|
50
freebsd/include/rpc/svc_dg.h
Normal file
50
freebsd/include/rpc/svc_dg.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* $NetBSD: svc_dg.h,v 1.1 2000/06/02 23:11:16 fvdl Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* XXX - this file exists only so that the rpcbind code can pull it in.
|
||||
* This should go away. It should only be include by svc_dg.c and
|
||||
* rpcb_svc_com.c in the rpcbind code.
|
||||
*/
|
||||
|
||||
/*
|
||||
* kept in xprt->xp_p2
|
||||
*/
|
||||
struct svc_dg_data {
|
||||
/* XXX: optbuf should be the first field, used by ti_opts.c code */
|
||||
size_t su_iosz; /* size of send.recv buffer */
|
||||
u_int32_t su_xid; /* transaction id */
|
||||
XDR su_xdrs; /* XDR handle */
|
||||
char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
|
||||
void *su_cache; /* cached data, NULL if none */
|
||||
struct netbuf su_srcaddr; /* dst address of last msg */
|
||||
};
|
||||
|
||||
#define __rpcb_get_dg_xidp(x) (&((struct svc_dg_data *)(x)->xp_p2)->su_xid)
|
102
freebsd/include/rpcsvc/bootparam_prot.x
Normal file
102
freebsd/include/rpcsvc/bootparam_prot.x
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* RPC for bootparms service.
|
||||
* There are two procedures:
|
||||
* WHOAMI takes a net address and returns a client name and also a
|
||||
* likely net address for routing
|
||||
* GETFILE takes a client name and file identifier and returns the
|
||||
* server name, server net address and pathname for the file.
|
||||
* file identifiers typically include root, swap, pub and dump
|
||||
*/
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%#include <rpc/types.h>
|
||||
%#include <sys/time.h>
|
||||
%#include <sys/errno.h>
|
||||
%#include <sys/param.h>
|
||||
%#include <sys/syslimits.h>
|
||||
#else
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)bootparam_prot.x 1.2 87/06/24 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)bootparam_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const MAX_MACHINE_NAME = 255;
|
||||
const MAX_PATH_LEN = 1024;
|
||||
const MAX_FILEID = 32;
|
||||
const IP_ADDR_TYPE = 1;
|
||||
|
||||
typedef string bp_machine_name_t<MAX_MACHINE_NAME>;
|
||||
typedef string bp_path_t<MAX_PATH_LEN>;
|
||||
typedef string bp_fileid_t<MAX_FILEID>;
|
||||
|
||||
struct ip_addr_t {
|
||||
char net;
|
||||
char host;
|
||||
char lh;
|
||||
char impno;
|
||||
};
|
||||
|
||||
union bp_address switch (int address_type) {
|
||||
case IP_ADDR_TYPE:
|
||||
ip_addr_t ip_addr;
|
||||
};
|
||||
|
||||
struct bp_whoami_arg {
|
||||
bp_address client_address;
|
||||
};
|
||||
|
||||
struct bp_whoami_res {
|
||||
bp_machine_name_t client_name;
|
||||
bp_machine_name_t domain_name;
|
||||
bp_address router_address;
|
||||
};
|
||||
|
||||
struct bp_getfile_arg {
|
||||
bp_machine_name_t client_name;
|
||||
bp_fileid_t file_id;
|
||||
};
|
||||
|
||||
struct bp_getfile_res {
|
||||
bp_machine_name_t server_name;
|
||||
bp_address server_address;
|
||||
bp_path_t server_path;
|
||||
};
|
||||
|
||||
program BOOTPARAMPROG {
|
||||
version BOOTPARAMVERS {
|
||||
bp_whoami_res BOOTPARAMPROC_WHOAMI(bp_whoami_arg) = 1;
|
||||
bp_getfile_res BOOTPARAMPROC_GETFILE(bp_getfile_arg) = 2;
|
||||
} = 1;
|
||||
} = 100026;
|
87
freebsd/include/rpcsvc/crypt.h
Normal file
87
freebsd/include/rpcsvc/crypt.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _CRYPT_H_RPCGEN
|
||||
#define _CRYPT_H_RPCGEN
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
enum des_dir {
|
||||
ENCRYPT_DES = 0,
|
||||
DECRYPT_DES = 1,
|
||||
};
|
||||
typedef enum des_dir des_dir;
|
||||
|
||||
enum des_mode {
|
||||
CBC_DES = 0,
|
||||
ECB_DES = 1,
|
||||
};
|
||||
typedef enum des_mode des_mode;
|
||||
|
||||
struct desargs {
|
||||
u_char des_key[8];
|
||||
des_dir des_dir;
|
||||
des_mode des_mode;
|
||||
u_char des_ivec[8];
|
||||
struct {
|
||||
u_int desbuf_len;
|
||||
char *desbuf_val;
|
||||
} desbuf;
|
||||
};
|
||||
typedef struct desargs desargs;
|
||||
|
||||
struct desresp {
|
||||
struct {
|
||||
u_int desbuf_len;
|
||||
char *desbuf_val;
|
||||
} desbuf;
|
||||
u_char des_ivec[8];
|
||||
int stat;
|
||||
};
|
||||
typedef struct desresp desresp;
|
||||
|
||||
#define CRYPT_PROG 600100029
|
||||
#define CRYPT_VERS 1
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define DES_CRYPT 1
|
||||
extern desresp * des_crypt_1(desargs *, CLIENT *);
|
||||
extern desresp * des_crypt_1_svc(desargs *, struct svc_req *);
|
||||
extern int crypt_prog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
|
||||
|
||||
#else /* K&R C */
|
||||
#define DES_CRYPT 1
|
||||
extern desresp * des_crypt_1();
|
||||
extern desresp * des_crypt_1_svc();
|
||||
extern int crypt_prog_1_freeresult ();
|
||||
#endif /* K&R C */
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
extern bool_t xdr_des_dir (XDR *, des_dir*);
|
||||
extern bool_t xdr_des_mode (XDR *, des_mode*);
|
||||
extern bool_t xdr_desargs (XDR *, desargs*);
|
||||
extern bool_t xdr_desresp (XDR *, desresp*);
|
||||
|
||||
#else /* K&R C */
|
||||
extern bool_t xdr_des_dir ();
|
||||
extern bool_t xdr_des_mode ();
|
||||
extern bool_t xdr_desargs ();
|
||||
extern bool_t xdr_desresp ();
|
||||
|
||||
#endif /* K&R C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_CRYPT_H_RPCGEN */
|
87
freebsd/include/rpcsvc/crypt.x
Normal file
87
freebsd/include/rpcsvc/crypt.x
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Bill Paul.
|
||||
* 4. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This protocol definition exists because of the U.S. government and
|
||||
* its stupid export laws. We can't export DES code from the United
|
||||
* States to other countries (even though the code already exists
|
||||
* outside the U.S. -- go figure that one out) but we need to make
|
||||
* Secure RPC work. The normal way around this is to break the DES
|
||||
* code out into a shared library; we can then provide a dummy lib
|
||||
* in the base OS and provide the real lib in the secure dist, which
|
||||
* the user can install later. But we need Secure RPC for NIS+, and
|
||||
* there are several system programs that use NIS+ which are statically
|
||||
* linked. We would have to provide replacements for these programs
|
||||
* in the secure dist, but there are a lot, and this is a pain. The
|
||||
* shared lib trick won't work for these programs, and we can't change
|
||||
* them once they're compiled.
|
||||
*
|
||||
* One solution for this problem is to do the DES encryption as a system
|
||||
* call; no programs need to be changed and we can even supply the DES
|
||||
* support as an LKM. But this bloats the kernel. Maybe if we have
|
||||
* Secure NFS one day this will be worth it, but for now we should keep
|
||||
* this mess in user space.
|
||||
*
|
||||
* So we have this second solution: we provide a server that does the
|
||||
* DES encryption for us. In this case, the server is keyserv (we need
|
||||
* it to make Secure RPC work anyway) and we use this protocol to ship
|
||||
* the data back and forth between keyserv and the application.
|
||||
*/
|
||||
|
||||
enum des_dir { ENCRYPT_DES, DECRYPT_DES };
|
||||
enum des_mode { CBC_DES, ECB_DES };
|
||||
|
||||
struct desargs {
|
||||
u_char des_key[8]; /* key (with low bit parity) */
|
||||
des_dir des_dir; /* direction */
|
||||
des_mode des_mode; /* mode */
|
||||
u_char des_ivec[8]; /* input vector */
|
||||
opaque desbuf<>;
|
||||
};
|
||||
|
||||
struct desresp {
|
||||
opaque desbuf<>;
|
||||
u_char des_ivec[8];
|
||||
int stat;
|
||||
};
|
||||
|
||||
program CRYPT_PROG {
|
||||
version CRYPT_VERS {
|
||||
desresp
|
||||
DES_CRYPT(desargs) = 1;
|
||||
} = 1;
|
||||
} = 600100029;
|
285
freebsd/include/rpcsvc/key_prot.x
Normal file
285
freebsd/include/rpcsvc/key_prot.x
Normal file
@ -0,0 +1,285 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
/*
|
||||
* Key server protocol definition
|
||||
* Copyright (C) 1990, 1991 Sun Microsystems, Inc.
|
||||
*
|
||||
* The keyserver is a public key storage/encryption/decryption service
|
||||
* The encryption method used is based on the Diffie-Hellman exponential
|
||||
* key exchange technology.
|
||||
*
|
||||
* The key server is local to each machine, akin to the portmapper.
|
||||
* Under TI-RPC, communication with the keyserver is through the
|
||||
* loopback transport.
|
||||
*
|
||||
* NOTE: This .x file generates the USER level headers for the keyserver.
|
||||
* the KERNEL level headers are created by hand as they kernel has special
|
||||
* requirements.
|
||||
*/
|
||||
|
||||
%/* From: #pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI" */
|
||||
%/* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
%
|
||||
%/*
|
||||
% * Compiled from key_prot.x using rpcgen.
|
||||
% * DO NOT EDIT THIS FILE!
|
||||
% * This is NOT source code!
|
||||
% */
|
||||
|
||||
/*
|
||||
* PROOT and MODULUS define the way the Diffie-Hellman key is generated.
|
||||
*
|
||||
* MODULUS should be chosen as a prime of the form: MODULUS == 2*p + 1,
|
||||
* where p is also prime.
|
||||
*
|
||||
* PROOT satisfies the following two conditions:
|
||||
* (1) (PROOT ** 2) % MODULUS != 1
|
||||
* (2) (PROOT ** p) % MODULUS != 1
|
||||
*
|
||||
*/
|
||||
|
||||
const PROOT = 3;
|
||||
const HEXMODULUS = "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b";
|
||||
|
||||
const HEXKEYBYTES = 48; /* HEXKEYBYTES == strlen(HEXMODULUS) */
|
||||
const KEYSIZE = 192; /* KEYSIZE == bit length of key */
|
||||
const KEYBYTES = 24; /* byte length of key */
|
||||
|
||||
/*
|
||||
* The first 16 hex digits of the encrypted secret key are used as
|
||||
* a checksum in the database.
|
||||
*/
|
||||
const KEYCHECKSUMSIZE = 16;
|
||||
|
||||
/*
|
||||
* status of operation
|
||||
*/
|
||||
enum keystatus {
|
||||
KEY_SUCCESS, /* no problems */
|
||||
KEY_NOSECRET, /* no secret key stored */
|
||||
KEY_UNKNOWN, /* unknown netname */
|
||||
KEY_SYSTEMERR /* system error (out of memory, encryption failure) */
|
||||
};
|
||||
|
||||
typedef opaque keybuf[HEXKEYBYTES]; /* store key in hex */
|
||||
|
||||
typedef string netnamestr<MAXNETNAMELEN>;
|
||||
|
||||
/*
|
||||
* Argument to ENCRYPT or DECRYPT
|
||||
*/
|
||||
struct cryptkeyarg {
|
||||
netnamestr remotename;
|
||||
des_block deskey;
|
||||
};
|
||||
|
||||
/*
|
||||
* Argument to ENCRYPT_PK or DECRYPT_PK
|
||||
*/
|
||||
struct cryptkeyarg2 {
|
||||
netnamestr remotename;
|
||||
netobj remotekey; /* Contains a length up to 1024 bytes */
|
||||
des_block deskey;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Result of ENCRYPT, DECRYPT, ENCRYPT_PK, and DECRYPT_PK
|
||||
*/
|
||||
union cryptkeyres switch (keystatus status) {
|
||||
case KEY_SUCCESS:
|
||||
des_block deskey;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
const MAXGIDS = 16; /* max number of gids in gid list */
|
||||
|
||||
/*
|
||||
* Unix credential
|
||||
*/
|
||||
struct unixcred {
|
||||
u_int uid;
|
||||
u_int gid;
|
||||
u_int gids<MAXGIDS>;
|
||||
};
|
||||
|
||||
/*
|
||||
* Result returned from GETCRED
|
||||
*/
|
||||
union getcredres switch (keystatus status) {
|
||||
case KEY_SUCCESS:
|
||||
unixcred cred;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
/*
|
||||
* key_netstarg;
|
||||
*/
|
||||
|
||||
struct key_netstarg {
|
||||
keybuf st_priv_key;
|
||||
keybuf st_pub_key;
|
||||
netnamestr st_netname;
|
||||
};
|
||||
|
||||
union key_netstres switch (keystatus status){
|
||||
case KEY_SUCCESS:
|
||||
key_netstarg knet;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%#ifndef opaque
|
||||
%#define opaque char
|
||||
%#endif
|
||||
%
|
||||
#endif
|
||||
program KEY_PROG {
|
||||
version KEY_VERS {
|
||||
|
||||
/*
|
||||
* This is my secret key.
|
||||
* Store it for me.
|
||||
*/
|
||||
keystatus
|
||||
KEY_SET(keybuf) = 1;
|
||||
|
||||
/*
|
||||
* I want to talk to X.
|
||||
* Encrypt a conversation key for me.
|
||||
*/
|
||||
cryptkeyres
|
||||
KEY_ENCRYPT(cryptkeyarg) = 2;
|
||||
|
||||
/*
|
||||
* X just sent me a message.
|
||||
* Decrypt the conversation key for me.
|
||||
*/
|
||||
cryptkeyres
|
||||
KEY_DECRYPT(cryptkeyarg) = 3;
|
||||
|
||||
/*
|
||||
* Generate a secure conversation key for me
|
||||
*/
|
||||
des_block
|
||||
KEY_GEN(void) = 4;
|
||||
|
||||
/*
|
||||
* Get me the uid, gid and group-access-list associated
|
||||
* with this netname (for kernel which cannot use NIS)
|
||||
*/
|
||||
getcredres
|
||||
KEY_GETCRED(netnamestr) = 5;
|
||||
} = 1;
|
||||
version KEY_VERS2 {
|
||||
|
||||
/*
|
||||
* #######
|
||||
* Procedures 1-5 are identical to version 1
|
||||
* #######
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is my secret key.
|
||||
* Store it for me.
|
||||
*/
|
||||
keystatus
|
||||
KEY_SET(keybuf) = 1;
|
||||
|
||||
/*
|
||||
* I want to talk to X.
|
||||
* Encrypt a conversation key for me.
|
||||
*/
|
||||
cryptkeyres
|
||||
KEY_ENCRYPT(cryptkeyarg) = 2;
|
||||
|
||||
/*
|
||||
* X just sent me a message.
|
||||
* Decrypt the conversation key for me.
|
||||
*/
|
||||
cryptkeyres
|
||||
KEY_DECRYPT(cryptkeyarg) = 3;
|
||||
|
||||
/*
|
||||
* Generate a secure conversation key for me
|
||||
*/
|
||||
des_block
|
||||
KEY_GEN(void) = 4;
|
||||
|
||||
/*
|
||||
* Get me the uid, gid and group-access-list associated
|
||||
* with this netname (for kernel which cannot use NIS)
|
||||
*/
|
||||
getcredres
|
||||
KEY_GETCRED(netnamestr) = 5;
|
||||
|
||||
/*
|
||||
* I want to talk to X. and I know X's public key
|
||||
* Encrypt a conversation key for me.
|
||||
*/
|
||||
cryptkeyres
|
||||
KEY_ENCRYPT_PK(cryptkeyarg2) = 6;
|
||||
|
||||
/*
|
||||
* X just sent me a message. and I know X's public key
|
||||
* Decrypt the conversation key for me.
|
||||
*/
|
||||
cryptkeyres
|
||||
KEY_DECRYPT_PK(cryptkeyarg2) = 7;
|
||||
|
||||
/*
|
||||
* Store my public key, netname and private key.
|
||||
*/
|
||||
keystatus
|
||||
KEY_NET_PUT(key_netstarg) = 8;
|
||||
|
||||
/*
|
||||
* Retrieve my public key, netname and private key.
|
||||
*/
|
||||
key_netstres
|
||||
KEY_NET_GET(void) = 9;
|
||||
|
||||
/*
|
||||
* Return me the conversation key that is constructed
|
||||
* from my secret key and this publickey.
|
||||
*/
|
||||
|
||||
cryptkeyres
|
||||
KEY_GET_CONV(keybuf) = 10;
|
||||
|
||||
|
||||
} = 2;
|
||||
} = 100029;
|
||||
|
||||
|
139
freebsd/include/rpcsvc/klm_prot.x
Normal file
139
freebsd/include/rpcsvc/klm_prot.x
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Kernel/lock manager protocol definition
|
||||
* Copyright (C) 1986 Sun Microsystems, Inc.
|
||||
*
|
||||
* protocol used between the UNIX kernel (the "client") and the
|
||||
* local lock manager. The local lock manager is a deamon running
|
||||
* above the kernel.
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)klm_prot.x 1.7 87/07/08 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)klm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const LM_MAXSTRLEN = 1024;
|
||||
|
||||
/*
|
||||
* lock manager status returns
|
||||
*/
|
||||
enum klm_stats {
|
||||
klm_granted = 0, /* lock is granted */
|
||||
klm_denied = 1, /* lock is denied */
|
||||
klm_denied_nolocks = 2, /* no lock entry available */
|
||||
klm_working = 3 /* lock is being processed */
|
||||
};
|
||||
|
||||
/*
|
||||
* lock manager lock identifier
|
||||
*/
|
||||
struct klm_lock {
|
||||
string server_name<LM_MAXSTRLEN>;
|
||||
netobj fh; /* a counted file handle */
|
||||
int pid; /* holder of the lock */
|
||||
unsigned l_offset; /* beginning offset of the lock */
|
||||
unsigned l_len; /* byte length of the lock;
|
||||
* zero means through end of file */
|
||||
};
|
||||
|
||||
/*
|
||||
* lock holder identifier
|
||||
*/
|
||||
struct klm_holder {
|
||||
bool exclusive; /* FALSE if shared lock */
|
||||
int svid; /* holder of the lock (pid) */
|
||||
unsigned l_offset; /* beginning offset of the lock */
|
||||
unsigned l_len; /* byte length of the lock;
|
||||
* zero means through end of file */
|
||||
};
|
||||
|
||||
/*
|
||||
* reply to KLM_LOCK / KLM_UNLOCK / KLM_CANCEL
|
||||
*/
|
||||
struct klm_stat {
|
||||
klm_stats stat;
|
||||
};
|
||||
|
||||
/*
|
||||
* reply to a KLM_TEST call
|
||||
*/
|
||||
union klm_testrply switch (klm_stats stat) {
|
||||
case klm_denied:
|
||||
struct klm_holder holder;
|
||||
default: /* All other cases return no arguments */
|
||||
void;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* arguments to KLM_LOCK
|
||||
*/
|
||||
struct klm_lockargs {
|
||||
bool block;
|
||||
bool exclusive;
|
||||
struct klm_lock alock;
|
||||
};
|
||||
|
||||
/*
|
||||
* arguments to KLM_TEST
|
||||
*/
|
||||
struct klm_testargs {
|
||||
bool exclusive;
|
||||
struct klm_lock alock;
|
||||
};
|
||||
|
||||
/*
|
||||
* arguments to KLM_UNLOCK
|
||||
*/
|
||||
struct klm_unlockargs {
|
||||
struct klm_lock alock;
|
||||
};
|
||||
|
||||
program KLM_PROG {
|
||||
version KLM_VERS {
|
||||
|
||||
klm_testrply KLM_TEST (struct klm_testargs) = 1;
|
||||
|
||||
klm_stat KLM_LOCK (struct klm_lockargs) = 2;
|
||||
|
||||
klm_stat KLM_CANCEL (struct klm_lockargs) = 3;
|
||||
/* klm_granted=> the cancel request fails due to lock is already granted */
|
||||
/* klm_denied=> the cancel request successfully aborts
|
||||
lock request */
|
||||
|
||||
klm_stat KLM_UNLOCK (struct klm_unlockargs) = 4;
|
||||
} = 1;
|
||||
} = 100020;
|
257
freebsd/include/rpcsvc/mount.x
Normal file
257
freebsd/include/rpcsvc/mount.x
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Protocol description for the mount program
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)mount.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)mount.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const MNTPATHLEN = 1024; /* maximum bytes in a pathname argument */
|
||||
const MNTNAMLEN = 255; /* maximum bytes in a name argument */
|
||||
const FHSIZE = 32; /* size in bytes of a file handle */
|
||||
#ifdef WANT_NFS3
|
||||
const FHSIZE3 = 64; /* size in bytes of a file handle (v3) */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The fhandle is the file handle that the server passes to the client.
|
||||
* All file operations are done using the file handles to refer to a file
|
||||
* or a directory. The file handle can contain whatever information the
|
||||
* server needs to distinguish an individual file.
|
||||
*/
|
||||
typedef opaque fhandle[FHSIZE];
|
||||
#ifdef WANT_NFS3
|
||||
typedef opaque fhandle3<FHSIZE3>;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If a status of zero is returned, the call completed successfully, and
|
||||
* a file handle for the directory follows. A non-zero status indicates
|
||||
* some sort of error. The status corresponds with UNIX error numbers.
|
||||
*/
|
||||
union fhstatus switch (unsigned fhs_status) {
|
||||
case 0:
|
||||
fhandle fhs_fhandle;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
#ifdef WANT_NFS3
|
||||
/*
|
||||
* Status codes returned by the version 3 mount call.
|
||||
*/
|
||||
enum mountstat3 {
|
||||
MNT3_OK = 0, /* no error */
|
||||
MNT3ERR_PERM = 1, /* Not owner */
|
||||
MNT3ERR_NOENT = 2, /* No such file or directory */
|
||||
MNT3ERR_IO = 5, /* I/O error */
|
||||
MNT3ERR_ACCES = 13, /* Permission denied */
|
||||
MNT3ERR_NOTDIR = 20, /* Not a directory */
|
||||
MNT3ERR_INVAL = 22, /* Invalid argument */
|
||||
MNT3ERR_NAMETOOLONG = 63, /* Filename too long */
|
||||
MNT3ERR_NOTSUPP = 10004, /* Operation not supported */
|
||||
MNT3ERR_SERVERFAULT = 10006 /* A failure on the server */
|
||||
};
|
||||
|
||||
struct mountres3_ok {
|
||||
fhandle3 fhandle;
|
||||
int auth_flavors<>;
|
||||
};
|
||||
|
||||
union mountres3 switch (mountstat3 fhs_status) {
|
||||
case 0:
|
||||
mountres3_ok mountinfo;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The type dirpath is the pathname of a directory
|
||||
*/
|
||||
typedef string dirpath<MNTPATHLEN>;
|
||||
|
||||
/*
|
||||
* The type name is used for arbitrary names (hostnames, groupnames)
|
||||
*/
|
||||
typedef string name<MNTNAMLEN>;
|
||||
|
||||
/*
|
||||
* A list of who has what mounted
|
||||
*/
|
||||
typedef struct mountbody *mountlist;
|
||||
struct mountbody {
|
||||
name ml_hostname;
|
||||
dirpath ml_directory;
|
||||
mountlist ml_next;
|
||||
};
|
||||
|
||||
/*
|
||||
* A list of netgroups
|
||||
*/
|
||||
typedef struct groupnode *groups;
|
||||
struct groupnode {
|
||||
name gr_name;
|
||||
groups gr_next;
|
||||
};
|
||||
|
||||
/*
|
||||
* A list of what is exported and to whom
|
||||
*/
|
||||
typedef struct exportnode *exports;
|
||||
struct exportnode {
|
||||
dirpath ex_dir;
|
||||
groups ex_groups;
|
||||
exports ex_next;
|
||||
};
|
||||
|
||||
program MOUNTPROG {
|
||||
/*
|
||||
* Version one of the mount protocol communicates with version two
|
||||
* of the NFS protocol. Version three communicates with
|
||||
* version three of the NFS protocol. The only connecting
|
||||
* point is the fhandle structure, which is the same for both
|
||||
* protocols.
|
||||
*/
|
||||
version MOUNTVERS {
|
||||
/*
|
||||
* Does no work. It is made available in all RPC services
|
||||
* to allow server reponse testing and timing
|
||||
*/
|
||||
void
|
||||
MOUNTPROC_NULL(void) = 0;
|
||||
|
||||
/*
|
||||
* If fhs_status is 0, then fhs_fhandle contains the
|
||||
* file handle for the directory. This file handle may
|
||||
* be used in the NFS protocol. This procedure also adds
|
||||
* a new entry to the mount list for this client mounting
|
||||
* the directory.
|
||||
* Unix authentication required.
|
||||
*/
|
||||
fhstatus
|
||||
MOUNTPROC_MNT(dirpath) = 1;
|
||||
|
||||
/*
|
||||
* Returns the list of remotely mounted filesystems. The
|
||||
* mountlist contains one entry for each hostname and
|
||||
* directory pair.
|
||||
*/
|
||||
mountlist
|
||||
MOUNTPROC_DUMP(void) = 2;
|
||||
|
||||
/*
|
||||
* Removes the mount list entry for the directory
|
||||
* Unix authentication required.
|
||||
*/
|
||||
void
|
||||
MOUNTPROC_UMNT(dirpath) = 3;
|
||||
|
||||
/*
|
||||
* Removes all of the mount list entries for this client
|
||||
* Unix authentication required.
|
||||
*/
|
||||
void
|
||||
MOUNTPROC_UMNTALL(void) = 4;
|
||||
|
||||
/*
|
||||
* Returns a list of all the exported filesystems, and which
|
||||
* machines are allowed to import it.
|
||||
*/
|
||||
exports
|
||||
MOUNTPROC_EXPORT(void) = 5;
|
||||
|
||||
/*
|
||||
* Identical to MOUNTPROC_EXPORT above
|
||||
*/
|
||||
exports
|
||||
MOUNTPROC_EXPORTALL(void) = 6;
|
||||
} = 1;
|
||||
#ifdef WANT_NFS3
|
||||
version MOUNTVERS3 {
|
||||
/*
|
||||
* Does no work. It is made available in all RPC services
|
||||
* to allow server reponse testing and timing
|
||||
*/
|
||||
void
|
||||
MOUNTPROC_NULL(void) = 0;
|
||||
|
||||
/*
|
||||
* If mountres3.fhs_status is MNT3_OK, then
|
||||
* mountres3.mountinfo contains the file handle for
|
||||
* the directory and a list of acceptable
|
||||
* authentication flavors. This file handle may only
|
||||
* be used in the NFS version 3 protocol. This
|
||||
* procedure also results in the server adding a new
|
||||
* entry to its mount list recording that this client
|
||||
* has mounted the directory. AUTH_UNIX authentication
|
||||
* or better is required.
|
||||
*/
|
||||
mountres3
|
||||
MOUNTPROC_MNT(dirpath) = 1;
|
||||
|
||||
/*
|
||||
* Returns the list of remotely mounted filesystems. The
|
||||
* mountlist contains one entry for each hostname and
|
||||
* directory pair.
|
||||
*/
|
||||
mountlist
|
||||
MOUNTPROC_DUMP(void) = 2;
|
||||
|
||||
/*
|
||||
* Removes the mount list entry for the directory
|
||||
* Unix authentication required.
|
||||
*/
|
||||
void
|
||||
MOUNTPROC_UMNT(dirpath) = 3;
|
||||
|
||||
/*
|
||||
* Removes all of the mount list entries for this client
|
||||
* Unix authentication required.
|
||||
*/
|
||||
void
|
||||
MOUNTPROC_UMNTALL(void) = 4;
|
||||
|
||||
/*
|
||||
* Returns a list of all the exported filesystems, and which
|
||||
* machines are allowed to import it.
|
||||
*/
|
||||
exports
|
||||
MOUNTPROC_EXPORT(void) = 5;
|
||||
} = 3;
|
||||
#endif
|
||||
} = 100005;
|
1266
freebsd/include/rpcsvc/nfs_prot.x
Normal file
1266
freebsd/include/rpcsvc/nfs_prot.x
Normal file
File diff suppressed because it is too large
Load Diff
289
freebsd/include/rpcsvc/nis.h
Normal file
289
freebsd/include/rpcsvc/nis.h
Normal file
@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _NIS_H_RPCGEN
|
||||
#define _NIS_H_RPCGEN
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user or with the express written consent of
|
||||
* Sun Microsystems, Inc.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
#ifndef __nis_object_h
|
||||
#define __nis_object_h
|
||||
|
||||
#define NIS_MAXSTRINGLEN 255
|
||||
#define NIS_MAXNAMELEN 1024
|
||||
#define NIS_MAXATTRNAME 32
|
||||
#define NIS_MAXATTRVAL 2048
|
||||
#define NIS_MAXCOLUMNS 64
|
||||
#define NIS_MAXATTR 16
|
||||
#define NIS_MAXPATH 1024
|
||||
#define NIS_MAXREPLICAS 128
|
||||
#define NIS_MAXLINKS 16
|
||||
#define NIS_PK_NONE 0
|
||||
#define NIS_PK_DH 1
|
||||
#define NIS_PK_RSA 2
|
||||
#define NIS_PK_KERB 3
|
||||
|
||||
struct nis_attr {
|
||||
char *zattr_ndx;
|
||||
struct {
|
||||
u_int zattr_val_len;
|
||||
char *zattr_val_val;
|
||||
} zattr_val;
|
||||
};
|
||||
typedef struct nis_attr nis_attr;
|
||||
|
||||
typedef char *nis_name;
|
||||
|
||||
enum zotypes {
|
||||
BOGUS_OBJ = 0,
|
||||
NO_OBJ = 1,
|
||||
DIRECTORY_OBJ = 2,
|
||||
GROUP_OBJ = 3,
|
||||
TABLE_OBJ = 4,
|
||||
ENTRY_OBJ = 5,
|
||||
LINK_OBJ = 6,
|
||||
PRIVATE_OBJ = 7,
|
||||
};
|
||||
typedef enum zotypes zotypes;
|
||||
|
||||
enum nstype {
|
||||
UNKNOWN = 0,
|
||||
NIS = 1,
|
||||
SUNYP = 2,
|
||||
IVY = 3,
|
||||
DNS = 4,
|
||||
X500 = 5,
|
||||
DNANS = 6,
|
||||
XCHS = 7,
|
||||
CDS = 8,
|
||||
};
|
||||
typedef enum nstype nstype;
|
||||
|
||||
struct oar_mask {
|
||||
u_long oa_rights;
|
||||
zotypes oa_otype;
|
||||
};
|
||||
typedef struct oar_mask oar_mask;
|
||||
|
||||
struct endpoint {
|
||||
char *uaddr;
|
||||
char *family;
|
||||
char *proto;
|
||||
};
|
||||
typedef struct endpoint endpoint;
|
||||
|
||||
struct nis_server {
|
||||
nis_name name;
|
||||
struct {
|
||||
u_int ep_len;
|
||||
endpoint *ep_val;
|
||||
} ep;
|
||||
u_long key_type;
|
||||
netobj pkey;
|
||||
};
|
||||
typedef struct nis_server nis_server;
|
||||
|
||||
struct directory_obj {
|
||||
nis_name do_name;
|
||||
nstype do_type;
|
||||
struct {
|
||||
u_int do_servers_len;
|
||||
nis_server *do_servers_val;
|
||||
} do_servers;
|
||||
u_long do_ttl;
|
||||
struct {
|
||||
u_int do_armask_len;
|
||||
oar_mask *do_armask_val;
|
||||
} do_armask;
|
||||
};
|
||||
typedef struct directory_obj directory_obj;
|
||||
#define EN_BINARY 1
|
||||
#define EN_CRYPT 2
|
||||
#define EN_XDR 4
|
||||
#define EN_MODIFIED 8
|
||||
#define EN_ASN1 64
|
||||
|
||||
struct entry_col {
|
||||
u_long ec_flags;
|
||||
struct {
|
||||
u_int ec_value_len;
|
||||
char *ec_value_val;
|
||||
} ec_value;
|
||||
};
|
||||
typedef struct entry_col entry_col;
|
||||
|
||||
struct entry_obj {
|
||||
char *en_type;
|
||||
struct {
|
||||
u_int en_cols_len;
|
||||
entry_col *en_cols_val;
|
||||
} en_cols;
|
||||
};
|
||||
typedef struct entry_obj entry_obj;
|
||||
|
||||
struct group_obj {
|
||||
u_long gr_flags;
|
||||
struct {
|
||||
u_int gr_members_len;
|
||||
nis_name *gr_members_val;
|
||||
} gr_members;
|
||||
};
|
||||
typedef struct group_obj group_obj;
|
||||
|
||||
struct link_obj {
|
||||
zotypes li_rtype;
|
||||
struct {
|
||||
u_int li_attrs_len;
|
||||
nis_attr *li_attrs_val;
|
||||
} li_attrs;
|
||||
nis_name li_name;
|
||||
};
|
||||
typedef struct link_obj link_obj;
|
||||
#define TA_BINARY 1
|
||||
#define TA_CRYPT 2
|
||||
#define TA_XDR 4
|
||||
#define TA_SEARCHABLE 8
|
||||
#define TA_CASE 16
|
||||
#define TA_MODIFIED 32
|
||||
#define TA_ASN1 64
|
||||
|
||||
struct table_col {
|
||||
char *tc_name;
|
||||
u_long tc_flags;
|
||||
u_long tc_rights;
|
||||
};
|
||||
typedef struct table_col table_col;
|
||||
|
||||
struct table_obj {
|
||||
char *ta_type;
|
||||
int ta_maxcol;
|
||||
u_char ta_sep;
|
||||
struct {
|
||||
u_int ta_cols_len;
|
||||
table_col *ta_cols_val;
|
||||
} ta_cols;
|
||||
char *ta_path;
|
||||
};
|
||||
typedef struct table_obj table_obj;
|
||||
|
||||
struct objdata {
|
||||
zotypes zo_type;
|
||||
union {
|
||||
struct directory_obj di_data;
|
||||
struct group_obj gr_data;
|
||||
struct table_obj ta_data;
|
||||
struct entry_obj en_data;
|
||||
struct link_obj li_data;
|
||||
struct {
|
||||
u_int po_data_len;
|
||||
char *po_data_val;
|
||||
} po_data;
|
||||
} objdata_u;
|
||||
};
|
||||
typedef struct objdata objdata;
|
||||
|
||||
struct nis_oid {
|
||||
u_long ctime;
|
||||
u_long mtime;
|
||||
};
|
||||
typedef struct nis_oid nis_oid;
|
||||
|
||||
struct nis_object {
|
||||
nis_oid zo_oid;
|
||||
nis_name zo_name;
|
||||
nis_name zo_owner;
|
||||
nis_name zo_group;
|
||||
nis_name zo_domain;
|
||||
u_long zo_access;
|
||||
u_long zo_ttl;
|
||||
objdata zo_data;
|
||||
};
|
||||
typedef struct nis_object nis_object;
|
||||
|
||||
#endif /* if __nis_object_h */
|
||||
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
extern bool_t xdr_nis_attr (XDR *, nis_attr*);
|
||||
extern bool_t xdr_nis_name (XDR *, nis_name*);
|
||||
extern bool_t xdr_zotypes (XDR *, zotypes*);
|
||||
extern bool_t xdr_nstype (XDR *, nstype*);
|
||||
extern bool_t xdr_oar_mask (XDR *, oar_mask*);
|
||||
extern bool_t xdr_endpoint (XDR *, endpoint*);
|
||||
extern bool_t xdr_nis_server (XDR *, nis_server*);
|
||||
extern bool_t xdr_directory_obj (XDR *, directory_obj*);
|
||||
extern bool_t xdr_entry_col (XDR *, entry_col*);
|
||||
extern bool_t xdr_entry_obj (XDR *, entry_obj*);
|
||||
extern bool_t xdr_group_obj (XDR *, group_obj*);
|
||||
extern bool_t xdr_link_obj (XDR *, link_obj*);
|
||||
extern bool_t xdr_table_col (XDR *, table_col*);
|
||||
extern bool_t xdr_table_obj (XDR *, table_obj*);
|
||||
extern bool_t xdr_objdata (XDR *, objdata*);
|
||||
extern bool_t xdr_nis_oid (XDR *, nis_oid*);
|
||||
extern bool_t xdr_nis_object (XDR *, nis_object*);
|
||||
|
||||
#else /* K&R C */
|
||||
extern bool_t xdr_nis_attr ();
|
||||
extern bool_t xdr_nis_name ();
|
||||
extern bool_t xdr_zotypes ();
|
||||
extern bool_t xdr_nstype ();
|
||||
extern bool_t xdr_oar_mask ();
|
||||
extern bool_t xdr_endpoint ();
|
||||
extern bool_t xdr_nis_server ();
|
||||
extern bool_t xdr_directory_obj ();
|
||||
extern bool_t xdr_entry_col ();
|
||||
extern bool_t xdr_entry_obj ();
|
||||
extern bool_t xdr_group_obj ();
|
||||
extern bool_t xdr_link_obj ();
|
||||
extern bool_t xdr_table_col ();
|
||||
extern bool_t xdr_table_obj ();
|
||||
extern bool_t xdr_objdata ();
|
||||
extern bool_t xdr_nis_oid ();
|
||||
extern bool_t xdr_nis_object ();
|
||||
|
||||
#endif /* K&R C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_NIS_H_RPCGEN */
|
464
freebsd/include/rpcsvc/nis.x
Normal file
464
freebsd/include/rpcsvc/nis.x
Normal file
@ -0,0 +1,464 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user or with the express written consent of
|
||||
% * Sun Microsystems, Inc.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* From 4.1 : @(#)nis.x 1.61 Copyright 1989 Sun Microsystems
|
||||
*
|
||||
* RPC Language Protocol description file for NIS Plus
|
||||
* This version : 1.61
|
||||
* Last Modified : 3/19/91
|
||||
*/
|
||||
#ifdef RPC_HDR
|
||||
%/*
|
||||
% * nis.h
|
||||
% *
|
||||
% * This file is the main include file for NIS clients. It contains
|
||||
% * both the client library function defines and the various data
|
||||
% * structures used by the NIS service. It includes the file nis_tags.h
|
||||
% * which defines the tag values. This allows the tags to change without
|
||||
% * having to change the nis.x file.
|
||||
% *
|
||||
% * NOTE : DO NOT EDIT THIS FILE! It is automatically generated when
|
||||
% * rpcgen is run on the nis.x file. Note that there is a
|
||||
% * simple sed script to remove some unneeded lines. (See the
|
||||
% * Makefile target nis.h)
|
||||
% *
|
||||
% */
|
||||
%#include <rpcsvc/nis_tags.h>
|
||||
#endif
|
||||
|
||||
/* This gets stuffed into the source files. */
|
||||
#if RPC_HDR
|
||||
%#include <rpc/xdr.h>
|
||||
#endif
|
||||
/*
|
||||
* This is just pointless.
|
||||
*/
|
||||
#ifdef SUN_STUPIDITY
|
||||
#if RPC_SVC
|
||||
%#include "nis_svc.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Include the RPC Language description of NIS objects */
|
||||
#include "nis_object.x"
|
||||
|
||||
/* Errors that can be returned by the service */
|
||||
enum nis_error {
|
||||
NIS_SUCCESS = 0, /* A-ok, let's rock n roll */
|
||||
NIS_S_SUCCESS = 1, /* Name found (maybe) */
|
||||
NIS_NOTFOUND = 2, /* Name definitely not found */
|
||||
NIS_S_NOTFOUND = 3, /* Name maybe not found */
|
||||
NIS_CACHEEXPIRED = 4, /* Name exists but cache out of date */
|
||||
NIS_NAMEUNREACHABLE = 5, /* Can't get there from here */
|
||||
NIS_UNKNOWNOBJ = 6, /* Object type is bogus */
|
||||
NIS_TRYAGAIN = 7, /* I'm busy, call back */
|
||||
NIS_SYSTEMERROR = 8, /* Out of band failure */
|
||||
NIS_CHAINBROKEN = 9, /* First/Next warning */
|
||||
NIS_PERMISSION = 10, /* Not enough permission to access */
|
||||
NIS_NOTOWNER = 11, /* You don't own it, sorry */
|
||||
NIS_NOT_ME = 12, /* I don't serve this name */
|
||||
NIS_NOMEMORY = 13, /* Outta VM! Help! */
|
||||
NIS_NAMEEXISTS = 14, /* Can't create over another name */
|
||||
NIS_NOTMASTER = 15, /* I'm justa secondaray, don't ask me */
|
||||
NIS_INVALIDOBJ = 16, /* Object is broken somehow */
|
||||
NIS_BADNAME = 17, /* Unparsable name */
|
||||
NIS_NOCALLBACK = 18, /* Couldn't talk to call back proc */
|
||||
NIS_CBRESULTS = 19, /* Results being called back to you */
|
||||
NIS_NOSUCHNAME = 20, /* Name unknown */
|
||||
NIS_NOTUNIQUE = 21, /* Value is not uniques (entry) */
|
||||
NIS_IBMODERROR = 22, /* Inf. Base. Modify error. */
|
||||
NIS_NOSUCHTABLE = 23, /* Name for table was wrong */
|
||||
NIS_TYPEMISMATCH = 24, /* Entry and table type mismatch */
|
||||
NIS_LINKNAMEERROR = 25, /* Link points to bogus name */
|
||||
NIS_PARTIAL = 26, /* Partial success, found table */
|
||||
NIS_TOOMANYATTRS = 27, /* Too many attributes */
|
||||
NIS_RPCERROR = 28, /* RPC error encountered */
|
||||
NIS_BADATTRIBUTE = 29, /* Bad or invalid attribute */
|
||||
NIS_NOTSEARCHABLE = 30, /* Non-searchable object searched */
|
||||
NIS_CBERROR = 31, /* Error during callback (svc crash) */
|
||||
NIS_FOREIGNNS = 32, /* Foreign Namespace */
|
||||
NIS_BADOBJECT = 33, /* Malformed object structure */
|
||||
NIS_NOTSAMEOBJ = 34, /* Object swapped during deletion */
|
||||
NIS_MODFAIL = 35, /* Failure during a Modify. */
|
||||
NIS_BADREQUEST = 36, /* Illegal query for table */
|
||||
NIS_NOTEMPTY = 37, /* Attempt to remove a non-empty tbl */
|
||||
NIS_COLDSTART_ERR = 38, /* Error accesing the cold start file */
|
||||
NIS_RESYNC = 39, /* Transaction log too far out of date */
|
||||
NIS_FAIL = 40, /* NIS operation failed. */
|
||||
NIS_UNAVAIL = 41, /* NIS+ service is unavailable (client) */
|
||||
NIS_RES2BIG = 42, /* NIS+ result too big for datagram */
|
||||
NIS_SRVAUTH = 43, /* NIS+ server wasn't authenticated. */
|
||||
NIS_CLNTAUTH = 44, /* NIS+ Client wasn't authenticated. */
|
||||
NIS_NOFILESPACE = 45, /* NIS+ server ran out of disk space */
|
||||
NIS_NOPROC = 46, /* NIS+ server couldn't create new proc */
|
||||
NIS_DUMPLATER = 47 /* NIS+ server already has dump child */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Structure definitions for the parameters and results of the actual
|
||||
* NIS RPC calls.
|
||||
*
|
||||
* This is the standard result (in the protocol) of most of the nis
|
||||
* requests.
|
||||
*/
|
||||
|
||||
struct nis_result {
|
||||
nis_error status; /* Status of the response */
|
||||
nis_object objects<>; /* objects found */
|
||||
netobj cookie; /* Cookie Data */
|
||||
u_long zticks; /* server ticks */
|
||||
u_long dticks; /* DBM ticks. */
|
||||
u_long aticks; /* Cache (accel) ticks */
|
||||
u_long cticks; /* Client ticks */
|
||||
};
|
||||
|
||||
/*
|
||||
* A Name Service request
|
||||
* This request is used to access the name space, ns_name is the name
|
||||
* of the object within the namespace and the object is it's value, for
|
||||
* add/modify, a copy of the original for remove.
|
||||
*/
|
||||
|
||||
struct ns_request {
|
||||
nis_name ns_name; /* Name in the NIS name space */
|
||||
nis_object ns_object<1>; /* Optional Object (add/remove) */
|
||||
};
|
||||
|
||||
/*
|
||||
* An information base request
|
||||
* This request includes the NIS name of the table we wish to search, the
|
||||
* search criteria in the form of attribute/value pairs and an optional
|
||||
* callback program number. If the callback program number is provided
|
||||
* the server will send back objects one at a time, otherwise it will
|
||||
* return them all in the response.
|
||||
*/
|
||||
|
||||
struct ib_request {
|
||||
nis_name ibr_name; /* The name of the Table */
|
||||
nis_attr ibr_srch<>; /* The search critereia */
|
||||
u_long ibr_flags; /* Optional flags */
|
||||
nis_object ibr_obj<1>; /* optional object (add/modify) */
|
||||
nis_server ibr_cbhost<1>; /* Optional callback info */
|
||||
u_long ibr_bufsize; /* Optional first/next bufsize */
|
||||
netobj ibr_cookie; /* The first/next cookie */
|
||||
};
|
||||
|
||||
/*
|
||||
* This argument to the PING call notifies the replicas that something in
|
||||
* a directory has changed and this is it's timestamp. The replica will use
|
||||
* the timestamp to determine if its resync operation was successful.
|
||||
*/
|
||||
struct ping_args {
|
||||
nis_name dir; /* Directory that had the change */
|
||||
u_long stamp; /* timestamp of the transaction */
|
||||
};
|
||||
|
||||
/*
|
||||
* These are the type of entries that are stored in the transaction log,
|
||||
* note that modifications will appear as two entries, for names, they have
|
||||
* an "OLD" entry followed by a "NEW" entry. For entries in tables, there
|
||||
* is a remove followed by an add. It is done this way so that we can read
|
||||
* the log backwards to back out transactions and forwards to propogate
|
||||
* updated.
|
||||
*/
|
||||
enum log_entry_t {
|
||||
LOG_NOP = 0,
|
||||
ADD_NAME = 1, /* Name Added to name space */
|
||||
REM_NAME = 2, /* Name removed from name space */
|
||||
MOD_NAME_OLD = 3, /* Name was modified in the name space */
|
||||
MOD_NAME_NEW = 4, /* Name was modified in the name space */
|
||||
ADD_IBASE = 5, /* Entry added to information base */
|
||||
REM_IBASE = 6, /* Entry removed from information base */
|
||||
MOD_IBASE = 7, /* Entry was modified in information base */
|
||||
UPD_STAMP = 8 /* Update timestamp (used as fenceposts) */
|
||||
};
|
||||
|
||||
/*
|
||||
* This result is returned from the name service when it is requested to
|
||||
* dump logged entries from its transaction log. Information base updates
|
||||
* will have the name of the information base in the le_name field and
|
||||
* a canonical set of attribute/value pairs to fully specify the entry's
|
||||
* 'name'.
|
||||
*/
|
||||
struct log_entry {
|
||||
u_long le_time; /* Time in seconds */
|
||||
log_entry_t le_type; /* Type of log entry */
|
||||
nis_name le_princp; /* Principal making the change */
|
||||
nis_name le_name; /* Name of table/dir involved */
|
||||
nis_attr le_attrs<>; /* List of AV pairs. */
|
||||
nis_object le_object; /* Actual object value */
|
||||
};
|
||||
|
||||
struct log_result {
|
||||
nis_error lr_status; /* The status itself */
|
||||
netobj lr_cookie; /* Used by the dump callback */
|
||||
log_entry lr_entries<>; /* zero or more entries */
|
||||
};
|
||||
|
||||
struct cp_result {
|
||||
nis_error cp_status; /* Status of the checkpoint */
|
||||
u_long cp_zticks; /* Service 'ticks' */
|
||||
u_long cp_dticks; /* Database 'ticks' */
|
||||
};
|
||||
|
||||
/*
|
||||
* This structure defines a generic NIS tag list. The taglist contains
|
||||
* zero or tags, each of which is a type and a value. (u_long).
|
||||
* These are used to report statistics (see tag definitions below)
|
||||
* and to set or reset state variables.
|
||||
*/
|
||||
struct nis_tag {
|
||||
u_long tag_type; /* Statistic tag (may vary) */
|
||||
string tag_val<1024>; /* Statistic value may also vary */
|
||||
};
|
||||
|
||||
struct nis_taglist {
|
||||
nis_tag tags<>; /* List of tags */
|
||||
};
|
||||
|
||||
struct dump_args {
|
||||
nis_name da_dir; /* Directory to dump */
|
||||
u_long da_time; /* From this timestamp */
|
||||
nis_server da_cbhost<1>; /* Callback to use. */
|
||||
};
|
||||
|
||||
struct fd_args {
|
||||
nis_name dir_name; /* The directory we're looking for */
|
||||
nis_name requester; /* Host principal name for signature */
|
||||
};
|
||||
|
||||
struct fd_result {
|
||||
nis_error status; /* Status returned by function */
|
||||
nis_name source; /* Source of this answer */
|
||||
opaque dir_data<>; /* Directory Data (XDR'ed) */
|
||||
opaque signature<>; /* Signature of the source */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* What's going on here? Well, it's like this. When the service
|
||||
* is being compiled it wants to have the service definition specific
|
||||
* info included, and when the client is being compiled it wants that
|
||||
* info. This includes the appropriate file which was generated by
|
||||
* make in the protocols directory (probably /usr/include/rpcsvc).
|
||||
*
|
||||
* Uhm... guys? With RPC, you aren't supposed to have separate
|
||||
* server-specific and client-specific header files. You have one header
|
||||
* file that's suitable for both. If your code doesn't work using just
|
||||
* the one header file, I submit to you that it's broken.
|
||||
* -Bill
|
||||
*/
|
||||
#ifdef SUN_STUPIDITY
|
||||
#ifdef RPC_SVC
|
||||
%#include "nis_svc.h"
|
||||
#endif
|
||||
#ifdef RPC_CLNT
|
||||
%#include "nis_clnt.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
program NIS_PROG {
|
||||
|
||||
/* RPC Language description of the NIS+ protocol */
|
||||
version NIS_VERSION {
|
||||
/* The name service functions */
|
||||
nis_result NIS_LOOKUP(ns_request) = 1;
|
||||
nis_result NIS_ADD(ns_request) = 2;
|
||||
nis_result NIS_MODIFY(ns_request) = 3;
|
||||
nis_result NIS_REMOVE(ns_request) = 4;
|
||||
|
||||
/* The information base functions */
|
||||
nis_result NIS_IBLIST(ib_request) = 5;
|
||||
nis_result NIS_IBADD(ib_request) = 6;
|
||||
nis_result NIS_IBMODIFY(ib_request) = 7;
|
||||
nis_result NIS_IBREMOVE(ib_request) = 8;
|
||||
nis_result NIS_IBFIRST(ib_request) = 9;
|
||||
nis_result NIS_IBNEXT(ib_request) = 10;
|
||||
|
||||
/* NIS Administrative functions */
|
||||
fd_result NIS_FINDDIRECTORY(fd_args) = 12;
|
||||
|
||||
/* If fetch and optionally reset statistics */
|
||||
nis_taglist NIS_STATUS(nis_taglist) = 14;
|
||||
|
||||
/* Dump changes to directory since time in da_time */
|
||||
log_result NIS_DUMPLOG(dump_args) = 15;
|
||||
|
||||
/* Dump contents of directory named */
|
||||
log_result NIS_DUMP(dump_args) = 16;
|
||||
|
||||
/* Check status of callback thread */
|
||||
bool NIS_CALLBACK(netobj) = 17;
|
||||
|
||||
/* Return last update time for named dir */
|
||||
u_long NIS_CPTIME(nis_name) = 18;
|
||||
|
||||
/* Checkpoint directory or table named */
|
||||
cp_result NIS_CHECKPOINT(nis_name) = 19;
|
||||
|
||||
/* Send 'status changed' ping to replicates */
|
||||
void NIS_PING(ping_args) = 20;
|
||||
|
||||
/* Modify server behaviour (such as debugging) */
|
||||
nis_taglist NIS_SERVSTATE(nis_taglist) = 21;
|
||||
|
||||
/* Create a Directory */
|
||||
nis_error NIS_MKDIR(nis_name) = 22;
|
||||
|
||||
/* Remove a Directory */
|
||||
nis_error NIS_RMDIR(nis_name) = 23;
|
||||
|
||||
/* Update public keys of a directory object */
|
||||
nis_error NIS_UPDKEYS(nis_name) = 24;
|
||||
} = 3;
|
||||
} = 100300;
|
||||
|
||||
/*
|
||||
* Included below are the defines that become part of nis.h,
|
||||
* they are technically not part of the protocol, but do define
|
||||
* key aspects of the implementation and are therefore useful
|
||||
* in building a conforming server or client.
|
||||
*/
|
||||
#if RPC_HDR
|
||||
%/*
|
||||
% * Generic "hash" datastructures, used by all types of hashed data.
|
||||
% */
|
||||
%struct nis_hash_data {
|
||||
% nis_name name; /* NIS name of hashed item */
|
||||
% int keychain; /* It's hash key (for pop) */
|
||||
% struct nis_hash_data *next; /* Hash collision pointer */
|
||||
% struct nis_hash_data *prv_item; /* A serial, doubly linked list */
|
||||
% struct nis_hash_data *nxt_item; /* of items in the hash table */
|
||||
%};
|
||||
%typedef struct nis_hash_data NIS_HASH_ITEM;
|
||||
%
|
||||
%struct nis_hash_table {
|
||||
% NIS_HASH_ITEM *keys[64]; /* A hash table of items */
|
||||
% NIS_HASH_ITEM *first; /* The first "item" in serial list */
|
||||
%};
|
||||
%typedef struct nis_hash_table NIS_HASH_TABLE;
|
||||
%
|
||||
%/* Structure for storing dynamically allocated static data */
|
||||
%struct nis_sdata {
|
||||
% void *buf; /* Memory allocation pointer */
|
||||
% u_long size; /* Buffer size */
|
||||
%};
|
||||
%
|
||||
%/* Generic client creating flags */
|
||||
%#define ZMH_VC 1
|
||||
%#define ZMH_DG 2
|
||||
%#define ZMH_AUTH 4
|
||||
%
|
||||
%/* Testing Access rights for objects */
|
||||
%
|
||||
%#define NIS_READ_ACC 1
|
||||
%#define NIS_MODIFY_ACC 2
|
||||
%#define NIS_CREATE_ACC 4
|
||||
%#define NIS_DESTROY_ACC 8
|
||||
%/* Test macros. a == access rights, m == desired rights. */
|
||||
%#define WORLD(a, m) (((a) & (m)) != 0)
|
||||
%#define GROUP(a, m) (((a) & ((m) << 8)) != 0)
|
||||
%#define OWNER(a, m) (((a) & ((m) << 16)) != 0)
|
||||
%#define NOBODY(a, m) (((a) & ((m) << 24)) != 0)
|
||||
%
|
||||
%#define OATYPE(d, n) (((d)->do_armask.do_armask_val+n)->oa_otype)
|
||||
%#define OARIGHTS(d, n) (((d)->do_armask.do_armask_val+n)->oa_rights)
|
||||
%#define WORLD_DEFAULT (NIS_READ_ACC)
|
||||
%#define GROUP_DEFAULT (NIS_READ_ACC << 8)
|
||||
%#define OWNER_DEFAULT ((NIS_READ_ACC +\
|
||||
NIS_MODIFY_ACC +\
|
||||
NIS_CREATE_ACC +\
|
||||
NIS_DESTROY_ACC) << 16)
|
||||
%#define DEFAULT_RIGHTS (WORLD_DEFAULT | GROUP_DEFAULT | OWNER_DEFAULT)
|
||||
%
|
||||
%/* Result manipulation defines ... */
|
||||
%#define NIS_RES_NUMOBJ(x) ((x)->objects.objects_len)
|
||||
%#define NIS_RES_OBJECT(x) ((x)->objects.objects_val)
|
||||
%#define NIS_RES_COOKIE(x) ((x)->cookie)
|
||||
%#define NIS_RES_STATUS(x) ((x)->status)
|
||||
%
|
||||
%/* These defines make getting at the variant part of the object easier. */
|
||||
%#define TA_data zo_data.objdata_u.ta_data
|
||||
%#define EN_data zo_data.objdata_u.en_data
|
||||
%#define DI_data zo_data.objdata_u.di_data
|
||||
%#define LI_data zo_data.objdata_u.li_data
|
||||
%#define GR_data zo_data.objdata_u.gr_data
|
||||
%
|
||||
%#define __type_of(o) ((o)->zo_data.zo_type)
|
||||
%
|
||||
%/* Declarations for the internal subroutines in nislib.c */
|
||||
%enum name_pos {SAME_NAME, HIGHER_NAME, LOWER_NAME, NOT_SEQUENTIAL, BAD_NAME};
|
||||
%typedef enum name_pos name_pos;
|
||||
%
|
||||
%/*
|
||||
% * Defines for getting at column data in entry objects. Because RPCGEN
|
||||
% * generates some rather wordy structures, we create some defines that
|
||||
% * collapse the needed keystrokes to access a particular value using
|
||||
% * these definitions they take an nis_object *, and an int and return
|
||||
% * a u_char * for Value, and an int for length.
|
||||
% */
|
||||
%#define ENTRY_VAL(obj, col) \
|
||||
(obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val
|
||||
%#define ENTRY_LEN(obj, col) \
|
||||
(obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len
|
||||
%
|
||||
%#ifdef __cplusplus
|
||||
%}
|
||||
%#endif
|
||||
%
|
||||
%/* Prototypes, and extern declarations for the NIS library functions. */
|
||||
%#include <rpcsvc/nislib.h>
|
||||
%#endif /* __NIS_RPCGEN_H */
|
||||
%/* EDIT_START */
|
||||
%
|
||||
%/*
|
||||
% * nis_3.h
|
||||
% *
|
||||
% * This file contains definitions that are only of interest to the actual
|
||||
% * service daemon and client stubs. Normal users of NIS will not include
|
||||
% * this file.
|
||||
% *
|
||||
% * NOTE : This include file is automatically created by a combination
|
||||
% * of rpcgen and sed. DO NOT EDIT IT, change the nis.x file instead
|
||||
% * and then remake this file.
|
||||
% */
|
||||
%#ifndef __nis_3_h
|
||||
%#define __nis_3_h
|
||||
%#ifdef __cplusplus
|
||||
%extern "C" {
|
||||
%#endif
|
||||
#endif
|
85
freebsd/include/rpcsvc/nis_cache.x
Normal file
85
freebsd/include/rpcsvc/nis_cache.x
Normal file
@ -0,0 +1,85 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user or with the express written consent of
|
||||
% * Sun Microsystems, Inc.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
|
||||
/*
|
||||
* nis_cache.x
|
||||
*
|
||||
* Copyright (c) 1988-1992 Sun Microsystems Inc
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
/* From: %#pragma ident "@(#)nis_cache.x 1.11 94/05/03 SMI" */
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%#include <rpc/types.h>
|
||||
%#include <rpcsvc/nis.h>
|
||||
%
|
||||
%/* default cache file */
|
||||
%#define CACHEFILE "/var/nis/NIS_SHARED_DIRCACHE"
|
||||
%
|
||||
%/* clients have to read-lock the cache file, and SVR4 locking requires that */
|
||||
%/* the file be writable, but we don't want a world-writable cache file. */
|
||||
%/* So... everyone agrees to use a different, world-writable file for the */
|
||||
%/* locking operations, but the data is in CACHEFILE. */
|
||||
%#define CACHELOCK "/usr/tmp/.NIS_DIR_CACHELOCK"
|
||||
%
|
||||
%/* the file containing one trusted XDR'ed directory object.
|
||||
% * This has to be present for the system to work.
|
||||
% */
|
||||
%#define COLD_START_FILE "/var/nis/NIS_COLD_START"
|
||||
%
|
||||
%enum pc_status {HIT, MISS, NEAR_MISS};
|
||||
%
|
||||
%extern int __nis_debuglevel;
|
||||
%
|
||||
%
|
||||
#endif
|
||||
|
||||
#ifdef RPC_CLNT
|
||||
#ifdef SOLARIS
|
||||
%#include "../gen/nis_clnt.h"
|
||||
#else
|
||||
%#include "nis.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
program CACHEPROG {
|
||||
version CACHE_VER_1 {
|
||||
void NIS_CACHE_ADD_ENTRY(fd_result) = 1;
|
||||
void NIS_CACHE_REMOVE_ENTRY(directory_obj) = 2;
|
||||
void NIS_CACHE_READ_COLDSTART(void) = 3;
|
||||
void NIS_CACHE_REFRESH_ENTRY(string<>) = 4;
|
||||
} = 1;
|
||||
} = 100301;
|
74
freebsd/include/rpcsvc/nis_callback.x
Normal file
74
freebsd/include/rpcsvc/nis_callback.x
Normal file
@ -0,0 +1,74 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user or with the express written consent of
|
||||
% * Sun Microsystems, Inc.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
|
||||
/*
|
||||
* nis_callback.x
|
||||
*
|
||||
* Copyright (c) 1988-1992 Sun Microsystems Inc
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
/* From: %#pragma ident "@(#)nis_callback.x 1.7 94/05/03 SMI" */
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* "@(#)zns_cback.x 1.2 90/09/10 Copyr 1990 Sun Micro"
|
||||
*
|
||||
* RPCL description of the Callback Service.
|
||||
*/
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%#include <rpcsvc/nis.h>
|
||||
#endif
|
||||
#ifdef RPC_XDR
|
||||
#ifdef SOLARIS
|
||||
%#include "nis_clnt.h"
|
||||
#else
|
||||
%#include "nis.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef nis_object *obj_p;
|
||||
|
||||
struct cback_data {
|
||||
obj_p entries<>; /* List of objects */
|
||||
};
|
||||
|
||||
program CB_PROG {
|
||||
version CB_VERS {
|
||||
bool CBPROC_RECEIVE(cback_data) = 1;
|
||||
void CBPROC_FINISH(void) = 2;
|
||||
void CBPROC_ERROR(nis_error) = 3;
|
||||
} = 1;
|
||||
} = 100302;
|
317
freebsd/include/rpcsvc/nis_object.x
Normal file
317
freebsd/include/rpcsvc/nis_object.x
Normal file
@ -0,0 +1,317 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user or with the express written consent of
|
||||
% * Sun Microsystems, Inc.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
|
||||
/*
|
||||
* nis_object.x
|
||||
*
|
||||
* Copyright (c) 1988-1992 Sun Microsystems Inc
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
/* From: %#pragma ident "@(#)nis_object.x 1.10 94/05/03 SMI" */
|
||||
|
||||
#if RPC_HDR
|
||||
%
|
||||
%#ifndef __nis_object_h
|
||||
%#define __nis_object_h
|
||||
%
|
||||
#endif
|
||||
/*
|
||||
* This file defines the format for a NIS object in RPC language.
|
||||
* It is included by the main .x file and the database access protocol
|
||||
* file. It is common because both of them need to deal with the same
|
||||
* type of object. Generating the actual code though is a bit messy because
|
||||
* the nis.x file and the nis_dba.x file will generate xdr routines to
|
||||
* encode/decode objects when only one set is needed. Such is life when
|
||||
* one is using rpcgen.
|
||||
*
|
||||
* Note, the protocol doesn't specify any limits on such things as
|
||||
* maximum name length, number of attributes, etc. These are enforced
|
||||
* by the database backend. When you hit them you will no. Also see
|
||||
* the db_getlimits() function for fetching the limit values.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Some manifest constants, chosen to maximize flexibility without
|
||||
* plugging the wire full of data.
|
||||
*/
|
||||
const NIS_MAXSTRINGLEN = 255;
|
||||
const NIS_MAXNAMELEN = 1024;
|
||||
const NIS_MAXATTRNAME = 32;
|
||||
const NIS_MAXATTRVAL = 2048;
|
||||
const NIS_MAXCOLUMNS = 64;
|
||||
const NIS_MAXATTR = 16;
|
||||
const NIS_MAXPATH = 1024;
|
||||
const NIS_MAXREPLICAS = 128;
|
||||
const NIS_MAXLINKS = 16;
|
||||
|
||||
const NIS_PK_NONE = 0; /* no public key (unix/sys auth) */
|
||||
const NIS_PK_DH = 1; /* Public key is Diffie-Hellman type */
|
||||
const NIS_PK_RSA = 2; /* Public key if RSA type */
|
||||
const NIS_PK_KERB = 3; /* Use kerberos style authentication */
|
||||
|
||||
/*
|
||||
* The fundamental name type of NIS. The name may consist of two parts,
|
||||
* the first being the fully qualified name, and the second being an
|
||||
* optional set of attribute/value pairs.
|
||||
*/
|
||||
struct nis_attr {
|
||||
string zattr_ndx<>; /* name of the index */
|
||||
opaque zattr_val<>; /* Value for the attribute. */
|
||||
};
|
||||
|
||||
typedef string nis_name<>; /* The NIS name itself. */
|
||||
|
||||
/* NIS object types are defined by the following enumeration. The numbers
|
||||
* they use are based on the following scheme :
|
||||
* 0 - 1023 are reserved for Sun,
|
||||
* 1024 - 2047 are defined to be private to a particular tree.
|
||||
* 2048 - 4095 are defined to be user defined.
|
||||
* 4096 - ... are reserved for future use.
|
||||
*/
|
||||
|
||||
enum zotypes {
|
||||
BOGUS_OBJ = 0, /* Uninitialized object structure */
|
||||
NO_OBJ = 1, /* NULL object (no data) */
|
||||
DIRECTORY_OBJ = 2, /* Directory object describing domain */
|
||||
GROUP_OBJ = 3, /* Group object (a list of names) */
|
||||
TABLE_OBJ = 4, /* Table object (a database schema) */
|
||||
ENTRY_OBJ = 5, /* Entry object (a database record) */
|
||||
LINK_OBJ = 6, /* A name link. */
|
||||
PRIVATE_OBJ = 7 /* Private object (all opaque data) */
|
||||
};
|
||||
|
||||
/*
|
||||
* The types of Name services NIS knows about. They are enumerated
|
||||
* here. The Binder code will use this type to determine if it has
|
||||
* a set of library routines that will access the indicated name service.
|
||||
*/
|
||||
enum nstype {
|
||||
UNKNOWN = 0,
|
||||
NIS = 1, /* Nis Plus Service */
|
||||
SUNYP = 2, /* Old NIS Service */
|
||||
IVY = 3, /* Nis Plus Plus Service */
|
||||
DNS = 4, /* Domain Name Service */
|
||||
X500 = 5, /* ISO/CCCIT X.500 Service */
|
||||
DNANS = 6, /* Digital DECNet Name Service */
|
||||
XCHS = 7, /* Xerox ClearingHouse Service */
|
||||
CDS= 8
|
||||
};
|
||||
|
||||
/*
|
||||
* DIRECTORY - The name service object. These objects identify other name
|
||||
* servers that are serving some portion of the name space. Each has a
|
||||
* type associated with it. The resolver library will note whether or not
|
||||
* is has the needed routines to access that type of service.
|
||||
* The oarmask structure defines an access rights mask on a per object
|
||||
* type basis for the name spaces. The only bits currently used are
|
||||
* create and destroy. By enabling or disabling these access rights for
|
||||
* a specific object type for a one of the accessor entities (owner,
|
||||
* group, world) the administrator can control what types of objects
|
||||
* may be freely added to the name space and which require the
|
||||
* administrator's approval.
|
||||
*/
|
||||
struct oar_mask {
|
||||
u_long oa_rights; /* Access rights mask */
|
||||
zotypes oa_otype; /* Object type */
|
||||
};
|
||||
|
||||
struct endpoint {
|
||||
string uaddr<>;
|
||||
string family<>; /* Transport family (INET, OSI, etc) */
|
||||
string proto<>; /* Protocol (TCP, UDP, CLNP, etc) */
|
||||
};
|
||||
|
||||
/*
|
||||
* Note: pkey is a netobj which is limited to 1024 bytes which limits the
|
||||
* keysize to 8192 bits. This is consider to be a reasonable limit for
|
||||
* the expected lifetime of this service.
|
||||
*/
|
||||
struct nis_server {
|
||||
nis_name name; /* Principal name of the server */
|
||||
endpoint ep<>; /* Universal addr(s) for server */
|
||||
u_long key_type; /* Public key type */
|
||||
netobj pkey; /* server's public key */
|
||||
};
|
||||
|
||||
struct directory_obj {
|
||||
nis_name do_name; /* Name of the directory being served */
|
||||
nstype do_type; /* one of NIS, DNS, IVY, YP, or X.500 */
|
||||
nis_server do_servers<>; /* <0> == Primary name server */
|
||||
u_long do_ttl; /* Time To Live (for caches) */
|
||||
oar_mask do_armask<>; /* Create/Destroy rights by object type */
|
||||
};
|
||||
|
||||
/*
|
||||
* ENTRY - This is one row of data from an information base.
|
||||
* The type value is used by the client library to convert the entry to
|
||||
* it's internal structure representation. The Table name is a back pointer
|
||||
* to the table where the entry is stored. This allows the client library
|
||||
* to determine where to send a request if the client wishes to change this
|
||||
* entry but got to it through a LINK rather than directly.
|
||||
* If the entry is a "standalone" entry then this field is void.
|
||||
*/
|
||||
const EN_BINARY = 1; /* Indicates value is binary data */
|
||||
const EN_CRYPT = 2; /* Indicates the value is encrypted */
|
||||
const EN_XDR = 4; /* Indicates the value is XDR encoded */
|
||||
const EN_MODIFIED = 8; /* Indicates entry is modified. */
|
||||
const EN_ASN1 = 64; /* Means contents use ASN.1 encoding */
|
||||
|
||||
struct entry_col {
|
||||
u_long ec_flags; /* Flags for this value */
|
||||
opaque ec_value<>; /* It's textual value */
|
||||
};
|
||||
|
||||
struct entry_obj {
|
||||
string en_type<>; /* Type of entry such as "passwd" */
|
||||
entry_col en_cols<>; /* Value for the entry */
|
||||
};
|
||||
|
||||
/*
|
||||
* GROUP - The group object contains a list of NIS principal names. Groups
|
||||
* are used to authorize principals. Each object has a set of access rights
|
||||
* for members of its group. Principal names in groups are in the form
|
||||
* name.directory and recursive groups are expressed as @groupname.directory
|
||||
*/
|
||||
struct group_obj {
|
||||
u_long gr_flags; /* Flags controlling group */
|
||||
nis_name gr_members<>; /* List of names in group */
|
||||
};
|
||||
|
||||
/*
|
||||
* LINK - This is the LINK object. It is quite similar to a symbolic link
|
||||
* in the UNIX filesystem. The attributes in the main object structure are
|
||||
* relative to the LINK data and not what it points to (like the file system)
|
||||
* "modify" privleges here indicate the right to modify what the link points
|
||||
* at and not to modify that actual object pointed to by the link.
|
||||
*/
|
||||
struct link_obj {
|
||||
zotypes li_rtype; /* Real type of the object */
|
||||
nis_attr li_attrs<>; /* Attribute/Values for tables */
|
||||
nis_name li_name; /* The object's real NIS name */
|
||||
};
|
||||
|
||||
/*
|
||||
* TABLE - This is the table object. It implements a simple
|
||||
* data base that applications and use for configuration or
|
||||
* administration purposes. The role of the table is to group together
|
||||
* a set of related entries. Tables are the simple database component
|
||||
* of NIS. Like many databases, tables are logically divided into columns
|
||||
* and rows. The columns are labeled with indexes and each ENTRY makes
|
||||
* up a row. Rows may be addressed within the table by selecting one
|
||||
* or more indexes, and values for those indexes. Each row which has
|
||||
* a value for the given index that matches the desired value is returned.
|
||||
* Within the definition of each column there is a flags variable, this
|
||||
* variable contains flags which determine whether or not the column is
|
||||
* searchable, contains binary data, and access rights for the entry objects
|
||||
* column value.
|
||||
*/
|
||||
|
||||
const TA_BINARY = 1; /* Means table data is binary */
|
||||
const TA_CRYPT = 2; /* Means value should be encrypted */
|
||||
const TA_XDR = 4; /* Means value is XDR encoded */
|
||||
const TA_SEARCHABLE = 8; /* Means this column is searchable */
|
||||
const TA_CASE = 16; /* Means this column is Case Sensitive */
|
||||
const TA_MODIFIED = 32; /* Means this columns attrs are modified*/
|
||||
const TA_ASN1 = 64; /* Means contents use ASN.1 encoding */
|
||||
|
||||
struct table_col {
|
||||
string tc_name<64>; /* Column Name */
|
||||
u_long tc_flags; /* control flags */
|
||||
u_long tc_rights; /* Access rights mask */
|
||||
};
|
||||
|
||||
struct table_obj {
|
||||
string ta_type<64>; /* Table type such as "passwd" */
|
||||
int ta_maxcol; /* Total number of columns */
|
||||
u_char ta_sep; /* Separator character */
|
||||
table_col ta_cols<>; /* The number of table indexes */
|
||||
string ta_path<>; /* A search path for this table */
|
||||
};
|
||||
|
||||
/*
|
||||
* This union joins together all of the currently known objects.
|
||||
*/
|
||||
union objdata switch (zotypes zo_type) {
|
||||
case DIRECTORY_OBJ :
|
||||
struct directory_obj di_data;
|
||||
case GROUP_OBJ :
|
||||
struct group_obj gr_data;
|
||||
case TABLE_OBJ :
|
||||
struct table_obj ta_data;
|
||||
case ENTRY_OBJ:
|
||||
struct entry_obj en_data;
|
||||
case LINK_OBJ :
|
||||
struct link_obj li_data;
|
||||
case PRIVATE_OBJ :
|
||||
opaque po_data<>;
|
||||
case NO_OBJ :
|
||||
void;
|
||||
case BOGUS_OBJ :
|
||||
void;
|
||||
default :
|
||||
void;
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the basic NIS object data type. It consists of a generic part
|
||||
* which all objects contain, and a specialized part which varies depending
|
||||
* on the type of the object. All of the specialized sections have been
|
||||
* described above. You might have wondered why they all start with an
|
||||
* integer size, followed by the useful data. The answer is, when the
|
||||
* server doesn't recognize the type returned it treats it as opaque data.
|
||||
* And the definition for opaque data is {int size; char *data;}. In this
|
||||
* way, servers and utility routines that do not understand a given type
|
||||
* may still pass it around. One has to be careful in setting
|
||||
* this variable accurately, it must take into account such things as
|
||||
* XDR padding of structures etc. The best way to set it is to note one's
|
||||
* position in the XDR encoding stream, encode the structure, look at the
|
||||
* new position and calculate the size.
|
||||
*/
|
||||
struct nis_oid {
|
||||
u_long ctime; /* Time of objects creation */
|
||||
u_long mtime; /* Time of objects modification */
|
||||
};
|
||||
|
||||
struct nis_object {
|
||||
nis_oid zo_oid; /* object identity verifier. */
|
||||
nis_name zo_name; /* The NIS name for this object */
|
||||
nis_name zo_owner; /* NIS name of object owner. */
|
||||
nis_name zo_group; /* NIS name of access group. */
|
||||
nis_name zo_domain; /* The administrator for the object */
|
||||
u_long zo_access; /* Access rights (owner, group, world) */
|
||||
u_long zo_ttl; /* Object's time to live in seconds. */
|
||||
objdata zo_data; /* Data structure for this type */
|
||||
};
|
||||
#if RPC_HDR
|
||||
%
|
||||
%#endif /* if __nis_object_h */
|
||||
%
|
||||
#endif
|
327
freebsd/include/rpcsvc/nlm_prot.x
Normal file
327
freebsd/include/rpcsvc/nlm_prot.x
Normal file
@ -0,0 +1,327 @@
|
||||
/*
|
||||
* Network lock manager protocol definition
|
||||
* Copyright (C) 1986 Sun Microsystems, Inc.
|
||||
*
|
||||
* protocol used between local lock manager and remote lock manager
|
||||
*/
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%#define LM_MAXSTRLEN 1024
|
||||
%#define MAXNAMELEN LM_MAXSTRLEN+1
|
||||
#else
|
||||
%#include <sys/cdefs.h>
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%__RCSID("$NetBSD: nlm_prot.x,v 1.6 2000/06/07 14:30:15 bouyer Exp $");
|
||||
%#endif /* not lint */
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* status of a call to the lock manager
|
||||
*/
|
||||
enum nlm_stats {
|
||||
nlm_granted = 0,
|
||||
nlm_denied = 1,
|
||||
nlm_denied_nolocks = 2,
|
||||
nlm_blocked = 3,
|
||||
nlm_denied_grace_period = 4,
|
||||
nlm_deadlck = 5
|
||||
};
|
||||
|
||||
struct nlm_holder {
|
||||
bool exclusive;
|
||||
int svid;
|
||||
netobj oh;
|
||||
unsigned l_offset;
|
||||
unsigned l_len;
|
||||
};
|
||||
|
||||
union nlm_testrply switch (nlm_stats stat) {
|
||||
case nlm_denied:
|
||||
struct nlm_holder holder;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
struct nlm_stat {
|
||||
nlm_stats stat;
|
||||
};
|
||||
|
||||
struct nlm_res {
|
||||
netobj cookie;
|
||||
nlm_stat stat;
|
||||
};
|
||||
|
||||
struct nlm_testres {
|
||||
netobj cookie;
|
||||
nlm_testrply stat;
|
||||
};
|
||||
|
||||
struct nlm_lock {
|
||||
string caller_name<LM_MAXSTRLEN>;
|
||||
netobj fh; /* identify a file */
|
||||
netobj oh; /* identify owner of a lock */
|
||||
int svid; /* generated from pid for svid */
|
||||
unsigned l_offset;
|
||||
unsigned l_len;
|
||||
};
|
||||
|
||||
struct nlm_lockargs {
|
||||
netobj cookie;
|
||||
bool block;
|
||||
bool exclusive;
|
||||
struct nlm_lock alock;
|
||||
bool reclaim; /* used for recovering locks */
|
||||
int state; /* specify local status monitor state */
|
||||
};
|
||||
|
||||
struct nlm_cancargs {
|
||||
netobj cookie;
|
||||
bool block;
|
||||
bool exclusive;
|
||||
struct nlm_lock alock;
|
||||
};
|
||||
|
||||
struct nlm_testargs {
|
||||
netobj cookie;
|
||||
bool exclusive;
|
||||
struct nlm_lock alock;
|
||||
};
|
||||
|
||||
struct nlm_unlockargs {
|
||||
netobj cookie;
|
||||
struct nlm_lock alock;
|
||||
};
|
||||
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%/*
|
||||
% * The following enums are actually bit encoded for efficient
|
||||
% * boolean algebra.... DON'T change them.....
|
||||
% */
|
||||
#endif
|
||||
enum fsh_mode {
|
||||
fsm_DN = 0, /* deny none */
|
||||
fsm_DR = 1, /* deny read */
|
||||
fsm_DW = 2, /* deny write */
|
||||
fsm_DRW = 3 /* deny read/write */
|
||||
};
|
||||
|
||||
enum fsh_access {
|
||||
fsa_NONE = 0, /* for completeness */
|
||||
fsa_R = 1, /* read only */
|
||||
fsa_W = 2, /* write only */
|
||||
fsa_RW = 3 /* read/write */
|
||||
};
|
||||
|
||||
struct nlm_share {
|
||||
string caller_name<LM_MAXSTRLEN>;
|
||||
netobj fh;
|
||||
netobj oh;
|
||||
fsh_mode mode;
|
||||
fsh_access access;
|
||||
};
|
||||
|
||||
struct nlm_shareargs {
|
||||
netobj cookie;
|
||||
nlm_share share;
|
||||
bool reclaim;
|
||||
};
|
||||
|
||||
struct nlm_shareres {
|
||||
netobj cookie;
|
||||
nlm_stats stat;
|
||||
int sequence;
|
||||
};
|
||||
|
||||
struct nlm_notify {
|
||||
string name<MAXNAMELEN>;
|
||||
long state;
|
||||
};
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%/* definitions for NLM version 4 */
|
||||
#endif
|
||||
enum nlm4_stats {
|
||||
nlm4_granted = 0,
|
||||
nlm4_denied = 1,
|
||||
nlm4_denied_nolocks = 2,
|
||||
nlm4_blocked = 3,
|
||||
nlm4_denied_grace_period = 4,
|
||||
nlm4_deadlck = 5,
|
||||
nlm4_rofs = 6,
|
||||
nlm4_stale_fh = 7,
|
||||
nlm4_fbig = 8,
|
||||
nlm4_failed = 9
|
||||
};
|
||||
|
||||
struct nlm4_stat {
|
||||
nlm4_stats stat;
|
||||
};
|
||||
|
||||
struct nlm4_holder {
|
||||
bool exclusive;
|
||||
u_int32_t svid;
|
||||
netobj oh;
|
||||
u_int64_t l_offset;
|
||||
u_int64_t l_len;
|
||||
};
|
||||
|
||||
struct nlm4_lock {
|
||||
string caller_name<MAXNAMELEN>;
|
||||
netobj fh;
|
||||
netobj oh;
|
||||
u_int32_t svid;
|
||||
u_int64_t l_offset;
|
||||
u_int64_t l_len;
|
||||
};
|
||||
|
||||
struct nlm4_share {
|
||||
string caller_name<MAXNAMELEN>;
|
||||
netobj fh;
|
||||
netobj oh;
|
||||
fsh_mode mode;
|
||||
fsh_access access;
|
||||
};
|
||||
|
||||
union nlm4_testrply switch (nlm4_stats stat) {
|
||||
case nlm_denied:
|
||||
struct nlm4_holder holder;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
struct nlm4_testres {
|
||||
netobj cookie;
|
||||
nlm4_testrply stat;
|
||||
};
|
||||
|
||||
struct nlm4_testargs {
|
||||
netobj cookie;
|
||||
bool exclusive;
|
||||
struct nlm4_lock alock;
|
||||
};
|
||||
|
||||
struct nlm4_res {
|
||||
netobj cookie;
|
||||
nlm4_stat stat;
|
||||
};
|
||||
|
||||
struct nlm4_lockargs {
|
||||
netobj cookie;
|
||||
bool block;
|
||||
bool exclusive;
|
||||
struct nlm4_lock alock;
|
||||
bool reclaim; /* used for recovering locks */
|
||||
int state; /* specify local status monitor state */
|
||||
};
|
||||
|
||||
struct nlm4_cancargs {
|
||||
netobj cookie;
|
||||
bool block;
|
||||
bool exclusive;
|
||||
struct nlm4_lock alock;
|
||||
};
|
||||
|
||||
struct nlm4_unlockargs {
|
||||
netobj cookie;
|
||||
struct nlm4_lock alock;
|
||||
};
|
||||
|
||||
struct nlm4_shareargs {
|
||||
netobj cookie;
|
||||
nlm4_share share;
|
||||
bool reclaim;
|
||||
};
|
||||
|
||||
struct nlm4_shareres {
|
||||
netobj cookie;
|
||||
nlm4_stats stat;
|
||||
int sequence;
|
||||
};
|
||||
|
||||
/*
|
||||
* argument for the procedure called by rpc.statd when a monitored host
|
||||
* status change.
|
||||
* XXX assumes LM_MAXSTRLEN == SM_MAXSTRLEN
|
||||
*/
|
||||
struct nlm_sm_status {
|
||||
string mon_name<LM_MAXSTRLEN>; /* name of host */
|
||||
int state; /* new state */
|
||||
opaque priv[16]; /* private data */
|
||||
};
|
||||
|
||||
struct nlm4_notify {
|
||||
string name<MAXNAMELEN>;
|
||||
int32_t state;
|
||||
};
|
||||
|
||||
/*
|
||||
* Over-the-wire protocol used between the network lock managers
|
||||
*/
|
||||
|
||||
program NLM_PROG {
|
||||
|
||||
version NLM_SM {
|
||||
void NLM_SM_NOTIFY(struct nlm_sm_status) = 1;
|
||||
} = 0;
|
||||
|
||||
version NLM_VERS {
|
||||
|
||||
nlm_testres NLM_TEST(struct nlm_testargs) = 1;
|
||||
|
||||
nlm_res NLM_LOCK(struct nlm_lockargs) = 2;
|
||||
|
||||
nlm_res NLM_CANCEL(struct nlm_cancargs) = 3;
|
||||
nlm_res NLM_UNLOCK(struct nlm_unlockargs) = 4;
|
||||
|
||||
/*
|
||||
* remote lock manager call-back to grant lock
|
||||
*/
|
||||
nlm_res NLM_GRANTED(struct nlm_testargs)= 5;
|
||||
/*
|
||||
* message passing style of requesting lock
|
||||
*/
|
||||
void NLM_TEST_MSG(struct nlm_testargs) = 6;
|
||||
void NLM_LOCK_MSG(struct nlm_lockargs) = 7;
|
||||
void NLM_CANCEL_MSG(struct nlm_cancargs) =8;
|
||||
void NLM_UNLOCK_MSG(struct nlm_unlockargs) = 9;
|
||||
void NLM_GRANTED_MSG(struct nlm_testargs) = 10;
|
||||
void NLM_TEST_RES(nlm_testres) = 11;
|
||||
void NLM_LOCK_RES(nlm_res) = 12;
|
||||
void NLM_CANCEL_RES(nlm_res) = 13;
|
||||
void NLM_UNLOCK_RES(nlm_res) = 14;
|
||||
void NLM_GRANTED_RES(nlm_res) = 15;
|
||||
} = 1;
|
||||
|
||||
version NLM_VERSX {
|
||||
nlm_shareres NLM_SHARE(nlm_shareargs) = 20;
|
||||
nlm_shareres NLM_UNSHARE(nlm_shareargs) = 21;
|
||||
nlm_res NLM_NM_LOCK(nlm_lockargs) = 22;
|
||||
void NLM_FREE_ALL(nlm_notify) = 23;
|
||||
} = 3;
|
||||
|
||||
version NLM_VERS4 {
|
||||
nlm4_testres NLM4_TEST(nlm4_testargs) = 1;
|
||||
nlm4_res NLM4_LOCK(nlm4_lockargs) = 2;
|
||||
nlm4_res NLM4_CANCEL(nlm4_cancargs) = 3;
|
||||
nlm4_res NLM4_UNLOCK(nlm4_unlockargs) = 4;
|
||||
nlm4_res NLM4_GRANTED(nlm4_testargs) = 5;
|
||||
void NLM4_TEST_MSG(nlm4_testargs) = 6;
|
||||
void NLM4_LOCK_MSG(nlm4_lockargs) = 7;
|
||||
void NLM4_CANCEL_MSG(nlm4_cancargs) = 8;
|
||||
void NLM4_UNLOCK_MSG(nlm4_unlockargs) = 9;
|
||||
void NLM4_GRANTED_MSG(nlm4_testargs) = 10;
|
||||
void NLM4_TEST_RES(nlm4_testres) = 11;
|
||||
void NLM4_LOCK_RES(nlm4_res) = 12;
|
||||
void NLM4_CANCEL_RES(nlm4_res) = 13;
|
||||
void NLM4_UNLOCK_RES(nlm4_res) = 14;
|
||||
void NLM4_GRANTED_RES(nlm4_res) = 15;
|
||||
nlm4_shareres NLM4_SHARE(nlm4_shareargs) = 20;
|
||||
nlm4_shareres NLM4_UNSHARE(nlm4_shareargs) = 21;
|
||||
nlm4_res NLM4_NM_LOCK(nlm4_lockargs) = 22;
|
||||
void NLM4_FREE_ALL(nlm4_notify) = 23;
|
||||
} = 4;
|
||||
} = 100021;
|
279
freebsd/include/rpcsvc/pmap_prot.x
Normal file
279
freebsd/include/rpcsvc/pmap_prot.x
Normal file
@ -0,0 +1,279 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
%/*
|
||||
% * Copyright (c) 1984,1989 by Sun Microsystems, Inc.
|
||||
% */
|
||||
|
||||
%/* from pmap_prot.x */
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%#pragma ident "@(#)pmap_prot.x 1.6 94/04/29 SMI"
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
%
|
||||
%#ifndef _KERNEL
|
||||
%
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Port Mapper Protocol Specification (in RPC Language)
|
||||
* derived from RFC 1057
|
||||
*/
|
||||
|
||||
%/*
|
||||
% * Protocol for the local binder service, or pmap.
|
||||
% *
|
||||
% * Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
% *
|
||||
% * The following procedures are supported by the protocol:
|
||||
% *
|
||||
% * PMAPPROC_NULL() returns ()
|
||||
% * takes nothing, returns nothing
|
||||
% *
|
||||
% * PMAPPROC_SET(struct pmap) returns (bool_t)
|
||||
% * TRUE is success, FALSE is failure. Registers the tuple
|
||||
% * [prog, vers, prot, port].
|
||||
% *
|
||||
% * PMAPPROC_UNSET(struct pmap) returns (bool_t)
|
||||
% * TRUE is success, FALSE is failure. Un-registers pair
|
||||
% * [prog, vers]. prot and port are ignored.
|
||||
% *
|
||||
% * PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
|
||||
% * 0 is failure. Otherwise returns the port number where the pair
|
||||
% * [prog, vers] is registered. It may lie!
|
||||
% *
|
||||
% * PMAPPROC_DUMP() RETURNS (struct pmaplist_ptr)
|
||||
% *
|
||||
% * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
|
||||
% * RETURNS (port, string<>);
|
||||
% * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc,
|
||||
% * encapsulatedargs);
|
||||
% * Calls the procedure on the local machine. If it is not registered,
|
||||
% * this procedure is quite; ie it does not return error information!!!
|
||||
% * This procedure only is supported on rpc/udp and calls via
|
||||
% * rpc/udp. This routine only passes null authentication parameters.
|
||||
% * This file has no interface to xdr routines for PMAPPROC_CALLIT.
|
||||
% *
|
||||
% * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
|
||||
% */
|
||||
%
|
||||
const PMAPPORT = 111; /* portmapper port number */
|
||||
%
|
||||
%
|
||||
%/*
|
||||
% * A mapping of (program, version, protocol) to port number
|
||||
% */
|
||||
|
||||
struct pmap {
|
||||
unsigned long pm_prog;
|
||||
unsigned long pm_vers;
|
||||
unsigned long pm_prot;
|
||||
unsigned long pm_port;
|
||||
};
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%typedef pmap PMAP;
|
||||
%
|
||||
#endif
|
||||
%
|
||||
%/*
|
||||
% * Supported values for the "prot" field
|
||||
% */
|
||||
%
|
||||
const PMAP_IPPROTO_TCP = 6; /* protocol number for TCP/IP */
|
||||
const PMAP_IPPROTO_UDP = 17; /* protocol number for UDP/IP */
|
||||
%
|
||||
%
|
||||
%/*
|
||||
% * A list of mappings
|
||||
% *
|
||||
% * Below are two definitions for the pmaplist structure. This is done because
|
||||
% * xdr_pmaplist() is specified to take a struct pmaplist **, rather than a
|
||||
% * struct pmaplist * that rpcgen would produce. One version of the pmaplist
|
||||
% * structure (actually called pm__list) is used with rpcgen, and the other is
|
||||
% * defined only in the header file for compatibility with the specified
|
||||
% * interface.
|
||||
% */
|
||||
|
||||
struct pm__list {
|
||||
pmap pml_map;
|
||||
struct pm__list *pml_next;
|
||||
};
|
||||
|
||||
typedef pm__list *pmaplist_ptr; /* results of PMAPPROC_DUMP */
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%typedef struct pm__list pmaplist;
|
||||
%typedef struct pm__list PMAPLIST;
|
||||
%
|
||||
%#ifndef __cplusplus
|
||||
%struct pmaplist {
|
||||
% PMAP pml_map;
|
||||
% struct pmaplist *pml_next;
|
||||
%};
|
||||
%#endif
|
||||
%
|
||||
%#ifdef __cplusplus
|
||||
%extern "C" {
|
||||
%#endif
|
||||
%extern bool_t xdr_pmaplist(XDR *, pmaplist**);
|
||||
%#ifdef __cplusplus
|
||||
%}
|
||||
%#endif
|
||||
%
|
||||
#endif
|
||||
|
||||
%
|
||||
%/*
|
||||
% * Arguments to callit
|
||||
% */
|
||||
|
||||
struct rmtcallargs {
|
||||
unsigned long prog;
|
||||
unsigned long vers;
|
||||
unsigned long proc;
|
||||
opaque args<>;
|
||||
};
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%/*
|
||||
% * Client-side only representation of rmtcallargs structure.
|
||||
% *
|
||||
% * The routine that XDRs the rmtcallargs structure must deal with the
|
||||
% * opaque arguments in the "args" structure. xdr_rmtcall_args() needs to be
|
||||
% * passed the XDR routine that knows the args' structure. This routine
|
||||
% * doesn't need to go over-the-wire (and it wouldn't make sense anyway) since
|
||||
% * the application being called knows the args structure already. So we use a
|
||||
% * different "XDR" structure on the client side, p_rmtcallargs, which includes
|
||||
% * the args' XDR routine.
|
||||
% */
|
||||
%struct p_rmtcallargs {
|
||||
% u_long prog;
|
||||
% u_long vers;
|
||||
% u_long proc;
|
||||
% struct {
|
||||
% u_int args_len;
|
||||
% char *args_val;
|
||||
% } args;
|
||||
% xdrproc_t xdr_args; /* encodes args */
|
||||
%};
|
||||
%
|
||||
#endif /* def RPC_HDR */
|
||||
%
|
||||
%
|
||||
%/*
|
||||
% * Results of callit
|
||||
% */
|
||||
|
||||
struct rmtcallres {
|
||||
unsigned long port;
|
||||
opaque res<>;
|
||||
};
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%/*
|
||||
% * Client-side only representation of rmtcallres structure.
|
||||
% */
|
||||
%struct p_rmtcallres {
|
||||
% u_long port;
|
||||
% struct {
|
||||
% u_int res_len;
|
||||
% char *res_val;
|
||||
% } res;
|
||||
% xdrproc_t xdr_res; /* decodes res */
|
||||
%};
|
||||
%
|
||||
#endif /* def RPC_HDR */
|
||||
|
||||
/*
|
||||
* Port mapper procedures
|
||||
*/
|
||||
|
||||
program PMAPPROG {
|
||||
version PMAPVERS {
|
||||
void
|
||||
PMAPPROC_NULL(void) = 0;
|
||||
|
||||
bool
|
||||
PMAPPROC_SET(pmap) = 1;
|
||||
|
||||
bool
|
||||
PMAPPROC_UNSET(pmap) = 2;
|
||||
|
||||
unsigned long
|
||||
PMAPPROC_GETPORT(pmap) = 3;
|
||||
|
||||
pmaplist_ptr
|
||||
PMAPPROC_DUMP(void) = 4;
|
||||
|
||||
rmtcallres
|
||||
PMAPPROC_CALLIT(rmtcallargs) = 5;
|
||||
} = 2;
|
||||
} = 100000;
|
||||
%
|
||||
#ifdef RPC_HDR
|
||||
%#define PMAPVERS_PROTO ((u_long)2)
|
||||
%#define PMAPVERS_ORIG ((u_long)1)
|
||||
%
|
||||
%#else /* ndef _KERNEL */
|
||||
%
|
||||
%#include <rpc/pmap_rmt.h>
|
||||
%
|
||||
%#ifdef __cplusplus
|
||||
%extern "C" {
|
||||
%#endif
|
||||
%
|
||||
%#define PMAPPORT 111
|
||||
%
|
||||
%struct pmap {
|
||||
% long unsigned pm_prog;
|
||||
% long unsigned pm_vers;
|
||||
% long unsigned pm_prot;
|
||||
% long unsigned pm_port;
|
||||
%};
|
||||
%typedef struct pmap PMAP;
|
||||
%extern bool_t xdr_pmap (XDR *, struct pmap *);
|
||||
%
|
||||
%struct pmaplist {
|
||||
% struct pmap pml_map;
|
||||
% struct pmaplist *pml_next;
|
||||
%};
|
||||
%typedef struct pmaplist PMAPLIST;
|
||||
%typedef struct pmaplist *pmaplist_ptr;
|
||||
%
|
||||
%
|
||||
%#ifdef __cplusplus
|
||||
%}
|
||||
%#endif
|
||||
%
|
||||
%#endif /* ndef _KERNEL */
|
||||
#endif
|
||||
|
235
freebsd/include/rpcsvc/rex.x
Normal file
235
freebsd/include/rpcsvc/rex.x
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Remote execution (rex) protocol specification
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)rex.x 1.3 87/09/18 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)rex.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const STRINGSIZE = 1024;
|
||||
typedef string rexstring<1024>;
|
||||
|
||||
/*
|
||||
* values to pass to REXPROC_SIGNAL
|
||||
*/
|
||||
const SIGINT = 2; /* interrupt */
|
||||
|
||||
/*
|
||||
* Values for rst_flags, below
|
||||
*/
|
||||
const REX_INTERACTIVE = 1; /* interactive mode */
|
||||
|
||||
struct rex_start {
|
||||
rexstring rst_cmd<>; /* list of command and args */
|
||||
rexstring rst_host; /* working directory host name */
|
||||
rexstring rst_fsname; /* working directory file system name */
|
||||
rexstring rst_dirwithin;/* working directory within file system */
|
||||
rexstring rst_env<>; /* list of environment */
|
||||
unsigned int rst_port0; /* port for stdin */
|
||||
unsigned int rst_port1; /* port for stdout */
|
||||
unsigned int rst_port2; /* port for stderr */
|
||||
unsigned int rst_flags; /* options - see const above */
|
||||
};
|
||||
|
||||
struct rex_result {
|
||||
int rlt_stat; /* integer status code */
|
||||
rexstring rlt_message; /* string message for human consumption */
|
||||
};
|
||||
|
||||
|
||||
struct sgttyb {
|
||||
unsigned four; /* always equals 4 */
|
||||
opaque chars[4];
|
||||
/* chars[0] == input speed */
|
||||
/* chars[1] == output speed */
|
||||
/* chars[2] == kill character */
|
||||
/* chars[3] == erase character */
|
||||
unsigned flags;
|
||||
};
|
||||
/* values for speeds above (baud rates) */
|
||||
const B0 = 0;
|
||||
const B50 = 1;
|
||||
const B75 = 2;
|
||||
const B110 = 3;
|
||||
const B134 = 4;
|
||||
const B150 = 5;
|
||||
const B200 = 6;
|
||||
const B300 = 7;
|
||||
const B600 = 8;
|
||||
const B1200 = 9;
|
||||
const B1800 = 10;
|
||||
const B2400 = 11;
|
||||
const B4800 = 12;
|
||||
const B9600 = 13;
|
||||
const B19200 = 14;
|
||||
const B38400 = 15;
|
||||
|
||||
/* values for flags above */
|
||||
const TANDEM = 0x00000001; /* send stopc on out q full */
|
||||
const CBREAK = 0x00000002; /* half-cooked mode */
|
||||
const LCASE = 0x00000004; /* simulate lower case */
|
||||
const ECHO = 0x00000008; /* echo input */
|
||||
const CRMOD = 0x00000010; /* map \r to \r\n on output */
|
||||
const RAW = 0x00000020; /* no i/o processing */
|
||||
const ODDP = 0x00000040; /* get/send odd parity */
|
||||
const EVENP = 0x00000080; /* get/send even parity */
|
||||
const ANYP = 0x000000c0; /* get any parity/send none */
|
||||
const NLDELAY = 0x00000300; /* \n delay */
|
||||
const NL0 = 0x00000000;
|
||||
const NL1 = 0x00000100; /* tty 37 */
|
||||
const NL2 = 0x00000200; /* vt05 */
|
||||
const NL3 = 0x00000300;
|
||||
const TBDELAY = 0x00000c00; /* horizontal tab delay */
|
||||
const TAB0 = 0x00000000;
|
||||
const TAB1 = 0x00000400; /* tty 37 */
|
||||
const TAB2 = 0x00000800;
|
||||
const XTABS = 0x00000c00; /* expand tabs on output */
|
||||
const CRDELAY = 0x00003000; /* \r delay */
|
||||
const CR0 = 0x00000000;
|
||||
const CR1 = 0x00001000; /* tn 300 */
|
||||
const CR2 = 0x00002000; /* tty 37 */
|
||||
const CR3 = 0x00003000; /* concept 100 */
|
||||
const VTDELAY = 0x00004000; /* vertical tab delay */
|
||||
const FF0 = 0x00000000;
|
||||
const FF1 = 0x00004000; /* tty 37 */
|
||||
const BSDELAY = 0x00008000; /* \b delay */
|
||||
const BS0 = 0x00000000;
|
||||
const BS1 = 0x00008000;
|
||||
const CRTBS = 0x00010000; /* do backspacing for crt */
|
||||
const PRTERA = 0x00020000; /* \ ... / erase */
|
||||
const CRTERA = 0x00040000; /* " \b " to wipe out char */
|
||||
const TILDE = 0x00080000; /* hazeltine tilde kludge */
|
||||
const MDMBUF = 0x00100000; /* start/stop output on carrier intr */
|
||||
const LITOUT = 0x00200000; /* literal output */
|
||||
const TOSTOP = 0x00400000; /* SIGTTOU on background output */
|
||||
const FLUSHO = 0x00800000; /* flush output to terminal */
|
||||
const NOHANG = 0x01000000; /* no SIGHUP on carrier drop */
|
||||
const L001000 = 0x02000000;
|
||||
const CRTKIL = 0x04000000; /* kill line with " \b " */
|
||||
const PASS8 = 0x08000000;
|
||||
const CTLECH = 0x10000000; /* echo control chars as ^X */
|
||||
const PENDIN = 0x20000000; /* tp->t_rawq needs reread */
|
||||
const DECCTQ = 0x40000000; /* only ^Q starts after ^S */
|
||||
const NOFLSH = 0x80000000; /* no output flush on signal */
|
||||
|
||||
struct tchars {
|
||||
unsigned six; /* always equals 6 */
|
||||
opaque chars[6];
|
||||
/* chars[0] == interrupt char */
|
||||
/* chars[1] == quit char */
|
||||
/* chars[2] == start output char */
|
||||
/* chars[3] == stop output char */
|
||||
/* chars[4] == end-of-file char */
|
||||
/* chars[5] == input delimeter (like nl) */
|
||||
};
|
||||
|
||||
struct ltchars {
|
||||
unsigned six; /* always equals 6 */
|
||||
opaque chars[6];
|
||||
/* chars[0] == stop process signal */
|
||||
/* chars[1] == delayed stop process signal */
|
||||
/* chars[2] == reprint line */
|
||||
/* chars[3] == flush output */
|
||||
/* chars[4] == word erase */
|
||||
/* chars[5] == literal next character */
|
||||
unsigned mode;
|
||||
};
|
||||
|
||||
struct rex_ttysize {
|
||||
int ts_lines;
|
||||
int ts_cols;
|
||||
};
|
||||
|
||||
struct rex_ttymode {
|
||||
sgttyb basic; /* standard unix tty flags */
|
||||
tchars more; /* interrupt, kill characters, etc. */
|
||||
ltchars yetmore; /* special Berkeley characters */
|
||||
unsigned andmore; /* and Berkeley modes */
|
||||
};
|
||||
|
||||
/* values for andmore above */
|
||||
const LCRTBS = 0x0001; /* do backspacing for crt */
|
||||
const LPRTERA = 0x0002; /* \ ... / erase */
|
||||
const LCRTERA = 0x0004; /* " \b " to wipe out char */
|
||||
const LTILDE = 0x0008; /* hazeltine tilde kludge */
|
||||
const LMDMBUF = 0x0010; /* start/stop output on carrier intr */
|
||||
const LLITOUT = 0x0020; /* literal output */
|
||||
const LTOSTOP = 0x0040; /* SIGTTOU on background output */
|
||||
const LFLUSHO = 0x0080; /* flush output to terminal */
|
||||
const LNOHANG = 0x0100; /* no SIGHUP on carrier drop */
|
||||
const LL001000 = 0x0200;
|
||||
const LCRTKIL = 0x0400; /* kill line with " \b " */
|
||||
const LPASS8 = 0x0800;
|
||||
const LCTLECH = 0x1000; /* echo control chars as ^X */
|
||||
const LPENDIN = 0x2000; /* needs reread */
|
||||
const LDECCTQ = 0x4000; /* only ^Q starts after ^S */
|
||||
const LNOFLSH = 0x8000; /* no output flush on signal */
|
||||
|
||||
program REXPROG {
|
||||
version REXVERS {
|
||||
|
||||
/*
|
||||
* Start remote execution
|
||||
*/
|
||||
rex_result
|
||||
REXPROC_START(rex_start) = 1;
|
||||
|
||||
/*
|
||||
* Wait for remote execution to terminate
|
||||
*/
|
||||
rex_result
|
||||
REXPROC_WAIT(void) = 2;
|
||||
|
||||
/*
|
||||
* Send tty modes
|
||||
*/
|
||||
void
|
||||
REXPROC_MODES(rex_ttymode) = 3;
|
||||
|
||||
/*
|
||||
* Send window size change
|
||||
*/
|
||||
void
|
||||
REXPROC_WINCH(rex_ttysize) = 4;
|
||||
|
||||
/*
|
||||
* Send other signal
|
||||
*/
|
||||
void
|
||||
REXPROC_SIGNAL(int) = 5;
|
||||
} = 1;
|
||||
} = 100017;
|
123
freebsd/include/rpcsvc/rnusers.x
Normal file
123
freebsd/include/rpcsvc/rnusers.x
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Find out about remote users
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)rnusers.x 1.2 87/09/20 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)rnusers.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const MAXUSERS = 100;
|
||||
const MAXUTLEN = 256;
|
||||
|
||||
struct utmp {
|
||||
string ut_line<MAXUTLEN>;
|
||||
string ut_name<MAXUTLEN>;
|
||||
string ut_host<MAXUTLEN>;
|
||||
int ut_time;
|
||||
};
|
||||
|
||||
|
||||
struct utmpidle {
|
||||
utmp ui_utmp;
|
||||
unsigned int ui_idle;
|
||||
};
|
||||
|
||||
typedef utmp utmparr<MAXUSERS>;
|
||||
|
||||
typedef utmpidle utmpidlearr<MAXUSERS>;
|
||||
|
||||
const RUSERS_MAXUSERLEN = 32;
|
||||
const RUSERS_MAXLINELEN = 32;
|
||||
const RUSERS_MAXHOSTLEN = 257;
|
||||
|
||||
struct rusers_utmp {
|
||||
string ut_user<RUSERS_MAXUSERLEN>; /* aka ut_name */
|
||||
string ut_line<RUSERS_MAXLINELEN>; /* device */
|
||||
string ut_host<RUSERS_MAXHOSTLEN>; /* host user logged on from */
|
||||
int ut_type; /* type of entry */
|
||||
int ut_time; /* time entry was made */
|
||||
unsigned int ut_idle; /* minutes idle */
|
||||
};
|
||||
|
||||
typedef rusers_utmp utmp_array<>;
|
||||
|
||||
program RUSERSPROG {
|
||||
/*
|
||||
* Old version does not include idle information
|
||||
*/
|
||||
version RUSERSVERS_ORIG {
|
||||
int
|
||||
RUSERSPROC_NUM(void) = 1;
|
||||
|
||||
utmparr
|
||||
RUSERSPROC_NAMES(void) = 2;
|
||||
|
||||
utmparr
|
||||
RUSERSPROC_ALLNAMES(void) = 3;
|
||||
} = 1;
|
||||
|
||||
/*
|
||||
* Includes idle information
|
||||
*/
|
||||
version RUSERSVERS_IDLE {
|
||||
int
|
||||
RUSERSPROC_NUM(void) = 1;
|
||||
|
||||
utmpidlearr
|
||||
RUSERSPROC_NAMES(void) = 2;
|
||||
|
||||
utmpidlearr
|
||||
RUSERSPROC_ALLNAMES(void) = 3;
|
||||
} = 2;
|
||||
|
||||
/*
|
||||
* Version 3 rusers procedures (from Solaris).
|
||||
* (Thanks a lot Sun.)
|
||||
*/
|
||||
version RUSERSVERS_3 {
|
||||
int
|
||||
RUSERSPROC_NUM(void) = 1;
|
||||
|
||||
utmp_array
|
||||
RUSERSPROC_NAMES(void) = 2;
|
||||
|
||||
utmp_array
|
||||
RUSERSPROC_ALLNAMES(void) = 3;
|
||||
} = 3;
|
||||
|
||||
} = 100002;
|
||||
|
67
freebsd/include/rpcsvc/rquota.x
Normal file
67
freebsd/include/rpcsvc/rquota.x
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Remote quota protocol
|
||||
* Requires unix authentication
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)rquota.x 1.2 87/09/20 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)rquota.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const RQ_PATHLEN = 1024;
|
||||
|
||||
struct getquota_args {
|
||||
string gqa_pathp<RQ_PATHLEN>; /* path to filesystem of interest */
|
||||
int gqa_uid; /* inquire about quota for uid */
|
||||
};
|
||||
|
||||
/*
|
||||
* remote quota structure
|
||||
*/
|
||||
struct rquota {
|
||||
int rq_bsize; /* block size for block counts */
|
||||
bool rq_active; /* indicates whether quota is active */
|
||||
unsigned int rq_bhardlimit; /* absolute limit on disk blks alloc */
|
||||
unsigned int rq_bsoftlimit; /* preferred limit on disk blks */
|
||||
unsigned int rq_curblocks; /* current block count */
|
||||
unsigned int rq_fhardlimit; /* absolute limit on allocated files */
|
||||
unsigned int rq_fsoftlimit; /* preferred file limit */
|
||||
unsigned int rq_curfiles; /* current # allocated files */
|
||||
unsigned int rq_btimeleft; /* time left for excessive disk use */
|
||||
unsigned int rq_ftimeleft; /* time left for excessive files */
|
||||
};
|
||||
|
||||
enum gqr_status {
|
||||
Q_OK = 1, /* quota returned */
|
||||
Q_NOQUOTA = 2, /* noquota for uid */
|
||||
Q_EPERM = 3 /* no permission to access quota */
|
||||
};
|
||||
|
||||
union getquota_rslt switch (gqr_status status) {
|
||||
case Q_OK:
|
||||
rquota gqr_rquota; /* valid if status == Q_OK */
|
||||
case Q_NOQUOTA:
|
||||
void;
|
||||
case Q_EPERM:
|
||||
void;
|
||||
};
|
||||
|
||||
program RQUOTAPROG {
|
||||
version RQUOTAVERS {
|
||||
/*
|
||||
* Get all quotas
|
||||
*/
|
||||
getquota_rslt
|
||||
RQUOTAPROC_GETQUOTA(getquota_args) = 1;
|
||||
|
||||
/*
|
||||
* Get active quotas only
|
||||
*/
|
||||
getquota_rslt
|
||||
RQUOTAPROC_GETACTIVEQUOTA(getquota_args) = 2;
|
||||
} = 1;
|
||||
} = 100011;
|
158
freebsd/include/rpcsvc/rstat.x
Normal file
158
freebsd/include/rpcsvc/rstat.x
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Gather statistics on remote machines
|
||||
*/
|
||||
|
||||
#ifdef RPC_HDR
|
||||
|
||||
%#ifndef FSCALE
|
||||
%/*
|
||||
% * Scale factor for scaled integers used to count load averages.
|
||||
% */
|
||||
%#define FSHIFT 8 /* bits to right of fixed binary point */
|
||||
%#define FSCALE (1<<FSHIFT)
|
||||
%
|
||||
%#endif /* ndef FSCALE */
|
||||
|
||||
#else
|
||||
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)rstat.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)rstat.x 2.2 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
|
||||
#endif /* def RPC_HDR */
|
||||
|
||||
const RSTAT_CPUSTATES = 4;
|
||||
const RSTAT_DK_NDRIVE = 4;
|
||||
|
||||
/*
|
||||
* GMT since 0:00, January 1, 1970
|
||||
*/
|
||||
struct rstat_timeval {
|
||||
unsigned int tv_sec; /* seconds */
|
||||
unsigned int tv_usec; /* and microseconds */
|
||||
};
|
||||
|
||||
struct statstime { /* RSTATVERS_TIME */
|
||||
int cp_time[RSTAT_CPUSTATES];
|
||||
int dk_xfer[RSTAT_DK_NDRIVE];
|
||||
unsigned int v_pgpgin; /* these are cumulative sum */
|
||||
unsigned int v_pgpgout;
|
||||
unsigned int v_pswpin;
|
||||
unsigned int v_pswpout;
|
||||
unsigned int v_intr;
|
||||
int if_ipackets;
|
||||
int if_ierrors;
|
||||
int if_oerrors;
|
||||
int if_collisions;
|
||||
unsigned int v_swtch;
|
||||
int avenrun[3]; /* scaled by FSCALE */
|
||||
rstat_timeval boottime;
|
||||
rstat_timeval curtime;
|
||||
int if_opackets;
|
||||
};
|
||||
|
||||
struct statsswtch { /* RSTATVERS_SWTCH */
|
||||
int cp_time[RSTAT_CPUSTATES];
|
||||
int dk_xfer[RSTAT_DK_NDRIVE];
|
||||
unsigned int v_pgpgin; /* these are cumulative sum */
|
||||
unsigned int v_pgpgout;
|
||||
unsigned int v_pswpin;
|
||||
unsigned int v_pswpout;
|
||||
unsigned int v_intr;
|
||||
int if_ipackets;
|
||||
int if_ierrors;
|
||||
int if_oerrors;
|
||||
int if_collisions;
|
||||
unsigned int v_swtch;
|
||||
unsigned int avenrun[3];/* scaled by FSCALE */
|
||||
rstat_timeval boottime;
|
||||
int if_opackets;
|
||||
};
|
||||
|
||||
struct stats { /* RSTATVERS_ORIG */
|
||||
int cp_time[RSTAT_CPUSTATES];
|
||||
int dk_xfer[RSTAT_DK_NDRIVE];
|
||||
unsigned int v_pgpgin; /* these are cumulative sum */
|
||||
unsigned int v_pgpgout;
|
||||
unsigned int v_pswpin;
|
||||
unsigned int v_pswpout;
|
||||
unsigned int v_intr;
|
||||
int if_ipackets;
|
||||
int if_ierrors;
|
||||
int if_oerrors;
|
||||
int if_collisions;
|
||||
int if_opackets;
|
||||
};
|
||||
|
||||
|
||||
program RSTATPROG {
|
||||
/*
|
||||
* Newest version includes current time and context switching info
|
||||
*/
|
||||
version RSTATVERS_TIME {
|
||||
statstime
|
||||
RSTATPROC_STATS(void) = 1;
|
||||
|
||||
unsigned int
|
||||
RSTATPROC_HAVEDISK(void) = 2;
|
||||
} = 3;
|
||||
/*
|
||||
* Does not have current time
|
||||
*/
|
||||
version RSTATVERS_SWTCH {
|
||||
statsswtch
|
||||
RSTATPROC_STATS(void) = 1;
|
||||
|
||||
unsigned int
|
||||
RSTATPROC_HAVEDISK(void) = 2;
|
||||
} = 2;
|
||||
/*
|
||||
* Old version has no info about current time or context switching
|
||||
*/
|
||||
version RSTATVERS_ORIG {
|
||||
stats
|
||||
RSTATPROC_STATS(void) = 1;
|
||||
|
||||
unsigned int
|
||||
RSTATPROC_HAVEDISK(void) = 2;
|
||||
} = 1;
|
||||
} = 100001;
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%enum clnt_stat rstat(char *, struct statstime *);
|
||||
%int havedisk(char *);
|
||||
%
|
||||
#endif
|
57
freebsd/include/rpcsvc/rwall.x
Normal file
57
freebsd/include/rpcsvc/rwall.x
Normal file
@ -0,0 +1,57 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user or with the express written consent of
|
||||
% * Sun Microsystems, Inc.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
|
||||
%/*
|
||||
% * Copyright (c) 1984, 1990 by Sun Microsystems, Inc.
|
||||
% */
|
||||
%
|
||||
%/* from @(#)rwall.x 1.6 91/03/11 TIRPC 1.0 */
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%#ifndef _rpcsvc_rwall_h
|
||||
%#define _rpcsvc_rwall_h
|
||||
%
|
||||
%typedef char *wrapstring;
|
||||
%
|
||||
#endif
|
||||
|
||||
program WALLPROG {
|
||||
version WALLVERS {
|
||||
void
|
||||
WALLPROC_WALL(wrapstring) = 2;
|
||||
|
||||
} = 1;
|
||||
} = 100008;
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%#endif /* ! _rpcsvc_rwall_h */
|
||||
#endif
|
125
freebsd/include/rpcsvc/sm_inter.x
Normal file
125
freebsd/include/rpcsvc/sm_inter.x
Normal file
@ -0,0 +1,125 @@
|
||||
/* @(#)sm_inter.x 2.2 88/08/01 4.0 RPCSRC */
|
||||
/* @(#)sm_inter.x 1.7 87/06/24 Copyr 1987 Sun Micro */
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Status monitor protocol specification
|
||||
* Copyright (C) 1986 Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
program SM_PROG {
|
||||
version SM_VERS {
|
||||
/* res_stat = stat_succ if status monitor agrees to monitor */
|
||||
/* res_stat = stat_fail if status monitor cannot monitor */
|
||||
/* if res_stat == stat_succ, state = state number of site sm_name */
|
||||
struct sm_stat_res SM_STAT(struct sm_name) = 1;
|
||||
|
||||
/* res_stat = stat_succ if status monitor agrees to monitor */
|
||||
/* res_stat = stat_fail if status monitor cannot monitor */
|
||||
/* stat consists of state number of local site */
|
||||
struct sm_stat_res SM_MON(struct mon) = 2;
|
||||
|
||||
/* stat consists of state number of local site */
|
||||
struct sm_stat SM_UNMON(struct mon_id) = 3;
|
||||
|
||||
/* stat consists of state number of local site */
|
||||
struct sm_stat SM_UNMON_ALL(struct my_id) = 4;
|
||||
|
||||
void SM_SIMU_CRASH(void) = 5;
|
||||
void SM_NOTIFY(struct stat_chge) = 6;
|
||||
|
||||
} = 1;
|
||||
} = 100024;
|
||||
|
||||
const SM_MAXSTRLEN = 1024;
|
||||
|
||||
struct sm_name {
|
||||
string mon_name<SM_MAXSTRLEN>;
|
||||
};
|
||||
|
||||
struct my_id {
|
||||
string my_name<SM_MAXSTRLEN>; /* name of the site iniates the monitoring request*/
|
||||
int my_prog; /* rpc program # of the requesting process */
|
||||
int my_vers; /* rpc version # of the requesting process */
|
||||
int my_proc; /* rpc procedure # of the requesting process */
|
||||
};
|
||||
|
||||
struct mon_id {
|
||||
string mon_name<SM_MAXSTRLEN>; /* name of the site to be monitored */
|
||||
struct my_id my_id;
|
||||
};
|
||||
|
||||
|
||||
struct mon{
|
||||
struct mon_id mon_id;
|
||||
opaque priv[16]; /* private information to store at monitor for requesting process */
|
||||
};
|
||||
|
||||
struct stat_chge {
|
||||
string mon_name<SM_MAXSTRLEN>; /* name of the site that had the state change */
|
||||
int state;
|
||||
};
|
||||
|
||||
/*
|
||||
* state # of status monitor monitonically increases each time
|
||||
* status of the site changes:
|
||||
* an even number (>= 0) indicates the site is down and
|
||||
* an odd number (> 0) indicates the site is up;
|
||||
*/
|
||||
struct sm_stat {
|
||||
int state; /* state # of status monitor */
|
||||
};
|
||||
|
||||
enum sm_res {
|
||||
stat_succ = 0, /* status monitor agrees to monitor */
|
||||
stat_fail = 1 /* status monitor cannot monitor */
|
||||
};
|
||||
|
||||
struct sm_stat_res {
|
||||
sm_res res_stat;
|
||||
int state;
|
||||
};
|
||||
|
||||
/*
|
||||
* structure of the status message sent back by the status monitor
|
||||
* when monitor site status changes
|
||||
*/
|
||||
struct sm_status {
|
||||
string mon_name<SM_MAXSTRLEN>;
|
||||
int state;
|
||||
opaque priv[16]; /* stored private information */
|
||||
};
|
90
freebsd/include/rpcsvc/spray.x
Normal file
90
freebsd/include/rpcsvc/spray.x
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Spray a server with packets
|
||||
* Useful for testing flakiness of network interfaces
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)spray.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)spray.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const SPRAYMAX = 8845; /* max amount can spray */
|
||||
|
||||
/*
|
||||
* GMT since 0:00, 1 January 1970
|
||||
*/
|
||||
struct spraytimeval {
|
||||
unsigned int sec;
|
||||
unsigned int usec;
|
||||
};
|
||||
|
||||
/*
|
||||
* spray statistics
|
||||
*/
|
||||
struct spraycumul {
|
||||
unsigned int counter;
|
||||
spraytimeval clock;
|
||||
};
|
||||
|
||||
/*
|
||||
* spray data
|
||||
*/
|
||||
typedef opaque sprayarr<SPRAYMAX>;
|
||||
|
||||
program SPRAYPROG {
|
||||
version SPRAYVERS {
|
||||
/*
|
||||
* Just throw away the data and increment the counter
|
||||
* This call never returns, so the client should always
|
||||
* time it out.
|
||||
*/
|
||||
void
|
||||
SPRAYPROC_SPRAY(sprayarr) = 1;
|
||||
|
||||
/*
|
||||
* Get the value of the counter and elapsed time since
|
||||
* last CLEAR.
|
||||
*/
|
||||
spraycumul
|
||||
SPRAYPROC_GET(void) = 2;
|
||||
|
||||
/*
|
||||
* Clear the counter and reset the elapsed time
|
||||
*/
|
||||
void
|
||||
SPRAYPROC_CLEAR(void) = 3;
|
||||
} = 1;
|
||||
} = 100012;
|
377
freebsd/include/rpcsvc/yp.x
Normal file
377
freebsd/include/rpcsvc/yp.x
Normal file
@ -0,0 +1,377 @@
|
||||
/* @(#)yp.x 2.1 88/08/01 4.0 RPCSRC */
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* Protocol description file for the Yellow Pages Service
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
const YPMAXRECORD = 1024;
|
||||
const YPMAXDOMAIN = 64;
|
||||
const YPMAXMAP = 64;
|
||||
const YPMAXPEER = 64;
|
||||
|
||||
|
||||
enum ypstat {
|
||||
YP_TRUE = 1,
|
||||
YP_NOMORE = 2,
|
||||
YP_FALSE = 0,
|
||||
YP_NOMAP = -1,
|
||||
YP_NODOM = -2,
|
||||
YP_NOKEY = -3,
|
||||
YP_BADOP = -4,
|
||||
YP_BADDB = -5,
|
||||
YP_YPERR = -6,
|
||||
YP_BADARGS = -7,
|
||||
YP_VERS = -8
|
||||
};
|
||||
|
||||
|
||||
enum ypxfrstat {
|
||||
YPXFR_SUCC = 1,
|
||||
YPXFR_AGE = 2,
|
||||
YPXFR_NOMAP = -1,
|
||||
YPXFR_NODOM = -2,
|
||||
YPXFR_RSRC = -3,
|
||||
YPXFR_RPC = -4,
|
||||
YPXFR_MADDR = -5,
|
||||
YPXFR_YPERR = -6,
|
||||
YPXFR_BADARGS = -7,
|
||||
YPXFR_DBM = -8,
|
||||
YPXFR_FILE = -9,
|
||||
YPXFR_SKEW = -10,
|
||||
YPXFR_CLEAR = -11,
|
||||
YPXFR_FORCE = -12,
|
||||
YPXFR_XFRERR = -13,
|
||||
YPXFR_REFUSED = -14
|
||||
};
|
||||
|
||||
|
||||
typedef string domainname<YPMAXDOMAIN>;
|
||||
typedef string mapname<YPMAXMAP>;
|
||||
typedef string peername<YPMAXPEER>;
|
||||
typedef opaque keydat<YPMAXRECORD>;
|
||||
typedef opaque valdat<YPMAXRECORD>;
|
||||
|
||||
|
||||
struct ypmap_parms {
|
||||
domainname domain;
|
||||
mapname map;
|
||||
unsigned int ordernum;
|
||||
peername peer;
|
||||
};
|
||||
|
||||
struct ypreq_key {
|
||||
domainname domain;
|
||||
mapname map;
|
||||
keydat key;
|
||||
};
|
||||
|
||||
struct ypreq_nokey {
|
||||
domainname domain;
|
||||
mapname map;
|
||||
};
|
||||
|
||||
struct ypreq_xfr {
|
||||
ypmap_parms map_parms;
|
||||
unsigned int transid;
|
||||
unsigned int prog;
|
||||
unsigned int port;
|
||||
};
|
||||
|
||||
|
||||
struct ypresp_val {
|
||||
ypstat stat;
|
||||
valdat val;
|
||||
};
|
||||
|
||||
struct ypresp_key_val {
|
||||
ypstat stat;
|
||||
#ifdef STUPID_SUN_BUG /* These are backwards */
|
||||
keydat key;
|
||||
valdat val;
|
||||
#else
|
||||
valdat val;
|
||||
keydat key;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct ypresp_master {
|
||||
ypstat stat;
|
||||
peername peer;
|
||||
};
|
||||
|
||||
struct ypresp_order {
|
||||
ypstat stat;
|
||||
unsigned int ordernum;
|
||||
};
|
||||
|
||||
union ypresp_all switch (bool more) {
|
||||
case TRUE:
|
||||
ypresp_key_val val;
|
||||
case FALSE:
|
||||
void;
|
||||
};
|
||||
|
||||
struct ypresp_xfr {
|
||||
unsigned int transid;
|
||||
ypxfrstat xfrstat;
|
||||
};
|
||||
|
||||
struct ypmaplist {
|
||||
mapname map;
|
||||
ypmaplist *next;
|
||||
};
|
||||
|
||||
struct ypresp_maplist {
|
||||
ypstat stat;
|
||||
ypmaplist *maps;
|
||||
};
|
||||
|
||||
enum yppush_status {
|
||||
YPPUSH_SUCC = 1, /* Success */
|
||||
YPPUSH_AGE = 2, /* Master's version not newer */
|
||||
YPPUSH_NOMAP = -1, /* Can't find server for map */
|
||||
YPPUSH_NODOM = -2, /* Domain not supported */
|
||||
YPPUSH_RSRC = -3, /* Local resource alloc failure */
|
||||
YPPUSH_RPC = -4, /* RPC failure talking to server */
|
||||
YPPUSH_MADDR = -5, /* Can't get master address */
|
||||
YPPUSH_YPERR = -6, /* YP server/map db error */
|
||||
YPPUSH_BADARGS = -7, /* Request arguments bad */
|
||||
YPPUSH_DBM = -8, /* Local dbm operation failed */
|
||||
YPPUSH_FILE = -9, /* Local file I/O operation failed */
|
||||
YPPUSH_SKEW = -10, /* Map version skew during transfer */
|
||||
YPPUSH_CLEAR = -11, /* Can't send "Clear" req to local ypserv */
|
||||
YPPUSH_FORCE = -12, /* No local order number in map use -f flag. */
|
||||
YPPUSH_XFRERR = -13, /* ypxfr error */
|
||||
YPPUSH_REFUSED = -14 /* Transfer request refused by ypserv */
|
||||
};
|
||||
|
||||
struct yppushresp_xfr {
|
||||
unsigned transid;
|
||||
yppush_status status;
|
||||
};
|
||||
|
||||
/*
|
||||
* Response structure and overall result status codes. Success and failure
|
||||
* represent two separate response message types.
|
||||
*/
|
||||
|
||||
enum ypbind_resptype {
|
||||
YPBIND_SUCC_VAL = 1,
|
||||
YPBIND_FAIL_VAL = 2
|
||||
};
|
||||
|
||||
struct ypbind_binding {
|
||||
opaque ypbind_binding_addr[4]; /* In network order */
|
||||
opaque ypbind_binding_port[2]; /* In network order */
|
||||
};
|
||||
|
||||
union ypbind_resp switch (ypbind_resptype ypbind_status) {
|
||||
case YPBIND_FAIL_VAL:
|
||||
unsigned ypbind_error;
|
||||
case YPBIND_SUCC_VAL:
|
||||
ypbind_binding ypbind_bindinfo;
|
||||
};
|
||||
|
||||
/* Detailed failure reason codes for response field ypbind_error*/
|
||||
|
||||
const YPBIND_ERR_ERR = 1; /* Internal error */
|
||||
const YPBIND_ERR_NOSERV = 2; /* No bound server for passed domain */
|
||||
const YPBIND_ERR_RESC = 3; /* System resource allocation failure */
|
||||
|
||||
|
||||
/*
|
||||
* Request data structure for ypbind "Set domain" procedure.
|
||||
*/
|
||||
struct ypbind_setdom {
|
||||
domainname ypsetdom_domain;
|
||||
ypbind_binding ypsetdom_binding;
|
||||
unsigned ypsetdom_vers;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* NIS v1 support for backwards compatibility
|
||||
*/
|
||||
enum ypreqtype {
|
||||
YPREQ_KEY = 1,
|
||||
YPREQ_NOKEY = 2,
|
||||
YPREQ_MAP_PARMS = 3
|
||||
};
|
||||
|
||||
enum ypresptype {
|
||||
YPRESP_VAL = 1,
|
||||
YPRESP_KEY_VAL = 2,
|
||||
YPRESP_MAP_PARMS = 3
|
||||
};
|
||||
|
||||
union yprequest switch (ypreqtype yp_reqtype) {
|
||||
case YPREQ_KEY:
|
||||
ypreq_key yp_req_keytype;
|
||||
case YPREQ_NOKEY:
|
||||
ypreq_nokey yp_req_nokeytype;
|
||||
case YPREQ_MAP_PARMS:
|
||||
ypmap_parms yp_req_map_parmstype;
|
||||
};
|
||||
|
||||
union ypresponse switch (ypresptype yp_resptype) {
|
||||
case YPRESP_VAL:
|
||||
ypresp_val yp_resp_valtype;
|
||||
case YPRESP_KEY_VAL:
|
||||
ypresp_key_val yp_resp_key_valtype;
|
||||
case YPRESP_MAP_PARMS:
|
||||
ypmap_parms yp_resp_map_parmstype;
|
||||
};
|
||||
|
||||
#if !defined(YPBIND_ONLY) && !defined(YPPUSH_ONLY)
|
||||
/*
|
||||
* YP access protocol
|
||||
*/
|
||||
program YPPROG {
|
||||
/*
|
||||
* NIS v1 support for backwards compatibility
|
||||
*/
|
||||
version YPOLDVERS {
|
||||
void
|
||||
YPOLDPROC_NULL(void) = 0;
|
||||
|
||||
bool
|
||||
YPOLDPROC_DOMAIN(domainname) = 1;
|
||||
|
||||
bool
|
||||
YPOLDPROC_DOMAIN_NONACK(domainname) = 2;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_MATCH(yprequest) = 3;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_FIRST(yprequest) = 4;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_NEXT(yprequest) = 5;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_POLL(yprequest) = 6;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_PUSH(yprequest) = 7;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_PULL(yprequest) = 8;
|
||||
|
||||
ypresponse
|
||||
YPOLDPROC_GET(yprequest) = 9;
|
||||
} = 1;
|
||||
|
||||
version YPVERS {
|
||||
void
|
||||
YPPROC_NULL(void) = 0;
|
||||
|
||||
bool
|
||||
YPPROC_DOMAIN(domainname) = 1;
|
||||
|
||||
bool
|
||||
YPPROC_DOMAIN_NONACK(domainname) = 2;
|
||||
|
||||
ypresp_val
|
||||
YPPROC_MATCH(ypreq_key) = 3;
|
||||
|
||||
ypresp_key_val
|
||||
#ifdef STUPID_SUN_BUG /* should be ypreq_nokey */
|
||||
YPPROC_FIRST(ypreq_key) = 4;
|
||||
#else
|
||||
YPPROC_FIRST(ypreq_nokey) = 4;
|
||||
#endif
|
||||
ypresp_key_val
|
||||
YPPROC_NEXT(ypreq_key) = 5;
|
||||
|
||||
ypresp_xfr
|
||||
YPPROC_XFR(ypreq_xfr) = 6;
|
||||
|
||||
void
|
||||
YPPROC_CLEAR(void) = 7;
|
||||
|
||||
ypresp_all
|
||||
YPPROC_ALL(ypreq_nokey) = 8;
|
||||
|
||||
ypresp_master
|
||||
YPPROC_MASTER(ypreq_nokey) = 9;
|
||||
|
||||
ypresp_order
|
||||
YPPROC_ORDER(ypreq_nokey) = 10;
|
||||
|
||||
ypresp_maplist
|
||||
YPPROC_MAPLIST(domainname) = 11;
|
||||
} = 2;
|
||||
} = 100004;
|
||||
#endif
|
||||
#if !defined(YPSERV_ONLY) && !defined(YPBIND_ONLY)
|
||||
/*
|
||||
* YPPUSHPROC_XFRRESP is the callback routine for result of YPPROC_XFR
|
||||
*/
|
||||
program YPPUSH_XFRRESPPROG {
|
||||
version YPPUSH_XFRRESPVERS {
|
||||
void
|
||||
YPPUSHPROC_NULL(void) = 0;
|
||||
#ifdef STUPID_SUN_BUG /* argument and return value are backwards */
|
||||
yppushresp_xfr
|
||||
YPPUSHPROC_XFRRESP(void) = 1;
|
||||
#else
|
||||
void
|
||||
YPPUSHPROC_XFRRESP(yppushresp_xfr) = 1;
|
||||
#endif
|
||||
} = 1;
|
||||
} = 0x40000000; /* transient: could be anything up to 0x5fffffff */
|
||||
#endif
|
||||
#if !defined(YPSERV_ONLY) && !defined(YPPUSH_ONLY)
|
||||
/*
|
||||
* YP binding protocol
|
||||
*/
|
||||
program YPBINDPROG {
|
||||
version YPBINDVERS {
|
||||
void
|
||||
YPBINDPROC_NULL(void) = 0;
|
||||
|
||||
ypbind_resp
|
||||
YPBINDPROC_DOMAIN(domainname) = 1;
|
||||
|
||||
void
|
||||
YPBINDPROC_SETDOM(ypbind_setdom) = 2;
|
||||
} = 2;
|
||||
} = 100007;
|
||||
|
||||
#endif
|
75
freebsd/include/rpcsvc/yppasswd.x
Normal file
75
freebsd/include/rpcsvc/yppasswd.x
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* YP password update protocol
|
||||
* Requires unix authentication
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#ifndef lint
|
||||
%/*static char sccsid[] = "from: @(#)yppasswd.x 1.1 87/04/13 Copyr 1987 Sun Micro";*/
|
||||
%/*static char sccsid[] = "from: @(#)yppasswd.x 2.1 88/08/01 4.0 RPCSRC";*/
|
||||
%#endif /* not lint */
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
program YPPASSWDPROG {
|
||||
version YPPASSWDVERS {
|
||||
/*
|
||||
* Update my passwd entry
|
||||
*/
|
||||
int
|
||||
YPPASSWDPROC_UPDATE(yppasswd) = 1;
|
||||
} = 1;
|
||||
} = 100009;
|
||||
|
||||
|
||||
struct x_passwd {
|
||||
string pw_name<>; /* username */
|
||||
string pw_passwd<>; /* encrypted password */
|
||||
int pw_uid; /* user id */
|
||||
int pw_gid; /* group id */
|
||||
string pw_gecos<>; /* in real life name */
|
||||
string pw_dir<>; /* home directory */
|
||||
string pw_shell<>; /* default shell */
|
||||
};
|
||||
|
||||
struct yppasswd {
|
||||
string oldpass<>; /* unencrypted old password */
|
||||
x_passwd newpw; /* new passwd entry */
|
||||
};
|
||||
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%extern int _yppasswd( char * , struct x_passwd * );
|
||||
%#define yppasswd(x,y) _yppasswd(x,y)
|
||||
#endif
|
86
freebsd/include/rpcsvc/ypupdate_prot.x
Normal file
86
freebsd/include/rpcsvc/ypupdate_prot.x
Normal file
@ -0,0 +1,86 @@
|
||||
%/*
|
||||
% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
% * unrestricted use provided that this legend is included on all tape
|
||||
% * media and as a part of the software program in whole or part. Users
|
||||
% * may copy or modify Sun RPC without charge, but are not authorized
|
||||
% * to license or distribute it to anyone else except as part of a product or
|
||||
% * program developed by the user or with the express written consent of
|
||||
% * Sun Microsystems, Inc.
|
||||
% *
|
||||
% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
% *
|
||||
% * Sun RPC is provided with no support and without any obligation on the
|
||||
% * part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
% * modification or enhancement.
|
||||
% *
|
||||
% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
% * OR ANY PART THEREOF.
|
||||
% *
|
||||
% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
% * or profits or other special, indirect and consequential damages, even if
|
||||
% * Sun has been advised of the possibility of such damages.
|
||||
% *
|
||||
% * Sun Microsystems, Inc.
|
||||
% * 2550 Garcia Avenue
|
||||
% * Mountain View, California 94043
|
||||
% */
|
||||
|
||||
%/*
|
||||
% * Copyright (c) 1986, 1990 by Sun Microsystems, Inc.
|
||||
% */
|
||||
%
|
||||
%/* from @(#)ypupdate_prot.x 1.3 91/03/11 TIRPC 1.0 */
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
%
|
||||
%/*
|
||||
% * Compiled from ypupdate_prot.x using rpcgen
|
||||
% * This is NOT source code!
|
||||
% * DO NOT EDIT THIS FILE!
|
||||
% */
|
||||
|
||||
/*
|
||||
* YP update service protocol
|
||||
*/
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%#ifndef _rpcsvc_ypupdate_prot_h
|
||||
%#define _rpcsvc_ypupdate_prot_h
|
||||
%
|
||||
#endif
|
||||
|
||||
const MAXMAPNAMELEN = 255;
|
||||
const MAXYPDATALEN = 1023;
|
||||
const MAXERRMSGLEN = 255;
|
||||
|
||||
program YPU_PROG {
|
||||
version YPU_VERS {
|
||||
u_int YPU_CHANGE(ypupdate_args) = 1;
|
||||
u_int YPU_INSERT(ypupdate_args) = 2;
|
||||
u_int YPU_DELETE(ypdelete_args) = 3;
|
||||
u_int YPU_STORE(ypupdate_args) = 4;
|
||||
} = 1;
|
||||
} = 100028;
|
||||
|
||||
typedef opaque yp_buf<MAXYPDATALEN>;
|
||||
|
||||
struct ypupdate_args {
|
||||
string mapname<MAXMAPNAMELEN>;
|
||||
yp_buf key;
|
||||
yp_buf datum;
|
||||
};
|
||||
|
||||
struct ypdelete_args {
|
||||
string mapname<MAXMAPNAMELEN>;
|
||||
yp_buf key;
|
||||
};
|
||||
|
||||
#ifdef RPC_HDR
|
||||
%
|
||||
%#endif /* !_rpcsvc_ypupdate_prot_h */
|
||||
#endif
|
169
freebsd/include/rpcsvc/ypxfrd.x
Normal file
169
freebsd/include/rpcsvc/ypxfrd.x
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996
|
||||
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Bill Paul.
|
||||
* 4. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This protocol definition file describes a file transfer
|
||||
* system used to very quickly move NIS maps from one host to
|
||||
* another. This is similar to what Sun does with their ypxfrd
|
||||
* protocol, but it must be stressed that this protocol is _NOT_
|
||||
* compatible with Sun's. There are a couple of reasons for this:
|
||||
*
|
||||
* 1) Sun's protocol is proprietary. The protocol definition is
|
||||
* not freely available in any of the SunRPC source distributions,
|
||||
* even though the NIS v2 protocol is.
|
||||
*
|
||||
* 2) The idea here is to transfer entire raw files rather than
|
||||
* sending just the records. Sun uses ndbm for its NIS map files,
|
||||
* while FreeBSD uses Berkeley DB. Both are hash databases, but the
|
||||
* formats are incompatible, making it impossible for them to
|
||||
* use each others' files. Even if FreeBSD adopted ndbm for its
|
||||
* database format, FreeBSD/i386 is a little-endian OS and
|
||||
* SunOS/SPARC is big-endian; ndbm is byte-order sensitive and
|
||||
* not very smart about it, which means an attempt to read a
|
||||
* database on a little-endian box that was created on a big-endian
|
||||
* box (or vice-versa) can cause the ndbm code to eat itself.
|
||||
* Luckily, Berkeley DB is able to deal with this situation in
|
||||
* a more graceful manner.
|
||||
*
|
||||
* While the protocol is incompatible, the idea is the same: we just open
|
||||
* up a TCP pipe to the client and transfer the raw map database
|
||||
* from the master server to the slave. This is many times faster than
|
||||
* the standard yppush/ypxfr transfer method since it saves us from
|
||||
* having to recreate the map databases via the DB library each time.
|
||||
* For example: creating a passwd database with 30,000 entries with yp_mkdb
|
||||
* can take a couple of minutes, but to just copy the file takes only a few
|
||||
* seconds.
|
||||
*/
|
||||
|
||||
#ifndef RPC_HDR
|
||||
%#include <sys/cdefs.h>
|
||||
%__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
/* XXX cribbed from yp.x */
|
||||
const _YPMAXRECORD = 1024;
|
||||
const _YPMAXDOMAIN = 64;
|
||||
const _YPMAXMAP = 64;
|
||||
const _YPMAXPEER = 64;
|
||||
|
||||
/* Suggested default -- not necesarrily the one used. */
|
||||
const YPXFRBLOCK = 32767;
|
||||
|
||||
/*
|
||||
* Possible return codes from the remote server.
|
||||
*/
|
||||
enum xfrstat {
|
||||
XFR_REQUEST_OK = 1, /* Transfer request granted */
|
||||
XFR_DENIED = 2, /* Transfer request denied */
|
||||
XFR_NOFILE = 3, /* Requested map file doesn't exist */
|
||||
XFR_ACCESS = 4, /* File exists, but I couldn't access it */
|
||||
XFR_BADDB = 5, /* File is not a hash database */
|
||||
XFR_READ_OK = 6, /* Block read successfully */
|
||||
XFR_READ_ERR = 7, /* Read error during transfer */
|
||||
XFR_DONE = 8, /* Transfer completed */
|
||||
XFR_DB_ENDIAN_MISMATCH = 9, /* Database byte order mismatch */
|
||||
XFR_DB_TYPE_MISMATCH = 10 /* Database type mismatch */
|
||||
};
|
||||
|
||||
/*
|
||||
* Database type specifications. The client can use this to ask
|
||||
* the server for a particular type of database or just take whatever
|
||||
* the server has to offer.
|
||||
*/
|
||||
enum xfr_db_type {
|
||||
XFR_DB_ASCII = 1, /* Flat ASCII text */
|
||||
XFR_DB_BSD_HASH = 2, /* Berkeley DB, hash method */
|
||||
XFR_DB_BSD_BTREE = 3, /* Berkeley DB, btree method */
|
||||
XFR_DB_BSD_RECNO = 4, /* Berkeley DB, recno method */
|
||||
XFR_DB_BSD_MPOOL = 5, /* Berkeley DB, mpool method */
|
||||
XFR_DB_BSD_NDBM = 6, /* Berkeley DB, hash, ndbm compat */
|
||||
XFR_DB_GNU_GDBM = 7, /* GNU GDBM */
|
||||
XFR_DB_DBM = 8, /* Old, deprecated dbm format */
|
||||
XFR_DB_NDBM = 9, /* ndbm format (used by Sun's NISv2) */
|
||||
XFR_DB_OPAQUE = 10, /* Mystery format -- just pass along */
|
||||
XFR_DB_ANY = 11, /* I'll take any format you've got */
|
||||
XFR_DB_UNKNOWN = 12 /* Unknown format */
|
||||
};
|
||||
|
||||
/*
|
||||
* Machine byte order specification. This allows the client to check
|
||||
* that it's copying a map database from a machine of similar byte sex.
|
||||
* This is necessary for handling database libraries that are fatally
|
||||
* byte order sensitive.
|
||||
*
|
||||
* The XFR_ENDIAN_ANY type is for use with the Berkeley DB database
|
||||
* formats; Berkeley DB is smart enough to make up for byte order
|
||||
* differences, so byte sex isn't important.
|
||||
*/
|
||||
enum xfr_byte_order {
|
||||
XFR_ENDIAN_BIG = 1, /* We want big endian */
|
||||
XFR_ENDIAN_LITTLE = 2, /* We want little endian */
|
||||
XFR_ENDIAN_ANY = 3 /* We'll take whatever you got */
|
||||
};
|
||||
|
||||
typedef string xfrdomain<_YPMAXDOMAIN>;
|
||||
typedef string xfrmap<_YPMAXMAP>;
|
||||
typedef string xfrmap_filename<_YPMAXMAP>; /* actual name of map file */
|
||||
|
||||
/*
|
||||
* Ask the remote ypxfrd for a map using this structure.
|
||||
* Note: we supply both a map name and a map file name. These are not
|
||||
* the same thing. In the case of ndbm, maps are stored in two files:
|
||||
* map.bykey.pag and may.bykey.dir. We may also have to deal with
|
||||
* file extensions (on the off chance that the remote server is supporting
|
||||
* multiple DB formats). To handle this, we tell the remote server both
|
||||
* what map we want and, in the case of ndbm, whether we want the .dir
|
||||
* or the .pag part. This name should not be a fully qualified path:
|
||||
* it's up to the remote server to decide which directories to look in.
|
||||
*/
|
||||
struct ypxfr_mapname {
|
||||
xfrmap xfrmap;
|
||||
xfrdomain xfrdomain;
|
||||
xfrmap_filename xfrmap_filename;
|
||||
xfr_db_type xfr_db_type;
|
||||
xfr_byte_order xfr_byte_order;
|
||||
};
|
||||
|
||||
/* Read response using this structure. */
|
||||
union xfr switch (bool ok) {
|
||||
case TRUE:
|
||||
opaque xfrblock_buf<>;
|
||||
case FALSE:
|
||||
xfrstat xfrstat;
|
||||
};
|
||||
|
||||
program YPXFRD_FREEBSD_PROG {
|
||||
version YPXFRD_FREEBSD_VERS {
|
||||
union xfr
|
||||
YPXFRD_GETMAP(ypxfr_mapname) = 1;
|
||||
} = 1;
|
||||
} = 600100069; /* 100069 + 60000000 -- 100069 is the Sun ypxfrd prog number */
|
499
freebsd/lib/libc/rpc/auth_des.c
Normal file
499
freebsd/lib/libc/rpc/auth_des.c
Normal file
@ -0,0 +1,499 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1988 by Sun Microsystems, Inc.
|
||||
*/
|
||||
/*
|
||||
* auth_des.c, client-side implementation of DES authentication
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <rpc/des_crypt.h>
|
||||
#include <syslog.h>
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_des.h>
|
||||
#include <rpc/clnt.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <sys/socket.h>
|
||||
#undef NIS
|
||||
#include <rpcsvc/nis.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)auth_des.c 2.2 88/07/29 4.0 RPCSRC; from 1.9 88/02/08 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#define USEC_PER_SEC 1000000
|
||||
#define RTIME_TIMEOUT 5 /* seconds to wait for sync */
|
||||
|
||||
#define AUTH_PRIVATE(auth) (struct ad_private *) auth->ah_private
|
||||
#define ALLOC(object_type) (object_type *) mem_alloc(sizeof(object_type))
|
||||
#define FREE(ptr, size) mem_free((char *)(ptr), (int) size)
|
||||
#define ATTEMPT(xdr_op) if (!(xdr_op)) return (FALSE)
|
||||
|
||||
extern bool_t xdr_authdes_cred( XDR *, struct authdes_cred *);
|
||||
extern bool_t xdr_authdes_verf( XDR *, struct authdes_verf *);
|
||||
extern int key_encryptsession_pk();
|
||||
|
||||
extern bool_t __rpc_get_time_offset(struct timeval *, nis_server *, char *,
|
||||
char **, char **);
|
||||
|
||||
/*
|
||||
* DES authenticator operations vector
|
||||
*/
|
||||
static void authdes_nextverf(AUTH *);
|
||||
static bool_t authdes_marshal(AUTH *, XDR *);
|
||||
static bool_t authdes_validate(AUTH *, struct opaque_auth *);
|
||||
static bool_t authdes_refresh(AUTH *, void *);
|
||||
static void authdes_destroy(AUTH *);
|
||||
|
||||
static struct auth_ops *authdes_ops(void);
|
||||
|
||||
/*
|
||||
* This struct is pointed to by the ah_private field of an "AUTH *"
|
||||
*/
|
||||
struct ad_private {
|
||||
char *ad_fullname; /* client's full name */
|
||||
u_int ad_fullnamelen; /* length of name, rounded up */
|
||||
char *ad_servername; /* server's full name */
|
||||
u_int ad_servernamelen; /* length of name, rounded up */
|
||||
u_int ad_window; /* client specified window */
|
||||
bool_t ad_dosync; /* synchronize? */
|
||||
struct netbuf ad_syncaddr; /* remote host to synch with */
|
||||
char *ad_timehost; /* remote host to synch with */
|
||||
struct timeval ad_timediff; /* server's time - client's time */
|
||||
u_int ad_nickname; /* server's nickname for client */
|
||||
struct authdes_cred ad_cred; /* storage for credential */
|
||||
struct authdes_verf ad_verf; /* storage for verifier */
|
||||
struct timeval ad_timestamp; /* timestamp sent */
|
||||
des_block ad_xkey; /* encrypted conversation key */
|
||||
u_char ad_pkey[1024]; /* Server's actual public key */
|
||||
char *ad_netid; /* Timehost netid */
|
||||
char *ad_uaddr; /* Timehost uaddr */
|
||||
nis_server *ad_nis_srvr; /* NIS+ server struct */
|
||||
};
|
||||
|
||||
AUTH *authdes_pk_seccreate(const char *, netobj *, u_int, const char *,
|
||||
const des_block *, nis_server *);
|
||||
|
||||
/*
|
||||
* documented version of authdes_seccreate
|
||||
*/
|
||||
/*
|
||||
servername: network name of server
|
||||
win: time to live
|
||||
timehost: optional hostname to sync with
|
||||
ckey: optional conversation key to use
|
||||
*/
|
||||
|
||||
AUTH *
|
||||
authdes_seccreate(const char *servername, const u_int win,
|
||||
const char *timehost, const des_block *ckey)
|
||||
{
|
||||
u_char pkey_data[1024];
|
||||
netobj pkey;
|
||||
AUTH *dummy;
|
||||
|
||||
if (! getpublickey(servername, (char *) pkey_data)) {
|
||||
syslog(LOG_ERR,
|
||||
"authdes_seccreate: no public key found for %s",
|
||||
servername);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
pkey.n_bytes = (char *) pkey_data;
|
||||
pkey.n_len = (u_int)strlen((char *)pkey_data) + 1;
|
||||
dummy = authdes_pk_seccreate(servername, &pkey, win, timehost,
|
||||
ckey, NULL);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
/*
|
||||
* Slightly modified version of authdessec_create which takes the public key
|
||||
* of the server principal as an argument. This spares us a call to
|
||||
* getpublickey() which in the nameserver context can cause a deadlock.
|
||||
*/
|
||||
AUTH *
|
||||
authdes_pk_seccreate(const char *servername, netobj *pkey, u_int window,
|
||||
const char *timehost, const des_block *ckey, nis_server *srvr)
|
||||
{
|
||||
AUTH *auth;
|
||||
struct ad_private *ad;
|
||||
char namebuf[MAXNETNAMELEN+1];
|
||||
|
||||
/*
|
||||
* Allocate everything now
|
||||
*/
|
||||
auth = ALLOC(AUTH);
|
||||
if (auth == NULL) {
|
||||
syslog(LOG_ERR, "authdes_pk_seccreate: out of memory");
|
||||
return (NULL);
|
||||
}
|
||||
ad = ALLOC(struct ad_private);
|
||||
if (ad == NULL) {
|
||||
syslog(LOG_ERR, "authdes_pk_seccreate: out of memory");
|
||||
goto failed;
|
||||
}
|
||||
ad->ad_fullname = ad->ad_servername = NULL; /* Sanity reasons */
|
||||
ad->ad_timehost = NULL;
|
||||
ad->ad_netid = NULL;
|
||||
ad->ad_uaddr = NULL;
|
||||
ad->ad_nis_srvr = NULL;
|
||||
ad->ad_timediff.tv_sec = 0;
|
||||
ad->ad_timediff.tv_usec = 0;
|
||||
memcpy(ad->ad_pkey, pkey->n_bytes, pkey->n_len);
|
||||
if (!getnetname(namebuf))
|
||||
goto failed;
|
||||
ad->ad_fullnamelen = RNDUP((u_int) strlen(namebuf));
|
||||
ad->ad_fullname = (char *)mem_alloc(ad->ad_fullnamelen + 1);
|
||||
ad->ad_servernamelen = strlen(servername);
|
||||
ad->ad_servername = (char *)mem_alloc(ad->ad_servernamelen + 1);
|
||||
|
||||
if (ad->ad_fullname == NULL || ad->ad_servername == NULL) {
|
||||
syslog(LOG_ERR, "authdes_seccreate: out of memory");
|
||||
goto failed;
|
||||
}
|
||||
if (timehost != NULL) {
|
||||
ad->ad_timehost = (char *)mem_alloc(strlen(timehost) + 1);
|
||||
if (ad->ad_timehost == NULL) {
|
||||
syslog(LOG_ERR, "authdes_seccreate: out of memory");
|
||||
goto failed;
|
||||
}
|
||||
memcpy(ad->ad_timehost, timehost, strlen(timehost) + 1);
|
||||
ad->ad_dosync = TRUE;
|
||||
} else if (srvr != NULL) {
|
||||
ad->ad_nis_srvr = srvr; /* transient */
|
||||
ad->ad_dosync = TRUE;
|
||||
} else {
|
||||
ad->ad_dosync = FALSE;
|
||||
}
|
||||
memcpy(ad->ad_fullname, namebuf, ad->ad_fullnamelen + 1);
|
||||
memcpy(ad->ad_servername, servername, ad->ad_servernamelen + 1);
|
||||
ad->ad_window = window;
|
||||
if (ckey == NULL) {
|
||||
if (key_gendes(&auth->ah_key) < 0) {
|
||||
syslog(LOG_ERR,
|
||||
"authdes_seccreate: keyserv(1m) is unable to generate session key");
|
||||
goto failed;
|
||||
}
|
||||
} else {
|
||||
auth->ah_key = *ckey;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up auth handle
|
||||
*/
|
||||
auth->ah_cred.oa_flavor = AUTH_DES;
|
||||
auth->ah_verf.oa_flavor = AUTH_DES;
|
||||
auth->ah_ops = authdes_ops();
|
||||
auth->ah_private = (caddr_t)ad;
|
||||
|
||||
if (!authdes_refresh(auth, NULL)) {
|
||||
goto failed;
|
||||
}
|
||||
ad->ad_nis_srvr = NULL; /* not needed any longer */
|
||||
return (auth);
|
||||
|
||||
failed:
|
||||
if (auth)
|
||||
FREE(auth, sizeof (AUTH));
|
||||
if (ad) {
|
||||
if (ad->ad_fullname)
|
||||
FREE(ad->ad_fullname, ad->ad_fullnamelen + 1);
|
||||
if (ad->ad_servername)
|
||||
FREE(ad->ad_servername, ad->ad_servernamelen + 1);
|
||||
if (ad->ad_timehost)
|
||||
FREE(ad->ad_timehost, strlen(ad->ad_timehost) + 1);
|
||||
if (ad->ad_netid)
|
||||
FREE(ad->ad_netid, strlen(ad->ad_netid) + 1);
|
||||
if (ad->ad_uaddr)
|
||||
FREE(ad->ad_uaddr, strlen(ad->ad_uaddr) + 1);
|
||||
FREE(ad, sizeof (struct ad_private));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Implement the five authentication operations
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* 1. Next Verifier
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
authdes_nextverf(AUTH *auth)
|
||||
{
|
||||
/* what the heck am I supposed to do??? */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 2. Marshal
|
||||
*/
|
||||
static bool_t
|
||||
authdes_marshal(AUTH *auth, XDR *xdrs)
|
||||
{
|
||||
/* LINTED pointer alignment */
|
||||
struct ad_private *ad = AUTH_PRIVATE(auth);
|
||||
struct authdes_cred *cred = &ad->ad_cred;
|
||||
struct authdes_verf *verf = &ad->ad_verf;
|
||||
des_block cryptbuf[2];
|
||||
des_block ivec;
|
||||
int status;
|
||||
int len;
|
||||
rpc_inline_t *ixdr;
|
||||
|
||||
/*
|
||||
* Figure out the "time", accounting for any time difference
|
||||
* with the server if necessary.
|
||||
*/
|
||||
(void) gettimeofday(&ad->ad_timestamp, (struct timezone *)NULL);
|
||||
ad->ad_timestamp.tv_sec += ad->ad_timediff.tv_sec;
|
||||
ad->ad_timestamp.tv_usec += ad->ad_timediff.tv_usec;
|
||||
while (ad->ad_timestamp.tv_usec >= USEC_PER_SEC) {
|
||||
ad->ad_timestamp.tv_usec -= USEC_PER_SEC;
|
||||
ad->ad_timestamp.tv_sec++;
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR the timestamp and possibly some other things, then
|
||||
* encrypt them.
|
||||
*/
|
||||
ixdr = (rpc_inline_t *)cryptbuf;
|
||||
IXDR_PUT_INT32(ixdr, ad->ad_timestamp.tv_sec);
|
||||
IXDR_PUT_INT32(ixdr, ad->ad_timestamp.tv_usec);
|
||||
if (ad->ad_cred.adc_namekind == ADN_FULLNAME) {
|
||||
IXDR_PUT_U_INT32(ixdr, ad->ad_window);
|
||||
IXDR_PUT_U_INT32(ixdr, ad->ad_window - 1);
|
||||
ivec.key.high = ivec.key.low = 0;
|
||||
status = cbc_crypt((char *)&auth->ah_key, (char *)cryptbuf,
|
||||
(u_int) 2 * sizeof (des_block),
|
||||
DES_ENCRYPT | DES_HW, (char *)&ivec);
|
||||
} else {
|
||||
status = ecb_crypt((char *)&auth->ah_key, (char *)cryptbuf,
|
||||
(u_int) sizeof (des_block),
|
||||
DES_ENCRYPT | DES_HW);
|
||||
}
|
||||
if (DES_FAILED(status)) {
|
||||
syslog(LOG_ERR, "authdes_marshal: DES encryption failure");
|
||||
return (FALSE);
|
||||
}
|
||||
ad->ad_verf.adv_xtimestamp = cryptbuf[0];
|
||||
if (ad->ad_cred.adc_namekind == ADN_FULLNAME) {
|
||||
ad->ad_cred.adc_fullname.window = cryptbuf[1].key.high;
|
||||
ad->ad_verf.adv_winverf = cryptbuf[1].key.low;
|
||||
} else {
|
||||
ad->ad_cred.adc_nickname = ad->ad_nickname;
|
||||
ad->ad_verf.adv_winverf = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize the credential and verifier into opaque
|
||||
* authentication data.
|
||||
*/
|
||||
if (ad->ad_cred.adc_namekind == ADN_FULLNAME) {
|
||||
len = ((1 + 1 + 2 + 1)*BYTES_PER_XDR_UNIT + ad->ad_fullnamelen);
|
||||
} else {
|
||||
len = (1 + 1)*BYTES_PER_XDR_UNIT;
|
||||
}
|
||||
|
||||
if ((ixdr = xdr_inline(xdrs, 2*BYTES_PER_XDR_UNIT))) {
|
||||
IXDR_PUT_INT32(ixdr, AUTH_DES);
|
||||
IXDR_PUT_INT32(ixdr, len);
|
||||
} else {
|
||||
ATTEMPT(xdr_putint32(xdrs, (int *)&auth->ah_cred.oa_flavor));
|
||||
ATTEMPT(xdr_putint32(xdrs, &len));
|
||||
}
|
||||
ATTEMPT(xdr_authdes_cred(xdrs, cred));
|
||||
|
||||
len = (2 + 1)*BYTES_PER_XDR_UNIT;
|
||||
if ((ixdr = xdr_inline(xdrs, 2*BYTES_PER_XDR_UNIT))) {
|
||||
IXDR_PUT_INT32(ixdr, AUTH_DES);
|
||||
IXDR_PUT_INT32(ixdr, len);
|
||||
} else {
|
||||
ATTEMPT(xdr_putint32(xdrs, (int *)&auth->ah_verf.oa_flavor));
|
||||
ATTEMPT(xdr_putint32(xdrs, &len));
|
||||
}
|
||||
ATTEMPT(xdr_authdes_verf(xdrs, verf));
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 3. Validate
|
||||
*/
|
||||
static bool_t
|
||||
authdes_validate(AUTH *auth, struct opaque_auth *rverf)
|
||||
{
|
||||
/* LINTED pointer alignment */
|
||||
struct ad_private *ad = AUTH_PRIVATE(auth);
|
||||
struct authdes_verf verf;
|
||||
int status;
|
||||
uint32_t *ixdr;
|
||||
des_block buf;
|
||||
|
||||
if (rverf->oa_length != (2 + 1) * BYTES_PER_XDR_UNIT) {
|
||||
return (FALSE);
|
||||
}
|
||||
/* LINTED pointer alignment */
|
||||
ixdr = (uint32_t *)rverf->oa_base;
|
||||
buf.key.high = (uint32_t)*ixdr++;
|
||||
buf.key.low = (uint32_t)*ixdr++;
|
||||
verf.adv_int_u = (uint32_t)*ixdr++;
|
||||
|
||||
/*
|
||||
* Decrypt the timestamp
|
||||
*/
|
||||
status = ecb_crypt((char *)&auth->ah_key, (char *)&buf,
|
||||
(u_int)sizeof (des_block), DES_DECRYPT | DES_HW);
|
||||
|
||||
if (DES_FAILED(status)) {
|
||||
syslog(LOG_ERR, "authdes_validate: DES decryption failure");
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* xdr the decrypted timestamp
|
||||
*/
|
||||
/* LINTED pointer alignment */
|
||||
ixdr = (uint32_t *)buf.c;
|
||||
verf.adv_timestamp.tv_sec = IXDR_GET_INT32(ixdr) + 1;
|
||||
verf.adv_timestamp.tv_usec = IXDR_GET_INT32(ixdr);
|
||||
|
||||
/*
|
||||
* validate
|
||||
*/
|
||||
if (bcmp((char *)&ad->ad_timestamp, (char *)&verf.adv_timestamp,
|
||||
sizeof(struct timeval)) != 0) {
|
||||
syslog(LOG_DEBUG, "authdes_validate: verifier mismatch");
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* We have a nickname now, let's use it
|
||||
*/
|
||||
ad->ad_nickname = verf.adv_nickname;
|
||||
ad->ad_cred.adc_namekind = ADN_NICKNAME;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 4. Refresh
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
authdes_refresh(AUTH *auth, void *dummy)
|
||||
{
|
||||
/* LINTED pointer alignment */
|
||||
struct ad_private *ad = AUTH_PRIVATE(auth);
|
||||
struct authdes_cred *cred = &ad->ad_cred;
|
||||
int ok;
|
||||
netobj pkey;
|
||||
|
||||
if (ad->ad_dosync) {
|
||||
ok = __rpc_get_time_offset(&ad->ad_timediff, ad->ad_nis_srvr,
|
||||
ad->ad_timehost, &(ad->ad_uaddr),
|
||||
&(ad->ad_netid));
|
||||
if (! ok) {
|
||||
/*
|
||||
* Hope the clocks are synced!
|
||||
*/
|
||||
ad->ad_dosync = 0;
|
||||
syslog(LOG_DEBUG,
|
||||
"authdes_refresh: unable to synchronize clock");
|
||||
}
|
||||
}
|
||||
ad->ad_xkey = auth->ah_key;
|
||||
pkey.n_bytes = (char *)(ad->ad_pkey);
|
||||
pkey.n_len = (u_int)strlen((char *)ad->ad_pkey) + 1;
|
||||
if (key_encryptsession_pk(ad->ad_servername, &pkey, &ad->ad_xkey) < 0) {
|
||||
syslog(LOG_INFO,
|
||||
"authdes_refresh: keyserv(1m) is unable to encrypt session key");
|
||||
return (FALSE);
|
||||
}
|
||||
cred->adc_fullname.key = ad->ad_xkey;
|
||||
cred->adc_namekind = ADN_FULLNAME;
|
||||
cred->adc_fullname.name = ad->ad_fullname;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 5. Destroy
|
||||
*/
|
||||
static void
|
||||
authdes_destroy(AUTH *auth)
|
||||
{
|
||||
/* LINTED pointer alignment */
|
||||
struct ad_private *ad = AUTH_PRIVATE(auth);
|
||||
|
||||
FREE(ad->ad_fullname, ad->ad_fullnamelen + 1);
|
||||
FREE(ad->ad_servername, ad->ad_servernamelen + 1);
|
||||
if (ad->ad_timehost)
|
||||
FREE(ad->ad_timehost, strlen(ad->ad_timehost) + 1);
|
||||
if (ad->ad_netid)
|
||||
FREE(ad->ad_netid, strlen(ad->ad_netid) + 1);
|
||||
if (ad->ad_uaddr)
|
||||
FREE(ad->ad_uaddr, strlen(ad->ad_uaddr) + 1);
|
||||
FREE(ad, sizeof (struct ad_private));
|
||||
FREE(auth, sizeof(AUTH));
|
||||
}
|
||||
|
||||
static struct auth_ops *
|
||||
authdes_ops(void)
|
||||
{
|
||||
static struct auth_ops ops;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
mutex_lock(&authdes_ops_lock);
|
||||
if (ops.ah_nextverf == NULL) {
|
||||
ops.ah_nextverf = authdes_nextverf;
|
||||
ops.ah_marshal = authdes_marshal;
|
||||
ops.ah_validate = authdes_validate;
|
||||
ops.ah_refresh = authdes_refresh;
|
||||
ops.ah_destroy = authdes_destroy;
|
||||
}
|
||||
mutex_unlock(&authdes_ops_lock);
|
||||
return (&ops);
|
||||
}
|
177
freebsd/lib/libc/rpc/auth_none.c
Normal file
177
freebsd/lib/libc/rpc/auth_none.c
Normal file
@ -0,0 +1,177 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* auth_none.c
|
||||
* Creates a client authentication handle for passing "null"
|
||||
* credentials and verifiers to remote systems.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#define MAX_MARSHAL_SIZE 20
|
||||
|
||||
/*
|
||||
* Authenticator operations routines
|
||||
*/
|
||||
|
||||
static bool_t authnone_marshal (AUTH *, XDR *);
|
||||
static void authnone_verf (AUTH *);
|
||||
static bool_t authnone_validate (AUTH *, struct opaque_auth *);
|
||||
static bool_t authnone_refresh (AUTH *, void *);
|
||||
static void authnone_destroy (AUTH *);
|
||||
|
||||
extern bool_t xdr_opaque_auth();
|
||||
|
||||
static struct auth_ops *authnone_ops();
|
||||
|
||||
static struct authnone_private {
|
||||
AUTH no_client;
|
||||
char marshalled_client[MAX_MARSHAL_SIZE];
|
||||
u_int mcnt;
|
||||
} *authnone_private;
|
||||
|
||||
AUTH *
|
||||
authnone_create()
|
||||
{
|
||||
struct authnone_private *ap = authnone_private;
|
||||
XDR xdr_stream;
|
||||
XDR *xdrs;
|
||||
|
||||
mutex_lock(&authnone_lock);
|
||||
if (ap == 0) {
|
||||
ap = (struct authnone_private *)calloc(1, sizeof (*ap));
|
||||
if (ap == 0) {
|
||||
mutex_unlock(&authnone_lock);
|
||||
return (0);
|
||||
}
|
||||
authnone_private = ap;
|
||||
}
|
||||
if (!ap->mcnt) {
|
||||
ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
|
||||
ap->no_client.ah_ops = authnone_ops();
|
||||
xdrs = &xdr_stream;
|
||||
xdrmem_create(xdrs, ap->marshalled_client,
|
||||
(u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
|
||||
(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
|
||||
(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
|
||||
ap->mcnt = XDR_GETPOS(xdrs);
|
||||
XDR_DESTROY(xdrs);
|
||||
}
|
||||
mutex_unlock(&authnone_lock);
|
||||
return (&ap->no_client);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
authnone_marshal(AUTH *client, XDR *xdrs)
|
||||
{
|
||||
struct authnone_private *ap;
|
||||
bool_t dummy;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
|
||||
ap = authnone_private;
|
||||
if (ap == NULL) {
|
||||
mutex_unlock(&authnone_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
|
||||
ap->marshalled_client, ap->mcnt);
|
||||
mutex_unlock(&authnone_lock);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
/* All these unused parameters are required to keep ANSI-C from grumbling */
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
authnone_verf(AUTH *client)
|
||||
{
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
authnone_validate(AUTH *client, struct opaque_auth *opaque)
|
||||
{
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
authnone_refresh(AUTH *client, void *dummy)
|
||||
{
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
authnone_destroy(AUTH *client)
|
||||
{
|
||||
}
|
||||
|
||||
static struct auth_ops *
|
||||
authnone_ops()
|
||||
{
|
||||
static struct auth_ops ops;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.ah_nextverf == NULL) {
|
||||
ops.ah_nextverf = authnone_verf;
|
||||
ops.ah_marshal = authnone_marshal;
|
||||
ops.ah_validate = authnone_validate;
|
||||
ops.ah_refresh = authnone_refresh;
|
||||
ops.ah_destroy = authnone_destroy;
|
||||
}
|
||||
mutex_unlock(&ops_lock);
|
||||
return (&ops);
|
||||
}
|
509
freebsd/lib/libc/rpc/auth_time.c
Normal file
509
freebsd/lib/libc/rpc/auth_time.c
Normal file
@ -0,0 +1,509 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* #pragma ident "@(#)auth_time.c 1.4 92/11/10 SMI" */
|
||||
|
||||
/*
|
||||
* auth_time.c
|
||||
*
|
||||
* This module contains the private function __rpc_get_time_offset()
|
||||
* which will return the difference in seconds between the local system's
|
||||
* notion of time and a remote server's notion of time. This must be
|
||||
* possible without calling any functions that may invoke the name
|
||||
* service. (netdir_getbyxxx, getXbyY, etc). The function is used in the
|
||||
* synchronize call of the authdes code to synchronize clocks between
|
||||
* NIS+ clients and their servers.
|
||||
*
|
||||
* Note to minimize the amount of duplicate code, portions of the
|
||||
* synchronize() function were folded into this code, and the synchronize
|
||||
* call becomes simply a wrapper around this function. Further, if this
|
||||
* function is called with a timehost it *DOES* recurse to the name
|
||||
* server so don't use it in that mode if you are doing name service code.
|
||||
*
|
||||
* Copyright (c) 1992 Sun Microsystems Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Side effects :
|
||||
* When called a client handle to a RPCBIND process is created
|
||||
* and destroyed. Two strings "netid" and "uaddr" are malloc'd
|
||||
* and returned. The SIGALRM processing is modified only if
|
||||
* needed to deal with TCP connections.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/signal.h>
|
||||
#include <rtems/bsd/sys/errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#include <rpc/rpcb_prot.h>
|
||||
#undef NIS
|
||||
#include <rpcsvc/nis.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
extern int _rpc_dtablesize( void );
|
||||
|
||||
#ifdef TESTING
|
||||
#define msg(x) printf("ERROR: %s\n", x)
|
||||
/* #define msg(x) syslog(LOG_ERR, "%s", x) */
|
||||
#else
|
||||
#define msg(x)
|
||||
#endif
|
||||
|
||||
static int saw_alarm = 0;
|
||||
|
||||
static void
|
||||
alarm_hndler(s)
|
||||
int s;
|
||||
{
|
||||
saw_alarm = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* The internet time server defines the epoch to be Jan 1, 1900
|
||||
* whereas UNIX defines it to be Jan 1, 1970. To adjust the result
|
||||
* from internet time-service time, into UNIX time we subtract the
|
||||
* following offset :
|
||||
*/
|
||||
#define NYEARS (1970 - 1900)
|
||||
#define TOFFSET ((u_long)60*60*24*(365*NYEARS + (NYEARS/4)))
|
||||
|
||||
|
||||
/*
|
||||
* Stolen from rpc.nisd:
|
||||
* Turn a 'universal address' into a struct sockaddr_in.
|
||||
* Bletch.
|
||||
*/
|
||||
static int uaddr_to_sockaddr(uaddr, sin)
|
||||
#ifdef foo
|
||||
endpoint *endpt;
|
||||
#endif
|
||||
char *uaddr;
|
||||
struct sockaddr_in *sin;
|
||||
{
|
||||
unsigned char p_bytes[2];
|
||||
int i;
|
||||
unsigned long a[6];
|
||||
|
||||
i = sscanf(uaddr, "%lu.%lu.%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2],
|
||||
&a[3], &a[4], &a[5]);
|
||||
|
||||
if (i < 6)
|
||||
return(1);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
sin->sin_addr.s_addr |= (a[i] & 0x000000FF) << (8 * i);
|
||||
|
||||
p_bytes[0] = (unsigned char)a[4] & 0x000000FF;
|
||||
p_bytes[1] = (unsigned char)a[5] & 0x000000FF;
|
||||
|
||||
sin->sin_family = AF_INET; /* always */
|
||||
bcopy((char *)&p_bytes, (char *)&sin->sin_port, 2);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* free_eps()
|
||||
*
|
||||
* Free the strings that were strduped into the eps structure.
|
||||
*/
|
||||
static void
|
||||
free_eps(eps, num)
|
||||
endpoint eps[];
|
||||
int num;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
free(eps[i].uaddr);
|
||||
free(eps[i].proto);
|
||||
free(eps[i].family);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_server()
|
||||
*
|
||||
* This function constructs a nis_server structure description for the
|
||||
* indicated hostname.
|
||||
*
|
||||
* NOTE: There is a chance we may end up recursing here due to the
|
||||
* fact that gethostbyname() could do an NIS search. Ideally, the
|
||||
* NIS+ server will call __rpc_get_time_offset() with the nis_server
|
||||
* structure already populated.
|
||||
*/
|
||||
static nis_server *
|
||||
get_server(sin, host, srv, eps, maxep)
|
||||
struct sockaddr_in *sin;
|
||||
char *host; /* name of the time host */
|
||||
nis_server *srv; /* nis_server struct to use. */
|
||||
endpoint eps[]; /* array of endpoints */
|
||||
int maxep; /* max array size */
|
||||
{
|
||||
char hname[256];
|
||||
int num_ep = 0, i;
|
||||
struct hostent *he;
|
||||
struct hostent dummy;
|
||||
char *ptr[2];
|
||||
endpoint *ep;
|
||||
|
||||
if (host == NULL && sin == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (sin == NULL) {
|
||||
he = gethostbyname(host);
|
||||
if (he == NULL)
|
||||
return(NULL);
|
||||
} else {
|
||||
he = &dummy;
|
||||
ptr[0] = (char *)&sin->sin_addr.s_addr;
|
||||
ptr[1] = NULL;
|
||||
dummy.h_addr_list = ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is lame. We go around once for TCP, then again
|
||||
* for UDP.
|
||||
*/
|
||||
for (i = 0, ep = eps; (he->h_addr_list[i] != NULL) && (num_ep < maxep);
|
||||
i++, ep++, num_ep++) {
|
||||
struct in_addr *a;
|
||||
|
||||
a = (struct in_addr *)he->h_addr_list[i];
|
||||
snprintf(hname, sizeof(hname), "%s.0.111", inet_ntoa(*a));
|
||||
ep->uaddr = strdup(hname);
|
||||
ep->family = strdup("inet");
|
||||
ep->proto = strdup("tcp");
|
||||
if (ep->uaddr == NULL || ep->family == NULL || ep->proto == NULL) {
|
||||
free_eps(eps, num_ep + 1);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; (he->h_addr_list[i] != NULL) && (num_ep < maxep);
|
||||
i++, ep++, num_ep++) {
|
||||
struct in_addr *a;
|
||||
|
||||
a = (struct in_addr *)he->h_addr_list[i];
|
||||
snprintf(hname, sizeof(hname), "%s.0.111", inet_ntoa(*a));
|
||||
ep->uaddr = strdup(hname);
|
||||
ep->family = strdup("inet");
|
||||
ep->proto = strdup("udp");
|
||||
if (ep->uaddr == NULL || ep->family == NULL || ep->proto == NULL) {
|
||||
free_eps(eps, num_ep + 1);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
srv->name = (nis_name) host;
|
||||
srv->ep.ep_len = num_ep;
|
||||
srv->ep.ep_val = eps;
|
||||
srv->key_type = NIS_PK_NONE;
|
||||
srv->pkey.n_bytes = NULL;
|
||||
srv->pkey.n_len = 0;
|
||||
return (srv);
|
||||
}
|
||||
|
||||
/*
|
||||
* __rpc_get_time_offset()
|
||||
*
|
||||
* This function uses a nis_server structure to contact the a remote
|
||||
* machine (as named in that structure) and returns the offset in time
|
||||
* between that machine and this one. This offset is returned in seconds
|
||||
* and may be positive or negative.
|
||||
*
|
||||
* The first time through, a lot of fiddling is done with the netconfig
|
||||
* stuff to find a suitable transport. The function is very aggressive
|
||||
* about choosing UDP or at worst TCP if it can. This is because
|
||||
* those transports support both the RCPBIND call and the internet
|
||||
* time service.
|
||||
*
|
||||
* Once through, *uaddr is set to the universal address of
|
||||
* the machine and *netid is set to the local netid for the transport
|
||||
* that uaddr goes with. On the second call, the netconfig stuff
|
||||
* is skipped and the uaddr/netid pair are used to fetch the netconfig
|
||||
* structure and to then contact the machine for the time.
|
||||
*
|
||||
* td = "server" - "client"
|
||||
*/
|
||||
int
|
||||
__rpc_get_time_offset(td, srv, thost, uaddr, netid)
|
||||
struct timeval *td; /* Time difference */
|
||||
nis_server *srv; /* NIS Server description */
|
||||
char *thost; /* if no server, this is the timehost */
|
||||
char **uaddr; /* known universal address */
|
||||
struct sockaddr_in *netid; /* known network identifier */
|
||||
{
|
||||
CLIENT *clnt; /* Client handle */
|
||||
endpoint *ep, /* useful endpoints */
|
||||
*useep = NULL; /* endpoint of xp */
|
||||
char *useua = NULL; /* uaddr of selected xp */
|
||||
int epl, i; /* counters */
|
||||
enum clnt_stat status; /* result of clnt_call */
|
||||
u_long thetime, delta;
|
||||
int needfree = 0;
|
||||
struct timeval tv;
|
||||
int time_valid;
|
||||
int udp_ep = -1, tcp_ep = -1;
|
||||
int a1, a2, a3, a4;
|
||||
char ut[64], ipuaddr[64];
|
||||
endpoint teps[32];
|
||||
nis_server tsrv;
|
||||
void (*oldsig)() = NULL; /* old alarm handler */
|
||||
struct sockaddr_in sin;
|
||||
socklen_t len;
|
||||
int s = RPC_ANYSOCK;
|
||||
int type = 0;
|
||||
|
||||
td->tv_sec = 0;
|
||||
td->tv_usec = 0;
|
||||
|
||||
/*
|
||||
* First check to see if we need to find and address for this
|
||||
* server.
|
||||
*/
|
||||
if (*uaddr == NULL) {
|
||||
if ((srv != NULL) && (thost != NULL)) {
|
||||
msg("both timehost and srv pointer used!");
|
||||
return (0);
|
||||
}
|
||||
if (! srv) {
|
||||
srv = get_server(netid, thost, &tsrv, teps, 32);
|
||||
if (srv == NULL) {
|
||||
msg("unable to contruct server data.");
|
||||
return (0);
|
||||
}
|
||||
needfree = 1; /* need to free data in endpoints */
|
||||
}
|
||||
|
||||
ep = srv->ep.ep_val;
|
||||
epl = srv->ep.ep_len;
|
||||
|
||||
/* Identify the TCP and UDP endpoints */
|
||||
for (i = 0;
|
||||
(i < epl) && ((udp_ep == -1) || (tcp_ep == -1)); i++) {
|
||||
if (strcasecmp(ep[i].proto, "udp") == 0)
|
||||
udp_ep = i;
|
||||
if (strcasecmp(ep[i].proto, "tcp") == 0)
|
||||
tcp_ep = i;
|
||||
}
|
||||
|
||||
/* Check to see if it is UDP or TCP */
|
||||
if (tcp_ep > -1) {
|
||||
useep = &ep[tcp_ep];
|
||||
useua = ep[tcp_ep].uaddr;
|
||||
type = SOCK_STREAM;
|
||||
} else if (udp_ep > -1) {
|
||||
useep = &ep[udp_ep];
|
||||
useua = ep[udp_ep].uaddr;
|
||||
type = SOCK_DGRAM;
|
||||
}
|
||||
|
||||
if (useep == NULL) {
|
||||
msg("no acceptable transport endpoints.");
|
||||
if (needfree)
|
||||
free_eps(teps, tsrv.ep.ep_len);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a sockaddr from the uaddr.
|
||||
*/
|
||||
if (*uaddr != NULL)
|
||||
useua = *uaddr;
|
||||
|
||||
/* Fixup test for NIS+ */
|
||||
sscanf(useua, "%d.%d.%d.%d.", &a1, &a2, &a3, &a4);
|
||||
sprintf(ipuaddr, "%d.%d.%d.%d.0.111", a1, a2, a3, a4);
|
||||
useua = &ipuaddr[0];
|
||||
|
||||
bzero((char *)&sin, sizeof(sin));
|
||||
if (uaddr_to_sockaddr(useua, &sin)) {
|
||||
msg("unable to translate uaddr to sockaddr.");
|
||||
if (needfree)
|
||||
free_eps(teps, tsrv.ep.ep_len);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the client handle to rpcbind. Note we always try
|
||||
* version 3 since that is the earliest version that supports
|
||||
* the RPCB_GETTIME call. Also it is the version that comes
|
||||
* standard with SVR4. Since most everyone supports TCP/IP
|
||||
* we could consider trying the rtime call first.
|
||||
*/
|
||||
clnt = clnttcp_create(&sin, RPCBPROG, RPCBVERS, &s, 0, 0);
|
||||
if (clnt == NULL) {
|
||||
msg("unable to create client handle to rpcbind.");
|
||||
if (needfree)
|
||||
free_eps(teps, tsrv.ep.ep_len);
|
||||
return (0);
|
||||
}
|
||||
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
time_valid = 0;
|
||||
status = clnt_call(clnt, RPCBPROC_GETTIME, (xdrproc_t)xdr_void, NULL,
|
||||
(xdrproc_t)xdr_u_long, &thetime, tv);
|
||||
/*
|
||||
* The only error we check for is anything but success. In
|
||||
* fact we could have seen PROGMISMATCH if talking to a 4.1
|
||||
* machine (pmap v2) or TIMEDOUT if the net was busy.
|
||||
*/
|
||||
if (status == RPC_SUCCESS)
|
||||
time_valid = 1;
|
||||
else {
|
||||
int save;
|
||||
|
||||
/* Blow away possible stale CLNT handle. */
|
||||
if (clnt != NULL) {
|
||||
clnt_destroy(clnt);
|
||||
clnt = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert PMAP address into timeservice address
|
||||
* We take advantage of the fact that we "know" what
|
||||
* the universal address looks like for inet transports.
|
||||
*
|
||||
* We also know that the internet timeservice is always
|
||||
* listening on port 37.
|
||||
*/
|
||||
sscanf(useua, "%d.%d.%d.%d.", &a1, &a2, &a3, &a4);
|
||||
sprintf(ut, "%d.%d.%d.%d.0.37", a1, a2, a3, a4);
|
||||
|
||||
if (uaddr_to_sockaddr(ut, &sin)) {
|
||||
msg("cannot convert timeservice uaddr to sockaddr.");
|
||||
goto error;
|
||||
}
|
||||
|
||||
s = _socket(AF_INET, type, 0);
|
||||
if (s == -1) {
|
||||
msg("unable to open fd to network.");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now depending on whether or not we're talking to
|
||||
* UDP we set a timeout or not.
|
||||
*/
|
||||
if (type == SOCK_DGRAM) {
|
||||
struct timeval timeout = { 20, 0 };
|
||||
struct sockaddr_in from;
|
||||
fd_set readfds;
|
||||
int res;
|
||||
|
||||
if (_sendto(s, &thetime, sizeof(thetime), 0,
|
||||
(struct sockaddr *)&sin, sizeof(sin)) == -1) {
|
||||
msg("udp : sendto failed.");
|
||||
goto error;
|
||||
}
|
||||
do {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(s, &readfds);
|
||||
res = _select(_rpc_dtablesize(), &readfds,
|
||||
(fd_set *)NULL, (fd_set *)NULL, &timeout);
|
||||
} while (res < 0 && errno == EINTR);
|
||||
if (res <= 0)
|
||||
goto error;
|
||||
len = sizeof(from);
|
||||
res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0,
|
||||
(struct sockaddr *)&from, &len);
|
||||
if (res == -1) {
|
||||
msg("recvfrom failed on udp transport.");
|
||||
goto error;
|
||||
}
|
||||
time_valid = 1;
|
||||
} else {
|
||||
int res;
|
||||
|
||||
oldsig = (void (*)())signal(SIGALRM, alarm_hndler);
|
||||
saw_alarm = 0; /* global tracking the alarm */
|
||||
alarm(20); /* only wait 20 seconds */
|
||||
res = _connect(s, (struct sockaddr *)&sin, sizeof(sin));
|
||||
if (res == -1) {
|
||||
msg("failed to connect to tcp endpoint.");
|
||||
goto error;
|
||||
}
|
||||
if (saw_alarm) {
|
||||
msg("alarm caught it, must be unreachable.");
|
||||
goto error;
|
||||
}
|
||||
res = _read(s, (char *)&thetime, sizeof(thetime));
|
||||
if (res != sizeof(thetime)) {
|
||||
if (saw_alarm)
|
||||
msg("timed out TCP call.");
|
||||
else
|
||||
msg("wrong size of results returned");
|
||||
|
||||
goto error;
|
||||
}
|
||||
time_valid = 1;
|
||||
}
|
||||
save = errno;
|
||||
(void)_close(s);
|
||||
errno = save;
|
||||
s = RPC_ANYSOCK;
|
||||
|
||||
if (time_valid) {
|
||||
thetime = ntohl(thetime);
|
||||
thetime = thetime - TOFFSET; /* adjust to UNIX time */
|
||||
} else
|
||||
thetime = 0;
|
||||
}
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
|
||||
error:
|
||||
/*
|
||||
* clean up our allocated data structures.
|
||||
*/
|
||||
|
||||
if (s != RPC_ANYSOCK)
|
||||
(void)_close(s);
|
||||
|
||||
if (clnt != NULL)
|
||||
clnt_destroy(clnt);
|
||||
|
||||
alarm(0); /* reset that alarm if its outstanding */
|
||||
if (oldsig) {
|
||||
signal(SIGALRM, oldsig);
|
||||
}
|
||||
|
||||
/*
|
||||
* note, don't free uaddr strings until after we've made a
|
||||
* copy of them.
|
||||
*/
|
||||
if (time_valid) {
|
||||
if (*uaddr == NULL)
|
||||
*uaddr = strdup(useua);
|
||||
|
||||
/* Round to the nearest second */
|
||||
tv.tv_sec += (tv.tv_sec > 500000) ? 1 : 0;
|
||||
delta = (thetime > tv.tv_sec) ? thetime - tv.tv_sec :
|
||||
tv.tv_sec - thetime;
|
||||
td->tv_sec = (thetime < tv.tv_sec) ? - delta : delta;
|
||||
td->tv_usec = 0;
|
||||
} else {
|
||||
msg("unable to get the server's time.");
|
||||
}
|
||||
|
||||
if (needfree)
|
||||
free_eps(teps, tsrv.ep.ep_len);
|
||||
|
||||
return (time_valid);
|
||||
}
|
384
freebsd/lib/libc/rpc/auth_unix.c
Normal file
384
freebsd/lib/libc/rpc/auth_unix.c
Normal file
@ -0,0 +1,384 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: auth_unix.c,v 1.18 2000/07/06 03:03:30 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)auth_unix.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* auth_unix.c, Implements UNIX style authentication parameters.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
* The system is very weak. The client uses no encryption for it's
|
||||
* credentials and only sends null verifiers. The server sends backs
|
||||
* null verifiers or optionally a verifier that suggests a new short hand
|
||||
* for the credentials.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_unix.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
/* auth_unix.c */
|
||||
static void authunix_nextverf (AUTH *);
|
||||
static bool_t authunix_marshal (AUTH *, XDR *);
|
||||
static bool_t authunix_validate (AUTH *, struct opaque_auth *);
|
||||
static bool_t authunix_refresh (AUTH *, void *);
|
||||
static void authunix_destroy (AUTH *);
|
||||
static void marshal_new_auth (AUTH *);
|
||||
static struct auth_ops *authunix_ops (void);
|
||||
|
||||
/*
|
||||
* This struct is pointed to by the ah_private field of an auth_handle.
|
||||
*/
|
||||
struct audata {
|
||||
struct opaque_auth au_origcred; /* original credentials */
|
||||
struct opaque_auth au_shcred; /* short hand cred */
|
||||
u_long au_shfaults; /* short hand cache faults */
|
||||
char au_marshed[MAX_AUTH_BYTES];
|
||||
u_int au_mpos; /* xdr pos at end of marshed */
|
||||
};
|
||||
#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
|
||||
|
||||
/*
|
||||
* Create a unix style authenticator.
|
||||
* Returns an auth handle with the given stuff in it.
|
||||
*/
|
||||
AUTH *
|
||||
authunix_create(machname, uid, gid, len, aup_gids)
|
||||
char *machname;
|
||||
u_int uid;
|
||||
u_int gid;
|
||||
int len;
|
||||
u_int *aup_gids;
|
||||
{
|
||||
struct authunix_parms aup;
|
||||
char mymem[MAX_AUTH_BYTES];
|
||||
struct timeval now;
|
||||
XDR xdrs;
|
||||
AUTH *auth;
|
||||
struct audata *au;
|
||||
|
||||
/*
|
||||
* Allocate and set up auth handle
|
||||
*/
|
||||
au = NULL;
|
||||
auth = mem_alloc(sizeof(*auth));
|
||||
#ifndef _KERNEL
|
||||
if (auth == NULL) {
|
||||
warnx("authunix_create: out of memory");
|
||||
goto cleanup_authunix_create;
|
||||
}
|
||||
#endif
|
||||
au = mem_alloc(sizeof(*au));
|
||||
#ifndef _KERNEL
|
||||
if (au == NULL) {
|
||||
warnx("authunix_create: out of memory");
|
||||
goto cleanup_authunix_create;
|
||||
}
|
||||
#endif
|
||||
auth->ah_ops = authunix_ops();
|
||||
auth->ah_private = (caddr_t)au;
|
||||
auth->ah_verf = au->au_shcred = _null_auth;
|
||||
au->au_shfaults = 0;
|
||||
au->au_origcred.oa_base = NULL;
|
||||
|
||||
/*
|
||||
* fill in param struct from the given params
|
||||
*/
|
||||
(void)gettimeofday(&now, NULL);
|
||||
aup.aup_time = now.tv_sec;
|
||||
aup.aup_machname = machname;
|
||||
aup.aup_uid = uid;
|
||||
aup.aup_gid = gid;
|
||||
aup.aup_len = (u_int)len;
|
||||
aup.aup_gids = aup_gids;
|
||||
|
||||
/*
|
||||
* Serialize the parameters into origcred
|
||||
*/
|
||||
xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
|
||||
if (! xdr_authunix_parms(&xdrs, &aup))
|
||||
abort();
|
||||
au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
|
||||
au->au_origcred.oa_flavor = AUTH_UNIX;
|
||||
#ifdef _KERNEL
|
||||
au->au_origcred.oa_base = mem_alloc((u_int) len);
|
||||
#else
|
||||
if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
|
||||
warnx("authunix_create: out of memory");
|
||||
goto cleanup_authunix_create;
|
||||
}
|
||||
#endif
|
||||
memmove(au->au_origcred.oa_base, mymem, (size_t)len);
|
||||
|
||||
/*
|
||||
* set auth handle to reflect new cred.
|
||||
*/
|
||||
auth->ah_cred = au->au_origcred;
|
||||
marshal_new_auth(auth);
|
||||
return (auth);
|
||||
#ifndef _KERNEL
|
||||
cleanup_authunix_create:
|
||||
if (auth)
|
||||
mem_free(auth, sizeof(*auth));
|
||||
if (au) {
|
||||
if (au->au_origcred.oa_base)
|
||||
mem_free(au->au_origcred.oa_base, (u_int)len);
|
||||
mem_free(au, sizeof(*au));
|
||||
}
|
||||
return (NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an auth handle with parameters determined by doing lots of
|
||||
* syscalls.
|
||||
*/
|
||||
AUTH *
|
||||
authunix_create_default()
|
||||
{
|
||||
AUTH *auth;
|
||||
int ngids;
|
||||
long ngids_max;
|
||||
char machname[MAXHOSTNAMELEN + 1];
|
||||
u_int uid;
|
||||
u_int gid;
|
||||
u_int *gids;
|
||||
|
||||
ngids_max = sysconf(_SC_NGROUPS_MAX) + 1;
|
||||
gids = malloc(sizeof(gid_t) * ngids_max);
|
||||
if (gids == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (gethostname(machname, sizeof machname) == -1)
|
||||
abort();
|
||||
machname[sizeof(machname) - 1] = 0;
|
||||
uid = geteuid();
|
||||
gid = getegid();
|
||||
if ((ngids = getgroups(ngids_max, gids)) < 0)
|
||||
abort();
|
||||
if (ngids > NGRPS)
|
||||
ngids = NGRPS;
|
||||
/* XXX: interface problem; we should translate from uid_t and gid_t */
|
||||
auth = authunix_create(machname, uid, gid, ngids, gids);
|
||||
free(gids);
|
||||
return (auth);
|
||||
}
|
||||
|
||||
/*
|
||||
* authunix operations
|
||||
*/
|
||||
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
authunix_nextverf(auth)
|
||||
AUTH *auth;
|
||||
{
|
||||
/* no action necessary */
|
||||
}
|
||||
|
||||
static bool_t
|
||||
authunix_marshal(auth, xdrs)
|
||||
AUTH *auth;
|
||||
XDR *xdrs;
|
||||
{
|
||||
struct audata *au;
|
||||
|
||||
assert(auth != NULL);
|
||||
assert(xdrs != NULL);
|
||||
|
||||
au = AUTH_PRIVATE(auth);
|
||||
return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
|
||||
}
|
||||
|
||||
static bool_t
|
||||
authunix_validate(auth, verf)
|
||||
AUTH *auth;
|
||||
struct opaque_auth *verf;
|
||||
{
|
||||
struct audata *au;
|
||||
XDR xdrs;
|
||||
|
||||
assert(auth != NULL);
|
||||
assert(verf != NULL);
|
||||
|
||||
if (verf->oa_flavor == AUTH_SHORT) {
|
||||
au = AUTH_PRIVATE(auth);
|
||||
xdrmem_create(&xdrs, verf->oa_base, verf->oa_length,
|
||||
XDR_DECODE);
|
||||
|
||||
if (au->au_shcred.oa_base != NULL) {
|
||||
mem_free(au->au_shcred.oa_base,
|
||||
au->au_shcred.oa_length);
|
||||
au->au_shcred.oa_base = NULL;
|
||||
}
|
||||
if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
|
||||
auth->ah_cred = au->au_shcred;
|
||||
} else {
|
||||
xdrs.x_op = XDR_FREE;
|
||||
(void)xdr_opaque_auth(&xdrs, &au->au_shcred);
|
||||
au->au_shcred.oa_base = NULL;
|
||||
auth->ah_cred = au->au_origcred;
|
||||
}
|
||||
marshal_new_auth(auth);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
authunix_refresh(AUTH *auth, void *dummy)
|
||||
{
|
||||
struct audata *au = AUTH_PRIVATE(auth);
|
||||
struct authunix_parms aup;
|
||||
struct timeval now;
|
||||
XDR xdrs;
|
||||
int stat;
|
||||
|
||||
assert(auth != NULL);
|
||||
|
||||
if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
|
||||
/* there is no hope. Punt */
|
||||
return (FALSE);
|
||||
}
|
||||
au->au_shfaults ++;
|
||||
|
||||
/* first deserialize the creds back into a struct authunix_parms */
|
||||
aup.aup_machname = NULL;
|
||||
aup.aup_gids = NULL;
|
||||
xdrmem_create(&xdrs, au->au_origcred.oa_base,
|
||||
au->au_origcred.oa_length, XDR_DECODE);
|
||||
stat = xdr_authunix_parms(&xdrs, &aup);
|
||||
if (! stat)
|
||||
goto done;
|
||||
|
||||
/* update the time and serialize in place */
|
||||
(void)gettimeofday(&now, NULL);
|
||||
aup.aup_time = now.tv_sec;
|
||||
xdrs.x_op = XDR_ENCODE;
|
||||
XDR_SETPOS(&xdrs, 0);
|
||||
stat = xdr_authunix_parms(&xdrs, &aup);
|
||||
if (! stat)
|
||||
goto done;
|
||||
auth->ah_cred = au->au_origcred;
|
||||
marshal_new_auth(auth);
|
||||
done:
|
||||
/* free the struct authunix_parms created by deserializing */
|
||||
xdrs.x_op = XDR_FREE;
|
||||
(void)xdr_authunix_parms(&xdrs, &aup);
|
||||
XDR_DESTROY(&xdrs);
|
||||
return (stat);
|
||||
}
|
||||
|
||||
static void
|
||||
authunix_destroy(auth)
|
||||
AUTH *auth;
|
||||
{
|
||||
struct audata *au;
|
||||
|
||||
assert(auth != NULL);
|
||||
|
||||
au = AUTH_PRIVATE(auth);
|
||||
mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
|
||||
|
||||
if (au->au_shcred.oa_base != NULL)
|
||||
mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
|
||||
|
||||
mem_free(auth->ah_private, sizeof(struct audata));
|
||||
|
||||
if (auth->ah_verf.oa_base != NULL)
|
||||
mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
|
||||
|
||||
mem_free(auth, sizeof(*auth));
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshals (pre-serializes) an auth struct.
|
||||
* sets private data, au_marshed and au_mpos
|
||||
*/
|
||||
static void
|
||||
marshal_new_auth(auth)
|
||||
AUTH *auth;
|
||||
{
|
||||
XDR xdr_stream;
|
||||
XDR *xdrs = &xdr_stream;
|
||||
struct audata *au;
|
||||
|
||||
assert(auth != NULL);
|
||||
|
||||
au = AUTH_PRIVATE(auth);
|
||||
xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
|
||||
if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
|
||||
(! xdr_opaque_auth(xdrs, &(auth->ah_verf))))
|
||||
warnx("auth_none.c - Fatal marshalling problem");
|
||||
else
|
||||
au->au_mpos = XDR_GETPOS(xdrs);
|
||||
XDR_DESTROY(xdrs);
|
||||
}
|
||||
|
||||
static struct auth_ops *
|
||||
authunix_ops()
|
||||
{
|
||||
static struct auth_ops ops;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.ah_nextverf == NULL) {
|
||||
ops.ah_nextverf = authunix_nextverf;
|
||||
ops.ah_marshal = authunix_marshal;
|
||||
ops.ah_validate = authunix_validate;
|
||||
ops.ah_refresh = authunix_refresh;
|
||||
ops.ah_destroy = authunix_destroy;
|
||||
}
|
||||
mutex_unlock(&ops_lock);
|
||||
return (&ops);
|
||||
}
|
95
freebsd/lib/libc/rpc/authdes_prot.c
Normal file
95
freebsd/lib/libc/rpc/authdes_prot.c
Normal file
@ -0,0 +1,95 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)authdes_prot.c 2.1 88/07/29 4.0 RPCSRC; from 1.6 88/02/08 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* authdes_prot.c, XDR routines for DES authentication
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_des.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#define ATTEMPT(xdr_op) if (!(xdr_op)) return (FALSE)
|
||||
|
||||
bool_t
|
||||
xdr_authdes_cred(xdrs, cred)
|
||||
XDR *xdrs;
|
||||
struct authdes_cred *cred;
|
||||
{
|
||||
enum authdes_namekind *padc_namekind = &cred->adc_namekind;
|
||||
/*
|
||||
* Unrolled xdr
|
||||
*/
|
||||
ATTEMPT(xdr_enum(xdrs, (enum_t *) padc_namekind));
|
||||
switch (cred->adc_namekind) {
|
||||
case ADN_FULLNAME:
|
||||
ATTEMPT(xdr_string(xdrs, &cred->adc_fullname.name,
|
||||
MAXNETNAMELEN));
|
||||
ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_fullname.key,
|
||||
sizeof(des_block)));
|
||||
ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_fullname.window,
|
||||
sizeof(cred->adc_fullname.window)));
|
||||
return (TRUE);
|
||||
case ADN_NICKNAME:
|
||||
ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_nickname,
|
||||
sizeof(cred->adc_nickname)));
|
||||
return (TRUE);
|
||||
default:
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool_t
|
||||
xdr_authdes_verf(xdrs, verf)
|
||||
XDR *xdrs;
|
||||
struct authdes_verf *verf;
|
||||
{
|
||||
/*
|
||||
* Unrolled xdr
|
||||
*/
|
||||
ATTEMPT(xdr_opaque(xdrs, (caddr_t)&verf->adv_xtimestamp,
|
||||
sizeof(des_block)));
|
||||
ATTEMPT(xdr_opaque(xdrs, (caddr_t)&verf->adv_int_u,
|
||||
sizeof(verf->adv_int_u)));
|
||||
return (TRUE);
|
||||
}
|
80
freebsd/lib/libc/rpc/authunix_prot.c
Normal file
80
freebsd/lib/libc/rpc/authunix_prot.c
Normal file
@ -0,0 +1,80 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: authunix_prot.c,v 1.12 2000/01/22 22:19:17 mycroft Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* authunix_prot.c
|
||||
* XDR for UNIX style authentication parameters for RPC
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_unix.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/*
|
||||
* XDR for unix authentication parameters.
|
||||
*/
|
||||
bool_t
|
||||
xdr_authunix_parms(xdrs, p)
|
||||
XDR *xdrs;
|
||||
struct authunix_parms *p;
|
||||
{
|
||||
u_int **paup_gids;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(p != NULL);
|
||||
|
||||
paup_gids = &p->aup_gids;
|
||||
|
||||
if (xdr_u_long(xdrs, &(p->aup_time)) &&
|
||||
xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) &&
|
||||
xdr_u_int(xdrs, &(p->aup_uid)) &&
|
||||
xdr_u_int(xdrs, &(p->aup_gid)) &&
|
||||
xdr_array(xdrs, (char **) paup_gids,
|
||||
&(p->aup_len), NGRPS, sizeof(u_int), (xdrproc_t)xdr_u_int) ) {
|
||||
return (TRUE);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
162
freebsd/lib/libc/rpc/bindresvport.c
Normal file
162
freebsd/lib/libc/rpc/bindresvport.c
Normal file
@ -0,0 +1,162 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: bindresvport.c,v 1.19 2000/07/06 03:03:59 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "from: @(#)bindresvport.c 1.8 88/02/08 SMI";
|
||||
static char *sccsid = "from: @(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
/* from: $OpenBSD: bindresvport.c,v 1.7 1996/07/30 16:25:47 downsj Exp $ */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987 by Sun Microsystems, Inc.
|
||||
*
|
||||
* Portions Copyright(C) 1996, Jason Downs. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include <string.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/*
|
||||
* Bind a socket to a privileged IP port
|
||||
*/
|
||||
int
|
||||
bindresvport(sd, sin)
|
||||
int sd;
|
||||
struct sockaddr_in *sin;
|
||||
{
|
||||
return bindresvport_sa(sd, (struct sockaddr *)sin);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bind a socket to a privileged IP port
|
||||
*/
|
||||
int
|
||||
bindresvport_sa(sd, sa)
|
||||
int sd;
|
||||
struct sockaddr *sa;
|
||||
{
|
||||
int old, error, af;
|
||||
struct sockaddr_storage myaddr;
|
||||
struct sockaddr_in *sin;
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
int proto, portrange, portlow;
|
||||
u_int16_t *portp;
|
||||
socklen_t salen;
|
||||
|
||||
if (sa == NULL) {
|
||||
salen = sizeof(myaddr);
|
||||
sa = (struct sockaddr *)&myaddr;
|
||||
|
||||
if (_getsockname(sd, sa, &salen) == -1)
|
||||
return -1; /* errno is correctly set */
|
||||
|
||||
af = sa->sa_family;
|
||||
memset(sa, 0, salen);
|
||||
} else
|
||||
af = sa->sa_family;
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
proto = IPPROTO_IP;
|
||||
portrange = IP_PORTRANGE;
|
||||
portlow = IP_PORTRANGE_LOW;
|
||||
sin = (struct sockaddr_in *)sa;
|
||||
salen = sizeof(struct sockaddr_in);
|
||||
portp = &sin->sin_port;
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
proto = IPPROTO_IPV6;
|
||||
portrange = IPV6_PORTRANGE;
|
||||
portlow = IPV6_PORTRANGE_LOW;
|
||||
sin6 = (struct sockaddr_in6 *)sa;
|
||||
salen = sizeof(struct sockaddr_in6);
|
||||
portp = &sin6->sin6_port;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
errno = EPFNOSUPPORT;
|
||||
return (-1);
|
||||
}
|
||||
sa->sa_family = af;
|
||||
sa->sa_len = salen;
|
||||
|
||||
if (*portp == 0) {
|
||||
socklen_t oldlen = sizeof(old);
|
||||
|
||||
error = _getsockopt(sd, proto, portrange, &old, &oldlen);
|
||||
if (error < 0)
|
||||
return (error);
|
||||
|
||||
error = _setsockopt(sd, proto, portrange, &portlow,
|
||||
sizeof(portlow));
|
||||
if (error < 0)
|
||||
return (error);
|
||||
}
|
||||
|
||||
error = _bind(sd, sa, salen);
|
||||
|
||||
if (*portp == 0) {
|
||||
int saved_errno = errno;
|
||||
|
||||
if (error < 0) {
|
||||
if (_setsockopt(sd, proto, portrange, &old,
|
||||
sizeof(old)) < 0)
|
||||
errno = saved_errno;
|
||||
return (error);
|
||||
}
|
||||
|
||||
if (sa != (struct sockaddr *)&myaddr) {
|
||||
/* Hmm, what did the kernel assign? */
|
||||
if (_getsockname(sd, sa, &salen) < 0)
|
||||
errno = saved_errno;
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
return (error);
|
||||
}
|
674
freebsd/lib/libc/rpc/clnt_bcast.c
Normal file
674
freebsd/lib/libc/rpc/clnt_bcast.c
Normal file
@ -0,0 +1,674 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_bcast.c,v 1.3 2000/07/06 03:05:20 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#ident "@(#)clnt_bcast.c 1.18 94/05/03 SMI"
|
||||
static char sccsid[] = "@(#)clnt_bcast.c 1.15 89/04/21 Copyr 1988 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
|
||||
/*
|
||||
* clnt_bcast.c
|
||||
* Client interface to broadcast service.
|
||||
*
|
||||
* Copyright (C) 1988, Sun Microsystems, Inc.
|
||||
*
|
||||
* The following is kludged-up support for simple rpc broadcasts.
|
||||
* Someday a large, complicated system will replace these routines.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/queue.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <sys/poll.h>
|
||||
#include <rpc/rpc.h>
|
||||
#ifdef PORTMAP
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include <rpc/pmap_rmt.h>
|
||||
#endif /* PORTMAP */
|
||||
#include <rpc/nettype.h>
|
||||
#include <arpa/inet.h>
|
||||
#ifdef RPC_DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "rpc_com.h"
|
||||
|
||||
#define MAXBCAST 20 /* Max no of broadcasting transports */
|
||||
#define INITTIME 4000 /* Time to wait initially */
|
||||
#define WAITTIME 8000 /* Maximum time to wait */
|
||||
|
||||
/*
|
||||
* If nettype is NULL, it broadcasts on all the available
|
||||
* datagram_n transports. May potentially lead to broadacst storms
|
||||
* and hence should be used with caution, care and courage.
|
||||
*
|
||||
* The current parameter xdr packet size is limited by the max tsdu
|
||||
* size of the transport. If the max tsdu size of any transport is
|
||||
* smaller than the parameter xdr packet, then broadcast is not
|
||||
* sent on that transport.
|
||||
*
|
||||
* Also, the packet size should be less the packet size of
|
||||
* the data link layer (for ethernet it is 1400 bytes). There is
|
||||
* no easy way to find out the max size of the data link layer and
|
||||
* we are assuming that the args would be smaller than that.
|
||||
*
|
||||
* The result size has to be smaller than the transport tsdu size.
|
||||
*
|
||||
* If PORTMAP has been defined, we send two packets for UDP, one for
|
||||
* rpcbind and one for portmap. For those machines which support
|
||||
* both rpcbind and portmap, it will cause them to reply twice, and
|
||||
* also here it will get two responses ... inefficient and clumsy.
|
||||
*/
|
||||
|
||||
struct broadif {
|
||||
int index;
|
||||
struct sockaddr_storage broadaddr;
|
||||
TAILQ_ENTRY(broadif) link;
|
||||
};
|
||||
|
||||
typedef TAILQ_HEAD(, broadif) broadlist_t;
|
||||
|
||||
int __rpc_getbroadifs(int, int, int, broadlist_t *);
|
||||
void __rpc_freebroadifs(broadlist_t *);
|
||||
int __rpc_broadenable(int, int, struct broadif *);
|
||||
|
||||
int __rpc_lowvers = 0;
|
||||
|
||||
int
|
||||
__rpc_getbroadifs(int af, int proto, int socktype, broadlist_t *list)
|
||||
{
|
||||
int count = 0;
|
||||
struct broadif *bip;
|
||||
struct ifaddrs *ifap, *ifp;
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
struct sockaddr_in *sin;
|
||||
struct addrinfo hints, *res;
|
||||
|
||||
if (getifaddrs(&ifp) < 0)
|
||||
return 0;
|
||||
|
||||
memset(&hints, 0, sizeof hints);
|
||||
|
||||
hints.ai_family = af;
|
||||
hints.ai_protocol = proto;
|
||||
hints.ai_socktype = socktype;
|
||||
|
||||
if (getaddrinfo(NULL, "sunrpc", &hints, &res) != 0) {
|
||||
freeifaddrs(ifp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
|
||||
if (ifap->ifa_addr->sa_family != af ||
|
||||
!(ifap->ifa_flags & IFF_UP))
|
||||
continue;
|
||||
bip = (struct broadif *)malloc(sizeof *bip);
|
||||
if (bip == NULL)
|
||||
break;
|
||||
bip->index = if_nametoindex(ifap->ifa_name);
|
||||
if (
|
||||
#ifdef INET6
|
||||
af != AF_INET6 &&
|
||||
#endif
|
||||
(ifap->ifa_flags & IFF_BROADCAST) &&
|
||||
ifap->ifa_broadaddr) {
|
||||
memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
|
||||
(size_t)ifap->ifa_broadaddr->sa_len);
|
||||
sin = (struct sockaddr_in *)(void *)&bip->broadaddr;
|
||||
sin->sin_port =
|
||||
((struct sockaddr_in *)
|
||||
(void *)res->ai_addr)->sin_port;
|
||||
} else
|
||||
#ifdef INET6
|
||||
if (af == AF_INET6 && (ifap->ifa_flags & IFF_MULTICAST)) {
|
||||
sin6 = (struct sockaddr_in6 *)(void *)&bip->broadaddr;
|
||||
inet_pton(af, RPCB_MULTICAST_ADDR, &sin6->sin6_addr);
|
||||
sin6->sin6_family = af;
|
||||
sin6->sin6_len = sizeof *sin6;
|
||||
sin6->sin6_port =
|
||||
((struct sockaddr_in6 *)
|
||||
(void *)res->ai_addr)->sin6_port;
|
||||
sin6->sin6_scope_id = bip->index;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
free(bip);
|
||||
continue;
|
||||
}
|
||||
TAILQ_INSERT_TAIL(list, bip, link);
|
||||
count++;
|
||||
}
|
||||
freeifaddrs(ifp);
|
||||
freeaddrinfo(res);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
__rpc_freebroadifs(broadlist_t *list)
|
||||
{
|
||||
struct broadif *bip, *next;
|
||||
|
||||
bip = TAILQ_FIRST(list);
|
||||
|
||||
while (bip != NULL) {
|
||||
next = TAILQ_NEXT(bip, link);
|
||||
free(bip);
|
||||
bip = next;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
/*ARGSUSED*/
|
||||
__rpc_broadenable(int af, int s, struct broadif *bip)
|
||||
{
|
||||
int o = 1;
|
||||
|
||||
#if 0
|
||||
if (af == AF_INET6) {
|
||||
fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
|
||||
if (_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
|
||||
sizeof bip->index) < 0)
|
||||
return -1;
|
||||
} else
|
||||
#endif
|
||||
if (_setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
enum clnt_stat
|
||||
rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
|
||||
eachresult, inittime, waittime, nettype)
|
||||
rpcprog_t prog; /* program number */
|
||||
rpcvers_t vers; /* version number */
|
||||
rpcproc_t proc; /* procedure number */
|
||||
xdrproc_t xargs; /* xdr routine for args */
|
||||
caddr_t argsp; /* pointer to args */
|
||||
xdrproc_t xresults; /* xdr routine for results */
|
||||
caddr_t resultsp; /* pointer to results */
|
||||
resultproc_t eachresult; /* call with each result obtained */
|
||||
int inittime; /* how long to wait initially */
|
||||
int waittime; /* maximum time to wait */
|
||||
const char *nettype; /* transport type */
|
||||
{
|
||||
enum clnt_stat stat = RPC_SUCCESS; /* Return status */
|
||||
XDR xdr_stream; /* XDR stream */
|
||||
XDR *xdrs = &xdr_stream;
|
||||
struct rpc_msg msg; /* RPC message */
|
||||
struct timeval t;
|
||||
char *outbuf = NULL; /* Broadcast msg buffer */
|
||||
char *inbuf = NULL; /* Reply buf */
|
||||
int inlen;
|
||||
u_int maxbufsize = 0;
|
||||
AUTH *sys_auth = authunix_create_default();
|
||||
int i;
|
||||
void *handle;
|
||||
char uaddress[1024]; /* A self imposed limit */
|
||||
char *uaddrp = uaddress;
|
||||
int pmap_reply_flag; /* reply recvd from PORTMAP */
|
||||
/* An array of all the suitable broadcast transports */
|
||||
struct {
|
||||
int fd; /* File descriptor */
|
||||
int af;
|
||||
int proto;
|
||||
struct netconfig *nconf; /* Netconfig structure */
|
||||
u_int asize; /* Size of the addr buf */
|
||||
u_int dsize; /* Size of the data buf */
|
||||
struct sockaddr_storage raddr; /* Remote address */
|
||||
broadlist_t nal;
|
||||
} fdlist[MAXBCAST];
|
||||
struct pollfd pfd[MAXBCAST];
|
||||
size_t fdlistno = 0;
|
||||
struct r_rpcb_rmtcallargs barg; /* Remote arguments */
|
||||
struct r_rpcb_rmtcallres bres; /* Remote results */
|
||||
size_t outlen;
|
||||
struct netconfig *nconf;
|
||||
int msec;
|
||||
int pollretval;
|
||||
int fds_found;
|
||||
|
||||
#ifdef PORTMAP
|
||||
size_t outlen_pmap = 0;
|
||||
u_long port; /* Remote port number */
|
||||
int pmap_flag = 0; /* UDP exists ? */
|
||||
char *outbuf_pmap = NULL;
|
||||
struct rmtcallargs barg_pmap; /* Remote arguments */
|
||||
struct rmtcallres bres_pmap; /* Remote results */
|
||||
u_int udpbufsz = 0;
|
||||
#endif /* PORTMAP */
|
||||
|
||||
if (sys_auth == NULL) {
|
||||
return (RPC_SYSTEMERROR);
|
||||
}
|
||||
/*
|
||||
* initialization: create a fd, a broadcast address, and send the
|
||||
* request on the broadcast transport.
|
||||
* Listen on all of them and on replies, call the user supplied
|
||||
* function.
|
||||
*/
|
||||
|
||||
if (nettype == NULL)
|
||||
nettype = "datagram_n";
|
||||
if ((handle = __rpc_setconf(nettype)) == NULL) {
|
||||
AUTH_DESTROY(sys_auth);
|
||||
return (RPC_UNKNOWNPROTO);
|
||||
}
|
||||
while ((nconf = __rpc_getconf(handle)) != NULL) {
|
||||
int fd;
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
if (nconf->nc_semantics != NC_TPI_CLTS)
|
||||
continue;
|
||||
if (fdlistno >= MAXBCAST)
|
||||
break; /* No more slots available */
|
||||
if (!__rpc_nconf2sockinfo(nconf, &si))
|
||||
continue;
|
||||
|
||||
TAILQ_INIT(&fdlist[fdlistno].nal);
|
||||
if (__rpc_getbroadifs(si.si_af, si.si_proto, si.si_socktype,
|
||||
&fdlist[fdlistno].nal) == 0)
|
||||
continue;
|
||||
|
||||
fd = _socket(si.si_af, si.si_socktype, si.si_proto);
|
||||
if (fd < 0) {
|
||||
stat = RPC_CANTSEND;
|
||||
continue;
|
||||
}
|
||||
fdlist[fdlistno].af = si.si_af;
|
||||
fdlist[fdlistno].proto = si.si_proto;
|
||||
fdlist[fdlistno].fd = fd;
|
||||
fdlist[fdlistno].nconf = nconf;
|
||||
fdlist[fdlistno].asize = __rpc_get_a_size(si.si_af);
|
||||
pfd[fdlistno].events = POLLIN | POLLPRI |
|
||||
POLLRDNORM | POLLRDBAND;
|
||||
pfd[fdlistno].fd = fdlist[fdlistno].fd = fd;
|
||||
fdlist[fdlistno].dsize = __rpc_get_t_size(si.si_af, si.si_proto,
|
||||
0);
|
||||
|
||||
if (maxbufsize <= fdlist[fdlistno].dsize)
|
||||
maxbufsize = fdlist[fdlistno].dsize;
|
||||
|
||||
#ifdef PORTMAP
|
||||
if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) {
|
||||
udpbufsz = fdlist[fdlistno].dsize;
|
||||
if ((outbuf_pmap = malloc(udpbufsz)) == NULL) {
|
||||
_close(fd);
|
||||
stat = RPC_SYSTEMERROR;
|
||||
goto done_broad;
|
||||
}
|
||||
pmap_flag = 1;
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
fdlistno++;
|
||||
}
|
||||
|
||||
if (fdlistno == 0) {
|
||||
if (stat == RPC_SUCCESS)
|
||||
stat = RPC_UNKNOWNPROTO;
|
||||
goto done_broad;
|
||||
}
|
||||
if (maxbufsize == 0) {
|
||||
if (stat == RPC_SUCCESS)
|
||||
stat = RPC_CANTSEND;
|
||||
goto done_broad;
|
||||
}
|
||||
inbuf = malloc(maxbufsize);
|
||||
outbuf = malloc(maxbufsize);
|
||||
if ((inbuf == NULL) || (outbuf == NULL)) {
|
||||
stat = RPC_SYSTEMERROR;
|
||||
goto done_broad;
|
||||
}
|
||||
|
||||
/* Serialize all the arguments which have to be sent */
|
||||
(void) gettimeofday(&t, NULL);
|
||||
msg.rm_xid = __RPC_GETXID(&t);
|
||||
msg.rm_direction = CALL;
|
||||
msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
|
||||
msg.rm_call.cb_prog = RPCBPROG;
|
||||
msg.rm_call.cb_vers = RPCBVERS;
|
||||
msg.rm_call.cb_proc = RPCBPROC_CALLIT;
|
||||
barg.prog = prog;
|
||||
barg.vers = vers;
|
||||
barg.proc = proc;
|
||||
barg.args.args_val = argsp;
|
||||
barg.xdr_args = xargs;
|
||||
bres.addr = uaddrp;
|
||||
bres.results.results_val = resultsp;
|
||||
bres.xdr_res = xresults;
|
||||
msg.rm_call.cb_cred = sys_auth->ah_cred;
|
||||
msg.rm_call.cb_verf = sys_auth->ah_verf;
|
||||
xdrmem_create(xdrs, outbuf, maxbufsize, XDR_ENCODE);
|
||||
if ((!xdr_callmsg(xdrs, &msg)) ||
|
||||
(!xdr_rpcb_rmtcallargs(xdrs,
|
||||
(struct rpcb_rmtcallargs *)(void *)&barg))) {
|
||||
stat = RPC_CANTENCODEARGS;
|
||||
goto done_broad;
|
||||
}
|
||||
outlen = xdr_getpos(xdrs);
|
||||
xdr_destroy(xdrs);
|
||||
|
||||
#ifdef PORTMAP
|
||||
/* Prepare the packet for version 2 PORTMAP */
|
||||
if (pmap_flag) {
|
||||
msg.rm_xid++; /* One way to distinguish */
|
||||
msg.rm_call.cb_prog = PMAPPROG;
|
||||
msg.rm_call.cb_vers = PMAPVERS;
|
||||
msg.rm_call.cb_proc = PMAPPROC_CALLIT;
|
||||
barg_pmap.prog = prog;
|
||||
barg_pmap.vers = vers;
|
||||
barg_pmap.proc = proc;
|
||||
barg_pmap.args_ptr = argsp;
|
||||
barg_pmap.xdr_args = xargs;
|
||||
bres_pmap.port_ptr = &port;
|
||||
bres_pmap.xdr_results = xresults;
|
||||
bres_pmap.results_ptr = resultsp;
|
||||
xdrmem_create(xdrs, outbuf_pmap, udpbufsz, XDR_ENCODE);
|
||||
if ((! xdr_callmsg(xdrs, &msg)) ||
|
||||
(! xdr_rmtcall_args(xdrs, &barg_pmap))) {
|
||||
stat = RPC_CANTENCODEARGS;
|
||||
goto done_broad;
|
||||
}
|
||||
outlen_pmap = xdr_getpos(xdrs);
|
||||
xdr_destroy(xdrs);
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
|
||||
/*
|
||||
* Basic loop: broadcast the packets to transports which
|
||||
* support data packets of size such that one can encode
|
||||
* all the arguments.
|
||||
* Wait a while for response(s).
|
||||
* The response timeout grows larger per iteration.
|
||||
*/
|
||||
for (msec = inittime; msec <= waittime; msec += msec) {
|
||||
struct broadif *bip;
|
||||
|
||||
/* Broadcast all the packets now */
|
||||
for (i = 0; i < fdlistno; i++) {
|
||||
if (fdlist[i].dsize < outlen) {
|
||||
stat = RPC_CANTSEND;
|
||||
continue;
|
||||
}
|
||||
for (bip = TAILQ_FIRST(&fdlist[i].nal); bip != NULL;
|
||||
bip = TAILQ_NEXT(bip, link)) {
|
||||
void *addr;
|
||||
|
||||
addr = &bip->broadaddr;
|
||||
|
||||
__rpc_broadenable(fdlist[i].af, fdlist[i].fd,
|
||||
bip);
|
||||
|
||||
/*
|
||||
* Only use version 3 if lowvers is not set
|
||||
*/
|
||||
|
||||
if (!__rpc_lowvers)
|
||||
if (_sendto(fdlist[i].fd, outbuf,
|
||||
outlen, 0, (struct sockaddr*)addr,
|
||||
(size_t)fdlist[i].asize) !=
|
||||
outlen) {
|
||||
#ifdef RPC_DEBUG
|
||||
perror("sendto");
|
||||
#endif
|
||||
warnx("clnt_bcast: cannot send "
|
||||
"broadcast packet");
|
||||
stat = RPC_CANTSEND;
|
||||
continue;
|
||||
};
|
||||
#ifdef RPC_DEBUG
|
||||
if (!__rpc_lowvers)
|
||||
fprintf(stderr, "Broadcast packet sent "
|
||||
"for %s\n",
|
||||
fdlist[i].nconf->nc_netid);
|
||||
#endif
|
||||
#ifdef PORTMAP
|
||||
/*
|
||||
* Send the version 2 packet also
|
||||
* for UDP/IP
|
||||
*/
|
||||
if (pmap_flag &&
|
||||
fdlist[i].proto == IPPROTO_UDP) {
|
||||
if (_sendto(fdlist[i].fd, outbuf_pmap,
|
||||
outlen_pmap, 0, addr,
|
||||
(size_t)fdlist[i].asize) !=
|
||||
outlen_pmap) {
|
||||
warnx("clnt_bcast: "
|
||||
"Cannot send broadcast packet");
|
||||
stat = RPC_CANTSEND;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#ifdef RPC_DEBUG
|
||||
fprintf(stderr, "PMAP Broadcast packet "
|
||||
"sent for %s\n",
|
||||
fdlist[i].nconf->nc_netid);
|
||||
#endif
|
||||
#endif /* PORTMAP */
|
||||
}
|
||||
/* End for sending all packets on this transport */
|
||||
} /* End for sending on all transports */
|
||||
|
||||
if (eachresult == NULL) {
|
||||
stat = RPC_SUCCESS;
|
||||
goto done_broad;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get all the replies from these broadcast requests
|
||||
*/
|
||||
recv_again:
|
||||
|
||||
switch (pollretval = _poll(pfd, fdlistno, msec)) {
|
||||
case 0: /* timed out */
|
||||
stat = RPC_TIMEDOUT;
|
||||
continue;
|
||||
case -1: /* some kind of error - we ignore it */
|
||||
goto recv_again;
|
||||
} /* end of poll results switch */
|
||||
|
||||
for (i = fds_found = 0;
|
||||
i < fdlistno && fds_found < pollretval; i++) {
|
||||
bool_t done = FALSE;
|
||||
|
||||
if (pfd[i].revents == 0)
|
||||
continue;
|
||||
else if (pfd[i].revents & POLLNVAL) {
|
||||
/*
|
||||
* Something bad has happened to this descri-
|
||||
* ptor. We can cause _poll() to ignore
|
||||
* it simply by using a negative fd. We do that
|
||||
* rather than compacting the pfd[] and fdlist[]
|
||||
* arrays.
|
||||
*/
|
||||
pfd[i].fd = -1;
|
||||
fds_found++;
|
||||
continue;
|
||||
} else
|
||||
fds_found++;
|
||||
#ifdef RPC_DEBUG
|
||||
fprintf(stderr, "response for %s\n",
|
||||
fdlist[i].nconf->nc_netid);
|
||||
#endif
|
||||
try_again:
|
||||
inlen = _recvfrom(fdlist[i].fd, inbuf, fdlist[i].dsize,
|
||||
0, (struct sockaddr *)(void *)&fdlist[i].raddr,
|
||||
&fdlist[i].asize);
|
||||
if (inlen < 0) {
|
||||
if (errno == EINTR)
|
||||
goto try_again;
|
||||
warnx("clnt_bcast: Cannot receive reply to "
|
||||
"broadcast");
|
||||
stat = RPC_CANTRECV;
|
||||
continue;
|
||||
}
|
||||
if (inlen < sizeof (u_int32_t))
|
||||
continue; /* Drop that and go ahead */
|
||||
/*
|
||||
* see if reply transaction id matches sent id.
|
||||
* If so, decode the results. If return id is xid + 1
|
||||
* it was a PORTMAP reply
|
||||
*/
|
||||
if (*((u_int32_t *)(void *)(inbuf)) ==
|
||||
*((u_int32_t *)(void *)(outbuf))) {
|
||||
pmap_reply_flag = 0;
|
||||
msg.acpted_rply.ar_verf = _null_auth;
|
||||
msg.acpted_rply.ar_results.where =
|
||||
(caddr_t)(void *)&bres;
|
||||
msg.acpted_rply.ar_results.proc =
|
||||
(xdrproc_t)xdr_rpcb_rmtcallres;
|
||||
#ifdef PORTMAP
|
||||
} else if (pmap_flag &&
|
||||
*((u_int32_t *)(void *)(inbuf)) ==
|
||||
*((u_int32_t *)(void *)(outbuf_pmap))) {
|
||||
pmap_reply_flag = 1;
|
||||
msg.acpted_rply.ar_verf = _null_auth;
|
||||
msg.acpted_rply.ar_results.where =
|
||||
(caddr_t)(void *)&bres_pmap;
|
||||
msg.acpted_rply.ar_results.proc =
|
||||
(xdrproc_t)xdr_rmtcallres;
|
||||
#endif /* PORTMAP */
|
||||
} else
|
||||
continue;
|
||||
xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
|
||||
if (xdr_replymsg(xdrs, &msg)) {
|
||||
if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
|
||||
(msg.acpted_rply.ar_stat == SUCCESS)) {
|
||||
struct netbuf taddr, *np;
|
||||
struct sockaddr_in *sin;
|
||||
|
||||
#ifdef PORTMAP
|
||||
if (pmap_flag && pmap_reply_flag) {
|
||||
sin = (struct sockaddr_in *)
|
||||
(void *)&fdlist[i].raddr;
|
||||
sin->sin_port =
|
||||
htons((u_short)port);
|
||||
taddr.len = taddr.maxlen =
|
||||
fdlist[i].raddr.ss_len;
|
||||
taddr.buf = &fdlist[i].raddr;
|
||||
done = (*eachresult)(resultsp,
|
||||
&taddr, fdlist[i].nconf);
|
||||
} else {
|
||||
#endif /* PORTMAP */
|
||||
#ifdef RPC_DEBUG
|
||||
fprintf(stderr, "uaddr %s\n",
|
||||
uaddrp);
|
||||
#endif
|
||||
np = uaddr2taddr(
|
||||
fdlist[i].nconf, uaddrp);
|
||||
done = (*eachresult)(resultsp,
|
||||
np, fdlist[i].nconf);
|
||||
free(np);
|
||||
#ifdef PORTMAP
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
}
|
||||
/* otherwise, we just ignore the errors ... */
|
||||
}
|
||||
/* else some kind of deserialization problem ... */
|
||||
|
||||
xdrs->x_op = XDR_FREE;
|
||||
msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
|
||||
(void) xdr_replymsg(xdrs, &msg);
|
||||
(void) (*xresults)(xdrs, resultsp);
|
||||
XDR_DESTROY(xdrs);
|
||||
if (done) {
|
||||
stat = RPC_SUCCESS;
|
||||
goto done_broad;
|
||||
} else {
|
||||
goto recv_again;
|
||||
}
|
||||
} /* The recv for loop */
|
||||
} /* The giant for loop */
|
||||
|
||||
done_broad:
|
||||
if (inbuf)
|
||||
(void) free(inbuf);
|
||||
if (outbuf)
|
||||
(void) free(outbuf);
|
||||
#ifdef PORTMAP
|
||||
if (outbuf_pmap)
|
||||
(void) free(outbuf_pmap);
|
||||
#endif /* PORTMAP */
|
||||
for (i = 0; i < fdlistno; i++) {
|
||||
(void)_close(fdlist[i].fd);
|
||||
__rpc_freebroadifs(&fdlist[i].nal);
|
||||
}
|
||||
AUTH_DESTROY(sys_auth);
|
||||
(void) __rpc_endconf(handle);
|
||||
|
||||
return (stat);
|
||||
}
|
||||
|
||||
|
||||
enum clnt_stat
|
||||
rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
|
||||
eachresult, nettype)
|
||||
rpcprog_t prog; /* program number */
|
||||
rpcvers_t vers; /* version number */
|
||||
rpcproc_t proc; /* procedure number */
|
||||
xdrproc_t xargs; /* xdr routine for args */
|
||||
caddr_t argsp; /* pointer to args */
|
||||
xdrproc_t xresults; /* xdr routine for results */
|
||||
caddr_t resultsp; /* pointer to results */
|
||||
resultproc_t eachresult; /* call with each result obtained */
|
||||
const char *nettype; /* transport type */
|
||||
{
|
||||
enum clnt_stat dummy;
|
||||
|
||||
dummy = rpc_broadcast_exp(prog, vers, proc, xargs, argsp,
|
||||
xresults, resultsp, eachresult,
|
||||
INITTIME, WAITTIME, nettype);
|
||||
return (dummy);
|
||||
}
|
860
freebsd/lib/libc/rpc/clnt_dg.c
Normal file
860
freebsd/lib/libc/rpc/clnt_dg.c
Normal file
@ -0,0 +1,860 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_dg.c,v 1.4 2000/07/14 08:40:41 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#ident "@(#)clnt_dg.c 1.23 94/04/22 SMI"
|
||||
static char sccsid[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Implements a connectionless client side RPC.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include "un-namespace.h"
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
|
||||
#ifdef _FREEFALL_CONFIG
|
||||
/*
|
||||
* Disable RPC exponential back-off for FreeBSD.org systems.
|
||||
*/
|
||||
#define RPC_MAX_BACKOFF 1 /* second */
|
||||
#else
|
||||
#define RPC_MAX_BACKOFF 30 /* seconds */
|
||||
#endif
|
||||
|
||||
|
||||
static struct clnt_ops *clnt_dg_ops(void);
|
||||
static bool_t time_not_ok(struct timeval *);
|
||||
static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
|
||||
xdrproc_t, void *, struct timeval);
|
||||
static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
|
||||
static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
|
||||
static void clnt_dg_abort(CLIENT *);
|
||||
static bool_t clnt_dg_control(CLIENT *, u_int, void *);
|
||||
static void clnt_dg_destroy(CLIENT *);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This machinery implements per-fd locks for MT-safety. It is not
|
||||
* sufficient to do per-CLIENT handle locks for MT-safety because a
|
||||
* user may create more than one CLIENT handle with the same fd behind
|
||||
* it. Therfore, we allocate an array of flags (dg_fd_locks), protected
|
||||
* by the clnt_fd_lock mutex, and an array (dg_cv) of condition variables
|
||||
* similarly protected. Dg_fd_lock[fd] == 1 => a call is activte on some
|
||||
* CLIENT handle created for that fd.
|
||||
* The current implementation holds locks across the entire RPC and reply,
|
||||
* including retransmissions. Yes, this is silly, and as soon as this
|
||||
* code is proven to work, this should be the first thing fixed. One step
|
||||
* at a time.
|
||||
*/
|
||||
static int *dg_fd_locks;
|
||||
static cond_t *dg_cv;
|
||||
#define release_fd_lock(fd, mask) { \
|
||||
mutex_lock(&clnt_fd_lock); \
|
||||
dg_fd_locks[fd] = 0; \
|
||||
mutex_unlock(&clnt_fd_lock); \
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL); \
|
||||
cond_signal(&dg_cv[fd]); \
|
||||
}
|
||||
|
||||
static const char mem_err_clnt_dg[] = "clnt_dg_create: out of memory";
|
||||
|
||||
/* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd_locks, dg_cv */
|
||||
|
||||
#define MCALL_MSG_SIZE 24
|
||||
|
||||
/*
|
||||
* Private data kept per client handle
|
||||
*/
|
||||
struct cu_data {
|
||||
int cu_fd; /* connections fd */
|
||||
bool_t cu_closeit; /* opened by library */
|
||||
struct sockaddr_storage cu_raddr; /* remote address */
|
||||
int cu_rlen;
|
||||
struct timeval cu_wait; /* retransmit interval */
|
||||
struct timeval cu_total; /* total time for the call */
|
||||
struct rpc_err cu_error;
|
||||
XDR cu_outxdrs;
|
||||
u_int cu_xdrpos;
|
||||
u_int cu_sendsz; /* send size */
|
||||
char cu_outhdr[MCALL_MSG_SIZE];
|
||||
char *cu_outbuf;
|
||||
u_int cu_recvsz; /* recv size */
|
||||
int cu_async;
|
||||
int cu_connect; /* Use connect(). */
|
||||
int cu_connected; /* Have done connect(). */
|
||||
struct kevent cu_kin;
|
||||
int cu_kq;
|
||||
char cu_inbuf[1];
|
||||
};
|
||||
|
||||
/*
|
||||
* Connection less client creation returns with client handle parameters.
|
||||
* Default options are set, which the user can change using clnt_control().
|
||||
* fd should be open and bound.
|
||||
* NB: The rpch->cl_auth is initialized to null authentication.
|
||||
* Caller may wish to set this something more useful.
|
||||
*
|
||||
* sendsz and recvsz are the maximum allowable packet sizes that can be
|
||||
* sent and received. Normally they are the same, but they can be
|
||||
* changed to improve the program efficiency and buffer allocation.
|
||||
* If they are 0, use the transport default.
|
||||
*
|
||||
* If svcaddr is NULL, returns NULL.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
|
||||
int fd; /* open file descriptor */
|
||||
const struct netbuf *svcaddr; /* servers address */
|
||||
rpcprog_t program; /* program number */
|
||||
rpcvers_t version; /* version number */
|
||||
u_int sendsz; /* buffer recv size */
|
||||
u_int recvsz; /* buffer send size */
|
||||
{
|
||||
CLIENT *cl = NULL; /* client handle */
|
||||
struct cu_data *cu = NULL; /* private data */
|
||||
struct timeval now;
|
||||
struct rpc_msg call_msg;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
struct __rpc_sockinfo si;
|
||||
int one = 1;
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
if (dg_fd_locks == (int *) NULL) {
|
||||
int cv_allocsz;
|
||||
size_t fd_allocsz;
|
||||
int dtbsize = __rpc_dtbsize();
|
||||
|
||||
fd_allocsz = dtbsize * sizeof (int);
|
||||
dg_fd_locks = (int *) mem_alloc(fd_allocsz);
|
||||
if (dg_fd_locks == (int *) NULL) {
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
goto err1;
|
||||
} else
|
||||
memset(dg_fd_locks, '\0', fd_allocsz);
|
||||
|
||||
cv_allocsz = dtbsize * sizeof (cond_t);
|
||||
dg_cv = (cond_t *) mem_alloc(cv_allocsz);
|
||||
if (dg_cv == (cond_t *) NULL) {
|
||||
mem_free(dg_fd_locks, fd_allocsz);
|
||||
dg_fd_locks = (int *) NULL;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
goto err1;
|
||||
} else {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dtbsize; i++)
|
||||
cond_init(&dg_cv[i], 0, (void *) 0);
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
|
||||
if (svcaddr == NULL) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (!__rpc_fd2sockinfo(fd, &si)) {
|
||||
rpc_createerr.cf_stat = RPC_TLIERROR;
|
||||
rpc_createerr.cf_error.re_errno = 0;
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
* Find the receive and the send size
|
||||
*/
|
||||
sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
|
||||
recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
|
||||
if ((sendsz == 0) || (recvsz == 0)) {
|
||||
rpc_createerr.cf_stat = RPC_TLIERROR; /* XXX */
|
||||
rpc_createerr.cf_error.re_errno = 0;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((cl = mem_alloc(sizeof (CLIENT))) == NULL)
|
||||
goto err1;
|
||||
/*
|
||||
* Should be multiple of 4 for XDR.
|
||||
*/
|
||||
sendsz = ((sendsz + 3) / 4) * 4;
|
||||
recvsz = ((recvsz + 3) / 4) * 4;
|
||||
cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
|
||||
if (cu == NULL)
|
||||
goto err1;
|
||||
(void) memcpy(&cu->cu_raddr, svcaddr->buf, (size_t)svcaddr->len);
|
||||
cu->cu_rlen = svcaddr->len;
|
||||
cu->cu_outbuf = &cu->cu_inbuf[recvsz];
|
||||
/* Other values can also be set through clnt_control() */
|
||||
cu->cu_wait.tv_sec = 15; /* heuristically chosen */
|
||||
cu->cu_wait.tv_usec = 0;
|
||||
cu->cu_total.tv_sec = -1;
|
||||
cu->cu_total.tv_usec = -1;
|
||||
cu->cu_sendsz = sendsz;
|
||||
cu->cu_recvsz = recvsz;
|
||||
cu->cu_async = FALSE;
|
||||
cu->cu_connect = FALSE;
|
||||
cu->cu_connected = FALSE;
|
||||
(void) gettimeofday(&now, NULL);
|
||||
call_msg.rm_xid = __RPC_GETXID(&now);
|
||||
call_msg.rm_call.cb_prog = program;
|
||||
call_msg.rm_call.cb_vers = version;
|
||||
xdrmem_create(&(cu->cu_outxdrs), cu->cu_outhdr, MCALL_MSG_SIZE,
|
||||
XDR_ENCODE);
|
||||
if (! xdr_callhdr(&cu->cu_outxdrs, &call_msg)) {
|
||||
rpc_createerr.cf_stat = RPC_CANTENCODEARGS; /* XXX */
|
||||
rpc_createerr.cf_error.re_errno = 0;
|
||||
goto err2;
|
||||
}
|
||||
cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
|
||||
XDR_DESTROY(&cu->cu_outxdrs);
|
||||
xdrmem_create(&cu->cu_outxdrs, cu->cu_outbuf, sendsz, XDR_ENCODE);
|
||||
|
||||
/* XXX fvdl - do we still want this? */
|
||||
#if 0
|
||||
(void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
|
||||
#endif
|
||||
_ioctl(fd, FIONBIO, (char *)(void *)&one);
|
||||
|
||||
/*
|
||||
* By default, closeit is always FALSE. It is users responsibility
|
||||
* to do a close on it, else the user may use clnt_control
|
||||
* to let clnt_destroy do it for him/her.
|
||||
*/
|
||||
cu->cu_closeit = FALSE;
|
||||
cu->cu_fd = fd;
|
||||
cl->cl_ops = clnt_dg_ops();
|
||||
cl->cl_private = (caddr_t)(void *)cu;
|
||||
cl->cl_auth = authnone_create();
|
||||
cl->cl_tp = NULL;
|
||||
cl->cl_netid = NULL;
|
||||
cu->cu_kq = -1;
|
||||
EV_SET(&cu->cu_kin, cu->cu_fd, EVFILT_READ, EV_ADD, 0, 0, 0);
|
||||
return (cl);
|
||||
err1:
|
||||
warnx(mem_err_clnt_dg);
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
err2:
|
||||
if (cl) {
|
||||
mem_free(cl, sizeof (CLIENT));
|
||||
if (cu)
|
||||
mem_free(cu, sizeof (*cu) + sendsz + recvsz);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static enum clnt_stat
|
||||
clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
|
||||
CLIENT *cl; /* client handle */
|
||||
rpcproc_t proc; /* procedure number */
|
||||
xdrproc_t xargs; /* xdr routine for args */
|
||||
void *argsp; /* pointer to args */
|
||||
xdrproc_t xresults; /* xdr routine for results */
|
||||
void *resultsp; /* pointer to results */
|
||||
struct timeval utimeout; /* seconds to wait before giving up */
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
XDR *xdrs;
|
||||
size_t outlen = 0;
|
||||
struct rpc_msg reply_msg;
|
||||
XDR reply_xdrs;
|
||||
bool_t ok;
|
||||
int nrefreshes = 2; /* number of times to refresh cred */
|
||||
int nretries = 0; /* number of times we retransmitted */
|
||||
struct timeval timeout;
|
||||
struct timeval retransmit_time;
|
||||
struct timeval next_sendtime, starttime, time_waited, tv;
|
||||
struct timespec ts;
|
||||
struct kevent kv;
|
||||
struct sockaddr *sa;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
socklen_t inlen, salen;
|
||||
ssize_t recvlen = 0;
|
||||
int kin_len, n, rpc_lock_value;
|
||||
u_int32_t xid;
|
||||
|
||||
outlen = 0;
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (dg_fd_locks[cu->cu_fd])
|
||||
cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
|
||||
if (__isthreaded)
|
||||
rpc_lock_value = 1;
|
||||
else
|
||||
rpc_lock_value = 0;
|
||||
dg_fd_locks[cu->cu_fd] = rpc_lock_value;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
if (cu->cu_total.tv_usec == -1) {
|
||||
timeout = utimeout; /* use supplied timeout */
|
||||
} else {
|
||||
timeout = cu->cu_total; /* use default timeout */
|
||||
}
|
||||
|
||||
if (cu->cu_connect && !cu->cu_connected) {
|
||||
if (_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
|
||||
cu->cu_rlen) < 0) {
|
||||
cu->cu_error.re_errno = errno;
|
||||
cu->cu_error.re_status = RPC_CANTSEND;
|
||||
goto out;
|
||||
}
|
||||
cu->cu_connected = 1;
|
||||
}
|
||||
if (cu->cu_connected) {
|
||||
sa = NULL;
|
||||
salen = 0;
|
||||
} else {
|
||||
sa = (struct sockaddr *)&cu->cu_raddr;
|
||||
salen = cu->cu_rlen;
|
||||
}
|
||||
time_waited.tv_sec = 0;
|
||||
time_waited.tv_usec = 0;
|
||||
retransmit_time = next_sendtime = cu->cu_wait;
|
||||
gettimeofday(&starttime, NULL);
|
||||
|
||||
/* Clean up in case the last call ended in a longjmp(3) call. */
|
||||
if (cu->cu_kq >= 0)
|
||||
_close(cu->cu_kq);
|
||||
if ((cu->cu_kq = kqueue()) < 0) {
|
||||
cu->cu_error.re_errno = errno;
|
||||
cu->cu_error.re_status = RPC_CANTSEND;
|
||||
goto out;
|
||||
}
|
||||
kin_len = 1;
|
||||
|
||||
call_again:
|
||||
if (cu->cu_async == TRUE && xargs == NULL)
|
||||
goto get_reply;
|
||||
/*
|
||||
* the transaction is the first thing in the out buffer
|
||||
* XXX Yes, and it's in network byte order, so we should to
|
||||
* be careful when we increment it, shouldn't we.
|
||||
*/
|
||||
xid = ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr));
|
||||
xid++;
|
||||
*(u_int32_t *)(void *)(cu->cu_outhdr) = htonl(xid);
|
||||
call_again_same_xid:
|
||||
xdrs = &(cu->cu_outxdrs);
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
XDR_SETPOS(xdrs, 0);
|
||||
|
||||
if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
|
||||
if ((! XDR_PUTBYTES(xdrs, cu->cu_outhdr, cu->cu_xdrpos)) ||
|
||||
(! XDR_PUTINT32(xdrs, &proc)) ||
|
||||
(! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
|
||||
(! (*xargs)(xdrs, argsp))) {
|
||||
cu->cu_error.re_status = RPC_CANTENCODEARGS;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
*(uint32_t *) &cu->cu_outhdr[cu->cu_xdrpos] = htonl(proc);
|
||||
if (!__rpc_gss_wrap(cl->cl_auth, cu->cu_outhdr,
|
||||
cu->cu_xdrpos + sizeof(uint32_t),
|
||||
xdrs, xargs, argsp)) {
|
||||
cu->cu_error.re_status = RPC_CANTENCODEARGS;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
outlen = (size_t)XDR_GETPOS(xdrs);
|
||||
|
||||
send_again:
|
||||
if (_sendto(cu->cu_fd, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) {
|
||||
cu->cu_error.re_errno = errno;
|
||||
cu->cu_error.re_status = RPC_CANTSEND;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hack to provide rpc-based message passing
|
||||
*/
|
||||
if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
|
||||
cu->cu_error.re_status = RPC_TIMEDOUT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
get_reply:
|
||||
|
||||
/*
|
||||
* sub-optimal code appears here because we have
|
||||
* some clock time to spare while the packets are in flight.
|
||||
* (We assume that this is actually only executed once.)
|
||||
*/
|
||||
reply_msg.acpted_rply.ar_verf = _null_auth;
|
||||
if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
|
||||
reply_msg.acpted_rply.ar_results.where = resultsp;
|
||||
reply_msg.acpted_rply.ar_results.proc = xresults;
|
||||
} else {
|
||||
reply_msg.acpted_rply.ar_results.where = NULL;
|
||||
reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
/* Decide how long to wait. */
|
||||
if (timercmp(&next_sendtime, &timeout, <))
|
||||
timersub(&next_sendtime, &time_waited, &tv);
|
||||
else
|
||||
timersub(&timeout, &time_waited, &tv);
|
||||
if (tv.tv_sec < 0 || tv.tv_usec < 0)
|
||||
tv.tv_sec = tv.tv_usec = 0;
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &ts);
|
||||
|
||||
n = _kevent(cu->cu_kq, &cu->cu_kin, kin_len, &kv, 1, &ts);
|
||||
/* We don't need to register the event again. */
|
||||
kin_len = 0;
|
||||
|
||||
if (n == 1) {
|
||||
if (kv.flags & EV_ERROR) {
|
||||
cu->cu_error.re_errno = kv.data;
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
/* We have some data now */
|
||||
do {
|
||||
recvlen = _recvfrom(cu->cu_fd, cu->cu_inbuf,
|
||||
cu->cu_recvsz, 0, NULL, NULL);
|
||||
} while (recvlen < 0 && errno == EINTR);
|
||||
if (recvlen < 0 && errno != EWOULDBLOCK) {
|
||||
cu->cu_error.re_errno = errno;
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
if (recvlen >= sizeof(u_int32_t) &&
|
||||
(cu->cu_async == TRUE ||
|
||||
*((u_int32_t *)(void *)(cu->cu_inbuf)) ==
|
||||
*((u_int32_t *)(void *)(cu->cu_outbuf)))) {
|
||||
/* We now assume we have the proper reply. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n == -1 && errno != EINTR) {
|
||||
cu->cu_error.re_errno = errno;
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
gettimeofday(&tv, NULL);
|
||||
timersub(&tv, &starttime, &time_waited);
|
||||
|
||||
/* Check for timeout. */
|
||||
if (timercmp(&time_waited, &timeout, >)) {
|
||||
cu->cu_error.re_status = RPC_TIMEDOUT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Retransmit if necessary. */
|
||||
if (timercmp(&time_waited, &next_sendtime, >)) {
|
||||
/* update retransmit_time */
|
||||
if (retransmit_time.tv_sec < RPC_MAX_BACKOFF)
|
||||
timeradd(&retransmit_time, &retransmit_time,
|
||||
&retransmit_time);
|
||||
timeradd(&next_sendtime, &retransmit_time,
|
||||
&next_sendtime);
|
||||
nretries++;
|
||||
|
||||
/*
|
||||
* When retransmitting a RPCSEC_GSS message,
|
||||
* we must use a new sequence number (handled
|
||||
* by __rpc_gss_wrap above).
|
||||
*/
|
||||
if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS)
|
||||
goto send_again;
|
||||
else
|
||||
goto call_again_same_xid;
|
||||
}
|
||||
}
|
||||
inlen = (socklen_t)recvlen;
|
||||
|
||||
/*
|
||||
* now decode and validate the response
|
||||
*/
|
||||
|
||||
xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)recvlen, XDR_DECODE);
|
||||
ok = xdr_replymsg(&reply_xdrs, &reply_msg);
|
||||
/* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
|
||||
if (ok) {
|
||||
if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
|
||||
(reply_msg.acpted_rply.ar_stat == SUCCESS))
|
||||
cu->cu_error.re_status = RPC_SUCCESS;
|
||||
else
|
||||
_seterr_reply(&reply_msg, &(cu->cu_error));
|
||||
|
||||
if (cu->cu_error.re_status == RPC_SUCCESS) {
|
||||
if (! AUTH_VALIDATE(cl->cl_auth,
|
||||
&reply_msg.acpted_rply.ar_verf)) {
|
||||
if (nretries &&
|
||||
cl->cl_auth->ah_cred.oa_flavor
|
||||
== RPCSEC_GSS)
|
||||
/*
|
||||
* If we retransmitted, its
|
||||
* possible that we will
|
||||
* receive a reply for one of
|
||||
* the earlier transmissions
|
||||
* (which will use an older
|
||||
* RPCSEC_GSS sequence
|
||||
* number). In this case, just
|
||||
* go back and listen for a
|
||||
* new reply. We could keep a
|
||||
* record of all the seq
|
||||
* numbers we have transmitted
|
||||
* so far so that we could
|
||||
* accept a reply for any of
|
||||
* them here.
|
||||
*/
|
||||
goto get_reply;
|
||||
cu->cu_error.re_status = RPC_AUTHERROR;
|
||||
cu->cu_error.re_why = AUTH_INVALIDRESP;
|
||||
} else {
|
||||
if (cl->cl_auth->ah_cred.oa_flavor
|
||||
== RPCSEC_GSS) {
|
||||
if (!__rpc_gss_unwrap(cl->cl_auth,
|
||||
&reply_xdrs, xresults,
|
||||
resultsp))
|
||||
cu->cu_error.re_status =
|
||||
RPC_CANTDECODERES;
|
||||
}
|
||||
}
|
||||
if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
|
||||
xdrs->x_op = XDR_FREE;
|
||||
(void) xdr_opaque_auth(xdrs,
|
||||
&(reply_msg.acpted_rply.ar_verf));
|
||||
}
|
||||
} /* end successful completion */
|
||||
/*
|
||||
* If unsuccesful AND error is an authentication error
|
||||
* then refresh credentials and try again, else break
|
||||
*/
|
||||
else if (cu->cu_error.re_status == RPC_AUTHERROR)
|
||||
/* maybe our credentials need to be refreshed ... */
|
||||
if (nrefreshes > 0 &&
|
||||
AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
|
||||
nrefreshes--;
|
||||
goto call_again;
|
||||
}
|
||||
/* end of unsuccessful completion */
|
||||
} /* end of valid reply message */
|
||||
else {
|
||||
cu->cu_error.re_status = RPC_CANTDECODERES;
|
||||
|
||||
}
|
||||
out:
|
||||
if (cu->cu_kq >= 0)
|
||||
_close(cu->cu_kq);
|
||||
cu->cu_kq = -1;
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (cu->cu_error.re_status);
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_dg_geterr(cl, errp)
|
||||
CLIENT *cl;
|
||||
struct rpc_err *errp;
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
|
||||
*errp = cu->cu_error;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
clnt_dg_freeres(cl, xdr_res, res_ptr)
|
||||
CLIENT *cl;
|
||||
xdrproc_t xdr_res;
|
||||
void *res_ptr;
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
XDR *xdrs = &(cu->cu_outxdrs);
|
||||
bool_t dummy;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (dg_fd_locks[cu->cu_fd])
|
||||
cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
|
||||
xdrs->x_op = XDR_FREE;
|
||||
dummy = (*xdr_res)(xdrs, res_ptr);
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &mask, NULL);
|
||||
cond_signal(&dg_cv[cu->cu_fd]);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
clnt_dg_abort(h)
|
||||
CLIENT *h;
|
||||
{
|
||||
}
|
||||
|
||||
static bool_t
|
||||
clnt_dg_control(cl, request, info)
|
||||
CLIENT *cl;
|
||||
u_int request;
|
||||
void *info;
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
struct netbuf *addr;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
int rpc_lock_value;
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (dg_fd_locks[cu->cu_fd])
|
||||
cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
|
||||
if (__isthreaded)
|
||||
rpc_lock_value = 1;
|
||||
else
|
||||
rpc_lock_value = 0;
|
||||
dg_fd_locks[cu->cu_fd] = rpc_lock_value;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
switch (request) {
|
||||
case CLSET_FD_CLOSE:
|
||||
cu->cu_closeit = TRUE;
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (TRUE);
|
||||
case CLSET_FD_NCLOSE:
|
||||
cu->cu_closeit = FALSE;
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/* for other requests which use info */
|
||||
if (info == NULL) {
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
switch (request) {
|
||||
case CLSET_TIMEOUT:
|
||||
if (time_not_ok((struct timeval *)info)) {
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
cu->cu_total = *(struct timeval *)info;
|
||||
break;
|
||||
case CLGET_TIMEOUT:
|
||||
*(struct timeval *)info = cu->cu_total;
|
||||
break;
|
||||
case CLGET_SERVER_ADDR: /* Give him the fd address */
|
||||
/* Now obsolete. Only for backward compatibility */
|
||||
(void) memcpy(info, &cu->cu_raddr, (size_t)cu->cu_rlen);
|
||||
break;
|
||||
case CLSET_RETRY_TIMEOUT:
|
||||
if (time_not_ok((struct timeval *)info)) {
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
cu->cu_wait = *(struct timeval *)info;
|
||||
break;
|
||||
case CLGET_RETRY_TIMEOUT:
|
||||
*(struct timeval *)info = cu->cu_wait;
|
||||
break;
|
||||
case CLGET_FD:
|
||||
*(int *)info = cu->cu_fd;
|
||||
break;
|
||||
case CLGET_SVC_ADDR:
|
||||
addr = (struct netbuf *)info;
|
||||
addr->buf = &cu->cu_raddr;
|
||||
addr->len = cu->cu_rlen;
|
||||
addr->maxlen = sizeof cu->cu_raddr;
|
||||
break;
|
||||
case CLSET_SVC_ADDR: /* set to new address */
|
||||
addr = (struct netbuf *)info;
|
||||
if (addr->len < sizeof cu->cu_raddr) {
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
(void) memcpy(&cu->cu_raddr, addr->buf, addr->len);
|
||||
cu->cu_rlen = addr->len;
|
||||
break;
|
||||
case CLGET_XID:
|
||||
/*
|
||||
* use the knowledge that xid is the
|
||||
* first element in the call structure *.
|
||||
* This will get the xid of the PREVIOUS call
|
||||
*/
|
||||
*(u_int32_t *)info =
|
||||
ntohl(*(u_int32_t *)(void *)cu->cu_outhdr);
|
||||
break;
|
||||
|
||||
case CLSET_XID:
|
||||
/* This will set the xid of the NEXT call */
|
||||
*(u_int32_t *)(void *)cu->cu_outhdr =
|
||||
htonl(*(u_int32_t *)info - 1);
|
||||
/* decrement by 1 as clnt_dg_call() increments once */
|
||||
break;
|
||||
|
||||
case CLGET_VERS:
|
||||
/*
|
||||
* This RELIES on the information that, in the call body,
|
||||
* the version number field is the fifth field from the
|
||||
* begining of the RPC header. MUST be changed if the
|
||||
* call_struct is changed
|
||||
*/
|
||||
*(u_int32_t *)info =
|
||||
ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
|
||||
4 * BYTES_PER_XDR_UNIT));
|
||||
break;
|
||||
|
||||
case CLSET_VERS:
|
||||
*(u_int32_t *)(void *)(cu->cu_outhdr + 4 * BYTES_PER_XDR_UNIT)
|
||||
= htonl(*(u_int32_t *)info);
|
||||
break;
|
||||
|
||||
case CLGET_PROG:
|
||||
/*
|
||||
* This RELIES on the information that, in the call body,
|
||||
* the program number field is the fourth field from the
|
||||
* begining of the RPC header. MUST be changed if the
|
||||
* call_struct is changed
|
||||
*/
|
||||
*(u_int32_t *)info =
|
||||
ntohl(*(u_int32_t *)(void *)(cu->cu_outhdr +
|
||||
3 * BYTES_PER_XDR_UNIT));
|
||||
break;
|
||||
|
||||
case CLSET_PROG:
|
||||
*(u_int32_t *)(void *)(cu->cu_outhdr + 3 * BYTES_PER_XDR_UNIT)
|
||||
= htonl(*(u_int32_t *)info);
|
||||
break;
|
||||
case CLSET_ASYNC:
|
||||
cu->cu_async = *(int *)info;
|
||||
break;
|
||||
case CLSET_CONNECT:
|
||||
cu->cu_connect = *(int *)info;
|
||||
break;
|
||||
default:
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
release_fd_lock(cu->cu_fd, mask);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_dg_destroy(cl)
|
||||
CLIENT *cl;
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
int cu_fd = cu->cu_fd;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (dg_fd_locks[cu_fd])
|
||||
cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
|
||||
if (cu->cu_closeit)
|
||||
(void)_close(cu_fd);
|
||||
if (cu->cu_kq >= 0)
|
||||
_close(cu->cu_kq);
|
||||
XDR_DESTROY(&(cu->cu_outxdrs));
|
||||
mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
|
||||
if (cl->cl_netid && cl->cl_netid[0])
|
||||
mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
|
||||
if (cl->cl_tp && cl->cl_tp[0])
|
||||
mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
|
||||
mem_free(cl, sizeof (CLIENT));
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &mask, NULL);
|
||||
cond_signal(&dg_cv[cu_fd]);
|
||||
}
|
||||
|
||||
static struct clnt_ops *
|
||||
clnt_dg_ops()
|
||||
{
|
||||
static struct clnt_ops ops;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.cl_call == NULL) {
|
||||
ops.cl_call = clnt_dg_call;
|
||||
ops.cl_abort = clnt_dg_abort;
|
||||
ops.cl_geterr = clnt_dg_geterr;
|
||||
ops.cl_freeres = clnt_dg_freeres;
|
||||
ops.cl_destroy = clnt_dg_destroy;
|
||||
ops.cl_control = clnt_dg_control;
|
||||
}
|
||||
mutex_unlock(&ops_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &mask, NULL);
|
||||
return (&ops);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure that the time is not garbage. -1 value is allowed.
|
||||
*/
|
||||
static bool_t
|
||||
time_not_ok(t)
|
||||
struct timeval *t;
|
||||
{
|
||||
return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
|
||||
t->tv_usec < -1 || t->tv_usec > 1000000);
|
||||
}
|
||||
|
450
freebsd/lib/libc/rpc/clnt_generic.c
Normal file
450
freebsd/lib/libc/rpc/clnt_generic.c
Normal file
@ -0,0 +1,450 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_generic.c,v 1.18 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010, Oracle America, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of the "Oracle America, Inc." nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* #ident "@(#)clnt_generic.c 1.40 99/04/21 SMI" */
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "from: @(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
|
||||
static char *sccsid = "from: @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986-1996,1998 by Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <syslog.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/nettype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
#include "rpc_com.h"
|
||||
|
||||
extern bool_t __rpc_is_local_host(const char *);
|
||||
int __rpc_raise_fd(int);
|
||||
|
||||
#ifndef NETIDLEN
|
||||
#define NETIDLEN 32
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Generic client creation with version checking the value of
|
||||
* vers_out is set to the highest server supported value
|
||||
* vers_low <= vers_out <= vers_high AND an error results
|
||||
* if this can not be done.
|
||||
*
|
||||
* It calls clnt_create_vers_timed() with a NULL value for the timeout
|
||||
* pointer, which indicates that the default timeout should be used.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_create_vers(const char *hostname, rpcprog_t prog, rpcvers_t *vers_out,
|
||||
rpcvers_t vers_low, rpcvers_t vers_high, const char *nettype)
|
||||
{
|
||||
|
||||
return (clnt_create_vers_timed(hostname, prog, vers_out, vers_low,
|
||||
vers_high, nettype, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* This the routine has the same definition as clnt_create_vers(),
|
||||
* except it takes an additional timeout parameter - a pointer to
|
||||
* a timeval structure. A NULL value for the pointer indicates
|
||||
* that the default timeout value should be used.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_create_vers_timed(const char *hostname, rpcprog_t prog,
|
||||
rpcvers_t *vers_out, rpcvers_t vers_low, rpcvers_t vers_high,
|
||||
const char *nettype, const struct timeval *tp)
|
||||
{
|
||||
CLIENT *clnt;
|
||||
struct timeval to;
|
||||
enum clnt_stat rpc_stat;
|
||||
struct rpc_err rpcerr;
|
||||
|
||||
clnt = clnt_create_timed(hostname, prog, vers_high, nettype, tp);
|
||||
if (clnt == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
to.tv_sec = 10;
|
||||
to.tv_usec = 0;
|
||||
rpc_stat = clnt_call(clnt, NULLPROC, (xdrproc_t)xdr_void,
|
||||
(char *)NULL, (xdrproc_t)xdr_void, (char *)NULL, to);
|
||||
if (rpc_stat == RPC_SUCCESS) {
|
||||
*vers_out = vers_high;
|
||||
return (clnt);
|
||||
}
|
||||
while (rpc_stat == RPC_PROGVERSMISMATCH && vers_high > vers_low) {
|
||||
unsigned int minvers, maxvers;
|
||||
|
||||
clnt_geterr(clnt, &rpcerr);
|
||||
minvers = rpcerr.re_vers.low;
|
||||
maxvers = rpcerr.re_vers.high;
|
||||
if (maxvers < vers_high)
|
||||
vers_high = maxvers;
|
||||
else
|
||||
vers_high--;
|
||||
if (minvers > vers_low)
|
||||
vers_low = minvers;
|
||||
if (vers_low > vers_high) {
|
||||
goto error;
|
||||
}
|
||||
CLNT_CONTROL(clnt, CLSET_VERS, (char *)&vers_high);
|
||||
rpc_stat = clnt_call(clnt, NULLPROC, (xdrproc_t)xdr_void,
|
||||
(char *)NULL, (xdrproc_t)xdr_void,
|
||||
(char *)NULL, to);
|
||||
if (rpc_stat == RPC_SUCCESS) {
|
||||
*vers_out = vers_high;
|
||||
return (clnt);
|
||||
}
|
||||
}
|
||||
clnt_geterr(clnt, &rpcerr);
|
||||
|
||||
error:
|
||||
rpc_createerr.cf_stat = rpc_stat;
|
||||
rpc_createerr.cf_error = rpcerr;
|
||||
clnt_destroy(clnt);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Top level client creation routine.
|
||||
* Generic client creation: takes (servers name, program-number, nettype) and
|
||||
* returns client handle. Default options are set, which the user can
|
||||
* change using the rpc equivalent of _ioctl()'s.
|
||||
*
|
||||
* It tries for all the netids in that particular class of netid until
|
||||
* it succeeds.
|
||||
* XXX The error message in the case of failure will be the one
|
||||
* pertaining to the last create error.
|
||||
*
|
||||
* It calls clnt_create_timed() with the default timeout.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_create(const char *hostname, rpcprog_t prog, rpcvers_t vers,
|
||||
const char *nettype)
|
||||
{
|
||||
|
||||
return (clnt_create_timed(hostname, prog, vers, nettype, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* This the routine has the same definition as clnt_create(),
|
||||
* except it takes an additional timeout parameter - a pointer to
|
||||
* a timeval structure. A NULL value for the pointer indicates
|
||||
* that the default timeout value should be used.
|
||||
*
|
||||
* This function calls clnt_tp_create_timed().
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_create_timed(const char *hostname, rpcprog_t prog, rpcvers_t vers,
|
||||
const char *netclass, const struct timeval *tp)
|
||||
{
|
||||
struct netconfig *nconf;
|
||||
CLIENT *clnt = NULL;
|
||||
void *handle;
|
||||
enum clnt_stat save_cf_stat = RPC_SUCCESS;
|
||||
struct rpc_err save_cf_error;
|
||||
char nettype_array[NETIDLEN];
|
||||
char *nettype = &nettype_array[0];
|
||||
|
||||
if (netclass == NULL)
|
||||
nettype = NULL;
|
||||
else {
|
||||
size_t len = strlen(netclass);
|
||||
if (len >= sizeof (nettype_array)) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
return (NULL);
|
||||
}
|
||||
strcpy(nettype, netclass);
|
||||
}
|
||||
|
||||
if ((handle = __rpc_setconf((char *)nettype)) == NULL) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
return (NULL);
|
||||
}
|
||||
rpc_createerr.cf_stat = RPC_SUCCESS;
|
||||
while (clnt == NULL) {
|
||||
if ((nconf = __rpc_getconf(handle)) == NULL) {
|
||||
if (rpc_createerr.cf_stat == RPC_SUCCESS)
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
break;
|
||||
}
|
||||
#ifdef CLNT_DEBUG
|
||||
printf("trying netid %s\n", nconf->nc_netid);
|
||||
#endif
|
||||
clnt = clnt_tp_create_timed(hostname, prog, vers, nconf, tp);
|
||||
if (clnt)
|
||||
break;
|
||||
else
|
||||
/*
|
||||
* Since we didn't get a name-to-address
|
||||
* translation failure here, we remember
|
||||
* this particular error. The object of
|
||||
* this is to enable us to return to the
|
||||
* caller a more-specific error than the
|
||||
* unhelpful ``Name to address translation
|
||||
* failed'' which might well occur if we
|
||||
* merely returned the last error (because
|
||||
* the local loopbacks are typically the
|
||||
* last ones in /etc/netconfig and the most
|
||||
* likely to be unable to translate a host
|
||||
* name). We also check for a more
|
||||
* meaningful error than ``unknown host
|
||||
* name'' for the same reasons.
|
||||
*/
|
||||
if (rpc_createerr.cf_stat != RPC_N2AXLATEFAILURE &&
|
||||
rpc_createerr.cf_stat != RPC_UNKNOWNHOST) {
|
||||
save_cf_stat = rpc_createerr.cf_stat;
|
||||
save_cf_error = rpc_createerr.cf_error;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to return an error more specific than ``Name to address
|
||||
* translation failed'' or ``unknown host name''
|
||||
*/
|
||||
if ((rpc_createerr.cf_stat == RPC_N2AXLATEFAILURE ||
|
||||
rpc_createerr.cf_stat == RPC_UNKNOWNHOST) &&
|
||||
(save_cf_stat != RPC_SUCCESS)) {
|
||||
rpc_createerr.cf_stat = save_cf_stat;
|
||||
rpc_createerr.cf_error = save_cf_error;
|
||||
}
|
||||
__rpc_endconf(handle);
|
||||
return (clnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic client creation: takes (servers name, program-number, netconf) and
|
||||
* returns client handle. Default options are set, which the user can
|
||||
* change using the rpc equivalent of _ioctl()'s : clnt_control()
|
||||
* It finds out the server address from rpcbind and calls clnt_tli_create().
|
||||
*
|
||||
* It calls clnt_tp_create_timed() with the default timeout.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_tp_create(const char *hostname, rpcprog_t prog, rpcvers_t vers,
|
||||
const struct netconfig *nconf)
|
||||
{
|
||||
|
||||
return (clnt_tp_create_timed(hostname, prog, vers, nconf, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* This has the same definition as clnt_tp_create(), except it
|
||||
* takes an additional parameter - a pointer to a timeval structure.
|
||||
* A NULL value for the timeout pointer indicates that the default
|
||||
* value for the timeout should be used.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_tp_create_timed(const char *hostname, rpcprog_t prog, rpcvers_t vers,
|
||||
const struct netconfig *nconf, const struct timeval *tp)
|
||||
{
|
||||
struct netbuf *svcaddr; /* servers address */
|
||||
CLIENT *cl = NULL; /* client handle */
|
||||
|
||||
if (nconf == NULL) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the address of the server
|
||||
*/
|
||||
if ((svcaddr = __rpcb_findaddr_timed(prog, vers,
|
||||
(struct netconfig *)nconf, (char *)hostname,
|
||||
&cl, (struct timeval *)tp)) == NULL) {
|
||||
/* appropriate error number is set by rpcbind libraries */
|
||||
return (NULL);
|
||||
}
|
||||
if (cl == NULL) {
|
||||
cl = clnt_tli_create(RPC_ANYFD, nconf, svcaddr,
|
||||
prog, vers, 0, 0);
|
||||
} else {
|
||||
/* Reuse the CLIENT handle and change the appropriate fields */
|
||||
if (CLNT_CONTROL(cl, CLSET_SVC_ADDR, (void *)svcaddr) == TRUE) {
|
||||
if (cl->cl_netid == NULL)
|
||||
cl->cl_netid = strdup(nconf->nc_netid);
|
||||
if (cl->cl_tp == NULL)
|
||||
cl->cl_tp = strdup(nconf->nc_device);
|
||||
(void) CLNT_CONTROL(cl, CLSET_PROG, (void *)&prog);
|
||||
(void) CLNT_CONTROL(cl, CLSET_VERS, (void *)&vers);
|
||||
} else {
|
||||
CLNT_DESTROY(cl);
|
||||
cl = clnt_tli_create(RPC_ANYFD, nconf, svcaddr,
|
||||
prog, vers, 0, 0);
|
||||
}
|
||||
}
|
||||
free(svcaddr->buf);
|
||||
free(svcaddr);
|
||||
return (cl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic client creation: returns client handle.
|
||||
* Default options are set, which the user can
|
||||
* change using the rpc equivalent of _ioctl()'s : clnt_control().
|
||||
* If fd is RPC_ANYFD, it will be opened using nconf.
|
||||
* It will be bound if not so.
|
||||
* If sizes are 0; appropriate defaults will be chosen.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_tli_create(int fd, const struct netconfig *nconf,
|
||||
struct netbuf *svcaddr, rpcprog_t prog, rpcvers_t vers,
|
||||
uint sendsz, uint recvsz)
|
||||
{
|
||||
CLIENT *cl; /* client handle */
|
||||
bool_t madefd = FALSE; /* whether fd opened here */
|
||||
long servtype;
|
||||
int one = 1;
|
||||
struct __rpc_sockinfo si;
|
||||
extern int __rpc_minfd;
|
||||
|
||||
if (fd == RPC_ANYFD) {
|
||||
if (nconf == NULL) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
fd = __rpc_nconf2fd(nconf);
|
||||
|
||||
if (fd == -1)
|
||||
goto err;
|
||||
if (fd < __rpc_minfd)
|
||||
fd = __rpc_raise_fd(fd);
|
||||
madefd = TRUE;
|
||||
servtype = nconf->nc_semantics;
|
||||
if (!__rpc_fd2sockinfo(fd, &si))
|
||||
goto err;
|
||||
bindresvport(fd, NULL);
|
||||
} else {
|
||||
if (!__rpc_fd2sockinfo(fd, &si))
|
||||
goto err;
|
||||
servtype = __rpc_socktype2seman(si.si_socktype);
|
||||
if (servtype == -1) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (si.si_af != ((struct sockaddr *)svcaddr->buf)->sa_family) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNHOST; /* XXX */
|
||||
goto err1;
|
||||
}
|
||||
|
||||
switch (servtype) {
|
||||
case NC_TPI_COTS:
|
||||
cl = clnt_vc_create(fd, svcaddr, prog, vers, sendsz, recvsz);
|
||||
break;
|
||||
case NC_TPI_COTS_ORD:
|
||||
if (nconf && ((strcmp(nconf->nc_protofmly, "inet") == 0))) {
|
||||
_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one,
|
||||
sizeof (one));
|
||||
}
|
||||
cl = clnt_vc_create(fd, svcaddr, prog, vers, sendsz, recvsz);
|
||||
break;
|
||||
case NC_TPI_CLTS:
|
||||
cl = clnt_dg_create(fd, svcaddr, prog, vers, sendsz, recvsz);
|
||||
break;
|
||||
default:
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (cl == NULL)
|
||||
goto err1; /* borrow errors from clnt_dg/vc creates */
|
||||
if (nconf) {
|
||||
cl->cl_netid = strdup(nconf->nc_netid);
|
||||
cl->cl_tp = strdup(nconf->nc_device);
|
||||
} else {
|
||||
cl->cl_netid = "";
|
||||
cl->cl_tp = "";
|
||||
}
|
||||
if (madefd) {
|
||||
(void) CLNT_CONTROL(cl, CLSET_FD_CLOSE, NULL);
|
||||
/* (void) CLNT_CONTROL(cl, CLSET_POP_TIMOD, NULL); */
|
||||
};
|
||||
|
||||
return (cl);
|
||||
|
||||
err:
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
err1: if (madefd)
|
||||
(void)_close(fd);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* To avoid conflicts with the "magic" file descriptors (0, 1, and 2),
|
||||
* we try to not use them. The __rpc_raise_fd() routine will dup
|
||||
* a descriptor to a higher value. If we fail to do it, we continue
|
||||
* to use the old one (and hope for the best).
|
||||
*/
|
||||
int __rpc_minfd = 3;
|
||||
|
||||
int
|
||||
__rpc_raise_fd(int fd)
|
||||
{
|
||||
int nfd;
|
||||
|
||||
if (fd >= __rpc_minfd)
|
||||
return (fd);
|
||||
|
||||
if ((nfd = _fcntl(fd, F_DUPFD, __rpc_minfd)) == -1)
|
||||
return (fd);
|
||||
|
||||
if (_fsync(nfd) == -1) {
|
||||
_close(nfd);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
if (_close(fd) == -1) {
|
||||
/* this is okay, we will syslog an error, then use the new fd */
|
||||
(void) syslog(LOG_ERR,
|
||||
"could not close() fd %d; mem & fd leak", fd);
|
||||
}
|
||||
|
||||
return (nfd);
|
||||
}
|
334
freebsd/lib/libc/rpc/clnt_perror.c
Normal file
334
freebsd/lib/libc/rpc/clnt_perror.c
Normal file
@ -0,0 +1,334 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $ */
|
||||
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* clnt_perror.c
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/clnt.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
static char *buf;
|
||||
|
||||
static char *_buf(void);
|
||||
static char *auth_errmsg(enum auth_stat);
|
||||
#define CLNT_PERROR_BUFLEN 256
|
||||
|
||||
static char *
|
||||
_buf()
|
||||
{
|
||||
|
||||
if (buf == 0)
|
||||
buf = (char *)malloc(CLNT_PERROR_BUFLEN);
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print reply error info
|
||||
*/
|
||||
char *
|
||||
clnt_sperror(rpch, s)
|
||||
CLIENT *rpch;
|
||||
const char *s;
|
||||
{
|
||||
struct rpc_err e;
|
||||
char *err;
|
||||
char *str;
|
||||
char *strstart;
|
||||
size_t len, i;
|
||||
|
||||
assert(rpch != NULL);
|
||||
assert(s != NULL);
|
||||
|
||||
str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
|
||||
if (str == 0)
|
||||
return (0);
|
||||
len = CLNT_PERROR_BUFLEN;
|
||||
strstart = str;
|
||||
CLNT_GETERR(rpch, &e);
|
||||
|
||||
if ((i = snprintf(str, len, "%s: ", s)) > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
|
||||
(void)strncpy(str, clnt_sperrno(e.re_status), len - 1);
|
||||
i = strlen(str);
|
||||
str += i;
|
||||
len -= i;
|
||||
|
||||
switch (e.re_status) {
|
||||
case RPC_SUCCESS:
|
||||
case RPC_CANTENCODEARGS:
|
||||
case RPC_CANTDECODERES:
|
||||
case RPC_TIMEDOUT:
|
||||
case RPC_PROGUNAVAIL:
|
||||
case RPC_PROCUNAVAIL:
|
||||
case RPC_CANTDECODEARGS:
|
||||
case RPC_SYSTEMERROR:
|
||||
case RPC_UNKNOWNHOST:
|
||||
case RPC_UNKNOWNPROTO:
|
||||
case RPC_PMAPFAILURE:
|
||||
case RPC_PROGNOTREGISTERED:
|
||||
case RPC_FAILED:
|
||||
break;
|
||||
|
||||
case RPC_CANTSEND:
|
||||
case RPC_CANTRECV:
|
||||
i = snprintf(str, len, "; errno = %s", strerror(e.re_errno));
|
||||
if (i > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
break;
|
||||
|
||||
case RPC_VERSMISMATCH:
|
||||
i = snprintf(str, len, "; low version = %u, high version = %u",
|
||||
e.re_vers.low, e.re_vers.high);
|
||||
if (i > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
break;
|
||||
|
||||
case RPC_AUTHERROR:
|
||||
err = auth_errmsg(e.re_why);
|
||||
i = snprintf(str, len, "; why = ");
|
||||
if (i > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
if (err != NULL) {
|
||||
i = snprintf(str, len, "%s",err);
|
||||
} else {
|
||||
i = snprintf(str, len,
|
||||
"(unknown authentication error - %d)",
|
||||
(int) e.re_why);
|
||||
}
|
||||
if (i > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
break;
|
||||
|
||||
case RPC_PROGVERSMISMATCH:
|
||||
i = snprintf(str, len, "; low version = %u, high version = %u",
|
||||
e.re_vers.low, e.re_vers.high);
|
||||
if (i > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* unknown */
|
||||
i = snprintf(str, len, "; s1 = %u, s2 = %u",
|
||||
e.re_lb.s1, e.re_lb.s2);
|
||||
if (i > 0) {
|
||||
str += i;
|
||||
len -= i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
strstart[CLNT_PERROR_BUFLEN-1] = '\0';
|
||||
return(strstart) ;
|
||||
}
|
||||
|
||||
void
|
||||
clnt_perror(rpch, s)
|
||||
CLIENT *rpch;
|
||||
const char *s;
|
||||
{
|
||||
|
||||
assert(rpch != NULL);
|
||||
assert(s != NULL);
|
||||
|
||||
(void) fprintf(stderr, "%s\n", clnt_sperror(rpch,s));
|
||||
}
|
||||
|
||||
static const char *const rpc_errlist[] = {
|
||||
"RPC: Success", /* 0 - RPC_SUCCESS */
|
||||
"RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */
|
||||
"RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */
|
||||
"RPC: Unable to send", /* 3 - RPC_CANTSEND */
|
||||
"RPC: Unable to receive", /* 4 - RPC_CANTRECV */
|
||||
"RPC: Timed out", /* 5 - RPC_TIMEDOUT */
|
||||
"RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */
|
||||
"RPC: Authentication error", /* 7 - RPC_AUTHERROR */
|
||||
"RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */
|
||||
"RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */
|
||||
"RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */
|
||||
"RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */
|
||||
"RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */
|
||||
"RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */
|
||||
"RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */
|
||||
"RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */
|
||||
"RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */
|
||||
"RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* This interface for use by clntrpc
|
||||
*/
|
||||
char *
|
||||
clnt_sperrno(stat)
|
||||
enum clnt_stat stat;
|
||||
{
|
||||
unsigned int errnum = stat;
|
||||
|
||||
if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
|
||||
/* LINTED interface problem */
|
||||
return (char *)rpc_errlist[errnum];
|
||||
|
||||
return ("RPC: (unknown error code)");
|
||||
}
|
||||
|
||||
void
|
||||
clnt_perrno(num)
|
||||
enum clnt_stat num;
|
||||
{
|
||||
(void) fprintf(stderr, "%s\n", clnt_sperrno(num));
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
clnt_spcreateerror(s)
|
||||
const char *s;
|
||||
{
|
||||
char *str;
|
||||
size_t len, i;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
|
||||
if (str == 0)
|
||||
return(0);
|
||||
len = CLNT_PERROR_BUFLEN;
|
||||
i = snprintf(str, len, "%s: ", s);
|
||||
if (i > 0)
|
||||
len -= i;
|
||||
(void)strncat(str, clnt_sperrno(rpc_createerr.cf_stat), len - 1);
|
||||
switch (rpc_createerr.cf_stat) {
|
||||
case RPC_PMAPFAILURE:
|
||||
(void) strncat(str, " - ", len - 1);
|
||||
(void) strncat(str,
|
||||
clnt_sperrno(rpc_createerr.cf_error.re_status), len - 4);
|
||||
break;
|
||||
|
||||
case RPC_SYSTEMERROR:
|
||||
(void)strncat(str, " - ", len - 1);
|
||||
(void)strncat(str, strerror(rpc_createerr.cf_error.re_errno),
|
||||
len - 4);
|
||||
break;
|
||||
|
||||
case RPC_CANTSEND:
|
||||
case RPC_CANTDECODERES:
|
||||
case RPC_CANTENCODEARGS:
|
||||
case RPC_SUCCESS:
|
||||
case RPC_UNKNOWNPROTO:
|
||||
case RPC_PROGNOTREGISTERED:
|
||||
case RPC_FAILED:
|
||||
case RPC_UNKNOWNHOST:
|
||||
case RPC_CANTDECODEARGS:
|
||||
case RPC_PROCUNAVAIL:
|
||||
case RPC_PROGVERSMISMATCH:
|
||||
case RPC_PROGUNAVAIL:
|
||||
case RPC_AUTHERROR:
|
||||
case RPC_VERSMISMATCH:
|
||||
case RPC_TIMEDOUT:
|
||||
case RPC_CANTRECV:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
str[CLNT_PERROR_BUFLEN-1] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
void
|
||||
clnt_pcreateerror(s)
|
||||
const char *s;
|
||||
{
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
(void) fprintf(stderr, "%s\n", clnt_spcreateerror(s));
|
||||
}
|
||||
|
||||
static const char *const auth_errlist[] = {
|
||||
"Authentication OK", /* 0 - AUTH_OK */
|
||||
"Invalid client credential", /* 1 - AUTH_BADCRED */
|
||||
"Server rejected credential", /* 2 - AUTH_REJECTEDCRED */
|
||||
"Invalid client verifier", /* 3 - AUTH_BADVERF */
|
||||
"Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */
|
||||
"Client credential too weak", /* 5 - AUTH_TOOWEAK */
|
||||
"Invalid server verifier", /* 6 - AUTH_INVALIDRESP */
|
||||
"Failed (unspecified error)", /* 7 - AUTH_FAILED */
|
||||
"Kerberos generic error", /* 8 - AUTH_KERB_GENERIC*/
|
||||
"Kerberos credential expired", /* 9 - AUTH_TIMEEXPIRE */
|
||||
"Bad kerberos ticket file", /* 10 - AUTH_TKT_FILE */
|
||||
"Can't decode kerberos authenticator", /* 11 - AUTH_DECODE */
|
||||
"Address wrong in kerberos ticket", /* 12 - AUTH_NET_ADDR */
|
||||
"GSS-API crediential problem", /* 13 - RPCSEC_GSS_CREDPROBLEM */
|
||||
"GSS-API context problem" /* 14 - RPCSEC_GSS_CTXPROBLEM */
|
||||
};
|
||||
|
||||
static char *
|
||||
auth_errmsg(stat)
|
||||
enum auth_stat stat;
|
||||
{
|
||||
unsigned int errnum = stat;
|
||||
|
||||
if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
|
||||
/* LINTED interface problem */
|
||||
return (char *)auth_errlist[errnum];
|
||||
|
||||
return(NULL);
|
||||
}
|
316
freebsd/lib/libc/rpc/clnt_raw.c
Normal file
316
freebsd/lib/libc/rpc/clnt_raw.c
Normal file
@ -0,0 +1,316 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_raw.c,v 1.20 2000/12/10 04:12:03 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* clnt_raw.c
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
* Memory based rpc for simple testing and timing.
|
||||
* Interface to create an rpc client and server in the same process.
|
||||
* This lets us similate rpc and get round trip overhead, without
|
||||
* any interference from the kernel.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/raw.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#define MCALL_MSG_SIZE 24
|
||||
|
||||
/*
|
||||
* This is the "network" we will be moving stuff over.
|
||||
*/
|
||||
static struct clntraw_private {
|
||||
CLIENT client_object;
|
||||
XDR xdr_stream;
|
||||
char *_raw_buf;
|
||||
union {
|
||||
struct rpc_msg mashl_rpcmsg;
|
||||
char mashl_callmsg[MCALL_MSG_SIZE];
|
||||
} u;
|
||||
u_int mcnt;
|
||||
} *clntraw_private;
|
||||
|
||||
static enum clnt_stat clnt_raw_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
|
||||
xdrproc_t, void *, struct timeval);
|
||||
static void clnt_raw_geterr(CLIENT *, struct rpc_err *);
|
||||
static bool_t clnt_raw_freeres(CLIENT *, xdrproc_t, void *);
|
||||
static void clnt_raw_abort(CLIENT *);
|
||||
static bool_t clnt_raw_control(CLIENT *, u_int, void *);
|
||||
static void clnt_raw_destroy(CLIENT *);
|
||||
static struct clnt_ops *clnt_raw_ops(void);
|
||||
|
||||
/*
|
||||
* Create a client handle for memory based rpc.
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_raw_create(prog, vers)
|
||||
rpcprog_t prog;
|
||||
rpcvers_t vers;
|
||||
{
|
||||
struct clntraw_private *clp;
|
||||
struct rpc_msg call_msg;
|
||||
XDR *xdrs;
|
||||
CLIENT *client;
|
||||
|
||||
mutex_lock(&clntraw_lock);
|
||||
if ((clp = clntraw_private) == NULL) {
|
||||
clp = (struct clntraw_private *)calloc(1, sizeof (*clp));
|
||||
if (clp == NULL) {
|
||||
mutex_unlock(&clntraw_lock);
|
||||
return NULL;
|
||||
}
|
||||
if (__rpc_rawcombuf == NULL)
|
||||
__rpc_rawcombuf =
|
||||
(char *)calloc(UDPMSGSIZE, sizeof (char));
|
||||
clp->_raw_buf = __rpc_rawcombuf;
|
||||
clntraw_private = clp;
|
||||
}
|
||||
xdrs = &clp->xdr_stream;
|
||||
client = &clp->client_object;
|
||||
|
||||
/*
|
||||
* pre-serialize the static part of the call msg and stash it away
|
||||
*/
|
||||
call_msg.rm_direction = CALL;
|
||||
call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
|
||||
/* XXX: prog and vers have been long historically :-( */
|
||||
call_msg.rm_call.cb_prog = (u_int32_t)prog;
|
||||
call_msg.rm_call.cb_vers = (u_int32_t)vers;
|
||||
xdrmem_create(xdrs, clp->u.mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
|
||||
if (! xdr_callhdr(xdrs, &call_msg))
|
||||
warnx("clntraw_create - Fatal header serialization error.");
|
||||
clp->mcnt = XDR_GETPOS(xdrs);
|
||||
XDR_DESTROY(xdrs);
|
||||
|
||||
/*
|
||||
* Set xdrmem for client/server shared buffer
|
||||
*/
|
||||
xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
|
||||
|
||||
/*
|
||||
* create client handle
|
||||
*/
|
||||
client->cl_ops = clnt_raw_ops();
|
||||
client->cl_auth = authnone_create();
|
||||
mutex_unlock(&clntraw_lock);
|
||||
return (client);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static enum clnt_stat
|
||||
clnt_raw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
|
||||
CLIENT *h;
|
||||
rpcproc_t proc;
|
||||
xdrproc_t xargs;
|
||||
void *argsp;
|
||||
xdrproc_t xresults;
|
||||
void *resultsp;
|
||||
struct timeval timeout;
|
||||
{
|
||||
struct clntraw_private *clp = clntraw_private;
|
||||
XDR *xdrs = &clp->xdr_stream;
|
||||
struct rpc_msg msg;
|
||||
enum clnt_stat status;
|
||||
struct rpc_err error;
|
||||
|
||||
assert(h != NULL);
|
||||
|
||||
mutex_lock(&clntraw_lock);
|
||||
if (clp == NULL) {
|
||||
mutex_unlock(&clntraw_lock);
|
||||
return (RPC_FAILED);
|
||||
}
|
||||
mutex_unlock(&clntraw_lock);
|
||||
|
||||
call_again:
|
||||
/*
|
||||
* send request
|
||||
*/
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
XDR_SETPOS(xdrs, 0);
|
||||
clp->u.mashl_rpcmsg.rm_xid ++ ;
|
||||
if ((! XDR_PUTBYTES(xdrs, clp->u.mashl_callmsg, clp->mcnt)) ||
|
||||
(! XDR_PUTINT32(xdrs, &proc)) ||
|
||||
(! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
|
||||
(! (*xargs)(xdrs, argsp))) {
|
||||
return (RPC_CANTENCODEARGS);
|
||||
}
|
||||
(void)XDR_GETPOS(xdrs); /* called just to cause overhead */
|
||||
|
||||
/*
|
||||
* We have to call server input routine here because this is
|
||||
* all going on in one process. Yuk.
|
||||
*/
|
||||
svc_getreq_common(FD_SETSIZE);
|
||||
|
||||
/*
|
||||
* get results
|
||||
*/
|
||||
xdrs->x_op = XDR_DECODE;
|
||||
XDR_SETPOS(xdrs, 0);
|
||||
msg.acpted_rply.ar_verf = _null_auth;
|
||||
msg.acpted_rply.ar_results.where = resultsp;
|
||||
msg.acpted_rply.ar_results.proc = xresults;
|
||||
if (! xdr_replymsg(xdrs, &msg)) {
|
||||
/*
|
||||
* It's possible for xdr_replymsg() to fail partway
|
||||
* through its attempt to decode the result from the
|
||||
* server. If this happens, it will leave the reply
|
||||
* structure partially populated with dynamically
|
||||
* allocated memory. (This can happen if someone uses
|
||||
* clntudp_bufcreate() to create a CLIENT handle and
|
||||
* specifies a receive buffer size that is too small.)
|
||||
* This memory must be free()ed to avoid a leak.
|
||||
*/
|
||||
int op = xdrs->x_op;
|
||||
xdrs->x_op = XDR_FREE;
|
||||
xdr_replymsg(xdrs, &msg);
|
||||
xdrs->x_op = op;
|
||||
return (RPC_CANTDECODERES);
|
||||
}
|
||||
_seterr_reply(&msg, &error);
|
||||
status = error.re_status;
|
||||
|
||||
if (status == RPC_SUCCESS) {
|
||||
if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
|
||||
status = RPC_AUTHERROR;
|
||||
}
|
||||
} /* end successful completion */
|
||||
else {
|
||||
if (AUTH_REFRESH(h->cl_auth, &msg))
|
||||
goto call_again;
|
||||
} /* end of unsuccessful completion */
|
||||
|
||||
if (status == RPC_SUCCESS) {
|
||||
if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
|
||||
status = RPC_AUTHERROR;
|
||||
}
|
||||
if (msg.acpted_rply.ar_verf.oa_base != NULL) {
|
||||
xdrs->x_op = XDR_FREE;
|
||||
(void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
|
||||
}
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
clnt_raw_geterr(cl, err)
|
||||
CLIENT *cl;
|
||||
struct rpc_err *err;
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* ARGSUSED */
|
||||
static bool_t
|
||||
clnt_raw_freeres(cl, xdr_res, res_ptr)
|
||||
CLIENT *cl;
|
||||
xdrproc_t xdr_res;
|
||||
void *res_ptr;
|
||||
{
|
||||
struct clntraw_private *clp = clntraw_private;
|
||||
XDR *xdrs = &clp->xdr_stream;
|
||||
bool_t rval;
|
||||
|
||||
mutex_lock(&clntraw_lock);
|
||||
if (clp == NULL) {
|
||||
rval = (bool_t) RPC_FAILED;
|
||||
mutex_unlock(&clntraw_lock);
|
||||
return (rval);
|
||||
}
|
||||
mutex_unlock(&clntraw_lock);
|
||||
xdrs->x_op = XDR_FREE;
|
||||
return ((*xdr_res)(xdrs, res_ptr));
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
clnt_raw_abort(cl)
|
||||
CLIENT *cl;
|
||||
{
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
clnt_raw_control(cl, ui, str)
|
||||
CLIENT *cl;
|
||||
u_int ui;
|
||||
void *str;
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
clnt_raw_destroy(cl)
|
||||
CLIENT *cl;
|
||||
{
|
||||
}
|
||||
|
||||
static struct clnt_ops *
|
||||
clnt_raw_ops()
|
||||
{
|
||||
static struct clnt_ops ops;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.cl_call == NULL) {
|
||||
ops.cl_call = clnt_raw_call;
|
||||
ops.cl_abort = clnt_raw_abort;
|
||||
ops.cl_geterr = clnt_raw_geterr;
|
||||
ops.cl_freeres = clnt_raw_freeres;
|
||||
ops.cl_destroy = clnt_raw_destroy;
|
||||
ops.cl_control = clnt_raw_control;
|
||||
}
|
||||
mutex_unlock(&ops_lock);
|
||||
return (&ops);
|
||||
}
|
207
freebsd/lib/libc/rpc/clnt_simple.c
Normal file
207
freebsd/lib/libc/rpc/clnt_simple.c
Normal file
@ -0,0 +1,207 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_simple.c,v 1.21 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "from: @(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "from: @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* clnt_simple.c
|
||||
* Simplified front end to client rpc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 64
|
||||
#endif
|
||||
|
||||
#ifndef NETIDLEN
|
||||
#define NETIDLEN 32
|
||||
#endif
|
||||
|
||||
struct rpc_call_private {
|
||||
int valid; /* Is this entry valid ? */
|
||||
CLIENT *client; /* Client handle */
|
||||
pid_t pid; /* process-id at moment of creation */
|
||||
rpcprog_t prognum; /* Program */
|
||||
rpcvers_t versnum; /* Version */
|
||||
char host[MAXHOSTNAMELEN]; /* Servers host */
|
||||
char nettype[NETIDLEN]; /* Network type */
|
||||
};
|
||||
static struct rpc_call_private *rpc_call_private_main;
|
||||
static thread_key_t rpc_call_key;
|
||||
static once_t rpc_call_once = ONCE_INITIALIZER;
|
||||
static int rpc_call_key_error;
|
||||
|
||||
static void rpc_call_key_init(void);
|
||||
static void rpc_call_destroy(void *);
|
||||
|
||||
static void
|
||||
rpc_call_destroy(void *vp)
|
||||
{
|
||||
struct rpc_call_private *rcp = (struct rpc_call_private *)vp;
|
||||
|
||||
if (rcp) {
|
||||
if (rcp->client)
|
||||
CLNT_DESTROY(rcp->client);
|
||||
free(rcp);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rpc_call_key_init(void)
|
||||
{
|
||||
|
||||
rpc_call_key_error = thr_keycreate(&rpc_call_key, rpc_call_destroy);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the simplified interface to the client rpc layer.
|
||||
* The client handle is not destroyed here and is reused for
|
||||
* the future calls to same prog, vers, host and nettype combination.
|
||||
*
|
||||
* The total time available is 25 seconds.
|
||||
*/
|
||||
enum clnt_stat
|
||||
rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
|
||||
const char *host; /* host name */
|
||||
rpcprog_t prognum; /* program number */
|
||||
rpcvers_t versnum; /* version number */
|
||||
rpcproc_t procnum; /* procedure number */
|
||||
xdrproc_t inproc, outproc; /* in/out XDR procedures */
|
||||
const char *in;
|
||||
char *out; /* recv/send data */
|
||||
const char *nettype; /* nettype */
|
||||
{
|
||||
struct rpc_call_private *rcp = (struct rpc_call_private *) 0;
|
||||
enum clnt_stat clnt_stat;
|
||||
struct timeval timeout, tottimeout;
|
||||
int main_thread = 1;
|
||||
|
||||
if ((main_thread = thr_main())) {
|
||||
rcp = rpc_call_private_main;
|
||||
} else {
|
||||
if (thr_once(&rpc_call_once, rpc_call_key_init) != 0 ||
|
||||
rpc_call_key_error != 0) {
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = rpc_call_key_error;
|
||||
return (rpc_createerr.cf_stat);
|
||||
}
|
||||
rcp = (struct rpc_call_private *)thr_getspecific(rpc_call_key);
|
||||
}
|
||||
if (rcp == NULL) {
|
||||
rcp = malloc(sizeof (*rcp));
|
||||
if (rcp == NULL) {
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
return (rpc_createerr.cf_stat);
|
||||
}
|
||||
if (main_thread)
|
||||
rpc_call_private_main = rcp;
|
||||
else
|
||||
thr_setspecific(rpc_call_key, (void *) rcp);
|
||||
rcp->valid = 0;
|
||||
rcp->client = NULL;
|
||||
}
|
||||
if ((nettype == NULL) || (nettype[0] == 0))
|
||||
nettype = "netpath";
|
||||
if (!(rcp->valid && rcp->pid == getpid() &&
|
||||
(rcp->prognum == prognum) &&
|
||||
(rcp->versnum == versnum) &&
|
||||
(!strcmp(rcp->host, host)) &&
|
||||
(!strcmp(rcp->nettype, nettype)))) {
|
||||
int fd;
|
||||
|
||||
rcp->valid = 0;
|
||||
if (rcp->client)
|
||||
CLNT_DESTROY(rcp->client);
|
||||
/*
|
||||
* Using the first successful transport for that type
|
||||
*/
|
||||
rcp->client = clnt_create(host, prognum, versnum, nettype);
|
||||
rcp->pid = getpid();
|
||||
if (rcp->client == NULL) {
|
||||
return (rpc_createerr.cf_stat);
|
||||
}
|
||||
/*
|
||||
* Set time outs for connectionless case. Do it
|
||||
* unconditionally. Faster than doing a t_getinfo()
|
||||
* and then doing the right thing.
|
||||
*/
|
||||
timeout.tv_usec = 0;
|
||||
timeout.tv_sec = 5;
|
||||
(void) CLNT_CONTROL(rcp->client,
|
||||
CLSET_RETRY_TIMEOUT, (char *)(void *)&timeout);
|
||||
if (CLNT_CONTROL(rcp->client, CLGET_FD, (char *)(void *)&fd))
|
||||
_fcntl(fd, F_SETFD, 1); /* make it "close on exec" */
|
||||
rcp->prognum = prognum;
|
||||
rcp->versnum = versnum;
|
||||
if ((strlen(host) < (size_t)MAXHOSTNAMELEN) &&
|
||||
(strlen(nettype) < (size_t)NETIDLEN)) {
|
||||
(void) strcpy(rcp->host, host);
|
||||
(void) strcpy(rcp->nettype, nettype);
|
||||
rcp->valid = 1;
|
||||
} else {
|
||||
rcp->valid = 0;
|
||||
}
|
||||
} /* else reuse old client */
|
||||
tottimeout.tv_sec = 25;
|
||||
tottimeout.tv_usec = 0;
|
||||
/*LINTED const castaway*/
|
||||
clnt_stat = CLNT_CALL(rcp->client, procnum, inproc, (char *) in,
|
||||
outproc, out, tottimeout);
|
||||
/*
|
||||
* if call failed, empty cache
|
||||
*/
|
||||
if (clnt_stat != RPC_SUCCESS)
|
||||
rcp->valid = 0;
|
||||
return (clnt_stat);
|
||||
}
|
874
freebsd/lib/libc/rpc/clnt_vc.c
Normal file
874
freebsd/lib/libc/rpc/clnt_vc.c
Normal file
@ -0,0 +1,874 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
static char sccsid3[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* clnt_tcp.c, Implements a TCP/IP based, client side RPC.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
* TCP based RPC supports 'batched calls'.
|
||||
* A sequence of calls may be batched-up in a send buffer. The rpc call
|
||||
* return immediately to the client even though the call was not necessarily
|
||||
* sent. The batching occurs if the results' xdr routine is NULL (0) AND
|
||||
* the rpc timeout value is zero (see clnt.h, rpc).
|
||||
*
|
||||
* Clients should NOT casually batch calls that in fact return results; that is,
|
||||
* the server side should be aware that a call is batched and not produce any
|
||||
* return message. Batched calls that produce many result messages can
|
||||
* deadlock (netlock) the client and the server....
|
||||
*
|
||||
* Now go hang yourself.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
#include "un-namespace.h"
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#define MCALL_MSG_SIZE 24
|
||||
|
||||
struct cmessage {
|
||||
struct cmsghdr cmsg;
|
||||
struct cmsgcred cmcred;
|
||||
};
|
||||
|
||||
static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
|
||||
xdrproc_t, void *, struct timeval);
|
||||
static void clnt_vc_geterr(CLIENT *, struct rpc_err *);
|
||||
static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, void *);
|
||||
static void clnt_vc_abort(CLIENT *);
|
||||
static bool_t clnt_vc_control(CLIENT *, u_int, void *);
|
||||
static void clnt_vc_destroy(CLIENT *);
|
||||
static struct clnt_ops *clnt_vc_ops(void);
|
||||
static bool_t time_not_ok(struct timeval *);
|
||||
static int read_vc(void *, void *, int);
|
||||
static int write_vc(void *, void *, int);
|
||||
static int __msgwrite(int, void *, size_t);
|
||||
static int __msgread(int, void *, size_t);
|
||||
|
||||
struct ct_data {
|
||||
int ct_fd; /* connection's fd */
|
||||
bool_t ct_closeit; /* close it on destroy */
|
||||
struct timeval ct_wait; /* wait interval in milliseconds */
|
||||
bool_t ct_waitset; /* wait set by clnt_control? */
|
||||
struct netbuf ct_addr; /* remote addr */
|
||||
struct rpc_err ct_error;
|
||||
union {
|
||||
char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
|
||||
u_int32_t ct_mcalli;
|
||||
} ct_u;
|
||||
u_int ct_mpos; /* pos after marshal */
|
||||
XDR ct_xdrs; /* XDR stream */
|
||||
};
|
||||
|
||||
/*
|
||||
* This machinery implements per-fd locks for MT-safety. It is not
|
||||
* sufficient to do per-CLIENT handle locks for MT-safety because a
|
||||
* user may create more than one CLIENT handle with the same fd behind
|
||||
* it. Therfore, we allocate an array of flags (vc_fd_locks), protected
|
||||
* by the clnt_fd_lock mutex, and an array (vc_cv) of condition variables
|
||||
* similarly protected. Vc_fd_lock[fd] == 1 => a call is activte on some
|
||||
* CLIENT handle created for that fd.
|
||||
* The current implementation holds locks across the entire RPC and reply.
|
||||
* Yes, this is silly, and as soon as this code is proven to work, this
|
||||
* should be the first thing fixed. One step at a time.
|
||||
*/
|
||||
static int *vc_fd_locks;
|
||||
static cond_t *vc_cv;
|
||||
#define release_fd_lock(fd, mask) { \
|
||||
mutex_lock(&clnt_fd_lock); \
|
||||
vc_fd_locks[fd] = 0; \
|
||||
mutex_unlock(&clnt_fd_lock); \
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), (sigset_t *) NULL); \
|
||||
cond_signal(&vc_cv[fd]); \
|
||||
}
|
||||
|
||||
static const char clnt_vc_errstr[] = "%s : %s";
|
||||
static const char clnt_vc_str[] = "clnt_vc_create";
|
||||
static const char clnt_read_vc_str[] = "read_vc";
|
||||
static const char __no_mem_str[] = "out of memory";
|
||||
|
||||
/*
|
||||
* Create a client handle for a connection.
|
||||
* Default options are set, which the user can change using clnt_control()'s.
|
||||
* The rpc/vc package does buffering similar to stdio, so the client
|
||||
* must pick send and receive buffer sizes, 0 => use the default.
|
||||
* NB: fd is copied into a private area.
|
||||
* NB: The rpch->cl_auth is set null authentication. Caller may wish to
|
||||
* set this something more useful.
|
||||
*
|
||||
* fd should be an open socket
|
||||
*/
|
||||
CLIENT *
|
||||
clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
|
||||
int fd; /* open file descriptor */
|
||||
const struct netbuf *raddr; /* servers address */
|
||||
const rpcprog_t prog; /* program number */
|
||||
const rpcvers_t vers; /* version number */
|
||||
u_int sendsz; /* buffer recv size */
|
||||
u_int recvsz; /* buffer send size */
|
||||
{
|
||||
CLIENT *cl; /* client handle */
|
||||
struct ct_data *ct = NULL; /* client handle */
|
||||
struct timeval now;
|
||||
struct rpc_msg call_msg;
|
||||
static u_int32_t disrupt;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen;
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
if (disrupt == 0)
|
||||
disrupt = (u_int32_t)(long)raddr;
|
||||
|
||||
cl = (CLIENT *)mem_alloc(sizeof (*cl));
|
||||
ct = (struct ct_data *)mem_alloc(sizeof (*ct));
|
||||
if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
|
||||
(void) syslog(LOG_ERR, clnt_vc_errstr,
|
||||
clnt_vc_str, __no_mem_str);
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
goto err;
|
||||
}
|
||||
ct->ct_addr.buf = NULL;
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
if (vc_fd_locks == (int *) NULL) {
|
||||
int cv_allocsz, fd_allocsz;
|
||||
int dtbsize = __rpc_dtbsize();
|
||||
|
||||
fd_allocsz = dtbsize * sizeof (int);
|
||||
vc_fd_locks = (int *) mem_alloc(fd_allocsz);
|
||||
if (vc_fd_locks == (int *) NULL) {
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
goto err;
|
||||
} else
|
||||
memset(vc_fd_locks, '\0', fd_allocsz);
|
||||
|
||||
assert(vc_cv == (cond_t *) NULL);
|
||||
cv_allocsz = dtbsize * sizeof (cond_t);
|
||||
vc_cv = (cond_t *) mem_alloc(cv_allocsz);
|
||||
if (vc_cv == (cond_t *) NULL) {
|
||||
mem_free(vc_fd_locks, fd_allocsz);
|
||||
vc_fd_locks = (int *) NULL;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
goto err;
|
||||
} else {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dtbsize; i++)
|
||||
cond_init(&vc_cv[i], 0, (void *) 0);
|
||||
}
|
||||
} else
|
||||
assert(vc_cv != (cond_t *) NULL);
|
||||
|
||||
/*
|
||||
* XXX - fvdl connecting while holding a mutex?
|
||||
*/
|
||||
slen = sizeof ss;
|
||||
if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
|
||||
if (errno != ENOTCONN) {
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
goto err;
|
||||
}
|
||||
if (_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
if (!__rpc_fd2sockinfo(fd, &si))
|
||||
goto err;
|
||||
|
||||
ct->ct_closeit = FALSE;
|
||||
|
||||
/*
|
||||
* Set up private data struct
|
||||
*/
|
||||
ct->ct_fd = fd;
|
||||
ct->ct_wait.tv_usec = 0;
|
||||
ct->ct_waitset = FALSE;
|
||||
ct->ct_addr.buf = malloc(raddr->maxlen);
|
||||
if (ct->ct_addr.buf == NULL)
|
||||
goto err;
|
||||
memcpy(ct->ct_addr.buf, raddr->buf, raddr->len);
|
||||
ct->ct_addr.len = raddr->maxlen;
|
||||
ct->ct_addr.maxlen = raddr->maxlen;
|
||||
|
||||
/*
|
||||
* Initialize call message
|
||||
*/
|
||||
(void)gettimeofday(&now, NULL);
|
||||
call_msg.rm_xid = ((u_int32_t)++disrupt) ^ __RPC_GETXID(&now);
|
||||
call_msg.rm_direction = CALL;
|
||||
call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
|
||||
call_msg.rm_call.cb_prog = (u_int32_t)prog;
|
||||
call_msg.rm_call.cb_vers = (u_int32_t)vers;
|
||||
|
||||
/*
|
||||
* pre-serialize the static part of the call msg and stash it away
|
||||
*/
|
||||
xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
|
||||
XDR_ENCODE);
|
||||
if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
|
||||
if (ct->ct_closeit) {
|
||||
(void)_close(fd);
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
|
||||
XDR_DESTROY(&(ct->ct_xdrs));
|
||||
assert(ct->ct_mpos + sizeof(uint32_t) <= MCALL_MSG_SIZE);
|
||||
|
||||
/*
|
||||
* Create a client handle which uses xdrrec for serialization
|
||||
* and authnone for authentication.
|
||||
*/
|
||||
cl->cl_ops = clnt_vc_ops();
|
||||
cl->cl_private = ct;
|
||||
cl->cl_auth = authnone_create();
|
||||
sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
|
||||
recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
|
||||
xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
|
||||
cl->cl_private, read_vc, write_vc);
|
||||
return (cl);
|
||||
|
||||
err:
|
||||
if (ct) {
|
||||
if (ct->ct_addr.len)
|
||||
mem_free(ct->ct_addr.buf, ct->ct_addr.len);
|
||||
mem_free(ct, sizeof (struct ct_data));
|
||||
}
|
||||
if (cl)
|
||||
mem_free(cl, sizeof (CLIENT));
|
||||
return ((CLIENT *)NULL);
|
||||
}
|
||||
|
||||
static enum clnt_stat
|
||||
clnt_vc_call(cl, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
|
||||
CLIENT *cl;
|
||||
rpcproc_t proc;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
xdrproc_t xdr_results;
|
||||
void *results_ptr;
|
||||
struct timeval timeout;
|
||||
{
|
||||
struct ct_data *ct = (struct ct_data *) cl->cl_private;
|
||||
XDR *xdrs = &(ct->ct_xdrs);
|
||||
struct rpc_msg reply_msg;
|
||||
u_int32_t x_id;
|
||||
u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
|
||||
bool_t shipnow;
|
||||
int refreshes = 2;
|
||||
sigset_t mask, newmask;
|
||||
int rpc_lock_value;
|
||||
bool_t reply_stat;
|
||||
|
||||
assert(cl != NULL);
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (vc_fd_locks[ct->ct_fd])
|
||||
cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
|
||||
if (__isthreaded)
|
||||
rpc_lock_value = 1;
|
||||
else
|
||||
rpc_lock_value = 0;
|
||||
vc_fd_locks[ct->ct_fd] = rpc_lock_value;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
if (!ct->ct_waitset) {
|
||||
/* If time is not within limits, we ignore it. */
|
||||
if (time_not_ok(&timeout) == FALSE)
|
||||
ct->ct_wait = timeout;
|
||||
}
|
||||
|
||||
shipnow =
|
||||
(xdr_results == NULL && timeout.tv_sec == 0
|
||||
&& timeout.tv_usec == 0) ? FALSE : TRUE;
|
||||
|
||||
call_again:
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
ct->ct_error.re_status = RPC_SUCCESS;
|
||||
x_id = ntohl(--(*msg_x_id));
|
||||
|
||||
if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
|
||||
if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
|
||||
(! XDR_PUTINT32(xdrs, &proc)) ||
|
||||
(! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
|
||||
(! (*xdr_args)(xdrs, args_ptr))) {
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS)
|
||||
ct->ct_error.re_status = RPC_CANTENCODEARGS;
|
||||
(void)xdrrec_endofrecord(xdrs, TRUE);
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (ct->ct_error.re_status);
|
||||
}
|
||||
} else {
|
||||
*(uint32_t *) &ct->ct_u.ct_mcallc[ct->ct_mpos] = htonl(proc);
|
||||
if (! __rpc_gss_wrap(cl->cl_auth, ct->ct_u.ct_mcallc,
|
||||
ct->ct_mpos + sizeof(uint32_t),
|
||||
xdrs, xdr_args, args_ptr)) {
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS)
|
||||
ct->ct_error.re_status = RPC_CANTENCODEARGS;
|
||||
(void)xdrrec_endofrecord(xdrs, TRUE);
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (ct->ct_error.re_status);
|
||||
}
|
||||
}
|
||||
if (! xdrrec_endofrecord(xdrs, shipnow)) {
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (ct->ct_error.re_status = RPC_CANTSEND);
|
||||
}
|
||||
if (! shipnow) {
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (RPC_SUCCESS);
|
||||
}
|
||||
/*
|
||||
* Hack to provide rpc-based message passing
|
||||
*/
|
||||
if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return(ct->ct_error.re_status = RPC_TIMEDOUT);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Keep receiving until we get a valid transaction id
|
||||
*/
|
||||
xdrs->x_op = XDR_DECODE;
|
||||
while (TRUE) {
|
||||
reply_msg.acpted_rply.ar_verf = _null_auth;
|
||||
reply_msg.acpted_rply.ar_results.where = NULL;
|
||||
reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
|
||||
if (! xdrrec_skiprecord(xdrs)) {
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (ct->ct_error.re_status);
|
||||
}
|
||||
/* now decode and validate the response header */
|
||||
if (! xdr_replymsg(xdrs, &reply_msg)) {
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS)
|
||||
continue;
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (ct->ct_error.re_status);
|
||||
}
|
||||
if (reply_msg.rm_xid == x_id)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* process header
|
||||
*/
|
||||
_seterr_reply(&reply_msg, &(ct->ct_error));
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS) {
|
||||
if (! AUTH_VALIDATE(cl->cl_auth,
|
||||
&reply_msg.acpted_rply.ar_verf)) {
|
||||
ct->ct_error.re_status = RPC_AUTHERROR;
|
||||
ct->ct_error.re_why = AUTH_INVALIDRESP;
|
||||
} else {
|
||||
if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
|
||||
reply_stat = (*xdr_results)(xdrs, results_ptr);
|
||||
} else {
|
||||
reply_stat = __rpc_gss_unwrap(cl->cl_auth,
|
||||
xdrs, xdr_results, results_ptr);
|
||||
}
|
||||
if (! reply_stat) {
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS)
|
||||
ct->ct_error.re_status =
|
||||
RPC_CANTDECODERES;
|
||||
}
|
||||
}
|
||||
/* free verifier ... */
|
||||
if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
|
||||
xdrs->x_op = XDR_FREE;
|
||||
(void)xdr_opaque_auth(xdrs,
|
||||
&(reply_msg.acpted_rply.ar_verf));
|
||||
}
|
||||
} /* end successful completion */
|
||||
else {
|
||||
/* maybe our credentials need to be refreshed ... */
|
||||
if (refreshes-- && AUTH_REFRESH(cl->cl_auth, &reply_msg))
|
||||
goto call_again;
|
||||
} /* end of unsuccessful completion */
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (ct->ct_error.re_status);
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_vc_geterr(cl, errp)
|
||||
CLIENT *cl;
|
||||
struct rpc_err *errp;
|
||||
{
|
||||
struct ct_data *ct;
|
||||
|
||||
assert(cl != NULL);
|
||||
assert(errp != NULL);
|
||||
|
||||
ct = (struct ct_data *) cl->cl_private;
|
||||
*errp = ct->ct_error;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
clnt_vc_freeres(cl, xdr_res, res_ptr)
|
||||
CLIENT *cl;
|
||||
xdrproc_t xdr_res;
|
||||
void *res_ptr;
|
||||
{
|
||||
struct ct_data *ct;
|
||||
XDR *xdrs;
|
||||
bool_t dummy;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
|
||||
assert(cl != NULL);
|
||||
|
||||
ct = (struct ct_data *)cl->cl_private;
|
||||
xdrs = &(ct->ct_xdrs);
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (vc_fd_locks[ct->ct_fd])
|
||||
cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
|
||||
xdrs->x_op = XDR_FREE;
|
||||
dummy = (*xdr_res)(xdrs, res_ptr);
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
cond_signal(&vc_cv[ct->ct_fd]);
|
||||
|
||||
return dummy;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
clnt_vc_abort(cl)
|
||||
CLIENT *cl;
|
||||
{
|
||||
}
|
||||
|
||||
static bool_t
|
||||
clnt_vc_control(cl, request, info)
|
||||
CLIENT *cl;
|
||||
u_int request;
|
||||
void *info;
|
||||
{
|
||||
struct ct_data *ct;
|
||||
void *infop = info;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
int rpc_lock_value;
|
||||
|
||||
assert(cl != NULL);
|
||||
|
||||
ct = (struct ct_data *)cl->cl_private;
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (vc_fd_locks[ct->ct_fd])
|
||||
cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
|
||||
if (__isthreaded)
|
||||
rpc_lock_value = 1;
|
||||
else
|
||||
rpc_lock_value = 0;
|
||||
vc_fd_locks[ct->ct_fd] = rpc_lock_value;
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
|
||||
switch (request) {
|
||||
case CLSET_FD_CLOSE:
|
||||
ct->ct_closeit = TRUE;
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (TRUE);
|
||||
case CLSET_FD_NCLOSE:
|
||||
ct->ct_closeit = FALSE;
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (TRUE);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* for other requests which use info */
|
||||
if (info == NULL) {
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
switch (request) {
|
||||
case CLSET_TIMEOUT:
|
||||
if (time_not_ok((struct timeval *)info)) {
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
ct->ct_wait = *(struct timeval *)infop;
|
||||
ct->ct_waitset = TRUE;
|
||||
break;
|
||||
case CLGET_TIMEOUT:
|
||||
*(struct timeval *)infop = ct->ct_wait;
|
||||
break;
|
||||
case CLGET_SERVER_ADDR:
|
||||
(void) memcpy(info, ct->ct_addr.buf, (size_t)ct->ct_addr.len);
|
||||
break;
|
||||
case CLGET_FD:
|
||||
*(int *)info = ct->ct_fd;
|
||||
break;
|
||||
case CLGET_SVC_ADDR:
|
||||
/* The caller should not free this memory area */
|
||||
*(struct netbuf *)info = ct->ct_addr;
|
||||
break;
|
||||
case CLSET_SVC_ADDR: /* set to new address */
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (FALSE);
|
||||
case CLGET_XID:
|
||||
/*
|
||||
* use the knowledge that xid is the
|
||||
* first element in the call structure
|
||||
* This will get the xid of the PREVIOUS call
|
||||
*/
|
||||
*(u_int32_t *)info =
|
||||
ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli);
|
||||
break;
|
||||
case CLSET_XID:
|
||||
/* This will set the xid of the NEXT call */
|
||||
*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli =
|
||||
htonl(*((u_int32_t *)info) + 1);
|
||||
/* increment by 1 as clnt_vc_call() decrements once */
|
||||
break;
|
||||
case CLGET_VERS:
|
||||
/*
|
||||
* This RELIES on the information that, in the call body,
|
||||
* the version number field is the fifth field from the
|
||||
* begining of the RPC header. MUST be changed if the
|
||||
* call_struct is changed
|
||||
*/
|
||||
*(u_int32_t *)info =
|
||||
ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
||||
4 * BYTES_PER_XDR_UNIT));
|
||||
break;
|
||||
|
||||
case CLSET_VERS:
|
||||
*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
||||
4 * BYTES_PER_XDR_UNIT) =
|
||||
htonl(*(u_int32_t *)info);
|
||||
break;
|
||||
|
||||
case CLGET_PROG:
|
||||
/*
|
||||
* This RELIES on the information that, in the call body,
|
||||
* the program number field is the fourth field from the
|
||||
* begining of the RPC header. MUST be changed if the
|
||||
* call_struct is changed
|
||||
*/
|
||||
*(u_int32_t *)info =
|
||||
ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
||||
3 * BYTES_PER_XDR_UNIT));
|
||||
break;
|
||||
|
||||
case CLSET_PROG:
|
||||
*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
|
||||
3 * BYTES_PER_XDR_UNIT) =
|
||||
htonl(*(u_int32_t *)info);
|
||||
break;
|
||||
|
||||
default:
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (FALSE);
|
||||
}
|
||||
release_fd_lock(ct->ct_fd, mask);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
clnt_vc_destroy(cl)
|
||||
CLIENT *cl;
|
||||
{
|
||||
struct ct_data *ct = (struct ct_data *) cl->cl_private;
|
||||
int ct_fd = ct->ct_fd;
|
||||
sigset_t mask;
|
||||
sigset_t newmask;
|
||||
|
||||
assert(cl != NULL);
|
||||
|
||||
ct = (struct ct_data *) cl->cl_private;
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&clnt_fd_lock);
|
||||
while (vc_fd_locks[ct_fd])
|
||||
cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
|
||||
if (ct->ct_closeit && ct->ct_fd != -1) {
|
||||
(void)_close(ct->ct_fd);
|
||||
}
|
||||
XDR_DESTROY(&(ct->ct_xdrs));
|
||||
if (ct->ct_addr.buf)
|
||||
free(ct->ct_addr.buf);
|
||||
mem_free(ct, sizeof(struct ct_data));
|
||||
if (cl->cl_netid && cl->cl_netid[0])
|
||||
mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
|
||||
if (cl->cl_tp && cl->cl_tp[0])
|
||||
mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
|
||||
mem_free(cl, sizeof(CLIENT));
|
||||
mutex_unlock(&clnt_fd_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
cond_signal(&vc_cv[ct_fd]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Interface between xdr serializer and tcp connection.
|
||||
* Behaves like the system calls, read & write, but keeps some error state
|
||||
* around for the rpc level.
|
||||
*/
|
||||
static int
|
||||
read_vc(ctp, buf, len)
|
||||
void *ctp;
|
||||
void *buf;
|
||||
int len;
|
||||
{
|
||||
struct sockaddr sa;
|
||||
socklen_t sal;
|
||||
struct ct_data *ct = (struct ct_data *)ctp;
|
||||
struct pollfd fd;
|
||||
int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) +
|
||||
(ct->ct_wait.tv_usec / 1000));
|
||||
|
||||
if (len == 0)
|
||||
return (0);
|
||||
fd.fd = ct->ct_fd;
|
||||
fd.events = POLLIN;
|
||||
for (;;) {
|
||||
switch (_poll(&fd, 1, milliseconds)) {
|
||||
case 0:
|
||||
ct->ct_error.re_status = RPC_TIMEDOUT;
|
||||
return (-1);
|
||||
|
||||
case -1:
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
ct->ct_error.re_status = RPC_CANTRECV;
|
||||
ct->ct_error.re_errno = errno;
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
sal = sizeof(sa);
|
||||
if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
|
||||
(sa.sa_family == AF_LOCAL)) {
|
||||
len = __msgread(ct->ct_fd, buf, (size_t)len);
|
||||
} else {
|
||||
len = _read(ct->ct_fd, buf, (size_t)len);
|
||||
}
|
||||
|
||||
switch (len) {
|
||||
case 0:
|
||||
/* premature eof */
|
||||
ct->ct_error.re_errno = ECONNRESET;
|
||||
ct->ct_error.re_status = RPC_CANTRECV;
|
||||
len = -1; /* it's really an error */
|
||||
break;
|
||||
|
||||
case -1:
|
||||
ct->ct_error.re_errno = errno;
|
||||
ct->ct_error.re_status = RPC_CANTRECV;
|
||||
break;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
static int
|
||||
write_vc(ctp, buf, len)
|
||||
void *ctp;
|
||||
void *buf;
|
||||
int len;
|
||||
{
|
||||
struct sockaddr sa;
|
||||
socklen_t sal;
|
||||
struct ct_data *ct = (struct ct_data *)ctp;
|
||||
int i, cnt;
|
||||
|
||||
sal = sizeof(sa);
|
||||
if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
|
||||
(sa.sa_family == AF_LOCAL)) {
|
||||
for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
|
||||
if ((i = __msgwrite(ct->ct_fd, buf,
|
||||
(size_t)cnt)) == -1) {
|
||||
ct->ct_error.re_errno = errno;
|
||||
ct->ct_error.re_status = RPC_CANTSEND;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
|
||||
if ((i = _write(ct->ct_fd, buf, (size_t)cnt)) == -1) {
|
||||
ct->ct_error.re_errno = errno;
|
||||
ct->ct_error.re_status = RPC_CANTSEND;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
static struct clnt_ops *
|
||||
clnt_vc_ops()
|
||||
{
|
||||
static struct clnt_ops ops;
|
||||
sigset_t mask, newmask;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
sigfillset(&newmask);
|
||||
thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.cl_call == NULL) {
|
||||
ops.cl_call = clnt_vc_call;
|
||||
ops.cl_abort = clnt_vc_abort;
|
||||
ops.cl_geterr = clnt_vc_geterr;
|
||||
ops.cl_freeres = clnt_vc_freeres;
|
||||
ops.cl_destroy = clnt_vc_destroy;
|
||||
ops.cl_control = clnt_vc_control;
|
||||
}
|
||||
mutex_unlock(&ops_lock);
|
||||
thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
|
||||
return (&ops);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure that the time is not garbage. -1 value is disallowed.
|
||||
* Note this is different from time_not_ok in clnt_dg.c
|
||||
*/
|
||||
static bool_t
|
||||
time_not_ok(t)
|
||||
struct timeval *t;
|
||||
{
|
||||
return (t->tv_sec <= -1 || t->tv_sec > 100000000 ||
|
||||
t->tv_usec <= -1 || t->tv_usec > 1000000);
|
||||
}
|
||||
|
||||
static int
|
||||
__msgread(sock, buf, cnt)
|
||||
int sock;
|
||||
void *buf;
|
||||
size_t cnt;
|
||||
{
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
union {
|
||||
struct cmsghdr cmsg;
|
||||
char control[CMSG_SPACE(sizeof(struct cmsgcred))];
|
||||
} cm;
|
||||
|
||||
bzero((char *)&cm, sizeof(cm));
|
||||
iov[0].iov_base = buf;
|
||||
iov[0].iov_len = cnt;
|
||||
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_control = (caddr_t)&cm;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
|
||||
msg.msg_flags = 0;
|
||||
|
||||
return(_recvmsg(sock, &msg, 0));
|
||||
}
|
||||
|
||||
static int
|
||||
__msgwrite(sock, buf, cnt)
|
||||
int sock;
|
||||
void *buf;
|
||||
size_t cnt;
|
||||
{
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
union {
|
||||
struct cmsghdr cmsg;
|
||||
char control[CMSG_SPACE(sizeof(struct cmsgcred))];
|
||||
} cm;
|
||||
|
||||
bzero((char *)&cm, sizeof(cm));
|
||||
iov[0].iov_base = buf;
|
||||
iov[0].iov_len = cnt;
|
||||
|
||||
cm.cmsg.cmsg_type = SCM_CREDS;
|
||||
cm.cmsg.cmsg_level = SOL_SOCKET;
|
||||
cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
|
||||
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_control = (caddr_t)&cm;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
|
||||
msg.msg_flags = 0;
|
||||
|
||||
return(_sendmsg(sock, &msg, 0));
|
||||
}
|
103
freebsd/lib/libc/rpc/crypt_client.c
Normal file
103
freebsd/lib/libc/rpc/crypt_client.c
Normal file
@ -0,0 +1,103 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Bill Paul.
|
||||
* 4. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <err.h>
|
||||
#include <sys/types.h>
|
||||
#include <rpc/des_crypt.h>
|
||||
#include <rpc/des.h>
|
||||
#include <string.h>
|
||||
#include <rpcsvc/crypt.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
int
|
||||
_des_crypt_call(buf, len, dparms)
|
||||
char *buf;
|
||||
int len;
|
||||
struct desparams *dparms;
|
||||
{
|
||||
CLIENT *clnt;
|
||||
desresp *result_1;
|
||||
desargs des_crypt_1_arg;
|
||||
struct netconfig *nconf;
|
||||
void *localhandle;
|
||||
int stat;
|
||||
|
||||
nconf = NULL;
|
||||
localhandle = setnetconfig();
|
||||
while ((nconf = getnetconfig(localhandle)) != NULL) {
|
||||
if (nconf->nc_protofmly != NULL &&
|
||||
strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0)
|
||||
break;
|
||||
}
|
||||
if (nconf == NULL) {
|
||||
warnx("getnetconfig: %s", nc_sperror());
|
||||
return(DESERR_HWERROR);
|
||||
}
|
||||
clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf);
|
||||
if (clnt == (CLIENT *) NULL) {
|
||||
endnetconfig(localhandle);
|
||||
return(DESERR_HWERROR);
|
||||
}
|
||||
endnetconfig(localhandle);
|
||||
|
||||
des_crypt_1_arg.desbuf.desbuf_len = len;
|
||||
des_crypt_1_arg.desbuf.desbuf_val = buf;
|
||||
des_crypt_1_arg.des_dir = (dparms->des_dir == ENCRYPT) ? ENCRYPT_DES : DECRYPT_DES;
|
||||
des_crypt_1_arg.des_mode = (dparms->des_mode == CBC) ? CBC_DES : ECB_DES;
|
||||
bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8);
|
||||
bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8);
|
||||
|
||||
result_1 = des_crypt_1(&des_crypt_1_arg, clnt);
|
||||
if (result_1 == (desresp *) NULL) {
|
||||
clnt_destroy(clnt);
|
||||
return(DESERR_HWERROR);
|
||||
}
|
||||
|
||||
stat = result_1->stat;
|
||||
|
||||
if (result_1->stat == DESERR_NONE ||
|
||||
result_1->stat == DESERR_NOHWDEVICE) {
|
||||
bcopy(result_1->desbuf.desbuf_val, buf, len);
|
||||
bcopy(result_1->des_ivec, dparms->des_ivec, 8);
|
||||
}
|
||||
|
||||
clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1);
|
||||
clnt_destroy(clnt);
|
||||
|
||||
return(stat);
|
||||
}
|
155
freebsd/lib/libc/rpc/des_crypt.c
Normal file
155
freebsd/lib/libc/rpc/des_crypt.c
Normal file
@ -0,0 +1,155 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* des_crypt.c, DES encryption library routines
|
||||
* Copyright (C) 1986, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <rpc/des_crypt.h>
|
||||
#include <rpc/des.h>
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)des_crypt.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
static int common_crypt( char *, char *, unsigned, unsigned, struct desparams * );
|
||||
int (*__des_crypt_LOCAL)() = 0;
|
||||
extern int _des_crypt_call(char *, int, struct desparams *);
|
||||
/*
|
||||
* Copy 8 bytes
|
||||
*/
|
||||
#define COPY8(src, dst) { \
|
||||
char *a = (char *) dst; \
|
||||
char *b = (char *) src; \
|
||||
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
||||
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy multiple of 8 bytes
|
||||
*/
|
||||
#define DESCOPY(src, dst, len) { \
|
||||
char *a = (char *) dst; \
|
||||
char *b = (char *) src; \
|
||||
int i; \
|
||||
for (i = (int) len; i > 0; i -= 8) { \
|
||||
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
||||
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* CBC mode encryption
|
||||
*/
|
||||
int
|
||||
cbc_crypt(key, buf, len, mode, ivec)
|
||||
char *key;
|
||||
char *buf;
|
||||
unsigned len;
|
||||
unsigned mode;
|
||||
char *ivec;
|
||||
{
|
||||
int err;
|
||||
struct desparams dp;
|
||||
|
||||
#ifdef BROKEN_DES
|
||||
dp.UDES.UDES_buf = buf;
|
||||
dp.des_mode = ECB;
|
||||
#else
|
||||
dp.des_mode = CBC;
|
||||
#endif
|
||||
COPY8(ivec, dp.des_ivec);
|
||||
err = common_crypt(key, buf, len, mode, &dp);
|
||||
COPY8(dp.des_ivec, ivec);
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ECB mode encryption
|
||||
*/
|
||||
int
|
||||
ecb_crypt(key, buf, len, mode)
|
||||
char *key;
|
||||
char *buf;
|
||||
unsigned len;
|
||||
unsigned mode;
|
||||
{
|
||||
struct desparams dp;
|
||||
|
||||
#ifdef BROKEN_DES
|
||||
dp.UDES.UDES_buf = buf;
|
||||
dp.des_mode = CBC;
|
||||
#else
|
||||
dp.des_mode = ECB;
|
||||
#endif
|
||||
return(common_crypt(key, buf, len, mode, &dp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Common code to cbc_crypt() & ecb_crypt()
|
||||
*/
|
||||
static int
|
||||
common_crypt(key, buf, len, mode, desp)
|
||||
char *key;
|
||||
char *buf;
|
||||
unsigned len;
|
||||
unsigned mode;
|
||||
struct desparams *desp;
|
||||
{
|
||||
int desdev;
|
||||
|
||||
if ((len % 8) != 0 || len > DES_MAXDATA) {
|
||||
return(DESERR_BADPARAM);
|
||||
}
|
||||
desp->des_dir =
|
||||
((mode & DES_DIRMASK) == DES_ENCRYPT) ? ENCRYPT : DECRYPT;
|
||||
|
||||
desdev = mode & DES_DEVMASK;
|
||||
COPY8(key, desp->des_key);
|
||||
/*
|
||||
* software
|
||||
*/
|
||||
if (__des_crypt_LOCAL != NULL) {
|
||||
if (!__des_crypt_LOCAL(buf, len, desp)) {
|
||||
return (DESERR_HWERROR);
|
||||
}
|
||||
} else {
|
||||
if (!_des_crypt_call(buf, len, desp)) {
|
||||
return (DESERR_HWERROR);
|
||||
}
|
||||
}
|
||||
return(desdev == DES_SW ? DESERR_NONE : DESERR_NOHWDEVICE);
|
||||
}
|
72
freebsd/lib/libc/rpc/des_soft.c
Normal file
72
freebsd/lib/libc/rpc/des_soft.c
Normal file
@ -0,0 +1,72 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)des_soft.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Table giving odd parity in the low bit for ASCII characters
|
||||
*/
|
||||
static char partab[128] = {
|
||||
0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07,
|
||||
0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e,
|
||||
0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,
|
||||
0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f,
|
||||
0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26,
|
||||
0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f,
|
||||
0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37,
|
||||
0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e,
|
||||
0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,
|
||||
0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f,
|
||||
0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57,
|
||||
0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e,
|
||||
0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67,
|
||||
0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e,
|
||||
0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,
|
||||
0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f,
|
||||
};
|
||||
|
||||
/*
|
||||
* Add odd parity to low bit of 8 byte key
|
||||
*/
|
||||
void
|
||||
des_setparity(p)
|
||||
char *p;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
*p = partab[*p & 0x7f];
|
||||
p++;
|
||||
}
|
||||
}
|
742
freebsd/lib/libc/rpc/getnetconfig.c
Normal file
742
freebsd/lib/libc/rpc/getnetconfig.c
Normal file
@ -0,0 +1,742 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: getnetconfig.c,v 1.3 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getnetconfig.c 1.12 91/12/19 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <netconfig.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
#include "rpc_com.h"
|
||||
|
||||
/*
|
||||
* The five library routines in this file provide application access to the
|
||||
* system network configuration database, /etc/netconfig. In addition to the
|
||||
* netconfig database and the routines for accessing it, the environment
|
||||
* variable NETPATH and its corresponding routines in getnetpath.c may also be
|
||||
* used to specify the network transport to be used.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* netconfig errors
|
||||
*/
|
||||
|
||||
#define NC_NONETCONFIG ENOENT
|
||||
#define NC_NOMEM ENOMEM
|
||||
#define NC_NOTINIT EINVAL /* setnetconfig was not called first */
|
||||
#define NC_BADFILE EBADF /* format for netconfig file is bad */
|
||||
#define NC_NOTFOUND ENOPROTOOPT /* specified netid was not found */
|
||||
|
||||
/*
|
||||
* semantics as strings (should be in netconfig.h)
|
||||
*/
|
||||
#define NC_TPI_CLTS_S "tpi_clts"
|
||||
#define NC_TPI_COTS_S "tpi_cots"
|
||||
#define NC_TPI_COTS_ORD_S "tpi_cots_ord"
|
||||
#define NC_TPI_RAW_S "tpi_raw"
|
||||
|
||||
/*
|
||||
* flags as characters (also should be in netconfig.h)
|
||||
*/
|
||||
#define NC_NOFLAG_C '-'
|
||||
#define NC_VISIBLE_C 'v'
|
||||
#define NC_BROADCAST_C 'b'
|
||||
|
||||
/*
|
||||
* Character used to indicate there is no name-to-address lookup library
|
||||
*/
|
||||
#define NC_NOLOOKUP "-"
|
||||
|
||||
static const char * const _nc_errors[] = {
|
||||
"Netconfig database not found",
|
||||
"Not enough memory",
|
||||
"Not initialized",
|
||||
"Netconfig database has invalid format",
|
||||
"Netid not found in netconfig database"
|
||||
};
|
||||
|
||||
struct netconfig_info {
|
||||
int eof; /* all entries has been read */
|
||||
int ref; /* # of times setnetconfig() has been called */
|
||||
struct netconfig_list *head; /* head of the list */
|
||||
struct netconfig_list *tail; /* last of the list */
|
||||
};
|
||||
|
||||
struct netconfig_list {
|
||||
char *linep; /* hold line read from netconfig */
|
||||
struct netconfig *ncp;
|
||||
struct netconfig_list *next;
|
||||
};
|
||||
|
||||
struct netconfig_vars {
|
||||
int valid; /* token that indicates a valid netconfig_vars */
|
||||
int flag; /* first time flag */
|
||||
struct netconfig_list *nc_configs; /* pointer to the current netconfig entry */
|
||||
};
|
||||
|
||||
#define NC_VALID 0xfeed
|
||||
#define NC_STORAGE 0xf00d
|
||||
#define NC_INVALID 0
|
||||
|
||||
|
||||
static int *__nc_error(void);
|
||||
static int parse_ncp(char *, struct netconfig *);
|
||||
static struct netconfig *dup_ncp(struct netconfig *);
|
||||
|
||||
|
||||
static FILE *nc_file; /* for netconfig db */
|
||||
static mutex_t nc_file_lock = MUTEX_INITIALIZER;
|
||||
|
||||
static struct netconfig_info ni = { 0, 0, NULL, NULL};
|
||||
static mutex_t ni_lock = MUTEX_INITIALIZER;
|
||||
|
||||
static thread_key_t nc_key;
|
||||
static once_t nc_once = ONCE_INITIALIZER;
|
||||
static int nc_key_error;
|
||||
|
||||
static void
|
||||
nc_key_init(void)
|
||||
{
|
||||
|
||||
nc_key_error = thr_keycreate(&nc_key, free);
|
||||
}
|
||||
|
||||
#define MAXNETCONFIGLINE 1000
|
||||
|
||||
static int *
|
||||
__nc_error()
|
||||
{
|
||||
static int nc_error = 0;
|
||||
int *nc_addr;
|
||||
|
||||
/*
|
||||
* Use the static `nc_error' if we are the main thread
|
||||
* (including non-threaded programs), or if an allocation
|
||||
* fails.
|
||||
*/
|
||||
if (thr_main())
|
||||
return (&nc_error);
|
||||
if (thr_once(&nc_once, nc_key_init) != 0 || nc_key_error != 0)
|
||||
return (&nc_error);
|
||||
if ((nc_addr = (int *)thr_getspecific(nc_key)) == NULL) {
|
||||
nc_addr = (int *)malloc(sizeof (int));
|
||||
if (thr_setspecific(nc_key, (void *) nc_addr) != 0) {
|
||||
if (nc_addr)
|
||||
free(nc_addr);
|
||||
return (&nc_error);
|
||||
}
|
||||
*nc_addr = 0;
|
||||
}
|
||||
return (nc_addr);
|
||||
}
|
||||
|
||||
#define nc_error (*(__nc_error()))
|
||||
/*
|
||||
* A call to setnetconfig() establishes a /etc/netconfig "session". A session
|
||||
* "handle" is returned on a successful call. At the start of a session (after
|
||||
* a call to setnetconfig()) searches through the /etc/netconfig database will
|
||||
* proceed from the start of the file. The session handle must be passed to
|
||||
* getnetconfig() to parse the file. Each call to getnetconfig() using the
|
||||
* current handle will process one subsequent entry in /etc/netconfig.
|
||||
* setnetconfig() must be called before the first call to getnetconfig().
|
||||
* (Handles are used to allow for nested calls to setnetpath()).
|
||||
*
|
||||
* A new session is established with each call to setnetconfig(), with a new
|
||||
* handle being returned on each call. Previously established sessions remain
|
||||
* active until endnetconfig() is called with that session's handle as an
|
||||
* argument.
|
||||
*
|
||||
* setnetconfig() need *not* be called before a call to getnetconfigent().
|
||||
* setnetconfig() returns a NULL pointer on failure (for example, if
|
||||
* the netconfig database is not present).
|
||||
*/
|
||||
void *
|
||||
setnetconfig()
|
||||
{
|
||||
struct netconfig_vars *nc_vars;
|
||||
|
||||
if ((nc_vars = (struct netconfig_vars *)malloc(sizeof
|
||||
(struct netconfig_vars))) == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* For multiple calls, i.e. nc_file is not NULL, we just return the
|
||||
* handle without reopening the netconfig db.
|
||||
*/
|
||||
mutex_lock(&ni_lock);
|
||||
ni.ref++;
|
||||
mutex_unlock(&ni_lock);
|
||||
|
||||
mutex_lock(&nc_file_lock);
|
||||
if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "r")) != NULL) {
|
||||
nc_vars->valid = NC_VALID;
|
||||
nc_vars->flag = 0;
|
||||
nc_vars->nc_configs = ni.head;
|
||||
mutex_unlock(&nc_file_lock);
|
||||
return ((void *)nc_vars);
|
||||
}
|
||||
mutex_unlock(&nc_file_lock);
|
||||
|
||||
mutex_lock(&ni_lock);
|
||||
ni.ref--;
|
||||
mutex_unlock(&ni_lock);
|
||||
|
||||
nc_error = NC_NONETCONFIG;
|
||||
free(nc_vars);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* When first called, getnetconfig() returns a pointer to the first entry in
|
||||
* the netconfig database, formatted as a struct netconfig. On each subsequent
|
||||
* call, getnetconfig() returns a pointer to the next entry in the database.
|
||||
* getnetconfig() can thus be used to search the entire netconfig file.
|
||||
* getnetconfig() returns NULL at end of file.
|
||||
*/
|
||||
|
||||
struct netconfig *
|
||||
getnetconfig(handlep)
|
||||
void *handlep;
|
||||
{
|
||||
struct netconfig_vars *ncp = (struct netconfig_vars *)handlep;
|
||||
char *stringp; /* tmp string pointer */
|
||||
struct netconfig_list *list;
|
||||
struct netconfig *np;
|
||||
struct netconfig *result;
|
||||
|
||||
/*
|
||||
* Verify that handle is valid
|
||||
*/
|
||||
mutex_lock(&nc_file_lock);
|
||||
if (ncp == NULL || nc_file == NULL) {
|
||||
nc_error = NC_NOTINIT;
|
||||
mutex_unlock(&nc_file_lock);
|
||||
return (NULL);
|
||||
}
|
||||
mutex_unlock(&nc_file_lock);
|
||||
|
||||
switch (ncp->valid) {
|
||||
case NC_VALID:
|
||||
/*
|
||||
* If entry has already been read into the list,
|
||||
* we return the entry in the linked list.
|
||||
* If this is the first time call, check if there are any entries in
|
||||
* linked list. If no entries, we need to read the netconfig db.
|
||||
* If we have been here and the next entry is there, we just return
|
||||
* it.
|
||||
*/
|
||||
if (ncp->flag == 0) { /* first time */
|
||||
ncp->flag = 1;
|
||||
mutex_lock(&ni_lock);
|
||||
ncp->nc_configs = ni.head;
|
||||
mutex_unlock(&ni_lock);
|
||||
if (ncp->nc_configs != NULL) /* entry already exist */
|
||||
return(ncp->nc_configs->ncp);
|
||||
}
|
||||
else if (ncp->nc_configs != NULL && ncp->nc_configs->next != NULL) {
|
||||
ncp->nc_configs = ncp->nc_configs->next;
|
||||
return(ncp->nc_configs->ncp);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we cannot find the entry in the list and is end of file,
|
||||
* we give up.
|
||||
*/
|
||||
mutex_lock(&ni_lock);
|
||||
if (ni.eof == 1) {
|
||||
mutex_unlock(&ni_lock);
|
||||
return(NULL);
|
||||
}
|
||||
mutex_unlock(&ni_lock);
|
||||
|
||||
break;
|
||||
default:
|
||||
nc_error = NC_NOTINIT;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
stringp = (char *) malloc(MAXNETCONFIGLINE);
|
||||
if (stringp == NULL)
|
||||
return (NULL);
|
||||
|
||||
#ifdef MEM_CHK
|
||||
if (malloc_verify() == 0) {
|
||||
fprintf(stderr, "memory heap corrupted in getnetconfig\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read a line from netconfig file.
|
||||
*/
|
||||
mutex_lock(&nc_file_lock);
|
||||
do {
|
||||
if (fgets(stringp, MAXNETCONFIGLINE, nc_file) == NULL) {
|
||||
free(stringp);
|
||||
mutex_lock(&ni_lock);
|
||||
ni.eof = 1;
|
||||
mutex_unlock(&ni_lock);
|
||||
mutex_unlock(&nc_file_lock);
|
||||
return (NULL);
|
||||
}
|
||||
} while (*stringp == '#');
|
||||
mutex_unlock(&nc_file_lock);
|
||||
|
||||
list = (struct netconfig_list *) malloc(sizeof (struct netconfig_list));
|
||||
if (list == NULL) {
|
||||
free(stringp);
|
||||
return(NULL);
|
||||
}
|
||||
np = (struct netconfig *) malloc(sizeof (struct netconfig));
|
||||
if (np == NULL) {
|
||||
free(stringp);
|
||||
free(list);
|
||||
return(NULL);
|
||||
}
|
||||
list->ncp = np;
|
||||
list->next = NULL;
|
||||
list->ncp->nc_lookups = NULL;
|
||||
list->linep = stringp;
|
||||
if (parse_ncp(stringp, list->ncp) == -1) {
|
||||
free(stringp);
|
||||
free(np);
|
||||
free(list);
|
||||
return (NULL);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* If this is the first entry that's been read, it is the head of
|
||||
* the list. If not, put the entry at the end of the list.
|
||||
* Reposition the current pointer of the handle to the last entry
|
||||
* in the list.
|
||||
*/
|
||||
mutex_lock(&ni_lock);
|
||||
if (ni.head == NULL) { /* first entry */
|
||||
ni.head = ni.tail = list;
|
||||
}
|
||||
else {
|
||||
ni.tail->next = list;
|
||||
ni.tail = ni.tail->next;
|
||||
}
|
||||
ncp->nc_configs = ni.tail;
|
||||
result = ni.tail->ncp;
|
||||
mutex_unlock(&ni_lock);
|
||||
return(result);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endnetconfig() may be called to "unbind" or "close" the netconfig database
|
||||
* when processing is complete, releasing resources for reuse. endnetconfig()
|
||||
* may not be called before setnetconfig(). endnetconfig() returns 0 on
|
||||
* success and -1 on failure (for example, if setnetconfig() was not called
|
||||
* previously).
|
||||
*/
|
||||
int
|
||||
endnetconfig(handlep)
|
||||
void *handlep;
|
||||
{
|
||||
struct netconfig_vars *nc_handlep = (struct netconfig_vars *)handlep;
|
||||
|
||||
struct netconfig_list *q, *p;
|
||||
|
||||
/*
|
||||
* Verify that handle is valid
|
||||
*/
|
||||
if (nc_handlep == NULL || (nc_handlep->valid != NC_VALID &&
|
||||
nc_handlep->valid != NC_STORAGE)) {
|
||||
nc_error = NC_NOTINIT;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 0 if anyone still needs it.
|
||||
*/
|
||||
nc_handlep->valid = NC_INVALID;
|
||||
nc_handlep->flag = 0;
|
||||
nc_handlep->nc_configs = NULL;
|
||||
mutex_lock(&ni_lock);
|
||||
if (--ni.ref > 0) {
|
||||
mutex_unlock(&ni_lock);
|
||||
free(nc_handlep);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Noone needs these entries anymore, then frees them.
|
||||
* Make sure all info in netconfig_info structure has been reinitialized.
|
||||
*/
|
||||
q = ni.head;
|
||||
ni.eof = ni.ref = 0;
|
||||
ni.head = NULL;
|
||||
ni.tail = NULL;
|
||||
mutex_unlock(&ni_lock);
|
||||
|
||||
while (q != NULL) {
|
||||
p = q->next;
|
||||
if (q->ncp->nc_lookups != NULL) free(q->ncp->nc_lookups);
|
||||
free(q->ncp);
|
||||
free(q->linep);
|
||||
free(q);
|
||||
q = p;
|
||||
}
|
||||
free(nc_handlep);
|
||||
|
||||
mutex_lock(&nc_file_lock);
|
||||
fclose(nc_file);
|
||||
nc_file = NULL;
|
||||
mutex_unlock(&nc_file_lock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* getnetconfigent(netid) returns a pointer to the struct netconfig structure
|
||||
* corresponding to netid. It returns NULL if netid is invalid (that is, does
|
||||
* not name an entry in the netconfig database). It returns NULL and sets
|
||||
* errno in case of failure (for example, if the netconfig database cannot be
|
||||
* opened).
|
||||
*/
|
||||
|
||||
struct netconfig *
|
||||
getnetconfigent(netid)
|
||||
const char *netid;
|
||||
{
|
||||
FILE *file; /* NETCONFIG db's file pointer */
|
||||
char *linep; /* holds current netconfig line */
|
||||
char *stringp; /* temporary string pointer */
|
||||
struct netconfig *ncp = NULL; /* returned value */
|
||||
struct netconfig_list *list; /* pointer to cache list */
|
||||
|
||||
nc_error = NC_NOTFOUND; /* default error. */
|
||||
if (netid == NULL || strlen(netid) == 0) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up table if the entries have already been read and parsed in
|
||||
* getnetconfig(), then copy this entry into a buffer and return it.
|
||||
* If we cannot find the entry in the current list and there are more
|
||||
* entries in the netconfig db that has not been read, we then read the
|
||||
* db and try find the match netid.
|
||||
* If all the netconfig db has been read and placed into the list and
|
||||
* there is no match for the netid, return NULL.
|
||||
*/
|
||||
mutex_lock(&ni_lock);
|
||||
if (ni.head != NULL) {
|
||||
for (list = ni.head; list; list = list->next) {
|
||||
if (strcmp(list->ncp->nc_netid, netid) == 0) {
|
||||
mutex_unlock(&ni_lock);
|
||||
return(dup_ncp(list->ncp));
|
||||
}
|
||||
}
|
||||
if (ni.eof == 1) { /* that's all the entries */
|
||||
mutex_unlock(&ni_lock);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
mutex_unlock(&ni_lock);
|
||||
|
||||
|
||||
if ((file = fopen(NETCONFIG, "r")) == NULL) {
|
||||
nc_error = NC_NONETCONFIG;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((linep = malloc(MAXNETCONFIGLINE)) == NULL) {
|
||||
fclose(file);
|
||||
nc_error = NC_NOMEM;
|
||||
return (NULL);
|
||||
}
|
||||
do {
|
||||
ptrdiff_t len;
|
||||
char *tmpp; /* tmp string pointer */
|
||||
|
||||
do {
|
||||
if ((stringp = fgets(linep, MAXNETCONFIGLINE, file)) == NULL) {
|
||||
break;
|
||||
}
|
||||
} while (*stringp == '#');
|
||||
if (stringp == NULL) { /* eof */
|
||||
break;
|
||||
}
|
||||
if ((tmpp = strpbrk(stringp, "\t ")) == NULL) { /* can't parse file */
|
||||
nc_error = NC_BADFILE;
|
||||
break;
|
||||
}
|
||||
if (strlen(netid) == (size_t) (len = tmpp - stringp) && /* a match */
|
||||
strncmp(stringp, netid, (size_t)len) == 0) {
|
||||
if ((ncp = (struct netconfig *)
|
||||
malloc(sizeof (struct netconfig))) == NULL) {
|
||||
break;
|
||||
}
|
||||
ncp->nc_lookups = NULL;
|
||||
if (parse_ncp(linep, ncp) == -1) {
|
||||
free(ncp);
|
||||
ncp = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (stringp != NULL);
|
||||
if (ncp == NULL) {
|
||||
free(linep);
|
||||
}
|
||||
fclose(file);
|
||||
return(ncp);
|
||||
}
|
||||
|
||||
/*
|
||||
* freenetconfigent(netconfigp) frees the netconfig structure pointed to by
|
||||
* netconfigp (previously returned by getnetconfigent()).
|
||||
*/
|
||||
|
||||
void
|
||||
freenetconfigent(netconfigp)
|
||||
struct netconfig *netconfigp;
|
||||
{
|
||||
if (netconfigp != NULL) {
|
||||
free(netconfigp->nc_netid); /* holds all netconfigp's strings */
|
||||
if (netconfigp->nc_lookups != NULL)
|
||||
free(netconfigp->nc_lookups);
|
||||
free(netconfigp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse line and stuff it in a struct netconfig
|
||||
* Typical line might look like:
|
||||
* udp tpi_cots vb inet udp /dev/udp /usr/lib/ip.so,/usr/local/ip.so
|
||||
*
|
||||
* We return -1 if any of the tokens don't parse, or malloc fails.
|
||||
*
|
||||
* Note that we modify stringp (putting NULLs after tokens) and
|
||||
* we set the ncp's string field pointers to point to these tokens within
|
||||
* stringp.
|
||||
*/
|
||||
|
||||
static int
|
||||
parse_ncp(stringp, ncp)
|
||||
char *stringp; /* string to parse */
|
||||
struct netconfig *ncp; /* where to put results */
|
||||
{
|
||||
char *tokenp; /* for processing tokens */
|
||||
char *lasts;
|
||||
char **nc_lookups;
|
||||
|
||||
nc_error = NC_BADFILE; /* nearly anything that breaks is for this reason */
|
||||
stringp[strlen(stringp)-1] = '\0'; /* get rid of newline */
|
||||
/* netid */
|
||||
if ((ncp->nc_netid = strtok_r(stringp, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* semantics */
|
||||
if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
if (strcmp(tokenp, NC_TPI_COTS_ORD_S) == 0)
|
||||
ncp->nc_semantics = NC_TPI_COTS_ORD;
|
||||
else if (strcmp(tokenp, NC_TPI_COTS_S) == 0)
|
||||
ncp->nc_semantics = NC_TPI_COTS;
|
||||
else if (strcmp(tokenp, NC_TPI_CLTS_S) == 0)
|
||||
ncp->nc_semantics = NC_TPI_CLTS;
|
||||
else if (strcmp(tokenp, NC_TPI_RAW_S) == 0)
|
||||
ncp->nc_semantics = NC_TPI_RAW;
|
||||
else
|
||||
return (-1);
|
||||
|
||||
/* flags */
|
||||
if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
for (ncp->nc_flag = NC_NOFLAG; *tokenp != '\0';
|
||||
tokenp++) {
|
||||
switch (*tokenp) {
|
||||
case NC_NOFLAG_C:
|
||||
break;
|
||||
case NC_VISIBLE_C:
|
||||
ncp->nc_flag |= NC_VISIBLE;
|
||||
break;
|
||||
case NC_BROADCAST_C:
|
||||
ncp->nc_flag |= NC_BROADCAST;
|
||||
break;
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
/* protocol family */
|
||||
if ((ncp->nc_protofmly = strtok_r(NULL, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
/* protocol name */
|
||||
if ((ncp->nc_proto = strtok_r(NULL, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
/* network device */
|
||||
if ((ncp->nc_device = strtok_r(NULL, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
if (strcmp(tokenp, NC_NOLOOKUP) == 0) {
|
||||
ncp->nc_nlookups = 0;
|
||||
ncp->nc_lookups = NULL;
|
||||
} else {
|
||||
char *cp; /* tmp string */
|
||||
|
||||
if (ncp->nc_lookups != NULL) /* from last visit */
|
||||
free(ncp->nc_lookups);
|
||||
ncp->nc_lookups = NULL;
|
||||
ncp->nc_nlookups = 0;
|
||||
while ((cp = tokenp) != NULL) {
|
||||
if ((nc_lookups = realloc(ncp->nc_lookups,
|
||||
(ncp->nc_nlookups + 1) * sizeof *ncp->nc_lookups)) == NULL) {
|
||||
free(ncp->nc_lookups);
|
||||
ncp->nc_lookups = NULL;
|
||||
return (-1);
|
||||
}
|
||||
tokenp = _get_next_token(cp, ',');
|
||||
ncp->nc_lookups = nc_lookups;
|
||||
ncp->nc_lookups[ncp->nc_nlookups++] = cp;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns a string describing the reason for failure.
|
||||
*/
|
||||
char *
|
||||
nc_sperror()
|
||||
{
|
||||
const char *message;
|
||||
|
||||
switch(nc_error) {
|
||||
case NC_NONETCONFIG:
|
||||
message = _nc_errors[0];
|
||||
break;
|
||||
case NC_NOMEM:
|
||||
message = _nc_errors[1];
|
||||
break;
|
||||
case NC_NOTINIT:
|
||||
message = _nc_errors[2];
|
||||
break;
|
||||
case NC_BADFILE:
|
||||
message = _nc_errors[3];
|
||||
break;
|
||||
case NC_NOTFOUND:
|
||||
message = _nc_errors[4];
|
||||
break;
|
||||
default:
|
||||
message = "Unknown network selection error";
|
||||
}
|
||||
/* LINTED const castaway */
|
||||
return ((char *)message);
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints a message onto standard error describing the reason for failure.
|
||||
*/
|
||||
void
|
||||
nc_perror(s)
|
||||
const char *s;
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", s, nc_sperror());
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicates the matched netconfig buffer.
|
||||
*/
|
||||
static struct netconfig *
|
||||
dup_ncp(ncp)
|
||||
struct netconfig *ncp;
|
||||
{
|
||||
struct netconfig *p;
|
||||
char *tmp;
|
||||
u_int i;
|
||||
|
||||
if ((tmp=malloc(MAXNETCONFIGLINE)) == NULL)
|
||||
return(NULL);
|
||||
if ((p=(struct netconfig *)malloc(sizeof(struct netconfig))) == NULL) {
|
||||
free(tmp);
|
||||
return(NULL);
|
||||
}
|
||||
/*
|
||||
* First we dup all the data from matched netconfig buffer. Then we
|
||||
* adjust some of the member pointer to a pre-allocated buffer where
|
||||
* contains part of the data.
|
||||
* To follow the convention used in parse_ncp(), we store all the
|
||||
* necessary information in the pre-allocated buffer and let each
|
||||
* of the netconfig char pointer member point to the right address
|
||||
* in the buffer.
|
||||
*/
|
||||
*p = *ncp;
|
||||
p->nc_netid = (char *)strcpy(tmp,ncp->nc_netid);
|
||||
tmp = strchr(tmp, '\0') + 1;
|
||||
p->nc_protofmly = (char *)strcpy(tmp,ncp->nc_protofmly);
|
||||
tmp = strchr(tmp, '\0') + 1;
|
||||
p->nc_proto = (char *)strcpy(tmp,ncp->nc_proto);
|
||||
tmp = strchr(tmp, '\0') + 1;
|
||||
p->nc_device = (char *)strcpy(tmp,ncp->nc_device);
|
||||
p->nc_lookups = (char **)malloc((size_t)(p->nc_nlookups+1) * sizeof(char *));
|
||||
if (p->nc_lookups == NULL) {
|
||||
free(p->nc_netid);
|
||||
free(p);
|
||||
return(NULL);
|
||||
}
|
||||
for (i=0; i < p->nc_nlookups; i++) {
|
||||
tmp = strchr(tmp, '\0') + 1;
|
||||
p->nc_lookups[i] = (char *)strcpy(tmp,ncp->nc_lookups[i]);
|
||||
}
|
||||
return(p);
|
||||
}
|
276
freebsd/lib/libc/rpc/getnetpath.c
Normal file
276
freebsd/lib/libc/rpc/getnetpath.c
Normal file
@ -0,0 +1,276 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: getnetpath.c,v 1.3 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getnetpath.c 1.11 91/12/19 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <netconfig.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/*
|
||||
* internal structure to keep track of a netpath "session"
|
||||
*/
|
||||
struct netpath_chain {
|
||||
struct netconfig *ncp; /* an nconf entry */
|
||||
struct netpath_chain *nchain_next; /* next nconf entry allocated */
|
||||
};
|
||||
|
||||
|
||||
struct netpath_vars {
|
||||
int valid; /* token that indicates a valid netpath_vars */
|
||||
void *nc_handlep; /* handle for current netconfig "session" */
|
||||
char *netpath; /* pointer to current view-point in NETPATH */
|
||||
char *netpath_start; /* pointer to start of our copy of NETPATH */
|
||||
struct netpath_chain *ncp_list; /* list of nconfs allocated this session*/
|
||||
};
|
||||
|
||||
#define NP_VALID 0xf00d
|
||||
#define NP_INVALID 0
|
||||
|
||||
char *_get_next_token(char *, int);
|
||||
|
||||
|
||||
/*
|
||||
* A call to setnetpath() establishes a NETPATH "session". setnetpath()
|
||||
* must be called before the first call to getnetpath(). A "handle" is
|
||||
* returned to distinguish the session; this handle should be passed
|
||||
* subsequently to getnetpath(). (Handles are used to allow for nested calls
|
||||
* to setnetpath()).
|
||||
* If setnetpath() is unable to establish a session (due to lack of memory
|
||||
* resources, or the absence of the /etc/netconfig file), a NULL pointer is
|
||||
* returned.
|
||||
*/
|
||||
|
||||
void *
|
||||
setnetpath()
|
||||
{
|
||||
|
||||
struct netpath_vars *np_sessionp; /* this session's variables */
|
||||
char *npp; /* NETPATH env variable */
|
||||
|
||||
#ifdef MEM_CHK
|
||||
malloc_debug(1);
|
||||
#endif
|
||||
|
||||
if ((np_sessionp =
|
||||
(struct netpath_vars *)malloc(sizeof (struct netpath_vars))) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
if ((np_sessionp->nc_handlep = setnetconfig()) == NULL) {
|
||||
free(np_sessionp);
|
||||
syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
|
||||
return (NULL);
|
||||
}
|
||||
np_sessionp->valid = NP_VALID;
|
||||
np_sessionp->ncp_list = NULL;
|
||||
if ((npp = getenv(NETPATH)) == NULL) {
|
||||
np_sessionp->netpath = NULL;
|
||||
} else {
|
||||
(void) endnetconfig(np_sessionp->nc_handlep);/* won't need nc session*/
|
||||
np_sessionp->nc_handlep = NULL;
|
||||
if ((np_sessionp->netpath = malloc(strlen(npp)+1)) == NULL)
|
||||
goto failed;
|
||||
else {
|
||||
(void) strcpy(np_sessionp->netpath, npp);
|
||||
}
|
||||
}
|
||||
np_sessionp->netpath_start = np_sessionp->netpath;
|
||||
return ((void *)np_sessionp);
|
||||
|
||||
failed:
|
||||
free(np_sessionp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* When first called, getnetpath() returns a pointer to the netconfig
|
||||
* database entry corresponding to the first valid NETPATH component. The
|
||||
* netconfig entry is formatted as a struct netconfig.
|
||||
* On each subsequent call, getnetpath returns a pointer to the netconfig
|
||||
* entry that corresponds to the next valid NETPATH component. getnetpath
|
||||
* can thus be used to search the netconfig database for all networks
|
||||
* included in the NETPATH variable.
|
||||
* When NETPATH has been exhausted, getnetpath() returns NULL. It returns
|
||||
* NULL and sets errno in case of an error (e.g., setnetpath was not called
|
||||
* previously).
|
||||
* getnetpath() silently ignores invalid NETPATH components. A NETPATH
|
||||
* compnent is invalid if there is no corresponding entry in the netconfig
|
||||
* database.
|
||||
* If the NETPATH variable is unset, getnetpath() behaves as if NETPATH
|
||||
* were set to the sequence of default or visible networks in the netconfig
|
||||
* database, in the order in which they are listed.
|
||||
*/
|
||||
|
||||
struct netconfig *
|
||||
getnetpath(handlep)
|
||||
void *handlep;
|
||||
{
|
||||
struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep;
|
||||
struct netconfig *ncp = NULL; /* temp. holds a netconfig session */
|
||||
struct netpath_chain *chainp; /* holds chain of ncp's we alloc */
|
||||
char *npp; /* holds current NETPATH */
|
||||
|
||||
if (np_sessionp == NULL || np_sessionp->valid != NP_VALID) {
|
||||
errno = EINVAL;
|
||||
return (NULL);
|
||||
}
|
||||
if (np_sessionp->netpath_start == NULL) { /* NETPATH was not set */
|
||||
do { /* select next visible network */
|
||||
if (np_sessionp->nc_handlep == NULL) {
|
||||
np_sessionp->nc_handlep = setnetconfig();
|
||||
if (np_sessionp->nc_handlep == NULL)
|
||||
syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
|
||||
}
|
||||
if ((ncp = getnetconfig(np_sessionp->nc_handlep)) == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
} while ((ncp->nc_flag & NC_VISIBLE) == 0);
|
||||
return (ncp);
|
||||
}
|
||||
/*
|
||||
* Find first valid network ID in netpath.
|
||||
*/
|
||||
while ((npp = np_sessionp->netpath) != NULL && strlen(npp) != 0) {
|
||||
np_sessionp->netpath = _get_next_token(npp, ':');
|
||||
/*
|
||||
* npp is a network identifier.
|
||||
*/
|
||||
if ((ncp = getnetconfigent(npp)) != NULL) {
|
||||
chainp = (struct netpath_chain *) /* cobble alloc chain entry */
|
||||
malloc(sizeof (struct netpath_chain));
|
||||
chainp->ncp = ncp;
|
||||
chainp->nchain_next = NULL;
|
||||
if (np_sessionp->ncp_list == NULL) {
|
||||
np_sessionp->ncp_list = chainp;
|
||||
} else {
|
||||
np_sessionp->ncp_list->nchain_next = chainp;
|
||||
}
|
||||
return (ncp);
|
||||
}
|
||||
/* couldn't find this token in the database; go to next one. */
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* endnetpath() may be called to unbind NETPATH when processing is complete,
|
||||
* releasing resources for reuse. It returns 0 on success and -1 on failure
|
||||
* (e.g. if setnetpath() was not called previously.
|
||||
*/
|
||||
int
|
||||
endnetpath(handlep)
|
||||
void *handlep;
|
||||
{
|
||||
struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep;
|
||||
struct netpath_chain *chainp, *lastp;
|
||||
|
||||
if (np_sessionp == NULL || np_sessionp->valid != NP_VALID) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
if (np_sessionp->nc_handlep != NULL)
|
||||
endnetconfig(np_sessionp->nc_handlep);
|
||||
if (np_sessionp->netpath_start != NULL)
|
||||
free(np_sessionp->netpath_start);
|
||||
for (chainp = np_sessionp->ncp_list; chainp != NULL;
|
||||
lastp=chainp, chainp=chainp->nchain_next, free(lastp)) {
|
||||
freenetconfigent(chainp->ncp);
|
||||
}
|
||||
free(np_sessionp);
|
||||
#ifdef MEM_CHK
|
||||
if (malloc_verify() == 0) {
|
||||
fprintf(stderr, "memory heap corrupted in endnetpath\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Returns pointer to the rest-of-the-string after the current token.
|
||||
* The token itself starts at arg, and we null terminate it. We return NULL
|
||||
* if either the arg is empty, or if this is the last token.
|
||||
*/
|
||||
|
||||
char *
|
||||
_get_next_token(npp, token)
|
||||
char *npp; /* string */
|
||||
int token; /* char to parse string for */
|
||||
{
|
||||
char *cp; /* char pointer */
|
||||
char *np; /* netpath pointer */
|
||||
char *ep; /* escape pointer */
|
||||
|
||||
if ((cp = strchr(npp, token)) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
* did find a token, but it might be escaped.
|
||||
*/
|
||||
if ((cp > npp) && (cp[-1] == '\\')) {
|
||||
/* if slash was also escaped, carry on, otherwise find next token */
|
||||
if ((cp > npp + 1) && (cp[-2] != '\\')) {
|
||||
/* shift r-o-s onto the escaped token */
|
||||
strcpy(&cp[-1], cp); /* XXX: overlapping string copy */
|
||||
/*
|
||||
* Do a recursive call.
|
||||
* We don't know how many escaped tokens there might be.
|
||||
*/
|
||||
return (_get_next_token(cp, token));
|
||||
}
|
||||
}
|
||||
|
||||
*cp++ = '\0'; /* null-terminate token */
|
||||
/* get rid of any backslash escapes */
|
||||
ep = npp;
|
||||
while ((np = strchr(ep, '\\')) != 0) {
|
||||
if (np[1] == '\\')
|
||||
np++;
|
||||
strcpy(np, (ep = &np[1])); /* XXX: overlapping string copy */
|
||||
}
|
||||
return (cp); /* return ptr to r-o-s */
|
||||
}
|
179
freebsd/lib/libc/rpc/getpublickey.c
Normal file
179
freebsd/lib/libc/rpc/getpublickey.c
Normal file
@ -0,0 +1,179 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)publickey.c 1.10 91/03/11 Copyr 1986 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* publickey.c
|
||||
* Copyright (C) 1986, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Public key lookup routines
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/key_prot.h>
|
||||
#include <rpcsvc/yp_prot.h>
|
||||
#include <rpcsvc/ypclnt.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#define PKFILE "/etc/publickey"
|
||||
|
||||
/*
|
||||
* Hack to let ypserv/rpc.nisd use AUTH_DES.
|
||||
*/
|
||||
int (*__getpublickey_LOCAL)() = 0;
|
||||
|
||||
/*
|
||||
* Get somebody's public key
|
||||
*/
|
||||
static int
|
||||
__getpublickey_real(netname, publickey)
|
||||
const char *netname;
|
||||
char *publickey;
|
||||
{
|
||||
char lookup[3 * HEXKEYBYTES];
|
||||
char *p;
|
||||
|
||||
if (publickey == NULL)
|
||||
return (0);
|
||||
if (!getpublicandprivatekey(netname, lookup))
|
||||
return (0);
|
||||
p = strchr(lookup, ':');
|
||||
if (p == NULL) {
|
||||
return (0);
|
||||
}
|
||||
*p = '\0';
|
||||
(void) strncpy(publickey, lookup, HEXKEYBYTES);
|
||||
publickey[HEXKEYBYTES] = '\0';
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* reads the file /etc/publickey looking for a + to optionally go to the
|
||||
* yellow pages
|
||||
*/
|
||||
|
||||
int
|
||||
getpublicandprivatekey(key, ret)
|
||||
const char *key;
|
||||
char *ret;
|
||||
{
|
||||
char buf[1024]; /* big enough */
|
||||
char *res;
|
||||
FILE *fd;
|
||||
char *mkey;
|
||||
char *mval;
|
||||
|
||||
fd = fopen(PKFILE, "r");
|
||||
if (fd == NULL)
|
||||
return (0);
|
||||
for (;;) {
|
||||
res = fgets(buf, sizeof(buf), fd);
|
||||
if (res == NULL) {
|
||||
fclose(fd);
|
||||
return (0);
|
||||
}
|
||||
if (res[0] == '#')
|
||||
continue;
|
||||
else if (res[0] == '+') {
|
||||
#ifdef YP
|
||||
char *PKMAP = "publickey.byname";
|
||||
char *lookup;
|
||||
char *domain;
|
||||
int err;
|
||||
int len;
|
||||
|
||||
err = yp_get_default_domain(&domain);
|
||||
if (err) {
|
||||
continue;
|
||||
}
|
||||
lookup = NULL;
|
||||
err = yp_match(domain, PKMAP, key, strlen(key), &lookup, &len);
|
||||
if (err) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "match failed error %d\n", err);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
lookup[len] = 0;
|
||||
strcpy(ret, lookup);
|
||||
fclose(fd);
|
||||
free(lookup);
|
||||
return (2);
|
||||
#else /* YP */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"Bad record in %s '+' -- NIS not supported in this library copy\n", PKFILE);
|
||||
#endif /* DEBUG */
|
||||
continue;
|
||||
#endif /* YP */
|
||||
} else {
|
||||
mkey = strsep(&res, "\t ");
|
||||
if (mkey == NULL) {
|
||||
fprintf(stderr,
|
||||
"Bad record in %s -- %s", PKFILE, buf);
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
mval = strsep(&res, " \t#\n");
|
||||
} while (mval != NULL && !*mval);
|
||||
if (mval == NULL) {
|
||||
fprintf(stderr,
|
||||
"Bad record in %s val problem - %s", PKFILE, buf);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(mkey, key) == 0) {
|
||||
strcpy(ret, mval);
|
||||
fclose(fd);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getpublickey(netname, publickey)
|
||||
const char *netname;
|
||||
char *publickey;
|
||||
{
|
||||
if (__getpublickey_LOCAL != NULL)
|
||||
return(__getpublickey_LOCAL(netname, publickey));
|
||||
else
|
||||
return(__getpublickey_real(netname, publickey));
|
||||
}
|
1048
freebsd/lib/libc/rpc/getrpcent.c
Normal file
1048
freebsd/lib/libc/rpc/getrpcent.c
Normal file
File diff suppressed because it is too large
Load Diff
79
freebsd/lib/libc/rpc/getrpcport.c
Normal file
79
freebsd/lib/libc/rpc/getrpcport.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: getrpcport.c,v 1.16 2000/01/22 22:19:18 mycroft Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)getrpcport.c 1.3 87/08/11 SMI";
|
||||
static char *sccsid = "@(#)getrpcport.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Copyright (c) 1985 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
int
|
||||
getrpcport(host, prognum, versnum, proto)
|
||||
char *host;
|
||||
int prognum, versnum, proto;
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
struct hostent *hp;
|
||||
|
||||
assert(host != NULL);
|
||||
|
||||
if ((hp = gethostbyname(host)) == NULL)
|
||||
return (0);
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_len = sizeof(struct sockaddr_in);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = 0;
|
||||
if (hp->h_length > addr.sin_len)
|
||||
hp->h_length = addr.sin_len;
|
||||
memcpy(&addr.sin_addr.s_addr, hp->h_addr, (size_t)hp->h_length);
|
||||
/* Inconsistent interfaces need casts! :-( */
|
||||
return (pmap_getport(&addr, (u_long)prognum, (u_long)versnum,
|
||||
(u_int)proto));
|
||||
}
|
481
freebsd/lib/libc/rpc/key_call.c
Normal file
481
freebsd/lib/libc/rpc/key_call.c
Normal file
@ -0,0 +1,481 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#ident "@(#)key_call.c 1.25 94/04/24 SMI"
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* key_call.c, Interface to keyserver
|
||||
*
|
||||
* setsecretkey(key) - set your secret key
|
||||
* encryptsessionkey(agent, deskey) - encrypt a session key to talk to agent
|
||||
* decryptsessionkey(agent, deskey) - decrypt ditto
|
||||
* gendeskey(deskey) - generate a secure des key
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_unix.h>
|
||||
#include <rpc/key_prot.h>
|
||||
#include <string.h>
|
||||
#include <netconfig.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
|
||||
#define KEY_TIMEOUT 5 /* per-try timeout in seconds */
|
||||
#define KEY_NRETRY 12 /* number of retries */
|
||||
|
||||
#ifdef DEBUG
|
||||
#define debug(msg) (void) fprintf(stderr, "%s\n", msg);
|
||||
#else
|
||||
#define debug(msg)
|
||||
#endif /* DEBUG */
|
||||
|
||||
/*
|
||||
* Hack to allow the keyserver to use AUTH_DES (for authenticated
|
||||
* NIS+ calls, for example). The only functions that get called
|
||||
* are key_encryptsession_pk, key_decryptsession_pk, and key_gendes.
|
||||
*
|
||||
* The approach is to have the keyserver fill in pointers to local
|
||||
* implementations of these functions, and to call those in key_call().
|
||||
*/
|
||||
|
||||
cryptkeyres *(*__key_encryptsession_pk_LOCAL)() = 0;
|
||||
cryptkeyres *(*__key_decryptsession_pk_LOCAL)() = 0;
|
||||
des_block *(*__key_gendes_LOCAL)() = 0;
|
||||
|
||||
static int key_call( u_long, xdrproc_t, void *, xdrproc_t, void *);
|
||||
|
||||
int
|
||||
key_setsecret(secretkey)
|
||||
const char *secretkey;
|
||||
{
|
||||
keystatus status;
|
||||
|
||||
if (!key_call((u_long) KEY_SET, (xdrproc_t)xdr_keybuf,
|
||||
(void *)secretkey,
|
||||
(xdrproc_t)xdr_keystatus, &status)) {
|
||||
return (-1);
|
||||
}
|
||||
if (status != KEY_SUCCESS) {
|
||||
debug("set status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* key_secretkey_is_set() returns 1 if the keyserver has a secret key
|
||||
* stored for the caller's effective uid; it returns 0 otherwise
|
||||
*
|
||||
* N.B.: The KEY_NET_GET key call is undocumented. Applications shouldn't
|
||||
* be using it, because it allows them to get the user's secret key.
|
||||
*/
|
||||
|
||||
int
|
||||
key_secretkey_is_set(void)
|
||||
{
|
||||
struct key_netstres kres;
|
||||
|
||||
memset((void*)&kres, 0, sizeof (kres));
|
||||
if (key_call((u_long) KEY_NET_GET, (xdrproc_t)xdr_void, NULL,
|
||||
(xdrproc_t)xdr_key_netstres, &kres) &&
|
||||
(kres.status == KEY_SUCCESS) &&
|
||||
(kres.key_netstres_u.knet.st_priv_key[0] != 0)) {
|
||||
/* avoid leaving secret key in memory */
|
||||
memset(kres.key_netstres_u.knet.st_priv_key, 0, HEXKEYBYTES);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
key_encryptsession_pk(remotename, remotekey, deskey)
|
||||
char *remotename;
|
||||
netobj *remotekey;
|
||||
des_block *deskey;
|
||||
{
|
||||
cryptkeyarg2 arg;
|
||||
cryptkeyres res;
|
||||
|
||||
arg.remotename = remotename;
|
||||
arg.remotekey = *remotekey;
|
||||
arg.deskey = *deskey;
|
||||
if (!key_call((u_long)KEY_ENCRYPT_PK, (xdrproc_t)xdr_cryptkeyarg2, &arg,
|
||||
(xdrproc_t)xdr_cryptkeyres, &res)) {
|
||||
return (-1);
|
||||
}
|
||||
if (res.status != KEY_SUCCESS) {
|
||||
debug("encrypt status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
*deskey = res.cryptkeyres_u.deskey;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
key_decryptsession_pk(remotename, remotekey, deskey)
|
||||
char *remotename;
|
||||
netobj *remotekey;
|
||||
des_block *deskey;
|
||||
{
|
||||
cryptkeyarg2 arg;
|
||||
cryptkeyres res;
|
||||
|
||||
arg.remotename = remotename;
|
||||
arg.remotekey = *remotekey;
|
||||
arg.deskey = *deskey;
|
||||
if (!key_call((u_long)KEY_DECRYPT_PK, (xdrproc_t)xdr_cryptkeyarg2, &arg,
|
||||
(xdrproc_t)xdr_cryptkeyres, &res)) {
|
||||
return (-1);
|
||||
}
|
||||
if (res.status != KEY_SUCCESS) {
|
||||
debug("decrypt status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
*deskey = res.cryptkeyres_u.deskey;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
key_encryptsession(remotename, deskey)
|
||||
const char *remotename;
|
||||
des_block *deskey;
|
||||
{
|
||||
cryptkeyarg arg;
|
||||
cryptkeyres res;
|
||||
|
||||
arg.remotename = (char *) remotename;
|
||||
arg.deskey = *deskey;
|
||||
if (!key_call((u_long)KEY_ENCRYPT, (xdrproc_t)xdr_cryptkeyarg, &arg,
|
||||
(xdrproc_t)xdr_cryptkeyres, &res)) {
|
||||
return (-1);
|
||||
}
|
||||
if (res.status != KEY_SUCCESS) {
|
||||
debug("encrypt status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
*deskey = res.cryptkeyres_u.deskey;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
key_decryptsession(remotename, deskey)
|
||||
const char *remotename;
|
||||
des_block *deskey;
|
||||
{
|
||||
cryptkeyarg arg;
|
||||
cryptkeyres res;
|
||||
|
||||
arg.remotename = (char *) remotename;
|
||||
arg.deskey = *deskey;
|
||||
if (!key_call((u_long)KEY_DECRYPT, (xdrproc_t)xdr_cryptkeyarg, &arg,
|
||||
(xdrproc_t)xdr_cryptkeyres, &res)) {
|
||||
return (-1);
|
||||
}
|
||||
if (res.status != KEY_SUCCESS) {
|
||||
debug("decrypt status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
*deskey = res.cryptkeyres_u.deskey;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
key_gendes(key)
|
||||
des_block *key;
|
||||
{
|
||||
if (!key_call((u_long)KEY_GEN, (xdrproc_t)xdr_void, NULL,
|
||||
(xdrproc_t)xdr_des_block, key)) {
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
key_setnet(arg)
|
||||
struct key_netstarg *arg;
|
||||
{
|
||||
keystatus status;
|
||||
|
||||
|
||||
if (!key_call((u_long) KEY_NET_PUT, (xdrproc_t)xdr_key_netstarg, arg,
|
||||
(xdrproc_t)xdr_keystatus, &status)){
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (status != KEY_SUCCESS) {
|
||||
debug("key_setnet status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
key_get_conv(pkey, deskey)
|
||||
char *pkey;
|
||||
des_block *deskey;
|
||||
{
|
||||
cryptkeyres res;
|
||||
|
||||
if (!key_call((u_long) KEY_GET_CONV, (xdrproc_t)xdr_keybuf, pkey,
|
||||
(xdrproc_t)xdr_cryptkeyres, &res)) {
|
||||
return (-1);
|
||||
}
|
||||
if (res.status != KEY_SUCCESS) {
|
||||
debug("get_conv status is nonzero");
|
||||
return (-1);
|
||||
}
|
||||
*deskey = res.cryptkeyres_u.deskey;
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct key_call_private {
|
||||
CLIENT *client; /* Client handle */
|
||||
pid_t pid; /* process-id at moment of creation */
|
||||
uid_t uid; /* user-id at last authorization */
|
||||
};
|
||||
static struct key_call_private *key_call_private_main = NULL;
|
||||
static thread_key_t key_call_key;
|
||||
static once_t key_call_once = ONCE_INITIALIZER;
|
||||
static int key_call_key_error;
|
||||
|
||||
static void
|
||||
key_call_destroy(void *vp)
|
||||
{
|
||||
struct key_call_private *kcp = (struct key_call_private *)vp;
|
||||
|
||||
if (kcp) {
|
||||
if (kcp->client)
|
||||
clnt_destroy(kcp->client);
|
||||
free(kcp);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
key_call_init(void)
|
||||
{
|
||||
|
||||
key_call_key_error = thr_keycreate(&key_call_key, key_call_destroy);
|
||||
}
|
||||
|
||||
/*
|
||||
* Keep the handle cached. This call may be made quite often.
|
||||
*/
|
||||
static CLIENT *
|
||||
getkeyserv_handle(vers)
|
||||
int vers;
|
||||
{
|
||||
void *localhandle;
|
||||
struct netconfig *nconf;
|
||||
struct netconfig *tpconf;
|
||||
struct key_call_private *kcp;
|
||||
struct timeval wait_time;
|
||||
struct utsname u;
|
||||
int main_thread;
|
||||
int fd;
|
||||
|
||||
#define TOTAL_TIMEOUT 30 /* total timeout talking to keyserver */
|
||||
#define TOTAL_TRIES 5 /* Number of tries */
|
||||
|
||||
if ((main_thread = thr_main())) {
|
||||
kcp = key_call_private_main;
|
||||
} else {
|
||||
if (thr_once(&key_call_once, key_call_init) != 0 ||
|
||||
key_call_key_error != 0)
|
||||
return ((CLIENT *) NULL);
|
||||
kcp = (struct key_call_private *)thr_getspecific(key_call_key);
|
||||
}
|
||||
if (kcp == (struct key_call_private *)NULL) {
|
||||
kcp = (struct key_call_private *)malloc(sizeof (*kcp));
|
||||
if (kcp == (struct key_call_private *)NULL) {
|
||||
return ((CLIENT *) NULL);
|
||||
}
|
||||
if (main_thread)
|
||||
key_call_private_main = kcp;
|
||||
else
|
||||
thr_setspecific(key_call_key, (void *) kcp);
|
||||
kcp->client = NULL;
|
||||
}
|
||||
|
||||
/* if pid has changed, destroy client and rebuild */
|
||||
if (kcp->client != NULL && kcp->pid != getpid()) {
|
||||
clnt_destroy(kcp->client);
|
||||
kcp->client = NULL;
|
||||
}
|
||||
|
||||
if (kcp->client != NULL) {
|
||||
/* if uid has changed, build client handle again */
|
||||
if (kcp->uid != geteuid()) {
|
||||
kcp->uid = geteuid();
|
||||
auth_destroy(kcp->client->cl_auth);
|
||||
kcp->client->cl_auth =
|
||||
authsys_create("", kcp->uid, 0, 0, NULL);
|
||||
if (kcp->client->cl_auth == NULL) {
|
||||
clnt_destroy(kcp->client);
|
||||
kcp->client = NULL;
|
||||
return ((CLIENT *) NULL);
|
||||
}
|
||||
}
|
||||
/* Change the version number to the new one */
|
||||
clnt_control(kcp->client, CLSET_VERS, (void *)&vers);
|
||||
return (kcp->client);
|
||||
}
|
||||
if (!(localhandle = setnetconfig())) {
|
||||
return ((CLIENT *) NULL);
|
||||
}
|
||||
tpconf = NULL;
|
||||
#if defined(__FreeBSD__)
|
||||
if (uname(&u) == -1)
|
||||
#else
|
||||
#if defined(i386)
|
||||
if (_nuname(&u) == -1)
|
||||
#elif defined(sparc)
|
||||
if (_uname(&u) == -1)
|
||||
#else
|
||||
#error Unknown architecture!
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
endnetconfig(localhandle);
|
||||
return ((CLIENT *) NULL);
|
||||
}
|
||||
while ((nconf = getnetconfig(localhandle)) != NULL) {
|
||||
if (strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) {
|
||||
/*
|
||||
* We use COTS_ORD here so that the caller can
|
||||
* find out immediately if the server is dead.
|
||||
*/
|
||||
if (nconf->nc_semantics == NC_TPI_COTS_ORD) {
|
||||
kcp->client = clnt_tp_create(u.nodename,
|
||||
KEY_PROG, vers, nconf);
|
||||
if (kcp->client)
|
||||
break;
|
||||
} else {
|
||||
tpconf = nconf;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((kcp->client == (CLIENT *) NULL) && (tpconf))
|
||||
/* Now, try the CLTS or COTS loopback transport */
|
||||
kcp->client = clnt_tp_create(u.nodename,
|
||||
KEY_PROG, vers, tpconf);
|
||||
endnetconfig(localhandle);
|
||||
|
||||
if (kcp->client == (CLIENT *) NULL) {
|
||||
return ((CLIENT *) NULL);
|
||||
}
|
||||
kcp->uid = geteuid();
|
||||
kcp->pid = getpid();
|
||||
kcp->client->cl_auth = authsys_create("", kcp->uid, 0, 0, NULL);
|
||||
if (kcp->client->cl_auth == NULL) {
|
||||
clnt_destroy(kcp->client);
|
||||
kcp->client = NULL;
|
||||
return ((CLIENT *) NULL);
|
||||
}
|
||||
|
||||
wait_time.tv_sec = TOTAL_TIMEOUT/TOTAL_TRIES;
|
||||
wait_time.tv_usec = 0;
|
||||
(void) clnt_control(kcp->client, CLSET_RETRY_TIMEOUT,
|
||||
(char *)&wait_time);
|
||||
if (clnt_control(kcp->client, CLGET_FD, (char *)&fd))
|
||||
_fcntl(fd, F_SETFD, 1); /* make it "close on exec" */
|
||||
|
||||
return (kcp->client);
|
||||
}
|
||||
|
||||
/* returns 0 on failure, 1 on success */
|
||||
|
||||
static int
|
||||
key_call(proc, xdr_arg, arg, xdr_rslt, rslt)
|
||||
u_long proc;
|
||||
xdrproc_t xdr_arg;
|
||||
void *arg;
|
||||
xdrproc_t xdr_rslt;
|
||||
void *rslt;
|
||||
{
|
||||
CLIENT *clnt;
|
||||
struct timeval wait_time;
|
||||
|
||||
if (proc == KEY_ENCRYPT_PK && __key_encryptsession_pk_LOCAL) {
|
||||
cryptkeyres *res;
|
||||
res = (*__key_encryptsession_pk_LOCAL)(geteuid(), arg);
|
||||
*(cryptkeyres*)rslt = *res;
|
||||
return (1);
|
||||
} else if (proc == KEY_DECRYPT_PK && __key_decryptsession_pk_LOCAL) {
|
||||
cryptkeyres *res;
|
||||
res = (*__key_decryptsession_pk_LOCAL)(geteuid(), arg);
|
||||
*(cryptkeyres*)rslt = *res;
|
||||
return (1);
|
||||
} else if (proc == KEY_GEN && __key_gendes_LOCAL) {
|
||||
des_block *res;
|
||||
res = (*__key_gendes_LOCAL)(geteuid(), 0);
|
||||
*(des_block*)rslt = *res;
|
||||
return (1);
|
||||
}
|
||||
|
||||
if ((proc == KEY_ENCRYPT_PK) || (proc == KEY_DECRYPT_PK) ||
|
||||
(proc == KEY_NET_GET) || (proc == KEY_NET_PUT) ||
|
||||
(proc == KEY_GET_CONV))
|
||||
clnt = getkeyserv_handle(2); /* talk to version 2 */
|
||||
else
|
||||
clnt = getkeyserv_handle(1); /* talk to version 1 */
|
||||
|
||||
if (clnt == NULL) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
wait_time.tv_sec = TOTAL_TIMEOUT;
|
||||
wait_time.tv_usec = 0;
|
||||
|
||||
if (clnt_call(clnt, proc, xdr_arg, arg, xdr_rslt, rslt,
|
||||
wait_time) == RPC_SUCCESS) {
|
||||
return (1);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
}
|
179
freebsd/lib/libc/rpc/key_prot_xdr.c
Normal file
179
freebsd/lib/libc/rpc/key_prot_xdr.c
Normal file
@ -0,0 +1,179 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rpc/key_prot.h>
|
||||
#include "un-namespace.h"
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */
|
||||
|
||||
/* #pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI" */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Compiled from key_prot.x using rpcgen.
|
||||
* DO NOT EDIT THIS FILE!
|
||||
* This is NOT source code!
|
||||
*/
|
||||
|
||||
bool_t
|
||||
xdr_keystatus(register XDR *xdrs, keystatus *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum(xdrs, (enum_t *)objp))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_keybuf(register XDR *xdrs, keybuf objp)
|
||||
{
|
||||
|
||||
if (!xdr_opaque(xdrs, objp, HEXKEYBYTES))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_netnamestr(register XDR *xdrs, netnamestr *objp)
|
||||
{
|
||||
|
||||
if (!xdr_string(xdrs, objp, MAXNETNAMELEN))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_cryptkeyarg(register XDR *xdrs, cryptkeyarg *objp)
|
||||
{
|
||||
|
||||
if (!xdr_netnamestr(xdrs, &objp->remotename))
|
||||
return (FALSE);
|
||||
if (!xdr_des_block(xdrs, &objp->deskey))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_cryptkeyarg2(register XDR *xdrs, cryptkeyarg2 *objp)
|
||||
{
|
||||
|
||||
if (!xdr_netnamestr(xdrs, &objp->remotename))
|
||||
return (FALSE);
|
||||
if (!xdr_netobj(xdrs, &objp->remotekey))
|
||||
return (FALSE);
|
||||
if (!xdr_des_block(xdrs, &objp->deskey))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_cryptkeyres(register XDR *xdrs, cryptkeyres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_keystatus(xdrs, &objp->status))
|
||||
return (FALSE);
|
||||
switch (objp->status) {
|
||||
case KEY_SUCCESS:
|
||||
if (!xdr_des_block(xdrs, &objp->cryptkeyres_u.deskey))
|
||||
return (FALSE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_unixcred(register XDR *xdrs, unixcred *objp)
|
||||
{
|
||||
u_int **pgids_val;
|
||||
|
||||
if (!xdr_u_int(xdrs, &objp->uid))
|
||||
return (FALSE);
|
||||
if (!xdr_u_int(xdrs, &objp->gid))
|
||||
return (FALSE);
|
||||
pgids_val = &objp->gids.gids_val;
|
||||
if (!xdr_array(xdrs, (char **) pgids_val, (u_int *) &objp->gids.gids_len, MAXGIDS,
|
||||
sizeof (u_int), (xdrproc_t) xdr_u_int))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_getcredres(register XDR *xdrs, getcredres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_keystatus(xdrs, &objp->status))
|
||||
return (FALSE);
|
||||
switch (objp->status) {
|
||||
case KEY_SUCCESS:
|
||||
if (!xdr_unixcred(xdrs, &objp->getcredres_u.cred))
|
||||
return (FALSE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_key_netstarg(register XDR *xdrs, key_netstarg *objp)
|
||||
{
|
||||
|
||||
if (!xdr_keybuf(xdrs, objp->st_priv_key))
|
||||
return (FALSE);
|
||||
if (!xdr_keybuf(xdrs, objp->st_pub_key))
|
||||
return (FALSE);
|
||||
if (!xdr_netnamestr(xdrs, &objp->st_netname))
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_key_netstres(register XDR *xdrs, key_netstres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_keystatus(xdrs, &objp->status))
|
||||
return (FALSE);
|
||||
switch (objp->status) {
|
||||
case KEY_SUCCESS:
|
||||
if (!xdr_key_netstarg(xdrs, &objp->key_netstres_u.knet))
|
||||
return (FALSE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
119
freebsd/lib/libc/rpc/mt_misc.c
Normal file
119
freebsd/lib/libc/rpc/mt_misc.c
Normal file
@ -0,0 +1,119 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: mt_misc.c,v 1.1 2000/06/02 23:11:11 fvdl Exp $ */
|
||||
|
||||
/* #pragma ident "@(#)mt_misc.c 1.24 93/04/29 SMI" */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <rpc/rpc.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
/* Take these objects out of the application namespace. */
|
||||
#define svc_lock __svc_lock
|
||||
#define svc_fd_lock __svc_fd_lock
|
||||
#define rpcbaddr_cache_lock __rpcbaddr_cache_lock
|
||||
#define authdes_ops_lock __authdes_ops_lock
|
||||
#define authnone_lock __authnone_lock
|
||||
#define authsvc_lock __authsvc_lock
|
||||
#define clnt_fd_lock __clnt_fd_lock
|
||||
#define clntraw_lock __clntraw_lock
|
||||
#define dupreq_lock __dupreq_lock
|
||||
#define loopnconf_lock __loopnconf_lock
|
||||
#define ops_lock __ops_lock
|
||||
#define proglst_lock __proglst_lock
|
||||
#define rpcsoc_lock __rpcsoc_lock
|
||||
#define svcraw_lock __svcraw_lock
|
||||
#define xprtlist_lock __xprtlist_lock
|
||||
|
||||
/* protects the services list (svc.c) */
|
||||
pthread_rwlock_t svc_lock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
/* protects svc_fdset and the xports[] array */
|
||||
pthread_rwlock_t svc_fd_lock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
/* protects the RPCBIND address cache */
|
||||
pthread_rwlock_t rpcbaddr_cache_lock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
/* serializes authdes ops initializations */
|
||||
pthread_mutex_t authdes_ops_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* protects des stats list */
|
||||
pthread_mutex_t svcauthdesstats_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* auth_none.c serialization */
|
||||
pthread_mutex_t authnone_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* protects the Auths list (svc_auth.c) */
|
||||
pthread_mutex_t authsvc_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* protects client-side fd lock array */
|
||||
pthread_mutex_t clnt_fd_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* clnt_raw.c serialization */
|
||||
pthread_mutex_t clntraw_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* dupreq variables (svc_dg.c) */
|
||||
pthread_mutex_t dupreq_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* loopnconf (rpcb_clnt.c) */
|
||||
pthread_mutex_t loopnconf_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* serializes ops initializations */
|
||||
pthread_mutex_t ops_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* protects proglst list (svc_simple.c) */
|
||||
pthread_mutex_t proglst_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* serializes clnt_com_create() (rpc_soc.c) */
|
||||
pthread_mutex_t rpcsoc_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* svc_raw.c serialization */
|
||||
pthread_mutex_t svcraw_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* xprtlist (svc_generic.c) */
|
||||
pthread_mutex_t xprtlist_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#undef rpc_createerr
|
||||
|
||||
struct rpc_createerr rpc_createerr;
|
||||
static thread_key_t rce_key;
|
||||
static once_t rce_once = ONCE_INITIALIZER;
|
||||
static int rce_key_error;
|
||||
|
||||
static void
|
||||
rce_key_init(void)
|
||||
{
|
||||
|
||||
rce_key_error = thr_keycreate(&rce_key, free);
|
||||
}
|
||||
|
||||
struct rpc_createerr *
|
||||
__rpc_createerr()
|
||||
{
|
||||
struct rpc_createerr *rce_addr = 0;
|
||||
|
||||
if (thr_main())
|
||||
return (&rpc_createerr);
|
||||
if (thr_once(&rce_once, rce_key_init) != 0 || rce_key_error != 0)
|
||||
return (&rpc_createerr);
|
||||
rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key);
|
||||
if (!rce_addr) {
|
||||
rce_addr = (struct rpc_createerr *)
|
||||
malloc(sizeof (struct rpc_createerr));
|
||||
if (thr_setspecific(rce_key, (void *) rce_addr) != 0) {
|
||||
if (rce_addr)
|
||||
free(rce_addr);
|
||||
return (&rpc_createerr);
|
||||
}
|
||||
memset(rce_addr, 0, sizeof (struct rpc_createerr));
|
||||
return (rce_addr);
|
||||
}
|
||||
return (rce_addr);
|
||||
}
|
65
freebsd/lib/libc/rpc/mt_misc.h
Normal file
65
freebsd/lib/libc/rpc/mt_misc.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The FreeBSD Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifndef _MT_MISC_H
|
||||
#define _MT_MISC_H
|
||||
|
||||
/* Take these locks out of the application namespace. */
|
||||
#define svc_lock __svc_lock
|
||||
#define svc_fd_lock __svc_fd_lock
|
||||
#define rpcbaddr_cache_lock __rpcbaddr_cache_lock
|
||||
#define authdes_ops_lock __authdes_ops_lock
|
||||
#define authnone_lock __authnone_lock
|
||||
#define authsvc_lock __authsvc_lock
|
||||
#define clnt_fd_lock __clnt_fd_lock
|
||||
#define clntraw_lock __clntraw_lock
|
||||
#define dupreq_lock __dupreq_lock
|
||||
#define loopnconf_lock __loopnconf_lock
|
||||
#define ops_lock __ops_lock
|
||||
#define proglst_lock __proglst_lock
|
||||
#define rpcsoc_lock __rpcsoc_lock
|
||||
#define svcraw_lock __svcraw_lock
|
||||
#define xprtlist_lock __xprtlist_lock
|
||||
|
||||
extern pthread_rwlock_t svc_lock;
|
||||
extern pthread_rwlock_t svc_fd_lock;
|
||||
extern pthread_rwlock_t rpcbaddr_cache_lock;
|
||||
extern pthread_mutex_t authdes_ops_lock;
|
||||
extern pthread_mutex_t svcauthdesstats_lock;
|
||||
extern pthread_mutex_t authnone_lock;
|
||||
extern pthread_mutex_t authsvc_lock;
|
||||
extern pthread_mutex_t clnt_fd_lock;
|
||||
extern pthread_mutex_t clntraw_lock;
|
||||
extern pthread_mutex_t dupreq_lock;
|
||||
extern pthread_mutex_t loopnconf_lock;
|
||||
extern pthread_mutex_t ops_lock;
|
||||
extern pthread_mutex_t proglst_lock;
|
||||
extern pthread_mutex_t rpcsoc_lock;
|
||||
extern pthread_mutex_t svcraw_lock;
|
||||
extern pthread_mutex_t tsd_lock;
|
||||
extern pthread_mutex_t xprtlist_lock;
|
||||
|
||||
#endif
|
150
freebsd/lib/libc/rpc/netname.c
Normal file
150
freebsd/lib/libc/rpc/netname.c
Normal file
@ -0,0 +1,150 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* netname utility routines
|
||||
* convert from unix names to network names and vice-versa
|
||||
* This module is operating system dependent!
|
||||
* What we define here will work with any unix system that has adopted
|
||||
* the sun NIS domain architecture.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#ifdef YP
|
||||
#include <rpcsvc/yp_prot.h>
|
||||
#include <rpcsvc/ypclnt.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 256
|
||||
#endif
|
||||
|
||||
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
|
||||
|
||||
#define TYPE_SIGNED(type) (((type) -1) < 0)
|
||||
|
||||
/*
|
||||
** 302 / 1000 is log10(2.0) rounded up.
|
||||
** Subtract one for the sign bit if the type is signed;
|
||||
** add one for integer division truncation;
|
||||
** add one more for a minus sign if the type is signed.
|
||||
*/
|
||||
#define INT_STRLEN_MAXIMUM(type) \
|
||||
((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
|
||||
|
||||
static char *OPSYS = "unix";
|
||||
|
||||
/*
|
||||
* Figure out my fully qualified network name
|
||||
*/
|
||||
int
|
||||
getnetname(name)
|
||||
char name[MAXNETNAMELEN+1];
|
||||
{
|
||||
uid_t uid;
|
||||
|
||||
uid = geteuid();
|
||||
if (uid == 0) {
|
||||
return (host2netname(name, (char *) NULL, (char *) NULL));
|
||||
} else {
|
||||
return (user2netname(name, uid, (char *) NULL));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert unix cred to network-name
|
||||
*/
|
||||
int
|
||||
user2netname(netname, uid, domain)
|
||||
char netname[MAXNETNAMELEN + 1];
|
||||
const uid_t uid;
|
||||
const char *domain;
|
||||
{
|
||||
char *dfltdom;
|
||||
|
||||
if (domain == NULL) {
|
||||
if (__rpc_get_default_domain(&dfltdom) != 0) {
|
||||
return (0);
|
||||
}
|
||||
domain = dfltdom;
|
||||
}
|
||||
if (strlen(domain) + 1 + INT_STRLEN_MAXIMUM(u_long) + 1 + strlen(OPSYS) > MAXNETNAMELEN) {
|
||||
return (0);
|
||||
}
|
||||
(void) sprintf(netname, "%s.%ld@%s", OPSYS, (u_long)uid, domain);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert host to network-name
|
||||
*/
|
||||
int
|
||||
host2netname(netname, host, domain)
|
||||
char netname[MAXNETNAMELEN + 1];
|
||||
const char *host;
|
||||
const char *domain;
|
||||
{
|
||||
char *dfltdom;
|
||||
char hostname[MAXHOSTNAMELEN+1];
|
||||
|
||||
if (domain == NULL) {
|
||||
if (__rpc_get_default_domain(&dfltdom) != 0) {
|
||||
return (0);
|
||||
}
|
||||
domain = dfltdom;
|
||||
}
|
||||
if (host == NULL) {
|
||||
(void) gethostname(hostname, sizeof(hostname));
|
||||
host = hostname;
|
||||
}
|
||||
if (strlen(domain) + 1 + strlen(host) + 1 + strlen(OPSYS) > MAXNETNAMELEN) {
|
||||
return (0);
|
||||
}
|
||||
(void) sprintf(netname, "%s.%s@%s", OPSYS, host, domain);
|
||||
return (1);
|
||||
}
|
331
freebsd/lib/libc/rpc/netnamer.c
Normal file
331
freebsd/lib/libc/rpc/netnamer.c
Normal file
@ -0,0 +1,331 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)netnamer.c 1.13 91/03/11 Copyr 1986 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* netname utility routines convert from unix names to network names and
|
||||
* vice-versa This module is operating system dependent! What we define here
|
||||
* will work with any unix system that has adopted the sun NIS domain
|
||||
* architecture.
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#ifdef YP
|
||||
#include <rpcsvc/yp_prot.h>
|
||||
#include <rpcsvc/ypclnt.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
static char *OPSYS = "unix";
|
||||
#ifdef YP
|
||||
static char *NETID = "netid.byname";
|
||||
#endif
|
||||
static char *NETIDFILE = "/etc/netid";
|
||||
|
||||
static int getnetid( char *, char * );
|
||||
static int _getgroups( char *, gid_t * );
|
||||
|
||||
/*
|
||||
* Convert network-name into unix credential
|
||||
*/
|
||||
int
|
||||
netname2user(netname, uidp, gidp, gidlenp, gidlist)
|
||||
char netname[MAXNETNAMELEN + 1];
|
||||
uid_t *uidp;
|
||||
gid_t *gidp;
|
||||
int *gidlenp;
|
||||
gid_t *gidlist;
|
||||
{
|
||||
char *p;
|
||||
int gidlen;
|
||||
uid_t uid;
|
||||
long luid;
|
||||
struct passwd *pwd;
|
||||
char val[1024];
|
||||
char *val1, *val2;
|
||||
char *domain;
|
||||
int vallen;
|
||||
int err;
|
||||
|
||||
if (getnetid(netname, val)) {
|
||||
char *res = val;
|
||||
|
||||
p = strsep(&res, ":");
|
||||
if (p == NULL)
|
||||
return (0);
|
||||
*uidp = (uid_t) atol(p);
|
||||
p = strsep(&res, "\n,");
|
||||
if (p == NULL) {
|
||||
return (0);
|
||||
}
|
||||
*gidp = (gid_t) atol(p);
|
||||
for (gidlen = 0; gidlen < NGRPS; gidlen++) {
|
||||
p = strsep(&res, "\n,");
|
||||
if (p == NULL)
|
||||
break;
|
||||
gidlist[gidlen] = (gid_t) atol(p);
|
||||
}
|
||||
*gidlenp = gidlen;
|
||||
|
||||
return (1);
|
||||
}
|
||||
val1 = strchr(netname, '.');
|
||||
if (val1 == NULL)
|
||||
return (0);
|
||||
if (strncmp(netname, OPSYS, (val1-netname)))
|
||||
return (0);
|
||||
val1++;
|
||||
val2 = strchr(val1, '@');
|
||||
if (val2 == NULL)
|
||||
return (0);
|
||||
vallen = val2 - val1;
|
||||
if (vallen > (1024 - 1))
|
||||
vallen = 1024 - 1;
|
||||
(void) strncpy(val, val1, 1024);
|
||||
val[vallen] = 0;
|
||||
|
||||
err = __rpc_get_default_domain(&domain); /* change to rpc */
|
||||
if (err)
|
||||
return (0);
|
||||
|
||||
if (strcmp(val2 + 1, domain))
|
||||
return (0); /* wrong domain */
|
||||
|
||||
if (sscanf(val, "%ld", &luid) != 1)
|
||||
return (0);
|
||||
uid = luid;
|
||||
|
||||
/* use initgroups method */
|
||||
pwd = getpwuid(uid);
|
||||
if (pwd == NULL)
|
||||
return (0);
|
||||
*uidp = pwd->pw_uid;
|
||||
*gidp = pwd->pw_gid;
|
||||
*gidlenp = _getgroups(pwd->pw_name, gidlist);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* initgroups
|
||||
*/
|
||||
|
||||
static int
|
||||
_getgroups(uname, groups)
|
||||
char *uname;
|
||||
gid_t groups[NGRPS];
|
||||
{
|
||||
gid_t ngroups = 0;
|
||||
struct group *grp;
|
||||
int i;
|
||||
int j;
|
||||
int filter;
|
||||
|
||||
setgrent();
|
||||
while ((grp = getgrent())) {
|
||||
for (i = 0; grp->gr_mem[i]; i++)
|
||||
if (!strcmp(grp->gr_mem[i], uname)) {
|
||||
if (ngroups == NGRPS) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"initgroups: %s is in too many groups\n", uname);
|
||||
#endif
|
||||
goto toomany;
|
||||
}
|
||||
/* filter out duplicate group entries */
|
||||
filter = 0;
|
||||
for (j = 0; j < ngroups; j++)
|
||||
if (groups[j] == grp->gr_gid) {
|
||||
filter++;
|
||||
break;
|
||||
}
|
||||
if (!filter)
|
||||
groups[ngroups++] = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
toomany:
|
||||
endgrent();
|
||||
return (ngroups);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert network-name to hostname
|
||||
*/
|
||||
int
|
||||
netname2host(netname, hostname, hostlen)
|
||||
char netname[MAXNETNAMELEN + 1];
|
||||
char *hostname;
|
||||
int hostlen;
|
||||
{
|
||||
int err;
|
||||
char valbuf[1024];
|
||||
char *val;
|
||||
char *val2;
|
||||
int vallen;
|
||||
char *domain;
|
||||
|
||||
if (getnetid(netname, valbuf)) {
|
||||
val = valbuf;
|
||||
if ((*val == '0') && (val[1] == ':')) {
|
||||
(void) strncpy(hostname, val + 2, hostlen);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
val = strchr(netname, '.');
|
||||
if (val == NULL)
|
||||
return (0);
|
||||
if (strncmp(netname, OPSYS, (val - netname)))
|
||||
return (0);
|
||||
val++;
|
||||
val2 = strchr(val, '@');
|
||||
if (val2 == NULL)
|
||||
return (0);
|
||||
vallen = val2 - val;
|
||||
if (vallen > (hostlen - 1))
|
||||
vallen = hostlen - 1;
|
||||
(void) strncpy(hostname, val, vallen);
|
||||
hostname[vallen] = 0;
|
||||
|
||||
err = __rpc_get_default_domain(&domain); /* change to rpc */
|
||||
if (err)
|
||||
return (0);
|
||||
|
||||
if (strcmp(val2 + 1, domain))
|
||||
return (0); /* wrong domain */
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* reads the file /etc/netid looking for a + to optionally go to the
|
||||
* network information service.
|
||||
*/
|
||||
int
|
||||
getnetid(key, ret)
|
||||
char *key, *ret;
|
||||
{
|
||||
char buf[1024]; /* big enough */
|
||||
char *res;
|
||||
char *mkey;
|
||||
char *mval;
|
||||
FILE *fd;
|
||||
#ifdef YP
|
||||
char *domain;
|
||||
int err;
|
||||
char *lookup;
|
||||
int len;
|
||||
#endif
|
||||
|
||||
fd = fopen(NETIDFILE, "r");
|
||||
if (fd == NULL) {
|
||||
#ifdef YP
|
||||
res = "+";
|
||||
goto getnetidyp;
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
for (;;) {
|
||||
if (fd == NULL)
|
||||
return (0); /* getnetidyp brings us here */
|
||||
res = fgets(buf, sizeof(buf), fd);
|
||||
if (res == NULL) {
|
||||
fclose(fd);
|
||||
return (0);
|
||||
}
|
||||
if (res[0] == '#')
|
||||
continue;
|
||||
else if (res[0] == '+') {
|
||||
#ifdef YP
|
||||
getnetidyp:
|
||||
err = yp_get_default_domain(&domain);
|
||||
if (err) {
|
||||
continue;
|
||||
}
|
||||
lookup = NULL;
|
||||
err = yp_match(domain, NETID, key,
|
||||
strlen(key), &lookup, &len);
|
||||
if (err) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "match failed error %d\n", err);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
lookup[len] = 0;
|
||||
strcpy(ret, lookup);
|
||||
free(lookup);
|
||||
if (fd != NULL)
|
||||
fclose(fd);
|
||||
return (2);
|
||||
#else /* YP */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"Bad record in %s '+' -- NIS not supported in this library copy\n",
|
||||
NETIDFILE);
|
||||
#endif
|
||||
continue;
|
||||
#endif /* YP */
|
||||
} else {
|
||||
mkey = strsep(&res, "\t ");
|
||||
if (mkey == NULL) {
|
||||
fprintf(stderr,
|
||||
"Bad record in %s -- %s", NETIDFILE, buf);
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
mval = strsep(&res, " \t#\n");
|
||||
} while (mval != NULL && !*mval);
|
||||
if (mval == NULL) {
|
||||
fprintf(stderr,
|
||||
"Bad record in %s val problem - %s", NETIDFILE, buf);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(mkey, key) == 0) {
|
||||
strcpy(ret, mval);
|
||||
fclose(fd);
|
||||
return (1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
121
freebsd/lib/libc/rpc/pmap_clnt.c
Normal file
121
freebsd/lib/libc/rpc/pmap_clnt.c
Normal file
@ -0,0 +1,121 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* pmap_clnt.c
|
||||
* Client interface to pmap rpc service.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include <rpc/nettype.h>
|
||||
#include <netinet/in.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "rpc_com.h"
|
||||
|
||||
bool_t
|
||||
pmap_set(u_long program, u_long version, int protocol, int port)
|
||||
{
|
||||
bool_t rslt;
|
||||
struct netbuf *na;
|
||||
struct netconfig *nconf;
|
||||
char buf[32];
|
||||
|
||||
if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {
|
||||
return (FALSE);
|
||||
}
|
||||
nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");
|
||||
if (nconf == NULL) {
|
||||
return (FALSE);
|
||||
}
|
||||
snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",
|
||||
(((u_int32_t)port) >> 8) & 0xff, port & 0xff);
|
||||
na = uaddr2taddr(nconf, buf);
|
||||
if (na == NULL) {
|
||||
freenetconfigent(nconf);
|
||||
return (FALSE);
|
||||
}
|
||||
rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);
|
||||
free(na);
|
||||
freenetconfigent(nconf);
|
||||
return (rslt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the mapping between program, version and port.
|
||||
* Calls the pmap service remotely to do the un-mapping.
|
||||
*/
|
||||
bool_t
|
||||
pmap_unset(u_long program, u_long version)
|
||||
{
|
||||
struct netconfig *nconf;
|
||||
bool_t udp_rslt = FALSE;
|
||||
bool_t tcp_rslt = FALSE;
|
||||
|
||||
nconf = __rpc_getconfip("udp");
|
||||
if (nconf != NULL) {
|
||||
udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
|
||||
nconf);
|
||||
freenetconfigent(nconf);
|
||||
}
|
||||
nconf = __rpc_getconfip("tcp");
|
||||
if (nconf != NULL) {
|
||||
tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
|
||||
nconf);
|
||||
freenetconfigent(nconf);
|
||||
}
|
||||
/*
|
||||
* XXX: The call may still succeed even if only one of the
|
||||
* calls succeeded. This was the best that could be
|
||||
* done for backward compatibility.
|
||||
*/
|
||||
return (tcp_rslt || udp_rslt);
|
||||
}
|
101
freebsd/lib/libc/rpc/pmap_getmaps.c
Normal file
101
freebsd/lib/libc/rpc/pmap_getmaps.c
Normal file
@ -0,0 +1,101 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: pmap_getmaps.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* pmap_getmap.c
|
||||
* Client interface to pmap rpc service.
|
||||
* contains pmap_getmaps, which is only tcp service involved
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#define NAMELEN 255
|
||||
#define MAX_BROADCAST_SIZE 1400
|
||||
|
||||
/*
|
||||
* Get a copy of the current port maps.
|
||||
* Calls the pmap service remotely to do get the maps.
|
||||
*/
|
||||
struct pmaplist *
|
||||
pmap_getmaps(address)
|
||||
struct sockaddr_in *address;
|
||||
{
|
||||
struct pmaplist *head = NULL;
|
||||
int sock = -1;
|
||||
struct timeval minutetimeout;
|
||||
CLIENT *client;
|
||||
|
||||
assert(address != NULL);
|
||||
|
||||
minutetimeout.tv_sec = 60;
|
||||
minutetimeout.tv_usec = 0;
|
||||
address->sin_port = htons(PMAPPORT);
|
||||
client = clnttcp_create(address, PMAPPROG,
|
||||
PMAPVERS, &sock, 50, 500);
|
||||
if (client != NULL) {
|
||||
if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP,
|
||||
(xdrproc_t)xdr_void, NULL,
|
||||
(xdrproc_t)xdr_pmaplist, &head, minutetimeout) !=
|
||||
RPC_SUCCESS) {
|
||||
clnt_perror(client, "pmap_getmaps rpc problem");
|
||||
}
|
||||
CLNT_DESTROY(client);
|
||||
}
|
||||
address->sin_port = 0;
|
||||
return (head);
|
||||
}
|
105
freebsd/lib/libc/rpc/pmap_getport.c
Normal file
105
freebsd/lib/libc/rpc/pmap_getport.c
Normal file
@ -0,0 +1,105 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: pmap_getport.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "from: @(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "from: @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* pmap_getport.c
|
||||
* Client interface to pmap rpc service.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
static const struct timeval timeout = { 5, 0 };
|
||||
static const struct timeval tottimeout = { 60, 0 };
|
||||
|
||||
/*
|
||||
* Find the mapped port for program,version.
|
||||
* Calls the pmap service remotely to do the lookup.
|
||||
* Returns 0 if no map exists.
|
||||
*/
|
||||
u_short
|
||||
pmap_getport(address, program, version, protocol)
|
||||
struct sockaddr_in *address;
|
||||
u_long program;
|
||||
u_long version;
|
||||
u_int protocol;
|
||||
{
|
||||
u_short port = 0;
|
||||
int sock = -1;
|
||||
CLIENT *client;
|
||||
struct pmap parms;
|
||||
|
||||
assert(address != NULL);
|
||||
|
||||
address->sin_port = htons(PMAPPORT);
|
||||
client = clntudp_bufcreate(address, PMAPPROG,
|
||||
PMAPVERS, timeout, &sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
|
||||
if (client != NULL) {
|
||||
parms.pm_prog = program;
|
||||
parms.pm_vers = version;
|
||||
parms.pm_prot = protocol;
|
||||
parms.pm_port = 0; /* not needed or used */
|
||||
if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_GETPORT,
|
||||
(xdrproc_t)xdr_pmap,
|
||||
&parms, (xdrproc_t)xdr_u_short, &port, tottimeout) !=
|
||||
RPC_SUCCESS){
|
||||
rpc_createerr.cf_stat = RPC_PMAPFAILURE;
|
||||
clnt_geterr(client, &rpc_createerr.cf_error);
|
||||
} else if (port == 0) {
|
||||
rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
|
||||
}
|
||||
CLNT_DESTROY(client);
|
||||
}
|
||||
address->sin_port = 0;
|
||||
return (port);
|
||||
}
|
70
freebsd/lib/libc/rpc/pmap_prot.c
Normal file
70
freebsd/lib/libc/rpc/pmap_prot.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: pmap_prot.c,v 1.10 2000/01/22 22:19:18 mycroft Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)pmap_prot.c 1.17 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)pmap_prot.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* pmap_prot.c
|
||||
* Protocol for the local binder service, or pmap.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
|
||||
bool_t
|
||||
xdr_pmap(xdrs, regs)
|
||||
XDR *xdrs;
|
||||
struct pmap *regs;
|
||||
{
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(regs != NULL);
|
||||
|
||||
if (xdr_u_long(xdrs, ®s->pm_prog) &&
|
||||
xdr_u_long(xdrs, ®s->pm_vers) &&
|
||||
xdr_u_long(xdrs, ®s->pm_prot))
|
||||
return (xdr_u_long(xdrs, ®s->pm_port));
|
||||
return (FALSE);
|
||||
}
|
144
freebsd/lib/libc/rpc/pmap_prot2.c
Normal file
144
freebsd/lib/libc/rpc/pmap_prot2.c
Normal file
@ -0,0 +1,144 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: pmap_prot2.c,v 1.14 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* pmap_prot2.c
|
||||
* Protocol for the local binder service, or pmap.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
|
||||
/*
|
||||
* What is going on with linked lists? (!)
|
||||
* First recall the link list declaration from pmap_prot.h:
|
||||
*
|
||||
* struct pmaplist {
|
||||
* struct pmap pml_map;
|
||||
* struct pmaplist *pml_map;
|
||||
* };
|
||||
*
|
||||
* Compare that declaration with a corresponding xdr declaration that
|
||||
* is (a) pointer-less, and (b) recursive:
|
||||
*
|
||||
* typedef union switch (bool_t) {
|
||||
*
|
||||
* case TRUE: struct {
|
||||
* struct pmap;
|
||||
* pmaplist_t foo;
|
||||
* };
|
||||
*
|
||||
* case FALSE: struct {};
|
||||
* } pmaplist_t;
|
||||
*
|
||||
* Notice that the xdr declaration has no nxt pointer while
|
||||
* the C declaration has no bool_t variable. The bool_t can be
|
||||
* interpreted as ``more data follows me''; if FALSE then nothing
|
||||
* follows this bool_t; if TRUE then the bool_t is followed by
|
||||
* an actual struct pmap, and then (recursively) by the
|
||||
* xdr union, pamplist_t.
|
||||
*
|
||||
* This could be implemented via the xdr_union primitive, though this
|
||||
* would cause a one recursive call per element in the list. Rather than do
|
||||
* that we can ``unwind'' the recursion
|
||||
* into a while loop and do the union arms in-place.
|
||||
*
|
||||
* The head of the list is what the C programmer wishes to past around
|
||||
* the net, yet is the data that the pointer points to which is interesting;
|
||||
* this sounds like a job for xdr_reference!
|
||||
*/
|
||||
bool_t
|
||||
xdr_pmaplist(xdrs, rp)
|
||||
XDR *xdrs;
|
||||
struct pmaplist **rp;
|
||||
{
|
||||
/*
|
||||
* more_elements is pre-computed in case the direction is
|
||||
* XDR_ENCODE or XDR_FREE. more_elements is overwritten by
|
||||
* xdr_bool when the direction is XDR_DECODE.
|
||||
*/
|
||||
bool_t more_elements;
|
||||
int freeing;
|
||||
struct pmaplist **next = NULL; /* pacify gcc */
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(rp != NULL);
|
||||
|
||||
freeing = (xdrs->x_op == XDR_FREE);
|
||||
|
||||
for (;;) {
|
||||
more_elements = (bool_t)(*rp != NULL);
|
||||
if (! xdr_bool(xdrs, &more_elements))
|
||||
return (FALSE);
|
||||
if (! more_elements)
|
||||
return (TRUE); /* we are done */
|
||||
/*
|
||||
* the unfortunate side effect of non-recursion is that in
|
||||
* the case of freeing we must remember the next object
|
||||
* before we free the current object ...
|
||||
*/
|
||||
if (freeing)
|
||||
next = &((*rp)->pml_next);
|
||||
if (! xdr_reference(xdrs, (caddr_t *)rp,
|
||||
(u_int)sizeof(struct pmaplist), (xdrproc_t)xdr_pmap))
|
||||
return (FALSE);
|
||||
rp = (freeing) ? next : &((*rp)->pml_next);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* xdr_pmaplist_ptr() is specified to take a PMAPLIST *, but is identical in
|
||||
* functionality to xdr_pmaplist().
|
||||
*/
|
||||
bool_t
|
||||
xdr_pmaplist_ptr(xdrs, rp)
|
||||
XDR *xdrs;
|
||||
struct pmaplist *rp;
|
||||
{
|
||||
return xdr_pmaplist(xdrs, (struct pmaplist **)(void *)rp);
|
||||
}
|
177
freebsd/lib/libc/rpc/pmap_rmt.c
Normal file
177
freebsd/lib/libc/rpc/pmap_rmt.c
Normal file
@ -0,0 +1,177 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* pmap_rmt.c
|
||||
* Client interface to pmap rpc service.
|
||||
* remote call and broadcast service
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include <rpc/pmap_rmt.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
static const struct timeval timeout = { 3, 0 };
|
||||
|
||||
/*
|
||||
* pmapper remote-call-service interface.
|
||||
* This routine is used to call the pmapper remote call service
|
||||
* which will look up a service program in the port maps, and then
|
||||
* remotely call that routine with the given parameters. This allows
|
||||
* programs to do a lookup and call in one step.
|
||||
*/
|
||||
enum clnt_stat
|
||||
pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
|
||||
port_ptr)
|
||||
struct sockaddr_in *addr;
|
||||
u_long prog, vers, proc;
|
||||
xdrproc_t xdrargs, xdrres;
|
||||
caddr_t argsp, resp;
|
||||
struct timeval tout;
|
||||
u_long *port_ptr;
|
||||
{
|
||||
int sock = -1;
|
||||
CLIENT *client;
|
||||
struct rmtcallargs a;
|
||||
struct rmtcallres r;
|
||||
enum clnt_stat stat;
|
||||
|
||||
assert(addr != NULL);
|
||||
assert(port_ptr != NULL);
|
||||
|
||||
addr->sin_port = htons(PMAPPORT);
|
||||
client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
|
||||
if (client != NULL) {
|
||||
a.prog = prog;
|
||||
a.vers = vers;
|
||||
a.proc = proc;
|
||||
a.args_ptr = argsp;
|
||||
a.xdr_args = xdrargs;
|
||||
r.port_ptr = port_ptr;
|
||||
r.results_ptr = resp;
|
||||
r.xdr_results = xdrres;
|
||||
stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
|
||||
(xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
|
||||
&r, tout);
|
||||
CLNT_DESTROY(client);
|
||||
} else {
|
||||
stat = RPC_FAILED;
|
||||
}
|
||||
addr->sin_port = 0;
|
||||
return (stat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* XDR remote call arguments
|
||||
* written for XDR_ENCODE direction only
|
||||
*/
|
||||
bool_t
|
||||
xdr_rmtcall_args(xdrs, cap)
|
||||
XDR *xdrs;
|
||||
struct rmtcallargs *cap;
|
||||
{
|
||||
u_int lenposition, argposition, position;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(cap != NULL);
|
||||
|
||||
if (xdr_u_long(xdrs, &(cap->prog)) &&
|
||||
xdr_u_long(xdrs, &(cap->vers)) &&
|
||||
xdr_u_long(xdrs, &(cap->proc))) {
|
||||
lenposition = XDR_GETPOS(xdrs);
|
||||
if (! xdr_u_long(xdrs, &(cap->arglen)))
|
||||
return (FALSE);
|
||||
argposition = XDR_GETPOS(xdrs);
|
||||
if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
|
||||
return (FALSE);
|
||||
position = XDR_GETPOS(xdrs);
|
||||
cap->arglen = (u_long)position - (u_long)argposition;
|
||||
XDR_SETPOS(xdrs, lenposition);
|
||||
if (! xdr_u_long(xdrs, &(cap->arglen)))
|
||||
return (FALSE);
|
||||
XDR_SETPOS(xdrs, position);
|
||||
return (TRUE);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR remote call results
|
||||
* written for XDR_DECODE direction only
|
||||
*/
|
||||
bool_t
|
||||
xdr_rmtcallres(xdrs, crp)
|
||||
XDR *xdrs;
|
||||
struct rmtcallres *crp;
|
||||
{
|
||||
caddr_t port_ptr;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(crp != NULL);
|
||||
|
||||
port_ptr = (caddr_t)(void *)crp->port_ptr;
|
||||
if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
|
||||
(xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
|
||||
crp->port_ptr = (u_long *)(void *)port_ptr;
|
||||
return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
208
freebsd/lib/libc/rpc/rpc_callmsg.c
Normal file
208
freebsd/lib/libc/rpc/rpc_callmsg.c
Normal file
@ -0,0 +1,208 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* rpc_callmsg.c
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/*
|
||||
* XDR a call message
|
||||
*/
|
||||
bool_t
|
||||
xdr_callmsg(xdrs, cmsg)
|
||||
XDR *xdrs;
|
||||
struct rpc_msg *cmsg;
|
||||
{
|
||||
enum msg_type *prm_direction;
|
||||
int32_t *buf;
|
||||
struct opaque_auth *oa;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(cmsg != NULL);
|
||||
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
|
||||
return (FALSE);
|
||||
}
|
||||
buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
|
||||
+ RNDUP(cmsg->rm_call.cb_cred.oa_length)
|
||||
+ 2 * BYTES_PER_XDR_UNIT
|
||||
+ RNDUP(cmsg->rm_call.cb_verf.oa_length));
|
||||
if (buf != NULL) {
|
||||
IXDR_PUT_INT32(buf, cmsg->rm_xid);
|
||||
IXDR_PUT_ENUM(buf, cmsg->rm_direction);
|
||||
if (cmsg->rm_direction != CALL) {
|
||||
return (FALSE);
|
||||
}
|
||||
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers);
|
||||
if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
|
||||
return (FALSE);
|
||||
}
|
||||
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog);
|
||||
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers);
|
||||
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc);
|
||||
oa = &cmsg->rm_call.cb_cred;
|
||||
IXDR_PUT_ENUM(buf, oa->oa_flavor);
|
||||
IXDR_PUT_INT32(buf, oa->oa_length);
|
||||
if (oa->oa_length) {
|
||||
memmove(buf, oa->oa_base, oa->oa_length);
|
||||
buf += RNDUP(oa->oa_length) / sizeof (int32_t);
|
||||
}
|
||||
oa = &cmsg->rm_call.cb_verf;
|
||||
IXDR_PUT_ENUM(buf, oa->oa_flavor);
|
||||
IXDR_PUT_INT32(buf, oa->oa_length);
|
||||
if (oa->oa_length) {
|
||||
memmove(buf, oa->oa_base, oa->oa_length);
|
||||
/* no real need....
|
||||
buf += RNDUP(oa->oa_length) / sizeof (int32_t);
|
||||
*/
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
if (xdrs->x_op == XDR_DECODE) {
|
||||
buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
|
||||
if (buf != NULL) {
|
||||
cmsg->rm_xid = IXDR_GET_U_INT32(buf);
|
||||
cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
|
||||
if (cmsg->rm_direction != CALL) {
|
||||
return (FALSE);
|
||||
}
|
||||
cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf);
|
||||
if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
|
||||
return (FALSE);
|
||||
}
|
||||
cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf);
|
||||
cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf);
|
||||
cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf);
|
||||
oa = &cmsg->rm_call.cb_cred;
|
||||
oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
|
||||
oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
|
||||
if (oa->oa_length) {
|
||||
if (oa->oa_length > MAX_AUTH_BYTES) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (oa->oa_base == NULL) {
|
||||
oa->oa_base = (caddr_t)
|
||||
mem_alloc(oa->oa_length);
|
||||
if (oa->oa_base == NULL)
|
||||
return (FALSE);
|
||||
}
|
||||
buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
|
||||
if (buf == NULL) {
|
||||
if (xdr_opaque(xdrs, oa->oa_base,
|
||||
oa->oa_length) == FALSE) {
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
memmove(oa->oa_base, buf,
|
||||
oa->oa_length);
|
||||
/* no real need....
|
||||
buf += RNDUP(oa->oa_length) /
|
||||
sizeof (int32_t);
|
||||
*/
|
||||
}
|
||||
}
|
||||
oa = &cmsg->rm_call.cb_verf;
|
||||
buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
|
||||
if (buf == NULL) {
|
||||
if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
|
||||
xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
|
||||
oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
|
||||
}
|
||||
if (oa->oa_length) {
|
||||
if (oa->oa_length > MAX_AUTH_BYTES) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (oa->oa_base == NULL) {
|
||||
oa->oa_base = (caddr_t)
|
||||
mem_alloc(oa->oa_length);
|
||||
if (oa->oa_base == NULL)
|
||||
return (FALSE);
|
||||
}
|
||||
buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
|
||||
if (buf == NULL) {
|
||||
if (xdr_opaque(xdrs, oa->oa_base,
|
||||
oa->oa_length) == FALSE) {
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
memmove(oa->oa_base, buf,
|
||||
oa->oa_length);
|
||||
/* no real need...
|
||||
buf += RNDUP(oa->oa_length) /
|
||||
sizeof (int32_t);
|
||||
*/
|
||||
}
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
prm_direction = &cmsg->rm_direction;
|
||||
if (
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
|
||||
xdr_enum(xdrs, (enum_t *) prm_direction) &&
|
||||
(cmsg->rm_direction == CALL) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
|
||||
(cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
|
||||
xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
|
||||
return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
|
||||
return (FALSE);
|
||||
}
|
94
freebsd/lib/libc/rpc/rpc_com.h
Normal file
94
freebsd/lib/libc/rpc/rpc_com.h
Normal file
@ -0,0 +1,94 @@
|
||||
/* $NetBSD: rpc_com.h,v 1.3 2000/12/10 04:10:08 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* rpc_com.h, Common definitions for both the server and client side.
|
||||
* All for the topmost layer of rpc
|
||||
*
|
||||
* In Sun's tirpc distribution, this was installed as <rpc/rpc_com.h>,
|
||||
* but as it contains only non-exported interfaces, it was moved here.
|
||||
*/
|
||||
|
||||
#ifndef _RPC_RPCCOM_H
|
||||
#define _RPC_RPCCOM_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/* #pragma ident "@(#)rpc_com.h 1.11 93/07/05 SMI" */
|
||||
|
||||
/*
|
||||
* The max size of the transport, if the size cannot be determined
|
||||
* by other means.
|
||||
*/
|
||||
#define RPC_MAXDATASIZE 9000
|
||||
#define RPC_MAXADDRSIZE 1024
|
||||
|
||||
#define __RPC_GETXID(now) ((u_int32_t)getpid() ^ (u_int32_t)(now)->tv_sec ^ \
|
||||
(u_int32_t)(now)->tv_usec)
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern u_int __rpc_get_a_size(int);
|
||||
extern int __rpc_dtbsize(void);
|
||||
extern struct netconfig * __rpcgettp(int);
|
||||
extern int __rpc_get_default_domain(char **);
|
||||
|
||||
char *__rpc_taddr2uaddr_af(int, const struct netbuf *);
|
||||
struct netbuf *__rpc_uaddr2taddr_af(int, const char *);
|
||||
int __rpc_fixup_addr(struct netbuf *, const struct netbuf *);
|
||||
int __rpc_sockinfo2netid(struct __rpc_sockinfo *, const char **);
|
||||
int __rpc_seman2socktype(int);
|
||||
int __rpc_socktype2seman(int);
|
||||
void *rpc_nullproc(CLIENT *);
|
||||
int __rpc_sockisbound(int);
|
||||
|
||||
struct netbuf *__rpcb_findaddr_timed(rpcprog_t, rpcvers_t,
|
||||
const struct netconfig *, const char *host, CLIENT **clpp,
|
||||
struct timeval *tp);
|
||||
|
||||
bool_t __rpc_control(int,void *);
|
||||
|
||||
char *_get_next_token(char *, int);
|
||||
|
||||
bool_t __svc_clean_idle(fd_set *, int, bool_t);
|
||||
bool_t __xdrrec_setnonblock(XDR *, int);
|
||||
bool_t __xdrrec_getrec(XDR *, enum xprt_stat *, bool_t);
|
||||
void __xprt_unregister_unlocked(SVCXPRT *);
|
||||
|
||||
SVCXPRT **__svc_xports;
|
||||
int __svc_maxrec;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _RPC_RPCCOM_H */
|
49
freebsd/lib/libc/rpc/rpc_commondata.c
Normal file
49
freebsd/lib/libc/rpc/rpc_commondata.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpc_commondata.c,v 1.7 2000/06/02 23:11:13 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid = "@(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rpc/rpc.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/*
|
||||
* This file should only contain common data (global data) that is exported
|
||||
* by public interfaces
|
||||
*/
|
||||
struct opaque_auth _null_auth;
|
||||
fd_set svc_fdset;
|
||||
int svc_maxfd = -1;
|
68
freebsd/lib/libc/rpc/rpc_dtablesize.c
Normal file
68
freebsd/lib/libc/rpc/rpc_dtablesize.c
Normal file
@ -0,0 +1,68 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpc_dtablesize.c,v 1.14 1998/11/15 17:32:43 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";
|
||||
static char *sccsid = "@(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
int _rpc_dtablesize(void); /* XXX */
|
||||
|
||||
/*
|
||||
* Cache the result of getdtablesize(), so we don't have to do an
|
||||
* expensive system call every time.
|
||||
*/
|
||||
/*
|
||||
* XXX In FreeBSD 2.x, you can have the maximum number of open file
|
||||
* descriptors be greater than FD_SETSIZE (which us 256 by default).
|
||||
*
|
||||
* Since old programs tend to use this call to determine the first arg
|
||||
* for _select(), having this return > FD_SETSIZE is a Bad Idea(TM)!
|
||||
*/
|
||||
int
|
||||
_rpc_dtablesize(void)
|
||||
{
|
||||
static int size;
|
||||
|
||||
if (size == 0) {
|
||||
size = getdtablesize();
|
||||
if (size > FD_SETSIZE)
|
||||
size = FD_SETSIZE;
|
||||
}
|
||||
return (size);
|
||||
}
|
848
freebsd/lib/libc/rpc/rpc_generic.c
Normal file
848
freebsd/lib/libc/rpc/rpc_generic.c
Normal file
@ -0,0 +1,848 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpc_generic.c,v 1.4 2000/09/28 09:07:04 kleink Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
/* #pragma ident "@(#)rpc_generic.c 1.17 94/04/24 SMI" */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* rpc_generic.c, Miscl routines for RPC.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/un.h>
|
||||
#include <rtems/bsd/sys/resource.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include <netconfig.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <rpc/nettype.h>
|
||||
#include "un-namespace.h"
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
struct handle {
|
||||
NCONF_HANDLE *nhandle;
|
||||
int nflag; /* Whether NETPATH or NETCONFIG */
|
||||
int nettype;
|
||||
};
|
||||
|
||||
static const struct _rpcnettype {
|
||||
const char *name;
|
||||
const int type;
|
||||
} _rpctypelist[] = {
|
||||
{ "netpath", _RPC_NETPATH },
|
||||
{ "visible", _RPC_VISIBLE },
|
||||
{ "circuit_v", _RPC_CIRCUIT_V },
|
||||
{ "datagram_v", _RPC_DATAGRAM_V },
|
||||
{ "circuit_n", _RPC_CIRCUIT_N },
|
||||
{ "datagram_n", _RPC_DATAGRAM_N },
|
||||
{ "tcp", _RPC_TCP },
|
||||
{ "udp", _RPC_UDP },
|
||||
{ 0, _RPC_NONE }
|
||||
};
|
||||
|
||||
struct netid_af {
|
||||
const char *netid;
|
||||
int af;
|
||||
int protocol;
|
||||
};
|
||||
|
||||
static const struct netid_af na_cvt[] = {
|
||||
{ "udp", AF_INET, IPPROTO_UDP },
|
||||
{ "tcp", AF_INET, IPPROTO_TCP },
|
||||
#ifdef INET6
|
||||
{ "udp6", AF_INET6, IPPROTO_UDP },
|
||||
{ "tcp6", AF_INET6, IPPROTO_TCP },
|
||||
#endif
|
||||
{ "local", AF_LOCAL, 0 }
|
||||
};
|
||||
|
||||
#if 0
|
||||
static char *strlocase(char *);
|
||||
#endif
|
||||
static int getnettype(const char *);
|
||||
|
||||
/*
|
||||
* Cache the result of getrlimit(), so we don't have to do an
|
||||
* expensive call every time.
|
||||
*/
|
||||
int
|
||||
__rpc_dtbsize()
|
||||
{
|
||||
static int tbsize;
|
||||
struct rlimit rl;
|
||||
|
||||
if (tbsize) {
|
||||
return (tbsize);
|
||||
}
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
|
||||
return (tbsize = (int)rl.rlim_max);
|
||||
}
|
||||
/*
|
||||
* Something wrong. I'll try to save face by returning a
|
||||
* pessimistic number.
|
||||
*/
|
||||
return (32);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Find the appropriate buffer size
|
||||
*/
|
||||
u_int
|
||||
/*ARGSUSED*/
|
||||
__rpc_get_t_size(af, proto, size)
|
||||
int af, proto;
|
||||
int size; /* Size requested */
|
||||
{
|
||||
int maxsize, defsize;
|
||||
|
||||
maxsize = 256 * 1024; /* XXX */
|
||||
switch (proto) {
|
||||
case IPPROTO_TCP:
|
||||
defsize = 64 * 1024; /* XXX */
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
defsize = UDPMSGSIZE;
|
||||
break;
|
||||
default:
|
||||
defsize = RPC_MAXDATASIZE;
|
||||
break;
|
||||
}
|
||||
if (size == 0)
|
||||
return defsize;
|
||||
|
||||
/* Check whether the value is within the upper max limit */
|
||||
return (size > maxsize ? (u_int)maxsize : (u_int)size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the appropriate address buffer size
|
||||
*/
|
||||
u_int
|
||||
__rpc_get_a_size(af)
|
||||
int af;
|
||||
{
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return sizeof (struct sockaddr_in);
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
return sizeof (struct sockaddr_in6);
|
||||
#endif
|
||||
case AF_LOCAL:
|
||||
return sizeof (struct sockaddr_un);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ((u_int)RPC_MAXADDRSIZE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static char *
|
||||
strlocase(p)
|
||||
char *p;
|
||||
{
|
||||
char *t = p;
|
||||
|
||||
for (; *p; p++)
|
||||
if (isupper(*p))
|
||||
*p = tolower(*p);
|
||||
return (t);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Returns the type of the network as defined in <rpc/nettype.h>
|
||||
* If nettype is NULL, it defaults to NETPATH.
|
||||
*/
|
||||
static int
|
||||
getnettype(nettype)
|
||||
const char *nettype;
|
||||
{
|
||||
int i;
|
||||
|
||||
if ((nettype == NULL) || (nettype[0] == 0)) {
|
||||
return (_RPC_NETPATH); /* Default */
|
||||
}
|
||||
|
||||
#if 0
|
||||
nettype = strlocase(nettype);
|
||||
#endif
|
||||
for (i = 0; _rpctypelist[i].name; i++)
|
||||
if (strcasecmp(nettype, _rpctypelist[i].name) == 0) {
|
||||
return (_rpctypelist[i].type);
|
||||
}
|
||||
return (_rpctypelist[i].type);
|
||||
}
|
||||
|
||||
static thread_key_t tcp_key, udp_key;
|
||||
static once_t keys_once = ONCE_INITIALIZER;
|
||||
static int tcp_key_error, udp_key_error;
|
||||
|
||||
static void
|
||||
keys_init(void)
|
||||
{
|
||||
|
||||
tcp_key_error = thr_keycreate(&tcp_key, free);
|
||||
udp_key_error = thr_keycreate(&udp_key, free);
|
||||
}
|
||||
|
||||
/*
|
||||
* For the given nettype (tcp or udp only), return the first structure found.
|
||||
* This should be freed by calling freenetconfigent()
|
||||
*/
|
||||
struct netconfig *
|
||||
__rpc_getconfip(nettype)
|
||||
const char *nettype;
|
||||
{
|
||||
char *netid;
|
||||
char *netid_tcp = (char *) NULL;
|
||||
char *netid_udp = (char *) NULL;
|
||||
static char *netid_tcp_main;
|
||||
static char *netid_udp_main;
|
||||
struct netconfig *dummy;
|
||||
int main_thread;
|
||||
|
||||
if ((main_thread = thr_main())) {
|
||||
netid_udp = netid_udp_main;
|
||||
netid_tcp = netid_tcp_main;
|
||||
} else {
|
||||
if (thr_once(&keys_once, keys_init) != 0 ||
|
||||
tcp_key_error != 0 || udp_key_error != 0)
|
||||
return (NULL);
|
||||
netid_tcp = (char *)thr_getspecific(tcp_key);
|
||||
netid_udp = (char *)thr_getspecific(udp_key);
|
||||
}
|
||||
if (!netid_udp && !netid_tcp) {
|
||||
struct netconfig *nconf;
|
||||
void *confighandle;
|
||||
|
||||
if (!(confighandle = setnetconfig())) {
|
||||
syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
|
||||
return (NULL);
|
||||
}
|
||||
while ((nconf = getnetconfig(confighandle)) != NULL) {
|
||||
if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
|
||||
if (strcmp(nconf->nc_proto, NC_TCP) == 0 &&
|
||||
netid_tcp == NULL) {
|
||||
netid_tcp = strdup(nconf->nc_netid);
|
||||
if (main_thread)
|
||||
netid_tcp_main = netid_tcp;
|
||||
else
|
||||
thr_setspecific(tcp_key,
|
||||
(void *) netid_tcp);
|
||||
} else
|
||||
if (strcmp(nconf->nc_proto, NC_UDP) == 0 &&
|
||||
netid_udp == NULL) {
|
||||
netid_udp = strdup(nconf->nc_netid);
|
||||
if (main_thread)
|
||||
netid_udp_main = netid_udp;
|
||||
else
|
||||
thr_setspecific(udp_key,
|
||||
(void *) netid_udp);
|
||||
}
|
||||
}
|
||||
}
|
||||
endnetconfig(confighandle);
|
||||
}
|
||||
if (strcmp(nettype, "udp") == 0)
|
||||
netid = netid_udp;
|
||||
else if (strcmp(nettype, "tcp") == 0)
|
||||
netid = netid_tcp;
|
||||
else {
|
||||
return (NULL);
|
||||
}
|
||||
if ((netid == NULL) || (netid[0] == 0)) {
|
||||
return (NULL);
|
||||
}
|
||||
dummy = getnetconfigent(netid);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the type of the nettype, which should then be used with
|
||||
* __rpc_getconf().
|
||||
*/
|
||||
void *
|
||||
__rpc_setconf(nettype)
|
||||
const char *nettype;
|
||||
{
|
||||
struct handle *handle;
|
||||
|
||||
handle = (struct handle *) malloc(sizeof (struct handle));
|
||||
if (handle == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
switch (handle->nettype = getnettype(nettype)) {
|
||||
case _RPC_NETPATH:
|
||||
case _RPC_CIRCUIT_N:
|
||||
case _RPC_DATAGRAM_N:
|
||||
if (!(handle->nhandle = setnetpath()))
|
||||
goto failed;
|
||||
handle->nflag = TRUE;
|
||||
break;
|
||||
case _RPC_VISIBLE:
|
||||
case _RPC_CIRCUIT_V:
|
||||
case _RPC_DATAGRAM_V:
|
||||
case _RPC_TCP:
|
||||
case _RPC_UDP:
|
||||
if (!(handle->nhandle = setnetconfig())) {
|
||||
syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
|
||||
goto failed;
|
||||
}
|
||||
handle->nflag = FALSE;
|
||||
break;
|
||||
default:
|
||||
goto failed;
|
||||
}
|
||||
|
||||
return (handle);
|
||||
|
||||
failed:
|
||||
free(handle);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the next netconfig struct for the given "net" type.
|
||||
* __rpc_setconf() should have been called previously.
|
||||
*/
|
||||
struct netconfig *
|
||||
__rpc_getconf(vhandle)
|
||||
void *vhandle;
|
||||
{
|
||||
struct handle *handle;
|
||||
struct netconfig *nconf;
|
||||
|
||||
handle = (struct handle *)vhandle;
|
||||
if (handle == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
for (;;) {
|
||||
if (handle->nflag)
|
||||
nconf = getnetpath(handle->nhandle);
|
||||
else
|
||||
nconf = getnetconfig(handle->nhandle);
|
||||
if (nconf == NULL)
|
||||
break;
|
||||
if ((nconf->nc_semantics != NC_TPI_CLTS) &&
|
||||
(nconf->nc_semantics != NC_TPI_COTS) &&
|
||||
(nconf->nc_semantics != NC_TPI_COTS_ORD))
|
||||
continue;
|
||||
switch (handle->nettype) {
|
||||
case _RPC_VISIBLE:
|
||||
if (!(nconf->nc_flag & NC_VISIBLE))
|
||||
continue;
|
||||
/* FALLTHROUGH */
|
||||
case _RPC_NETPATH: /* Be happy */
|
||||
break;
|
||||
case _RPC_CIRCUIT_V:
|
||||
if (!(nconf->nc_flag & NC_VISIBLE))
|
||||
continue;
|
||||
/* FALLTHROUGH */
|
||||
case _RPC_CIRCUIT_N:
|
||||
if ((nconf->nc_semantics != NC_TPI_COTS) &&
|
||||
(nconf->nc_semantics != NC_TPI_COTS_ORD))
|
||||
continue;
|
||||
break;
|
||||
case _RPC_DATAGRAM_V:
|
||||
if (!(nconf->nc_flag & NC_VISIBLE))
|
||||
continue;
|
||||
/* FALLTHROUGH */
|
||||
case _RPC_DATAGRAM_N:
|
||||
if (nconf->nc_semantics != NC_TPI_CLTS)
|
||||
continue;
|
||||
break;
|
||||
case _RPC_TCP:
|
||||
if (((nconf->nc_semantics != NC_TPI_COTS) &&
|
||||
(nconf->nc_semantics != NC_TPI_COTS_ORD)) ||
|
||||
(strcmp(nconf->nc_protofmly, NC_INET)
|
||||
#ifdef INET6
|
||||
&& strcmp(nconf->nc_protofmly, NC_INET6))
|
||||
#else
|
||||
)
|
||||
#endif
|
||||
||
|
||||
strcmp(nconf->nc_proto, NC_TCP))
|
||||
continue;
|
||||
break;
|
||||
case _RPC_UDP:
|
||||
if ((nconf->nc_semantics != NC_TPI_CLTS) ||
|
||||
(strcmp(nconf->nc_protofmly, NC_INET)
|
||||
#ifdef INET6
|
||||
&& strcmp(nconf->nc_protofmly, NC_INET6))
|
||||
#else
|
||||
)
|
||||
#endif
|
||||
||
|
||||
strcmp(nconf->nc_proto, NC_UDP))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (nconf);
|
||||
}
|
||||
|
||||
void
|
||||
__rpc_endconf(vhandle)
|
||||
void * vhandle;
|
||||
{
|
||||
struct handle *handle;
|
||||
|
||||
handle = (struct handle *) vhandle;
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
if (handle->nflag) {
|
||||
endnetpath(handle->nhandle);
|
||||
} else {
|
||||
endnetconfig(handle->nhandle);
|
||||
}
|
||||
free(handle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Used to ping the NULL procedure for clnt handle.
|
||||
* Returns NULL if fails, else a non-NULL pointer.
|
||||
*/
|
||||
void *
|
||||
rpc_nullproc(clnt)
|
||||
CLIENT *clnt;
|
||||
{
|
||||
struct timeval TIMEOUT = {25, 0};
|
||||
|
||||
if (clnt_call(clnt, NULLPROC, (xdrproc_t) xdr_void, NULL,
|
||||
(xdrproc_t) xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
|
||||
return (NULL);
|
||||
}
|
||||
return ((void *) clnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try all possible transports until
|
||||
* one succeeds in finding the netconf for the given fd.
|
||||
*/
|
||||
struct netconfig *
|
||||
__rpcgettp(fd)
|
||||
int fd;
|
||||
{
|
||||
const char *netid;
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
if (!__rpc_fd2sockinfo(fd, &si))
|
||||
return NULL;
|
||||
|
||||
if (!__rpc_sockinfo2netid(&si, &netid))
|
||||
return NULL;
|
||||
|
||||
/*LINTED const castaway*/
|
||||
return getnetconfigent((char *)netid);
|
||||
}
|
||||
|
||||
int
|
||||
__rpc_fd2sockinfo(int fd, struct __rpc_sockinfo *sip)
|
||||
{
|
||||
socklen_t len;
|
||||
int type, proto;
|
||||
struct sockaddr_storage ss;
|
||||
|
||||
len = sizeof ss;
|
||||
if (_getsockname(fd, (struct sockaddr *)(void *)&ss, &len) < 0)
|
||||
return 0;
|
||||
sip->si_alen = len;
|
||||
|
||||
len = sizeof type;
|
||||
if (_getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &len) < 0)
|
||||
return 0;
|
||||
|
||||
/* XXX */
|
||||
if (ss.ss_family != AF_LOCAL) {
|
||||
if (type == SOCK_STREAM)
|
||||
proto = IPPROTO_TCP;
|
||||
else if (type == SOCK_DGRAM)
|
||||
proto = IPPROTO_UDP;
|
||||
else
|
||||
return 0;
|
||||
} else
|
||||
proto = 0;
|
||||
|
||||
sip->si_af = ss.ss_family;
|
||||
sip->si_proto = proto;
|
||||
sip->si_socktype = type;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Linear search, but the number of entries is small.
|
||||
*/
|
||||
int
|
||||
__rpc_nconf2sockinfo(const struct netconfig *nconf, struct __rpc_sockinfo *sip)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (sizeof na_cvt) / (sizeof (struct netid_af)); i++)
|
||||
if (strcmp(na_cvt[i].netid, nconf->nc_netid) == 0 || (
|
||||
strcmp(nconf->nc_netid, "unix") == 0 &&
|
||||
strcmp(na_cvt[i].netid, "local") == 0)) {
|
||||
sip->si_af = na_cvt[i].af;
|
||||
sip->si_proto = na_cvt[i].protocol;
|
||||
sip->si_socktype =
|
||||
__rpc_seman2socktype((int)nconf->nc_semantics);
|
||||
if (sip->si_socktype == -1)
|
||||
return 0;
|
||||
sip->si_alen = __rpc_get_a_size(sip->si_af);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
__rpc_nconf2fd(const struct netconfig *nconf)
|
||||
{
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
if (!__rpc_nconf2sockinfo(nconf, &si))
|
||||
return 0;
|
||||
|
||||
return _socket(si.si_af, si.si_socktype, si.si_proto);
|
||||
}
|
||||
|
||||
int
|
||||
__rpc_sockinfo2netid(struct __rpc_sockinfo *sip, const char **netid)
|
||||
{
|
||||
int i;
|
||||
struct netconfig *nconf;
|
||||
|
||||
nconf = getnetconfigent("local");
|
||||
|
||||
for (i = 0; i < (sizeof na_cvt) / (sizeof (struct netid_af)); i++) {
|
||||
if (na_cvt[i].af == sip->si_af &&
|
||||
na_cvt[i].protocol == sip->si_proto) {
|
||||
if (strcmp(na_cvt[i].netid, "local") == 0 && nconf == NULL) {
|
||||
if (netid)
|
||||
*netid = "unix";
|
||||
} else {
|
||||
if (netid)
|
||||
*netid = na_cvt[i].netid;
|
||||
}
|
||||
if (nconf != NULL)
|
||||
freenetconfigent(nconf);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (nconf != NULL)
|
||||
freenetconfigent(nconf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
taddr2uaddr(const struct netconfig *nconf, const struct netbuf *nbuf)
|
||||
{
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
if (!__rpc_nconf2sockinfo(nconf, &si))
|
||||
return NULL;
|
||||
return __rpc_taddr2uaddr_af(si.si_af, nbuf);
|
||||
}
|
||||
|
||||
struct netbuf *
|
||||
uaddr2taddr(const struct netconfig *nconf, const char *uaddr)
|
||||
{
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
if (!__rpc_nconf2sockinfo(nconf, &si))
|
||||
return NULL;
|
||||
return __rpc_uaddr2taddr_af(si.si_af, uaddr);
|
||||
}
|
||||
|
||||
char *
|
||||
__rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf)
|
||||
{
|
||||
char *ret;
|
||||
struct sockaddr_in *sin;
|
||||
struct sockaddr_un *sun;
|
||||
char namebuf[INET_ADDRSTRLEN];
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6 *sin6;
|
||||
char namebuf6[INET6_ADDRSTRLEN];
|
||||
#endif
|
||||
u_int16_t port;
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
sin = nbuf->buf;
|
||||
if (inet_ntop(af, &sin->sin_addr, namebuf, sizeof namebuf)
|
||||
== NULL)
|
||||
return NULL;
|
||||
port = ntohs(sin->sin_port);
|
||||
if (asprintf(&ret, "%s.%u.%u", namebuf, ((u_int32_t)port) >> 8,
|
||||
port & 0xff) < 0)
|
||||
return NULL;
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
sin6 = nbuf->buf;
|
||||
if (inet_ntop(af, &sin6->sin6_addr, namebuf6, sizeof namebuf6)
|
||||
== NULL)
|
||||
return NULL;
|
||||
port = ntohs(sin6->sin6_port);
|
||||
if (asprintf(&ret, "%s.%u.%u", namebuf6, ((u_int32_t)port) >> 8,
|
||||
port & 0xff) < 0)
|
||||
return NULL;
|
||||
break;
|
||||
#endif
|
||||
case AF_LOCAL:
|
||||
sun = nbuf->buf;
|
||||
if (asprintf(&ret, "%.*s", (int)(sun->sun_len -
|
||||
offsetof(struct sockaddr_un, sun_path)),
|
||||
sun->sun_path) < 0)
|
||||
return (NULL);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct netbuf *
|
||||
__rpc_uaddr2taddr_af(int af, const char *uaddr)
|
||||
{
|
||||
struct netbuf *ret = NULL;
|
||||
char *addrstr, *p;
|
||||
unsigned port, portlo, porthi;
|
||||
struct sockaddr_in *sin;
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
struct sockaddr_un *sun;
|
||||
|
||||
port = 0;
|
||||
sin = NULL;
|
||||
addrstr = strdup(uaddr);
|
||||
if (addrstr == NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* AF_LOCAL addresses are expected to be absolute
|
||||
* pathnames, anything else will be AF_INET or AF_INET6.
|
||||
*/
|
||||
if (*addrstr != '/') {
|
||||
p = strrchr(addrstr, '.');
|
||||
if (p == NULL)
|
||||
goto out;
|
||||
portlo = (unsigned)atoi(p + 1);
|
||||
*p = '\0';
|
||||
|
||||
p = strrchr(addrstr, '.');
|
||||
if (p == NULL)
|
||||
goto out;
|
||||
porthi = (unsigned)atoi(p + 1);
|
||||
*p = '\0';
|
||||
port = (porthi << 8) | portlo;
|
||||
}
|
||||
|
||||
ret = (struct netbuf *)malloc(sizeof *ret);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
sin = (struct sockaddr_in *)malloc(sizeof *sin);
|
||||
if (sin == NULL)
|
||||
goto out;
|
||||
memset(sin, 0, sizeof *sin);
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_port = htons(port);
|
||||
if (inet_pton(AF_INET, addrstr, &sin->sin_addr) <= 0) {
|
||||
free(sin);
|
||||
free(ret);
|
||||
ret = NULL;
|
||||
goto out;
|
||||
}
|
||||
sin->sin_len = ret->maxlen = ret->len = sizeof *sin;
|
||||
ret->buf = sin;
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
sin6 = (struct sockaddr_in6 *)malloc(sizeof *sin6);
|
||||
if (sin6 == NULL)
|
||||
goto out;
|
||||
memset(sin6, 0, sizeof *sin6);
|
||||
sin6->sin6_family = AF_INET6;
|
||||
sin6->sin6_port = htons(port);
|
||||
if (inet_pton(AF_INET6, addrstr, &sin6->sin6_addr) <= 0) {
|
||||
free(sin6);
|
||||
free(ret);
|
||||
ret = NULL;
|
||||
goto out;
|
||||
}
|
||||
sin6->sin6_len = ret->maxlen = ret->len = sizeof *sin6;
|
||||
ret->buf = sin6;
|
||||
break;
|
||||
#endif
|
||||
case AF_LOCAL:
|
||||
sun = (struct sockaddr_un *)malloc(sizeof *sun);
|
||||
if (sun == NULL)
|
||||
goto out;
|
||||
memset(sun, 0, sizeof *sun);
|
||||
sun->sun_family = AF_LOCAL;
|
||||
strncpy(sun->sun_path, addrstr, sizeof(sun->sun_path) - 1);
|
||||
ret->len = ret->maxlen = sun->sun_len = SUN_LEN(sun);
|
||||
ret->buf = sun;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
out:
|
||||
free(addrstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
__rpc_seman2socktype(int semantics)
|
||||
{
|
||||
switch (semantics) {
|
||||
case NC_TPI_CLTS:
|
||||
return SOCK_DGRAM;
|
||||
case NC_TPI_COTS_ORD:
|
||||
return SOCK_STREAM;
|
||||
case NC_TPI_RAW:
|
||||
return SOCK_RAW;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
__rpc_socktype2seman(int socktype)
|
||||
{
|
||||
switch (socktype) {
|
||||
case SOCK_DGRAM:
|
||||
return NC_TPI_CLTS;
|
||||
case SOCK_STREAM:
|
||||
return NC_TPI_COTS_ORD;
|
||||
case SOCK_RAW:
|
||||
return NC_TPI_RAW;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXXX - IPv6 scope IDs can't be handled in universal addresses.
|
||||
* Here, we compare the original server address to that of the RPC
|
||||
* service we just received back from a call to rpcbind on the remote
|
||||
* machine. If they are both "link local" or "site local", copy
|
||||
* the scope id of the server address over to the service address.
|
||||
*/
|
||||
int
|
||||
__rpc_fixup_addr(struct netbuf *new, const struct netbuf *svc)
|
||||
{
|
||||
#ifdef INET6
|
||||
struct sockaddr *sa_new, *sa_svc;
|
||||
struct sockaddr_in6 *sin6_new, *sin6_svc;
|
||||
|
||||
sa_svc = (struct sockaddr *)svc->buf;
|
||||
sa_new = (struct sockaddr *)new->buf;
|
||||
|
||||
if (sa_new->sa_family == sa_svc->sa_family &&
|
||||
sa_new->sa_family == AF_INET6) {
|
||||
sin6_new = (struct sockaddr_in6 *)new->buf;
|
||||
sin6_svc = (struct sockaddr_in6 *)svc->buf;
|
||||
|
||||
if ((IN6_IS_ADDR_LINKLOCAL(&sin6_new->sin6_addr) &&
|
||||
IN6_IS_ADDR_LINKLOCAL(&sin6_svc->sin6_addr)) ||
|
||||
(IN6_IS_ADDR_SITELOCAL(&sin6_new->sin6_addr) &&
|
||||
IN6_IS_ADDR_SITELOCAL(&sin6_svc->sin6_addr))) {
|
||||
sin6_new->sin6_scope_id = sin6_svc->sin6_scope_id;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
__rpc_sockisbound(int fd)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen;
|
||||
|
||||
slen = sizeof (struct sockaddr_storage);
|
||||
if (_getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) < 0)
|
||||
return 0;
|
||||
|
||||
switch (ss.ss_family) {
|
||||
case AF_INET:
|
||||
return (((struct sockaddr_in *)
|
||||
(void *)&ss)->sin_port != 0);
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
return (((struct sockaddr_in6 *)
|
||||
(void *)&ss)->sin6_port != 0);
|
||||
#endif
|
||||
case AF_LOCAL:
|
||||
/* XXX check this */
|
||||
return (((struct sockaddr_un *)
|
||||
(void *)&ss)->sun_path[0] != '\0');
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
373
freebsd/lib/libc/rpc/rpc_prot.c
Normal file
373
freebsd/lib/libc/rpc/rpc_prot.c
Normal file
@ -0,0 +1,373 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpc_prot.c,v 1.16 2000/06/02 23:11:13 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* rpc_prot.c
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
* This set of routines implements the rpc message definition,
|
||||
* its serializer and some common rpc utility routines.
|
||||
* The routines are meant for various implementations of rpc -
|
||||
* they are NOT for the rpc client or rpc service implementations!
|
||||
* Because authentication stuff is easy and is part of rpc, the opaque
|
||||
* routines are also in this program.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
static void accepted(enum accept_stat, struct rpc_err *);
|
||||
static void rejected(enum reject_stat, struct rpc_err *);
|
||||
|
||||
/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
|
||||
|
||||
extern struct opaque_auth _null_auth;
|
||||
|
||||
/*
|
||||
* XDR an opaque authentication struct
|
||||
* (see auth.h)
|
||||
*/
|
||||
bool_t
|
||||
xdr_opaque_auth(xdrs, ap)
|
||||
XDR *xdrs;
|
||||
struct opaque_auth *ap;
|
||||
{
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(ap != NULL);
|
||||
|
||||
if (xdr_enum(xdrs, &(ap->oa_flavor)))
|
||||
return (xdr_bytes(xdrs, &ap->oa_base,
|
||||
&ap->oa_length, MAX_AUTH_BYTES));
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR a DES block
|
||||
*/
|
||||
bool_t
|
||||
xdr_des_block(xdrs, blkp)
|
||||
XDR *xdrs;
|
||||
des_block *blkp;
|
||||
{
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(blkp != NULL);
|
||||
|
||||
return (xdr_opaque(xdrs, (caddr_t)(void *)blkp, sizeof(des_block)));
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* XDR the MSG_ACCEPTED part of a reply message union
|
||||
*/
|
||||
bool_t
|
||||
xdr_accepted_reply(xdrs, ar)
|
||||
XDR *xdrs;
|
||||
struct accepted_reply *ar;
|
||||
{
|
||||
enum accept_stat *par_stat;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(ar != NULL);
|
||||
|
||||
par_stat = &ar->ar_stat;
|
||||
|
||||
/* personalized union, rather than calling xdr_union */
|
||||
if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
|
||||
return (FALSE);
|
||||
if (! xdr_enum(xdrs, (enum_t *) par_stat))
|
||||
return (FALSE);
|
||||
switch (ar->ar_stat) {
|
||||
|
||||
case SUCCESS:
|
||||
return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
|
||||
|
||||
case PROG_MISMATCH:
|
||||
if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low)))
|
||||
return (FALSE);
|
||||
return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high)));
|
||||
|
||||
case GARBAGE_ARGS:
|
||||
case SYSTEM_ERR:
|
||||
case PROC_UNAVAIL:
|
||||
case PROG_UNAVAIL:
|
||||
break;
|
||||
}
|
||||
return (TRUE); /* TRUE => open ended set of problems */
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR the MSG_DENIED part of a reply message union
|
||||
*/
|
||||
bool_t
|
||||
xdr_rejected_reply(xdrs, rr)
|
||||
XDR *xdrs;
|
||||
struct rejected_reply *rr;
|
||||
{
|
||||
enum reject_stat *prj_stat;
|
||||
enum auth_stat *prj_why;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(rr != NULL);
|
||||
|
||||
prj_stat = &rr->rj_stat;
|
||||
|
||||
/* personalized union, rather than calling xdr_union */
|
||||
if (! xdr_enum(xdrs, (enum_t *) prj_stat))
|
||||
return (FALSE);
|
||||
switch (rr->rj_stat) {
|
||||
|
||||
case RPC_MISMATCH:
|
||||
if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low)))
|
||||
return (FALSE);
|
||||
return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high)));
|
||||
|
||||
case AUTH_ERROR:
|
||||
prj_why = &rr->rj_why;
|
||||
return (xdr_enum(xdrs, (enum_t *) prj_why));
|
||||
}
|
||||
/* NOTREACHED */
|
||||
assert(0);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static const struct xdr_discrim reply_dscrm[3] = {
|
||||
{ (int)MSG_ACCEPTED, (xdrproc_t)xdr_accepted_reply },
|
||||
{ (int)MSG_DENIED, (xdrproc_t)xdr_rejected_reply },
|
||||
{ __dontcare__, NULL_xdrproc_t } };
|
||||
|
||||
/*
|
||||
* XDR a reply message
|
||||
*/
|
||||
bool_t
|
||||
xdr_replymsg(xdrs, rmsg)
|
||||
XDR *xdrs;
|
||||
struct rpc_msg *rmsg;
|
||||
{
|
||||
enum msg_type *prm_direction;
|
||||
enum reply_stat *prp_stat;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(rmsg != NULL);
|
||||
|
||||
prm_direction = &rmsg->rm_direction;
|
||||
prp_stat = &rmsg->rm_reply.rp_stat;
|
||||
|
||||
if (
|
||||
xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
|
||||
xdr_enum(xdrs, (enum_t *) prm_direction) &&
|
||||
(rmsg->rm_direction == REPLY) )
|
||||
return (xdr_union(xdrs, (enum_t *) prp_stat,
|
||||
(caddr_t)(void *)&(rmsg->rm_reply.ru), reply_dscrm,
|
||||
NULL_xdrproc_t));
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Serializes the "static part" of a call message header.
|
||||
* The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
|
||||
* The rm_xid is not really static, but the user can easily munge on the fly.
|
||||
*/
|
||||
bool_t
|
||||
xdr_callhdr(xdrs, cmsg)
|
||||
XDR *xdrs;
|
||||
struct rpc_msg *cmsg;
|
||||
{
|
||||
enum msg_type *prm_direction;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(cmsg != NULL);
|
||||
|
||||
prm_direction = &cmsg->rm_direction;
|
||||
|
||||
cmsg->rm_direction = CALL;
|
||||
cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
|
||||
if (
|
||||
(xdrs->x_op == XDR_ENCODE) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
|
||||
xdr_enum(xdrs, (enum_t *) prm_direction) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
|
||||
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
|
||||
return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/* ************************** Client utility routine ************* */
|
||||
|
||||
static void
|
||||
accepted(acpt_stat, error)
|
||||
enum accept_stat acpt_stat;
|
||||
struct rpc_err *error;
|
||||
{
|
||||
|
||||
assert(error != NULL);
|
||||
|
||||
switch (acpt_stat) {
|
||||
|
||||
case PROG_UNAVAIL:
|
||||
error->re_status = RPC_PROGUNAVAIL;
|
||||
return;
|
||||
|
||||
case PROG_MISMATCH:
|
||||
error->re_status = RPC_PROGVERSMISMATCH;
|
||||
return;
|
||||
|
||||
case PROC_UNAVAIL:
|
||||
error->re_status = RPC_PROCUNAVAIL;
|
||||
return;
|
||||
|
||||
case GARBAGE_ARGS:
|
||||
error->re_status = RPC_CANTDECODEARGS;
|
||||
return;
|
||||
|
||||
case SYSTEM_ERR:
|
||||
error->re_status = RPC_SYSTEMERROR;
|
||||
return;
|
||||
|
||||
case SUCCESS:
|
||||
error->re_status = RPC_SUCCESS;
|
||||
return;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
/* something's wrong, but we don't know what ... */
|
||||
error->re_status = RPC_FAILED;
|
||||
error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
|
||||
error->re_lb.s2 = (int32_t)acpt_stat;
|
||||
}
|
||||
|
||||
static void
|
||||
rejected(rjct_stat, error)
|
||||
enum reject_stat rjct_stat;
|
||||
struct rpc_err *error;
|
||||
{
|
||||
|
||||
assert(error != NULL);
|
||||
|
||||
switch (rjct_stat) {
|
||||
case RPC_MISMATCH:
|
||||
error->re_status = RPC_VERSMISMATCH;
|
||||
return;
|
||||
|
||||
case AUTH_ERROR:
|
||||
error->re_status = RPC_AUTHERROR;
|
||||
return;
|
||||
}
|
||||
/* something's wrong, but we don't know what ... */
|
||||
/* NOTREACHED */
|
||||
error->re_status = RPC_FAILED;
|
||||
error->re_lb.s1 = (int32_t)MSG_DENIED;
|
||||
error->re_lb.s2 = (int32_t)rjct_stat;
|
||||
}
|
||||
|
||||
/*
|
||||
* given a reply message, fills in the error
|
||||
*/
|
||||
void
|
||||
_seterr_reply(msg, error)
|
||||
struct rpc_msg *msg;
|
||||
struct rpc_err *error;
|
||||
{
|
||||
|
||||
assert(msg != NULL);
|
||||
assert(error != NULL);
|
||||
|
||||
/* optimized for normal, SUCCESSful case */
|
||||
switch (msg->rm_reply.rp_stat) {
|
||||
|
||||
case MSG_ACCEPTED:
|
||||
if (msg->acpted_rply.ar_stat == SUCCESS) {
|
||||
error->re_status = RPC_SUCCESS;
|
||||
return;
|
||||
}
|
||||
accepted(msg->acpted_rply.ar_stat, error);
|
||||
break;
|
||||
|
||||
case MSG_DENIED:
|
||||
rejected(msg->rjcted_rply.rj_stat, error);
|
||||
break;
|
||||
|
||||
default:
|
||||
error->re_status = RPC_FAILED;
|
||||
error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
|
||||
break;
|
||||
}
|
||||
switch (error->re_status) {
|
||||
|
||||
case RPC_VERSMISMATCH:
|
||||
error->re_vers.low = msg->rjcted_rply.rj_vers.low;
|
||||
error->re_vers.high = msg->rjcted_rply.rj_vers.high;
|
||||
break;
|
||||
|
||||
case RPC_AUTHERROR:
|
||||
error->re_why = msg->rjcted_rply.rj_why;
|
||||
break;
|
||||
|
||||
case RPC_PROGVERSMISMATCH:
|
||||
error->re_vers.low = msg->acpted_rply.ar_vers.low;
|
||||
error->re_vers.high = msg->acpted_rply.ar_vers.high;
|
||||
break;
|
||||
|
||||
case RPC_FAILED:
|
||||
case RPC_SUCCESS:
|
||||
case RPC_PROGNOTREGISTERED:
|
||||
case RPC_PMAPFAILURE:
|
||||
case RPC_UNKNOWNPROTO:
|
||||
case RPC_UNKNOWNHOST:
|
||||
case RPC_SYSTEMERROR:
|
||||
case RPC_CANTDECODEARGS:
|
||||
case RPC_PROCUNAVAIL:
|
||||
case RPC_PROGUNAVAIL:
|
||||
case RPC_TIMEDOUT:
|
||||
case RPC_CANTRECV:
|
||||
case RPC_CANTSEND:
|
||||
case RPC_CANTDECODERES:
|
||||
case RPC_CANTENCODEARGS:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
583
freebsd/lib/libc/rpc/rpc_soc.c
Normal file
583
freebsd/lib/libc/rpc/rpc_soc.c
Normal file
@ -0,0 +1,583 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpc_soc.c,v 1.6 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* #ident "@(#)rpc_soc.c 1.17 94/04/24 SMI" */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
* In addition, portions of such source code were derived from Berkeley
|
||||
* 4.3 BSD under license from the Regents of the University of
|
||||
* California.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)rpc_soc.c 1.41 89/05/02 Copyr 1988 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#ifdef PORTMAP
|
||||
/*
|
||||
* rpc_soc.c
|
||||
*
|
||||
* The backward compatibility routines for the earlier implementation
|
||||
* of RPC, where the only transports supported were tcp/ip and udp/ip.
|
||||
* Based on berkeley socket abstraction, now implemented on the top
|
||||
* of TLI/Streams
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/nettype.h>
|
||||
#include <syslog.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
static CLIENT *clnt_com_create(struct sockaddr_in *, rpcprog_t, rpcvers_t,
|
||||
int *, u_int, u_int, char *);
|
||||
static SVCXPRT *svc_com_create(int, u_int, u_int, char *);
|
||||
static bool_t rpc_wrap_bcast(char *, struct netbuf *, struct netconfig *);
|
||||
|
||||
/* XXX */
|
||||
#define IN4_LOCALHOST_STRING "127.0.0.1"
|
||||
#define IN6_LOCALHOST_STRING "::1"
|
||||
|
||||
/*
|
||||
* A common clnt create routine
|
||||
*/
|
||||
static CLIENT *
|
||||
clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, tp)
|
||||
struct sockaddr_in *raddr;
|
||||
rpcprog_t prog;
|
||||
rpcvers_t vers;
|
||||
int *sockp;
|
||||
u_int sendsz;
|
||||
u_int recvsz;
|
||||
char *tp;
|
||||
{
|
||||
CLIENT *cl;
|
||||
int madefd = FALSE;
|
||||
int fd = *sockp;
|
||||
struct netconfig *nconf;
|
||||
struct netbuf bindaddr;
|
||||
|
||||
mutex_lock(&rpcsoc_lock);
|
||||
if ((nconf = __rpc_getconfip(tp)) == NULL) {
|
||||
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
||||
mutex_unlock(&rpcsoc_lock);
|
||||
return (NULL);
|
||||
}
|
||||
if (fd == RPC_ANYSOCK) {
|
||||
fd = __rpc_nconf2fd(nconf);
|
||||
if (fd == -1)
|
||||
goto syserror;
|
||||
madefd = TRUE;
|
||||
}
|
||||
|
||||
if (raddr->sin_port == 0) {
|
||||
u_int proto;
|
||||
u_short sport;
|
||||
|
||||
mutex_unlock(&rpcsoc_lock); /* pmap_getport is recursive */
|
||||
proto = strcmp(tp, "udp") == 0 ? IPPROTO_UDP : IPPROTO_TCP;
|
||||
sport = pmap_getport(raddr, (u_long)prog, (u_long)vers,
|
||||
proto);
|
||||
if (sport == 0) {
|
||||
goto err;
|
||||
}
|
||||
raddr->sin_port = htons(sport);
|
||||
mutex_lock(&rpcsoc_lock); /* pmap_getport is recursive */
|
||||
}
|
||||
|
||||
/* Transform sockaddr_in to netbuf */
|
||||
bindaddr.maxlen = bindaddr.len = sizeof (struct sockaddr_in);
|
||||
bindaddr.buf = raddr;
|
||||
|
||||
bindresvport(fd, NULL);
|
||||
cl = clnt_tli_create(fd, nconf, &bindaddr, prog, vers,
|
||||
sendsz, recvsz);
|
||||
if (cl) {
|
||||
if (madefd == TRUE) {
|
||||
/*
|
||||
* The fd should be closed while destroying the handle.
|
||||
*/
|
||||
(void) CLNT_CONTROL(cl, CLSET_FD_CLOSE, NULL);
|
||||
*sockp = fd;
|
||||
}
|
||||
(void) freenetconfigent(nconf);
|
||||
mutex_unlock(&rpcsoc_lock);
|
||||
return (cl);
|
||||
}
|
||||
goto err;
|
||||
|
||||
syserror:
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
|
||||
err: if (madefd == TRUE)
|
||||
(void)_close(fd);
|
||||
(void) freenetconfigent(nconf);
|
||||
mutex_unlock(&rpcsoc_lock);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
CLIENT *
|
||||
clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz)
|
||||
struct sockaddr_in *raddr;
|
||||
u_long prog;
|
||||
u_long vers;
|
||||
struct timeval wait;
|
||||
int *sockp;
|
||||
u_int sendsz;
|
||||
u_int recvsz;
|
||||
{
|
||||
CLIENT *cl;
|
||||
|
||||
cl = clnt_com_create(raddr, (rpcprog_t)prog, (rpcvers_t)vers, sockp,
|
||||
sendsz, recvsz, "udp");
|
||||
if (cl == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
(void) CLNT_CONTROL(cl, CLSET_RETRY_TIMEOUT, &wait);
|
||||
return (cl);
|
||||
}
|
||||
|
||||
CLIENT *
|
||||
clntudp_create(raddr, program, version, wait, sockp)
|
||||
struct sockaddr_in *raddr;
|
||||
u_long program;
|
||||
u_long version;
|
||||
struct timeval wait;
|
||||
int *sockp;
|
||||
{
|
||||
|
||||
return clntudp_bufcreate(raddr, program, version, wait, sockp,
|
||||
UDPMSGSIZE, UDPMSGSIZE);
|
||||
}
|
||||
|
||||
CLIENT *
|
||||
clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
|
||||
struct sockaddr_in *raddr;
|
||||
u_long prog;
|
||||
u_long vers;
|
||||
int *sockp;
|
||||
u_int sendsz;
|
||||
u_int recvsz;
|
||||
{
|
||||
|
||||
return clnt_com_create(raddr, (rpcprog_t)prog, (rpcvers_t)vers, sockp,
|
||||
sendsz, recvsz, "tcp");
|
||||
}
|
||||
|
||||
CLIENT *
|
||||
clntraw_create(prog, vers)
|
||||
u_long prog;
|
||||
u_long vers;
|
||||
{
|
||||
|
||||
return clnt_raw_create((rpcprog_t)prog, (rpcvers_t)vers);
|
||||
}
|
||||
|
||||
/*
|
||||
* A common server create routine
|
||||
*/
|
||||
static SVCXPRT *
|
||||
svc_com_create(fd, sendsize, recvsize, netid)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
char *netid;
|
||||
{
|
||||
struct netconfig *nconf;
|
||||
SVCXPRT *svc;
|
||||
int madefd = FALSE;
|
||||
int port;
|
||||
struct sockaddr_in sin;
|
||||
|
||||
if ((nconf = __rpc_getconfip(netid)) == NULL) {
|
||||
(void) syslog(LOG_ERR, "Could not get %s transport", netid);
|
||||
return (NULL);
|
||||
}
|
||||
if (fd == RPC_ANYSOCK) {
|
||||
fd = __rpc_nconf2fd(nconf);
|
||||
if (fd == -1) {
|
||||
(void) freenetconfigent(nconf);
|
||||
(void) syslog(LOG_ERR,
|
||||
"svc%s_create: could not open connection", netid);
|
||||
return (NULL);
|
||||
}
|
||||
madefd = TRUE;
|
||||
}
|
||||
|
||||
memset(&sin, 0, sizeof sin);
|
||||
sin.sin_family = AF_INET;
|
||||
bindresvport(fd, &sin);
|
||||
_listen(fd, SOMAXCONN);
|
||||
svc = svc_tli_create(fd, nconf, NULL, sendsize, recvsize);
|
||||
(void) freenetconfigent(nconf);
|
||||
if (svc == NULL) {
|
||||
if (madefd)
|
||||
(void)_close(fd);
|
||||
return (NULL);
|
||||
}
|
||||
port = (((struct sockaddr_in *)svc->xp_ltaddr.buf)->sin_port);
|
||||
svc->xp_port = ntohs(port);
|
||||
return (svc);
|
||||
}
|
||||
|
||||
SVCXPRT *
|
||||
svctcp_create(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
|
||||
return svc_com_create(fd, sendsize, recvsize, "tcp");
|
||||
}
|
||||
|
||||
SVCXPRT *
|
||||
svcudp_bufcreate(fd, sendsz, recvsz)
|
||||
int fd;
|
||||
u_int sendsz, recvsz;
|
||||
{
|
||||
|
||||
return svc_com_create(fd, sendsz, recvsz, "udp");
|
||||
}
|
||||
|
||||
SVCXPRT *
|
||||
svcfd_create(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
|
||||
return svc_fd_create(fd, sendsize, recvsize);
|
||||
}
|
||||
|
||||
|
||||
SVCXPRT *
|
||||
svcudp_create(fd)
|
||||
int fd;
|
||||
{
|
||||
|
||||
return svc_com_create(fd, UDPMSGSIZE, UDPMSGSIZE, "udp");
|
||||
}
|
||||
|
||||
SVCXPRT *
|
||||
svcraw_create()
|
||||
{
|
||||
|
||||
return svc_raw_create();
|
||||
}
|
||||
|
||||
int
|
||||
get_myaddress(addr)
|
||||
struct sockaddr_in *addr;
|
||||
{
|
||||
|
||||
memset((void *) addr, 0, sizeof(*addr));
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = htons(PMAPPORT);
|
||||
addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* For connectionless "udp" transport. Obsoleted by rpc_call().
|
||||
*/
|
||||
int
|
||||
callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
|
||||
const char *host;
|
||||
int prognum, versnum, procnum;
|
||||
xdrproc_t inproc, outproc;
|
||||
void *in, *out;
|
||||
{
|
||||
|
||||
return (int)rpc_call(host, (rpcprog_t)prognum, (rpcvers_t)versnum,
|
||||
(rpcproc_t)procnum, inproc, in, outproc, out, "udp");
|
||||
}
|
||||
|
||||
/*
|
||||
* For connectionless kind of transport. Obsoleted by rpc_reg()
|
||||
*/
|
||||
int
|
||||
registerrpc(prognum, versnum, procnum, progname, inproc, outproc)
|
||||
int prognum, versnum, procnum;
|
||||
char *(*progname)(char [UDPMSGSIZE]);
|
||||
xdrproc_t inproc, outproc;
|
||||
{
|
||||
|
||||
return rpc_reg((rpcprog_t)prognum, (rpcvers_t)versnum,
|
||||
(rpcproc_t)procnum, progname, inproc, outproc, "udp");
|
||||
}
|
||||
|
||||
/*
|
||||
* All the following clnt_broadcast stuff is convulated; it supports
|
||||
* the earlier calling style of the callback function
|
||||
*/
|
||||
static thread_key_t clnt_broadcast_key;
|
||||
static resultproc_t clnt_broadcast_result_main;
|
||||
static once_t clnt_broadcast_once = ONCE_INITIALIZER;
|
||||
|
||||
static void
|
||||
clnt_broadcast_key_init(void)
|
||||
{
|
||||
|
||||
thr_keycreate(&clnt_broadcast_key, free);
|
||||
}
|
||||
|
||||
/*
|
||||
* Need to translate the netbuf address into sockaddr_in address.
|
||||
* Dont care about netid here.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static bool_t
|
||||
rpc_wrap_bcast(resultp, addr, nconf)
|
||||
char *resultp; /* results of the call */
|
||||
struct netbuf *addr; /* address of the guy who responded */
|
||||
struct netconfig *nconf; /* Netconf of the transport */
|
||||
{
|
||||
resultproc_t clnt_broadcast_result;
|
||||
|
||||
if (strcmp(nconf->nc_netid, "udp"))
|
||||
return (FALSE);
|
||||
if (thr_main())
|
||||
clnt_broadcast_result = clnt_broadcast_result_main;
|
||||
else
|
||||
clnt_broadcast_result = (resultproc_t)thr_getspecific(clnt_broadcast_key);
|
||||
return (*clnt_broadcast_result)(resultp,
|
||||
(struct sockaddr_in *)addr->buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Broadcasts on UDP transport. Obsoleted by rpc_broadcast().
|
||||
*/
|
||||
enum clnt_stat
|
||||
clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
|
||||
u_long prog; /* program number */
|
||||
u_long vers; /* version number */
|
||||
u_long proc; /* procedure number */
|
||||
xdrproc_t xargs; /* xdr routine for args */
|
||||
void *argsp; /* pointer to args */
|
||||
xdrproc_t xresults; /* xdr routine for results */
|
||||
void *resultsp; /* pointer to results */
|
||||
resultproc_t eachresult; /* call with each result obtained */
|
||||
{
|
||||
|
||||
if (thr_main())
|
||||
clnt_broadcast_result_main = eachresult;
|
||||
else {
|
||||
thr_once(&clnt_broadcast_once, clnt_broadcast_key_init);
|
||||
thr_setspecific(clnt_broadcast_key, (void *) eachresult);
|
||||
}
|
||||
return rpc_broadcast((rpcprog_t)prog, (rpcvers_t)vers,
|
||||
(rpcproc_t)proc, xargs, argsp, xresults, resultsp,
|
||||
(resultproc_t) rpc_wrap_bcast, "udp");
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the client des authentication object. Obsoleted by
|
||||
* authdes_seccreate().
|
||||
*/
|
||||
AUTH *
|
||||
authdes_create(servername, window, syncaddr, ckey)
|
||||
char *servername; /* network name of server */
|
||||
u_int window; /* time to live */
|
||||
struct sockaddr *syncaddr; /* optional hostaddr to sync with */
|
||||
des_block *ckey; /* optional conversation key to use */
|
||||
{
|
||||
AUTH *dummy;
|
||||
AUTH *nauth;
|
||||
char hostname[NI_MAXHOST];
|
||||
|
||||
if (syncaddr) {
|
||||
/*
|
||||
* Change addr to hostname, because that is the way
|
||||
* new interface takes it.
|
||||
*/
|
||||
if (getnameinfo(syncaddr, syncaddr->sa_len, hostname,
|
||||
sizeof hostname, NULL, 0, 0) != 0)
|
||||
goto fallback;
|
||||
|
||||
nauth = authdes_seccreate(servername, window, hostname, ckey);
|
||||
return (nauth);
|
||||
}
|
||||
fallback:
|
||||
dummy = authdes_seccreate(servername, window, NULL, ckey);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a client handle for a unix connection. Obsoleted by clnt_vc_create()
|
||||
*/
|
||||
CLIENT *
|
||||
clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
|
||||
struct sockaddr_un *raddr;
|
||||
u_long prog;
|
||||
u_long vers;
|
||||
int *sockp;
|
||||
u_int sendsz;
|
||||
u_int recvsz;
|
||||
{
|
||||
struct netbuf *svcaddr;
|
||||
struct netconfig *nconf;
|
||||
CLIENT *cl;
|
||||
int len;
|
||||
|
||||
cl = NULL;
|
||||
nconf = NULL;
|
||||
svcaddr = NULL;
|
||||
if ((raddr->sun_len == 0) ||
|
||||
((svcaddr = malloc(sizeof(struct netbuf))) == NULL ) ||
|
||||
((svcaddr->buf = malloc(sizeof(struct sockaddr_un))) == NULL)) {
|
||||
if (svcaddr != NULL)
|
||||
free(svcaddr);
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
return(cl);
|
||||
}
|
||||
if (*sockp < 0) {
|
||||
*sockp = _socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
len = raddr->sun_len = SUN_LEN(raddr);
|
||||
if ((*sockp < 0) || (_connect(*sockp,
|
||||
(struct sockaddr *)raddr, len) < 0)) {
|
||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||
rpc_createerr.cf_error.re_errno = errno;
|
||||
if (*sockp != -1)
|
||||
(void)_close(*sockp);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
svcaddr->buf = raddr;
|
||||
svcaddr->len = raddr->sun_len;
|
||||
svcaddr->maxlen = sizeof (struct sockaddr_un);
|
||||
cl = clnt_vc_create(*sockp, svcaddr, prog,
|
||||
vers, sendsz, recvsz);
|
||||
done:
|
||||
free(svcaddr->buf);
|
||||
free(svcaddr);
|
||||
return(cl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates, registers, and returns a (rpc) unix based transporter.
|
||||
* Obsoleted by svc_vc_create().
|
||||
*/
|
||||
SVCXPRT *
|
||||
svcunix_create(sock, sendsize, recvsize, path)
|
||||
int sock;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
char *path;
|
||||
{
|
||||
struct netconfig *nconf;
|
||||
void *localhandle;
|
||||
struct sockaddr_un sun;
|
||||
struct sockaddr *sa;
|
||||
struct t_bind taddr;
|
||||
SVCXPRT *xprt;
|
||||
int addrlen;
|
||||
|
||||
xprt = (SVCXPRT *)NULL;
|
||||
localhandle = setnetconfig();
|
||||
while ((nconf = getnetconfig(localhandle)) != NULL) {
|
||||
if (nconf->nc_protofmly != NULL &&
|
||||
strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0)
|
||||
break;
|
||||
}
|
||||
if (nconf == NULL)
|
||||
return(xprt);
|
||||
|
||||
if ((sock = __rpc_nconf2fd(nconf)) < 0)
|
||||
goto done;
|
||||
|
||||
memset(&sun, 0, sizeof sun);
|
||||
sun.sun_family = AF_LOCAL;
|
||||
if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
|
||||
sizeof(sun.sun_path))
|
||||
goto done;
|
||||
sun.sun_len = SUN_LEN(&sun);
|
||||
addrlen = sizeof (struct sockaddr_un);
|
||||
sa = (struct sockaddr *)&sun;
|
||||
|
||||
if (_bind(sock, sa, addrlen) < 0)
|
||||
goto done;
|
||||
|
||||
taddr.addr.len = taddr.addr.maxlen = addrlen;
|
||||
taddr.addr.buf = malloc(addrlen);
|
||||
if (taddr.addr.buf == NULL)
|
||||
goto done;
|
||||
memcpy(taddr.addr.buf, sa, addrlen);
|
||||
|
||||
if (nconf->nc_semantics != NC_TPI_CLTS) {
|
||||
if (_listen(sock, SOMAXCONN) < 0) {
|
||||
free(taddr.addr.buf);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
xprt = (SVCXPRT *)svc_tli_create(sock, nconf, &taddr, sendsize, recvsize);
|
||||
|
||||
done:
|
||||
endnetconfig(localhandle);
|
||||
return(xprt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like svunix_create(), except the routine takes any *open* UNIX file
|
||||
* descriptor as its first input. Obsoleted by svc_fd_create();
|
||||
*/
|
||||
SVCXPRT *
|
||||
svcunixfd_create(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
return (svc_fd_create(fd, sendsize, recvsize));
|
||||
}
|
||||
|
||||
#endif /* PORTMAP */
|
1342
freebsd/lib/libc/rpc/rpcb_clnt.c
Normal file
1342
freebsd/lib/libc/rpc/rpcb_clnt.c
Normal file
File diff suppressed because it is too large
Load Diff
333
freebsd/lib/libc/rpc/rpcb_prot.c
Normal file
333
freebsd/lib/libc/rpc/rpcb_prot.c
Normal file
@ -0,0 +1,333 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpcb_prot.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
/* #ident "@(#)rpcb_prot.c 1.13 94/04/24 SMI" */
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* rpcb_prot.c
|
||||
* XDR routines for the rpcbinder version 3.
|
||||
*
|
||||
* Copyright (C) 1984, 1988, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/rpcb_prot.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
bool_t
|
||||
xdr_rpcb(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
RPCB *objp;
|
||||
{
|
||||
if (!xdr_u_int32_t(xdrs, &objp->r_prog)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->r_vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* rpcblist_ptr implements a linked list. The RPCL definition from
|
||||
* rpcb_prot.x is:
|
||||
*
|
||||
* struct rpcblist {
|
||||
* rpcb rpcb_map;
|
||||
* struct rpcblist *rpcb_next;
|
||||
* };
|
||||
* typedef rpcblist *rpcblist_ptr;
|
||||
*
|
||||
* Recall that "pointers" in XDR are encoded as a boolean, indicating whether
|
||||
* there's any data behind the pointer, followed by the data (if any exists).
|
||||
* The boolean can be interpreted as ``more data follows me''; if FALSE then
|
||||
* nothing follows the boolean; if TRUE then the boolean is followed by an
|
||||
* actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
|
||||
* rpcblist *").
|
||||
*
|
||||
* This could be implemented via the xdr_pointer type, though this would
|
||||
* result in one recursive call per element in the list. Rather than do that
|
||||
* we can ``unwind'' the recursion into a while loop and use xdr_reference to
|
||||
* serialize the rpcb elements.
|
||||
*/
|
||||
|
||||
bool_t
|
||||
xdr_rpcblist_ptr(xdrs, rp)
|
||||
XDR *xdrs;
|
||||
rpcblist_ptr *rp;
|
||||
{
|
||||
/*
|
||||
* more_elements is pre-computed in case the direction is
|
||||
* XDR_ENCODE or XDR_FREE. more_elements is overwritten by
|
||||
* xdr_bool when the direction is XDR_DECODE.
|
||||
*/
|
||||
bool_t more_elements;
|
||||
int freeing = (xdrs->x_op == XDR_FREE);
|
||||
rpcblist_ptr next;
|
||||
rpcblist_ptr next_copy;
|
||||
|
||||
next = NULL;
|
||||
for (;;) {
|
||||
more_elements = (bool_t)(*rp != NULL);
|
||||
if (! xdr_bool(xdrs, &more_elements)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (! more_elements) {
|
||||
return (TRUE); /* we are done */
|
||||
}
|
||||
/*
|
||||
* the unfortunate side effect of non-recursion is that in
|
||||
* the case of freeing we must remember the next object
|
||||
* before we free the current object ...
|
||||
*/
|
||||
if (freeing && *rp)
|
||||
next = (*rp)->rpcb_next;
|
||||
if (! xdr_reference(xdrs, (caddr_t *)rp,
|
||||
(u_int)sizeof (rpcblist), (xdrproc_t)xdr_rpcb)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (freeing) {
|
||||
next_copy = next;
|
||||
rp = &next_copy;
|
||||
/*
|
||||
* Note that in the subsequent iteration, next_copy
|
||||
* gets nulled out by the xdr_reference
|
||||
* but next itself survives.
|
||||
*/
|
||||
} else if (*rp) {
|
||||
rp = &((*rp)->rpcb_next);
|
||||
}
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
|
||||
* functionality to xdr_rpcblist_ptr().
|
||||
*/
|
||||
bool_t
|
||||
xdr_rpcblist(xdrs, rp)
|
||||
XDR *xdrs;
|
||||
RPCBLIST **rp;
|
||||
{
|
||||
bool_t dummy;
|
||||
|
||||
dummy = xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
|
||||
bool_t
|
||||
xdr_rpcb_entry(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcb_entry *objp;
|
||||
{
|
||||
if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpcb_entry_list_ptr(xdrs, rp)
|
||||
XDR *xdrs;
|
||||
rpcb_entry_list_ptr *rp;
|
||||
{
|
||||
/*
|
||||
* more_elements is pre-computed in case the direction is
|
||||
* XDR_ENCODE or XDR_FREE. more_elements is overwritten by
|
||||
* xdr_bool when the direction is XDR_DECODE.
|
||||
*/
|
||||
bool_t more_elements;
|
||||
int freeing = (xdrs->x_op == XDR_FREE);
|
||||
rpcb_entry_list_ptr next;
|
||||
rpcb_entry_list_ptr next_copy;
|
||||
|
||||
next = NULL;
|
||||
for (;;) {
|
||||
more_elements = (bool_t)(*rp != NULL);
|
||||
if (! xdr_bool(xdrs, &more_elements)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (! more_elements) {
|
||||
return (TRUE); /* we are done */
|
||||
}
|
||||
/*
|
||||
* the unfortunate side effect of non-recursion is that in
|
||||
* the case of freeing we must remember the next object
|
||||
* before we free the current object ...
|
||||
*/
|
||||
if (freeing)
|
||||
next = (*rp)->rpcb_entry_next;
|
||||
if (! xdr_reference(xdrs, (caddr_t *)rp,
|
||||
(u_int)sizeof (rpcb_entry_list),
|
||||
(xdrproc_t)xdr_rpcb_entry)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (freeing && *rp) {
|
||||
next_copy = next;
|
||||
rp = &next_copy;
|
||||
/*
|
||||
* Note that in the subsequent iteration, next_copy
|
||||
* gets nulled out by the xdr_reference
|
||||
* but next itself survives.
|
||||
*/
|
||||
} else if (*rp) {
|
||||
rp = &((*rp)->rpcb_entry_next);
|
||||
}
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR remote call arguments
|
||||
* written for XDR_ENCODE direction only
|
||||
*/
|
||||
bool_t
|
||||
xdr_rpcb_rmtcallargs(xdrs, p)
|
||||
XDR *xdrs;
|
||||
struct rpcb_rmtcallargs *p;
|
||||
{
|
||||
struct r_rpcb_rmtcallargs *objp =
|
||||
(struct r_rpcb_rmtcallargs *)(void *)p;
|
||||
u_int lenposition, argposition, position;
|
||||
int32_t *buf;
|
||||
|
||||
buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
|
||||
if (buf == NULL) {
|
||||
if (!xdr_u_int32_t(xdrs, &objp->prog)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->proc)) {
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
IXDR_PUT_U_INT32(buf, objp->prog);
|
||||
IXDR_PUT_U_INT32(buf, objp->vers);
|
||||
IXDR_PUT_U_INT32(buf, objp->proc);
|
||||
}
|
||||
|
||||
/*
|
||||
* All the jugglery for just getting the size of the arguments
|
||||
*/
|
||||
lenposition = XDR_GETPOS(xdrs);
|
||||
if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
|
||||
return (FALSE);
|
||||
}
|
||||
argposition = XDR_GETPOS(xdrs);
|
||||
if (! (*objp->xdr_args)(xdrs, objp->args.args_val)) {
|
||||
return (FALSE);
|
||||
}
|
||||
position = XDR_GETPOS(xdrs);
|
||||
objp->args.args_len = (u_int)((u_long)position - (u_long)argposition);
|
||||
XDR_SETPOS(xdrs, lenposition);
|
||||
if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
|
||||
return (FALSE);
|
||||
}
|
||||
XDR_SETPOS(xdrs, position);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR remote call results
|
||||
* written for XDR_DECODE direction only
|
||||
*/
|
||||
bool_t
|
||||
xdr_rpcb_rmtcallres(xdrs, p)
|
||||
XDR *xdrs;
|
||||
struct rpcb_rmtcallres *p;
|
||||
{
|
||||
bool_t dummy;
|
||||
struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p;
|
||||
|
||||
if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int(xdrs, &objp->results.results_len)) {
|
||||
return (FALSE);
|
||||
}
|
||||
dummy = (*(objp->xdr_res))(xdrs, objp->results.results_val);
|
||||
return (dummy);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_netbuf(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
struct netbuf *objp;
|
||||
{
|
||||
bool_t dummy;
|
||||
void **pp;
|
||||
|
||||
if (!xdr_u_int32_t(xdrs, (u_int32_t *) &objp->maxlen)) {
|
||||
return (FALSE);
|
||||
}
|
||||
pp = &objp->buf;
|
||||
dummy = xdr_bytes(xdrs, (char **) pp,
|
||||
(u_int *)&(objp->len), objp->maxlen);
|
||||
return (dummy);
|
||||
}
|
276
freebsd/lib/libc/rpc/rpcb_st_xdr.c
Normal file
276
freebsd/lib/libc/rpc/rpcb_st_xdr.c
Normal file
@ -0,0 +1,276 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: rpcb_st_xdr.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright 1991 Sun Microsystems, Inc.
|
||||
* rpcb_stat_xdr.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file was generated from rpcb_prot.x, but includes only those
|
||||
* routines used with the rpcbind stats facility.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rpc/rpc.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/* Link list of all the stats about getport and getaddr */
|
||||
|
||||
bool_t
|
||||
xdr_rpcbs_addrlist(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcbs_addrlist *objp;
|
||||
{
|
||||
struct rpcbs_addrlist **pnext;
|
||||
|
||||
if (!xdr_u_int32_t(xdrs, &objp->prog)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->success)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->failure)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
pnext = &objp->next;
|
||||
|
||||
if (!xdr_pointer(xdrs, (char **) pnext,
|
||||
sizeof (rpcbs_addrlist),
|
||||
(xdrproc_t)xdr_rpcbs_addrlist)) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/* Link list of all the stats about rmtcall */
|
||||
|
||||
bool_t
|
||||
xdr_rpcbs_rmtcalllist(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcbs_rmtcalllist *objp;
|
||||
{
|
||||
int32_t *buf;
|
||||
struct rpcbs_rmtcalllist **pnext;
|
||||
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
|
||||
if (buf == NULL) {
|
||||
if (!xdr_u_int32_t(xdrs, &objp->prog)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->proc)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->success)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->failure)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->indirect)) {
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
IXDR_PUT_U_INT32(buf, objp->prog);
|
||||
IXDR_PUT_U_INT32(buf, objp->vers);
|
||||
IXDR_PUT_U_INT32(buf, objp->proc);
|
||||
IXDR_PUT_INT32(buf, objp->success);
|
||||
IXDR_PUT_INT32(buf, objp->failure);
|
||||
IXDR_PUT_INT32(buf, objp->indirect);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
pnext = &objp->next;
|
||||
if (!xdr_pointer(xdrs, (char **) pnext,
|
||||
sizeof (rpcbs_rmtcalllist),
|
||||
(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
} else if (xdrs->x_op == XDR_DECODE) {
|
||||
buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
|
||||
if (buf == NULL) {
|
||||
if (!xdr_u_int32_t(xdrs, &objp->prog)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->proc)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->success)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->failure)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->indirect)) {
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
|
||||
objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
|
||||
objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
|
||||
objp->success = (int)IXDR_GET_INT32(buf);
|
||||
objp->failure = (int)IXDR_GET_INT32(buf);
|
||||
objp->indirect = (int)IXDR_GET_INT32(buf);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_pointer(xdrs, (char **) pnext,
|
||||
sizeof (rpcbs_rmtcalllist),
|
||||
(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->prog)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->proc)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->success)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->failure)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->indirect)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_pointer(xdrs, (char **) pnext,
|
||||
sizeof (rpcbs_rmtcalllist),
|
||||
(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpcbs_proc(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcbs_proc objp;
|
||||
{
|
||||
if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
|
||||
sizeof (int), (xdrproc_t)xdr_int)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpcbs_addrlist_ptr(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcbs_addrlist_ptr *objp;
|
||||
{
|
||||
if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist),
|
||||
(xdrproc_t)xdr_rpcbs_addrlist)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpcbs_rmtcalllist_ptr(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcbs_rmtcalllist_ptr *objp;
|
||||
{
|
||||
if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
|
||||
(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpcb_stat(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcb_stat *objp;
|
||||
{
|
||||
|
||||
if (!xdr_rpcbs_proc(xdrs, objp->info)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->setinfo)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_int(xdrs, &objp->unsetinfo)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* One rpcb_stat structure is returned for each version of rpcbind
|
||||
* being monitored.
|
||||
*/
|
||||
bool_t
|
||||
xdr_rpcb_stat_byvers(xdrs, objp)
|
||||
XDR *xdrs;
|
||||
rpcb_stat_byvers objp;
|
||||
{
|
||||
if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
|
||||
sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
82
freebsd/lib/libc/rpc/rpcdname.c
Normal file
82
freebsd/lib/libc/rpc/rpcdname.c
Normal file
@ -0,0 +1,82 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)rpcdname.c 1.7 91/03/11 Copyr 1989 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* rpcdname.c
|
||||
* Gets the default domain name
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
static char *default_domain = 0;
|
||||
|
||||
static char *
|
||||
get_default_domain()
|
||||
{
|
||||
char temp[256];
|
||||
|
||||
if (default_domain)
|
||||
return (default_domain);
|
||||
if (getdomainname(temp, sizeof(temp)) < 0)
|
||||
return (0);
|
||||
if ((int) strlen(temp) > 0) {
|
||||
default_domain = (char *)malloc((strlen(temp)+(unsigned)1));
|
||||
if (default_domain == 0)
|
||||
return (0);
|
||||
(void) strcpy(default_domain, temp);
|
||||
return (default_domain);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a wrapper for the system call getdomainname which returns a
|
||||
* ypclnt.h error code in the failure case. It also checks to see that
|
||||
* the domain name is non-null, knowing that the null string is going to
|
||||
* get rejected elsewhere in the NIS client package.
|
||||
*/
|
||||
int
|
||||
__rpc_get_default_domain(domain)
|
||||
char **domain;
|
||||
{
|
||||
if ((*domain = get_default_domain()) != 0)
|
||||
return (0);
|
||||
return (-1);
|
||||
}
|
50
freebsd/lib/libc/rpc/rpcsec_gss_stub.c
Normal file
50
freebsd/lib/libc/rpc/rpcsec_gss_stub.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 Doug Rabson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
|
||||
bool_t
|
||||
__rpc_gss_wrap_stub(AUTH *auth, void *header, size_t headerlen, XDR* xdrs,
|
||||
xdrproc_t xdr_args, void *args_ptr)
|
||||
{
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
__rpc_gss_unwrap_stub(AUTH *auth, XDR* xdrs, xdrproc_t xdr_args, void *args_ptr)
|
||||
{
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
__weak_reference(__rpc_gss_wrap_stub, __rpc_gss_wrap);
|
||||
__weak_reference(__rpc_gss_unwrap_stub, __rpc_gss_unwrap);
|
161
freebsd/lib/libc/rpc/rtime.c
Normal file
161
freebsd/lib/libc/rpc/rtime.c
Normal file
@ -0,0 +1,161 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 by Sun Microsystems, Inc.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* rtime - get time from remote machine
|
||||
*
|
||||
* gets time, obtaining value from host
|
||||
* on the udp/time socket. Since timeserver returns
|
||||
* with time of day in seconds since Jan 1, 1900, must
|
||||
* subtract seconds before Jan 1, 1970 to get
|
||||
* what unix uses.
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)rtime.c 2.2 88/08/10 4.0 RPCSRC; from 1.8 88/02/08 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
extern int _rpc_dtablesize( void );
|
||||
|
||||
#define NYEARS (unsigned long)(1970 - 1900)
|
||||
#define TOFFSET (unsigned long)(60*60*24*(365*NYEARS + (NYEARS/4)))
|
||||
|
||||
static void do_close( int );
|
||||
|
||||
int
|
||||
rtime(addrp, timep, timeout)
|
||||
struct sockaddr_in *addrp;
|
||||
struct timeval *timep;
|
||||
struct timeval *timeout;
|
||||
{
|
||||
int s;
|
||||
fd_set readfds;
|
||||
int res;
|
||||
unsigned long thetime;
|
||||
struct sockaddr_in from;
|
||||
socklen_t fromlen;
|
||||
int type;
|
||||
struct servent *serv;
|
||||
|
||||
if (timeout == NULL) {
|
||||
type = SOCK_STREAM;
|
||||
} else {
|
||||
type = SOCK_DGRAM;
|
||||
}
|
||||
s = _socket(AF_INET, type, 0);
|
||||
if (s < 0) {
|
||||
return(-1);
|
||||
}
|
||||
addrp->sin_family = AF_INET;
|
||||
|
||||
/* TCP and UDP port are the same in this case */
|
||||
if ((serv = getservbyname("time", "tcp")) == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
addrp->sin_port = serv->s_port;
|
||||
|
||||
if (type == SOCK_DGRAM) {
|
||||
res = _sendto(s, (char *)&thetime, sizeof(thetime), 0,
|
||||
(struct sockaddr *)addrp, sizeof(*addrp));
|
||||
if (res < 0) {
|
||||
do_close(s);
|
||||
return(-1);
|
||||
}
|
||||
do {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(s, &readfds);
|
||||
res = _select(_rpc_dtablesize(), &readfds,
|
||||
(fd_set *)NULL, (fd_set *)NULL, timeout);
|
||||
} while (res < 0 && errno == EINTR);
|
||||
if (res <= 0) {
|
||||
if (res == 0) {
|
||||
errno = ETIMEDOUT;
|
||||
}
|
||||
do_close(s);
|
||||
return(-1);
|
||||
}
|
||||
fromlen = sizeof(from);
|
||||
res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0,
|
||||
(struct sockaddr *)&from, &fromlen);
|
||||
do_close(s);
|
||||
if (res < 0) {
|
||||
return(-1);
|
||||
}
|
||||
} else {
|
||||
if (_connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) {
|
||||
do_close(s);
|
||||
return(-1);
|
||||
}
|
||||
res = _read(s, (char *)&thetime, sizeof(thetime));
|
||||
do_close(s);
|
||||
if (res < 0) {
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
if (res != sizeof(thetime)) {
|
||||
errno = EIO;
|
||||
return(-1);
|
||||
}
|
||||
thetime = ntohl(thetime);
|
||||
timep->tv_sec = thetime - TOFFSET;
|
||||
timep->tv_usec = 0;
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void
|
||||
do_close(s)
|
||||
int s;
|
||||
{
|
||||
int save;
|
||||
|
||||
save = errno;
|
||||
(void)_close(s);
|
||||
errno = save;
|
||||
}
|
798
freebsd/lib/libc/rpc/svc.c
Normal file
798
freebsd/lib/libc/rpc/svc.c
Normal file
@ -0,0 +1,798 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc.c,v 1.21 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)svc.c 2.4 88/08/11 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc.c, Server-side remote procedure call interface.
|
||||
*
|
||||
* There are two sets of procedures here. The xprt routines are
|
||||
* for handling transport handles. The svc routines handle the
|
||||
* list of service routines.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/poll.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#ifdef PORTMAP
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#endif /* PORTMAP */
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#define RQCRED_SIZE 400 /* this size is excessive */
|
||||
|
||||
#define SVC_VERSQUIET 0x0001 /* keep quiet about vers mismatch */
|
||||
#define version_keepquiet(xp) (SVC_EXT(xp)->xp_flags & SVC_VERSQUIET)
|
||||
|
||||
#define max(a, b) (a > b ? a : b)
|
||||
|
||||
/*
|
||||
* The services list
|
||||
* Each entry represents a set of procedures (an rpc program).
|
||||
* The dispatch routine takes request structs and runs the
|
||||
* apropriate procedure.
|
||||
*/
|
||||
static struct svc_callout {
|
||||
struct svc_callout *sc_next;
|
||||
rpcprog_t sc_prog;
|
||||
rpcvers_t sc_vers;
|
||||
char *sc_netid;
|
||||
void (*sc_dispatch)(struct svc_req *, SVCXPRT *);
|
||||
} *svc_head;
|
||||
|
||||
static struct svc_callout *svc_find(rpcprog_t, rpcvers_t,
|
||||
struct svc_callout **, char *);
|
||||
static void __xprt_do_unregister (SVCXPRT *xprt, bool_t dolock);
|
||||
|
||||
/* *************** SVCXPRT related stuff **************** */
|
||||
|
||||
/*
|
||||
* Activate a transport handle.
|
||||
*/
|
||||
void
|
||||
xprt_register(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
int sock;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
sock = xprt->xp_fd;
|
||||
|
||||
rwlock_wrlock(&svc_fd_lock);
|
||||
if (__svc_xports == NULL) {
|
||||
__svc_xports = (SVCXPRT **)
|
||||
mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
|
||||
if (__svc_xports == NULL) {
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
return;
|
||||
}
|
||||
memset(__svc_xports, '\0', FD_SETSIZE * sizeof(SVCXPRT *));
|
||||
}
|
||||
if (sock < FD_SETSIZE) {
|
||||
__svc_xports[sock] = xprt;
|
||||
FD_SET(sock, &svc_fdset);
|
||||
svc_maxfd = max(svc_maxfd, sock);
|
||||
}
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
}
|
||||
|
||||
void
|
||||
xprt_unregister(SVCXPRT *xprt)
|
||||
{
|
||||
__xprt_do_unregister(xprt, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
__xprt_unregister_unlocked(SVCXPRT *xprt)
|
||||
{
|
||||
__xprt_do_unregister(xprt, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* De-activate a transport handle.
|
||||
*/
|
||||
static void
|
||||
__xprt_do_unregister(xprt, dolock)
|
||||
SVCXPRT *xprt;
|
||||
bool_t dolock;
|
||||
{
|
||||
int sock;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
sock = xprt->xp_fd;
|
||||
|
||||
if (dolock)
|
||||
rwlock_wrlock(&svc_fd_lock);
|
||||
if ((sock < FD_SETSIZE) && (__svc_xports[sock] == xprt)) {
|
||||
__svc_xports[sock] = NULL;
|
||||
FD_CLR(sock, &svc_fdset);
|
||||
if (sock >= svc_maxfd) {
|
||||
for (svc_maxfd--; svc_maxfd>=0; svc_maxfd--)
|
||||
if (__svc_xports[svc_maxfd])
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dolock)
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a service program to the callout list.
|
||||
* The dispatch routine will be called when a rpc request for this
|
||||
* program number comes in.
|
||||
*/
|
||||
bool_t
|
||||
svc_reg(xprt, prog, vers, dispatch, nconf)
|
||||
SVCXPRT *xprt;
|
||||
const rpcprog_t prog;
|
||||
const rpcvers_t vers;
|
||||
void (*dispatch)(struct svc_req *, SVCXPRT *);
|
||||
const struct netconfig *nconf;
|
||||
{
|
||||
bool_t dummy;
|
||||
struct svc_callout *prev;
|
||||
struct svc_callout *s;
|
||||
struct netconfig *tnconf;
|
||||
char *netid = NULL;
|
||||
int flag = 0;
|
||||
|
||||
/* VARIABLES PROTECTED BY svc_lock: s, prev, svc_head */
|
||||
|
||||
if (xprt->xp_netid) {
|
||||
netid = strdup(xprt->xp_netid);
|
||||
flag = 1;
|
||||
} else if (nconf && nconf->nc_netid) {
|
||||
netid = strdup(nconf->nc_netid);
|
||||
flag = 1;
|
||||
} else if ((tnconf = __rpcgettp(xprt->xp_fd)) != NULL) {
|
||||
netid = strdup(tnconf->nc_netid);
|
||||
flag = 1;
|
||||
freenetconfigent(tnconf);
|
||||
} /* must have been created with svc_raw_create */
|
||||
if ((netid == NULL) && (flag == 1)) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
rwlock_wrlock(&svc_lock);
|
||||
if ((s = svc_find(prog, vers, &prev, netid)) != NULL) {
|
||||
if (netid)
|
||||
free(netid);
|
||||
if (s->sc_dispatch == dispatch)
|
||||
goto rpcb_it; /* he is registering another xptr */
|
||||
rwlock_unlock(&svc_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
s = mem_alloc(sizeof (struct svc_callout));
|
||||
if (s == NULL) {
|
||||
if (netid)
|
||||
free(netid);
|
||||
rwlock_unlock(&svc_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
s->sc_prog = prog;
|
||||
s->sc_vers = vers;
|
||||
s->sc_dispatch = dispatch;
|
||||
s->sc_netid = netid;
|
||||
s->sc_next = svc_head;
|
||||
svc_head = s;
|
||||
|
||||
if ((xprt->xp_netid == NULL) && (flag == 1) && netid)
|
||||
((SVCXPRT *) xprt)->xp_netid = strdup(netid);
|
||||
|
||||
rpcb_it:
|
||||
rwlock_unlock(&svc_lock);
|
||||
/* now register the information with the local binder service */
|
||||
if (nconf) {
|
||||
/*LINTED const castaway*/
|
||||
dummy = rpcb_set(prog, vers, (struct netconfig *) nconf,
|
||||
&((SVCXPRT *) xprt)->xp_ltaddr);
|
||||
return (dummy);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a service program from the callout list.
|
||||
*/
|
||||
void
|
||||
svc_unreg(prog, vers)
|
||||
const rpcprog_t prog;
|
||||
const rpcvers_t vers;
|
||||
{
|
||||
struct svc_callout *prev;
|
||||
struct svc_callout *s;
|
||||
|
||||
/* unregister the information anyway */
|
||||
(void) rpcb_unset(prog, vers, NULL);
|
||||
rwlock_wrlock(&svc_lock);
|
||||
while ((s = svc_find(prog, vers, &prev, NULL)) != NULL) {
|
||||
if (prev == NULL) {
|
||||
svc_head = s->sc_next;
|
||||
} else {
|
||||
prev->sc_next = s->sc_next;
|
||||
}
|
||||
s->sc_next = NULL;
|
||||
if (s->sc_netid)
|
||||
mem_free(s->sc_netid, sizeof (s->sc_netid) + 1);
|
||||
mem_free(s, sizeof (struct svc_callout));
|
||||
}
|
||||
rwlock_unlock(&svc_lock);
|
||||
}
|
||||
|
||||
/* ********************** CALLOUT list related stuff ************* */
|
||||
|
||||
#ifdef PORTMAP
|
||||
/*
|
||||
* Add a service program to the callout list.
|
||||
* The dispatch routine will be called when a rpc request for this
|
||||
* program number comes in.
|
||||
*/
|
||||
bool_t
|
||||
svc_register(xprt, prog, vers, dispatch, protocol)
|
||||
SVCXPRT *xprt;
|
||||
u_long prog;
|
||||
u_long vers;
|
||||
void (*dispatch)(struct svc_req *, SVCXPRT *);
|
||||
int protocol;
|
||||
{
|
||||
struct svc_callout *prev;
|
||||
struct svc_callout *s;
|
||||
|
||||
assert(xprt != NULL);
|
||||
assert(dispatch != NULL);
|
||||
|
||||
if ((s = svc_find((rpcprog_t)prog, (rpcvers_t)vers, &prev, NULL)) !=
|
||||
NULL) {
|
||||
if (s->sc_dispatch == dispatch)
|
||||
goto pmap_it; /* he is registering another xptr */
|
||||
return (FALSE);
|
||||
}
|
||||
s = mem_alloc(sizeof(struct svc_callout));
|
||||
if (s == NULL) {
|
||||
return (FALSE);
|
||||
}
|
||||
s->sc_prog = (rpcprog_t)prog;
|
||||
s->sc_vers = (rpcvers_t)vers;
|
||||
s->sc_dispatch = dispatch;
|
||||
s->sc_next = svc_head;
|
||||
svc_head = s;
|
||||
pmap_it:
|
||||
/* now register the information with the local binder service */
|
||||
if (protocol) {
|
||||
return (pmap_set(prog, vers, protocol, xprt->xp_port));
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a service program from the callout list.
|
||||
*/
|
||||
void
|
||||
svc_unregister(prog, vers)
|
||||
u_long prog;
|
||||
u_long vers;
|
||||
{
|
||||
struct svc_callout *prev;
|
||||
struct svc_callout *s;
|
||||
|
||||
if ((s = svc_find((rpcprog_t)prog, (rpcvers_t)vers, &prev, NULL)) ==
|
||||
NULL)
|
||||
return;
|
||||
if (prev == NULL) {
|
||||
svc_head = s->sc_next;
|
||||
} else {
|
||||
prev->sc_next = s->sc_next;
|
||||
}
|
||||
s->sc_next = NULL;
|
||||
mem_free(s, sizeof(struct svc_callout));
|
||||
/* now unregister the information with the local binder service */
|
||||
(void)pmap_unset(prog, vers);
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
|
||||
/*
|
||||
* Search the callout list for a program number, return the callout
|
||||
* struct.
|
||||
*/
|
||||
static struct svc_callout *
|
||||
svc_find(prog, vers, prev, netid)
|
||||
rpcprog_t prog;
|
||||
rpcvers_t vers;
|
||||
struct svc_callout **prev;
|
||||
char *netid;
|
||||
{
|
||||
struct svc_callout *s, *p;
|
||||
|
||||
assert(prev != NULL);
|
||||
|
||||
p = NULL;
|
||||
for (s = svc_head; s != NULL; s = s->sc_next) {
|
||||
if (((s->sc_prog == prog) && (s->sc_vers == vers)) &&
|
||||
((netid == NULL) || (s->sc_netid == NULL) ||
|
||||
(strcmp(netid, s->sc_netid) == 0)))
|
||||
break;
|
||||
p = s;
|
||||
}
|
||||
*prev = p;
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* ******************* REPLY GENERATION ROUTINES ************ */
|
||||
|
||||
/*
|
||||
* Send a reply to an rpc request
|
||||
*/
|
||||
bool_t
|
||||
svc_sendreply(xprt, xdr_results, xdr_location)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_results;
|
||||
void * xdr_location;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
rply.acpted_rply.ar_verf = xprt->xp_verf;
|
||||
rply.acpted_rply.ar_stat = SUCCESS;
|
||||
rply.acpted_rply.ar_results.where = xdr_location;
|
||||
rply.acpted_rply.ar_results.proc = xdr_results;
|
||||
return (SVC_REPLY(xprt, &rply));
|
||||
}
|
||||
|
||||
/*
|
||||
* No procedure error reply
|
||||
*/
|
||||
void
|
||||
svcerr_noproc(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
rply.acpted_rply.ar_verf = xprt->xp_verf;
|
||||
rply.acpted_rply.ar_stat = PROC_UNAVAIL;
|
||||
SVC_REPLY(xprt, &rply);
|
||||
}
|
||||
|
||||
/*
|
||||
* Can't decode args error reply
|
||||
*/
|
||||
void
|
||||
svcerr_decode(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
rply.acpted_rply.ar_verf = xprt->xp_verf;
|
||||
rply.acpted_rply.ar_stat = GARBAGE_ARGS;
|
||||
SVC_REPLY(xprt, &rply);
|
||||
}
|
||||
|
||||
/*
|
||||
* Some system error
|
||||
*/
|
||||
void
|
||||
svcerr_systemerr(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
rply.acpted_rply.ar_verf = xprt->xp_verf;
|
||||
rply.acpted_rply.ar_stat = SYSTEM_ERR;
|
||||
SVC_REPLY(xprt, &rply);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Tell RPC package to not complain about version errors to the client. This
|
||||
* is useful when revving broadcast protocols that sit on a fixed address.
|
||||
* There is really one (or should be only one) example of this kind of
|
||||
* protocol: the portmapper (or rpc binder).
|
||||
*/
|
||||
void
|
||||
__svc_versquiet_on(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
|
||||
SVC_EXT(xprt)->xp_flags |= SVC_VERSQUIET;
|
||||
}
|
||||
|
||||
void
|
||||
__svc_versquiet_off(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
|
||||
SVC_EXT(xprt)->xp_flags &= ~SVC_VERSQUIET;
|
||||
}
|
||||
|
||||
void
|
||||
svc_versquiet(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
__svc_versquiet_on(xprt);
|
||||
}
|
||||
|
||||
int
|
||||
__svc_versquiet_get(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
|
||||
return (SVC_EXT(xprt)->xp_flags & SVC_VERSQUIET);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Authentication error reply
|
||||
*/
|
||||
void
|
||||
svcerr_auth(xprt, why)
|
||||
SVCXPRT *xprt;
|
||||
enum auth_stat why;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_DENIED;
|
||||
rply.rjcted_rply.rj_stat = AUTH_ERROR;
|
||||
rply.rjcted_rply.rj_why = why;
|
||||
SVC_REPLY(xprt, &rply);
|
||||
}
|
||||
|
||||
/*
|
||||
* Auth too weak error reply
|
||||
*/
|
||||
void
|
||||
svcerr_weakauth(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
svcerr_auth(xprt, AUTH_TOOWEAK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Program unavailable error reply
|
||||
*/
|
||||
void
|
||||
svcerr_noprog(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
rply.acpted_rply.ar_verf = xprt->xp_verf;
|
||||
rply.acpted_rply.ar_stat = PROG_UNAVAIL;
|
||||
SVC_REPLY(xprt, &rply);
|
||||
}
|
||||
|
||||
/*
|
||||
* Program version mismatch error reply
|
||||
*/
|
||||
void
|
||||
svcerr_progvers(xprt, low_vers, high_vers)
|
||||
SVCXPRT *xprt;
|
||||
rpcvers_t low_vers;
|
||||
rpcvers_t high_vers;
|
||||
{
|
||||
struct rpc_msg rply;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
rply.rm_direction = REPLY;
|
||||
rply.rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
rply.acpted_rply.ar_verf = xprt->xp_verf;
|
||||
rply.acpted_rply.ar_stat = PROG_MISMATCH;
|
||||
rply.acpted_rply.ar_vers.low = (u_int32_t)low_vers;
|
||||
rply.acpted_rply.ar_vers.high = (u_int32_t)high_vers;
|
||||
SVC_REPLY(xprt, &rply);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new server transport structure. All fields are
|
||||
* initialized to zero and xp_p3 is initialized to point at an
|
||||
* extension structure to hold various flags and authentication
|
||||
* parameters.
|
||||
*/
|
||||
SVCXPRT *
|
||||
svc_xprt_alloc()
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
SVCXPRT_EXT *ext;
|
||||
|
||||
xprt = mem_alloc(sizeof(SVCXPRT));
|
||||
if (xprt == NULL)
|
||||
return (NULL);
|
||||
memset(xprt, 0, sizeof(SVCXPRT));
|
||||
ext = mem_alloc(sizeof(SVCXPRT_EXT));
|
||||
if (ext == NULL) {
|
||||
mem_free(xprt, sizeof(SVCXPRT));
|
||||
return (NULL);
|
||||
}
|
||||
memset(ext, 0, sizeof(SVCXPRT_EXT));
|
||||
xprt->xp_p3 = ext;
|
||||
ext->xp_auth.svc_ah_ops = &svc_auth_null_ops;
|
||||
|
||||
return (xprt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a server transport structure.
|
||||
*/
|
||||
void
|
||||
svc_xprt_free(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
|
||||
mem_free(xprt->xp_p3, sizeof(SVCXPRT_EXT));
|
||||
mem_free(xprt, sizeof(SVCXPRT));
|
||||
}
|
||||
|
||||
/* ******************* SERVER INPUT STUFF ******************* */
|
||||
|
||||
/*
|
||||
* Get server side input from some transport.
|
||||
*
|
||||
* Statement of authentication parameters management:
|
||||
* This function owns and manages all authentication parameters, specifically
|
||||
* the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
|
||||
* the "cooked" credentials (rqst->rq_clntcred).
|
||||
* However, this function does not know the structure of the cooked
|
||||
* credentials, so it make the following assumptions:
|
||||
* a) the structure is contiguous (no pointers), and
|
||||
* b) the cred structure size does not exceed RQCRED_SIZE bytes.
|
||||
* In all events, all three parameters are freed upon exit from this routine.
|
||||
* The storage is trivially management on the call stack in user land, but
|
||||
* is mallocated in kernel land.
|
||||
*/
|
||||
|
||||
void
|
||||
svc_getreq(rdfds)
|
||||
int rdfds;
|
||||
{
|
||||
fd_set readfds;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
readfds.fds_bits[0] = rdfds;
|
||||
svc_getreqset(&readfds);
|
||||
}
|
||||
|
||||
void
|
||||
svc_getreqset(readfds)
|
||||
fd_set *readfds;
|
||||
{
|
||||
int bit, fd;
|
||||
fd_mask mask, *maskp;
|
||||
int sock;
|
||||
|
||||
assert(readfds != NULL);
|
||||
|
||||
maskp = readfds->fds_bits;
|
||||
for (sock = 0; sock < FD_SETSIZE; sock += NFDBITS) {
|
||||
for (mask = *maskp++; (bit = ffsl(mask)) != 0;
|
||||
mask ^= (1ul << (bit - 1))) {
|
||||
/* sock has input waiting */
|
||||
fd = sock + bit - 1;
|
||||
svc_getreq_common(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
svc_getreq_common(fd)
|
||||
int fd;
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
struct svc_req r;
|
||||
struct rpc_msg msg;
|
||||
int prog_found;
|
||||
rpcvers_t low_vers;
|
||||
rpcvers_t high_vers;
|
||||
enum xprt_stat stat;
|
||||
char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];
|
||||
|
||||
msg.rm_call.cb_cred.oa_base = cred_area;
|
||||
msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
|
||||
r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]);
|
||||
|
||||
rwlock_rdlock(&svc_fd_lock);
|
||||
xprt = __svc_xports[fd];
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
if (xprt == NULL)
|
||||
/* But do we control sock? */
|
||||
return;
|
||||
/* now receive msgs from xprtprt (support batch calls) */
|
||||
do {
|
||||
if (SVC_RECV(xprt, &msg)) {
|
||||
|
||||
/* now find the exported program and call it */
|
||||
struct svc_callout *s;
|
||||
enum auth_stat why;
|
||||
|
||||
r.rq_xprt = xprt;
|
||||
r.rq_prog = msg.rm_call.cb_prog;
|
||||
r.rq_vers = msg.rm_call.cb_vers;
|
||||
r.rq_proc = msg.rm_call.cb_proc;
|
||||
r.rq_cred = msg.rm_call.cb_cred;
|
||||
/* first authenticate the message */
|
||||
if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
|
||||
/*
|
||||
* RPCSEC_GSS uses this return code
|
||||
* for requests that form part of its
|
||||
* context establishment protocol and
|
||||
* should not be dispatched to the
|
||||
* application.
|
||||
*/
|
||||
if (why != RPCSEC_GSS_NODISPATCH)
|
||||
svcerr_auth(xprt, why);
|
||||
goto call_done;
|
||||
}
|
||||
/* now match message with a registered service*/
|
||||
prog_found = FALSE;
|
||||
low_vers = (rpcvers_t) -1L;
|
||||
high_vers = (rpcvers_t) 0L;
|
||||
for (s = svc_head; s != NULL; s = s->sc_next) {
|
||||
if (s->sc_prog == r.rq_prog) {
|
||||
if (s->sc_vers == r.rq_vers) {
|
||||
(*s->sc_dispatch)(&r, xprt);
|
||||
goto call_done;
|
||||
} /* found correct version */
|
||||
prog_found = TRUE;
|
||||
if (s->sc_vers < low_vers)
|
||||
low_vers = s->sc_vers;
|
||||
if (s->sc_vers > high_vers)
|
||||
high_vers = s->sc_vers;
|
||||
} /* found correct program */
|
||||
}
|
||||
/*
|
||||
* if we got here, the program or version
|
||||
* is not served ...
|
||||
*/
|
||||
if (prog_found)
|
||||
svcerr_progvers(xprt, low_vers, high_vers);
|
||||
else
|
||||
svcerr_noprog(xprt);
|
||||
/* Fall through to ... */
|
||||
}
|
||||
/*
|
||||
* Check if the xprt has been disconnected in a
|
||||
* recursive call in the service dispatch routine.
|
||||
* If so, then break.
|
||||
*/
|
||||
rwlock_rdlock(&svc_fd_lock);
|
||||
if (xprt != __svc_xports[fd]) {
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
break;
|
||||
}
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
call_done:
|
||||
if ((stat = SVC_STAT(xprt)) == XPRT_DIED){
|
||||
SVC_DESTROY(xprt);
|
||||
break;
|
||||
}
|
||||
} while (stat == XPRT_MOREREQS);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
svc_getreq_poll(pfdp, pollretval)
|
||||
struct pollfd *pfdp;
|
||||
int pollretval;
|
||||
{
|
||||
int i;
|
||||
int fds_found;
|
||||
|
||||
for (i = fds_found = 0; fds_found < pollretval; i++) {
|
||||
struct pollfd *p = &pfdp[i];
|
||||
|
||||
if (p->revents) {
|
||||
/* fd has input waiting */
|
||||
fds_found++;
|
||||
/*
|
||||
* We assume that this function is only called
|
||||
* via someone _select()ing from svc_fdset or
|
||||
* _poll()ing from svc_pollset[]. Thus it's safe
|
||||
* to handle the POLLNVAL event by simply turning
|
||||
* the corresponding bit off in svc_fdset. The
|
||||
* svc_pollset[] array is derived from svc_fdset
|
||||
* and so will also be updated eventually.
|
||||
*
|
||||
* XXX Should we do an xprt_unregister() instead?
|
||||
*/
|
||||
if (p->revents & POLLNVAL) {
|
||||
rwlock_wrlock(&svc_fd_lock);
|
||||
FD_CLR(p->fd, &svc_fdset);
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
} else
|
||||
svc_getreq_common(p->fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool_t
|
||||
rpc_control(int what, void *arg)
|
||||
{
|
||||
int val;
|
||||
|
||||
switch (what) {
|
||||
case RPC_SVC_CONNMAXREC_SET:
|
||||
val = *(int *)arg;
|
||||
if (val <= 0)
|
||||
return FALSE;
|
||||
__svc_maxrec = val;
|
||||
return TRUE;
|
||||
case RPC_SVC_CONNMAXREC_GET:
|
||||
*(int *)arg = __svc_maxrec;
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
235
freebsd/lib/libc/rpc/svc_auth.c
Normal file
235
freebsd/lib/libc/rpc/svc_auth.c
Normal file
@ -0,0 +1,235 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_auth.c,v 1.12 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#ident "@(#)svc_auth.c 1.16 94/04/24 SMI"
|
||||
static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_auth.c, Server-side rpc authenticator interface.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <stdlib.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
/*
|
||||
* svcauthsw is the bdevsw of server side authentication.
|
||||
*
|
||||
* Server side authenticators are called from authenticate by
|
||||
* using the client auth struct flavor field to index into svcauthsw.
|
||||
* The server auth flavors must implement a routine that looks
|
||||
* like:
|
||||
*
|
||||
* enum auth_stat
|
||||
* flavorx_auth(rqst, msg)
|
||||
* struct svc_req *rqst;
|
||||
* struct rpc_msg *msg;
|
||||
*
|
||||
*/
|
||||
|
||||
/* declarations to allow servers to specify new authentication flavors */
|
||||
struct authsvc {
|
||||
int flavor;
|
||||
enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *);
|
||||
struct authsvc *next;
|
||||
};
|
||||
static struct authsvc *Auths = NULL;
|
||||
|
||||
struct svc_auth_ops svc_auth_null_ops;
|
||||
|
||||
/*
|
||||
* The call rpc message, msg has been obtained from the wire. The msg contains
|
||||
* the raw form of credentials and verifiers. authenticate returns AUTH_OK
|
||||
* if the msg is successfully authenticated. If AUTH_OK then the routine also
|
||||
* does the following things:
|
||||
* set rqst->rq_xprt->verf to the appropriate response verifier;
|
||||
* sets rqst->rq_client_cred to the "cooked" form of the credentials.
|
||||
*
|
||||
* NB: rqst->rq_cxprt->verf must be pre-alloctaed;
|
||||
* its length is set appropriately.
|
||||
*
|
||||
* The caller still owns and is responsible for msg->u.cmb.cred and
|
||||
* msg->u.cmb.verf. The authentication system retains ownership of
|
||||
* rqst->rq_client_cred, the cooked credentials.
|
||||
*
|
||||
* There is an assumption that any flavour less than AUTH_NULL is
|
||||
* invalid.
|
||||
*/
|
||||
enum auth_stat
|
||||
_authenticate(rqst, msg)
|
||||
struct svc_req *rqst;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
int cred_flavor;
|
||||
struct authsvc *asp;
|
||||
enum auth_stat dummy;
|
||||
|
||||
/* VARIABLES PROTECTED BY authsvc_lock: asp, Auths */
|
||||
|
||||
rqst->rq_cred = msg->rm_call.cb_cred;
|
||||
SVC_AUTH(rqst->rq_xprt).svc_ah_ops = &svc_auth_null_ops;
|
||||
SVC_AUTH(rqst->rq_xprt).svc_ah_private = NULL;
|
||||
rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
|
||||
rqst->rq_xprt->xp_verf.oa_length = 0;
|
||||
cred_flavor = rqst->rq_cred.oa_flavor;
|
||||
switch (cred_flavor) {
|
||||
case AUTH_NULL:
|
||||
dummy = _svcauth_null(rqst, msg);
|
||||
return (dummy);
|
||||
case AUTH_SYS:
|
||||
dummy = _svcauth_unix(rqst, msg);
|
||||
return (dummy);
|
||||
case AUTH_SHORT:
|
||||
dummy = _svcauth_short(rqst, msg);
|
||||
return (dummy);
|
||||
#ifdef DES_BUILTIN
|
||||
case AUTH_DES:
|
||||
dummy = _svcauth_des(rqst, msg);
|
||||
return (dummy);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* flavor doesn't match any of the builtin types, so try new ones */
|
||||
mutex_lock(&authsvc_lock);
|
||||
for (asp = Auths; asp; asp = asp->next) {
|
||||
if (asp->flavor == cred_flavor) {
|
||||
enum auth_stat as;
|
||||
|
||||
as = (*asp->handler)(rqst, msg);
|
||||
mutex_unlock(&authsvc_lock);
|
||||
return (as);
|
||||
}
|
||||
}
|
||||
mutex_unlock(&authsvc_lock);
|
||||
|
||||
return (AUTH_REJECTEDCRED);
|
||||
}
|
||||
|
||||
/*
|
||||
* A set of null auth methods used by any authentication protocols
|
||||
* that don't need to inspect or modify the message body.
|
||||
*/
|
||||
static bool_t
|
||||
svcauth_null_wrap(auth, xdrs, xdr_func, xdr_ptr)
|
||||
SVCAUTH *auth;
|
||||
XDR *xdrs;
|
||||
xdrproc_t xdr_func;
|
||||
caddr_t xdr_ptr;
|
||||
{
|
||||
|
||||
return (xdr_func(xdrs, xdr_ptr));
|
||||
}
|
||||
|
||||
struct svc_auth_ops svc_auth_null_ops = {
|
||||
svcauth_null_wrap,
|
||||
svcauth_null_wrap,
|
||||
};
|
||||
|
||||
/*ARGSUSED*/
|
||||
enum auth_stat
|
||||
_svcauth_null(rqst, msg)
|
||||
struct svc_req *rqst;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
return (AUTH_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allow the rpc service to register new authentication types that it is
|
||||
* prepared to handle. When an authentication flavor is registered,
|
||||
* the flavor is checked against already registered values. If not
|
||||
* registered, then a new Auths entry is added on the list.
|
||||
*
|
||||
* There is no provision to delete a registration once registered.
|
||||
*
|
||||
* This routine returns:
|
||||
* 0 if registration successful
|
||||
* 1 if flavor already registered
|
||||
* -1 if can't register (errno set)
|
||||
*/
|
||||
|
||||
int
|
||||
svc_auth_reg(cred_flavor, handler)
|
||||
int cred_flavor;
|
||||
enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *);
|
||||
{
|
||||
struct authsvc *asp;
|
||||
|
||||
switch (cred_flavor) {
|
||||
case AUTH_NULL:
|
||||
case AUTH_SYS:
|
||||
case AUTH_SHORT:
|
||||
#ifdef DES_BUILTIN
|
||||
case AUTH_DES:
|
||||
#endif
|
||||
/* already registered */
|
||||
return (1);
|
||||
|
||||
default:
|
||||
mutex_lock(&authsvc_lock);
|
||||
for (asp = Auths; asp; asp = asp->next) {
|
||||
if (asp->flavor == cred_flavor) {
|
||||
/* already registered */
|
||||
mutex_unlock(&authsvc_lock);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* this is a new one, so go ahead and register it */
|
||||
asp = mem_alloc(sizeof (*asp));
|
||||
if (asp == NULL) {
|
||||
mutex_unlock(&authsvc_lock);
|
||||
return (-1);
|
||||
}
|
||||
asp->flavor = cred_flavor;
|
||||
asp->handler = handler;
|
||||
asp->next = Auths;
|
||||
Auths = asp;
|
||||
mutex_unlock(&authsvc_lock);
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
539
freebsd/lib/libc/rpc/svc_auth_des.c
Normal file
539
freebsd/lib/libc/rpc/svc_auth_des.c
Normal file
@ -0,0 +1,539 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* svcauth_des.c, server-side des authentication
|
||||
*
|
||||
* We insure for the service the following:
|
||||
* (1) The timestamp microseconds do not exceed 1 million.
|
||||
* (2) The timestamp plus the window is less than the current time.
|
||||
* (3) The timestamp is not less than the one previously
|
||||
* seen in the current session.
|
||||
*
|
||||
* It is up to the server to determine if the window size is
|
||||
* too small .
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <rpc/des_crypt.h>
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <netinet/in.h>
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/auth_des.h>
|
||||
#include <rpc/svc.h>
|
||||
#include <rpc/rpc_msg.h>
|
||||
#include <rpc/svc_auth.h>
|
||||
#include "libc_private.h"
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)svcauth_des.c 2.3 89/07/11 4.0 RPCSRC; from 1.15 88/02/08 SMI";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
extern int key_decryptsession_pk(const char *, netobj *, des_block *);
|
||||
|
||||
#define debug(msg) printf("svcauth_des: %s\n", msg)
|
||||
|
||||
#define USEC_PER_SEC ((u_long) 1000000L)
|
||||
#define BEFORE(t1, t2) timercmp(t1, t2, <)
|
||||
|
||||
/*
|
||||
* LRU cache of conversation keys and some other useful items.
|
||||
*/
|
||||
#define AUTHDES_CACHESZ 64
|
||||
struct cache_entry {
|
||||
des_block key; /* conversation key */
|
||||
char *rname; /* client's name */
|
||||
u_int window; /* credential lifetime window */
|
||||
struct timeval laststamp; /* detect replays of creds */
|
||||
char *localcred; /* generic local credential */
|
||||
};
|
||||
static struct cache_entry *authdes_cache/* [AUTHDES_CACHESZ] */;
|
||||
static short *authdes_lru/* [AUTHDES_CACHESZ] */;
|
||||
|
||||
static void cache_init(); /* initialize the cache */
|
||||
static short cache_spot(); /* find an entry in the cache */
|
||||
static void cache_ref(/*short sid*/); /* note that sid was ref'd */
|
||||
|
||||
static void invalidate(); /* invalidate entry in cache */
|
||||
|
||||
/*
|
||||
* cache statistics
|
||||
*/
|
||||
static struct {
|
||||
u_long ncachehits; /* times cache hit, and is not replay */
|
||||
u_long ncachereplays; /* times cache hit, and is replay */
|
||||
u_long ncachemisses; /* times cache missed */
|
||||
} svcauthdes_stats;
|
||||
|
||||
/*
|
||||
* Service side authenticator for AUTH_DES
|
||||
*/
|
||||
enum auth_stat
|
||||
_svcauth_des(rqst, msg)
|
||||
struct svc_req *rqst;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
|
||||
long *ixdr;
|
||||
des_block cryptbuf[2];
|
||||
struct authdes_cred *cred;
|
||||
struct authdes_verf verf;
|
||||
int status;
|
||||
struct cache_entry *entry;
|
||||
short sid = 0;
|
||||
des_block *sessionkey;
|
||||
des_block ivec;
|
||||
u_int window;
|
||||
struct timeval timestamp;
|
||||
u_long namelen;
|
||||
struct area {
|
||||
struct authdes_cred area_cred;
|
||||
char area_netname[MAXNETNAMELEN+1];
|
||||
} *area;
|
||||
|
||||
if (authdes_cache == NULL) {
|
||||
cache_init();
|
||||
}
|
||||
|
||||
area = (struct area *)rqst->rq_clntcred;
|
||||
cred = (struct authdes_cred *)&area->area_cred;
|
||||
|
||||
/*
|
||||
* Get the credential
|
||||
*/
|
||||
ixdr = (long *)msg->rm_call.cb_cred.oa_base;
|
||||
cred->adc_namekind = IXDR_GET_ENUM(ixdr, enum authdes_namekind);
|
||||
switch (cred->adc_namekind) {
|
||||
case ADN_FULLNAME:
|
||||
namelen = IXDR_GET_U_LONG(ixdr);
|
||||
if (namelen > MAXNETNAMELEN) {
|
||||
return (AUTH_BADCRED);
|
||||
}
|
||||
cred->adc_fullname.name = area->area_netname;
|
||||
bcopy((char *)ixdr, cred->adc_fullname.name,
|
||||
(u_int)namelen);
|
||||
cred->adc_fullname.name[namelen] = 0;
|
||||
ixdr += (RNDUP(namelen) / BYTES_PER_XDR_UNIT);
|
||||
cred->adc_fullname.key.key.high = (u_long)*ixdr++;
|
||||
cred->adc_fullname.key.key.low = (u_long)*ixdr++;
|
||||
cred->adc_fullname.window = (u_long)*ixdr++;
|
||||
break;
|
||||
case ADN_NICKNAME:
|
||||
cred->adc_nickname = (u_long)*ixdr++;
|
||||
break;
|
||||
default:
|
||||
return (AUTH_BADCRED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the verifier
|
||||
*/
|
||||
ixdr = (long *)msg->rm_call.cb_verf.oa_base;
|
||||
verf.adv_xtimestamp.key.high = (u_long)*ixdr++;
|
||||
verf.adv_xtimestamp.key.low = (u_long)*ixdr++;
|
||||
verf.adv_int_u = (u_long)*ixdr++;
|
||||
|
||||
|
||||
/*
|
||||
* Get the conversation key
|
||||
*/
|
||||
if (cred->adc_namekind == ADN_FULLNAME) {
|
||||
netobj pkey;
|
||||
char pkey_data[1024];
|
||||
|
||||
sessionkey = &cred->adc_fullname.key;
|
||||
if (! getpublickey(cred->adc_fullname.name, pkey_data)) {
|
||||
debug("getpublickey");
|
||||
return(AUTH_BADCRED);
|
||||
}
|
||||
pkey.n_bytes = pkey_data;
|
||||
pkey.n_len = strlen(pkey_data) + 1;
|
||||
if (key_decryptsession_pk(cred->adc_fullname.name, &pkey,
|
||||
sessionkey) < 0) {
|
||||
debug("decryptsessionkey");
|
||||
return (AUTH_BADCRED); /* key not found */
|
||||
}
|
||||
} else { /* ADN_NICKNAME */
|
||||
sid = (short)cred->adc_nickname;
|
||||
if (sid < 0 || sid >= AUTHDES_CACHESZ) {
|
||||
debug("bad nickname");
|
||||
return (AUTH_BADCRED); /* garbled credential */
|
||||
}
|
||||
sessionkey = &authdes_cache[sid].key;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Decrypt the timestamp
|
||||
*/
|
||||
cryptbuf[0] = verf.adv_xtimestamp;
|
||||
if (cred->adc_namekind == ADN_FULLNAME) {
|
||||
cryptbuf[1].key.high = cred->adc_fullname.window;
|
||||
cryptbuf[1].key.low = verf.adv_winverf;
|
||||
ivec.key.high = ivec.key.low = 0;
|
||||
status = cbc_crypt((char *)sessionkey, (char *)cryptbuf,
|
||||
2*sizeof(des_block), DES_DECRYPT | DES_HW,
|
||||
(char *)&ivec);
|
||||
} else {
|
||||
status = ecb_crypt((char *)sessionkey, (char *)cryptbuf,
|
||||
sizeof(des_block), DES_DECRYPT | DES_HW);
|
||||
}
|
||||
if (DES_FAILED(status)) {
|
||||
debug("decryption failure");
|
||||
return (AUTH_FAILED); /* system error */
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR the decrypted timestamp
|
||||
*/
|
||||
ixdr = (long *)cryptbuf;
|
||||
timestamp.tv_sec = IXDR_GET_LONG(ixdr);
|
||||
timestamp.tv_usec = IXDR_GET_LONG(ixdr);
|
||||
|
||||
/*
|
||||
* Check for valid credentials and verifiers.
|
||||
* They could be invalid because the key was flushed
|
||||
* out of the cache, and so a new session should begin.
|
||||
* Be sure and send AUTH_REJECTED{CRED, VERF} if this is the case.
|
||||
*/
|
||||
{
|
||||
struct timeval current;
|
||||
int nick;
|
||||
int winverf;
|
||||
|
||||
if (cred->adc_namekind == ADN_FULLNAME) {
|
||||
window = IXDR_GET_U_LONG(ixdr);
|
||||
winverf = IXDR_GET_U_LONG(ixdr);
|
||||
if (winverf != window - 1) {
|
||||
debug("window verifier mismatch");
|
||||
return (AUTH_BADCRED); /* garbled credential */
|
||||
}
|
||||
sid = cache_spot(sessionkey, cred->adc_fullname.name,
|
||||
×tamp);
|
||||
if (sid < 0) {
|
||||
debug("replayed credential");
|
||||
return (AUTH_REJECTEDCRED); /* replay */
|
||||
}
|
||||
nick = 0;
|
||||
} else { /* ADN_NICKNAME */
|
||||
window = authdes_cache[sid].window;
|
||||
nick = 1;
|
||||
}
|
||||
|
||||
if ((u_long)timestamp.tv_usec >= USEC_PER_SEC) {
|
||||
debug("invalid usecs");
|
||||
/* cached out (bad key), or garbled verifier */
|
||||
return (nick ? AUTH_REJECTEDVERF : AUTH_BADVERF);
|
||||
}
|
||||
if (nick && BEFORE(×tamp,
|
||||
&authdes_cache[sid].laststamp)) {
|
||||
debug("timestamp before last seen");
|
||||
return (AUTH_REJECTEDVERF); /* replay */
|
||||
}
|
||||
(void) gettimeofday(¤t, (struct timezone *)NULL);
|
||||
current.tv_sec -= window; /* allow for expiration */
|
||||
if (!BEFORE(¤t, ×tamp)) {
|
||||
debug("timestamp expired");
|
||||
/* replay, or garbled credential */
|
||||
return (nick ? AUTH_REJECTEDVERF : AUTH_BADCRED);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the reply verifier
|
||||
*/
|
||||
verf.adv_nickname = (u_long)sid;
|
||||
|
||||
/*
|
||||
* xdr the timestamp before encrypting
|
||||
*/
|
||||
ixdr = (long *)cryptbuf;
|
||||
IXDR_PUT_LONG(ixdr, timestamp.tv_sec - 1);
|
||||
IXDR_PUT_LONG(ixdr, timestamp.tv_usec);
|
||||
|
||||
/*
|
||||
* encrypt the timestamp
|
||||
*/
|
||||
status = ecb_crypt((char *)sessionkey, (char *)cryptbuf,
|
||||
sizeof(des_block), DES_ENCRYPT | DES_HW);
|
||||
if (DES_FAILED(status)) {
|
||||
debug("encryption failure");
|
||||
return (AUTH_FAILED); /* system error */
|
||||
}
|
||||
verf.adv_xtimestamp = cryptbuf[0];
|
||||
|
||||
/*
|
||||
* Serialize the reply verifier, and update rqst
|
||||
*/
|
||||
ixdr = (long *)msg->rm_call.cb_verf.oa_base;
|
||||
*ixdr++ = (long)verf.adv_xtimestamp.key.high;
|
||||
*ixdr++ = (long)verf.adv_xtimestamp.key.low;
|
||||
*ixdr++ = (long)verf.adv_int_u;
|
||||
|
||||
rqst->rq_xprt->xp_verf.oa_flavor = AUTH_DES;
|
||||
rqst->rq_xprt->xp_verf.oa_base = msg->rm_call.cb_verf.oa_base;
|
||||
rqst->rq_xprt->xp_verf.oa_length =
|
||||
(char *)ixdr - msg->rm_call.cb_verf.oa_base;
|
||||
|
||||
/*
|
||||
* We succeeded, commit the data to the cache now and
|
||||
* finish cooking the credential.
|
||||
*/
|
||||
entry = &authdes_cache[sid];
|
||||
entry->laststamp = timestamp;
|
||||
cache_ref(sid);
|
||||
if (cred->adc_namekind == ADN_FULLNAME) {
|
||||
cred->adc_fullname.window = window;
|
||||
cred->adc_nickname = (u_long)sid; /* save nickname */
|
||||
if (entry->rname != NULL) {
|
||||
mem_free(entry->rname, strlen(entry->rname) + 1);
|
||||
}
|
||||
entry->rname = (char *)mem_alloc((u_int)strlen(cred->adc_fullname.name)
|
||||
+ 1);
|
||||
if (entry->rname != NULL) {
|
||||
(void) strcpy(entry->rname, cred->adc_fullname.name);
|
||||
} else {
|
||||
debug("out of memory");
|
||||
}
|
||||
entry->key = *sessionkey;
|
||||
entry->window = window;
|
||||
invalidate(entry->localcred); /* mark any cached cred invalid */
|
||||
} else { /* ADN_NICKNAME */
|
||||
/*
|
||||
* nicknames are cooked into fullnames
|
||||
*/
|
||||
cred->adc_namekind = ADN_FULLNAME;
|
||||
cred->adc_fullname.name = entry->rname;
|
||||
cred->adc_fullname.key = entry->key;
|
||||
cred->adc_fullname.window = entry->window;
|
||||
}
|
||||
return (AUTH_OK); /* we made it!*/
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the cache
|
||||
*/
|
||||
static void
|
||||
cache_init()
|
||||
{
|
||||
int i;
|
||||
|
||||
authdes_cache = (struct cache_entry *)
|
||||
mem_alloc(sizeof(struct cache_entry) * AUTHDES_CACHESZ);
|
||||
bzero((char *)authdes_cache,
|
||||
sizeof(struct cache_entry) * AUTHDES_CACHESZ);
|
||||
|
||||
authdes_lru = (short *)mem_alloc(sizeof(short) * AUTHDES_CACHESZ);
|
||||
/*
|
||||
* Initialize the lru list
|
||||
*/
|
||||
for (i = 0; i < AUTHDES_CACHESZ; i++) {
|
||||
authdes_lru[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Find the lru victim
|
||||
*/
|
||||
static short
|
||||
cache_victim()
|
||||
{
|
||||
return (authdes_lru[AUTHDES_CACHESZ-1]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that sid was referenced
|
||||
*/
|
||||
static void
|
||||
cache_ref(sid)
|
||||
short sid;
|
||||
{
|
||||
int i;
|
||||
short curr;
|
||||
short prev;
|
||||
|
||||
prev = authdes_lru[0];
|
||||
authdes_lru[0] = sid;
|
||||
for (i = 1; prev != sid; i++) {
|
||||
curr = authdes_lru[i];
|
||||
authdes_lru[i] = prev;
|
||||
prev = curr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Find a spot in the cache for a credential containing
|
||||
* the items given. Return -1 if a replay is detected, otherwise
|
||||
* return the spot in the cache.
|
||||
*/
|
||||
static short
|
||||
cache_spot(key, name, timestamp)
|
||||
des_block *key;
|
||||
char *name;
|
||||
struct timeval *timestamp;
|
||||
{
|
||||
struct cache_entry *cp;
|
||||
int i;
|
||||
u_long hi;
|
||||
|
||||
hi = key->key.high;
|
||||
for (cp = authdes_cache, i = 0; i < AUTHDES_CACHESZ; i++, cp++) {
|
||||
if (cp->key.key.high == hi &&
|
||||
cp->key.key.low == key->key.low &&
|
||||
cp->rname != NULL &&
|
||||
bcmp(cp->rname, name, strlen(name) + 1) == 0) {
|
||||
if (BEFORE(timestamp, &cp->laststamp)) {
|
||||
svcauthdes_stats.ncachereplays++;
|
||||
return (-1); /* replay */
|
||||
}
|
||||
svcauthdes_stats.ncachehits++;
|
||||
return (i); /* refresh */
|
||||
}
|
||||
}
|
||||
svcauthdes_stats.ncachemisses++;
|
||||
return (cache_victim()); /* new credential */
|
||||
}
|
||||
|
||||
|
||||
#if (defined(sun) || defined(vax) || defined(__FreeBSD__))
|
||||
/*
|
||||
* Local credential handling stuff.
|
||||
* NOTE: bsd unix dependent.
|
||||
* Other operating systems should put something else here.
|
||||
*/
|
||||
#define UNKNOWN -2 /* grouplen, if cached cred is unknown user */
|
||||
#define INVALID -1 /* grouplen, if cache entry is invalid */
|
||||
|
||||
struct bsdcred {
|
||||
uid_t uid; /* cached uid */
|
||||
gid_t gid; /* cached gid */
|
||||
int grouplen; /* length of cached groups */
|
||||
gid_t groups[NGRPS]; /* cached groups */
|
||||
};
|
||||
|
||||
/*
|
||||
* Map a des credential into a unix cred.
|
||||
* We cache the credential here so the application does
|
||||
* not have to make an rpc call every time to interpret
|
||||
* the credential.
|
||||
*/
|
||||
int
|
||||
authdes_getucred(adc, uid, gid, grouplen, groups)
|
||||
struct authdes_cred *adc;
|
||||
uid_t *uid;
|
||||
gid_t *gid;
|
||||
int *grouplen;
|
||||
gid_t *groups;
|
||||
{
|
||||
unsigned sid;
|
||||
int i;
|
||||
uid_t i_uid;
|
||||
gid_t i_gid;
|
||||
int i_grouplen;
|
||||
struct bsdcred *cred;
|
||||
|
||||
sid = adc->adc_nickname;
|
||||
if (sid >= AUTHDES_CACHESZ) {
|
||||
debug("invalid nickname");
|
||||
return (0);
|
||||
}
|
||||
cred = (struct bsdcred *)authdes_cache[sid].localcred;
|
||||
if (cred == NULL) {
|
||||
cred = (struct bsdcred *)mem_alloc(sizeof(struct bsdcred));
|
||||
authdes_cache[sid].localcred = (char *)cred;
|
||||
cred->grouplen = INVALID;
|
||||
}
|
||||
if (cred->grouplen == INVALID) {
|
||||
/*
|
||||
* not in cache: lookup
|
||||
*/
|
||||
if (!netname2user(adc->adc_fullname.name, &i_uid, &i_gid,
|
||||
&i_grouplen, groups))
|
||||
{
|
||||
debug("unknown netname");
|
||||
cred->grouplen = UNKNOWN; /* mark as lookup up, but not found */
|
||||
return (0);
|
||||
}
|
||||
debug("missed ucred cache");
|
||||
*uid = cred->uid = i_uid;
|
||||
*gid = cred->gid = i_gid;
|
||||
*grouplen = cred->grouplen = i_grouplen;
|
||||
for (i = i_grouplen - 1; i >= 0; i--) {
|
||||
cred->groups[i] = groups[i]; /* int to short */
|
||||
}
|
||||
return (1);
|
||||
} else if (cred->grouplen == UNKNOWN) {
|
||||
/*
|
||||
* Already lookup up, but no match found
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* cached credentials
|
||||
*/
|
||||
*uid = cred->uid;
|
||||
*gid = cred->gid;
|
||||
*grouplen = cred->grouplen;
|
||||
for (i = cred->grouplen - 1; i >= 0; i--) {
|
||||
groups[i] = cred->groups[i]; /* short to int */
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
invalidate(cred)
|
||||
char *cred;
|
||||
{
|
||||
if (cred == NULL) {
|
||||
return;
|
||||
}
|
||||
((struct bsdcred *)cred)->grouplen = INVALID;
|
||||
}
|
||||
#endif
|
||||
|
157
freebsd/lib/libc/rpc/svc_auth_unix.c
Normal file
157
freebsd/lib/libc/rpc/svc_auth_unix.c
Normal file
@ -0,0 +1,157 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_auth_unix.c
|
||||
* Handles UNIX flavor authentication parameters on the service side of rpc.
|
||||
* There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
|
||||
* _svcauth_unix does full blown unix style uid,gid+gids auth,
|
||||
* _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
|
||||
* Note: the shorthand has been gutted for efficiency.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/*
|
||||
* Unix longhand authenticator
|
||||
*/
|
||||
enum auth_stat
|
||||
_svcauth_unix(rqst, msg)
|
||||
struct svc_req *rqst;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
enum auth_stat stat;
|
||||
XDR xdrs;
|
||||
struct authunix_parms *aup;
|
||||
int32_t *buf;
|
||||
struct area {
|
||||
struct authunix_parms area_aup;
|
||||
char area_machname[MAX_MACHINE_NAME+1];
|
||||
u_int area_gids[NGRPS];
|
||||
} *area;
|
||||
u_int auth_len;
|
||||
size_t str_len, gid_len;
|
||||
u_int i;
|
||||
|
||||
assert(rqst != NULL);
|
||||
assert(msg != NULL);
|
||||
|
||||
area = (struct area *) rqst->rq_clntcred;
|
||||
aup = &area->area_aup;
|
||||
aup->aup_machname = area->area_machname;
|
||||
aup->aup_gids = area->area_gids;
|
||||
auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
|
||||
xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
|
||||
buf = XDR_INLINE(&xdrs, auth_len);
|
||||
if (buf != NULL) {
|
||||
aup->aup_time = IXDR_GET_INT32(buf);
|
||||
str_len = (size_t)IXDR_GET_U_INT32(buf);
|
||||
if (str_len > MAX_MACHINE_NAME) {
|
||||
stat = AUTH_BADCRED;
|
||||
goto done;
|
||||
}
|
||||
memmove(aup->aup_machname, buf, str_len);
|
||||
aup->aup_machname[str_len] = 0;
|
||||
str_len = RNDUP(str_len);
|
||||
buf += str_len / sizeof (int32_t);
|
||||
aup->aup_uid = (int)IXDR_GET_INT32(buf);
|
||||
aup->aup_gid = (int)IXDR_GET_INT32(buf);
|
||||
gid_len = (size_t)IXDR_GET_U_INT32(buf);
|
||||
if (gid_len > NGRPS) {
|
||||
stat = AUTH_BADCRED;
|
||||
goto done;
|
||||
}
|
||||
aup->aup_len = gid_len;
|
||||
for (i = 0; i < gid_len; i++) {
|
||||
aup->aup_gids[i] = (int)IXDR_GET_INT32(buf);
|
||||
}
|
||||
/*
|
||||
* five is the smallest unix credentials structure -
|
||||
* timestamp, hostname len (0), uid, gid, and gids len (0).
|
||||
*/
|
||||
if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
|
||||
(void) printf("bad auth_len gid %ld str %ld auth %u\n",
|
||||
(long)gid_len, (long)str_len, auth_len);
|
||||
stat = AUTH_BADCRED;
|
||||
goto done;
|
||||
}
|
||||
} else if (! xdr_authunix_parms(&xdrs, aup)) {
|
||||
xdrs.x_op = XDR_FREE;
|
||||
(void)xdr_authunix_parms(&xdrs, aup);
|
||||
stat = AUTH_BADCRED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* get the verifier */
|
||||
if ((u_int)msg->rm_call.cb_verf.oa_length) {
|
||||
rqst->rq_xprt->xp_verf.oa_flavor =
|
||||
msg->rm_call.cb_verf.oa_flavor;
|
||||
rqst->rq_xprt->xp_verf.oa_base =
|
||||
msg->rm_call.cb_verf.oa_base;
|
||||
rqst->rq_xprt->xp_verf.oa_length =
|
||||
msg->rm_call.cb_verf.oa_length;
|
||||
} else {
|
||||
rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
|
||||
rqst->rq_xprt->xp_verf.oa_length = 0;
|
||||
}
|
||||
stat = AUTH_OK;
|
||||
done:
|
||||
XDR_DESTROY(&xdrs);
|
||||
return (stat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Shorthand unix authenticator
|
||||
* Looks up longhand in a cache.
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
enum auth_stat
|
||||
_svcauth_short(rqst, msg)
|
||||
struct svc_req *rqst;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
return (AUTH_REJECTEDCRED);
|
||||
}
|
740
freebsd/lib/libc/rpc/svc_dg.c
Normal file
740
freebsd/lib/libc/rpc/svc_dg.c
Normal file
@ -0,0 +1,740 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_dg.c,v 1.4 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#ident "@(#)svc_dg.c 1.17 94/04/24 SMI"
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_dg.c, Server side for connectionless RPC.
|
||||
*
|
||||
* Does some caching in the hopes of achieving execute-at-most-once semantics.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/svc_dg.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef RPC_CACHE_DEBUG
|
||||
#include <netconfig.h>
|
||||
#include <netdir.h>
|
||||
#endif
|
||||
#include <err.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#define su_data(xprt) ((struct svc_dg_data *)(xprt->xp_p2))
|
||||
#define rpc_buffer(xprt) ((xprt)->xp_p1)
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
static void svc_dg_ops(SVCXPRT *);
|
||||
static enum xprt_stat svc_dg_stat(SVCXPRT *);
|
||||
static bool_t svc_dg_recv(SVCXPRT *, struct rpc_msg *);
|
||||
static bool_t svc_dg_reply(SVCXPRT *, struct rpc_msg *);
|
||||
static bool_t svc_dg_getargs(SVCXPRT *, xdrproc_t, void *);
|
||||
static bool_t svc_dg_freeargs(SVCXPRT *, xdrproc_t, void *);
|
||||
static void svc_dg_destroy(SVCXPRT *);
|
||||
static bool_t svc_dg_control(SVCXPRT *, const u_int, void *);
|
||||
static int cache_get(SVCXPRT *, struct rpc_msg *, char **, size_t *);
|
||||
static void cache_set(SVCXPRT *, size_t);
|
||||
int svc_dg_enablecache(SVCXPRT *, u_int);
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* xprt = svc_dg_create(sock, sendsize, recvsize);
|
||||
* Does other connectionless specific initializations.
|
||||
* Once *xprt is initialized, it is registered.
|
||||
* see (svc.h, xprt_register). If recvsize or sendsize are 0 suitable
|
||||
* system defaults are chosen.
|
||||
* The routines returns NULL if a problem occurred.
|
||||
*/
|
||||
static const char svc_dg_str[] = "svc_dg_create: %s";
|
||||
static const char svc_dg_err1[] = "could not get transport information";
|
||||
static const char svc_dg_err2[] = "transport does not support data transfer";
|
||||
static const char svc_dg_err3[] = "getsockname failed";
|
||||
static const char svc_dg_err4[] = "cannot set IP_RECVDSTADDR";
|
||||
static const char __no_mem_str[] = "out of memory";
|
||||
|
||||
SVCXPRT *
|
||||
svc_dg_create(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
struct svc_dg_data *su = NULL;
|
||||
struct __rpc_sockinfo si;
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen;
|
||||
|
||||
if (!__rpc_fd2sockinfo(fd, &si)) {
|
||||
warnx(svc_dg_str, svc_dg_err1);
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
* Find the receive and the send size
|
||||
*/
|
||||
sendsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsize);
|
||||
recvsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsize);
|
||||
if ((sendsize == 0) || (recvsize == 0)) {
|
||||
warnx(svc_dg_str, svc_dg_err2);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
xprt = svc_xprt_alloc();
|
||||
if (xprt == NULL)
|
||||
goto freedata;
|
||||
|
||||
su = mem_alloc(sizeof (*su));
|
||||
if (su == NULL)
|
||||
goto freedata;
|
||||
su->su_iosz = ((MAX(sendsize, recvsize) + 3) / 4) * 4;
|
||||
if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL)
|
||||
goto freedata;
|
||||
xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
|
||||
XDR_DECODE);
|
||||
su->su_cache = NULL;
|
||||
xprt->xp_fd = fd;
|
||||
xprt->xp_p2 = su;
|
||||
xprt->xp_verf.oa_base = su->su_verfbody;
|
||||
svc_dg_ops(xprt);
|
||||
xprt->xp_rtaddr.maxlen = sizeof (struct sockaddr_storage);
|
||||
|
||||
slen = sizeof ss;
|
||||
if (_getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
|
||||
warnx(svc_dg_str, svc_dg_err3);
|
||||
goto freedata_nowarn;
|
||||
}
|
||||
xprt->xp_ltaddr.buf = mem_alloc(sizeof (struct sockaddr_storage));
|
||||
xprt->xp_ltaddr.maxlen = sizeof (struct sockaddr_storage);
|
||||
xprt->xp_ltaddr.len = slen;
|
||||
memcpy(xprt->xp_ltaddr.buf, &ss, slen);
|
||||
|
||||
if (ss.ss_family == AF_INET) {
|
||||
struct sockaddr_in *sin;
|
||||
static const int true_value = 1;
|
||||
|
||||
sin = (struct sockaddr_in *)(void *)&ss;
|
||||
if (sin->sin_addr.s_addr == INADDR_ANY) {
|
||||
su->su_srcaddr.buf = mem_alloc(sizeof (ss));
|
||||
su->su_srcaddr.maxlen = sizeof (ss);
|
||||
|
||||
if (_setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR,
|
||||
&true_value, sizeof(true_value))) {
|
||||
warnx(svc_dg_str, svc_dg_err4);
|
||||
goto freedata_nowarn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xprt_register(xprt);
|
||||
return (xprt);
|
||||
freedata:
|
||||
(void) warnx(svc_dg_str, __no_mem_str);
|
||||
freedata_nowarn:
|
||||
if (xprt) {
|
||||
if (su)
|
||||
(void) mem_free(su, sizeof (*su));
|
||||
svc_xprt_free(xprt);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static enum xprt_stat
|
||||
svc_dg_stat(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
return (XPRT_IDLE);
|
||||
}
|
||||
|
||||
static int
|
||||
svc_dg_recvfrom(int fd, char *buf, int buflen,
|
||||
struct sockaddr *raddr, socklen_t *raddrlen,
|
||||
struct sockaddr *laddr, socklen_t *laddrlen)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec msg_iov[1];
|
||||
struct sockaddr_in *lin = (struct sockaddr_in *)laddr;
|
||||
int rlen;
|
||||
bool_t have_lin = FALSE;
|
||||
char tmp[CMSG_LEN(sizeof(*lin))];
|
||||
struct cmsghdr *cmsg;
|
||||
|
||||
memset((char *)&msg, 0, sizeof(msg));
|
||||
msg_iov[0].iov_base = buf;
|
||||
msg_iov[0].iov_len = buflen;
|
||||
msg.msg_iov = msg_iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_namelen = *raddrlen;
|
||||
msg.msg_name = (char *)raddr;
|
||||
if (laddr != NULL) {
|
||||
msg.msg_control = (caddr_t)tmp;
|
||||
msg.msg_controllen = CMSG_LEN(sizeof(*lin));
|
||||
}
|
||||
rlen = _recvmsg(fd, &msg, 0);
|
||||
if (rlen >= 0)
|
||||
*raddrlen = msg.msg_namelen;
|
||||
|
||||
if (rlen == -1 || laddr == NULL ||
|
||||
msg.msg_controllen < sizeof(struct cmsghdr) ||
|
||||
msg.msg_flags & MSG_CTRUNC)
|
||||
return rlen;
|
||||
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
||||
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
if (cmsg->cmsg_level == IPPROTO_IP &&
|
||||
cmsg->cmsg_type == IP_RECVDSTADDR) {
|
||||
have_lin = TRUE;
|
||||
memcpy(&lin->sin_addr,
|
||||
(struct in_addr *)CMSG_DATA(cmsg),
|
||||
sizeof(struct in_addr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lin->sin_family = AF_INET;
|
||||
lin->sin_port = 0;
|
||||
*laddrlen = sizeof(struct sockaddr_in);
|
||||
|
||||
if (!have_lin)
|
||||
lin->sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
return rlen;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_dg_recv(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
struct svc_dg_data *su = su_data(xprt);
|
||||
XDR *xdrs = &(su->su_xdrs);
|
||||
char *reply;
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t alen;
|
||||
size_t replylen;
|
||||
ssize_t rlen;
|
||||
|
||||
again:
|
||||
alen = sizeof (struct sockaddr_storage);
|
||||
rlen = svc_dg_recvfrom(xprt->xp_fd, rpc_buffer(xprt), su->su_iosz,
|
||||
(struct sockaddr *)(void *)&ss, &alen,
|
||||
(struct sockaddr *)su->su_srcaddr.buf, &su->su_srcaddr.len);
|
||||
if (rlen == -1 && errno == EINTR)
|
||||
goto again;
|
||||
if (rlen == -1 || (rlen < (ssize_t)(4 * sizeof (u_int32_t))))
|
||||
return (FALSE);
|
||||
if (xprt->xp_rtaddr.len < alen) {
|
||||
if (xprt->xp_rtaddr.len != 0)
|
||||
mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.len);
|
||||
xprt->xp_rtaddr.buf = mem_alloc(alen);
|
||||
xprt->xp_rtaddr.len = alen;
|
||||
}
|
||||
memcpy(xprt->xp_rtaddr.buf, &ss, alen);
|
||||
#ifdef PORTMAP
|
||||
if (ss.ss_family == AF_INET) {
|
||||
xprt->xp_raddr = *(struct sockaddr_in *)xprt->xp_rtaddr.buf;
|
||||
xprt->xp_addrlen = sizeof (struct sockaddr_in);
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
xdrs->x_op = XDR_DECODE;
|
||||
XDR_SETPOS(xdrs, 0);
|
||||
if (! xdr_callmsg(xdrs, msg)) {
|
||||
return (FALSE);
|
||||
}
|
||||
su->su_xid = msg->rm_xid;
|
||||
if (su->su_cache != NULL) {
|
||||
if (cache_get(xprt, msg, &reply, &replylen)) {
|
||||
(void)_sendto(xprt->xp_fd, reply, replylen, 0,
|
||||
(struct sockaddr *)(void *)&ss, alen);
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
svc_dg_sendto(int fd, char *buf, int buflen,
|
||||
const struct sockaddr *raddr, socklen_t raddrlen,
|
||||
const struct sockaddr *laddr, socklen_t laddrlen)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec msg_iov[1];
|
||||
struct sockaddr_in *laddr_in = (struct sockaddr_in *)laddr;
|
||||
struct in_addr *lin = &laddr_in->sin_addr;
|
||||
char tmp[CMSG_SPACE(sizeof(*lin))];
|
||||
struct cmsghdr *cmsg;
|
||||
|
||||
memset((char *)&msg, 0, sizeof(msg));
|
||||
msg_iov[0].iov_base = buf;
|
||||
msg_iov[0].iov_len = buflen;
|
||||
msg.msg_iov = msg_iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_namelen = raddrlen;
|
||||
msg.msg_name = (char *)raddr;
|
||||
|
||||
if (laddr != NULL && laddr->sa_family == AF_INET &&
|
||||
lin->s_addr != INADDR_ANY) {
|
||||
msg.msg_control = (caddr_t)tmp;
|
||||
msg.msg_controllen = CMSG_LEN(sizeof(*lin));
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(sizeof(*lin));
|
||||
cmsg->cmsg_level = IPPROTO_IP;
|
||||
cmsg->cmsg_type = IP_SENDSRCADDR;
|
||||
memcpy(CMSG_DATA(cmsg), lin, sizeof(*lin));
|
||||
}
|
||||
|
||||
return _sendmsg(fd, &msg, 0);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_dg_reply(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
struct svc_dg_data *su = su_data(xprt);
|
||||
XDR *xdrs = &(su->su_xdrs);
|
||||
bool_t stat = TRUE;
|
||||
size_t slen;
|
||||
xdrproc_t xdr_proc;
|
||||
caddr_t xdr_where;
|
||||
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
XDR_SETPOS(xdrs, 0);
|
||||
msg->rm_xid = su->su_xid;
|
||||
if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
|
||||
msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
|
||||
xdr_proc = msg->acpted_rply.ar_results.proc;
|
||||
xdr_where = msg->acpted_rply.ar_results.where;
|
||||
msg->acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
|
||||
msg->acpted_rply.ar_results.where = NULL;
|
||||
|
||||
if (!xdr_replymsg(xdrs, msg) ||
|
||||
!SVCAUTH_WRAP(&SVC_AUTH(xprt), xdrs, xdr_proc, xdr_where))
|
||||
stat = FALSE;
|
||||
} else {
|
||||
stat = xdr_replymsg(xdrs, msg);
|
||||
}
|
||||
if (stat) {
|
||||
slen = XDR_GETPOS(xdrs);
|
||||
if (svc_dg_sendto(xprt->xp_fd, rpc_buffer(xprt), slen,
|
||||
(struct sockaddr *)xprt->xp_rtaddr.buf,
|
||||
(socklen_t)xprt->xp_rtaddr.len,
|
||||
(struct sockaddr *)su->su_srcaddr.buf,
|
||||
(socklen_t)su->su_srcaddr.len) == (ssize_t) slen) {
|
||||
stat = TRUE;
|
||||
if (su->su_cache)
|
||||
cache_set(xprt, slen);
|
||||
}
|
||||
}
|
||||
return (stat);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_dg_getargs(xprt, xdr_args, args_ptr)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
{
|
||||
struct svc_dg_data *su;
|
||||
|
||||
assert(xprt != NULL);
|
||||
su = su_data(xprt);
|
||||
return (SVCAUTH_UNWRAP(&SVC_AUTH(xprt),
|
||||
&su->su_xdrs, xdr_args, args_ptr));
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_dg_freeargs(xprt, xdr_args, args_ptr)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
{
|
||||
XDR *xdrs = &(su_data(xprt)->su_xdrs);
|
||||
|
||||
xdrs->x_op = XDR_FREE;
|
||||
return (*xdr_args)(xdrs, args_ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
svc_dg_destroy(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct svc_dg_data *su = su_data(xprt);
|
||||
|
||||
xprt_unregister(xprt);
|
||||
if (xprt->xp_fd != -1)
|
||||
(void)_close(xprt->xp_fd);
|
||||
XDR_DESTROY(&(su->su_xdrs));
|
||||
(void) mem_free(rpc_buffer(xprt), su->su_iosz);
|
||||
if (su->su_srcaddr.buf)
|
||||
(void) mem_free(su->su_srcaddr.buf, su->su_srcaddr.maxlen);
|
||||
(void) mem_free(su, sizeof (*su));
|
||||
if (xprt->xp_rtaddr.buf)
|
||||
(void) mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.maxlen);
|
||||
if (xprt->xp_ltaddr.buf)
|
||||
(void) mem_free(xprt->xp_ltaddr.buf, xprt->xp_ltaddr.maxlen);
|
||||
if (xprt->xp_tp)
|
||||
(void) free(xprt->xp_tp);
|
||||
svc_xprt_free(xprt);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
/*ARGSUSED*/
|
||||
svc_dg_control(xprt, rq, in)
|
||||
SVCXPRT *xprt;
|
||||
const u_int rq;
|
||||
void *in;
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
svc_dg_ops(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
static struct xp_ops ops;
|
||||
static struct xp_ops2 ops2;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.xp_recv == NULL) {
|
||||
ops.xp_recv = svc_dg_recv;
|
||||
ops.xp_stat = svc_dg_stat;
|
||||
ops.xp_getargs = svc_dg_getargs;
|
||||
ops.xp_reply = svc_dg_reply;
|
||||
ops.xp_freeargs = svc_dg_freeargs;
|
||||
ops.xp_destroy = svc_dg_destroy;
|
||||
ops2.xp_control = svc_dg_control;
|
||||
}
|
||||
xprt->xp_ops = &ops;
|
||||
xprt->xp_ops2 = &ops2;
|
||||
mutex_unlock(&ops_lock);
|
||||
}
|
||||
|
||||
/* The CACHING COMPONENT */
|
||||
|
||||
/*
|
||||
* Could have been a separate file, but some part of it depends upon the
|
||||
* private structure of the client handle.
|
||||
*
|
||||
* Fifo cache for cl server
|
||||
* Copies pointers to reply buffers into fifo cache
|
||||
* Buffers are sent again if retransmissions are detected.
|
||||
*/
|
||||
|
||||
#define SPARSENESS 4 /* 75% sparse */
|
||||
|
||||
#define ALLOC(type, size) \
|
||||
(type *) mem_alloc((sizeof (type) * (size)))
|
||||
|
||||
#define MEMZERO(addr, type, size) \
|
||||
(void) memset((void *) (addr), 0, sizeof (type) * (int) (size))
|
||||
|
||||
#define FREE(addr, type, size) \
|
||||
mem_free((addr), (sizeof (type) * (size)))
|
||||
|
||||
/*
|
||||
* An entry in the cache
|
||||
*/
|
||||
typedef struct cache_node *cache_ptr;
|
||||
struct cache_node {
|
||||
/*
|
||||
* Index into cache is xid, proc, vers, prog and address
|
||||
*/
|
||||
u_int32_t cache_xid;
|
||||
rpcproc_t cache_proc;
|
||||
rpcvers_t cache_vers;
|
||||
rpcprog_t cache_prog;
|
||||
struct netbuf cache_addr;
|
||||
/*
|
||||
* The cached reply and length
|
||||
*/
|
||||
char *cache_reply;
|
||||
size_t cache_replylen;
|
||||
/*
|
||||
* Next node on the list, if there is a collision
|
||||
*/
|
||||
cache_ptr cache_next;
|
||||
};
|
||||
|
||||
/*
|
||||
* The entire cache
|
||||
*/
|
||||
struct cl_cache {
|
||||
u_int uc_size; /* size of cache */
|
||||
cache_ptr *uc_entries; /* hash table of entries in cache */
|
||||
cache_ptr *uc_fifo; /* fifo list of entries in cache */
|
||||
u_int uc_nextvictim; /* points to next victim in fifo list */
|
||||
rpcprog_t uc_prog; /* saved program number */
|
||||
rpcvers_t uc_vers; /* saved version number */
|
||||
rpcproc_t uc_proc; /* saved procedure number */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* the hashing function
|
||||
*/
|
||||
#define CACHE_LOC(transp, xid) \
|
||||
(xid % (SPARSENESS * ((struct cl_cache *) \
|
||||
su_data(transp)->su_cache)->uc_size))
|
||||
|
||||
/*
|
||||
* Enable use of the cache. Returns 1 on success, 0 on failure.
|
||||
* Note: there is no disable.
|
||||
*/
|
||||
static const char cache_enable_str[] = "svc_enablecache: %s %s";
|
||||
static const char alloc_err[] = "could not allocate cache ";
|
||||
static const char enable_err[] = "cache already enabled";
|
||||
|
||||
int
|
||||
svc_dg_enablecache(transp, size)
|
||||
SVCXPRT *transp;
|
||||
u_int size;
|
||||
{
|
||||
struct svc_dg_data *su = su_data(transp);
|
||||
struct cl_cache *uc;
|
||||
|
||||
mutex_lock(&dupreq_lock);
|
||||
if (su->su_cache != NULL) {
|
||||
(void) warnx(cache_enable_str, enable_err, " ");
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (0);
|
||||
}
|
||||
uc = ALLOC(struct cl_cache, 1);
|
||||
if (uc == NULL) {
|
||||
warnx(cache_enable_str, alloc_err, " ");
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (0);
|
||||
}
|
||||
uc->uc_size = size;
|
||||
uc->uc_nextvictim = 0;
|
||||
uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
|
||||
if (uc->uc_entries == NULL) {
|
||||
warnx(cache_enable_str, alloc_err, "data");
|
||||
FREE(uc, struct cl_cache, 1);
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (0);
|
||||
}
|
||||
MEMZERO(uc->uc_entries, cache_ptr, size * SPARSENESS);
|
||||
uc->uc_fifo = ALLOC(cache_ptr, size);
|
||||
if (uc->uc_fifo == NULL) {
|
||||
warnx(cache_enable_str, alloc_err, "fifo");
|
||||
FREE(uc->uc_entries, cache_ptr, size * SPARSENESS);
|
||||
FREE(uc, struct cl_cache, 1);
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (0);
|
||||
}
|
||||
MEMZERO(uc->uc_fifo, cache_ptr, size);
|
||||
su->su_cache = (char *)(void *)uc;
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set an entry in the cache. It assumes that the uc entry is set from
|
||||
* the earlier call to cache_get() for the same procedure. This will always
|
||||
* happen because cache_get() is calle by svc_dg_recv and cache_set() is called
|
||||
* by svc_dg_reply(). All this hoopla because the right RPC parameters are
|
||||
* not available at svc_dg_reply time.
|
||||
*/
|
||||
|
||||
static const char cache_set_str[] = "cache_set: %s";
|
||||
static const char cache_set_err1[] = "victim not found";
|
||||
static const char cache_set_err2[] = "victim alloc failed";
|
||||
static const char cache_set_err3[] = "could not allocate new rpc buffer";
|
||||
|
||||
static void
|
||||
cache_set(xprt, replylen)
|
||||
SVCXPRT *xprt;
|
||||
size_t replylen;
|
||||
{
|
||||
cache_ptr victim;
|
||||
cache_ptr *vicp;
|
||||
struct svc_dg_data *su = su_data(xprt);
|
||||
struct cl_cache *uc = (struct cl_cache *) su->su_cache;
|
||||
u_int loc;
|
||||
char *newbuf;
|
||||
#ifdef RPC_CACHE_DEBUG
|
||||
struct netconfig *nconf;
|
||||
char *uaddr;
|
||||
#endif
|
||||
|
||||
mutex_lock(&dupreq_lock);
|
||||
/*
|
||||
* Find space for the new entry, either by
|
||||
* reusing an old entry, or by mallocing a new one
|
||||
*/
|
||||
victim = uc->uc_fifo[uc->uc_nextvictim];
|
||||
if (victim != NULL) {
|
||||
loc = CACHE_LOC(xprt, victim->cache_xid);
|
||||
for (vicp = &uc->uc_entries[loc];
|
||||
*vicp != NULL && *vicp != victim;
|
||||
vicp = &(*vicp)->cache_next)
|
||||
;
|
||||
if (*vicp == NULL) {
|
||||
warnx(cache_set_str, cache_set_err1);
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return;
|
||||
}
|
||||
*vicp = victim->cache_next; /* remove from cache */
|
||||
newbuf = victim->cache_reply;
|
||||
} else {
|
||||
victim = ALLOC(struct cache_node, 1);
|
||||
if (victim == NULL) {
|
||||
warnx(cache_set_str, cache_set_err2);
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return;
|
||||
}
|
||||
newbuf = mem_alloc(su->su_iosz);
|
||||
if (newbuf == NULL) {
|
||||
warnx(cache_set_str, cache_set_err3);
|
||||
FREE(victim, struct cache_node, 1);
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Store it away
|
||||
*/
|
||||
#ifdef RPC_CACHE_DEBUG
|
||||
if (nconf = getnetconfigent(xprt->xp_netid)) {
|
||||
uaddr = taddr2uaddr(nconf, &xprt->xp_rtaddr);
|
||||
freenetconfigent(nconf);
|
||||
printf(
|
||||
"cache set for xid= %x prog=%d vers=%d proc=%d for rmtaddr=%s\n",
|
||||
su->su_xid, uc->uc_prog, uc->uc_vers,
|
||||
uc->uc_proc, uaddr);
|
||||
free(uaddr);
|
||||
}
|
||||
#endif
|
||||
victim->cache_replylen = replylen;
|
||||
victim->cache_reply = rpc_buffer(xprt);
|
||||
rpc_buffer(xprt) = newbuf;
|
||||
xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt),
|
||||
su->su_iosz, XDR_ENCODE);
|
||||
victim->cache_xid = su->su_xid;
|
||||
victim->cache_proc = uc->uc_proc;
|
||||
victim->cache_vers = uc->uc_vers;
|
||||
victim->cache_prog = uc->uc_prog;
|
||||
victim->cache_addr = xprt->xp_rtaddr;
|
||||
victim->cache_addr.buf = ALLOC(char, xprt->xp_rtaddr.len);
|
||||
(void) memcpy(victim->cache_addr.buf, xprt->xp_rtaddr.buf,
|
||||
(size_t)xprt->xp_rtaddr.len);
|
||||
loc = CACHE_LOC(xprt, victim->cache_xid);
|
||||
victim->cache_next = uc->uc_entries[loc];
|
||||
uc->uc_entries[loc] = victim;
|
||||
uc->uc_fifo[uc->uc_nextvictim++] = victim;
|
||||
uc->uc_nextvictim %= uc->uc_size;
|
||||
mutex_unlock(&dupreq_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to get an entry from the cache
|
||||
* return 1 if found, 0 if not found and set the stage for cache_set()
|
||||
*/
|
||||
static int
|
||||
cache_get(xprt, msg, replyp, replylenp)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
char **replyp;
|
||||
size_t *replylenp;
|
||||
{
|
||||
u_int loc;
|
||||
cache_ptr ent;
|
||||
struct svc_dg_data *su = su_data(xprt);
|
||||
struct cl_cache *uc = (struct cl_cache *) su->su_cache;
|
||||
#ifdef RPC_CACHE_DEBUG
|
||||
struct netconfig *nconf;
|
||||
char *uaddr;
|
||||
#endif
|
||||
|
||||
mutex_lock(&dupreq_lock);
|
||||
loc = CACHE_LOC(xprt, su->su_xid);
|
||||
for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
|
||||
if (ent->cache_xid == su->su_xid &&
|
||||
ent->cache_proc == msg->rm_call.cb_proc &&
|
||||
ent->cache_vers == msg->rm_call.cb_vers &&
|
||||
ent->cache_prog == msg->rm_call.cb_prog &&
|
||||
ent->cache_addr.len == xprt->xp_rtaddr.len &&
|
||||
(memcmp(ent->cache_addr.buf, xprt->xp_rtaddr.buf,
|
||||
xprt->xp_rtaddr.len) == 0)) {
|
||||
#ifdef RPC_CACHE_DEBUG
|
||||
if (nconf = getnetconfigent(xprt->xp_netid)) {
|
||||
uaddr = taddr2uaddr(nconf, &xprt->xp_rtaddr);
|
||||
freenetconfigent(nconf);
|
||||
printf(
|
||||
"cache entry found for xid=%x prog=%d vers=%d proc=%d for rmtaddr=%s\n",
|
||||
su->su_xid, msg->rm_call.cb_prog,
|
||||
msg->rm_call.cb_vers,
|
||||
msg->rm_call.cb_proc, uaddr);
|
||||
free(uaddr);
|
||||
}
|
||||
#endif
|
||||
*replyp = ent->cache_reply;
|
||||
*replylenp = ent->cache_replylen;
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Failed to find entry
|
||||
* Remember a few things so we can do a set later
|
||||
*/
|
||||
uc->uc_proc = msg->rm_call.cb_proc;
|
||||
uc->uc_vers = msg->rm_call.cb_vers;
|
||||
uc->uc_prog = msg->rm_call.cb_prog;
|
||||
mutex_unlock(&dupreq_lock);
|
||||
return (0);
|
||||
}
|
312
freebsd/lib/libc/rpc/svc_generic.c
Normal file
312
freebsd/lib/libc/rpc/svc_generic.c
Normal file
@ -0,0 +1,312 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_generic.c,v 1.3 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#ident "@(#)svc_generic.c 1.19 94/04/24 SMI"
|
||||
static char sccsid[] = "@(#)svc_generic.c 1.21 89/02/28 Copyr 1988 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_generic.c, Server side for RPC.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/nettype.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
extern int __svc_vc_setflag(SVCXPRT *, int);
|
||||
|
||||
/*
|
||||
* The highest level interface for server creation.
|
||||
* It tries for all the nettokens in that particular class of token
|
||||
* and returns the number of handles it can create and/or find.
|
||||
*
|
||||
* It creates a link list of all the handles it could create.
|
||||
* If svc_create() is called multiple times, it uses the handle
|
||||
* created earlier instead of creating a new handle every time.
|
||||
*/
|
||||
int
|
||||
svc_create(dispatch, prognum, versnum, nettype)
|
||||
void (*dispatch)(struct svc_req *, SVCXPRT *);
|
||||
rpcprog_t prognum; /* Program number */
|
||||
rpcvers_t versnum; /* Version number */
|
||||
const char *nettype; /* Networktype token */
|
||||
{
|
||||
struct xlist {
|
||||
SVCXPRT *xprt; /* Server handle */
|
||||
struct xlist *next; /* Next item */
|
||||
} *l;
|
||||
static struct xlist *xprtlist; /* A link list of all the handles */
|
||||
int num = 0;
|
||||
SVCXPRT *xprt;
|
||||
struct netconfig *nconf;
|
||||
void *handle;
|
||||
|
||||
/* VARIABLES PROTECTED BY xprtlist_lock: xprtlist */
|
||||
|
||||
if ((handle = __rpc_setconf(nettype)) == NULL) {
|
||||
warnx("svc_create: unknown protocol");
|
||||
return (0);
|
||||
}
|
||||
while ((nconf = __rpc_getconf(handle)) != NULL) {
|
||||
mutex_lock(&xprtlist_lock);
|
||||
for (l = xprtlist; l; l = l->next) {
|
||||
if (strcmp(l->xprt->xp_netid, nconf->nc_netid) == 0) {
|
||||
/* Found an old one, use it */
|
||||
(void) rpcb_unset(prognum, versnum, nconf);
|
||||
if (svc_reg(l->xprt, prognum, versnum,
|
||||
dispatch, nconf) == FALSE)
|
||||
warnx(
|
||||
"svc_create: could not register prog %u vers %u on %s",
|
||||
(unsigned)prognum, (unsigned)versnum,
|
||||
nconf->nc_netid);
|
||||
else
|
||||
num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (l == NULL) {
|
||||
/* It was not found. Now create a new one */
|
||||
xprt = svc_tp_create(dispatch, prognum, versnum, nconf);
|
||||
if (xprt) {
|
||||
l = (struct xlist *)malloc(sizeof (*l));
|
||||
if (l == NULL) {
|
||||
warnx("svc_create: no memory");
|
||||
mutex_unlock(&xprtlist_lock);
|
||||
return (0);
|
||||
}
|
||||
l->xprt = xprt;
|
||||
l->next = xprtlist;
|
||||
xprtlist = l;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&xprtlist_lock);
|
||||
}
|
||||
__rpc_endconf(handle);
|
||||
/*
|
||||
* In case of num == 0; the error messages are generated by the
|
||||
* underlying layers; and hence not needed here.
|
||||
*/
|
||||
return (num);
|
||||
}
|
||||
|
||||
/*
|
||||
* The high level interface to svc_tli_create().
|
||||
* It tries to create a server for "nconf" and registers the service
|
||||
* with the rpcbind. It calls svc_tli_create();
|
||||
*/
|
||||
SVCXPRT *
|
||||
svc_tp_create(dispatch, prognum, versnum, nconf)
|
||||
void (*dispatch)(struct svc_req *, SVCXPRT *);
|
||||
rpcprog_t prognum; /* Program number */
|
||||
rpcvers_t versnum; /* Version number */
|
||||
const struct netconfig *nconf; /* Netconfig structure for the network */
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
|
||||
if (nconf == NULL) {
|
||||
warnx(
|
||||
"svc_tp_create: invalid netconfig structure for prog %u vers %u",
|
||||
(unsigned)prognum, (unsigned)versnum);
|
||||
return (NULL);
|
||||
}
|
||||
xprt = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
|
||||
if (xprt == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
/*LINTED const castaway*/
|
||||
(void) rpcb_unset(prognum, versnum, (struct netconfig *) nconf);
|
||||
if (svc_reg(xprt, prognum, versnum, dispatch, nconf) == FALSE) {
|
||||
warnx(
|
||||
"svc_tp_create: Could not register prog %u vers %u on %s",
|
||||
(unsigned)prognum, (unsigned)versnum,
|
||||
nconf->nc_netid);
|
||||
SVC_DESTROY(xprt);
|
||||
return (NULL);
|
||||
}
|
||||
return (xprt);
|
||||
}
|
||||
|
||||
/*
|
||||
* If fd is RPC_ANYFD, then it opens a fd for the given transport
|
||||
* provider (nconf cannot be NULL then). If the t_state is T_UNBND and
|
||||
* bindaddr is NON-NULL, it performs a t_bind using the bindaddr. For
|
||||
* NULL bindadr and Connection oriented transports, the value of qlen
|
||||
* is set to 8.
|
||||
*
|
||||
* If sendsz or recvsz are zero, their default values are chosen.
|
||||
*/
|
||||
SVCXPRT *
|
||||
svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz)
|
||||
int fd; /* Connection end point */
|
||||
const struct netconfig *nconf; /* Netconfig struct for nettoken */
|
||||
const struct t_bind *bindaddr; /* Local bind address */
|
||||
u_int sendsz; /* Max sendsize */
|
||||
u_int recvsz; /* Max recvsize */
|
||||
{
|
||||
SVCXPRT *xprt = NULL; /* service handle */
|
||||
bool_t madefd = FALSE; /* whether fd opened here */
|
||||
struct __rpc_sockinfo si;
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen;
|
||||
|
||||
if (fd == RPC_ANYFD) {
|
||||
if (nconf == NULL) {
|
||||
warnx("svc_tli_create: invalid netconfig");
|
||||
return (NULL);
|
||||
}
|
||||
fd = __rpc_nconf2fd(nconf);
|
||||
if (fd == -1) {
|
||||
warnx(
|
||||
"svc_tli_create: could not open connection for %s",
|
||||
nconf->nc_netid);
|
||||
return (NULL);
|
||||
}
|
||||
__rpc_nconf2sockinfo(nconf, &si);
|
||||
madefd = TRUE;
|
||||
} else {
|
||||
/*
|
||||
* It is an open descriptor. Get the transport info.
|
||||
*/
|
||||
if (!__rpc_fd2sockinfo(fd, &si)) {
|
||||
warnx(
|
||||
"svc_tli_create: could not get transport information");
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the fd is unbound, try to bind it.
|
||||
*/
|
||||
if (madefd || !__rpc_sockisbound(fd)) {
|
||||
if (bindaddr == NULL) {
|
||||
if (bindresvport(fd, NULL) < 0) {
|
||||
memset(&ss, 0, sizeof ss);
|
||||
ss.ss_family = si.si_af;
|
||||
ss.ss_len = si.si_alen;
|
||||
if (_bind(fd, (struct sockaddr *)(void *)&ss,
|
||||
(socklen_t)si.si_alen) < 0) {
|
||||
warnx(
|
||||
"svc_tli_create: could not bind to anonymous port");
|
||||
goto freedata;
|
||||
}
|
||||
}
|
||||
_listen(fd, SOMAXCONN);
|
||||
} else {
|
||||
if (_bind(fd,
|
||||
(struct sockaddr *)bindaddr->addr.buf,
|
||||
(socklen_t)si.si_alen) < 0) {
|
||||
warnx(
|
||||
"svc_tli_create: could not bind to requested address");
|
||||
goto freedata;
|
||||
}
|
||||
_listen(fd, (int)bindaddr->qlen);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* call transport specific function.
|
||||
*/
|
||||
switch (si.si_socktype) {
|
||||
case SOCK_STREAM:
|
||||
slen = sizeof ss;
|
||||
if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen)
|
||||
== 0) {
|
||||
/* accepted socket */
|
||||
xprt = svc_fd_create(fd, sendsz, recvsz);
|
||||
} else
|
||||
xprt = svc_vc_create(fd, sendsz, recvsz);
|
||||
if (!nconf || !xprt)
|
||||
break;
|
||||
#if 0
|
||||
/* XXX fvdl */
|
||||
if (strcmp(nconf->nc_protofmly, "inet") == 0 ||
|
||||
strcmp(nconf->nc_protofmly, "inet6") == 0)
|
||||
(void) __svc_vc_setflag(xprt, TRUE);
|
||||
#endif
|
||||
break;
|
||||
case SOCK_DGRAM:
|
||||
xprt = svc_dg_create(fd, sendsz, recvsz);
|
||||
break;
|
||||
default:
|
||||
warnx("svc_tli_create: bad service type");
|
||||
goto freedata;
|
||||
}
|
||||
|
||||
if (xprt == NULL)
|
||||
/*
|
||||
* The error messages here are spitted out by the lower layers:
|
||||
* svc_vc_create(), svc_fd_create() and svc_dg_create().
|
||||
*/
|
||||
goto freedata;
|
||||
|
||||
/* Fill in type of service */
|
||||
xprt->xp_type = __rpc_socktype2seman(si.si_socktype);
|
||||
|
||||
if (nconf) {
|
||||
xprt->xp_netid = strdup(nconf->nc_netid);
|
||||
xprt->xp_tp = strdup(nconf->nc_device);
|
||||
}
|
||||
return (xprt);
|
||||
|
||||
freedata:
|
||||
if (madefd)
|
||||
(void)_close(fd);
|
||||
if (xprt) {
|
||||
if (!madefd) /* so that svc_destroy doesnt close fd */
|
||||
xprt->xp_fd = RPC_ANYFD;
|
||||
SVC_DESTROY(xprt);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
287
freebsd/lib/libc/rpc/svc_raw.c
Normal file
287
freebsd/lib/libc/rpc/svc_raw.c
Normal file
@ -0,0 +1,287 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_raw.c,v 1.14 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
/* #ident "@(#)svc_raw.c 1.16 94/04/24 SMI" */
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_raw.c, This a toy for simple testing and timing.
|
||||
* Interface to create an rpc client and server in the same UNIX process.
|
||||
* This lets us similate rpc and get rpc (round trip) overhead, without
|
||||
* any interference from the kernel.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <rpc/rpc.h>
|
||||
#include <sys/types.h>
|
||||
#include <rpc/raw.h>
|
||||
#include <stdlib.h>
|
||||
#include "un-namespace.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
#ifndef UDPMSGSIZE
|
||||
#define UDPMSGSIZE 8800
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is the "network" that we will be moving data over
|
||||
*/
|
||||
static struct svc_raw_private {
|
||||
char *raw_buf; /* should be shared with the cl handle */
|
||||
SVCXPRT *server;
|
||||
XDR xdr_stream;
|
||||
char verf_body[MAX_AUTH_BYTES];
|
||||
} *svc_raw_private;
|
||||
|
||||
static enum xprt_stat svc_raw_stat(SVCXPRT *);
|
||||
static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *);
|
||||
static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *);
|
||||
static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *);
|
||||
static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *);
|
||||
static void svc_raw_destroy(SVCXPRT *);
|
||||
static void svc_raw_ops(SVCXPRT *);
|
||||
static bool_t svc_raw_control(SVCXPRT *, const u_int, void *);
|
||||
|
||||
char *__rpc_rawcombuf = NULL;
|
||||
|
||||
SVCXPRT *
|
||||
svc_raw_create()
|
||||
{
|
||||
struct svc_raw_private *srp;
|
||||
/* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
|
||||
|
||||
mutex_lock(&svcraw_lock);
|
||||
srp = svc_raw_private;
|
||||
if (srp == NULL) {
|
||||
srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
|
||||
if (srp == NULL) {
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (NULL);
|
||||
}
|
||||
if (__rpc_rawcombuf == NULL) {
|
||||
__rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
|
||||
if (__rpc_rawcombuf == NULL) {
|
||||
free(srp);
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
|
||||
srp->server = svc_xprt_alloc();
|
||||
if (srp->server == NULL) {
|
||||
free(__rpc_rawcombuf);
|
||||
free(srp);
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (NULL);
|
||||
}
|
||||
svc_raw_private = srp;
|
||||
}
|
||||
srp->server->xp_fd = FD_SETSIZE;
|
||||
srp->server->xp_port = 0;
|
||||
svc_raw_ops(srp->server);
|
||||
srp->server->xp_verf.oa_base = srp->verf_body;
|
||||
xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE);
|
||||
xprt_register(srp->server);
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (srp->server);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static enum xprt_stat
|
||||
svc_raw_stat(xprt)
|
||||
SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */
|
||||
{
|
||||
return (XPRT_IDLE);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
svc_raw_recv(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
struct svc_raw_private *srp;
|
||||
XDR *xdrs;
|
||||
|
||||
mutex_lock(&svcraw_lock);
|
||||
srp = svc_raw_private;
|
||||
if (srp == NULL) {
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
mutex_unlock(&svcraw_lock);
|
||||
|
||||
xdrs = &srp->xdr_stream;
|
||||
xdrs->x_op = XDR_DECODE;
|
||||
(void) XDR_SETPOS(xdrs, 0);
|
||||
if (! xdr_callmsg(xdrs, msg)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
svc_raw_reply(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
struct svc_raw_private *srp;
|
||||
XDR *xdrs;
|
||||
bool_t stat;
|
||||
xdrproc_t xdr_proc;
|
||||
caddr_t xdr_where;
|
||||
|
||||
mutex_lock(&svcraw_lock);
|
||||
srp = svc_raw_private;
|
||||
if (srp == NULL) {
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
mutex_unlock(&svcraw_lock);
|
||||
|
||||
xdrs = &srp->xdr_stream;
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
(void) XDR_SETPOS(xdrs, 0);
|
||||
if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
|
||||
msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
|
||||
xdr_proc = msg->acpted_rply.ar_results.proc;
|
||||
xdr_where = msg->acpted_rply.ar_results.where;
|
||||
msg->acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
|
||||
msg->acpted_rply.ar_results.where = NULL;
|
||||
|
||||
stat = xdr_replymsg(xdrs, msg) &&
|
||||
SVCAUTH_WRAP(&SVC_AUTH(xprt), xdrs, xdr_proc, xdr_where);
|
||||
} else {
|
||||
stat = xdr_replymsg(xdrs, msg);
|
||||
}
|
||||
if (!stat) {
|
||||
return (FALSE);
|
||||
}
|
||||
(void) XDR_GETPOS(xdrs); /* called just for overhead */
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
svc_raw_getargs(xprt, xdr_args, args_ptr)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
{
|
||||
struct svc_raw_private *srp;
|
||||
|
||||
mutex_lock(&svcraw_lock);
|
||||
srp = svc_raw_private;
|
||||
if (srp == NULL) {
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
mutex_unlock(&svcraw_lock);
|
||||
|
||||
return (SVCAUTH_UNWRAP(&SVC_AUTH(xprt), &srp->xdr_stream,
|
||||
xdr_args, args_ptr));
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
svc_raw_freeargs(xprt, xdr_args, args_ptr)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
{
|
||||
struct svc_raw_private *srp;
|
||||
XDR *xdrs;
|
||||
|
||||
mutex_lock(&svcraw_lock);
|
||||
srp = svc_raw_private;
|
||||
if (srp == NULL) {
|
||||
mutex_unlock(&svcraw_lock);
|
||||
return (FALSE);
|
||||
}
|
||||
mutex_unlock(&svcraw_lock);
|
||||
|
||||
xdrs = &srp->xdr_stream;
|
||||
xdrs->x_op = XDR_FREE;
|
||||
return (*xdr_args)(xdrs, args_ptr);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
svc_raw_destroy(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
svc_raw_control(xprt, rq, in)
|
||||
SVCXPRT *xprt;
|
||||
const u_int rq;
|
||||
void *in;
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
svc_raw_ops(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
static struct xp_ops ops;
|
||||
static struct xp_ops2 ops2;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops */
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.xp_recv == NULL) {
|
||||
ops.xp_recv = svc_raw_recv;
|
||||
ops.xp_stat = svc_raw_stat;
|
||||
ops.xp_getargs = svc_raw_getargs;
|
||||
ops.xp_reply = svc_raw_reply;
|
||||
ops.xp_freeargs = svc_raw_freeargs;
|
||||
ops.xp_destroy = svc_raw_destroy;
|
||||
ops2.xp_control = svc_raw_control;
|
||||
}
|
||||
xprt->xp_ops = &ops;
|
||||
xprt->xp_ops2 = &ops2;
|
||||
mutex_unlock(&ops_lock);
|
||||
}
|
99
freebsd/lib/libc/rpc/svc_run.c
Normal file
99
freebsd/lib/libc/rpc/svc_run.c
Normal file
@ -0,0 +1,99 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_run.c,v 1.17 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "from: @(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "from: @(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* This is the rpc server side idle loop
|
||||
* Wait for input, call server program.
|
||||
*/
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
void
|
||||
svc_run()
|
||||
{
|
||||
fd_set readfds, cleanfds;
|
||||
struct timeval timeout;
|
||||
|
||||
timeout.tv_sec = 30;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
for (;;) {
|
||||
rwlock_rdlock(&svc_fd_lock);
|
||||
readfds = svc_fdset;
|
||||
cleanfds = svc_fdset;
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
switch (_select(svc_maxfd+1, &readfds, NULL, NULL, &timeout)) {
|
||||
case -1:
|
||||
FD_ZERO(&readfds);
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
_warn("svc_run: - select failed");
|
||||
return;
|
||||
case 0:
|
||||
__svc_clean_idle(&cleanfds, 30, FALSE);
|
||||
continue;
|
||||
default:
|
||||
svc_getreqset(&readfds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function causes svc_run() to exit by telling it that it has no
|
||||
* more work to do.
|
||||
*/
|
||||
void
|
||||
svc_exit()
|
||||
{
|
||||
rwlock_wrlock(&svc_fd_lock);
|
||||
FD_ZERO(&svc_fdset);
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
}
|
314
freebsd/lib/libc/rpc/svc_simple.c
Normal file
314
freebsd/lib/libc/rpc/svc_simple.c
Normal file
@ -0,0 +1,314 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_simple.c,v 1.20 2000/07/06 03:10:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1986-1991 by Sun Microsystems Inc.
|
||||
*/
|
||||
|
||||
/* #pragma ident "@(#)svc_simple.c 1.18 94/04/24 SMI" */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_simple.c
|
||||
* Simplified front end to rpc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This interface creates a virtual listener for all the services
|
||||
* started thru rpc_reg(). It listens on the same endpoint for
|
||||
* all the services and then executes the corresponding service
|
||||
* for the given prognum and procnum.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/nettype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
|
||||
static void universal(struct svc_req *, SVCXPRT *);
|
||||
|
||||
static struct proglst {
|
||||
char *(*p_progname)(char *);
|
||||
rpcprog_t p_prognum;
|
||||
rpcvers_t p_versnum;
|
||||
rpcproc_t p_procnum;
|
||||
SVCXPRT *p_transp;
|
||||
char *p_netid;
|
||||
char *p_xdrbuf;
|
||||
int p_recvsz;
|
||||
xdrproc_t p_inproc, p_outproc;
|
||||
struct proglst *p_nxt;
|
||||
} *proglst;
|
||||
|
||||
static const char rpc_reg_err[] = "%s: %s";
|
||||
static const char rpc_reg_msg[] = "rpc_reg: ";
|
||||
static const char __reg_err1[] = "can't find appropriate transport";
|
||||
static const char __reg_err2[] = "can't get protocol info";
|
||||
static const char __reg_err3[] = "unsupported transport size";
|
||||
static const char __no_mem_str[] = "out of memory";
|
||||
|
||||
/*
|
||||
* For simplified, easy to use kind of rpc interfaces.
|
||||
* nettype indicates the type of transport on which the service will be
|
||||
* listening. Used for conservation of the system resource. Only one
|
||||
* handle is created for all the services (actually one of each netid)
|
||||
* and same xdrbuf is used for same netid. The size of the arguments
|
||||
* is also limited by the recvsize for that transport, even if it is
|
||||
* a COTS transport. This may be wrong, but for cases like these, they
|
||||
* should not use the simplified interfaces like this.
|
||||
*/
|
||||
|
||||
int
|
||||
rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype)
|
||||
rpcprog_t prognum; /* program number */
|
||||
rpcvers_t versnum; /* version number */
|
||||
rpcproc_t procnum; /* procedure number */
|
||||
char *(*progname)(char *); /* Server routine */
|
||||
xdrproc_t inproc, outproc; /* in/out XDR procedures */
|
||||
char *nettype; /* nettype */
|
||||
{
|
||||
struct netconfig *nconf;
|
||||
int done = FALSE;
|
||||
void *handle;
|
||||
|
||||
|
||||
if (procnum == NULLPROC) {
|
||||
warnx("%s can't reassign procedure number %u", rpc_reg_msg,
|
||||
NULLPROC);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (nettype == NULL)
|
||||
nettype = "netpath"; /* The default behavior */
|
||||
if ((handle = __rpc_setconf(nettype)) == NULL) {
|
||||
warnx(rpc_reg_err, rpc_reg_msg, __reg_err1);
|
||||
return (-1);
|
||||
}
|
||||
/* VARIABLES PROTECTED BY proglst_lock: proglst */
|
||||
mutex_lock(&proglst_lock);
|
||||
while ((nconf = __rpc_getconf(handle)) != NULL) {
|
||||
struct proglst *pl;
|
||||
SVCXPRT *svcxprt;
|
||||
int madenow;
|
||||
u_int recvsz;
|
||||
char *xdrbuf;
|
||||
char *netid;
|
||||
|
||||
madenow = FALSE;
|
||||
svcxprt = NULL;
|
||||
recvsz = 0;
|
||||
xdrbuf = netid = NULL;
|
||||
for (pl = proglst; pl; pl = pl->p_nxt) {
|
||||
if (strcmp(pl->p_netid, nconf->nc_netid) == 0) {
|
||||
svcxprt = pl->p_transp;
|
||||
xdrbuf = pl->p_xdrbuf;
|
||||
recvsz = pl->p_recvsz;
|
||||
netid = pl->p_netid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (svcxprt == NULL) {
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
svcxprt = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
|
||||
if (svcxprt == NULL)
|
||||
continue;
|
||||
if (!__rpc_fd2sockinfo(svcxprt->xp_fd, &si)) {
|
||||
warnx(rpc_reg_err, rpc_reg_msg, __reg_err2);
|
||||
SVC_DESTROY(svcxprt);
|
||||
continue;
|
||||
}
|
||||
recvsz = __rpc_get_t_size(si.si_af, si.si_proto, 0);
|
||||
if (recvsz == 0) {
|
||||
warnx(rpc_reg_err, rpc_reg_msg, __reg_err3);
|
||||
SVC_DESTROY(svcxprt);
|
||||
continue;
|
||||
}
|
||||
if (((xdrbuf = malloc((unsigned)recvsz)) == NULL) ||
|
||||
((netid = strdup(nconf->nc_netid)) == NULL)) {
|
||||
warnx(rpc_reg_err, rpc_reg_msg, __no_mem_str);
|
||||
if (xdrbuf != NULL)
|
||||
free(xdrbuf);
|
||||
if (netid != NULL)
|
||||
free(netid);
|
||||
SVC_DESTROY(svcxprt);
|
||||
break;
|
||||
}
|
||||
madenow = TRUE;
|
||||
}
|
||||
/*
|
||||
* Check if this (program, version, netid) had already been
|
||||
* registered. The check may save a few RPC calls to rpcbind
|
||||
*/
|
||||
for (pl = proglst; pl; pl = pl->p_nxt)
|
||||
if ((pl->p_prognum == prognum) &&
|
||||
(pl->p_versnum == versnum) &&
|
||||
(strcmp(pl->p_netid, netid) == 0))
|
||||
break;
|
||||
if (pl == NULL) { /* Not yet */
|
||||
(void) rpcb_unset(prognum, versnum, nconf);
|
||||
} else {
|
||||
/* so that svc_reg does not call rpcb_set() */
|
||||
nconf = NULL;
|
||||
}
|
||||
|
||||
if (!svc_reg(svcxprt, prognum, versnum, universal, nconf)) {
|
||||
warnx("%s couldn't register prog %u vers %u for %s",
|
||||
rpc_reg_msg, (unsigned)prognum,
|
||||
(unsigned)versnum, netid);
|
||||
if (madenow) {
|
||||
SVC_DESTROY(svcxprt);
|
||||
free(xdrbuf);
|
||||
free(netid);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
pl = malloc(sizeof (struct proglst));
|
||||
if (pl == NULL) {
|
||||
warnx(rpc_reg_err, rpc_reg_msg, __no_mem_str);
|
||||
if (madenow) {
|
||||
SVC_DESTROY(svcxprt);
|
||||
free(xdrbuf);
|
||||
free(netid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pl->p_progname = progname;
|
||||
pl->p_prognum = prognum;
|
||||
pl->p_versnum = versnum;
|
||||
pl->p_procnum = procnum;
|
||||
pl->p_inproc = inproc;
|
||||
pl->p_outproc = outproc;
|
||||
pl->p_transp = svcxprt;
|
||||
pl->p_xdrbuf = xdrbuf;
|
||||
pl->p_recvsz = recvsz;
|
||||
pl->p_netid = netid;
|
||||
pl->p_nxt = proglst;
|
||||
proglst = pl;
|
||||
done = TRUE;
|
||||
}
|
||||
__rpc_endconf(handle);
|
||||
mutex_unlock(&proglst_lock);
|
||||
|
||||
if (done == FALSE) {
|
||||
warnx("%s cant find suitable transport for %s",
|
||||
rpc_reg_msg, nettype);
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* The universal handler for the services registered using registerrpc.
|
||||
* It handles both the connectionless and the connection oriented cases.
|
||||
*/
|
||||
|
||||
static void
|
||||
universal(rqstp, transp)
|
||||
struct svc_req *rqstp;
|
||||
SVCXPRT *transp;
|
||||
{
|
||||
rpcprog_t prog;
|
||||
rpcvers_t vers;
|
||||
rpcproc_t proc;
|
||||
char *outdata;
|
||||
char *xdrbuf;
|
||||
struct proglst *pl;
|
||||
|
||||
/*
|
||||
* enforce "procnum 0 is echo" convention
|
||||
*/
|
||||
if (rqstp->rq_proc == NULLPROC) {
|
||||
if (svc_sendreply(transp, (xdrproc_t) xdr_void, NULL) ==
|
||||
FALSE) {
|
||||
warnx("svc_sendreply failed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
prog = rqstp->rq_prog;
|
||||
vers = rqstp->rq_vers;
|
||||
proc = rqstp->rq_proc;
|
||||
mutex_lock(&proglst_lock);
|
||||
for (pl = proglst; pl; pl = pl->p_nxt)
|
||||
if (pl->p_prognum == prog && pl->p_procnum == proc &&
|
||||
pl->p_versnum == vers &&
|
||||
(strcmp(pl->p_netid, transp->xp_netid) == 0)) {
|
||||
/* decode arguments into a CLEAN buffer */
|
||||
xdrbuf = pl->p_xdrbuf;
|
||||
/* Zero the arguments: reqd ! */
|
||||
(void) memset(xdrbuf, 0, sizeof (pl->p_recvsz));
|
||||
/*
|
||||
* Assuming that sizeof (xdrbuf) would be enough
|
||||
* for the arguments; if not then the program
|
||||
* may bomb. BEWARE!
|
||||
*/
|
||||
if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
|
||||
svcerr_decode(transp);
|
||||
mutex_unlock(&proglst_lock);
|
||||
return;
|
||||
}
|
||||
outdata = (*(pl->p_progname))(xdrbuf);
|
||||
if (outdata == NULL &&
|
||||
pl->p_outproc != (xdrproc_t) xdr_void){
|
||||
/* there was an error */
|
||||
mutex_unlock(&proglst_lock);
|
||||
return;
|
||||
}
|
||||
if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
|
||||
warnx(
|
||||
"rpc: rpc_reg trouble replying to prog %u vers %u",
|
||||
(unsigned)prog, (unsigned)vers);
|
||||
mutex_unlock(&proglst_lock);
|
||||
return;
|
||||
}
|
||||
/* free the decoded arguments */
|
||||
(void)svc_freeargs(transp, pl->p_inproc, xdrbuf);
|
||||
mutex_unlock(&proglst_lock);
|
||||
return;
|
||||
}
|
||||
mutex_unlock(&proglst_lock);
|
||||
/* This should never happen */
|
||||
warnx("rpc: rpc_reg: never registered prog %u vers %u",
|
||||
(unsigned)prog, (unsigned)vers);
|
||||
return;
|
||||
}
|
812
freebsd/lib/libc/rpc/svc_vc.c
Normal file
812
freebsd/lib/libc/rpc/svc_vc.c
Normal file
@ -0,0 +1,812 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *sccsid2 = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* svc_vc.c, Server side for Connection Oriented based RPC.
|
||||
*
|
||||
* Actually implements two flavors of transporter -
|
||||
* a tcp rendezvouser (a listner and connection establisher)
|
||||
* and a record/tcp stream.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include <sys/types.h>
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include "rpc_com.h"
|
||||
#include "mt_misc.h"
|
||||
#include "un-namespace.h"
|
||||
|
||||
static SVCXPRT *makefd_xprt(int, u_int, u_int);
|
||||
static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *);
|
||||
static enum xprt_stat rendezvous_stat(SVCXPRT *);
|
||||
static void svc_vc_destroy(SVCXPRT *);
|
||||
static void __svc_vc_dodestroy (SVCXPRT *);
|
||||
static int read_vc(void *, void *, int);
|
||||
static int write_vc(void *, void *, int);
|
||||
static enum xprt_stat svc_vc_stat(SVCXPRT *);
|
||||
static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *);
|
||||
static bool_t svc_vc_getargs(SVCXPRT *, xdrproc_t, void *);
|
||||
static bool_t svc_vc_freeargs(SVCXPRT *, xdrproc_t, void *);
|
||||
static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *);
|
||||
static void svc_vc_rendezvous_ops(SVCXPRT *);
|
||||
static void svc_vc_ops(SVCXPRT *);
|
||||
static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in);
|
||||
static bool_t svc_vc_rendezvous_control (SVCXPRT *xprt, const u_int rq,
|
||||
void *in);
|
||||
|
||||
struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
int maxrec;
|
||||
};
|
||||
|
||||
struct cf_conn { /* kept in xprt->xp_p1 for actual connection */
|
||||
enum xprt_stat strm_stat;
|
||||
u_int32_t x_id;
|
||||
XDR xdrs;
|
||||
char verf_body[MAX_AUTH_BYTES];
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
int maxrec;
|
||||
bool_t nonblock;
|
||||
struct timeval last_recv_time;
|
||||
};
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* xprt = svc_vc_create(sock, send_buf_size, recv_buf_size);
|
||||
*
|
||||
* Creates, registers, and returns a (rpc) tcp based transporter.
|
||||
* Once *xprt is initialized, it is registered as a transporter
|
||||
* see (svc.h, xprt_register). This routine returns
|
||||
* a NULL if a problem occurred.
|
||||
*
|
||||
* The filedescriptor passed in is expected to refer to a bound, but
|
||||
* not yet connected socket.
|
||||
*
|
||||
* Since streams do buffered io similar to stdio, the caller can specify
|
||||
* how big the send and receive buffers are via the second and third parms;
|
||||
* 0 => use the system default.
|
||||
*/
|
||||
SVCXPRT *
|
||||
svc_vc_create(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
struct cf_rendezvous *r = NULL;
|
||||
struct __rpc_sockinfo si;
|
||||
struct sockaddr_storage sslocal;
|
||||
socklen_t slen;
|
||||
|
||||
if (!__rpc_fd2sockinfo(fd, &si))
|
||||
return NULL;
|
||||
|
||||
r = mem_alloc(sizeof(*r));
|
||||
if (r == NULL) {
|
||||
warnx("svc_vc_create: out of memory");
|
||||
goto cleanup_svc_vc_create;
|
||||
}
|
||||
r->sendsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsize);
|
||||
r->recvsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsize);
|
||||
r->maxrec = __svc_maxrec;
|
||||
xprt = svc_xprt_alloc();
|
||||
if (xprt == NULL) {
|
||||
warnx("svc_vc_create: out of memory");
|
||||
goto cleanup_svc_vc_create;
|
||||
}
|
||||
xprt->xp_p1 = r;
|
||||
xprt->xp_verf = _null_auth;
|
||||
svc_vc_rendezvous_ops(xprt);
|
||||
xprt->xp_port = (u_short)-1; /* It is the rendezvouser */
|
||||
xprt->xp_fd = fd;
|
||||
|
||||
slen = sizeof (struct sockaddr_storage);
|
||||
if (_getsockname(fd, (struct sockaddr *)(void *)&sslocal, &slen) < 0) {
|
||||
warnx("svc_vc_create: could not retrieve local addr");
|
||||
goto cleanup_svc_vc_create;
|
||||
}
|
||||
|
||||
xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len;
|
||||
xprt->xp_ltaddr.buf = mem_alloc((size_t)sslocal.ss_len);
|
||||
if (xprt->xp_ltaddr.buf == NULL) {
|
||||
warnx("svc_vc_create: no mem for local addr");
|
||||
goto cleanup_svc_vc_create;
|
||||
}
|
||||
memcpy(xprt->xp_ltaddr.buf, &sslocal, (size_t)sslocal.ss_len);
|
||||
|
||||
xprt->xp_rtaddr.maxlen = sizeof (struct sockaddr_storage);
|
||||
xprt_register(xprt);
|
||||
return (xprt);
|
||||
cleanup_svc_vc_create:
|
||||
if (xprt)
|
||||
mem_free(xprt, sizeof(*xprt));
|
||||
if (r != NULL)
|
||||
mem_free(r, sizeof(*r));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like svtcp_create(), except the routine takes any *open* UNIX file
|
||||
* descriptor as its first input.
|
||||
*/
|
||||
SVCXPRT *
|
||||
svc_fd_create(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen;
|
||||
SVCXPRT *ret;
|
||||
|
||||
assert(fd != -1);
|
||||
|
||||
ret = makefd_xprt(fd, sendsize, recvsize);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
slen = sizeof (struct sockaddr_storage);
|
||||
if (_getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
|
||||
warnx("svc_fd_create: could not retrieve local addr");
|
||||
goto freedata;
|
||||
}
|
||||
ret->xp_ltaddr.maxlen = ret->xp_ltaddr.len = ss.ss_len;
|
||||
ret->xp_ltaddr.buf = mem_alloc((size_t)ss.ss_len);
|
||||
if (ret->xp_ltaddr.buf == NULL) {
|
||||
warnx("svc_fd_create: no mem for local addr");
|
||||
goto freedata;
|
||||
}
|
||||
memcpy(ret->xp_ltaddr.buf, &ss, (size_t)ss.ss_len);
|
||||
|
||||
slen = sizeof (struct sockaddr_storage);
|
||||
if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
|
||||
warnx("svc_fd_create: could not retrieve remote addr");
|
||||
goto freedata;
|
||||
}
|
||||
ret->xp_rtaddr.maxlen = ret->xp_rtaddr.len = ss.ss_len;
|
||||
ret->xp_rtaddr.buf = mem_alloc((size_t)ss.ss_len);
|
||||
if (ret->xp_rtaddr.buf == NULL) {
|
||||
warnx("svc_fd_create: no mem for local addr");
|
||||
goto freedata;
|
||||
}
|
||||
memcpy(ret->xp_rtaddr.buf, &ss, (size_t)ss.ss_len);
|
||||
#ifdef PORTMAP
|
||||
if (ss.ss_family == AF_INET || ss.ss_family == AF_LOCAL) {
|
||||
ret->xp_raddr = *(struct sockaddr_in *)ret->xp_rtaddr.buf;
|
||||
ret->xp_addrlen = sizeof (struct sockaddr_in);
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
|
||||
return ret;
|
||||
|
||||
freedata:
|
||||
if (ret->xp_ltaddr.buf != NULL)
|
||||
mem_free(ret->xp_ltaddr.buf, rep->xp_ltaddr.maxlen);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SVCXPRT *
|
||||
makefd_xprt(fd, sendsize, recvsize)
|
||||
int fd;
|
||||
u_int sendsize;
|
||||
u_int recvsize;
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
struct cf_conn *cd;
|
||||
const char *netid;
|
||||
struct __rpc_sockinfo si;
|
||||
|
||||
assert(fd != -1);
|
||||
|
||||
xprt = svc_xprt_alloc();
|
||||
if (xprt == NULL) {
|
||||
warnx("svc_vc: makefd_xprt: out of memory");
|
||||
goto done;
|
||||
}
|
||||
cd = mem_alloc(sizeof(struct cf_conn));
|
||||
if (cd == NULL) {
|
||||
warnx("svc_tcp: makefd_xprt: out of memory");
|
||||
svc_xprt_free(xprt);
|
||||
xprt = NULL;
|
||||
goto done;
|
||||
}
|
||||
cd->strm_stat = XPRT_IDLE;
|
||||
xdrrec_create(&(cd->xdrs), sendsize, recvsize,
|
||||
xprt, read_vc, write_vc);
|
||||
xprt->xp_p1 = cd;
|
||||
xprt->xp_verf.oa_base = cd->verf_body;
|
||||
svc_vc_ops(xprt); /* truely deals with calls */
|
||||
xprt->xp_port = 0; /* this is a connection, not a rendezvouser */
|
||||
xprt->xp_fd = fd;
|
||||
if (__rpc_fd2sockinfo(fd, &si) && __rpc_sockinfo2netid(&si, &netid))
|
||||
xprt->xp_netid = strdup(netid);
|
||||
|
||||
xprt_register(xprt);
|
||||
done:
|
||||
return (xprt);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
rendezvous_request(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
int sock, flags;
|
||||
struct cf_rendezvous *r;
|
||||
struct cf_conn *cd;
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t len;
|
||||
struct __rpc_sockinfo si;
|
||||
SVCXPRT *newxprt;
|
||||
fd_set cleanfds;
|
||||
|
||||
assert(xprt != NULL);
|
||||
assert(msg != NULL);
|
||||
|
||||
r = (struct cf_rendezvous *)xprt->xp_p1;
|
||||
again:
|
||||
len = sizeof addr;
|
||||
if ((sock = _accept(xprt->xp_fd, (struct sockaddr *)(void *)&addr,
|
||||
&len)) < 0) {
|
||||
if (errno == EINTR)
|
||||
goto again;
|
||||
/*
|
||||
* Clean out the most idle file descriptor when we're
|
||||
* running out.
|
||||
*/
|
||||
if (errno == EMFILE || errno == ENFILE) {
|
||||
cleanfds = svc_fdset;
|
||||
__svc_clean_idle(&cleanfds, 0, FALSE);
|
||||
goto again;
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
/*
|
||||
* make a new transporter (re-uses xprt)
|
||||
*/
|
||||
newxprt = makefd_xprt(sock, r->sendsize, r->recvsize);
|
||||
newxprt->xp_rtaddr.buf = mem_alloc(len);
|
||||
if (newxprt->xp_rtaddr.buf == NULL)
|
||||
return (FALSE);
|
||||
memcpy(newxprt->xp_rtaddr.buf, &addr, len);
|
||||
newxprt->xp_rtaddr.len = len;
|
||||
#ifdef PORTMAP
|
||||
if (addr.ss_family == AF_INET || addr.ss_family == AF_LOCAL) {
|
||||
newxprt->xp_raddr = *(struct sockaddr_in *)newxprt->xp_rtaddr.buf;
|
||||
newxprt->xp_addrlen = sizeof (struct sockaddr_in);
|
||||
}
|
||||
#endif /* PORTMAP */
|
||||
if (__rpc_fd2sockinfo(sock, &si) && si.si_proto == IPPROTO_TCP) {
|
||||
len = 1;
|
||||
/* XXX fvdl - is this useful? */
|
||||
_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &len, sizeof (len));
|
||||
}
|
||||
|
||||
cd = (struct cf_conn *)newxprt->xp_p1;
|
||||
|
||||
cd->recvsize = r->recvsize;
|
||||
cd->sendsize = r->sendsize;
|
||||
cd->maxrec = r->maxrec;
|
||||
|
||||
if (cd->maxrec != 0) {
|
||||
flags = _fcntl(sock, F_GETFL, 0);
|
||||
if (flags == -1)
|
||||
return (FALSE);
|
||||
if (_fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1)
|
||||
return (FALSE);
|
||||
if (cd->recvsize > cd->maxrec)
|
||||
cd->recvsize = cd->maxrec;
|
||||
cd->nonblock = TRUE;
|
||||
__xdrrec_setnonblock(&cd->xdrs, cd->maxrec);
|
||||
} else
|
||||
cd->nonblock = FALSE;
|
||||
|
||||
gettimeofday(&cd->last_recv_time, NULL);
|
||||
|
||||
return (FALSE); /* there is never an rpc msg to be processed */
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static enum xprt_stat
|
||||
rendezvous_stat(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
|
||||
return (XPRT_IDLE);
|
||||
}
|
||||
|
||||
static void
|
||||
svc_vc_destroy(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
assert(xprt != NULL);
|
||||
|
||||
xprt_unregister(xprt);
|
||||
__svc_vc_dodestroy(xprt);
|
||||
}
|
||||
|
||||
static void
|
||||
__svc_vc_dodestroy(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct cf_conn *cd;
|
||||
struct cf_rendezvous *r;
|
||||
|
||||
cd = (struct cf_conn *)xprt->xp_p1;
|
||||
|
||||
if (xprt->xp_fd != RPC_ANYFD)
|
||||
(void)_close(xprt->xp_fd);
|
||||
if (xprt->xp_port != 0) {
|
||||
/* a rendezvouser socket */
|
||||
r = (struct cf_rendezvous *)xprt->xp_p1;
|
||||
mem_free(r, sizeof (struct cf_rendezvous));
|
||||
xprt->xp_port = 0;
|
||||
} else {
|
||||
/* an actual connection socket */
|
||||
XDR_DESTROY(&(cd->xdrs));
|
||||
mem_free(cd, sizeof(struct cf_conn));
|
||||
}
|
||||
if (xprt->xp_rtaddr.buf)
|
||||
mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.maxlen);
|
||||
if (xprt->xp_ltaddr.buf)
|
||||
mem_free(xprt->xp_ltaddr.buf, xprt->xp_ltaddr.maxlen);
|
||||
if (xprt->xp_tp)
|
||||
free(xprt->xp_tp);
|
||||
if (xprt->xp_netid)
|
||||
free(xprt->xp_netid);
|
||||
svc_xprt_free(xprt);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
svc_vc_control(xprt, rq, in)
|
||||
SVCXPRT *xprt;
|
||||
const u_int rq;
|
||||
void *in;
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_vc_rendezvous_control(xprt, rq, in)
|
||||
SVCXPRT *xprt;
|
||||
const u_int rq;
|
||||
void *in;
|
||||
{
|
||||
struct cf_rendezvous *cfp;
|
||||
|
||||
cfp = (struct cf_rendezvous *)xprt->xp_p1;
|
||||
if (cfp == NULL)
|
||||
return (FALSE);
|
||||
switch (rq) {
|
||||
case SVCGET_CONNMAXREC:
|
||||
*(int *)in = cfp->maxrec;
|
||||
break;
|
||||
case SVCSET_CONNMAXREC:
|
||||
cfp->maxrec = *(int *)in;
|
||||
break;
|
||||
default:
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* reads data from the tcp or uip connection.
|
||||
* any error is fatal and the connection is closed.
|
||||
* (And a read of zero bytes is a half closed stream => error.)
|
||||
* All read operations timeout after 35 seconds. A timeout is
|
||||
* fatal for the connection.
|
||||
*/
|
||||
static int
|
||||
read_vc(xprtp, buf, len)
|
||||
void *xprtp;
|
||||
void *buf;
|
||||
int len;
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
int sock;
|
||||
int milliseconds = 35 * 1000;
|
||||
struct pollfd pollfd;
|
||||
struct cf_conn *cfp;
|
||||
|
||||
xprt = (SVCXPRT *)xprtp;
|
||||
assert(xprt != NULL);
|
||||
|
||||
sock = xprt->xp_fd;
|
||||
|
||||
cfp = (struct cf_conn *)xprt->xp_p1;
|
||||
|
||||
if (cfp->nonblock) {
|
||||
len = _read(sock, buf, (size_t)len);
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN)
|
||||
len = 0;
|
||||
else
|
||||
goto fatal_err;
|
||||
}
|
||||
if (len != 0)
|
||||
gettimeofday(&cfp->last_recv_time, NULL);
|
||||
return len;
|
||||
}
|
||||
|
||||
do {
|
||||
pollfd.fd = sock;
|
||||
pollfd.events = POLLIN;
|
||||
pollfd.revents = 0;
|
||||
switch (_poll(&pollfd, 1, milliseconds)) {
|
||||
case -1:
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
/*FALLTHROUGH*/
|
||||
case 0:
|
||||
goto fatal_err;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while ((pollfd.revents & POLLIN) == 0);
|
||||
|
||||
if ((len = _read(sock, buf, (size_t)len)) > 0) {
|
||||
gettimeofday(&cfp->last_recv_time, NULL);
|
||||
return (len);
|
||||
}
|
||||
|
||||
fatal_err:
|
||||
((struct cf_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* writes data to the tcp connection.
|
||||
* Any error is fatal and the connection is closed.
|
||||
*/
|
||||
static int
|
||||
write_vc(xprtp, buf, len)
|
||||
void *xprtp;
|
||||
void *buf;
|
||||
int len;
|
||||
{
|
||||
SVCXPRT *xprt;
|
||||
int i, cnt;
|
||||
struct cf_conn *cd;
|
||||
struct timeval tv0, tv1;
|
||||
|
||||
xprt = (SVCXPRT *)xprtp;
|
||||
assert(xprt != NULL);
|
||||
|
||||
cd = (struct cf_conn *)xprt->xp_p1;
|
||||
|
||||
if (cd->nonblock)
|
||||
gettimeofday(&tv0, NULL);
|
||||
|
||||
for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
|
||||
i = _write(xprt->xp_fd, buf, (size_t)cnt);
|
||||
if (i < 0) {
|
||||
if (errno != EAGAIN || !cd->nonblock) {
|
||||
cd->strm_stat = XPRT_DIED;
|
||||
return (-1);
|
||||
}
|
||||
if (cd->nonblock) {
|
||||
/*
|
||||
* For non-blocking connections, do not
|
||||
* take more than 2 seconds writing the
|
||||
* data out.
|
||||
*
|
||||
* XXX 2 is an arbitrary amount.
|
||||
*/
|
||||
gettimeofday(&tv1, NULL);
|
||||
if (tv1.tv_sec - tv0.tv_sec >= 2) {
|
||||
cd->strm_stat = XPRT_DIED;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
static enum xprt_stat
|
||||
svc_vc_stat(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
struct cf_conn *cd;
|
||||
|
||||
assert(xprt != NULL);
|
||||
|
||||
cd = (struct cf_conn *)(xprt->xp_p1);
|
||||
|
||||
if (cd->strm_stat == XPRT_DIED)
|
||||
return (XPRT_DIED);
|
||||
if (! xdrrec_eof(&(cd->xdrs)))
|
||||
return (XPRT_MOREREQS);
|
||||
return (XPRT_IDLE);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_vc_recv(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
struct cf_conn *cd;
|
||||
XDR *xdrs;
|
||||
|
||||
assert(xprt != NULL);
|
||||
assert(msg != NULL);
|
||||
|
||||
cd = (struct cf_conn *)(xprt->xp_p1);
|
||||
xdrs = &(cd->xdrs);
|
||||
|
||||
if (cd->nonblock) {
|
||||
if (!__xdrrec_getrec(xdrs, &cd->strm_stat, TRUE))
|
||||
return FALSE;
|
||||
} else {
|
||||
(void)xdrrec_skiprecord(xdrs);
|
||||
}
|
||||
|
||||
xdrs->x_op = XDR_DECODE;
|
||||
if (xdr_callmsg(xdrs, msg)) {
|
||||
cd->x_id = msg->rm_xid;
|
||||
return (TRUE);
|
||||
}
|
||||
cd->strm_stat = XPRT_DIED;
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_vc_getargs(xprt, xdr_args, args_ptr)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
{
|
||||
struct cf_conn *cd;
|
||||
|
||||
assert(xprt != NULL);
|
||||
cd = (struct cf_conn *)(xprt->xp_p1);
|
||||
return (SVCAUTH_UNWRAP(&SVC_AUTH(xprt),
|
||||
&cd->xdrs, xdr_args, args_ptr));
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_vc_freeargs(xprt, xdr_args, args_ptr)
|
||||
SVCXPRT *xprt;
|
||||
xdrproc_t xdr_args;
|
||||
void *args_ptr;
|
||||
{
|
||||
XDR *xdrs;
|
||||
|
||||
assert(xprt != NULL);
|
||||
/* args_ptr may be NULL */
|
||||
|
||||
xdrs = &(((struct cf_conn *)(xprt->xp_p1))->xdrs);
|
||||
|
||||
xdrs->x_op = XDR_FREE;
|
||||
return ((*xdr_args)(xdrs, args_ptr));
|
||||
}
|
||||
|
||||
static bool_t
|
||||
svc_vc_reply(xprt, msg)
|
||||
SVCXPRT *xprt;
|
||||
struct rpc_msg *msg;
|
||||
{
|
||||
struct cf_conn *cd;
|
||||
XDR *xdrs;
|
||||
bool_t rstat;
|
||||
xdrproc_t xdr_proc;
|
||||
caddr_t xdr_where;
|
||||
u_int pos;
|
||||
|
||||
assert(xprt != NULL);
|
||||
assert(msg != NULL);
|
||||
|
||||
cd = (struct cf_conn *)(xprt->xp_p1);
|
||||
xdrs = &(cd->xdrs);
|
||||
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
msg->rm_xid = cd->x_id;
|
||||
rstat = TRUE;
|
||||
if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
|
||||
msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
|
||||
xdr_proc = msg->acpted_rply.ar_results.proc;
|
||||
xdr_where = msg->acpted_rply.ar_results.where;
|
||||
msg->acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
|
||||
msg->acpted_rply.ar_results.where = NULL;
|
||||
|
||||
pos = XDR_GETPOS(xdrs);
|
||||
if (!xdr_replymsg(xdrs, msg) ||
|
||||
!SVCAUTH_WRAP(&SVC_AUTH(xprt), xdrs, xdr_proc, xdr_where)) {
|
||||
XDR_SETPOS(xdrs, pos);
|
||||
rstat = FALSE;
|
||||
}
|
||||
} else {
|
||||
rstat = xdr_replymsg(xdrs, msg);
|
||||
}
|
||||
|
||||
if (rstat)
|
||||
(void)xdrrec_endofrecord(xdrs, TRUE);
|
||||
|
||||
return (rstat);
|
||||
}
|
||||
|
||||
static void
|
||||
svc_vc_ops(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
static struct xp_ops ops;
|
||||
static struct xp_ops2 ops2;
|
||||
|
||||
/* VARIABLES PROTECTED BY ops_lock: ops, ops2 */
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.xp_recv == NULL) {
|
||||
ops.xp_recv = svc_vc_recv;
|
||||
ops.xp_stat = svc_vc_stat;
|
||||
ops.xp_getargs = svc_vc_getargs;
|
||||
ops.xp_reply = svc_vc_reply;
|
||||
ops.xp_freeargs = svc_vc_freeargs;
|
||||
ops.xp_destroy = svc_vc_destroy;
|
||||
ops2.xp_control = svc_vc_control;
|
||||
}
|
||||
xprt->xp_ops = &ops;
|
||||
xprt->xp_ops2 = &ops2;
|
||||
mutex_unlock(&ops_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
svc_vc_rendezvous_ops(xprt)
|
||||
SVCXPRT *xprt;
|
||||
{
|
||||
static struct xp_ops ops;
|
||||
static struct xp_ops2 ops2;
|
||||
|
||||
mutex_lock(&ops_lock);
|
||||
if (ops.xp_recv == NULL) {
|
||||
ops.xp_recv = rendezvous_request;
|
||||
ops.xp_stat = rendezvous_stat;
|
||||
ops.xp_getargs =
|
||||
(bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort;
|
||||
ops.xp_reply =
|
||||
(bool_t (*)(SVCXPRT *, struct rpc_msg *))abort;
|
||||
ops.xp_freeargs =
|
||||
(bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort,
|
||||
ops.xp_destroy = svc_vc_destroy;
|
||||
ops2.xp_control = svc_vc_rendezvous_control;
|
||||
}
|
||||
xprt->xp_ops = &ops;
|
||||
xprt->xp_ops2 = &ops2;
|
||||
mutex_unlock(&ops_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the effective UID of the sending process. Used by rpcbind, keyserv
|
||||
* and rpc.yppasswdd on AF_LOCAL.
|
||||
*/
|
||||
int
|
||||
__rpc_get_local_uid(SVCXPRT *transp, uid_t *uid) {
|
||||
int sock, ret;
|
||||
gid_t egid;
|
||||
uid_t euid;
|
||||
struct sockaddr *sa;
|
||||
|
||||
sock = transp->xp_fd;
|
||||
sa = (struct sockaddr *)transp->xp_rtaddr.buf;
|
||||
if (sa->sa_family == AF_LOCAL) {
|
||||
ret = getpeereid(sock, &euid, &egid);
|
||||
if (ret == 0)
|
||||
*uid = euid;
|
||||
return (ret);
|
||||
} else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy xprts that have not have had any activity in 'timeout' seconds.
|
||||
* If 'cleanblock' is true, blocking connections (the default) are also
|
||||
* cleaned. If timeout is 0, the least active connection is picked.
|
||||
*/
|
||||
bool_t
|
||||
__svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock)
|
||||
{
|
||||
int i, ncleaned;
|
||||
SVCXPRT *xprt, *least_active;
|
||||
struct timeval tv, tdiff, tmax;
|
||||
struct cf_conn *cd;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
tmax.tv_sec = tmax.tv_usec = 0;
|
||||
least_active = NULL;
|
||||
rwlock_wrlock(&svc_fd_lock);
|
||||
for (i = ncleaned = 0; i <= svc_maxfd; i++) {
|
||||
if (FD_ISSET(i, fds)) {
|
||||
xprt = __svc_xports[i];
|
||||
if (xprt == NULL || xprt->xp_ops == NULL ||
|
||||
xprt->xp_ops->xp_recv != svc_vc_recv)
|
||||
continue;
|
||||
cd = (struct cf_conn *)xprt->xp_p1;
|
||||
if (!cleanblock && !cd->nonblock)
|
||||
continue;
|
||||
if (timeout == 0) {
|
||||
timersub(&tv, &cd->last_recv_time, &tdiff);
|
||||
if (timercmp(&tdiff, &tmax, >)) {
|
||||
tmax = tdiff;
|
||||
least_active = xprt;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (tv.tv_sec - cd->last_recv_time.tv_sec > timeout) {
|
||||
__xprt_unregister_unlocked(xprt);
|
||||
__svc_vc_dodestroy(xprt);
|
||||
ncleaned++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timeout == 0 && least_active != NULL) {
|
||||
__xprt_unregister_unlocked(least_active);
|
||||
__svc_vc_dodestroy(least_active);
|
||||
ncleaned++;
|
||||
}
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
return ncleaned > 0 ? TRUE : FALSE;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user