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