Compare commits

...

40 Commits

Author SHA1 Message Date
Mario Fetka
ed5da6c063 tests 2026-05-23 14:23:25 +02:00
Mario Fetka
19ded9333b tests 2026-05-23 14:20:47 +02:00
Mario Fetka
847559631a tests 2026-05-23 14:13:15 +02:00
Mario Fetka
1f74c940d8 tests 2026-05-23 14:06:36 +02:00
Mario Fetka
24ccc1257d tests 2026-05-23 13:33:54 +02:00
Mario Fetka
e6495fb949 tests 2026-05-23 13:28:02 +02:00
Mario Fetka
e5aa3a8b90 tests 2026-05-23 13:23:47 +02:00
Mario Fetka
56a76d3b43 tests 2026-05-23 13:21:26 +02:00
Mario Fetka
0c14d040aa tests 2026-05-23 13:14:57 +02:00
Mario Fetka
7ceddb8a82 kern 2026-05-23 13:10:03 +02:00
Mario Fetka
cc96eb72c4 flag 2026-05-23 12:47:16 +02:00
Mario Fetka
fe91b08d5d flag 2026-05-23 11:47:47 +02:00
Mario Fetka
ae2e1c3062 flag 2026-05-23 11:38:07 +02:00
Mario Fetka
f48f62dd91 flag 2026-05-23 11:19:55 +02:00
Mario Fetka
fa999bd0c9 flag 2026-05-23 11:15:44 +02:00
Mario Fetka
e4dc502dcb flag 2026-05-23 10:26:05 +02:00
Mario Fetka
02566b661f flag 2026-05-23 10:19:30 +02:00
Mario Fetka
c412f2ebbd map warnings 2026-05-22 20:47:34 +02:00
Mario Fetka
b8b323e3c3 map warnings 2026-05-22 20:45:59 +02:00
Mario Fetka
30fc1f7069 add flag 2026-05-22 20:44:06 +02:00
Mario Fetka
b42b0e2a58 map del 2026-05-22 20:21:08 +02:00
Mario Fetka
4d01fbd118 slist 2026-05-22 20:06:55 +02:00
Mario Fetka
a2d4025452 slist 2026-05-22 19:55:48 +02:00
Mario Fetka
f0bb61b0d7 slist 2026-05-22 19:51:38 +02:00
Mario Fetka
6db4fc17fa slist 2026-05-22 19:45:36 +02:00
Mario Fetka
1601a80513 slist 2026-05-22 19:38:31 +02:00
Mario Fetka
d1840da361 slist 2026-05-22 19:34:07 +02:00
Mario Fetka
f263335ef9 Login Vars 2026-05-22 19:23:48 +02:00
Mario Fetka
bb6c34dce4 pathins fix 2026-05-22 19:06:30 +02:00
Mario Fetka
f0c1cfcd84 pathins fix 2026-05-22 18:55:15 +02:00
Mario Fetka
7e5b75b4cc pathins fix 2026-05-22 18:48:27 +02:00
Mario Fetka
4809bd7e30 pathins fix 2026-05-22 18:16:01 +02:00
Mario Fetka
0ca6a3baaf pathins fix 2026-05-22 18:12:51 +02:00
Mario Fetka
3d2e7913ad Login new debug UNC 2026-05-22 17:52:11 +02:00
Mario Fetka
04c737d310 Login new debug UNC 2026-05-22 17:50:14 +02:00
Mario Fetka
7dad85c13e Login new debug 2026-05-22 17:37:17 +02:00
Mario Fetka
00654ad161 Login new 2026-05-22 17:32:13 +02:00
Mario Fetka
7b3778ceb4 Login new 2026-05-22 17:26:56 +02:00
Mario Fetka
f08aa986a8 Login new 2026-05-22 17:18:33 +02:00
Mario Fetka
4e49ecec1a Login new 2026-05-22 17:16:17 +02:00
10 changed files with 1697 additions and 70 deletions

View File

