xref: /titanic_44/usr/src/lib/libnisdb/yptol/shim.h (revision 4a19049349b8aa3a6f741b8303a0a60e1fa770c9)
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
5*4a190493Ssdussud  * Common Development and Distribution License (the "License").
6*4a190493Ssdussud  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*4a190493Ssdussud  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	__SHIM_H
277c478bd9Sstevel@tonic-gate #define	__SHIM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * DESCRIPTION: Shim header information not relating to hooks
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Structure for holding all the information relating to one map. These will
427c478bd9Sstevel@tonic-gate  * probably end up in shared memory so everyone can get at them.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * DBM pointers are non NULL only while the file is open.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate typedef struct {
477c478bd9Sstevel@tonic-gate 	/* These are used in all modes */
487c478bd9Sstevel@tonic-gate 	DBM	*entries;	/* NIS entry DBM file */
497c478bd9Sstevel@tonic-gate 	int	hash_val;	/* Hash of name (to save repeated rehashing) */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 	/*
527c478bd9Sstevel@tonic-gate 	 * Names.
537c478bd9Sstevel@tonic-gate 	 *
547c478bd9Sstevel@tonic-gate 	 * There is some duplication of information here but this enables these
557c478bd9Sstevel@tonic-gate 	 * strings to be worked out once (when the map_ctrl is created) rather
567c478bd9Sstevel@tonic-gate 	 * than many times as it is used.
577c478bd9Sstevel@tonic-gate 	 */
587c478bd9Sstevel@tonic-gate 	char	*map_name;	/* Name of map, unqualified */
597c478bd9Sstevel@tonic-gate 	char	*domain;	/* Domain name */
607c478bd9Sstevel@tonic-gate 	char 	*map_path;	/* Full qualified path to map */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	/* These are used only in N2L mode */
637c478bd9Sstevel@tonic-gate 	DBM	*ttl;		/* TTL DBM file */
647c478bd9Sstevel@tonic-gate 	char	*ttl_path;	/* Full qualified path to TTL file */
657c478bd9Sstevel@tonic-gate 	char	*trad_map_path;	/* Equivalent qualified traditional map name */
667c478bd9Sstevel@tonic-gate 	datum	key_data;	/* See NOTE at top of shim.c */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	/* Open parameters (in case of reopen ) */
697c478bd9Sstevel@tonic-gate 	mode_t	open_mode;
707c478bd9Sstevel@tonic-gate 	int	open_flags;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	int	magic;		/* Check that this really is a map_ctrl */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate }map_ctrl;
757c478bd9Sstevel@tonic-gate #define	MAP_MAGIC	0x09876543
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
78*4a190493Ssdussud  * Structure for holding unique map IDs.
79*4a190493Ssdussud  * Used for locking purposes, in N2L mode only.
80*4a190493Ssdussud  */
81*4a190493Ssdussud typedef struct map_id_elt {
82*4a190493Ssdussud 	char *map_name;
83*4a190493Ssdussud 	int map_id;
84*4a190493Ssdussud 	struct map_id_elt *next;
85*4a190493Ssdussud } map_id_elt_t;
86*4a190493Ssdussud 
87*4a190493Ssdussud /*
887c478bd9Sstevel@tonic-gate  * Success and failure codes the same as used by DBM
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate typedef int suc_code;
917c478bd9Sstevel@tonic-gate #define	SUCCESS 0
927c478bd9Sstevel@tonic-gate #define	FAILURE -1
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Extern defs for new DBM calls. Must have identical args to traditional
967c478bd9Sstevel@tonic-gate  * version.
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate extern void 	shim_dbm_close(DBM *db);
997c478bd9Sstevel@tonic-gate extern int 	shim_dbm_delete(DBM *db, datum key);
1007c478bd9Sstevel@tonic-gate extern datum 	shim_dbm_fetch(DBM *db, datum key);
1017c478bd9Sstevel@tonic-gate extern datum 	shim_dbm_fetch_noupdate(DBM *db, datum key);
1027c478bd9Sstevel@tonic-gate extern datum	shim_dbm_firstkey(DBM *db);
1037c478bd9Sstevel@tonic-gate extern datum 	shim_dbm_nextkey(DBM *db);
1047c478bd9Sstevel@tonic-gate extern DBM 	*shim_dbm_open(const  char  *file,  int  open_flags,
1057c478bd9Sstevel@tonic-gate 				mode_t file_mode);
1067c478bd9Sstevel@tonic-gate extern int  	shim_dbm_store(DBM  *db,  datum  key,  datum  content,
1077c478bd9Sstevel@tonic-gate 				int store_mode);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * Other externs
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate extern map_ctrl *get_map_ctrl(DBM *);
1137c478bd9Sstevel@tonic-gate extern map_ctrl *create_map_ctrl(char *);
1147c478bd9Sstevel@tonic-gate extern void 	free_map_ctrl(map_ctrl *);
1157c478bd9Sstevel@tonic-gate extern map_ctrl *dup_map_ctrl(map_ctrl *);
1167c478bd9Sstevel@tonic-gate extern void 	dump_map_ctrl(map_ctrl *);
1177c478bd9Sstevel@tonic-gate extern suc_code map_ctrl_init(map_ctrl *map, char *name);
1187c478bd9Sstevel@tonic-gate extern int	lock_map_ctrl(map_ctrl *map);
1197c478bd9Sstevel@tonic-gate extern int	unlock_map_ctrl(map_ctrl *map);
120*4a190493Ssdussud extern int	map_id_list_init();
121*4a190493Ssdussud extern void	get_list_max(map_id_elt_t ***list, int *max);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate extern int	try_lock_map_update(map_ctrl *map);
1247c478bd9Sstevel@tonic-gate extern suc_code lock_map_update(map_ctrl *map);
1257c478bd9Sstevel@tonic-gate extern suc_code unlock_map_update(map_ctrl *map);
1267c478bd9Sstevel@tonic-gate extern bool_t init_update_lock_map();
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Globals
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate extern bool_t yptol_mode;
132*4a190493Ssdussud extern bool_t yptol_newlock;
1337c478bd9Sstevel@tonic-gate extern bool_t ypxfrd_flag;
1347c478bd9Sstevel@tonic-gate extern int yp2ldap;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * String extensions used in N2L
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /* Prefix used for N2L map names */
1417c478bd9Sstevel@tonic-gate #define	NTOL_PREFIX "LDAP_"
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /* Postfix used for TTL DBM files */
1447c478bd9Sstevel@tonic-gate #define	TTL_POSTFIX "_TTL"
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /* Postfix for temporary files */
1477c478bd9Sstevel@tonic-gate #define	TEMP_POSTFIX "_TMP"
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /* File separator character. If this is defined elsewhere can be removed */
1507c478bd9Sstevel@tonic-gate #define	SEP_CHAR '/'
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * Special keys used in DBM files. No real NIS map can use these keys.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate #define	MAP_EXPIRY_KEY "YP_EXPIRY_TIME"
1567c478bd9Sstevel@tonic-gate #define	MAP_OLD_MAP_DATE_KEY "YP_OLD_MAP_DATE_TIME"
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /* Mmaped file used for update flags shared memory */
1597c478bd9Sstevel@tonic-gate #define	SHM_FILE "/var/run/nis_shim"
1607c478bd9Sstevel@tonic-gate 
161*4a190493Ssdussud /* used for map arrays reallocation purposes */
162*4a190493Ssdussud #define	ARRAY_CHUNK	10
163*4a190493Ssdussud 
1647c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate #endif
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #endif	/* __SHIM_H */
169