diff options
author | J. Bruce Fields <bfields@citi.umich.edu> | 2010-01-09 10:44:57 -0700 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2010-01-13 15:39:14 -0500 |
commit | e0819debc9d1d322e06ca4047a125a4fd8176d13 (patch) | |
tree | 7b7650f9dd5dca9d66485b3555006204ff7e9faf /utils/mountd | |
parent | 40af0d2957a168bee50337695379313f3f88c635 (diff) | |
download | nfs-utils-e0819debc9d1d322e06ca4047a125a4fd8176d13.tar.gz nfs-utils-e0819debc9d1d322e06ca4047a125a4fd8176d13.tar.xz nfs-utils-e0819debc9d1d322e06ca4047a125a4fd8176d13.zip |
mountd: minor v4root_set cleanup, check strdup return
Move more of v4root_set into a helper function.
Also, check the return value from strdup. (We don't really handle the
error well yet--we'll end up giving negative replies to export upcalls
when we should be giving the kernel exports, resulting in spurious
-ENOENTs or -ESTALE's--but that's better than crashing with a NULL
dereference.)
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'utils/mountd')
-rw-r--r-- | utils/mountd/v4root.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c index ac800b3..7fd6af3 100644 --- a/utils/mountd/v4root.c +++ b/utils/mountd/v4root.c @@ -137,6 +137,31 @@ int pseudofs_update(char *hostname, char *path, nfs_export *source) return 0; } +static int v4root_add_parents(nfs_export *exp) +{ + char *hostname = exp->m_export.e_hostname; + char *path; + char *ptr; + + path = strdup(exp->m_export.e_path); + if (!path) + return -ENOMEM; + for (ptr = path + 1; ptr; ptr = strchr(ptr, '/')) { + int ret; + char saved; + + saved = *ptr; + *ptr = '\0'; + ret = pseudofs_update(hostname, path, exp); + if (ret) + return ret; + *ptr = saved; + ptr++; + } + free(path); + return 0; +} + /* * Create pseudo exports by running through the real export * looking at the components of the path that make up the export. @@ -148,9 +173,7 @@ void v4root_set() { nfs_export *exp; - int i; - char *path, *ptr; - char *hostname; + int i, ret; if (!v4root_needed) return; @@ -159,8 +182,6 @@ v4root_set() for (i = 0; i < MCL_MAXTYPES; i++) { for (exp = exportlist[i].p_head; exp; exp = exp->m_next) { - hostname = exp->m_export.e_hostname; - if (exp->m_export.e_flags & NFSEXP_V4ROOT) /* * We just added this one, so its @@ -168,19 +189,8 @@ v4root_set() */ continue; - path = strdup(exp->m_export.e_path); - for (ptr = path + 1; ptr; ptr = strchr(ptr, '/')) { - int ret; - char saved; - - saved = *ptr; - *ptr = '\0'; - ret = pseudofs_update(hostname, path, exp); - /* XXX: error handling */ - *ptr = saved; - ptr++; - } - free(path); + ret = v4root_add_parents(exp); + /* XXX: error handling! */ } } } |