All checks were successful
Source release / source-package (push) Successful in 46s
Add an optional Linux-side smoke test for the first implemented NetWare AFP endpoint. The WebSDK documents NCP 0x2222/35/12 AFP Get Entry ID From Path Name as taking a NetWare directory handle and path string and returning a 32-bit AFP entry id. MARS-NWE now has a guarded implementation of that probe when the optional Netatalk/libatalk backend is compiled in, but exercising it does not require a real AppleTalk workstation. Use the ncpfs/libncp client library as the test transport. ncpfs is commonly available on Linux mars_nwe test hosts and its NWRequestSimple() helper builds the same length-prefixed subfunction request format used by normal libncp callers. The test accepts standard ncpfs connection options such as -S, -U, -P, and -n, sends NCP 0x23/0x0c, and prints the returned entry id. Keep the test out of normal builds behind MARS_NWE_BUILD_LINUX_TESTS because it depends on host ncpfs development headers/library and on a running server. Add an --allow-invalid-namespace mode so builds without the Netatalk backend can still run a negative smoke test and verify that AFP remains unavailable. This adds test infrastructure only and does not change server protocol behavior.
171 lines
4.5 KiB
C
171 lines
4.5 KiB
C
/*
|
|
* Linux smoke test for NetWare AFP Entry ID path lookup.
|
|
*
|
|
* This intentionally uses ncpfs/libncp instead of a private socket path so the
|
|
* request is sent through the same client stack that is commonly available on
|
|
* Linux mars_nwe test hosts.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <ncp/nwcalls.h>
|
|
#include <ncp/ncplib.h>
|
|
|
|
#ifndef NCPC_SUBFUNCTION
|
|
#define NCPC_SUBFUNCTION 0x10000
|
|
#endif
|
|
#ifndef NCPC_SFN
|
|
#define NCPC_SFN(FN, SFN) ((FN) | ((SFN) << 8) | NCPC_SUBFUNCTION)
|
|
#endif
|
|
|
|
#define AFP_GET_ENTRY_ID_FROM_PATH_NAME 0x0c
|
|
#define NWE_INVALID_NAMESPACE 0xbf
|
|
|
|
static void usage(const char *prog)
|
|
{
|
|
fprintf(stderr,
|
|
"Usage: %s [--allow-invalid-namespace] [--dir-handle N] "
|
|
"[ncpfs options] PATH\n"
|
|
"\n"
|
|
"ncpfs options are parsed by ncp_initialize(), for example:\n"
|
|
" -S SERVER -U USER -P PASSWORD -n\n"
|
|
"\n"
|
|
"Examples:\n"
|
|
" %s -S MARS -U SUPERVISOR -P secret SYS:LOGIN\n"
|
|
" %s --allow-invalid-namespace -S MARS SYS:LOGIN\n",
|
|
prog, prog, prog);
|
|
}
|
|
|
|
static int parse_u8(const char *text, unsigned int *value)
|
|
{
|
|
char *end = NULL;
|
|
unsigned long v;
|
|
|
|
errno = 0;
|
|
v = strtoul(text, &end, 0);
|
|
if (errno || !end || *end || v > 255)
|
|
return -1;
|
|
*value = (unsigned int)v;
|
|
return 0;
|
|
}
|
|
|
|
static uint32_t be32_to_cpu(const uint8_t p[4])
|
|
{
|
|
return ((uint32_t)p[0] << 24) |
|
|
((uint32_t)p[1] << 16) |
|
|
((uint32_t)p[2] << 8) |
|
|
((uint32_t)p[3]);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
NWCONN_HANDLE conn;
|
|
NW_FRAGMENT reply;
|
|
long init_err = 0;
|
|
const char *path = NULL;
|
|
unsigned int dir_handle = 0;
|
|
int allow_invalid_namespace = 0;
|
|
int i;
|
|
size_t path_len;
|
|
uint8_t request[1 + 1 + 255];
|
|
uint8_t reply_buf[4];
|
|
NWCCODE err;
|
|
|
|
if (NWCallsInit(NULL, NULL)) {
|
|
fprintf(stderr, "NWCallsInit failed\n");
|
|
return 2;
|
|
}
|
|
|
|
conn = ncp_initialize(&argc, argv, 0, &init_err);
|
|
if (!conn) {
|
|
fprintf(stderr, "ncp_initialize failed: %ld\n", init_err);
|
|
usage(argv[0]);
|
|
return 2;
|
|
}
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
if (!strcmp(argv[i], "--allow-invalid-namespace")) {
|
|
allow_invalid_namespace = 1;
|
|
} else if (!strcmp(argv[i], "--dir-handle")) {
|
|
if (++i >= argc || parse_u8(argv[i], &dir_handle)) {
|
|
fprintf(stderr, "invalid --dir-handle value\n");
|
|
ncp_close(conn);
|
|
return 2;
|
|
}
|
|
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
|
|
usage(argv[0]);
|
|
ncp_close(conn);
|
|
return 0;
|
|
} else if (!path) {
|
|
path = argv[i];
|
|
} else {
|
|
fprintf(stderr, "unexpected argument: %s\n", argv[i]);
|
|
usage(argv[0]);
|
|
ncp_close(conn);
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
if (!path) {
|
|
fprintf(stderr, "missing PATH\n");
|
|
usage(argv[0]);
|
|
ncp_close(conn);
|
|
return 2;
|
|
}
|
|
|
|
path_len = strlen(path);
|
|
if (path_len > 255) {
|
|
fprintf(stderr, "PATH is too long for AFP Get Entry ID From Path Name: %zu\n",
|
|
path_len);
|
|
ncp_close(conn);
|
|
return 2;
|
|
}
|
|
|
|
request[0] = (uint8_t)dir_handle;
|
|
request[1] = (uint8_t)path_len;
|
|
memcpy(request + 2, path, path_len);
|
|
|
|
memset(reply_buf, 0, sizeof(reply_buf));
|
|
reply.fragAddr.rw = reply_buf;
|
|
reply.fragSize = sizeof(reply_buf);
|
|
|
|
err = NWRequestSimple(conn,
|
|
NCPC_SFN(0x23, AFP_GET_ENTRY_ID_FROM_PATH_NAME),
|
|
request,
|
|
2 + path_len,
|
|
&reply);
|
|
|
|
if (err == NWE_INVALID_NAMESPACE && allow_invalid_namespace) {
|
|
printf("AFP Get Entry ID From Path Name returned invalid namespace "
|
|
"as expected: path=%s\n", path);
|
|
ncp_close(conn);
|
|
return 0;
|
|
}
|
|
|
|
if (err) {
|
|
fprintf(stderr,
|
|
"AFP Get Entry ID From Path Name failed: completion=0x%02x (%u) path=%s\n",
|
|
(unsigned int)err & 0xff, (unsigned int)err, path);
|
|
ncp_close(conn);
|
|
return 1;
|
|
}
|
|
|
|
if (reply.fragSize < 4) {
|
|
fprintf(stderr, "short AFP reply: %zu bytes\n", reply.fragSize);
|
|
ncp_close(conn);
|
|
return 1;
|
|
}
|
|
|
|
printf("AFP Entry ID path=%s dir_handle=%u entry_id=0x%08x (%u)\n",
|
|
path, dir_handle,
|
|
(unsigned int)be32_to_cpu(reply_buf),
|
|
(unsigned int)be32_to_cpu(reply_buf));
|
|
|
|
ncp_close(conn);
|
|
return 0;
|
|
}
|