ioctl.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. #include <linux/capability.h>
  10. #include <linux/compat.h>
  11. #include <linux/errno.h>
  12. #include <linux/fs.h>
  13. #include <linux/ioctl.h>
  14. #include <linux/time.h>
  15. #include <linux/mm.h>
  16. #include <linux/highuid.h>
  17. #include <linux/smp_lock.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/ncp_fs.h>
  20. #include <asm/uaccess.h>
  21. #include "ncplib_kernel.h"
  22. /* maximum limit for ncp_objectname_ioctl */
  23. #define NCP_OBJECT_NAME_MAX_LEN 4096
  24. /* maximum limit for ncp_privatedata_ioctl */
  25. #define NCP_PRIVATE_DATA_MAX_LEN 8192
  26. /* maximum negotiable packet size */
  27. #define NCP_PACKET_SIZE_INTERNAL 65536
  28. static int
  29. ncp_get_fs_info(struct ncp_server * server, struct file *file,
  30. struct ncp_fs_info __user *arg)
  31. {
  32. struct inode *inode = file->f_path.dentry->d_inode;
  33. struct ncp_fs_info info;
  34. if ((file_permission(file, MAY_WRITE) != 0)
  35. && (current->uid != server->m.mounted_uid)) {
  36. return -EACCES;
  37. }
  38. if (copy_from_user(&info, arg, sizeof(info)))
  39. return -EFAULT;
  40. if (info.version != NCP_GET_FS_INFO_VERSION) {
  41. DPRINTK("info.version invalid: %d\n", info.version);
  42. return -EINVAL;
  43. }
  44. /* TODO: info.addr = server->m.serv_addr; */
  45. SET_UID(info.mounted_uid, server->m.mounted_uid);
  46. info.connection = server->connection;
  47. info.buffer_size = server->buffer_size;
  48. info.volume_number = NCP_FINFO(inode)->volNumber;
  49. info.directory_id = NCP_FINFO(inode)->DosDirNum;
  50. if (copy_to_user(arg, &info, sizeof(info)))
  51. return -EFAULT;
  52. return 0;
  53. }
  54. static int
  55. ncp_get_fs_info_v2(struct ncp_server * server, struct file *file,
  56. struct ncp_fs_info_v2 __user * arg)
  57. {
  58. struct inode *inode = file->f_path.dentry->d_inode;
  59. struct ncp_fs_info_v2 info2;
  60. if ((file_permission(file, MAY_WRITE) != 0)
  61. && (current->uid != server->m.mounted_uid)) {
  62. return -EACCES;
  63. }
  64. if (copy_from_user(&info2, arg, sizeof(info2)))
  65. return -EFAULT;
  66. if (info2.version != NCP_GET_FS_INFO_VERSION_V2) {
  67. DPRINTK("info.version invalid: %d\n", info2.version);
  68. return -EINVAL;
  69. }
  70. info2.mounted_uid = server->m.mounted_uid;
  71. info2.connection = server->connection;
  72. info2.buffer_size = server->buffer_size;
  73. info2.volume_number = NCP_FINFO(inode)->volNumber;
  74. info2.directory_id = NCP_FINFO(inode)->DosDirNum;
  75. info2.dummy1 = info2.dummy2 = info2.dummy3 = 0;
  76. if (copy_to_user(arg, &info2, sizeof(info2)))
  77. return -EFAULT;
  78. return 0;
  79. }
  80. #ifdef CONFIG_COMPAT
  81. struct compat_ncp_objectname_ioctl
  82. {
  83. s32 auth_type;
  84. u32 object_name_len;
  85. compat_caddr_t object_name; /* an userspace data, in most cases user name */
  86. };
  87. struct compat_ncp_fs_info_v2 {
  88. s32 version;
  89. u32 mounted_uid;
  90. u32 connection;
  91. u32 buffer_size;
  92. u32 volume_number;
  93. u32 directory_id;
  94. u32 dummy1;
  95. u32 dummy2;
  96. u32 dummy3;
  97. };
  98. struct compat_ncp_ioctl_request {
  99. u32 function;
  100. u32 size;
  101. compat_caddr_t data;
  102. };
  103. struct compat_ncp_privatedata_ioctl
  104. {
  105. u32 len;
  106. compat_caddr_t data; /* ~1000 for NDS */
  107. };
  108. #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct compat_ncp_fs_info_v2)
  109. #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct compat_ncp_ioctl_request)
  110. #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct compat_ncp_objectname_ioctl)
  111. #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct compat_ncp_objectname_ioctl)
  112. #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct compat_ncp_privatedata_ioctl)
  113. #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct compat_ncp_privatedata_ioctl)
  114. static int
  115. ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file,
  116. struct compat_ncp_fs_info_v2 __user * arg)
  117. {
  118. struct inode *inode = file->f_path.dentry->d_inode;
  119. struct compat_ncp_fs_info_v2 info2;
  120. if ((file_permission(file, MAY_WRITE) != 0)
  121. && (current->uid != server->m.mounted_uid)) {
  122. return -EACCES;
  123. }
  124. if (copy_from_user(&info2, arg, sizeof(info2)))
  125. return -EFAULT;
  126. if (info2.version != NCP_GET_FS_INFO_VERSION_V2) {
  127. DPRINTK("info.version invalid: %d\n", info2.version);
  128. return -EINVAL;
  129. }
  130. info2.mounted_uid = server->m.mounted_uid;
  131. info2.connection = server->connection;
  132. info2.buffer_size = server->buffer_size;
  133. info2.volume_number = NCP_FINFO(inode)->volNumber;
  134. info2.directory_id = NCP_FINFO(inode)->DosDirNum;
  135. info2.dummy1 = info2.dummy2 = info2.dummy3 = 0;
  136. if (copy_to_user(arg, &info2, sizeof(info2)))
  137. return -EFAULT;
  138. return 0;
  139. }
  140. #endif
  141. #define NCP_IOC_GETMOUNTUID16 _IOW('n', 2, u16)
  142. #define NCP_IOC_GETMOUNTUID32 _IOW('n', 2, u32)
  143. #define NCP_IOC_GETMOUNTUID64 _IOW('n', 2, u64)
  144. #ifdef CONFIG_NCPFS_NLS
  145. /* Here we are select the iocharset and the codepage for NLS.
  146. * Thanks Petr Vandrovec for idea and many hints.
  147. */
  148. static int
  149. ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
  150. {
  151. struct ncp_nls_ioctl user;
  152. struct nls_table *codepage;
  153. struct nls_table *iocharset;
  154. struct nls_table *oldset_io;
  155. struct nls_table *oldset_cp;
  156. if (!capable(CAP_SYS_ADMIN))
  157. return -EACCES;
  158. if (server->root_setuped)
  159. return -EBUSY;
  160. if (copy_from_user(&user, arg, sizeof(user)))
  161. return -EFAULT;
  162. codepage = NULL;
  163. user.codepage[NCP_IOCSNAME_LEN] = 0;
  164. if (!user.codepage[0] || !strcmp(user.codepage, "default"))
  165. codepage = load_nls_default();
  166. else {
  167. codepage = load_nls(user.codepage);
  168. if (!codepage) {
  169. return -EBADRQC;
  170. }
  171. }
  172. iocharset = NULL;
  173. user.iocharset[NCP_IOCSNAME_LEN] = 0;
  174. if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) {
  175. iocharset = load_nls_default();
  176. NCP_CLR_FLAG(server, NCP_FLAG_UTF8);
  177. } else if (!strcmp(user.iocharset, "utf8")) {
  178. iocharset = load_nls_default();
  179. NCP_SET_FLAG(server, NCP_FLAG_UTF8);
  180. } else {
  181. iocharset = load_nls(user.iocharset);
  182. if (!iocharset) {
  183. unload_nls(codepage);
  184. return -EBADRQC;
  185. }
  186. NCP_CLR_FLAG(server, NCP_FLAG_UTF8);
  187. }
  188. oldset_cp = server->nls_vol;
  189. server->nls_vol = codepage;
  190. oldset_io = server->nls_io;
  191. server->nls_io = iocharset;
  192. if (oldset_cp)
  193. unload_nls(oldset_cp);
  194. if (oldset_io)
  195. unload_nls(oldset_io);
  196. return 0;
  197. }
  198. static int
  199. ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
  200. {
  201. struct ncp_nls_ioctl user;
  202. int len;
  203. memset(&user, 0, sizeof(user));
  204. if (server->nls_vol && server->nls_vol->charset) {
  205. len = strlen(server->nls_vol->charset);
  206. if (len > NCP_IOCSNAME_LEN)
  207. len = NCP_IOCSNAME_LEN;
  208. strncpy(user.codepage, server->nls_vol->charset, len);
  209. user.codepage[len] = 0;
  210. }
  211. if (NCP_IS_FLAG(server, NCP_FLAG_UTF8))
  212. strcpy(user.iocharset, "utf8");
  213. else if (server->nls_io && server->nls_io->charset) {
  214. len = strlen(server->nls_io->charset);
  215. if (len > NCP_IOCSNAME_LEN)
  216. len = NCP_IOCSNAME_LEN;
  217. strncpy(user.iocharset, server->nls_io->charset, len);
  218. user.iocharset[len] = 0;
  219. }
  220. if (copy_to_user(arg, &user, sizeof(user)))
  221. return -EFAULT;
  222. return 0;
  223. }
  224. #endif /* CONFIG_NCPFS_NLS */
  225. int ncp_ioctl(struct inode *inode, struct file *filp,
  226. unsigned int cmd, unsigned long arg)
  227. {
  228. struct ncp_server *server = NCP_SERVER(inode);
  229. int result;
  230. struct ncp_ioctl_request request;
  231. char* bouncebuffer;
  232. void __user *argp = (void __user *)arg;
  233. switch (cmd) {
  234. #ifdef CONFIG_COMPAT
  235. case NCP_IOC_NCPREQUEST_32:
  236. #endif
  237. case NCP_IOC_NCPREQUEST:
  238. if ((file_permission(filp, MAY_WRITE) != 0)
  239. && (current->uid != server->m.mounted_uid)) {
  240. return -EACCES;
  241. }
  242. #ifdef CONFIG_COMPAT
  243. if (cmd == NCP_IOC_NCPREQUEST_32) {
  244. struct compat_ncp_ioctl_request request32;
  245. if (copy_from_user(&request32, argp, sizeof(request32)))
  246. return -EFAULT;
  247. request.function = request32.function;
  248. request.size = request32.size;
  249. request.data = compat_ptr(request32.data);
  250. } else
  251. #endif
  252. if (copy_from_user(&request, argp, sizeof(request)))
  253. return -EFAULT;
  254. if ((request.function > 255)
  255. || (request.size >
  256. NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) {
  257. return -EINVAL;
  258. }
  259. bouncebuffer = vmalloc(NCP_PACKET_SIZE_INTERNAL);
  260. if (!bouncebuffer)
  261. return -ENOMEM;
  262. if (copy_from_user(bouncebuffer, request.data, request.size)) {
  263. vfree(bouncebuffer);
  264. return -EFAULT;
  265. }
  266. ncp_lock_server(server);
  267. /* FIXME: We hack around in the server's structures
  268. here to be able to use ncp_request */
  269. server->has_subfunction = 0;
  270. server->current_size = request.size;
  271. memcpy(server->packet, bouncebuffer, request.size);
  272. result = ncp_request2(server, request.function,
  273. bouncebuffer, NCP_PACKET_SIZE_INTERNAL);
  274. if (result < 0)
  275. result = -EIO;
  276. else
  277. result = server->reply_size;
  278. ncp_unlock_server(server);
  279. DPRINTK("ncp_ioctl: copy %d bytes\n",
  280. result);
  281. if (result >= 0)
  282. if (copy_to_user(request.data, bouncebuffer, result))
  283. result = -EFAULT;
  284. vfree(bouncebuffer);
  285. return result;
  286. case NCP_IOC_CONN_LOGGED_IN:
  287. if (!capable(CAP_SYS_ADMIN))
  288. return -EACCES;
  289. if (!(server->m.int_flags & NCP_IMOUNT_LOGGEDIN_POSSIBLE))
  290. return -EINVAL;
  291. if (server->root_setuped)
  292. return -EBUSY;
  293. server->root_setuped = 1;
  294. return ncp_conn_logged_in(inode->i_sb);
  295. case NCP_IOC_GET_FS_INFO:
  296. return ncp_get_fs_info(server, filp, argp);
  297. case NCP_IOC_GET_FS_INFO_V2:
  298. return ncp_get_fs_info_v2(server, filp, argp);
  299. #ifdef CONFIG_COMPAT
  300. case NCP_IOC_GET_FS_INFO_V2_32:
  301. return ncp_get_compat_fs_info_v2(server, filp, argp);
  302. #endif
  303. /* we have too many combinations of CONFIG_COMPAT,
  304. * CONFIG_64BIT and CONFIG_UID16, so just handle
  305. * any of the possible ioctls */
  306. case NCP_IOC_GETMOUNTUID16:
  307. case NCP_IOC_GETMOUNTUID32:
  308. case NCP_IOC_GETMOUNTUID64:
  309. if ((file_permission(filp, MAY_READ) != 0)
  310. && (current->uid != server->m.mounted_uid)) {
  311. return -EACCES;
  312. }
  313. if (cmd == NCP_IOC_GETMOUNTUID16) {
  314. u16 uid;
  315. SET_UID(uid, server->m.mounted_uid);
  316. if (put_user(uid, (u16 __user *)argp))
  317. return -EFAULT;
  318. } else if (cmd == NCP_IOC_GETMOUNTUID32) {
  319. if (put_user(server->m.mounted_uid,
  320. (u32 __user *)argp))
  321. return -EFAULT;
  322. } else {
  323. if (put_user(server->m.mounted_uid,
  324. (u64 __user *)argp))
  325. return -EFAULT;
  326. }
  327. return 0;
  328. case NCP_IOC_GETROOT:
  329. {
  330. struct ncp_setroot_ioctl sr;
  331. if ((file_permission(filp, MAY_READ) != 0)
  332. && (current->uid != server->m.mounted_uid))
  333. {
  334. return -EACCES;
  335. }
  336. if (server->m.mounted_vol[0]) {
  337. struct dentry* dentry = inode->i_sb->s_root;
  338. if (dentry) {
  339. struct inode* inode = dentry->d_inode;
  340. if (inode) {
  341. sr.volNumber = NCP_FINFO(inode)->volNumber;
  342. sr.dirEntNum = NCP_FINFO(inode)->dirEntNum;
  343. sr.namespace = server->name_space[sr.volNumber];
  344. } else
  345. DPRINTK("ncpfs: s_root->d_inode==NULL\n");
  346. } else
  347. DPRINTK("ncpfs: s_root==NULL\n");
  348. } else {
  349. sr.volNumber = -1;
  350. sr.namespace = 0;
  351. sr.dirEntNum = 0;
  352. }
  353. if (copy_to_user(argp, &sr, sizeof(sr)))
  354. return -EFAULT;
  355. return 0;
  356. }
  357. case NCP_IOC_SETROOT:
  358. {
  359. struct ncp_setroot_ioctl sr;
  360. __u32 vnum;
  361. __le32 de;
  362. __le32 dosde;
  363. struct dentry* dentry;
  364. if (!capable(CAP_SYS_ADMIN))
  365. {
  366. return -EACCES;
  367. }
  368. if (server->root_setuped) return -EBUSY;
  369. if (copy_from_user(&sr, argp, sizeof(sr)))
  370. return -EFAULT;
  371. if (sr.volNumber < 0) {
  372. server->m.mounted_vol[0] = 0;
  373. vnum = NCP_NUMBER_OF_VOLUMES;
  374. de = 0;
  375. dosde = 0;
  376. } else if (sr.volNumber >= NCP_NUMBER_OF_VOLUMES) {
  377. return -EINVAL;
  378. } else if (ncp_mount_subdir(server, sr.volNumber,
  379. sr.namespace, sr.dirEntNum,
  380. &vnum, &de, &dosde)) {
  381. return -ENOENT;
  382. }
  383. dentry = inode->i_sb->s_root;
  384. server->root_setuped = 1;
  385. if (dentry) {
  386. struct inode* inode = dentry->d_inode;
  387. if (inode) {
  388. NCP_FINFO(inode)->volNumber = vnum;
  389. NCP_FINFO(inode)->dirEntNum = de;
  390. NCP_FINFO(inode)->DosDirNum = dosde;
  391. } else
  392. DPRINTK("ncpfs: s_root->d_inode==NULL\n");
  393. } else
  394. DPRINTK("ncpfs: s_root==NULL\n");
  395. return 0;
  396. }
  397. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  398. case NCP_IOC_SIGN_INIT:
  399. if ((file_permission(filp, MAY_WRITE) != 0)
  400. && (current->uid != server->m.mounted_uid))
  401. {
  402. return -EACCES;
  403. }
  404. if (argp) {
  405. if (server->sign_wanted)
  406. {
  407. struct ncp_sign_init sign;
  408. if (copy_from_user(&sign, argp, sizeof(sign)))
  409. return -EFAULT;
  410. memcpy(server->sign_root,sign.sign_root,8);
  411. memcpy(server->sign_last,sign.sign_last,16);
  412. server->sign_active = 1;
  413. }
  414. /* ignore when signatures not wanted */
  415. } else {
  416. server->sign_active = 0;
  417. }
  418. return 0;
  419. case NCP_IOC_SIGN_WANTED:
  420. if ((file_permission(filp, MAY_READ) != 0)
  421. && (current->uid != server->m.mounted_uid))
  422. {
  423. return -EACCES;
  424. }
  425. if (put_user(server->sign_wanted, (int __user *)argp))
  426. return -EFAULT;
  427. return 0;
  428. case NCP_IOC_SET_SIGN_WANTED:
  429. {
  430. int newstate;
  431. if ((file_permission(filp, MAY_WRITE) != 0)
  432. && (current->uid != server->m.mounted_uid))
  433. {
  434. return -EACCES;
  435. }
  436. /* get only low 8 bits... */
  437. if (get_user(newstate, (unsigned char __user *)argp))
  438. return -EFAULT;
  439. if (server->sign_active) {
  440. /* cannot turn signatures OFF when active */
  441. if (!newstate) return -EINVAL;
  442. } else {
  443. server->sign_wanted = newstate != 0;
  444. }
  445. return 0;
  446. }
  447. #endif /* CONFIG_NCPFS_PACKET_SIGNING */
  448. #ifdef CONFIG_NCPFS_IOCTL_LOCKING
  449. case NCP_IOC_LOCKUNLOCK:
  450. if ((file_permission(filp, MAY_WRITE) != 0)
  451. && (current->uid != server->m.mounted_uid))
  452. {
  453. return -EACCES;
  454. }
  455. {
  456. struct ncp_lock_ioctl rqdata;
  457. int result;
  458. if (copy_from_user(&rqdata, argp, sizeof(rqdata)))
  459. return -EFAULT;
  460. if (rqdata.origin != 0)
  461. return -EINVAL;
  462. /* check for cmd */
  463. switch (rqdata.cmd) {
  464. case NCP_LOCK_EX:
  465. case NCP_LOCK_SH:
  466. if (rqdata.timeout == 0)
  467. rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT;
  468. else if (rqdata.timeout > NCP_LOCK_MAX_TIMEOUT)
  469. rqdata.timeout = NCP_LOCK_MAX_TIMEOUT;
  470. break;
  471. case NCP_LOCK_LOG:
  472. rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */
  473. case NCP_LOCK_CLEAR:
  474. break;
  475. default:
  476. return -EINVAL;
  477. }
  478. /* locking needs both read and write access */
  479. if ((result = ncp_make_open(inode, O_RDWR)) != 0)
  480. {
  481. return result;
  482. }
  483. result = -EIO;
  484. if (!ncp_conn_valid(server))
  485. goto outrel;
  486. result = -EISDIR;
  487. if (!S_ISREG(inode->i_mode))
  488. goto outrel;
  489. if (rqdata.cmd == NCP_LOCK_CLEAR)
  490. {
  491. result = ncp_ClearPhysicalRecord(NCP_SERVER(inode),
  492. NCP_FINFO(inode)->file_handle,
  493. rqdata.offset,
  494. rqdata.length);
  495. if (result > 0) result = 0; /* no such lock */
  496. }
  497. else
  498. {
  499. int lockcmd;
  500. switch (rqdata.cmd)
  501. {
  502. case NCP_LOCK_EX: lockcmd=1; break;
  503. case NCP_LOCK_SH: lockcmd=3; break;
  504. default: lockcmd=0; break;
  505. }
  506. result = ncp_LogPhysicalRecord(NCP_SERVER(inode),
  507. NCP_FINFO(inode)->file_handle,
  508. lockcmd,
  509. rqdata.offset,
  510. rqdata.length,
  511. rqdata.timeout);
  512. if (result > 0) result = -EAGAIN;
  513. }
  514. outrel:
  515. ncp_inode_close(inode);
  516. return result;
  517. }
  518. #endif /* CONFIG_NCPFS_IOCTL_LOCKING */
  519. #ifdef CONFIG_COMPAT
  520. case NCP_IOC_GETOBJECTNAME_32:
  521. if (current->uid != server->m.mounted_uid) {
  522. return -EACCES;
  523. }
  524. {
  525. struct compat_ncp_objectname_ioctl user;
  526. size_t outl;
  527. if (copy_from_user(&user, argp, sizeof(user)))
  528. return -EFAULT;
  529. user.auth_type = server->auth.auth_type;
  530. outl = user.object_name_len;
  531. user.object_name_len = server->auth.object_name_len;
  532. if (outl > user.object_name_len)
  533. outl = user.object_name_len;
  534. if (outl) {
  535. if (copy_to_user(compat_ptr(user.object_name),
  536. server->auth.object_name,
  537. outl)) return -EFAULT;
  538. }
  539. if (copy_to_user(argp, &user, sizeof(user)))
  540. return -EFAULT;
  541. return 0;
  542. }
  543. #endif
  544. case NCP_IOC_GETOBJECTNAME:
  545. if (current->uid != server->m.mounted_uid) {
  546. return -EACCES;
  547. }
  548. {
  549. struct ncp_objectname_ioctl user;
  550. size_t outl;
  551. if (copy_from_user(&user, argp, sizeof(user)))
  552. return -EFAULT;
  553. user.auth_type = server->auth.auth_type;
  554. outl = user.object_name_len;
  555. user.object_name_len = server->auth.object_name_len;
  556. if (outl > user.object_name_len)
  557. outl = user.object_name_len;
  558. if (outl) {
  559. if (copy_to_user(user.object_name,
  560. server->auth.object_name,
  561. outl)) return -EFAULT;
  562. }
  563. if (copy_to_user(argp, &user, sizeof(user)))
  564. return -EFAULT;
  565. return 0;
  566. }
  567. #ifdef CONFIG_COMPAT
  568. case NCP_IOC_SETOBJECTNAME_32:
  569. #endif
  570. case NCP_IOC_SETOBJECTNAME:
  571. if (current->uid != server->m.mounted_uid) {
  572. return -EACCES;
  573. }
  574. {
  575. struct ncp_objectname_ioctl user;
  576. void* newname;
  577. void* oldname;
  578. size_t oldnamelen;
  579. void* oldprivate;
  580. size_t oldprivatelen;
  581. #ifdef CONFIG_COMPAT
  582. if (cmd == NCP_IOC_SETOBJECTNAME_32) {
  583. struct compat_ncp_objectname_ioctl user32;
  584. if (copy_from_user(&user32, argp, sizeof(user32)))
  585. return -EFAULT;
  586. user.auth_type = user32.auth_type;
  587. user.object_name_len = user32.object_name_len;
  588. user.object_name = compat_ptr(user32.object_name);
  589. } else
  590. #endif
  591. if (copy_from_user(&user, argp, sizeof(user)))
  592. return -EFAULT;
  593. if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN)
  594. return -ENOMEM;
  595. if (user.object_name_len) {
  596. newname = kmalloc(user.object_name_len, GFP_USER);
  597. if (!newname)
  598. return -ENOMEM;
  599. if (copy_from_user(newname, user.object_name, user.object_name_len)) {
  600. kfree(newname);
  601. return -EFAULT;
  602. }
  603. } else {
  604. newname = NULL;
  605. }
  606. /* enter critical section */
  607. /* maybe that kfree can sleep so do that this way */
  608. /* it is at least more SMP friendly (in future...) */
  609. oldname = server->auth.object_name;
  610. oldnamelen = server->auth.object_name_len;
  611. oldprivate = server->priv.data;
  612. oldprivatelen = server->priv.len;
  613. server->auth.auth_type = user.auth_type;
  614. server->auth.object_name_len = user.object_name_len;
  615. server->auth.object_name = newname;
  616. server->priv.len = 0;
  617. server->priv.data = NULL;
  618. /* leave critical section */
  619. kfree(oldprivate);
  620. kfree(oldname);
  621. return 0;
  622. }
  623. #ifdef CONFIG_COMPAT
  624. case NCP_IOC_GETPRIVATEDATA_32:
  625. #endif
  626. case NCP_IOC_GETPRIVATEDATA:
  627. if (current->uid != server->m.mounted_uid) {
  628. return -EACCES;
  629. }
  630. {
  631. struct ncp_privatedata_ioctl user;
  632. size_t outl;
  633. #ifdef CONFIG_COMPAT
  634. if (cmd == NCP_IOC_GETPRIVATEDATA_32) {
  635. struct compat_ncp_privatedata_ioctl user32;
  636. if (copy_from_user(&user32, argp, sizeof(user32)))
  637. return -EFAULT;
  638. user.len = user32.len;
  639. user.data = compat_ptr(user32.data);
  640. } else
  641. #endif
  642. if (copy_from_user(&user, argp, sizeof(user)))
  643. return -EFAULT;
  644. outl = user.len;
  645. user.len = server->priv.len;
  646. if (outl > user.len) outl = user.len;
  647. if (outl) {
  648. if (copy_to_user(user.data,
  649. server->priv.data,
  650. outl)) return -EFAULT;
  651. }
  652. #ifdef CONFIG_COMPAT
  653. if (cmd == NCP_IOC_GETPRIVATEDATA_32) {
  654. struct compat_ncp_privatedata_ioctl user32;
  655. user32.len = user.len;
  656. user32.data = (unsigned long) user.data;
  657. if (copy_to_user(argp, &user32, sizeof(user32)))
  658. return -EFAULT;
  659. } else
  660. #endif
  661. if (copy_to_user(argp, &user, sizeof(user)))
  662. return -EFAULT;
  663. return 0;
  664. }
  665. #ifdef CONFIG_COMPAT
  666. case NCP_IOC_SETPRIVATEDATA_32:
  667. #endif
  668. case NCP_IOC_SETPRIVATEDATA:
  669. if (current->uid != server->m.mounted_uid) {
  670. return -EACCES;
  671. }
  672. {
  673. struct ncp_privatedata_ioctl user;
  674. void* new;
  675. void* old;
  676. size_t oldlen;
  677. #ifdef CONFIG_COMPAT
  678. if (cmd == NCP_IOC_SETPRIVATEDATA_32) {
  679. struct compat_ncp_privatedata_ioctl user32;
  680. if (copy_from_user(&user32, argp, sizeof(user32)))
  681. return -EFAULT;
  682. user.len = user32.len;
  683. user.data = compat_ptr(user32.data);
  684. } else
  685. #endif
  686. if (copy_from_user(&user, argp, sizeof(user)))
  687. return -EFAULT;
  688. if (user.len > NCP_PRIVATE_DATA_MAX_LEN)
  689. return -ENOMEM;
  690. if (user.len) {
  691. new = kmalloc(user.len, GFP_USER);
  692. if (!new)
  693. return -ENOMEM;
  694. if (copy_from_user(new, user.data, user.len)) {
  695. kfree(new);
  696. return -EFAULT;
  697. }
  698. } else {
  699. new = NULL;
  700. }
  701. /* enter critical section */
  702. old = server->priv.data;
  703. oldlen = server->priv.len;
  704. server->priv.len = user.len;
  705. server->priv.data = new;
  706. /* leave critical section */
  707. kfree(old);
  708. return 0;
  709. }
  710. #ifdef CONFIG_NCPFS_NLS
  711. case NCP_IOC_SETCHARSETS:
  712. return ncp_set_charsets(server, argp);
  713. case NCP_IOC_GETCHARSETS:
  714. return ncp_get_charsets(server, argp);
  715. #endif /* CONFIG_NCPFS_NLS */
  716. case NCP_IOC_SETDENTRYTTL:
  717. if ((file_permission(filp, MAY_WRITE) != 0) &&
  718. (current->uid != server->m.mounted_uid))
  719. return -EACCES;
  720. {
  721. u_int32_t user;
  722. if (copy_from_user(&user, argp, sizeof(user)))
  723. return -EFAULT;
  724. /* 20 secs at most... */
  725. if (user > 20000)
  726. return -EINVAL;
  727. user = (user * HZ) / 1000;
  728. server->dentry_ttl = user;
  729. return 0;
  730. }
  731. case NCP_IOC_GETDENTRYTTL:
  732. {
  733. u_int32_t user = (server->dentry_ttl * 1000) / HZ;
  734. if (copy_to_user(argp, &user, sizeof(user)))
  735. return -EFAULT;
  736. return 0;
  737. }
  738. }
  739. return -EINVAL;
  740. }
  741. #ifdef CONFIG_COMPAT
  742. long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  743. {
  744. struct inode *inode = file->f_path.dentry->d_inode;
  745. int ret;
  746. lock_kernel();
  747. arg = (unsigned long) compat_ptr(arg);
  748. ret = ncp_ioctl(inode, file, cmd, arg);
  749. unlock_kernel();
  750. return ret;
  751. }
  752. #endif