diff options
Diffstat (limited to 'fs/nfs/nfs4namespace.c')
-rw-r--r-- | fs/nfs/nfs4namespace.c | 86 |
1 files changed, 81 insertions, 5 deletions
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 9c8eca315f43..a7f3dedc4ec7 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c | |||
@@ -52,6 +52,30 @@ Elong: | |||
52 | } | 52 | } |
53 | 53 | ||
54 | /* | 54 | /* |
55 | * return the path component of "<server>:<path>" | ||
56 | * nfspath - the "<server>:<path>" string | ||
57 | * end - one past the last char that could contain "<server>:" | ||
58 | * returns NULL on failure | ||
59 | */ | ||
60 | static char *nfs_path_component(const char *nfspath, const char *end) | ||
61 | { | ||
62 | char *p; | ||
63 | |||
64 | if (*nfspath == '[') { | ||
65 | /* parse [] escaped IPv6 addrs */ | ||
66 | p = strchr(nfspath, ']'); | ||
67 | if (p != NULL && ++p < end && *p == ':') | ||
68 | return p + 1; | ||
69 | } else { | ||
70 | /* otherwise split on first colon */ | ||
71 | p = strchr(nfspath, ':'); | ||
72 | if (p != NULL && p < end) | ||
73 | return p + 1; | ||
74 | } | ||
75 | return NULL; | ||
76 | } | ||
77 | |||
78 | /* | ||
55 | * Determine the mount path as a string | 79 | * Determine the mount path as a string |
56 | */ | 80 | */ |
57 | static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen) | 81 | static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen) |
@@ -59,9 +83,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen) | |||
59 | char *limit; | 83 | char *limit; |
60 | char *path = nfs_path(&limit, dentry, buffer, buflen); | 84 | char *path = nfs_path(&limit, dentry, buffer, buflen); |
61 | if (!IS_ERR(path)) { | 85 | if (!IS_ERR(path)) { |
62 | char *colon = strchr(path, ':'); | 86 | char *path_component = nfs_path_component(path, limit); |
63 | if (colon && colon < limit) | 87 | if (path_component) |
64 | path = colon + 1; | 88 | return path_component; |
65 | } | 89 | } |
66 | return path; | 90 | return path; |
67 | } | 91 | } |
@@ -108,6 +132,58 @@ static size_t nfs_parse_server_name(char *string, size_t len, | |||
108 | return ret; | 132 | return ret; |
109 | } | 133 | } |
110 | 134 | ||
135 | static rpc_authflavor_t nfs4_negotiate_security(struct inode *inode, struct qstr *name) | ||
136 | { | ||
137 | struct page *page; | ||
138 | struct nfs4_secinfo_flavors *flavors; | ||
139 | rpc_authflavor_t flavor; | ||
140 | int err; | ||
141 | |||
142 | page = alloc_page(GFP_KERNEL); | ||
143 | if (!page) | ||
144 | return -ENOMEM; | ||
145 | flavors = page_address(page); | ||
146 | |||
147 | err = nfs4_proc_secinfo(inode, name, flavors); | ||
148 | if (err < 0) { | ||
149 | flavor = err; | ||
150 | goto out; | ||
151 | } | ||
152 | |||
153 | flavor = nfs_find_best_sec(flavors); | ||
154 | |||
155 | out: | ||
156 | put_page(page); | ||
157 | return flavor; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * Please call rpc_shutdown_client() when you are done with this client. | ||
162 | */ | ||
163 | struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *clnt, struct inode *inode, | ||
164 | struct qstr *name) | ||
165 | { | ||
166 | struct rpc_clnt *clone; | ||
167 | struct rpc_auth *auth; | ||
168 | rpc_authflavor_t flavor; | ||
169 | |||
170 | flavor = nfs4_negotiate_security(inode, name); | ||
171 | if (flavor < 0) | ||
172 | return ERR_PTR(flavor); | ||
173 | |||
174 | clone = rpc_clone_client(clnt); | ||
175 | if (IS_ERR(clone)) | ||
176 | return clone; | ||
177 | |||
178 | auth = rpcauth_create(flavor, clone); | ||
179 | if (!auth) { | ||
180 | rpc_shutdown_client(clone); | ||
181 | clone = ERR_PTR(-EIO); | ||
182 | } | ||
183 | |||
184 | return clone; | ||
185 | } | ||
186 | |||
111 | static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, | 187 | static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, |
112 | char *page, char *page2, | 188 | char *page, char *page2, |
113 | const struct nfs4_fs_location *location) | 189 | const struct nfs4_fs_location *location) |
@@ -224,7 +300,7 @@ out: | |||
224 | * @dentry - dentry of referral | 300 | * @dentry - dentry of referral |
225 | * | 301 | * |
226 | */ | 302 | */ |
227 | struct vfsmount *nfs_do_refmount(struct dentry *dentry) | 303 | struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry) |
228 | { | 304 | { |
229 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); | 305 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); |
230 | struct dentry *parent; | 306 | struct dentry *parent; |
@@ -250,7 +326,7 @@ struct vfsmount *nfs_do_refmount(struct dentry *dentry) | |||
250 | dprintk("%s: getting locations for %s/%s\n", | 326 | dprintk("%s: getting locations for %s/%s\n", |
251 | __func__, parent->d_name.name, dentry->d_name.name); | 327 | __func__, parent->d_name.name, dentry->d_name.name); |
252 | 328 | ||
253 | err = nfs4_proc_fs_locations(parent->d_inode, &dentry->d_name, fs_locations, page); | 329 | err = nfs4_proc_fs_locations(client, parent->d_inode, &dentry->d_name, fs_locations, page); |
254 | dput(parent); | 330 | dput(parent); |
255 | if (err != 0 || | 331 | if (err != 0 || |
256 | fs_locations->nlocations <= 0 || | 332 | fs_locations->nlocations <= 0 || |