diff options
author | 2020-01-26 11:23:42 +0000 | |
---|---|---|
committer | 2020-01-26 11:23:42 +0000 | |
commit | c25b38fff2ea729a46ee9b8f0704d242513576ce (patch) | |
tree | 05ad5d5b3885817c482a3a10a003513fe02f54bf | |
parent | We are not going to write keys to disk. (diff) | |
download | wireguard-openbsd-c25b38fff2ea729a46ee9b8f0704d242513576ce.tar.xz wireguard-openbsd-c25b38fff2ea729a46ee9b8f0704d242513576ce.zip |
Remove now unused unix/file.c and unix/fsaccess.c
OK jca, tedu
-rw-r--r-- | usr.sbin/bind/bin/dig/dighost.c | 4 | ||||
-rw-r--r-- | usr.sbin/bind/lib/dns/dst_api.c | 6 | ||||
-rw-r--r-- | usr.sbin/bind/lib/dns/dst_parse.c | 6 | ||||
-rw-r--r-- | usr.sbin/bind/lib/dns/masterdump.c | 2 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/Makefile.in | 2 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/fsaccess.c | 102 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/include/isc/Makefile.in | 2 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/include/isc/file.h | 368 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/include/isc/fsaccess.h | 177 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/lex.c | 4 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/log.c | 4 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/regex.c | 2 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/unix/Makefile.in | 5 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/unix/file.c | 661 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/unix/fsaccess.c | 92 |
15 files changed, 18 insertions, 1419 deletions
diff --git a/usr.sbin/bind/bin/dig/dighost.c b/usr.sbin/bind/bin/dig/dighost.c index 0290bd73e01..6cd485c34e2 100644 --- a/usr.sbin/bind/bin/dig/dighost.c +++ b/usr.sbin/bind/bin/dig/dighost.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.39 2020/01/25 10:59:19 florian Exp $ */ +/* $Id: dighost.c,v 1.40 2020/01/26 11:23:42 florian Exp $ */ /*! \file * \note @@ -55,7 +55,7 @@ #include <isc/app.h> #include <isc/base64.h> -#include <isc/file.h> + #include <isc/hex.h> #include <isc/lang.h> #include <isc/log.h> diff --git a/usr.sbin/bind/lib/dns/dst_api.c b/usr.sbin/bind/lib/dns/dst_api.c index 007e68e3499..a4097ae0b7b 100644 --- a/usr.sbin/bind/lib/dns/dst_api.c +++ b/usr.sbin/bind/lib/dns/dst_api.c @@ -33,7 +33,7 @@ /* * Principal Author: Brian Wellington - * $Id: dst_api.c,v 1.20 2020/01/26 11:22:33 florian Exp $ + * $Id: dst_api.c,v 1.21 2020/01/26 11:23:42 florian Exp $ */ /*! \file */ @@ -46,7 +46,7 @@ #include <isc/buffer.h> #include <isc/dir.h> -#include <isc/fsaccess.h> + #include <isc/hmacsha.h> #include <isc/lex.h> @@ -59,7 +59,7 @@ #include <string.h> #include <isc/time.h> #include <isc/util.h> -#include <isc/file.h> + diff --git a/usr.sbin/bind/lib/dns/dst_parse.c b/usr.sbin/bind/lib/dns/dst_parse.c index 9329614750c..037151b7d61 100644 --- a/usr.sbin/bind/lib/dns/dst_parse.c +++ b/usr.sbin/bind/lib/dns/dst_parse.c @@ -33,15 +33,15 @@ /*% * Principal Author: Brian Wellington - * $Id: dst_parse.c,v 1.11 2020/01/26 11:22:33 florian Exp $ + * $Id: dst_parse.c,v 1.12 2020/01/26 11:23:42 florian Exp $ */ #include <isc/base64.h> #include <isc/dir.h> -#include <isc/file.h> -#include <isc/fsaccess.h> + + #include <isc/lex.h> diff --git a/usr.sbin/bind/lib/dns/masterdump.c b/usr.sbin/bind/lib/dns/masterdump.c index 44f6acad8a9..c2ec60bbc9c 100644 --- a/usr.sbin/bind/lib/dns/masterdump.c +++ b/usr.sbin/bind/lib/dns/masterdump.c @@ -21,7 +21,7 @@ #include <stdlib.h> #include <isc/event.h> -#include <isc/file.h> + #include <isc/magic.h> diff --git a/usr.sbin/bind/lib/isc/Makefile.in b/usr.sbin/bind/lib/isc/Makefile.in index 4bf98db88e6..4f7262e4ee7 100644 --- a/usr.sbin/bind/lib/isc/Makefile.in +++ b/usr.sbin/bind/lib/isc/Makefile.in @@ -30,7 +30,7 @@ CWARNINGS = # Alphabetically UNIXOBJS = \ unix/app.@O@ unix/dir.@O@ unix/errno.@O@ \ - unix/errno2result.@O@ unix/file.@O@ unix/fsaccess.@O@ \ + unix/errno2result.@O@ \ unix/net.@O@ \ unix/socket.@O@ unix/stdio.@O@ \ unix/stdtime.@O@ unix/strerror.@O@ unix/time.@O@ diff --git a/usr.sbin/bind/lib/isc/fsaccess.c b/usr.sbin/bind/lib/isc/fsaccess.c deleted file mode 100644 index 5be67607475..00000000000 --- a/usr.sbin/bind/lib/isc/fsaccess.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: fsaccess.c,v 1.4 2020/01/09 13:47:13 florian Exp $ */ - -/*! \file - * \brief - * This file contains the OS-independent functionality of the API. - */ -#include <isc/fsaccess.h> - -#include <isc/result.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) - -void -isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access) { - REQUIRE(trustee <= 0x7); - REQUIRE(permission <= 0xFF); - - if ((trustee & ISC_FSACCESS_OWNER) != 0) - *access |= permission; - - if ((trustee & ISC_FSACCESS_GROUP) != 0) - *access |= (permission << GROUP); - - if ((trustee & ISC_FSACCESS_OTHER) != 0) - *access |= (permission << OTHER); -} - -void -isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access) { - REQUIRE(trustee <= 0x7); - REQUIRE(permission <= 0xFF); - - - if ((trustee & ISC_FSACCESS_OWNER) != 0) - *access &= ~permission; - - if ((trustee & ISC_FSACCESS_GROUP) != 0) - *access &= ~(permission << GROUP); - - if ((trustee & ISC_FSACCESS_OTHER) != 0) - *access &= ~(permission << OTHER); -} - -static isc_result_t -check_bad_bits(isc_fsaccess_t access, isc_boolean_t is_dir) { - isc_fsaccess_t bits; - - /* - * Check for disallowed user bits. - */ - if (is_dir) - bits = ISC_FSACCESS_READ | - ISC_FSACCESS_WRITE | - ISC_FSACCESS_EXECUTE; - else - bits = ISC_FSACCESS_CREATECHILD | - ISC_FSACCESS_ACCESSCHILD | - ISC_FSACCESS_DELETECHILD | - ISC_FSACCESS_LISTDIRECTORY; - - /* - * Set group bad bits. - */ - bits |= bits << STEP; - /* - * Set other bad bits. - */ - bits |= bits << STEP; - - if ((access & bits) != 0) { - if (is_dir) - return (ISC_R_NOTFILE); - else - return (ISC_R_NOTDIRECTORY); - } - - return (ISC_R_SUCCESS); -} diff --git a/usr.sbin/bind/lib/isc/include/isc/Makefile.in b/usr.sbin/bind/lib/isc/include/isc/Makefile.in index 60e7de220e4..72640e58c81 100644 --- a/usr.sbin/bind/lib/isc/include/isc/Makefile.in +++ b/usr.sbin/bind/lib/isc/include/isc/Makefile.in @@ -26,7 +26,7 @@ VERSION=@BIND9_VERSION@ HEADERS = aes.h app.h assertions.h base32.h base64.h \ bind9.h boolean.h buffer.h bufferlist.h \ commandline.h errno.h error.h \ - event.h eventclass.h file.h formatcheck.h fsaccess.h \ + event.h eventclass.h formatcheck.h \ hash.h heap.h hex.h hmacmd5.h hmacsha.h \ @ISC_IPV6_H@ iterated_hash.h \ lang.h lex.h lib.h likely.h list.h log.h \ diff --git a/usr.sbin/bind/lib/isc/include/isc/file.h b/usr.sbin/bind/lib/isc/include/isc/file.h deleted file mode 100644 index d523564f5d6..00000000000 --- a/usr.sbin/bind/lib/isc/include/isc/file.h +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: file.h,v 1.5 2020/01/25 10:58:21 deraadt Exp $ */ - -#ifndef ISC_FILE_H -#define ISC_FILE_H 1 - -/*! \file isc/file.h */ - -#include <stdio.h> - -#include <isc/lang.h> -#include <isc/stat.h> -#include <isc/types.h> - -ISC_LANG_BEGINDECLS - -isc_result_t -isc_file_settime(const char *file, isc_time_t *time); - -isc_result_t -isc_file_mode(const char *file, mode_t *modep); - -isc_result_t -isc_file_getmodtime(const char *file, isc_time_t *time); -/*!< - * \brief Get the time of last modification of a file. - * - * Notes: - *\li The time that is set is relative to the (OS-specific) epoch, as are - * all isc_time_t structures. - * - * Requires: - *\li file != NULL. - *\li time != NULL. - * - * Ensures: - *\li If the file could not be accessed, 'time' is unchanged. - * - * Returns: - *\li #ISC_R_SUCCESS - * Success. - *\li #ISC_R_NOTFOUND - * No such file exists. - *\li #ISC_R_INVALIDFILE - * The path specified was not usable by the operating system. - *\li #ISC_R_NOPERM - * The file's metainformation could not be retrieved because - * permission was denied to some part of the file's path. - *\li #ISC_R_IOERROR - * Hardware error interacting with the filesystem. - *\li #ISC_R_UNEXPECTED - * Something totally unexpected happened. - * - */ - -isc_result_t -isc_file_mktemplate(const char *path, char *buf, size_t buflen); -/*!< - * \brief Generate a template string suitable for use with isc_file_openunique(). - * - * Notes: - *\li This function is intended to make creating temporary files - * portable between different operating systems. - * - *\li The path is prepended to an implementation-defined string and - * placed into buf. The string has no path characters in it, - * and its maximum length is 14 characters plus a NUL. Thus - * buflen should be at least strlen(path) + 15 characters or - * an error will be returned. - * - * Requires: - *\li buf != NULL. - * - * Ensures: - *\li If result == #ISC_R_SUCCESS: - * buf contains a string suitable for use as the template argument - * to isc_file_openunique(). - * - *\li If result != #ISC_R_SUCCESS: - * buf is unchanged. - * - * Returns: - *\li #ISC_R_SUCCESS Success. - *\li #ISC_R_NOSPACE buflen indicates buf is too small for the catenation - * of the path with the internal template string. - */ - -isc_result_t -isc_file_openunique(char *templet, FILE **fp); -isc_result_t -isc_file_openuniqueprivate(char *templet, FILE **fp); -isc_result_t -isc_file_openuniquemode(char *templet, int mode, FILE **fp); -isc_result_t -isc_file_bopenunique(char *templet, FILE **fp); -isc_result_t -isc_file_bopenuniqueprivate(char *templet, FILE **fp); -isc_result_t -isc_file_bopenuniquemode(char *templet, int mode, FILE **fp); -/*!< - * \brief Create and open a file with a unique name based on 'templet'. - * isc_file_bopen*() open the file in binary mode in Windows. - * isc_file_open*() open the file in text mode in Windows. - * - * Notes: - *\li 'template' is a reserved work in C++. If you want to complain - * about the spelling of 'templet', first look it up in the - * Merriam-Webster English dictionary. (http://www.m-w.com/) - * - *\li This function works by using the template to generate file names. - * The template must be a writable string, as it is modified in place. - * Trailing X characters in the file name (full file name on Unix, - * basename on Win32 -- eg, tmp-XXXXXX vs XXXXXX.tmp, respectively) - * are replaced with ASCII characters until a non-existent filename - * is found. If the template does not include pathname information, - * the files in the working directory of the program are searched. - * - *\li isc_file_mktemplate is a good, portable way to get a template. - * - * Requires: - *\li 'fp' is non-NULL and '*fp' is NULL. - * - *\li 'template' is non-NULL, and of a form suitable for use by - * the system as described above. - * - * Ensures: - *\li If result is #ISC_R_SUCCESS: - * *fp points to an stream opening in stdio's "w+" mode. - * - *\li If result is not #ISC_R_SUCCESS: - * *fp is NULL. - * - * No file is open. Even if one was created (but unable - * to be reopened as a stdio FILE pointer) then it has been - * removed. - * - *\li This function does *not* ensure that the template string has not been - * modified, even if the operation was unsuccessful. - * - * Returns: - *\li #ISC_R_SUCCESS - * Success. - *\li #ISC_R_EXISTS - * No file with a unique name could be created based on the - * template. - *\li #ISC_R_INVALIDFILE - * The path specified was not usable by the operating system. - *\li #ISC_R_NOPERM - * The file could not be created because permission was denied - * to some part of the file's path. - *\li #ISC_R_IOERROR - * Hardware error interacting with the filesystem. - *\li #ISC_R_UNEXPECTED - * Something totally unexpected happened. - */ - -isc_result_t -isc_file_remove(const char *filename); -/*!< - * \brief Remove the file named by 'filename'. - */ - -isc_result_t -isc_file_rename(const char *oldname, const char *newname); -/*!< - * \brief Rename the file 'oldname' to 'newname'. - */ - -isc_boolean_t -isc_file_exists(const char *pathname); -/*!< - * \brief Return #ISC_TRUE if the calling process can tell that the given file exists. - * Will not return true if the calling process has insufficient privileges - * to search the entire path. - */ - -isc_boolean_t -isc_file_isabsolute(const char *filename); -/*!< - * \brief Return #ISC_TRUE if the given file name is absolute. - */ - -isc_result_t -isc_file_isplainfile(const char *name); - -isc_result_t -isc_file_isplainfilefd(int fd); -/*!< - * \brief Check that the file is a plain file - * - * Returns: - *\li #ISC_R_SUCCESS - * Success. The file is a plain file. - *\li #ISC_R_INVALIDFILE - * The path specified was not usable by the operating system. - *\li #ISC_R_FILENOTFOUND - * The file does not exist. This return code comes from - * errno=ENOENT when stat returns -1. This code is mentioned - * here, because in logconf.c, it is the one rcode that is - * permitted in addition to ISC_R_SUCCESS. This is done since - * the next call in logconf.c is to isc_stdio_open(), which - * will create the file if it can. - *\li other ISC_R_* errors translated from errno - * These occur when stat returns -1 and an errno. - */ - -isc_result_t -isc_file_isdirectory(const char *name); -/*!< - * \brief Check that 'name' exists and is a directory. - * - * Returns: - *\li #ISC_R_SUCCESS - * Success, file is a directory. - *\li #ISC_R_INVALIDFILE - * File is not a directory. - *\li #ISC_R_FILENOTFOUND - * File does not exist. - *\li other ISC_R_* errors translated from errno - * These occur when stat returns -1 and an errno. - */ - -isc_boolean_t -isc_file_iscurrentdir(const char *filename); -/*!< - * \brief Return #ISC_TRUE if the given file name is the current directory ("."). - */ - -isc_boolean_t -isc_file_ischdiridempotent(const char *filename); -/*%< - * Return #ISC_TRUE if calling chdir(filename) multiple times will give - * the same result as calling it once. - */ - -const char * -isc_file_basename(const char *filename); -/*%< - * Return the final component of the path in the file name. - */ - -isc_result_t -isc_file_progname(const char *filename, char *buf, size_t buflen); -/*!< - * \brief Given an operating system specific file name "filename" - * referring to a program, return the canonical program name. - * - * Any directory prefix or executable file name extension (if - * used on the OS in case) is stripped. On systems where program - * names are case insensitive, the name is canonicalized to all - * lower case. The name is written to 'buf', an array of 'buflen' - * chars, and null terminated. - * - * Returns: - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOSPACE The name did not fit in 'buf'. - */ - -isc_result_t -isc_file_template(const char *path, const char *templet, char *buf, - size_t buflen); -/*%< - * Create an OS specific template using 'path' to define the directory - * 'templet' to describe the filename and store the result in 'buf' - * such that path can be renamed to buf atomically. - */ - -isc_result_t -isc_file_renameunique(const char *file, char *templet); -/*%< - * Rename 'file' using 'templet' as a template for the new file name. - */ - -isc_result_t -isc_file_absolutepath(const char *filename, char *path, size_t pathlen); -/*%< - * Given a file name, return the fully qualified path to the file. - */ - -/* - * XXX We should also have a isc_file_writeeopen() function - * for safely open a file in a publicly writable directory - * (see write_open() in BIND 8's ns_config.c). - */ - -isc_result_t -isc_file_truncate(const char *filename, isc_offset_t size); -/*%< - * Truncate/extend the file specified to 'size' bytes. - */ - -isc_result_t -isc_file_safecreate(const char *filename, FILE **fp); -/*%< - * Open 'filename' for writing, truncating if necessary. Ensure that - * if it existed it was a normal file. If creating the file, ensure - * that only the owner can read/write it. - */ - -isc_result_t -isc_file_splitpath(const char *path, - char **dirname, char const **basename); -/*%< - * Split a path into dirname and basename. If 'path' contains no slash - * (or, on windows, backslash), then '*dirname' is set to ".". - * - * Allocates memory for '*dirname'. - * - * Returns: - * - ISC_R_SUCCESS on success - * - ISC_R_INVALIDFILE if 'path' is empty or ends with '/' - * - ISC_R_NOMEMORY if unable to allocate memory - */ - -isc_result_t -isc_file_getsize(const char *file, off_t *size); -/*%< - * Return the size of the file (stored in the parameter pointed - * to by 'size') in bytes. - * - * Returns: - * - ISC_R_SUCCESS on success - */ - -isc_result_t -isc_file_getsizefd(int fd, off_t *size); -/*%< - * Return the size of the file (stored in the parameter pointed - * to by 'size') in bytes. - * - * Returns: - * - ISC_R_SUCCESS on success - */ - -void * -isc_file_mmap(void *addr, size_t len, int prot, - int flags, int fd, off_t offset); -/*%< - * Portable front-end to mmap(). If mmap() is not defined on this - * platform, then we simulate it by calling malloc() and read(). - * (In this event, the addr, prot, and flags parameters are ignored). - */ - -int -isc_file_munmap(void *addr, size_t len); -/*%< - * Portable front-end to munmap(). If munmap() is not defined on - * this platform, then we simply free the memory. - */ - -ISC_LANG_ENDDECLS - -#endif /* ISC_FILE_H */ diff --git a/usr.sbin/bind/lib/isc/include/isc/fsaccess.h b/usr.sbin/bind/lib/isc/include/isc/fsaccess.h deleted file mode 100644 index 5187f4ef11b..00000000000 --- a/usr.sbin/bind/lib/isc/include/isc/fsaccess.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: fsaccess.h,v 1.4 2020/01/09 18:17:19 florian Exp $ */ - -#ifndef ISC_FSACCESS_H -#define ISC_FSACCESS_H 1 - -/*! \file isc/fsaccess.h - * \brief The ISC filesystem access module encapsulates the setting of file - * and directory access permissions into one API that is meant to be - * portable to multiple operating systems. - * - * The two primary operating system flavors that are initially accommodated - * are POSIX and Windows NT 4.0 and later. The Windows NT access model is - * considerable more flexible than POSIX's model (as much as I am loathe to - * admit it), and so the ISC API has a higher degree of complexity than would - * be needed to simply address POSIX's needs. - * - * The full breadth of NT's flexibility is not available either, for the - * present time. Much of it is to provide compatibility with what Unix - * programmers are expecting. This is also due to not yet really needing all - * of the functionality of an NT system (or, for that matter, a POSIX system) - * in BIND9, and so resolving how to handle the various incompatibilities has - * been a purely theoretical exercise with no operational experience to - * indicate how flawed the thinking may be. - * - * Some of the more notable dumbing down of NT for this API includes: - * - *\li Each of FILE_READ_DATA and FILE_READ_EA are set with #ISC_FSACCESS_READ. - * - * \li All of FILE_WRITE_DATA, FILE_WRITE_EA and FILE_APPEND_DATA are - * set with #ISC_FSACCESS_WRITE. FILE_WRITE_ATTRIBUTES is not set - * so as to be consistent with Unix, where only the owner of the file - * or the superuser can change the attributes/mode of a file. - * - * \li Both of FILE_ADD_FILE and FILE_ADD_SUBDIRECTORY are set with - * #ISC_FSACCESS_CREATECHILD. This is similar to setting the WRITE - * permission on a Unix directory. - * - * \li SYNCHRONIZE is always set for files and directories, unless someone - * can give me a reason why this is a bad idea. - * - * \li READ_CONTROL and FILE_READ_ATTRIBUTES are always set; this is - * consistent with Unix, where any file or directory can be stat()'d - * unless the directory path disallows complete access somewhere along - * the way. - * - * \li WRITE_DAC is only set for the owner. This too is consistent with - * Unix, and is tighter security than allowing anyone else to be - * able to set permissions. - * - * \li DELETE is only set for the owner. On Unix the ability to delete - * a file is controlled by the directory permissions, but it isn't - * currently clear to me what happens on NT if the directory has - * FILE_DELETE_CHILD set but a file within it does not have DELETE - * set. Always setting DELETE on the file/directory for the owner - * gives maximum flexibility to the owner without exposing the - * file to deletion by others. - * - * \li WRITE_OWNER is never set. This too is consistent with Unix, - * and is also tighter security than allowing anyone to change the - * ownership of the file apart from the superu..ahem, Administrator. - * - * \li Inheritance is set to NO_INHERITANCE. - * - * Unix's dumbing down includes: - * - * \li The sticky bit cannot be set. - * - * \li setuid and setgid cannot be set. - * - * \li Only regular files and directories can be set. - * - * The rest of this comment discusses a few of the incompatibilities - * between the two systems that need more thought if this API is to - * be extended to accommodate them. - * - * The Windows standard access right "DELETE" doesn't have a direct - * equivalent in the Unix world, so it isn't clear what should be done - * with it. - * - * The Unix sticky bit is not supported. While NT does have a concept - * of allowing users to create files in a directory but not delete or - * rename them, it does not have a concept of allowing them to be deleted - * if they are owned by the user trying to delete/rename. While it is - * probable that something could be cobbled together in NT 5 with inheritance, - * it can't really be done in NT 4 as a single property that you could - * set on a directory. You'd need to coordinate something with file creation - * so that every file created had DELETE set for the owner but noone else. - * - * On Unix systems, setting #ISC_FSACCESS_LISTDIRECTORY sets READ. - * ... setting either #ISC_FSACCESS_CREATECHILD or #ISC_FSACCESS_DELETECHILD - * sets WRITE. - * ... setting #ISC_FSACCESS_ACCESSCHILD sets EXECUTE. - * - * On NT systems, setting #ISC_FSACCESS_LISTDIRECTORY sets FILE_LIST_DIRECTORY. - * ... setting #ISC_FSACCESS_CREATECHILD sets FILE_CREATE_CHILD independently. - * ... setting #ISC_FSACCESS_DELETECHILD sets FILE_DELETE_CHILD independently. - * ... setting #ISC_FSACCESS_ACCESSCHILD sets FILE_TRAVERSE. - * - * Unresolved: XXXDCL - * \li What NT access right controls the ability to rename a file? - * \li How does DELETE work? If a directory has FILE_DELETE_CHILD but a - * file or directory within it does not have DELETE, is that file - * or directory deletable? - * \li To implement isc_fsaccess_get(), mapping an existing Unix permission - * mode_t back to an isc_fsaccess_t is pretty trivial; however, mapping - * an NT DACL could be impossible to do in a responsible way. - * \li Similarly, trying to implement the functionality of being able to - * say "add group writability to whatever permissions already exist" - * could be tricky on NT because of the order-of-entry issue combined - * with possibly having one or more matching ACEs already explicitly - * granting or denying access. Because this functionality is - * not yet needed by the ISC, no code has been written to try to - * solve this problem. - */ - -#include <isc/lang.h> -#include <isc/types.h> - -/* - * Trustees. - */ -#define ISC_FSACCESS_OWNER 0x1 /*%< User account. */ -#define ISC_FSACCESS_GROUP 0x2 /*%< Primary group owner. */ -#define ISC_FSACCESS_OTHER 0x4 /*%< Not the owner or the group owner. */ -#define ISC_FSACCESS_WORLD 0x7 /*%< User, Group, Other. */ - -/* - * Types of permission. - */ -#define ISC_FSACCESS_READ 0x00000001 /*%< File only. */ -#define ISC_FSACCESS_WRITE 0x00000002 /*%< File only. */ -#define ISC_FSACCESS_EXECUTE 0x00000004 /*%< File only. */ -#define ISC_FSACCESS_CREATECHILD 0x00000008 /*%< Dir only. */ -#define ISC_FSACCESS_DELETECHILD 0x00000010 /*%< Dir only. */ -#define ISC_FSACCESS_LISTDIRECTORY 0x00000020 /*%< Dir only. */ -#define ISC_FSACCESS_ACCESSCHILD 0x00000040 /*%< Dir only. */ - -/*% - * Adding any permission bits beyond 0x200 would mean typedef'ing - * isc_fsaccess_t as uint64_t, and redefining this value to - * reflect the new range of permission types, Probably to 21 for - * maximum flexibility. The number of bits has to accommodate all of - * the permission types, and three full sets of them have to fit - * within an isc_fsaccess_t. - */ -#define ISC__FSACCESS_PERMISSIONBITS 10 - -ISC_LANG_BEGINDECLS - -void -isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access); - -void -isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access); - -isc_result_t -isc_fsaccess_set(const char *path, isc_fsaccess_t access); - -ISC_LANG_ENDDECLS - -#endif /* ISC_FSACCESS_H */ diff --git a/usr.sbin/bind/lib/isc/lex.c b/usr.sbin/bind/lib/isc/lex.c index 4e478b2890f..a3965e3d5cd 100644 --- a/usr.sbin/bind/lib/isc/lex.c +++ b/usr.sbin/bind/lib/isc/lex.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: lex.c,v 1.15 2020/01/22 13:02:10 florian Exp $ */ +/* $Id: lex.c,v 1.16 2020/01/26 11:23:42 florian Exp $ */ /*! \file */ @@ -25,7 +25,7 @@ #include <stdlib.h> #include <isc/buffer.h> -#include <isc/file.h> + #include <isc/lex.h> #include <isc/msgs.h> diff --git a/usr.sbin/bind/lib/isc/log.c b/usr.sbin/bind/lib/isc/log.c index 9485104809e..65ef138f73f 100644 --- a/usr.sbin/bind/lib/isc/log.c +++ b/usr.sbin/bind/lib/isc/log.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.21 2020/01/26 11:21:58 florian Exp $ */ +/* $Id: log.c,v 1.22 2020/01/26 11:23:42 florian Exp $ */ /*! \file * \author Principal Authors: DCL */ @@ -29,7 +29,7 @@ #include <sys/types.h> /* dev_t FreeBSD 2.1 */ #include <isc/dir.h> -#include <isc/file.h> + #include <isc/log.h> #include <isc/magic.h> #include <isc/msgs.h> diff --git a/usr.sbin/bind/lib/isc/regex.c b/usr.sbin/bind/lib/isc/regex.c index df73e2fdffd..4344a8b0339 100644 --- a/usr.sbin/bind/lib/isc/regex.c +++ b/usr.sbin/bind/lib/isc/regex.c @@ -16,7 +16,7 @@ -#include <isc/file.h> + #include <isc/regex.h> #include <string.h> diff --git a/usr.sbin/bind/lib/isc/unix/Makefile.in b/usr.sbin/bind/lib/isc/unix/Makefile.in index 899ddffd586..0935825bca9 100644 --- a/usr.sbin/bind/lib/isc/unix/Makefile.in +++ b/usr.sbin/bind/lib/isc/unix/Makefile.in @@ -28,15 +28,14 @@ CWARNINGS = # Alphabetically OBJS = \ app.@O@ dir.@O@ errno.@O@ errno2result.@O@ \ - file.@O@ fsaccess.@O@ \ net.@O@ \ socket.@O@ stdio.@O@ stdtime.@O@ \ strerror.@O@ time.@O@ # Alphabetically SRCS = @ISC_IPV6_C@ @ISC_PK11_API_C@ \ - app.c dir.c errno.c errno2result.c file.c \ - fsaccess.c net.c \ + app.c dir.c errno.c errno2result.c \ + net.c \ socket.c stdio.c stdtime.c \ strerror.c time.c diff --git a/usr.sbin/bind/lib/isc/unix/file.c b/usr.sbin/bind/lib/isc/unix/file.c deleted file mode 100644 index f6be77670dc..00000000000 --- a/usr.sbin/bind/lib/isc/unix/file.c +++ /dev/null @@ -1,661 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Portions Copyright (c) 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $Id: file.c,v 1.15 2020/01/25 10:58:21 deraadt Exp $ */ - -/*! \file */ - - - -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <stdlib.h> -#include <time.h> /* Required for utimes on some platforms. */ -#include <unistd.h> /* Required for mkstemp on NetBSD. */ - - -#include <sys/stat.h> -#include <sys/time.h> - -#include <sys/mman.h> - -#include <isc/dir.h> -#include <isc/file.h> -#include <isc/log.h> - - -#include <string.h> -#include <isc/time.h> -#include <isc/util.h> - -#include "errno2result.h" - -/* - * XXXDCL As the API for accessing file statistics undoubtedly gets expanded, - * it might be good to provide a mechanism that allows for the results - * of a previous stat() to be used again without having to do another stat, - * such as perl's mechanism of using "_" in place of a file name to indicate - * that the results of the last stat should be used. But then you get into - * annoying MP issues. BTW, Win32 has stat(). - */ -static isc_result_t -file_stats(const char *file, struct stat *stats) { - isc_result_t result = ISC_R_SUCCESS; - - REQUIRE(file != NULL); - REQUIRE(stats != NULL); - - if (stat(file, stats) != 0) - result = isc__errno2result(errno); - - return (result); -} - -static isc_result_t -fd_stats(int fd, struct stat *stats) { - isc_result_t result = ISC_R_SUCCESS; - - REQUIRE(stats != NULL); - - if (fstat(fd, stats) != 0) - result = isc__errno2result(errno); - - return (result); -} - -isc_result_t -isc_file_getsizefd(int fd, off_t *size) { - isc_result_t result; - struct stat stats; - - REQUIRE(size != NULL); - - result = fd_stats(fd, &stats); - - if (result == ISC_R_SUCCESS) - *size = stats.st_size; - - return (result); -} - -isc_result_t -isc_file_mode(const char *file, mode_t *modep) { - isc_result_t result; - struct stat stats; - - REQUIRE(modep != NULL); - - result = file_stats(file, &stats); - if (result == ISC_R_SUCCESS) - *modep = (stats.st_mode & 07777); - - return (result); -} - -isc_result_t -isc_file_getmodtime(const char *file, isc_time_t *modtime) { - isc_result_t result; - struct stat stats; - - REQUIRE(file != NULL); - REQUIRE(modtime != NULL); - - result = file_stats(file, &stats); - - if (result == ISC_R_SUCCESS) - isc_time_set(modtime, stats.st_mtime, stats.st_mtim.tv_nsec); - - return (result); -} - -isc_result_t -isc_file_getsize(const char *file, off_t *size) { - isc_result_t result; - struct stat stats; - - REQUIRE(file != NULL); - REQUIRE(size != NULL); - - result = file_stats(file, &stats); - - if (result == ISC_R_SUCCESS) - *size = stats.st_size; - - return (result); -} - -isc_result_t -isc_file_settime(const char *file, isc_time_t *when) { - struct timeval times[2]; - - REQUIRE(file != NULL && when != NULL); - - /* - * tv_sec is at least a 32 bit quantity on all platforms we're - * dealing with, but it is signed on most (all?) of them, - * so we need to make sure the high bit isn't set. This unfortunately - * loses when either: - * * tv_sec becomes a signed 64 bit integer but long is 32 bits - * and isc_time_seconds > LONG_MAX, or - * * isc_time_seconds is changed to be > 32 bits but long is 32 bits - * and isc_time_seconds has at least 33 significant bits. - */ - times[0].tv_sec = times[1].tv_sec = (long)isc_time_seconds(when); - - /* - * Here is the real check for the high bit being set. - */ - if ((times[0].tv_sec & - (1ULL << (sizeof(times[0].tv_sec) * CHAR_BIT - 1))) != 0) - return (ISC_R_RANGE); - - /* - * isc_time_nanoseconds guarantees a value that divided by 1000 will - * fit into the minimum possible size tv_usec field. Unfortunately, - * we don't know what that type is so can't cast directly ... but - * we can at least cast to signed so the IRIX compiler shuts up. - */ - times[0].tv_usec = times[1].tv_usec = - (int32_t)(isc_time_nanoseconds(when) / 1000); - - if (utimes(file, times) < 0) - return (isc__errno2result(errno)); - - return (ISC_R_SUCCESS); -} - -#undef TEMPLATE -#define TEMPLATE "tmp-XXXXXXXXXX" /*%< 14 characters. */ - -isc_result_t -isc_file_mktemplate(const char *path, char *buf, size_t buflen) { - return (isc_file_template(path, TEMPLATE, buf, buflen)); -} - -isc_result_t -isc_file_template(const char *path, const char *templet, char *buf, - size_t buflen) -{ - const char *s; - - REQUIRE(path != NULL); - REQUIRE(templet != NULL); - REQUIRE(buf != NULL); - - s = strrchr(templet, '/'); - if (s != NULL) - templet = s + 1; - - s = strrchr(path, '/'); - - if (s != NULL) { - size_t prefixlen = s - path + 1; - if ((prefixlen + strlen(templet) + 1) > buflen) - return (ISC_R_NOSPACE); - - /* Copy 'prefixlen' bytes and NUL terminate. */ - strlcpy(buf, path, ISC_MIN(prefixlen + 1, buflen)); - strlcat(buf, templet, buflen); - } else { - if ((strlen(templet) + 1) > buflen) - return (ISC_R_NOSPACE); - - strlcpy(buf, templet, buflen); - } - - return (ISC_R_SUCCESS); -} - -static char alphnum[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - -isc_result_t -isc_file_renameunique(const char *file, char *templet) { - char *x; - char *cp; - - REQUIRE(file != NULL); - REQUIRE(templet != NULL); - - cp = templet; - while (*cp != '\0') - cp++; - if (cp == templet) - return (ISC_R_FAILURE); - - x = cp--; - while (cp >= templet && *cp == 'X') { - *cp = alphnum[arc4random_uniform(sizeof(alphnum) - 1)]; - x = cp--; - } - while (link(file, templet) == -1) { - if (errno != EEXIST) - return (isc__errno2result(errno)); - for (cp = x;;) { - const char *t; - if (*cp == '\0') - return (ISC_R_FAILURE); - t = strchr(alphnum, *cp); - if (t == NULL || *++t == '\0') - *cp++ = alphnum[0]; - else { - *cp = *t; - break; - } - } - } - if (unlink(file) < 0) - if (errno != ENOENT) - return (isc__errno2result(errno)); - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_file_openunique(char *templet, FILE **fp) { - int mode = S_IWUSR|S_IRUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; - return (isc_file_openuniquemode(templet, mode, fp)); -} - -isc_result_t -isc_file_openuniqueprivate(char *templet, FILE **fp) { - int mode = S_IWUSR|S_IRUSR; - return (isc_file_openuniquemode(templet, mode, fp)); -} - -isc_result_t -isc_file_openuniquemode(char *templet, int mode, FILE **fp) { - int fd; - FILE *f; - isc_result_t result = ISC_R_SUCCESS; - char *x; - char *cp; - - REQUIRE(templet != NULL); - REQUIRE(fp != NULL && *fp == NULL); - - cp = templet; - while (*cp != '\0') - cp++; - if (cp == templet) - return (ISC_R_FAILURE); - - x = cp--; - while (cp >= templet && *cp == 'X') { - *cp = alphnum[arc4random_uniform(sizeof(alphnum) - 1)]; - x = cp--; - } - - - while ((fd = open(templet, O_RDWR|O_CREAT|O_EXCL, mode)) == -1) { - if (errno != EEXIST) - return (isc__errno2result(errno)); - for (cp = x;;) { - char *t; - if (*cp == '\0') - return (ISC_R_FAILURE); - t = strchr(alphnum, *cp); - if (t == NULL || *++t == '\0') - *cp++ = alphnum[0]; - else { - *cp = *t; - break; - } - } - } - f = fdopen(fd, "w+"); - if (f == NULL) { - result = isc__errno2result(errno); - if (remove(templet) < 0) { - isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, - ISC_LOGMODULE_FILE, ISC_LOG_ERROR, - "remove '%s': failed", templet); - } - (void)close(fd); - } else - *fp = f; - - return (result); -} - -isc_result_t -isc_file_bopenunique(char *templet, FILE **fp) { - int mode = S_IWUSR|S_IRUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; - return (isc_file_openuniquemode(templet, mode, fp)); -} - -isc_result_t -isc_file_bopenuniqueprivate(char *templet, FILE **fp) { - int mode = S_IWUSR|S_IRUSR; - return (isc_file_openuniquemode(templet, mode, fp)); -} - -isc_result_t -isc_file_bopenuniquemode(char *templet, int mode, FILE **fp) { - return (isc_file_openuniquemode(templet, mode, fp)); -} - -isc_result_t -isc_file_remove(const char *filename) { - int r; - - REQUIRE(filename != NULL); - - r = unlink(filename); - if (r == 0) - return (ISC_R_SUCCESS); - else - return (isc__errno2result(errno)); -} - -isc_result_t -isc_file_rename(const char *oldname, const char *newname) { - int r; - - REQUIRE(oldname != NULL); - REQUIRE(newname != NULL); - - r = rename(oldname, newname); - if (r == 0) - return (ISC_R_SUCCESS); - else - return (isc__errno2result(errno)); -} - -isc_boolean_t -isc_file_exists(const char *pathname) { - struct stat stats; - - REQUIRE(pathname != NULL); - - return (ISC_TF(file_stats(pathname, &stats) == ISC_R_SUCCESS)); -} - -isc_result_t -isc_file_isplainfile(const char *filename) { - /* - * This function returns success if filename is a plain file. - */ - struct stat filestat; - memset(&filestat,0,sizeof(struct stat)); - - if ((stat(filename, &filestat)) == -1) - return(isc__errno2result(errno)); - - if(! S_ISREG(filestat.st_mode)) - return(ISC_R_INVALIDFILE); - - return(ISC_R_SUCCESS); -} - -isc_result_t -isc_file_isplainfilefd(int fd) { - /* - * This function returns success if filename is a plain file. - */ - struct stat filestat; - memset(&filestat,0,sizeof(struct stat)); - - if ((fstat(fd, &filestat)) == -1) - return(isc__errno2result(errno)); - - if(! S_ISREG(filestat.st_mode)) - return(ISC_R_INVALIDFILE); - - return(ISC_R_SUCCESS); -} - -isc_result_t -isc_file_isdirectory(const char *filename) { - /* - * This function returns success if filename exists and is a - * directory. - */ - struct stat filestat; - memset(&filestat,0,sizeof(struct stat)); - - if ((stat(filename, &filestat)) == -1) - return(isc__errno2result(errno)); - - if(! S_ISDIR(filestat.st_mode)) - return(ISC_R_INVALIDFILE); - - return(ISC_R_SUCCESS); -} - - -isc_boolean_t -isc_file_isabsolute(const char *filename) { - REQUIRE(filename != NULL); - return (ISC_TF(filename[0] == '/')); -} - -isc_boolean_t -isc_file_iscurrentdir(const char *filename) { - REQUIRE(filename != NULL); - return (ISC_TF(filename[0] == '.' && filename[1] == '\0')); -} - -isc_boolean_t -isc_file_ischdiridempotent(const char *filename) { - REQUIRE(filename != NULL); - if (isc_file_isabsolute(filename)) - return (ISC_TRUE); - if (isc_file_iscurrentdir(filename)) - return (ISC_TRUE); - return (ISC_FALSE); -} - -const char * -isc_file_basename(const char *filename) { - const char *s; - - REQUIRE(filename != NULL); - - s = strrchr(filename, '/'); - if (s == NULL) - return (filename); - - return (s + 1); -} - -isc_result_t -isc_file_progname(const char *filename, char *buf, size_t buflen) { - const char *base; - size_t len; - - REQUIRE(filename != NULL); - REQUIRE(buf != NULL); - - base = isc_file_basename(filename); - len = strlen(base) + 1; - - if (len > buflen) - return (ISC_R_NOSPACE); - memmove(buf, base, len); - - return (ISC_R_SUCCESS); -} - -/* - * Put the absolute name of the current directory into 'dirname', which is - * a buffer of at least 'length' characters. End the string with the - * appropriate path separator, such that the final product could be - * concatenated with a relative pathname to make a valid pathname string. - */ -static isc_result_t -dir_current(char *dirname, size_t length) { - char *cwd; - isc_result_t result = ISC_R_SUCCESS; - - REQUIRE(dirname != NULL); - REQUIRE(length > 0U); - - cwd = getcwd(dirname, length); - - if (cwd == NULL) { - if (errno == ERANGE) { - result = ISC_R_NOSPACE; - } else { - result = isc__errno2result(errno); - } - } else { - if (strlen(dirname) + 1 == length) { - result = ISC_R_NOSPACE; - } else if (dirname[1] != '\0') { - strlcat(dirname, "/", length); - } - } - - return (result); -} - -isc_result_t -isc_file_absolutepath(const char *filename, char *path, size_t pathlen) { - isc_result_t result; - result = dir_current(path, pathlen); - if (result != ISC_R_SUCCESS) - return (result); - if (strlen(path) + strlen(filename) + 1 > pathlen) - return (ISC_R_NOSPACE); - strlcat(path, filename, pathlen); - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_file_truncate(const char *filename, isc_offset_t size) { - isc_result_t result = ISC_R_SUCCESS; - - if (truncate(filename, size) < 0) - result = isc__errno2result(errno); - return (result); -} - -isc_result_t -isc_file_safecreate(const char *filename, FILE **fp) { - isc_result_t result; - int flags; - struct stat sb; - FILE *f; - int fd; - - REQUIRE(filename != NULL); - REQUIRE(fp != NULL && *fp == NULL); - - result = file_stats(filename, &sb); - if (result == ISC_R_SUCCESS) { - if ((sb.st_mode & S_IFREG) == 0) - return (ISC_R_INVALIDFILE); - flags = O_WRONLY | O_TRUNC; - } else if (result == ISC_R_FILENOTFOUND) { - flags = O_WRONLY | O_CREAT | O_EXCL; - } else - return (result); - - fd = open(filename, flags, S_IRUSR | S_IWUSR); - if (fd == -1) - return (isc__errno2result(errno)); - - f = fdopen(fd, "w"); - if (f == NULL) { - result = isc__errno2result(errno); - close(fd); - return (result); - } - - *fp = f; - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_file_splitpath(const char *path, char **dirname, - char const **bname) -{ - char *dir; - const char *file, *slash; - - if (path == NULL) - return (ISC_R_INVALIDFILE); - - slash = strrchr(path, '/'); - - if (slash == path) { - file = ++slash; - dir = strdup("/"); - } else if (slash != NULL) { - file = ++slash; - dir = malloc(slash - path); - if (dir != NULL) - strlcpy(dir, path, slash - path); - } else { - file = path; - dir = strdup("."); - } - - if (dir == NULL) - return (ISC_R_NOMEMORY); - - if (*file == '\0') { - free(dir); - return (ISC_R_INVALIDFILE); - } - - *dirname = dir; - *bname = file; - - return (ISC_R_SUCCESS); -} - -void * -isc_file_mmap(void *addr, size_t len, int prot, - int flags, int fd, off_t offset) -{ - return (mmap(addr, len, prot, flags, fd, offset)); -} - -int -isc_file_munmap(void *addr, size_t len) { - return (munmap(addr, len)); -} diff --git a/usr.sbin/bind/lib/isc/unix/fsaccess.c b/usr.sbin/bind/lib/isc/unix/fsaccess.c deleted file mode 100644 index f1fe7e72537..00000000000 --- a/usr.sbin/bind/lib/isc/unix/fsaccess.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: fsaccess.c,v 1.7 2020/01/22 13:02:10 florian Exp $ */ - - - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.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; - mode_t mode; - isc_boolean_t is_dir = ISC_FALSE; - isc_fsaccess_t bits; - isc_result_t result; - - if (stat(path, &statb) != 0) - return (isc__errno2result(errno)); - - if ((statb.st_mode & S_IFDIR) != 0) - is_dir = ISC_TRUE; - else if ((statb.st_mode & S_IFREG) == 0) - return (ISC_R_INVALIDFILE); - - result = check_bad_bits(access, is_dir); - if (result != ISC_R_SUCCESS) - return (result); - - /* - * Done with checking bad bits. Set mode_t. - */ - mode = 0; - -#define SET_AND_CLEAR1(modebit) \ - if ((access & bits) != 0) { \ - mode |= modebit; \ - access &= ~bits; \ - } -#define SET_AND_CLEAR(user, group, other) \ - SET_AND_CLEAR1(user); \ - bits <<= STEP; \ - SET_AND_CLEAR1(group); \ - bits <<= STEP; \ - SET_AND_CLEAR1(other); - - bits = ISC_FSACCESS_READ | ISC_FSACCESS_LISTDIRECTORY; - - SET_AND_CLEAR(S_IRUSR, S_IRGRP, S_IROTH); - - bits = ISC_FSACCESS_WRITE | - ISC_FSACCESS_CREATECHILD | - ISC_FSACCESS_DELETECHILD; - - SET_AND_CLEAR(S_IWUSR, S_IWGRP, S_IWOTH); - - bits = ISC_FSACCESS_EXECUTE | - ISC_FSACCESS_ACCESSCHILD; - - SET_AND_CLEAR(S_IXUSR, S_IXGRP, S_IXOTH); - - INSIST(access == 0); - - if (chmod(path, mode) < 0) - return (isc__errno2result(errno)); - - return (ISC_R_SUCCESS); -} |