libc: support access() in plugins

Fixes #1703
This commit is contained in:
Emery Hemingway 2015-09-18 11:10:29 +02:00 committed by Christian Helmuth
parent 9b21c88bc6
commit 5d434944eb
7 changed files with 33 additions and 2 deletions

View File

@ -44,6 +44,7 @@ namespace Libc {
virtual int priority(); virtual int priority();
virtual bool supports_access(char const *path, int amode);
virtual bool supports_execve(char const *filename, char *const argv[], virtual bool supports_execve(char const *filename, char *const argv[],
char *const envp[]); char *const envp[]);
virtual bool supports_mkdir(const char *path, mode_t mode); virtual bool supports_mkdir(const char *path, mode_t mode);
@ -70,6 +71,7 @@ namespace Libc {
virtual File_descriptor *accept(File_descriptor *, virtual File_descriptor *accept(File_descriptor *,
struct ::sockaddr *addr, struct ::sockaddr *addr,
socklen_t *addrlen); socklen_t *addrlen);
virtual int access(char const *, int);
virtual int bind(File_descriptor *, virtual int bind(File_descriptor *,
const struct ::sockaddr *addr, const struct ::sockaddr *addr,
socklen_t addrlen); socklen_t addrlen);

View File

@ -24,7 +24,8 @@ namespace Libc {
class Plugin_registry : public List<Plugin> class Plugin_registry : public List<Plugin>
{ {
public: public:
Plugin *get_plugin_for_access(char const *pathname, int amode);
Plugin *get_plugin_for_execve(char const *filename, char *const argv[], Plugin *get_plugin_for_execve(char const *filename, char *const argv[],
char *const envp[]); char *const envp[]);
Plugin *get_plugin_for_freeaddrinfo(struct addrinfo *res); Plugin *get_plugin_for_freeaddrinfo(struct addrinfo *res);

View File

@ -43,7 +43,6 @@ ret_type name args \
return ret_val; \ return ret_val; \
} }
DUMMY(int , -1, access, (const char *, int))
DUMMY(int , -1, chmod, (const char *, mode_t)) DUMMY(int , -1, chmod, (const char *, mode_t))
DUMMY(int , -1, chown, (const char *, uid_t, gid_t)) DUMMY(int , -1, chown, (const char *, uid_t, gid_t))
DUMMY(int , -1, chroot, (const char *)) DUMMY(int , -1, chroot, (const char *))

View File

@ -214,6 +214,19 @@ static void resolve_symlinks_except_last_element(char const *path, Absolute_path
** Libc functions ** ** Libc functions **
********************/ ********************/
extern "C" int access(const char *path, int amode)
{
try {
Absolute_path resolved_path;
resolve_symlinks(path, resolved_path);
FNAME_FUNC_WRAPPER(access, resolved_path.base(), amode);
} catch (Symlink_resolve_error) {
errno = ENOENT;
return -1;
}
}
extern "C" int chdir(const char *path) extern "C" int chdir(const char *path)
{ {
struct stat stat_buf; struct stat stat_buf;

View File

@ -42,6 +42,12 @@ int Plugin::priority()
} }
bool Plugin::supports_access(char const *path, int amode)
{
return false;
}
bool Plugin::supports_execve(char const *filename, char *const argv[], bool Plugin::supports_execve(char const *filename, char *const argv[],
char *const envp[]) char *const envp[])
{ {
@ -189,6 +195,7 @@ DUMMY(ssize_t, -1, write, (File_descriptor *, const void *, ::size_t));
/* /*
* Misc * Misc
*/ */
DUMMY(int, -1, access, (char const *, int));
DUMMY(int, -1, execve, (char const *, char *const[], char *const[])); DUMMY(int, -1, execve, (char const *, char *const[], char *const[]));
DUMMY(void, , freeaddrinfo, (struct ::addrinfo *)); DUMMY(void, , freeaddrinfo, (struct ::addrinfo *));
DUMMY(int, -1, getaddrinfo, (const char *, const char *, const struct ::addrinfo *, struct ::addrinfo **)); DUMMY(int, -1, getaddrinfo, (const char *, const char *, const struct ::addrinfo *, struct ::addrinfo **));

View File

@ -37,6 +37,9 @@ using namespace Libc;
} \ } \
return result; return result;
Plugin *Plugin_registry::get_plugin_for_access(char const *path, int amode) {
GET_PLUGIN_FOR(access, path, amode) }
Plugin *Plugin_registry::get_plugin_for_execve(char const *filename, char *const argv[], Plugin *Plugin_registry::get_plugin_for_execve(char const *filename, char *const argv[],
char *const envp[]) { char *const envp[]) {
GET_PLUGIN_FOR(execve, filename, argv, envp) } GET_PLUGIN_FOR(execve, filename, argv, envp) }

View File

@ -210,6 +210,7 @@ class Libc::Vfs_plugin : public Libc::Plugin
~Vfs_plugin() { } ~Vfs_plugin() { }
bool supports_access(const char *, int) override { return true; }
bool supports_mkdir(const char *, mode_t) override { return true; } bool supports_mkdir(const char *, mode_t) override { return true; }
bool supports_open(const char *, int) override { return true; } bool supports_open(const char *, int) override { return true; }
bool supports_readlink(const char *, char *, size_t) override { return true; } bool supports_readlink(const char *, char *, size_t) override { return true; }
@ -227,6 +228,7 @@ class Libc::Vfs_plugin : public Libc::Plugin
return open(path, flags, Libc::ANY_FD); return open(path, flags, Libc::ANY_FD);
} }
int access(char const *, int) override;
int close(Libc::File_descriptor *) override; int close(Libc::File_descriptor *) override;
int dup2(Libc::File_descriptor *, Libc::File_descriptor *) override; int dup2(Libc::File_descriptor *, Libc::File_descriptor *) override;
int fcntl(Libc::File_descriptor *, int, long) override; int fcntl(Libc::File_descriptor *, int, long) override;
@ -251,6 +253,10 @@ class Libc::Vfs_plugin : public Libc::Plugin
}; };
int Libc::Vfs_plugin::access(const char *path, int amode) {
return _root_dir.leaf_path(path) ? 0 : -1; }
Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags, Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags,
int libc_fd) int libc_fd)
{ {