aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/connect.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2012-12-10 06:10:45 -0500
committerSteve French <smfrench@gmail.com>2012-12-11 12:48:49 -0500
commit62a1a439e0fdd4ec8a80dc00fcbb9f26b5c34de1 (patch)
treef1d331829b62e57c9307dc037ac2e1321946df1f /fs/cifs/connect.c
parent193cdd8a293007d1a1ad252cf66b2dc5b793d2d0 (diff)
cifs: clean up handling of unc= option
Make sure we free any existing memory allocated for vol->UNC, just in case someone passes in multiple unc= options. Get rid of the check for too long a UNC. The check for >300 bytes seems arbitrary. We later copy this into the tcon->treeName, for instance and it's a lot shorter than 300 bytes. Eliminate an extra kmalloc and copy as well. Just set the vol->UNC directly with the contents of match_strdup. Establish that the UNC should be stored with '\\' delimiters. Use convert_delimiter to change it in place in the vol->UNC. Finally, move the check for a malformed UNC into cifs_parse_mount_options so we can catch that situation earlier. Pavel Shilovsky <piastry@etersoft.ru> Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <smfrench@gmail.com>
Diffstat (limited to 'fs/cifs/connect.c')
-rw-r--r--fs/cifs/connect.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index f3276239e075..9c5c8b8c19fe 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1566,29 +1566,15 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1566 got_ip = true; 1566 got_ip = true;
1567 break; 1567 break;
1568 case Opt_unc: 1568 case Opt_unc:
1569 string = match_strdup(args); 1569 kfree(vol->UNC);
1570 if (string == NULL) 1570 vol->UNC = match_strdup(args);
1571 if (vol->UNC == NULL)
1571 goto out_nomem; 1572 goto out_nomem;
1572 1573
1573 temp_len = strnlen(string, 300); 1574 convert_delimiter(vol->UNC, '\\');
1574 if (temp_len == 300) { 1575 if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') {
1575 printk(KERN_WARNING "CIFS: UNC name too long\n");
1576 goto cifs_parse_mount_err;
1577 }
1578
1579 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1580 if (vol->UNC == NULL) {
1581 printk(KERN_WARNING "CIFS: no memory for UNC\n");
1582 goto cifs_parse_mount_err;
1583 }
1584 strcpy(vol->UNC, string);
1585
1586 if (strncmp(string, "//", 2) == 0) {
1587 vol->UNC[0] = '\\';
1588 vol->UNC[1] = '\\';
1589 } else if (strncmp(string, "\\\\", 2) != 0) {
1590 printk(KERN_WARNING "CIFS: UNC Path does not " 1576 printk(KERN_WARNING "CIFS: UNC Path does not "
1591 "begin with // or \\\\\n"); 1577 "begin with // or \\\\\n");
1592 goto cifs_parse_mount_err; 1578 goto cifs_parse_mount_err;
1593 } 1579 }
1594 1580
@@ -1813,6 +1799,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1813 goto cifs_parse_mount_err; 1799 goto cifs_parse_mount_err;
1814 } 1800 }
1815 1801
1802 /* make sure UNC has a share name */
1803 if (!strchr(vol->UNC + 3, '\\')) {
1804 cERROR(1, "Malformed UNC. Unable to find share name.");
1805 goto cifs_parse_mount_err;
1806 }
1807
1816 if (!got_ip) { 1808 if (!got_ip) {
1817 /* No ip= option specified? Try to get it from UNC */ 1809 /* No ip= option specified? Try to get it from UNC */
1818 if (!cifs_convert_address(dstaddr, &vol->UNC[2], 1810 if (!cifs_convert_address(dstaddr, &vol->UNC[2],
@@ -2575,13 +2567,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
2575 } 2567 }
2576 } 2568 }
2577 2569
2578 if (strchr(volume_info->UNC + 3, '\\') == NULL
2579 && strchr(volume_info->UNC + 3, '/') == NULL) {
2580 cERROR(1, "Missing share name");
2581 rc = -ENODEV;
2582 goto out_fail;
2583 }
2584
2585 /* 2570 /*
2586 * BB Do we need to wrap session_mutex around this TCon call and Unix 2571 * BB Do we need to wrap session_mutex around this TCon call and Unix
2587 * SetFS as we do on SessSetup and reconnect? 2572 * SetFS as we do on SessSetup and reconnect?