int crfs_start_mig(char *tgt) { int ret; ret = lsetxattr(crfs_mig_mnt, "migration.tgt", tgt, strlen(tgt), 0); int run = 1; ret = lsetxattr(crfs_mig_mnt, "migration.state", &run, sizeof(int), 0); dbg("*** have started mig to %s\n", tgt); return ret; }
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size, int flags) { char buffer[PATH_MAX]; return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size, flags); }
int do_mode_posix_iface_xattr_write (struct state *state) { long int i; int ret = -1; char block[state->block_size]; char *dname = NULL, *dirc = NULL; char *bname = NULL, *basec = NULL; dirc = strdup (state->prefix); basec = strdup (state->prefix); dname = dirname (dirc); bname = basename (basec); for (i=0; i<state->count; i++) { char key[512]; sprintf (key, "glusterfs.file.%s.%06ld", bname, i); ret = lsetxattr (dname, key, block, state->block_size, 0); if (ret != 0) { fprintf (stderr, "lsetxattr (%s, %s, %p) => %s\n", dname, key, block, strerror (errno)); break; } state->io_size += state->block_size; } free (dirc); free (basec); return i; }
static int process_set_xattr(const char *path, const char *name, const void *data, int len, void *user) { int ret = 0; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); if (g_verbose >= 2) { fprintf(stderr, "set_xattr %s - name=%s data_len=%d " "data=%.*s\n", path, name, len, len, (char*)data); } ret = lsetxattr(full_path, name, data, len, 0); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: lsetxattr %s %s=%.*s failed. %s\n", path, name, len, (char*)data, strerror(-ret)); goto out; } out: free(full_path); return ret; }
gboolean ot_lsetxattrat (int dfd, const char *path, const char *attribute, const void *value, gsize value_size, int flags, GError **error) { /* A workaround for the lack of lsetxattrat(), thanks to Florian Weimer: * https://mail.gnome.org/archives/ostree-list/2014-February/msg00017.html */ g_autofree char *full_path = g_strdup_printf ("/proc/self/fd/%d/%s", dfd, path); int res; do res = lsetxattr (full_path, "user.ostreemeta", value, value_size, flags); while (G_UNLIKELY (res == -1 && errno == EINTR)); if (G_UNLIKELY (res == -1)) { glnx_set_error_from_errno (error); return FALSE; } return TRUE; }
int sys_lsetxattr (const char *path, const char *uname, const void *value, size_t size, int flags) { const char *name = prefix(uname); #if defined(HAVE_LSETXATTR) return lsetxattr(path, name, value, size, flags); #elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT) int options = XATTR_NOFOLLOW; return setxattr(path, name, value, size, 0, options); #elif defined(LSETEA) return lsetea(path, name, value, size, flags); #elif defined(HAVE_EXTATTR_SET_LINK) int retval = 0; if (flags) { /* Check attribute existence */ retval = extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0); if (retval < 0) { /* REPLACE attribute, that doesn't exist */ if (flags & XATTR_REPLACE && errno == ENOATTR) { errno = ENOATTR; return -1; } /* Ignore other errors */ } else { /* CREATE attribute, that already exists */ if (flags & XATTR_CREATE) { errno = EEXIST; return -1; } } } retval = extattr_set_link(path, EXTATTR_NAMESPACE_USER, uname, value, size); return (retval < 0) ? -1 : 0; #elif defined(HAVE_ATTR_SET) int myflags = ATTR_DONTFOLLOW; char *attrname = strchr(name,'.') + 1; if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT; if (flags & XATTR_CREATE) myflags |= ATTR_CREATE; if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE; return attr_set(path, attrname, (const char *)value, size, myflags); #elif defined(HAVE_ATTROPEN) int ret = -1; int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW; int attrfd; if (flags & XATTR_CREATE) myflags |= O_EXCL; if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT; attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE); if (attrfd >= 0) { ret = solaris_write_xattr(attrfd, value, size); close(attrfd); } return ret; #else errno = ENOSYS; return -1; #endif }
/* * lupdate_file_info - update file size, atime, mtime, ctime */ void lupdate_file_info(char *path, int type) { /* get inode and sudo_inode */ struct stat inode; lstat(path, &inode); struct stat sudo_inode; lgetxattr(path, "user.inode_info", (void*)&sudo_inode, sizeof(struct stat)); /* set sudo_inode */ switch (type) { case INODE_SIZE: sudo_inode.st_size = inode.st_size; break; case INODE_ATIME: sudo_inode.st_atime = inode.st_atime; break; case INODE_MTIME: sudo_inode.st_mtime = inode.st_mtime; break; case INODE_CTIME: sudo_inode.st_ctime = inode.st_ctime; break; } lsetxattr(path, "user.inode_info", (void*)&sudo_inode, sizeof(struct stat), 0); }
static rpmRC ima_psm_post(rpmPlugin plugin, rpmte te, int res) { rpmfi fi = rpmteFI(te); const char *fpath; const unsigned char * fsig = NULL; size_t len; int rc = 0; if (fi == NULL) { rc = RPMERR_BAD_MAGIC; goto exit; } while (!rc) { rc = rpmfiNext(fi); if (rc < 0) { if (rc == RPMERR_ITER_END) rc = 0; break; } /* Don't install signatures for (mutable) config files */ if (!(rpmfiFFlags(fi) & RPMFILE_CONFIG)) { fpath = rpmfiFN(fi); fsig = rpmfiFSignature(fi, &len); if (fsig) { lsetxattr(fpath, XATTR_NAME_IMA, fsig, len, 0); } } } exit: return rc; }
int xattr_close (Npfid *fid) { Fid *f = fid->aux; int rc = 0; if (f->xattr) { if ((f->xattr->flags & XATTR_FLAGS_SET)) { if (f->xattr->len > 0) { if (lsetxattr (path_s (f->path), f->xattr->name, f->xattr->buf, f->xattr->len, f->xattr->setflags) < 0) { np_uerror (errno); rc = -1; } } else if (f->xattr->len == 0) { if (lremovexattr (path_s (f->path), f->xattr->name) < 0) { np_uerror (errno); rc = -1; } } } _xattr_destroy (&f->xattr); } return rc; }
int mac_smack_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { #ifdef HAVE_SMACK struct stat st; #endif int r = 0; assert(path); #ifdef HAVE_SMACK if (!mac_smack_use()) return 0; /* * Path must be in /dev and must exist */ if (!path_startswith(path, "/dev")) return 0; r = lstat(path, &st); if (r >= 0) { const char *label; /* * Label directories and character devices "*". * Label symlinks "_". * Don't change anything else. */ if (S_ISDIR(st.st_mode)) label = SMACK_STAR_LABEL; else if (S_ISLNK(st.st_mode)) label = SMACK_FLOOR_LABEL; else if (S_ISCHR(st.st_mode)) label = SMACK_STAR_LABEL; else return 0; r = lsetxattr(path, "security.SMACK64", label, strlen(label), 0); /* If the FS doesn't support labels, then exit without warning */ if (r < 0 && errno == ENOTSUP) return 0; } if (r < 0) { /* Ignore ENOENT in some cases */ if (ignore_enoent && errno == ENOENT) return 0; if (ignore_erofs && errno == EROFS) return 0; r = log_debug_errno(errno, "Unable to fix SMACK label of %s: %m", path); } #endif return r; }
/* xattr operations are optional and can safely be left unimplemented */ static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { int res = lsetxattr(path, name, value, size, flags); if (res == -1) return -errno; return 0; }
static INT64_T chirp_fs_local_lsetxattr(const char *path, const char *name, const void *data, size_t size, int flags) { #ifdef CCTOOLS_OPSYS_DARWIN return setxattr(path, name, data, size, 0, XATTR_NOFOLLOW | flags); #else return lsetxattr(path, name, data, size, flags); #endif }
void testValues() { f = 2; char buf[10]; lsetxattr(anystring(), anystring(), buf, 10, anyint()); //@ assert f == 2; //@ assert vacuous: \false; }
static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { char fpath[PATH_MAX]; xmp_fullpath(fpath, path); int res = lsetxattr(fpath, name, value, size, flags); if (res == -1) return -errno; return 0; }
static int bru_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { SET_CALLER_UID(); REDIR_PATH(path, new_path); int ret = lsetxattr(new_path, name, value, size, flags); SET_RET_ERRNO(); return ret; }
int crfs_stop_mig() { int ret; int run = 0; ret = lsetxattr(crfs_mig_mnt, "migration.state", &run, sizeof(int), 0); dbg("**** have stopped mig\n"); return ret; }
/** Set extended attributes */ int bb_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { char fpath[PATH_MAX]; log_msg("\nbb_setxattr(path=\"%s\", name=\"%s\", value=\"%s\", size=%d, flags=0x%08x)\n", path, name, value, size, flags); bb_fullpath(fpath, path); return log_syscall("lsetxattr", lsetxattr(fpath, name, value, size, flags), 0); }
oc::result<void> selinux_lset_context(const std::string &path, const std::string &context) { if (lsetxattr(path.c_str(), SELINUX_XATTR, context.c_str(), context.size() + 1, 0) < 0) { return ec_from_errno(); } return oc::success(); }
/** Set extended attributes */ int bb_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { int retstat = 0; char fpath[PATH_MAX]; bb_fullpath(fpath, path); retstat = lsetxattr(fpath, name, value, size, flags); return retstat; }
static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { const char* new_path = rewritepath(path); int res = lsetxattr(new_path, name, value, size, flags); free((void*)new_path); if (res == -1) return -errno; return 0; }
static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { char buf[BUFSIZE]; int res = lsetxattr(_xmp_fullpath(buf, path, BUFSIZE), name, value, size, flags); if (res == -1) return -errno; return 0; }
/** Set extended attributes */ int bb_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { int retstat = 0; char fpath[PATH_MAX]; log_msg("\nbb_setxattr(path=\"%s\", name=\"%s\", value=\"%s\", size=%d, flags=0x%08x)\n", path, name, value, size, flags); bb_fullpath(fpath, path); retstat = lsetxattr(fpath, name, value, size, flags); if (retstat < 0) retstat = bb_error("bb_setxattr lsetxattr"); return retstat; }
int add_or_update_ea(enum FILE_TYPE ft, int fd, int ea_flags, const char *prt_str) { int ret = 0; switch (ft) { case NORMAL: ret = fsetxattr(fd, xattr_name, xattr_value, xattr_value_sz, ea_flags); if (ret < 0) { ret = errno; fprintf(stderr, "Failed at fsetxattr(%s,errno:%d,%s) " "on %s:xattr_name=%s,xattr_value_sz=%ld," "xattr_value=%s\n", prt_str, ret, strerror(ret), filename, xattr_name, strlen(xattr_value) + 1, xattr_value); ret = -1; } break; case SYMLINK: ret = lsetxattr(filename, xattr_name, xattr_value, xattr_value_sz, ea_flags); if (ret < 0) { ret = errno; fprintf(stderr, "Failed at lsetxattr(%s,errno:%d,%s) " "on %s:xattr_name=%s,xattr_value_sz=%ld," "xattr_value=%s\n", prt_str, ret, strerror(ret), filename, xattr_name, strlen(xattr_value) + 1, xattr_value); ret = -1; } break; case DIRECTORY: ret = setxattr(filename, xattr_name, xattr_value, xattr_value_sz, ea_flags); if (ret < 0) { ret = errno; fprintf(stderr, "Failed at setxattr(%s,errno:%d,%s) " "on %s:xattr_name=%s,xattr_value_sz=%ld," "xattr_value=%s\n", prt_str, ret, strerror(ret), filename, xattr_name, strlen(xattr_value) + 1, xattr_value); ret = -1; } break; default: break; } return ret; }
static INT64_T chirp_fs_local_lsetxattr(const char *path, const char *name, const void *data, size_t size, int flags) { PREAMBLE("lsetxattr(`%s', `%s', %p, %zu, %d)", path, name, data, size, flags); RESOLVE(path) #ifdef CCTOOLS_OPSYS_DARWIN rc = setxattr(path, name, data, size, 0, XATTR_NOFOLLOW | flags); #else rc = lsetxattr(path, name, data, size, flags); #endif PROLOGUE }
static int enc_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { /* change path to specific mirror directory instead of root */ char fpath[PATH_MAX]; enc_fullpath(fpath, path); int res = lsetxattr(fpath, name, value, size, flags); if (res == -1) return -errno; return 0; }
static int encfs_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { char fpath[PATH_MAX]; // Full buffer to pass to static function dj_fullpath(fpath, path); int res = lsetxattr(fpath, name, value, size, flags); if (res == -1) return -errno; return 0; }
static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { fprintf(f,"setxattr: %s\n",path); int res = lsetxattr(path, name, value, size, flags); if (res == -1){ fprintf(f, "operation failed\n"); return -errno; } fprintf(f, "operation succeeded\n"); return 0; }
/** Set extended attributes */ int sfs_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { int retstat = 0; char fpath[PATH_MAX]; // TODO: log? sfs_fullpath(fpath, path); retstat = lsetxattr(fpath, name, value, size, flags); if (retstat < 0) retstat = sfs_error("sfs_setxattr lsetxattr"); return retstat; }
static void *ciopfs_init(struct fuse_conn_info *conn) { if (chdir(dirname) == -1) { log_print("init: %s\n", strerror(errno)); exit(1); } if (lsetxattr(".", "user.ciopfs", VERSION, sizeof(VERSION) -1, 0) == -1 && errno == ENOTSUP) log_print("warning underlying filesystem does not support extended attributes, " "converting all filenames to lower case\n"); return NULL; }
static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size, int flags) { char buffer[PATH_MAX]; if (strncmp(name, "user.virtfs.", 12) == 0) { /* * Don't allow fetch of user.virtfs namesapce * in case of mapped security */ errno = EACCES; return -1; } return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags); }