2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 21:17:54 +00:00
bind/lib/dns/gen-win32.h
Ondřej Surý 978c7b2e89 Complete rewrite the BIND 9 build system
The rewrite of BIND 9 build system is a large work and cannot be reasonable
split into separate merge requests.  Addition of the automake has a positive
effect on the readability and maintainability of the build system as it is more
declarative, it allows conditional and we are able to drop all of the custom
make code that BIND 9 developed over the years to overcome the deficiencies of
autoconf + custom Makefile.in files.

This squashed commit contains following changes:

- conversion (or rather fresh rewrite) of all Makefile.in files to Makefile.am
  by using automake

- the libtool is now properly integrated with automake (the way we used it
  was rather hackish as the only official way how to use libtool is via
  automake

- the dynamic module loading was rewritten from a custom patchwork to libtool's
  libltdl (which includes the patchwork to support module loading on different
  systems internally)

- conversion of the unit test executor from kyua to automake parallel driver

- conversion of the system test executor from custom make/shell to automake
  parallel driver

- The GSSAPI has been refactored, the custom SPNEGO on the basis that
  all major KRB5/GSSAPI (mit-krb5, heimdal and Windows) implementations
  support SPNEGO mechanism.

- The various defunct tests from bin/tests have been removed:
  bin/tests/optional and bin/tests/pkcs11

- The text files generated from the MD files have been removed, the
  MarkDown has been designed to be readable by both humans and computers

- The xsl header is now generated by a simple sed command instead of
  perl helper

- The <irs/platform.h> header has been removed

- cleanups of configure.ac script to make it more simpler, addition of multiple
  macros (there's still work to be done though)

- the tarball can now be prepared with `make dist`

- the system tests are partially able to run in oot build

Here's a list of unfinished work that needs to be completed in subsequent merge
requests:

- `make distcheck` doesn't yet work (because of system tests oot run is not yet
  finished)

- documentation is not yet built, there's a different merge request with docbook
  to sphinx-build rst conversion that needs to be rebased and adapted on top of
  the automake

- msvc build is non functional yet and we need to decide whether we will just
  cross-compile bind9 using mingw-w64 or fix the msvc build

- contributed dlz modules are not included neither in the autoconf nor automake
2020-04-21 14:19:48 +02:00

300 lines
7.7 KiB
C

/*
* 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.
*/
/*
* Copyright (c) 1987, 1993, 1994
* 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.
*/
/*
* \note This file was adapted from the NetBSD project's source tree, RCS ID:
* NetBSD: getopt.c,v 1.15 1999/09/20 04:39:37 lukem Exp
*
* The primary change has been to rename items to the ISC namespace
* and format in the ISC coding style.
*
* This file is responsible for defining two operations that are not
* directly portable between Unix-like systems and Windows NT, option
* parsing and directory scanning. It is here because it was decided
* that the "gen" build utility was not to depend on libisc.a, so
* the functions declared in isc/commandline.h and isc/dir.h could not
* be used.
*
* The commandline stuff is pretty much a straight copy from the initial
* isc/commandline.c. The dir stuff was shrunk to fit the needs of gen.c.
*/
#ifndef DNS_GEN_WIN32_H
#define DNS_GEN_WIN32_H 1
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#ifdef __cplusplus
#define ISC_LANG_BEGINDECLS extern "C" {
#define ISC_LANG_ENDDECLS }
#else /* ifdef __cplusplus */
#define ISC_LANG_BEGINDECLS
#define ISC_LANG_ENDDECLS
#endif /* ifdef __cplusplus */
int isc_commandline_index = 1; /* Index into parent argv vector. */
int isc_commandline_option; /* Character checked for validity. */
char *isc_commandline_argument; /* Argument associated with option. */
char *isc_commandline_progname; /* For printing error messages. */
bool isc_commandline_errprint = true; /* Print error messages. */
bool isc_commandline_reset = true; /* Reset processing. */
#define BADOPT '?'
#define BADARG ':'
#define ENDOPT ""
ISC_LANG_BEGINDECLS
/*
* getopt --
* Parse argc/argv argument vector.
*/
int
isc_commandline_parse(int argc, char *const *argv, const char *options) {
static char *place = ENDOPT;
char *option; /* Index into *options of option. */
/*
* Update scanning pointer, either because a reset was requested or
* the previous argv was finished.
*/
if (isc_commandline_reset || *place == '\0') {
isc_commandline_reset = false;
if (isc_commandline_progname == NULL) {
isc_commandline_progname = argv[0];
}
if (isc_commandline_index >= argc ||
*(place = argv[isc_commandline_index]) != '-')
{
/*
* Index out of range or points to non-option.
*/
place = ENDOPT;
return (-1);
}
if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
/*
* Found '--' to signal end of options. Advance
* index to next argv, the first non-option.
*/
isc_commandline_index++;
place = ENDOPT;
return (-1);
}
}
isc_commandline_option = *place++;
option = strchr(options, isc_commandline_option);
/*
* Ensure valid option has been passed as specified by options string.
* '-:' is never a valid command line option because it could not
* distinguish ':' from the argument specifier in the options string.
*/
if (isc_commandline_option == ':' || option == NULL) {
if (*place == '\0') {
isc_commandline_index++;
}
if (isc_commandline_errprint && *options != ':') {
fprintf(stderr, "%s: illegal option -- %c\n",
isc_commandline_progname,
isc_commandline_option);
}
return (BADOPT);
}
if (*++option != ':') {
/*
* Option does not take an argument.
*/
isc_commandline_argument = NULL;
/*
* Skip to next argv if at the end of the current argv.
*/
if (*place == '\0') {
++isc_commandline_index;
}
} else {
/*
* Option needs an argument.
*/
if (*place != '\0') {
/*
* Option is in this argv, -D1 style.
*/
isc_commandline_argument = place;
} else if (argc > ++isc_commandline_index) {
/*
* Option is next argv, -D 1 style.
*/
isc_commandline_argument = argv[isc_commandline_index];
} else {
/*
* Argument needed, but no more argv.
*/
place = ENDOPT;
/*
* Silent failure with "missing argument" return
* when ':' starts options string, per historical spec.
*/
if (*options == ':') {
return (BADARG);
}
if (isc_commandline_errprint) {
fprintf(stderr,
"%s: option requires an argument -- "
"%c\n",
isc_commandline_progname,
isc_commandline_option);
}
return (BADOPT);
}
place = ENDOPT;
/*
* Point to argv that follows argument.
*/
isc_commandline_index++;
}
return (isc_commandline_option);
}
typedef struct {
HANDLE handle;
WIN32_FIND_DATA find_data;
bool first_file;
char *filename;
} isc_dir_t;
bool
start_directory(const char *path, isc_dir_t *dir) {
char pattern[_MAX_PATH], *p;
/*
* Need space for slash-splat and final NUL.
*/
if (strlen(path) + 3 > sizeof(pattern)) {
return (false);
}
strcpy(pattern, path);
/*
* Append slash (if needed) and splat.
*/
p = pattern + strlen(pattern);
if (p != pattern && p[-1] != '\\' && p[-1] != ':') {
*p++ = '\\';
}
*p++ = '*';
*p++ = '\0';
dir->first_file = true;
dir->handle = FindFirstFile(pattern, &dir->find_data);
if (dir->handle == INVALID_HANDLE_VALUE) {
dir->filename = NULL;
return (false);
} else {
dir->filename = dir->find_data.cFileName;
return (true);
}
}
bool
next_file(isc_dir_t *dir) {
if (dir->first_file) {
dir->first_file = false;
} else if (dir->handle != INVALID_HANDLE_VALUE) {
if (FindNextFile(dir->handle, &dir->find_data) == TRUE) {
dir->filename = dir->find_data.cFileName;
} else {
dir->filename = NULL;
}
} else {
dir->filename = NULL;
}
if (dir->filename != NULL) {
return (true);
} else {
return (false);
}
}
void
end_directory(isc_dir_t *dir) {
if (dir->handle != INVALID_HANDLE_VALUE) {
FindClose(dir->handle);
}
}
inline struct tm *
gmtime_r(const time_t *clock, struct tm *result) {
errno_t ret = gmtime_s(result, clock);
if (ret != 0) {
errno = ret;
return (NULL);
}
return (result);
}
ISC_LANG_ENDDECLS
#endif /* DNS_GEN_WIN32_H */