7c50bfa9c438a1c7342e1f8e21291a8b1dd98187
[pandora-kernel.git] / fs / cifs / cifs_debug.c
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
34 void
35 cifs_dump_mem(char *label, void *data, int length)
36 {
37         int i, j;
38         int *intptr = data;
39         char *charptr = data;
40         char buf[10], line[80];
41
42         printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
43                 label, length, data);
44         for (i = 0; i < length; i += 16) {
45                 line[0] = 0;
46                 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
47                         sprintf(buf, " %08x", intptr[i / 4 + j]);
48                         strcat(line, buf);
49                 }
50                 buf[0] = ' ';
51                 buf[2] = 0;
52                 for (j = 0; (j < 16) && (i + j < length); j++) {
53                         buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
54                         strcat(line, buf);
55                 }
56                 printk(KERN_DEBUG "%s\n", line);
57         }
58 }
59
60 #ifdef CONFIG_CIFS_DEBUG
61 void cifs_vfs_err(const char *fmt, ...)
62 {
63         struct va_format vaf;
64         va_list args;
65
66         va_start(args, fmt);
67
68         vaf.fmt = fmt;
69         vaf.va = &args;
70
71         printk(KERN_ERR "CIFS VFS: %pV", &vaf);
72
73         va_end(args);
74 }
75 #endif
76
77 void cifs_dump_detail(void *buf)
78 {
79 #ifdef CONFIG_CIFS_DEBUG2
80         struct smb_hdr *smb = (struct smb_hdr *)buf;
81
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 */
87 }
88
89 void cifs_dump_mids(struct TCP_Server_Info *server)
90 {
91 #ifdef CONFIG_CIFS_DEBUG2
92         struct list_head *tmp;
93         struct mid_q_entry *mid_entry;
94
95         if (server == NULL)
96                 return;
97
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),
105                          mid_entry->pid,
106                          mid_entry->callback_data,
107                          mid_entry->mid);
108 #ifdef CONFIG_CIFS_STATS2
109                 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
110                          mid_entry->large_buf,
111                          mid_entry->resp_buf,
112                          mid_entry->when_received,
113                          jiffies);
114 #endif /* STATS2 */
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);
121                 }
122         }
123         spin_unlock(&GlobalMid_Lock);
124 #endif /* CONFIG_CIFS_DEBUG2 */
125 }
126
127 #ifdef CONFIG_PROC_FS
128 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
129 {
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;
135         int i, j;
136         __u32 dev_type;
137
138         seq_puts(m,
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");
145 #endif
146 #ifdef CONFIG_CIFS_FSCACHE
147         seq_printf(m, " fscache");
148 #endif
149 #ifdef CONFIG_CIFS_WEAK_PW_HASH
150         seq_printf(m, " lanman");
151 #endif
152 #ifdef CONFIG_CIFS_POSIX
153         seq_printf(m, " posix");
154 #endif
155 #ifdef CONFIG_CIFS_UPCALL
156         seq_printf(m, " spnego");
157 #endif
158 #ifdef CONFIG_CIFS_XATTR
159         seq_printf(m, " xattr");
160 #endif
161 #ifdef CONFIG_CIFS_ACL
162         seq_printf(m, " acl");
163 #endif
164         seq_putc(m, '\n');
165         seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
166         seq_printf(m, "Servers:");
167
168         i = 0;
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,
172                                     tcp_ses_list);
173                 i++;
174                 list_for_each(tmp2, &server->smb_ses_list) {
175                         ses = list_entry(tmp2, struct cifs_ses,
176                                          smb_ses_list);
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);
182                         } else {
183                                 seq_printf(m,
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);
190                         }
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));
195
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));
200 #endif
201
202                         seq_puts(m, "\n\tShares:");
203                         j = 0;
204                         list_for_each(tmp3, &ses->tcon_list) {
205                                 tcon = list_entry(tmp3, struct cifs_tcon,
206                                                   tcon_list);
207                                 ++j;
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);
214                                 }
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),
220                                         tcon->tidStatus);
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 ");
225                                 else
226                                         seq_printf(m, " type: %d ", dev_type);
227                                 if (server->ops->dump_share_caps)
228                                         server->ops->dump_share_caps(m, tcon);
229
230                                 if (tcon->need_reconnect)
231                                         seq_puts(m, "\tDISCONNECTED ");
232                                 seq_putc(m, '\n');
233                         }
234
235                         seq_puts(m, "\n\tMIDs:\n");
236
237                         spin_lock(&GlobalMid_Lock);
238                         list_for_each(tmp3, &server->pending_mid_q) {
239                                 mid_entry = list_entry(tmp3, struct mid_q_entry,
240                                         qhead);
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),
245                                               mid_entry->pid,
246                                               mid_entry->callback_data,
247                                               mid_entry->mid);
248                         }
249                         spin_unlock(&GlobalMid_Lock);
250                 }
251         }
252         spin_unlock(&cifs_tcp_ses_lock);
253         seq_putc(m, '\n');
254
255         /* BB add code to dump additional info such as TCP session info now */
256         return 0;
257 }
258
259 static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
260 {
261         return single_open(file, cifs_debug_data_proc_show, NULL);
262 }
263
264 static const struct file_operations cifs_debug_data_proc_fops = {
265         .owner          = THIS_MODULE,
266         .open           = cifs_debug_data_proc_open,
267         .read           = seq_read,
268         .llseek         = seq_lseek,
269         .release        = single_release,
270 };
271
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)
275 {
276         char c;
277         bool bv;
278         int rc;
279         struct list_head *tmp1, *tmp2, *tmp3;
280         struct TCP_Server_Info *server;
281         struct cifs_ses *ses;
282         struct cifs_tcon *tcon;
283
284         rc = get_user(c, buffer);
285         if (rc)
286                 return rc;
287
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,
296                                             tcp_ses_list);
297                         list_for_each(tmp2, &server->smb_ses_list) {
298                                 ses = list_entry(tmp2, struct cifs_ses,
299                                                  smb_ses_list);
300                                 list_for_each(tmp3, &ses->tcon_list) {
301                                         tcon = list_entry(tmp3,
302                                                           struct cifs_tcon,
303                                                           tcon_list);
304                                         atomic_set(&tcon->num_smbs_sent, 0);
305                                         if (server->ops->clear_stats)
306                                                 server->ops->clear_stats(tcon);
307                                 }
308                         }
309                 }
310                 spin_unlock(&cifs_tcp_ses_lock);
311         }
312
313         return count;
314 }
315
316 static int cifs_stats_proc_show(struct seq_file *m, void *v)
317 {
318         int i;
319         struct list_head *tmp1, *tmp2, *tmp3;
320         struct TCP_Server_Info *server;
321         struct cifs_ses *ses;
322         struct cifs_tcon *tcon;
323
324         seq_printf(m,
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 */
339
340         seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
341         seq_printf(m,
342                 "\n%d session %d share reconnects\n",
343                 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
344
345         seq_printf(m,
346                 "Total vfs operations: %d maximum at one time: %d\n",
347                 GlobalCurrentXid, GlobalMaxActiveXid);
348
349         i = 0;
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,
353                                     tcp_ses_list);
354                 list_for_each(tmp2, &server->smb_ses_list) {
355                         ses = list_entry(tmp2, struct cifs_ses,
356                                          smb_ses_list);
357                         list_for_each(tmp3, &ses->tcon_list) {
358                                 tcon = list_entry(tmp3,
359                                                   struct cifs_tcon,
360                                                   tcon_list);
361                                 i++;
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);
369                         }
370                 }
371         }
372         spin_unlock(&cifs_tcp_ses_lock);
373
374         seq_putc(m, '\n');
375         return 0;
376 }
377
378 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
379 {
380         return single_open(file, cifs_stats_proc_show, NULL);
381 }
382
383 static const struct file_operations cifs_stats_proc_fops = {
384         .owner          = THIS_MODULE,
385         .open           = cifs_stats_proc_open,
386         .read           = seq_read,
387         .llseek         = seq_lseek,
388         .release        = single_release,
389         .write          = cifs_stats_proc_write,
390 };
391 #endif /* STATS */
392
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;
399
400 void
401 cifs_proc_init(void)
402 {
403         proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
404         if (proc_fs_cifs == NULL)
405                 return;
406
407         proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
408
409 #ifdef CONFIG_CIFS_STATS
410         proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
411 #endif /* STATS */
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);
420 }
421
422 void
423 cifs_proc_clean(void)
424 {
425         if (proc_fs_cifs == NULL)
426                 return;
427
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);
433 #endif
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);
438 }
439
440 static int cifsFYI_proc_show(struct seq_file *m, void *v)
441 {
442         seq_printf(m, "%d\n", cifsFYI);
443         return 0;
444 }
445
446 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
447 {
448         return single_open(file, cifsFYI_proc_show, NULL);
449 }
450
451 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
452                 size_t count, loff_t *ppos)
453 {
454         char c;
455         bool bv;
456         int rc;
457
458         rc = get_user(c, buffer);
459         if (rc)
460                 return rc;
461         if (strtobool(&c, &bv) == 0)
462                 cifsFYI = bv;
463         else if ((c > '1') && (c <= '9'))
464                 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
465
466         return count;
467 }
468
469 static const struct file_operations cifsFYI_proc_fops = {
470         .owner          = THIS_MODULE,
471         .open           = cifsFYI_proc_open,
472         .read           = seq_read,
473         .llseek         = seq_lseek,
474         .release        = single_release,
475         .write          = cifsFYI_proc_write,
476 };
477
478 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
479 {
480         seq_printf(m, "%d\n", linuxExtEnabled);
481         return 0;
482 }
483
484 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
485 {
486         return single_open(file, cifs_linux_ext_proc_show, NULL);
487 }
488
489 static ssize_t cifs_linux_ext_proc_write(struct file *file,
490                 const char __user *buffer, size_t count, loff_t *ppos)
491 {
492         char c;
493         bool bv;
494         int rc;
495
496         rc = get_user(c, buffer);
497         if (rc)
498                 return rc;
499
500         rc = strtobool(&c, &bv);
501         if (rc)
502                 return rc;
503
504         linuxExtEnabled = bv;
505
506         return count;
507 }
508
509 static const struct file_operations cifs_linux_ext_proc_fops = {
510         .owner          = THIS_MODULE,
511         .open           = cifs_linux_ext_proc_open,
512         .read           = seq_read,
513         .llseek         = seq_lseek,
514         .release        = single_release,
515         .write          = cifs_linux_ext_proc_write,
516 };
517
518 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
519 {
520         seq_printf(m, "%d\n", lookupCacheEnabled);
521         return 0;
522 }
523
524 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
525 {
526         return single_open(file, cifs_lookup_cache_proc_show, NULL);
527 }
528
529 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
530                 const char __user *buffer, size_t count, loff_t *ppos)
531 {
532         char c;
533         bool bv;
534         int rc;
535
536         rc = get_user(c, buffer);
537         if (rc)
538                 return rc;
539
540         rc = strtobool(&c, &bv);
541         if (rc)
542                 return rc;
543
544         lookupCacheEnabled = bv;
545
546         return count;
547 }
548
549 static const struct file_operations cifs_lookup_cache_proc_fops = {
550         .owner          = THIS_MODULE,
551         .open           = cifs_lookup_cache_proc_open,
552         .read           = seq_read,
553         .llseek         = seq_lseek,
554         .release        = single_release,
555         .write          = cifs_lookup_cache_proc_write,
556 };
557
558 static int traceSMB_proc_show(struct seq_file *m, void *v)
559 {
560         seq_printf(m, "%d\n", traceSMB);
561         return 0;
562 }
563
564 static int traceSMB_proc_open(struct inode *inode, struct file *file)
565 {
566         return single_open(file, traceSMB_proc_show, NULL);
567 }
568
569 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
570                 size_t count, loff_t *ppos)
571 {
572         char c;
573         bool bv;
574         int rc;
575
576         rc = get_user(c, buffer);
577         if (rc)
578                 return rc;
579
580         rc = strtobool(&c, &bv);
581         if (rc)
582                 return rc;
583
584         traceSMB = bv;
585
586         return count;
587 }
588
589 static const struct file_operations traceSMB_proc_fops = {
590         .owner          = THIS_MODULE,
591         .open           = traceSMB_proc_open,
592         .read           = seq_read,
593         .llseek         = seq_lseek,
594         .release        = single_release,
595         .write          = traceSMB_proc_write,
596 };
597
598 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
599 {
600         seq_printf(m, "0x%x\n", global_secflags);
601         return 0;
602 }
603
604 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
605 {
606         return single_open(file, cifs_security_flags_proc_show, NULL);
607 }
608
609 /*
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.
613  */
614 static void
615 cifs_security_flags_handle_must_flags(unsigned int *flags)
616 {
617         unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
618
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;
631
632         *flags |= signflags;
633 }
634
635 static ssize_t cifs_security_flags_proc_write(struct file *file,
636                 const char __user *buffer, size_t count, loff_t *ppos)
637 {
638         int rc;
639         unsigned int flags;
640         char flags_string[12];
641         char c;
642         bool bv;
643
644         if ((count < 1) || (count > 11))
645                 return -EINVAL;
646
647         memset(flags_string, 0, 12);
648
649         if (copy_from_user(flags_string, buffer, count))
650                 return -EFAULT;
651
652         if (count < 3) {
653                 /* single char or single char followed by null */
654                 c = flags_string[0];
655                 if (strtobool(&c, &bv) == 0) {
656                         global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
657                         return count;
658                 } else if (!isdigit(c)) {
659                         cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
660                                         flags_string);
661                         return -EINVAL;
662                 }
663         }
664
665         /* else we have a number */
666         rc = kstrtouint(flags_string, 0, &flags);
667         if (rc) {
668                 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
669                                 flags_string);
670                 return rc;
671         }
672
673         cifs_dbg(FYI, "sec flags 0x%x\n", flags);
674
675         if (flags == 0)  {
676                 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
677                 return -EINVAL;
678         }
679
680         if (flags & ~CIFSSEC_MASK) {
681                 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
682                          flags & ~CIFSSEC_MASK);
683                 return -EINVAL;
684         }
685
686         cifs_security_flags_handle_must_flags(&flags);
687
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");
696         }
697         /* BB should we turn on MAY flags for other MUST options? */
698         return count;
699 }
700
701 static const struct file_operations cifs_security_flags_proc_fops = {
702         .owner          = THIS_MODULE,
703         .open           = cifs_security_flags_proc_open,
704         .read           = seq_read,
705         .llseek         = seq_lseek,
706         .release        = single_release,
707         .write          = cifs_security_flags_proc_write,
708 };
709 #else
710 inline void cifs_proc_init(void)
711 {
712 }
713
714 inline void cifs_proc_clean(void)
715 {
716 }
717 #endif /* PROC_FS */