diff options
| author | 2020-02-04 18:45:07 +0000 | |
|---|---|---|
| committer | 2020-02-04 18:45:07 +0000 | |
| commit | 217d53ce1ee21a790df87d68dd5fca5db46ee871 (patch) | |
| tree | 4be07e968b8df2eaa22884b5c303280fd59ce2f8 /usr.sbin/bind/lib/isc/unix | |
| parent | We are not going to generate sig0 records so we can rip out the (diff) | |
| download | wireguard-openbsd-217d53ce1ee21a790df87d68dd5fca5db46ee871.tar.xz wireguard-openbsd-217d53ce1ee21a790df87d68dd5fca5db46ee871.zip | |
Remove a bunch of unused functions who access the filesystem and then
get rid of lib/isc/unix/dir.c
Diffstat (limited to 'usr.sbin/bind/lib/isc/unix')
| -rw-r--r-- | usr.sbin/bind/lib/isc/unix/Makefile.inc | 4 | ||||
| -rw-r--r-- | usr.sbin/bind/lib/isc/unix/dir.c | 237 | ||||
| -rw-r--r-- | usr.sbin/bind/lib/isc/unix/include/isc/dir.h | 90 |
3 files changed, 2 insertions, 329 deletions
diff --git a/usr.sbin/bind/lib/isc/unix/Makefile.inc b/usr.sbin/bind/lib/isc/unix/Makefile.inc index 5cc42d9f8b4..67d11eb82df 100644 --- a/usr.sbin/bind/lib/isc/unix/Makefile.inc +++ b/usr.sbin/bind/lib/isc/unix/Makefile.inc @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile.inc,v 1.1 2020/01/28 17:17:06 florian Exp $ +# $OpenBSD: Makefile.inc,v 1.2 2020/02/04 18:45:08 florian Exp $ .PATH: ${.CURDIR}/lib/isc/unix -SRCS+= app.c dir.c errno.c errno2result.c socket.c stdio.c net.c stdtime.c +SRCS+= app.c errno.c errno2result.c socket.c stdio.c net.c stdtime.c SRCS+= strerror.c time.c diff --git a/usr.sbin/bind/lib/isc/unix/dir.c b/usr.sbin/bind/lib/isc/unix/dir.c deleted file mode 100644 index b3e8e017ba0..00000000000 --- a/usr.sbin/bind/lib/isc/unix/dir.c +++ /dev/null @@ -1,237 +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. - */ - -/*! \file - * \author Principal Authors: DCL */ - - - -#include <sys/types.h> -#include <sys/stat.h> - -#include <ctype.h> -#include <errno.h> -#include <unistd.h> - -#include <isc/dir.h> -#include <isc/magic.h> -#include <isc/netdb.h> - -#include <string.h> -#include <isc/util.h> - -#include "errno2result.h" - -#define ISC_DIR_MAGIC ISC_MAGIC('D', 'I', 'R', '*') -#define VALID_DIR(dir) ISC_MAGIC_VALID(dir, ISC_DIR_MAGIC) - -void -isc_dir_init(isc_dir_t *dir) { - REQUIRE(dir != NULL); - - dir->entry.name[0] = '\0'; - dir->entry.length = 0; - - dir->handle = NULL; - - dir->magic = ISC_DIR_MAGIC; -} - -/*! - * \brief Allocate workspace and open directory stream. If either one fails, - * NULL will be returned. - */ -isc_result_t -isc_dir_open(isc_dir_t *dir, const char *dirname) { - char *p; - isc_result_t result = ISC_R_SUCCESS; - - REQUIRE(VALID_DIR(dir)); - REQUIRE(dirname != NULL); - - /* - * Copy directory name. Need to have enough space for the name, - * a possible path separator, the wildcard, and the final NUL. - */ - if (strlen(dirname) + 3 > sizeof(dir->dirname)) { - /* XXXDCL ? */ - return (ISC_R_NOSPACE); - } - strlcpy(dir->dirname, dirname, sizeof(dir->dirname)); - - /* - * Append path separator, if needed, and "*". - */ - p = dir->dirname + strlen(dir->dirname); - if (dir->dirname < p && *(p - 1) != '/') - *p++ = '/'; - *p++ = '*'; - *p = '\0'; - - /* - * Open stream. - */ - dir->handle = opendir(dirname); - - if (dir->handle == NULL) { - return (isc__errno2result(errno)); - } - - return (result); -} - -/*! - * \brief Return previously retrieved file or get next one. - - * Unix's dirent has - * separate open and read functions, but the Win32 and DOS interfaces open - * the dir stream and reads the first file in one operation. - */ -isc_result_t -isc_dir_read(isc_dir_t *dir) { - struct dirent *entry; - - REQUIRE(VALID_DIR(dir) && dir->handle != NULL); - - /* - * Fetch next file in directory. - */ - entry = readdir(dir->handle); - - if (entry == NULL) - return (ISC_R_NOMORE); - - /* - * Make sure that the space for the name is long enough. - */ - if (sizeof(dir->entry.name) <= strlen(entry->d_name)) - return (ISC_R_UNEXPECTED); - - strlcpy(dir->entry.name, entry->d_name, sizeof(dir->entry.name)); - - /* - * Some dirents have d_namlen, but it is not portable. - */ - dir->entry.length = strlen(entry->d_name); - - return (ISC_R_SUCCESS); -} - -/*! - * \brief Close directory stream. - */ -void -isc_dir_close(isc_dir_t *dir) { - REQUIRE(VALID_DIR(dir) && dir->handle != NULL); - - (void)closedir(dir->handle); - dir->handle = NULL; -} - -/*! - * \brief Reposition directory stream at start. - */ -isc_result_t -isc_dir_reset(isc_dir_t *dir) { - REQUIRE(VALID_DIR(dir) && dir->handle != NULL); - - rewinddir(dir->handle); - - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_dir_chdir(const char *dirname) { - /*! - * \brief Change the current directory to 'dirname'. - */ - - REQUIRE(dirname != NULL); - - if (chdir(dirname) < 0) - return (isc__errno2result(errno)); - - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_dir_createunique(char *templet) { - isc_result_t result; - char *x; - char *p; - int i; - int pid; - - REQUIRE(templet != NULL); - - /*! - * \brief mkdtemp is not portable, so this emulates it. - */ - - pid = getpid(); - - /* - * Replace trailing Xs with the process-id, zero-filled. - */ - for (x = templet + strlen(templet) - 1; *x == 'X' && x >= templet; - x--, pid /= 10) - *x = pid % 10 + '0'; - - x++; /* Set x to start of ex-Xs. */ - - do { - i = mkdir(templet, 0700); - if (i == 0 || errno != EEXIST) - break; - - /* - * The BSD algorithm. - */ - p = x; - while (*p != '\0') { - if (isdigit(*p & 0xff)) - *p = 'a'; - else if (*p != 'z') - ++*p; - else { - /* - * Reset character and move to next. - */ - *p++ = 'a'; - continue; - } - - break; - } - - if (*p == '\0') { - /* - * Tried all combinations. errno should already - * be EEXIST, but ensure it is anyway for - * isc__errno2result(). - */ - errno = EEXIST; - break; - } - } while (1); - - if (i == -1) - result = isc__errno2result(errno); - else - result = ISC_R_SUCCESS; - - return (result); -} diff --git a/usr.sbin/bind/lib/isc/unix/include/isc/dir.h b/usr.sbin/bind/lib/isc/unix/include/isc/dir.h deleted file mode 100644 index 865743f17f8..00000000000 --- a/usr.sbin/bind/lib/isc/unix/include/isc/dir.h +++ /dev/null @@ -1,90 +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: dir.h,v 1.4 2020/01/25 10:42:50 deraadt Exp $ */ - -/* Principal Authors: DCL */ - -#ifndef ISC_DIR_H -#define ISC_DIR_H 1 - -/*! \file */ - -#include <sys/types.h> /* Required on some systems. */ -#include <dirent.h> - -#include <isc/lang.h> -#include <isc/result.h> - -#define ISC_DIR_NAMEMAX 256 -#define ISC_DIR_PATHMAX 1024 - -/*% Directory Entry */ -typedef struct isc_direntry { - /*! - * Ideally, this should be NAME_MAX, but AIX does not define it by - * default and dynamically allocating the space based on pathconf() - * complicates things undesirably, as does adding special conditionals - * just for AIX. So a comfortably sized buffer is chosen instead. - */ - char name[ISC_DIR_NAMEMAX]; - unsigned int length; -} isc_direntry_t; - -/*% Directory */ -typedef struct isc_dir { - unsigned int magic; - /*! - * As with isc_direntry_t->name, making this "right" for all systems - * is slightly problematic because AIX does not define PATH_MAX. - */ - char dirname[ISC_DIR_PATHMAX]; - isc_direntry_t entry; - DIR * handle; -} isc_dir_t; - -ISC_LANG_BEGINDECLS - -void -isc_dir_init(isc_dir_t *dir); - -isc_result_t -isc_dir_open(isc_dir_t *dir, const char *dirname); - -isc_result_t -isc_dir_read(isc_dir_t *dir); - -isc_result_t -isc_dir_reset(isc_dir_t *dir); - -void -isc_dir_close(isc_dir_t *dir); - -isc_result_t -isc_dir_chdir(const char *dirname); - -isc_result_t -isc_dir_createunique(char *templet); -/*!< - * Use a templet (such as from isc_file_mktemplate()) to create a uniquely - * named, empty directory. The templet string is modified in place. - * If result == ISC_R_SUCCESS, it is the name of the directory that was - * created. - */ - -ISC_LANG_ENDDECLS - -#endif /* ISC_DIR_H */ |
