forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: Rafal Szczesniak <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
- Loading branch information
Steve French
committed
Dec 14, 2020
1 parent
bc04499
commit 047092f
Showing
3 changed files
with
68 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (C) 2020, Microsoft Corporation. | ||
* | ||
* Author(s): Steve French <[email protected]> | ||
* Suresh Jayaraman <[email protected]> | ||
* Jeff Layton <[email protected]> | ||
*/ | ||
|
||
#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; | ||
} |