0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/fs.h>
0011 #include <linux/slab.h>
0012 #include <linux/inet.h>
0013 #include <linux/ctype.h>
0014 #include "cifsglob.h"
0015 #include "cifsproto.h"
0016
0017
0018 char *extract_hostname(const char *unc)
0019 {
0020 const char *src;
0021 char *dst, *delim;
0022 unsigned int len;
0023
0024
0025
0026 if (strlen(unc) < 3)
0027 return ERR_PTR(-EINVAL);
0028 for (src = unc; *src && *src == '\\'; src++)
0029 ;
0030 if (!*src)
0031 return ERR_PTR(-EINVAL);
0032
0033
0034 delim = strchr(src, '\\');
0035 if (!delim)
0036 return ERR_PTR(-EINVAL);
0037
0038 len = delim - src;
0039 dst = kmalloc((len + 1), GFP_KERNEL);
0040 if (dst == NULL)
0041 return ERR_PTR(-ENOMEM);
0042
0043 memcpy(dst, src, len);
0044 dst[len] = '\0';
0045
0046 return dst;
0047 }
0048
0049 char *extract_sharename(const char *unc)
0050 {
0051 const char *src;
0052 char *delim, *dst;
0053
0054
0055 src = unc + 2;
0056
0057
0058 delim = strchr(src, '\\');
0059 if (!delim)
0060 return ERR_PTR(-EINVAL);
0061 delim++;
0062
0063
0064 dst = kstrdup(delim, GFP_KERNEL);
0065 if (!dst)
0066 return ERR_PTR(-ENOMEM);
0067
0068 return dst;
0069 }