cifs_debug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. "\nPathComponentMax: %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 (tcon->need_reconnect)
  211. seq_puts(m, "\tDISCONNECTED ");
  212. seq_putc(m, '\n');
  213. }
  214. seq_puts(m, "\n\tMIDs:\n");
  215. spin_lock(&GlobalMid_Lock);
  216. list_for_each(tmp3, &server->pending_mid_q) {
  217. mid_entry = list_entry(tmp3, struct mid_q_entry,
  218. qhead);
  219. seq_printf(m, "\tState: %d com: %d pid:"
  220. " %d cbdata: %p mid %llu\n",
  221. mid_entry->mid_state,
  222. le16_to_cpu(mid_entry->command),
  223. mid_entry->pid,
  224. mid_entry->callback_data,
  225. mid_entry->mid);
  226. }
  227. spin_unlock(&GlobalMid_Lock);
  228. }
  229. }
  230. spin_unlock(&cifs_tcp_ses_lock);
  231. seq_putc(m, '\n');
  232. /* BB add code to dump additional info such as TCP session info now */
  233. return 0;
  234. }
  235. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  236. {
  237. return single_open(file, cifs_debug_data_proc_show, NULL);
  238. }
  239. static const struct file_operations cifs_debug_data_proc_fops = {
  240. .owner = THIS_MODULE,
  241. .open = cifs_debug_data_proc_open,
  242. .read = seq_read,
  243. .llseek = seq_lseek,
  244. .release = single_release,
  245. };
  246. #ifdef CONFIG_CIFS_STATS
  247. static ssize_t cifs_stats_proc_write(struct file *file,
  248. const char __user *buffer, size_t count, loff_t *ppos)
  249. {
  250. char c;
  251. int rc;
  252. struct list_head *tmp1, *tmp2, *tmp3;
  253. struct TCP_Server_Info *server;
  254. struct cifs_ses *ses;
  255. struct cifs_tcon *tcon;
  256. rc = get_user(c, buffer);
  257. if (rc)
  258. return rc;
  259. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  260. #ifdef CONFIG_CIFS_STATS2
  261. atomic_set(&totBufAllocCount, 0);
  262. atomic_set(&totSmBufAllocCount, 0);
  263. #endif /* CONFIG_CIFS_STATS2 */
  264. spin_lock(&cifs_tcp_ses_lock);
  265. list_for_each(tmp1, &cifs_tcp_ses_list) {
  266. server = list_entry(tmp1, struct TCP_Server_Info,
  267. tcp_ses_list);
  268. list_for_each(tmp2, &server->smb_ses_list) {
  269. ses = list_entry(tmp2, struct cifs_ses,
  270. smb_ses_list);
  271. list_for_each(tmp3, &ses->tcon_list) {
  272. tcon = list_entry(tmp3,
  273. struct cifs_tcon,
  274. tcon_list);
  275. atomic_set(&tcon->num_smbs_sent, 0);
  276. if (server->ops->clear_stats)
  277. server->ops->clear_stats(tcon);
  278. }
  279. }
  280. }
  281. spin_unlock(&cifs_tcp_ses_lock);
  282. }
  283. return count;
  284. }
  285. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  286. {
  287. int i;
  288. struct list_head *tmp1, *tmp2, *tmp3;
  289. struct TCP_Server_Info *server;
  290. struct cifs_ses *ses;
  291. struct cifs_tcon *tcon;
  292. seq_printf(m,
  293. "Resources in use\nCIFS Session: %d\n",
  294. sesInfoAllocCount.counter);
  295. seq_printf(m, "Share (unique mount targets): %d\n",
  296. tconInfoAllocCount.counter);
  297. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  298. bufAllocCount.counter,
  299. cifs_min_rcv + tcpSesAllocCount.counter);
  300. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  301. smBufAllocCount.counter, cifs_min_small);
  302. #ifdef CONFIG_CIFS_STATS2
  303. seq_printf(m, "Total Large %d Small %d Allocations\n",
  304. atomic_read(&totBufAllocCount),
  305. atomic_read(&totSmBufAllocCount));
  306. #endif /* CONFIG_CIFS_STATS2 */
  307. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  308. seq_printf(m,
  309. "\n%d session %d share reconnects\n",
  310. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  311. seq_printf(m,
  312. "Total vfs operations: %d maximum at one time: %d\n",
  313. GlobalCurrentXid, GlobalMaxActiveXid);
  314. i = 0;
  315. spin_lock(&cifs_tcp_ses_lock);
  316. list_for_each(tmp1, &cifs_tcp_ses_list) {
  317. server = list_entry(tmp1, struct TCP_Server_Info,
  318. tcp_ses_list);
  319. list_for_each(tmp2, &server->smb_ses_list) {
  320. ses = list_entry(tmp2, struct cifs_ses,
  321. smb_ses_list);
  322. list_for_each(tmp3, &ses->tcon_list) {
  323. tcon = list_entry(tmp3,
  324. struct cifs_tcon,
  325. tcon_list);
  326. i++;
  327. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  328. if (tcon->need_reconnect)
  329. seq_puts(m, "\tDISCONNECTED ");
  330. seq_printf(m, "\nSMBs: %d",
  331. atomic_read(&tcon->num_smbs_sent));
  332. if (server->ops->print_stats)
  333. server->ops->print_stats(m, tcon);
  334. }
  335. }
  336. }
  337. spin_unlock(&cifs_tcp_ses_lock);
  338. seq_putc(m, '\n');
  339. return 0;
  340. }
  341. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  342. {
  343. return single_open(file, cifs_stats_proc_show, NULL);
  344. }
  345. static const struct file_operations cifs_stats_proc_fops = {
  346. .owner = THIS_MODULE,
  347. .open = cifs_stats_proc_open,
  348. .read = seq_read,
  349. .llseek = seq_lseek,
  350. .release = single_release,
  351. .write = cifs_stats_proc_write,
  352. };
  353. #endif /* STATS */
  354. static struct proc_dir_entry *proc_fs_cifs;
  355. static const struct file_operations cifsFYI_proc_fops;
  356. static const struct file_operations cifs_lookup_cache_proc_fops;
  357. static const struct file_operations traceSMB_proc_fops;
  358. static const struct file_operations cifs_security_flags_proc_fops;
  359. static const struct file_operations cifs_linux_ext_proc_fops;
  360. void
  361. cifs_proc_init(void)
  362. {
  363. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  364. if (proc_fs_cifs == NULL)
  365. return;
  366. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  367. #ifdef CONFIG_CIFS_STATS
  368. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  369. #endif /* STATS */
  370. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  371. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  372. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  373. &cifs_linux_ext_proc_fops);
  374. proc_create("SecurityFlags", 0, proc_fs_cifs,
  375. &cifs_security_flags_proc_fops);
  376. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  377. &cifs_lookup_cache_proc_fops);
  378. }
  379. void
  380. cifs_proc_clean(void)
  381. {
  382. if (proc_fs_cifs == NULL)
  383. return;
  384. remove_proc_entry("DebugData", proc_fs_cifs);
  385. remove_proc_entry("cifsFYI", proc_fs_cifs);
  386. remove_proc_entry("traceSMB", proc_fs_cifs);
  387. #ifdef CONFIG_CIFS_STATS
  388. remove_proc_entry("Stats", proc_fs_cifs);
  389. #endif
  390. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  391. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  392. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  393. remove_proc_entry("fs/cifs", NULL);
  394. }
  395. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  396. {
  397. seq_printf(m, "%d\n", cifsFYI);
  398. return 0;
  399. }
  400. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  401. {
  402. return single_open(file, cifsFYI_proc_show, NULL);
  403. }
  404. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  405. size_t count, loff_t *ppos)
  406. {
  407. char c;
  408. int rc;
  409. rc = get_user(c, buffer);
  410. if (rc)
  411. return rc;
  412. if (c == '0' || c == 'n' || c == 'N')
  413. cifsFYI = 0;
  414. else if (c == '1' || c == 'y' || c == 'Y')
  415. cifsFYI = 1;
  416. else if ((c > '1') && (c <= '9'))
  417. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  418. return count;
  419. }
  420. static const struct file_operations cifsFYI_proc_fops = {
  421. .owner = THIS_MODULE,
  422. .open = cifsFYI_proc_open,
  423. .read = seq_read,
  424. .llseek = seq_lseek,
  425. .release = single_release,
  426. .write = cifsFYI_proc_write,
  427. };
  428. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  429. {
  430. seq_printf(m, "%d\n", linuxExtEnabled);
  431. return 0;
  432. }
  433. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  434. {
  435. return single_open(file, cifs_linux_ext_proc_show, NULL);
  436. }
  437. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  438. const char __user *buffer, size_t count, loff_t *ppos)
  439. {
  440. char c;
  441. int rc;
  442. rc = get_user(c, buffer);
  443. if (rc)
  444. return rc;
  445. if (c == '0' || c == 'n' || c == 'N')
  446. linuxExtEnabled = 0;
  447. else if (c == '1' || c == 'y' || c == 'Y')
  448. linuxExtEnabled = 1;
  449. return count;
  450. }
  451. static const struct file_operations cifs_linux_ext_proc_fops = {
  452. .owner = THIS_MODULE,
  453. .open = cifs_linux_ext_proc_open,
  454. .read = seq_read,
  455. .llseek = seq_lseek,
  456. .release = single_release,
  457. .write = cifs_linux_ext_proc_write,
  458. };
  459. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  460. {
  461. seq_printf(m, "%d\n", lookupCacheEnabled);
  462. return 0;
  463. }
  464. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  465. {
  466. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  467. }
  468. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  469. const char __user *buffer, size_t count, loff_t *ppos)
  470. {
  471. char c;
  472. int rc;
  473. rc = get_user(c, buffer);
  474. if (rc)
  475. return rc;
  476. if (c == '0' || c == 'n' || c == 'N')
  477. lookupCacheEnabled = 0;
  478. else if (c == '1' || c == 'y' || c == 'Y')
  479. lookupCacheEnabled = 1;
  480. return count;
  481. }
  482. static const struct file_operations cifs_lookup_cache_proc_fops = {
  483. .owner = THIS_MODULE,
  484. .open = cifs_lookup_cache_proc_open,
  485. .read = seq_read,
  486. .llseek = seq_lseek,
  487. .release = single_release,
  488. .write = cifs_lookup_cache_proc_write,
  489. };
  490. static int traceSMB_proc_show(struct seq_file *m, void *v)
  491. {
  492. seq_printf(m, "%d\n", traceSMB);
  493. return 0;
  494. }
  495. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  496. {
  497. return single_open(file, traceSMB_proc_show, NULL);
  498. }
  499. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  500. size_t count, loff_t *ppos)
  501. {
  502. char c;
  503. int rc;
  504. rc = get_user(c, buffer);
  505. if (rc)
  506. return rc;
  507. if (c == '0' || c == 'n' || c == 'N')
  508. traceSMB = 0;
  509. else if (c == '1' || c == 'y' || c == 'Y')
  510. traceSMB = 1;
  511. return count;
  512. }
  513. static const struct file_operations traceSMB_proc_fops = {
  514. .owner = THIS_MODULE,
  515. .open = traceSMB_proc_open,
  516. .read = seq_read,
  517. .llseek = seq_lseek,
  518. .release = single_release,
  519. .write = traceSMB_proc_write,
  520. };
  521. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  522. {
  523. seq_printf(m, "0x%x\n", global_secflags);
  524. return 0;
  525. }
  526. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  527. {
  528. return single_open(file, cifs_security_flags_proc_show, NULL);
  529. }
  530. static ssize_t cifs_security_flags_proc_write(struct file *file,
  531. const char __user *buffer, size_t count, loff_t *ppos)
  532. {
  533. unsigned int flags;
  534. char flags_string[12];
  535. char c;
  536. if ((count < 1) || (count > 11))
  537. return -EINVAL;
  538. memset(flags_string, 0, 12);
  539. if (copy_from_user(flags_string, buffer, count))
  540. return -EFAULT;
  541. if (count < 3) {
  542. /* single char or single char followed by null */
  543. c = flags_string[0];
  544. if (c == '0' || c == 'n' || c == 'N') {
  545. global_secflags = CIFSSEC_DEF; /* default */
  546. return count;
  547. } else if (c == '1' || c == 'y' || c == 'Y') {
  548. global_secflags = CIFSSEC_MAX;
  549. return count;
  550. } else if (!isdigit(c)) {
  551. cifs_dbg(VFS, "invalid flag %c\n", c);
  552. return -EINVAL;
  553. }
  554. }
  555. /* else we have a number */
  556. flags = simple_strtoul(flags_string, NULL, 0);
  557. cifs_dbg(FYI, "sec flags 0x%x\n", flags);
  558. if (flags <= 0) {
  559. cifs_dbg(VFS, "invalid security flags %s\n", flags_string);
  560. return -EINVAL;
  561. }
  562. if (flags & ~CIFSSEC_MASK) {
  563. cifs_dbg(VFS, "attempt to set unsupported security flags 0x%x\n",
  564. flags & ~CIFSSEC_MASK);
  565. return -EINVAL;
  566. }
  567. /* flags look ok - update the global security flags for cifs module */
  568. global_secflags = flags;
  569. if (global_secflags & CIFSSEC_MUST_SIGN) {
  570. /* requiring signing implies signing is allowed */
  571. global_secflags |= CIFSSEC_MAY_SIGN;
  572. cifs_dbg(FYI, "packet signing now required\n");
  573. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  574. cifs_dbg(FYI, "packet signing disabled\n");
  575. }
  576. /* BB should we turn on MAY flags for other MUST options? */
  577. return count;
  578. }
  579. static const struct file_operations cifs_security_flags_proc_fops = {
  580. .owner = THIS_MODULE,
  581. .open = cifs_security_flags_proc_open,
  582. .read = seq_read,
  583. .llseek = seq_lseek,
  584. .release = single_release,
  585. .write = cifs_security_flags_proc_write,
  586. };
  587. #else
  588. inline void cifs_proc_init(void)
  589. {
  590. }
  591. inline void cifs_proc_clean(void)
  592. {
  593. }
  594. #endif /* PROC_FS */