1/* 2 * Copyright (c) 2010 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** rpcddb.h 82** 83** FACILITY: 84** 85** RPC Daemon Basic Database Routines - header file 86** 87** ABSTRACT: 88** 89** RPC Daemon basic database "private" types, defines, routines, ... 90** 91** 92*/ 93 94#ifndef RPCDDB_H 95#define RPCDDB_H 96 97/* 98 * Database entry list and hash table management typedefs 99 */ 100 101typedef enum db_list_type_t 102{ 103 db_c_entry_list, db_c_object_list, db_c_interface_list 104} db_list_type_t; 105 106/* 107 * forward and backward ptrs when used within an entry. 108 * first and last entry on list when used to manage a list 109 */ 110 111typedef struct db_list 112{ 113 struct db_list *fwd; 114 struct db_list *back; 115} db_list_t; 116 117typedef struct 118{ 119 db_list_t entry_list; 120 db_list_t object_list; 121 db_list_t interface_list; 122} db_lists_t, *db_lists_p_t; 123 124#define db_c_nbucket 64 125 126typedef db_list_t db_hash_table_t[db_c_nbucket]; 127 128typedef struct 129{ 130 db_list_t entry_list; 131 db_hash_table_t object_table; 132 db_hash_table_t interface_table; 133} db_lists_mgmt_t; 134 135/* 136 * The header of a persistant endpoint database file. 137 */ 138struct db_file_hdr { 139 unsigned32 version; 140 idl_uuid_t object; 141}; 142 143/* 144 * The internal structure of an ep database handle. 145 */ 146struct db { 147 dsm_handle_t dsh; 148 idl_uuid_t object; 149 db_lists_mgmt_t lists_mgmt; /* entry, object, interface lists mgmt */ 150 dcethread_mutex lock; /* Database mutex lock */ 151 dcethread* sliv_task1_h; /* Server liveness task 1 handle */ 152 dcethread* sliv_task2_h; /* Server liveness task 2 handle */ 153 dcethread_cond sliv_task2_cv; /* Server liveness condition variable used by 154 sliv_task1 to send an event to sliv_task2 */ 155}; 156 157/* 158 * This internal entry format is required to support 159 * the forwarding map mechanism (hence the rpc addr) 160 * and the DCE 1.0 endpoint mapper network interface. 161 * The queues are recreated at startup time. The addr 162 * field is derived from the tower at startup time. 163 * All other fields are stablely stored on the disk. 164 */ 165 166typedef struct 167{ 168 db_lists_t lists; 169 unsigned16 read_nrefs; /* # readers of this entry who have given up db_lock */ 170 unsigned16 ncomm_fails; /* # consecutive pings that have failed to this server */ 171 ndr_boolean delete_flag; /* entry should be deleted when read_nrefs == 0 */ 172 ndr_boolean object_nil; 173 ndr_boolean if_nil; 174 idl_uuid_t object; 175 rpc_if_id_t interface; 176 idl_uuid_t data_rep_id; 177 unsigned32 data_rep_vers_major; 178 unsigned32 data_rep_vers_minor; 179 rpc_protocol_id_t rpc_protocol; 180 unsigned32 rpc_protocol_vers_major; 181 unsigned32 rpc_protocol_vers_minor; 182 idl_uuid_t type; /* for LB compat */ 183 unsigned32 llb_flags; /* for LB compat */ 184 unsigned32 saddr_len; /* for LB compat */ 185 rpc_addr_p_t addr; 186 unsigned_char_t annotation[ept_max_annotation_size]; 187 twr_t tower; 188} db_entry_t, *db_entry_p_t; 189 190/* 191 * Max read references to an entry (must fit epdb_entry_t.read_nrefs - unsigned16) 192 * Leave some room for sliv_task1 and sliv_task2 so they don't need to check 193 * for overflow. 194 */ 195#define db_c_max_read_nrefs 0x0fff0 196 197PRIVATE void db_open 198 ( 199 struct db *h, 200 unsigned char *database_file, 201 unsigned32 version, 202 error_status_t *status 203 ); 204 205/* 206 * Update entry in place on disk 207 */ 208PRIVATE void db_update_entry 209 ( 210 struct db *h, 211 db_entry_p_t entp, 212 error_status_t *status 213 ); 214 215PRIVATE void db_init_lists 216 ( 217 struct db *h 218 ); 219 220PRIVATE void db_lists_add 221 ( 222 struct db *h, 223 db_entry_t *entp 224 ); 225 226PRIVATE void db_lists_remove 227 ( 228 struct db *h, 229 db_entry_t *entp 230 ); 231 232PRIVATE void db_htable_add 233 ( 234 db_hash_table_t htable, 235 db_list_type_t table_type, 236 uuid_p_t id, 237 db_lists_t *entp 238 ); 239 240PRIVATE void db_htable_remove 241 ( 242 db_hash_table_t htable, 243 db_list_type_t table_type, 244 uuid_p_t id, 245 db_lists_t *entp 246 ); 247 248PRIVATE void db_list_add 249 ( 250 db_list_t *list, 251 db_list_type_t list_type, 252 db_lists_t *entp 253 ); 254 255PRIVATE void db_list_remove 256 ( 257 db_list_t *list, 258 db_list_type_t list_type, 259 db_lists_t *entp 260 ); 261 262PRIVATE db_lists_t *db_list_first 263 ( 264 db_lists_mgmt_t *lists_mgmt, 265 db_list_type_t list_type, 266 uuid_p_t id 267 ); 268 269PRIVATE db_lists_t *db_list_next 270 ( 271 db_list_type_t list_type, 272 db_lists_t *entp 273 ); 274 275PRIVATE void db_save_context 276 ( 277 struct db *h, 278 ept_lookup_handle_t *entry_handle, 279 db_list_type_t list_type, 280 db_lists_t *lp, 281 unsigned32 pass 282 ); 283 284PRIVATE void db_delete_context 285 ( 286 struct db *h, 287 ept_lookup_handle_t *entry_handle 288 ); 289 290PRIVATE void db_get_context 291 ( 292 struct db *h, 293 ept_lookup_handle_t *entry_handle, 294 db_list_type_t *list_type, 295 db_lists_t **lp, 296 unsigned32 *pass, 297 error_status_t *status 298 ); 299 300PRIVATE boolean32 db_different_context 301 ( 302 struct db *h, 303 ept_lookup_handle_t *entry_handle, 304 error_status_t *status 305 ); 306 307PRIVATE void db_lock 308 ( 309 struct db *h 310 ); 311 312PRIVATE void db_unlock 313 ( 314 struct db *h 315 ); 316 317PRIVATE void db_init_lock 318 ( 319 struct db *h 320 ); 321 322PRIVATE void db_to_ept_ecode 323 ( 324 error_status_t *status 325 ); 326 327#endif 328