diff options
author | Sepherosa Ziehau <sephe@FreeBSD.org> | 2017-05-04 01:46:04 +0000 |
---|---|---|
committer | Sepherosa Ziehau <sephe@FreeBSD.org> | 2017-05-04 01:46:04 +0000 |
commit | c321779676d0722f5d0a65c30e8b23b8a6547364 (patch) | |
tree | 4ef55341efcf4a228a07be3b01597490b53caccd /contrib/hyperv/tools | |
parent | a8fc61d51a53345b7267b1a5e83077c52d6a9b59 (diff) | |
download | src-c321779676d0722f5d0a65c30e8b23b8a6547364.tar.gz src-c321779676d0722f5d0a65c30e8b23b8a6547364.zip |
hyperv/kvp: Fix pool direcrory and file permission
PR: 209385
MFC after: 2 weeks
Sponsored by: Microsoft
Notes
Notes:
svn path=/head/; revision=317783
Diffstat (limited to 'contrib/hyperv/tools')
-rw-r--r-- | contrib/hyperv/tools/hv_kvp_daemon.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/contrib/hyperv/tools/hv_kvp_daemon.c b/contrib/hyperv/tools/hv_kvp_daemon.c index 50bd27628b30..2770a8d6bc97 100644 --- a/contrib/hyperv/tools/hv_kvp_daemon.c +++ b/contrib/hyperv/tools/hv_kvp_daemon.c @@ -61,6 +61,10 @@ typedef uint16_t __u16; typedef uint32_t __u32; typedef uint64_t __u64; +#define POOL_FILE_MODE (S_IRUSR | S_IWUSR) +#define POOL_DIR_MODE (POOL_FILE_MODE | S_IXUSR) +#define POOL_DIR "/var/db/hyperv/pool" + /* * ENUM Data */ @@ -285,11 +289,12 @@ kvp_file_init(void) int i; int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK; - if (mkdir("/var/db/hyperv/pool", S_IRUSR | S_IWUSR | S_IROTH) < 0 && + if (mkdir(POOL_DIR, POOL_DIR_MODE) < 0 && (errno != EEXIST && errno != EISDIR)) { KVP_LOG(LOG_ERR, " Failed to create /var/db/hyperv/pool\n"); exit(EXIT_FAILURE); } + chmod(POOL_DIR, POOL_DIR_MODE); /* fix old mistake */ for (i = 0; i < HV_KVP_POOL_COUNT; i++) { @@ -297,11 +302,12 @@ kvp_file_init(void) records_read = 0; num_blocks = 1; snprintf(fname, MAX_FILE_NAME, "/var/db/hyperv/pool/.kvp_pool_%d", i); - fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH); + fd = open(fname, O_RDWR | O_CREAT, POOL_FILE_MODE); if (fd == -1) { return (1); } + fchmod(fd, POOL_FILE_MODE); /* fix old mistake */ filep = fopen(fname, "r"); |