ssize_t sys_listxattr (const char *path, char *list, size_t size) { #if defined(HAVE_LISTXATTR) ssize_t ret; #ifndef XATTR_ADD_OPT ret = listxattr(path, list, size); #else int options = 0; ret = listxattr(path, list, size, options); #endif return remove_user(ret, list, size); #elif defined(HAVE_LISTEA) return listea(path, list, size); #elif defined(HAVE_EXTATTR_LIST_FILE) extattr_arg arg; arg.path = path; return bsd_attr_list(0, arg, list, size); #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H) return irix_attr_list(path, 0, list, size, 0); #elif defined(HAVE_ATTROPEN) ssize_t ret = -1; int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0); if (attrdirfd >= 0) { ret = solaris_list_xattr(attrdirfd, list, size); close(attrdirfd); } return ret; #else errno = ENOSYS; return -1; #endif }
static int has_xattr(const char *filename, const char *xattrname) { char *nl, *nlp; ssize_t r; int exisiting; r = listxattr(filename, NULL, 0, XATTR_SHOWCOMPRESSION); if (r < 0) return (0); if (r == 0) return (0); nl = malloc(r); if (!assert(nl != NULL)) return (0); r = listxattr(filename, nl, r, XATTR_SHOWCOMPRESSION); if (r < 0) { free(nl); return (0); } exisiting = 0; for (nlp = nl; nlp < nl + r; nlp += strlen(nlp) + 1) { if (strcmp(nlp, xattrname) == 0) { exisiting = 1; break; } } free(nl); return (exisiting); }
ssize_t rep_listxattr (const char *path, char *list, size_t size) { #if defined(HAVE_LISTXATTR) #ifndef XATTR_ADDITIONAL_OPTIONS return listxattr(path, list, size); #else /* So that we do not recursivly call this function */ #undef listxattr int options = 0; return listxattr(path, list, size, options); #endif #elif defined(HAVE_LISTEA) return listea(path, list, size); #elif defined(HAVE_EXTATTR_LIST_FILE) extattr_arg arg; arg.path = path; return bsd_attr_list(0, arg, list, size); #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H) return irix_attr_list(path, 0, list, size, 0); #elif defined(HAVE_ATTROPEN) ssize_t ret = -1; int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0); if (attrdirfd >= 0) { ret = solaris_list_xattr(attrdirfd, list, size); close(attrdirfd); } return ret; #else errno = ENOSYS; return -1; #endif }
static INT64_T chirp_fs_local_listxattr(const char *path, char *list, size_t size) { #ifdef CCTOOLS_OPSYS_DARWIN return listxattr(path, list, size, 0); #else return listxattr(path, list, size); #endif }
static ssize_t _listxattr(const char* path, char* namebuf, size_t size) { #if defined(__LWI_DARWIN__) return listxattr(path, namebuf, size, XATTR_NOFOLLOW); #else return listxattr(path, namebuf, size); #endif }
static int setup_xattrs(struct archive_read_disk *a, struct archive_entry *entry, int fd) { char *list, *p; const char *path; ssize_t list_size; path = archive_entry_sourcepath(entry); if (path == NULL) path = archive_entry_pathname(entry); if (!a->follow_symlinks) list_size = llistxattr(path, NULL, 0); else list_size = listxattr(path, NULL, 0); if (list_size == -1) { if (errno == ENOTSUP) return (ARCHIVE_OK); archive_set_error(&a->archive, errno, "Couldn't list extended attributes"); return (ARCHIVE_WARN); } if (list_size == 0) return (ARCHIVE_OK); if ((list = malloc(list_size)) == NULL) { archive_set_error(&a->archive, errno, "Out of memory"); return (ARCHIVE_FATAL); } if (!a->follow_symlinks) list_size = llistxattr(path, list, list_size); else list_size = listxattr(path, list, list_size); if (list_size == -1) { archive_set_error(&a->archive, errno, "Couldn't retrieve extended attributes"); free(list); return (ARCHIVE_WARN); } for (p = list; (p - list) < list_size; p += strlen(p) + 1) { if (strncmp(p, "system.", 7) == 0 || strncmp(p, "xfsroot.", 8) == 0) continue; setup_xattr(a, entry, p, fd); } free(list); return (ARCHIVE_OK); }
static INT64_T chirp_fs_local_listxattr(const char *path, char *list, size_t size) { PREAMBLE("listxattr(`%s', %p, %zu)", path, list, size); RESOLVE(path) #ifdef CCTOOLS_OPSYS_DARWIN rc = listxattr(path, list, size, 0); #else rc = listxattr(path, list, size); #endif PROLOGUE }
static ssize_t xlistxattr(const char *path, char *list, size_t size, int symlink) { #ifdef XATTR_EXTRA_ARGS return listxattr(path, list, size, symlink ? XATTR_NOFOLLOW : 0); #else switch (symlink) { case 0: return listxattr(path, list, size); default: return llistxattr(path, list, size); } #endif }
static gboolean _load_from_xattr(struct attr_handle_s *attr_handle, GError ** error){ char *last_name, *buf; register ssize_t i; ssize_t bufSize, bufMax; GError *local_error = NULL; if (attr_handle->attr_hash == NULL) { SETERRCODE(error, EINVAL, "Invalid parameter : attr_hash is null"); return FALSE; } bufMax = listxattr(attr_handle->chunk_path, NULL, 0); if (0 > bufMax) { SETERRCODE(error, errno, "Failed to list XAttr : %s", strerror(errno)); return FALSE; } if (0 == bufMax) { /* According to the man page, listxattr should return -1 if xattr * is not supported by the underlying fs. It looks that in reality, * it just returns a size of 0, so we'll consider this as an error. */ SETERRCODE(error, ENOTSUP, "Failed to list xattr from chunk [%s] : size of list of attr names is 0", attr_handle->chunk_path); return FALSE; } buf = g_malloc0(bufMax); bufSize = listxattr(attr_handle->chunk_path, buf, bufMax); for (last_name = buf, i = 0; i < bufSize; i++) { if (buf[i] == '\0') { char *value = NULL; if (_getxattr_from_chunk(attr_handle, &local_error, last_name, &value)) g_hash_table_insert(attr_handle->attr_hash, g_strdup(last_name), value); else { SETERRCODE(error, local_error->code, "Cannot get xattr %s from %s : %s", last_name, attr_handle->chunk_path, local_error->message); g_clear_error(&local_error); g_free(buf); return FALSE; } last_name = buf + i + 1; } } g_free(buf); return TRUE; }
ssize_t ceph_os_listxattr(const char *path, char *list, size_t size) { ssize_t error = -1; #if defined(__FreeBSD__) /* * XXX. The format of the list FreeBSD returns differs * from the Linux ones. We have to perform the conversion. :-( */ char *newlist, *p, *p1; if (size != 0) { newlist = malloc(size); if (newlist != NULL) { error = extattr_list_file(path, EXTATTR_NAMESPACE_USER, newlist, size); if (error > 0) { p = newlist; p1 = list; while ((p - newlist) < error) { uint8_t len = *(uint8_t *)p; p++; if ((p + len - newlist) > error) break; if (len > 0) { bcopy(p, p1, len); p += len; p1 += len; *p1++ = '\0'; } } error = p1 - list; } free(newlist); } } else { error = extattr_list_file(path, EXTATTR_NAMESPACE_USER, list, size); } #elif defined(__linux__) error = listxattr(path, list, size); #elif defined(DARWIN) error = listxattr(path, list, size, 0); #endif return (error); }
int main (int argc, char *argv[]) { int ret = -1; char *value = NULL; char *value_p = NULL; char *file_path = NULL; if(argc > 1) file_path = argv[1]; else file_path = FILE_PATH; value = malloc(BUF_SIZE); memset(value, '\0', 500); ret = listxattr(file_path, value, 500); POSITIVE_OR_RETURN(ret, "can not get xattr"); value_p = value; printf("xattr total length:%d\n", ret); while (ret>0) { printf("ret=%d,value_p=%s\n", ret, value_p); ret -= strlen(value_p) + 1; value_p += strlen(value_p) + 1; } /* memcpy (value, "nihao", 5); ret = setxattr(FILE_PATH, name, value, 5, XATTR_CREATE); ZERO_OR_RETURN(ret, "can not set xattr");*/ return 0; }
static int spade_listxattr(const char *path, char *list, size_t size) { ssize_t res = listxattr(path, list, size, XATTR_NOFOLLOW); if (res > 0) { if (list) { size_t len = 0; char *curr = list; do { size_t thislen = strlen(curr) + 1; if (strcmp(curr, G_KAUTH_FILESEC_XATTR) == 0) { memmove(curr, curr + thislen, res - len - thislen); res -= thislen; break; } curr += thislen; len += thislen; } while (len < res); } } if (res == -1) { return -errno; } return res; }
static int farm_init(char *p) { struct siocb iocb; dprintf("use farm store driver\n"); if (create_directory(p) < 0) goto err; if ((listxattr(p, NULL, 0) == -1) && (errno == ENOTSUP)) goto err; if (trunk_init() < 0) goto err; if (snap_init() < 0) goto err; if (init_sys_vdi_bitmap(p) < 0) goto err; iocb.epoch = sys->epoch ? sys->epoch - 1 : 0; farm_cleanup_sys_obj(&iocb); return SD_RES_SUCCESS; err: return SD_RES_EIO; }
int main(int argc,char *argv[]) { char list[XATTR_SIZE],value[XATTR_SIZE]; ssize_t listLen,valueLen; int ns,j,k,opt; Boolean hexDisplay; hexDisplay = 0; while((opt = getopt(argc,argv,"x")) != -1) { switch (opt) { case 'x':hexDisplay = 1;break; case '?': usageError(argv[0]); } } if (optind >= argc + 2) { usageError(argv[0]); } for (j = optind; j < argc; j++) { listLen = listxattr(argv[j],list,XATTR_SIZE); if (listLen == -1) { errExit("listxattr\n"); } printf("%s:\n",argv[j]); /* Loop through all EA names,displaying name + value */ for (ns = 0; ns < listLen; ns += strlen(&list[ns]) + 1) { printf(" name=%s;",&list[ns]); valueLen = getxattr(argv[j],&list[ns],value,XATTR_SIZE); if (valueLen == -1) { printf("couldn't get value"); }else if (!hexDisplay) { printf("value=%.*s",(int)valueLen,value); }else { printf("value="); for (k = 0; k < valueLen; k++) { printf("%02x",(unsigned int)value[k]); } } printf("\n"); } printf("\n"); } exit(EXIT_SUCCESS); }
static int xmp_listxattr(const char *path, char *list, size_t size) { int res = listxattr(path, list, size, XATTR_NOFOLLOW); if (res == -1) return -errno; return res; }
int main (int argc, char **argv) { char list[BUFFER_SIZE] = {0}; int ret; if (argc != 2) { fprintf(stderr, "Usage: %s FILE\n", argv[0]); return 1; } // Ask the kernel for the list of attributes. printf("Listing attributes of \"%s\"\n", argv[1]); ret = listxattr(argv[1], list, BUFFER_SIZE); printf("listxattr() returned %d\n", ret); if (ret == -1) { printf("listxattr() failed: %s\n", strerror(errno)); return 2; } else { printf(" List contents:\n"); print_attribute_list(list, ret); } printf("\n"); // Get each attribute in the list--none of these calls should fail. print_each_attribute(argv[1], list, ret); return 0; }
ssize_t sys_llistxattr (const char *path, char *list, size_t size) { #if defined(HAVE_LLISTXATTR) ssize_t ret; ret = llistxattr(path, list, size); return remove_user(ret, list, size); #elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT) ssize_t ret; int options = XATTR_NOFOLLOW; ret = listxattr(path, list, size, options); return remove_user(ret, list, size); #elif defined(HAVE_LLISTEA) return llistea(path, list, size); #elif defined(HAVE_EXTATTR_LIST_LINK) extattr_arg arg; arg.path = path; return bsd_attr_list(1, arg, list, size); #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H) return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW); #elif defined(HAVE_ATTROPEN) ssize_t ret = -1; int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0); if (attrdirfd >= 0) { ret = solaris_list_xattr(attrdirfd, list, size); close(attrdirfd); } return ret; #else errno = ENOSYS; return -1; #endif }
char get_acl(char *filename) { acl_t acl; acl_entry_t dummy; ssize_t xattr; char str[10]; xattr = 0; acl = NULL; acl = acl_get_link_np(filename, ACL_TYPE_EXTENDED); if (acl && acl_get_entry(acl, ACL_FIRST_ENTRY, &dummy) == -1) { acl_free(acl); acl = NULL; } xattr = listxattr(filename, NULL, 0, XATTR_NOFOLLOW); if (xattr < 0) xattr = 0; str[1] = '\0'; if (xattr > 0) str[0] = '@'; else if (acl) str[0] = '+'; else str[0] = ' '; return (str[0]); }
int volume_listxattr_path_on_active_volumes(const char *relative_raid_path, char *name, size_t size) { pthread_mutex_lock(&volume_list_mutex); VolumeNode_t *volume = active_volumes; int master_ret = -EACCES; struct stat stbuf; while (volume) { char fullpath[PATH_MAX]; volume_full_path_for_raid_path(volume->volume, relative_raid_path, fullpath); /* If no file exists, do not attempt */ if (stat(fullpath, &stbuf)) { volume = volume->next; continue; } int ret = (int)listxattr(fullpath, name, size __APPLE_XATTR_POSITION_P3__ ); if (ret > 0) { pthread_mutex_unlock(&volume_list_mutex); return ret; } else if (ret == 0) { master_ret = 0; } else if (master_ret) { master_ret = -errno; } volume = volume->next; } pthread_mutex_unlock(&volume_list_mutex); return master_ret; }
char *ft_find_right(t_stat *stats, char *str, char *join) { char buf[100]; str = ft_strnew(12); str[0] = ft_find_type(stats->st_mode); str[1] = (stats->st_mode & S_IRUSR) ? 'r' : '-'; str[2] = (stats->st_mode & S_IWUSR) ? 'w' : '-'; if (stats->st_mode & S_IXUSR) str[3] = (S_UID(stats->st_mode) ? 's' : 'x'); else str[3] = (S_UID(stats->st_mode) ? 'S' : '-'); str[4] = (stats->st_mode & S_IRGRP) ? 'r' : '-'; str[5] = (stats->st_mode & S_IWGRP) ? 'w' : '-'; if (stats->st_mode & S_IXGRP) str[6] = (S_GID(stats->st_mode) ? 's' : 'x'); else str[6] = (S_GID(stats->st_mode) ? 'S' : '-'); str[7] = (stats->st_mode & S_IROTH) ? 'r' : '-'; str[8] = (stats->st_mode & S_IWOTH) ? 'w' : '-'; if (stats->st_mode & S_IXOTH) str[9] = (S_VTX(stats->st_mode) ? 't' : 'x'); else str[9] = (S_VTX(stats->st_mode) ? 'T' : '-'); str[10] = (listxattr(join, buf, 100, XATTR_NOFOLLOW) <= 0 ? ' ' : '@'); str[11] = '\0'; return (str); }
static ssize_t xlistxattr(const char *path, char *list, size_t size) { ssize_t ret = listxattr(path, list, size); if (ret < 0) err(1, "listxattr() failed"); return ret; }
static gboolean _load_from_xattr(struct attr_handle_s *attr_handle, GError ** error) { char *last_name, *buf; register ssize_t i; ssize_t s, size; EXTRA_ASSERT(attr_handle != NULL); EXTRA_ASSERT(attr_handle->attr_hash != NULL); s = longest_xattr_list; buf = g_malloc0(s); retry: size = listxattr(attr_handle->chunk_path, buf, s); if (0 > size) { if (errno != ERANGE) { SETERRCODE(error, errno, "Failed to list xattr from file [%s] : %s", attr_handle->chunk_path, strerror(errno)); g_free(buf); return FALSE; } else { s = s*2; longest_xattr_list = 1 + MAX(longest_xattr_list, s); buf = g_realloc(buf, s); memset(buf, 0, s); goto retry; } } if (!size) { g_free(buf); return TRUE; } for (last_name = buf, i = 0; i < size; i++) { if (buf[i] == '\0') { char *value = _getxattr_from_chunk(attr_handle->chunk_path, attr_handle->chunk_file_des, last_name); if (NULL != value) { g_hash_table_insert(attr_handle->attr_hash, g_strdup(last_name), value); } else if (errno == ENOATTR) { /* XATTR disappeared ! */ } else { SETERRCODE(error, errno, "Cannot get xattr %s from %s : %s", last_name, attr_handle->chunk_path, strerror(errno)); g_free(buf); return FALSE; } last_name = buf + i + 1; } } g_free(buf); return TRUE; }
static ssize_t xattr_listxattr(const char *path, char *namebuf, size_t size, int options) { if (!(options == 0 || options == XATTR_XATTR_NOFOLLOW)) { return -1; } if (options & XATTR_XATTR_NOFOLLOW) { return llistxattr(path, namebuf, size); } else { return listxattr(path, namebuf, size); } }
/* list all extended attributes for the file */ void list_xattr(const char* filename, int nofollow) { int options = nofollow ? XATTR_NOFOLLOW : 0; ssize_t buffer_size = listxattr(filename, NULL, 0, options); if(buffer_size < 0) { perror("listxattr"); exit(1); } if(buffer_size == 0) { // no xattr data return; } char* buffer = (char*)malloc(buffer_size); size_t n_read = listxattr(filename, buffer, buffer_size, options); if(n_read != buffer_size) { perror("listxattr (size mismatch)"); free(buffer); exit(1); } // build a list of name,value,name,value,name,value,... int index = 0; char* name = buffer; for(; name < buffer+buffer_size; name += strlen(name) + 1, index++) { int size = getxattr(filename, name, 0, 0, 0, options); if(size < 0) { perror("getxattr"); exit(1); } char* buf2 = (char*)malloc(size + 1); int size2 = getxattr(filename, name, buf2, size, 0, options); if(size != size2) { perror("getxattr (size mismatch)"); exit(1); } printf("%s : %s\n", name, buf2); free(buf2); } free(buffer); }
void ft_write_atx(char *str) { char buf[1024]; if (listxattr(str, buf, 1024, 0) > 0) ft_putstr("@ "); else if (acl_get_file(str, ACL_TYPE_EXTENDED)) ft_putstr("+ "); else ft_putstr(" "); }
ssize_t listAttrs( const char* path, void* data, size_t nbytes ) { ssize_t listxattrRet = listxattr( path, (char*) data, nbytes ); checkReturnValue( "listAttrs", listxattrRet); ssize_t numEntries = numCharInStr( '.', data, listxattrRet ); // remove non-user namespace list items and remove the namespace name // specifier // first allocate a list of pointers to each string. Worst case every // attribute which is found is in the USER namespace so we need a // dynamically array which is this long char** usefulBits = (char**) malloc( sizeof(char*) * numEntries ); if ( usefulBits == NULL ) errExit( "usefulBits malloc in listAttrs" ); // fill usefulBits with NULL for now for ( ssize_t i = 0; i < numEntries; i++ ) usefulBits[i] = NULL; // now put in the relevant pointers size_t numEntriesRemaining = numEntries; usefulBits[0] = seekToInterestingPart( (char*) data, &numEntriesRemaining ); for ( ssize_t i = 1; i < numEntries; i++ ) { // don't do this too many times // returns NULL if we have run out usefulBits[i] = seekToInterestingPart( usefulBits[i-1] + strlen(usefulBits[i-1]) + 6, &numEntriesRemaining ); } // work out how many entries we have ssize_t numInterestingEntries = 0; for ( ssize_t i = 0; i < numEntries; i++ ) { if ( usefulBits[i] == NULL ) { // this is all of them break; } else { numInterestingEntries++; } } // now we overwrite data with the newly edited list. This will definitely // fit because we have removed things from what was previously in data // for the same reason we can be sure that we won't be overwriting ourself // these for loops could all be combined however this form is better for readability char* currPos = (char*) data; for ( ssize_t i = 0; i < numInterestingEntries; i++ ) { size_t size = strlen( usefulBits[i] ); strcpy( currPos, usefulBits[i] ); currPos += ( size + 2 ); } free( usefulBits ); return numInterestingEntries; }
int cow_listxattr(const char *path, char *buf, size_t count) { int res = 0; char *fqpath = create_path(cow_getConfig()->srcdir, path); if(fqpath==NULL){ return -errno; } res=listxattr(fqpath, buf, count); free(fqpath); if (res == -1) return -errno; return res; }
ssize_t sys_listxattr (const char *path, char *list, size_t size) { #if defined(HAVE_LISTXATTR) return listxattr(path, list, size); #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H) return irix_attr_list(path, 0, list, size, 0); #else errno = ENOSYS; return -1; #endif }
int fs_real_listxattr(const char *path, char *list, size_t size) { char ppath[FS_MAXPATH]; struct stat v_stbuf; char *newpath=ppath; FSDEBUG("path=%s",path); isofs_inode *inode = fs_lookup(path); if (inode) { FSDEBUG("you don't have permission on %s",path); return -ENOTSUP; } if (fs_home_stat(path,&newpath,&v_stbuf) == 0) { if (listxattr(newpath,list,size) == 0) return 0; return -errno; } if (listxattr(path,list,size) == 0) return 0; return -errno; }
// Pull the list of all the extended attributes for a path std::vector<std::string> parseExtendedAttributeList(const std::string &path) { std::vector<std::string> attributes; ssize_t value = listxattr(path.c_str(), nullptr, (size_t)0, 0); char *content = (char *)malloc(value); if (content == nullptr) { return attributes; } ssize_t ret = listxattr(path.c_str(), content, value, 0); if (ret == 0) { return attributes; } char *stable = content; do { attributes.push_back(std::string(content)); content += attributes.back().size() + 1; } while (content - stable < value); free(stable); return attributes; }