Commit df4a6f99 authored by Marc Vef's avatar Marc Vef
Browse files

Check user/group/other permission done. At least in theory

parent 63f2de8f
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -12,25 +12,30 @@ int chk_access(const Metadata& md, const int mode) {
    if (fuse_get_context()->uid == 0)
        return 0;

    // mode should be unsigned int. Init here.

    //check user
    //check user leftmost 3 bits for rwx in md->mode
    if (md.uid() == fuse_get_context()->uid) {
        ADAFS_DATA->logger->info("Metadata UID: {}, fuse context uid: {}, mode: {}",
                                 md.uid(), fuse_get_context()->uid, mode);
        // XXX
        // Because mode comes only with the first 3 bits used, the user bits have to be shifted to the right to compare
        if ((mode & md.mode() >> 6) == (unsigned int) mode)
            return 0;
        else
            return -EACCES;
    }

    //check group
    //check group middle 3 bits for rwx in md->mode
    if (md.gid() == fuse_get_context()->gid) {
        ADAFS_DATA->logger->info("Metadata GID: {}, fuse context gid: {}, mode: {}",
                                 md.uid(), fuse_get_context()->gid, mode);
        // XXX
        if ((mode & md.mode() >> 3) == (unsigned int) mode)
            return 0;
        else
            return -EACCES;
    }
    //check public
    ADAFS_DATA->logger->info("mode {}, mdi mode: {}, mdi & mode {}", mode, (int) md.mode(), (mode & md.mode()));

    if ((mode & (int) md.mode()) == mode) {
    //check other rightmost 3 bits for rwx in md->mode.
    // Because they are the rightmost bits they don't need to be shifted
    if ((mode & md.mode()) == (unsigned int) mode) {
        return 0;
    }