summaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:33:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:33:50 +0000
commitfe39ffb8b90ae4e002ed73fe98617cd590abb467 (patch)
treeb80e5956907d8aeaaffe4e4f0c068c0e6157ce8b /os
parentInitial commit. (diff)
downloadapache2-upstream/2.4.56.tar.xz
apache2-upstream/2.4.56.zip
Adding upstream version 2.4.56.upstream/2.4.56
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'os')
-rw-r--r--os/.indent.pro54
-rw-r--r--os/Makefile.in4
-rw-r--r--os/bs2000/ebcdic.c210
-rw-r--r--os/bs2000/ebcdic.h33
-rw-r--r--os/bs2000/os.c136
-rw-r--r--os/bs2000/os.h40
-rw-r--r--os/config.m426
-rw-r--r--os/netware/apache.xdcbin0 -> 128 bytes
-rw-r--r--os/netware/modules.c117
-rw-r--r--os/netware/netware_config_layout.h31
-rw-r--r--os/netware/os.h57
-rw-r--r--os/netware/pre_nw.h70
-rw-r--r--os/netware/util_nw.c112
-rw-r--r--os/os2/Makefile.in5
-rw-r--r--os/os2/config.m43
-rw-r--r--os/os2/core.mk7
-rw-r--r--os/os2/core_header.def19
-rw-r--r--os/os2/os.h40
-rw-r--r--os/os2/util_os2.c39
-rw-r--r--os/unix/Makefile.in5
-rw-r--r--os/unix/config.m47
-rw-r--r--os/unix/os.h52
-rw-r--r--os/unix/unixd.c733
-rw-r--r--os/unix/unixd.h142
-rw-r--r--os/win32/BaseAddr.ref135
-rw-r--r--os/win32/Makefile.in5
-rw-r--r--os/win32/ap_regkey.c642
-rw-r--r--os/win32/modules.c56
-rw-r--r--os/win32/os.h136
-rw-r--r--os/win32/util_win32.c103
-rw-r--r--os/win32/win32_config_layout.h31
31 files changed, 3050 insertions, 0 deletions
diff --git a/os/.indent.pro b/os/.indent.pro
new file mode 100644
index 0000000..a9fbe9f
--- /dev/null
+++ b/os/.indent.pro
@@ -0,0 +1,54 @@
+-i4 -npsl -di0 -br -nce -d0 -cli0 -npcs -nfc1
+-TBUFF
+-TFILE
+-TTRANS
+-TUINT4
+-T_trans
+-Tallow_options_t
+-Tapache_sfio
+-Tarray_header
+-Tbool_int
+-Tbuf_area
+-Tbuff_struct
+-Tbuffy
+-Tcmd_how
+-Tcmd_parms
+-Tcommand_rec
+-Tcommand_struct
+-Tconn_rec
+-Tcore_dir_config
+-Tcore_server_config
+-Tdir_maker_func
+-Tevent
+-Tglobals_s
+-Thandler_func
+-Thandler_rec
+-Tjoblist_s
+-Tlisten_rec
+-Tmerger_func
+-Tmode_t
+-Tmodule
+-Tmodule_struct
+-Tmutex
+-Tn_long
+-Tother_child_rec
+-Toverrides_t
+-Tparent_score
+-Tpid_t
+-Tpiped_log
+-Tpool
+-Trequest_rec
+-Trequire_line
+-Trlim_t
+-Tscoreboard
+-Tsemaphore
+-Tserver_addr_rec
+-Tserver_rec
+-Tserver_rec_chain
+-Tshort_score
+-Ttable
+-Ttable_entry
+-Tthread
+-Tu_wide_int
+-Tvtime_t
+-Twide_int
diff --git a/os/Makefile.in b/os/Makefile.in
new file mode 100644
index 0000000..9b35d49
--- /dev/null
+++ b/os/Makefile.in
@@ -0,0 +1,4 @@
+
+SUBDIRS = $(OS_DIR)
+
+include $(top_builddir)/build/rules.mk
diff --git a/os/bs2000/ebcdic.c b/os/bs2000/ebcdic.c
new file mode 100644
index 0000000..7ec0076
--- /dev/null
+++ b/os/bs2000/ebcdic.c
@@ -0,0 +1,210 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ap_config.h"
+#if APR_CHARSET_EBCDIC
+#include "ebcdic.h"
+/*
+ Initial Port for Apache-1.3 by <Martin.Kraemer Mch.SNI.De>
+
+"BS2000 OSD" is a POSIX on a main frame. It is made by Siemens AG, Germany.
+Within the POSIX subsystem, the same character set was chosen as in
+"native BS2000", namely EBCDIC.
+
+EBCDIC Table. (Yes, in EBCDIC, the letters 'a'..'z' are not contiguous!)
+This apr_table_t is bijective, i.e. there are no ambiguous or duplicate characters
+00 00 01 02 03 85 09 86 7f 87 8d 8e 0b 0c 0d 0e 0f *................*
+10 10 11 12 13 8f 0a 08 97 18 19 9c 9d 1c 1d 1e 1f *................*
+20 80 81 82 83 84 92 17 1b 88 89 8a 8b 8c 05 06 07 *................*
+30 90 91 16 93 94 95 96 04 98 99 9a 9b 14 15 9e 1a *................*
+40 20 a0 e2 e4 e0 e1 e3 e5 e7 f1 60 2e 3c 28 2b 7c * .........`.<(+|*
+50 26 e9 ea eb e8 ed ee ef ec df 21 24 2a 29 3b 9f *&.........!$*);.*
+60 2d 2f c2 c4 c0 c1 c3 c5 c7 d1 5e 2c 25 5f 3e 3f *-/........^,%_>?*
+70 f8 c9 ca cb c8 cd ce cf cc a8 3a 23 40 27 3d 22 *..........:#@'="*
+80 d8 61 62 63 64 65 66 67 68 69 ab bb f0 fd fe b1 *.abcdefghi......*
+90 b0 6a 6b 6c 6d 6e 6f 70 71 72 aa ba e6 b8 c6 a4 *.jklmnopqr......*
+a0 b5 af 73 74 75 76 77 78 79 7a a1 bf d0 dd de ae *..stuvwxyz......*
+b0 a2 a3 a5 b7 a9 a7 b6 bc bd be ac 5b 5c 5d b4 d7 *...........[\]..*
+c0 f9 41 42 43 44 45 46 47 48 49 ad f4 f6 f2 f3 f5 *.ABCDEFGHI......*
+d0 a6 4a 4b 4c 4d 4e 4f 50 51 52 b9 fb fc db fa ff *.JKLMNOPQR......*
+e0 d9 f7 53 54 55 56 57 58 59 5a b2 d4 d6 d2 d3 d5 *..STUVWXYZ......*
+f0 30 31 32 33 34 35 36 37 38 39 b3 7b dc 7d da 7e *0123456789.{.}.~*
+*/
+
+/* The bijective ebcdic-to-ascii table: */
+const unsigned char os_toascii_strictly[256] = {
+/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
+ 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
+/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
+ 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
+/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
+/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
+ 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
+/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
+ 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
+/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
+ 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
+/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
+ 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
+/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
+ 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
+/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
+/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
+/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
+/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
+ 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
+/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
+/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
+ 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
+/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
+/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
+};
+
+/* This apr_table_t is (almost) identical to the previous one. The only difference
+ * is the fact that it maps every EBCDIC *except 0x0A* to its ASCII
+ * equivalent. The reason for this apr_table_t is simple: Throughout the
+ * server, protocol strings are used in the form
+ * "Content-Type: text/plain\015\012". Now all the characters in the string
+ * are stored as EBCDIC, only the semantics of \012 is completely
+ * different from LF (look it up in the apr_table_t above). \015 happens to be
+ * mapped to \015 anyway, so there's no special case for it.
+ *
+ * In THIS table, EBCDIC-\012 is mapped to ASCII-\012.
+ * This apr_table_t is therefore used wherever an EBCDIC to ASCII conversion is
+ * needed in the server.
+ */
+/* ebcdic-to-ascii with \012 mapped to ASCII-\n */
+const unsigned char os_toascii[256] = {
+/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
+ 0x87, 0x8d, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
+/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
+ 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
+/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
+/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
+ 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
+/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
+ 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
+/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
+ 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
+/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
+ 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
+/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
+ 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
+/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
+/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
+/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
+/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
+ 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
+/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
+/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
+ 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
+/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
+/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
+};
+
+/* The ascii-to-ebcdic table:
+00 00 01 02 03 37 2d 2e 2f 16 05 15 0b 0c 0d 0e 0f *................*
+10 10 11 12 13 3c 3d 32 26 18 19 3f 27 1c 1d 1e 1f *................*
+20 40 5a 7f 7b 5b 6c 50 7d 4d 5d 5c 4e 6b 60 4b 61 * !"#$%&'()*+,-./
+30 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 7a 5e 4c 7e 6e 6f *0123456789:;<=>?*
+40 7c c1 c2 c3 c4 c5 c6 c7 c8 c9 d1 d2 d3 d4 d5 d6 *@ABCDEFGHIJKLMNO*
+50 d7 d8 d9 e2 e3 e4 e5 e6 e7 e8 e9 bb bc bd 6a 6d *PQRSTUVWXYZ[\]^_*
+60 4a 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 *`abcdefghijklmno*
+70 97 98 99 a2 a3 a4 a5 a6 a7 a8 a9 fb 4f fd ff 07 *pqrstuvwxyz{|}~.*
+80 20 21 22 23 24 04 06 08 28 29 2a 2b 2c 09 0a 14 *................*
+90 30 31 25 33 34 35 36 17 38 39 3a 3b 1a 1b 3e 5f *................*
+a0 41 aa b0 b1 9f b2 d0 b5 79 b4 9a 8a ba ca af a1 *................*
+b0 90 8f ea fa be a0 b6 b3 9d da 9b 8b b7 b8 b9 ab *................*
+c0 64 65 62 66 63 67 9e 68 74 71 72 73 78 75 76 77 *................*
+d0 ac 69 ed ee eb ef ec bf 80 e0 fe dd fc ad ae 59 *................*
+e0 44 45 42 46 43 47 9c 48 54 51 52 53 58 55 56 57 *................*
+f0 8c 49 cd ce cb cf cc e1 70 c0 de db dc 8d 8e df *................*
+*/
+const unsigned char os_toebcdic[256] = {
+/*00*/ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,
+ 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
+/*10*/ 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,
+ 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
+/*20*/ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
+ 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
+/*30*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /*0123456789:;<=>?*/
+/*40*/ 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /*@ABCDEFGHIJKLMNO*/
+/*50*/ 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
+ 0xe7, 0xe8, 0xe9, 0xbb, 0xbc, 0xbd, 0x6a, 0x6d, /*PQRSTUVWXYZ[\]^_*/
+/*60*/ 0x4a, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /*`abcdefghijklmno*/
+/*70*/ 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
+ 0xa7, 0xa8, 0xa9, 0xfb, 0x4f, 0xfd, 0xff, 0x07, /*pqrstuvwxyz{|}~.*/
+/*80*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /*................*/
+/*90*/ 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17,
+ 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0x5f, /*................*/
+/*a0*/ 0x41, 0xaa, 0xb0, 0xb1, 0x9f, 0xb2, 0xd0, 0xb5,
+ 0x79, 0xb4, 0x9a, 0x8a, 0xba, 0xca, 0xaf, 0xa1, /*................*/
+/*b0*/ 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3,
+ 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /*................*/
+/*c0*/ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68,
+ 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /*................*/
+/*d0*/ 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf,
+ 0x80, 0xe0, 0xfe, 0xdd, 0xfc, 0xad, 0xae, 0x59, /*................*/
+/*e0*/ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48,
+ 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /*................*/
+/*f0*/ 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1,
+ 0x70, 0xc0, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /*................*/
+};
+
+/* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)
+ * dest and srce may be identical, or separate memory blocks, but
+ * should not overlap.
+ */
+void
+ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count)
+{
+ while (count-- != 0) {
+ *dest++ = os_toascii[*srce++];
+ }
+}
+void
+ebcdic2ascii_strictly(unsigned char *dest, const unsigned char *srce, size_t count)
+{
+ while (count-- != 0) {
+ *dest++ = os_toascii_strictly[*srce++];
+ }
+}
+void
+ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count)
+{
+ while (count-- != 0) {
+ *dest++ = os_toebcdic[*srce++];
+ }
+}
+#endif /*APR_CHARSET_EBCDIC*/
diff --git a/os/bs2000/ebcdic.h b/os/bs2000/ebcdic.h
new file mode 100644
index 0000000..e48b859
--- /dev/null
+++ b/os/bs2000/ebcdic.h
@@ -0,0 +1,33 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file bs2000/ebcdic.h
+ * @brief EBCDIC/ASCII converson function declarations
+ *
+ * @addtogroup APACHE_OS_BS2000
+ * @{
+ */
+
+#include <sys/types.h>
+
+extern const unsigned char os_toascii[256];
+extern const unsigned char os_toebcdic[256];
+void ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count);
+void ebcdic2ascii_strictly(unsigned char *dest, const unsigned char *srce, size_t count);
+void ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count);
+/** @} */
+
diff --git a/os/bs2000/os.c b/os/bs2000/os.c
new file mode 100644
index 0000000..199706f
--- /dev/null
+++ b/os/bs2000/os.c
@@ -0,0 +1,136 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file will include OS specific functions which are not inlineable.
+ * Any inlineable functions should be defined in os-inline.c instead.
+ */
+
+#ifdef _OSD_POSIX
+
+#include "os.h"
+
+#include "httpd.h"
+#include "http_config.h"
+#include "http_log.h"
+#include "apr_lib.h"
+
+#define USER_LEN 8
+
+APLOG_USE_MODULE(core);
+
+typedef enum
+{
+ bs2_unknown, /* not initialized yet. */
+ bs2_noFORK, /* no fork() because -X flag was specified */
+ bs2_FORK, /* only fork() because uid != 0 */
+ bs2_UFORK /* Normally, ufork() is used to switch identities. */
+} bs2_ForkType;
+
+static bs2_ForkType forktype = bs2_unknown;
+
+/* Determine the method for forking off a child in such a way as to
+ * set both the POSIX and BS2000 user id's to the unprivileged user.
+ */
+static bs2_ForkType os_forktype(int one_process)
+{
+ /* have we checked the OS version before? If yes return the previous
+ * result - the OS release isn't going to change suddenly!
+ */
+ if (forktype == bs2_unknown) {
+ /* not initialized yet */
+
+ /* No fork if the one_process option was set */
+ if (one_process) {
+ forktype = bs2_noFORK;
+ }
+ /* If the user is unprivileged, use the normal fork() only. */
+ else if (getuid() != 0) {
+ forktype = bs2_FORK;
+ }
+ else
+ forktype = bs2_UFORK;
+ }
+ return forktype;
+}
+
+
+
+/* This routine complements the setuid() call: it causes the BS2000 job
+ * environment to be switched to the target user's user id.
+ * That is important if CGI scripts try to execute native BS2000 commands.
+ */
+int os_init_job_environment(server_rec *server, const char *user_name, int one_process)
+{
+ bs2_ForkType type = os_forktype(one_process);
+
+ /* We can be sure that no change to uid==0 is possible because of
+ * the checks in http_core.c:set_user()
+ */
+
+ if (one_process) {
+
+ type = forktype = bs2_noFORK;
+
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, APLOGNO(02170)
+ "The debug mode of Apache should only "
+ "be started by an unprivileged user!");
+ return 0;
+ }
+
+ return 0;
+}
+
+/* BS2000 requires a "special" version of fork() before a setuid() call */
+pid_t os_fork(const char *user)
+{
+ pid_t pid;
+ char username[USER_LEN+1];
+
+ switch (os_forktype(0)) {
+
+ case bs2_FORK:
+ pid = fork();
+ break;
+
+ case bs2_UFORK:
+ apr_cpystrn(username, user, sizeof username);
+
+ /* Make user name all upper case - for some versions of ufork() */
+ ap_str_toupper(username);
+
+ pid = ufork(username);
+ if (pid == -1 && errno == EPERM) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, errno, ap_server_conf,
+ APLOGNO(02171) "ufork: Possible mis-configuration "
+ "for user %s - Aborting.", user);
+ exit(1);
+ }
+ break;
+
+ default:
+ pid = 0;
+ break;
+ }
+
+ return pid;
+}
+
+#else /* _OSD_POSIX */
+void bs2000_os_is_not_here()
+{
+}
+#endif /* _OSD_POSIX */
diff --git a/os/bs2000/os.h b/os/bs2000/os.h
new file mode 100644
index 0000000..3b64c6e
--- /dev/null
+++ b/os/bs2000/os.h
@@ -0,0 +1,40 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file bs2000/os.h
+ * @brief This file in included in all Apache source code. It contains definitions
+ * of facilities available on _this_ operating system (HAVE_* macros),
+ * and prototypes of OS specific functions defined in os.c or os-inline.c
+ *
+ * @defgroup APACHE_OS_BS2000 bs2000
+ * @ingroup APACHE_OS
+ * @{
+ */
+
+#ifndef APACHE_OS_BS2000_H
+#define APACHE_OS_BS2000_H
+
+#define PLATFORM "BS2000"
+
+#include "../unix/os.h"
+
+/* Other ap_os_ routines not used by this platform */
+
+extern pid_t os_fork(const char *user);
+
+#endif /* APACHE_OS_BS2000_H */
+/** @} */
diff --git a/os/config.m4 b/os/config.m4
new file mode 100644
index 0000000..3188091
--- /dev/null
+++ b/os/config.m4
@@ -0,0 +1,26 @@
+AC_MSG_CHECKING(for target platform)
+
+case $host in
+*pc-os2-emx*)
+ OS="os2"
+ OS_DIR=$OS
+ ;;
+bs2000*)
+ OS="unix"
+ OS_DIR=$OS
+ ;;
+*cygwin*)
+ OS="cygwin"
+ OS_DIR="unix"
+ ;;
+*mingw32*)
+ OS="win32"
+ OS_DIR=$OS
+ ;;
+*)
+ OS="unix"
+ OS_DIR=$OS;;
+esac
+
+AC_MSG_RESULT($OS)
+APACHE_FAST_OUTPUT(os/${OS_DIR}/Makefile)
diff --git a/os/netware/apache.xdc b/os/netware/apache.xdc
new file mode 100644
index 0000000..12a7f6b
--- /dev/null
+++ b/os/netware/apache.xdc
Binary files differ
diff --git a/os/netware/modules.c b/os/netware/modules.c
new file mode 100644
index 0000000..2a7beee
--- /dev/null
+++ b/os/netware/modules.c
@@ -0,0 +1,117 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* modules.c --- major modules compiled into Apache for NetWare.
+ * Only insert an entry for a module if it must be compiled into
+ * the core server
+ */
+
+
+#include "httpd.h"
+#include "http_config.h"
+
+extern module core_module;
+extern module mpm_netware_module;
+extern module http_module;
+extern module so_module;
+extern module mime_module;
+extern module authn_core_module;
+extern module authz_core_module;
+extern module authz_host_module;
+extern module negotiation_module;
+extern module include_module;
+extern module dir_module;
+extern module alias_module;
+extern module env_module;
+extern module log_config_module;
+extern module setenvif_module;
+extern module watchdog_module;
+#ifdef USE_WINSOCK
+extern module nwssl_module;
+#endif
+extern module netware_module;
+
+module *ap_prelinked_modules[] = {
+ &core_module, /* core must come first */
+ &mpm_netware_module,
+ &http_module,
+ &so_module,
+ &mime_module,
+ &authn_core_module,
+ &authz_core_module,
+ &authz_host_module,
+ &negotiation_module,
+ &include_module,
+ &dir_module,
+ &alias_module,
+ &env_module,
+ &log_config_module,
+ &setenvif_module,
+ &watchdog_module,
+#ifdef USE_WINSOCK
+ &nwssl_module,
+#endif
+ &netware_module,
+ NULL
+};
+
+ap_module_symbol_t ap_prelinked_module_symbols[] = {
+ {"core_module", &core_module},
+ {"mpm_netware_module", &mpm_netware_module},
+ {"http_module", &http_module},
+ {"so_module", &so_module},
+ {"mime_module", &mime_module},
+ {"authn_core_module", &authn_core_module},
+ {"authz_core_module", &authz_core_module},
+ {"authz_host_module", &authz_host_module},
+ {"negotiation_module", &negotiation_module},
+ {"include_module", &include_module},
+ {"dir_module", &dir_module},
+ {"alias_module", &alias_module},
+ {"env_module", &env_module},
+ {"log_config_module", &log_config_module},
+ {"setenvif_module", &setenvif_module},
+ {"watchdog module", &watchdog_module},
+#ifdef USE_WINSOCK
+ {"nwssl_module", &nwssl_module},
+#endif
+ {"netware_module", &netware_module},
+ {NULL, NULL}
+};
+
+module *ap_preloaded_modules[] = {
+ &core_module,
+ &mpm_netware_module,
+ &http_module,
+ &so_module,
+ &mime_module,
+ &authn_core_module,
+ &authz_core_module,
+ &authz_host_module,
+ &negotiation_module,
+ &include_module,
+ &dir_module,
+ &alias_module,
+ &env_module,
+ &log_config_module,
+ &setenvif_module,
+ &watchdog_module,
+#ifdef USE_WINSOCK
+ &nwssl_module,
+#endif
+ &netware_module,
+ NULL
+};
diff --git a/os/netware/netware_config_layout.h b/os/netware/netware_config_layout.h
new file mode 100644
index 0000000..29d3320
--- /dev/null
+++ b/os/netware/netware_config_layout.h
@@ -0,0 +1,31 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file netware/netware_config_layout.h
+ * @brief This provides layout definitions for non-autoconf-based NetWare
+ * builds, and is copied to include/ap_config_layout.h during the build.
+ */
+
+#ifndef AP_CONFIG_LAYOUT_H
+#define AP_CONFIG_LAYOUT_H
+
+/* Check for definition of DEFAULT_REL_RUNTIMEDIR */
+#ifndef DEFAULT_REL_RUNTIMEDIR
+#define DEFAULT_REL_RUNTIMEDIR "logs"
+#endif
+
+#endif /* AP_CONFIG_LAYOUT_H */
diff --git a/os/netware/os.h b/os/netware/os.h
new file mode 100644
index 0000000..3c2209c
--- /dev/null
+++ b/os/netware/os.h
@@ -0,0 +1,57 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file netware/os.h
+ * @brief This file in included in all Apache source code. It contains definitions
+ * of facilities available on _this_ operating system (HAVE_* macros),
+ * and prototypes of OS specific functions defined in os.c or os-inline.c
+ *
+ * @defgroup APACHE_OS_NETWARE netware
+ * @ingroup APACHE_OS
+ * @{
+ */
+
+#ifndef APACHE_OS_H
+#define APACHE_OS_H
+
+#ifndef PLATFORM
+#define PLATFORM "NETWARE"
+#endif
+
+/* Define command-line rewriting for this platform, handled by core.
+ * For Netware, this is currently handled inside the Netware MPM.
+ * XXX To support a choice of MPMs, extract common platform behavior
+ * into a function specified here.
+ */
+#define AP_PLATFORM_REWRITE_ARGS_HOOK NULL
+
+#include <screen.h>
+
+AP_DECLARE_DATA extern int hold_screen_on_exit; /* Indicates whether the screen should be held open on exit*/
+
+#define CASE_BLIND_FILESYSTEM
+#define NO_WRITEV
+
+#define getpid NXThreadGetId
+
+/* Hold the screen open if there is an exit code and the hold_screen_on_exit flag >= 0 or the
+ hold_screen_on_exit > 0. If the hold_screen_on_exit flag is < 0 then close the screen no
+ matter what the exit code is. */
+#define exit(s) {if((s||hold_screen_on_exit)&&(hold_screen_on_exit>=0)){pressanykey();}apr_terminate();exit(s);}
+
+#endif /* ! APACHE_OS_H */
+/** @} */
diff --git a/os/netware/pre_nw.h b/os/netware/pre_nw.h
new file mode 100644
index 0000000..eef1f6f
--- /dev/null
+++ b/os/netware/pre_nw.h
@@ -0,0 +1,70 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file pre_nw.h
+ * @brief Definitions for Netware systems
+ *
+ * @addtogroup APACHE_OS_NETWARE
+ * @{
+ */
+
+#ifndef __pre_nw__
+#define __pre_nw__
+
+#include <stdint.h>
+
+#ifndef __GNUC__
+#pragma precompile_target "precomp.mch"
+#endif
+
+#define NETWARE
+
+#define N_PLAT_NLM
+
+/* hint for MSL C++ that we're on NetWare platform */
+#define __NETWARE__
+
+/* the FAR keyword has no meaning in a 32-bit environment
+ but is used in the SDK headers so we take it out */
+#define FAR
+#define far
+
+/* no-op for Codewarrior C compiler; a functions are cdecl
+ by default */
+#define cdecl
+
+/* if we have wchar_t enabled in C++, predefine this type to avoid
+ a conflict in Novell's header files */
+#ifndef __GNUC__
+#if (__option(cplusplus) && __option(wchar_type))
+#define _WCHAR_T
+#endif
+#endif
+
+/* C9X definition used by MSL C++ library */
+#define DECIMAL_DIG 17
+
+/* some code may want to use the MS convention for long long */
+#ifndef __int64
+#define __int64 long long
+#endif
+
+/* Restrict the number of nested includes */
+#define AP_MAX_INCLUDE_DEPTH 48
+
+#endif
+/** @} */
diff --git a/os/netware/util_nw.c b/os/netware/util_nw.c
new file mode 100644
index 0000000..97845d4
--- /dev/null
+++ b/os/netware/util_nw.c
@@ -0,0 +1,112 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "httpd.h"
+#include "http_log.h"
+#include "ap_mpm.h"
+
+#include <netware.h>
+#include <nks/netware.h>
+#include <nks/vm.h>
+
+void ap_down_server_cb(void *, void *);
+void ap_dummy_cb(void *, void *);
+void ap_cb_destroy(void *);
+
+int nlmUnloadSignaled(int wait);
+event_handle_t eh;
+Warn_t ref;
+Report_t dum;
+
+AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
+ const request_rec *r,
+ apr_proc_t *newproc, const char *progname,
+ const char * const *args,
+ const char * const *env,
+ apr_procattr_t *attr, apr_pool_t *p)
+{
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+}
+
+int _NonAppCheckUnload(void)
+{
+ return nlmUnloadSignaled(1);
+}
+
+/* down server event callback */
+void ap_down_server_cb(void *a, void *b)
+{
+ nlmUnloadSignaled(0);
+ return;
+}
+
+/* Required place holder event callback */
+void ap_dummy_cb(void *a, void *b)
+{
+ return;
+}
+
+/* destroy callback resources */
+void ap_cb_destroy(void *a)
+{
+ /* cleanup down event notification */
+ UnRegisterEventNotification(eh);
+ NX_UNWRAP_INTERFACE(ref);
+ NX_UNWRAP_INTERFACE(dum);
+}
+
+int _NonAppStart
+(
+ void *NLMHandle,
+ void *errorScreen,
+ const char *cmdLine,
+ const char *loadDirPath,
+ size_t uninitializedDataLength,
+ void *NLMFileHandle,
+ int (*readRoutineP)( int conn, void *fileHandle, size_t offset,
+ size_t nbytes, size_t *bytesRead, void *buffer ),
+ size_t customDataOffset,
+ size_t customDataSize,
+ int messageCount,
+ const char **messages
+)
+{
+#pragma unused(cmdLine)
+#pragma unused(loadDirPath)
+#pragma unused(uninitializedDataLength)
+#pragma unused(NLMFileHandle)
+#pragma unused(readRoutineP)
+#pragma unused(customDataOffset)
+#pragma unused(customDataSize)
+#pragma unused(messageCount)
+#pragma unused(messages)
+
+ /* register for down server event */
+ rtag_t rt = AllocateResourceTag(NLMHandle, "Apache2 Down Server Callback",
+ EventSignature);
+
+ NX_WRAP_INTERFACE((void *)ap_down_server_cb, 2, (void **)&ref);
+ NX_WRAP_INTERFACE((void *)ap_dummy_cb, 2, (void **)&dum);
+ eh = RegisterForEventNotification(rt, EVENT_DOWN_SERVER,
+ EVENT_PRIORITY_APPLICATION,
+ ref, dum, NULL);
+
+ /* clean-up */
+ NXVmRegisterExitHandler(ap_cb_destroy, NULL);
+
+ return 0;
+}
+
diff --git a/os/os2/Makefile.in b/os/os2/Makefile.in
new file mode 100644
index 0000000..fba4972
--- /dev/null
+++ b/os/os2/Makefile.in
@@ -0,0 +1,5 @@
+
+LTLIBRARY_NAME = libos.la
+LTLIBRARY_SOURCES = util_os2.c
+
+include $(top_srcdir)/build/ltlib.mk
diff --git a/os/os2/config.m4 b/os/os2/config.m4
new file mode 100644
index 0000000..b62d214
--- /dev/null
+++ b/os/os2/config.m4
@@ -0,0 +1,3 @@
+if test "$OS" = "os2" ; then
+ APR_ADDTO(CFLAGS, [-DOS2 -O2])
+fi
diff --git a/os/os2/core.mk b/os/os2/core.mk
new file mode 100644
index 0000000..639417e
--- /dev/null
+++ b/os/os2/core.mk
@@ -0,0 +1,7 @@
+# Some rules for making a shared core dll on OS/2
+
+os2core: httpd.dll $(CORE_IMPLIB)
+ $(LIBTOOL) --mode=link gcc -Zstack 512 $(LDFLAGS) $(EXTRA_LDFLAGS) -o httpd $(CORE_IMPLIB)
+
+httpd.dll: $(PROGRAM_DEPENDENCIES) $(CORE_IMPLIB)
+ $(LINK) -Zdll $(EXTRA_LDFLAGS) -s -o $@ server/exports.lo modules.lo $(PROGRAM_DEPENDENCIES) $(AP_LIBS) server/ApacheCoreOS2.def
diff --git a/os/os2/core_header.def b/os/os2/core_header.def
new file mode 100644
index 0000000..ec3703a
--- /dev/null
+++ b/os/os2/core_header.def
@@ -0,0 +1,19 @@
+LIBRARY httpd INITINSTANCE
+DESCRIPTION "Apache Server Core"
+DATA NONSHARED
+
+EXPORTS
+ "main"
+
+; One for mod_dav from socket library
+ "_swaps"
+
+; And some more for mod_unique_id
+ "gethostname"
+ "gethostbyname"
+ "_swapl"
+ "h_errno"
+ "inet_ntoa"
+
+; mod_proxy needs this one
+ "inet_addr"
diff --git a/os/os2/os.h b/os/os2/os.h
new file mode 100644
index 0000000..1f8c9ba
--- /dev/null
+++ b/os/os2/os.h
@@ -0,0 +1,40 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file os2/os.h
+ * @brief This file in included in all Apache source code. It contains definitions
+ * of facilities available on _this_ operating system (HAVE_* macros),
+ * and prototypes of OS specific functions defined in os.c or os-inline.c
+ *
+ * @defgroup APACHE_OS_OS2 os2
+ * @ingroup APACHE_OS
+ * @{
+ */
+
+#ifndef APACHE_OS_H
+#define APACHE_OS_H
+
+#define PLATFORM "OS/2"
+
+/* going away shortly... */
+#define HAVE_DRIVE_LETTERS
+#define HAVE_UNC_PATHS
+#define CASE_BLIND_FILESYSTEM
+#define AP_PLATFORM_REWRITE_ARGS_HOOK NULL
+
+#endif /* ! APACHE_OS_H */
+/** @} */
diff --git a/os/os2/util_os2.c b/os/os2/util_os2.c
new file mode 100644
index 0000000..9156fb3
--- /dev/null
+++ b/os/os2/util_os2.c
@@ -0,0 +1,39 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define INCL_DOS
+#define INCL_DOSERRORS
+#include <os2.h>
+#include "ap_config.h"
+#include "httpd.h"
+#include "http_log.h"
+#include "os.h"
+#include <sys/time.h>
+#include <sys/signal.h>
+#include <ctype.h>
+#include <string.h>
+#include "apr_strings.h"
+
+
+AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
+ const request_rec *r,
+ apr_proc_t *newproc, const char *progname,
+ const char * const *args,
+ const char * const *env,
+ apr_procattr_t *attr, apr_pool_t *p)
+{
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+}
diff --git a/os/unix/Makefile.in b/os/unix/Makefile.in
new file mode 100644
index 0000000..eddb2c2
--- /dev/null
+++ b/os/unix/Makefile.in
@@ -0,0 +1,5 @@
+
+LTLIBRARY_NAME = libos.la
+LTLIBRARY_SOURCES = unixd.c
+
+include $(top_srcdir)/build/ltlib.mk
diff --git a/os/unix/config.m4 b/os/unix/config.m4
new file mode 100644
index 0000000..dacbf6b
--- /dev/null
+++ b/os/unix/config.m4
@@ -0,0 +1,7 @@
+if test "$OS" = "unix" ; then
+ APACHE_TYPE_RLIM_T
+
+ AC_CHECK_HEADERS(sys/time.h sys/resource.h sys/sem.h sys/ipc.h)
+
+ AC_CHECK_FUNCS(setsid killpg)
+fi
diff --git a/os/unix/os.h b/os/unix/os.h
new file mode 100644
index 0000000..1494edd
--- /dev/null
+++ b/os/unix/os.h
@@ -0,0 +1,52 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file unix/os.h
+ * @brief This file in included in all Apache source code. It contains definitions
+ * of facilities available on _this_ operating system (HAVE_* macros),
+ * and prototypes of OS specific functions defined in os.c or os-inline.c
+ *
+ * @defgroup APACHE_OS_UNIX unix
+ * @ingroup APACHE_OS
+ * @{
+ */
+
+#ifndef APACHE_OS_H
+#define APACHE_OS_H
+
+#include "apr.h"
+#include "ap_config.h"
+
+#ifndef PLATFORM
+#define PLATFORM "Unix"
+#endif
+
+/* On platforms where AP_NEED_SET_MUTEX_PERMS is defined, modules
+ * should call unixd_set_*_mutex_perms on mutexes created in the
+ * parent process. */
+#define AP_NEED_SET_MUTEX_PERMS 1
+
+/* Define command-line rewriting for this platform, handled by core.
+ */
+#define AP_PLATFORM_REWRITE_ARGS_HOOK ap_mpm_rewrite_args
+
+#ifdef _OSD_POSIX
+pid_t os_fork(const char *user);
+#endif
+
+#endif /* !APACHE_OS_H */
+/** @} */
diff --git a/os/unix/unixd.c b/os/unix/unixd.c
new file mode 100644
index 0000000..0245720
--- /dev/null
+++ b/os/unix/unixd.c
@@ -0,0 +1,733 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ap_config.h"
+#include "httpd.h"
+#include "http_config.h"
+#include "http_main.h"
+#include "http_core.h"
+#include "http_log.h"
+#include "unixd.h"
+#include "mpm_common.h"
+#include "os.h"
+#include "ap_mpm.h"
+#include "apr_thread_proc.h"
+#include "apr_signal.h"
+#include "apr_strings.h"
+#include "apr_portable.h"
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+/* XXX */
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#ifdef HAVE_SYS_SEM_H
+#include <sys/sem.h>
+#endif
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
+unixd_config_rec ap_unixd_config;
+
+APLOG_USE_MODULE(core);
+
+AP_DECLARE(void) ap_unixd_set_rlimit(cmd_parms *cmd, struct rlimit **plimit,
+ const char *arg,
+ const char * arg2, int type)
+{
+#if (defined(RLIMIT_CPU) || defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_NPROC) || defined(RLIMIT_AS)) && APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT
+ char *str;
+ struct rlimit *limit;
+ /* If your platform doesn't define rlim_t then typedef it in ap_config.h */
+ rlim_t cur = 0;
+ rlim_t max = 0;
+
+ *plimit = (struct rlimit *)apr_pcalloc(cmd->pool, sizeof(**plimit));
+ limit = *plimit;
+ if ((getrlimit(type, limit)) != 0) {
+ *plimit = NULL;
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, cmd->server, APLOGNO(02172)
+ "%s: getrlimit failed", cmd->cmd->name);
+ return;
+ }
+
+ if (*(str = ap_getword_conf(cmd->temp_pool, &arg)) != '\0') {
+ if (!strcasecmp(str, "max")) {
+ cur = limit->rlim_max;
+ }
+ else {
+ cur = atol(str);
+ }
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server, APLOGNO(02173)
+ "Invalid parameters for %s", cmd->cmd->name);
+ return;
+ }
+
+ if (arg2 && (*(str = ap_getword_conf(cmd->temp_pool, &arg2)) != '\0')) {
+ max = atol(str);
+ }
+
+ /* if we aren't running as root, cannot increase max */
+ if (geteuid()) {
+ limit->rlim_cur = cur;
+ if (max && (max > limit->rlim_max)) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server, APLOGNO(02174)
+ "Must be uid 0 to raise maximum %s", cmd->cmd->name);
+ }
+ else if (max) {
+ limit->rlim_max = max;
+ }
+ }
+ else {
+ if (cur) {
+ limit->rlim_cur = cur;
+ }
+ if (max) {
+ limit->rlim_max = max;
+ }
+ }
+#else
+
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server, APLOGNO(02175)
+ "Platform does not support rlimit for %s", cmd->cmd->name);
+#endif
+}
+
+APR_HOOK_STRUCT(
+ APR_HOOK_LINK(get_suexec_identity)
+)
+
+AP_IMPLEMENT_HOOK_RUN_FIRST(ap_unix_identity_t *, get_suexec_identity,
+ (const request_rec *r), (r), NULL)
+
+static apr_status_t ap_unix_create_privileged_process(
+ apr_proc_t *newproc, const char *progname,
+ const char * const *args,
+ const char * const *env,
+ apr_procattr_t *attr, ap_unix_identity_t *ugid,
+ apr_pool_t *p)
+{
+ int i = 0;
+ const char **newargs;
+ char *newprogname;
+ char *execuser, *execgroup;
+ const char *argv0;
+
+ if (!ap_unixd_config.suexec_enabled) {
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+ }
+
+ argv0 = ap_strrchr_c(progname, '/');
+ /* Allow suexec's "/" check to succeed */
+ if (argv0 != NULL) {
+ argv0++;
+ }
+ else {
+ argv0 = progname;
+ }
+
+
+ if (ugid->userdir) {
+ execuser = apr_psprintf(p, "~%ld", (long) ugid->uid);
+ }
+ else {
+ execuser = apr_psprintf(p, "%ld", (long) ugid->uid);
+ }
+ execgroup = apr_psprintf(p, "%ld", (long) ugid->gid);
+
+ if (!execuser || !execgroup) {
+ return APR_ENOMEM;
+ }
+
+ i = 0;
+ while (args[i])
+ i++;
+ /* allocate space for 4 new args, the input args, and a null terminator */
+ newargs = apr_palloc(p, sizeof(char *) * (i + 4));
+ newprogname = SUEXEC_BIN;
+ newargs[0] = SUEXEC_BIN;
+ newargs[1] = execuser;
+ newargs[2] = execgroup;
+ newargs[3] = apr_pstrdup(p, argv0);
+
+ /*
+ ** using a shell to execute suexec makes no sense thus
+ ** we force everything to be APR_PROGRAM, and never
+ ** APR_SHELLCMD
+ */
+ if (apr_procattr_cmdtype_set(attr, APR_PROGRAM) != APR_SUCCESS) {
+ return APR_EGENERAL;
+ }
+
+ i = 1;
+ do {
+ newargs[i + 3] = args[i];
+ } while (args[i++]);
+
+ return apr_proc_create(newproc, newprogname, newargs, env, attr, p);
+}
+
+AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
+ const request_rec *r,
+ apr_proc_t *newproc, const char *progname,
+ const char * const *args,
+ const char * const *env,
+ apr_procattr_t *attr, apr_pool_t *p)
+{
+ ap_unix_identity_t *ugid = ap_run_get_suexec_identity(r);
+
+ if (ugid == NULL) {
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+ }
+
+ return ap_unix_create_privileged_process(newproc, progname, args, env,
+ attr, ugid, p);
+}
+
+/* XXX move to APR and externalize (but implement differently :) ) */
+static apr_lockmech_e proc_mutex_mech(apr_proc_mutex_t *pmutex)
+{
+ const char *mechname = apr_proc_mutex_name(pmutex);
+
+ if (!strcmp(mechname, "sysvsem")) {
+ return APR_LOCK_SYSVSEM;
+ }
+ else if (!strcmp(mechname, "flock")) {
+ return APR_LOCK_FLOCK;
+ }
+ return APR_LOCK_DEFAULT;
+}
+
+AP_DECLARE(apr_status_t) ap_unixd_set_proc_mutex_perms(apr_proc_mutex_t *pmutex)
+{
+ if (!geteuid()) {
+ apr_lockmech_e mech = proc_mutex_mech(pmutex);
+
+ switch(mech) {
+#if APR_HAS_SYSVSEM_SERIALIZE
+ case APR_LOCK_SYSVSEM:
+ {
+ apr_os_proc_mutex_t ospmutex;
+#if !APR_HAVE_UNION_SEMUN
+ union semun {
+ long val;
+ struct semid_ds *buf;
+ unsigned short *array;
+ };
+#endif
+ union semun ick;
+ struct semid_ds buf = { { 0 } };
+
+ apr_os_proc_mutex_get(&ospmutex, pmutex);
+ buf.sem_perm.uid = ap_unixd_config.user_id;
+ buf.sem_perm.gid = ap_unixd_config.group_id;
+ buf.sem_perm.mode = 0600;
+ ick.buf = &buf;
+ if (semctl(ospmutex.crossproc, 0, IPC_SET, ick) < 0) {
+ return errno;
+ }
+ }
+ break;
+#endif
+#if APR_HAS_FLOCK_SERIALIZE
+ case APR_LOCK_FLOCK:
+ {
+ const char *lockfile = apr_proc_mutex_lockfile(pmutex);
+
+ if (lockfile) {
+ if (chown(lockfile, ap_unixd_config.user_id,
+ -1 /* no gid change */) < 0) {
+ return errno;
+ }
+ }
+ }
+ break;
+#endif
+ default:
+ /* do nothing */
+ break;
+ }
+ }
+ return APR_SUCCESS;
+}
+
+AP_DECLARE(apr_status_t) ap_unixd_set_global_mutex_perms(apr_global_mutex_t *gmutex)
+{
+#if !APR_PROC_MUTEX_IS_GLOBAL
+ apr_os_global_mutex_t osgmutex;
+ apr_os_global_mutex_get(&osgmutex, gmutex);
+ return ap_unixd_set_proc_mutex_perms(osgmutex.proc_mutex);
+#else /* APR_PROC_MUTEX_IS_GLOBAL */
+ /* In this case, apr_proc_mutex_t and apr_global_mutex_t are the same. */
+ return ap_unixd_set_proc_mutex_perms(gmutex);
+#endif /* APR_PROC_MUTEX_IS_GLOBAL */
+}
+
+AP_DECLARE(apr_status_t) ap_unixd_accept(void **accepted, ap_listen_rec *lr,
+ apr_pool_t *ptrans)
+{
+ apr_socket_t *csd;
+ apr_status_t status;
+#ifdef _OSD_POSIX
+ int sockdes;
+#endif
+
+ *accepted = NULL;
+ status = apr_socket_accept(&csd, lr->sd, ptrans);
+ if (status == APR_SUCCESS) {
+ *accepted = csd;
+#ifdef _OSD_POSIX
+ apr_os_sock_get(&sockdes, csd);
+ if (sockdes >= FD_SETSIZE) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf, APLOGNO(02176)
+ "new file descriptor %d is too large; you probably need "
+ "to rebuild Apache with a larger FD_SETSIZE "
+ "(currently %d)",
+ sockdes, FD_SETSIZE);
+ apr_socket_close(csd);
+ return APR_EINTR;
+ }
+#endif
+ return APR_SUCCESS;
+ }
+
+ if (APR_STATUS_IS_EINTR(status)) {
+ return status;
+ }
+ /* Our old behaviour here was to continue after accept()
+ * errors. But this leads us into lots of troubles
+ * because most of the errors are quite fatal. For
+ * example, EMFILE can be caused by slow descriptor
+ * leaks (say in a 3rd party module, or libc). It's
+ * foolish for us to continue after an EMFILE. We also
+ * seem to tickle kernel bugs on some platforms which
+ * lead to never-ending loops here. So it seems best
+ * to just exit in most cases.
+ */
+ switch (status) {
+#if defined(HPUX11) && defined(ENOBUFS)
+ /* On HPUX 11.x, the 'ENOBUFS, No buffer space available'
+ * error occurs because the accept() cannot complete.
+ * You will not see ENOBUFS with 10.20 because the kernel
+ * hides any occurrence from being returned to user space.
+ * ENOBUFS with 11.x's TCP/IP stack is possible, and could
+ * occur intermittently. As a work-around, we are going to
+ * ignore ENOBUFS.
+ */
+ case ENOBUFS:
+#endif
+
+#ifdef EPROTO
+ /* EPROTO on certain older kernels really means
+ * ECONNABORTED, so we need to ignore it for them.
+ * See discussion in new-httpd archives nh.9701
+ * search for EPROTO.
+ *
+ * Also see nh.9603, search for EPROTO:
+ * There is potentially a bug in Solaris 2.x x<6,
+ * and other boxes that implement tcp sockets in
+ * userland (i.e. on top of STREAMS). On these
+ * systems, EPROTO can actually result in a fatal
+ * loop. See PR#981 for example. It's hard to
+ * handle both uses of EPROTO.
+ */
+ case EPROTO:
+#endif
+#ifdef ECONNABORTED
+ case ECONNABORTED:
+#endif
+ /* Linux generates the rest of these, other tcp
+ * stacks (i.e. bsd) tend to hide them behind
+ * getsockopt() interfaces. They occur when
+ * the net goes sour or the client disconnects
+ * after the three-way handshake has been done
+ * in the kernel but before userland has picked
+ * up the socket.
+ */
+#ifdef ECONNRESET
+ case ECONNRESET:
+#endif
+#ifdef ETIMEDOUT
+ case ETIMEDOUT:
+#endif
+#ifdef EHOSTUNREACH
+ case EHOSTUNREACH:
+#endif
+#ifdef ENETUNREACH
+ case ENETUNREACH:
+#endif
+ /* EAGAIN/EWOULDBLOCK can be returned on BSD-derived
+ * TCP stacks when the connection is aborted before
+ * we call connect, but only because our listener
+ * sockets are non-blocking (AP_NONBLOCK_WHEN_MULTI_LISTEN)
+ */
+#ifdef EAGAIN
+ case EAGAIN:
+#endif
+#ifdef EWOULDBLOCK
+#if !defined(EAGAIN) || EAGAIN != EWOULDBLOCK
+ case EWOULDBLOCK:
+#endif
+#endif
+ break;
+#ifdef ENETDOWN
+ case ENETDOWN:
+ /*
+ * When the network layer has been shut down, there
+ * is not much use in simply exiting: the parent
+ * would simply re-create us (and we'd fail again).
+ * Use the CHILDFATAL code to tear the server down.
+ * @@@ Martin's idea for possible improvement:
+ * A different approach would be to define
+ * a new APEXIT_NETDOWN exit code, the reception
+ * of which would make the parent shutdown all
+ * children, then idle-loop until it detected that
+ * the network is up again, and restart the children.
+ * Ben Hyde noted that temporary ENETDOWN situations
+ * occur in mobile IP.
+ */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf, APLOGNO(02177)
+ "apr_socket_accept: giving up.");
+ return APR_EGENERAL;
+#endif /*ENETDOWN*/
+
+ default:
+ /* If the socket has been closed in ap_close_listeners()
+ * by the restart/stop action, we may get EBADF.
+ * Do not print an error in this case.
+ */
+ if (!lr->active) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, status, ap_server_conf, APLOGNO(02178)
+ "apr_socket_accept failed for inactive listener");
+ return status;
+ }
+ ap_log_error(APLOG_MARK, APLOG_ERR, status, ap_server_conf, APLOGNO(02179)
+ "apr_socket_accept: (client socket)");
+ return APR_EGENERAL;
+ }
+ return status;
+}
+
+
+/* Unixes MPMs' */
+
+static ap_unixd_mpm_retained_data *retained_data = NULL;
+static apr_status_t retained_data_cleanup(void *unused)
+{
+ (void)unused;
+ retained_data = NULL;
+ return APR_SUCCESS;
+}
+
+AP_DECLARE(ap_unixd_mpm_retained_data *) ap_unixd_mpm_get_retained_data()
+{
+ if (!retained_data) {
+ retained_data = ap_retained_data_create("ap_unixd_mpm_retained_data",
+ sizeof(*retained_data));
+ apr_pool_pre_cleanup_register(ap_pglobal, NULL, retained_data_cleanup);
+ retained_data->mpm_state = AP_MPMQ_STARTING;
+ }
+ return retained_data;
+}
+
+static void sig_term(int sig)
+{
+ if (!retained_data) {
+ /* Main process (ap_pglobal) is dying */
+ return;
+ }
+ retained_data->mpm_state = AP_MPMQ_STOPPING;
+ if (retained_data->shutdown_pending
+ && (retained_data->is_ungraceful
+ || sig == AP_SIG_GRACEFUL_STOP)) {
+ /* Already handled */
+ return;
+ }
+
+ retained_data->shutdown_pending = 1;
+ if (sig != AP_SIG_GRACEFUL_STOP) {
+ retained_data->is_ungraceful = 1;
+ }
+}
+
+static void sig_restart(int sig)
+{
+ if (!retained_data) {
+ /* Main process (ap_pglobal) is dying */
+ return;
+ }
+ retained_data->mpm_state = AP_MPMQ_STOPPING;
+ if (retained_data->restart_pending
+ && (retained_data->is_ungraceful
+ || sig == AP_SIG_GRACEFUL)) {
+ /* Already handled */
+ return;
+ }
+
+ retained_data->restart_pending = 1;
+ if (sig != AP_SIG_GRACEFUL) {
+ retained_data->is_ungraceful = 1;
+ }
+}
+
+static apr_status_t unset_signals(void *unused)
+{
+ if (!retained_data) {
+ /* Main process (ap_pglobal) is dying */
+ return APR_SUCCESS;
+ }
+ retained_data->shutdown_pending = retained_data->restart_pending = 0;
+ retained_data->was_graceful = !retained_data->is_ungraceful;
+ retained_data->is_ungraceful = 0;
+
+ return APR_SUCCESS;
+}
+
+static void ap_terminate(void)
+{
+ ap_main_state = AP_SQ_MS_EXITING;
+ apr_pool_destroy(ap_pglobal);
+ apr_terminate();
+}
+
+AP_DECLARE(void) ap_unixd_mpm_set_signals(apr_pool_t *pconf, int one_process)
+{
+#ifndef NO_USE_SIGACTION
+ struct sigaction sa;
+#endif
+
+ if (!one_process) {
+ ap_fatal_signal_setup(ap_server_conf, pconf);
+ }
+ else if (!ap_retained_data_get("ap_unixd_mpm_one_process_cleanup")) {
+ /* In one process mode (debug), httpd will exit immediately when asked
+ * to (SIGTERM/SIGINT) and never restart. We still want the cleanups to
+ * run though (such that e.g. temporary files/IPCs don't leak on the
+ * system), so the first time around we use atexit() to cleanup after
+ * ourselves.
+ */
+ ap_retained_data_create("ap_unixd_mpm_one_process_cleanup", 1);
+ atexit(ap_terminate);
+ }
+
+ /* Signals' handlers depend on retained data */
+ (void)ap_unixd_mpm_get_retained_data();
+
+#ifndef NO_USE_SIGACTION
+ memset(&sa, 0, sizeof sa);
+ sigemptyset(&sa.sa_mask);
+
+#ifdef SIGPIPE
+ sa.sa_handler = SIG_IGN;
+ if (sigaction(SIGPIPE, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00269)
+ "sigaction(SIGPIPE)");
+#endif
+#ifdef SIGXCPU
+ sa.sa_handler = SIG_DFL;
+ if (sigaction(SIGXCPU, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00267)
+ "sigaction(SIGXCPU)");
+#endif
+#ifdef SIGXFSZ
+ /* For systems following the LFS standard, ignoring SIGXFSZ allows
+ * a write() beyond the 2GB limit to fail gracefully with E2BIG
+ * rather than terminate the process. */
+ sa.sa_handler = SIG_IGN;
+ if (sigaction(SIGXFSZ, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00268)
+ "sigaction(SIGXFSZ)");
+#endif
+
+ sa.sa_handler = sig_term;
+ if (sigaction(SIGTERM, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00264)
+ "sigaction(SIGTERM)");
+#ifdef SIGINT
+ if (sigaction(SIGINT, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00266)
+ "sigaction(SIGINT)");
+#endif
+#ifdef AP_SIG_GRACEFUL_STOP
+ if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00265)
+ "sigaction(" AP_SIG_GRACEFUL_STOP_STRING ")");
+#endif
+
+ /* Don't catch restart signals in ONE_PROCESS mode :) */
+ if (!one_process) {
+ sa.sa_handler = sig_restart;
+ if (sigaction(SIGHUP, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00270)
+ "sigaction(SIGHUP)");
+ if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00271)
+ "sigaction(" AP_SIG_GRACEFUL_STRING ")");
+ }
+
+#else /* NO_USE_SIGACTION */
+
+#ifdef SIGPIPE
+ apr_signal(SIGPIPE, SIG_IGN);
+#endif /* SIGPIPE */
+#ifdef SIGXCPU
+ apr_signal(SIGXCPU, SIG_DFL);
+#endif /* SIGXCPU */
+#ifdef SIGXFSZ
+ apr_signal(SIGXFSZ, SIG_IGN);
+#endif /* SIGXFSZ */
+
+ apr_signal(SIGTERM, sig_term);
+#ifdef AP_SIG_GRACEFUL_STOP
+ apr_signal(AP_SIG_GRACEFUL_STOP, sig_term);
+#endif /* AP_SIG_GRACEFUL_STOP */
+
+ if (!one_process) {
+ /* Don't restart in ONE_PROCESS mode :) */
+#ifdef SIGHUP
+ apr_signal(SIGHUP, sig_restart);
+#endif /* SIGHUP */
+#ifdef AP_SIG_GRACEFUL
+ apr_signal(AP_SIG_GRACEFUL, sig_restart);
+#endif /* AP_SIG_GRACEFUL */
+ }
+
+#endif /* NO_USE_SIGACTION */
+
+ apr_pool_cleanup_register(pconf, NULL, unset_signals,
+ apr_pool_cleanup_null);
+}
+
+
+#ifdef _OSD_POSIX
+
+#include "apr_lib.h"
+
+#define USER_LEN 8
+
+typedef enum
+{
+ bs2_unknown, /* not initialized yet. */
+ bs2_noFORK, /* no fork() because -X flag was specified */
+ bs2_FORK, /* only fork() because uid != 0 */
+ bs2_UFORK /* Normally, ufork() is used to switch identities. */
+} bs2_ForkType;
+
+static bs2_ForkType forktype = bs2_unknown;
+
+/* Determine the method for forking off a child in such a way as to
+ * set both the POSIX and BS2000 user id's to the unprivileged user.
+ */
+static bs2_ForkType os_forktype(int one_process)
+{
+ /* have we checked the OS version before? If yes return the previous
+ * result - the OS release isn't going to change suddenly!
+ */
+ if (forktype == bs2_unknown) {
+ /* not initialized yet */
+
+ /* No fork if the one_process option was set */
+ if (one_process) {
+ forktype = bs2_noFORK;
+ }
+ /* If the user is unprivileged, use the normal fork() only. */
+ else if (getuid() != 0) {
+ forktype = bs2_FORK;
+ }
+ else
+ forktype = bs2_UFORK;
+ }
+ return forktype;
+}
+
+
+
+/* This routine complements the setuid() call: it causes the BS2000 job
+ * environment to be switched to the target user's user id.
+ * That is important if CGI scripts try to execute native BS2000 commands.
+ */
+int os_init_job_environment(server_rec *server, const char *user_name, int one_process)
+{
+ bs2_ForkType type = os_forktype(one_process);
+
+ /* We can be sure that no change to uid==0 is possible because of
+ * the checks in http_core.c:set_user()
+ */
+
+ if (one_process) {
+
+ type = forktype = bs2_noFORK;
+
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, APLOGNO(02180)
+ "The debug mode of Apache should only "
+ "be started by an unprivileged user!");
+ return 0;
+ }
+
+ return 0;
+}
+
+/* BS2000 requires a "special" version of fork() before a setuid() call */
+pid_t os_fork(const char *user)
+{
+ pid_t pid;
+ char username[USER_LEN+1];
+
+ switch (os_forktype(0)) {
+
+ case bs2_FORK:
+ pid = fork();
+ break;
+
+ case bs2_UFORK:
+ apr_cpystrn(username, user, sizeof username);
+
+ /* Make user name all upper case - for some versions of ufork() */
+ ap_str_toupper(username);
+
+ pid = ufork(username);
+ if (pid == -1 && errno == EPERM) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, errno, ap_server_conf,
+ APLOGNO(02181) "ufork: Possible mis-configuration "
+ "for user %s - Aborting.", user);
+ exit(1);
+ }
+ break;
+
+ default:
+ pid = 0;
+ break;
+ }
+
+ return pid;
+}
+
+#endif /* _OSD_POSIX */
+
diff --git a/os/unix/unixd.h b/os/unix/unixd.h
new file mode 100644
index 0000000..ed977c6
--- /dev/null
+++ b/os/unix/unixd.h
@@ -0,0 +1,142 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file unixd.h
+ * @brief common stuff that unix MPMs will want
+ *
+ * @addtogroup APACHE_OS_UNIX
+ * @{
+ */
+
+#ifndef UNIXD_H
+#define UNIXD_H
+
+#include "httpd.h"
+#include "http_config.h"
+#include "scoreboard.h"
+#include "ap_listen.h"
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+#include "apr_hooks.h"
+#include "apr_thread_proc.h"
+#include "apr_proc_mutex.h"
+#include "apr_global_mutex.h"
+
+#include <pwd.h>
+#include <grp.h>
+#if APR_HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_IPC_H
+#include <sys/ipc.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uid_t uid;
+ gid_t gid;
+ int userdir;
+} ap_unix_identity_t;
+
+AP_DECLARE_HOOK(ap_unix_identity_t *, get_suexec_identity,(const request_rec *r))
+
+
+/* Default user name and group name. These may be specified as numbers by
+ * placing a # before a number */
+
+#ifndef DEFAULT_USER
+#define DEFAULT_USER "#-1"
+#endif
+#ifndef DEFAULT_GROUP
+#define DEFAULT_GROUP "#-1"
+#endif
+
+typedef struct {
+ const char *user_name;
+ const char *group_name;
+ uid_t user_id;
+ gid_t group_id;
+ int suexec_enabled;
+ const char *chroot_dir;
+ const char *suexec_disabled_reason; /* suitable msg if !suexec_enabled */
+} unixd_config_rec;
+AP_DECLARE_DATA extern unixd_config_rec ap_unixd_config;
+
+#if defined(RLIMIT_CPU) || defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_NPROC) || defined(RLIMIT_AS)
+AP_DECLARE(void) ap_unixd_set_rlimit(cmd_parms *cmd, struct rlimit **plimit,
+ const char *arg,
+ const char * arg2, int type);
+#endif
+
+/**
+ * One of the functions to set mutex permissions should be called in
+ * the parent process on platforms that switch identity when the
+ * server is started as root.
+ * If the child init logic is performed before switching identity
+ * (e.g., MPM setup for an accept mutex), it should only be called
+ * for SysV semaphores. Otherwise, it is safe to call it for all
+ * mutex types.
+ */
+AP_DECLARE(apr_status_t) ap_unixd_set_proc_mutex_perms(apr_proc_mutex_t *pmutex);
+AP_DECLARE(apr_status_t) ap_unixd_set_global_mutex_perms(apr_global_mutex_t *gmutex);
+AP_DECLARE(apr_status_t) ap_unixd_accept(void **accepted, ap_listen_rec *lr, apr_pool_t *ptrans);
+
+#ifdef HAVE_KILLPG
+#define ap_unixd_killpg(x, y) (killpg ((x), (y)))
+#define ap_os_killpg(x, y) (killpg ((x), (y)))
+#else /* HAVE_KILLPG */
+#define ap_unixd_killpg(x, y) (kill (-(x), (y)))
+#define ap_os_killpg(x, y) (kill (-(x), (y)))
+#endif /* HAVE_KILLPG */
+
+typedef struct {
+ void *baton; /* MPM's */
+
+ /* volatile because they're updated from signals' handlers */
+ int volatile mpm_state;
+ int volatile shutdown_pending;
+ int volatile restart_pending;
+ int volatile is_ungraceful;
+
+ ap_generation_t my_generation;
+ int module_loads;
+ int was_graceful;
+
+ /*
+ * Current number of listeners buckets and maximum reached across
+ * restarts (to size retained data according to dynamic num_buckets,
+ * eg. idle_spawn_rate).
+ */
+ int num_buckets, max_buckets;
+} ap_unixd_mpm_retained_data;
+
+AP_DECLARE(ap_unixd_mpm_retained_data *) ap_unixd_mpm_get_retained_data(void);
+AP_DECLARE(void) ap_unixd_mpm_set_signals(apr_pool_t *pconf, int once_process);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/** @} */
diff --git a/os/win32/BaseAddr.ref b/os/win32/BaseAddr.ref
new file mode 100644
index 0000000..569552a
--- /dev/null
+++ b/os/win32/BaseAddr.ref
@@ -0,0 +1,135 @@
+; os/win32/BaseAddr.ref contains the central repository
+; of all module base addresses
+; to avoid relocation
+
+; WARNING: Update this file by reviewing the image size
+; of the debug-generated dll files; release images
+; should fit in the larger debug-sized space.
+
+; module name base-address max-size
+
+libhttpd.dll 0x6FF00000 0x000E0000
+mod_auth_basic.so 0x6FFE0000 0x00020000
+mod_auth_digest.so 0x70000000 0x00020000
+mod_cern_meta.so 0x70020000 0x00010000
+mod_expires.so 0x70030000 0x00010000
+mod_headers.so 0x70040000 0x00020000
+mod_info.so 0x70060000 0x00020000
+mod_rewrite.so 0x70080000 0x00030000
+mod_speling.so 0x700B0000 0x00010000
+mod_status.so 0x700C0000 0x00020000
+mod_usertrack.so 0x700E0000 0x00010000
+mod_file_cache.so 0x700F0000 0x00020000
+mod_unique_id.so 0x70110000 0x00010000
+mod_vhost_alias.so 0x70120000 0x00010000
+mod_mime_magic.so 0x70130000 0x00020000
+mod_dav.so 0x70150000 0x00040000
+mod_dav_fs.so 0x70190000 0x00030000
+mod_proxy_connect.so 0x701C0000 0x00020000
+mod_proxy_ftp.so 0x701E0000 0x00020000
+mod_proxy_http.so 0x70200000 0x00020000
+mod_ssl.so 0x70220000 0x00070000
+mod_actions.so 0x70290000 0x00010000
+mod_alias.so 0x702A0000 0x00020000
+mod_asis.so 0x702C0000 0x00010000
+mod_autoindex.so 0x702D0000 0x00020000
+mod_cgi.so 0x702F0000 0x00020000
+mod_dir.so 0x70310000 0x00010000
+mod_env.so 0x70320000 0x00010000
+mod_imagemap.so 0x70330000 0x00020000
+mod_include.so 0x70350000 0x00030000
+mod_isapi.so 0x70380000 0x00020000
+mod_log_config.so 0x703A0000 0x00020000
+mod_mime.so 0x703C0000 0x00020000
+mod_negotiation.so 0x703E0000 0x00020000
+mod_setenvif.so 0x70400000 0x00020000
+mod_userdir.so 0x70420000 0x00010000
+mod_cache.so 0x70430000 0x00030000
+mod_cache_disk.so 0x70460000 0x00020000
+mod_buffer.so 0x70480000 0x00010000
+mod_deflate.so 0x70490000 0x00020000
+mod_ext_filter.so 0x704B0000 0x00020000
+mod_charset_lite.so 0x704D0000 0x00010000
+mod_authn_anon.so 0x704E0000 0x00010000
+mod_authn_dbm.so 0x704F0000 0x00010000
+mod_authn_file.so 0x70500000 0x00010000
+mod_authz_dbm.so 0x70510000 0x00010000
+mod_authz_groupfile.so 0x70520000 0x00010000
+mod_authz_host.so 0x70530000 0x00010000
+mod_authz_user.so 0x70540000 0x00010000
+mod_logio.so 0x70550000 0x00010000
+mod_ldap.so 0x70560000 0x00030000
+mod_authnz_ldap.so 0x70590000 0x00020000
+mod_ident.so 0x705B0000 0x00010000
+mod_proxy_ajp.so 0x705C0000 0x00020000
+mod_proxy_balancer.so 0x705E0000 0x00020000
+mod_log_forensic.so 0x70600000 0x00010000
+mod_version.so 0x70610000 0x00010000
+mod_bucketeer.so 0x70620000 0x00010000
+mod_dumpio.so 0x70630000 0x00010000
+mod_echo.so 0x70640000 0x00010000
+mod_authn_dbd.so 0x70650000 0x00010000
+mod_dbd.so 0x70660000 0x00020000
+mod_proxy.so 0x70680000 0x00040000
+mod_access_compat.so 0x706C0000 0x00010000
+mod_authz_core.so 0x706D0000 0x00020000
+mod_proxy_fcgi.so 0x706F0000 0x00020000
+mod_authn_core.so 0x70710000 0x00010000
+mod_authz_dbd.so 0x70720000 0x00010000
+mod_authz_owner.so 0x70730000 0x00010000
+mod_example_hooks.so 0x70740000 0x00020000
+mod_case_filter.so 0x70760000 0x00010000
+mod_case_filter_in.so 0x70770000 0x00010000
+mod_substitute.so 0x70780000 0x00020000
+mod_filter.so 0x707A0000 0x00020000
+mod_dav_lock.so 0x707C0000 0x00020000
+mod_auth_form.so 0x707E0000 0x00020000
+mod_example_ipc.so 0x70800000 0x00010000
+mod_request.so 0x70810000 0x00010000
+mod_session.so 0x70830000 0x00020000
+mod_session_cookie.so 0x70850000 0x00010000
+mod_session_crypto.so 0x70860000 0x00020000
+mod_session_dbd.so 0x70880000 0x00020000
+mod_socache_dbm.so 0x708A0000 0x00020000
+mod_socache_dc.so 0x708C0000 0x00010000
+mod_socache_memcache.so 0x708D0000 0x00010000
+mod_socache_shmcb.so 0x708E0000 0x00020000
+mod_sed.so 0x70900000 0x00020000
+mod_lua.so 0x70920000 0x00040000
+mod_ratelimit.so 0x70960000 0x00010000
+mod_remoteip.so 0x70970000 0x00010000
+mod_lbmethod_bybusyness.so 0x70980000 0x00010000
+mod_lbmethod_byrequests.so 0x70990000 0x00010000
+mod_lbmethod_bytraffic.so 0x709A0000 0x00010000
+mod_lbmethod_heartbeat.so 0x709B0000 0x00020000
+mod_heartbeat.so 0x709D0000 0x00010000
+mod_heartmonitor.so 0x709E0000 0x00020000
+mod_watchdog.so 0x70A00000 0x00020000
+mod_proxy_scgi.so 0x70A20000 0x00020000
+mod_reqtimeout.so 0x70A40000 0x00020000
+mod_reflector.so 0x70A60000 0x00010000
+mod_slotmem_plain.so 0x70A70000 0x00010000
+mod_slotmem_shm.so 0x70A80000 0x00020000
+mod_authn_socache.so 0x70AA0000 0x00020000
+mod_proxy_express.so 0x70AC0000 0x00010000
+mod_log_debug.so 0x70AD0000 0x00010000
+mod_proxy_html.so 0x70AE0000 0x00020000
+mod_xml2enc.so 0x70B00000 0x00020000
+mod_data.so 0x70B20000 0x00010000
+mod_allowmethods.so 0x70B30000 0x00010000
+mod_macro.so 0x70B40000 0x00020000
+mod_cache_socache.so 0x70B60000 0x00020000
+mod_proxy_wstunnel.so 0x70B80000 0x00020000
+mod_dialup.so 0x70BA0000 0x00010000
+mod_optional_fn_export.so 0x70BB0000 0x00010000
+mod_optional_fn_import.so 0x70BC0000 0x00010000
+mod_optional_hook_export.so 0x70BD0000 0x00010000
+mod_optional_hook_import.so 0x70BE0000 0x00010000
+mod_authnz_fcgi.so 0x70BF0000 0x00020000
+mod_proxy_hcheck.so 0x70C10000 0x00020000
+mod_proxy_http2.so 0x70C30000 0x00020000
+mod_http2.so 0x70C50000 0x00040000
+mod_brotli.so 0x70C90000 0x000C0000
+mod_md.so 0x70D50000 0x00030000
+mod_proxy_uwsgi.so 0x70D80000 0x00020000
+mod_socache_redis.so 0x70DA0000 0x00010000 \ No newline at end of file
diff --git a/os/win32/Makefile.in b/os/win32/Makefile.in
new file mode 100644
index 0000000..8a16bb8
--- /dev/null
+++ b/os/win32/Makefile.in
@@ -0,0 +1,5 @@
+
+LTLIBRARY_NAME = libos.la
+LTLIBRARY_SOURCES = util_win32.c ap_regkey.c modules.c
+
+include $(top_srcdir)/build/ltlib.mk
diff --git a/os/win32/ap_regkey.c b/os/win32/ap_regkey.c
new file mode 100644
index 0000000..13c2377
--- /dev/null
+++ b/os/win32/ap_regkey.c
@@ -0,0 +1,642 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef WIN32
+
+#include "apr.h"
+#include "arch/win32/apr_arch_file_io.h"
+#include "arch/win32/apr_arch_misc.h"
+#include "ap_regkey.h"
+
+struct ap_regkey_t {
+ apr_pool_t *pool;
+ HKEY hkey;
+};
+
+
+AP_DECLARE(const ap_regkey_t *) ap_regkey_const(int i)
+{
+ static struct ap_regkey_t ap_regkey_consts[7] =
+ {
+ {NULL, HKEY_CLASSES_ROOT},
+ {NULL, HKEY_CURRENT_CONFIG},
+ {NULL, HKEY_CURRENT_USER},
+ {NULL, HKEY_LOCAL_MACHINE},
+ {NULL, HKEY_USERS},
+ {NULL, HKEY_PERFORMANCE_DATA},
+ {NULL, HKEY_DYN_DATA}
+ };
+ return ap_regkey_consts + i;
+}
+
+
+static apr_status_t regkey_cleanup(void *key)
+{
+ ap_regkey_t *regkey = key;
+
+ if (regkey->hkey && regkey->hkey != INVALID_HANDLE_VALUE) {
+ RegCloseKey(regkey->hkey);
+ regkey->hkey = INVALID_HANDLE_VALUE;
+ }
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_open(ap_regkey_t **newkey,
+ const ap_regkey_t *parentkey,
+ const char *keyname,
+ apr_int32_t flags,
+ apr_pool_t *pool)
+{
+ DWORD access = KEY_QUERY_VALUE;
+ DWORD exists;
+ HKEY hkey;
+ LONG rc;
+
+ if (flags & APR_READ)
+ access |= KEY_READ;
+ if (flags & APR_WRITE)
+ access |= KEY_WRITE;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t keylen = strlen(keyname) + 1;
+ apr_size_t wkeylen = 256;
+ apr_wchar_t wkeyname[256];
+ apr_status_t rv = apr_conv_utf8_to_ucs2(keyname, &keylen, wkeyname, &wkeylen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (keylen)
+ return APR_ENAMETOOLONG;
+
+ if (flags & APR_CREATE)
+ rc = RegCreateKeyExW(parentkey->hkey, wkeyname, 0, NULL, 0,
+ access, NULL, &hkey, &exists);
+ else
+ rc = RegOpenKeyExW(parentkey->hkey, wkeyname, 0, access, &hkey);
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ if (flags & APR_CREATE)
+ rc = RegCreateKeyEx(parentkey->hkey, keyname, 0, NULL, 0,
+ access, NULL, &hkey, &exists);
+ else
+ rc = RegOpenKeyEx(parentkey->hkey, keyname, 0, access, &hkey);
+ }
+#endif
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+ if ((flags & APR_EXCL) && (exists == REG_OPENED_EXISTING_KEY)) {
+ RegCloseKey(hkey);
+ return APR_EEXIST;
+ }
+
+ *newkey = apr_palloc(pool, sizeof(**newkey));
+ (*newkey)->pool = pool;
+ (*newkey)->hkey = hkey;
+ apr_pool_cleanup_register((*newkey)->pool, (void *)(*newkey),
+ regkey_cleanup, apr_pool_cleanup_null);
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_close(ap_regkey_t *regkey)
+{
+ apr_status_t stat;
+ if ((stat = regkey_cleanup(regkey)) == APR_SUCCESS) {
+ apr_pool_cleanup_kill(regkey->pool, regkey, regkey_cleanup);
+ }
+ return stat;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_remove(const ap_regkey_t *parent,
+ const char *keyname,
+ apr_pool_t *pool)
+{
+ LONG rc;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t keylen = strlen(keyname) + 1;
+ apr_size_t wkeylen = 256;
+ apr_wchar_t wkeyname[256];
+ apr_status_t rv = apr_conv_utf8_to_ucs2(keyname, &keylen, wkeyname, &wkeylen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (keylen)
+ return APR_ENAMETOOLONG;
+ rc = RegDeleteKeyW(parent->hkey, wkeyname);
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ /* We need to determine if subkeys exist on Win9x, to provide
+ * consistent behavior with NT, which returns access denied
+ * if subkeys exist when attempting to delete a key.
+ */
+ DWORD subkeys;
+ HKEY hkey;
+ rc = RegOpenKeyEx(parent->hkey, keyname, 0, KEY_READ, &hkey);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+ rc = RegQueryInfoKey(hkey, NULL, NULL, NULL, &subkeys, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL);
+ RegCloseKey(hkey);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+ else if (subkeys)
+ return APR_FROM_OS_ERROR(ERROR_ACCESS_DENIED);
+ rc = RegDeleteKey(parent->hkey, keyname);
+ }
+#endif
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_get(char **result,
+ ap_regkey_t *key,
+ const char *valuename,
+ apr_pool_t *pool)
+{
+ /* Retrieve a registry string value, and explode any envvars
+ * that the system has configured (e.g. %SystemRoot%/someapp.exe)
+ */
+ LONG rc;
+ DWORD type;
+ apr_size_t size = 0;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t valuelen = strlen(valuename) + 1;
+ apr_size_t wvallen = 256;
+ apr_wchar_t wvalname[256];
+ apr_wchar_t *wvalue;
+ apr_status_t rv;
+ rv = apr_conv_utf8_to_ucs2(valuename, &valuelen, wvalname, &wvallen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (valuelen)
+ return APR_ENAMETOOLONG;
+ /* Read to NULL buffer to determine value size */
+ rc = RegQueryValueExW(key->hkey, wvalname, 0, &type, NULL, (DWORD *)&size);
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+ if ((size < 2) || (type != REG_SZ && type != REG_EXPAND_SZ)) {
+ return APR_FROM_OS_ERROR(ERROR_INVALID_PARAMETER);
+ }
+
+ wvalue = apr_palloc(pool, size);
+ /* Read value based on size query above */
+ rc = RegQueryValueExW(key->hkey, wvalname, 0, &type,
+ (LPBYTE)wvalue, (DWORD *)&size);
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+ if (type == REG_EXPAND_SZ) {
+ apr_wchar_t zbuf[1];
+ size = ExpandEnvironmentStringsW(wvalue, zbuf, 0);
+ if (size) {
+ apr_wchar_t *tmp = wvalue;
+ /* The size returned by ExpandEnvironmentStringsW is wchars */
+ wvalue = apr_palloc(pool, size * 2);
+ size = ExpandEnvironmentStringsW(tmp, wvalue, (DWORD)size);
+ }
+ }
+ else {
+ /* count wchars from RegQueryValueExW, rather than bytes */
+ size /= 2;
+ }
+ /* ###: deliberately overallocate all but the trailing null.
+ * We could precalculate the exact buffer here instead, the question
+ * is a matter of storage v.s. cpu cycles.
+ */
+ valuelen = (size - 1) * 3 + 1;
+ *result = apr_palloc(pool, valuelen);
+ rv = apr_conv_ucs2_to_utf8(wvalue, &size, *result, &valuelen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (size)
+ return APR_ENAMETOOLONG;
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ /* Read to NULL buffer to determine value size */
+ rc = RegQueryValueEx(key->hkey, valuename, 0, &type, NULL, (DWORD *)&size);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+
+ if ((size < 1) || (type != REG_SZ && type != REG_EXPAND_SZ)) {
+ return APR_FROM_OS_ERROR(ERROR_INVALID_PARAMETER);
+ }
+
+ *result = apr_palloc(pool, size);
+ /* Read value based on size query above */
+ rc = RegQueryValueEx(key->hkey, valuename, 0, &type, *result, (DWORD *)&size);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+
+ if (type == REG_EXPAND_SZ) {
+ /* Advise ExpandEnvironmentStrings that we have a zero char
+ * buffer to force computation of the required length.
+ */
+ char zbuf[1];
+ size = ExpandEnvironmentStrings(*result, zbuf, 0);
+ if (size) {
+ char *tmp = *result;
+ *result = apr_palloc(pool, size);
+ size = ExpandEnvironmentStrings(tmp, *result, (DWORD)size);
+ }
+ }
+ }
+#endif
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_set(ap_regkey_t *key,
+ const char *valuename,
+ const char *value,
+ apr_int32_t flags,
+ apr_pool_t *pool)
+{
+ /* Retrieve a registry string value, and explode any envvars
+ * that the system has configured (e.g. %SystemRoot%/someapp.exe)
+ */
+ LONG rc;
+ apr_size_t size = strlen(value) + 1;
+ DWORD type = (flags & AP_REGKEY_EXPAND) ? REG_EXPAND_SZ : REG_SZ;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t alloclen;
+ apr_size_t valuelen = strlen(valuename) + 1;
+ apr_size_t wvallen = 256;
+ apr_wchar_t wvalname[256];
+ apr_wchar_t *wvalue;
+ apr_status_t rv;
+ rv = apr_conv_utf8_to_ucs2(valuename, &valuelen, wvalname, &wvallen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (valuelen)
+ return APR_ENAMETOOLONG;
+
+ wvallen = alloclen = size;
+ wvalue = apr_palloc(pool, alloclen * 2);
+ rv = apr_conv_utf8_to_ucs2(value, &size, wvalue, &wvallen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (size)
+ return APR_ENAMETOOLONG;
+
+ /* The size is the number of wchars consumed by apr_conv_utf8_to_ucs2
+ * converted to bytes; the trailing L'\0' continues to be counted.
+ */
+ size = (alloclen - wvallen) * 2;
+ rc = RegSetValueExW(key->hkey, wvalname, 0, type,
+ (LPBYTE)wvalue, (DWORD)size);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ rc = RegSetValueEx(key->hkey, valuename, 0, type, value, (DWORD)size);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+ }
+#endif
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_raw_get(void **result,
+ apr_size_t *resultsize,
+ apr_int32_t *resulttype,
+ ap_regkey_t *key,
+ const char *valuename,
+ apr_pool_t *pool)
+{
+ /* Retrieve a registry string value, and explode any envvars
+ * that the system has configured (e.g. %SystemRoot%/someapp.exe)
+ */
+ LONG rc;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t valuelen = strlen(valuename) + 1;
+ apr_size_t wvallen = 256;
+ apr_wchar_t wvalname[256];
+ apr_status_t rv;
+ rv = apr_conv_utf8_to_ucs2(valuename, &valuelen, wvalname, &wvallen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (valuelen)
+ return APR_ENAMETOOLONG;
+ /* Read to NULL buffer to determine value size */
+ rc = RegQueryValueExW(key->hkey, wvalname, 0, (LPDWORD)resulttype,
+ NULL, (LPDWORD)resultsize);
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+
+ /* Read value based on size query above */
+ *result = apr_palloc(pool, *resultsize);
+ rc = RegQueryValueExW(key->hkey, wvalname, 0, (LPDWORD)resulttype,
+ (LPBYTE)*result, (LPDWORD)resultsize);
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ /* Read to NULL buffer to determine value size */
+ rc = RegQueryValueEx(key->hkey, valuename, 0, (LPDWORD)resulttype,
+ NULL, (LPDWORD)resultsize);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+
+ /* Read value based on size query above */
+ *result = apr_palloc(pool, *resultsize);
+ rc = RegQueryValueEx(key->hkey, valuename, 0, (LPDWORD)resulttype,
+ (LPBYTE)*result, (LPDWORD)resultsize);
+ if (rc != ERROR_SUCCESS)
+ return APR_FROM_OS_ERROR(rc);
+ }
+#endif
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_raw_set(ap_regkey_t *key,
+ const char *valuename,
+ const void *value,
+ apr_size_t valuesize,
+ apr_int32_t valuetype,
+ apr_pool_t *pool)
+{
+ LONG rc;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t valuelen = strlen(valuename) + 1;
+ apr_size_t wvallen = 256;
+ apr_wchar_t wvalname[256];
+ apr_status_t rv;
+ rv = apr_conv_utf8_to_ucs2(valuename, &valuelen, wvalname, &wvallen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (valuelen)
+ return APR_ENAMETOOLONG;
+
+ rc = RegSetValueExW(key->hkey, wvalname, 0, valuetype,
+ (LPBYTE)value, (DWORD)valuesize);
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ rc = RegSetValueEx(key->hkey, valuename, 0, valuetype,
+ (LPBYTE)value, (DWORD)valuesize);
+ }
+#endif
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_array_get(apr_array_header_t **result,
+ ap_regkey_t *key,
+ const char *valuename,
+ apr_pool_t *pool)
+{
+ /* Retrieve a registry string value, and explode any envvars
+ * that the system has configured (e.g. %SystemRoot%/someapp.exe)
+ */
+ apr_status_t rv;
+ void *value;
+ char *buf;
+ char *tmp;
+ apr_int32_t type;
+ apr_size_t size = 0;
+
+ rv = ap_regkey_value_raw_get(&value, &size, &type, key, valuename, pool);
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+ else if (type != REG_MULTI_SZ) {
+ return APR_EINVAL;
+ }
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t alloclen;
+ apr_size_t valuelen = strlen(valuename) + 1;
+
+ /* ###: deliberately overallocate plus two extra nulls.
+ * We could precalculate the exact buffer here instead, the question
+ * is a matter of storage v.s. cpu cycles.
+ */
+ size /= 2;
+ alloclen = valuelen = size * 3 + 2;
+ buf = apr_palloc(pool, valuelen);
+ rv = apr_conv_ucs2_to_utf8(value, &size, buf, &valuelen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (size)
+ return APR_ENAMETOOLONG;
+ buf[(alloclen - valuelen)] = '\0';
+ buf[(alloclen - valuelen) + 1] = '\0';
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ /* Small possibility the array is either unterminated
+ * or single NULL terminated. Avert.
+ */
+ buf = (char *)value;
+ if (size < 2 || buf[size - 1] != '\0' || buf[size - 2] != '\0') {
+ buf = apr_palloc(pool, size + 2);
+ memcpy(buf, value, size);
+ buf[size + 1] = '\0';
+ buf[size] = '\0';
+ }
+ }
+#endif
+
+ size = 0; /* Element Count */
+ for (tmp = buf; *tmp; ++tmp) {
+ ++size;
+ while (*tmp) {
+ ++tmp;
+ }
+ }
+
+ *result = apr_array_make(pool, (int)size, sizeof(char *));
+ for (tmp = buf; *tmp; ++tmp) {
+ char **newelem = (char **) apr_array_push(*result);
+ *newelem = tmp;
+ while (*tmp) {
+ ++tmp;
+ }
+ }
+
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_array_set(ap_regkey_t *key,
+ const char *valuename,
+ int nelts,
+ const char * const * elts,
+ apr_pool_t *pool)
+{
+ /* Retrieve a registry string value, and explode any envvars
+ * that the system has configured (e.g. %SystemRoot%/someapp.exe)
+ */
+ int i;
+ const void *value;
+ apr_size_t bufsize;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_status_t rv;
+ apr_wchar_t *buf;
+ apr_wchar_t *tmp;
+ apr_size_t bufrem;
+
+ bufsize = 1; /* For trailing second null */
+ for (i = 0; i < nelts; ++i) {
+ bufsize += strlen(elts[i]) + 1;
+ }
+ if (!nelts) {
+ ++bufsize;
+ }
+
+ bufrem = bufsize;
+ buf = apr_palloc(pool, bufsize * 2);
+ tmp = buf;
+ for (i = 0; i < nelts; ++i) {
+ apr_size_t eltsize = strlen(elts[i]) + 1;
+ apr_size_t size = eltsize;
+ rv = apr_conv_utf8_to_ucs2(elts[i], &size, tmp, &bufrem);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (size)
+ return APR_ENAMETOOLONG;
+ tmp += eltsize;
+ }
+ if (!nelts) {
+ --bufrem;
+ (*tmp++) = L'\0';
+ }
+ --bufrem;
+ *tmp = L'\0'; /* Trailing second null */
+
+ bufsize = (bufsize - bufrem) * 2;
+ value = (void*)buf;
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ char *buf;
+ char *tmp;
+
+ bufsize = 1; /* For trailing second null */
+ for (i = 0; i < nelts; ++i) {
+ bufsize += strlen(elts[i]) + 1;
+ }
+ if (!nelts) {
+ ++bufsize;
+ }
+ buf = apr_palloc(pool, bufsize);
+ tmp = buf;
+ for (i = 0; i < nelts; ++i) {
+ apr_size_t len = strlen(elts[i]) + 1;
+ memcpy(tmp, elts[i], len);
+ tmp += len;
+ }
+ if (!nelts) {
+ (*tmp++) = '\0';
+ }
+ *tmp = '\0'; /* Trailing second null */
+ value = buf;
+ }
+#endif
+ return ap_regkey_value_raw_set(key, valuename, value,
+ bufsize, REG_MULTI_SZ, pool);
+}
+
+
+AP_DECLARE(apr_status_t) ap_regkey_value_remove(const ap_regkey_t *key,
+ const char *valuename,
+ apr_pool_t *pool)
+{
+ LONG rc;
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t valuelen = strlen(valuename) + 1;
+ apr_size_t wvallen = 256;
+ apr_wchar_t wvalname[256];
+ apr_status_t rv = apr_conv_utf8_to_ucs2(valuename, &valuelen, wvalname, &wvallen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (valuelen)
+ return APR_ENAMETOOLONG;
+ rc = RegDeleteValueW(key->hkey, wvalname);
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ rc = RegDeleteValue(key->hkey, valuename);
+ }
+#endif
+ if (rc != ERROR_SUCCESS) {
+ return APR_FROM_OS_ERROR(rc);
+ }
+ return APR_SUCCESS;
+}
+
+#endif /* defined WIN32 */
diff --git a/os/win32/modules.c b/os/win32/modules.c
new file mode 100644
index 0000000..9c3410e
--- /dev/null
+++ b/os/win32/modules.c
@@ -0,0 +1,56 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* modules.c --- major modules compiled into Apache for Win32.
+ * Only insert an entry for a module if it must be compiled into
+ * the core server
+ */
+
+#include "httpd.h"
+#include "http_config.h"
+
+extern module core_module;
+extern module win32_module;
+extern module mpm_winnt_module;
+extern module http_module;
+extern module so_module;
+
+AP_DECLARE_DATA module *ap_prelinked_modules[] = {
+ &core_module, /* core must come first */
+ &win32_module,
+ &mpm_winnt_module,
+ &http_module,
+ &so_module,
+ NULL
+};
+
+ap_module_symbol_t ap_prelinked_module_symbols[] = {
+ {"core_module", &core_module},
+ {"win32_module", &win32_module},
+ {"mpm_winnt_module", &mpm_winnt_module},
+ {"http_module", &http_module},
+ {"so_module", &so_module},
+ {NULL, NULL}
+};
+
+AP_DECLARE_DATA module *ap_preloaded_modules[] = {
+ &core_module,
+ &win32_module,
+ &mpm_winnt_module,
+ &http_module,
+ &so_module,
+ NULL
+};
diff --git a/os/win32/os.h b/os/win32/os.h
new file mode 100644
index 0000000..3a32af5
--- /dev/null
+++ b/os/win32/os.h
@@ -0,0 +1,136 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file win32/os.h
+ * @brief This file in included in all Apache source code. It contains definitions
+ * of facilities available on _this_ operating system (HAVE_* macros),
+ * and prototypes of OS specific functions defined in os.c or os-inline.c
+ *
+ * @defgroup APACHE_OS_WIN32 win32
+ * @ingroup APACHE_OS
+ * @{
+ */
+
+#ifdef WIN32
+
+#ifndef AP_OS_H
+#define AP_OS_H
+/* Delegate windows include to the apr.h header, if USER or GDI declarations
+ * are required (for a window rather than console application), include
+ * windows.h prior to any other Apache header files.
+ */
+#include "apr_pools.h"
+
+#include <io.h>
+#include <fcntl.h>
+
+#ifdef _WIN64
+#define PLATFORM "Win64"
+#else
+#define PLATFORM "Win32"
+#endif
+
+/* Define command-line rewriting for this platform, handled by core.
+ * For Windows, this is currently handled inside the WinNT MPM.
+ * XXX To support a choice of MPMs, extract common platform behavior
+ * into a function specified here.
+ */
+#define AP_PLATFORM_REWRITE_ARGS_HOOK NULL
+
+/* going away shortly... */
+#define HAVE_DRIVE_LETTERS
+#define HAVE_UNC_PATHS
+#define CASE_BLIND_FILESYSTEM
+
+#include <stddef.h>
+#include <stdlib.h> /* for exit() */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* BIG RED WARNING: exit() is mapped to allow us to capture the exit
+ * status. This header must only be included from modules linked into
+ * the ApacheCore.dll - since it's a horrible behavior to exit() from
+ * any module outside the main() block, and we -will- assume it's a
+ * fatal error.
+ */
+
+AP_DECLARE_DATA extern int ap_real_exit_code;
+
+#define exit(status) ((exit)((ap_real_exit_code==2) \
+ ? (ap_real_exit_code = (status)) \
+ : ((ap_real_exit_code = 0), (status))))
+
+#ifdef AP_DECLARE_EXPORT
+
+/* Defined in util_win32.c and available only to the core module for
+ * win32 MPM design.
+ */
+
+AP_DECLARE(apr_status_t) ap_os_proc_filepath(char **binpath, apr_pool_t *p);
+
+typedef enum {
+ AP_DLL_WINBASEAPI = 0, /* kernel32 From WinBase.h */
+ AP_DLL_WINADVAPI = 1, /* advapi32 From WinBase.h */
+ AP_DLL_WINSOCKAPI = 2, /* mswsock From WinSock.h */
+ AP_DLL_WINSOCK2API = 3, /* ws2_32 From WinSock2.h */
+ AP_DLL_defined = 4 /* must define as last idx_ + 1 */
+} ap_dlltoken_e;
+
+FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char* fnName, int ordinal);
+
+#define AP_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
+ typedef rettype (calltype *ap_winapi_fpt_##fn) args; \
+ static ap_winapi_fpt_##fn ap_winapi_pfn_##fn = NULL; \
+ static APR_INLINE rettype ap_winapi_##fn args \
+ { if (!ap_winapi_pfn_##fn) \
+ ap_winapi_pfn_##fn = (ap_winapi_fpt_##fn) ap_load_dll_func(lib, #fn, ord); \
+ return (*(ap_winapi_pfn_##fn)) names; }; \
+
+/* Win2K kernel only */
+AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINADVAPI, BOOL, WINAPI, ChangeServiceConfig2A, 0, (
+ SC_HANDLE hService,
+ DWORD dwInfoLevel,
+ LPVOID lpInfo),
+ (hService, dwInfoLevel, lpInfo));
+#undef ChangeServiceConfig2
+#define ChangeServiceConfig2 ap_winapi_ChangeServiceConfig2A
+
+/* WinNT kernel only */
+AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
+ IN HANDLE hFile),
+ (hFile));
+#undef CancelIo
+#define CancelIo ap_winapi_CancelIo
+
+/* Win9x kernel only */
+AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINBASEAPI, DWORD, WINAPI, RegisterServiceProcess, 0, (
+ DWORD dwProcessId,
+ DWORD dwType),
+ (dwProcessId, dwType));
+#define RegisterServiceProcess ap_winapi_RegisterServiceProcess
+
+#endif /* def AP_DECLARE_EXPORT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ndef AP_OS_H */
+#endif /* def WIN32 */
+/** @} */
diff --git a/os/win32/util_win32.c b/os/win32/util_win32.c
new file mode 100644
index 0000000..728e4b5
--- /dev/null
+++ b/os/win32/util_win32.c
@@ -0,0 +1,103 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_strings.h"
+#include "arch/win32/apr_arch_file_io.h"
+#include "arch/win32/apr_arch_misc.h"
+
+#include "httpd.h"
+#include "http_log.h"
+#include "ap_mpm.h"
+
+#include <stdarg.h>
+#include <time.h>
+#include <stdlib.h>
+
+
+AP_DECLARE(apr_status_t) ap_os_proc_filepath(char **binpath, apr_pool_t *p)
+{
+ apr_wchar_t wbinpath[APR_PATH_MAX];
+
+#if APR_HAS_UNICODE_FS
+ IF_WIN_OS_IS_UNICODE
+ {
+ apr_size_t binlen;
+ apr_size_t wbinlen;
+ apr_status_t rv;
+ if (!GetModuleFileNameW(NULL, wbinpath, sizeof(wbinpath)
+ / sizeof(apr_wchar_t))) {
+ return apr_get_os_error();
+ }
+ wbinlen = wcslen(wbinpath) + 1;
+ binlen = (wbinlen - 1) * 3 + 1;
+ *binpath = apr_palloc(p, binlen);
+ rv = apr_conv_ucs2_to_utf8(wbinpath, &wbinlen, *binpath, &binlen);
+ if (rv != APR_SUCCESS)
+ return rv;
+ else if (wbinlen)
+ return APR_ENAMETOOLONG;
+ }
+#endif /* APR_HAS_UNICODE_FS */
+#if APR_HAS_ANSI_FS
+ ELSE_WIN_OS_IS_ANSI
+ {
+ /* share the same scratch buffer */
+ char *pathbuf = (char*) wbinpath;
+ if (!GetModuleFileName(NULL, pathbuf, sizeof(wbinpath))) {
+ return apr_get_os_error();
+ }
+ *binpath = apr_pstrdup(p, pathbuf);
+ }
+#endif
+ return APR_SUCCESS;
+}
+
+
+AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
+ const request_rec *r,
+ apr_proc_t *newproc, const char *progname,
+ const char * const *args,
+ const char * const *env,
+ apr_procattr_t *attr, apr_pool_t *p)
+{
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+}
+
+
+/* This code is stolen from misc/win32/misc.c and apr_private.h
+ * This helper code resolves late bound entry points
+ * missing from one or more releases of the Win32 API...
+ * but it sure would be nice if we didn't duplicate this code
+ * from the APR ;-)
+ */
+static const char* const lateDllName[DLL_defined] = {
+ "kernel32", "advapi32", "mswsock", "ws2_32" };
+static HMODULE lateDllHandle[DLL_defined] = {
+ NULL, NULL, NULL, NULL };
+
+
+FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char* fnName, int ordinal)
+{
+ if (!lateDllHandle[fnLib]) {
+ lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]);
+ if (!lateDllHandle[fnLib])
+ return NULL;
+ }
+ if (ordinal)
+ return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal);
+ else
+ return GetProcAddress(lateDllHandle[fnLib], fnName);
+}
diff --git a/os/win32/win32_config_layout.h b/os/win32/win32_config_layout.h
new file mode 100644
index 0000000..5f770a2
--- /dev/null
+++ b/os/win32/win32_config_layout.h
@@ -0,0 +1,31 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file win32/win32_config_layout.h
+ * @brief This provides layout definitions for non-autoconf-based Windows
+ * builds, and is copied to include/ap_config_layout.h during the build.
+ */
+
+#ifndef AP_CONFIG_LAYOUT_H
+#define AP_CONFIG_LAYOUT_H
+
+/* Check for definition of DEFAULT_REL_RUNTIMEDIR */
+#ifndef DEFAULT_REL_RUNTIMEDIR
+#define DEFAULT_REL_RUNTIMEDIR "logs"
+#endif
+
+#endif /* AP_CONFIG_LAYOUT_H */