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 5c13de8f6Sab196087 * Common Development and Distribution License (the "License"). 6c13de8f6Sab196087 * 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*57ef7aa9SRod Evans * Copyright 2009 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 __CRLE_H 277c478bd9Sstevel@tonic-gate #define __CRLE_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <gelf.h> 317c478bd9Sstevel@tonic-gate #include <sgs.h> 327c478bd9Sstevel@tonic-gate #include <rtc.h> 337c478bd9Sstevel@tonic-gate #include <machdep.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * Hash table support routines. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate typedef struct hash_obj Hash_obj; 437c478bd9Sstevel@tonic-gate typedef struct hash_ent Hash_ent; 447c478bd9Sstevel@tonic-gate typedef struct hash_tbl Hash_tbl; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate typedef enum { 477c478bd9Sstevel@tonic-gate HASH_STR, 487c478bd9Sstevel@tonic-gate HASH_INT 497c478bd9Sstevel@tonic-gate } Hash_type; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * Each unique object (identified by dev/inode pair) is maintained as a hash 537c478bd9Sstevel@tonic-gate * object. This descriptor identifies the object (file or directory), whether 547c478bd9Sstevel@tonic-gate * it has an alternate, or represents a non-existent object. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate struct hash_obj { 577c478bd9Sstevel@tonic-gate Half o_flags; /* object identification */ 587c478bd9Sstevel@tonic-gate Hash_tbl *o_tbl; /* its dev/inode table */ 597c478bd9Sstevel@tonic-gate char *o_alter; /* any alternate path */ 607c478bd9Sstevel@tonic-gate Word o_calter; /* and its conf offset */ 617c478bd9Sstevel@tonic-gate char *o_path; /* the objects real path */ 627c478bd9Sstevel@tonic-gate Lword o_info; /* information for cache */ 637c478bd9Sstevel@tonic-gate /* consistency checks */ 647c478bd9Sstevel@tonic-gate }; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Each element of a hash table is maintained as a hash entry. Each element 687c478bd9Sstevel@tonic-gate * points to a unique hash object. Many elements can point to the same hash 697c478bd9Sstevel@tonic-gate * object (as is the case with linked files). Elements on the string table 707c478bd9Sstevel@tonic-gate * hash lists identify their directory id, either the directory itself, or the 717c478bd9Sstevel@tonic-gate * files that belong to the directory. These directory and file entries are 727c478bd9Sstevel@tonic-gate * what will be converted into object descriptors in the final cache file. 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate struct hash_ent { 757c478bd9Sstevel@tonic-gate Hash_ent *e_next; /* next hash item */ 767c478bd9Sstevel@tonic-gate Word e_hash; /* hash value (or inode no.) */ 777c478bd9Sstevel@tonic-gate Addr e_key; /* name (or inode no.) */ 787c478bd9Sstevel@tonic-gate int e_off; /* offset of file in dirname */ 797c478bd9Sstevel@tonic-gate Half e_id; /* directory identifier */ 807c478bd9Sstevel@tonic-gate Half e_flags; /* entry specific flags */ 817c478bd9Sstevel@tonic-gate Word e_cnt; /* no. of files in directory */ 827c478bd9Sstevel@tonic-gate Hash_ent *e_dir; /* files directory */ 837c478bd9Sstevel@tonic-gate Hash_ent *e_path; /* files full path entry */ 847c478bd9Sstevel@tonic-gate Hash_obj *e_obj; /* unique object */ 857c478bd9Sstevel@tonic-gate Rtc_obj *e_cobj; /* final configuration object */ 867c478bd9Sstevel@tonic-gate }; 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Each hash table is maintained as a hash table descriptor. Each dev has a 907c478bd9Sstevel@tonic-gate * hash table of inodes, and all directory and file entries are also maintained 917c478bd9Sstevel@tonic-gate * on the string table hash table. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate struct hash_tbl { 947c478bd9Sstevel@tonic-gate ulong_t t_ident; /* dev no. for inode cache */ 957c478bd9Sstevel@tonic-gate int t_size; /* no. of buckets */ 967c478bd9Sstevel@tonic-gate Hash_type t_type; /* HASH_INT or HASH_STR */ 977c478bd9Sstevel@tonic-gate Hash_ent **t_entry; /* entries */ 987c478bd9Sstevel@tonic-gate }; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #define HASH_FND_ENT 0x01 /* search for existing hash entry */ 1017c478bd9Sstevel@tonic-gate #define HASH_ADD_ENT 0x02 /* add hash entry */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Environment variable support. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate typedef struct { 1077c478bd9Sstevel@tonic-gate const char *e_str; /* complete environment string */ 1087c478bd9Sstevel@tonic-gate size_t e_varsz; /* variable size, ie. the LD_XXX part */ 1097c478bd9Sstevel@tonic-gate size_t e_totsz; /* total string size */ 1107c478bd9Sstevel@tonic-gate uint_t e_flags; 1117c478bd9Sstevel@tonic-gate } Env_desc; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate /* 1147c478bd9Sstevel@tonic-gate * Filter/filtee association support. The filtees are a list of Hash_ent's. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate typedef struct { 1177c478bd9Sstevel@tonic-gate Hash_ent *f_fent; /* filter */ 1187c478bd9Sstevel@tonic-gate const char *f_str; /* filtee string and its associated */ 1197c478bd9Sstevel@tonic-gate size_t f_strsz; /* size */ 120*57ef7aa9SRod Evans APlist *f_filtee; /* filtees */ 1217c478bd9Sstevel@tonic-gate } Flt_desc; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * Global data for final configuration files construction. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate typedef struct crle_desc { 1277c478bd9Sstevel@tonic-gate char *c_name; /* calling program */ 1287c478bd9Sstevel@tonic-gate char *c_tempname; /* temporary file, file descriptor */ 1297c478bd9Sstevel@tonic-gate int c_tempfd; /* mmapped address and size */ 1307c478bd9Sstevel@tonic-gate Addr c_tempaddr; 1317c478bd9Sstevel@tonic-gate size_t c_tempsize; 132c13de8f6Sab196087 Addr c_tempheadaddr; /* Ptr to Rtc_head within c_tempaddr */ 1337c478bd9Sstevel@tonic-gate char *c_confil; /* configuration file */ 1347c478bd9Sstevel@tonic-gate char *c_objdir; /* current object directory for */ 1357c478bd9Sstevel@tonic-gate /* dldump(3dl) */ 1367c478bd9Sstevel@tonic-gate char *c_audit; /* audit library name */ 1377c478bd9Sstevel@tonic-gate uint_t c_flags; /* state flags for crle processing */ 1387c478bd9Sstevel@tonic-gate int c_dlflags; /* current dldump(3dl) flags */ 1397c478bd9Sstevel@tonic-gate int c_strbkts; /* internal hash table initialization */ 1407c478bd9Sstevel@tonic-gate int c_inobkts; /* parameters */ 1417c478bd9Sstevel@tonic-gate uint_t c_dirnum; /* no. of directories processed */ 1427c478bd9Sstevel@tonic-gate uint_t c_filenum; /* no. of files processed */ 1437c478bd9Sstevel@tonic-gate uint_t c_hashstrnum; /* no. of hashed strings to create */ 1447c478bd9Sstevel@tonic-gate Hash_tbl *c_strtbl; /* string table and size */ 1457c478bd9Sstevel@tonic-gate size_t c_strsize; 146*57ef7aa9SRod Evans APlist *c_inotbls; /* list of inode tables */ 1477c478bd9Sstevel@tonic-gate const char *c_app; /* specific application */ 1487c478bd9Sstevel@tonic-gate char *c_edlibpath; /* ELF default library path */ 1497c478bd9Sstevel@tonic-gate char *c_adlibpath; /* AOUT default library path */ 1507c478bd9Sstevel@tonic-gate char *c_eslibpath; /* ELF secure library path */ 1517c478bd9Sstevel@tonic-gate char *c_aslibpath; /* AOUT secure library path */ 152*57ef7aa9SRod Evans APlist *c_env; /* environment variables */ 1537c478bd9Sstevel@tonic-gate uint_t c_envnum; /* and associated number */ 154*57ef7aa9SRod Evans APlist *c_flt; /* filter/filtee associations */ 1557c478bd9Sstevel@tonic-gate uint_t c_fltrnum; /* and associated filter number */ 1567c478bd9Sstevel@tonic-gate uint_t c_fltenum; /* and associated filtee number */ 1577c478bd9Sstevel@tonic-gate } Crle_desc; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate #define CRLE_CREAT 0x0001 /* config file creation required */ 1607c478bd9Sstevel@tonic-gate #define CRLE_ALTER 0x0002 /* alternative entries required */ 1617c478bd9Sstevel@tonic-gate #define CRLE_DUMP 0x0004 /* alternative create by dldump(3dl) */ 162c13de8f6Sab196087 #define CRLE_ADDID 0x0008 /* Add Rtc_id to head of new files */ 1637c478bd9Sstevel@tonic-gate #define CRLE_VERBOSE 0x0010 /* verbose mode */ 1647c478bd9Sstevel@tonic-gate #define CRLE_AOUT 0x0020 /* AOUT flag in effect */ 1657c478bd9Sstevel@tonic-gate #define CRLE_EXISTS 0x0040 /* config file already exists */ 1667c478bd9Sstevel@tonic-gate #define CRLE_DIFFDEV 0x0080 /* config file and temporary exist on */ 1677c478bd9Sstevel@tonic-gate /* different filesystems */ 1687c478bd9Sstevel@tonic-gate #define CRLE_CONFDEF 0x0100 /* configuration file is default */ 1697c478bd9Sstevel@tonic-gate #define CRLE_UPDATE 0x0200 /* update existing configuration file */ 1707c478bd9Sstevel@tonic-gate #define CRLE_RPLENV 0x0400 /* replaceable environment variable */ 1717c478bd9Sstevel@tonic-gate #define CRLE_PRMENV 0x0800 /* permanent environment variable */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate #define CRLE_EDLIB 0x1000 /* default elf search path supplied */ 1747c478bd9Sstevel@tonic-gate #define CRLE_ESLIB 0x2000 /* default elf secure path supplied */ 1757c478bd9Sstevel@tonic-gate #define CRLE_ADLIB 0x4000 /* default AOUT search path supplied */ 1767c478bd9Sstevel@tonic-gate #define CRLE_ASLIB 0x8000 /* default AOUT secure path supplied */ 1777c478bd9Sstevel@tonic-gate 178*57ef7aa9SRod Evans #define AL_CNT_CRLE 10 179*57ef7aa9SRod Evans 1807c478bd9Sstevel@tonic-gate /* 181c13de8f6Sab196087 * Return type code returned by inspectconfig() 182c13de8f6Sab196087 */ 183c13de8f6Sab196087 typedef enum { 184c13de8f6Sab196087 INSCFG_RET_OK = 0, /* Config file is OK */ 185c13de8f6Sab196087 INSCFG_RET_FAIL = 1, /* Config file has a fatal problem */ 186c13de8f6Sab196087 INSCFG_RET_NEED64 = 2, /* 64-bit config seen by 32-bit crle */ 187c13de8f6Sab196087 } INSCFG_RET; 188c13de8f6Sab196087 189c13de8f6Sab196087 /* 1907c478bd9Sstevel@tonic-gate * Local functions. 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate extern int addlib(Crle_desc *, char **, const char *); 1937c478bd9Sstevel@tonic-gate extern int addenv(Crle_desc *, const char *, uint_t); 1947c478bd9Sstevel@tonic-gate extern int depend(Crle_desc *, const char *, Half, GElf_Ehdr *); 1957c478bd9Sstevel@tonic-gate extern int dlflags(Crle_desc *, const char *); 1967c478bd9Sstevel@tonic-gate extern int dump(Crle_desc *); 1977c478bd9Sstevel@tonic-gate extern int genconfig(Crle_desc *); 1987c478bd9Sstevel@tonic-gate extern Hash_ent *get_hash(Hash_tbl *, Addr, Half, int); 1997c478bd9Sstevel@tonic-gate extern int inspect(Crle_desc *, const char *, Half); 2007c478bd9Sstevel@tonic-gate extern Hash_tbl *make_hash(int, Hash_type, ulong_t); 201587032cfSab196087 extern INSCFG_RET inspectconfig(Crle_desc *, int); 2027c478bd9Sstevel@tonic-gate extern int updateconfig(Crle_desc *); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate #endif 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #endif /* __CRLE_H */ 209