root/librpc/ndr/ndr_table.c

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

DEFINITIONS

This source file includes following definitions.
  1. ndr_table_register
  2. ndr_interface_name
  3. ndr_interface_num_calls
  4. ndr_table_by_name
  5. ndr_table_by_uuid
  6. ndr_table_list
  7. ndr_table_init

   1 /* 
   2    Unix SMB/CIFS implementation.
   3 
   4    dcerpc utility functions
   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 "../lib/util/dlinklist.h"
  25 #include "librpc/ndr/libndr.h"
  26 #include "librpc/ndr/ndr_table.h"
  27 #undef strcasecmp
  28 
  29 static struct ndr_interface_list *ndr_interfaces;
  30 
  31 /*
  32   register a ndr interface table
  33 */
  34 NTSTATUS ndr_table_register(const struct ndr_interface_table *table)
     /* [<][>][^][v][top][bottom][index][help] */
  35 {
  36         struct ndr_interface_list *l;
  37 
  38         for (l = ndr_interfaces; l; l = l->next) {
  39                 if (GUID_equal(&table->syntax_id.uuid, &l->table->syntax_id.uuid)) {
  40                         DEBUG(0, ("Attempt to register interface %s which has the "
  41                                   "same UUID as already registered interface %s\n", 
  42                                   table->name, l->table->name));
  43                         return NT_STATUS_OBJECT_NAME_COLLISION;
  44                 }
  45         }
  46 
  47         l = talloc(talloc_autofree_context(), struct ndr_interface_list);
  48         l->table = table;
  49 
  50         DLIST_ADD(ndr_interfaces, l);
  51 
  52         return NT_STATUS_OK;
  53 }
  54 
  55 /*
  56   find the pipe name for a local IDL interface
  57 */
  58 const char *ndr_interface_name(const struct GUID *uuid, uint32_t if_version)
     /* [<][>][^][v][top][bottom][index][help] */
  59 {
  60         const struct ndr_interface_list *l;
  61         for (l=ndr_table_list();l;l=l->next) {
  62                 if (GUID_equal(&l->table->syntax_id.uuid, uuid) &&
  63                     l->table->syntax_id.if_version == if_version) {
  64                         return l->table->name;
  65                 }
  66         }
  67         return "UNKNOWN";
  68 }
  69 
  70 /*
  71   find the number of calls defined by local IDL
  72 */
  73 int ndr_interface_num_calls(const struct GUID *uuid, uint32_t if_version)
     /* [<][>][^][v][top][bottom][index][help] */
  74 {
  75         const struct ndr_interface_list *l;
  76         for (l=ndr_interfaces;l;l=l->next){
  77                 if (GUID_equal(&l->table->syntax_id.uuid, uuid) &&
  78                     l->table->syntax_id.if_version == if_version) {
  79                         return l->table->num_calls;
  80                 }
  81         }
  82         return -1;
  83 }
  84 
  85 
  86 /*
  87   find a dcerpc interface by name
  88 */
  89 const struct ndr_interface_table *ndr_table_by_name(const char *name)
     /* [<][>][^][v][top][bottom][index][help] */
  90 {
  91         const struct ndr_interface_list *l;
  92         for (l=ndr_interfaces;l;l=l->next) {
  93                 if (strcasecmp(l->table->name, name) == 0) {
  94                         return l->table;
  95                 }
  96         }
  97         return NULL;
  98 }
  99 
 100 /*
 101   find a dcerpc interface by uuid
 102 */
 103 const struct ndr_interface_table *ndr_table_by_uuid(const struct GUID *uuid)
     /* [<][>][^][v][top][bottom][index][help] */
 104 {
 105         const struct ndr_interface_list *l;
 106         for (l=ndr_interfaces;l;l=l->next) {
 107                 if (GUID_equal(&l->table->syntax_id.uuid, uuid)) {
 108                         return l->table;
 109                 }
 110         }
 111         return NULL;
 112 }
 113 
 114 /*
 115   return the list of registered dcerpc_pipes
 116 */
 117 const struct ndr_interface_list *ndr_table_list(void)
     /* [<][>][^][v][top][bottom][index][help] */
 118 {
 119         return ndr_interfaces;
 120 }
 121 
 122 
 123 NTSTATUS ndr_table_init(void)
     /* [<][>][^][v][top][bottom][index][help] */
 124 {
 125         static bool initialized = false;
 126 
 127         if (initialized) return NT_STATUS_OK;
 128         initialized = true;
 129 
 130         ndr_table_register_builtin_tables();
 131 
 132         return NT_STATUS_OK;
 133 }

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