ioctl.c 21 KB

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