Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ioctl.c |
| 3 | * |
| 4 | * Copyright (C) 1995, 1996 by Volker Lendecke |
| 5 | * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache |
| 6 | * Modified 1998, 1999 Wolfram Pienkoss for NLS |
| 7 | * |
| 8 | */ |
| 9 | |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 10 | #include <linux/capability.h> |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 11 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/errno.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/ioctl.h> |
| 15 | #include <linux/time.h> |
| 16 | #include <linux/mm.h> |
Dave Hansen | a761a1c | 2008-02-15 14:37:39 -0800 | [diff] [blame] | 17 | #include <linux/mount.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/highuid.h> |
| 20 | #include <linux/vmalloc.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 21 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <linux/ncp_fs.h> |
| 24 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 25 | #include <asm/uaccess.h> |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "ncplib_kernel.h" |
| 28 | |
| 29 | /* maximum limit for ncp_objectname_ioctl */ |
| 30 | #define NCP_OBJECT_NAME_MAX_LEN 4096 |
| 31 | /* maximum limit for ncp_privatedata_ioctl */ |
| 32 | #define NCP_PRIVATE_DATA_MAX_LEN 8192 |
| 33 | /* maximum negotiable packet size */ |
| 34 | #define NCP_PACKET_SIZE_INTERNAL 65536 |
| 35 | |
| 36 | static int |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 37 | ncp_get_fs_info(struct ncp_server * server, struct inode *inode, |
Christoph Hellwig | 8c744fb | 2005-11-08 21:35:04 -0800 | [diff] [blame] | 38 | struct ncp_fs_info __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | struct ncp_fs_info info; |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | if (copy_from_user(&info, arg, sizeof(info))) |
| 43 | return -EFAULT; |
| 44 | |
| 45 | if (info.version != NCP_GET_FS_INFO_VERSION) { |
| 46 | DPRINTK("info.version invalid: %d\n", info.version); |
| 47 | return -EINVAL; |
| 48 | } |
| 49 | /* TODO: info.addr = server->m.serv_addr; */ |
| 50 | SET_UID(info.mounted_uid, server->m.mounted_uid); |
| 51 | info.connection = server->connection; |
| 52 | info.buffer_size = server->buffer_size; |
| 53 | info.volume_number = NCP_FINFO(inode)->volNumber; |
| 54 | info.directory_id = NCP_FINFO(inode)->DosDirNum; |
| 55 | |
| 56 | if (copy_to_user(arg, &info, sizeof(info))) |
| 57 | return -EFAULT; |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static int |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 62 | ncp_get_fs_info_v2(struct ncp_server * server, struct inode *inode, |
Christoph Hellwig | 8c744fb | 2005-11-08 21:35:04 -0800 | [diff] [blame] | 63 | struct ncp_fs_info_v2 __user * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | struct ncp_fs_info_v2 info2; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | if (copy_from_user(&info2, arg, sizeof(info2))) |
| 68 | return -EFAULT; |
| 69 | |
| 70 | if (info2.version != NCP_GET_FS_INFO_VERSION_V2) { |
| 71 | DPRINTK("info.version invalid: %d\n", info2.version); |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | info2.mounted_uid = server->m.mounted_uid; |
| 75 | info2.connection = server->connection; |
| 76 | info2.buffer_size = server->buffer_size; |
| 77 | info2.volume_number = NCP_FINFO(inode)->volNumber; |
| 78 | info2.directory_id = NCP_FINFO(inode)->DosDirNum; |
| 79 | info2.dummy1 = info2.dummy2 = info2.dummy3 = 0; |
| 80 | |
| 81 | if (copy_to_user(arg, &info2, sizeof(info2))) |
| 82 | return -EFAULT; |
| 83 | return 0; |
| 84 | } |
| 85 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 86 | #ifdef CONFIG_COMPAT |
| 87 | struct compat_ncp_objectname_ioctl |
| 88 | { |
| 89 | s32 auth_type; |
| 90 | u32 object_name_len; |
Frederik Schwarzer | 0211a9c | 2008-12-29 22:14:56 +0100 | [diff] [blame] | 91 | compat_caddr_t object_name; /* a userspace data, in most cases user name */ |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct compat_ncp_fs_info_v2 { |
| 95 | s32 version; |
| 96 | u32 mounted_uid; |
| 97 | u32 connection; |
| 98 | u32 buffer_size; |
| 99 | |
| 100 | u32 volume_number; |
| 101 | u32 directory_id; |
| 102 | |
| 103 | u32 dummy1; |
| 104 | u32 dummy2; |
| 105 | u32 dummy3; |
| 106 | }; |
| 107 | |
| 108 | struct compat_ncp_ioctl_request { |
| 109 | u32 function; |
| 110 | u32 size; |
| 111 | compat_caddr_t data; |
| 112 | }; |
| 113 | |
| 114 | struct compat_ncp_privatedata_ioctl |
| 115 | { |
| 116 | u32 len; |
| 117 | compat_caddr_t data; /* ~1000 for NDS */ |
| 118 | }; |
| 119 | |
| 120 | #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct compat_ncp_fs_info_v2) |
| 121 | #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct compat_ncp_ioctl_request) |
| 122 | #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct compat_ncp_objectname_ioctl) |
| 123 | #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct compat_ncp_objectname_ioctl) |
| 124 | #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct compat_ncp_privatedata_ioctl) |
| 125 | #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct compat_ncp_privatedata_ioctl) |
| 126 | |
| 127 | static int |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 128 | ncp_get_compat_fs_info_v2(struct ncp_server * server, struct inode *inode, |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 129 | struct compat_ncp_fs_info_v2 __user * arg) |
| 130 | { |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 131 | struct compat_ncp_fs_info_v2 info2; |
| 132 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 133 | if (copy_from_user(&info2, arg, sizeof(info2))) |
| 134 | return -EFAULT; |
| 135 | |
| 136 | if (info2.version != NCP_GET_FS_INFO_VERSION_V2) { |
| 137 | DPRINTK("info.version invalid: %d\n", info2.version); |
| 138 | return -EINVAL; |
| 139 | } |
| 140 | info2.mounted_uid = server->m.mounted_uid; |
| 141 | info2.connection = server->connection; |
| 142 | info2.buffer_size = server->buffer_size; |
| 143 | info2.volume_number = NCP_FINFO(inode)->volNumber; |
| 144 | info2.directory_id = NCP_FINFO(inode)->DosDirNum; |
| 145 | info2.dummy1 = info2.dummy2 = info2.dummy3 = 0; |
| 146 | |
| 147 | if (copy_to_user(arg, &info2, sizeof(info2))) |
| 148 | return -EFAULT; |
| 149 | return 0; |
| 150 | } |
| 151 | #endif |
| 152 | |
| 153 | #define NCP_IOC_GETMOUNTUID16 _IOW('n', 2, u16) |
| 154 | #define NCP_IOC_GETMOUNTUID32 _IOW('n', 2, u32) |
| 155 | #define NCP_IOC_GETMOUNTUID64 _IOW('n', 2, u64) |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #ifdef CONFIG_NCPFS_NLS |
| 158 | /* Here we are select the iocharset and the codepage for NLS. |
| 159 | * Thanks Petr Vandrovec for idea and many hints. |
| 160 | */ |
| 161 | static int |
| 162 | ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) |
| 163 | { |
| 164 | struct ncp_nls_ioctl user; |
| 165 | struct nls_table *codepage; |
| 166 | struct nls_table *iocharset; |
| 167 | struct nls_table *oldset_io; |
| 168 | struct nls_table *oldset_cp; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 169 | int utf8; |
| 170 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | if (copy_from_user(&user, arg, sizeof(user))) |
| 173 | return -EFAULT; |
| 174 | |
| 175 | codepage = NULL; |
| 176 | user.codepage[NCP_IOCSNAME_LEN] = 0; |
| 177 | if (!user.codepage[0] || !strcmp(user.codepage, "default")) |
| 178 | codepage = load_nls_default(); |
| 179 | else { |
| 180 | codepage = load_nls(user.codepage); |
| 181 | if (!codepage) { |
| 182 | return -EBADRQC; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | iocharset = NULL; |
| 187 | user.iocharset[NCP_IOCSNAME_LEN] = 0; |
| 188 | if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) { |
| 189 | iocharset = load_nls_default(); |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 190 | utf8 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } else if (!strcmp(user.iocharset, "utf8")) { |
| 192 | iocharset = load_nls_default(); |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 193 | utf8 = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } else { |
| 195 | iocharset = load_nls(user.iocharset); |
| 196 | if (!iocharset) { |
| 197 | unload_nls(codepage); |
| 198 | return -EBADRQC; |
| 199 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 200 | utf8 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 203 | mutex_lock(&server->root_setup_lock); |
| 204 | if (server->root_setuped) { |
| 205 | oldset_cp = codepage; |
| 206 | oldset_io = iocharset; |
| 207 | err = -EBUSY; |
| 208 | } else { |
| 209 | if (utf8) |
| 210 | NCP_SET_FLAG(server, NCP_FLAG_UTF8); |
| 211 | else |
| 212 | NCP_CLR_FLAG(server, NCP_FLAG_UTF8); |
| 213 | oldset_cp = server->nls_vol; |
| 214 | server->nls_vol = codepage; |
| 215 | oldset_io = server->nls_io; |
| 216 | server->nls_io = iocharset; |
| 217 | err = 0; |
| 218 | } |
| 219 | mutex_unlock(&server->root_setup_lock); |
Thomas Gleixner | 6d729e4 | 2009-08-16 21:05:08 +0000 | [diff] [blame] | 220 | unload_nls(oldset_cp); |
| 221 | unload_nls(oldset_io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 223 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static int |
| 227 | ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) |
| 228 | { |
| 229 | struct ncp_nls_ioctl user; |
| 230 | int len; |
| 231 | |
| 232 | memset(&user, 0, sizeof(user)); |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 233 | mutex_lock(&server->root_setup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if (server->nls_vol && server->nls_vol->charset) { |
| 235 | len = strlen(server->nls_vol->charset); |
| 236 | if (len > NCP_IOCSNAME_LEN) |
| 237 | len = NCP_IOCSNAME_LEN; |
| 238 | strncpy(user.codepage, server->nls_vol->charset, len); |
| 239 | user.codepage[len] = 0; |
| 240 | } |
| 241 | |
| 242 | if (NCP_IS_FLAG(server, NCP_FLAG_UTF8)) |
| 243 | strcpy(user.iocharset, "utf8"); |
| 244 | else if (server->nls_io && server->nls_io->charset) { |
| 245 | len = strlen(server->nls_io->charset); |
| 246 | if (len > NCP_IOCSNAME_LEN) |
| 247 | len = NCP_IOCSNAME_LEN; |
| 248 | strncpy(user.iocharset, server->nls_io->charset, len); |
| 249 | user.iocharset[len] = 0; |
| 250 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 251 | mutex_unlock(&server->root_setup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | if (copy_to_user(arg, &user, sizeof(user))) |
| 254 | return -EFAULT; |
| 255 | return 0; |
| 256 | } |
| 257 | #endif /* CONFIG_NCPFS_NLS */ |
| 258 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 259 | static long __ncp_ioctl(struct inode *inode, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
| 261 | struct ncp_server *server = NCP_SERVER(inode); |
| 262 | int result; |
| 263 | struct ncp_ioctl_request request; |
| 264 | char* bouncebuffer; |
| 265 | void __user *argp = (void __user *)arg; |
| 266 | |
| 267 | switch (cmd) { |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 268 | #ifdef CONFIG_COMPAT |
| 269 | case NCP_IOC_NCPREQUEST_32: |
| 270 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | case NCP_IOC_NCPREQUEST: |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 272 | #ifdef CONFIG_COMPAT |
| 273 | if (cmd == NCP_IOC_NCPREQUEST_32) { |
| 274 | struct compat_ncp_ioctl_request request32; |
| 275 | if (copy_from_user(&request32, argp, sizeof(request32))) |
| 276 | return -EFAULT; |
| 277 | request.function = request32.function; |
| 278 | request.size = request32.size; |
| 279 | request.data = compat_ptr(request32.data); |
| 280 | } else |
| 281 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (copy_from_user(&request, argp, sizeof(request))) |
| 283 | return -EFAULT; |
| 284 | |
| 285 | if ((request.function > 255) |
| 286 | || (request.size > |
| 287 | NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) { |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | bouncebuffer = vmalloc(NCP_PACKET_SIZE_INTERNAL); |
| 291 | if (!bouncebuffer) |
| 292 | return -ENOMEM; |
| 293 | if (copy_from_user(bouncebuffer, request.data, request.size)) { |
| 294 | vfree(bouncebuffer); |
| 295 | return -EFAULT; |
| 296 | } |
| 297 | ncp_lock_server(server); |
| 298 | |
| 299 | /* FIXME: We hack around in the server's structures |
| 300 | here to be able to use ncp_request */ |
| 301 | |
| 302 | server->has_subfunction = 0; |
| 303 | server->current_size = request.size; |
| 304 | memcpy(server->packet, bouncebuffer, request.size); |
| 305 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 306 | result = ncp_request2(server, request.function, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | bouncebuffer, NCP_PACKET_SIZE_INTERNAL); |
| 308 | if (result < 0) |
| 309 | result = -EIO; |
| 310 | else |
| 311 | result = server->reply_size; |
| 312 | ncp_unlock_server(server); |
| 313 | DPRINTK("ncp_ioctl: copy %d bytes\n", |
| 314 | result); |
| 315 | if (result >= 0) |
| 316 | if (copy_to_user(request.data, bouncebuffer, result)) |
| 317 | result = -EFAULT; |
| 318 | vfree(bouncebuffer); |
| 319 | return result; |
| 320 | |
| 321 | case NCP_IOC_CONN_LOGGED_IN: |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (!(server->m.int_flags & NCP_IMOUNT_LOGGEDIN_POSSIBLE)) |
| 324 | return -EINVAL; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 325 | mutex_lock(&server->root_setup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (server->root_setuped) |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 327 | result = -EBUSY; |
| 328 | else { |
| 329 | result = ncp_conn_logged_in(inode->i_sb); |
| 330 | if (result == 0) |
| 331 | server->root_setuped = 1; |
| 332 | } |
| 333 | mutex_unlock(&server->root_setup_lock); |
| 334 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | case NCP_IOC_GET_FS_INFO: |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 337 | return ncp_get_fs_info(server, inode, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | case NCP_IOC_GET_FS_INFO_V2: |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 340 | return ncp_get_fs_info_v2(server, inode, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 342 | #ifdef CONFIG_COMPAT |
| 343 | case NCP_IOC_GET_FS_INFO_V2_32: |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 344 | return ncp_get_compat_fs_info_v2(server, inode, argp); |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 345 | #endif |
| 346 | /* we have too many combinations of CONFIG_COMPAT, |
| 347 | * CONFIG_64BIT and CONFIG_UID16, so just handle |
| 348 | * any of the possible ioctls */ |
| 349 | case NCP_IOC_GETMOUNTUID16: |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 350 | { |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 351 | u16 uid; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 352 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 353 | SET_UID(uid, server->m.mounted_uid); |
| 354 | if (put_user(uid, (u16 __user *)argp)) |
| 355 | return -EFAULT; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 356 | return 0; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 357 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 358 | case NCP_IOC_GETMOUNTUID32: |
| 359 | if (put_user(server->m.mounted_uid, |
| 360 | (u32 __user *)argp)) |
| 361 | return -EFAULT; |
| 362 | return 0; |
| 363 | case NCP_IOC_GETMOUNTUID64: |
| 364 | if (put_user(server->m.mounted_uid, |
| 365 | (u64 __user *)argp)) |
| 366 | return -EFAULT; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 367 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | case NCP_IOC_GETROOT: |
| 370 | { |
| 371 | struct ncp_setroot_ioctl sr; |
| 372 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 373 | result = -EACCES; |
| 374 | mutex_lock(&server->root_setup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | if (server->m.mounted_vol[0]) { |
| 376 | struct dentry* dentry = inode->i_sb->s_root; |
| 377 | |
| 378 | if (dentry) { |
Harvey Harrison | 305787e | 2008-04-28 02:14:00 -0700 | [diff] [blame] | 379 | struct inode* s_inode = dentry->d_inode; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 380 | |
Harvey Harrison | 305787e | 2008-04-28 02:14:00 -0700 | [diff] [blame] | 381 | if (s_inode) { |
| 382 | sr.volNumber = NCP_FINFO(s_inode)->volNumber; |
| 383 | sr.dirEntNum = NCP_FINFO(s_inode)->dirEntNum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | sr.namespace = server->name_space[sr.volNumber]; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 385 | result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } else |
| 387 | DPRINTK("ncpfs: s_root->d_inode==NULL\n"); |
| 388 | } else |
| 389 | DPRINTK("ncpfs: s_root==NULL\n"); |
| 390 | } else { |
| 391 | sr.volNumber = -1; |
| 392 | sr.namespace = 0; |
| 393 | sr.dirEntNum = 0; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 394 | result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 396 | mutex_unlock(&server->root_setup_lock); |
| 397 | if (!result && copy_to_user(argp, &sr, sizeof(sr))) |
| 398 | result = -EFAULT; |
| 399 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
David Howells | 4893702 | 2008-11-14 10:38:58 +1100 | [diff] [blame] | 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | case NCP_IOC_SETROOT: |
| 403 | { |
| 404 | struct ncp_setroot_ioctl sr; |
| 405 | __u32 vnum; |
| 406 | __le32 de; |
| 407 | __le32 dosde; |
| 408 | struct dentry* dentry; |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | if (copy_from_user(&sr, argp, sizeof(sr))) |
| 411 | return -EFAULT; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 412 | mutex_lock(&server->root_setup_lock); |
| 413 | if (server->root_setuped) |
| 414 | result = -EBUSY; |
| 415 | else { |
| 416 | if (sr.volNumber < 0) { |
| 417 | server->m.mounted_vol[0] = 0; |
| 418 | vnum = NCP_NUMBER_OF_VOLUMES; |
| 419 | de = 0; |
| 420 | dosde = 0; |
| 421 | result = 0; |
| 422 | } else if (sr.volNumber >= NCP_NUMBER_OF_VOLUMES) { |
| 423 | result = -EINVAL; |
| 424 | } else if (ncp_mount_subdir(server, sr.volNumber, |
| 425 | sr.namespace, sr.dirEntNum, |
| 426 | &vnum, &de, &dosde)) { |
| 427 | result = -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } else |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 429 | result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 431 | if (result == 0) { |
| 432 | dentry = inode->i_sb->s_root; |
| 433 | if (dentry) { |
| 434 | struct inode* s_inode = dentry->d_inode; |
| 435 | |
| 436 | if (s_inode) { |
| 437 | NCP_FINFO(s_inode)->volNumber = vnum; |
| 438 | NCP_FINFO(s_inode)->dirEntNum = de; |
| 439 | NCP_FINFO(s_inode)->DosDirNum = dosde; |
| 440 | server->root_setuped = 1; |
| 441 | } else { |
| 442 | DPRINTK("ncpfs: s_root->d_inode==NULL\n"); |
| 443 | result = -EIO; |
| 444 | } |
| 445 | } else { |
| 446 | DPRINTK("ncpfs: s_root==NULL\n"); |
| 447 | result = -EIO; |
| 448 | } |
| 449 | } |
| 450 | result = 0; |
| 451 | } |
| 452 | mutex_unlock(&server->root_setup_lock); |
| 453 | |
| 454 | return result; |
| 455 | } |
| 456 | |
| 457 | #ifdef CONFIG_NCPFS_PACKET_SIGNING |
| 458 | case NCP_IOC_SIGN_INIT: |
| 459 | { |
| 460 | struct ncp_sign_init sign; |
| 461 | |
| 462 | if (argp) |
| 463 | if (copy_from_user(&sign, argp, sizeof(sign))) |
| 464 | return -EFAULT; |
| 465 | ncp_lock_server(server); |
| 466 | mutex_lock(&server->rcv.creq_mutex); |
| 467 | if (argp) { |
| 468 | if (server->sign_wanted) { |
| 469 | memcpy(server->sign_root,sign.sign_root,8); |
| 470 | memcpy(server->sign_last,sign.sign_last,16); |
| 471 | server->sign_active = 1; |
| 472 | } |
| 473 | /* ignore when signatures not wanted */ |
| 474 | } else { |
| 475 | server->sign_active = 0; |
| 476 | } |
| 477 | mutex_unlock(&server->rcv.creq_mutex); |
| 478 | ncp_unlock_server(server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | case NCP_IOC_SIGN_WANTED: |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 483 | { |
| 484 | int state; |
| 485 | |
| 486 | ncp_lock_server(server); |
| 487 | state = server->sign_wanted; |
| 488 | ncp_unlock_server(server); |
| 489 | if (put_user(state, (int __user *)argp)) |
| 490 | return -EFAULT; |
| 491 | return 0; |
| 492 | } |
David Howells | 4893702 | 2008-11-14 10:38:58 +1100 | [diff] [blame] | 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | case NCP_IOC_SET_SIGN_WANTED: |
| 495 | { |
| 496 | int newstate; |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* get only low 8 bits... */ |
| 499 | if (get_user(newstate, (unsigned char __user *)argp)) |
| 500 | return -EFAULT; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 501 | result = 0; |
| 502 | ncp_lock_server(server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (server->sign_active) { |
| 504 | /* cannot turn signatures OFF when active */ |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 505 | if (!newstate) |
| 506 | result = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } else { |
| 508 | server->sign_wanted = newstate != 0; |
| 509 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 510 | ncp_unlock_server(server); |
| 511 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | #endif /* CONFIG_NCPFS_PACKET_SIGNING */ |
| 515 | |
| 516 | #ifdef CONFIG_NCPFS_IOCTL_LOCKING |
| 517 | case NCP_IOC_LOCKUNLOCK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { |
| 519 | struct ncp_lock_ioctl rqdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
| 521 | if (copy_from_user(&rqdata, argp, sizeof(rqdata))) |
| 522 | return -EFAULT; |
| 523 | if (rqdata.origin != 0) |
| 524 | return -EINVAL; |
| 525 | /* check for cmd */ |
| 526 | switch (rqdata.cmd) { |
| 527 | case NCP_LOCK_EX: |
| 528 | case NCP_LOCK_SH: |
| 529 | if (rqdata.timeout == 0) |
| 530 | rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; |
| 531 | else if (rqdata.timeout > NCP_LOCK_MAX_TIMEOUT) |
| 532 | rqdata.timeout = NCP_LOCK_MAX_TIMEOUT; |
| 533 | break; |
| 534 | case NCP_LOCK_LOG: |
| 535 | rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */ |
| 536 | case NCP_LOCK_CLEAR: |
| 537 | break; |
| 538 | default: |
| 539 | return -EINVAL; |
| 540 | } |
| 541 | /* locking needs both read and write access */ |
| 542 | if ((result = ncp_make_open(inode, O_RDWR)) != 0) |
| 543 | { |
| 544 | return result; |
| 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | result = -EISDIR; |
| 547 | if (!S_ISREG(inode->i_mode)) |
| 548 | goto outrel; |
| 549 | if (rqdata.cmd == NCP_LOCK_CLEAR) |
| 550 | { |
| 551 | result = ncp_ClearPhysicalRecord(NCP_SERVER(inode), |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 552 | NCP_FINFO(inode)->file_handle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | rqdata.offset, |
| 554 | rqdata.length); |
| 555 | if (result > 0) result = 0; /* no such lock */ |
| 556 | } |
| 557 | else |
| 558 | { |
| 559 | int lockcmd; |
| 560 | |
| 561 | switch (rqdata.cmd) |
| 562 | { |
| 563 | case NCP_LOCK_EX: lockcmd=1; break; |
| 564 | case NCP_LOCK_SH: lockcmd=3; break; |
| 565 | default: lockcmd=0; break; |
| 566 | } |
| 567 | result = ncp_LogPhysicalRecord(NCP_SERVER(inode), |
| 568 | NCP_FINFO(inode)->file_handle, |
| 569 | lockcmd, |
| 570 | rqdata.offset, |
| 571 | rqdata.length, |
| 572 | rqdata.timeout); |
| 573 | if (result > 0) result = -EAGAIN; |
| 574 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 575 | outrel: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | ncp_inode_close(inode); |
| 577 | return result; |
| 578 | } |
| 579 | #endif /* CONFIG_NCPFS_IOCTL_LOCKING */ |
| 580 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 581 | #ifdef CONFIG_COMPAT |
| 582 | case NCP_IOC_GETOBJECTNAME_32: |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 583 | { |
| 584 | struct compat_ncp_objectname_ioctl user; |
| 585 | size_t outl; |
| 586 | |
| 587 | if (copy_from_user(&user, argp, sizeof(user))) |
| 588 | return -EFAULT; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 589 | down_read(&server->auth_rwsem); |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 590 | user.auth_type = server->auth.auth_type; |
| 591 | outl = user.object_name_len; |
| 592 | user.object_name_len = server->auth.object_name_len; |
| 593 | if (outl > user.object_name_len) |
| 594 | outl = user.object_name_len; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 595 | result = 0; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 596 | if (outl) { |
| 597 | if (copy_to_user(compat_ptr(user.object_name), |
| 598 | server->auth.object_name, |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 599 | outl)) |
| 600 | result = -EFAULT; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 601 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 602 | up_read(&server->auth_rwsem); |
| 603 | if (!result && copy_to_user(argp, &user, sizeof(user))) |
| 604 | result = -EFAULT; |
| 605 | return result; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 606 | } |
| 607 | #endif |
David Howells | 4893702 | 2008-11-14 10:38:58 +1100 | [diff] [blame] | 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | case NCP_IOC_GETOBJECTNAME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | struct ncp_objectname_ioctl user; |
| 612 | size_t outl; |
| 613 | |
| 614 | if (copy_from_user(&user, argp, sizeof(user))) |
| 615 | return -EFAULT; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 616 | down_read(&server->auth_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | user.auth_type = server->auth.auth_type; |
| 618 | outl = user.object_name_len; |
| 619 | user.object_name_len = server->auth.object_name_len; |
| 620 | if (outl > user.object_name_len) |
| 621 | outl = user.object_name_len; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 622 | result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | if (outl) { |
| 624 | if (copy_to_user(user.object_name, |
| 625 | server->auth.object_name, |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 626 | outl)) |
| 627 | result = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 629 | up_read(&server->auth_rwsem); |
| 630 | if (!result && copy_to_user(argp, &user, sizeof(user))) |
| 631 | result = -EFAULT; |
| 632 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
David Howells | 4893702 | 2008-11-14 10:38:58 +1100 | [diff] [blame] | 634 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 635 | #ifdef CONFIG_COMPAT |
| 636 | case NCP_IOC_SETOBJECTNAME_32: |
| 637 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | case NCP_IOC_SETOBJECTNAME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
| 640 | struct ncp_objectname_ioctl user; |
| 641 | void* newname; |
| 642 | void* oldname; |
| 643 | size_t oldnamelen; |
| 644 | void* oldprivate; |
| 645 | size_t oldprivatelen; |
| 646 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 647 | #ifdef CONFIG_COMPAT |
| 648 | if (cmd == NCP_IOC_SETOBJECTNAME_32) { |
| 649 | struct compat_ncp_objectname_ioctl user32; |
| 650 | if (copy_from_user(&user32, argp, sizeof(user32))) |
| 651 | return -EFAULT; |
| 652 | user.auth_type = user32.auth_type; |
| 653 | user.object_name_len = user32.object_name_len; |
| 654 | user.object_name = compat_ptr(user32.object_name); |
| 655 | } else |
| 656 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | if (copy_from_user(&user, argp, sizeof(user))) |
| 658 | return -EFAULT; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN) |
| 661 | return -ENOMEM; |
| 662 | if (user.object_name_len) { |
Li Zefan | a9482eb | 2009-04-08 15:08:53 +0800 | [diff] [blame] | 663 | newname = memdup_user(user.object_name, |
| 664 | user.object_name_len); |
| 665 | if (IS_ERR(newname)) |
| 666 | return PTR_ERR(newname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } else { |
| 668 | newname = NULL; |
| 669 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 670 | down_write(&server->auth_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | oldname = server->auth.object_name; |
| 672 | oldnamelen = server->auth.object_name_len; |
| 673 | oldprivate = server->priv.data; |
| 674 | oldprivatelen = server->priv.len; |
| 675 | server->auth.auth_type = user.auth_type; |
| 676 | server->auth.object_name_len = user.object_name_len; |
| 677 | server->auth.object_name = newname; |
| 678 | server->priv.len = 0; |
| 679 | server->priv.data = NULL; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 680 | up_write(&server->auth_rwsem); |
Pekka Enberg | 44db77f | 2006-01-14 13:21:12 -0800 | [diff] [blame] | 681 | kfree(oldprivate); |
| 682 | kfree(oldname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | return 0; |
| 684 | } |
David Howells | 4893702 | 2008-11-14 10:38:58 +1100 | [diff] [blame] | 685 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 686 | #ifdef CONFIG_COMPAT |
| 687 | case NCP_IOC_GETPRIVATEDATA_32: |
| 688 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | case NCP_IOC_GETPRIVATEDATA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
| 691 | struct ncp_privatedata_ioctl user; |
| 692 | size_t outl; |
| 693 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 694 | #ifdef CONFIG_COMPAT |
| 695 | if (cmd == NCP_IOC_GETPRIVATEDATA_32) { |
| 696 | struct compat_ncp_privatedata_ioctl user32; |
| 697 | if (copy_from_user(&user32, argp, sizeof(user32))) |
| 698 | return -EFAULT; |
| 699 | user.len = user32.len; |
| 700 | user.data = compat_ptr(user32.data); |
| 701 | } else |
| 702 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | if (copy_from_user(&user, argp, sizeof(user))) |
| 704 | return -EFAULT; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 705 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 706 | down_read(&server->auth_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | outl = user.len; |
| 708 | user.len = server->priv.len; |
| 709 | if (outl > user.len) outl = user.len; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 710 | result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if (outl) { |
| 712 | if (copy_to_user(user.data, |
| 713 | server->priv.data, |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 714 | outl)) |
| 715 | result = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 717 | up_read(&server->auth_rwsem); |
| 718 | if (result) |
| 719 | return result; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 720 | #ifdef CONFIG_COMPAT |
| 721 | if (cmd == NCP_IOC_GETPRIVATEDATA_32) { |
| 722 | struct compat_ncp_privatedata_ioctl user32; |
| 723 | user32.len = user.len; |
| 724 | user32.data = (unsigned long) user.data; |
Al Viro | 5c09d96 | 2006-10-09 20:24:49 +0100 | [diff] [blame] | 725 | if (copy_to_user(argp, &user32, sizeof(user32))) |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 726 | return -EFAULT; |
| 727 | } else |
| 728 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | if (copy_to_user(argp, &user, sizeof(user))) |
| 730 | return -EFAULT; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | return 0; |
| 733 | } |
David Howells | 4893702 | 2008-11-14 10:38:58 +1100 | [diff] [blame] | 734 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 735 | #ifdef CONFIG_COMPAT |
| 736 | case NCP_IOC_SETPRIVATEDATA_32: |
| 737 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | case NCP_IOC_SETPRIVATEDATA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
| 740 | struct ncp_privatedata_ioctl user; |
| 741 | void* new; |
| 742 | void* old; |
| 743 | size_t oldlen; |
| 744 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 745 | #ifdef CONFIG_COMPAT |
| 746 | if (cmd == NCP_IOC_SETPRIVATEDATA_32) { |
| 747 | struct compat_ncp_privatedata_ioctl user32; |
| 748 | if (copy_from_user(&user32, argp, sizeof(user32))) |
| 749 | return -EFAULT; |
| 750 | user.len = user32.len; |
| 751 | user.data = compat_ptr(user32.data); |
| 752 | } else |
| 753 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | if (copy_from_user(&user, argp, sizeof(user))) |
| 755 | return -EFAULT; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (user.len > NCP_PRIVATE_DATA_MAX_LEN) |
| 758 | return -ENOMEM; |
| 759 | if (user.len) { |
Li Zefan | a9482eb | 2009-04-08 15:08:53 +0800 | [diff] [blame] | 760 | new = memdup_user(user.data, user.len); |
| 761 | if (IS_ERR(new)) |
| 762 | return PTR_ERR(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } else { |
| 764 | new = NULL; |
| 765 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 766 | down_write(&server->auth_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | old = server->priv.data; |
| 768 | oldlen = server->priv.len; |
| 769 | server->priv.len = user.len; |
| 770 | server->priv.data = new; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 771 | up_write(&server->auth_rwsem); |
Pekka Enberg | 44db77f | 2006-01-14 13:21:12 -0800 | [diff] [blame] | 772 | kfree(old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | #ifdef CONFIG_NCPFS_NLS |
| 777 | case NCP_IOC_SETCHARSETS: |
| 778 | return ncp_set_charsets(server, argp); |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | case NCP_IOC_GETCHARSETS: |
| 781 | return ncp_get_charsets(server, argp); |
| 782 | |
| 783 | #endif /* CONFIG_NCPFS_NLS */ |
| 784 | |
| 785 | case NCP_IOC_SETDENTRYTTL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
| 787 | u_int32_t user; |
| 788 | |
| 789 | if (copy_from_user(&user, argp, sizeof(user))) |
| 790 | return -EFAULT; |
| 791 | /* 20 secs at most... */ |
| 792 | if (user > 20000) |
| 793 | return -EINVAL; |
| 794 | user = (user * HZ) / 1000; |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 795 | atomic_set(&server->dentry_ttl, user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | return 0; |
| 797 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | case NCP_IOC_GETDENTRYTTL: |
| 800 | { |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 801 | u_int32_t user = (atomic_read(&server->dentry_ttl) * 1000) / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | if (copy_to_user(argp, &user, sizeof(user))) |
| 803 | return -EFAULT; |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | return -EINVAL; |
| 809 | } |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 810 | |
John Kacur | 93d84b6 | 2010-05-05 15:15:37 +0200 | [diff] [blame] | 811 | long ncp_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Dave Hansen | a761a1c | 2008-02-15 14:37:39 -0800 | [diff] [blame] | 812 | { |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 813 | struct inode *inode = filp->f_dentry->d_inode; |
| 814 | struct ncp_server *server = NCP_SERVER(inode); |
| 815 | uid_t uid = current_uid(); |
| 816 | int need_drop_write = 0; |
John Kacur | 93d84b6 | 2010-05-05 15:15:37 +0200 | [diff] [blame] | 817 | long ret; |
Dave Hansen | a761a1c | 2008-02-15 14:37:39 -0800 | [diff] [blame] | 818 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 819 | switch (cmd) { |
| 820 | case NCP_IOC_SETCHARSETS: |
| 821 | case NCP_IOC_CONN_LOGGED_IN: |
| 822 | case NCP_IOC_SETROOT: |
| 823 | if (!capable(CAP_SYS_ADMIN)) { |
John Kacur | 93d84b6 | 2010-05-05 15:15:37 +0200 | [diff] [blame] | 824 | ret = -EACCES; |
| 825 | goto out; |
| 826 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 827 | break; |
Dave Hansen | a761a1c | 2008-02-15 14:37:39 -0800 | [diff] [blame] | 828 | } |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 829 | if (server->m.mounted_uid != uid) { |
| 830 | switch (cmd) { |
| 831 | /* |
| 832 | * Only mount owner can issue these ioctls. Information |
| 833 | * necessary to authenticate to other NDS servers are |
| 834 | * stored here. |
| 835 | */ |
| 836 | case NCP_IOC_GETOBJECTNAME: |
| 837 | case NCP_IOC_SETOBJECTNAME: |
| 838 | case NCP_IOC_GETPRIVATEDATA: |
| 839 | case NCP_IOC_SETPRIVATEDATA: |
| 840 | #ifdef CONFIG_COMPAT |
| 841 | case NCP_IOC_GETOBJECTNAME_32: |
| 842 | case NCP_IOC_SETOBJECTNAME_32: |
| 843 | case NCP_IOC_GETPRIVATEDATA_32: |
| 844 | case NCP_IOC_SETPRIVATEDATA_32: |
| 845 | #endif |
| 846 | ret = -EACCES; |
| 847 | goto out; |
| 848 | /* |
| 849 | * These require write access on the inode if user id |
| 850 | * does not match. Note that they do not write to the |
| 851 | * file... But old code did mnt_want_write, so I keep |
| 852 | * it as is. Of course not for mountpoint owner, as |
| 853 | * that breaks read-only mounts altogether as ncpmount |
| 854 | * needs working NCP_IOC_NCPREQUEST and |
| 855 | * NCP_IOC_GET_FS_INFO. Some of these codes (setdentryttl, |
| 856 | * signinit, setsignwanted) should be probably restricted |
| 857 | * to owner only, or even more to CAP_SYS_ADMIN). |
| 858 | */ |
| 859 | case NCP_IOC_GET_FS_INFO: |
| 860 | case NCP_IOC_GET_FS_INFO_V2: |
| 861 | case NCP_IOC_NCPREQUEST: |
| 862 | case NCP_IOC_SETDENTRYTTL: |
| 863 | case NCP_IOC_SIGN_INIT: |
| 864 | case NCP_IOC_LOCKUNLOCK: |
| 865 | case NCP_IOC_SET_SIGN_WANTED: |
| 866 | #ifdef CONFIG_COMPAT |
| 867 | case NCP_IOC_GET_FS_INFO_V2_32: |
| 868 | case NCP_IOC_NCPREQUEST_32: |
| 869 | #endif |
| 870 | ret = mnt_want_write_file(filp); |
| 871 | if (ret) |
| 872 | goto out; |
| 873 | need_drop_write = 1; |
| 874 | ret = inode_permission(inode, MAY_WRITE); |
| 875 | if (ret) |
| 876 | goto outDropWrite; |
| 877 | break; |
| 878 | /* |
| 879 | * Read access required. |
| 880 | */ |
| 881 | case NCP_IOC_GETMOUNTUID16: |
| 882 | case NCP_IOC_GETMOUNTUID32: |
| 883 | case NCP_IOC_GETMOUNTUID64: |
| 884 | case NCP_IOC_GETROOT: |
| 885 | case NCP_IOC_SIGN_WANTED: |
| 886 | ret = inode_permission(inode, MAY_READ); |
| 887 | if (ret) |
| 888 | goto out; |
| 889 | break; |
| 890 | /* |
| 891 | * Anybody can read these. |
| 892 | */ |
| 893 | case NCP_IOC_GETCHARSETS: |
| 894 | case NCP_IOC_GETDENTRYTTL: |
| 895 | default: |
| 896 | /* Three codes below are protected by CAP_SYS_ADMIN above. */ |
| 897 | case NCP_IOC_SETCHARSETS: |
| 898 | case NCP_IOC_CONN_LOGGED_IN: |
| 899 | case NCP_IOC_SETROOT: |
| 900 | break; |
| 901 | } |
| 902 | } |
| 903 | ret = __ncp_ioctl(inode, cmd, arg); |
| 904 | outDropWrite: |
| 905 | if (need_drop_write) |
Dave Hansen | a761a1c | 2008-02-15 14:37:39 -0800 | [diff] [blame] | 906 | mnt_drop_write(filp->f_path.mnt); |
John Kacur | 93d84b6 | 2010-05-05 15:15:37 +0200 | [diff] [blame] | 907 | out: |
Dave Hansen | a761a1c | 2008-02-15 14:37:39 -0800 | [diff] [blame] | 908 | return ret; |
| 909 | } |
| 910 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 911 | #ifdef CONFIG_COMPAT |
| 912 | long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 913 | { |
John Kacur | 93d84b6 | 2010-05-05 15:15:37 +0200 | [diff] [blame] | 914 | long ret; |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 915 | |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 916 | arg = (unsigned long) compat_ptr(arg); |
John Kacur | 93d84b6 | 2010-05-05 15:15:37 +0200 | [diff] [blame] | 917 | ret = ncp_ioctl(file, cmd, arg); |
Petr Vandrovec | 54f67f6 | 2006-09-30 23:27:55 -0700 | [diff] [blame] | 918 | return ret; |
| 919 | } |
| 920 | #endif |