@@ -24,6 +24,7 @@ set(MARS_DOSUTILS_PUBLIC_TOOLS
mapdel
logout
slist
flag
capture
endcap
)
@@ -35,6 +36,7 @@ if(MARS_NWE_BUILD_DOSUTILS)
find_package(OpenWatcom REQUIRED)
set(DOSUTILS_C_SOURCES
kern.c
net.c
tools.c
netcall.c
@@ -42,6 +44,7 @@ if(MARS_NWE_BUILD_DOSUTILS)
login.c
map.c
slist.c
flag.c
nwcrypt.c
nwdebug.c
nwtests.c
@@ -117,3 +120,8 @@ install(FILES "${MARS_DOSUTILS_NET_EXE}"
install(FILES "${MARS_DOSUTILS_NET_EXE}"
DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login"
RENAME map.exe)
install(FILES "${MARS_DOSUTILS_NET_EXE}"
DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login"
RENAME slist.exe)

486
flag.c Normal file
View File

@@ -0,0 +1,486 @@
/* flag.c - Novell FLAG-like DOS utility, stage 1 */
#include "net.h"
#include <dos.h>
/*
* FLAG v4b: NCP 87 namespace DOS info.
*
* ncpfs reference:
* ncp_ns_modify_entry_dos_info():
* subfunction 7, namespace DOS, search attrs SA_ALL,
* ModifyInformationMask, struct ncp_dos_info, handle/path.
*
* We use dirstyle=0 (short directory handle) against the current DOS
* directory handle and a one-component DOS filename.
*/
#define FLAG_NW_NS_DOS 0x00
#define FLAG_SA_ALL 0x0006
#define FLAG_RIM_ATTRIBUTES 0x00000004UL
#define NWFA_RO 0x00000001UL
#define NWFA_H 0x00000002UL
#define NWFA_SY 0x00000004UL
#define NWFA_A 0x00000020UL
#define NWFA_S 0x00000080UL
#define NWFA_T 0x00001000UL
#define NWFA_RA 0x00004000UL
#define NWFA_WA 0x00008000UL
#define NWFA_P 0x00010000UL
#define NWFA_RI 0x00020000UL
#define NWFA_DI 0x00040000UL
#define NWFA_CI 0x00080000UL
static void flag_put_word_lh(uint8 *p, uint16 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
}
static void flag_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 flag_get_dword_lh(uint8 *p)
{
return((uint32)p[0] |
((uint32)p[1] << 8) |
((uint32)p[2] << 16) |
((uint32)p[3] << 24));
}
static int flag_get_current_drive(void)
{
REGS regs;
regs.h.ah = 0x19; /* DOS get current default drive */
int86(0x21, &regs, &regs); /* AL = 0 for A:, 1 for B:, ... */
return((int)regs.h.al);
}
static int flag_current_dhandle(uint8 *dhandle)
{
uint8 connid = 0;
uint8 flags = 0;
int drive;
drive = flag_get_current_drive();
if (get_drive_info((uint8)drive, &connid, dhandle, &flags))
return(-1);
if (!connid || (flags & 0x80))
return(-1);
return(0);
}
static int flag_add_handle_path(uint8 *p, uint8 dhandle, char *name)
{
int nlen;
nlen = strlen(name);
if (nlen > 255) nlen = 255;
/*
* handle/path:
* volume/handle byte
* dir base dword
* dirstyle byte (0 = short dir handle)
* path components: 1 component, length, bytes
*/
*p++ = dhandle;
flag_put_dword_lh(p, 0L); p += 4;
*p++ = 0; /* dirstyle = handle */
*p++ = 1; /* one path component */
*p++ = (uint8)nlen;
memcpy(p, name, nlen);
p += nlen;
return(1 + 4 + 1 + 1 + 1 + nlen);
}
static int flag_ncp87_obtain_attrs(char *name, uint32 *attrs)
{
struct {
uint16 len;
uint8 data[320];
} req;
struct {
uint16 len;
uint8 data[128];
} repl;
uint8 dhandle = 0;
uint8 *p;
int hlen;
if (flag_current_dhandle(&dhandle))
return(-1);
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
p = req.data;
*p++ = 6; /* subfunction: obtain file/subdir info */
*p++ = FLAG_NW_NS_DOS; /* source namespace */
*p++ = FLAG_NW_NS_DOS; /* target namespace */
flag_put_word_lh(p, FLAG_SA_ALL); p += 2;
flag_put_dword_lh(p, FLAG_RIM_ATTRIBUTES); p += 4;
hlen = flag_add_handle_path(p, dhandle, name);
p += hlen;
req.len = (uint16)(p - req.data);
repl.len = sizeof(repl.data);
neterrno = Net_Call(0xF257, &req, &repl);
if (neterrno)
return(-1);
/*
* With RIM_ATTRIBUTES only, ncpfs expects NSI_Attributes first.
* First dword is the 32-bit Attributes field.
*/
if (attrs)
*attrs = flag_get_dword_lh(repl.data);
return(0);
}
static int flag_ncp87_modify_attrs(char *name, uint32 attrs)
{
struct {
uint16 len;
uint8 data[384];
} req;
struct {
uint16 len;
uint8 data[8];
} repl;
uint8 dhandle = 0;
uint8 *p;
int hlen;
if (flag_current_dhandle(&dhandle))
return(-1);
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
p = req.data;
*p++ = 7; /* subfunction: modify DOS info */
*p++ = FLAG_NW_NS_DOS;
*p++ = 0; /* reserved */
flag_put_word_lh(p, FLAG_SA_ALL); p += 2;
flag_put_dword_lh(p, FLAG_RIM_ATTRIBUTES); p += 4; /* modify mask */
flag_put_dword_lh(p, attrs); p += 4; /* Attributes */
/*
* Remaining ncp_dos_info fields. Mask says only Attributes is valid,
* so these should be ignored, but ncpfs still sends the full structure.
*/
memset(p, 0, 34);
p += 34;
hlen = flag_add_handle_path(p, dhandle, name);
p += hlen;
req.len = (uint16)(p - req.data);
repl.len = sizeof(repl.data);
neterrno = Net_Call(0xF257, &req, &repl);
if (neterrno)
return(-1);
return(0);
}
#ifndef _A_NORMAL
#define _A_NORMAL 0x00
#endif
#ifndef _A_RDONLY
#define _A_RDONLY 0x01
#endif
#ifndef _A_HIDDEN
#define _A_HIDDEN 0x02
#endif
#ifndef _A_SYSTEM
#define _A_SYSTEM 0x04
#endif
#ifndef _A_SUBDIR
#define _A_SUBDIR 0x10
#endif
#ifndef _A_ARCH
#define _A_ARCH 0x20
#endif
static int flag_same(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 flag_help(void)
{
fprintf(stdout, "USAGE: FLAG [path [ option | [+|-] attribute(s) ] [SUB]]\n");
fprintf(stdout, "\n");
fprintf(stdout, "386 Attributes:\n");
fprintf(stdout, "--------------\n");
fprintf(stdout, "\n");
fprintf(stdout, "RO Read Only\n");
fprintf(stdout, "RW Read Write\n");
fprintf(stdout, "S Sharable\n");
fprintf(stdout, "H Hidden\n");
fprintf(stdout, "Sy System\n");
fprintf(stdout, "T Transactional\n");
fprintf(stdout, "P Purge\n");
fprintf(stdout, "A Archive Needed\n");
fprintf(stdout, "RA Read Audit\n");
fprintf(stdout, "WA Write Audit\n");
fprintf(stdout, "CI Copy Inhibit\n");
fprintf(stdout, "DI Delete Inhibit\n");
fprintf(stdout, "RI Rename Inhibit\n");
fprintf(stdout, "\n");
fprintf(stdout, "All All\n");
fprintf(stdout, "N Normal\n");
fprintf(stdout, "SUB\n");
}
static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
{
int set = 1;
char *p = s;
if (*p == '+') {
set = 1;
p++;
} else if (*p == '-') {
set = 0;
p++;
}
if (!*p) return(-1);
if (flag_same(p, "RO")) {
if (set) {
*setbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
} else {
*clearbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
}
} else if (flag_same(p, "RW")) {
*clearbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "S")) {
if (set) *setbits |= (unsigned)NWFA_S;
else *clearbits |= (unsigned)NWFA_S;
} else if (flag_same(p, "H")) {
if (set) *setbits |= (unsigned)NWFA_H;
else *clearbits |= (unsigned)NWFA_H;
} else if (flag_same(p, "SY") || flag_same(p, "SYS") || flag_same(p, "SYSTEM")) {
if (set) *setbits |= (unsigned)NWFA_SY;
else *clearbits |= (unsigned)NWFA_SY;
} else if (flag_same(p, "T")) {
if (set) *setbits |= (unsigned)NWFA_T;
else *clearbits |= (unsigned)NWFA_T;
} else if (flag_same(p, "P")) {
if (set) *setbits |= (unsigned)NWFA_P;
else *clearbits |= (unsigned)NWFA_P;
} else if (flag_same(p, "A")) {
if (set) *setbits |= (unsigned)NWFA_A;
else *clearbits |= (unsigned)NWFA_A;
} else if (flag_same(p, "RA")) {
if (set) *setbits |= (unsigned)NWFA_RA;
else *clearbits |= (unsigned)NWFA_RA;
} else if (flag_same(p, "WA")) {
if (set) *setbits |= (unsigned)NWFA_WA;
else *clearbits |= (unsigned)NWFA_WA;
} else if (flag_same(p, "CI")) {
if (set) *setbits |= (unsigned)NWFA_CI;
else *clearbits |= (unsigned)NWFA_CI;
} else if (flag_same(p, "DI")) {
if (set) *setbits |= (unsigned)NWFA_DI;
else *clearbits |= (unsigned)NWFA_DI;
} else if (flag_same(p, "RI")) {
if (set) *setbits |= (unsigned)NWFA_RI;
else *clearbits |= (unsigned)NWFA_RI;
} else if (flag_same(p, "N") || flag_same(p, "NORMAL")) {
*clearbits |= (unsigned)(NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "ALL")) {
*setbits |= (unsigned)(NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else {
fprintf(stderr, "Unknown attribute encountered in command line.\n");
return(-1);
}
return(0);
}
static void flag_print_attrs(unsigned attr)
{
/*
* Novell order:
* RO/RW S A H Sy T P RA WA CI DI RI
*/
fprintf(stdout, "[ ");
fprintf(stdout, "%s ", (attr & NWFA_RO) ? "RO" : "Rw");
fprintf(stdout, "%c ", (attr & NWFA_S) ? 'S' : '-');
fprintf(stdout, "%c ", (attr & NWFA_A) ? 'A' : '-');
fprintf(stdout, "%c ", (attr & NWFA_H) ? 'H' : '-');
fprintf(stdout, "%s ", (attr & NWFA_SY) ? "Sy" : "-");
fprintf(stdout, "%c ", (attr & NWFA_T) ? 'T' : '-');
fprintf(stdout, "%c ", (attr & NWFA_P) ? 'P' : '-');
fprintf(stdout, "%s ", (attr & NWFA_RA) ? "Ra" : "--");
fprintf(stdout, "%s ", (attr & NWFA_WA) ? "Wa" : "--");
fprintf(stdout, "%s ", (attr & NWFA_CI) ? "CI" : "--");
fprintf(stdout, "%s ", (attr & NWFA_DI) ? "DI" : "--");
fprintf(stdout, "%s ", (attr & NWFA_RI) ? "RI" : "--");
fprintf(stdout, "]");
}
static void flag_display_one(char *name, unsigned attr)
{
fprintf(stdout, " %-23s ", name);
flag_print_attrs(attr);
fprintf(stdout, "\n");
}
static int flag_has_wildcards(char *s)
{
while (*s) {
if (*s == '*' || *s == '?') return(1);
s++;
}
return(0);
}
static int flag_list(char *pattern)
{
struct find_t ff;
unsigned findattr = _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH;
int found = 0;
if (_dos_findfirst(pattern, findattr, &ff))
return(-1);
do {
if (!(ff.attrib & _A_SUBDIR)) {
uint32 nwattrs;
if (flag_ncp87_obtain_attrs(ff.name, &nwattrs))
nwattrs = (uint32)ff.attrib;
flag_display_one(ff.name, (unsigned)nwattrs);
found++;
}
} while (!_dos_findnext(&ff));
return(found);
}
static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
{
struct find_t ff;
unsigned findattr = _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH;
int shown = 0;
if (_dos_findfirst(pattern, findattr, &ff))
return(-1);
do {
uint32 attrs;
uint32 newattrs;
char fname[260];
if (ff.attrib & _A_SUBDIR) continue;
strmaxcpy(fname, ff.name, sizeof(fname) - 1);
if (flag_ncp87_obtain_attrs(fname, &attrs))
attrs = (uint32)ff.attrib;
newattrs = (attrs | (uint32)setbits) & ~((uint32)clearbits);
if (newattrs != attrs) {
if (flag_ncp87_modify_attrs(fname, newattrs)) {
unsigned dosattr = (unsigned)(newattrs & (_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH));
if (_dos_setfileattr(fname, dosattr)) {
fprintf(stderr, "You don't have rights to change : %s\n", fname);
continue;
}
}
}
if (flag_ncp87_obtain_attrs(fname, &attrs))
attrs = newattrs;
flag_display_one(fname, (unsigned)attrs);
shown++;
} while (!_dos_findnext(&ff));
return(shown);
}
int func_flag(int argc, char *argv[], int mode)
{
char *path = "*.*";
int i;
unsigned setbits = 0;
unsigned clearbits = 0;
int have_change = 0;
int rc;
(void)mode;
if (argc > 1 && (flag_same(argv[1], "/?") || flag_same(argv[1], "-?") ||
flag_same(argv[1], "?"))) {
flag_help();
return(0);
}
if (argc > 1) {
path = argv[1];
if (flag_same(path, "SUB")) path = "*.*";
}
for (i = 2; i < argc; i++) {
if (flag_same(argv[i], "SUB")) continue;
rc = flag_attr_mask(argv[i], &setbits, &clearbits);
if (rc < 0) return(1);
if (rc > 0) continue;
have_change = 1;
}
if (have_change) {
rc = flag_apply(path, setbits, clearbits);
if (rc < 0) {
fprintf(stderr, "Files could not be found with pattern \"%s\"\n", path);
return(1);
}
return(0);
}
rc = flag_list(path);
if (rc < 0) {
fprintf(stderr, "Files could not be found with pattern \"%s\"\n", path);
return(1);
}
return(0);
}

226
kern.c Normal file
View File

@@ -0,0 +1,226 @@
/*
* kern.c - C-side experimental NetWare/DOS request wrappers
*
* kern_wasm.asm remains the production/reference implementation.
* These C functions are test wrappers so we can inspect register setup and
* slowly port proven pieces from ASM to C.
*/
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include "net.h"
#if defined(__WATCOMC__)
#define KERN_C_CALL _Cdecl
#else
#define KERN_C_CALL
#endif
typedef struct {
unsigned int in_ax;
unsigned int in_bx;
unsigned int in_cx;
unsigned int in_dx;
unsigned int in_si;
unsigned int in_di;
unsigned int in_ds;
unsigned int in_es;
unsigned int out_ax;
unsigned int out_bx;
unsigned int out_cx;
unsigned int out_dx;
unsigned int out_si;
unsigned int out_di;
unsigned int out_flags;
void far *req_ptr;
void far *repl_ptr;
int rc;
} NET_CALL_C_DEBUG;
NET_CALL_C_DEBUG Net_Call_C_Last;
static void net_call_c_clear(void)
{
memset(&Net_Call_C_Last, 0, sizeof(Net_Call_C_Last));
}
static void net_call_c_save_in(union REGS *r, struct SREGS *s,
void *req, void *repl)
{
Net_Call_C_Last.in_ax = r->x.ax;
Net_Call_C_Last.in_bx = r->x.bx;
Net_Call_C_Last.in_cx = r->x.cx;
Net_Call_C_Last.in_dx = r->x.dx;
Net_Call_C_Last.in_si = r->x.si;
Net_Call_C_Last.in_di = r->x.di;
Net_Call_C_Last.in_ds = s->ds;
Net_Call_C_Last.in_es = s->es;
Net_Call_C_Last.req_ptr = req;
Net_Call_C_Last.repl_ptr = repl;
}
static void net_call_c_save_out(union REGS *r, unsigned int returned_ax)
{
Net_Call_C_Last.out_ax = returned_ax;
Net_Call_C_Last.out_bx = r->x.bx;
Net_Call_C_Last.out_cx = r->x.cx;
Net_Call_C_Last.out_dx = r->x.dx;
Net_Call_C_Last.out_si = r->x.si;
Net_Call_C_Last.out_di = r->x.di;
Net_Call_C_Last.out_flags = r->x.cflag;
Net_Call_C_Last.rc = returned_ax & 0x00ff;
}
/*
* C equivalent of kern_wasm.asm Net_Call:
* AX = func
* DS:SI = request
* ES:DI = reply
* int 21h
* return AL only, because kern_wasm.asm clears AH before return.
*/
int KERN_C_CALL Net_Call_C(unsigned int ax, void *req, void *repl)
{
return Net_Call_CX(ax, 0, 0, 0, req, repl);
}
int KERN_C_CALL Net_Call_CX(unsigned int ax, unsigned int bx,
unsigned int cx, unsigned int dx,
void *req, void *repl)
{
union REGS inregs;
union REGS outregs;
struct SREGS segregs;
unsigned int ret_ax;
memset(&inregs, 0, sizeof(inregs));
memset(&outregs, 0, sizeof(outregs));
memset(&segregs, 0, sizeof(segregs));
net_call_c_clear();
inregs.x.ax = ax;
inregs.x.bx = bx;
inregs.x.cx = cx;
inregs.x.dx = dx;
inregs.x.si = FP_OFF(req);
inregs.x.di = FP_OFF(repl);
segregs.ds = FP_SEG(req);
segregs.es = FP_SEG(repl);
net_call_c_save_in(&inregs, &segregs, req, repl);
int86x(0x21, &inregs, &outregs, &segregs);
ret_ax = outregs.x.ax & 0x00ff; /* match ASM Net_Call return */
net_call_c_save_out(&outregs, ret_ax);
return (int)ret_ax;
}
/*
* Experimental Novell Client/VLM AH=F2 wrapper derived from official FLAG.EXE
* disassembly:
* AH = F2h
* AL = NCP function, e.g. 57h for NCP 87
* CX = request length
* DX = reply buffer length
* DS:SI = request buffer
* ES:DI = reply buffer
*/
int KERN_C_CALL Net_Call_F2_C(unsigned int function,
unsigned int req_len,
unsigned int repl_len,
void *req,
void *repl)
{
union REGS inregs;
union REGS outregs;
struct SREGS segregs;
unsigned int ret_ax;
memset(&inregs, 0, sizeof(inregs));
memset(&outregs, 0, sizeof(outregs));
memset(&segregs, 0, sizeof(segregs));
net_call_c_clear();
inregs.h.ah = 0xF2;
inregs.h.al = (unsigned char)(function & 0xff);
inregs.x.cx = req_len;
inregs.x.dx = repl_len;
inregs.x.si = FP_OFF(req);
inregs.x.di = FP_OFF(repl);
segregs.ds = FP_SEG(req);
segregs.es = FP_SEG(repl);
net_call_c_save_in(&inregs, &segregs, req, repl);
int86x(0x21, &inregs, &outregs, &segregs);
/*
* Novell wrapper behavior:
* xor ah,ah
* or al,al
* if al != 0: ah=89h
* Return AL only for C caller, but keep 89xx in debug out_ax.
*/
ret_ax = outregs.x.ax & 0x00ff;
if (ret_ax)
ret_ax |= 0x8900;
net_call_c_save_out(&outregs, ret_ax);
return (int)(ret_ax & 0x00ff);
}
void KERN_C_CALL Net_Call_C_Dump(void)
{
fprintf(stdout, "NETCALLC in : AX=%04X BX=%04X CX=%04X DX=%04X DS:SI=%04X:%04X ES:DI=%04X:%04X\n",
Net_Call_C_Last.in_ax,
Net_Call_C_Last.in_bx,
Net_Call_C_Last.in_cx,
Net_Call_C_Last.in_dx,
Net_Call_C_Last.in_ds,
Net_Call_C_Last.in_si,
Net_Call_C_Last.in_es,
Net_Call_C_Last.in_di);
fprintf(stdout, "NETCALLC out: AX=%04X BX=%04X CX=%04X DX=%04X SI=%04X DI=%04X CF=%04X RC=%d\n",
Net_Call_C_Last.out_ax,
Net_Call_C_Last.out_bx,
Net_Call_C_Last.out_cx,
Net_Call_C_Last.out_dx,
Net_Call_C_Last.out_si,
Net_Call_C_Last.out_di,
Net_Call_C_Last.out_flags,
Net_Call_C_Last.rc);
}
unsigned int KERN_C_CALL Net_Call_C_GetDebug(unsigned int idx)
{
switch (idx) {
case 0: return Net_Call_C_Last.in_ax;
case 1: return Net_Call_C_Last.in_bx;
case 2: return Net_Call_C_Last.in_cx;
case 3: return Net_Call_C_Last.in_dx;
case 4: return Net_Call_C_Last.in_ds;
case 5: return Net_Call_C_Last.in_si;
case 6: return Net_Call_C_Last.in_es;
case 7: return Net_Call_C_Last.in_di;
case 8: return Net_Call_C_Last.out_ax;
case 9: return Net_Call_C_Last.out_bx;
case 10: return Net_Call_C_Last.out_cx;
case 11: return Net_Call_C_Last.out_dx;
case 12: return Net_Call_C_Last.out_si;
case 13: return Net_Call_C_Last.out_di;
case 14: return Net_Call_C_Last.out_flags;
case 15: return (unsigned int)Net_Call_C_Last.rc;
}
return 0xffff;
}

11
kern.h
View File

@@ -13,8 +13,17 @@ extern void asm_esr_routine(void);
extern void esr_routine(ECB *ecb);
extern void KERN_CALL xmemmove(void *ziel, void *quelle, UI anz);
extern int KERN_CALL Net_Call(UI func, void *req, void *repl);
extern int KERN_CALL Net_Call_C(UI func, void *req, void *repl);
extern int KERN_CALL Net_Call_CX(UI func, UI bx, UI cx, UI dx,
void *req, void *repl);
extern int KERN_CALL Net_Call_F2_C(UI function, UI req_len, UI repl_len,
void *req, void *repl);
extern void KERN_CALL Net_Call_C_Dump(void);
extern UI KERN_CALL Net_Call_C_GetDebug(UI idx);
#undef KERN_CALL

350
login.c
View File

@@ -6,6 +6,7 @@
#include "net.h"
#include "nwcrypt.h"
#include <time.h>
#ifndef BLACK
#define BLACK 0
@@ -23,6 +24,75 @@
static uint8 script_login_name[64];
static uint8 script_file_server[52];
static char **build_argv(char *buf, int bufsize, char *str);
extern int read_command_file(char *fstr);
extern int get_fs_name(int connid, char *name);
static uint8 login_video_attr = 0x07;
static void login_gotoxy(int x, int y)
{
REGS regs;
regs.h.ah = 0x02;
regs.h.bh = 0x00;
regs.h.dh = (uint8)(y - 1);
regs.h.dl = (uint8)(x - 1);
int86(0x10, &regs, &regs);
}
static void login_cls_attr(uint8 attr)
{
REGS regs;
regs.h.ah = 0x06;
regs.h.al = 0x00;
regs.h.bh = attr;
regs.h.ch = 0;
regs.h.cl = 0;
regs.h.dh = 24;
regs.h.dl = 79;
int86(0x10, &regs, &regs);
login_gotoxy(1, 1);
}
static void login_write_attr(int x, int y, const char *s, uint8 attr)
{
REGS regs;
int col = x;
while (*s) {
login_gotoxy(col++, y);
regs.h.ah = 0x09;
regs.h.al = (uint8)*s++;
regs.h.bh = 0;
regs.h.bl = attr;
regs.x.cx = 1;
int86(0x10, &regs, &regs);
}
login_gotoxy(col, y);
}
static void login_fill_line(int y, uint8 attr)
{
REGS regs;
login_gotoxy(1, y);
regs.h.ah = 0x09;
regs.h.al = ' ';
regs.h.bh = 0;
regs.h.bl = attr;
regs.x.cx = 80;
int86(0x10, &regs, &regs);
}
static void login_screen_normal(void)
{
login_video_attr = 0x07;
}
static int login_help(void)
{
fprintf(stdout, "\n");
@@ -46,20 +116,22 @@ static int login_help(void)
static void login_banner(void)
{
int i;
login_cls_attr(0x07); /* normal black background */
textbackground(BLUE);
textcolor(WHITE);
clrscr();
/*
* NetWare-like header, but blue for Mars NWE:
* blue separator
* blue title line
* blue separator
* then normal black prompt area.
*/
login_fill_line(1, 0x1f); /* white on blue */
login_fill_line(2, 0x1f); /* white on blue */
login_write_attr(36, 2, "Mars NWE", 0x1f);
login_fill_line(3, 0x1f); /* white on blue */
gotoxy(1, 1);
for (i = 0; i < 80; i++) putch(' ');
gotoxy(36, 1);
cputs("Mars NWE");
textbackground(BLACK);
textcolor(LIGHTGRAY);
gotoxy(1, 3);
login_screen_normal();
login_gotoxy(1, 4);
}
static char *skip_spaces(char *p)
@@ -88,18 +160,100 @@ static void strip_quotes(char *s)
*d = '\0';
}
static void script_get_timevar(char *name, char *out, int outlen)
{
time_t now;
struct tm *tmv;
int hour;
static char *months[] = {
"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
"JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
};
static char *days[] = {
"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY",
"THURSDAY", "FRIDAY", "SATURDAY"
};
*out = '\0';
time(&now);
tmv = localtime(&now);
if (!tmv) return;
upstr(name);
if (!strcmp(name, "GREETING_TIME")) {
if (tmv->tm_hour < 12) strcpy(out, "MORNING");
else if (tmv->tm_hour < 18) strcpy(out, "AFTERNOON");
else strcpy(out, "EVENING");
} else if (!strcmp(name, "MONTH_NAME")) {
strmaxcpy(out, months[tmv->tm_mon], outlen - 1);
} else if (!strcmp(name, "MONTH")) {
sprintf(out, "%02d", tmv->tm_mon + 1);
} else if (!strcmp(name, "DAY")) {
sprintf(out, "%02d", tmv->tm_mday);
} else if (!strcmp(name, "YEAR")) {
sprintf(out, "%04d", tmv->tm_year + 1900);
} else if (!strcmp(name, "DAY_OF_WEEK")) {
strmaxcpy(out, days[tmv->tm_wday], outlen - 1);
} else if (!strcmp(name, "HOUR")) {
hour = tmv->tm_hour % 12;
if (!hour) hour = 12;
sprintf(out, "%d", hour);
} else if (!strcmp(name, "MINUTE")) {
sprintf(out, "%02d", tmv->tm_min);
} else if (!strcmp(name, "SECOND")) {
sprintf(out, "%02d", tmv->tm_sec);
} else if (!strcmp(name, "AM_PM")) {
strcpy(out, tmv->tm_hour >= 12 ? "PM" : "AM");
}
}
static void script_expand_var(char *name, char *out, int outlen)
{
upstr(name);
*out = '\0';
if (!strcmp(name, "LOGIN_NAME")) {
strmaxcpy(out, script_login_name, outlen - 1);
} else if (!strcmp(name, "FILE_SERVER")) {
strmaxcpy(out, script_file_server, outlen - 1);
} else if (!strcmp(name, "P_STATION") || !strcmp(name, "STATION")) {
strcpy(out, "000000000000");
} else {
script_get_timevar(name, out, outlen);
if (!*out) {
strcpy(out, "%");
strncat(out, name, outlen - strlen(out) - 1);
}
}
}
static void script_put_expanded(char *s)
{
while (s && *s) {
if (!strncmp(s, "%LOGIN_NAME", 11) || !strncmp(s, "%login_name", 11)) {
fprintf(stdout, "%s", script_login_name);
s += 11;
} else if (!strncmp(s, "%FILE_SERVER", 12) || !strncmp(s, "%file_server", 12)) {
fprintf(stdout, "%s", script_file_server);
s += 12;
} else if (!strncmp(s, "%P_STATION", 10) || !strncmp(s, "%p_station", 10)) {
fprintf(stdout, "000000000000");
s += 10;
if (*s == '%') {
char name[64];
char value[128];
int i = 0;
s++;
while ((*s == '_' ||
(*s >= 'A' && *s <= 'Z') ||
(*s >= 'a' && *s <= 'z') ||
(*s >= '0' && *s <= '9')) &&
i < (int)sizeof(name) - 1) {
name[i++] = *s++;
}
name[i] = '\0';
if (i) {
script_expand_var(name, value, sizeof(value));
fprintf(stdout, "%s", value);
} else {
fputc('%', stdout);
}
} else {
fputc(*s++, stdout);
}
@@ -170,26 +324,62 @@ static int script_eval_if(char *line)
if (q != NULL) {
char want[64];
char *v;
char have[64];
int i = 0;
q += neg ? 2 : 1;
q = skip_spaces(q);
if (*q == '"' || *q == '\'') q++;
while (*q && *q != '"' && *q != '\'' && *q != 32 && *q != '\t' && i < 63) {
while (*q && *q != '"' && *q != '\'' && *q != 32 && *q != '\t' && i < 63)
want[i++] = *q++;
}
want[i] = '\0';
strmaxcpy(tmp, script_login_name, sizeof(tmp) - 1);
upstr(tmp);
strmaxcpy(have, script_login_name, sizeof(have) - 1);
upstr(have);
if (neg) return(strcmp(tmp, want) != 0);
else return(strcmp(tmp, want) == 0);
if (neg) return(strcmp(have, want) != 0);
return(strcmp(have, want) == 0);
}
}
p = strstr(tmp, "DAY_OF_WEEK");
if (p != NULL) {
q = strchr(p, '=');
if (q != NULL) {
char want[64];
char have[64];
int i = 0;
q++;
q = skip_spaces(q);
if (*q == '"' || *q == '\'') q++;
while (*q && *q != '"' && *q != '\'' && *q != 32 && *q != '\t' && i < 63)
want[i++] = *q++;
want[i] = '\0';
strcpy(have, "DAY_OF_WEEK");
script_get_timevar(have, have, sizeof(have));
upstr(have);
return(strcmp(have, want) == 0);
}
}
return(0);
}
static int login_strnicmp(char *a, char *b, int n)
{
while (n-- > 0) {
int ca = *a++;
int cb = *b++;
if (ca >= 'a' && ca <= 'z') ca -= 32;
if (cb >= 'a' && cb <= 'z') cb -= 32;
if (ca != cb) return(ca - cb);
if (!ca) return(0);
}
return(0);
}
@@ -204,7 +394,7 @@ static int script_execute_line(char *line)
strmaxcpy(work, line, sizeof(work) - 1);
p = skip_spaces(work);
if (!*p) return(0);
if (!*p || *p == ';') return(0);
i = 0;
while (p[i] && p[i] != 32 && p[i] != '\t' && i < 31) {
@@ -230,7 +420,7 @@ static int script_execute_line(char *line)
}
if (!strcmp(cmd, "CLS")) {
clrscr();
login_cls_attr(0x07);
return(0);
}
@@ -262,10 +452,17 @@ static int script_execute_line(char *line)
return(0);
}
if (!strncmp(up, "ROOT ", 5)) {
char callbuf[512];
sprintf(callbuf, "MAP %s", skip_spaces(arg + 5));
script_call_line(callbuf);
return(0);
}
if (!strncmp(up, "INS ", 4) || !strncmp(up, "INSERT ", 7)) {
char callbuf[512];
char *a = arg;
if (!strnicmp(up, "INS ", 4)) a += 4;
if (!login_strnicmp(up, "INS ", 4)) a += 4;
else a += 7;
sprintf(callbuf, "PATHINS %s", skip_spaces(a));
script_call_line(callbuf);
@@ -275,7 +472,7 @@ static int script_execute_line(char *line)
if (!strncmp(up, "DEL ", 4) || !strncmp(up, "DELETE ", 7)) {
char callbuf[512];
char *a = arg;
if (!strnicmp(up, "DEL ", 4)) a += 4;
if (!login_strnicmp(up, "DEL ", 4)) a += 4;
else a += 7;
sprintf(callbuf, "PATHDEL %s", skip_spaces(a));
script_call_line(callbuf);
@@ -283,6 +480,10 @@ static int script_execute_line(char *line)
}
}
if (!strcmp(cmd, "ATTACH")) {
return(0);
}
if (!strcmp(cmd, "EXIT")) {
return(1);
}
@@ -291,20 +492,87 @@ static int script_execute_line(char *line)
return(0);
}
static int try_login_script_file(char *name)
{
return(read_command_file(name));
}
static int run_login_script(void)
{
char profile[200];
char drive;
sprintf(profile, "%snet$log.dat", prgpath);
if (read_command_file(profile) != -2) return(0);
/*
* Novell LOGIN looks for the system login script using server based paths,
* for example \\SERVER\SYS\PUBLIC\NET$LOG.DAT. Try that first.
*/
if (*script_file_server) {
sprintf(profile, "\\\\%s\\SYS\\PUBLIC\\NET$LOG.DAT", script_file_server);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%slogin", prgpath);
if (read_command_file(profile) != -2) return(0);
sprintf(profile, "\\\\%s\\SYS\\PUBLIC\\net$log.dat", script_file_server);
if (try_login_script_file(profile) != -2) return(0);
if (read_command_file("net$log.dat") != -2) return(0);
if (read_command_file("login") != -2) return(0);
if (read_command_file("\\login\\login") != -2) return(0);
if (read_command_file("\\login\\net$log.dat") != -2) return(0);
sprintf(profile, "\\\\%s\\SYS\\LOGIN\\LOGIN", script_file_server);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "\\\\%s\\SYS\\LOGIN\\NET$LOG.DAT", script_file_server);
if (try_login_script_file(profile) != -2) return(0);
}
/*
* Then try current directory and the executable path. LOGIN.EXE is often
* executed from PUBLIC, so this covers SYS:PUBLIC\NET$LOG.DAT without
* relying on an absolute drive path.
*/
if (try_login_script_file("NET$LOG.DAT") != -2) return(0);
if (try_login_script_file("net$log.dat") != -2) return(0);
if (try_login_script_file("LOGIN") != -2) return(0);
if (try_login_script_file("login") != -2) return(0);
if (*prgpath) {
sprintf(profile, "%sNET$LOG.DAT", prgpath);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%snet$log.dat", prgpath);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%sLOGIN", prgpath);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%slogin", prgpath);
if (try_login_script_file(profile) != -2) return(0);
}
/*
* Fallbacks for requesters/runtimes that cannot open UNC from C fopen().
*/
if (try_login_script_file("\\PUBLIC\\NET$LOG.DAT") != -2) return(0);
if (try_login_script_file("\\public\\net$log.dat") != -2) return(0);
if (try_login_script_file("\\PUBLIC\\LOGIN") != -2) return(0);
if (try_login_script_file("\\public\\login") != -2) return(0);
if (try_login_script_file("\\LOGIN\\LOGIN") != -2) return(0);
if (try_login_script_file("\\login\\login") != -2) return(0);
if (try_login_script_file("\\LOGIN\\NET$LOG.DAT") != -2) return(0);
if (try_login_script_file("\\login\\net$log.dat") != -2) return(0);
for (drive = 'C'; drive <= 'Z'; drive++) {
sprintf(profile, "%c:\\PUBLIC\\NET$LOG.DAT", drive);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%c:\\public\\net$log.dat", drive);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%c:\\PUBLIC\\LOGIN", drive);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%c:\\LOGIN\\LOGIN", drive);
if (try_login_script_file(profile) != -2) return(0);
sprintf(profile, "%c:\\LOGIN\\NET$LOG.DAT", drive);
if (try_login_script_file(profile) != -2) return(0);
}
return(-2);
}
@@ -469,7 +737,7 @@ int func_login(int argc, char *argv[], int mode)
if (argv[1][0] == '-' || argv[1][0] == '/') {
if (argv[1][1] == 'u' || argv[1][1] == 'U') option |= 1;
else if (!strcmp(argv[1], "/NS") || !strcmp(argv[1], "-NS")) no_script = 1;
else if (!strcmp(argv[1], "/CLS") || !strcmp(argv[1], "-CLS")) clrscr();
else if (!strcmp(argv[1], "/CLS") || !strcmp(argv[1], "-CLS")) login_cls_attr(0x07);
else return(login_usage());
argc--;
argv++;

306
map.c
View File

@@ -28,9 +28,9 @@ static void show_map(uint8 *drvstr)
if (flags & 0x80) { /* lokal DRIVE */
path[0]= '\\';
if (j < 2){
strcpy(path, "DISK LW");
strcpy(path, "maps to a local disk.");
} else if (getcurdir(j+1, path+1)) {
strcpy(path, "LW !OK");
strcpy(path, "maps to a local disk.");
}
} else {
if (get_dir_path(dhandle, path)) {
@@ -41,7 +41,7 @@ static void show_map(uint8 *drvstr)
strcat(servern, "\\");
} else servern[0]='\0';
}
printf("MAP %c: = %s%s\n", (char)j+'A', servern, path);
if (flags & 0x80) printf("Drive %c: %s\n", (char)j+'A', path); else printf("Drive %c: = %s%s\n", (char)j+'A', servern, path);
}
}
}
@@ -58,9 +58,9 @@ static void do_map(int drive, NWPATH *nwp)
if (flags & 0x80) { /* lokal DRIVE */
path[0]= '\\';
if (drive < 2){
strcpy(path, "DISK LW");
strcpy(path, "maps to a local disk.");
} else if (getcurdir(drive+1, path+1)) {
strcpy(path, "LW !OK");
strcpy(path, "maps to a local disk.");
}
} else {
if (get_dir_path(dhandle, path)) {
@@ -188,11 +188,129 @@ static int parse_argv(uint8 *drvstr, NWPATH *nwpath,
return(0);
}
static int parse_pathins_arg(uint8 *drvstr, NWPATH *nwp,
int argc, char *argv[], int mode);
static int set_search_native(uint8 *drvstr, NWPATH *nwp, int pathmode);
static int show_search(uint8 *drvstr);
static int map_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 int map_is_drive_arg(char *s)
{
if (!s || !s[0] || s[1] != ':' || s[2]) return(0);
if (s[0] >= 'A' && s[0] <= 'Z') return(1);
if (s[0] >= 'a' && s[0] <= 'z') return(1);
return(0);
}
static int map_drive_index(char *s)
{
if (s[0] >= 'a' && s[0] <= 'z') return(s[0] - 'a');
return(s[0] - 'A');
}
static void map_drive_name(char *dst, char *src)
{
dst[0] = src[0];
if (dst[0] >= 'a' && dst[0] <= 'z') dst[0] -= 32;
dst[1] = ':';
dst[2] = '\0';
}
static int map_handle_path_command(int argc, char *argv[], int pathmode)
{
uint8 drvstr[22];
NWPATH nwpath;
int rc;
rc = parse_pathins_arg(drvstr, &nwpath, argc, argv, pathmode);
if (!rc) {
int result = 0;
if (*(nwpath.path) || pathmode == 1)
result = set_search_native(drvstr, &nwpath, pathmode);
if (result < 0)
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
else if (pathmode != 1)
show_search(drvstr);
else
fprintf(stdout, "The search mapping for drive S%d: was deleted\n",
(int)drvstr[1]);
return(result);
}
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(-1);
}
int func_map(int argc, char *argv[], int mode)
{
uint8 drvstr[22];
NWPATH nwpath;
if (!ipx_init()) argc = 1;
/*
* Novell MAP accepts subcommands through MAP itself:
* MAP DEL H:
* MAP INS S1:=SYS:PUBLIC
* MAP DEL S1:
* The original mars-dosutils exposed those mainly as MAPDEL/PATHINS/PATHDEL,
* so handle the Novell syntax here and then reuse the existing primitives.
*/
if (argc > 1) {
if (map_same_arg(argv[1], "/?") || map_same_arg(argv[1], "-?") ||
map_same_arg(argv[1], "?")) {
fprintf(stderr, "Directory \"/?\" is not locatable.\n");
return(1);
}
if (map_same_arg(argv[1], "INS") || map_same_arg(argv[1], "INSERT")) {
if (argc < 3) {
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}
return(map_handle_path_command(argc - 1, argv + 1, 2));
}
if (map_same_arg(argv[1], "DEL") || map_same_arg(argv[1], "DELETE")) {
if (argc < 3) {
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}
if (map_is_drive_arg(argv[2])) {
char dname[3];
int drive = map_drive_index(argv[2]);
if (do_map(drive, &nwpath, 1) < 0) {
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}
map_drive_name(dname, argv[2]);
fprintf(stdout, "The mapping for drive %s has been deleted.\n", dname);
return(0);
}
return(map_handle_path_command(argc - 1, argv + 1, 1));
}
}
if (!parse_argv(drvstr, &nwpath, argc, argv, 0, mode)) {
if (*(nwpath.path) || mode==1) {
if (do_map(*drvstr - 'A', &nwpath, mode)< 0)
@@ -297,18 +415,192 @@ static int set_search(uint8 *drvstr, NWPATH *nwp, int pathmode)
return(result);
}
static int path_is_drive_path(uint8 *path)
{
if (!path || !path[0] || path[1] != ':') return(0);
if (path[0] >= 'A' && path[0] <= 'Z') return(1);
if (path[0] >= 'a' && path[0] <= 'z') return(1);
return(0);
}
static void upstr_local(uint8 *s)
{
while (*s) {
if (*s >= 'a' && *s <= 'z') *s -= 0x20;
s++;
}
}
static int parse_pathins_arg(uint8 *drvstr, NWPATH *nwp, int argc, char *argv[], int mode)
{
char joined[512];
char *p;
char *q;
int slot = 0;
int k;
*drvstr = '\0';
memset(nwp, 0, sizeof(NWPATH));
nwp->path = nwp->buff;
*(nwp->buff) = '\0';
if (argc < 2) return(1);
joined[0] = '\0';
for (k = 1; k < argc; k++) {
if (k > 1) strcat(joined, " ");
strncat(joined, argv[k], sizeof(joined) - strlen(joined) - 1);
}
p = joined;
while (*p == ' ' || *p == '\t') p++;
if (*p != 'S' && *p != 's') return(-1);
p++;
while (*p >= '0' && *p <= '9') {
slot = slot * 10 + (*p - '0');
p++;
}
if (slot < 1 || slot > 16) return(-1);
if (*p != ':') return(-1);
p++;
drvstr[0] = 's';
drvstr[1] = (uint8)slot;
drvstr[2] = '\0';
while (*p == ' ' || *p == '\t') p++;
if (mode == 1) {
/* PATHDEL S1: */
return(0);
}
if (*p == '=') p++;
while (*p == ' ' || *p == '\t') p++;
if (!*p) return(-1);
q = nwp->buff;
while (*p && (q - nwp->buff) < (int)sizeof(nwp->buff) - 1) {
*q++ = *p++;
}
*q = '\0';
upstr_local(nwp->buff);
nwp->path = nwp->buff;
return(0);
}
static int set_search_native(uint8 *drvstr, NWPATH *nwp, int pathmode)
{
int result=-1;
SEARCH_VECTOR drives;
SEARCH_VECTOR_ENTRY *p=drives;
int j=0;
int entry = (*drvstr=='s') ? *(drvstr+1) : 0;
get_search_drive_vektor(drives);
while (p->drivenummer != 0xff && j++ < 16) {
if (!entry && path_is_drive_path(nwp->path)
&& (p->drivenummer + 'A' == nwp->path[0])) entry=j;
if (path_is_drive_path(nwp->path)
&& p->drivenummer + 'A' == nwp->path[0]
&& !strcmp(nwp->path+2, p->dospath)) {
p->drivenummer=0xfe;
*(p->dospath) = '\0';
p->flags = 0;
}
p++;
}
if (entry > 0) {
if (entry > 16) entry = 16;
if (pathmode == 2 && entry <= j && entry < 16) { /* insert modus */
int k=j+1-entry;
if (j < 16) {
p++;
k++;
j++;
}
while (k--) {
memcpy(p, p-1, sizeof(SEARCH_VECTOR_ENTRY));
--p;
}
}
if (--entry < j)
p = drives+entry;
else
(p+1)->drivenummer = 0xff;
memset(p, 0, sizeof(SEARCH_VECTOR_ENTRY));
if (pathmode==1) {
p->drivenummer = 0xfe;
*(p->dospath) = '\0';
result = set_search_drive_vektor(drives);
} else if (path_is_drive_path(nwp->path)) {
p->flags = 0;
p->drivenummer = (uint8)(nwp->path[0] - 'A');
if (nwp->path[0] >= 'a' && nwp->path[0] <= 'z')
p->drivenummer = (uint8)(nwp->path[0] - 'a');
strmaxcpy(p->dospath, nwp->path+2, sizeof(p->dospath)-1);
result = set_search_drive_vektor(drives);
} else {
/*
* Search path entries are not drive mappings. The original code stores
* the NetWare path text directly in dospath with drivenummer=0xfe.
* Client32 keeps/prints these entries correctly; allocating a permanent
* directory handle here made set_search_drive_vektor() return success,
* but the entry did not actually replace SEARCH1.
*/
p->flags = 0;
p->drivenummer = 0xfe;
strmaxcpy(p->dospath, nwp->path, sizeof(p->dospath)-1);
result = set_search_drive_vektor(drives);
}
}
return(result);
}
int func_path(int argc, char *argv[], int mode)
{
uint8 drvstr[22];
NWPATH nwpath;
if (!parse_argv(drvstr, &nwpath, argc, argv, 1, mode)) {
int rc;
/*
* PATH/PATHINS/PATHDEL need their own parser. The old parse_argv()
* rejects common login-script syntax such as:
* PATHINS S1:=SYS:PUBLIC
* MAP INS S1:=SYS:PUBLIC
*/
if (argc < 2) {
show_search("");
return(0);
}
rc = parse_pathins_arg(drvstr, &nwpath, argc, argv, mode);
if (!rc) {
int result=0;
if (*(nwpath.path) || mode==1)
result=set_search(drvstr, &nwpath, mode);
result=set_search_native(drvstr, &nwpath, mode);
if (mode != 1)
show_search(drvstr);
return(result);
}
fprintf(stderr, "Cannot interpret line. errcode=-1\n");
return(1);
}

1
net.c
View File

@@ -34,6 +34,7 @@ static struct s_net_functions {
{"PATHDEL","removes search path" , func_path , 1},
{"PATHINS","insert search path" , func_path , 2},
{"LOGOUT", "logout from server", func_logout , 0},
{"FLAG", "display or modify file attributes", func_flag , 0},
{"SLIST", "list servers", func_slist , 0},
{"PASSWD", "change password", func_passwd , 0},
#if 1

3
net.h
View File

@@ -252,6 +252,9 @@ extern int func_tests (int argc, char *argv[], int mode);
/* capture.c */
extern int func_capture(int argc, char *argv[], int mode);
/* flag.c */
extern int func_flag (int argc, char *argv[], int mode);
extern int ncp_17_37(uint32 last_id, uint16 objtyp, uint8 *pattern,
BINDERY_OBJECT *target);

292
nwtests.c
View File

@@ -6,13 +6,59 @@
#include "net.h"
static int usage(void)
static int tests_same_arg(char *a, char *b)
{
return(-1);
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);
}
int func_tests(int argc, char *argv[], int mode)
static void tests_usage(void)
{
fprintf(stdout, "Usage: TESTS [OLD|NETCALL|E300|NCPF2 [file] [REPLY]]\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;
@@ -42,3 +88,243 @@ int func_tests(int argc, char *argv[], int mode)
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);
}
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], "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);
}

84
slist.c
View File

@@ -2,17 +2,49 @@
#include "net.h"
#define NCP_BINDERY_FSERVER 0x0004
static int usage(void)
{
fprintf(stderr, "usage:\t%s [pattern]\n", funcname);
return(-1);
fprintf(stdout, "Usage: SLIST [Server] [/Continue]\n");
return(0);
}
static void print_net_node(uint8 *addr)
static int same_arg(char *a, char *b)
{
fprintf(stdout, "%08lX %02X%02X%02X%02X%02X%02X",
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 int is_help_arg(char *s)
{
if (!s) return(0);
return(same_arg(s, "/?") || same_arg(s, "-?") || same_arg(s, "?"));
}
static unsigned long node_to_number(uint8 *addr)
{
unsigned long n = 0;
int i;
for (i = 4; i < 10; i++)
n = (n << 8) + addr[i];
return(n);
}
static void print_net_node_status(uint8 *addr, int is_default)
{
fprintf(stdout, "[%08lX][%12lu]%s",
(unsigned long)GET_BE32(addr),
addr[4], addr[5], addr[6], addr[7], addr[8], addr[9]);
node_to_number(addr),
is_default ? "Default" : "");
}
int func_slist(int argc, char *argv[], int mode)
@@ -22,33 +54,50 @@ int func_slist(int argc, char *argv[], int mode)
uint8 pattern[50];
int found = 0;
int result;
int i;
(void)mode;
if (argc > 2) return(usage());
strcpy(pattern, "*");
for (i = 1; i < argc; i++) {
if (is_help_arg(argv[i])) return(usage());
if (argv[i][0] == '/' || argv[i][0] == '-') {
if (same_arg(argv[i], "/C") || same_arg(argv[i], "/CONTINUE") ||
same_arg(argv[i], "-C") || same_arg(argv[i], "-CONTINUE")) {
continue;
}
return(usage());
}
strmaxcpy(pattern, argv[i], sizeof(pattern) - 1);
}
if (argc == 2) strmaxcpy(pattern, argv[1], sizeof(pattern) - 1);
else strcpy(pattern, "*");
upstr(pattern);
fprintf(stdout, "\n%-52s%-10s%-12s\n",
"Known NetWare File Servers", "Network", "Node Address");
fprintf(stdout,
"-----------------------------------------------"
"---------------------------\n");
/*
* Novell-like layout from the DOS client:
* Known NetWare File Servers Network Node Address Status
* ------------------------- -------- -------------------
*/
fprintf(stdout, "%-44sNetwork Node Address Status\n",
"Known NetWare File Servers");
fprintf(stdout, "%-44s------- ----------- ------\n",
"--------------------------");
while ((result = ncp_17_37(last_id, NCP_BINDERY_FSERVER,
pattern, &obj)) == 0) {
NW_PROPERTY prop;
found = 1;
found++;
last_id = obj.object_id;
fprintf(stdout, "%-52s", obj.object_name);
fprintf(stdout, "%-44s", obj.object_name);
if (!ncp_17_3d(NCP_BINDERY_FSERVER, obj.object_name,
1, "NET_ADDRESS", &prop)) {
print_net_node(prop.value);
print_net_node_status(prop.value, found == 1);
}
fprintf(stdout, "\n");
@@ -56,8 +105,7 @@ int func_slist(int argc, char *argv[], int mode)
if (last_id == MAX_U32) break;
}
if (!found)
fprintf(stdout, "No servers found\n");
fprintf(stdout, "\nTotal of %d file servers found\n", found);
return(0);
}