#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
+#include <arpa/inet.h>
#include <atalk/adouble.h>
#include <atalk/ea.h>
#include <atalk/unix.h>
#include <atalk/compat.h>
-#ifndef ENOATTR
-#define ENOATTR ENODATA
-#endif
-
-
/**********************************************************************************
* EA VFS funcs for storing EAs in nativa filesystem EAs
**********************************************************************************/
LOG(log_debug7, logtype_afpd, "sys_getextattr_size(%s): attribute: \"%s\"", uname, attruname);
- if ((oflag & O_NOFOLLOW) ) {
- ret = sys_lgetxattr(uname, attruname, rbuf +4, 0);
- }
- else {
- ret = sys_getxattr(uname, attruname, rbuf +4, 0);
+ /* PBaranski fix */
+ if (fd != -1) {
+ LOG(log_debug, logtype_afpd, "sys_get_easize(%s): file is already opened", uname);
+ ret = sys_fgetxattr(fd, attruname, rbuf +4, 0);
+ } else {
+ if ((oflag & O_NOFOLLOW) ) {
+ ret = sys_lgetxattr(uname, attruname, rbuf +4, 0);
+ }
+ else {
+ ret = sys_getxattr(uname, attruname, rbuf +4, 0);
+ }
}
+ /* PBaranski fix */
+
if (ret == -1) {
memset(rbuf, 0, 4);
switch(errno) {
case OPEN_NOFOLLOW_ERRNO:
/* its a symlink and client requested O_NOFOLLOW */
- LOG(log_debug, logtype_afpd, "sys_getextattr_size(%s): encountered symlink with kXAttrNoFollow", uname);
- return AFP_OK;
+ LOG(log_debug, logtype_afpd, "sys_getextattr_size(%s): symlink with kXAttrNoFollow", uname);
+ return AFPERR_MISC;
case ENOATTR:
+ case ENOENT:
+ if (vol->v_obj->afp_version >= 34)
+ return AFPERR_NOITEM;
return AFPERR_MISC;
default:
- LOG(log_error, logtype_afpd, "sys_getextattr_size: error: %s", strerror(errno));
+ LOG(log_debug, logtype_afpd, "sys_getextattr_size: error: %s", strerror(errno));
return AFPERR_MISC;
}
}
* oflag (r) link and create flag
* attruname (r) name of attribute
* maxreply (r) maximum EA size as of current specs/real-life
- *
+ * fd (r) file descriptor
* Returns: AFP code: AFP_OK on success or appropiate AFP error code
*
* Effects:
LOG(log_debug7, logtype_afpd, "sys_getextattr_content(%s): attribute: \"%s\", size: %u", uname, attruname, maxreply);
- if ((oflag & O_NOFOLLOW) ) {
- ret = sys_lgetxattr(uname, attruname, rbuf +4, maxreply);
- }
- else {
- ret = sys_getxattr(uname, attruname, rbuf +4, maxreply);
+ /* PBaranski fix */
+ if (fd != -1) {
+ LOG(log_debug, logtype_afpd, "sys_get_eacontent(%s): file is already opened", uname);
+ ret = sys_fgetxattr(fd, attruname, rbuf +4, maxreply);
+ } else {
+ if ((oflag & O_NOFOLLOW) ) {
+ ret = sys_lgetxattr(uname, attruname, rbuf +4, maxreply);
+ }
+ else {
+ ret = sys_getxattr(uname, attruname, rbuf +4, maxreply);
+ }
}
-
+ /* PBaranski fix */
+
if (ret == -1) {
memset(rbuf, 0, 4);
*rbuflen += 4;
switch(errno) {
case OPEN_NOFOLLOW_ERRNO:
/* its a symlink and client requested O_NOFOLLOW */
- LOG(log_debug, logtype_afpd, "sys_getextattr_content(%s): encountered symlink with kXAttrNoFollow", uname);
- return AFP_OK;
+ LOG(log_debug, logtype_afpd, "sys_getextattr_content(%s): symlink with kXAttrNoFollow", uname);
+ return AFPERR_MISC;
case ENOATTR:
+ if (vol->v_obj->afp_version >= 34)
+ return AFPERR_NOITEM;
return AFPERR_MISC;
default:
- LOG(log_error, logtype_afpd, "sys_getextattr_content(%s): error: %s", attruname, strerror(errno));
+ LOG(log_debug, logtype_afpd, "sys_getextattr_content(%s): error: %s", attruname, strerror(errno));
return AFPERR_MISC;
}
}
*
* Copies names of all EAs of uname as consecutive C strings into rbuf.
* Increments *rbuflen accordingly.
+ * We hide the adouble:ea extended attributes here, but we currently
+ * allow reading, writing and deleteting them.
*/
int sys_list_eas(VFS_FUNC_ARGS_EA_LIST)
{
int ret, len, nlen;
char *buf;
char *ptr;
-
+ struct adouble ad, *adp;
+
buf = malloc(ATTRNAMEBUFSIZ);
if (!buf)
return AFPERR_MISC;
- if ((oflag & O_NOFOLLOW)) {
- ret = sys_llistxattr(uname, buf, ATTRNAMEBUFSIZ);
- }
- else {
- ret = sys_listxattr(uname, buf, ATTRNAMEBUFSIZ);
+ /* PBaranski fix */
+ if ( fd != -1) {
+ LOG(log_debug, logtype_afpd, "sys_list_eas(%s): file is already opened", uname);
+ ret = sys_flistxattr(fd, uname, buf, ATTRNAMEBUFSIZ);
+ } else {
+ if ((oflag & O_NOFOLLOW)) {
+ ret = sys_llistxattr(uname, buf, ATTRNAMEBUFSIZ);
+ }
+ else {
+ ret = sys_listxattr(uname, buf, ATTRNAMEBUFSIZ);
+ }
}
+ /* PBaranski fix */
if (ret == -1) switch(errno) {
case OPEN_NOFOLLOW_ERRNO:
- /* its a symlink and client requested O_NOFOLLOW */
- ret = AFPERR_BADTYPE;
- goto exit;
-#ifdef HAVE_ATTROPEN /* Solaris */
- case ENOATTR:
+ /* its a symlink and client requested O_NOFOLLOW, we pretend 0 EAs */
+ LOG(log_debug, logtype_afpd, "sys_list_extattr(%s): symlink with kXAttrNoFollow", uname);
ret = AFP_OK;
goto exit;
-#endif
default:
- LOG(log_error, logtype_afpd, "sys_list_extattr(%s): error opening atttribute dir: %s", uname, strerror(errno));
- ret= AFPERR_MISC;
+ LOG(log_debug, logtype_afpd, "sys_list_extattr(%s): error opening atttribute dir: %s", uname, strerror(errno));
+ ret = AFPERR_MISC;
goto exit;
}
ptr = buf;
while (ret > 0) {
len = strlen(ptr);
+ if (NOT_NETATALK_EA(ptr)) {
+ /* Convert name to CH_UTF8_MAC and directly store in in the reply buffer */
+ if ( 0 >= ( nlen = convert_string(vol->v_volcharset, CH_UTF8_MAC, ptr, len, attrnamebuf + attrbuflen, 256)) ) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
- /* Convert name to CH_UTF8_MAC and directly store in in the reply buffer */
- if ( 0 >= ( nlen = convert_string(vol->v_volcharset, CH_UTF8_MAC, ptr, len, attrnamebuf + attrbuflen, 256)) ) {
- ret = AFPERR_MISC;
- goto exit;
- }
-
- LOG(log_debug7, logtype_afpd, "sys_list_extattr(%s): attribute: %s", uname, ptr);
+ LOG(log_debug7, logtype_afpd, "sys_list_extattr(%s): attribute: %s", uname, ptr);
- attrbuflen += nlen + 1;
- if (attrbuflen > (ATTRNAMEBUFSIZ - 256)) {
- /* Next EA name could overflow, so bail out with error.
- FIXME: evantually malloc/memcpy/realloc whatever.
- Is it worth it ? */
- LOG(log_warning, logtype_afpd, "sys_list_extattr(%s): running out of buffer for EA names", uname);
- ret = AFPERR_MISC;
- goto exit;
+ attrbuflen += nlen + 1;
+ if (attrbuflen > (ATTRNAMEBUFSIZ - 256)) {
+ /* Next EA name could overflow, so bail out with error.
+ FIXME: evantually malloc/memcpy/realloc whatever.
+ Is it worth it ? */
+ LOG(log_warning, logtype_afpd, "sys_list_extattr(%s): running out of buffer for EA names", uname);
+ ret = AFPERR_MISC;
+ goto exit;
+ }
}
- ret -= len +1;
- ptr += len +1;
+ ret -= len + 1;
+ ptr += len + 1;
}
ret = AFP_OK;
else if ((oflag & O_TRUNC) )
attr_flag |= XATTR_REPLACE;
- if ((oflag & O_NOFOLLOW) ) {
- ret = sys_lsetxattr(uname, attruname, ibuf, attrsize,attr_flag);
- }
- else {
- ret = sys_setxattr(uname, attruname, ibuf, attrsize, attr_flag);
+ /* PBaranski fix */
+ if ( fd != -1) {
+ LOG(log_debug, logtype_afpd, "sys_set_ea(%s): file is already opened", uname);
+ ret = sys_fsetxattr(fd, attruname, ibuf, attrsize, attr_flag);
+ } else {
+ if ((oflag & O_NOFOLLOW) ) {
+ ret = sys_lsetxattr(uname, attruname, ibuf, attrsize,attr_flag);
+ }
+ else {
+ ret = sys_setxattr(uname, attruname, ibuf, attrsize, attr_flag);
+ }
}
+ /* PBaranski fix */
if (ret == -1) {
switch(errno) {
case OPEN_NOFOLLOW_ERRNO:
/* its a symlink and client requested O_NOFOLLOW */
- LOG(log_debug, logtype_afpd, "sys_set_ea(%s/%s): encountered symlink with kXAttrNoFollow",
+ LOG(log_debug, logtype_afpd, "sys_set_ea(\"%s\", ea:'%s'): symlink with kXAttrNoFollow",
uname, attruname);
return AFP_OK;
case EEXIST:
- LOG(log_debug, logtype_afpd, "sys_set_ea(%s/%s): EA already exists",
- uname, attruname);
+ LOG(log_debug, logtype_afpd, "sys_set_ea(\"%s/%s\", ea:'%s'): EA already exists",
+ getcwdpath(), uname, attruname);
return AFPERR_EXIST;
+ case ENOATTR:
+ case ENOENT:
+ if ((attr_flag & XATTR_REPLACE) && (vol->v_obj->afp_version >= 34))
+ return AFPERR_NOITEM;
+ return AFPERR_MISC;
default:
- LOG(log_error, logtype_afpd, "sys_set_ea(%s/%s): error: %s", uname, attruname, strerror(errno));
+ LOG(log_debug, logtype_afpd, "sys_set_ea(\"%s/%s\", ea:'%s', size: %u, flags: %s|%s|%s): %s",
+ getcwdpath(), uname, attruname, attrsize,
+ oflag & O_CREAT ? "XATTR_CREATE" : "-",
+ oflag & O_TRUNC ? "XATTR_REPLACE" : "-",
+ oflag & O_NOFOLLOW ? "O_NOFOLLOW" : "-",
+ strerror(errno));
return AFPERR_MISC;
}
}
* uname (r) filename
* attruname (r) EA name
* oflag (r) link and create flag
+ * fd (r) file descriptor
*
* Returns: AFP code: AFP_OK on success or appropiate AFP error code
*
{
int ret;
- if ((oflag & O_NOFOLLOW) ) {
- ret = sys_lremovexattr(uname, attruname);
- }
- else {
- ret = sys_removexattr(uname, attruname);
+ /* PBaranski fix */
+ if ( fd != -1) {
+ LOG(log_debug, logtype_afpd, "sys_remove_ea(%s): file is already opened", uname);
+ ret = sys_fremovexattr(fd, uname, attruname);
+ } else {
+ if ((oflag & O_NOFOLLOW) ) {
+ ret = sys_lremovexattr(uname, attruname);
+ }
+ else {
+ ret = sys_removexattr(uname, attruname);
+ }
}
+ /* PBaranski fix */
if (ret == -1) {
switch(errno) {
case OPEN_NOFOLLOW_ERRNO:
/* its a symlink and client requested O_NOFOLLOW */
- LOG(log_debug, logtype_afpd, "sys_remove_ea(%s/%s): encountered symlink with kXAttrNoFollow", uname);
+ LOG(log_debug, logtype_afpd, "sys_remove_ea(%s/%s): symlink with kXAttrNoFollow", uname);
return AFP_OK;
- case EACCES:
- LOG(log_debug, logtype_afpd, "sys_remove_ea(%s/%s): error: %s", uname, attruname, strerror(errno));
- return AFPERR_ACCESS;
default:
- LOG(log_error, logtype_afpd, "sys_remove_ea(%s/%s): error: %s", uname, attruname, strerror(errno));
+ LOG(log_debug, logtype_afpd, "sys_remove_ea(%s/%s): error: %s", uname, attruname, strerror(errno));
return AFPERR_MISC;
}
}
if (!*name)
continue;
+ if (STRCMP(name, ==, AD_EA_META))
+ continue;
+
if (sfd != -1) {
if (fchdir(sfd) == -1) {
LOG(log_error, logtype_afpd, "sys_ea_copyfile: cant chdir to sfd: %s",