1 /* 2 * CDDL HEADER START 3 * 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 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _NSCD_DB_H 27 #define _NSCD_DB_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <nss_dbdefs.h> /* nssuint_t */ 34 #include "nscd_common.h" 35 36 /* make a pointer 8-byte aligned, or an integer a multiple of 8 */ 37 #define roundup(x) (((unsigned long)(x)+7) & ~7) 38 39 /* 40 * type of nscd data 41 */ 42 #define NSCD_DATA_UNKNOWN 0 43 #define NSCD_DATA_NSW_CONFIG 1 44 #define NSCD_DATA_NSW_STATE_BASE 2 45 #define NSCD_DATA_GETENT_CTX_BASE 3 46 #define NSCD_DATA_BACKEND_INFO 4 47 #define NSCD_DATA_BACKEND_INFO_DB 5 48 #define NSCD_DATA_CFG_NSW_DB_INDEX 6 49 #define NSCD_DATA_CFG_NSW_SRC_INDEX 7 50 #define NSCD_DATA_CFG_PARAM_INDEX 8 51 #define NSCD_DATA_CFG_STAT_INDEX 9 52 #define NSCD_DATA_ADDR 127 53 #define NSCD_DATA_CTX_ADDR 128 54 55 /* 56 * database operation options 57 */ 58 typedef enum { 59 NSCD_GET_FIRST_DB_ENTRY = 1, 60 NSCD_GET_NEXT_DB_ENTRY = 2, 61 NSCD_GET_EXACT_DB_ENTRY = 3, 62 NSCD_ADD_DB_ENTRY_FIRST = 4, 63 NSCD_ADD_DB_ENTRY_LAST = 5, 64 NSCD_ADD_DB_ENTRY_REPLACE = 6, 65 NSCD_ADD_DB_ENTRY_IF_NONE = 7, 66 NSCD_DEL_FIRST_DB_ENTRY = 8, 67 NSCD_DEL_ALL_DB_ENTRY = 9, 68 NSCD_DEL_EXACT_DB_ENTRY = 10 69 } nscd_db_option_t; 70 71 /* 72 * This structure defines an instance of the 73 * nscd database entry. 74 */ 75 typedef struct nscd_db_entry { 76 int type; 77 int id_num; 78 int num_data; 79 int num_array; 80 char *name; 81 void **data_array; 82 } nscd_db_entry_t; 83 84 /* 85 * sequence number attached to nscd data 86 */ 87 typedef nssuint_t nscd_seq_num_t; 88 typedef nssuint_t nscd_cookie_num_t; 89 90 /* 91 * The nscd_access_s datatype represents a nscd 92 * access data structure. It is an opaque structure. 93 */ 94 struct nscd_access_s; 95 typedef struct nscd_access_s nscd_access_t; 96 struct nscd_acc_data_s; 97 typedef struct nscd_acc_data_s nscd_acc_data_t; 98 99 /* 100 * The nscd_db_t datatype represents a nscd 101 * database. It is also an opaque structure. 102 */ 103 struct nscd_db_s; 104 typedef struct nscd_db_s nscd_db_t; 105 106 /* 107 * four sizes for a nscd database: 108 * large, medium, small, tiny 109 */ 110 #define NSCD_DB_SIZE_LARGE 1 111 #define NSCD_DB_SIZE_MEDIUM 2 112 #define NSCD_DB_SIZE_SMALL 3 113 #define NSCD_DB_SIZE_TINY 4 114 115 /* 116 * options for _nscd_alloc() 117 */ 118 #define NSCD_ALLOC_MUTEX 0x0001 119 #define NSCD_ALLOC_RWLOCK 0x0002 120 #define NSCD_ALLOC_COND 0x0004 121 122 /* 123 * prototypes 124 */ 125 nscd_seq_num_t 126 _nscd_get_seq_num(); 127 128 nscd_cookie_num_t 129 _nscd_get_cookie_num(); 130 131 nscd_acc_data_t * 132 _nscd_get( 133 nscd_acc_data_t *data); 134 135 nscd_acc_data_t 136 *_nscd_set( 137 nscd_acc_data_t *old, 138 nscd_acc_data_t *new); 139 140 void 141 _nscd_release( 142 nscd_acc_data_t *data); 143 144 nscd_acc_data_t 145 *_nscd_rdlock( 146 nscd_acc_data_t *data); 147 148 nscd_acc_data_t 149 *_nscd_wrlock( 150 nscd_acc_data_t *data); 151 152 void 153 _nscd_rw_unlock( 154 nscd_acc_data_t *data); 155 156 void 157 _nscd_rw_unlock_no_release( 158 nscd_acc_data_t *data); 159 160 nscd_acc_data_t 161 *_nscd_mutex_lock( 162 nscd_acc_data_t *data); 163 164 void 165 _nscd_mutex_unlock( 166 nscd_acc_data_t *data); 167 168 void 169 _nscd_cond_signal( 170 nscd_acc_data_t *data); 171 172 void 173 _nscd_cond_wait( 174 nscd_acc_data_t *data, 175 cond_t *cond); 176 177 nscd_acc_data_t * 178 _nscd_alloc( 179 int type, 180 size_t size, 181 void (*data_free)( 182 nscd_acc_data_t *data), 183 int option); 184 185 nscd_rc_t 186 _nscd_add_int_addr( 187 void *ptr, 188 int type, 189 nscd_seq_num_t seq_num); 190 191 rwlock_t * 192 _nscd_is_int_addr( 193 void *ptr, 194 nscd_seq_num_t seq_num); 195 196 void 197 _nscd_del_int_addr( 198 void *ptr, 199 nscd_seq_num_t seq_num); 200 201 nscd_db_t * 202 _nscd_alloc_db( 203 int size); 204 205 void 206 _nscd_free_db( 207 nscd_db_t *db); 208 209 nscd_db_entry_t * 210 _nscd_alloc_db_entry( 211 int type, 212 const char *name, 213 int dataSize, 214 int num_data, 215 int num_array); 216 217 const nscd_db_entry_t * 218 _nscd_get_db_entry( 219 const nscd_db_t *db, 220 int type, 221 const char *str, 222 nscd_db_option_t option, 223 int id_num); 224 225 nscd_rc_t 226 _nscd_add_db_entry( 227 nscd_db_t *db, 228 const char *str, 229 nscd_db_entry_t *entry, 230 nscd_db_option_t option); 231 232 nscd_rc_t 233 _nscd_delete_db_entry( 234 nscd_db_t *db, 235 int type, 236 const char *str, 237 nscd_db_option_t option, 238 int id_num); 239 240 241 void * 242 _nscd_create_int_addrDB(); 243 244 void 245 _nscd_destroy_int_addrDB(); 246 247 #ifdef __cplusplus 248 } 249 #endif 250 251 #endif /* _NSCD_DB_H */ 252