1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020, Microsoft Corporation.
5 * Author(s): Steve French <stfrench@microsoft.com>
6 * Suresh Jayaraman <sjayaraman@suse.de>
7 * Jeff Layton <jlayton@kernel.org>
11 #include <linux/slab.h>
12 #include <linux/inet.h>
13 #include <linux/ctype.h>
15 #include "cifsproto.h"
17 /* extract the host portion of the UNC string */
18 char *extract_hostname(const char *unc
)
24 /* skip double chars at beginning of string */
25 /* BB: check validity of these bytes? */
27 return ERR_PTR(-EINVAL
);
28 for (src
= unc
; *src
&& *src
== '\\'; src
++)
31 return ERR_PTR(-EINVAL
);
33 /* delimiter between hostname and sharename is always '\\' now */
34 delim
= strchr(src
, '\\');
36 return ERR_PTR(-EINVAL
);
39 dst
= kmalloc((len
+ 1), GFP_KERNEL
);
41 return ERR_PTR(-ENOMEM
);
43 memcpy(dst
, src
, len
);
49 char *extract_sharename(const char *unc
)
55 /* skip double chars at the beginning */
58 /* share name is always preceded by '\\' now */
59 delim
= strchr(src
, '\\');
61 return ERR_PTR(-EINVAL
);
65 /* caller has to free the memory */
66 dst
= kstrndup(delim
, len
, GFP_KERNEL
);
68 return ERR_PTR(-ENOMEM
);