Refactor lib/isc/fsaccess.c

Turn the static check_bad_bits() function used by both Unix and Windows
systems into a "private" function and extract the "private" parts of
lib/isc/fsaccess.c to lib/isc/fsaccess_common_p.h.  Instead of including
lib/isc/fsaccess.c from lib/isc/{unix,win32}/fsaccess.c, make the former
an independent C source file.

Rename lib/isc/fsaccess.c to lib/isc/fsaccess_common.c to prevent build
issues on Windows caused by multiple source files (lib/isc/fsaccess.c,
lib/isc/win32/fsaccess.c) being compiled into the same object file.

These changes improve consistency with the way "private" functions and
macros are treated elsewhere in the source tree.
This commit is contained in:
Michał Kępień 2020-06-05 13:19:49 +02:00
parent dc6b26abad
commit c3cfdb9670
8 changed files with 52 additions and 26 deletions

View file

@ -163,6 +163,7 @@ libisc_la_SOURCES = \
entropy.c \
error.c \
event.c \
fsaccess_common.c \
glob.c \
hash.c \
hp.c \
@ -211,6 +212,7 @@ libisc_la_SOURCES = \
pthreads/mutex.c \
pthreads/thread.c \
entropy_private.h \
fsaccess_common_p.h \
mem_p.h \
task_p.h \
timer_p.h

View file

@ -16,18 +16,11 @@
#include <stdbool.h>
#include <isc/fsaccess.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/types.h>
#include <isc/util.h>
/*!
* Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in
* <isc/fsaccess.h>. Could check consistency with sizeof(isc_fsaccess_t)
* and the number of bits in each function.
*/
#define STEP (ISC__FSACCESS_PERMISSIONBITS)
#define GROUP (STEP)
#define OTHER (STEP * 2)
#include "fsaccess_common_p.h"
void
isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access) {
@ -65,8 +58,8 @@ isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access) {
}
}
static isc_result_t
check_bad_bits(isc_fsaccess_t access, bool is_dir) {
isc_result_t
isc__fsaccess_check_bad_bits(isc_fsaccess_t access, bool is_dir) {
isc_fsaccess_t bits;
/*

View file

@ -0,0 +1,24 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
/*!
* Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in
* <isc/fsaccess.h>. Could check consistency with sizeof(isc_fsaccess_t)
* and the number of bits in each function.
*/
#define STEP (ISC__FSACCESS_PERMISSIONBITS)
#define GROUP (STEP)
#define OTHER (STEP * 2)
isc_result_t
isc__fsaccess_check_bad_bits(isc_fsaccess_t access, bool is_dir);

View file

@ -12,16 +12,15 @@
#include <errno.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <isc/fsaccess.h>
#include <isc/result.h>
#include <isc/types.h>
#include <isc/util.h>
#include "../fsaccess_common_p.h"
#include "errno2result.h"
/*! \file
* \brief
* The OS-independent part of the API is in lib/isc.
*/
#include "../fsaccess.c"
isc_result_t
isc_fsaccess_set(const char *path, isc_fsaccess_t access) {
struct stat statb;
@ -40,7 +39,7 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) {
return (ISC_R_INVALIDFILE);
}
result = check_bad_bits(access, is_dir);
result = isc__fsaccess_check_bad_bits(access, is_dir);
if (result != ISC_R_SUCCESS) {
return (result);
}

View file

@ -27,16 +27,15 @@
#include <sys/types.h>
#include <isc/file.h>
#include <isc/fsaccess.h>
#include <isc/result.h>
#include <isc/stat.h>
#include <isc/string.h>
#include <isc/util.h>
#include "../fsaccess_common_p.h"
#include "errno2result.h"
/*
* The OS-independent part of the API is in lib/isc.
*/
#include "../fsaccess.c"
/* Store the user account name locally */
static char username[255] = "\0";
static DWORD namelen = 0;
@ -323,7 +322,7 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) {
return (ISC_R_INVALIDFILE);
}
result = check_bad_bits(access, is_dir);
result = isc__fsaccess_check_bad_bits(access, is_dir);
if (result != ISC_R_SUCCESS) {
return (result);
}

View file

@ -349,6 +349,9 @@
<ClInclude Include="..\entropy_private.h">
<Filter>Win32 Header Files</Filter>
</ClInclude>
<ClInclude Include="..\fsaccess_common_p.h">
<Filter>Win32 Header Files</Filter>
</ClInclude>
<ClInclude Include="..\openssl_shim.h">
<Filter>Win32 Header Files</Filter>
</ClInclude>
@ -488,6 +491,9 @@
<ClCompile Include="..\entropy.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="..\fsaccess_common.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="..\hash.c">
<Filter>Library Source Files</Filter>
</ClCompile>

View file

@ -353,6 +353,7 @@ copy InstallFiles ..\Build\Release\
<ClInclude Include="include\isc\time.h" />
<ClInclude Include="include\isc\win32os.h" />
<ClInclude Include="..\entropy_private.h" />
<ClInclude Include="..\fsaccess_common_p.h" />
<ClInclude Include="..\openssl_shim.h" />
<ClInclude Include="syslog.h" />
<ClInclude Include="unistd.h" />
@ -375,6 +376,7 @@ copy InstallFiles ..\Build\Release\
<ClCompile Include="..\entropy.c" />
<ClCompile Include="..\error.c" />
<ClCompile Include="..\event.c" />
<ClCompile Include="..\fsaccess_common.c" />
<ClCompile Include="..\glob.c" />
<ClCompile Include="..\hash.c" />
<ClCompile Include="..\heap.c" />

View file

@ -1751,7 +1751,8 @@
./lib/isc/entropy_private.h C 2018,2019,2020
./lib/isc/error.c C 1998,1999,2000,2001,2004,2005,2007,2015,2016,2018,2019,2020
./lib/isc/event.c C 1998,1999,2000,2001,2004,2005,2007,2014,2016,2017,2018,2019,2020
./lib/isc/fsaccess.c C 2000,2001,2004,2005,2007,2016,2017,2018,2019,2020
./lib/isc/fsaccess_common.c C 2000,2001,2004,2005,2007,2016,2017,2018,2019,2020
./lib/isc/fsaccess_common_p.h C 2000,2001,2004,2005,2007,2016,2017,2018,2019,2020
./lib/isc/glob.c C 2020
./lib/isc/hash.c C 2003,2004,2005,2006,2007,2009,2013,2014,2015,2016,2017,2018,2019,2020
./lib/isc/heap.c C 1997,1998,1999,2000,2001,2004,2005,2006,2007,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020