xref: /titanic_52/usr/src/lib/libnisdb/yptol/shim.h (revision 4a19049349b8aa3a6f741b8303a0a60e1fa770c9)
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	__SHIM_H
27 #define	__SHIM_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * DESCRIPTION: Shim header information not relating to hooks
37  *
38  */
39 
40 /*
41  * Structure for holding all the information relating to one map. These will
42  * probably end up in shared memory so everyone can get at them.
43  *
44  * DBM pointers are non NULL only while the file is open.
45  */
46 typedef struct {
47 	/* These are used in all modes */
48 	DBM	*entries;	/* NIS entry DBM file */
49 	int	hash_val;	/* Hash of name (to save repeated rehashing) */
50 
51 	/*
52 	 * Names.
53 	 *
54 	 * There is some duplication of information here but this enables these
55 	 * strings to be worked out once (when the map_ctrl is created) rather
56 	 * than many times as it is used.
57 	 */
58 	char	*map_name;	/* Name of map, unqualified */
59 	char	*domain;	/* Domain name */
60 	char 	*map_path;	/* Full qualified path to map */
61 
62 	/* These are used only in N2L mode */
63 	DBM	*ttl;		/* TTL DBM file */
64 	char	*ttl_path;	/* Full qualified path to TTL file */
65 	char	*trad_map_path;	/* Equivalent qualified traditional map name */
66 	datum	key_data;	/* See NOTE at top of shim.c */
67 
68 	/* Open parameters (in case of reopen ) */
69 	mode_t	open_mode;
70 	int	open_flags;
71 
72 	int	magic;		/* Check that this really is a map_ctrl */
73 
74 }map_ctrl;
75 #define	MAP_MAGIC	0x09876543
76 
77 /*
78  * Structure for holding unique map IDs.
79  * Used for locking purposes, in N2L mode only.
80  */
81 typedef struct map_id_elt {
82 	char *map_name;
83 	int map_id;
84 	struct map_id_elt *next;
85 } map_id_elt_t;
86 
87 /*
88  * Success and failure codes the same as used by DBM
89  */
90 typedef int suc_code;
91 #define	SUCCESS 0
92 #define	FAILURE -1
93 
94 /*
95  * Extern defs for new DBM calls. Must have identical args to traditional
96  * version.
97  */
98 extern void 	shim_dbm_close(DBM *db);
99 extern int 	shim_dbm_delete(DBM *db, datum key);
100 extern datum 	shim_dbm_fetch(DBM *db, datum key);
101 extern datum 	shim_dbm_fetch_noupdate(DBM *db, datum key);
102 extern datum	shim_dbm_firstkey(DBM *db);
103 extern datum 	shim_dbm_nextkey(DBM *db);
104 extern DBM 	*shim_dbm_open(const  char  *file,  int  open_flags,
105 				mode_t file_mode);
106 extern int  	shim_dbm_store(DBM  *db,  datum  key,  datum  content,
107 				int store_mode);
108 
109 /*
110  * Other externs
111  */
112 extern map_ctrl *get_map_ctrl(DBM *);
113 extern map_ctrl *create_map_ctrl(char *);
114 extern void 	free_map_ctrl(map_ctrl *);
115 extern map_ctrl *dup_map_ctrl(map_ctrl *);
116 extern void 	dump_map_ctrl(map_ctrl *);
117 extern suc_code map_ctrl_init(map_ctrl *map, char *name);
118 extern int	lock_map_ctrl(map_ctrl *map);
119 extern int	unlock_map_ctrl(map_ctrl *map);
120 extern int	map_id_list_init();
121 extern void	get_list_max(map_id_elt_t ***list, int *max);
122 
123 extern int	try_lock_map_update(map_ctrl *map);
124 extern suc_code lock_map_update(map_ctrl *map);
125 extern suc_code unlock_map_update(map_ctrl *map);
126 extern bool_t init_update_lock_map();
127 
128 /*
129  * Globals
130  */
131 extern bool_t yptol_mode;
132 extern bool_t yptol_newlock;
133 extern bool_t ypxfrd_flag;
134 extern int yp2ldap;
135 
136 /*
137  * String extensions used in N2L
138  */
139 
140 /* Prefix used for N2L map names */
141 #define	NTOL_PREFIX "LDAP_"
142 
143 /* Postfix used for TTL DBM files */
144 #define	TTL_POSTFIX "_TTL"
145 
146 /* Postfix for temporary files */
147 #define	TEMP_POSTFIX "_TMP"
148 
149 /* File separator character. If this is defined elsewhere can be removed */
150 #define	SEP_CHAR '/'
151 
152 /*
153  * Special keys used in DBM files. No real NIS map can use these keys.
154  */
155 #define	MAP_EXPIRY_KEY "YP_EXPIRY_TIME"
156 #define	MAP_OLD_MAP_DATE_KEY "YP_OLD_MAP_DATE_TIME"
157 
158 /* Mmaped file used for update flags shared memory */
159 #define	SHM_FILE "/var/run/nis_shim"
160 
161 /* used for map arrays reallocation purposes */
162 #define	ARRAY_CHUNK	10
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif	/* __SHIM_H */
169