4 * Copyright (C) International Business Machines Corp., 2000,2005
6 * Modified by Steve French (sfrench@us.ibm.com)
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.
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.
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
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>
30 #include "cifsproto.h"
31 #include "cifs_debug.h"
35 cifs_dump_mem(char *label, void *data, int length)
40 char buf[10], line[80];
42 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
44 for (i = 0; i < length; i += 16) {
46 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
47 sprintf(buf, " %08x", intptr[i / 4 + j]);
52 for (j = 0; (j < 16) && (i + j < length); j++) {
53 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
56 printk(KERN_DEBUG "%s\n", line);
60 #ifdef CONFIG_CIFS_DEBUG
61 void cifs_vfs_err(const char *fmt, ...)
71 printk(KERN_ERR "CIFS VFS: %pV", &vaf);
77 void cifs_dump_detail(void *buf)
79 #ifdef CONFIG_CIFS_DEBUG2
80 struct smb_hdr *smb = (struct smb_hdr *)buf;
82 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
83 smb->Command, smb->Status.CifsError,
84 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
85 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
86 #endif /* CONFIG_CIFS_DEBUG2 */
89 void cifs_dump_mids(struct TCP_Server_Info *server)
91 #ifdef CONFIG_CIFS_DEBUG2
92 struct list_head *tmp;
93 struct mid_q_entry *mid_entry;
98 cifs_dbg(VFS, "Dump pending requests:\n");
99 spin_lock(&GlobalMid_Lock);
100 list_for_each(tmp, &server->pending_mid_q) {
101 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
102 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
103 mid_entry->mid_state,
104 le16_to_cpu(mid_entry->command),
106 mid_entry->callback_data,
108 #ifdef CONFIG_CIFS_STATS2
109 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
110 mid_entry->large_buf,
112 mid_entry->when_received,
115 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
116 mid_entry->multiRsp, mid_entry->multiEnd);
117 if (mid_entry->resp_buf) {
118 cifs_dump_detail(mid_entry->resp_buf);
119 cifs_dump_mem("existing buf: ",
120 mid_entry->resp_buf, 62);
123 spin_unlock(&GlobalMid_Lock);
124 #endif /* CONFIG_CIFS_DEBUG2 */
127 #ifdef CONFIG_PROC_FS
128 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
130 struct list_head *tmp1, *tmp2, *tmp3;
131 struct mid_q_entry *mid_entry;
132 struct TCP_Server_Info *server;
133 struct cifs_ses *ses;
134 struct cifs_tcon *tcon;
139 "Display Internal CIFS Data Structures for Debugging\n"
140 "---------------------------------------------------\n");
141 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
142 seq_printf(m, "Features:");
143 #ifdef CONFIG_CIFS_DFS_UPCALL
144 seq_printf(m, " dfs");
146 #ifdef CONFIG_CIFS_FSCACHE
147 seq_printf(m, " fscache");
149 #ifdef CONFIG_CIFS_WEAK_PW_HASH
150 seq_printf(m, " lanman");
152 #ifdef CONFIG_CIFS_POSIX
153 seq_printf(m, " posix");
155 #ifdef CONFIG_CIFS_UPCALL
156 seq_printf(m, " spnego");
158 #ifdef CONFIG_CIFS_XATTR
159 seq_printf(m, " xattr");
161 #ifdef CONFIG_CIFS_ACL
162 seq_printf(m, " acl");
165 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
166 seq_printf(m, "Servers:");
169 spin_lock(&cifs_tcp_ses_lock);
170 list_for_each(tmp1, &cifs_tcp_ses_list) {
171 server = list_entry(tmp1, struct TCP_Server_Info,
174 list_for_each(tmp2, &server->smb_ses_list) {
175 ses = list_entry(tmp2, struct cifs_ses,
177 if ((ses->serverDomain == NULL) ||
178 (ses->serverOS == NULL) ||
179 (ses->serverNOS == NULL)) {
180 seq_printf(m, "\n%d) entry for %s not fully "
181 "displayed\n\t", i, ses->serverName);
184 "\n%d) Name: %s Domain: %s Uses: %d OS:"
185 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
186 " session status: %d\t",
187 i, ses->serverName, ses->serverDomain,
188 ses->ses_count, ses->serverOS, ses->serverNOS,
189 ses->capabilities, ses->status);
191 seq_printf(m, "TCP status: %d\n\tLocal Users To "
192 "Server: %d SecMode: 0x%x Req On Wire: %d",
193 server->tcpStatus, server->srv_count,
194 server->sec_mode, in_flight(server));
196 #ifdef CONFIG_CIFS_STATS2
197 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
198 atomic_read(&server->in_send),
199 atomic_read(&server->num_waiters));
202 seq_puts(m, "\n\tShares:");
204 list_for_each(tmp3, &ses->tcon_list) {
205 tcon = list_entry(tmp3, struct cifs_tcon,
208 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
209 seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
210 tcon->treeName, tcon->tc_count);
211 if (tcon->nativeFileSystem) {
212 seq_printf(m, "Type: %s ",
213 tcon->nativeFileSystem);
215 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
216 "\n\tPathComponentMax: %d Status: %d",
217 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
218 le32_to_cpu(tcon->fsAttrInfo.Attributes),
219 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
221 if (dev_type == FILE_DEVICE_DISK)
222 seq_puts(m, " type: DISK ");
223 else if (dev_type == FILE_DEVICE_CD_ROM)
224 seq_puts(m, " type: CDROM ");
226 seq_printf(m, " type: %d ", dev_type);
227 if (server->ops->dump_share_caps)
228 server->ops->dump_share_caps(m, tcon);
230 if (tcon->need_reconnect)
231 seq_puts(m, "\tDISCONNECTED ");
235 seq_puts(m, "\n\tMIDs:\n");
237 spin_lock(&GlobalMid_Lock);
238 list_for_each(tmp3, &server->pending_mid_q) {
239 mid_entry = list_entry(tmp3, struct mid_q_entry,
241 seq_printf(m, "\tState: %d com: %d pid:"
242 " %d cbdata: %p mid %llu\n",
243 mid_entry->mid_state,
244 le16_to_cpu(mid_entry->command),
246 mid_entry->callback_data,
249 spin_unlock(&GlobalMid_Lock);
252 spin_unlock(&cifs_tcp_ses_lock);
255 /* BB add code to dump additional info such as TCP session info now */
259 static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
261 return single_open(file, cifs_debug_data_proc_show, NULL);
264 static const struct file_operations cifs_debug_data_proc_fops = {
265 .owner = THIS_MODULE,
266 .open = cifs_debug_data_proc_open,
269 .release = single_release,
272 #ifdef CONFIG_CIFS_STATS
273 static ssize_t cifs_stats_proc_write(struct file *file,
274 const char __user *buffer, size_t count, loff_t *ppos)
279 struct list_head *tmp1, *tmp2, *tmp3;
280 struct TCP_Server_Info *server;
281 struct cifs_ses *ses;
282 struct cifs_tcon *tcon;
284 rc = get_user(c, buffer);
288 if (strtobool(&c, &bv) == 0) {
289 #ifdef CONFIG_CIFS_STATS2
290 atomic_set(&totBufAllocCount, 0);
291 atomic_set(&totSmBufAllocCount, 0);
292 #endif /* CONFIG_CIFS_STATS2 */
293 spin_lock(&cifs_tcp_ses_lock);
294 list_for_each(tmp1, &cifs_tcp_ses_list) {
295 server = list_entry(tmp1, struct TCP_Server_Info,
297 list_for_each(tmp2, &server->smb_ses_list) {
298 ses = list_entry(tmp2, struct cifs_ses,
300 list_for_each(tmp3, &ses->tcon_list) {
301 tcon = list_entry(tmp3,
304 atomic_set(&tcon->num_smbs_sent, 0);
305 if (server->ops->clear_stats)
306 server->ops->clear_stats(tcon);
310 spin_unlock(&cifs_tcp_ses_lock);
316 static int cifs_stats_proc_show(struct seq_file *m, void *v)
319 struct list_head *tmp1, *tmp2, *tmp3;
320 struct TCP_Server_Info *server;
321 struct cifs_ses *ses;
322 struct cifs_tcon *tcon;
325 "Resources in use\nCIFS Session: %d\n",
326 sesInfoAllocCount.counter);
327 seq_printf(m, "Share (unique mount targets): %d\n",
328 tconInfoAllocCount.counter);
329 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
330 bufAllocCount.counter,
331 cifs_min_rcv + tcpSesAllocCount.counter);
332 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
333 smBufAllocCount.counter, cifs_min_small);
334 #ifdef CONFIG_CIFS_STATS2
335 seq_printf(m, "Total Large %d Small %d Allocations\n",
336 atomic_read(&totBufAllocCount),
337 atomic_read(&totSmBufAllocCount));
338 #endif /* CONFIG_CIFS_STATS2 */
340 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
342 "\n%d session %d share reconnects\n",
343 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
346 "Total vfs operations: %d maximum at one time: %d\n",
347 GlobalCurrentXid, GlobalMaxActiveXid);
350 spin_lock(&cifs_tcp_ses_lock);
351 list_for_each(tmp1, &cifs_tcp_ses_list) {
352 server = list_entry(tmp1, struct TCP_Server_Info,
354 list_for_each(tmp2, &server->smb_ses_list) {
355 ses = list_entry(tmp2, struct cifs_ses,
357 list_for_each(tmp3, &ses->tcon_list) {
358 tcon = list_entry(tmp3,
362 seq_printf(m, "\n%d) %s", i, tcon->treeName);
363 if (tcon->need_reconnect)
364 seq_puts(m, "\tDISCONNECTED ");
365 seq_printf(m, "\nSMBs: %d",
366 atomic_read(&tcon->num_smbs_sent));
367 if (server->ops->print_stats)
368 server->ops->print_stats(m, tcon);
372 spin_unlock(&cifs_tcp_ses_lock);
378 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
380 return single_open(file, cifs_stats_proc_show, NULL);
383 static const struct file_operations cifs_stats_proc_fops = {
384 .owner = THIS_MODULE,
385 .open = cifs_stats_proc_open,
388 .release = single_release,
389 .write = cifs_stats_proc_write,
393 static struct proc_dir_entry *proc_fs_cifs;
394 static const struct file_operations cifsFYI_proc_fops;
395 static const struct file_operations cifs_lookup_cache_proc_fops;
396 static const struct file_operations traceSMB_proc_fops;
397 static const struct file_operations cifs_security_flags_proc_fops;
398 static const struct file_operations cifs_linux_ext_proc_fops;
403 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
404 if (proc_fs_cifs == NULL)
407 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
409 #ifdef CONFIG_CIFS_STATS
410 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
412 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
413 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
414 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
415 &cifs_linux_ext_proc_fops);
416 proc_create("SecurityFlags", 0, proc_fs_cifs,
417 &cifs_security_flags_proc_fops);
418 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
419 &cifs_lookup_cache_proc_fops);
423 cifs_proc_clean(void)
425 if (proc_fs_cifs == NULL)
428 remove_proc_entry("DebugData", proc_fs_cifs);
429 remove_proc_entry("cifsFYI", proc_fs_cifs);
430 remove_proc_entry("traceSMB", proc_fs_cifs);
431 #ifdef CONFIG_CIFS_STATS
432 remove_proc_entry("Stats", proc_fs_cifs);
434 remove_proc_entry("SecurityFlags", proc_fs_cifs);
435 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
436 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
437 remove_proc_entry("fs/cifs", NULL);
440 static int cifsFYI_proc_show(struct seq_file *m, void *v)
442 seq_printf(m, "%d\n", cifsFYI);
446 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
448 return single_open(file, cifsFYI_proc_show, NULL);
451 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
452 size_t count, loff_t *ppos)
458 rc = get_user(c, buffer);
461 if (strtobool(&c, &bv) == 0)
463 else if ((c > '1') && (c <= '9'))
464 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
469 static const struct file_operations cifsFYI_proc_fops = {
470 .owner = THIS_MODULE,
471 .open = cifsFYI_proc_open,
474 .release = single_release,
475 .write = cifsFYI_proc_write,
478 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
480 seq_printf(m, "%d\n", linuxExtEnabled);
484 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
486 return single_open(file, cifs_linux_ext_proc_show, NULL);
489 static ssize_t cifs_linux_ext_proc_write(struct file *file,
490 const char __user *buffer, size_t count, loff_t *ppos)
496 rc = get_user(c, buffer);
500 rc = strtobool(&c, &bv);
504 linuxExtEnabled = bv;
509 static const struct file_operations cifs_linux_ext_proc_fops = {
510 .owner = THIS_MODULE,
511 .open = cifs_linux_ext_proc_open,
514 .release = single_release,
515 .write = cifs_linux_ext_proc_write,
518 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
520 seq_printf(m, "%d\n", lookupCacheEnabled);
524 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
526 return single_open(file, cifs_lookup_cache_proc_show, NULL);
529 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
530 const char __user *buffer, size_t count, loff_t *ppos)
536 rc = get_user(c, buffer);
540 rc = strtobool(&c, &bv);
544 lookupCacheEnabled = bv;
549 static const struct file_operations cifs_lookup_cache_proc_fops = {
550 .owner = THIS_MODULE,
551 .open = cifs_lookup_cache_proc_open,
554 .release = single_release,
555 .write = cifs_lookup_cache_proc_write,
558 static int traceSMB_proc_show(struct seq_file *m, void *v)
560 seq_printf(m, "%d\n", traceSMB);
564 static int traceSMB_proc_open(struct inode *inode, struct file *file)
566 return single_open(file, traceSMB_proc_show, NULL);
569 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
570 size_t count, loff_t *ppos)
576 rc = get_user(c, buffer);
580 rc = strtobool(&c, &bv);
589 static const struct file_operations traceSMB_proc_fops = {
590 .owner = THIS_MODULE,
591 .open = traceSMB_proc_open,
594 .release = single_release,
595 .write = traceSMB_proc_write,
598 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
600 seq_printf(m, "0x%x\n", global_secflags);
604 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
606 return single_open(file, cifs_security_flags_proc_show, NULL);
610 * Ensure that if someone sets a MUST flag, that we disable all other MAY
611 * flags except for the ones corresponding to the given MUST flag. If there are
612 * multiple MUST flags, then try to prefer more secure ones.
615 cifs_security_flags_handle_must_flags(unsigned int *flags)
617 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
619 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
620 *flags = CIFSSEC_MUST_KRB5;
621 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
622 *flags = CIFSSEC_MUST_NTLMSSP;
623 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
624 *flags = CIFSSEC_MUST_NTLMV2;
625 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
626 *flags = CIFSSEC_MUST_NTLM;
627 else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
628 *flags = CIFSSEC_MUST_LANMAN;
629 else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
630 *flags = CIFSSEC_MUST_PLNTXT;
635 static ssize_t cifs_security_flags_proc_write(struct file *file,
636 const char __user *buffer, size_t count, loff_t *ppos)
640 char flags_string[12];
644 if ((count < 1) || (count > 11))
647 memset(flags_string, 0, 12);
649 if (copy_from_user(flags_string, buffer, count))
653 /* single char or single char followed by null */
655 if (strtobool(&c, &bv) == 0) {
656 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
658 } else if (!isdigit(c)) {
659 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
665 /* else we have a number */
666 rc = kstrtouint(flags_string, 0, &flags);
668 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
673 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
676 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
680 if (flags & ~CIFSSEC_MASK) {
681 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
682 flags & ~CIFSSEC_MASK);
686 cifs_security_flags_handle_must_flags(&flags);
688 /* flags look ok - update the global security flags for cifs module */
689 global_secflags = flags;
690 if (global_secflags & CIFSSEC_MUST_SIGN) {
691 /* requiring signing implies signing is allowed */
692 global_secflags |= CIFSSEC_MAY_SIGN;
693 cifs_dbg(FYI, "packet signing now required\n");
694 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
695 cifs_dbg(FYI, "packet signing disabled\n");
697 /* BB should we turn on MAY flags for other MUST options? */
701 static const struct file_operations cifs_security_flags_proc_fops = {
702 .owner = THIS_MODULE,
703 .open = cifs_security_flags_proc_open,
706 .release = single_release,
707 .write = cifs_security_flags_proc_write,
710 inline void cifs_proc_init(void)
714 inline void cifs_proc_clean(void)