cifs_debug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * fs/cifs_debug.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2000,2005
  5. *
  6. * Modified by Steve French (sfrench@us.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  16. * the GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/fs.h>
  23. #include <linux/string.h>
  24. #include <linux/ctype.h>
  25. #include <linux/module.h>
  26. #include <linux/proc_fs.h>
  27. #include <asm/uaccess.h>
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifsfs.h"
  33. void
  34. cifs_dump_mem(char *label, void *data, int length)
  35. {
  36. int i, j;
  37. int *intptr = data;
  38. char *charptr = data;
  39. char buf[10], line[80];
  40. printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
  41. label, length, data);
  42. for (i = 0; i < length; i += 16) {
  43. line[0] = 0;
  44. for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
  45. sprintf(buf, " %08x", intptr[i / 4 + j]);
  46. strcat(line, buf);
  47. }
  48. buf[0] = ' ';
  49. buf[2] = 0;
  50. for (j = 0; (j < 16) && (i + j < length); j++) {
  51. buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
  52. strcat(line, buf);
  53. }
  54. printk(KERN_DEBUG "%s\n", line);
  55. }
  56. }
  57. #ifdef CONFIG_CIFS_DEBUG
  58. void cifs_vfs_err(const char *fmt, ...)
  59. {
  60. struct va_format vaf;
  61. va_list args;
  62. va_start(args, fmt);
  63. vaf.fmt = fmt;
  64. vaf.va = &args;
  65. printk(KERN_ERR "CIFS VFS: %pV", &vaf);
  66. va_end(args);
  67. }
  68. #endif
  69. void cifs_dump_detail(void *buf)
  70. {
  71. #ifdef CONFIG_CIFS_DEBUG2
  72. struct smb_hdr *smb = (struct smb_hdr *)buf;
  73. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
  74. smb->Command, smb->Status.CifsError,
  75. smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  76. cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
  77. #endif /* CONFIG_CIFS_DEBUG2 */
  78. }
  79. void cifs_dump_mids(struct TCP_Server_Info *server)
  80. {
  81. #ifdef CONFIG_CIFS_DEBUG2
  82. struct list_head *tmp;
  83. struct mid_q_entry *mid_entry;
  84. if (server == NULL)
  85. return;
  86. cifs_dbg(VFS, "Dump pending requests:\n");
  87. spin_lock(&GlobalMid_Lock);
  88. list_for_each(tmp, &server->pending_mid_q) {
  89. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  90. cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
  91. mid_entry->mid_state,
  92. le16_to_cpu(mid_entry->command),
  93. mid_entry->pid,
  94. mid_entry->callback_data,
  95. mid_entry->mid);
  96. #ifdef CONFIG_CIFS_STATS2
  97. cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
  98. mid_entry->large_buf,
  99. mid_entry->resp_buf,
  100. mid_entry->when_received,
  101. jiffies);
  102. #endif /* STATS2 */
  103. cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
  104. mid_entry->multiRsp, mid_entry->multiEnd);
  105. if (mid_entry->resp_buf) {
  106. cifs_dump_detail(mid_entry->resp_buf);
  107. cifs_dump_mem("existing buf: ",
  108. mid_entry->resp_buf, 62);
  109. }
  110. }
  111. spin_unlock(&GlobalMid_Lock);
  112. #endif /* CONFIG_CIFS_DEBUG2 */
  113. }
  114. #ifdef CONFIG_PROC_FS
  115. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  116. {
  117. struct list_head *tmp1, *tmp2, *tmp3;
  118. struct mid_q_entry *mid_entry;
  119. struct TCP_Server_Info *server;
  120. struct cifs_ses *ses;
  121. struct cifs_tcon *tcon;
  122. int i, j;
  123. __u32 dev_type;
  124. seq_puts(m,
  125. "Display Internal CIFS Data Structures for Debugging\n"
  126. "---------------------------------------------------\n");
  127. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  128. seq_printf(m, "Features:");
  129. #ifdef CONFIG_CIFS_DFS_UPCALL
  130. seq_printf(m, " dfs");
  131. #endif
  132. #ifdef CONFIG_CIFS_FSCACHE
  133. seq_printf(m, " fscache");
  134. #endif
  135. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  136. seq_printf(m, " lanman");
  137. #endif
  138. #ifdef CONFIG_CIFS_POSIX
  139. seq_printf(m, " posix");
  140. #endif
  141. #ifdef CONFIG_CIFS_UPCALL
  142. seq_printf(m, " spnego");
  143. #endif
  144. #ifdef CONFIG_CIFS_XATTR
  145. seq_printf(m, " xattr");
  146. #endif
  147. #ifdef CONFIG_CIFS_ACL
  148. seq_printf(m, " acl");
  149. #endif
  150. seq_putc(m, '\n');
  151. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  152. seq_printf(m, "Servers:");
  153. i = 0;
  154. spin_lock(&cifs_tcp_ses_lock);
  155. list_for_each(tmp1, &cifs_tcp_ses_list) {
  156. server = list_entry(tmp1, struct TCP_Server_Info,
  157. tcp_ses_list);
  158. i++;
  159. list_for_each(tmp2, &server->smb_ses_list) {
  160. ses = list_entry(tmp2, struct cifs_ses,
  161. smb_ses_list);
  162. if ((ses->serverDomain == NULL) ||
  163. (ses->serverOS == NULL) ||
  164. (ses->serverNOS == NULL)) {
  165. seq_printf(m, "\n%d) entry for %s not fully "
  166. "displayed\n\t", i, ses->serverName);
  167. } else {
  168. seq_printf(m,
  169. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  170. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  171. " session status: %d\t",
  172. i, ses->serverName, ses->serverDomain,
  173. ses->ses_count, ses->serverOS, ses->serverNOS,
  174. ses->capabilities, ses->status);
  175. }
  176. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  177. "Server: %d SecMode: 0x%x Req On Wire: %d",
  178. server->tcpStatus, server->srv_count,
  179. server->sec_mode, in_flight(server));
  180. #ifdef CONFIG_CIFS_STATS2
  181. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  182. atomic_read(&server->in_send),
  183. atomic_read(&server->num_waiters));
  184. #endif
  185. seq_puts(m, "\n\tShares:");
  186. j = 0;
  187. list_for_each(tmp3, &ses->tcon_list) {
  188. tcon = list_entry(tmp3, struct cifs_tcon,
  189. tcon_list);
  190. ++j;
  191. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  192. seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
  193. tcon->treeName, tcon->tc_count);
  194. if (tcon->nativeFileSystem) {
  195. seq_printf(m, "Type: %s ",
  196. tcon->nativeFileSystem);
  197. }
  198. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  199. "\n\tPathComponentMax: %d Status: 0x%d",
  200. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  201. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  202. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  203. tcon->tidStatus);
  204. if (dev_type == FILE_DEVICE_DISK)
  205. seq_puts(m, " type: DISK ");
  206. else if (dev_type == FILE_DEVICE_CD_ROM)
  207. seq_puts(m, " type: CDROM ");
  208. else
  209. seq_printf(m, " type: %d ", dev_type);
  210. if (server->ops->dump_share_caps)
  211. server->ops->dump_share_caps(m, tcon);
  212. if (tcon->need_reconnect)
  213. seq_puts(m, "\tDISCONNECTED ");
  214. seq_putc(m, '\n');
  215. }
  216. seq_puts(m, "\n\tMIDs:\n");
  217. spin_lock(&GlobalMid_Lock);
  218. list_for_each(tmp3, &server->pending_mid_q) {
  219. mid_entry = list_entry(tmp3, struct mid_q_entry,
  220. qhead);
  221. seq_printf(m, "\tState: %d com: %d pid:"
  222. " %d cbdata: %p mid %llu\n",
  223. mid_entry->mid_state,
  224. le16_to_cpu(mid_entry->command),
  225. mid_entry->pid,
  226. mid_entry->callback_data,
  227. mid_entry->mid);
  228. }
  229. spin_unlock(&GlobalMid_Lock);
  230. }
  231. }
  232. spin_unlock(&cifs_tcp_ses_lock);
  233. seq_putc(m, '\n');
  234. /* BB add code to dump additional info such as TCP session info now */
  235. return 0;
  236. }
  237. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  238. {
  239. return single_open(file, cifs_debug_data_proc_show, NULL);
  240. }
  241. static const struct file_operations cifs_debug_data_proc_fops = {
  242. .owner = THIS_MODULE,
  243. .open = cifs_debug_data_proc_open,
  244. .read = seq_read,
  245. .llseek = seq_lseek,
  246. .release = single_release,
  247. };
  248. #ifdef CONFIG_CIFS_STATS
  249. static ssize_t cifs_stats_proc_write(struct file *file,
  250. const char __user *buffer, size_t count, loff_t *ppos)
  251. {
  252. char c;
  253. int rc;
  254. struct list_head *tmp1, *tmp2, *tmp3;
  255. struct TCP_Server_Info *server;
  256. struct cifs_ses *ses;
  257. struct cifs_tcon *tcon;
  258. rc = get_user(c, buffer);
  259. if (rc)
  260. return rc;
  261. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  262. #ifdef CONFIG_CIFS_STATS2
  263. atomic_set(&totBufAllocCount, 0);
  264. atomic_set(&totSmBufAllocCount, 0);
  265. #endif /* CONFIG_CIFS_STATS2 */
  266. spin_lock(&cifs_tcp_ses_lock);
  267. list_for_each(tmp1, &cifs_tcp_ses_list) {
  268. server = list_entry(tmp1, struct TCP_Server_Info,
  269. tcp_ses_list);
  270. list_for_each(tmp2, &server->smb_ses_list) {
  271. ses = list_entry(tmp2, struct cifs_ses,
  272. smb_ses_list);
  273. list_for_each(tmp3, &ses->tcon_list) {
  274. tcon = list_entry(tmp3,
  275. struct cifs_tcon,
  276. tcon_list);
  277. atomic_set(&tcon->num_smbs_sent, 0);
  278. if (server->ops->clear_stats)
  279. server->ops->clear_stats(tcon);
  280. }
  281. }
  282. }
  283. spin_unlock(&cifs_tcp_ses_lock);
  284. }
  285. return count;
  286. }
  287. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  288. {
  289. int i;
  290. struct list_head *tmp1, *tmp2, *tmp3;
  291. struct TCP_Server_Info *server;
  292. struct cifs_ses *ses;
  293. struct cifs_tcon *tcon;
  294. seq_printf(m,
  295. "Resources in use\nCIFS Session: %d\n",
  296. sesInfoAllocCount.counter);
  297. seq_printf(m, "Share (unique mount targets): %d\n",
  298. tconInfoAllocCount.counter);
  299. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  300. bufAllocCount.counter,
  301. cifs_min_rcv + tcpSesAllocCount.counter);
  302. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  303. smBufAllocCount.counter, cifs_min_small);
  304. #ifdef CONFIG_CIFS_STATS2
  305. seq_printf(m, "Total Large %d Small %d Allocations\n",
  306. atomic_read(&totBufAllocCount),
  307. atomic_read(&totSmBufAllocCount));
  308. #endif /* CONFIG_CIFS_STATS2 */
  309. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  310. seq_printf(m,
  311. "\n%d session %d share reconnects\n",
  312. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  313. seq_printf(m,
  314. "Total vfs operations: %d maximum at one time: %d\n",
  315. GlobalCurrentXid, GlobalMaxActiveXid);
  316. i = 0;
  317. spin_lock(&cifs_tcp_ses_lock);
  318. list_for_each(tmp1, &cifs_tcp_ses_list) {
  319. server = list_entry(tmp1, struct TCP_Server_Info,
  320. tcp_ses_list);
  321. list_for_each(tmp2, &server->smb_ses_list) {
  322. ses = list_entry(tmp2, struct cifs_ses,
  323. smb_ses_list);
  324. list_for_each(tmp3, &ses->tcon_list) {
  325. tcon = list_entry(tmp3,
  326. struct cifs_tcon,
  327. tcon_list);
  328. i++;
  329. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  330. if (tcon->need_reconnect)
  331. seq_puts(m, "\tDISCONNECTED ");
  332. seq_printf(m, "\nSMBs: %d",
  333. atomic_read(&tcon->num_smbs_sent));
  334. if (server->ops->print_stats)
  335. server->ops->print_stats(m, tcon);
  336. }
  337. }
  338. }
  339. spin_unlock(&cifs_tcp_ses_lock);
  340. seq_putc(m, '\n');
  341. return 0;
  342. }
  343. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  344. {
  345. return single_open(file, cifs_stats_proc_show, NULL);
  346. }
  347. static const struct file_operations cifs_stats_proc_fops = {
  348. .owner = THIS_MODULE,
  349. .open = cifs_stats_proc_open,
  350. .read = seq_read,
  351. .llseek = seq_lseek,
  352. .release = single_release,
  353. .write = cifs_stats_proc_write,
  354. };
  355. #endif /* STATS */
  356. static struct proc_dir_entry *proc_fs_cifs;
  357. static const struct file_operations cifsFYI_proc_fops;
  358. static const struct file_operations cifs_lookup_cache_proc_fops;
  359. static const struct file_operations traceSMB_proc_fops;
  360. static const struct file_operations cifs_security_flags_proc_fops;
  361. static const struct file_operations cifs_linux_ext_proc_fops;
  362. void
  363. cifs_proc_init(void)
  364. {
  365. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  366. if (proc_fs_cifs == NULL)
  367. return;
  368. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  369. #ifdef CONFIG_CIFS_STATS
  370. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  371. #endif /* STATS */
  372. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  373. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  374. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  375. &cifs_linux_ext_proc_fops);
  376. proc_create("SecurityFlags", 0, proc_fs_cifs,
  377. &cifs_security_flags_proc_fops);
  378. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  379. &cifs_lookup_cache_proc_fops);
  380. }
  381. void
  382. cifs_proc_clean(void)
  383. {
  384. if (proc_fs_cifs == NULL)
  385. return;
  386. remove_proc_entry("DebugData", proc_fs_cifs);
  387. remove_proc_entry("cifsFYI", proc_fs_cifs);
  388. remove_proc_entry("traceSMB", proc_fs_cifs);
  389. #ifdef CONFIG_CIFS_STATS
  390. remove_proc_entry("Stats", proc_fs_cifs);
  391. #endif
  392. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  393. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  394. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  395. remove_proc_entry("fs/cifs", NULL);
  396. }
  397. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  398. {
  399. seq_printf(m, "%d\n", cifsFYI);
  400. return 0;
  401. }
  402. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  403. {
  404. return single_open(file, cifsFYI_proc_show, NULL);
  405. }
  406. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  407. size_t count, loff_t *ppos)
  408. {
  409. char c;
  410. int rc;
  411. rc = get_user(c, buffer);
  412. if (rc)
  413. return rc;
  414. if (c == '0' || c == 'n' || c == 'N')
  415. cifsFYI = 0;
  416. else if (c == '1' || c == 'y' || c == 'Y')
  417. cifsFYI = 1;
  418. else if ((c > '1') && (c <= '9'))
  419. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  420. return count;
  421. }
  422. static const struct file_operations cifsFYI_proc_fops = {
  423. .owner = THIS_MODULE,
  424. .open = cifsFYI_proc_open,
  425. .read = seq_read,
  426. .llseek = seq_lseek,
  427. .release = single_release,
  428. .write = cifsFYI_proc_write,
  429. };
  430. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  431. {
  432. seq_printf(m, "%d\n", linuxExtEnabled);
  433. return 0;
  434. }
  435. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  436. {
  437. return single_open(file, cifs_linux_ext_proc_show, NULL);
  438. }
  439. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  440. const char __user *buffer, size_t count, loff_t *ppos)
  441. {
  442. char c;
  443. int rc;
  444. rc = get_user(c, buffer);
  445. if (rc)
  446. return rc;
  447. if (c == '0' || c == 'n' || c == 'N')
  448. linuxExtEnabled = 0;
  449. else if (c == '1' || c == 'y' || c == 'Y')
  450. linuxExtEnabled = 1;
  451. return count;
  452. }
  453. static const struct file_operations cifs_linux_ext_proc_fops = {
  454. .owner = THIS_MODULE,
  455. .open = cifs_linux_ext_proc_open,
  456. .read = seq_read,
  457. .llseek = seq_lseek,
  458. .release = single_release,
  459. .write = cifs_linux_ext_proc_write,
  460. };
  461. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  462. {
  463. seq_printf(m, "%d\n", lookupCacheEnabled);
  464. return 0;
  465. }
  466. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  467. {
  468. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  469. }
  470. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  471. const char __user *buffer, size_t count, loff_t *ppos)
  472. {
  473. char c;
  474. int rc;
  475. rc = get_user(c, buffer);
  476. if (rc)
  477. return rc;
  478. if (c == '0' || c == 'n' || c == 'N')
  479. lookupCacheEnabled = 0;
  480. else if (c == '1' || c == 'y' || c == 'Y')
  481. lookupCacheEnabled = 1;
  482. return count;
  483. }
  484. static const struct file_operations cifs_lookup_cache_proc_fops = {
  485. .owner = THIS_MODULE,
  486. .open = cifs_lookup_cache_proc_open,
  487. .read = seq_read,
  488. .llseek = seq_lseek,
  489. .release = single_release,
  490. .write = cifs_lookup_cache_proc_write,
  491. };
  492. static int traceSMB_proc_show(struct seq_file *m, void *v)
  493. {
  494. seq_printf(m, "%d\n", traceSMB);
  495. return 0;
  496. }
  497. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  498. {
  499. return single_open(file, traceSMB_proc_show, NULL);
  500. }
  501. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  502. size_t count, loff_t *ppos)
  503. {
  504. char c;
  505. int rc;
  506. rc = get_user(c, buffer);
  507. if (rc)
  508. return rc;
  509. if (c == '0' || c == 'n' || c == 'N')
  510. traceSMB = 0;
  511. else if (c == '1' || c == 'y' || c == 'Y')
  512. traceSMB = 1;
  513. return count;
  514. }
  515. static const struct file_operations traceSMB_proc_fops = {
  516. .owner = THIS_MODULE,
  517. .open = traceSMB_proc_open,
  518. .read = seq_read,
  519. .llseek = seq_lseek,
  520. .release = single_release,
  521. .write = traceSMB_proc_write,
  522. };
  523. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  524. {
  525. seq_printf(m, "0x%x\n", global_secflags);
  526. return 0;
  527. }
  528. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  529. {
  530. return single_open(file, cifs_security_flags_proc_show, NULL);
  531. }
  532. /*
  533. * Ensure that if someone sets a MUST flag, that we disable all other MAY
  534. * flags except for the ones corresponding to the given MUST flag. If there are
  535. * multiple MUST flags, then try to prefer more secure ones.
  536. */
  537. static void
  538. cifs_security_flags_handle_must_flags(unsigned int *flags)
  539. {
  540. unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
  541. if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
  542. *flags = CIFSSEC_MUST_KRB5;
  543. else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
  544. *flags = CIFSSEC_MUST_NTLMSSP;
  545. else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
  546. *flags = CIFSSEC_MUST_NTLMV2;
  547. else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
  548. *flags = CIFSSEC_MUST_NTLM;
  549. else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
  550. *flags = CIFSSEC_MUST_LANMAN;
  551. else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
  552. *flags = CIFSSEC_MUST_PLNTXT;
  553. *flags |= signflags;
  554. }
  555. static ssize_t cifs_security_flags_proc_write(struct file *file,
  556. const char __user *buffer, size_t count, loff_t *ppos)
  557. {
  558. int rc;
  559. unsigned int flags;
  560. char flags_string[12];
  561. char c;
  562. if ((count < 1) || (count > 11))
  563. return -EINVAL;
  564. memset(flags_string, 0, 12);
  565. if (copy_from_user(flags_string, buffer, count))
  566. return -EFAULT;
  567. if (count < 3) {
  568. /* single char or single char followed by null */
  569. c = flags_string[0];
  570. if (c == '0' || c == 'n' || c == 'N') {
  571. global_secflags = CIFSSEC_DEF; /* default */
  572. return count;
  573. } else if (c == '1' || c == 'y' || c == 'Y') {
  574. global_secflags = CIFSSEC_MAX;
  575. return count;
  576. } else if (!isdigit(c)) {
  577. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  578. flags_string);
  579. return -EINVAL;
  580. }
  581. }
  582. /* else we have a number */
  583. rc = kstrtouint(flags_string, 0, &flags);
  584. if (rc) {
  585. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  586. flags_string);
  587. return rc;
  588. }
  589. cifs_dbg(FYI, "sec flags 0x%x\n", flags);
  590. if (flags == 0) {
  591. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
  592. return -EINVAL;
  593. }
  594. if (flags & ~CIFSSEC_MASK) {
  595. cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
  596. flags & ~CIFSSEC_MASK);
  597. return -EINVAL;
  598. }
  599. cifs_security_flags_handle_must_flags(&flags);
  600. /* flags look ok - update the global security flags for cifs module */
  601. global_secflags = flags;
  602. if (global_secflags & CIFSSEC_MUST_SIGN) {
  603. /* requiring signing implies signing is allowed */
  604. global_secflags |= CIFSSEC_MAY_SIGN;
  605. cifs_dbg(FYI, "packet signing now required\n");
  606. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  607. cifs_dbg(FYI, "packet signing disabled\n");
  608. }
  609. /* BB should we turn on MAY flags for other MUST options? */
  610. return count;
  611. }
  612. static const struct file_operations cifs_security_flags_proc_fops = {
  613. .owner = THIS_MODULE,
  614. .open = cifs_security_flags_proc_open,
  615. .read = seq_read,
  616. .llseek = seq_lseek,
  617. .release = single_release,
  618. .write = cifs_security_flags_proc_write,
  619. };
  620. #else
  621. inline void cifs_proc_init(void)
  622. {
  623. }
  624. inline void cifs_proc_clean(void)
  625. {
  626. }
  627. #endif /* PROC_FS */