Commit 047092ff authored by Steve French's avatar Steve French

cifs: cleanup misc.c

misc.c was getting a little large, move two of the UNC parsing relating
functions to a new C file unc.c which makes the coding of the
upcoming witness protocol patch series a little cleaner as well.
Suggested-by: default avatarRafal Szczesniak <rafal@elbingbrewery.org>
Reviewed-by: default avatarAurelien Aptel <aaptel@suse.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent bc044994
...@@ -8,7 +8,7 @@ obj-$(CONFIG_CIFS) += cifs.o ...@@ -8,7 +8,7 @@ obj-$(CONFIG_CIFS) += cifs.o
cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \ cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \
inode.o link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \ inode.o link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
cifs_unicode.o nterr.o cifsencrypt.o \ cifs_unicode.o nterr.o cifsencrypt.o \
readdir.o ioctl.o sess.o export.o smb1ops.o winucase.o \ readdir.o ioctl.o sess.o export.o smb1ops.o unc.o winucase.o \
smb2ops.o smb2maperror.o smb2transport.o \ smb2ops.o smb2maperror.o smb2transport.o \
smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o
......
...@@ -1195,59 +1195,3 @@ int update_super_prepath(struct cifs_tcon *tcon, char *prefix) ...@@ -1195,59 +1195,3 @@ int update_super_prepath(struct cifs_tcon *tcon, char *prefix)
cifs_put_tcon_super(sb); cifs_put_tcon_super(sb);
return rc; 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;
}
char *extract_sharename(const char *unc)
{
const char *src;
char *delim, *dst;
int len;
/* skip double chars at the beginning */
src = unc + 2;
/* share name is always preceded by '\\' now */
delim = strchr(src, '\\');
if (!delim)
return ERR_PTR(-EINVAL);
delim++;
len = strlen(delim);
/* caller has to free the memory */
dst = kstrndup(delim, len, GFP_KERNEL);
if (!dst)
return ERR_PTR(-ENOMEM);
return dst;
}
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2020, Microsoft Corporation.
*
* Author(s): Steve French <stfrench@microsoft.com>
* Suresh Jayaraman <sjayaraman@suse.de>
* Jeff Layton <jlayton@kernel.org>
*/
#include <linux/slab.h>
#include "cifsproto.h"
/* 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;
}
char *extract_sharename(const char *unc)
{
const char *src;
char *delim, *dst;
int len;
/* skip double chars at the beginning */
src = unc + 2;
/* share name is always preceded by '\\' now */
delim = strchr(src, '\\');
if (!delim)
return ERR_PTR(-EINVAL);
delim++;
len = strlen(delim);
/* caller has to free the memory */
dst = kstrndup(delim, len, GFP_KERNEL);
if (!dst)
return ERR_PTR(-ENOMEM);
return dst;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment