Exemplo n.º 1
0
static ssize_t
filecache_get_info_xattr(const char *cached_path, void **infopp)
{
  assert(cached_path != NULL);
  assert(infopp != NULL);
  assert(*infopp == NULL);

  ssize_t info_size;
  info_size = getxattr(cached_path, FILECACHE_INFO_ATTR, NULL, 0
#if defined(__APPLE__)
		       , 0, 0
#endif
		       );
  if (info_size == -1) {
    warnx("failed to retreive the size of tahoefs_info attr of %s.",
	 cached_path);
    return (-1);
  }

  char *infop = malloc(info_size);
  info_size = getxattr(cached_path, FILECACHE_INFO_ATTR, infop, info_size
#if defined(__APPLE__)
		       , 0, 0
#endif
		       );
  if (info_size == -1) {
    warn("failed to retreive the value of tahoefs_info attr of %s.",
	 cached_path);
    free(infop);
    return (-1);
  }

  *infopp = infop;
  return (info_size);
}
Exemplo n.º 2
0
static int local_lstat(FsContext *fs_ctx, const char *path, struct stat *stbuf)
{
    int err;
    err =  lstat(rpath(fs_ctx, path), stbuf);
    if (err) {
        return err;
    }
    if (fs_ctx->fs_sm == SM_MAPPED) {
        /* Actual credentials are part of extended attrs */
        uid_t tmp_uid;
        gid_t tmp_gid;
        mode_t tmp_mode;
        dev_t tmp_dev;
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.uid", &tmp_uid,
                    sizeof(uid_t)) > 0) {
            stbuf->st_uid = tmp_uid;
        }
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.gid", &tmp_gid,
                    sizeof(gid_t)) > 0) {
            stbuf->st_gid = tmp_gid;
        }
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.mode", &tmp_mode,
                    sizeof(mode_t)) > 0) {
            stbuf->st_mode = tmp_mode;
        }
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.rdev", &tmp_dev,
                        sizeof(dev_t)) > 0) {
                stbuf->st_rdev = tmp_dev;
        }
    }
    return err;
}
Exemplo n.º 3
0
static gchar *
gis_page_util_get_image_version (const gchar *path,
                                 GError     **error)
{
  ssize_t attrsize;
  g_autofree gchar *value = NULL;

  g_return_val_if_fail (path != NULL, NULL);

  attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, NULL, 0);
  if (attrsize >= 0)
    {
      value = g_malloc (attrsize + 1);
      value[attrsize] = 0;

      attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, value,
                           attrsize);
    }

  if (attrsize >= 0)
    {
      return g_steal_pointer (&value);
    }
  else
    {
      int errsv = errno;
      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                   "Error examining " EOS_IMAGE_VERSION_XATTR " on %s: %s",
                   path, g_strerror (errsv));
      return NULL;
    }
}
Exemplo n.º 4
0
ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
{
	ssize_t len;

	if (preserve_hfs_compression)
		xattr_options |= XATTR_SHOWCOMPRESSION;

	len = getxattr(path, name, value, size, 0, xattr_options);

	/* If we're retrieving data, handle resource forks > 64MB specially */
	if (value != NULL && len == GETXATTR_FETCH_LIMIT && (size_t)len < size) {
		/* getxattr will only return 64MB of data at a time, need to call again with a new offset */
		u_int32_t offset = len;
		size_t data_retrieved = len;
		while (data_retrieved < size) {
			len = getxattr(path, name, value + offset, size - data_retrieved, offset, xattr_options);
			if (len <= 0)
				break;
			data_retrieved += len;
			offset += (u_int32_t)len;
		}
		len = data_retrieved;
	}

	return len;
}
Exemplo n.º 5
0
int
main(int argc, char **argv)
{
	char *path;
	int size;
	char *l;

	if (argc != 2) {
		usage(argv[0]);
		return 1;
	}
	path = argv[1];

	size = getxattr(path, "rns.xml", NULL, 0);
	l = malloc(size + 1);
	if (l == NULL) {
		fprintf(stderr, "malloc failed\n");
		return 2;
	}
	if (getxattr(path, "rns.xml", l, size) == -1) {
		perror("getxattr");
		return 3;
	}
	l[size] = '\0';
	printf("%s", l);

	free(l);

	return 0;
}
Exemplo n.º 6
0
int bproc_nodeinfo(int node, struct bproc_node_info_t *info)
{
	char *path;
	struct stat buf;

	get_node_path(path, node);

	if (stat(path, &buf) != 0) {
		errno = BE_INVALIDNODE;
		return -1;
	}

	info->node = node;
	info->mode = buf.st_mode & 0111;	/*  */
	info->user = buf.st_uid;
	info->group = buf.st_gid;

	if (getxattr(path, BPROC_STATE_XATTR, info->status,
		     sizeof(info->status)) < 0) {
		errno = BE_INVALIDNODE;
		return -1;
	}

	if (getxattr(path, BPROC_ADDR_XATTR, &info->addr,
		     sizeof(info->addr)) < 0) {
		errno = BE_INVALIDNODE;
		return -1;
	}
	return 0;
}
Exemplo n.º 7
0
ssize_t
ceph_os_getxattr(const char *path, const char *name,
void *value, size_t size)
{
	ssize_t error = -1;

#if defined(__FreeBSD__)
	if (value == NULL || size == 0) {
		error = extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value,
		    size);
	} else {
		error = extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, NULL,
		    0);
		if (error > 0) {
			if (error > size) {
				errno = ERANGE;
				error = -1;
			} else  {
				error = extattr_get_file(path, EXTATTR_NAMESPACE_USER,
				    name, value, size);
			}
		}
	}
#elif defined(__linux__)
	error = getxattr(path, name, value, size);
#elif defined(DARWIN)
	error = getxattr(path, name, value, size, 0);
#endif

	return (error);
}
Exemplo n.º 8
0
/**
* This function populates a CTM (Chunk Transfer Metadata) structure.
* This structure holds infromation as to what chunks of a file have
* been transferred.
*
* Note that this function manages extended attributes on the
* transferred file, so that the information about what chunks need
* to be transferred, can be maintained through transfer failures.
*
* @param ctmptr		pointer to a CTM structure to
* 			populate. It is an OUT parameter.
* @param numchunks	a parameter that is looked at
* 			in the case of a new transfer.
* @param chunksize	a parameter that is used in
* 			the case of a new transfer
*
* @return a positive number if the population of the structure is
* 	completed. Otherwise a negative result is returned. (-1)
* 	means that the ctmptr was invalid. (-ENOTSUP) means that
* 	the xattr entries could not be read.
*/
int populateCTA(CTM *ctmptr, long numchunks, size_t chunksize) {
    ssize_t axist;							// hold the size of the returned chunknum xattr. Acts as a flag
    long anumchunks;						// value of number of chunks from the xattr
    size_t achunksize;						// value of chunk size from the xattr
    size_t arrysz;							// the size of the chunk flag bit array buffer in bytes

    if(!ctmptr || strIsBlank(ctmptr->chnkfname))			// make sure we have a valid structure
        return(-1);
    // if xattrs cannot be retieved ...
    if((axist = getxattr(ctmptr->chnkfname, CTA_CHNKNUM_XATTR, (void *)&anumchunks, sizeof(long))) < 0) {
        int syserr = errno;						// preserve errno

        if(syserr == ENOATTR) {					// no xattr for chnknum exists for file
            anumchunks = numchunks;					// use the parameters passed in
            achunksize = chunksize;
        }
        else
            return(-(syserr));						// any other error at this point is not handled
    }								// xattrs exist -> read chunk size
    else if(getxattr(ctmptr->chnkfname, CTA_CHNKSZ_XATTR, (void *)&achunksize, sizeof(size_t)) < 0)
        return(-ENOTSUP);						// error at this point means there are other issue -> return any error

    ctmptr->chnknum = anumchunks;					// now assign number of chunks to CTM structure
    ctmptr->chnksz = achunksize;					// assign chunk size to CTM structure
    if((arrysz=allocateCTMFlags(ctmptr)) <= 0)			// allocate the chunk flag bit array
        return(-1);							//    problems? -> return an error

    if(axist >= 0) {						// if first call to getxattr() >= 0 -> can read the chunk flags
        if(getxattr(ctmptr->chnkfname, CTA_CHNKFLAGS_XATTR, (void *)(ctmptr->chnkflags), arrysz) < 0)
            return(-ENOTSUP);						// error at this point means there are other issue -> return any error
    }

    return(1);
}
Exemplo n.º 9
0
static int
loopback_getxattr(const char *path, const char *name, char *value, size_t size,
                  uint32_t position)
{
    int res;

    if (strcmp(name, A_KAUTH_FILESEC_XATTR) == 0) {

        char new_name[MAXPATHLEN];

        memcpy(new_name, A_KAUTH_FILESEC_XATTR, sizeof(A_KAUTH_FILESEC_XATTR));
        memcpy(new_name, G_PREFIX, sizeof(G_PREFIX) - 1);

        res = getxattr(path, new_name, value, size, position, XATTR_NOFOLLOW);

    } else {
        res = getxattr(path, name, value, size, position, XATTR_NOFOLLOW);
    }

    if (res == -1) {
        return -errno;
    }

    return res;
}
Exemplo n.º 10
0
static Eina_Bool
_eina_xattr_value_ls_iterator_next(Eina_Xattr_Iterator *it, void **data)
{
   char *tmp;

   if (it->offset >= it->length)
     return EINA_FALSE;

   *data = it->attr;
   it->attr->name = it->xattr + it->offset;
   it->offset += strlen(it->attr->name) + 1;

   it->attr->length = getxattr(it->file, it->attr->name, NULL, 0);
   if (it->attr->length)
     {
        tmp = realloc((void*) it->attr->value, it->attr->length);
        if (!tmp)
          {
             free((void*) it->attr->value);
             it->attr->value = NULL;
             it->attr->length = 0;
          }
        else
          {
             it->attr->value = tmp;
             it->attr->length = getxattr(it->file, it->attr->name,
                                         (void*) it->attr->value,
                                         it->attr->length);
             tmp[it->attr->length] = '\0';
          }
     }

   return EINA_TRUE;
}
Exemplo n.º 11
0
ssize_t smack_new_label_from_path(const char *path, const char *xattr, 
				  int follow, char **label)
{
	char *result;
	ssize_t ret = 0;

	ret = follow ?
		getxattr(path, xattr, NULL, 0) :
		lgetxattr(path, xattr, NULL, 0);
	if (ret < 0 && errno != ERANGE)
		return -1;

	result = calloc(ret + 1, 1);
	if (result == NULL)
		return -1;

	ret = follow ?
		getxattr(path, xattr, result, ret) :
		lgetxattr(path, xattr, result, ret);
	if (ret < 0) {
		free(result);
		return -1;
	}

	*label = result;
	return 0;
}
Exemplo n.º 12
0
static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
{
    int err;
    char buffer[PATH_MAX];
    char *path = fs_path->data;

    err =  lstat(rpath(fs_ctx, path, buffer), stbuf);
    if (err) {
        return err;
    }
    if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
        /* Actual credentials are part of extended attrs */
        uid_t tmp_uid;
        gid_t tmp_gid;
        mode_t tmp_mode;
        dev_t tmp_dev;
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.uid", &tmp_uid,
                    sizeof(uid_t)) > 0) {
            stbuf->st_uid = tmp_uid;
        }
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.gid", &tmp_gid,
                    sizeof(gid_t)) > 0) {
            stbuf->st_gid = tmp_gid;
        }
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.mode",
                    &tmp_mode, sizeof(mode_t)) > 0) {
            stbuf->st_mode = tmp_mode;
        }
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.rdev", &tmp_dev,
                        sizeof(dev_t)) > 0) {
                stbuf->st_rdev = tmp_dev;
        }
    }
    return err;
}
Exemplo n.º 13
0
int fs_real_getxattr(const char *path, const char *name, void *value, size_t size)
{
    char ppath[2*FS_MAXPATH];
    struct stat v_stbuf;
    char *newpath=ppath;
    int retval;
    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)
    {
        retval = getxattr(newpath, name, value, size);
        if (retval == -1) return -errno;
        return retval;
    }

    retval = getxattr(path, name, value, size);
    if (retval == -1) return -errno;
    return retval;
}
Exemplo n.º 14
0
Arquivo: xattr.c Projeto: Algy/uwsgi
static char *uwsgi_route_var_xattr2(struct wsgi_request *wsgi_req, char *key, uint16_t keylen, uint16_t *vallen) {
        char *colon = memchr(key, ':', keylen);
        if (!colon) return NULL;
        uint16_t var_vallen = 0;
        char *var_value = uwsgi_get_var(wsgi_req, key, colon-key, &var_vallen);
        if (var_value) {
		uint16_t var2_vallen = 0;	
		char *var2_value = uwsgi_get_var(wsgi_req, colon+1, (keylen-1) - (colon-key), &var2_vallen);
		if (var2_value) {
                	char *filename = uwsgi_concat2n(var_value, var_vallen, "", 0);
                	char *name = uwsgi_concat2n(var2_value, var2_vallen, "", 0);
                	ssize_t rlen = getxattr(filename, name, NULL, 0);
                	if (rlen > 0) {
                        	char *value = uwsgi_calloc(rlen);
                        	getxattr(filename, name, value, rlen);
                        	*vallen = rlen;
                        	free(filename);
                        	free(name);
                        	return value;
                	}
                	free(filename);
                	free(name);
		}
        }
        return NULL;
}
Exemplo n.º 15
0
Arquivo: xattr.c Projeto: 0day-ci/ceph
ssize_t
ceph_os_getxattr(const char *path, const char *name,
void *value, size_t size)
{
	ssize_t error = -1;

#if defined(__FreeBSD__)
	if (value == NULL || size == 0) {
		error = extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value,
		    size);
	} else {
		error = extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, NULL,
		    0);
		if (error > 0) {
			if (error > size) {
				errno = ERANGE;
				error = -1;
			} else  {
				error = extattr_get_file(path, EXTATTR_NAMESPACE_USER,
				    name, value, size);
			}
		}
	}
