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 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef	__CRLE_H
27#define	__CRLE_H
28
29#include <sys/types.h>
30#include <gelf.h>
31#include <sgs.h>
32#include <rtc.h>
33#include <machdep.h>
34
35#ifdef	__cplusplus
36extern "C" {
37#endif
38
39/*
40 * Hash table support routines.
41 */
42typedef	struct hash_obj	Hash_obj;
43typedef struct hash_ent Hash_ent;
44typedef	struct hash_tbl	Hash_tbl;
45
46typedef enum {
47	HASH_STR,
48	HASH_INT
49} Hash_type;
50
51/*
52 * Each unique object (identified by dev/inode pair) is maintained as a hash
53 * object.  This descriptor identifies the object (file or directory), whether
54 * it has an alternate, or represents a non-existent object.
55 */
56struct hash_obj {
57	Half		o_flags;		/* object identification */
58	Hash_tbl	*o_tbl;			/* its dev/inode table */
59	char		*o_alter;		/* any alternate path */
60	Word		o_calter;		/*	and its conf offset */
61	char		*o_path;		/* the objects real path */
62	Lword		o_info;			/* information for cache */
63						/*	consistency checks */
64};
65
66/*
67 * Each element of a hash table is maintained as a hash entry.  Each element
68 * points to a unique hash object.  Many elements can point to the same hash
69 * object (as is the case with linked files).  Elements on the string table
70 * hash lists identify their directory id, either the directory itself, or the
71 * files that belong to the directory.  These directory and file entries are
72 * what will be converted into object descriptors in the final cache file.
73 */
74struct hash_ent {
75	Hash_ent	*e_next;		/* next hash item */
76	Word		e_hash;			/* hash value (or inode no.) */
77	Addr		e_key;			/* name (or inode no.) */
78	int		e_off;			/* offset of file in dirname */
79	Half		e_id;			/* directory identifier */
80	Half		e_flags;		/* entry specific flags */
81	Word		e_cnt;			/* no. of files in directory */
82	Hash_ent	*e_dir;			/* files directory */
83	Hash_ent	*e_path;		/* files full path entry */
84	Hash_obj	*e_obj;			/* unique object */
85	Rtc_obj		*e_cobj;		/* final configuration object */
86};
87
88/*
89 * Each hash table is maintained as a hash table descriptor.  Each dev has a
90 * hash table of inodes, and all directory and file entries are also maintained
91 * on the string table hash table.
92 */
93struct hash_tbl {
94	ulong_t		t_ident;		/* dev no. for inode cache */
95	int 		t_size;			/* no. of buckets */
96	Hash_type	t_type;			/* HASH_INT or HASH_STR */
97	Hash_ent	**t_entry;		/* entries */
98};
99
100#define	HASH_FND_ENT	0x01		/* search for existing hash entry */
101#define	HASH_ADD_ENT	0x02		/* add hash entry */
102
103/*
104 * Environment variable support.
105 */
106typedef struct {
107	const char	*e_str;		/* complete environment string */
108	size_t		e_varsz;	/* variable size, ie. the LD_XXX part */
109	size_t		e_totsz;	/* total string size */
110	uint_t		e_flags;
111} Env_desc;
112
113/*
114 * Filter/filtee association support.  The filtees are a list of Hash_ent's.
115 */
116typedef struct {
117	Hash_ent	*f_fent;	/* filter */
118	const char	*f_str;		/* filtee string and its associated */
119	size_t		f_strsz;	/*	size */
120	APlist		*f_filtee;	/* filtees */
121} Flt_desc;
122
123/*
124 * Global data for final configuration files construction.
125 */
126typedef	struct crle_desc {
127	char		*c_name;		/* calling program */
128	char		*c_tempname;	/* temporary file, file descriptor */
129	int		c_tempfd;	/*	mmapped address and size */
130	Addr		c_tempaddr;
131	size_t		c_tempsize;
132	Addr		c_tempheadaddr;	/* Ptr to Rtc_head within c_tempaddr */
133	char		*c_confil;	/* configuration file */
134	char		*c_objdir;	/* current object directory for */
135					/*	dldump(3dl) */
136	char		*c_audit;	/* audit library name */
137	uint_t		c_flags;	/* state flags for crle processing */
138	int		c_dlflags;	/* current dldump(3dl) flags */
139	int		c_strbkts;	/* internal hash table initialization */
140	int		c_inobkts;	/*	parameters */
141	uint_t		c_dirnum;	/* no. of directories processed */
142	uint_t		c_filenum;	/* no. of files processed */
143	uint_t		c_hashstrnum;	/* no. of hashed strings to create */
144	Hash_tbl	*c_strtbl;	/* string table and size */
145	size_t		c_strsize;
146	APlist		*c_inotbls;	/* list of inode tables */
147	const char	*c_app;		/* specific application */
148	char		*c_edlibpath;	/* ELF default library path */
149	char		*c_adlibpath;	/* AOUT default library path */
150	char		*c_eslibpath;	/* ELF secure library path */
151	char		*c_aslibpath;	/* AOUT secure library path */
152	APlist		*c_env;		/* environment variables */
153	uint_t		c_envnum;	/*	and associated number */
154	APlist		*c_flt;		/* filter/filtee associations */
155	uint_t		c_fltrnum;	/*	and associated filter number */
156	uint_t		c_fltenum;	/*	and associated filtee number */
157} Crle_desc;
158
159#define	CRLE_CREAT	0x0001		/* config file creation required */
160#define	CRLE_ALTER	0x0002		/* alternative entries required */
161#define	CRLE_DUMP	0x0004		/* alternative create by dldump(3dl) */
162#define	CRLE_ADDID	0x0008		/* Add Rtc_id to head of new files */
163#define	CRLE_VERBOSE	0x0010		/* verbose mode */
164#define	CRLE_AOUT	0x0020		/* AOUT flag in effect */
165#define	CRLE_EXISTS	0x0040		/* config file already exists */
166#define	CRLE_DIFFDEV	0x0080		/* config file and temporary exist on */
167					/*	different filesystems */
168#define	CRLE_CONFDEF	0x0100		/* configuration file is default */
169#define	CRLE_UPDATE	0x0200		/* update existing configuration file */
170#define	CRLE_RPLENV	0x0400		/* replaceable environment variable */
171#define	CRLE_PRMENV	0x0800		/* permanent environment variable */
172
173#define	CRLE_EDLIB	0x1000		/* default elf search path supplied */
174#define	CRLE_ESLIB	0x2000		/* default elf secure path supplied */
175#define	CRLE_ADLIB	0x4000		/* default AOUT search path supplied */
176#define	CRLE_ASLIB	0x8000		/* default AOUT secure path supplied */
177
178#define	AL_CNT_CRLE	10
179
180/*
181 * Return type code returned by inspectconfig()
182 */
183typedef enum {
184	INSCFG_RET_OK = 0,		/* Config file is OK */
185	INSCFG_RET_FAIL = 1,		/* Config file has a fatal problem */
186	INSCFG_RET_NEED64 = 2,		/* 64-bit config seen by 32-bit crle */
187} INSCFG_RET;
188
189/*
190 * Local functions.
191 */
192extern int		addlib(Crle_desc *, char **, const char *);
193extern int		addenv(Crle_desc *, const char *, uint_t);
194extern int		depend(Crle_desc *, const char *, Half, GElf_Ehdr *);
195extern int		dlflags(Crle_desc *, const char *);
196extern int		dump(Crle_desc *);
197extern int		genconfig(Crle_desc *);
198extern Hash_ent		*get_hash(Hash_tbl *, Addr, Half, int);
199extern int		inspect(Crle_desc *, const char *, Half);
200extern Hash_tbl		*make_hash(int, Hash_type, ulong_t);
201extern INSCFG_RET	inspectconfig(Crle_desc *, int);
202extern int		updateconfig(Crle_desc *);
203
204#ifdef	__cplusplus
205}
206#endif
207
208#endif	/* __CRLE_H */
209