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