#elif defined(__linux__)
	error = getxattr(path, name, value, size);
#elif defined(DARWIN)
	error = getxattr(path, name, value, size, 0 /* position  */, 0);
	/* ENOATTR and ENODATA have different values */
	if (error < 0 && errno == ENOATTR)
		errno = ENODATA;
#endif

	return (error);
}
Exemplo n.º 16
0
static INT64_T chirp_fs_local_getxattr(const char *path, const char *name, void *data, size_t size)
{
#ifdef CCTOOLS_OPSYS_DARWIN
	return getxattr(path, name, data, size, 0, 0);
#else
	return getxattr(path, name, data, size);
#endif
}
Exemplo n.º 17
0
ssize_t sys_getxattr (const char *path, const char *uname, void *value, size_t size)
{
	const char *name = prefix(uname);

#if defined(HAVE_GETXATTR)
#ifndef XATTR_ADD_OPT
	return getxattr(path, name, value, size);
#else
	int options = 0;
	return getxattr(path, name, value, size, 0, options);
#endif
#elif defined(HAVE_GETEA)
	return getea(path, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FILE)
	ssize_t retval;
	/*
	 * The BSD implementation has a nasty habit of silently truncating
	 * the returned value to the size of the buffer, so we have to check
	 * that the buffer is large enough to fit the returned value.
	 */
	if((retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0)) >= 0) {
        if (size == 0)
            /* size == 0 means only return size */
            return retval;
		if (retval > size) {
			errno = ERANGE;
			return -1;
		}
		if ((retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, value, size)) >= 0)
			return retval;
	}

	LOG(log_maxdebug, logtype_default, "sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno));
	return -1;
#elif defined(HAVE_ATTR_GET)
	int retval, flags = 0;
	int valuelength = (int)size;
	char *attrname = strchr(name,'.') + 1;
	
	if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;

	retval = attr_get(path, attrname, (char *)value, &valuelength, flags);

	return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
	ssize_t ret = -1;
	int attrfd = solaris_attropen(path, name, O_RDONLY, 0);
	if (attrfd >= 0) {
		ret = solaris_read_xattr(attrfd, value, size);
		close(attrfd);
	}
	return ret;
#else
	errno = ENOSYS;
	return -1;
#endif
}
Exemplo n.º 18
0
static
ssize_t _getxattr(const char* path, const char* name, void* value, size_t size)
{
#if defined(__LWI_DARWIN__)
	return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
#else
	return getxattr(path, name, value, size);
#endif
}
Exemplo n.º 19
0
int XattrHelper::getXattrValue(std::string & filePath, std::string & attrName, std::vector<char> & buff)
{
	ssize_t size = getxattr(filePath.c_str(), attrName.c_str(), NULL, 0);
	if(size > 0)
	{
		buff.resize(size);
		size = getxattr(filePath.c_str(), attrName.c_str(), &buff[0], buff.size());
	}
	return size;
}
Exemplo n.º 20
0
static INT64_T chirp_fs_local_getxattr(const char *path, const char *name, void *data, size_t size)
{
	PREAMBLE("getxattr(`%s', `%s', %p, %zu)", path, name, data, size);
	RESOLVE(path)
#ifdef CCTOOLS_OPSYS_DARWIN
	rc = getxattr(path, name, data, size, 0, 0);
#else
	rc = getxattr(path, name, data, size);
#endif
	PROLOGUE
}
Exemplo n.º 21
0
Arquivo: xattr.c Projeto: szborows/rr
int main(int argc, char* argv[]) {
  char path[PATH_MAX];
  const char* home = getenv("HOME");
  int fd;
  int ret;

  snprintf(path, sizeof(path), "%s/rr-xattr-XXXXXX", home ? home : "/tmp");
  path[sizeof(path) - 1] = 0;
  fd = mkstemp(path);
  test_assert(0 <= fd);

  ret = setxattr(path, attr_name, attr_value, sizeof(attr_value), XATTR_CREATE);
  if (ret < 0 && errno == EOPNOTSUPP) {
    atomic_printf("Extended attributes not supported on file %s, "
                  "skipping test\n",
                  path);
  } else {
    char buf[sizeof(attr_value) + 1];

    test_assert(ret == 0);

    memset(buf, '-', sizeof(buf));

    ret = fgetxattr(fd, attr_name, buf, sizeof(buf) - 5);
    test_assert(ret == -1);
    test_assert(errno == ERANGE);
    test_assert(buf[0] == '-');

    ret =
        fsetxattr(fd, attr_name, attr_value, sizeof(attr_value), XATTR_REPLACE);
    test_assert(ret == 0);

    ret = getxattr(path, attr_name, buf, sizeof(buf));
    test_assert(ret == sizeof(attr_value));
    test_assert(0 == memcmp(attr_value, buf, sizeof(attr_value)));
    test_assert(buf[sizeof(attr_value)] == '-');

    ret = fremovexattr(fd, attr_name);
    test_assert(ret == 0);

    memset(buf, '-', sizeof(buf));

    ret = getxattr(path, attr_name, buf, sizeof(buf));
    test_assert(ret == -1);
    test_assert(errno == ENODATA);
    test_assert(buf[0] == '-');
  }

  test_assert(0 == unlink(path));

  atomic_puts("EXIT-SUCCESS");
  return 0;
}
Exemplo n.º 22
0
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
		    struct fuse_file_info *fi)
{
	(void)fi;
	int res=0;
	int action;
	ssize_t vsize = 0;
	char *tval = NULL;

