zpool command complains about /etc/exports.d

If the /etc/exports.d directory does not exist, then we should only
create it when we're performing an action which already requires root
privileges.

This commit moves the directory creation to the enable/disable code
path which ensures that we have the appropriate privileges.

Reviewed-by: Richard Elling <Richard.Elling@RichardElling.com>
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: George Wilson <gwilson@delphix.com>
Closes #10785
Closes #10934
This commit is contained in:
George Wilson
2020-09-25 15:09:40 -05:00
committed by GitHub
parent a5c77dc4d5
commit bd76bcb36d
2 changed files with 65 additions and 44 deletions
+24 -14
View File
@@ -228,21 +228,33 @@ nfs_copy_entries(char *filename, const char *mountpoint)
int error = SA_OK;
char *line;
/*
* If the file doesn't exist then there is nothing more
* we need to do.
*/
FILE *oldfp = fopen(ZFS_EXPORTS_FILE, "r");
if (oldfp == NULL)
return (SA_OK);
FILE *newfp = fopen(filename, "w+");
fputs(FILE_HEADER, newfp);
while ((line = zgetline(oldfp, mountpoint)) != NULL)
fprintf(newfp, "%s\n", line);
if (ferror(oldfp) != 0) {
error = ferror(oldfp);
if (newfp == NULL) {
fprintf(stderr, "failed to open %s file: %s", filename,
strerror(errno));
fclose(oldfp);
return (SA_SYSTEM_ERR);
}
fputs(FILE_HEADER, newfp);
/*
* The ZFS_EXPORTS_FILE may not exist yet. If that's the
* case then just write out the new file.
*/
if (oldfp != NULL) {
while ((line = zgetline(oldfp, mountpoint)) != NULL)
fprintf(newfp, "%s\n", line);
if (ferror(oldfp) != 0) {
error = ferror(oldfp);
}
if (fclose(oldfp) != 0) {
fprintf(stderr, "Unable to close file %s: %s\n",
filename, strerror(errno));
error = error != 0 ? error : SA_SYSTEM_ERR;
}
}
if (error == 0 && ferror(newfp) != 0) {
error = ferror(newfp);
}
@@ -252,8 +264,6 @@ nfs_copy_entries(char *filename, const char *mountpoint)
filename, strerror(errno));
error = error != 0 ? error : SA_SYSTEM_ERR;
}
fclose(oldfp);
return (error);
}