1/*
2 * Copyright (c) 2010-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1.  Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 * 2.  Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
16 *     contributors may be used to endorse or promote products derived from
17 *     this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Portions of this software have been released under the following terms:
31 *
32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
35 *
36 * To anyone who acknowledges that this file is provided "AS IS"
37 * without any express or implied warranty:
38 * permission to use, copy, modify, and distribute this file for any
39 * purpose is hereby granted without fee, provided that the above
40 * copyright notices and this notice appears in all source code copies,
41 * and that none of the names of Open Software Foundation, Inc., Hewlett-
42 * Packard Company or Digital Equipment Corporation be used
43 * in advertising or publicity pertaining to distribution of the software
44 * without specific, written prior permission.  Neither Open Software
45 * Foundation, Inc., Hewlett-Packard Company nor Digital
46 * Equipment Corporation makes any representations about the suitability
47 * of this software for any purpose.
48 *
49 * Copyright (c) 2007, Novell, Inc. All rights reserved.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 *
54 * 1.  Redistributions of source code must retain the above copyright
55 *     notice, this list of conditions and the following disclaimer.
56 * 2.  Redistributions in binary form must reproduce the above copyright
57 *     notice, this list of conditions and the following disclaimer in the
58 *     documentation and/or other materials provided with the distribution.
59 * 3.  Neither the name of Novell Inc. nor the names of its contributors
60 *     may be used to endorse or promote products derived from this
61 *     this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 *
74 * @APPLE_LICENSE_HEADER_END@
75 */
76
77/*
78**
79**  NAME
80**
81**      com.h
82**
83**  FACILITY:
84**
85**      Remote Procedure Call (RPC)
86**
87**  ABSTRACT:
88**
89**  Private interface to the Common Communications Service for use
90**  by RPC Protocol Services and Network Address Family Extension Services.
91**
92**
93*/
94
95#ifndef _COM_H
96#define _COM_H	1
97
98#include <cominit.h>
99#include <sys/socket.h>
100
101/*
102 * the value of an invalid interface hint
103 */
104
105#define RPC_C_INVALID_IHINT     0xFFFF
106
107/***********************************************************************/
108/*
109 * U U I D _ G _ N I L _ U U I D
110 */
111EXTERNAL idl_uuid_t    uuid_g_nil_uuid;
112
113/***********************************************************************/
114/*
115 * R P C _ G _ I N I T I A L I Z E D
116 *
117 * The value that indicates whether or not the RPC runtime has previously
118 * been initialized. Its definition is in comp.c.
119 */
120EXTERNAL boolean        rpc_g_initialized;
121
122/***********************************************************************/
123/*
124 * R P C _ G _ T H R E A D _ C O N T E X T _ K E Y
125 *
126 * The key visible to all threads that contains a pointer to the
127 * per-thread context block.
128 */
129EXTERNAL dcethread_key  rpc_g_thread_context_key;
130
131/***********************************************************************/
132/*
133 * R P C _ G _ R U N T I M E _ P T H R E A D _ A T T R
134 *
135 * A dcethread attribute for creation of threads internal to the runtime
136 * (other than server threads).
137 * Initialized by rpc_init().
138 */
139EXTERNAL dcethread_attr     rpc_g_default_dcethread_attr;
140
141/***********************************************************************/
142/*
143 * R P C _ G _ G L O B A L _ M U T E X
144 *
145 * The global mutex used for the entire Communications Service. Note
146 * that this may be temporary since a per-data structure mutex may
147 * be employed. Its definition is in comp.c.
148 */
149EXTERNAL rpc_mutex_t    rpc_g_global_mutex;
150
151/***********************************************************************/
152/*
153 * R P C _ G _ G L O B A L _ B I N D I N G _ C O N D
154 *
155 * The global binding handle condition variable used for call
156 * serialization.  This condition variable is protected by the global
157 * mutex.  Note that this may be temporary since a per-binding handle
158 * cond var / mutex may be employed.  Its definition is in comp.c.
159 */
160EXTERNAL rpc_cond_t    rpc_g_global_binding_cond;
161
162/***********************************************************************/
163/*
164 * R P C _ G _ F O R K _ C O U N T
165 *
166 * The global fork count used to detect when a process using
167 * RPC has forked.  Its definition is in comp.c.
168 */
169EXTERNAL unsigned32    rpc_g_fork_count;
170
171/***********************************************************************/
172/*
173 * R P C _ V E R I F Y _ I N I T
174 *
175 * A macro which calls rpc__init if it hasn't been called yet.
176 */
177#define RPC_VERIFY_INIT()                                               \
178{                                                                       \
179    if (rpc_g_initialized == false)                                     \
180    {                                                                   \
181        rpc__init();                                                    \
182    }                                                                   \
183}
184
185/***********************************************************************/
186/*
187 * R P C _ P R O T S E Q _ I D _ T
188 *
189 * The RPC Protocol Sequence IDs are now in rpcbase.idl
190*/
191
192#ifdef TEST_PROTOCOL
193#define RPC_C_PROTSEQ_ID_NCATP_IP_TCP   15
194#endif /* TEST_PROTOCOL */
195
196/* Allow for dynamic protocols */
197#define RPC_C_PROTSEQ_ID_MAX            16
198
199typedef unsigned32       rpc_protseq_id_t, *rpc_protseq_id_p_t;
200
201/***********************************************************************/
202/*
203 * R P C _ P R O T S E Q _ T
204 *
205 * The RPC Protocol Sequence Strings.
206 */
207
208/*
209 * An RPC protocol sequence including '\0'.
210 */
211
212#define RPC_C_PROTSEQ_MAX               32
213
214typedef unsigned_char_t rpc_protseq_t[RPC_C_PROTSEQ_MAX];
215
216#define RPC_PROTSEQ_NCACN_IP_TCP        "ncacn_ip_tcp"
217#define RPC_PROTSEQ_NCACN_DNET_NSP      "ncacn_dnet_nsp"
218#define RPC_PROTSEQ_NCACN_OSI_DNA       "ncacn_osi_dna"
219#define RPC_PROTSEQ_NCADG_IP_UDP        "ncadg_ip_udp"
220#define RPC_PROTSEQ_NCADG_DDS           "ncadg_dds"
221#define RPC_PROTSEQ_NCALRPC             "ncalrpc"
222#define RPC_PROTSEQ_NCACN_NP            "ncacn_np"
223#define RPC_PROTSEQ_NCACN_NB            "ncacn_nb"
224#define RPC_PROTSEQ_NCACN_AT_DSP        "ncacn_at_dsp"
225#define RPC_PROTSEQ_NCACN_NB_IPX        "ncacn_nb_ipx"
226#define RPC_PROTSEQ_NCACN_SPX           "ncacn_spx"
227#define RPC_PROTSEQ_NCACN_NB_NB         "ncacn_nb_nb"
228#define RPC_PROTSEQ_NCACN_NB_TCP        "ncacn_nb_tcp"
229#define RPC_PROTSEQ_NCACN_VNS_SPP       "ncacn_vns_spp"
230#define RPC_PROTSEQ_NCADG_IPX           "ncadg_ipx"
231
232#ifdef PROT_NCATP
233#define RPC_PROTSEQ_NCATP_IP_TCP        "ncatp_ip_tcp"
234#endif
235
236/***********************************************************************/
237/*
238 * R P C _ P R O T O C O L _ I D _ T
239 *
240 * The RPC Protocol IDs.
241 */
242
243#define RPC_C_PROTOCOL_ID_NCACN         0
244#define RPC_C_PROTOCOL_ID_NCADG         1
245
246#ifdef PROT_NCATP
247#define RPC_C_PROTOCOL_ID_NCATP         2
248#endif
249/* allow for more of these */
250#define RPC_C_PROTOCOL_ID_MAX           16
251
252typedef unsigned32       rpc_protocol_id_t, *rpc_protocol_id_p_t;
253
254/***********************************************************************/
255/*
256 * R P C _ N A F _ I D _ T
257 *
258 * The Network Address Family IDs.
259 *
260 * NOTE WELL that this data type is defined as "unsigned32", not
261 * "unsigned16".  It's this way because of annoying problems in passing
262 * sub-"int" sized parameters using our model of how to work in both
263 * ANSI and pre-ANSI C environments.  An unfortunate upshot of this fact
264 * is that if you're trying to build up a "struct sockaddr" equivalent
265 * data type (e.g., "rpc_addr_p_t" below), you CAN'T use "rpc_naf_id_t"
266 * -- you must use "unsigned16".  (Arguably, you should just say "struct
267 * sockaddr", but that's another matter.)
268 */
269
270#define RPC_C_NAF_ID_UXD     1
271#define RPC_C_NAF_ID_IP      2
272#define RPC_C_NAF_ID_DNET    12
273#define RPC_C_NAF_ID_DDS     13         /* ###Check this one ###*/
274#define RPC_C_NAF_ID_NP      14
275#define RPC_C_NAF_ID_OSI     19
276#define RPC_C_NAF_ID_MAX     20
277
278typedef unsigned32       rpc_naf_id_t, *rpc_naf_id_p_t;
279
280/***********************************************************************/
281/*
282 * R P C _ N E T W O R K _ P R O T O C O L _ I D _ T
283 *
284 * The Network Protocol IDs.
285 */
286
287#define RPC_C_NETWORK_PROTOCOL_ID_UXD   0
288#define RPC_C_NETWORK_PROTOCOL_ID_TCP   6
289#define RPC_C_NETWORK_PROTOCOL_ID_UDP   17
290#define RPC_C_NETWORK_PROTOCOL_ID_NSP   1
291#define RPC_C_NETWORK_PROTOCOL_ID_DDS   0
292#define RPC_C_NETWORK_PROTOCOL_ID_DNASESSION 9
293#define RPC_C_NETWORK_PROTOCOL_ID_UNS   0
294/* This is a big hack - 1 is ICMP */
295#define RPC_C_NETWORK_PROTOCOL_ID_NP    1
296
297typedef unsigned32 rpc_network_protocol_id_t, *rpc_network_protocol_id_p_t;
298
299/***********************************************************************/
300/*
301 * R P C _ P R O T S E Q _ I N Q _ N E T _ I F _ I D
302 */
303
304#define RPC_PROTSEQ_INQ_NET_IF_ID(id)       rpc_g_protseq_id[id].network_if_id
305
306/*
307 * R P C _ N E T W O R K _ I F _ I D _ T
308 *
309 * The Network Interface Type IDs.
310 */
311
312#define RPC_C_NETWORK_IF_ID_STREAM      SOCK_STREAM
313#define RPC_C_NETWORK_IF_ID_DGRAM       SOCK_DGRAM
314
315#define RPC_C_NETWORK_IF_ID_SEQPACKET   SOCK_SEQPACKET
316
317typedef unsigned32       rpc_network_if_id_t, *rpc_network_if_id_p_t;
318
319/***********************************************************************/
320/*
321 * R P C _ C _ B H _ E X T E N D E D
322 *
323 * The values of the flag field within rpc_binding_rep_t (extended_bind_flag).
324 * If rpc_binding_rep_t is extended to include a new information in the
325 * future, add the definition here, and modify the affected routines
326 * accordingly.
327 */
328#define RPC_C_BH_EXTENDED_NONE          0x0000
329#define RPC_C_BH_EXTENDED_CODESETS      0x0001
330#define RPC_C_BH_IN_STUB_EVALUATION     0x0002
331
332/***********************************************************************/
333/*
334 * R P C _ P O R T _ R E S T R I C T I O N _ L I S T _ T
335 *
336 * Each protocol sequence (rpc_protseq_id_elt_t) is associated with an
337 * optional list of ranges of network "ports" to restrict binding dynamic
338 * endpoints to.  This facility is intended for use by sites which employ
339 * a network "firewall," but still wish to deploy WAN-based RPC
340 * applications.  This allows the network administrator to open certain
341 * ranges of ports in their firewalls to DCE servers.
342 *
343 * The rpc_port_restriction_list_t contains a void pointer to an
344 * AF-specific array of low/high pairs.  Logic in the AF code will define
345 * and interpret this array as locally appropriate.
346 *
347 * Also contained are two variables which provide sequencing of returned
348 * endpoints.  current_range_element points to the current active range in
349 * range_elements, and current_port_in_range is used in an AF-specific
350 * manner to provide the next port in a range.
351 *
352 */
353
354typedef struct
355{
356    unsigned32              n_tries;    /* specific to the AF */
357    unsigned32              n_elements; /* in range_elements */
358    void                    *range_elements;
359                                        /* pointer to an AF-specific array */
360    unsigned32              current_range_element;
361    unsigned32              current_port_in_range;
362} rpc_port_restriction_list_t, *rpc_port_restriction_list_p_t;
363
364/***********************************************************************/
365/*
366 * R P C _ P O R T _ R E S T R I C T I O N _ I N Q _ N _ T R I E S
367 */
368
369#define RPC_PORT_RESTRICTION_INQ_N_TRIES(protseq_id) \
370    (rpc_g_protseq_id[(protseq_id)].port_restriction_list->n_tries)
371
372/***********************************************************************/
373/*
374 * R P C _ P R O T S E Q _ I D _ E L T _ T
375 *
376 * The RPC Protocol Sequence ID table element structure.  An element
377 * describes a single RPC Protocol Sequence.
378 *
379 * The fields are:
380 *
381 *      supported       A boolean flag initialized to zero and filled
382 *                      in by rpc__init if it determines that this Protocol
383 *                      Sequence is actually supported by the system.
384 *
385 *      rpc_protseq_id  A constant identifier for the Protocol Sequence.
386 *
387 *      rpc_protocol_id A constant identifier for the RPC Protocol used
388 *                      in this Protocol Sequence.
389 *
390 *      naf_id          A constant identifier for the Network Address
391 *                      Family used in this Protocol Sequence.
392 *
393 *      net_protocol_id A constant identifier for the network protocol
394 *                      used in this Protocol Sequence.
395 *
396 *      net_if_id       A constant identifier for the network interface
397 *                      type used in this Protocol Sequence.
398 *
399 *      rpc_protseq     A string constant defining this Protocol Sequence.
400 *
401 * The typedef for an RPC Protocol Sequence string is contained in rpc.idl.
402 */
403typedef struct
404{
405    boolean                     supported;
406    boolean                     uses_ep_mapper;
407    rpc_protseq_id_t            rpc_protseq_id;
408    rpc_protocol_id_t           rpc_protocol_id;
409    rpc_naf_id_t                naf_id;
410    rpc_network_protocol_id_t   network_protocol_id;
411    rpc_network_if_id_t         network_if_id;
412    rpc_protseq_t               rpc_protseq;
413    rpc_port_restriction_list_p_t        port_restriction_list;
414    const struct rpc_socket_vtbl_s *   socket_vtbl;
415} rpc_protseq_id_elt_t, *rpc_protseq_id_elt_p_t;
416
417/***********************************************************************/
418/*
419 * R P C _ G _ P R O T S E Q _ I D
420 *
421 * The RPC Protocol Sequence ID table.  This table is indexed by an RPC
422 * Protocol Sequence ID.
423 *
424 * An RPC Protocol Sequence represents a specific RPC Protocol/Network
425 * Address Family combination which is by definition a valid combination
426 * of protocols. An RPC Protocol Sequence also represents a specific
427 * NAF interface type, since there may be multiple within a NAF. Each
428 * RPC Protocol Sequence has an entry in this table.
429 *
430 * Note that the ".rpc_protseq_id" field of i'th element in the table
431 * is always "i".  While redundant, this is useful so that you can pass
432 * pointers to individual table elements.
433 */
434EXTERNAL rpc_protseq_id_elt_t   rpc_g_protseq_id[RPC_C_PROTSEQ_ID_MAX];
435
436/***********************************************************************/
437/*
438 * R P C _ P R O T S E Q _ I N Q _ N E T _ P R O T _ I D
439 */
440#define RPC_PROTSEQ_INQ_NET_PROT_ID(id) \
441     rpc_g_protseq_id[id].network_protocol_id
442
443/***********************************************************************/
444/*
445 * R P C _ P R O T S E Q _ T E S T _ P O R T _ R E S T R I C T I O N
446 */
447#define RPC_PROTSEQ_TEST_PORT_RESTRICTION(id) \
448    (rpc_g_protseq_id[id].port_restriction_list != NULL)
449
450
451/***********************************************************************/
452/*
453 * R P C _ E N D P O I N T _ T
454 *
455 * The RPC Address endpoint structure.
456 */
457typedef unsigned_char_t *rpc_endpoint_t;
458typedef rpc_endpoint_t  *rpc_endpoint_p_t;
459
460/***********************************************************************/
461/*
462 * R P C _ N E T A D D R _ T
463 *
464 * The RPC Address network address (host name) structure.
465 */
466typedef unsigned_char_t *rpc_netaddr_t;
467
468/***********************************************************************/
469/*
470 * R P C _ N E T W O R K _ O P T I O N S _ T
471 *
472 * The RPC Address network options structure.
473 */
474typedef unsigned_char_t *rpc_network_options_t;
475
476/***********************************************************************/
477/*
478 * R P C _ A D D R _ P _ T
479 *
480 * The RPC Address data structure.  Note that we don't define a non-pointer
481 * variant of this data type since it's an open structure whose size
482 * can never be known at compile time.
483 */
484
485typedef struct
486{
487    rpc_protseq_id_t        rpc_protseq_id;
488    socklen_t               len;
489    sockaddr_t              sa;
490} *rpc_addr_p_t;
491
492typedef struct rpc_socket_handle_s* rpc_socket_t;
493
494#define RPC_SOCKET_INVALID (NULL)
495
496/***********************************************************************/
497/*
498 * R P C _ P R O T O C O L _ V E R S I O N _ T
499 *
500 * Holds the version number of a binding, stored in the binding handle.
501 */
502typedef struct
503{
504    unsigned32              major_version;
505    unsigned32              minor_version;
506} rpc_protocol_version_t, *rpc_protocol_version_p_t;
507
508/***********************************************************************/
509/*
510 *  R P C _ I F _ V E R S _ M A J O R
511 *  R P C _ I F _ V E R S _ M I N O R
512 *
513 * Macros to turn a 32 bit version number into its major and minor version
514 * number components.
515 */
516#define RPC_IF_VERS_MAJOR(_if_vers) ((_if_vers) & 0xffff)
517#define RPC_IF_VERS_MINOR(_if_vers) ((_if_vers) >> 16)
518
519/*
520 *  RPC_IF_IS_COMPATIBLE
521 *
522 * Macro used to compare an interface uuid and version in an if registry
523 * entry with a specified if UUID and version.  Note: this code will
524 * only match on version numbers if the major versions match exactly
525 * and if the minor version in the registry is greater than or equal
526 * to that in the if version passed by the caller.
527 */
528#define RPC_IF_IS_COMPATIBLE(_if_entry, _if_uuid, _if_vers, _status) \
529( \
530    UUID_EQ ((_if_entry)->if_spec->id, *(_if_uuid), (_status)) \
531    && RPC_IF_VERS_MAJOR((_if_entry)->if_spec->vers) == RPC_IF_VERS_MAJOR(_if_vers) \
532    && RPC_IF_VERS_MINOR((_if_entry)->if_spec->vers) >= RPC_IF_VERS_MINOR(_if_vers) \
533)
534
535
536/*
537 * R P C _ T O W E R _ F L O O R _ T
538 *
539 * Tower floor representation
540 */
541typedef struct
542{
543    unsigned16              free_twr_octet_flag;
544    unsigned16              prot_id_count;
545    unsigned16              address_count;
546    byte_t                  *octet_string;
547} rpc_tower_floor_t, *rpc_tower_floor_p_t;
548
549/*
550 * R P C _ T O W E R _ R E F _ T
551 *
552 * Runtime tower reference
553 *
554 * The runtime uses a reference structure to provide access
555 * to the individual floors of a tower.
556 */
557typedef struct
558{
559    unsigned16              count;
560    rpc_tower_floor_p_t     floor[1];
561} rpc_tower_ref_t, *rpc_tower_ref_p_t;
562
563/*
564 * R P C _ T O W E R _ R E F _ V E C T O R _ T
565 *
566 * Runtime tower reference vector
567 *
568 * The runtime uses a vector of tower reference structures while
569 * converting a binding to towers (each binding maps to multiple towers,
570 * one for each transfer syntax). In this case only RPC floor 2 differs
571 * for each tower.
572 *
573 * lower_flrs is obtained from CDS and is saved here as an optimization
574 * allowing the array of tower references (tower) to point into the
575 * lower_flrs data.
576 */
577typedef struct
578{
579    twr_p_t                 lower_flrs;
580    unsigned32              count;
581    rpc_tower_ref_p_t       tower[1];
582} rpc_tower_ref_vector_t, *rpc_tower_ref_vector_p_t;
583
584/*
585 * Protocol Tower constants
586 */
587
588/*
589 * Number of bytes in the tower floor count field
590 */
591
592#define  RPC_C_TOWER_FLR_COUNT_SIZE   2
593
594/*
595 * Number of bytes in the lhs count field of a floor.
596 */
597
598#define   RPC_C_TOWER_FLR_LHS_COUNT_SIZE  2
599
600/*
601 * Number of bytes in the rhs count field of a floor.
602 */
603
604#define   RPC_C_TOWER_FLR_RHS_COUNT_SIZE  2
605
606/*
607 * Number of bytes for storing a major or minor version.
608 */
609
610#define  RPC_C_TOWER_VERSION_SIZE  2
611
612/*
613 * Number of bytes for storing a tower floor protocol id or protocol id prefix.
614 */
615
616#define  RPC_C_TOWER_PROT_ID_SIZE  1
617
618/*
619 * Number of bytes for storing a uuid.
620 */
621#define  RPC_C_TOWER_UUID_SIZE  16
622
623/*
624 * Number of upper (RPC-specific floors. Each tower *must* have exactly
625 * this number of upper floors.
626 */
627#define  RPC_C_NUM_RPC_FLOORS   3
628
629/*
630 * Maximum number of lower (network-specific) floors used by RPC to figure
631 * out the rpc_protseq_id_t of the tower.
632 * Each tower *may* have more than this number of lower floors. However,
633 * the additional floors are not used directly by RPC.
634 */
635
636#define RPC_C_MAX_NUM_NETWORK_FLOORS  3
637
638/*
639 * Minimum number of lower (network_specific floors used by RPC to figure
640 * out the rpc_protseq_id_t of the tower. (The value is based on uxd.)
641 */
642
643#define RPC_C_MIN_NUM_NETWORK_FLOORS  1
644
645/*
646 * Minimum number of floors in a full rpc protocol tower.
647 */
648#define RPC_C_FULL_TOWER_MIN_FLR_COUNT \
649                        (RPC_C_NUM_RPC_FLOORS + RPC_C_MIN_NUM_NETWORK_FLOORS)
650
651/*
652 * Minimum number of floors is a minimal rpc protocol tower.
653 * (The +1 is for the rpc prot id floor).
654 */
655
656#define RPC_C_MIN_TOWER_MIN_FLR_COUNT (RPC_C_MIN_NUM_NETWORK_FLOORS + 1)
657
658/*
659 * The following macros help in processing the components
660 * of a tower floor.
661 */
662
663#define RPC_PROT_ID_COUNT(floor)    \
664    ((floor)->octet_string)
665
666#define RPC_PROT_ID_START(floor)    \
667    (RPC_PROT_ID_COUNT(floor) + RPC_C_TOWER_FLR_LHS_COUNT_SIZE)
668
669#define RPC_ADDRESS_COUNT(floor)    \
670    (RPC_PROT_ID_START(floor) + (floor)->prot_id_count)
671
672#define RPC_ADDRESS_START(floor)     \
673    (RPC_ADDRESS_COUNT(floor) + RPC_C_TOWER_FLR_RHS_COUNT_SIZE)
674
675/***********************************************************************/
676/*
677 * R P C _ A D D R _ V E C T O R _ P _ T
678 *
679 * A data structure containing an array of pointers to RPC Address data
680 * structures, along with a count of the number of pointers present.
681 */
682
683typedef struct
684{
685    unsigned32              len;
686    rpc_addr_p_t            addrs[1];
687} *rpc_addr_vector_p_t;
688
689/***********************************************************************/
690/*
691 * R P C _ A U T H N _ P R O T O C O L _ I D _ T
692 *
693 * The RPC Authentication Protocol IDs.  See the "rpc_c_authn_..." constants
694 * in "rpcauth.idl".
695 */
696typedef unsigned32 rpc_authn_protocol_id_t;
697
698#define RPC_C_AUTHN_PROTOCOL_ID_MAX     128
699
700/*
701 * R P C _ A U T H Z _ P R O T O C O L _ I D _ T
702 *
703 * The RPC Authorization Protocol IDs.  See the "rpc_c_authz_..." constants
704 * in "rpcauth.idl".
705 */
706typedef unsigned32 rpc_authz_protocol_id_t;
707
708/*
709 * R P C _ A U T H N _ L E V E L _ T
710 *
711 * The RPC Authentication levels.  See the "rpc_c_authn_level_..." constants
712 * in "rpcauth.idl".
713 */
714typedef unsigned32 rpc_authn_level_t;
715
716/***********************************************************************/
717/*
718 * R P C _ A U T H _ I N F O _ T
719 *
720 * The authentication data structures.  All authentication services capture
721 * their session information in a data structure that starts with an
722 * "rpc_auth_info_t".  "rpc_auth_info_t"s are attached to binding reps
723 * for bindings over which authenticated RPCs are to be performed.
724 *
725 * The "authn_svc" field determines which authentication service
726 * created and can manage an instance of this structure.  The
727 * "prot_auth_info" field is a pointer to session information that's
728 * private (and known only by) a particular authentication service and
729 * a particular RPC protocol service.
730 *
731 * All fields except those inside the union are valid regardless of whether
732 * the auth info is referenced from a server-side or client-side binding
733 * rep.  The "is_server" field determines which leg of the union is valid.
734 * If it's "true", then the "privs" field is valid, otherwise the
735 * "auth_identity" field is valid.
736 */
737typedef dce_pointer_t rpc_prot_auth_info_p_t;
738
739typedef struct
740{
741    rpc_list_t              cache_link;       /* MUST BE 1st */
742    unsigned16              refcount;
743    unsigned_char_p_t       server_princ_name;
744    rpc_authn_level_t       authn_level;
745    rpc_authn_protocol_id_t authn_protocol;
746    rpc_authz_protocol_id_t authz_protocol;
747    unsigned                is_server: 1;
748    union
749    {
750        rpc_auth_identity_handle_t  auth_identity;
751	struct
752	{
753	    rpc_authz_handle_t          privs;  /* pre 1.1 style credentials (client_name or PAC) */
754	    rpc_authz_cred_handle_t     *creds;  /* opaque 1.1+ style credentials */
755	} s;
756    } u;
757} rpc_auth_info_t, *rpc_auth_info_p_t;
758
759typedef struct
760{
761    unsigned16				refcount;
762    rpc_protseq_id_t			protseq;
763    rpc_transport_info_handle_t		handle;
764    const struct rpc_socket_vtbl_s *	vtbl;
765} rpc_transport_info_t, *rpc_transport_info_p_t;
766
767/***********************************************************************/
768
769/*
770 * Keying information (for encryption/integrity checks).
771 *
772 * One of these structures is associated with each 'connection' using
773 * a different key.
774 *
775 * There can be many of these associated with each common auth_info,
776 * which contains credential information.
777 *
778 * The "parent auth_info" contains the credentials used to send or
779 * receive the key(s) contained herein; this counts as a reference.
780 */
781
782typedef struct rpc_key_info_t {
783    rpc_auth_info_p_t           auth_info; /* parent auth_info */
784    unsigned                    refcnt: 16; /* reference count */
785    unsigned                    authn_level: 8;
786    unsigned                    is_server: 8;
787} rpc_key_info_t, *rpc_key_info_p_t;
788
789/***********************************************************************/
790/*
791 * R P C _ B I N D I N G _ R E P _ T
792 *
793 * The binding rep data structure. This is what a binding handle
794 * (handle_t) actually points to.
795 *
796 * Note well that the meaning (including validity) of some of these fields
797 * depends on context.  I.e., some fields don't really mean anything
798 * in case you're dealing with the binding rep that's passed to a server
799 * stub.
800 *
801 * A protocol service will typically define its own binding rep data
802 * structure with an "rpc_binding_rep_t" as its first field.
803 *
804 * A little clarification on some fields:
805 *
806 *  bound_server_instance   true iff the address in the binding handle
807 *                          has been used to actually communicate with
808 *                          a server and that subsequent calls using
809 *                          this handle should also go to this server.
810 *                          This flag is used to control call serialization
811 *                          so all calls go to the same server (support
812 *                          for concurrent / shared binding handles).
813 *                          Protocol services may also use this to
814 *                          determine whether or not "server binding
815 *                          information" (e.g. the rpc_addr info and/or
816 *                          protseq private info) needs to be initialized.
817 *
818 *  addr_has_endpoint       true iff the rpc_addr specifies an endpoint.
819 *                          This flag is used to support automatic call
820 *                          forwarding for "bound to host" binding handles.
821 *                          If bound_server_instance == true, then
822 *                          addr_has_endpoint must also be true (but
823 *                          not vice versa).
824 *
825 *  addr_is_dynamic         true iff the rpc_addr specifies an endpoint
826 *                          that was dynamically assigned.
827 *
828 *  calls_in_progress       used to prevent inappropriate API binding
829 *                          operations (e.g. rpc_binding_set_object)
830 *                          while calls are in progress.
831 *                          see RPC_BINDING_CALL_{START,END}()
832 *
833 *  refcnt                  used to support concurrent / shared handles.
834 *                          see RPC_BINDING_{REFERENCE,RELEASE}()
835 *
836 *  fork_count              The value of the global fork count at the time
837 *                          this handle was created.  This value is used is
838 *                          used to detect when an attempt is being made to
839 *                          use a binding handle across a fork.
840 *
841 *  extended_bind_flag      The flag indicates which extended information is
842 *                          attached to the binding handle.  Currently this
843 *                          can be either cs_method or cs_tags.  If this flag
844 *                          is set, there is more data attached to the binding
845 *                          in addition to the ordinary binding information.
846 */
847typedef struct rpc_handle_s_t
848{
849    /*
850     * The following fields are meaningful all the time.
851     */
852    rpc_list_t                  link;               /* This must be first! */
853    rpc_protocol_id_t           protocol_id;
854    signed8                     refcnt;
855    idl_uuid_t                      obj;
856    rpc_addr_p_t                rpc_addr;
857    unsigned                    is_server: 1;
858    unsigned                    addr_is_dynamic: 1;
859    rpc_auth_info_p_t           auth_info;
860    rpc_transport_info_p_t      transport_info;
861    unsigned32                  fork_count;
862    unsigned32			extended_bind_flag;
863    /*
864     * The following fields are not meaningful for binding reps
865     * that are passed to server stubs.
866     */
867    unsigned                    bound_server_instance: 1;
868    unsigned                    addr_has_endpoint: 1;
869    unsigned32                  timeout;    /* com timeout */
870    signed32                    calls_in_progress;
871    dce_pointer_t                   ns_specific;
872    rpc_clock_t                 call_timeout_time;  /* max execution time */
873    rpc_protocol_version_p_t    protocol_version;
874    rpc_cs_evaluation_t    	cs_eval;	/* code set i14y */
875    /*
876     *
877     */
878} rpc_binding_rep_t, *rpc_binding_rep_p_t;
879
880#define RPC_BINDING_IS_SERVER(binding_rep)    ((binding_rep)->is_server)
881#define RPC_BINDING_IS_CLIENT(binding_rep)    (! (binding_rep)->is_server)
882
883/*
884 * A string binding including '\0'.
885 *
886 * "object_uuid"@"protocol_sequence":"network_address"["endpoint"]
887 * "object_uuid"@"protocol_sequence":"network_address"[endpoint="endpoint"]
888 * "object_uuid"@"protocol_sequence":"network_address"\
889 *      [endpoint="endpoint",opt="opt"]
890 */
891#define RPC_C_STRING_BINDING_MAX        1088
892
893typedef unsigned_char_t rpc_string_binding_t[RPC_C_STRING_BINDING_MAX];
894
895/***********************************************************************/
896/*
897 * Signature of the call thread executor routine provided.
898 *
899 *      a routine whose address can be passed on a call to
900 *      rpc__cthread_invoke_null that will be called back by
901 *      the Call Thread Service when the thread is woken up
902 */
903typedef void (*rpc_prot_cthread_executor_fn_t) (
904        dce_pointer_t               /* args */,
905        boolean32               /* call_was_queued */
906    );
907
908/*
909 * R P C _ C T H R E A D _ P V T _ I N F O _ T
910 *
911 * Information *private* to the cthread-package.
912 *
913 * The "u.server.cthread." fields are logically PRIVATE to the cthread
914 * package; they just happen to reside directly in the call rep for
915 * convienience;  only the cthread package should be examining and
916 * modifying these fields.  Since these fields are logically internal
917 * to the cthread package, they are concurrency protected in a fashion
918 * that is most sensible for the package (which happens to ba a cthread
919 * package *internal* mutex, not the call rep's mutex)!
920 *
921 * The queued flag can probably be safely examined as long as no serious
922 * decision is made based on its value.  E.g., the protocol service might
923 * make some buffering policy decisions based on its value.).  If you
924 * want to do such things, use the RPC_CTHREAD_UNSAFE_IS_QUEUED macro
925 * so that it's obvious what you're doing.
926 *
927 * Note that we force storage unit alignment of the cthread private data.
928 * This is done because we must worry about hardware environments in
929 * which the code that references bit fields ends up dragging some larger
930 * unit from main memory, setting the bit and storing the unit back.
931 * This would end up reading and writing other call rep bits which are
932 * protected by the call rep mutex (which we won't be holding).
933 */
934typedef struct
935{
936    unsigned        : 0;            /* force alignment; see above */
937    unsigned        is_queued : 1;
938    rpc_prot_cthread_executor_fn_t
939                    executor;
940    dce_pointer_t       optargs;
941    dcethread*      thread_h;       /* valid iff !is_queued */
942    dce_pointer_t       qelt;           /* valid iff is_queued */
943    unsigned        : 0;            /* force alignment; see above */
944} rpc_cthread_pvt_info_t, *rpc_cthread_pvt_info_p_t;
945
946#define RPC_CTHREAD_UNSAFE_IS_QUEUED(call_rep)  \
947                (call_rep)->u.server.cthread.is_queued
948
949/***********************************************************************/
950/*
951 * R P C _ C A L L _ R E P _ T
952 *
953 * The call rep data structure. This is what the call handle
954 * (rpc_call_handle_t) actually points to.
955 *
956 * Note that there are two kinds of call reps:  server and client.  Both
957 * kinds of call reps have the same initial fields.  A union (.u) is
958 * used to contain the part that varies between server and client call
959 * reps; the .is_server field says which kind of call rep a particular
960 * instance is and which arm of the union is valid.
961 *
962 * A protocol service will typically define its own call rep data structure
963 * with an "rpc_call_rep_t" as its first field.
964 *
965 * The mutex is lower on the locking hierarchy than the global mutex
966 * (i.e. when both locks are required, the global lock must be acquired
967 * first to prevent deadlock).
968 */
969typedef struct
970{
971    rpc_list_t              link;               /* This must be first! */
972    rpc_mutex_t             m;                  /* common mutex */
973    rpc_protocol_id_t       protocol_id;        /* RPC protocol to dispatch to */
974    unsigned                is_server: 1;       /* union discriminator */
975    union                                       /* client or server? */
976    {
977        struct {                                /* server-only info */
978            struct                              /* common cancel info */
979            {
980                unsigned    accepting: 1;       /* T => can cancel cthread */
981                unsigned    queuing: 1;         /* T => queue cancel requests */
982                unsigned    had_pending: 1;     /* T => cthread had cancel pending */
983                unsigned16  count;              /* # of cancels sent to cthread */
984            } cancel;
985            rpc_cthread_pvt_info_t  cthread;    /* rpc__cthread *private*; see above */
986        } server;
987        struct {                                /* client-only info */
988            char            dummy;              /* no client-only info (yet) */
989        } client;
990    } u;
991} rpc_call_rep_t, *rpc_call_rep_p_t;
992
993#define RPC_CALL_IS_SERVER(call_h)  ((call_h)->is_server)
994#define RPC_CALL_IS_CLIENT(call_h)  (! (call_h)->is_server)
995
996/***********************************************************************/
997/*
998 * Call Rep Mutex lock macros
999 */
1000
1001#define RPC_CALL_LOCK_INIT(call)        RPC_MUTEX_INIT((call)->m)
1002#define RPC_CALL_LOCK(call)             RPC_MUTEX_LOCK((call)->m)
1003#define RPC_CALL_UNLOCK(call)           RPC_MUTEX_UNLOCK((call)->m)
1004#define RPC_CALL_TRY_LOCK(call, bp)     RPC_MUTEX_TRY_LOCK((call)->m,(bp))
1005#define RPC_CALL_LOCK_DELETE(call)      RPC_MUTEX_DELETE((call)->m)
1006#define RPC_CALL_LOCK_ASSERT(call)      RPC_MUTEX_LOCK_ASSERT((call)->m)
1007#define RPC_CALL_UNLOCK_ASSERT(call)    RPC_MUTEX_UNLOCKED_ASSERT(call->m)
1008
1009/***********************************************************************/
1010/*
1011 * R P C _ T H R E A D _ C O N T E X T _ T
1012 *
1013 * The thread context block data structure. The address of this structure
1014 * for a given thread can be obtained by doing a dcethread_getspecific() call
1015 * using the rpc_g_thread_context key. This structure can be extended as
1016 * needed to store any thread-specific context.
1017 */
1018typedef struct
1019{
1020    signed32                cancel_timeout;
1021    boolean32               ns_authn_state;
1022} rpc_thread_context_t, *rpc_thread_context_p_t;
1023
1024/***********************************************************************/
1025/*
1026 * Thread Context macros
1027 */
1028
1029/*
1030 * Get Thread Context - This macro should be called with a pointer to
1031 * an RPC thread context block.  If the macro had previously been called
1032 * within that thread it will return a pointer to the existing context
1033 * block.  If this is the first invocation within the thread a context
1034 * block will be created and set for the thread.  The user of this macro
1035 * should check the status value on completion to be sure everything
1036 * worked ok.  This macro depends on the fact that the thread context
1037 * key has been initialized (in rpc__init) and will fail if it hasn't
1038 * been.
1039 */
1040#define RPC_GET_THREAD_CONTEXT(thread_context, status) \
1041{ \
1042    *status = rpc_s_ok; \
1043\
1044    dcethread_getspecific_throw (rpc_g_thread_context_key, \
1045			 (dcethread_addr*)&thread_context); \
1046\
1047    if (thread_context == NULL) \
1048    { \
1049        RPC_MEM_ALLOC ( \
1050            thread_context, \
1051            rpc_thread_context_p_t, \
1052            sizeof (rpc_thread_context_t), \
1053            RPC_C_MEM_THREAD_CONTEXT, \
1054            RPC_C_MEM_WAITOK); \
1055\
1056        if (thread_context != NULL) \
1057        { \
1058            (thread_context)->cancel_timeout = rpc_c_cancel_infinite_timeout; \
1059            (thread_context)->ns_authn_state = true; \
1060            dcethread_setspecific_throw (rpc_g_thread_context_key, \
1061                (dcethread_addr)thread_context); \
1062        } \
1063        else \
1064        { \
1065            *status = rpc_s_no_memory; \
1066        } \
1067    } \
1068}
1069
1070#define RPC_SET_CANCEL_TIMEOUT(value, status) \
1071{ \
1072    rpc_thread_context_p_t      _thread_context; \
1073\
1074    RPC_GET_THREAD_CONTEXT (_thread_context, status); \
1075\
1076    if (*status == rpc_s_ok) \
1077    { \
1078        assert(_thread_context != NULL); \
1079        _thread_context->cancel_timeout = value; \
1080    } \
1081}
1082
1083#define RPC_GET_CANCEL_TIMEOUT(value, status) \
1084{ \
1085    rpc_thread_context_p_t      _thread_context; \
1086\
1087    RPC_GET_THREAD_CONTEXT (_thread_context, status); \
1088\
1089    if (*status == rpc_s_ok) \
1090    { \
1091        assert(_thread_context != NULL); \
1092        value = _thread_context->cancel_timeout; \
1093    } \
1094}
1095
1096/***********************************************************************/
1097/*
1098 * Runtime Global Mutex lock macros
1099 * (used for things that don't have their own lock)
1100 */
1101
1102#define RPC_LOCK_INIT(junk)        RPC_MUTEX_INIT(rpc_g_global_mutex)
1103#define RPC_LOCK(junk)             RPC_MUTEX_LOCK(rpc_g_global_mutex)
1104#define RPC_UNLOCK(junk)           RPC_MUTEX_UNLOCK(rpc_g_global_mutex)
1105#define RPC_TRY_LOCK(bp)           RPC_MUTEX_TRY_LOCK(rpc_g_global_mutex,(bp))
1106#define RPC_LOCK_DELETE(junk)      RPC_MUTEX_DELETE(rpc_g_global_mutex)
1107#define RPC_LOCK_ASSERT(junk)      RPC_MUTEX_LOCK_ASSERT(rpc_g_global_mutex)
1108#define RPC_UNLOCK_ASSERT(junk)    RPC_MUTEX_UNLOCKED_ASSERT(rpc_g_global_mutex)
1109
1110/*
1111 * Condition variable macros (here because there is no combind.h).
1112 */
1113#define RPC_BINDING_COND_INIT(junk) \
1114    RPC_COND_INIT(rpc_g_global_binding_cond, rpc_g_global_mutex)
1115
1116#define RPC_BINDING_COND_DELETE(junk) \
1117    RPC_COND_DELETE(rpc_g_global_binding_cond, rpc_g_global_mutex)
1118
1119#define RPC_BINDING_COND_WAIT(junk) \
1120    RPC_COND_WAIT(rpc_g_global_binding_cond, rpc_g_global_mutex)
1121
1122#define RPC_BINDING_COND_TIMED_WAIT(abstime) \
1123    RPC_COND_TIMED_WAIT(rpc_g_global_binding_cond, rpc_g_global_mutex, abstime)
1124
1125#define RPC_BINDING_COND_BROADCAST(junk) \
1126    RPC_COND_BROADCAST(rpc_g_global_binding_cond, rpc_g_global_mutex)
1127
1128/***********************************************************************/
1129/*
1130 * Possible values for the interface rep ".ifspec_vers" field.
1131 */
1132#define RPC_C_IFSPEC_VERS_DCE_1_0       1
1133
1134/*
1135 * Possible values for the interface rep ".stub_rtl_vers" field.
1136 */
1137
1138#define RPC_C_STUB_RTL_IF_VERS_NCS_1_0  0   /* NCS 1.0 / nidl -s */
1139#define RPC_C_STUB_RTL_IF_VERS_NCS_1_5  1   /* NCS 1.5 / nidl -m */
1140#define RPC_C_STUB_RTL_IF_VERS_DCE_1_0  2   /* DCE 1.0 RPC */
1141
1142#define RPC_IF_VALIDATE(ifrep, status) \
1143{ \
1144    if (!(ifrep)) \
1145    { \
1146	*(status) = rpc_s_coding_error; \
1147	return; \
1148    } \
1149    if ((ifrep)->ifspec_vers != RPC_C_IFSPEC_VERS_DCE_1_0) \
1150    { \
1151        *(status) = rpc_s_unknown_ifspec_vers; \
1152        return; \
1153    } \
1154    if ((ifrep)->stub_rtl_if_vers != RPC_C_STUB_RTL_IF_VERS_NCS_1_0 && \
1155        (ifrep)->stub_rtl_if_vers != RPC_C_STUB_RTL_IF_VERS_NCS_1_5 && \
1156        (ifrep)->stub_rtl_if_vers != RPC_C_STUB_RTL_IF_VERS_DCE_1_0) \
1157    { \
1158        *(status) = rpc_s_unknown_stub_rtl_if_vers; \
1159        return; \
1160    } \
1161    *(status) = rpc_s_ok; \
1162}
1163
1164/***********************************************************************/
1165/*
1166 * R P C _ F R E E _ I O V E _ B U F F E R
1167 *
1168 * Macro that calls and I/O vector element's dealloc routine and then munge
1169 * the element's pointer to avoid stupid mistakes.
1170 */
1171
1172#define RPC_FREE_IOVE_BUFFER(iove) { \
1173    assert((iove)->buff_dealloc != NULL); \
1174    (*(iove)->buff_dealloc)((iove)->buff_addr); \
1175    (iove)->buff_dealloc = NULL; \
1176    CLOBBER_PTR((iove)->buff_addr); \
1177    CLOBBER_PTR((iove)->data_addr); \
1178}
1179
1180/***********************************************************************/
1181/***********************************************************************/
1182/*
1183 * Note: This include for comsoc.h has to be after most of the typedef's
1184 * in this file, because they are used in it's prototype declaration.
1185 */
1186#include <comsoc.h>
1187
1188/***********************************************************************/
1189/***********************************************************************/
1190/*
1191 * Common Binding Services - shared macros and prototypes
1192 */
1193
1194/*
1195 * R P C _ B I N D I N G _ R E F E R E N C E
1196 *
1197 * Increment the reference count for the binding handle.
1198 */
1199
1200#define RPC_BINDING_REFERENCE(binding_rep_p_t) \
1201{ \
1202    RPC_LOCK_ASSERT(0); \
1203    (binding_rep_p_t)->refcnt++; \
1204    assert((binding_rep_p_t)->refcnt > 0); \
1205}
1206
1207/*
1208 * R P C _ B I N D I N G _ R E L E A S E
1209 *
1210 * Decrement the reference count for the binding handle and
1211 * NULL the reference (note this takes a &binding_rep_p_t).
1212 * Call the reall free routine if no more references exist.
1213 */
1214
1215#define RPC_BINDING_RELEASE(binding_rep_pp_t, status) { \
1216    RPC_LOCK_ASSERT(0); \
1217    assert((*(binding_rep_pp_t))->refcnt > 0); \
1218    if (--(*(binding_rep_pp_t))->refcnt == 0) \
1219        rpc__binding_free((binding_rep_pp_t), (status)); \
1220    else \
1221    { \
1222        *(binding_rep_pp_t) = NULL; \
1223        *(status) = rpc_s_ok; \
1224    } \
1225}
1226
1227/*
1228 * R P C _ B I N D I N G _ C A L L _ S T A R T
1229 *
1230 * A call_start has been performed using the binding handle,
1231 * increment the binding's calls_in_progress count.
1232 */
1233
1234#define RPC_BINDING_CALL_START(binding_rep_p_t) \
1235{ \
1236    RPC_LOCK_ASSERT(0); \
1237    (binding_rep_p_t)->calls_in_progress++; \
1238    assert((binding_rep_p_t)->calls_in_progress > 0); \
1239}
1240
1241/*
1242 * R P C _ B I N D I N G _ C A L L _ E N D
1243 *
1244 * A call_end has been performed using the binding handle,
1245 * decrement the binding's calls_in_progress count.
1246 */
1247
1248#define RPC_BINDING_CALL_END(binding_rep_p_t) { \
1249    RPC_LOCK_ASSERT(0); \
1250    assert((binding_rep_p_t)->calls_in_progress > 0); \
1251    --(binding_rep_p_t)->calls_in_progress; \
1252}
1253
1254PRIVATE void rpc__binding_free (
1255        rpc_binding_rep_p_t         * /* binding_rep */,
1256        unsigned32                  * /* status */
1257    );
1258
1259PRIVATE void rpc__string_netaddr_escape
1260(
1261        unsigned_char_p_t           /* netaddr */,
1262        unsigned_char_p_t           * /* escaped_netaddr */,
1263        unsigned32                  * /* status */
1264);
1265
1266PRIVATE void rpc__string_netaddr_unescape
1267(
1268        unsigned_char_p_t           /* escaped_netaddr */,
1269        unsigned_char_p_t           * /* netaddr */,
1270        unsigned32                  * /* status */
1271);
1272
1273PRIVATE rpc_binding_rep_t *rpc__binding_alloc (
1274        boolean32                   /* is_server */,
1275        uuid_p_t                    /* object_uuid */,
1276        rpc_protocol_id_t           /* protocol_id */,
1277        rpc_addr_p_t                /* rpc_addr */,
1278        unsigned32                  * /* status */
1279    );
1280
1281PRIVATE void rpc__binding_inq_sockaddr (
1282        rpc_binding_handle_t        /* binding_h */,
1283        sockaddr_p_t                */* sa */,
1284        unsigned32                  * /* status */
1285    );
1286
1287PRIVATE void rpc__binding_cross_fork (
1288        rpc_binding_rep_p_t         /* binding_rep */,
1289        unsigned32                  * /* status */
1290    );
1291
1292PRIVATE void rpc__binding_set_prot_version (
1293    rpc_binding_handle_t	   /* binding_h */,
1294    rpc_tower_ref_p_t		   /* tower_ref */,
1295    unsigned32			    * /* status */);
1296
1297PRIVATE void rpc__binding_prot_version_alloc (
1298    rpc_protocol_version_p_t    * /* prot_version */,
1299    unsigned32		          /* major_version */,
1300    unsigned32		          /* minor_version */,
1301    unsigned32		        * /* status */);
1302
1303PRIVATE void rpc__binding_prot_version_free (
1304    rpc_protocol_version_p_t	* /* protocol_version */ );
1305
1306/***********************************************************************/
1307/***********************************************************************/
1308/*
1309 * Common Call Services - shared macros and prototypes
1310 */
1311
1312/***********************************************************************/
1313/*
1314 * R P C _ _ C A L L _ R E J E C T
1315 *
1316 */
1317
1318PRIVATE void rpc__call_reject (
1319        rpc_call_rep_p_t            /* call_r */,
1320        unsigned32                  /* architected_status */,
1321        unsigned32                  status
1322    );
1323
1324/***********************************************************************/
1325/***********************************************************************/
1326/*
1327 * Common Call Thread Services - shared macros and prototypes
1328 */
1329
1330/***********************************************************************/
1331/***********************************************************************/
1332/*
1333 * Common Interface Services - shared macros and prototypes
1334 */
1335
1336PRIVATE void rpc__if_init (
1337        unsigned32                  * /* status */
1338    );
1339
1340PRIVATE void rpc__if_fork_handler (
1341        rpc_fork_stage_id_t stage
1342    );
1343
1344PRIVATE void rpc__if_lookup (
1345        uuid_p_t                    /* if_uuid */,
1346        unsigned32                  /* if_vers */,
1347        uuid_p_t                    /* type_uuid */,
1348        unsigned16                  */* ihint */,
1349        rpc_if_rep_p_t              */* ifspec */,
1350        rpc_v2_server_stub_epv_t    */* ss_epv */,
1351        rpc_mgr_epv_t               */* mgr_epv */,
1352        unsigned32                  * /* status */
1353    );
1354
1355PRIVATE void rpc__if_lookup2 (
1356        uuid_p_t                    /* if_uuid */,
1357        unsigned32                  /* if_vers */,
1358        uuid_p_t                    /* type_uuid */,
1359        unsigned16                  */* ihint */,
1360        rpc_if_rep_p_t              */* ifspec */,
1361        rpc_v2_server_stub_epv_t    */* ss_epv */,
1362        rpc_mgr_epv_t               */* mgr_epv */,
1363        unsigned32                  * /* flags */,
1364        unsigned32                  * /* max_calls */,
1365        unsigned32                  * /* max_rpc_size */,
1366        rpc_if_callback_fn_t        * /* if_callback */,
1367        unsigned32                  * /* status */
1368    );
1369
1370PRIVATE void rpc__if_set_wk_endpoint (
1371        rpc_if_rep_p_t              /* ifspec */,
1372        rpc_addr_p_t                */* rpc_addr */,
1373        unsigned32                  *st
1374    );
1375
1376PRIVATE boolean rpc__if_id_compare (
1377        rpc_if_id_p_t               /* if_id_ref */,
1378        rpc_if_id_p_t               /* if_id */,
1379        unsigned32                  /* if_vers_option */,
1380        unsigned32                  * /* status */
1381    );
1382
1383PRIVATE unsigned32 rpc__if_mgmt_inq_num_registered (void);
1384
1385PRIVATE void rpc__if_mgmt_inq_if_ids (
1386        rpc_if_id_vector_p_t        */* if_info */,
1387        unsigned32                  * /* status */
1388    );
1389
1390/***********************************************************************/
1391/***********************************************************************/
1392/*
1393 * Common Network Services - shared macros and prototypes
1394 */
1395
1396PRIVATE void rpc__network_init (
1397        unsigned32                  * /* status */
1398    );
1399
1400PRIVATE void rpc__network_fork_handler (
1401        rpc_fork_stage_id_t stage
1402    );
1403
1404PRIVATE void rpc__network_add_desc (
1405        rpc_socket_t                /* desc */,
1406        boolean32                   /* is_server */,
1407        boolean32                   /* is_dynamic */,
1408        rpc_protseq_id_t            /* rpc_protseq_id */,
1409        dce_pointer_t                   /* priv_info */,
1410        unsigned32                  * /* status */
1411    );
1412
1413PRIVATE void rpc__network_remove_desc (
1414        rpc_socket_t                /* desc */,
1415        unsigned32                  * /* status */
1416    );
1417
1418PRIVATE void rpc__network_set_priv_info (
1419        rpc_socket_t                /* desc */,
1420        dce_pointer_t                   /* priv_info */,
1421        unsigned32                  * /* status */
1422    );
1423
1424PRIVATE void rpc__network_inq_priv_info (
1425        rpc_socket_t                /* desc */,
1426        dce_pointer_t                   */* priv_info */,
1427        unsigned32                  * /* status */
1428    );
1429
1430PRIVATE void rpc__network_inq_prot_version (
1431        rpc_protseq_id_t            /* rpc_protseq_id */,
1432        unsigned8                   */* prot_id */,
1433        unsigned32                  */* version_major */,
1434        unsigned32                  */* version_minor */,
1435        unsigned32                  * /* status */
1436    );
1437
1438PRIVATE void rpc__network_pseq_from_pseq_id (
1439        rpc_protseq_id_t            /* rpc_protseq_id */,
1440        unsigned_char_p_t           */* protseq */,
1441        unsigned32                  * /* status */
1442    );
1443
1444PRIVATE rpc_protocol_id_t rpc__network_pseq_id_from_pseq   (
1445        unsigned_char_p_t           /* rpc_protseq */,
1446        unsigned32                  * /* status */
1447    );
1448
1449PRIVATE void rpc__network_inq_local_addr (
1450        rpc_protseq_id_t            /* rpc_protseq_id */,
1451        unsigned_char_p_t           /* endpoint */,
1452        rpc_addr_p_t                */* rpc_addr */,
1453        unsigned32                  * /* status */
1454    );
1455
1456/***********************************************************************/
1457/***********************************************************************/
1458/*
1459 * Common Network Address Family Services - shared macros and prototypes
1460 */
1461
1462PRIVATE void rpc__naf_addr_alloc (
1463        rpc_protseq_id_t            /* rpc_protseq_id */,
1464        rpc_naf_id_t                /* naf_id */,
1465        unsigned_char_p_t           /* endpoint */,
1466        unsigned_char_p_t           /* netaddr */,
1467        unsigned_char_p_t           /* network_options */,
1468        rpc_addr_p_t                */* rpc_addr */,
1469        unsigned32                  * /* status */
1470    );
1471
1472PRIVATE void rpc__naf_addr_copy (
1473        rpc_addr_p_t                /* src_rpc_addr */,
1474        rpc_addr_p_t                */* dst_rpc_addr */,
1475        unsigned32                  * /* status */
1476    );
1477
1478PRIVATE void rpc__naf_addr_overcopy (
1479        rpc_addr_p_t                /* src_rpc_addr */,
1480        rpc_addr_p_t                */* dst_rpc_addr */,
1481        unsigned32                  * /* status */
1482    );
1483
1484PRIVATE void rpc__naf_addr_free (
1485        rpc_addr_p_t                */* rpc_addr */,
1486        unsigned32                  * /* status */
1487    );
1488
1489PRIVATE void rpc__naf_addr_vector_free (
1490        rpc_addr_vector_p_t         */* rpc_addr_vec */,
1491        unsigned32                  * /* status */
1492    );
1493
1494PRIVATE void rpc__naf_addr_set_endpoint (
1495        unsigned_char_p_t           /* endpoint */,
1496        rpc_addr_p_t                */* rpc_addr */,
1497        unsigned32                  * /* status */
1498    );
1499
1500PRIVATE void rpc__naf_addr_inq_endpoint (
1501        rpc_addr_p_t                /* rpc_addr */,
1502        unsigned_char_t             **/* endpoint */,
1503        unsigned32                  * /* status */
1504    );
1505
1506PRIVATE void rpc__naf_addr_set_netaddr (
1507        unsigned_char_p_t           /* netaddr */,
1508        rpc_addr_p_t                */* rpc_addr */,
1509        unsigned32                  * /* status */
1510    );
1511
1512PRIVATE void rpc__naf_addr_inq_netaddr (
1513        rpc_addr_p_t                /* rpc_addr */,
1514        unsigned_char_t             **/* netaddr */,
1515        unsigned32                  * /* status */
1516    );
1517
1518PRIVATE void rpc__naf_addr_set_options (
1519        unsigned_char_p_t           /* network_options */,
1520        rpc_addr_p_t                */* rpc_addr */,
1521        unsigned32                  * /* status */
1522    );
1523
1524PRIVATE void rpc__naf_addr_inq_options (
1525        rpc_addr_p_t                /* rpc_addr */,
1526        unsigned_char_t             **/* network_options */,
1527        unsigned32                  * /* status */
1528    );
1529
1530PRIVATE void rpc__naf_desc_inq_addr (
1531        rpc_protseq_id_t            /* protseq_id */,
1532        rpc_socket_t                /* desc */,
1533        rpc_addr_vector_p_t         */* rpc_addr_vec */,
1534        unsigned32                  * /* status */
1535    );
1536
1537PRIVATE void rpc__naf_desc_inq_network (
1538        rpc_socket_t                /* desc */,
1539        rpc_naf_id_t                */* naf_id */,
1540        rpc_network_if_id_t         */* socket_type */,
1541        rpc_network_protocol_id_t   */* protocol_id */,
1542        unsigned32                  * /* status */
1543    );
1544
1545PRIVATE void rpc__naf_desc_inq_naf_id (
1546        rpc_socket_t                /* desc */,
1547        rpc_naf_id_t                */* naf_id */,
1548        unsigned32                  * /* status */
1549    );
1550
1551PRIVATE void rpc__naf_desc_inq_protseq_id (
1552        rpc_socket_t                /* desc */,
1553        rpc_network_protocol_id_t   /* protocol_id */,
1554        rpc_protseq_id_t            */* protseq_id */,
1555        unsigned32                  * /* status */
1556    );
1557
1558PRIVATE void rpc__naf_desc_inq_peer_addr (
1559        rpc_socket_t                /* desc */,
1560        rpc_protseq_id_t            /* protseq_id */,
1561        rpc_addr_p_t                */* addr */,
1562        unsigned32                  * /* status */
1563    );
1564
1565PRIVATE void rpc__naf_inq_max_tsdu (
1566        rpc_protseq_id_t            /* protseq_id */,
1567        unsigned32                  */* max_tsdu */,
1568        unsigned32                  * /* status */
1569    );
1570
1571PRIVATE void rpc__naf_get_broadcast (
1572        rpc_naf_id_t                /* naf_id */,
1573        rpc_protseq_id_t            /* protseq_id */,
1574        rpc_addr_vector_p_t         */* rpc_addrs */,
1575        unsigned32                  * /* status */
1576    );
1577
1578PRIVATE boolean rpc__naf_addr_compare (
1579        rpc_addr_p_t                /* addr1 */,
1580        rpc_addr_p_t                /* addr2 */,
1581        unsigned32                  * /* status */
1582    );
1583
1584PRIVATE void rpc__naf_inq_max_pth_unfrg_tpdu (
1585        rpc_addr_p_t                /* rpc_addr */,
1586        unsigned32                  */* max_tpdu */,
1587        unsigned32                  * /* status */
1588    );
1589
1590PRIVATE void rpc__naf_inq_max_loc_unfrg_tpdu (
1591        rpc_protseq_id_t            /* pseq_id */,
1592        unsigned32                  */* max_tpdu */,
1593        unsigned32                  * /* status */
1594    );
1595
1596PRIVATE void rpc__naf_set_pkt_nodelay (
1597        rpc_socket_t                /* desc */,
1598        rpc_addr_p_t                /* rpc_addr */,
1599        unsigned32                  * /* status */
1600    );
1601
1602PRIVATE boolean rpc__naf_is_connect_closed (
1603        rpc_socket_t                /* desc */,
1604        unsigned32                  * /* status */
1605    );
1606
1607PRIVATE void rpc__naf_inq_max_frag_size (
1608        rpc_addr_p_t                /* rpc_addr */,
1609        unsigned32                  * /* max_frag_size */,
1610        unsigned32                  * /* status */
1611    );
1612
1613/***********************************************************************/
1614/***********************************************************************/
1615/*
1616 * Common Object Services - shared macros and prototypes
1617 */
1618
1619PRIVATE void rpc__obj_init ( unsigned32 * /* status */ );
1620
1621PRIVATE void rpc__obj_fork_handler ( rpc_fork_stage_id_t );
1622
1623/***********************************************************************/
1624/***********************************************************************/
1625/*
1626 * Common Protocol Tower Services - shared macros and prototypes
1627 */
1628
1629PRIVATE void rpc__naf_addr_from_sa (
1630        sockaddr_p_t                /* sockaddr */,
1631        unsigned32                  /* sockaddr_len */,
1632        rpc_addr_p_t                */* rpc_addr */,
1633        unsigned32                  * /* status */
1634    );
1635
1636PRIVATE void rpc__naf_tower_flrs_from_addr (
1637        rpc_addr_p_t               /* rpc_addr */,
1638        twr_p_t                    */* lower_flrs */,
1639        unsigned32                 * /* status */
1640    );
1641
1642PRIVATE void rpc__naf_tower_flrs_to_addr (
1643        byte_p_t                   /* tower_octet_string */,
1644        rpc_addr_p_t               */* rpc_addr */,
1645        unsigned32                 * /* status */
1646    );
1647
1648/***********************************************************************/
1649/***********************************************************************/
1650/*
1651 * Common Server (object) Services - shared macros and prototypes
1652 */
1653
1654PRIVATE void rpc__server_register_if_int (
1655
1656        rpc_if_handle_t             /* ifspec_h */,
1657        uuid_p_t                    /* mgr_type_uuid */,
1658        rpc_mgr_epv_t               /* mgr_epv */,
1659        unsigned32                  /* flags */,
1660        unsigned32                  /* max_calls */,
1661        unsigned32                  /* max_rpc_size */,
1662        rpc_if_callback_fn_t        /* if_callback */,
1663        boolean32                   /* internal */,
1664        unsigned32                  * /* status */
1665    );
1666
1667PRIVATE void rpc__server_unregister_if_int (
1668        rpc_if_handle_t             /* ifspec_h */,
1669        uuid_p_t                    /* mgr_type_uuid */,
1670        rpc_if_handle_t             */* rtn_ifspec_h */,
1671        unsigned32                  * /* status */
1672    );
1673
1674PRIVATE void rpc__server_stop_listening (
1675        unsigned32                  * /* status */
1676    );
1677
1678PRIVATE boolean32 rpc__server_is_listening (void);
1679
1680PRIVATE void rpc__server_set_idle_timeout (
1681        unsigned32                  /* idle_secs */,
1682        unsigned32                  * /* status */
1683    );
1684
1685PRIVATE unsigned32 rpc__server_inq_idle_timeout (void);
1686
1687PRIVATE void rpc__server_incr_clients (void);
1688
1689PRIVATE void rpc__server_decr_clients (void);
1690
1691/***********************************************************************/
1692/***********************************************************************/
1693/*
1694 * Common Utility Services - shared macros and prototypes
1695 */
1696
1697PRIVATE unsigned32 rpc__strcspn (
1698        unsigned_char_p_t           /* string */,
1699        const char                  * /* term_set */
1700    );
1701
1702PRIVATE size_t rpc__get_token(
1703    const unsigned char       *string,
1704    unsigned_char_t	    escape,
1705    const char *       deliminators,
1706    unsigned_char_p_t       *token,
1707    unsigned32              *status
1708);
1709
1710PRIVATE void rpc__strncpy (
1711        unsigned_char_p_t           /* dst_string */,
1712        unsigned_char_p_t           /* src_string */,
1713        size_t                      /* max_length */
1714    );
1715
1716PRIVATE unsigned32 rpc__strsqz ( unsigned_char_p_t);
1717
1718PRIVATE unsigned_char_p_t rpc__stralloc ( unsigned_char_p_t);
1719
1720/***********************************************************************/
1721/***********************************************************************/
1722
1723/*
1724 * Name Service binding->ns_specific free function.
1725 */
1726
1727typedef void (*rpc_g_ns_specific_free_fn_t) (
1728        dce_pointer_t   * /* ns_specific*/
1729    );
1730
1731EXTERNAL rpc_g_ns_specific_free_fn_t  rpc_g_ns_specific_free_fn;
1732
1733/***********************************************************************/
1734/*
1735 * Common Authentication Services - shared macros and prototypes
1736 */
1737
1738/***********************************************************************/
1739/*
1740 * RPC Protocol specific authentication service EPV.
1741 */
1742
1743typedef void (*rpc_auth_rpc_prot_fn_t)(void );
1744
1745typedef struct
1746{
1747    rpc_auth_rpc_prot_fn_t      prot_specific;
1748} rpc_auth_rpc_prot_epv_t, *rpc_auth_rpc_prot_epv_p_t;
1749
1750typedef rpc_auth_rpc_prot_epv_p_t *rpc_auth_rpc_prot_epv_tbl_t;
1751typedef rpc_auth_rpc_prot_epv_tbl_t *rpc_auth_rpc_prot_epv_tbl_p_t;
1752
1753PRIVATE void rpc__auth_info_reference (
1754        rpc_auth_info_p_t       /* auth_info */
1755    );
1756
1757PRIVATE void rpc__auth_info_release (
1758        rpc_auth_info_p_t       * /* info */
1759    );
1760
1761PRIVATE rpc_auth_rpc_prot_epv_t *rpc__auth_rpc_prot_epv (
1762        rpc_authn_protocol_id_t /* authn_prot_id */,
1763        rpc_protocol_id_t       /* rpc_prot_id */
1764    );
1765
1766PRIVATE unsigned32 rpc__auth_cvt_id_api_to_wire (
1767        rpc_authn_protocol_id_t /* api_authn_prot_id */,
1768        unsigned32              * /* status */
1769    );
1770
1771PRIVATE rpc_authn_protocol_id_t rpc__auth_cvt_id_wire_to_api (
1772        unsigned32              /* wire_authn_prot_id */,
1773        unsigned32              * /* status */
1774    );
1775
1776PRIVATE boolean32 rpc__auth_inq_supported (rpc_authn_protocol_id_t);
1777
1778#endif /* _COM_H */
1779