summaryrefslogtreecommitdiffstats
path: root/fs/cifs/misc.c
diff options
context:
space:
mode:
authorSamuel Cabrero <scabrero@suse.de>2020-11-30 19:02:47 +0100
committerSteve French <stfrench@microsoft.com>2020-12-14 09:16:22 -0600
commita87e67254bc5da9ca6f3899e354fcf03d12cfd10 (patch)
treeb930a8acd6fe97cf896e7e56be5875af6d3ab273 /fs/cifs/misc.c
parenta2a52a8a3601c37a68b31b734f5a06af8a7903f1 (diff)
downloadlinux-a87e67254bc5da9ca6f3899e354fcf03d12cfd10.tar.gz
linux-a87e67254bc5da9ca6f3899e354fcf03d12cfd10.tar.bz2
linux-a87e67254bc5da9ca6f3899e354fcf03d12cfd10.zip
cifs: Make extract_hostname function public
Move the function to misc.c and give it a public header. Signed-off-by: Samuel Cabrero <scabrero@suse.de> Reviewed-by: Aurelien Aptel <aaptel@suse.com> Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifs/misc.c')
-rw-r--r--fs/cifs/misc.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 1c14cf01dbef..3d5cc25c167f 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -1195,3 +1195,35 @@ out:
cifs_put_tcon_super(sb);
return rc;
}
+
+/* extract the host portion of the UNC string */
+char *extract_hostname(const char *unc)
+{
+ const char *src;
+ char *dst, *delim;
+ unsigned int len;
+
+ /* skip double chars at beginning of string */
+ /* BB: check validity of these bytes? */
+ if (strlen(unc) < 3)
+ return ERR_PTR(-EINVAL);
+ for (src = unc; *src && *src == '\\'; src++)
+ ;
+ if (!*src)
+ return ERR_PTR(-EINVAL);
+
+ /* delimiter between hostname and sharename is always '\\' now */
+ delim = strchr(src, '\\');
+ if (!delim)
+ return ERR_PTR(-EINVAL);
+
+ len = delim - src;
+ dst = kmalloc((len + 1), GFP_KERNEL);
+ if (dst == NULL)
+ return ERR_PTR(-ENOMEM);
+
+ memcpy(dst, src, len);
+ dst[len] = '\0';
+
+ return dst;
+}