mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-02-04 06:14:29 +03:00
linux/libshare: nfs: don't needlessly strdup() hostspec
Reviewed-by: Don Brady <don.brady@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12067
This commit is contained in:
parent
605e03e51a
commit
9d4a44f0b8
@ -247,8 +247,8 @@ foreach_nfs_host(sa_share_impl_t impl_share, FILE *tmpfile,
|
|||||||
/*
|
/*
|
||||||
* Converts a Solaris NFS host specification to its Linux equivalent.
|
* Converts a Solaris NFS host specification to its Linux equivalent.
|
||||||
*/
|
*/
|
||||||
static int
|
static const char *
|
||||||
get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec)
|
get_linux_hostspec(const char *solaris_hostspec)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* For now we just support CIDR masks (e.g. @192.168.0.0/16) and host
|
* For now we just support CIDR masks (e.g. @192.168.0.0/16) and host
|
||||||
@ -259,16 +259,10 @@ get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec)
|
|||||||
* Solaris host specifier, e.g. @192.168.0.0/16; we just need
|
* Solaris host specifier, e.g. @192.168.0.0/16; we just need
|
||||||
* to skip the @ in this case
|
* to skip the @ in this case
|
||||||
*/
|
*/
|
||||||
*plinux_hostspec = strdup(solaris_hostspec + 1);
|
return (solaris_hostspec + 1);
|
||||||
} else {
|
} else {
|
||||||
*plinux_hostspec = strdup(solaris_hostspec);
|
return (solaris_hostspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*plinux_hostspec == NULL) {
|
|
||||||
return (SA_NO_MEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (SA_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -397,25 +391,18 @@ nfs_add_entry(FILE *tmpfile, const char *sharepath,
|
|||||||
const char *host, const char *security, const char *access_opts,
|
const char *host, const char *security, const char *access_opts,
|
||||||
void *pcookie)
|
void *pcookie)
|
||||||
{
|
{
|
||||||
int error;
|
|
||||||
char *linuxhost;
|
|
||||||
const char *linux_opts = (const char *)pcookie;
|
const char *linux_opts = (const char *)pcookie;
|
||||||
|
|
||||||
error = get_linux_hostspec(host, &linuxhost);
|
|
||||||
if (error != SA_OK)
|
|
||||||
return (error);
|
|
||||||
|
|
||||||
if (linux_opts == NULL)
|
if (linux_opts == NULL)
|
||||||
linux_opts = "";
|
linux_opts = "";
|
||||||
|
|
||||||
if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath, linuxhost,
|
if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath,
|
||||||
security, access_opts, linux_opts) < 0) {
|
get_linux_hostspec(host), security, access_opts,
|
||||||
|
linux_opts) < 0) {
|
||||||
fprintf(stderr, "failed to write to temporary file\n");
|
fprintf(stderr, "failed to write to temporary file\n");
|
||||||
free(linuxhost);
|
|
||||||
return (SA_SYSTEM_ERR);
|
return (SA_SYSTEM_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(linuxhost);
|
|
||||||
return (SA_OK);
|
return (SA_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user