mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add faccessat(2).
This commit is contained in:
parent
835f0d5fbc
commit
caf4a1f2c5
6 changed files with 51 additions and 4 deletions
|
@ -138,6 +138,7 @@ execvp.o \
|
|||
_exit.o \
|
||||
_Exit.o \
|
||||
exit.o \
|
||||
faccessat.o \
|
||||
fchmod.o \
|
||||
fcloseall.o \
|
||||
fcntl.o \
|
||||
|
|
34
libc/faccessat.cpp
Normal file
34
libc/faccessat.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
faccessat.cpp
|
||||
Check real user's permissions for a file
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL4(int, sys_faccessat, SYSCALL_FACCESSAT, int, const char*, int, int);
|
||||
|
||||
extern "C" int faccessat(int dirfd, const char* path, int mode, int flags)
|
||||
{
|
||||
return sys_faccessat(dirfd, path, mode, flags);
|
||||
}
|
|
@ -92,7 +92,6 @@ size_t confstr(int, char*, size_t);
|
|||
char* crypt(const char*, const char*);
|
||||
char* ctermid(char*);
|
||||
void encrypt(char [64], int);
|
||||
int faccessat(int, const char*, int, int);
|
||||
int fchdir(int);
|
||||
int fchown(int, uid_t, gid_t);
|
||||
int fchownat(int, const char*, uid_t, gid_t, int);
|
||||
|
@ -161,6 +160,7 @@ int execv(const char*, char* const []);
|
|||
int execve(const char*, char* const [], char* const []);
|
||||
int execvp(const char*, char* const []);
|
||||
pid_t fork(void);
|
||||
int faccessat(int, const char*, int, int);
|
||||
int ftruncate(int, off_t);
|
||||
char* getcwd(char*, size_t);
|
||||
char* get_current_dir_name(void);
|
||||
|
|
|
@ -56,6 +56,8 @@ __BEGIN_DECLS
|
|||
|
||||
#define AT_FDCWD (-100)
|
||||
#define AT_REMOVEDIR (1<<0)
|
||||
#define AT_EACCESS (1<<1)
|
||||
#define AT_SYMLINK_NOFOLLOW (1<<2)
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
#define SYSCALL_LINK 59
|
||||
#define SYSCALL_DUP2 60
|
||||
#define SYSCALL_UNLINKAT 61
|
||||
#define SYSCALL_MAX_NUM 62 /* index of highest constant + 1 */
|
||||
#define SYSCALL_FACCESSAT 62
|
||||
#define SYSCALL_MAX_NUM 63 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -158,19 +158,27 @@ static int sys_open(const char* path, int flags, mode_t mode)
|
|||
}
|
||||
|
||||
// TODO: This is a hack! Stat the file in some manner and check permissions.
|
||||
static int sys_access(const char* path, int /*mode*/)
|
||||
static int sys_faccessat(int dirfd, const char* path, int /*mode*/, int flags)
|
||||
{
|
||||
if ( flags )
|
||||
return errno = ENOSYS, -1;
|
||||
char* pathcopy = GetStringFromUser(path);
|
||||
if ( !pathcopy )
|
||||
return -1;
|
||||
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
||||
const char* relpath = pathcopy;
|
||||
Ref<Descriptor> from = PrepareLookup(&relpath);
|
||||
Ref<Descriptor> from = PrepareLookup(&relpath, dirfd);
|
||||
if ( !from ) { delete[] pathcopy; return -1; }
|
||||
Ref<Descriptor> desc = from->open(&ctx, relpath, O_RDONLY);
|
||||
delete[] pathcopy;
|
||||
return desc ? 0 : -1;
|
||||
}
|
||||
|
||||
static int sys_access(const char* path, int mode)
|
||||
{
|
||||
return sys_faccessat(AT_FDCWD, path, mode, 0);
|
||||
}
|
||||
|
||||
static int sys_unlinkat(int dirfd, const char* path, int flags)
|
||||
{
|
||||
char* pathcopy = GetStringFromUser(path);
|
||||
|
@ -429,6 +437,7 @@ void Init()
|
|||
Syscall::Register(SYSCALL_CLOSE, (void*) sys_close);
|
||||
Syscall::Register(SYSCALL_DUP, (void*) sys_dup);
|
||||
Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2);
|
||||
Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat);
|
||||
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
|
||||
Syscall::Register(SYSCALL_FSTATAT, (void*) sys_fstatat);
|
||||
Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);
|
||||
|
|
Loading…
Add table
Reference in a new issue