cifs_debug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. void cifs_dump_detail(void *buf)
  58. {
  59. #ifdef CONFIG_CIFS_DEBUG2
  60. struct smb_hdr *smb = (struct smb_hdr *)buf;
  61. cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
  62. smb->Command, smb->Status.CifsError,
  63. smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  64. cERROR(1, "smb buf %p len %u", smb, smbCalcSize(smb));
  65. #endif /* CONFIG_CIFS_DEBUG2 */
  66. }
  67. void cifs_dump_mids(struct TCP_Server_Info *server)
  68. {
  69. #ifdef CONFIG_CIFS_DEBUG2
  70. struct list_head *tmp;
  71. struct mid_q_entry *mid_entry;
  72. if (server == NULL)
  73. return;
  74. cERROR(1, "Dump pending requests:");
  75. spin_lock(&GlobalMid_Lock);
  76. list_for_each(tmp, &server->pending_mid_q) {
  77. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  78. cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu",
  79. mid_entry->mid_state,
  80. le16_to_cpu(mid_entry->command),
  81. mid_entry->pid,
  82. mid_entry->callback_data,
  83. mid_entry->mid);
  84. #ifdef CONFIG_CIFS_STATS2
  85. cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
  86. mid_entry->large_buf,
  87. mid_entry->resp_buf,
  88. mid_entry->when_received,
  89. jiffies);
  90. #endif /* STATS2 */
  91. cERROR(1, "IsMult: %d IsEnd: %d", mid_entry->multiRsp,
  92. mid_entry->multiEnd);
  93. if (mid_entry->resp_buf) {
  94. cifs_dump_detail(mid_entry->resp_buf);
  95. cifs_dump_mem("existing buf: ",
  96. mid_entry->resp_buf, 62);
  97. }
  98. }
  99. spin_unlock(&GlobalMid_Lock);
  100. #endif /* CONFIG_CIFS_DEBUG2 */
  101. }
  102. #ifdef CONFIG_PROC_FS
  103. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  104. {
  105. struct list_head *tmp1, *tmp2, *tmp3;
  106. struct mid_q_entry *mid_entry;
  107. struct TCP_Server_Info *server;
  108. struct cifs_ses *ses;
  109. struct cifs_tcon *tcon;
  110. int i, j;
  111. __u32 dev_type;
  112. seq_puts(m,
  113. "Display Internal CIFS Data Structures for Debugging\n"
  114. "---------------------------------------------------\n");
  115. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  116. seq_printf(m, "Features:");
  117. #ifdef CONFIG_CIFS_DFS_UPCALL
  118. seq_printf(m, " dfs");
  119. #endif
  120. #ifdef CONFIG_CIFS_FSCACHE
  121. seq_printf(m, " fscache");
  122. #endif
  123. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  124. seq_printf(m, " lanman");
  125. #endif
  126. #ifdef CONFIG_CIFS_POSIX
  127. seq_printf(m, " posix");
  128. #endif
  129. #ifdef CONFIG_CIFS_UPCALL
  130. seq_printf(m, " spnego");
  131. #endif
  132. #ifdef CONFIG_CIFS_XATTR
  133. seq_printf(m, " xattr");
  134. #endif
  135. #ifdef CONFIG_CIFS_ACL
  136. seq_printf(m, " acl");
  137. #endif
  138. seq_putc(m, '\n');
  139. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  140. seq_printf(m, "Servers:");
  141. i = 0;
  142. spin_lock(&cifs_tcp_ses_lock);
  143. list_for_each(tmp1, &cifs_tcp_ses_list) {
  144. server = list_entry(tmp1, struct TCP_Server_Info,
  145. tcp_ses_list);
  146. i++;
  147. list_for_each(tmp2, &server->smb_ses_list) {
  148. ses = list_entry(tmp2, struct cifs_ses,
  149. smb_ses_list);
  150. if ((ses->serverDomain == NULL) ||
  151. (ses->serverOS == NULL) ||
  152. (ses->serverNOS == NULL)) {
  153. seq_printf(m, "\n%d) entry for %s not fully "
  154. "displayed\n\t", i, ses->serverName);
  155. } else {
  156. seq_printf(m,
  157. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  158. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  159. " session status: %d\t",
  160. i, ses->serverName, ses->serverDomain,
  161. ses->ses_count, ses->serverOS, ses->serverNOS,
  162. ses->capabilities, ses->status);
  163. }
  164. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  165. "Server: %d SecMode: 0x%x Req On Wire: %d",
  166. server->tcpStatus, server->srv_count,
  167. server->sec_mode, in_flight(server));
  168. #ifdef CONFIG_CIFS_STATS2
  169. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  170. atomic_read(&server->in_send),
  171. atomic_read(&server->num_waiters));
  172. #endif
  173. seq_puts(m, "\n\tShares:");
  174. j = 0;
  175. list_for_each(tmp3, &ses->tcon_list) {
  176. tcon = list_entry(tmp3, struct cifs_tcon,
  177. tcon_list);
  178. ++j;
  179. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  180. seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
  181. tcon->treeName, tcon->tc_count);
  182. if (tcon->nativeFileSystem) {
  183. seq_printf(m, "Type: %s ",
  184. tcon->nativeFileSystem);
  185. }
  186. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  187. "\nPathComponentMax: %d Status: 0x%d",
  188. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  189. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  190. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  191. tcon->tidStatus);
  192. if (dev_type == FILE_DEVICE_DISK)
  193. seq_puts(m, " type: DISK ");
  194. else if (dev_type == FILE_DEVICE_CD_ROM)
  195. seq_puts(m, " type: CDROM ");
  196. else
  197. seq_printf(m, " type: %d ", dev_type);
  198. if (tcon->need_reconnect)
  199. seq_puts(m, "\tDISCONNECTED ");
  200. seq_putc(m, '\n');
  201. }
  202. seq_puts(m, "\n\tMIDs:\n");
  203. spin_lock(&GlobalMid_Lock);
  204. list_for_each(tmp3, &server->pending_mid_q) {
  205. mid_entry = list_entry(tmp3, struct mid_q_entry,
  206. qhead);
  207. seq_printf(m, "\tState: %d com: %d pid:"
  208. " %d cbdata: %p mid %llu\n",
  209. mid_entry->mid_state,
  210. le16_to_cpu(mid_entry->command),
  211. mid_entry->pid,
  212. mid_entry->callback_data,
  213. mid_entry->mid);
  214. }
  215. spin_unlock(&GlobalMid_Lock);
  216. }
  217. }
  218. spin_unlock(&cifs_tcp_ses_lock);
  219. seq_putc(m, '\n');
  220. /* BB add code to dump additional info such as TCP session info now */
  221. return 0;
  222. }
  223. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  224. {
  225. return single_open(file, cifs_debug_data_proc_show, NULL);
  226. }
  227. static const struct file_operations cifs_debug_data_proc_fops = {
  228. .owner = THIS_MODULE,
  229. .open = cifs_debug_data_proc_open,
  230. .read = seq_read,
  231. .llseek = seq_lseek,
  232. .release = single_release,
  233. };
  234. #ifdef CONFIG_CIFS_STATS
  235. static ssize_t cifs_stats_proc_write(struct file *file,
  236. const char __user *buffer, size_t count, loff_t *ppos)
  237. {
  238. char c;
  239. int rc;
  240. struct list_head *tmp1, *tmp2, *tmp3;
  241. struct TCP_Server_Info *server;
  242. struct cifs_ses *ses;
  243. struct cifs_tcon *tcon;
  244. rc = get_user(c, buffer);
  245. if (rc)
  246. return rc;
  247. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  248. #ifdef CONFIG_CIFS_STATS2
  249. atomic_set(&totBufAllocCount, 0);
  250. atomic_set(&totSmBufAllocCount, 0);
  251. #endif /* CONFIG_CIFS_STATS2 */
  252. spin_lock(&cifs_tcp_ses_lock);
  253. list_for_each(tmp1, &cifs_tcp_ses_list) {
  254. server = list_entry(tmp1, struct TCP_Server_Info,
  255. tcp_ses_list);
  256. list_for_each(tmp2, &server->smb_ses_list) {
  257. ses = list_entry(tmp2, struct cifs_ses,
  258. smb_ses_list);
  259. list_for_each(tmp3, &ses->tcon_list) {
  260. tcon = list_entry(tmp3,
  261. struct cifs_tcon,
  262. tcon_list);
  263. atomic_set(&tcon->num_smbs_sent, 0);
  264. if (server->ops->clear_stats)
  265. server->ops->clear_stats(tcon);
  266. }
  267. }
  268. }
  269. spin_unlock(&cifs_tcp_ses_lock);
  270. }
  271. return count;
  272. }
  273. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  274. {
  275. int i;
  276. struct list_head *tmp1, *tmp2, *tmp3;
  277. struct TCP_Server_Info *server;
  278. struct cifs_ses *ses;
  279. struct cifs_tcon *tcon;
  280. seq_printf(m,
  281. "Resources in use\nCIFS Session: %d\n",
  282. sesInfoAllocCount.counter);
  283. seq_printf(m, "Share (unique mount targets): %d\n",
  284. tconInfoAllocCount.counter);
  285. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  286. bufAllocCount.counter,
  287. cifs_min_rcv + tcpSesAllocCount.counter);
  288. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  289. smBufAllocCount.counter, cifs_min_small);
  290. #ifdef CONFIG_CIFS_STATS2
  291. seq_printf(m, "Total Large %d Small %d Allocations\n",
  292. atomic_read(&totBufAllocCount),
  293. atomic_read(&totSmBufAllocCount));
  294. #endif /* CONFIG_CIFS_STATS2 */
  295. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  296. seq_printf(m,
  297. "\n%d session %d share reconnects\n",
  298. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  299. seq_printf(m,
  300. "Total vfs operations: %d maximum at one time: %d\n",
  301. GlobalCurrentXid, GlobalMaxActiveXid);
  302. i = 0;
  303. spin_lock(&cifs_tcp_ses_lock);
  304. list_for_each(tmp1, &cifs_tcp_ses_list) {
  305. server = list_entry(tmp1, struct TCP_Server_Info,
  306. tcp_ses_list);
  307. list_for_each(tmp2, &server->smb_ses_list) {
  308. ses = list_entry(tmp2, struct cifs_ses,
  309. smb_ses_list);
  310. list_for_each(tmp3, &ses->tcon_list) {
  311. tcon = list_entry(tmp3,
  312. struct cifs_tcon,
  313. tcon_list);
  314. i++;
  315. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  316. if (tcon->need_reconnect)
  317. seq_puts(m, "\tDISCONNECTED ");
  318. seq_printf(m, "\nSMBs: %d",
  319. atomic_read(&tcon->num_smbs_sent));
  320. if (server->ops->print_stats)
  321. server->ops->print_stats(m, tcon);
  322. }
  323. }
  324. }
  325. spin_unlock(&cifs_tcp_ses_lock);
  326. seq_putc(m, '\n');
  327. return 0;
  328. }
  329. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  330. {
  331. return single_open(file, cifs_stats_proc_show, NULL);
  332. }
  333. static const struct file_operations cifs_stats_proc_fops = {
  334. .owner = THIS_MODULE,
  335. .open = cifs_stats_proc_open,
  336. .read = seq_read,
  337. .llseek = seq_lseek,
  338. .release = single_release,
  339. .write = cifs_stats_proc_write,
  340. };
  341. #endif /* STATS */
  342. static struct proc_dir_entry *proc_fs_cifs;
  343. static const struct file_operations cifsFYI_proc_fops;
  344. static const struct file_operations cifs_lookup_cache_proc_fops;
  345. static const struct file_operations traceSMB_proc_fops;
  346. static const struct file_operations cifs_security_flags_proc_fops;
  347. static const struct file_operations cifs_linux_ext_proc_fops;
  348. void
  349. cifs_proc_init(void)
  350. {
  351. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  352. if (proc_fs_cifs == NULL)
  353. return;
  354. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  355. #ifdef CONFIG_CIFS_STATS
  356. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  357. #endif /* STATS */
  358. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  359. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  360. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  361. &cifs_linux_ext_proc_fops);
  362. proc_create("SecurityFlags", 0, proc_fs_cifs,
  363. &cifs_security_flags_proc_fops);
  364. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  365. &cifs_lookup_cache_proc_fops);
  366. }
  367. void
  368. cifs_proc_clean(void)
  369. {
  370. if (proc_fs_cifs == NULL)
  371. return;
  372. remove_proc_entry("DebugData", proc_fs_cifs);
  373. remove_proc_entry("cifsFYI", proc_fs_cifs);
  374. remove_proc_entry("traceSMB", proc_fs_cifs);
  375. #ifdef CONFIG_CIFS_STATS
  376. remove_proc_entry("Stats", proc_fs_cifs);
  377. #endif
  378. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  379. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  380. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  381. remove_proc_entry("fs/cifs", NULL);
  382. }
  383. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  384. {
  385. seq_printf(m, "%d\n", cifsFYI);
  386. return 0;
  387. }
  388. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  389. {
  390. return single_open(file, cifsFYI_proc_show, NULL);
  391. }
  392. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  393. size_t count, loff_t *ppos)
  394. {
  395. char c;
  396. int rc;
  397. rc = get_user(c, buffer);
  398. if (rc)
  399. return rc;
  400. if (c == '0' || c == 'n' || c == 'N')
  401. cifsFYI = 0;
  402. else if (c == '1' || c == 'y' || c == 'Y')
  403. cifsFYI = 1;
  404. else if ((c > '1') && (c <= '9'))
  405. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  406. return count;
  407. }
  408. static const struct file_operations cifsFYI_proc_fops = {
  409. .owner = THIS_MODULE,
  410. .open = cifsFYI_proc_open,
  411. .read = seq_read,
  412. .llseek = seq_lseek,
  413. .release = single_release,
  414. .write = cifsFYI_proc_write,
  415. };
  416. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  417. {
  418. seq_printf(m, "%d\n", linuxExtEnabled);
  419. return 0;
  420. }
  421. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  422. {
  423. return single_open(file, cifs_linux_ext_proc_show, NULL);
  424. }
  425. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  426. const char __user *buffer, size_t count, loff_t *ppos)
  427. {
  428. char c;
  429. int rc;
  430. rc = get_user(c, buffer);
  431. if (rc)
  432. return rc;
  433. if (c == '0' || c == 'n' || c == 'N')
  434. linuxExtEnabled = 0;
  435. else if (c == '1' || c == 'y' || c == 'Y')
  436. linuxExtEnabled = 1;
  437. return count;
  438. }
  439. static const struct file_operations cifs_linux_ext_proc_fops = {
  440. .owner = THIS_MODULE,
  441. .open = cifs_linux_ext_proc_open,
  442. .read = seq_read,
  443. .llseek = seq_lseek,
  444. .release = single_release,
  445. .write = cifs_linux_ext_proc_write,
  446. };
  447. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  448. {
  449. seq_printf(m, "%d\n", lookupCacheEnabled);
  450. return 0;
  451. }
  452. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  453. {
  454. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  455. }
  456. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  457. const char __user *buffer, size_t count, loff_t *ppos)
  458. {
  459. char c;
  460. int rc;
  461. rc = get_user(c, buffer);
  462. if (rc)
  463. return rc;
  464. if (c == '0' || c == 'n' || c == 'N')
  465. lookupCacheEnabled = 0;
  466. else if (c == '1' || c == 'y' || c == 'Y')
  467. lookupCacheEnabled = 1;
  468. return count;
  469. }
  470. static const struct file_operations cifs_lookup_cache_proc_fops = {
  471. .owner = THIS_MODULE,
  472. .open = cifs_lookup_cache_proc_open,
  473. .read = seq_read,
  474. .llseek = seq_lseek,
  475. .release = single_release,
  476. .write = cifs_lookup_cache_proc_write,
  477. };
  478. static int traceSMB_proc_show(struct seq_file *m, void *v)
  479. {
  480. seq_printf(m, "%d\n", traceSMB);
  481. return 0;
  482. }
  483. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  484. {
  485. return single_open(file, traceSMB_proc_show, NULL);
  486. }
  487. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  488. size_t count, loff_t *ppos)
  489. {
  490. char c;
  491. int rc;
  492. rc = get_user(c, buffer);
  493. if (rc)
  494. return rc;
  495. if (c == '0' || c == 'n' || c == 'N')
  496. traceSMB = 0;
  497. else if (c == '1' || c == 'y' || c == 'Y')
  498. traceSMB = 1;
  499. return count;
  500. }
  501. static const struct file_operations traceSMB_proc_fops = {
  502. .owner = THIS_MODULE,
  503. .open = traceSMB_proc_open,
  504. .read = seq_read,
  505. .llseek = seq_lseek,
  506. .release = single_release,
  507. .write = traceSMB_proc_write,
  508. };
  509. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  510. {
  511. seq_printf(m, "0x%x\n", global_secflags);
  512. return 0;
  513. }
  514. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  515. {
  516. return single_open(file, cifs_security_flags_proc_show, NULL);
  517. }
  518. static ssize_t cifs_security_flags_proc_write(struct file *file,
  519. const char __user *buffer, size_t count, loff_t *ppos)
  520. {
  521. unsigned int flags;
  522. char flags_string[12];
  523. char c;
  524. if ((count < 1) || (count > 11))
  525. return -EINVAL;
  526. memset(flags_string, 0, 12);
  527. if (copy_from_user(flags_string, buffer, count))
  528. return -EFAULT;
  529. if (count < 3) {
  530. /* single char or single char followed by null */
  531. c = flags_string[0];
  532. if (c == '0' || c == 'n' || c == 'N') {
  533. global_secflags = CIFSSEC_DEF; /* default */
  534. return count;
  535. } else if (c == '1' || c == 'y' || c == 'Y') {
  536. global_secflags = CIFSSEC_MAX;
  537. return count;
  538. } else if (!isdigit(c)) {
  539. cERROR(1, "invalid flag %c", c);
  540. return -EINVAL;
  541. }
  542. }
  543. /* else we have a number */
  544. flags = simple_strtoul(flags_string, NULL, 0);
  545. cFYI(1, "sec flags 0x%x", flags);
  546. if (flags <= 0) {
  547. cERROR(1, "invalid security flags %s", flags_string);
  548. return -EINVAL;
  549. }
  550. if (flags & ~CIFSSEC_MASK) {
  551. cERROR(1, "attempt to set unsupported security flags 0x%x",
  552. flags & ~CIFSSEC_MASK);
  553. return -EINVAL;
  554. }
  555. /* flags look ok - update the global security flags for cifs module */
  556. global_secflags = flags;
  557. if (global_secflags & CIFSSEC_MUST_SIGN) {
  558. /* requiring signing implies signing is allowed */
  559. global_secflags |= CIFSSEC_MAY_SIGN;
  560. cFYI(1, "packet signing now required");
  561. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  562. cFYI(1, "packet signing disabled");
  563. }
  564. /* BB should we turn on MAY flags for other MUST options? */
  565. return count;
  566. }
  567. static const struct file_operations cifs_security_flags_proc_fops = {
  568. .owner = THIS_MODULE,
  569. .open = cifs_security_flags_proc_open,
  570. .read = seq_read,
  571. .llseek = seq_lseek,
  572. .release = single_release,
  573. .write = cifs_security_flags_proc_write,
  574. };
  575. #else
  576. inline void cifs_proc_init(void)
  577. {
  578. }
  579. inline void cifs_proc_clean(void)
  580. {
  581. }
  582. #endif /* PROC_FS */