Files
mars-dosutils/nwtests.c
Mario Fetka 3562cd1301 tests
2026-05-23 15:19:35 +02:00

516 lines
13 KiB
C

/* nwtests.c 20-May-96 */
/****************************************************************
* (C)opyright (C) 1993,1996 Martin Stover, Marburg, Germany *
****************************************************************/
#include "net.h"
static int tests_same_arg(char *a, char *b)
{
while (*a || *b) {
int ca = *a++;
int cb = *b++;
if (ca >= 'a' && ca <= 'z') ca -= 32;
if (cb >= 'a' && cb <= 'z') cb -= 32;
if (ca != cb) return(0);
}
return(1);
}
static void tests_usage(void)
{
fprintf(stdout, "Usage: TESTS [OLD|NETCALL|E300|NCPF2 [file]|NWREQ87 [file]]\n");
}
static int tests_netcall(void)
{
unsigned char req[4];
unsigned char repl[4];
int asm_rc;
int c_rc;
memset(req, 0, sizeof(req));
memset(repl, 0, sizeof(repl));
fprintf(stdout, "TEST Net_Call ASM vs C\n");
fprintf(stdout, "Call: INT 21h AH=19h get current drive\n");
fprintf(stdout, "Expected: AL=0 for A:, 1 for B:, 2 for C:, ...\n\n");
asm_rc = Net_Call(0x1900, req, repl);
fprintf(stdout, "ASM Net_Call(1900h) rc=%04X drive=%c:\n",
asm_rc, 'A' + (asm_rc & 0xff));
c_rc = Net_Call_C(0x1900, req, repl);
fprintf(stdout, "C Net_Call_C(1900h) rc=%04X drive=%c:\n",
c_rc, 'A' + (c_rc & 0xff));
Net_Call_C_Dump();
if ((asm_rc & 0xff) == (c_rc & 0xff))
fprintf(stdout, "\nNETCALL C basic register test OK\n");
else
fprintf(stdout, "\nNETCALL C basic register test FAILED\n");
return(0);
}
static int tests_old(int argc, char *argv[], int mode)
{
int level = ncp_17_02(NWCONN, 6);
int dirhandle = alloc_temp_dir_handle(0, "SYS:", 'd', NULL);
int result = -1;
uint8 *path = (argc < 2) ? "SYS:\\TMP" : argv[1];
if (dirhandle > -1) {
result = ncp_16_02(dirhandle, "SYSTEM/", NULL, NULL, NULL, NULL);
result = ncp_16_02(dirhandle, "SYSTEM", NULL, NULL, NULL, NULL);
}
fprintf(stdout, "dirhandle=%d, result=%d\n", dirhandle, result);
result = redir_device_drive(0x4, "u:", path);
fprintf(stdout, "redir path=%s, result=%d\n", path, result);
path="Q1";
result = redir_device_drive(0x3, "LPT1", path);
fprintf(stdout, "redir path=%s, result=%d\n", path, result);
{
int k =-1;
uint8 devname[20];
uint8 remotename[130];
int devicetyp;
while ((result = list_redir(++k, &devicetyp, devname, remotename)) > -1){
fprintf(stdout, "index=%d, dev=%s(%d), %s result=%d\n",
k, devname, devicetyp, remotename, result);
}
}
if (level > -1) (void) ncp_17_02(NWCONN, level);
return(0);
}
static void tests_dump_bytes(char *title, unsigned char *p, int len)
{
int i;
fprintf(stdout, "%s", title);
for (i = 0; i < len; i++)
fprintf(stdout, " %02X", p[i]);
fprintf(stdout, "\n");
}
static int tests_netcall_e300(void)
{
struct {
uint16 len;
uint8 func;
} req_asm, req_c;
struct {
uint16 len;
uint8 data[16];
} repl_asm, repl_c;
int asm_rc;
int c_rc;
memset(&req_asm, 0, sizeof(req_asm));
memset(&req_c, 0, sizeof(req_c));
memset(&repl_asm, 0, sizeof(repl_asm));
memset(&repl_c, 0, sizeof(repl_c));
/*
* NCP 17/17 Get Login Encryption Key.
* This is a known safe bindery/login helper call used by LOGIN/PASSWD code.
* Request via old DOS NetWare API AX=E300.
*/
req_asm.len = 1;
req_asm.func = 0x17;
repl_asm.len = 8;
req_c.len = 1;
req_c.func = 0x17;
repl_c.len = 8;
fprintf(stdout, "TEST Net_Call ASM vs C E300/NCP17/17\n");
fprintf(stdout, "Call: Get Login Encryption Key\n\n");
asm_rc = Net_Call(0xE300, &req_asm, &repl_asm);
fprintf(stdout, "ASM Net_Call(E300h) rc=%04X\n", asm_rc);
tests_dump_bytes("ASM key:", repl_asm.data, 8);
c_rc = Net_Call_C(0xE300, &req_c, &repl_c);
fprintf(stdout, "C Net_Call_C(E300h) rc=%04X\n", c_rc);
tests_dump_bytes("C key:", repl_c.data, 8);
Net_Call_C_Dump();
if ((asm_rc & 0xff) == (c_rc & 0xff))
fprintf(stdout, "\nNETCALL C E300 return test OK\n");
else
fprintf(stdout, "\nNETCALL C E300 return test FAILED\n");
/*
* Keys can differ per request, so do not require byte-identical keys.
* We only compare return status and check that both calls returned 8 bytes.
*/
return(0);
}
static void tests_put_word_lh(uint8 *p, uint16 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
}
static void tests_put_dword_lh(uint8 *p, uint32 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
p[2] = (uint8)((v >> 16) & 0xff);
p[3] = (uint8)((v >> 24) & 0xff);
}
static uint32 tests_get_dword_lh(uint8 *p)
{
return((uint32)p[0] |
((uint32)p[1] << 8) |
((uint32)p[2] << 16) |
((uint32)p[3] << 24));
}
static int tests_get_current_drive(void)
{
REGS regs;
regs.h.ah = 0x19;
int86(0x21, &regs, &regs);
return((int)regs.h.al);
}
static int tests_current_conn_dhandle(uint8 *connid, uint8 *dhandle)
{
uint8 flags = 0;
int drive;
drive = tests_get_current_drive();
if (get_drive_info((uint8)drive, connid, dhandle, &flags)) {
fprintf(stdout, "NCPF2DBG get_drive_info failed drive=%c:\n", 'A' + drive);
return(-1);
}
fprintf(stdout, "NCPF2DBG drive=%c: connid=%u dhandle=%u flags=%02X\n",
'A' + drive, *connid, *dhandle, flags);
if (!*connid || (flags & 0x80)) {
fprintf(stdout, "NCPF2DBG current drive is not a network drive\n");
return(-1);
}
return(0);
}
static int tests_add_handle_path(uint8 *p, uint8 dhandle, char *name)
{
int nlen;
nlen = strlen(name);
if (nlen > 255) nlen = 255;
*p++ = dhandle;
tests_put_dword_lh(p, 0L); p += 4;
*p++ = 0; /* dirstyle = short dir handle */
*p++ = 1; /* one component */
*p++ = (uint8)nlen;
memcpy(p, name, nlen);
p += nlen;
return(1 + 4 + 1 + 1 + 1 + nlen);
}
static int tests_ncpf2_read_one(char *name, UI cx_mode)
{
struct {
uint8 data[320];
} req;
struct {
uint8 data[256];
} repl;
uint8 *p;
uint8 connid = 0;
uint8 dhandle = 0;
UI cx;
int hlen;
int rc;
uint32 attr;
if (tests_current_conn_dhandle(&connid, &dhandle))
return(1);
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
p = req.data;
*p++ = 6; /* NCP87 subfunction 6: obtain file/subdir info */
*p++ = 0; /* source namespace DOS */
*p++ = 0; /* target namespace DOS */
tests_put_word_lh(p, 0x0006); p += 2; /* SA_ALL */
tests_put_dword_lh(p, 0x00000004UL); p += 4; /* RIM_ATTRIBUTES */
hlen = tests_add_handle_path(p, dhandle, name);
p += hlen;
if (cx_mode == 0)
cx = (UI)(p - req.data); /* most likely: request length */
else
cx = sizeof(repl.data); /* alternate: reply buffer size */
fprintf(stdout, "NCPF2DBG name=%s func=57 conn=%u cx=%u dx=%u mode=%u req.len=%u repl.max=%u\n",
name, connid, cx, (UI)sizeof(repl.data), cx_mode, (UI)(p - req.data), (UI)sizeof(repl.data));
tests_dump_bytes("NCPF2DBG req:", req.data, (p - req.data) > 64 ? 64 : (int)(p - req.data));
rc = Net_Call_F2_C(0x57, cx, (UI)sizeof(repl.data), req.data, repl.data);
fprintf(stdout, "NCPF2DBG rc=%04X\n", rc);
tests_dump_bytes("NCPF2DBG repl:", repl.data, 64);
Net_Call_C_Dump();
attr = tests_get_dword_lh(repl.data);
fprintf(stdout, "NCPF2DBG attr[0]=%08lX\n", attr);
return(0);
}
static int tests_ncpf2(int argc, char *argv[])
{
char *name = "LOGIN.EXE";
UI mode = 0;
if (argc > 2)
name = argv[2];
if (argc > 3 && tests_same_arg(argv[3], "REPLY"))
mode = 1;
fprintf(stdout, "TEST NCPF2 AH=F2/AL=57 NCP87 obtain RIM_ATTRIBUTES\n");
fprintf(stdout, "Default CX is request length. Add REPLY to use reply size.\n");
fprintf(stdout, "This is read-only, but still experimental.\n\n");
return tests_ncpf2_read_one(name, mode);
}
static void tests_build_nwreq87_path(uint8 *buf, uint8 dhandle,
char *name, UI *out_len)
{
uint8 *p;
int nlen;
memset(buf, 0, 300);
p = buf;
nlen = strlen(name);
if (nlen > 255) nlen = 255;
/*
* Same compact handle/path payload we used before:
* handle, dirbase, dirstyle, component-count, len, name
* The new part in this test is not the path itself; it is that we now
* reproduce NWCREQUEST's fragmented request and full reply size.
*/
*p++ = dhandle;
tests_put_dword_lh(p, 0L); p += 4;
*p++ = 0; /* dirstyle = short directory handle */
*p++ = 1; /* one path component */
*p++ = (uint8)nlen;
memcpy(p, name, nlen);
p += nlen;
*out_len = (UI)(p - buf);
}
static UI tests_build_nwreq87s6_flat(uint8 *req,
uint8 *path,
UI path_len)
{
uint8 *p;
memset(req, 0, 400);
p = req;
/*
* DeveloperNet ncpdos16 87s6.c builds two request fragments:
* frag 1 length 9:
* subfn=6, srcNS, dstNS, searchAttrs, returnInfoMask
* frag 2:
* packed handle/path structure
*
* NWCREQUEST for NETX/Shell concatenates those request fragments before
* calling NWCSHELLREQ.
*/
*p++ = 6; /* NCP87 subfunction 6 */
*p++ = 0; /* source namespace DOS */
*p++ = 0; /* target namespace DOS */
tests_put_word_lh(p, 0x0006); p += 2; /* SA_ALL */
tests_put_dword_lh(p, 0x00000004UL); p += 4;/* RIM_ATTRIBUTES */
memcpy(p, path, path_len);
p += path_len;
return (UI)(p - req);
}
static int tests_nwreq87(int argc, char *argv[])
{
char *name = "LOGIN.EXE";
uint8 connid = 0;
uint8 dhandle = 0;
uint8 path[300];
uint8 req[400];
uint8 repl[0x180];
uint8 dummy[8];
UI path_len;
UI req_len;
int rc;
uint32 a0;
uint32 a4;
uint32 a4d;
if (argc > 2)
name = argv[2];
if (tests_current_conn_dhandle(&connid, &dhandle))
return(1);
tests_build_nwreq87_path(path, dhandle, name, &path_len);
req_len = tests_build_nwreq87s6_flat(req, path, path_len);
memset(repl, 0, sizeof(repl));
memset(dummy, 0, sizeof(dummy));
fprintf(stdout, "TEST NWREQ87 shell-style NCP87/S6 for %s\n", name);
fprintf(stdout, "connid=%u dhandle=%u path.len=%u req.len=%u repl.len=%u\n",
connid, dhandle, path_len, req_len, (UI)0x014d);
tests_dump_bytes("NWREQ87 path:", path, path_len > 48 ? 48 : path_len);
tests_dump_bytes("NWREQ87 req :", req, req_len > 64 ? 64 : req_len);
/*
* Reproduce the NETX/Shell path in clndos16 dreq.c:
* first AH=F0/DX=conn via NWCSHELLREQ
* then AH=F2/AL=function with DS:SI=request, CX=requestLen,
* ES:DI=reply, DX=sum(replyFragLengths).
*
* For 87s6.c reply fragments are 0x4d + 0x100 = 0x014d.
*/
fprintf(stdout, "NWREQ87 init F000 DX=conn\n");
rc = Net_Call_F2X_C(0xF000, 0, 0, (UI)connid, dummy, repl);
fprintf(stdout, "NWREQ87 init rc=%04X\n", rc);
Net_Call_C_Dump();
fprintf(stdout, "NWREQ87 call F257 CX=req.len DX=014D\n");
rc = Net_Call_F2X_C(0xF257, 0, req_len, 0x014d, req, repl);
fprintf(stdout, "NWREQ87 rc=%04X\n", rc);
Net_Call_C_Dump();
tests_dump_bytes("NWREQ87 repl[0..63]:", repl, 64);
tests_dump_bytes("NWREQ87 repl[4d..8c]:", repl + 0x4d, 64);
a0 = tests_get_dword_lh(repl);
a4 = tests_get_dword_lh(repl + 4);
a4d = tests_get_dword_lh(repl + 0x4d);
fprintf(stdout, "NWREQ87 dword[0]=%08lX dword[4]=%08lX dword[4d]=%08lX\n",
a0, a4, a4d);
return(0);
}
static int tests_reqtype(void)
{
union REGS r;
struct SREGS s;
memset(&r, 0, sizeof(r));
memset(&s, 0, sizeof(s));
fprintf(stdout, "TEST requester type probes\n\n");
/*
* DeveloperNet 1997 dvlmreq.c:
* AX=7A20h, BX=0, INT 2Fh
* if AX==0 then ES:BX is VLM entry and client type is VLM.
*/
r.x.ax = 0x7A20;
r.x.bx = 0;
int86x(0x2F, &r, &r, &s);
fprintf(stdout, "INT 2F AX=7A20 -> AX=%04X BX=%04X ES=%04X\n",
r.x.ax, r.x.bx, s.es);
if (r.x.ax == 0)
fprintf(stdout, "VLM entry likely present at %04X:%04X\n", s.es, r.x.bx);
else
fprintf(stdout, "VLM entry not reported by INT 2F/7A20\n");
/*
* DeveloperNet 1997 dvlmreq.c:
* AH=DCh, CX=0, INT 21h
* if CX != 0 then NETX/Shell API is present.
*/
memset(&r, 0, sizeof(r));
memset(&s, 0, sizeof(s));
r.h.ah = 0xDC;
r.x.cx = 0;
int86x(0x21, &r, &r, &s);
fprintf(stdout, "INT 21 AH=DC CX=0 -> AX=%04X BX=%04X CX=%04X DX=%04X ES=%04X\n",
r.x.ax, r.x.bx, r.x.cx, r.x.dx, s.es);
if (r.x.cx != 0)
fprintf(stdout, "NETX/Shell API likely present\n");
else
fprintf(stdout, "NETX/Shell API not reported by AH=DC\n");
fprintf(stdout, "\nInterpretation like DeveloperNet dvlmreq.c:\n");
if (r.x.cx != 0)
fprintf(stdout, " Shell bit present\n");
fprintf(stdout, " If INT2F AX=7A20 returned AX=0000, VLM path should be used for NWCREQUEST.\n");
return(0);
}
int func_tests(int argc, char *argv[], int mode)
{
if (argc >= 2) {
if (tests_same_arg(argv[1], "NETCALL"))
return tests_netcall();
if (tests_same_arg(argv[1], "E300") || tests_same_arg(argv[1], "NETCALLE300"))
return tests_netcall_e300();
if (tests_same_arg(argv[1], "REQTYPE"))
return tests_reqtype();
if (tests_same_arg(argv[1], "NWREQ87"))
return tests_nwreq87(argc, argv);
if (tests_same_arg(argv[1], "NCPF2"))
return tests_ncpf2(argc, argv);
if (tests_same_arg(argv[1], "OLD"))
return tests_old(argc - 1, argv + 1, mode);
if (tests_same_arg(argv[1], "/?") || tests_same_arg(argv[1], "-?") ||
tests_same_arg(argv[1], "?")) {
tests_usage();
return(0);
}
}
/*
* Default and unknown arguments keep the historical nwtests.c behavior.
*/
return tests_old(argc, argv, mode);
}