Print this page
1575 untangle libmlrpc ... (libmlrpc)


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 #include <sys/errno.h>
  27 #include <string.h>
  28 #include <strings.h>
  29 
  30 #include <smbsrv/libsmb.h>
  31 #include <smbsrv/libmlrpc.h>
  32 
  33 #define NDR_DEFAULT_FRAGSZ      8192
  34 #define NDR_MULTI_FRAGSZ        (60 * 1024)
  35 
  36 static void ndr_clnt_init_hdr(ndr_client_t *, ndr_xa_t *);
  37 static int ndr_clnt_get_frags(ndr_client_t *, ndr_xa_t *);
  38 static int ndr_clnt_get_frag(ndr_client_t *, ndr_xa_t *, ndr_common_header_t *);
  39 
  40 int
  41 ndr_clnt_bind(ndr_client_t *clnt, const char *service_name,
  42     ndr_binding_t **ret_binding_p)
  43 {
  44         ndr_service_t           *msvc;
  45         ndr_binding_t           *mbind;
  46         ndr_xa_t                mxa;
  47         ndr_bind_hdr_t          *bhdr;
  48         ndr_p_cont_elem_t       *pce;
  49         ndr_bind_ack_hdr_t      *bahdr;
  50         ndr_p_result_t          *pre;
  51         int                     rc;
  52 
  53         bzero(&mxa, sizeof (mxa));
  54 
  55         msvc = ndr_svc_lookup_name(service_name);
  56         if (msvc == NULL)
  57                 return (NDR_DRC_FAULT_API_SERVICE_INVALID);
  58 
  59         mxa.binding_list = clnt->binding_list;
  60         if ((mbind = ndr_svc_new_binding(&mxa)) == NULL)
  61                 return (NDR_DRC_FAULT_API_BIND_NO_SLOTS);
  62 
  63         ndr_clnt_init_hdr(clnt, &mxa);
  64 
  65         bhdr = &mxa.send_hdr.bind_hdr;
  66         bhdr->common_hdr.ptype = NDR_PTYPE_BIND;
  67         bhdr->common_hdr.frag_length = sizeof (*bhdr);
  68         bhdr->max_xmit_frag = NDR_DEFAULT_FRAGSZ;
  69         bhdr->max_recv_frag = NDR_DEFAULT_FRAGSZ;
  70         bhdr->assoc_group_id = 0;
  71         bhdr->p_context_elem.n_context_elem = 1;
  72 
  73         /* Assign presentation context id */
  74         pce = &bhdr->p_context_elem.p_cont_elem[0];
  75         pce->p_cont_id = clnt->next_p_cont_id++;
  76         pce->n_transfer_syn = 1;
  77 
  78         /* Set up UUIDs and versions from the service */


 123                 return (NDR_DRC_FAULT_RECEIVED_MALFORMED);
 124 
 125         mbind->p_cont_id = pce->p_cont_id;
 126         mbind->which_side = NDR_BIND_SIDE_CLIENT;
 127         mbind->clnt = clnt;
 128         mbind->service = msvc;
 129         mbind->instance_specific = 0;
 130 
 131         *ret_binding_p = mbind;
 132         return (NDR_DRC_OK);
 133 
 134 fault_exit:
 135         (*clnt->xa_destruct)(clnt, &mxa);
 136         return (rc);
 137 }
 138 
 139 int
 140 ndr_clnt_call(ndr_binding_t *mbind, int opnum, void *params)
 141 {
 142         ndr_client_t            *clnt = mbind->clnt;
 143         ndr_service_t           *msvc = mbind->service;
 144         ndr_xa_t                mxa;
 145         ndr_request_hdr_t       *reqhdr;
 146         ndr_common_header_t     *rsphdr;
 147         unsigned long           recv_pdu_scan_offset;
 148         int                     rc;
 149 
 150         if (ndr_svc_lookup_name(msvc->name) == NULL)
 151                 return (NDR_DRC_FAULT_API_SERVICE_INVALID);
 152 
 153         bzero(&mxa, sizeof (mxa));
 154         mxa.ptype = NDR_PTYPE_REQUEST;
 155         mxa.opnum = opnum;
 156         mxa.binding = mbind;
 157 
 158         ndr_clnt_init_hdr(clnt, &mxa);
 159 
 160         reqhdr = &mxa.send_hdr.request_hdr;
 161         reqhdr->common_hdr.ptype = NDR_PTYPE_REQUEST;
 162         reqhdr->p_cont_id = mbind->p_cont_id;
 163         reqhdr->opnum = opnum;
 164 
 165         rc = (*clnt->xa_init)(clnt, &mxa);
 166         if (NDR_DRC_IS_FAULT(rc))
 167                 return (rc);
 168 
 169         /* Reserve room for hdr */
 170         mxa.send_nds.pdu_scan_offset = sizeof (*reqhdr);
 171 
 172         rc = ndr_encode_call(&mxa, params);




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  26  */
  27 
  28 #include <sys/errno.h>
  29 #include <string.h>
  30 #include <strings.h>
  31 
  32 #include <libmlrpc.h>

  33 
  34 #define NDR_DEFAULT_FRAGSZ      8192
  35 #define NDR_MULTI_FRAGSZ        (60 * 1024)
  36 
  37 static void ndr_clnt_init_hdr(ndr_client_t *, ndr_xa_t *);
  38 static int ndr_clnt_get_frags(ndr_client_t *, ndr_xa_t *);
  39 static int ndr_clnt_get_frag(ndr_client_t *, ndr_xa_t *, ndr_common_header_t *);
  40 
  41 int
  42 ndr_clnt_bind(ndr_client_t *clnt, ndr_service_t *msvc,
  43     ndr_binding_t **ret_binding_p)
  44 {

  45         ndr_binding_t           *mbind;
  46         ndr_xa_t                mxa;
  47         ndr_bind_hdr_t          *bhdr;
  48         ndr_p_cont_elem_t       *pce;
  49         ndr_bind_ack_hdr_t      *bahdr;
  50         ndr_p_result_t          *pre;
  51         int                     rc;
  52 
  53         bzero(&mxa, sizeof (mxa));
  54 




  55         mxa.binding_list = clnt->binding_list;
  56         if ((mbind = ndr_svc_new_binding(&mxa)) == NULL)
  57                 return (NDR_DRC_FAULT_API_BIND_NO_SLOTS);
  58 
  59         ndr_clnt_init_hdr(clnt, &mxa);
  60 
  61         bhdr = &mxa.send_hdr.bind_hdr;
  62         bhdr->common_hdr.ptype = NDR_PTYPE_BIND;
  63         bhdr->common_hdr.frag_length = sizeof (*bhdr);
  64         bhdr->max_xmit_frag = NDR_DEFAULT_FRAGSZ;
  65         bhdr->max_recv_frag = NDR_DEFAULT_FRAGSZ;
  66         bhdr->assoc_group_id = 0;
  67         bhdr->p_context_elem.n_context_elem = 1;
  68 
  69         /* Assign presentation context id */
  70         pce = &bhdr->p_context_elem.p_cont_elem[0];
  71         pce->p_cont_id = clnt->next_p_cont_id++;
  72         pce->n_transfer_syn = 1;
  73 
  74         /* Set up UUIDs and versions from the service */


 119                 return (NDR_DRC_FAULT_RECEIVED_MALFORMED);
 120 
 121         mbind->p_cont_id = pce->p_cont_id;
 122         mbind->which_side = NDR_BIND_SIDE_CLIENT;
 123         mbind->clnt = clnt;
 124         mbind->service = msvc;
 125         mbind->instance_specific = 0;
 126 
 127         *ret_binding_p = mbind;
 128         return (NDR_DRC_OK);
 129 
 130 fault_exit:
 131         (*clnt->xa_destruct)(clnt, &mxa);
 132         return (rc);
 133 }
 134 
 135 int
 136 ndr_clnt_call(ndr_binding_t *mbind, int opnum, void *params)
 137 {
 138         ndr_client_t            *clnt = mbind->clnt;

 139         ndr_xa_t                mxa;
 140         ndr_request_hdr_t       *reqhdr;
 141         ndr_common_header_t     *rsphdr;
 142         unsigned long           recv_pdu_scan_offset;
 143         int                     rc;
 144 



 145         bzero(&mxa, sizeof (mxa));
 146         mxa.ptype = NDR_PTYPE_REQUEST;
 147         mxa.opnum = opnum;
 148         mxa.binding = mbind;
 149 
 150         ndr_clnt_init_hdr(clnt, &mxa);
 151 
 152         reqhdr = &mxa.send_hdr.request_hdr;
 153         reqhdr->common_hdr.ptype = NDR_PTYPE_REQUEST;
 154         reqhdr->p_cont_id = mbind->p_cont_id;
 155         reqhdr->opnum = opnum;
 156 
 157         rc = (*clnt->xa_init)(clnt, &mxa);
 158         if (NDR_DRC_IS_FAULT(rc))
 159                 return (rc);
 160 
 161         /* Reserve room for hdr */
 162         mxa.send_nds.pdu_scan_offset = sizeof (*reqhdr);
 163 
 164         rc = ndr_encode_call(&mxa, params);