17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * db_dictionary_c.x 247c478bd9Sstevel@tonic-gate * 25*a506a34cSth160488 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate %#pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #if RPC_HDR 327c478bd9Sstevel@tonic-gate %#ifndef _DB_DICTIONARY_H 337c478bd9Sstevel@tonic-gate %#define _DB_DICTIONARY_H 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef USINGC 367c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h" 377c478bd9Sstevel@tonic-gate %#include "nisdb_ldap.h" 387c478bd9Sstevel@tonic-gate %#include "db_entry_c.h" 397c478bd9Sstevel@tonic-gate %#include "db_scheme_c.h" 407c478bd9Sstevel@tonic-gate %#include "db_vers_c.h" 417c478bd9Sstevel@tonic-gate %#include "ldap_xdr.h" 427c478bd9Sstevel@tonic-gate %typedef void *nullptr; 437c478bd9Sstevel@tonic-gate %typedef u_int db_dict_version; 447c478bd9Sstevel@tonic-gate #else 457c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h" 467c478bd9Sstevel@tonic-gate %#include "nisdb_ldap.h" 477c478bd9Sstevel@tonic-gate %#include "db_entry.h" 487c478bd9Sstevel@tonic-gate %#include "db_scheme.h" 497c478bd9Sstevel@tonic-gate %#include "db.h" 507c478bd9Sstevel@tonic-gate %#include "db_vers.h" 517c478bd9Sstevel@tonic-gate %#include "db_dictlog.h" 527c478bd9Sstevel@tonic-gate %#include "ldap_xdr.h" 53*a506a34cSth160488 #endif /* USINGC */ 54*a506a34cSth160488 #endif /* RPC_HDR */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate struct db_table_desc { 577c478bd9Sstevel@tonic-gate string table_name<NIS_MAXNAMELEN>; 587c478bd9Sstevel@tonic-gate u_long hashval; 597c478bd9Sstevel@tonic-gate db_scheme * scheme; 607c478bd9Sstevel@tonic-gate #ifdef USINGC 617c478bd9Sstevel@tonic-gate nullptr database; /* for XDR, keep database from descriptor */ 627c478bd9Sstevel@tonic-gate #else 637c478bd9Sstevel@tonic-gate db *database; /* for program use in c++ code */ 64*a506a34cSth160488 #endif /* USINGC */ 657c478bd9Sstevel@tonic-gate db_table_desc *next; 667c478bd9Sstevel@tonic-gate }; 677c478bd9Sstevel@tonic-gate typedef struct db_table_desc * db_table_desc_p; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* Defining own version of xdr_db_dict_version */ 707c478bd9Sstevel@tonic-gate #if RPC_HDR 717c478bd9Sstevel@tonic-gate #ifndef USINGC 727c478bd9Sstevel@tonic-gate typedef u_int db_dict_version; 737c478bd9Sstevel@tonic-gate %bool_t xdr_db_dict_version(); 74*a506a34cSth160488 #endif /* USINGC */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate typedef char * db_table_namep; 777c478bd9Sstevel@tonic-gate typedef db_table_namep db_table_names<>; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* Defining own version of xdr_db_dict_desc */ 807c478bd9Sstevel@tonic-gate #ifndef USINGC 817c478bd9Sstevel@tonic-gate struct db_dict_desc { 827c478bd9Sstevel@tonic-gate db_dict_version impl_vers; 837c478bd9Sstevel@tonic-gate db_table_desc_p tables<>; 847c478bd9Sstevel@tonic-gate int count; 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate #else 877c478bd9Sstevel@tonic-gate %struct db_dict_desc { 887c478bd9Sstevel@tonic-gate % db_dict_version impl_vers; 897c478bd9Sstevel@tonic-gate % struct { 907c478bd9Sstevel@tonic-gate % u_int tables_len; 917c478bd9Sstevel@tonic-gate % db_table_desc_p *tables_val; 927c478bd9Sstevel@tonic-gate % } tables; 937c478bd9Sstevel@tonic-gate % int count; 947c478bd9Sstevel@tonic-gate %}; 957c478bd9Sstevel@tonic-gate %typedef struct db_dict_desc db_dict_desc; 967c478bd9Sstevel@tonic-gate %bool_t xdr_db_dict_desc(); 97*a506a34cSth160488 #endif /* USINGC */ 98*a506a34cSth160488 997c478bd9Sstevel@tonic-gate #endif 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate typedef struct db_dict_desc * db_dict_desc_p; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #if RPC_HDR 1047c478bd9Sstevel@tonic-gate struct __nisdb_dictionary_defer_struct { 1057c478bd9Sstevel@tonic-gate db_dict_desc *dictionary; /* Old incarnation */ 1067c478bd9Sstevel@tonic-gate }; 1077c478bd9Sstevel@tonic-gate typedef struct __nisdb_dictionary_defer_struct __nisdb_dictionary_defer_t; 1087c478bd9Sstevel@tonic-gate #ifdef USINGC 1097c478bd9Sstevel@tonic-gate %bool_t xdr___nisdb_dictionary_defer_t(); 110*a506a34cSth160488 #endif /* USINGC */ 1117c478bd9Sstevel@tonic-gate #endif 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #ifndef USINGC 1147c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 1157c478bd9Sstevel@tonic-gate %class db_dictionary { 1167c478bd9Sstevel@tonic-gate % db_dict_desc_p dictionary; 1177c478bd9Sstevel@tonic-gate % bool_t initialized; 1187c478bd9Sstevel@tonic-gate % char* filename; 1197c478bd9Sstevel@tonic-gate % char* tmpfilename; 1207c478bd9Sstevel@tonic-gate % char* logfilename; 1217c478bd9Sstevel@tonic-gate % db_dictlog *logfile; 1227c478bd9Sstevel@tonic-gate % bool_t logfile_opened; 1237c478bd9Sstevel@tonic-gate % bool_t changed; 1247c478bd9Sstevel@tonic-gate % __nisdb_dictionary_defer_t deferred; 1257c478bd9Sstevel@tonic-gate % __nisdb_flag_t noWriteThrough; 1267c478bd9Sstevel@tonic-gate % STRUCTRWLOCK(dict); 1277c478bd9Sstevel@tonic-gate % 1287c478bd9Sstevel@tonic-gate %/* Dump contents of this dictionary (minus the database representation) 1297c478bd9Sstevel@tonic-gate % to its file. Returns 0 if operation succeeds, -1 otherwise. */ 1307c478bd9Sstevel@tonic-gate % int dump(); 1317c478bd9Sstevel@tonic-gate % 1327c478bd9Sstevel@tonic-gate %/* Delete old log file and descriptor */ 1337c478bd9Sstevel@tonic-gate % int reset_log(); 1347c478bd9Sstevel@tonic-gate % 1357c478bd9Sstevel@tonic-gate %/* Open log file (and creates descriptor) if it has not been opened */ 1367c478bd9Sstevel@tonic-gate % int open_log(); 1377c478bd9Sstevel@tonic-gate % 1387c478bd9Sstevel@tonic-gate %/* Incorporate updates in log to dictionary already loaded. 1397c478bd9Sstevel@tonic-gate % Does not affect "logfile" */ 1407c478bd9Sstevel@tonic-gate % int incorporate_log( char * ); 1417c478bd9Sstevel@tonic-gate % 1427c478bd9Sstevel@tonic-gate % /* closes log file if opened */ 1437c478bd9Sstevel@tonic-gate % int close_log(); 1447c478bd9Sstevel@tonic-gate % 1457c478bd9Sstevel@tonic-gate %/* Log the given action and execute it. 1467c478bd9Sstevel@tonic-gate % The minor version of the dictionary is updated after the action has 1477c478bd9Sstevel@tonic-gate % been executed and the dictionary is flagged as being changed. 1487c478bd9Sstevel@tonic-gate % Return the structure db_result, or NULL if the loggin failed or the 1497c478bd9Sstevel@tonic-gate % action is unknown. */ 1507c478bd9Sstevel@tonic-gate % db_status log_action(int, char* table, table_obj* tobj =0); 1517c478bd9Sstevel@tonic-gate % 1527c478bd9Sstevel@tonic-gate % db_status create_table_desc(char* table_name, table_obj* table_desc, 1537c478bd9Sstevel@tonic-gate % db_table_desc**); 1547c478bd9Sstevel@tonic-gate % 1557c478bd9Sstevel@tonic-gate % db_dict_desc_p db_copy_dictionary(void); 1567c478bd9Sstevel@tonic-gate % 1577c478bd9Sstevel@tonic-gate % public: 1587c478bd9Sstevel@tonic-gate %/* Constructor: creates an empty, uninitialized dictionary. */ 1597c478bd9Sstevel@tonic-gate % db_dictionary(); 1607c478bd9Sstevel@tonic-gate % 1617c478bd9Sstevel@tonic-gate %/* Destructor: noop. Use db_shutdown if you really want to clean up. */ 1627c478bd9Sstevel@tonic-gate % ~db_dictionary() {} 1637c478bd9Sstevel@tonic-gate % 1647c478bd9Sstevel@tonic-gate % db_status merge_dict (db_dictionary&, char *, char *); 1657c478bd9Sstevel@tonic-gate % 1667c478bd9Sstevel@tonic-gate % db_status massage_dict (char *, char *, char *); 1677c478bd9Sstevel@tonic-gate % int db_clone_bucket (db_table_desc *, db_table_desc_p *); 1687c478bd9Sstevel@tonic-gate % int change_table_name (db_table_desc *, char *, char *); 1697c478bd9Sstevel@tonic-gate % bool_t extract_entries (db_dictionary&, char **, int ); 1707c478bd9Sstevel@tonic-gate % 1717c478bd9Sstevel@tonic-gate %/* Real destructor: deletes filename and table descriptors */ 1727c478bd9Sstevel@tonic-gate % db_status db_shutdown(); 1737c478bd9Sstevel@tonic-gate % 1747c478bd9Sstevel@tonic-gate %/* Initialize dictionary from contents in 'file'. 1757c478bd9Sstevel@tonic-gate % If there is already information in this dictionary, it is removed. 1767c478bd9Sstevel@tonic-gate % Therefore, regardless of whether the load from the file succeeds, 1777c478bd9Sstevel@tonic-gate % the contents of this dictionary will be altered. Returns 1787c478bd9Sstevel@tonic-gate % whether table has been initialized successfully. */ 1797c478bd9Sstevel@tonic-gate % bool_t init( char* fname ); 1807c478bd9Sstevel@tonic-gate % bool_t inittemp( char* fname, db_dictionary&); 1817c478bd9Sstevel@tonic-gate % 1827c478bd9Sstevel@tonic-gate %/* closes any open log files for all tables in dictionary or 'tab'. 1837c478bd9Sstevel@tonic-gate % "tab" is an optional argument. 1847c478bd9Sstevel@tonic-gate % */ 1857c478bd9Sstevel@tonic-gate % db_status db_standby( char* tab = 0 ); 1867c478bd9Sstevel@tonic-gate % 1877c478bd9Sstevel@tonic-gate %/* Write out in-memory copy of dictionary to file. 1887c478bd9Sstevel@tonic-gate % 1. Update major version. 1897c478bd9Sstevel@tonic-gate % 2. Dump contents to temporary file. 1907c478bd9Sstevel@tonic-gate % 3. Rename temporary file to real dictionary file. 1917c478bd9Sstevel@tonic-gate % 4. Remove log file. 1927c478bd9Sstevel@tonic-gate % A checkpoint is done only if it has changed since the previous checkpoint. 1937c478bd9Sstevel@tonic-gate % Returns TRUE if checkpoint was successful; FALSE otherwise. */ 1947c478bd9Sstevel@tonic-gate % db_status checkpoint(); 1957c478bd9Sstevel@tonic-gate % 1967c478bd9Sstevel@tonic-gate %/* Checkpoints table specified by 'tab', or all tables if 'tab' is 0. */ 1977c478bd9Sstevel@tonic-gate % db_status db_checkpoint( char* tab = 0 ); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate %/* Add table with given name 'tab' and description 'zdesc' to dictionary. 2007c478bd9Sstevel@tonic-gate % Returns error code if table already exists, or if no memory can be found 2017c478bd9Sstevel@tonic-gate % to store the descriptor, or if dictionary has not been intialized. 2027c478bd9Sstevel@tonic-gate % Dictionary is updated to stable store before addition. 2037c478bd9Sstevel@tonic-gate % Fatal error occurs if dictionary cannot be saved. 2047c478bd9Sstevel@tonic-gate % Returns DB_SUCCESS if dictionary has been updated successfully. */ 2057c478bd9Sstevel@tonic-gate % db_status add_table_aux(char* table_name, table_obj* table_desc, int mode); 2067c478bd9Sstevel@tonic-gate % 2077c478bd9Sstevel@tonic-gate %/* Delete table with given name 'tab' from dictionary. 2087c478bd9Sstevel@tonic-gate % Returns error code if table does not exist or if dictionary has not been 2097c478bd9Sstevel@tonic-gate % initialized. Dictionary is updated to stable store if deletion is 2107c478bd9Sstevel@tonic-gate % successful. Fatal error occurs if dictionary cannot be saved. 2117c478bd9Sstevel@tonic-gate % Returns DB_SUCCESS if dictionary has been updated successfully. 2127c478bd9Sstevel@tonic-gate % Note that the files associated with the table are also removed. */ 2137c478bd9Sstevel@tonic-gate % db_status delete_table_aux( char* table_name, int mode ); 2147c478bd9Sstevel@tonic-gate % 2157c478bd9Sstevel@tonic-gate % db_status add_table( char* table_name, table_obj* table_desc ); 2167c478bd9Sstevel@tonic-gate % int copyfile( char* infile, char *outfile); 2177c478bd9Sstevel@tonic-gate % 2187c478bd9Sstevel@tonic-gate % db_status delete_table( char* table_name ); 2197c478bd9Sstevel@tonic-gate % 2207c478bd9Sstevel@tonic-gate %/* Return database structure of table named by 'table_name'. 2217c478bd9Sstevel@tonic-gate % If 'where' is set, set it to the table_desc of 'table_name.' 2227c478bd9Sstevel@tonic-gate % The database is loaded in from stable store if it has not been loaded. 2237c478bd9Sstevel@tonic-gate % If it cannot be loaded, it is initialized using the scheme stored in 2247c478bd9Sstevel@tonic-gate % the table_desc. NULL is returned if the initialization fails. */ 2257c478bd9Sstevel@tonic-gate % db* find_table( char* table_name, db_table_desc ** where = NULL ); 2267c478bd9Sstevel@tonic-gate % 2277c478bd9Sstevel@tonic-gate % db *find_table(char *table_name, db_table_desc **where, 2287c478bd9Sstevel@tonic-gate % bool_t searchDeferred); 2297c478bd9Sstevel@tonic-gate % db *find_table(char *table_name, db_table_desc **where, 2307c478bd9Sstevel@tonic-gate % bool_t searchDeferred, bool_t doLDAP, 2317c478bd9Sstevel@tonic-gate % bool_t doLoad); 2327c478bd9Sstevel@tonic-gate % 2337c478bd9Sstevel@tonic-gate % db *find_table_noLDAP(char *table_name, db_table_desc **where, 2347c478bd9Sstevel@tonic-gate % bool_t searchDeferred, bool_t doLoad); 2357c478bd9Sstevel@tonic-gate % 2367c478bd9Sstevel@tonic-gate %/* Returns db_table_desc of table name 'tab'. 2377c478bd9Sstevel@tonic-gate % Use this if you do not want table to be loaded. */ 2387c478bd9Sstevel@tonic-gate % db_table_desc * find_table_desc( char* table_name ); 2397c478bd9Sstevel@tonic-gate % 2407c478bd9Sstevel@tonic-gate % db_table_desc * find_table_desc(char *table_name, bool_t searchDeferred); 2417c478bd9Sstevel@tonic-gate % 2427c478bd9Sstevel@tonic-gate %/* Translate given nis attribute list to a db_query structure. 2437c478bd9Sstevel@tonic-gate % Return FALSE if dictionary has not been initialized, or 2447c478bd9Sstevel@tonic-gate % table does not have a scheme (which should be a fatal error?). */ 2457c478bd9Sstevel@tonic-gate % db_query * translate_to_query( db_table_desc*, int, nis_attr * ); 2467c478bd9Sstevel@tonic-gate % 2477c478bd9Sstevel@tonic-gate %/* Return an array of strings of table names of all tables in dictionary. */ 2487c478bd9Sstevel@tonic-gate % db_table_names * get_table_names(); 2497c478bd9Sstevel@tonic-gate % 2507c478bd9Sstevel@tonic-gate %/* Set/clear no-write-through flag */ 2517c478bd9Sstevel@tonic-gate % void setNoWriteThrough(void); 2527c478bd9Sstevel@tonic-gate % void clearNoWriteThrough(void); 2537c478bd9Sstevel@tonic-gate % 2547c478bd9Sstevel@tonic-gate %/* Locking */ 2557c478bd9Sstevel@tonic-gate % int acqexcl(void) { 2567c478bd9Sstevel@tonic-gate % return(WLOCK(dict)); 2577c478bd9Sstevel@tonic-gate % } 2587c478bd9Sstevel@tonic-gate % 2597c478bd9Sstevel@tonic-gate % int relexcl(void) { 2607c478bd9Sstevel@tonic-gate % return (WULOCK(dict)); 2617c478bd9Sstevel@tonic-gate % } 2627c478bd9Sstevel@tonic-gate % 2637c478bd9Sstevel@tonic-gate % int acqnonexcl(void) { 2647c478bd9Sstevel@tonic-gate % return (RLOCK(dict)); 2657c478bd9Sstevel@tonic-gate % } 2667c478bd9Sstevel@tonic-gate % 2677c478bd9Sstevel@tonic-gate % int relnonexcl(void) { 2687c478bd9Sstevel@tonic-gate % return (RULOCK(dict)); 2697c478bd9Sstevel@tonic-gate % } 2707c478bd9Sstevel@tonic-gate % 2717c478bd9Sstevel@tonic-gate %/* Set deferred commit mode; intended for replica resync */ 2727c478bd9Sstevel@tonic-gate % db_status defer(char *table); 2737c478bd9Sstevel@tonic-gate % 2747c478bd9Sstevel@tonic-gate %/* Commit deferred changes; intended for replica resync */ 2757c478bd9Sstevel@tonic-gate % db_status commit(char *table); 2767c478bd9Sstevel@tonic-gate % 2777c478bd9Sstevel@tonic-gate %/* Roll back deferred changes; intended for replica resync */ 2787c478bd9Sstevel@tonic-gate % db_status rollback(char *table); 2797c478bd9Sstevel@tonic-gate %}; 2807c478bd9Sstevel@tonic-gate %#ifdef __STDC__ 2817c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_table_desc_p(XDR *, db_table_desc_p *); 2827c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_table_desc(XDR *, db_table_desc *); 2837c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_dict_desc_p(XDR *, db_dict_desc_p *); 2847c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_table_namep(XDR *, db_table_namep *); 2857c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_table_names(XDR *, db_table_names *); 2867c478bd9Sstevel@tonic-gate %#endif 2877c478bd9Sstevel@tonic-gate 288*a506a34cSth160488 #endif /* RPC_HDR */ 289*a506a34cSth160488 #endif /* USINGC */ 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate #if RPC_HDR 292*a506a34cSth160488 %#endif /* _DB_DICTIONARY_H */ 293*a506a34cSth160488 #endif /* RPC_HDR */ 2947c478bd9Sstevel@tonic-gate 295