xref: /illumos-gate/usr/src/lib/libnisdb/yptol/shim.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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 #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * DESCRIPTION: Shim header information not relating to hooks
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Structure for holding all the information relating to one map. These will
407c478bd9Sstevel@tonic-gate  * probably end up in shared memory so everyone can get at them.
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * DBM pointers are non NULL only while the file is open.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate typedef struct {
457c478bd9Sstevel@tonic-gate 	/* These are used in all modes */
467c478bd9Sstevel@tonic-gate 	DBM	*entries;	/* NIS entry DBM file */
477c478bd9Sstevel@tonic-gate 	int	hash_val;	/* Hash of name (to save repeated rehashing) */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 	/*
507c478bd9Sstevel@tonic-gate 	 * Names.
517c478bd9Sstevel@tonic-gate 	 *
527c478bd9Sstevel@tonic-gate 	 * There is some duplication of information here but this enables these
537c478bd9Sstevel@tonic-gate 	 * strings to be worked out once (when the map_ctrl is created) rather
547c478bd9Sstevel@tonic-gate 	 * than many times as it is used.
557c478bd9Sstevel@tonic-gate 	 */
567c478bd9Sstevel@tonic-gate 	char	*map_name;	/* Name of map, unqualified */
577c478bd9Sstevel@tonic-gate 	char	*domain;	/* Domain name */
587c478bd9Sstevel@tonic-gate 	char 	*map_path;	/* Full qualified path to map */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	/* These are used only in N2L mode */
617c478bd9Sstevel@tonic-gate 	DBM	*ttl;		/* TTL DBM file */
627c478bd9Sstevel@tonic-gate 	char	*ttl_path;	/* Full qualified path to TTL file */
637c478bd9Sstevel@tonic-gate 	char	*trad_map_path;	/* Equivalent qualified traditional map name */
647c478bd9Sstevel@tonic-gate 	datum	key_data;	/* See NOTE at top of shim.c */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/* Open parameters (in case of reopen ) */
677c478bd9Sstevel@tonic-gate 	mode_t	open_mode;
687c478bd9Sstevel@tonic-gate 	int	open_flags;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	int	magic;		/* Check that this really is a map_ctrl */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate }map_ctrl;
737c478bd9Sstevel@tonic-gate #define	MAP_MAGIC	0x09876543
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
76*4a190493Ssdussud  * Structure for holding unique map IDs.
77*4a190493Ssdussud  * Used for locking purposes, in N2L mode only.
78*4a190493Ssdussud  */
79*4a190493Ssdussud typedef struct map_id_elt {
80*4a190493Ssdussud 	char *map_name;
81*4a190493Ssdussud 	int map_id;
82*4a190493Ssdussud 	struct map_id_elt *next;
83*4a190493Ssdussud } map_id_elt_t;
84*4a190493Ssdussud 
85*4a190493Ssdussud /*
867c478bd9Sstevel@tonic-gate  * Success and failure codes the same as used by DBM
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate typedef int suc_code;
897c478bd9Sstevel@tonic-gate #define	SUCCESS 0
907c478bd9Sstevel@tonic-gate #define	FAILURE -1
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * Extern defs for new DBM calls. Must have identical args to traditional
947c478bd9Sstevel@tonic-gate  * version.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate extern void 	shim_dbm_close(DBM *db);
977c478bd9Sstevel@tonic-gate extern int 	shim_dbm_delete(DBM *db, datum key);
987c478bd9Sstevel@tonic-gate extern datum 	shim_dbm_fetch(DBM *db, datum key);
997c478bd9Sstevel@tonic-gate extern datum 	shim_dbm_fetch_noupdate(DBM *db, datum key);
1007c478bd9Sstevel@tonic-gate extern datum	shim_dbm_firstkey(DBM *db);
1017c478bd9Sstevel@tonic-gate extern datum 	shim_dbm_nextkey(DBM *db);
1027c478bd9Sstevel@tonic-gate extern DBM 	*shim_dbm_open(const  char  *file,  int  open_flags,
1037c478bd9Sstevel@tonic-gate 				mode_t file_mode);
1047c478bd9Sstevel@tonic-gate extern int  	shim_dbm_store(DBM  *db,  datum  key,  datum  content,
1057c478bd9Sstevel@tonic-gate 				int store_mode);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Other externs
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate extern map_ctrl *get_map_ctrl(DBM *);
1117c478bd9Sstevel@tonic-gate extern map_ctrl *create_map_ctrl(char *);
1127c478bd9Sstevel@tonic-gate extern void 	free_map_ctrl(map_ctrl *);
1137c478bd9Sstevel@tonic-gate extern map_ctrl *dup_map_ctrl(map_ctrl *);
1147c478bd9Sstevel@tonic-gate extern void 	dump_map_ctrl(map_ctrl *);
1157c478bd9Sstevel@tonic-gate extern suc_code map_ctrl_init(map_ctrl *map, char *name);
1167c478bd9Sstevel@tonic-gate extern int	lock_map_ctrl(map_ctrl *map);
1177c478bd9Sstevel@tonic-gate extern int	unlock_map_ctrl(map_ctrl *map);
118*4a190493Ssdussud extern int	map_id_list_init();
119*4a190493Ssdussud extern void	get_list_max(map_id_elt_t ***list, int *max);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate extern int	try_lock_map_update(map_ctrl *map);
1227c478bd9Sstevel@tonic-gate extern suc_code lock_map_update(map_ctrl *map);
1237c478bd9Sstevel@tonic-gate extern suc_code unlock_map_update(map_ctrl *map);
1247c478bd9Sstevel@tonic-gate extern bool_t init_update_lock_map();
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * Globals
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate extern bool_t yptol_mode;
130*4a190493Ssdussud extern bool_t yptol_newlock;
1317c478bd9Sstevel@tonic-gate extern bool_t ypxfrd_flag;
1327c478bd9Sstevel@tonic-gate extern int yp2ldap;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * String extensions used in N2L
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /* Prefix used for N2L map names */
1397c478bd9Sstevel@tonic-gate #define	NTOL_PREFIX "LDAP_"
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /* Postfix used for TTL DBM files */
1427c478bd9Sstevel@tonic-gate #define	TTL_POSTFIX "_TTL"
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /* Postfix for temporary files */
1457c478bd9Sstevel@tonic-gate #define	TEMP_POSTFIX "_TMP"
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /* File separator character. If this is defined elsewhere can be removed */
1487c478bd9Sstevel@tonic-gate #define	SEP_CHAR '/'
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * Special keys used in DBM files. No real NIS map can use these keys.
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate #define	MAP_EXPIRY_KEY "YP_EXPIRY_TIME"
1547c478bd9Sstevel@tonic-gate #define	MAP_OLD_MAP_DATE_KEY "YP_OLD_MAP_DATE_TIME"
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /* Mmaped file used for update flags shared memory */
1577c478bd9Sstevel@tonic-gate #define	SHM_FILE "/var/run/nis_shim"
1587c478bd9Sstevel@tonic-gate 
159*4a190493Ssdussud /* used for map arrays reallocation purposes */
160*4a190493Ssdussud #define	ARRAY_CHUNK	10
161*4a190493Ssdussud 
1627c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate #endif
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #endif	/* __SHIM_H */
167