root/source4/rpc_server/epmapper/rpc_epmapper.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. build_ep_list
  2. dcesrv_epm_Insert
  3. dcesrv_epm_Delete
  4. dcesrv_epm_Lookup
  5. dcesrv_epm_Map
  6. dcesrv_epm_LookupHandleFree
  7. dcesrv_epm_InqObject
  8. dcesrv_epm_MgmtDelete
  9. dcesrv_epm_MapAuth

   1 /* 
   2    Unix SMB/CIFS implementation.
   3 
   4    endpoint server for the epmapper pipe
   5 
   6    Copyright (C) Andrew Tridgell 2003
   7    Copyright (C) Jelmer Vernooij 2004
   8    
   9    This program is free software; you can redistribute it and/or modify
  10    it under the terms of the GNU General Public License as published by
  11    the Free Software Foundation; either version 3 of the License, or
  12    (at your option) any later version.
  13    
  14    This program is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18    
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21 */
  22 
  23 #include "includes.h"
  24 #include "librpc/gen_ndr/ndr_epmapper.h"
  25 #include "rpc_server/dcerpc_server.h"
  26 #include "rpc_server/common/common.h"
  27 
  28 typedef uint32_t error_status_t;
  29 
  30 /* handle types for this module */
  31 enum handle_types {HTYPE_LOOKUP};
  32 
  33 /* a endpoint combined with an interface description */
  34 struct dcesrv_ep_iface {
  35         const char *name;
  36         struct epm_tower ep;
  37 };
  38 
  39 /*
  40   build a list of all interfaces handled by all endpoint servers
  41 */
  42 static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  43                               struct dcesrv_endpoint *endpoint_list,
  44                               struct dcesrv_ep_iface **eps)
  45 {
  46         struct dcesrv_endpoint *d;
  47         uint32_t total = 0;
  48         NTSTATUS status;
  49 
  50         *eps = NULL;
  51 
  52         for (d=endpoint_list; d; d=d->next) {
  53                 struct dcesrv_if_list *iface;
  54                 struct dcerpc_binding *description;
  55 
  56                 for (iface=d->interface_list;iface;iface=iface->next) {
  57                         (*eps) = talloc_realloc(mem_ctx, 
  58                                                   *eps, 
  59                                                   struct dcesrv_ep_iface,
  60                                                   total + 1);
  61                         if (!*eps) {
  62                                 return 0;
  63                         }
  64                         (*eps)[total].name = iface->iface.name;
  65 
  66                         description = d->ep_description;
  67                         description->object = iface->iface.syntax_id;
  68 
  69                         status = dcerpc_binding_build_tower(mem_ctx, description, &(*eps)[total].ep);
  70                         if (NT_STATUS_IS_ERR(status)) {
  71                                 DEBUG(1, ("Unable to build tower for %s\n", iface->iface.name));
  72                                 continue;
  73                         }
  74                         total++;
  75                 }
  76         }
  77 
  78         return total;
  79 }
  80 
  81 
  82 static error_status_t dcesrv_epm_Insert(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct epm_Insert *r)
     /* [<][>][^][v][top][bottom][index][help] */
  83 {
  84         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
  85 }
  86 
  87 static error_status_t dcesrv_epm_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 
     /* [<][>][^][v][top][bottom][index][help] */
  88                                  struct epm_Delete *r)
  89 {
  90         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
  91 }
  92 
  93 
  94 /*
  95   implement epm_Lookup. This call is used to enumerate the interfaces
  96   available on a rpc server
  97 */
  98 static error_status_t dcesrv_epm_Lookup(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 
     /* [<][>][^][v][top][bottom][index][help] */
  99                                  struct epm_Lookup *r)
 100 {
 101         struct dcesrv_handle *h;
 102         struct rpc_eps {
 103                 uint32_t count;
 104                 struct dcesrv_ep_iface *e;
 105         } *eps;
 106         uint32_t num_ents;
 107         int i;
 108 
 109         DCESRV_PULL_HANDLE_FAULT(h, r->in.entry_handle, HTYPE_LOOKUP);
 110 
 111         eps = h->data;
 112 
 113         if (!eps) {
 114                 /* this is the first call - fill the list. Subsequent calls 
 115                    will feed from this list, stored in the handle */
 116                 eps = talloc(h, struct rpc_eps);
 117                 if (!eps) {
 118                         return EPMAPPER_STATUS_NO_MEMORY;
 119                 }
 120                 h->data = eps;
 121 
 122                 eps->count = build_ep_list(h, dce_call->conn->dce_ctx->endpoint_list, &eps->e);
 123         }
 124 
 125         /* return the next N elements */
 126         num_ents = r->in.max_ents;
 127         if (num_ents > eps->count) {
 128                 num_ents = eps->count;
 129         }
 130 
 131         *r->out.entry_handle = h->wire_handle;
 132         r->out.num_ents = talloc(mem_ctx, uint32_t);
 133         *r->out.num_ents = num_ents;
 134 
 135         if (num_ents == 0) {
 136                 r->out.entries = NULL;
 137                 ZERO_STRUCTP(r->out.entry_handle);
 138                 talloc_free(h);
 139                 return EPMAPPER_STATUS_NO_MORE_ENTRIES;
 140         }
 141 
 142         r->out.entries = talloc_array(mem_ctx, struct epm_entry_t, num_ents);
 143         if (!r->out.entries) {
 144                 return EPMAPPER_STATUS_NO_MEMORY;
 145         }
 146 
 147         for (i=0;i<num_ents;i++) {
 148                 ZERO_STRUCT(r->out.entries[i].object);
 149                 r->out.entries[i].annotation = eps->e[i].name;
 150                 r->out.entries[i].tower = talloc(mem_ctx, struct epm_twr_t);
 151                 if (!r->out.entries[i].tower) {
 152                         return EPMAPPER_STATUS_NO_MEMORY;
 153                 }
 154                 r->out.entries[i].tower->tower = eps->e[i].ep;
 155         }
 156 
 157         eps->count -= num_ents;
 158         eps->e += num_ents;
 159 
 160         return EPMAPPER_STATUS_OK;
 161 }
 162 
 163 
 164 /*
 165   implement epm_Map. This is used to find the specific endpoint to talk to given
 166   a generic protocol tower
 167 */
 168 static error_status_t dcesrv_epm_Map(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 
     /* [<][>][^][v][top][bottom][index][help] */
 169                               struct epm_Map *r)
 170 {
 171         uint32_t count;
 172         int i;
 173         struct dcesrv_ep_iface *eps;
 174         struct epm_floor *floors;
 175         enum dcerpc_transport_t transport;
 176         struct ndr_syntax_id ndr_syntax;
 177 
 178         count = build_ep_list(mem_ctx, dce_call->conn->dce_ctx->endpoint_list, &eps);
 179 
 180         ZERO_STRUCT(*r->out.entry_handle);
 181         r->out.num_towers = talloc(mem_ctx, uint32_t);
 182         if (!r->out.num_towers) {
 183                 return EPMAPPER_STATUS_NO_MEMORY;
 184         }
 185         *r->out.num_towers = 1;
 186         r->out.towers = talloc(mem_ctx, struct epm_twr_p_t);
 187         if (!r->out.towers) {
 188                 return EPMAPPER_STATUS_NO_MEMORY;
 189         }
 190         r->out.towers->twr = talloc(mem_ctx, struct epm_twr_t);
 191         if (!r->out.towers->twr) {
 192                 return EPMAPPER_STATUS_NO_MEMORY;
 193         }
 194         
 195         if (!r->in.map_tower || r->in.max_towers == 0 || 
 196             r->in.map_tower->tower.num_floors < 3) {
 197                 goto failed;
 198         }
 199 
 200         floors = r->in.map_tower->tower.floors;
 201 
 202         dcerpc_floor_get_lhs_data(&r->in.map_tower->tower.floors[1], &ndr_syntax);
 203 
 204         if (floors[1].lhs.protocol != EPM_PROTOCOL_UUID ||
 205                 !GUID_equal(&ndr_syntax.uuid, &ndr_transfer_syntax.uuid) ||
 206             ndr_syntax.if_version != ndr_transfer_syntax.if_version) {
 207                 goto failed;
 208         }
 209 
 210         transport = dcerpc_transport_by_tower(&r->in.map_tower->tower);
 211 
 212         if (transport == -1) {
 213                 DEBUG(2, ("Client requested unknown transport with levels: "));
 214                 for (i = 2; i < r->in.map_tower->tower.num_floors; i++) {
 215                         DEBUG(2, ("%d, ", r->in.map_tower->tower.floors[i].lhs.protocol));
 216                 }
 217                 DEBUG(2, ("\n"));
 218                 goto failed;
 219         }
 220 
 221         for (i=0;i<count;i++) {
 222                 if (
 223                         data_blob_cmp(&r->in.map_tower->tower.floors[0].lhs.lhs_data, 
 224                         &eps[i].ep.floors[0].lhs.lhs_data) != 0 
 225                         || transport != dcerpc_transport_by_tower(&eps[i].ep)) {
 226                         continue;
 227                 }
 228                 
 229                 r->out.towers->twr->tower = eps[i].ep;
 230                 r->out.towers->twr->tower_length = 0;
 231                 return EPMAPPER_STATUS_OK;
 232         }
 233 
 234 
 235 failed:
 236         *r->out.num_towers = 0;
 237         r->out.towers->twr = NULL;
 238 
 239         return EPMAPPER_STATUS_NO_MORE_ENTRIES;
 240 }
 241 
 242 static error_status_t dcesrv_epm_LookupHandleFree(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 
     /* [<][>][^][v][top][bottom][index][help] */
 243                                            struct epm_LookupHandleFree *r)
 244 {
 245         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
 246 }
 247 
 248 static error_status_t dcesrv_epm_InqObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 
     /* [<][>][^][v][top][bottom][index][help] */
 249                                     struct epm_InqObject *r)
 250 {
 251         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
 252 }
 253 
 254 static error_status_t dcesrv_epm_MgmtDelete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 
     /* [<][>][^][v][top][bottom][index][help] */
 255                                struct epm_MgmtDelete *r)
 256 {
 257         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
 258 }
 259 
 260 static error_status_t dcesrv_epm_MapAuth(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 261                             struct epm_MapAuth *r)
 262 {
 263         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
 264 }
 265 
 266 /* include the generated boilerplate */
 267 #include "librpc/gen_ndr/ndr_epmapper_s.c"

/* [<][>][^][v][top][bottom][index][help] */