paul@181 | 1 | /* |
paul@181 | 2 | * Access control functions. |
paul@181 | 3 | * |
paul@181 | 4 | * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> |
paul@181 | 5 | * |
paul@181 | 6 | * This program is free software; you can redistribute it and/or |
paul@181 | 7 | * modify it under the terms of the GNU General Public License as |
paul@181 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@181 | 9 | * the License, or (at your option) any later version. |
paul@181 | 10 | * |
paul@181 | 11 | * This program is distributed in the hope that it will be useful, |
paul@181 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@181 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@181 | 14 | * GNU General Public License for more details. |
paul@181 | 15 | * |
paul@181 | 16 | * You should have received a copy of the GNU General Public License |
paul@181 | 17 | * along with this program; if not, write to the Free Software |
paul@181 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@181 | 19 | * Boston, MA 02110-1301, USA |
paul@181 | 20 | */ |
paul@181 | 21 | |
paul@181 | 22 | #include "access.h" |
paul@181 | 23 | |
paul@181 | 24 | int access_can_read(user_t user, struct ext2_inode *inode) |
paul@181 | 25 | { |
paul@181 | 26 | /* NOTE: Could use a generic function for properly testing access. |
paul@181 | 27 | NOTE: For example, this does not permit multiple groups. */ |
paul@181 | 28 | |
paul@181 | 29 | return ((inode->i_uid == user.uid) && (inode->i_mode & LINUX_S_IRUSR)) || |
paul@181 | 30 | ((inode->i_gid == user.gid) && (inode->i_mode & LINUX_S_IRGRP)) || |
paul@181 | 31 | (inode->i_mode & LINUX_S_IROTH); |
paul@181 | 32 | } |
paul@181 | 33 | |
paul@181 | 34 | int access_can_write(user_t user, struct ext2_inode *inode) |
paul@181 | 35 | { |
paul@181 | 36 | /* NOTE: Could use a generic function for properly testing access. |
paul@181 | 37 | NOTE: For example, this does not permit multiple groups. */ |
paul@181 | 38 | |
paul@181 | 39 | return ((inode->i_uid == user.uid) && (inode->i_mode & LINUX_S_IWUSR)) || |
paul@181 | 40 | ((inode->i_gid == user.gid) && (inode->i_mode & LINUX_S_IWGRP)) || |
paul@181 | 41 | (inode->i_mode & LINUX_S_IWOTH); |
paul@181 | 42 | } |