Files
mars-nwe/tests/linux/afp_set_file_info_smoke.c
OpenAI 995a1e6cd7
All checks were successful
Source release / source-package (push) Successful in 49s
nwconn: add AFP FinderInfo set smoke path
Implement a deliberately narrow write-safe slice of the WebSDK/NWAFP Set File Information semantics for the NCP 0x2222/35/16 AFP 2.0 Set File Information call.

The only accepted request bitmap is the FinderInfo bit (0x0020). The handler uses the same path-backed raw VOL:-style compatibility subset as the existing AFP get, scan, open-fork, and temporary-directory-handle smoke endpoints, resolves the effective NetWare volume from the path prefix, rejects entry-id-only lookup until persistent CNID/base-ID mapping exists, and rejects directory or non-FinderInfo writes rather than pretending to implement DOS attribute, timestamp, delete-protect, resource-fork, or broader Mac namespace write semantics.

Store the 32-byte FinderInfo block in mars_nwe-owned metadata under the source-level xattr name org.mars-nwe.afp.finder-info and teach the existing AFP file-info response builder to read that value before falling back to Netatalk/libatalk AppleDouble FinderInfo. This makes the write immediately verifiable through AFP 2.0 Get File Information without changing data-fork or resource-fork contents.

Add a small local xattr abstraction for mars_nwe-private metadata names. Netatalk exposes names such as org.netatalk.Metadata at the libatalk layer, but prefixes them with user. on Linux inside its EA wrapper. Mirror that behavior for mars_nwe so source code and documentation use org.mars-nwe.* consistently while Linux stores user.org.mars-nwe.* where the kernel requires a namespace prefix. Convert the existing archive/fileinfo xattr calls to the same wrapper so the previous org.mars-nwe.* namespace rename remains functional on Linux.

Add tests/linux/afp_set_file_info_smoke, which sends AFP 0x10 with a FinderInfo bitmap, then verifies the result through AFP 0x0f Get File Information. Document the smoke command, expected output, server-log shape, and the remaining unsupported Set File Information write semantics.

Tests: git diff --check; gcc -Iinclude -I/mnt/data/stubs -fsyntax-only tests/linux/afp_set_file_info_smoke.c; cmake --build build-off --target nwconn with ENABLE_NETATALK_LIBATALK=OFF; cmake --build build-on --target nwconn with ENABLE_NETATALK_LIBATALK=ON against Netatalk-4.4.3 headers and local link stubs.
2026-05-30 11:29:33 +02:00

266 lines
8.0 KiB
C

