shim_access.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * shim_access.c
  15. *
  16. * Implementation of system call "access" and "faccessat".
  17. */
  18. #include <errno.h>
  19. #include <linux/fcntl.h>
  20. #include <pal.h>
  21. #include <pal_error.h>
  22. #include <shim_fs.h>
  23. #include <shim_handle.h>
  24. #include <shim_internal.h>
  25. #include <shim_table.h>
  26. #include <shim_thread.h>
  27. int shim_do_access(const char* file, mode_t mode) {
  28. if (!file)
  29. return -EINVAL;
  30. if (test_user_string(file))
  31. return -EFAULT;
  32. struct shim_dentry* dent = NULL;
  33. int ret = 0;
  34. lock(&dcache_lock);
  35. ret = __path_lookupat(NULL, file, LOOKUP_ACCESS | LOOKUP_FOLLOW, &dent, 0, NULL, false);
  36. if (!ret)
  37. ret = __permission(dent, mode);
  38. unlock(&dcache_lock);
  39. return ret;
  40. }
  41. int shim_do_faccessat(int dfd, const char* filename, mode_t mode) {
  42. if (!filename)
  43. return -EINVAL;
  44. if (test_user_string(filename))
  45. return -EFAULT;
  46. struct shim_dentry* dir = NULL;
  47. struct shim_dentry* dent = NULL;
  48. int ret = 0;
  49. if ((ret = get_dirfd_dentry(dfd, &dir)) < 0)
  50. return ret;
  51. lock(&dcache_lock);
  52. ret = __path_lookupat(dir, filename, LOOKUP_ACCESS | LOOKUP_FOLLOW, &dent, 0, NULL, false);
  53. if (ret < 0)
  54. goto out;
  55. ret = __permission(dent, mode);
  56. out:
  57. unlock(&dcache_lock);
  58. put_dentry(dir);
  59. return ret;
  60. }