[3b7c123] | 1 | /* |
---|
| 2 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * embedded brains GmbH |
---|
| 5 | * Obere Lagerstr. 30 |
---|
| 6 | * 82178 Puchheim |
---|
| 7 | * Germany |
---|
| 8 | * <rtems@embedded-brains.de> |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 12 | * http://www.rtems.org/license/LICENSE. |
---|
[3b7c123] | 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[98c6d50] | 19 | #define TEST_INIT |
---|
| 20 | |
---|
[3b7c123] | 21 | #include "tmacros.h" |
---|
| 22 | |
---|
| 23 | #include <sys/stat.h> |
---|
| 24 | #include <sys/statvfs.h> |
---|
| 25 | #include <errno.h> |
---|
| 26 | #include <fcntl.h> |
---|
| 27 | #include <stdio.h> |
---|
| 28 | #include <stdlib.h> |
---|
| 29 | #include <utime.h> |
---|
| 30 | |
---|
| 31 | #include <rtems/libio_.h> |
---|
| 32 | |
---|
[bc75887] | 33 | const char rtems_test_name[] = "FSNOFS 1"; |
---|
| 34 | |
---|
[3b7c123] | 35 | static int node_count(const rtems_chain_control *chain) |
---|
| 36 | { |
---|
| 37 | int count = 0; |
---|
| 38 | const rtems_chain_node *current = rtems_chain_immutable_first(chain); |
---|
| 39 | const rtems_chain_node *tail = rtems_chain_immutable_tail(chain); |
---|
| 40 | |
---|
| 41 | while (current != tail) { |
---|
| 42 | ++count; |
---|
| 43 | |
---|
| 44 | current = rtems_chain_immutable_next(current); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | return count; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | static void rtems_test_assert_equal_to_null_loc( |
---|
| 51 | const rtems_filesystem_location_info_t *local_loc |
---|
| 52 | ) |
---|
| 53 | { |
---|
| 54 | rtems_filesystem_global_location_t *null_loc = |
---|
| 55 | &rtems_filesystem_global_location_null; |
---|
| 56 | |
---|
| 57 | rtems_test_assert(null_loc->location.node_access == local_loc->node_access); |
---|
| 58 | rtems_test_assert(null_loc->location.node_access_2 == local_loc->node_access_2); |
---|
| 59 | rtems_test_assert(null_loc->location.handlers == local_loc->handlers); |
---|
| 60 | rtems_test_assert(null_loc->location.mt_entry == local_loc->mt_entry); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | static void test_initial_values(void) |
---|
| 64 | { |
---|
| 65 | rtems_filesystem_global_location_t *null_loc = |
---|
| 66 | &rtems_filesystem_global_location_null; |
---|
| 67 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 68 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 69 | rtems_chain_node *loc_node = &null_loc->location.mt_entry_node; |
---|
| 70 | |
---|
| 71 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 72 | rtems_test_assert(rtems_chain_previous(loc_node) == rtems_chain_head(loc_chain)); |
---|
| 73 | rtems_test_assert(rtems_chain_next(loc_node) == rtems_chain_tail(loc_chain)); |
---|
| 74 | rtems_test_assert(null_mt->mt_point_node == null_loc); |
---|
| 75 | rtems_test_assert(null_mt->mt_fs_root == null_loc); |
---|
| 76 | rtems_test_assert(!null_mt->mounted); |
---|
| 77 | rtems_test_assert(!null_mt->writeable); |
---|
[66fac03] | 78 | rtems_test_assert(null_loc->reference_count == 4); |
---|
[ca4602e] | 79 | rtems_test_assert(null_loc->deferred_released_next == NULL); |
---|
[66fac03] | 80 | rtems_test_assert(null_loc->deferred_released_count == 0); |
---|
[3b7c123] | 81 | } |
---|
| 82 | |
---|
| 83 | static void test_location_obtain(void) |
---|
| 84 | { |
---|
| 85 | rtems_filesystem_global_location_t *global_loc = NULL; |
---|
| 86 | rtems_filesystem_global_location_t *null_loc = |
---|
| 87 | rtems_filesystem_global_location_obtain(&global_loc); |
---|
| 88 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 89 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 90 | |
---|
| 91 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 92 | rtems_test_assert(null_loc->reference_count == 5); |
---|
| 93 | |
---|
[66fac03] | 94 | rtems_filesystem_global_location_release(null_loc, false); |
---|
[3b7c123] | 95 | |
---|
| 96 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 97 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | static void test_null_location_obtain(void) |
---|
| 101 | { |
---|
| 102 | rtems_filesystem_global_location_t *null_loc = |
---|
| 103 | rtems_filesystem_global_location_obtain_null(); |
---|
| 104 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 105 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 106 | |
---|
| 107 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 108 | rtems_test_assert(null_loc->reference_count == 5); |
---|
| 109 | |
---|
[66fac03] | 110 | rtems_filesystem_global_location_release(null_loc, false); |
---|
[3b7c123] | 111 | |
---|
| 112 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 113 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | static void test_null_location_replace(void) |
---|
| 117 | { |
---|
| 118 | rtems_filesystem_global_location_t *null_loc = |
---|
| 119 | &rtems_filesystem_global_location_null; |
---|
| 120 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 121 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 122 | rtems_filesystem_location_info_t local_loc; |
---|
| 123 | |
---|
| 124 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 125 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 126 | rtems_test_assert(rtems_filesystem_global_location_is_null(null_loc)); |
---|
| 127 | |
---|
| 128 | rtems_filesystem_location_copy(&local_loc, &null_loc->location); |
---|
| 129 | |
---|
| 130 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 131 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 132 | |
---|
| 133 | rtems_filesystem_location_detach(&local_loc); |
---|
| 134 | |
---|
| 135 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 136 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 137 | rtems_test_assert(rtems_filesystem_location_is_null(&local_loc)); |
---|
| 138 | rtems_test_assert_equal_to_null_loc(&local_loc); |
---|
| 139 | |
---|
| 140 | rtems_filesystem_location_free(&local_loc); |
---|
| 141 | |
---|
| 142 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 143 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | static void test_null_location_get_and_replace(void) |
---|
| 147 | { |
---|
| 148 | rtems_filesystem_global_location_t *null_loc = |
---|
| 149 | &rtems_filesystem_global_location_null; |
---|
| 150 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 151 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 152 | rtems_filesystem_location_info_t local_loc_0; |
---|
| 153 | rtems_filesystem_location_info_t local_loc_1; |
---|
| 154 | |
---|
| 155 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 156 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 157 | |
---|
| 158 | rtems_filesystem_location_copy(&local_loc_0, &null_loc->location); |
---|
| 159 | |
---|
| 160 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 161 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 162 | rtems_test_assert_equal_to_null_loc(&local_loc_0); |
---|
| 163 | |
---|
| 164 | rtems_filesystem_location_copy_and_detach(&local_loc_1, &local_loc_0); |
---|
| 165 | |
---|
| 166 | rtems_test_assert(node_count(loc_chain) == 3); |
---|
| 167 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 168 | rtems_test_assert_equal_to_null_loc(&local_loc_0); |
---|
| 169 | rtems_test_assert_equal_to_null_loc(&local_loc_1); |
---|
| 170 | |
---|
| 171 | rtems_filesystem_location_free(&local_loc_0); |
---|
| 172 | |
---|
| 173 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 174 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 175 | rtems_test_assert_equal_to_null_loc(&local_loc_1); |
---|
| 176 | |
---|
| 177 | rtems_filesystem_location_free(&local_loc_1); |
---|
| 178 | |
---|
| 179 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 180 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | static void test_path_ops(void) |
---|
| 184 | { |
---|
| 185 | int rv = 0; |
---|
| 186 | long lrv = 0; |
---|
| 187 | struct stat st; |
---|
| 188 | struct statvfs stvfs; |
---|
| 189 | char buf [32]; |
---|
| 190 | ssize_t n = 0; |
---|
| 191 | const char *path = "/"; |
---|
| 192 | const struct utimbuf times; |
---|
| 193 | |
---|
| 194 | errno = 0; |
---|
| 195 | rv = open(path, O_RDONLY); |
---|
| 196 | rtems_test_assert(rv == -1); |
---|
| 197 | rtems_test_assert(errno == ENXIO); |
---|
| 198 | |
---|
| 199 | errno = 0; |
---|
| 200 | rv = chdir(path); |
---|
| 201 | rtems_test_assert(rv == -1); |
---|
| 202 | rtems_test_assert(errno == ENXIO); |
---|
| 203 | |
---|
| 204 | errno = 0; |
---|
| 205 | rv = chroot(path); |
---|
| 206 | rtems_test_assert(rv == -1); |
---|
| 207 | rtems_test_assert(errno == ENXIO); |
---|
| 208 | |
---|
| 209 | errno = 0; |
---|
| 210 | rv = mknod(path, S_IFREG, 0); |
---|
| 211 | rtems_test_assert(rv == -1); |
---|
| 212 | rtems_test_assert(errno == ENXIO); |
---|
| 213 | |
---|
| 214 | errno = 0; |
---|
| 215 | rv = mkdir(path, 0); |
---|
| 216 | rtems_test_assert(rv == -1); |
---|
| 217 | rtems_test_assert(errno == ENXIO); |
---|
| 218 | |
---|
| 219 | errno = 0; |
---|
| 220 | rv = mkfifo(path, 0); |
---|
| 221 | rtems_test_assert(rv == -1); |
---|
| 222 | rtems_test_assert(errno == ENXIO); |
---|
| 223 | |
---|
| 224 | errno = 0; |
---|
| 225 | rv = stat(path, &st); |
---|
| 226 | rtems_test_assert(rv == -1); |
---|
| 227 | rtems_test_assert(errno == ENXIO); |
---|
| 228 | |
---|
| 229 | errno = 0; |
---|
| 230 | rv = lstat(path, &st); |
---|
| 231 | rtems_test_assert(rv == -1); |
---|
| 232 | rtems_test_assert(errno == ENXIO); |
---|
| 233 | |
---|
| 234 | errno = 0; |
---|
| 235 | rv = statvfs(path, &stvfs); |
---|
| 236 | rtems_test_assert(rv == -1); |
---|
| 237 | rtems_test_assert(errno == ENXIO); |
---|
| 238 | |
---|
| 239 | errno = 0; |
---|
| 240 | n = readlink(path, buf, sizeof(buf)); |
---|
| 241 | rtems_test_assert(n == -1); |
---|
| 242 | rtems_test_assert(errno == ENXIO); |
---|
| 243 | |
---|
| 244 | errno = 0; |
---|
| 245 | rv = chmod(path, 0); |
---|
| 246 | rtems_test_assert(rv == -1); |
---|
| 247 | rtems_test_assert(errno == ENXIO); |
---|
| 248 | |
---|
| 249 | errno = 0; |
---|
| 250 | rv = chown(path, 0, 0); |
---|
| 251 | rtems_test_assert(rv == -1); |
---|
| 252 | rtems_test_assert(errno == ENXIO); |
---|
| 253 | |
---|
| 254 | errno = 0; |
---|
| 255 | rv = lchown(path, 0, 0); |
---|
| 256 | rtems_test_assert(rv == -1); |
---|
| 257 | rtems_test_assert(errno == ENXIO); |
---|
| 258 | |
---|
| 259 | errno = 0; |
---|
| 260 | rv = rmdir(path); |
---|
| 261 | rtems_test_assert(rv == -1); |
---|
| 262 | rtems_test_assert(errno == ENXIO); |
---|
| 263 | |
---|
| 264 | errno = 0; |
---|
| 265 | rv = unlink(path); |
---|
| 266 | rtems_test_assert(rv == -1); |
---|
| 267 | rtems_test_assert(errno == ENXIO); |
---|
| 268 | |
---|
| 269 | errno = 0; |
---|
| 270 | rv = truncate(path, 0); |
---|
| 271 | rtems_test_assert(rv == -1); |
---|
| 272 | rtems_test_assert(errno == ENXIO); |
---|
| 273 | |
---|
| 274 | errno = 0; |
---|
| 275 | rv = access(path, 0); |
---|
| 276 | rtems_test_assert(rv == -1); |
---|
| 277 | rtems_test_assert(errno == ENXIO); |
---|
| 278 | |
---|
| 279 | errno = 0; |
---|
| 280 | lrv = pathconf(path, _PC_LINK_MAX); |
---|
| 281 | rtems_test_assert(lrv == -1); |
---|
| 282 | rtems_test_assert(errno == ENXIO); |
---|
| 283 | |
---|
| 284 | errno = 0; |
---|
| 285 | rv = link(path, path); |
---|
| 286 | rtems_test_assert(rv == -1); |
---|
| 287 | rtems_test_assert(errno == ENXIO); |
---|
| 288 | |
---|
| 289 | errno = 0; |
---|
| 290 | rv = symlink(path, path); |
---|
| 291 | rtems_test_assert(rv == -1); |
---|
| 292 | rtems_test_assert(errno == ENXIO); |
---|
| 293 | |
---|
| 294 | errno = 0; |
---|
| 295 | rv = rename(path, path); |
---|
| 296 | rtems_test_assert(rv == -1); |
---|
| 297 | rtems_test_assert(errno == ENXIO); |
---|
| 298 | |
---|
| 299 | errno = 0; |
---|
| 300 | rv = utime(path, ×); |
---|
| 301 | rtems_test_assert(rv == -1); |
---|
| 302 | rtems_test_assert(errno == ENXIO); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | static void test_user_env(void) |
---|
| 306 | { |
---|
| 307 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 308 | rtems_filesystem_global_location_t *null_loc = |
---|
| 309 | &rtems_filesystem_global_location_null; |
---|
| 310 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 311 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 312 | |
---|
| 313 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 314 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 315 | |
---|
| 316 | sc = rtems_libio_set_private_env(); |
---|
| 317 | rtems_test_assert(sc == RTEMS_UNSATISFIED); |
---|
| 318 | |
---|
| 319 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 320 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 321 | |
---|
| 322 | rtems_libio_use_global_env(); |
---|
| 323 | |
---|
| 324 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 325 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 326 | } |
---|
| 327 | |
---|
[b8bd90f6] | 328 | typedef struct { |
---|
| 329 | int flags; |
---|
| 330 | mode_t object_mode; |
---|
| 331 | uid_t object_uid; |
---|
| 332 | gid_t object_gid; |
---|
| 333 | bool expected_ok; |
---|
| 334 | } check_access_case; |
---|
| 335 | |
---|
| 336 | #define FR RTEMS_FS_PERMS_READ |
---|
| 337 | #define FW RTEMS_FS_PERMS_WRITE |
---|
| 338 | #define FX RTEMS_FS_PERMS_EXEC |
---|
| 339 | |
---|
| 340 | #define UR S_IRUSR |
---|
| 341 | #define UW S_IWUSR |
---|
| 342 | #define UX S_IXUSR |
---|
| 343 | |
---|
| 344 | #define GR S_IRGRP |
---|
| 345 | #define GW S_IWGRP |
---|
| 346 | #define GX S_IXGRP |
---|
| 347 | |
---|
| 348 | #define OR S_IROTH |
---|
| 349 | #define OW S_IWOTH |
---|
| 350 | #define OX S_IXOTH |
---|
| 351 | |
---|
| 352 | static const check_access_case check_access_euid_0_cases[] = { |
---|
| 353 | { 0, 0, 6, 7, true }, |
---|
| 354 | { FR, 0, 6, 7, false }, |
---|
| 355 | { FW, 0, 6, 7, false }, |
---|
| 356 | { FX, 0, 6, 7, false }, |
---|
| 357 | { FR, UR, 6, 7, true }, |
---|
| 358 | { FW, UW, 6, 7, true }, |
---|
| 359 | { FX, UX, 6, 7, true }, |
---|
| 360 | { FR, GR, 6, 7, false }, |
---|
| 361 | { FW, GW, 6, 7, false }, |
---|
| 362 | { FX, GX, 6, 7, false }, |
---|
| 363 | { FR, OR, 6, 7, false }, |
---|
| 364 | { FW, OW, 6, 7, false }, |
---|
| 365 | { FX, OX, 6, 7, false } |
---|
| 366 | }; |
---|
| 367 | |
---|
| 368 | static const check_access_case check_access_egid_0_cases[] = { |
---|
| 369 | { 0, 0, 6, 7, true }, |
---|
| 370 | { FR, 0, 6, 7, false }, |
---|
| 371 | { FW, 0, 6, 7, false }, |
---|
| 372 | { FX, 0, 6, 7, false }, |
---|
| 373 | { FR, UR, 6, 7, false }, |
---|
| 374 | { FW, UW, 6, 7, false }, |
---|
| 375 | { FX, UX, 6, 7, false }, |
---|
| 376 | { FR, GR, 6, 7, true }, |
---|
| 377 | { FW, GW, 6, 7, true }, |
---|
| 378 | { FX, GX, 6, 7, true }, |
---|
| 379 | { FR, OR, 6, 7, false }, |
---|
| 380 | { FW, OW, 6, 7, false }, |
---|
| 381 | { FX, OX, 6, 7, false } |
---|
| 382 | }; |
---|
| 383 | |
---|
| 384 | static const check_access_case check_access_other_cases[] = { |
---|
| 385 | { 0, 0, 3, 7, true }, |
---|
| 386 | { FR, 0, 3, 7, false }, |
---|
| 387 | { FW, 0, 3, 7, false }, |
---|
| 388 | { FX, 0, 3, 7, false }, |
---|
| 389 | { FR, UR, 3, 7, true }, |
---|
| 390 | { FW, UW, 3, 7, true }, |
---|
| 391 | { FX, UX, 3, 7, true }, |
---|
| 392 | { FR, GR, 3, 7, false }, |
---|
| 393 | { FW, GW, 3, 7, false }, |
---|
| 394 | { FX, GX, 3, 7, false }, |
---|
| 395 | { FR, OR, 3, 7, false }, |
---|
| 396 | { FW, OW, 3, 7, false }, |
---|
| 397 | { FX, OX, 3, 7, false }, |
---|
| 398 | { 0, 0, 6, 4, true }, |
---|
| 399 | { FR, 0, 6, 4, false }, |
---|
| 400 | { FW, 0, 6, 4, false }, |
---|
| 401 | { FX, 0, 6, 4, false }, |
---|
| 402 | { FR, UR, 6, 4, false }, |
---|
| 403 | { FW, UW, 6, 4, false }, |
---|
| 404 | { FX, UX, 6, 4, false }, |
---|
| 405 | { FR, GR, 6, 4, true }, |
---|
| 406 | { FW, GW, 6, 4, true }, |
---|
| 407 | { FX, GX, 6, 4, true }, |
---|
| 408 | { FR, OR, 6, 4, false }, |
---|
| 409 | { FW, OW, 6, 4, false }, |
---|
| 410 | { FX, OX, 6, 4, false }, |
---|
| 411 | { 0, 0, 6, 5, true }, |
---|
| 412 | { FR, 0, 6, 5, false }, |
---|
| 413 | { FW, 0, 6, 5, false }, |
---|
| 414 | { FX, 0, 6, 5, false }, |
---|
| 415 | { FR, UR, 6, 5, false }, |
---|
| 416 | { FW, UW, 6, 5, false }, |
---|
| 417 | { FX, UX, 6, 5, false }, |
---|
| 418 | { FR, GR, 6, 5, true }, |
---|
| 419 | { FW, GW, 6, 5, true }, |
---|
| 420 | { FX, GX, 6, 5, true }, |
---|
| 421 | { FR, OR, 6, 5, false }, |
---|
| 422 | { FW, OW, 6, 5, false }, |
---|
| 423 | { FX, OX, 6, 5, false }, |
---|
| 424 | { 0, 0, 6, 7, true }, |
---|
| 425 | { FR, 0, 6, 7, false }, |
---|
| 426 | { FW, 0, 6, 7, false }, |
---|
| 427 | { FX, 0, 6, 7, false }, |
---|
| 428 | { FR, UR, 6, 7, false }, |
---|
| 429 | { FW, UW, 6, 7, false }, |
---|
| 430 | { FX, UX, 6, 7, false }, |
---|
| 431 | { FR, GR, 6, 7, false }, |
---|
| 432 | { FW, GW, 6, 7, false }, |
---|
| 433 | { FX, GX, 6, 7, false }, |
---|
| 434 | { FR, OR, 6, 7, true }, |
---|
| 435 | { FW, OW, 6, 7, true }, |
---|
| 436 | { FX, OX, 6, 7, true } |
---|
| 437 | }; |
---|
| 438 | |
---|
| 439 | static void check_access(const check_access_case *table, size_t n) |
---|
| 440 | { |
---|
| 441 | size_t i; |
---|
| 442 | |
---|
| 443 | for (i = 0; i < n; ++i) { |
---|
| 444 | const check_access_case *cac = &table[i]; |
---|
| 445 | bool ok = rtems_filesystem_check_access( |
---|
| 446 | cac->flags, |
---|
| 447 | cac->object_mode, |
---|
| 448 | cac->object_uid, |
---|
| 449 | cac->object_gid |
---|
| 450 | ); |
---|
| 451 | |
---|
| 452 | rtems_test_assert(ok == cac->expected_ok); |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | static void test_check_access(void) |
---|
| 457 | { |
---|
| 458 | rtems_user_env_t *uenv = rtems_current_user_env_get(); |
---|
| 459 | |
---|
| 460 | rtems_test_assert(uenv->uid == 0); |
---|
| 461 | rtems_test_assert(uenv->gid == 0); |
---|
| 462 | rtems_test_assert(uenv->euid == 0); |
---|
| 463 | rtems_test_assert(uenv->egid == 0); |
---|
| 464 | rtems_test_assert(uenv->ngroups == 0); |
---|
| 465 | |
---|
| 466 | uenv->uid = 1; |
---|
| 467 | uenv->gid = 2; |
---|
| 468 | |
---|
| 469 | check_access( |
---|
| 470 | &check_access_euid_0_cases[0], |
---|
| 471 | RTEMS_ARRAY_SIZE(check_access_euid_0_cases) |
---|
| 472 | ); |
---|
| 473 | |
---|
| 474 | uenv->euid = 3; |
---|
| 475 | |
---|
| 476 | check_access( |
---|
| 477 | &check_access_egid_0_cases[0], |
---|
| 478 | RTEMS_ARRAY_SIZE(check_access_egid_0_cases) |
---|
| 479 | ); |
---|
| 480 | |
---|
| 481 | uenv->egid = 4; |
---|
| 482 | uenv->ngroups = 1; |
---|
| 483 | uenv->groups[0] = 5; |
---|
| 484 | |
---|
| 485 | check_access( |
---|
| 486 | &check_access_other_cases[0], |
---|
| 487 | RTEMS_ARRAY_SIZE(check_access_other_cases) |
---|
| 488 | ); |
---|
| 489 | |
---|
| 490 | uenv->uid = 0; |
---|
| 491 | uenv->gid = 0; |
---|
| 492 | uenv->euid = 0; |
---|
| 493 | uenv->egid = 0; |
---|
| 494 | uenv->ngroups = 0; |
---|
| 495 | } |
---|
| 496 | |
---|
[3b7c123] | 497 | static void Init(rtems_task_argument arg) |
---|
| 498 | { |
---|
[24d0ee57] | 499 | TEST_BEGIN(); |
---|
[3b7c123] | 500 | |
---|
| 501 | test_initial_values(); |
---|
| 502 | test_location_obtain(); |
---|
| 503 | test_null_location_obtain(); |
---|
| 504 | test_null_location_replace(); |
---|
| 505 | test_null_location_get_and_replace(); |
---|
| 506 | test_path_ops(); |
---|
| 507 | test_user_env(); |
---|
[b8bd90f6] | 508 | test_check_access(); |
---|
[3b7c123] | 509 | |
---|
[24d0ee57] | 510 | TEST_END(); |
---|
[3b7c123] | 511 | exit(0); |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 515 | |
---|
| 516 | #define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM |
---|
| 517 | |
---|
| 518 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 519 | |
---|
[bc75887] | 520 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 521 | |
---|
[3b7c123] | 522 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 523 | |
---|
| 524 | #define CONFIGURE_INIT |
---|
| 525 | |
---|
| 526 | #include <rtems/confdefs.h> |
---|