/*
* Linux smoke test for NetWare AFP 2.0 Set File Information FinderInfo writes.
*/
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncp/nwcalls.h>
#include <ncp/ncplib.h>
#include <ncp/kernel/ncp.h>
#ifndef NCPC_SUBFUNCTION
#define NCPC_SUBFUNCTION 0x10000
#endif
#ifndef NCPC_SFN
#define NCPC_SFN(FN, SFN) ((FN) | ((SFN) << 8) | NCPC_SUBFUNCTION)
#endif
#define AFP20_GET_FILE_INFORMATION 0x0f
#define AFP20_SET_FILE_INFORMATION 0x10
#define AFP_FINDER_INFO_MASK 0x0020
#define AFP_REPLY_LEN 120
#define NWE_INVALID_NAMESPACE 0xbf
#define NWE_INVALID_PATH 0x9c
static void usage(const char *prog)
{
fprintf(stderr,
"Usage: %s [--allow-invalid-namespace] [--allow-invalid-path] "
"[--volume N] [--entry-id ID] [--type FOUR] [--creator FOUR] "
"[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 --type TEXT --creator MARS SYS:PUBLIC/pmdflts.ini\n"
" %s --allow-invalid-namespace -S MARS SYS:PUBLIC/pmdflts.ini\n",
prog, prog, prog);
}
static int parse_u32(const char *text, uint32_t *value)
{
char *end = NULL;
unsigned long v;
errno = 0;
v = strtoul(text, &end, 0);
if (errno || !end || *end || v > 0xffffffffUL)
return -1;
*value = (uint32_t)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) |
p[3];
}
static void cpu_to_be16(uint16_t v, uint8_t p[2])
{
p[0] = (uint8_t)(v >> 8);
p[1] = (uint8_t)v;
}
static void cpu_to_be32(uint32_t v, uint8_t p[4])
{
p[0] = (uint8_t)(v >> 24);
p[1] = (uint8_t)(v >> 16);
p[2] = (uint8_t)(v >> 8);
p[3] = (uint8_t)v;
}
static int copy_fourcc(const char *text, uint8_t out[4])
{
size_t len = strlen(text);
if (len != 4)
return -1;
memcpy(out, text, 4);
return 0;
}
static NWCCODE afp_get_file_info(NWCONN_HANDLE conn, const char *path,
uint32_t volume_number, uint32_t entry_id,
uint8_t reply_buf[AFP_REPLY_LEN])
{
NW_FRAGMENT reply;
uint8_t request[1 + 4 + 2 + 1 + 255];
size_t path_len = strlen(path);
memset(request, 0, sizeof(request));
request[0] = (uint8_t)volume_number;
cpu_to_be32(entry_id, request + 1);
cpu_to_be16(0xffff, request + 5);
request[7] = (uint8_t)path_len;
memcpy(request + 8, path, path_len);
memset(reply_buf, 0, AFP_REPLY_LEN);
reply.fragAddr.rw = reply_buf;
reply.fragSize = AFP_REPLY_LEN;
return NWRequestSimple(conn,
NCPC_SFN(0x23, AFP20_GET_FILE_INFORMATION),
request,
8 + path_len,
&reply);
}
int main(int argc, char **argv)
{
NWCONN_HANDLE conn;
long init_err = 0;
const char *path = NULL;
int allow_invalid_namespace = 0;
int allow_invalid_path = 0;
uint32_t volume_number = 0;
uint32_t entry_id = 0;
uint8_t finder_info[32];
uint8_t verify_buf[AFP_REPLY_LEN];
uint8_t request[1 + 4 + 2 + 1 + 255 + 1 + 32];
size_t path_len;
size_t afp_data_off;
size_t data_off;
int i;
NWCCODE err;
memset(finder_info, 0, sizeof(finder_info));
memcpy(finder_info + 0, "TEXT", 4);
memcpy(finder_info + 4, "MARS", 4);
if (NWCallsInit(NULL, NULL)) {
fprintf(stderr, "NWCallsInit failed\n");
return 2;
}
conn = ncp_initialize(&argc, argv, 1, &init_err);
if (!conn) {
fprintf(stderr, "ncp_initialize/login 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], "--allow-invalid-path")) {
allow_invalid_path = 1;
} else if (!strcmp(argv[i], "--volume")) {
if (++i >= argc || parse_u32(argv[i], &volume_number) || volume_number > 255) {
fprintf(stderr, "invalid --volume value\n");
ncp_close(conn);
return 2;
}
} else if (!strcmp(argv[i], "--entry-id")) {
if (++i >= argc || parse_u32(argv[i], &entry_id)) {
fprintf(stderr, "invalid --entry-id value\n");
ncp_close(conn);
return 2;
}
} else if (!strcmp(argv[i], "--type")) {
if (++i >= argc || copy_fourcc(argv[i], finder_info + 0)) {
fprintf(stderr, "invalid --type value, expected four characters\n");
ncp_close(conn);
return 2;
}
} else if (!strcmp(argv[i], "--creator")) {
if (++i >= argc || copy_fourcc(argv[i], finder_info + 4)) {
fprintf(stderr, "invalid --creator value, expected four characters\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 Set File Information: %zu\n", path_len);
ncp_close(conn);
return 2;
}
memset(request, 0, sizeof(request));
request[0] = (uint8_t)volume_number;
cpu_to_be32(entry_id, request + 1);
cpu_to_be16(AFP_FINDER_INFO_MASK, request + 5);
request[7] = (uint8_t)path_len;
memcpy(request + 8, path, path_len);
afp_data_off = 1 + 8 + path_len;
if (afp_data_off & 1)
afp_data_off++;
data_off = afp_data_off - 1;
memcpy(request + data_off, finder_info, sizeof(finder_info));
err = NWRequestSimple(conn,
NCPC_SFN(0x23, AFP20_SET_FILE_INFORMATION),
request,
data_off + sizeof(finder_info),
NULL);
if (err == NWE_INVALID_NAMESPACE && allow_invalid_namespace) {
printf("AFP Set File Information returned invalid namespace as expected for path=%s\n", path);
ncp_close(conn);
return 0;
}
if (err == NWE_INVALID_PATH && allow_invalid_path) {
printf("AFP Set File Information returned invalid path as expected for path=%s\n", path);
ncp_close(conn);
return 0;
}
if (err) {
fprintf(stderr,
"AFP Set File Information failed: completion=0x%02x (%u) path=%s\n",
(unsigned int)err & 0xff, (unsigned int)err, path);
ncp_close(conn);
return 1;
}
err = afp_get_file_info(conn, path, volume_number, entry_id, verify_buf);
if (err) {
fprintf(stderr,
"AFP Get File Information verify failed: completion=0x%02x (%u) path=%s\n",
(unsigned int)err & 0xff, (unsigned int)err, path);
ncp_close(conn);
return 1;
}
if (memcmp(verify_buf + 32, finder_info, sizeof(finder_info))) {
fprintf(stderr,
"AFP Set File Information verify mismatch: path=%s got_type=%.4s got_creator=%.4s\n",
path, verify_buf + 32, verify_buf + 36);
ncp_close(conn);
return 1;
}
printf("AFP Set File Info path=%s bitmap=0x%04x finder_type=%.4s finder_creator=%.4s entry_id=0x%08x verified\n",
path, AFP_FINDER_INFO_MASK, finder_info + 0, finder_info + 4,
be32_to_cpu(verify_buf + 0));
ncp_close(conn);
return 0;
}