Print this page
    
1575 untangle libmlrpc ... (libmlrpc)
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/lib/libmlrpc/common/libmlrpc.h
          +++ new/usr/src/lib/libmlrpc/common/libmlrpc.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  
    | 
      ↓ open down ↓ | 
    20 lines elided | 
    
      ↑ open up ↑ | 
  
  21   21  /*
  22   22   * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
  25   25  
  26   26  #ifndef _LIBMLRPC_H
  27   27  #define _LIBMLRPC_H
  28   28  
  29   29  #include <sys/types.h>
  30   30  #include <sys/uio.h>
  31      -#include <smbsrv/wintypes.h>
  32      -#include <smbsrv/ndr.h>
  33      -#include <smbsrv/smb_sid.h>
  34      -#include <smbsrv/smb_xdr.h>
  35   31  
       32 +#include <smb/wintypes.h>
       33 +#include <libmlrpc/ndr.h>
       34 +
  36   35  #ifdef  __cplusplus
  37   36  extern "C" {
  38   37  #endif
  39   38  
  40   39  /*
  41   40   * An MSRPC compatible implementation of OSF DCE RPC.  DCE RPC is derived
  42   41   * from the Apollo Network Computing Architecture (NCA) RPC implementation.
  43   42   *
  44   43   * CAE Specification (1997)
  45   44   * DCE 1.1: Remote Procedure Call
  46   45   * Document Number: C706
  47   46   * The Open Group
  48   47   * ogspecs@opengroup.org
  49   48   *
  50   49   * This implementation is based on the DCE Remote Procedure Call spec with
  51   50   * enhancements to support Unicode strings.  The diagram below shows the
  52   51   * DCE RPC layers compared against ONC SUN RPC.
  53   52   *
  54   53   *      NDR RPC Layers          Sun RPC Layers          Remark
  55   54   *      +---------------+       +---------------+       +---------------+
  56   55   *      +---------------+       +---------------+
  57   56   *      | Application   |       | Application   |       The application
  58   57   *      +---------------+       +---------------+
  59   58   *      | Hand coded    |       | RPCGEN gen'd  |       Where the real
  60   59   *      | client/server |       | client/server |       work happens
  61   60   *      | srvsvc.ndl    |       | *_svc.c *_clnt|
  62   61   *      | srvsvc.c      |       |               |
  63   62   *      +---------------+       +---------------+
  64   63   *      | RPC Library   |       | RPC Library   |       Calls/Return
  65   64   *      | ndr_*.c       |       |               |       Binding/PMAP
  66   65   *      +---------------+       +---------------+
  67   66   *      | RPC Protocol  |       | RPC Protocol  |       Headers, Auth,
  68   67   *      | rpcpdu.ndl    |       |               |
  69   68   *      +---------------+       +---------------+
  70   69   *      | IDL gen'd     |       | RPCGEN gen'd  |       Aggregate
  71   70   *      | NDR stubs     |       | XDR stubs     |       Composition
  72   71   *      | *__ndr.c      |       | *_xdr.c       |
  73   72   *      +---------------+       +---------------+
  74   73   *      | NDR Represen  |       | XDR Represen  |       Byte order, padding
  75   74   *      +---------------+       +---------------+
  76   75   *      | Packet Heaps  |       | Network Conn  |       DCERPC does not talk
  77   76   *      | ndo_*.c       |       | clnt_{tcp,udp}|       directly to network.
  78   77   *      +---------------+       +---------------+
  79   78   *
  80   79   * There are two major differences between the DCE RPC and ONC RPC:
  81   80   *
  82   81   * 1. NDR RPC only generates or processes packets from buffers.  Other
  83   82   *    layers must take care of packet transmission and reception.
  84   83   *    The packet heaps are managed through a simple interface provided
  85   84   *    by the Network Data Representation (NDR) module called ndr_stream_t.
  86   85   *    ndo_*.c modules implement the different flavors (operations) of
  87   86   *    packet heaps.
  88   87   *
  89   88   *    ONC RPC communicates directly with the network.  You have to do
  90   89   *    something special for the RPC packet to be placed in a buffer
  91   90   *    rather than sent to the wire.
  92   91   *
  93   92   * 2. NDR RPC uses application provided heaps to support operations.
  94   93   *    A heap is a single, monolithic chunk of memory that NDR RPC manages
  95   94   *    as it allocates.  When the operation and its result are done, the
  96   95   *    heap is disposed of as a single item.  The transaction, which
  97   96   *    is the anchor of most operations, contains the necessary book-
  98   97   *    keeping for the heap.
  99   98   *
 100   99   *    ONC RPC uses malloc() liberally throughout its run-time system.
 101  100   *    To free results, ONC RPC supports an XDR_FREE operation that
 102  101   *    traverses data structures freeing memory as it goes, whether
 103  102   *    it was malloc'd or not.
 104  103   */
 105  104  
 106  105  /*
 107  106   * Dispatch Return Code (DRC)
 108  107   *
 109  108   *      0x8000  15:01   Set to indicate a fault, clear indicates status
 110  109   *      0x7F00  08:07   Status/Fault specific
 111  110   *      0x00FF  00:08   PTYPE_... of PDU, 0xFF for header
 112  111   */
 113  112  #define NDR_DRC_OK                              0x0000
 114  113  #define NDR_DRC_MASK_FAULT                      0x8000
 115  114  #define NDR_DRC_MASK_SPECIFIER                  0xFF00
 116  115  #define NDR_DRC_MASK_PTYPE                      0x00FF
 117  116  
 118  117  /* Fake PTYPE DRC discriminators */
 119  118  #define NDR_DRC_PTYPE_RPCHDR(DRC)               ((DRC) | 0x00FF)
 120  119  #define NDR_DRC_PTYPE_API(DRC)                  ((DRC) | 0x00AA)
 121  120  
 122  121  /* DRC Recognizers */
 123  122  #define NDR_DRC_IS_OK(DRC)      (((DRC) & NDR_DRC_MASK_SPECIFIER) == 0)
 124  123  #define NDR_DRC_IS_FAULT(DRC)   (((DRC) & NDR_DRC_MASK_FAULT) != 0)
 125  124  
 126  125  /*
 127  126   * (Un)Marshalling category specifiers
 128  127   */
 129  128  #define NDR_DRC_FAULT_MODE_MISMATCH             0x8100
 130  129  #define NDR_DRC_RECEIVED                        0x0200
 131  130  #define NDR_DRC_FAULT_RECEIVED_RUNT             0x8300
 132  131  #define NDR_DRC_FAULT_RECEIVED_MALFORMED        0x8400
 133  132  #define NDR_DRC_DECODED                         0x0500
 134  133  #define NDR_DRC_FAULT_DECODE_FAILED             0x8600
 135  134  #define NDR_DRC_ENCODED                         0x0700
 136  135  #define NDR_DRC_FAULT_ENCODE_FAILED             0x8800
 137  136  #define NDR_DRC_FAULT_ENCODE_TOO_BIG            0x8900
 138  137  #define NDR_DRC_SENT                            0x0A00
 139  138  #define NDR_DRC_FAULT_SEND_FAILED               0x8B00
 140  139  
 141  140  /*
 142  141   * Resource category specifier
 143  142   */
 144  143  #define NDR_DRC_FAULT_RESOURCE_1                0x9100
 145  144  #define NDR_DRC_FAULT_RESOURCE_2                0x9200
 146  145  
 147  146  /*
 148  147   * Parameters. Usually #define'd with useful alias
 149  148   */
 150  149  #define NDR_DRC_FAULT_PARAM_0_INVALID           0xC000
 151  150  #define NDR_DRC_FAULT_PARAM_0_UNIMPLEMENTED     0xD000
 152  151  #define NDR_DRC_FAULT_PARAM_1_INVALID           0xC100
 153  152  #define NDR_DRC_FAULT_PARAM_1_UNIMPLEMENTED     0xD100
 154  153  #define NDR_DRC_FAULT_PARAM_2_INVALID           0xC200
 155  154  #define NDR_DRC_FAULT_PARAM_2_UNIMPLEMENTED     0xD200
 156  155  #define NDR_DRC_FAULT_PARAM_3_INVALID           0xC300
 157  156  #define NDR_DRC_FAULT_PARAM_3_UNIMPLEMENTED     0xD300
 158  157  
 159  158  #define NDR_DRC_FAULT_OUT_OF_MEMORY             0xF000
 160  159  
 161  160  /* RPCHDR */
 162  161  #define NDR_DRC_FAULT_RPCHDR_MODE_MISMATCH      0x81FF
 163  162  #define NDR_DRC_FAULT_RPCHDR_RECEIVED_RUNT      0x83FF
 164  163  #define NDR_DRC_FAULT_RPCHDR_DECODE_FAILED      0x86FF
 165  164  #define NDR_DRC_FAULT_RPCHDR_PTYPE_INVALID      0xC0FF  /* PARAM_0_INVALID */
 166  165  #define NDR_DRC_FAULT_RPCHDR_PTYPE_UNIMPLEMENTED 0xD0FF /* PARAM_0_UNIMP */
 167  166  
 168  167  /* Request */
 169  168  #define NDR_DRC_FAULT_REQUEST_PCONT_INVALID     0xC000  /* PARAM_0_INVALID */
 170  169  #define NDR_DRC_FAULT_REQUEST_OPNUM_INVALID     0xC100  /* PARAM_1_INVALID */
 171  170  
 172  171  /* Bind */
 173  172  #define NDR_DRC_BINDING_MADE                    0x000B  /* OK */
 174  173  #define NDR_DRC_FAULT_BIND_PCONT_BUSY           0xC00B  /* PARAM_0_INVALID */
 175  174  #define NDR_DRC_FAULT_BIND_UNKNOWN_SERVICE      0xC10B  /* PARAM_1_INVALID */
 176  175  #define NDR_DRC_FAULT_BIND_NO_SLOTS             0x910B  /* RESOURCE_1 */
 177  176  
 178  177  /* API */
 179  178  #define NDR_DRC_FAULT_API_SERVICE_INVALID       0xC0AA  /* PARAM_0_INVALID */
 180  179  #define NDR_DRC_FAULT_API_BIND_NO_SLOTS         0x91AA  /* RESOURCE_1 */
 181  180  #define NDR_DRC_FAULT_API_OPNUM_INVALID         0xC1AA  /* PARAM_1_INVALID */
 182  181  
 183  182  struct ndr_xa;
 184  183  struct ndr_client;
 185  184  
 186  185  typedef struct ndr_stub_table {
 187  186          int             (*func)(void *, struct ndr_xa *);
 188  187          unsigned short  opnum;
 189  188  } ndr_stub_table_t;
 190  189  
 191  190  typedef struct ndr_service {
 192  191          char            *name;
 193  192          char            *desc;
 194  193          char            *endpoint;
 195  194          char            *sec_addr_port;
 196  195          char            *abstract_syntax_uuid;
 197  196          int             abstract_syntax_version;
 198  197          char            *transfer_syntax_uuid;
 199  198          int             transfer_syntax_version;
 200  199          unsigned        bind_instance_size;
 201  200          int             (*bind_req)();
 202  201          int             (*unbind_and_close)();
 203  202          int             (*call_stub)(struct ndr_xa *);
 204  203          ndr_typeinfo_t  *interface_ti;
 205  204          ndr_stub_table_t *stub_table;
 206  205  } ndr_service_t;
 207  206  
 208  207  /*
 209  208   * The list of bindings is anchored at a connection.  Nothing in the
 210  209   * RPC mechanism allocates them.  Binding elements which have service==0
 211  210   * indicate free elements.  When a connection is instantiated, at least
 212  211   * one free binding entry should also be established.  Something like
 213  212   * this should suffice for most (all) situations:
 214  213   *
 215  214   *      struct connection {
 216  215   *              ....
 217  216   *              ndr_binding_t *binding_list_head;
 218  217   *              ndr_binding_t binding_pool[N_BINDING_POOL];
 219  218   *              ....
 220  219   *      };
 221  220   *
 222  221   *      init_connection(struct connection *conn) {
 223  222   *              ....
 224  223   *              ndr_svc_binding_pool_init(&conn->binding_list_head,
 225  224   *                  conn->binding_pool, N_BINDING_POOL);
 226  225   */
 227  226  typedef struct ndr_binding {
 228  227          struct ndr_binding      *next;
 229  228          ndr_p_context_id_t      p_cont_id;
 230  229          unsigned char           which_side;
 231  230          struct ndr_client       *clnt;
 232  231          ndr_service_t           *service;
 233  232          void                    *instance_specific;
 234  233  } ndr_binding_t;
 235  234  
 236  235  #define NDR_BIND_SIDE_CLIENT    1
 237  236  #define NDR_BIND_SIDE_SERVER    2
 238  237  
 239  238  #define NDR_BINDING_TO_SPECIFIC(BINDING, TYPE) \
 240  239          ((TYPE *) (BINDING)->instance_specific)
 241  240  
  
    | 
      ↓ open down ↓ | 
    196 lines elided | 
    
      ↑ open up ↑ | 
  
 242  241  /*
 243  242   * The binding list space must be provided by the application library
 244  243   * for use by the underlying RPC library.  We need at least two binding
 245  244   * slots per connection.
 246  245   */
 247  246  #define NDR_N_BINDING_POOL      2
 248  247  
 249  248  typedef struct ndr_pipe {
 250  249          void                    *np_listener;
 251  250          const char              *np_endpoint;
 252      -        smb_netuserinfo_t       *np_user;
      251 +        struct smb_netuserinfo  *np_user;
 253  252          int                     (*np_send)(struct ndr_pipe *, void *, size_t);
 254  253          int                     (*np_recv)(struct ndr_pipe *, void *, size_t);
 255  254          int                     np_fid;
 256  255          uint16_t                np_max_xmit_frag;
 257  256          uint16_t                np_max_recv_frag;
 258  257          ndr_binding_t           *np_binding;
 259  258          ndr_binding_t           np_binding_pool[NDR_N_BINDING_POOL];
 260  259  } ndr_pipe_t;
 261  260  
 262  261  /*
 263  262   * Number of bytes required to align SIZE on the next dword/4-byte
 264  263   * boundary.
 265  264   */
 266  265  #define NDR_ALIGN4(SIZE)        ((4 - (SIZE)) & 3);
 267  266  
 268  267  /*
 269  268   * DCE RPC strings (CAE section 14.3.4) are represented as varying or varying
 270  269   * and conformant one-dimensional arrays. Characters can be single-byte
 271  270   * or multi-byte as long as all characters conform to a fixed element size,
 272  271   * i.e. UCS-2 is okay but UTF-8 is not a valid DCE RPC string format. The
 273  272   * string is terminated by a null character of the appropriate element size.
 274  273   *
 275  274   * MSRPC strings should always be varying/conformant and not null terminated.
 276  275   * This format uses the size_is, first_is and length_is attributes (CAE
 277  276   * section 4.2.18).
 278  277   *
 279  278   *      typedef struct string {
 280  279   *              DWORD size_is;
 281  280   *              DWORD first_is;
 282  281   *              DWORD length_is;
 283  282   *              wchar_t string[ANY_SIZE_ARRAY];
 284  283   *      } string_t;
 285  284   *
 286  285   * The size_is attribute is used to specify the number of data elements in
 287  286   * each dimension of an array.
 288  287   *
 289  288   * The first_is attribute is used to define the lower bound for significant
 290  289   * elements in each dimension of an array. For strings this is always 0.
 291  290   *
 292  291   * The length_is attribute is used to define the number of significant
 293  292   * elements in each dimension of an array. For strings this is typically
 294  293   * the same as size_is. Although it might be (size_is - 1) if the string
 295  294   * is null terminated.
 296  295   *
 297  296   *   4 bytes   4 bytes   4 bytes  2bytes 2bytes 2bytes 2bytes
 298  297   * +---------+---------+---------+------+------+------+------+
 299  298   * |size_is  |first_is |length_is| char | char | char | char |
 300  299   * +---------+---------+---------+------+------+------+------+
 301  300   *
 302  301   * Unfortunately, not all MSRPC Unicode strings are null terminated, which
 303  302   * means that the recipient has to manually null-terminate the string after
 304  303   * it has been unmarshalled.  There may be a wide-char pad following a
 305  304   * string, and it may sometimes contains zero, but it's not guaranteed.
 306  305   *
 307  306   * To deal with this, MSRPC sometimes uses an additional wrapper with two
 308  307   * more fields, as shown below.
 309  308   *      length: the array length in bytes excluding terminating null bytes
 310  309   *      maxlen: the array length in bytes including null terminator bytes
 311  310   *      LPTSTR: converted to a string_t by NDR
 312  311   *
 313  312   * typedef struct ms_string {
 314  313   *              WORD length;
 315  314   *              WORD maxlen;
 316  315   *              LPTSTR str;
 317  316   * } ms_string_t;
 318  317   */
 319  318  typedef struct ndr_mstring {
 320  319          uint16_t length;
 321  320          uint16_t allosize;
 322  321          LPTSTR str;
 323  322  } ndr_mstring_t;
 324  323  
 325  324  /*
 326  325   * A number of heap areas are used during marshalling and unmarshalling.
 327  326   * Under some circumstances these areas can be discarded by the library
 328  327   * code, i.e. on the server side before returning to the client and on
 329  328   * completion of a client side bind.  In the case of a client side RPC
 330  329   * call, these areas must be preserved after an RPC returns to give the
 331  330   * caller time to take a copy of the data.  In this case the client must
 332  331   * call ndr_clnt_free_heap to free the memory.
 333  332   *
 334  333   * The heap management data definition looks a bit like this:
 335  334   *
 336  335   * heap -> +---------------+     +------------+
 337  336   *         | iovec[0].base | --> | data block |
 338  337   *         | iovec[0].len  |     +------------+
 339  338   *         +---------------+
 340  339   *                ::
 341  340   *                ::
 342  341   * iov  -> +---------------+     +------------+
 343  342   *         | iovec[n].base | --> | data block |
 344  343   *         | iovec[n].len  |     +------------+
 345  344   *         +---------------+     ^            ^
 346  345   *                               |            |
 347  346   *    next ----------------------+            |
 348  347   *    top  -----------------------------------+
 349  348   *
 350  349   */
 351  350  
 352  351  /*
 353  352   * Setting MAXIOV to 384 will use ((8 * 384) + 16) = 3088 bytes
 354  353   * of the first heap block.
 355  354   */
 356  355  #define NDR_HEAP_MAXIOV         384
 357  356  #define NDR_HEAP_BLKSZ          8192
 358  357  
 359  358  typedef struct ndr_heap {
 360  359          struct iovec iovec[NDR_HEAP_MAXIOV];
 361  360          struct iovec *iov;
 362  361          int iovcnt;
 363  362          char *top;
 364  363          char *next;
 365  364  } ndr_heap_t;
 366  365  
 367  366  /*
 368  367   * Alternate varying/conformant string definition
 369  368   * - for non-null-terminated strings.
 370  369   */
 371  370  typedef struct ndr_vcs {
 372  371          /*
 373  372           * size_is (actually a copy of length_is) will
 374  373           * be inserted here by the marshalling library.
 375  374           */
 376  375          uint32_t vc_first_is;
 377  376          uint32_t vc_length_is;
 378  377          uint16_t buffer[ANY_SIZE_ARRAY];
 379  378  } ndr_vcs_t;
 380  379  
 381  380  typedef struct ndr_vcstr {
 382  381          uint16_t wclen;
 383  382          uint16_t wcsize;
 384  383          ndr_vcs_t *vcs;
 385  384  } ndr_vcstr_t;
 386  385  
 387  386  typedef struct ndr_vcb {
 388  387          /*
 389  388           * size_is (actually a copy of length_is) will
 390  389           * be inserted here by the marshalling library.
 391  390           */
 392  391          uint32_t vc_first_is;
 393  392          uint32_t vc_length_is;
 394  393          uint8_t buffer[ANY_SIZE_ARRAY];
  
    | 
      ↓ open down ↓ | 
    132 lines elided | 
    
      ↑ open up ↑ | 
  
 395  394  } ndr_vcb_t;
 396  395  
 397  396  typedef struct ndr_vcbuf {
 398  397          uint16_t len;
 399  398          uint16_t size;
 400  399          ndr_vcb_t *vcb;
 401  400  } ndr_vcbuf_t;
 402  401  
 403  402  ndr_heap_t *ndr_heap_create(void);
 404  403  void ndr_heap_destroy(ndr_heap_t *);
      404 +void *ndr_heap_dupmem(ndr_heap_t *, const void *, size_t);
 405  405  void *ndr_heap_malloc(ndr_heap_t *, unsigned);
 406  406  void *ndr_heap_strdup(ndr_heap_t *, const char *);
 407  407  int ndr_heap_mstring(ndr_heap_t *, const char *, ndr_mstring_t *);
 408  408  void ndr_heap_mkvcs(ndr_heap_t *, char *, ndr_vcstr_t *);
 409  409  void ndr_heap_mkvcb(ndr_heap_t *, uint8_t *, uint32_t, ndr_vcbuf_t *);
 410      -smb_sid_t *ndr_heap_siddup(ndr_heap_t *, smb_sid_t *);
 411  410  int ndr_heap_used(ndr_heap_t *);
 412  411  int ndr_heap_avail(ndr_heap_t *);
 413  412  
 414  413  #define NDR_MALLOC(XA, SZ)      ndr_heap_malloc((XA)->heap, SZ)
 415  414  #define NDR_NEW(XA, T)          ndr_heap_malloc((XA)->heap, sizeof (T))
 416  415  #define NDR_NEWN(XA, T, N)      ndr_heap_malloc((XA)->heap, sizeof (T)*(N))
 417  416  #define NDR_STRDUP(XA, S)       ndr_heap_strdup((XA)->heap, (S))
 418  417  #define NDR_MSTRING(XA, S, OUT) ndr_heap_mstring((XA)->heap, (S), (OUT))
 419      -#define NDR_SIDDUP(XA, S)       ndr_heap_siddup((XA)->heap, (S))
      418 +#define NDR_SIDDUP(XA, S)       ndr_heap_dupmem((XA)->heap, (S), smb_sid_len(S))
 420  419  
 421  420  typedef struct ndr_xa {
 422  421          unsigned short          ptype;          /* high bits special */
 423  422          unsigned short          opnum;
 424  423          ndr_stream_t            recv_nds;
 425  424          ndr_hdr_t               recv_hdr;
 426  425          ndr_stream_t            send_nds;
 427  426          ndr_hdr_t               send_hdr;
 428  427          ndr_binding_t           *binding;       /* what we're using */
 429  428          ndr_binding_t           *binding_list;  /* from connection */
 430  429          ndr_heap_t              *heap;
 431  430          ndr_pipe_t              *pipe;
 432  431  } ndr_xa_t;
 433  432  
 434  433  /*
 435  434   * 20-byte opaque id used by various RPC services.
 436  435   */
 437  436  CONTEXT_HANDLE(ndr_hdid) ndr_hdid_t;
 438  437  
 439  438  typedef struct ndr_client {
 440  439          /* transport stuff (xa_* members) */
 441  440          int (*xa_init)(struct ndr_client *, ndr_xa_t *);
 442  441          int (*xa_exchange)(struct ndr_client *, ndr_xa_t *);
 443  442          int (*xa_read)(struct ndr_client *, ndr_xa_t *);
 444  443          void (*xa_preserve)(struct ndr_client *, ndr_xa_t *);
 445  444          void (*xa_destruct)(struct ndr_client *, ndr_xa_t *);
 446  445          void (*xa_release)(struct ndr_client *);
 447  446          void                    *xa_private;
 448  447          int                     xa_fd;
 449  448  
 450  449          ndr_hdid_t              *handle;
 451  450          ndr_binding_t           *binding;
 452  451          ndr_binding_t           *binding_list;
 453  452          ndr_binding_t           binding_pool[NDR_N_BINDING_POOL];
 454  453  
 455  454          boolean_t               nonull;
 456  455          boolean_t               heap_preserved;
 457  456          ndr_heap_t              *heap;
 458  457          ndr_stream_t            *recv_nds;
 459  458          ndr_stream_t            *send_nds;
 460  459  
 461  460          uint32_t                next_call_id;
 462  461          unsigned                next_p_cont_id;
 463  462  } ndr_client_t;
 464  463  
 465  464  typedef struct ndr_handle {
 466  465          ndr_hdid_t              nh_id;
 467  466          struct ndr_handle       *nh_next;
 468  467          ndr_pipe_t              *nh_pipe;
 469  468          const ndr_service_t     *nh_svc;
 470  469          ndr_client_t            *nh_clnt;
 471  470          void                    *nh_data;
 472  471          void                    (*nh_data_free)(void *);
 473  472  } ndr_handle_t;
 474  473  
 475  474  #define NDR_PDU_SIZE_HINT_DEFAULT       (16*1024)
 476  475  #define NDR_BUF_MAGIC                   0x4E425546      /* NBUF */
 477  476  
 478  477  typedef struct ndr_buf {
 479  478          uint32_t                nb_magic;
 480  479          ndr_stream_t            nb_nds;
  
    | 
      ↓ open down ↓ | 
    51 lines elided | 
    
      ↑ open up ↑ | 
  
 481  480          ndr_heap_t              *nb_heap;
 482  481          ndr_typeinfo_t          *nb_ti;
 483  482  } ndr_buf_t;
 484  483  
 485  484  /* ndr_ops.c */
 486  485  int nds_initialize(ndr_stream_t *, unsigned, int, ndr_heap_t *);
 487  486  void nds_destruct(ndr_stream_t *);
 488  487  void nds_show_state(ndr_stream_t *);
 489  488  
 490  489  /* ndr_client.c */
 491      -int ndr_clnt_bind(ndr_client_t *, const char *, ndr_binding_t **);
      490 +int ndr_clnt_bind(ndr_client_t *, ndr_service_t *, ndr_binding_t **);
 492  491  int ndr_clnt_call(ndr_binding_t *, int, void *);
 493  492  void ndr_clnt_free_heap(ndr_client_t *);
 494  493  
 495  494  /* ndr_marshal.c */
 496  495  ndr_buf_t *ndr_buf_init(ndr_typeinfo_t *);
 497  496  void ndr_buf_fini(ndr_buf_t *);
 498  497  int ndr_buf_decode(ndr_buf_t *, unsigned, unsigned, const char *data, size_t,
 499  498      void *);
 500  499  int ndr_decode_call(ndr_xa_t *, void *);
 501  500  int ndr_encode_return(ndr_xa_t *, void *);
 502  501  int ndr_encode_call(ndr_xa_t *, void *);
 503  502  int ndr_decode_return(ndr_xa_t *, void *);
 504  503  int ndr_decode_pdu_hdr(ndr_xa_t *);
 505  504  int ndr_encode_pdu_hdr(ndr_xa_t *);
 506  505  void ndr_decode_frag_hdr(ndr_stream_t *, ndr_common_header_t *);
  
    | 
      ↓ open down ↓ | 
    5 lines elided | 
    
      ↑ open up ↑ | 
  
 507  506  void ndr_remove_frag_hdr(ndr_stream_t *);
 508  507  void ndr_show_hdr(ndr_common_header_t *);
 509  508  unsigned ndr_bind_ack_hdr_size(ndr_xa_t *);
 510  509  unsigned ndr_alter_context_rsp_hdr_size(void);
 511  510  
 512  511  /* ndr_server.c */
 513  512  void ndr_pipe_worker(ndr_pipe_t *);
 514  513  
 515  514  int ndr_generic_call_stub(ndr_xa_t *);
 516  515  
 517      -boolean_t ndr_is_admin(ndr_xa_t *);
 518      -boolean_t ndr_is_poweruser(ndr_xa_t *);
 519      -int32_t ndr_native_os(ndr_xa_t *);
 520      -
 521  516  /* ndr_svc.c */
 522  517  ndr_stub_table_t *ndr_svc_find_stub(ndr_service_t *, int);
 523  518  ndr_service_t *ndr_svc_lookup_name(const char *);
 524  519  ndr_service_t *ndr_svc_lookup_uuid(ndr_uuid_t *, int, ndr_uuid_t *, int);
 525  520  int ndr_svc_register(ndr_service_t *);
 526  521  void ndr_svc_unregister(ndr_service_t *);
 527  522  void ndr_svc_binding_pool_init(ndr_binding_t **, ndr_binding_t pool[], int);
 528  523  ndr_binding_t *ndr_svc_find_binding(ndr_xa_t *, ndr_p_context_id_t);
 529  524  ndr_binding_t *ndr_svc_new_binding(ndr_xa_t *);
 530  525  
 531  526  int ndr_uuid_parse(char *, ndr_uuid_t *);
 532  527  void ndr_uuid_unparse(ndr_uuid_t *, char *);
 533  528  
 534  529  ndr_hdid_t *ndr_hdalloc(const ndr_xa_t *, const void *);
 535  530  void ndr_hdfree(const ndr_xa_t *, const ndr_hdid_t *);
 536  531  ndr_handle_t *ndr_hdlookup(const ndr_xa_t *, const ndr_hdid_t *);
 537  532  void ndr_hdclose(ndr_pipe_t *);
 538  533  
 539  534  ssize_t ndr_uiomove(caddr_t, size_t, enum uio_rw, struct uio *);
 540  535  
      536 +/*
      537 + * An ndr_client_t is created while binding a client connection to hold
      538 + * the context for calls made using that connection.
      539 + *
      540 + * Handles are RPC call specific and we use an inheritance mechanism to
      541 + * ensure that each handle has a pointer to the client_t.  When the top
      542 + * level (bind) handle is released, we close the connection.
      543 + *
      544 + * There are some places in libmlsvc where the code assumes that the
      545 + * handle member is first in this struct.  careful
      546 + */
      547 +typedef struct mlrpc_handle {
      548 +        ndr_hdid_t      handle;         /* keep first */
      549 +        ndr_client_t    *clnt;
      550 +} mlrpc_handle_t;
      551 +
      552 +int mlrpc_clh_create(mlrpc_handle_t *, void *);
      553 +uint32_t mlrpc_clh_bind(mlrpc_handle_t *, ndr_service_t *);
      554 +void mlrpc_clh_unbind(mlrpc_handle_t *);
      555 +void *mlrpc_clh_free(mlrpc_handle_t *);
      556 +
      557 +int ndr_rpc_call(mlrpc_handle_t *, int, void *);
      558 +int ndr_rpc_get_ssnkey(mlrpc_handle_t *, unsigned char *, size_t);
      559 +void *ndr_rpc_malloc(mlrpc_handle_t *, size_t);
      560 +ndr_heap_t *ndr_rpc_get_heap(mlrpc_handle_t *);
      561 +void ndr_rpc_release(mlrpc_handle_t *);
      562 +void ndr_rpc_set_nonull(mlrpc_handle_t *);
      563 +
      564 +boolean_t ndr_is_null_handle(mlrpc_handle_t *);
      565 +boolean_t ndr_is_bind_handle(mlrpc_handle_t *);
      566 +void ndr_inherit_handle(mlrpc_handle_t *, mlrpc_handle_t *);
      567 +
 541  568  #ifdef  __cplusplus
 542  569  }
 543  570  #endif
 544  571  
 545  572  #endif  /* _LIBMLRPC_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX