Exemple #1
0
int open(const char *path, int flags, ...)
{
    int ret;
    char *newpath = NULL;

    init_syms();

    if (STRPREFIX(path, SYSFS_PREFIX)) {
        init_sysfs();
        if (asprintf(&newpath, "%s/%s",
                     fakesysfsdir,
                     path + strlen(SYSFS_PREFIX)) < 0) {
            errno = ENOMEM;
            return -1;
        }
    }
    if (flags & O_CREAT) {
        va_list ap;
        mode_t mode;
        va_start(ap, flags);
        mode = va_arg(ap, mode_t);
        va_end(ap);
        ret = realopen(newpath ? newpath : path, flags, mode);
    } else {
        ret = realopen(newpath ? newpath : path, flags);
    }
    free(newpath);
    return ret;
}
Exemple #2
0
int access(const char *path, int mode)
{
    int ret;

    init_syms();

    if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
        init_sysfs();
        char *newpath;
        if (asprintf(&newpath, "%s/%s",
                     fakesysfscgroupdir,
                     path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
            errno = ENOMEM;
            return -1;
        }
        ret = real_access(newpath, mode);
        free(newpath);
    } else if (STREQ(path, "/proc/cgroups") ||
               STREQ(path, "/proc/self/cgroup") ||
               STREQ(path, SYSFS_CPU_PRESENT)) {
        /* These files are readable for all. */
        ret = (mode == F_OK || mode == R_OK) ? 0 : -1;
    } else if (STREQ(path, "/proc/mounts")) {
        /* This one is accessible anytime for anybody. In fact, it's just
         * a symlink to /proc/self/mounts. */
        ret = 0;
    } else {
        ret = real_access(path, mode);
    }
    return ret;
}
Exemple #3
0
int __xstat(int ver, const char *path, struct stat *sb)
{
    int ret;

    init_syms();

    if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
        init_sysfs();
        char *newpath;
        if (asprintf(&newpath, "%s/%s",
                     fakesysfscgroupdir,
                     path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
            errno = ENOMEM;
            return -1;
        }
        ret = real___xstat(ver, newpath, sb);
        free(newpath);
    } else if (STRPREFIX(path, fakedevicedir0)) {
        sb->st_mode = S_IFBLK;
        sb->st_rdev = makedev(8, 0);
        return 0;
    } else if (STRPREFIX(path, fakedevicedir1)) {
        sb->st_mode = S_IFBLK;
        sb->st_rdev = makedev(9, 0);
        return 0;
    } else {
        ret = real___xstat(ver, path, sb);
    }
    return ret;
}
Exemple #4
0
int main() {

  init_env(); // Poorly named. Has nothing to do with env alist.
  init_mem();

  uptr_t *env = refer(NIL);
  init_syms(env);

  uptr_t *form_p = refer(NIL);
  while(1) {
    print_env(env);
    print_mem();

    printf_P(PSTR("> "));
    *form_p = read_form(stdin);
    while(getc(stdin) != '\r');
    print_form(eval(env, *form_p));
    printf_P(PSTR("\n"));

    //    print_mem();
    __GC__();
  }

  release(2); // Just a formality really...

  return 0;
}
void selabel_close(struct selabel_handle *handle)
{
    init_syms();

    if (realis_selinux_enabled())
        return realselabel_close(handle);

    VIR_FREE(handle);
}
const char *selinux_lxc_contexts_path(void)
{
    init_syms();

    if (realis_selinux_enabled())
        return realselinux_lxc_contexts_path();

    return abs_srcdir "/securityselinuxhelperdata/lxc_contexts";
}
const char *selinux_virtual_image_context_path(void)
{
    init_syms();

    if (realis_selinux_enabled())
        return realselinux_virtual_image_context_path();

    return abs_srcdir "/securityselinuxhelperdata/virtual_image_context";
}
int security_get_boolean_active(const char *name)
{
    /* For the purpose of our test, nfs is not permitted.  */
    if (STREQ(name, "virt_use_nfs"))
        return 0;

    init_syms();
    return realsecurity_get_boolean_active(name);
}
int statfs(const char *path, struct statfs *buf)
{
    int ret;

    init_syms();

    ret = realstatfs(path, buf);
    if (!ret && STREQ(path, abs_builddir "/securityselinuxlabeldata/nfs"))
        buf->f_type = NFS_SUPER_MAGIC;
    return ret;
}
Exemple #10
0
FILE *
setmntent(const char *filename, const char *type)
{
    const char *mtab;

    init_syms();

    if ((mtab = getenv("LIBVIRT_MTAB")))
        filename = mtab;

    return real_setmntent(filename, type);
}
Exemple #11
0
int
statfs(const char *path, struct statfs *buf)
{
    const char *mtab;

    init_syms();

    if ((mtab = getenv("LIBVIRT_MTAB")))
        return statfs_mock(mtab, path, buf);

    return real_statfs(path, buf);
}
int socket(int domain,
           int type,
           int protocol)
{
    init_syms();

    if (getenv("LIBVIRT_TEST_IPV4ONLY") && domain == AF_INET6) {
        errno = EAFNOSUPPORT;
        return -1;
    }

    return realsocket(domain, type, protocol);
}
Exemple #13
0
int security_get_boolean_active(const char *name)
{
    if (!is_selinux_enabled()) {
        errno = ENOENT;
        return -1;
    }

    /* For the purpose of our test, nfs is not permitted.  */
    if (STREQ(name, "virt_use_nfs"))
        return 0;

    init_syms();
    return realsecurity_get_boolean_active(name);
}
Exemple #14
0
int selabel_lookup_raw(struct selabel_handle *handle,
                       security_context_t *con,
                       const char *key,
                       int type)
{
    init_syms();

    if (realis_selinux_enabled())
        return realselabel_lookup_raw(handle, con, key, type);

    /* Unimplemented */
    errno = ENOENT;
    return -1;
}
Exemple #15
0
struct selabel_handle *selabel_open(unsigned int backend,
                                    struct selinux_opt *opts,
                                    unsigned nopts)
{
    char *fake_handle;

    init_syms();

    if (realis_selinux_enabled())
        return realselabel_open(backend, opts, nopts);

    /* struct selabel_handle is opaque; fake it */
    if (VIR_ALLOC(fake_handle) < 0)
        return NULL;
    return (struct selabel_handle *)fake_handle;
}
Exemple #16
0
int
open(const char *path, int flags, ...)
{
    int ret;
    char *newpath = NULL;

    init_syms();

    if (STRPREFIX(path, LEASEDIR) &&
        getrealpath(&newpath, path) < 0)
        return -1;

    if (flags & O_CREAT) {
        va_list ap;
        mode_t mode;
        va_start(ap, flags);
        mode = va_arg(ap, int);
        va_end(ap);
        ret = real_open(newpath ? newpath : path, flags, mode);
    } else {
Exemple #17
0
int mkdir(const char *path, mode_t mode)
{
    int ret;

    init_syms();

    if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
        init_sysfs();
        char *newpath;
        if (asprintf(&newpath, "%s/%s",
                     fakesysfscgroupdir,
                     path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
            errno = ENOMEM;
            return -1;
        }
        ret = make_controller(newpath, mode);
        free(newpath);
    } else {
        ret = real_mkdir(path, mode);
    }
    return ret;
}
Exemple #18
0
int stat(const char *path, struct stat *sb)
{
    char *newpath = NULL;
    int ret;

    init_syms();

    if (STREQ(path, SYSFS_CPU_PRESENT)) {
        init_sysfs();
        if (asprintf(&newpath, "%s/%s",
                     fakesysfscgroupdir,
                     SYSFS_CPU_PRESENT_MOCKED) < 0) {
            errno = ENOMEM;
            return -1;
        }
    } else if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
        init_sysfs();
        if (asprintf(&newpath, "%s/%s",
                     fakesysfscgroupdir,
                     path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
            errno = ENOMEM;
            return -1;
        }
    } else if (STRPREFIX(path, fakedevicedir0)) {
        sb->st_mode = S_IFBLK;
        sb->st_rdev = makedev(8, 0);
        return 0;
    } else if (STRPREFIX(path, fakedevicedir1)) {
        sb->st_mode = S_IFBLK;
        sb->st_rdev = makedev(9, 0);
        return 0;
    } else {
        if (!(newpath = strdup(path)))
            return -1;
    }
    ret = real_stat(newpath, sb);
    free(newpath);
    return ret;
}
Exemple #19
0
FILE *fopen(const char *path, const char *mode)
{
    const char *mock;
    bool allinone = false, logind = false;
    init_syms();

    mock = getenv("VIR_CGROUP_MOCK_MODE");
    if (mock) {
        if (STREQ(mock, "allinone"))
            allinone = true;
        else if (STREQ(mock, "logind"))
            logind = true;
    }

    if (STREQ(path, "/proc/mounts")) {
        if (STREQ(mode, "r")) {
            if (allinone)
                return fmemopen((void *)procmountsallinone,
                                strlen(procmountsallinone), mode);
            else if (logind)
                return fmemopen((void *)procmountslogind,
                                strlen(procmountslogind), mode);
            else
                return fmemopen((void *)procmounts, strlen(procmounts), mode);
        } else {
            errno = EACCES;
            return NULL;
        }
    }
    if (STREQ(path, "/proc/cgroups")) {
        if (STREQ(mode, "r")) {
            if (allinone)
                return fmemopen((void *)proccgroupsallinone,
                                strlen(proccgroupsallinone), mode);
            else if (logind)
                return fmemopen((void *)proccgroupslogind,
                                strlen(proccgroupslogind), mode);
            else
                return fmemopen((void *)proccgroups, strlen(proccgroups), mode);
        } else {
            errno = EACCES;
            return NULL;
        }
    }
    if (STREQ(path, "/proc/self/cgroup")) {
        if (STREQ(mode, "r")) {
            if (allinone)
                return fmemopen((void *)procselfcgroupsallinone,
                                strlen(procselfcgroupsallinone), mode);
            else if (logind)
                return fmemopen((void *)procselfcgroupslogind,
                                strlen(procselfcgroupslogind), mode);
            else
                return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode);
        } else {
            errno = EACCES;
            return NULL;
        }
    }

    return real_fopen(path, mode);
}