Revision fc22118d hw/virtio-9p-local.c

b/hw/virtio-9p-local.c
12 12
 */
13 13
#include "virtio.h"
14 14
#include "virtio-9p.h"
15
#include "virtio-9p-xattr.h"
15 16
#include <arpa/inet.h>
16 17
#include <pwd.h>
17 18
#include <grp.h>
......
19 20
#include <sys/un.h>
20 21
#include <attr/xattr.h>
21 22

  
22
static const char *rpath(FsContext *ctx, const char *path)
23
{
24
    /* FIXME: so wrong... */
25
    static char buffer[4096];
26
    snprintf(buffer, sizeof(buffer), "%s/%s", ctx->fs_root, path);
27
    return buffer;
28
}
29

  
30 23

  
31 24
static int local_lstat(FsContext *fs_ctx, const char *path, struct stat *stbuf)
32 25
{
......
497 490
static ssize_t local_lgetxattr(FsContext *ctx, const char *path,
498 491
                               const char *name, void *value, size_t size)
499 492
{
500
    if ((ctx->fs_sm == SM_MAPPED) &&
501
        (strncmp(name, "user.virtfs.", 12) == 0)) {
502
        /*
503
         * Don't allow fetch of user.virtfs namesapce
504
         * in case of mapped security
505
         */
506
        errno = ENOATTR;
507
        return -1;
508
    }
509

  
510
    return lgetxattr(rpath(ctx, path), name, value, size);
493
    return v9fs_get_xattr(ctx, path, name, value, size);
511 494
}
512 495

  
513 496
static ssize_t local_llistxattr(FsContext *ctx, const char *path,
514 497
                                void *value, size_t size)
515 498
{
516
    ssize_t retval;
517
    ssize_t actual_len = 0;
518
    char *orig_value, *orig_value_start;
519
    char *temp_value, *temp_value_start;
520
    ssize_t xattr_len, parsed_len = 0, attr_len;
521

  
522
    if (ctx->fs_sm != SM_MAPPED) {
523
        return llistxattr(rpath(ctx, path), value, size);
524
    }
525

  
526
    /* Get the actual len */
527
    xattr_len = llistxattr(rpath(ctx, path), value, 0);
528

  
529
    /* Now fetch the xattr and find the actual size */
530
    orig_value = qemu_malloc(xattr_len);
531
    xattr_len = llistxattr(rpath(ctx, path), orig_value, xattr_len);
532

  
533
    /*
534
     * For mapped security model drop user.virtfs namespace
535
     * from the list
536
     */
537
    temp_value = qemu_mallocz(xattr_len);
538
    temp_value_start = temp_value;
539
    orig_value_start = orig_value;
540
    while (xattr_len > parsed_len) {
541
        attr_len = strlen(orig_value) + 1;
542
        if (strncmp(orig_value, "user.virtfs.", 12) != 0) {
543
            /* Copy this entry */
544
            strcat(temp_value, orig_value);
545
            temp_value  += attr_len;
546
            actual_len += attr_len;
547
        }
548
        parsed_len += attr_len;
549
        orig_value += attr_len;
550
    }
551
    if (!size) {
552
        retval = actual_len;
553
        goto out;
554
    } else if (size >= actual_len) {
555
        /* now copy the parsed attribute list back */
556
        memset(value, 0, size);
557
        memcpy(value, temp_value_start, actual_len);
558
        retval = actual_len;
559
        goto out;
560
    }
561
    errno = ERANGE;
562
    retval = -1;
563
out:
564
    qemu_free(orig_value_start);
565
    qemu_free(temp_value_start);
566
    return retval;
499
    return v9fs_list_xattr(ctx, path, value, size);
567 500
}
568 501

  
569 502
static int local_lsetxattr(FsContext *ctx, const char *path, const char *name,
570 503
                           void *value, size_t size, int flags)
571 504
{
572
    if ((ctx->fs_sm == SM_MAPPED) &&
573
        (strncmp(name, "user.virtfs.", 12) == 0)) {
574
        /*
575
         * Don't allow fetch of user.virtfs namesapce
576
         * in case of mapped security
577
         */
578
        errno = EACCES;
579
        return -1;
580
    }
581
    return lsetxattr(rpath(ctx, path), name, value, size, flags);
505
    return v9fs_set_xattr(ctx, path, name, value, size, flags);
582 506
}
583 507

  
584 508
static int local_lremovexattr(FsContext *ctx,
585 509
                              const char *path, const char *name)
586 510
{
587
    if ((ctx->fs_sm == SM_MAPPED) &&
588
        (strncmp(name, "user.virtfs.", 12) == 0)) {
589
        /*
590
         * Don't allow fetch of user.virtfs namesapce
591
         * in case of mapped security
592
         */
593
        errno = EACCES;
594
        return -1;
595
    }
596
    return lremovexattr(rpath(ctx, path), name);
511
    return v9fs_remove_xattr(ctx, path, name);
597 512
}
598 513

  
599 514

  

Also available in: Unified diff