1.1 --- a/Control Sun Jun 16 21:51:43 2019 +0200
1.2 +++ b/Control Mon Jul 08 21:24:48 2019 +0200
1.3 @@ -1,3 +1,3 @@
1.4 -requires: libc libext2fs
1.5 +requires: libc libext2fs libsystypes
1.6 provides: libe2access
1.7 maintainer: paul@boddie.org.uk
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/include/e2access/access.h Mon Jul 08 21:24:48 2019 +0200
2.3 @@ -0,0 +1,32 @@
2.4 +/*
2.5 + * Access control functions.
2.6 + *
2.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
2.8 + *
2.9 + * This program is free software; you can redistribute it and/or
2.10 + * modify it under the terms of the GNU General Public License as
2.11 + * published by the Free Software Foundation; either version 2 of
2.12 + * the License, or (at your option) any later version.
2.13 + *
2.14 + * This program is distributed in the hope that it will be useful,
2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 + * GNU General Public License for more details.
2.18 + *
2.19 + * You should have received a copy of the GNU General Public License
2.20 + * along with this program; if not, write to the Free Software
2.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
2.22 + * Boston, MA 02110-1301, USA
2.23 + */
2.24 +
2.25 +#pragma once
2.26 +
2.27 +#include <ext2fs/ext2fs.h>
2.28 +#include <systypes/user.h>
2.29 +
2.30 +EXTERN_C_BEGIN
2.31 +
2.32 +int access_can_read(user_t user, struct ext2_inode *inode);
2.33 +int access_can_write(user_t user, struct ext2_inode *inode);
2.34 +
2.35 +EXTERN_C_END
3.1 --- a/lib/src/Makefile Sun Jun 16 21:51:43 2019 +0200
3.2 +++ b/lib/src/Makefile Mon Jul 08 21:24:48 2019 +0200
3.3 @@ -3,9 +3,9 @@
3.4
3.5 TARGET = libe2access.a libe2access.so
3.6 PC_FILENAME = libe2access
3.7 -SRC_C = format.c image.c path.c
3.8 +SRC_C = access.c format.c image.c path.c
3.9
3.10 -REQUIRES_LIBS = libext2fs
3.11 +REQUIRES_LIBS = libext2fs libsystypes
3.12
3.13 PRIVATE_INCDIR += $(PKGDIR)/include/e2access
3.14 CONTRIB_INCDIR = libe2access
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/lib/src/access.c Mon Jul 08 21:24:48 2019 +0200
4.3 @@ -0,0 +1,42 @@
4.4 +/*
4.5 + * Access control functions.
4.6 + *
4.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include "access.h"
4.26 +
4.27 +int access_can_read(user_t user, struct ext2_inode *inode)
4.28 +{
4.29 + /* NOTE: Could use a generic function for properly testing access.
4.30 + NOTE: For example, this does not permit multiple groups. */
4.31 +
4.32 + return ((inode->i_uid == user.uid) && (inode->i_mode & LINUX_S_IRUSR)) ||
4.33 + ((inode->i_gid == user.gid) && (inode->i_mode & LINUX_S_IRGRP)) ||
4.34 + (inode->i_mode & LINUX_S_IROTH);
4.35 +}
4.36 +
4.37 +int access_can_write(user_t user, struct ext2_inode *inode)
4.38 +{
4.39 + /* NOTE: Could use a generic function for properly testing access.
4.40 + NOTE: For example, this does not permit multiple groups. */
4.41 +
4.42 + return ((inode->i_uid == user.uid) && (inode->i_mode & LINUX_S_IWUSR)) ||
4.43 + ((inode->i_gid == user.gid) && (inode->i_mode & LINUX_S_IWGRP)) ||
4.44 + (inode->i_mode & LINUX_S_IWOTH);
4.45 +}