change sockaddr generation to pass around correct types.
[trinity.git] / ioctls / autofs.c
blob4296ea51143efa564962e6dae8c54ac87e979e63
1 #include <linux/limits.h>
2 #include <linux/auto_fs4.h>
4 #include "ioctls.h"
5 #include "maps.h"
6 #include "random.h"
7 #include "sanitise.h"
8 #include "shm.h"
9 #include "utils.h"
11 /* include/linux/auto_dev-ioctl.h */
13 * Copyright 2008 Red Hat, Inc. All rights reserved.
14 * Copyright 2008 Ian Kent <raven@themaw.net>
16 * This file is part of the Linux kernel and is made available under
17 * the terms of the GNU General Public License, version 2, or at your
18 * option, any later version, incorporated herein by reference.
21 #include <string.h>
23 #define AUTOFS_DEVICE_NAME "autofs"
25 #define AUTOFS_DEV_IOCTL_VERSION_MAJOR 1
26 #define AUTOFS_DEV_IOCTL_VERSION_MINOR 0
28 #define AUTOFS_DEVID_LEN 16
30 #define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl)
33 * An ioctl interface for autofs mount point control.
36 struct args_protover {
37 __u32 version;
40 struct args_protosubver {
41 __u32 sub_version;
44 struct args_openmount {
45 __u32 devid;
48 struct args_ready {
49 __u32 token;
52 struct args_fail {
53 __u32 token;
54 __s32 status;
57 struct args_setpipefd {
58 __s32 pipefd;
61 struct args_timeout {
62 __u64 timeout;
65 struct args_requester {
66 __u32 uid;
67 __u32 gid;
70 struct args_expire {
71 __u32 how;
74 struct args_askumount {
75 __u32 may_umount;
78 struct args_ismountpoint {
79 union {
80 struct args_in {
81 __u32 type;
82 } in;
83 struct args_out {
84 __u32 devid;
85 __u32 magic;
86 } out;
91 * All the ioctls use this structure.
92 * When sending a path size must account for the total length
93 * of the chunk of memory otherwise is is the size of the
94 * structure.
97 struct autofs_dev_ioctl {
98 __u32 ver_major;
99 __u32 ver_minor;
100 __u32 size; /* total size of data passed in
101 * including this struct */
102 __s32 ioctlfd; /* automount command fd */
104 /* Command parameters */
106 union {
107 struct args_protover protover;
108 struct args_protosubver protosubver;
109 struct args_openmount openmount;
110 struct args_ready ready;
111 struct args_fail fail;
112 struct args_setpipefd setpipefd;
113 struct args_timeout timeout;
114 struct args_requester requester;
115 struct args_expire expire;
116 struct args_askumount askumount;
117 struct args_ismountpoint ismountpoint;
120 char path[0];
123 static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in)
125 memset(in, 0, sizeof(struct autofs_dev_ioctl));
126 in->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
127 in->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
128 in->size = sizeof(struct autofs_dev_ioctl);
129 in->ioctlfd = -1;
130 return;
134 * If you change this make sure you make the corresponding change
135 * to autofs-dev-ioctl.c:lookup_ioctl()
137 enum {
138 /* Get various version info */
139 AUTOFS_DEV_IOCTL_VERSION_CMD = 0x71,
140 AUTOFS_DEV_IOCTL_PROTOVER_CMD,
141 AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD,
143 /* Open mount ioctl fd */
144 AUTOFS_DEV_IOCTL_OPENMOUNT_CMD,
146 /* Close mount ioctl fd */
147 AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD,
149 /* Mount/expire status returns */
150 AUTOFS_DEV_IOCTL_READY_CMD,
151 AUTOFS_DEV_IOCTL_FAIL_CMD,
153 /* Activate/deactivate autofs mount */
154 AUTOFS_DEV_IOCTL_SETPIPEFD_CMD,
155 AUTOFS_DEV_IOCTL_CATATONIC_CMD,
157 /* Expiry timeout */
158 AUTOFS_DEV_IOCTL_TIMEOUT_CMD,
160 /* Get mount last requesting uid and gid */
161 AUTOFS_DEV_IOCTL_REQUESTER_CMD,
163 /* Check for eligible expire candidates */
164 AUTOFS_DEV_IOCTL_EXPIRE_CMD,
166 /* Request busy status */
167 AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD,
169 /* Check if path is a mountpoint */
170 AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD,
173 #define AUTOFS_IOCTL 0x93
175 #define AUTOFS_DEV_IOCTL_VERSION \
176 _IOWR(AUTOFS_IOCTL, \
177 AUTOFS_DEV_IOCTL_VERSION_CMD, struct autofs_dev_ioctl)
179 #define AUTOFS_DEV_IOCTL_PROTOVER \
180 _IOWR(AUTOFS_IOCTL, \
181 AUTOFS_DEV_IOCTL_PROTOVER_CMD, struct autofs_dev_ioctl)
183 #define AUTOFS_DEV_IOCTL_PROTOSUBVER \
184 _IOWR(AUTOFS_IOCTL, \
185 AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD, struct autofs_dev_ioctl)
187 #define AUTOFS_DEV_IOCTL_OPENMOUNT \
188 _IOWR(AUTOFS_IOCTL, \
189 AUTOFS_DEV_IOCTL_OPENMOUNT_CMD, struct autofs_dev_ioctl)
191 #define AUTOFS_DEV_IOCTL_CLOSEMOUNT \
192 _IOWR(AUTOFS_IOCTL, \
193 AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD, struct autofs_dev_ioctl)
195 #define AUTOFS_DEV_IOCTL_READY \
196 _IOWR(AUTOFS_IOCTL, \
197 AUTOFS_DEV_IOCTL_READY_CMD, struct autofs_dev_ioctl)
199 #define AUTOFS_DEV_IOCTL_FAIL \
200 _IOWR(AUTOFS_IOCTL, \
201 AUTOFS_DEV_IOCTL_FAIL_CMD, struct autofs_dev_ioctl)
203 #define AUTOFS_DEV_IOCTL_SETPIPEFD \
204 _IOWR(AUTOFS_IOCTL, \
205 AUTOFS_DEV_IOCTL_SETPIPEFD_CMD, struct autofs_dev_ioctl)
207 #define AUTOFS_DEV_IOCTL_CATATONIC \
208 _IOWR(AUTOFS_IOCTL, \
209 AUTOFS_DEV_IOCTL_CATATONIC_CMD, struct autofs_dev_ioctl)
211 #define AUTOFS_DEV_IOCTL_TIMEOUT \
212 _IOWR(AUTOFS_IOCTL, \
213 AUTOFS_DEV_IOCTL_TIMEOUT_CMD, struct autofs_dev_ioctl)
215 #define AUTOFS_DEV_IOCTL_REQUESTER \
216 _IOWR(AUTOFS_IOCTL, \
217 AUTOFS_DEV_IOCTL_REQUESTER_CMD, struct autofs_dev_ioctl)
219 #define AUTOFS_DEV_IOCTL_EXPIRE \
220 _IOWR(AUTOFS_IOCTL, \
221 AUTOFS_DEV_IOCTL_EXPIRE_CMD, struct autofs_dev_ioctl)
223 #define AUTOFS_DEV_IOCTL_ASKUMOUNT \
224 _IOWR(AUTOFS_IOCTL, \
225 AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD, struct autofs_dev_ioctl)
227 #define AUTOFS_DEV_IOCTL_ISMOUNTPOINT \
228 _IOWR(AUTOFS_IOCTL, \
229 AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD, struct autofs_dev_ioctl)
231 static const struct ioctl autofs_ioctls[] = {
232 IOCTL(AUTOFS_IOC_READY),
233 IOCTL(AUTOFS_IOC_FAIL),
234 IOCTL(AUTOFS_IOC_CATATONIC),
235 IOCTL(AUTOFS_IOC_PROTOVER),
236 /* IOCTL(AUTOFS_IOC_SETTIMEOUT32), */
237 IOCTL(AUTOFS_IOC_SETTIMEOUT),
238 IOCTL(AUTOFS_IOC_EXPIRE),
239 IOCTL(AUTOFS_IOC_EXPIRE_MULTI),
240 IOCTL(AUTOFS_IOC_EXPIRE_INDIRECT),
241 IOCTL(AUTOFS_IOC_EXPIRE_DIRECT),
242 IOCTL(AUTOFS_IOC_PROTOSUBVER),
243 IOCTL(AUTOFS_IOC_ASKUMOUNT),
245 IOCTL(AUTOFS_DEV_IOCTL_VERSION),
246 IOCTL(AUTOFS_DEV_IOCTL_PROTOVER),
247 IOCTL(AUTOFS_DEV_IOCTL_PROTOSUBVER),
248 IOCTL(AUTOFS_DEV_IOCTL_OPENMOUNT),
249 IOCTL(AUTOFS_DEV_IOCTL_CLOSEMOUNT),
250 IOCTL(AUTOFS_DEV_IOCTL_READY),
251 IOCTL(AUTOFS_DEV_IOCTL_FAIL),
252 IOCTL(AUTOFS_DEV_IOCTL_SETPIPEFD),
253 IOCTL(AUTOFS_DEV_IOCTL_CATATONIC),
254 IOCTL(AUTOFS_DEV_IOCTL_TIMEOUT),
255 IOCTL(AUTOFS_DEV_IOCTL_REQUESTER),
256 IOCTL(AUTOFS_DEV_IOCTL_EXPIRE),
257 IOCTL(AUTOFS_DEV_IOCTL_ASKUMOUNT),
258 IOCTL(AUTOFS_DEV_IOCTL_ISMOUNTPOINT),
261 static const char *const autofs_devs[] = {
262 "autofs",
265 static void autofs_sanitise(const struct ioctl_group *grp, int childno)
267 int i;
268 struct autofs_dev_ioctl *arg;
270 pick_random_ioctl(grp, childno);
272 shm->a3[childno] = (unsigned long) page_rand;
274 switch (shm->a2[childno]) {
275 case AUTOFS_DEV_IOCTL_VERSION:
276 case AUTOFS_DEV_IOCTL_PROTOVER:
277 case AUTOFS_DEV_IOCTL_PROTOSUBVER:
278 case AUTOFS_DEV_IOCTL_OPENMOUNT:
279 case AUTOFS_DEV_IOCTL_CLOSEMOUNT:
280 case AUTOFS_DEV_IOCTL_READY:
281 case AUTOFS_DEV_IOCTL_FAIL:
282 case AUTOFS_DEV_IOCTL_SETPIPEFD:
283 case AUTOFS_DEV_IOCTL_CATATONIC:
284 case AUTOFS_DEV_IOCTL_TIMEOUT:
285 case AUTOFS_DEV_IOCTL_REQUESTER:
286 case AUTOFS_DEV_IOCTL_EXPIRE:
287 case AUTOFS_DEV_IOCTL_ASKUMOUNT:
288 case AUTOFS_DEV_IOCTL_ISMOUNTPOINT:
289 arg = (struct autofs_dev_ioctl *)shm->a3[childno];
290 init_autofs_dev_ioctl(arg);
291 arg->ioctlfd = get_random_fd();
292 arg->fail.token = rand();
293 arg->fail.status = rand();
294 if (rand_bool()) {
295 arg->size += 5;
296 arg->path[0] = '/';
297 arg->path[1] = rand();
298 arg->path[2] = rand();
299 arg->path[3] = rand();
300 arg->path[4] = 0;
301 } else {
302 arg->size += rand();
303 for (i=0; i < 10; ++i)
304 arg->path[i] = rand();
306 break;
307 default:
308 break;
312 static const struct ioctl_group autofs_grp = {
313 .devtype = DEV_MISC,
314 .devs = autofs_devs,
315 .devs_cnt = ARRAY_SIZE(autofs_devs),
316 .sanitise = autofs_sanitise,
317 .ioctls = autofs_ioctls,
318 .ioctls_cnt = ARRAY_SIZE(autofs_ioctls),
321 REG_IOCTL_GROUP(autofs_grp)