From b40ec03e7de3cadb84b2dc1fc36869e115e703f7 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Fri, 22 May 2026 13:40:30 +0200 Subject: [PATCH] map via redir --- map.c | 49 ++++++++++++++++++++++++++++++++++--------------- netcall.c | 34 +++++----------------------------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/map.c b/map.c index e12a539..5726c58 100644 --- a/map.c +++ b/map.c @@ -80,19 +80,41 @@ static void do_map(int drive, NWPATH *nwp) static int do_map(int drive, NWPATH *nwp, int delete) { int result = -1; + if (drive > -1 && drive < 32) { - uint8 connid; - uint8 dhandle; - uint8 flags; - if (!delete || - (!get_drive_info(drive, &connid, &dhandle, &flags) && flags && connid)){ - uint8 nmdrive[3]; - nmdrive[0] = drive+'A'; - nmdrive[1] = ':'; - nmdrive[2] = '\0'; - result = redir_device_drive(delete ? -1 : 0x4, nmdrive, nwp->path); + uint8 connid = 0; + uint8 dhandle = 0; + uint8 flags = 0; + + if (delete) { + if (!get_drive_info(drive, &connid, &dhandle, &flags) + && flags && !(flags & 0x80) && connid) { + result = dealloc_dir_handle(dhandle); + } + } else { + /* + * The old mars-dosutils MAP used DOS redirector INT 21h AX=5F03h. + * NetWare Client32 returns AX=0001 for that call, while Novell MAP + * works. Use the NetWare shell/NCP "Allocate Permanent Directory + * Handle" path instead; this is what the surrounding code already + * provides via alloc_permanent_dir_handle(). + */ + if (!get_drive_info(drive, &connid, &dhandle, &flags) + && flags && !(flags & 0x80) && connid) { + (void)dealloc_dir_handle(dhandle); + } + + result = alloc_permanent_dir_handle(0, nwp->path, drive + 'A', NULL); + + /* + * Some requesters historically accepted lowercase drive letters in + * this call. Keep this only as compatibility fallback. + */ + if (result < 0) + result = alloc_permanent_dir_handle(0, nwp->path, drive + 'a', NULL); } } + return(result); } @@ -173,11 +195,8 @@ int func_map(int argc, char *argv[], int mode) if (!ipx_init()) argc = 1; if (!parse_argv(drvstr, &nwpath, argc, argv, 0, mode)) { if (*(nwpath.path) || mode==1) { - { - int rc = do_map(*drvstr - 'A', &nwpath, mode); - if (rc < 0) - fprintf(stderr, "MAP Error rc=%d\n", rc); - } + if (do_map(*drvstr - 'A', &nwpath, mode)< 0) + fprintf(stderr, "MAP Error\n"); } if (mode != 1) show_map(drvstr); diff --git a/netcall.c b/netcall.c index 69b1e7d..70667d2 100644 --- a/netcall.c +++ b/netcall.c @@ -54,47 +54,24 @@ int redir_device_drive(int devicetyp, uint8 *devname, uint8 *remotename) { REGS regs; SREGS sregs; + int result; uint8 buff1[16]; uint8 buff2[128]; uint8 *ldevname = buff1; uint8 *lremotename = buff2; - - memset(®s, 0, sizeof(regs)); - memset(&sregs, 0, sizeof(sregs)); - memset(buff1, 0, sizeof(buff1)); - memset(buff2, 0, sizeof(buff2)); - - strmaxcpy(ldevname, devname, sizeof(buff1) - 1); - + strncpy(ldevname, devname, 16); regs.x.ax = (devicetyp == -1) ? 0x5f04 : 0x5f03; regs.h.bl = (uint8)devicetyp; regs.x.cx = 0x574e; /* user sign 'NW' */ sregs.ds = FP_SEG(ldevname); regs.x.si = FP_OFF(ldevname); - if (devicetyp > -1) { - strmaxcpy(lremotename, remotename, sizeof(buff2) - 1); + strncpy(lremotename, remotename, 128); sregs.es = FP_SEG(lremotename); regs.x.di = FP_OFF(lremotename); } - -#if defined(__WATCOMC__) - fprintf(stderr, - "REDIR in: ax=%04x bx=%04x cx=%04x ds:si=%04x:%04x es:di=%04x:%04x dev='%s' remote='%s'\n", - regs.x.ax, regs.x.bx, regs.x.cx, - sregs.ds, regs.x.si, sregs.es, regs.x.di, - ldevname, devicetyp > -1 ? lremotename : ""); -#endif - - intdosx(®s, ®s, &sregs); - -#if defined(__WATCOMC__) - fprintf(stderr, - "REDIR out: cf=%u ax=%04x bx=%04x cx=%04x dx=%04x\n", - regs.x.cflag, regs.x.ax, regs.x.bx, regs.x.cx, regs.x.dx); -#endif - - return(regs.x.cflag ? -(int)regs.x.ax : 0); + result = intdosx(®s, ®s, &sregs); + return(regs.x.cflag ? -result : 0); } int list_redir(int index, int *devicetyp, uint8 *devname, uint8 *remotename) @@ -264,7 +241,6 @@ int alloc_dir_handle(int func, printf("alloc_dir_handle, path=%s, len=%d, disk=%c\n", path, pathlen, driveletter); */ neterrno = Net_Call(0xE200, &req, &repl); - fprintf(stderr, "neterrno=%d\n", neterrno); if (neterrno && neterrno != 0xff) return(-1); if (effrights) *effrights = repl.effrights;