/* * Work out the length that an NFSv4 path would render to as a standard posix * path, with a leading slash but no terminating slash.
*/ static ssize_t nfs4_pathname_len(conststruct nfs4_pathname *pathname)
{
ssize_t len = 0; int i;
for (i = 0; i < pathname->ncomponents; i++) { conststruct nfs4_string *component = &pathname->components[i];
if (component->len > NAME_MAX) goto too_long;
len += 1 + component->len; /* Adding "/foo" */ if (len > PATH_MAX) goto too_long;
} return len;
too_long: return -ENAMETOOLONG;
}
/* * Convert the NFSv4 pathname components into a standard posix path.
*/ staticchar *nfs4_pathname_string(conststruct nfs4_pathname *pathname, unsignedshort *_len)
{
ssize_t len; char *buf, *p; int i;
len = nfs4_pathname_len(pathname); if (len < 0) return ERR_PTR(len);
*_len = len;
p = buf = kmalloc(len + 1, GFP_KERNEL); if (!buf) return ERR_PTR(-ENOMEM);
for (i = 0; i < pathname->ncomponents; i++) { conststruct nfs4_string *component = &pathname->components[i];
*p++ = '/';
memcpy(p, component->data, component->len);
p += component->len;
}
*p = 0; return buf;
}
/* * return the path component of "<server>:<path>" * nfspath - the "<server>:<path>" string * end - one past the last char that could contain "<server>:" * returns NULL on failure
*/ staticchar *nfs_path_component(constchar *nfspath, constchar *end)
{ char *p;
if (*nfspath == '[') { /* parse [] escaped IPv6 addrs */
p = strchr(nfspath, ']'); if (p != NULL && ++p < end && *p == ':') return p + 1;
} else { /* otherwise split on first colon */
p = strchr(nfspath, ':'); if (p != NULL && p < end) return p + 1;
} return NULL;
}
/* * Determine the mount path as a string
*/ staticchar *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
{ char *limit; char *path = nfs_path(&limit, dentry, buffer, buflen,
NFS_PATH_CANONICAL); if (!IS_ERR(path)) { char *path_component = nfs_path_component(path, limit); if (path_component) return path_component;
} return path;
}
/* * Check that fs_locations::fs_root [RFC3530 6.3] is a prefix for what we * believe to be the server path to this dentry
*/ staticint nfs4_validate_fspath(struct dentry *dentry, conststruct nfs4_fs_locations *locations, struct nfs_fs_context *ctx)
{ constchar *path; char *fs_path; unsignedshort len; char *buf; int n;
buf = kmalloc(4096, GFP_KERNEL); if (!buf) return -ENOMEM;
n = strncmp(path, fs_path, len);
kfree(buf);
kfree(fs_path); if (n != 0) {
dprintk("%s: path %s does not begin with fsroot %s\n",
__func__, path, ctx->nfs_server.export_path); return -ENOENT;
}
ret = rpc_pton(net, string, len, sa, salen); if (ret == 0) {
ret = rpc_uaddr2sockaddr(net, string, len, sa, salen); if (ret == 0) {
ret = nfs_dns_resolve_name(net, string, len, ss, salen); if (ret < 0)
ret = 0;
}
} elseif (port) {
rpc_set_port(sa, port);
} return ret;
}
/** * nfs_find_best_sec - Find a security mechanism supported locally * @clnt: pointer to rpc_clnt * @server: NFS server struct * @flavors: List of security tuples returned by SECINFO procedure * * Return an rpc client that uses the first security mechanism in * "flavors" that is locally supported. The "flavors" array * is searched in the order returned from the server, per RFC 3530 * recommendation and each flavor is checked for membership in the * sec= mount option list if it exists. * * Return -EPERM if no matching flavor is found in the array. * * Please call rpc_shutdown_client() when you are done with this rpc client. *
*/ staticstruct rpc_clnt *nfs_find_best_sec(struct rpc_clnt *clnt, struct nfs_server *server, struct nfs4_secinfo_flavors *flavors)
{
rpc_authflavor_t pflavor; struct nfs4_secinfo4 *secinfo; unsignedint i;
for (i = 0; i < flavors->num_flavors; i++) {
secinfo = &flavors->flavors[i];
switch (secinfo->flavor) { case RPC_AUTH_NULL: case RPC_AUTH_UNIX: case RPC_AUTH_GSS:
pflavor = rpcauth_get_pseudoflavor(secinfo->flavor,
&secinfo->flavor_info); /* does the pseudoflavor match a sec= mount opt? */ if (pflavor != RPC_AUTH_MAXFLAVOR &&
nfs_auth_info_match(&server->auth_info, pflavor)) { struct rpc_clnt *new; struct rpc_cred *cred;
/* Cloning creates an rpc_auth for the flavor */ new = rpc_clone_client_set_auth(clnt, pflavor); if (IS_ERR(new)) continue; /** * Check that the user actually can use the * flavor. This is mostly for RPC_AUTH_GSS * where cr_init obtains a gss context
*/
cred = rpcauth_lookupcred(new->cl_auth, 0); if (IS_ERR(cred)) {
rpc_shutdown_client(new); continue;
}
put_rpccred(cred); returnnew;
}
}
} return ERR_PTR(-EPERM);
}
/** * nfs4_negotiate_security - in response to an NFS4ERR_WRONGSEC on lookup, * return an rpc_clnt that uses the best available security flavor with * respect to the secinfo flavor list and the sec= mount options. * * @clnt: RPC client to clone * @inode: directory inode * @name: lookup name * * Please call rpc_shutdown_client() when you are done with this rpc client.
*/ struct rpc_clnt *
nfs4_negotiate_security(struct rpc_clnt *clnt, struct inode *inode, conststruct qstr *name)
{ struct page *page; struct nfs4_secinfo_flavors *flavors; struct rpc_clnt *new; int err;
page = alloc_page(GFP_KERNEL); if (!page) return ERR_PTR(-ENOMEM);
flavors = page_address(page);
err = nfs4_proc_secinfo(inode, name, flavors); if (err < 0) { new = ERR_PTR(err); goto out;
}
new = nfs_find_best_sec(clnt, NFS_SERVER(inode), flavors);
/* Allocate a buffer big enough to hold any of the hostnames plus a * terminating char and also a buffer big enough to hold the hostname * plus a colon plus the path.
*/
len = 0; for (s = 0; s < location->nservers; s++) { conststruct nfs4_string *buf = &location->servers[s]; if (buf->len > len)
len = buf->len;
}
p = source;
memcpy(p, buf->data, buf->len);
p += buf->len;
*p++ = ':';
memcpy(p, ctx->nfs_server.export_path, ctx->nfs_server.export_path_len);
p += ctx->nfs_server.export_path_len;
*p = 0;
ret = nfs4_get_referral_tree(fc); if (ret == 0) return 0;
}
return ret;
}
/** * nfs_follow_referral - set up mountpoint when hitting a referral on moved error * @fc: pointer to struct nfs_fs_context * @locations: array of NFSv4 server location information *
*/ staticint nfs_follow_referral(struct fs_context *fc, conststruct nfs4_fs_locations *locations)
{ struct nfs_fs_context *ctx = nfs_fc2context(fc); int loc, error;
if (locations == NULL || locations->nlocations <= 0) return -ENOENT;
dprintk("%s: referral at %pd2\n", __func__, ctx->clone_data.dentry);
/* Ensure fs path is a prefix of current dentry path */
error = nfs4_validate_fspath(ctx->clone_data.dentry, locations, ctx); if (error < 0) return error;
error = -ENOENT; for (loc = 0; loc < locations->nlocations; loc++) { conststruct nfs4_fs_location *location = &locations->locations[loc];
/* Look it up again to get its attributes and sec flavor */
client = nfs4_proc_lookup_mountpoint(dir, dentry, ctx->mntfh,
ctx->clone_data.fattr);
dput(parent); if (IS_ERR(client)) return PTR_ERR(client);
ctx->selected_flavor = client->cl_auth->au_flavor; if (ctx->clone_data.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
ret = nfs_do_refmount(fc, client);
} else {
ret = nfs_do_submount(fc);
}
rpc_shutdown_client(client); return ret;
}
/* * Try one location from the fs_locations array. * * Returns zero on success, or a negative errno value.
*/ staticint nfs4_try_replacing_one_location(struct nfs_server *server, char *page, char *page2, conststruct nfs4_fs_location *location)
{ struct net *net = rpc_net_ns(server->client); struct sockaddr_storage *sap; unsignedint s;
size_t salen; int error;
sap = kmalloc(sizeof(*sap), GFP_KERNEL); if (sap == NULL) return -ENOMEM;
error = -ENOENT; for (s = 0; s < location->nservers; s++) { conststruct nfs4_string *buf = &location->servers[s]; char *hostname;
if (buf->len <= 0 || buf->len > PAGE_SIZE) continue;
if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len) != NULL) continue;
/** * nfs4_replace_transport - set up transport to destination server * * @server: export being migrated * @locations: fs_locations array * * Returns zero on success, or a negative errno value. * * The client tries all the entries in the "locations" array, in the * order returned by the server, until one works or the end of the * array is reached.
*/ int nfs4_replace_transport(struct nfs_server *server, conststruct nfs4_fs_locations *locations)
{ char *page = NULL, *page2 = NULL; int loc, error;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.