diff options
Diffstat (limited to 'fs/nfs/namespace.c')
-rw-r--r-- | fs/nfs/namespace.c | 140 |
1 files changed, 18 insertions, 122 deletions
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index 1807866bb3ab..08b9c93675da 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c | |||
@@ -26,11 +26,6 @@ static LIST_HEAD(nfs_automount_list); | |||
26 | static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); | 26 | static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); |
27 | int nfs_mountpoint_expiry_timeout = 500 * HZ; | 27 | int nfs_mountpoint_expiry_timeout = 500 * HZ; |
28 | 28 | ||
29 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, | ||
30 | struct nfs_fh *fh, | ||
31 | struct nfs_fattr *fattr, | ||
32 | rpc_authflavor_t authflavor); | ||
33 | |||
34 | /* | 29 | /* |
35 | * nfs_path - reconstruct the path given an arbitrary dentry | 30 | * nfs_path - reconstruct the path given an arbitrary dentry |
36 | * @base - used to return pointer to the end of devname part of path | 31 | * @base - used to return pointer to the end of devname part of path |
@@ -118,99 +113,6 @@ Elong: | |||
118 | return ERR_PTR(-ENAMETOOLONG); | 113 | return ERR_PTR(-ENAMETOOLONG); |
119 | } | 114 | } |
120 | 115 | ||
121 | #ifdef CONFIG_NFS_V4 | ||
122 | rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *flavors) | ||
123 | { | ||
124 | struct gss_api_mech *mech; | ||
125 | struct xdr_netobj oid; | ||
126 | int i; | ||
127 | rpc_authflavor_t pseudoflavor = RPC_AUTH_UNIX; | ||
128 | |||
129 | for (i = 0; i < flavors->num_flavors; i++) { | ||
130 | struct nfs4_secinfo_flavor *flavor; | ||
131 | flavor = &flavors->flavors[i]; | ||
132 | |||
133 | if (flavor->flavor == RPC_AUTH_NULL || flavor->flavor == RPC_AUTH_UNIX) { | ||
134 | pseudoflavor = flavor->flavor; | ||
135 | break; | ||
136 | } else if (flavor->flavor == RPC_AUTH_GSS) { | ||
137 | oid.len = flavor->gss.sec_oid4.len; | ||
138 | oid.data = flavor->gss.sec_oid4.data; | ||
139 | mech = gss_mech_get_by_OID(&oid); | ||
140 | if (!mech) | ||
141 | continue; | ||
142 | pseudoflavor = gss_svc_to_pseudoflavor(mech, flavor->gss.service); | ||
143 | gss_mech_put(mech); | ||
144 | break; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | return pseudoflavor; | ||
149 | } | ||
150 | |||
151 | static int nfs_negotiate_security(const struct dentry *parent, | ||
152 | const struct dentry *dentry, | ||
153 | rpc_authflavor_t *flavor) | ||
154 | { | ||
155 | struct page *page; | ||
156 | struct nfs4_secinfo_flavors *flavors; | ||
157 | int (*secinfo)(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); | ||
158 | int ret = -EPERM; | ||
159 | |||
160 | secinfo = NFS_PROTO(parent->d_inode)->secinfo; | ||
161 | if (secinfo != NULL) { | ||
162 | page = alloc_page(GFP_KERNEL); | ||
163 | if (!page) { | ||
164 | ret = -ENOMEM; | ||
165 | goto out; | ||
166 | } | ||
167 | flavors = page_address(page); | ||
168 | ret = secinfo(parent->d_inode, &dentry->d_name, flavors); | ||
169 | *flavor = nfs_find_best_sec(flavors); | ||
170 | put_page(page); | ||
171 | } | ||
172 | |||
173 | out: | ||
174 | return ret; | ||
175 | } | ||
176 | |||
177 | static int nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent, | ||
178 | struct dentry *dentry, struct path *path, | ||
179 | struct nfs_fh *fh, struct nfs_fattr *fattr, | ||
180 | rpc_authflavor_t *flavor) | ||
181 | { | ||
182 | struct rpc_clnt *clone; | ||
183 | struct rpc_auth *auth; | ||
184 | int err; | ||
185 | |||
186 | err = nfs_negotiate_security(parent, path->dentry, flavor); | ||
187 | if (err < 0) | ||
188 | goto out; | ||
189 | clone = rpc_clone_client(server->client); | ||
190 | auth = rpcauth_create(*flavor, clone); | ||
191 | if (!auth) { | ||
192 | err = -EIO; | ||
193 | goto out_shutdown; | ||
194 | } | ||
195 | err = server->nfs_client->rpc_ops->lookup(clone, parent->d_inode, | ||
196 | &path->dentry->d_name, | ||
197 | fh, fattr); | ||
198 | out_shutdown: | ||
199 | rpc_shutdown_client(clone); | ||
200 | out: | ||
201 | return err; | ||
202 | } | ||
203 | #else /* CONFIG_NFS_V4 */ | ||
204 | static inline int nfs_lookup_with_sec(struct nfs_server *server, | ||
205 | struct dentry *parent, struct dentry *dentry, | ||
206 | struct path *path, struct nfs_fh *fh, | ||
207 | struct nfs_fattr *fattr, | ||
208 | rpc_authflavor_t *flavor) | ||
209 | { | ||
210 | return -EPERM; | ||
211 | } | ||
212 | #endif /* CONFIG_NFS_V4 */ | ||
213 | |||
214 | /* | 116 | /* |
215 | * nfs_d_automount - Handle crossing a mountpoint on the server | 117 | * nfs_d_automount - Handle crossing a mountpoint on the server |
216 | * @path - The mountpoint | 118 | * @path - The mountpoint |
@@ -227,11 +129,8 @@ struct vfsmount *nfs_d_automount(struct path *path) | |||
227 | { | 129 | { |
228 | struct vfsmount *mnt; | 130 | struct vfsmount *mnt; |
229 | struct nfs_server *server = NFS_SERVER(path->dentry->d_inode); | 131 | struct nfs_server *server = NFS_SERVER(path->dentry->d_inode); |
230 | struct dentry *parent; | ||
231 | struct nfs_fh *fh = NULL; | 132 | struct nfs_fh *fh = NULL; |
232 | struct nfs_fattr *fattr = NULL; | 133 | struct nfs_fattr *fattr = NULL; |
233 | int err; | ||
234 | rpc_authflavor_t flavor = RPC_AUTH_UNIX; | ||
235 | 134 | ||
236 | dprintk("--> nfs_d_automount()\n"); | 135 | dprintk("--> nfs_d_automount()\n"); |
237 | 136 | ||
@@ -247,23 +146,7 @@ struct vfsmount *nfs_d_automount(struct path *path) | |||
247 | 146 | ||
248 | dprintk("%s: enter\n", __func__); | 147 | dprintk("%s: enter\n", __func__); |
249 | 148 | ||
250 | /* Look it up again to get its attributes */ | 149 | mnt = server->nfs_client->rpc_ops->submount(server, path->dentry, fh, fattr); |
251 | parent = dget_parent(path->dentry); | ||
252 | err = server->nfs_client->rpc_ops->lookup(server->client, parent->d_inode, | ||
253 | &path->dentry->d_name, | ||
254 | fh, fattr); | ||
255 | if (err == -EPERM && NFS_PROTO(parent->d_inode)->secinfo != NULL) | ||
256 | err = nfs_lookup_with_sec(server, parent, path->dentry, path, fh, fattr, &flavor); | ||
257 | dput(parent); | ||
258 | if (err != 0) { | ||
259 | mnt = ERR_PTR(err); | ||
260 | goto out; | ||
261 | } | ||
262 | |||
263 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) | ||
264 | mnt = nfs_do_refmount(path->dentry); | ||
265 | else | ||
266 | mnt = nfs_do_submount(path->dentry, fh, fattr, flavor); | ||
267 | if (IS_ERR(mnt)) | 150 | if (IS_ERR(mnt)) |
268 | goto out; | 151 | goto out; |
269 | 152 | ||
@@ -336,10 +219,8 @@ static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, | |||
336 | * @authflavor - security flavor to use when performing the mount | 219 | * @authflavor - security flavor to use when performing the mount |
337 | * | 220 | * |
338 | */ | 221 | */ |
339 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, | 222 | struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, |
340 | struct nfs_fh *fh, | 223 | struct nfs_fattr *fattr, rpc_authflavor_t authflavor) |
341 | struct nfs_fattr *fattr, | ||
342 | rpc_authflavor_t authflavor) | ||
343 | { | 224 | { |
344 | struct nfs_clone_mount mountdata = { | 225 | struct nfs_clone_mount mountdata = { |
345 | .sb = dentry->d_sb, | 226 | .sb = dentry->d_sb, |
@@ -372,3 +253,18 @@ out: | |||
372 | dprintk("<-- nfs_do_submount() = %p\n", mnt); | 253 | dprintk("<-- nfs_do_submount() = %p\n", mnt); |
373 | return mnt; | 254 | return mnt; |
374 | } | 255 | } |
256 | |||
257 | struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry, | ||
258 | struct nfs_fh *fh, struct nfs_fattr *fattr) | ||
259 | { | ||
260 | int err; | ||
261 | struct dentry *parent = dget_parent(dentry); | ||
262 | |||
263 | /* Look it up again to get its attributes */ | ||
264 | err = server->nfs_client->rpc_ops->lookup(parent->d_inode, &dentry->d_name, fh, fattr); | ||
265 | dput(parent); | ||
266 | if (err != 0) | ||
267 | return ERR_PTR(err); | ||
268 | |||
269 | return nfs_do_submount(dentry, fh, fattr, server->client->cl_auth->au_flavor); | ||
270 | } | ||