xref: /illumos-gate/usr/src/lib/libbsm/common/devalloc.h (revision a1af7ba02a81ee5af0f2cd6b30b99957a93fc605)
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 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DEVALLOC_H
28 #define	_DEVALLOC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdio.h>
37 #include <fcntl.h>
38 #include <sys/param.h>
39 #include <secdb.h>
40 
41 /*
42  * These are unsupported, SUNWprivate interfaces.
43  */
44 
45 #define	DA_UID			(uid_t)0	/* root */
46 #define	DA_GID			(gid_t)3	/* sys */
47 #define	ALLOC_MODE		0600
48 #define	DEALLOC_MODE    	0000
49 
50 #define	LOGINDEVPERM		"/etc/logindevperm"
51 #define	DA_DB_LOCK		"/etc/security/.da_db_lock"
52 #define	DA_DEV_LOCK		"/etc/security/.da_dev_lock"
53 #define	DEVALLOC		"/etc/security/device_allocate"
54 #define	DEVMAP			"/etc/security/device_maps"
55 #define	DEFATTRS		"/etc/security/tsol/devalloc_defaults"
56 #define	TMPALLOC		"/etc/security/.device_allocate"
57 #define	TMPMAP			"/etc/security/.device_maps"
58 #define	TMPATTRS		"/etc/security/tsol/.devalloc_defaults"
59 
60 #define	DA_DEFAULT_MIN		"admin_low"
61 #define	DA_DEFAULT_MAX		"admin_high"
62 #define	DA_DEFAULT_CLEAN	"/bin/true"
63 #define	DA_DEFAULT_AUDIO_CLEAN	"/etc/security/lib/audio_clean_wrapper"
64 #define	DA_DEFAULT_DISK_CLEAN	"/etc/security/lib/disk_clean"
65 #define	DA_DEFAULT_TAPE_CLEAN	"/etc/security/lib/st_clean"
66 
67 #define	DA_ON_STR		"DEVICE_ALLOCATION=ON\n"
68 #define	DA_OFF_STR		"DEVICE_ALLOCATION=OFF\n"
69 #define	DA_IS_LABELED		"system_labeled"
70 #define	DA_LABEL_CHECK		"/usr/bin/plabel"
71 #define	DA_DBMODE		0644
72 #define	DA_COUNT		5	/* allocatable devices suppported */
73 					/* audio, cd, floppy, rmdisk, tape */
74 #define	DA_AUTHLEN		MAX_CANON   /* approx. sum of strlen of all */
75 					    /* device auths in auth_list.h */
76 #define	DA_MAXNAME		80
77 #define	DA_BUFSIZE		4096
78 
79 #define	DA_RDWR			O_RDWR|O_CREAT|O_NONBLOCK
80 #define	DA_RDONLY		O_RDONLY|O_NONBLOCK
81 
82 #define	DA_ANYUSER		"*"
83 #define	DA_NOUSER		"@"
84 
85 #define	DA_SILENT		0x00000001
86 #define	DA_VERBOSE		0x00000002
87 #define	DA_ADD			0x00000004
88 #define	DA_REMOVE		0x00000008
89 #define	DA_UPDATE		0x00000010
90 #define	DA_ADD_ZONE		0x00000020
91 #define	DA_REMOVE_ZONE		0x00000040
92 #define	DA_FORCE		0x00000080
93 #define	DA_ALLOC_ONLY		0x00000100
94 #define	DA_MAPS_ONLY		0x00000200
95 #define	DA_ON			0x00000400
96 #define	DA_OFF			0x00000800
97 #define	DA_NO_OVERRIDE		0x00001000
98 #define	DA_DEFATTRS		0x00002000
99 
100 #define	DA_AUDIO		0x00001000
101 #define	DA_CD			0x00002000
102 #define	DA_FLOPPY		0x00004000
103 #define	DA_TAPE			0x00008000
104 #define	DA_RMDISK		0x00010000
105 
106 #define	DA_AUDIO_NAME		"audio"
107 #define	DA_SOUND_NAME		"sound"
108 #define	DA_AUDIO_TYPE		DA_AUDIO_NAME
109 #define	DA_AUDIO_DIR		"/dev/sound/"
110 
111 #define	DA_CD_NAME		"cdrom"
112 #define	DA_CD_TYPE		"sr"
113 
114 #define	DA_DISK_DIR		"/dev/dsk/"
115 #define	DA_DISK_DIRR		"/dev/rdsk/"
116 #define	DA_DISKR_DIR		"/dev/(r)dsk"
117 
118 #define	DA_FLOPPY_NAME		"floppy"
119 #define	DA_FLOPPY_TYPE		"fd"
120 
121 #define	DA_RMDISK_NAME		"rmdisk"
122 #define	DA_RMDISK_TYPE		DA_RMDISK_NAME
123 
124 #define	DA_TAPE_NAME		"tape"
125 #define	DA_TAPE_DIR		"/dev/rmt/"
126 #define	DA_TAPE_TYPE		"st"
127 
128 typedef struct _devinfo_t {
129 	char	*devname;
130 	char	*devtype;
131 	char	*devauths;
132 	char	*devexec;
133 	char	*devopts;
134 	char	*devlist;
135 	int	instance;
136 } devinfo_t;
137 
138 typedef struct _deventry_t {
139 	devinfo_t		devinfo;
140 	struct _deventry_t	*next;
141 } deventry_t;
142 
143 typedef struct _devlist_t {
144 	deventry_t	*audio;
145 	deventry_t	*cd;
146 	deventry_t	*floppy;
147 	deventry_t	*tape;
148 	deventry_t	*rmdisk;
149 } devlist_t;
150 
151 typedef struct _da_optargs {
152 	int		optflag;
153 	char		*rootdir;
154 	char		**devnames;
155 	devinfo_t	*devinfo;
156 } da_args;
157 
158 typedef struct _da_defs {
159 	char		*devtype;
160 	kva_t		*devopts;
161 } da_defs_t;
162 
163 da_defs_t *getdadefent(void);
164 da_defs_t *getdadeftype(char *);
165 void freedadefent(da_defs_t *);
166 void setdadefent(void);
167 void enddadefent(void);
168 int da_is_on(void);
169 int da_check_logindevperm(char *);
170 int da_open_devdb(char *, FILE **, FILE **, int);
171 int da_update_device(da_args *);
172 int da_update_defattrs(da_args *);
173 int da_add_list(devlist_t *, char *, int, int);
174 int da_remove_list(devlist_t *, char *, int, char *, int);
175 void da_print_device(int, devlist_t *);
176 
177 
178 #ifdef	__cplusplus
179 }
180 #endif
181 
182 #endif	/* _DEVALLOC_H */
183