	char fpath[PATH_MAX];
	xmp_getfullpath(fpath, path);

	vsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, NULL, 0);
	tval = malloc(sizeof(*tval)*(vsize));
	vsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, tval, vsize);

	fprintf(stderr, "Size: %zu, offset: %zu.\n", size, offset);

	/* If the specified attribute doesn't exist or it's set to false */
	if (vsize < 0 || memcmp(tval, "false", 5) == 0){
		if(errno == ENODATA){
			fprintf(stderr, "Read: No %s attribute set\n", XATRR_ENCRYPTED_FLAG);
		}
		action = COPY;
	}
	else if (memcmp(tval, "true", 4) == 0){
		action = DECRYPT;
		fprintf(stderr, "Read: file is encrypted, need to decrypt\n");
	}

	const char *tpath = ftemp(fpath, ".read");
	FILE *dfd = fopen(tpath, "wb+");
	FILE *fd = fopen(fpath, "rb");

	if(!do_crypt(fd, dfd, action, ENCFS_DATA->passkey)){
		fprintf(stderr, "Encryption failed, error code: %d\n", res);
    	}

    fseek(dfd, 0, SEEK_END);
   	size_t tflen = ftell(dfd);
    fseek(dfd, 0, SEEK_SET);

   	res = fread(buf, 1, tflen, dfd);
    	if (res == -1) res = -errno;

	fclose(fd);
	fclose(dfd);
	remove(tpath);
	free(tval);

	return res;
}
Exemplo n.º 23
0
Arquivo: attr.c Projeto: Jaharmi/zsh
static ssize_t
xgetxattr(const char *path, const char *name, void *value, size_t size, int symlink)
{
#ifdef XATTR_EXTRA_ARGS
    return getxattr(path, name, value, size, 0, symlink ? XATTR_NOFOLLOW: 0);
#else
    switch (symlink) {
    case 0:
        return getxattr(path, name, value, size);
    default:
        return lgetxattr(path, name, value, size);
    }
#endif
}
Exemplo n.º 24
0
static int isEncrypted(const char *npath){

	
	ssize_t size;
	size=getxattr(npath,NAME,NULL, 0);
	fprintf(stderr,"in isencrypted\n");
	/*if(0>size){//on error
		return DEC;
	}*/
	if(size<0){

		fprintf(stderr, "size of attr is less then 0 error\n");		

		if(errno==ENODATA){

			return 0;
		}else{
			exit(EXIT_FAILURE);
		}



	}
	//char value[5]; //declare buffer of size size
	char *attr;

	attr= malloc(sizeof(*attr)*(size+1));
	size=getxattr(npath,NAME,attr, size);
	//tmpval[valsize] = '\0'; may need to add this later where tmpval is avlue and val size is size
	attr[size]='\0';
//	char value[4]; //declare buffer of size size
//	size=getxattr(npath,NAME,value, 4);

	

	if(!strcmp(attr,"true")){
		fprintf(stderr,"is encrypted\n\n\n\n\n");
		free(attr);
		return 1;//return of value is true shwoing that it is encrypted

		
	}else{
		fprintf(stderr,"isnt encrpyted\n\n\n\n");
		free(attr);
		return 0;//returns value of false showing that it isnt encrpyted

		
	}
}
static int
get_rsrc_footer(const char *filename, char *buff, size_t s)
{
	ssize_t r;

	r = getxattr(filename, "com.apple.ResourceFork", NULL, 0, 0,
	    XATTR_SHOWCOMPRESSION);
	if (r < (ssize_t)s)
		return (-1);
	r = getxattr(filename, "com.apple.ResourceFork", buff, s,
	    r - s, XATTR_SHOWCOMPRESSION);
	if (r < (ssize_t)s)
		return (-1);
	return (0);
}
Exemplo n.º 26
0
cap_t cap_get_file(const char *filename)
{
    cap_t result;

    /* allocate a new capability set */
    result = cap_init();
    if (result) {
	struct vfs_cap_data rawvfscap;
	int sizeofcaps;

	_cap_debug("getting filename capabilities");

	/* fill the capability sets via a system call */
	sizeofcaps = getxattr(filename, XATTR_NAME_CAPS,
			      &rawvfscap, sizeof(rawvfscap));
	if (sizeofcaps < ssizeof(rawvfscap.magic_etc)) {
	    cap_free(result);
	    result = NULL;
	} else {
	    result = _fcaps_load(&rawvfscap, result, sizeofcaps);
	}
    }

    return result;
}
Exemplo n.º 27
0
enum sock_proto
getfdproto(struct tcb *tcp, int fd)
{
#ifdef HAVE_SYS_XATTR_H
	size_t bufsize = 256;
	char buf[bufsize];
	ssize_t r;
	char path[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];

	if (fd < 0)
		return SOCK_PROTO_UNKNOWN;

	sprintf(path, "/proc/%u/fd/%u", tcp->pid, fd);
	r = getxattr(path, "system.sockprotoname", buf, bufsize - 1);
	if (r <= 0)
		return SOCK_PROTO_UNKNOWN;
	else {
		/*
		 * This is a protection for the case when the kernel
		 * side does not append a null byte to the buffer.
		 */
		buf[r] = '\0';

		return get_proto_by_name(buf);
	}
#else
	return SOCK_PROTO_UNKNOWN;
#endif
}
Exemplo n.º 28
0
/* NOTE: no size discovery */
int
brstub_validate_version (char *bpath, unsigned long version)
{
        int ret = 0;
        int match = 0;
        size_t xsize = 0;
        br_version_t *xv = NULL;

        xsize = sizeof (br_version_t);

        xv = calloc (1, xsize);
        if (!xv) {
                match = -1;
                goto err;
        }

        ret = getxattr (bpath, "trusted.bit-rot.version", xv, xsize);
        if (ret < 0) {
                if (errno == ENODATA)
                        match = -2;
                goto err;
        }

        if (xv->ongoingversion != version) {
                match = -3;
                fprintf (stderr, "ongoingversion: %lu\n", xv->ongoingversion);
        }
        free (xv);

 err:
        return match;
}
Exemplo n.º 29
0
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
        struct fuse_file_info *fi)
{
    FILE *f, *memstream;
    int res;
    char pathbuf[BUFSIZE];
    char *membuf;
    size_t memsize;

    (void) fi;
    f = fopen(_xmp_fullpath(pathbuf, path, BUFSIZE), "r");
    memstream = open_memstream(&membuf, &memsize);
    if (f == NULL || memstream == NULL)
        return -errno;

    char attrbuf[8];
    ssize_t attr_len = getxattr(pathbuf, ENCRYPTED_ATTR, attrbuf, 8);
    int crypt_action = AES_PASSTHRU;
    if(attr_len != -1 && !memcmp(attrbuf, "true", 4)){
        crypt_action = AES_DECRYPT;
    }

    xmp_state *state = (xmp_state *)(fuse_get_context()->private_data);
    do_crypt(f, memstream, crypt_action, state->key);
    fflush(memstream);
    fseek(memstream, offset, SEEK_SET);
    res = fread(buf, 1, size, memstream);
    fclose(memstream);

    if (res == -1)
        res = -errno;

    fclose(f);
    return res;
}
Exemplo n.º 30
0
Arquivo: πfs.c Projeto: 47d5b/pifs
static int pifs_getxattr(const char *path, const char *name, char *value,
                         size_t size)
{
  FULL_PATH(path);
  int ret = getxattr(full_path, name, value, size);
  return ret == -1 ? -errno : ret;
}