Initial release MARS_NWE-PCAP 0.4 - Native Administration, Print and Login Edition

This commit is contained in:
2026-11-26 20:22:04 +00:00
commit 7ba7f59b08
51 changed files with 1966 additions and 0 deletions

60
patch-upstream.sh Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(realpath "$1")
here=$(cd "$(dirname "$0")" && pwd)
for f in src/emutli.c src/emutli1.c src/CMakeLists.txt include/emutli.h include/net.h; do test -f "$root/$f" || { echo "Unsupported source layout: $f" >&2; exit 1; }; done
if grep -q MARS_PCAP_PORT_V1 "$root/src/CMakeLists.txt"; then echo 'Already patched' >&2; exit 1; fi
for f in "$root/src/emutli.c" "$root/src/emutli1.c"; do
grep -Fq '#include "net.h"' "$f" && grep -Fq 'socket(AF_IPX' "$f" || { echo "Unexpected source version: $f" >&2; exit 1; }
sed -i '0,/#include "net.h"/s//#include "net.h"\n#include "mars_pcap_shim.h"/' "$f"
sed -Ei 's/\b(socket|bind|getsockname|setsockopt|sendto|recvfrom|ioctl)[[:space:]]*\(/mars_\1(/g' "$f"
done
grep -Fq '#include "config.h"' "$root/include/net.h" || exit 1
sed -i '0,/#include "config.h"/s//#include "config.h"\n#undef SIOCIPXNCPCONN\n#undef CALL_NWCONN_OVER_SOCKET\n#define CALL_NWCONN_OVER_SOCKET 0/' "$root/include/net.h"
find "$root/src" "$root/include" -type f \( -name '*.c' -o -name '*.h' \) -exec sed -Ei 's@/proc/net/ipx(_interface|_route)?(["\x27])@/run/mars-pcap/ipx\1\2@g' {} +
if grep -En '\bsocket[[:space:]]*\([[:space:]]*(AF|PF)_IPX\b' "$root"/src/*.c; then echo 'Unported direct IPX socket call' >&2; exit 1; fi
cp "$here/src/shim.h" "$root/include/mars_pcap_shim.h"
cat >> "$root/src/CMakeLists.txt" <<'CMAKE'
# MARS_PCAP_PORT_V1
set(MARS_PCAP_LIBRARY "" CACHE FILEPATH "PCAP socket adapter")
if(NOT EXISTS "${MARS_PCAP_LIBRARY}")
message(FATAL_ERROR "MARS_PCAP_LIBRARY is required")
endif()
foreach(t nwserv nwconn ncpserv nwclient nwbind nwrouted dbmtool)
if(TARGET ${t})
target_link_libraries(${t} "${MARS_PCAP_LIBRARY}")
endif()
endforeach()
CMAKE
printf 'Patched MARS_NWE transport.\n'
# Live admin adapter in nwbind's own serialized event loop.
f="$root/src/nwbind.c"
for anchor in 'int main(int argc, char *argv[])' ' set_sig();' 'if (t_rcvudata(ncp_fd, &ud, &rcv_flags) > -1)' ' nw_exit_dbm();'; do
[[ $(grep -Fc "$anchor" "$f") == 1 ]] || { echo "Unsupported nwbind anchor: $anchor" >&2; exit 1; }
done
cp "$here/upstream-adapter/"mars_{admin,scripts,acl}.inc "$root/src/"
sed -i '1i #ifndef _GNU_SOURCE\n#define _GNU_SOURCE\n#endif' "$f"
sed -i '/^int main(int argc, char \*argv\[\])/i #include "mars_admin.inc"' "$f"
sed -i '/^ set_sig();/a\ ma_init();' "$f"
sed -i 's/if (t_rcvudata(ncp_fd, \&ud, \&rcv_flags) > -1)/if (ma_wait(ncp_fd) \&\& t_rcvudata(ncp_fd, \&ud, \&rcv_flags) > -1)/' "$f"
sed -i '/^ nw_exit_dbm();/i\ ma_close();' "$f"
cat >> "$root/src/CMakeLists.txt" <<'CMAKE'
find_package(PkgConfig REQUIRED)
pkg_check_modules(MARS_JSON REQUIRED IMPORTED_TARGET json-c)
if(NOT TARGET nwbind)
message(FATAL_ERROR "nwbind target missing")
endif()
target_link_libraries(nwbind PkgConfig::MARS_JSON)
CMAKE
# Keep original spool file on a non-zero print subprocess exit.
f="$root/src/nwqconn.c"
[[ $(grep -Fc 'if (0 != (k=ext_pclose(fp))) {' "$f") == 1 ]] || { echo 'Unsupported nwqconn print hook' >&2; exit 1; }
sed -i '/if (0 != (k=ext_pclose(fp))) {/a\ is_ok=0; /* keep spool file on failed submission */' "$f"
printf 'Patched live Bindery administration and print error handling.\n'
# Extend upstream ftrustee, using its own original volume/trustee routines.
f="$root/src/ftrustee.c"
[[ $(grep -Fc 'int main(int argc, char *argv[])' "$f") == 1 && $(grep -Fc ' localinit();' "$f") == 1 ]] || { echo 'Unsupported ftrustee layout' >&2; exit 1; }
cp "$here/upstream-adapter/mars_trustee.inc" "$root/src/"
sed -i '/^int main(int argc, char \*argv\[\])/i #include "mars_trustee.inc"' "$f"
sed -i '/^ localinit();/a\ if (argc > 1 \&\& !strcmp(argv[1], "--mars-admin")) return mt_admin(argc, argv);' "$f"