nwatalk: use standalone mars_nwe AFP xattr backend
This commit is contained in:
@@ -77,10 +77,6 @@ add_executable(ftrustee ftrustee.c tools.c nwfname.c unxfile.c nwvolume.c nwattr
|
||||
|
||||
target_link_libraries(nwserv ${CRYPT_LIBRARIES} )
|
||||
target_link_libraries(nwconn ${CRYPT_LIBRARIES} ${XATTR_LIBRARIES} )
|
||||
IF(MARS_NWE_NETATALK_SUPPORT)
|
||||
target_include_directories(nwconn PRIVATE ${NETATALK_INCLUDE_DIRS})
|
||||
target_link_libraries(nwconn ${NETATALK_LIBRARIES})
|
||||
ENDIF(MARS_NWE_NETATALK_SUPPORT)
|
||||
target_link_libraries(ncpserv ${CRYPT_LIBRARIES} )
|
||||
target_link_libraries(nwclient ${CRYPT_LIBRARIES} )
|
||||
target_link_libraries(nwbind ${CRYPT_LIBRARIES} ${GDBM_LIBRARIES} )
|
||||
|
||||
119
src/nwatalk.c
119
src/nwatalk.c
@@ -1,4 +1,4 @@
|
||||
/* Optional Netatalk/libatalk AFP metadata backend helpers. */
|
||||
/* mars_nwe AFP xattr metadata backend helpers. */
|
||||
#include "net.h"
|
||||
#include "config.h"
|
||||
#include "nwatalk.h"
|
||||
@@ -11,11 +11,6 @@
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
#include <sys/stat.h>
|
||||
#include <atalk/adouble.h>
|
||||
#endif
|
||||
|
||||
#define MARS_NWE_AFP_ENTRY_ID_XATTR "org.mars-nwe.afp.entry-id"
|
||||
#define MARS_NWE_AFP_FINDER_INFO_XATTR "org.mars-nwe.afp.finder-info"
|
||||
#define MARS_NWE_AFP_ATTRIBUTES_XATTR "org.mars-nwe.afp.attributes"
|
||||
@@ -40,6 +35,14 @@ typedef struct {
|
||||
uint8 attributes[2];
|
||||
} MARS_NWE_AFP_ATTRIBUTES_XATTR_DATA;
|
||||
|
||||
int nwatalk_backend_available(void)
|
||||
{
|
||||
#if XATTR_SUPPORT
|
||||
return(1);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if XATTR_SUPPORT
|
||||
static int nwatalk_get_mars_entry_id_xattr(const char *path, uint32 *entry_id)
|
||||
@@ -73,46 +76,12 @@ static int nwatalk_get_mars_entry_id_xattr(const char *path, uint32 *entry_id)
|
||||
}
|
||||
#endif
|
||||
|
||||
int nwatalk_backend_available(void)
|
||||
{
|
||||
#if NETATALK_SUPPORT
|
||||
return(1);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
static int nwatalk_open_adouble(const char *path, struct adouble *ad)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!path || !*path) return(-0x9c); /* invalid path */
|
||||
|
||||
ad_init_old(ad, AD_VERSION, 0);
|
||||
|
||||
result = ad_open(ad, path,
|
||||
ADFLAGS_HF | ADFLAGS_RF | ADFLAGS_RDONLY |
|
||||
ADFLAGS_NOHF | ADFLAGS_NORF);
|
||||
if (result < 0) {
|
||||
return(-0x9c);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int nwatalk_get_finder_info(const char *path, uint8 *finder_info,
|
||||
int finder_info_len)
|
||||
{
|
||||
#if XATTR_SUPPORT
|
||||
ssize_t len;
|
||||
#endif
|
||||
#if NETATALK_SUPPORT
|
||||
struct adouble ad;
|
||||
void *entry;
|
||||
int result;
|
||||
#endif
|
||||
|
||||
if (!finder_info || finder_info_len < NWATALK_FINDER_INFO_LEN) {
|
||||
return(-0x9c);
|
||||
@@ -128,23 +97,12 @@ int nwatalk_get_finder_info(const char *path, uint8 *finder_info,
|
||||
return(0);
|
||||
memset(finder_info, 0, finder_info_len);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
result = nwatalk_open_adouble(path, &ad);
|
||||
if (result < 0) return(result);
|
||||
|
||||
entry = ad_entry(&ad, ADEID_FINDERI);
|
||||
if (entry && ad_getentrylen(&ad, ADEID_FINDERI) >= NWATALK_FINDER_INFO_LEN) {
|
||||
memcpy(finder_info, entry, NWATALK_FINDER_INFO_LEN);
|
||||
}
|
||||
|
||||
ad_close(&ad, 0);
|
||||
return(0);
|
||||
#else
|
||||
(void)path;
|
||||
return(-0xbf); /* invalid namespace / backend unavailable */
|
||||
#endif
|
||||
|
||||
/* Missing FinderInfo is a valid AFP state; absent metadata reads as zeroes. */
|
||||
return(0);
|
||||
}
|
||||
|
||||
int nwatalk_set_finder_info(const char *path, const uint8 *finder_info,
|
||||
@@ -170,8 +128,6 @@ int nwatalk_set_finder_info(const char *path, const uint8 *finder_info,
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int nwatalk_get_afp_attributes(const char *path, uint16 *attributes)
|
||||
{
|
||||
#if XATTR_SUPPORT
|
||||
@@ -269,64 +225,17 @@ int nwatalk_set_entry_id(const char *path, uint32 entry_id)
|
||||
|
||||
int nwatalk_get_resource_fork_size(const char *path, uint32 *resource_size)
|
||||
{
|
||||
#if NETATALK_SUPPORT
|
||||
struct adouble ad;
|
||||
off_t size;
|
||||
int result;
|
||||
|
||||
(void)path;
|
||||
if (!resource_size) return(-0x9c);
|
||||
*resource_size = 0;
|
||||
|
||||
result = nwatalk_open_adouble(path, &ad);
|
||||
if (result < 0) return(result);
|
||||
|
||||
size = ad_size(&ad, ADEID_RFORK);
|
||||
if (size > 0) {
|
||||
if (size > 0xffffffffUL) size = 0xffffffffUL;
|
||||
*resource_size = (uint32)size;
|
||||
}
|
||||
|
||||
ad_close(&ad, 0);
|
||||
return(0);
|
||||
#else
|
||||
(void)path;
|
||||
(void)resource_size;
|
||||
return(-0xbf); /* invalid namespace / backend unavailable */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int nwatalk_get_entry_id(const char *path, uint32 *entry_id)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!entry_id) return(-0x9c);
|
||||
*entry_id = 0;
|
||||
if (!path || !*path) return(-0x9c);
|
||||
|
||||
result = nwatalk_get_mars_entry_id_xattr(path, entry_id);
|
||||
if (!result && *entry_id)
|
||||
return(0);
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
{
|
||||
struct adouble ad;
|
||||
struct stat stbuff;
|
||||
uint32_t id;
|
||||
|
||||
if (stat(path, &stbuff)) return(-0x9c);
|
||||
|
||||
result = nwatalk_open_adouble(path, &ad);
|
||||
if (result < 0) return(result);
|
||||
|
||||
id = ad_getid(&ad, stbuff.st_dev, stbuff.st_ino, 0, NULL);
|
||||
if (id) *entry_id = (uint32)id;
|
||||
|
||||
ad_close(&ad, 0);
|
||||
return(id ? 0 : -0x9c);
|
||||
}
|
||||
#else
|
||||
(void)result;
|
||||
return(-0xbf); /* invalid namespace / backend unavailable */
|
||||
#endif
|
||||
return(nwatalk_get_mars_entry_id_xattr(path, entry_id));
|
||||
}
|
||||
|
||||
34
src/nwconn.c
34
src/nwconn.c
@@ -578,7 +578,7 @@ static uint32 afp_namespace_entry_id(int volume, const struct stat *stb)
|
||||
static uint32 afp_fallback_entry_id(int volume, const struct stat *stb)
|
||||
/*
|
||||
* Build a stable local AFP entry id from Unix identity data when the NetWare
|
||||
* namespace handle cannot represent the object and libatalk has no stored
|
||||
* namespace handle cannot represent the object and mars_nwe AFP xattr has no stored
|
||||
* CNID/AppleDouble id yet. This is only a legacy compatibility fallback.
|
||||
*/
|
||||
{
|
||||
@@ -609,7 +609,7 @@ static uint32 afp_get_or_create_entry_id(const char *unixname, int volume,
|
||||
int *fallback_out)
|
||||
/*
|
||||
* Return the mars_nwe namespace basehandle as AFP entry id whenever it can be
|
||||
* represented. nwatalk/libatalk metadata remains a cache/legacy fallback for
|
||||
* represented. mars_nwe AFP xattr metadata remains a cache/legacy fallback for
|
||||
* entries that cannot be mapped by the NetWare namespace table.
|
||||
*/
|
||||
{
|
||||
@@ -663,7 +663,7 @@ static int afp_get_entry_id_from_name(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "AFP Get Entry ID From Name rejected: libatalk backend unavailable"));
|
||||
XDPRINTF((3,0, "AFP Get Entry ID From Name rejected: AFP xattr metadata backend unavailable"));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -725,7 +725,7 @@ static int afp_get_entry_id_from_netware_handle(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "AFP Get Entry ID From NetWare Handle rejected: libatalk backend unavailable"));
|
||||
XDPRINTF((3,0, "AFP Get Entry ID From NetWare Handle rejected: AFP xattr metadata backend unavailable"));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -790,7 +790,7 @@ static int afp_open_file_fork(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "AFP Open File Fork rejected: libatalk backend unavailable"));
|
||||
XDPRINTF((3,0, "AFP Open File Fork rejected: AFP xattr metadata backend unavailable"));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -938,7 +938,7 @@ static int afp_alloc_temporary_dir_handle(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "AFP Alloc Temporary Dir Handle rejected: libatalk backend unavailable"));
|
||||
XDPRINTF((3,0, "AFP Alloc Temporary Dir Handle rejected: AFP xattr metadata backend unavailable"));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -1030,7 +1030,7 @@ static int afp_create_file(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "%s rejected: libatalk backend unavailable", call_name));
|
||||
XDPRINTF((3,0, "%s rejected: AFP xattr metadata backend unavailable", call_name));
|
||||
return(-0xbf);
|
||||
}
|
||||
if (!path_len) {
|
||||
@@ -1152,7 +1152,7 @@ static int afp_create_directory(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "%s rejected: libatalk backend unavailable", call_name));
|
||||
XDPRINTF((3,0, "%s rejected: AFP xattr metadata backend unavailable", call_name));
|
||||
return(-0xbf);
|
||||
}
|
||||
if (!path_len) {
|
||||
@@ -1422,7 +1422,7 @@ static int afp_get_entry_id_from_path_name(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "AFP Get Entry ID From Path Name rejected: libatalk backend unavailable"));
|
||||
XDPRINTF((3,0, "AFP Get Entry ID From Path Name rejected: AFP xattr metadata backend unavailable"));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -1478,7 +1478,7 @@ static int afp_dos_path_join(int volume, char *dst, int dst_len,
|
||||
*
|
||||
* AFP 0x12 returns a DOSPathString, not the real Unix directory entry name.
|
||||
* The reverse lookup still walks the Unix volume tree because current AFP entry
|
||||
* IDs are mars_nwe/libatalk metadata IDs, but the path returned to the client
|
||||
* IDs are mars_nwe AFP xattr metadata IDs, but the path returned to the client
|
||||
* must be the DOS namespace alias that mars_nwe already uses elsewhere.
|
||||
*/
|
||||
{
|
||||
@@ -1504,7 +1504,7 @@ static int afp_find_dos_name_from_entry_id_rec(int volume,
|
||||
*
|
||||
* NetWare's documented AFP 0x12 call is an entry-id-only lookup. mars_nwe's
|
||||
* current AFP ids are not the namespace base handles used by namspace.c; they
|
||||
* are mars_nwe/libatalk AFP metadata ids. Reuse the existing volume table for
|
||||
* are mars_nwe AFP xattr metadata ids. Reuse the existing volume table for
|
||||
* the search root and the nwatalk entry-id helper for the per-entry identity,
|
||||
* but do not create fallback ids while scanning. The first conservative smoke
|
||||
* target is therefore an entry that was already cached by Get Entry ID/Get File
|
||||
@@ -1644,7 +1644,7 @@ static int afp_get_dos_name_from_entry_id(uint8 *afp_req, int afp_len,
|
||||
entry_id = GET_BE32(afp_req + 2);
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "AFP Get DOS Name From Entry ID rejected: libatalk backend unavailable"));
|
||||
XDPRINTF((3,0, "AFP Get DOS Name From Entry ID rejected: AFP xattr metadata backend unavailable"));
|
||||
return(-0xbf); /* Invalid Namespace */
|
||||
}
|
||||
|
||||
@@ -1944,7 +1944,7 @@ static int afp_get_file_information(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "%s rejected: libatalk backend unavailable", call_name));
|
||||
XDPRINTF((3,0, "%s rejected: AFP xattr metadata backend unavailable", call_name));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -2123,7 +2123,7 @@ static int afp_set_file_information(uint8 *afp_req, int afp_len,
|
||||
path_data = afp_req + path_off;
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "%s rejected: libatalk backend unavailable", call_name));
|
||||
XDPRINTF((3,0, "%s rejected: AFP xattr metadata backend unavailable", call_name));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -2337,7 +2337,7 @@ static int afp_scan_file_information(uint8 *afp_req, int afp_len,
|
||||
}
|
||||
|
||||
if (!nwatalk_backend_available()) {
|
||||
XDPRINTF((3,0, "%s rejected: libatalk backend unavailable", call_name));
|
||||
XDPRINTF((3,0, "%s rejected: AFP xattr metadata backend unavailable", call_name));
|
||||
return(-0xbf); /* invalid namespace */
|
||||
}
|
||||
|
||||
@@ -4397,7 +4397,7 @@ static int handle_ncp_serv(void)
|
||||
* path-backed subset, so route it through the same helper
|
||||
* until persistent entry-id lookup and richer AFP 2.0
|
||||
* metadata are implemented. These calls still require
|
||||
* the optional libatalk backend to be present; without a Mac
|
||||
* the optional AFP xattr metadata backend to be present; without a Mac
|
||||
* namespace backend, keep returning invalid namespace.
|
||||
*/
|
||||
if (ufunc == 0x01 || ufunc == 0x0d) {
|
||||
@@ -4470,7 +4470,7 @@ static int handle_ncp_serv(void)
|
||||
if (result > -1) data_len = result;
|
||||
else completition = (uint8)-result;
|
||||
} else {
|
||||
XDPRINTF((3,0, "AFP call rejected: ufunc=0x%02x (%s), Mac namespace unavailable, libatalk backend=%s",
|
||||
XDPRINTF((3,0, "AFP call rejected: ufunc=0x%02x (%s), Mac namespace unavailable, AFP xattr metadata backend=%s",
|
||||
ufunc, afp_call_name(ufunc),
|
||||
nwatalk_backend_available() ? "enabled" : "disabled"));
|
||||
completition=0xbf; /* we say invalid namespace here */
|
||||
|
||||
Reference in New Issue
Block a user