summaryrefslogtreecommitdiffstats
path: root/fs/cifs/netmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/cifs/netmisc.c')
-rw-r--r--fs/cifs/netmisc.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index f06359cb22ee..646e1f06941b 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -132,6 +132,34 @@ static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
{0, 0}
};
+
+/* if the mount helper is missing we need to reverse the 1st slash
+ from '/' to backslash in order to format the UNC properly for
+ ip address parsing and for tree connect (unless the user
+ remembered to put the UNC name in properly). Fortunately we do
+ not have to call this twice (we check for IPv4 addresses
+ first, so it is already converted by the time we
+ try IPv6 addresses */
+static int canonicalize_unc(char *cp)
+{
+ int i;
+
+ for (i = 0; i <= 46 /* INET6_ADDRSTRLEN */ ; i++) {
+ if (cp[i] == 0)
+ break;
+ if (cp[i] == '\\')
+ break;
+ if (cp[i] == '/') {
+#ifdef CONFIG_CIFS_DEBUG2
+ cFYI(1, ("change slash to backslash in malformed UNC"));
+#endif
+ cp[i] = '\\';
+ return 1;
+ }
+ }
+ return 0;
+}
+
/* Convert string containing dotted ip address to binary form */
/* returns 0 if invalid address */
@@ -141,11 +169,13 @@ cifs_inet_pton(int address_family, char *cp, void *dst)
int ret = 0;
/* calculate length by finding first slash or NULL */
- /* BB Should we convert '/' slash to '\' here since it seems already
- * done before this */
- if ( address_family == AF_INET ) {
- ret = in4_pton(cp, -1 /* len */, dst , '\\', NULL);
- } else if ( address_family == AF_INET6 ) {
+ if (address_family == AF_INET) {
+ ret = in4_pton(cp, -1 /* len */, dst, '\\', NULL);
+ if (ret == 0) {
+ if (canonicalize_unc(cp))
+ ret = in4_pton(cp, -1, dst, '\\', NULL);
+ }
+ } else if (address_family == AF_INET6) {
ret = in6_pton(cp, -1 /* len */, dst , '\\', NULL);
}
#ifdef CONFIG_CIFS_DEBUG2
@@ -740,7 +770,7 @@ cifs_print_status(__u32 status_code)
static void
-ntstatus_to_dos(__u32 ntstatus, __u8 * eclass, __u16 * ecode)
+ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
{
int i;
if (ntstatus == 0) {
@@ -793,8 +823,8 @@ map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
if (smberrclass == ERRDOS) { /* 1 byte field no need to byte reverse */
for (i = 0;
i <
- sizeof (mapping_table_ERRDOS) /
- sizeof (struct smb_to_posix_error); i++) {
+ sizeof(mapping_table_ERRDOS) /
+ sizeof(struct smb_to_posix_error); i++) {
if (mapping_table_ERRDOS[i].smb_err == 0)
break;
else if (mapping_table_ERRDOS[i].smb_err ==
@@ -807,8 +837,8 @@ map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
} else if (smberrclass == ERRSRV) { /* server class of error codes */
for (i = 0;
i <
- sizeof (mapping_table_ERRSRV) /
- sizeof (struct smb_to_posix_error); i++) {
+ sizeof(mapping_table_ERRSRV) /
+ sizeof(struct smb_to_posix_error); i++) {
if (mapping_table_ERRSRV[i].smb_err == 0)
break;
else if (mapping_table_ERRSRV[i].smb_err ==
@@ -837,14 +867,14 @@ map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
unsigned int
smbCalcSize(struct smb_hdr *ptr)
{
- return (sizeof (struct smb_hdr) + (2 * ptr->WordCount) +
+ return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
2 /* size of the bcc field */ + BCC(ptr));
}
unsigned int
smbCalcSize_LE(struct smb_hdr *ptr)
{
- return (sizeof (struct smb_hdr) + (2 * ptr->WordCount) +
+ return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
2 /* size of the bcc field */ + le16_to_cpu(BCC_LE(ptr)));
}
OpenPOWER on IntegriCloud