1/* 2 * Copyright (c) International Business Machines Corp., 2004 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12 * the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19/* 20 * TEST CASE : right.c 21 * 22 * VARIATIONS : 63 23 * 24 * API'S TESTED : dm_request_right 25 * dm_release_right 26 * dm_query_right 27 * dm_upgrade_right 28 * dm_downgrade_right 29 */ 30#include <string.h> 31#include <stdio.h> 32#include <errno.h> 33#include <pthread.h> 34#include <unistd.h> 35#include <sys/stat.h> 36#include <sys/mount.h> 37#include <fcntl.h> 38#include "dm_test.h" 39 40pthread_t tid; 41dm_sessid_t sid; 42char dmMsgBuf[4096]; 43char command[4096]; 44char *mountPt; 45char *deviceNm; 46char DummyFile[FILENAME_MAX]; 47char DummySubdir[FILENAME_MAX]; 48int fd_f; 49int runTestOnCreate; 50 51void *Thread(void *); 52 53int main(int argc, char **argv) 54{ 55 56 char *varstr; 57 int rc; 58 char *szSessionInfo = "dm_test session info"; 59 dm_eventset_t events; 60 61 DMOPT_PARSE(argc, argv); 62 DMLOG_START(); 63 64 DMEV_ZERO(events); 65 DMEV_SET(DM_EVENT_MOUNT, events); 66 67 /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */ 68 if ((rc = dm_init_service(&varstr)) != 0) { 69 DMLOG_PRINT(DMLVL_ERR, 70 "dm_init_service failed! (rc = %d, errno = %d)\n", 71 rc, errno); 72 DM_EXIT(); 73 } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) 74 == -1) { 75 DMLOG_PRINT(DMLVL_ERR, 76 "dm_create_session failed! (rc = %d, errno = %d)\n", 77 rc, errno); 78 DM_EXIT(); 79 } else 80 if ((rc = 81 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, 82 &events, DM_EVENT_MAX)) == -1) { 83 DMLOG_PRINT(DMLVL_ERR, 84 "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, 85 errno); 86 dm_destroy_session(sid); 87 DM_EXIT(); 88 } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) { 89 DMLOG_PRINT(DMLVL_ERR, 90 "pthread_create failed! (rc = %d, errno = %d)\n", 91 rc, errno); 92 dm_destroy_session(sid); 93 DM_EXIT(); 94 } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) { 95 DMLOG_PRINT(DMLVL_ERR, 96 "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, 97 errno); 98 dm_destroy_session(sid); 99 DM_EXIT(); 100 } else { 101 sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE); 102 sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR); 103 104 remove(DummyFile); 105 rmdir(DummySubdir); 106 } 107 108 fd_f = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); 109 if (fd_f == -1) { 110 DMLOG_PRINT(DMLVL_ERR, "open failed! (rc = %d, errno = %d)\n", 111 rc, errno); 112 } 113 114 /* This is what kicks off the test case, variations done in thread */ 115 runTestOnCreate = 1; 116 rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); 117 runTestOnCreate = 0; 118 if (rc == -1) { 119 DMLOG_PRINT(DMLVL_ERR, "mkdir failed! (rc = %d, errno = %d)\n", 120 rc, errno); 121 } 122 123 rc = rmdir(DummySubdir); 124 if (rc == -1) { 125 DMLOG_PRINT(DMLVL_ERR, "rmdir failed! (rc = %d, errno = %d)\n", 126 rc, errno); 127 } 128 129 rc = close(fd_f); 130 if (rc == -1) { 131 DMLOG_PRINT(DMLVL_ERR, "close failed! (rc = %d, errno = %d)\n", 132 rc, errno); 133 } 134 135 rc = remove(DummyFile); 136 if (rc == -1) { 137 DMLOG_PRINT(DMLVL_ERR, "remove failed! (rc = %d, errno = %d)\n", 138 rc, errno); 139 } 140 141 rc = umount(mountPt); 142 if (rc == -1) { 143 DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", 144 rc, errno); 145 } 146 147 pthread_join(tid, NULL); 148 149 rc = dm_destroy_session(sid); 150 if (rc == -1) { 151 DMLOG_PRINT(DMLVL_ERR, 152 "dm_destroy_session failed! (rc = %d, errno = %d)\n", 153 rc, errno); 154 } 155 156 DMLOG_STOP(); 157 158 tst_exit(); 159} 160 161void DoTest(dm_token_t token, void *hanp, size_t hlen) 162{ 163 164 char *szFuncName; 165 int rc; 166 167 DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI rights tests\n"); 168 169 szFuncName = "dm_request_right"; 170 171 /* 172 * TEST : dm_request_right - invalid sid 173 * EXPECTED: rc = -1, errno = EINVAL 174 */ 175 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 1)) { 176 177 /* Variation set up */ 178 179 /* Variation */ 180 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); 181 rc = dm_request_right(INVALID_ADDR, hanp, hlen, token, 0, 182 DM_RIGHT_SHARED); 183 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 184 185 /* Variation clean up */ 186 } 187 188 /* 189 * TEST : dm_request_right - invalid hanp 190 * EXPECTED: rc = -1, errno = EFAULT 191 */ 192 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 2)) { 193 194 /* Variation set up */ 195 196 /* Variation */ 197 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); 198 rc = dm_request_right(sid, (void *)INVALID_ADDR, hlen, token, 0, 199 DM_RIGHT_SHARED); 200 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 201 202 /* Variation clean up */ 203 } 204 205 /* 206 * TEST : dm_request_right - invalid hlen 207 * EXPECTED: rc = -1, errno = EBADF 208 */ 209 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 3)) { 210 211 /* Variation set up */ 212 213 /* Variation */ 214 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); 215 rc = dm_request_right(sid, hanp, INVALID_ADDR, token, 0, 216 DM_RIGHT_SHARED); 217 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 218 219 /* Variation clean up */ 220 } 221 222 /* 223 * TEST : dm_request_right - invalid token 224 * EXPECTED: rc = -1, errno = EINVAL 225 */ 226 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 4)) { 227 228 /* Variation set up */ 229 230 /* Variation */ 231 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); 232 rc = dm_request_right(sid, hanp, hlen, INVALID_ADDR, 0, 233 DM_RIGHT_SHARED); 234 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 235 236 /* Variation clean up */ 237 } 238 239 /* 240 * TEST : dm_request_right - invalid right 241 * EXPECTED: rc = -1, errno = EINVAL 242 * 243 * This variation uncovered XFS BUG #29 (0 returned instead of -1 and 244 * errno EINVAL) 245 */ 246 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 5)) { 247 248 /* Variation set up */ 249 250 /* Variation */ 251 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid right)\n", szFuncName); 252 rc = dm_request_right(sid, hanp, hlen, token, 0, INVALID_ADDR); 253 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 254 255 /* Variation clean up */ 256 } 257 258 /* 259 * TEST : dm_request_right - DM_NO_TOKEN 260 * EXPECTED: rc = -1, errno = EINVAL 261 */ 262 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 6)) { 263 264 /* Variation set up */ 265 266 /* Variation */ 267 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN)\n", szFuncName); 268 rc = dm_request_right(sid, hanp, hlen, DM_NO_TOKEN, 0, 269 DM_RIGHT_SHARED); 270 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 271 272 /* Variation clean up */ 273 } 274 275 /* 276 * TEST : dm_request_right - DM_RIGHT_SHARED from DM_RIGHT_NULL 277 * EXPECTED: rc = 0 278 */ 279 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 7)) { 280 281 /* Variation set up */ 282 283 /* Variation */ 284 DMLOG_PRINT(DMLVL_DEBUG, 285 "%s(DM_RIGHT_NULL -> DM_RIGHT_SHARED)\n", 286 szFuncName); 287 rc = dm_request_right(sid, hanp, hlen, token, 0, 288 DM_RIGHT_SHARED); 289 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 290 291 /* Variation clean up */ 292 rc = dm_release_right(sid, hanp, hlen, token); 293 if (rc == -1) { 294 DMLOG_PRINT(DMLVL_DEBUG, 295 "Unable to clean up variation! (errno = %d)\n", 296 errno); 297 } 298 } 299 300 /* 301 * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_NULL 302 * EXPECTED: rc = 0 303 */ 304 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 8)) { 305 306 /* Variation set up */ 307 308 /* Variation */ 309 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL -> DM_RIGHT_EXCL)\n", 310 szFuncName); 311 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 312 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 313 314 /* Variation clean up */ 315 rc = dm_release_right(sid, hanp, hlen, token); 316 if (rc == -1) { 317 DMLOG_PRINT(DMLVL_DEBUG, 318 "Unable to clean up variation! (errno = %d)\n", 319 errno); 320 } 321 } 322 323 /* 324 * TEST : dm_request_right - DM_RIGHT_SHARED from DM_RIGHT_SHARED 325 * EXPECTED: rc = 0 326 */ 327 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 9)) { 328 329 /* Variation set up */ 330 rc = dm_request_right(sid, hanp, hlen, token, 0, 331 DM_RIGHT_SHARED); 332 if (rc == -1) { 333 DMLOG_PRINT(DMLVL_DEBUG, 334 "Unable to set up variation! (errno = %d)\n", 335 errno); 336 DMVAR_SKIP(); 337 } else { 338 /* Variation */ 339 DMLOG_PRINT(DMLVL_DEBUG, 340 "%s(DM_RIGHT_SHARED -> DM_RIGHT_SHARED)\n", 341 szFuncName); 342 rc = dm_request_right(sid, hanp, hlen, token, 0, 343 DM_RIGHT_SHARED); 344 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 345 346 /* Variation clean up */ 347 rc = dm_release_right(sid, hanp, hlen, token); 348 if (rc == -1) { 349 DMLOG_PRINT(DMLVL_DEBUG, 350 "Unable to clean up variation! (errno = %d)\n", 351 errno); 352 } 353 } 354 } 355 356 /* 357 * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_SHARED, 358 * DM_RR_WAIT clear 359 * EXPECTED: rc = 0 360 */ 361 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 10)) { 362 363 /* Variation set up */ 364 rc = dm_request_right(sid, hanp, hlen, token, 0, 365 DM_RIGHT_SHARED); 366 if (rc == -1) { 367 DMLOG_PRINT(DMLVL_DEBUG, 368 "Unable to set up variation! (errno = %d)\n", 369 errno); 370 DMVAR_SKIP(); 371 } else { 372 /* Variation */ 373 DMLOG_PRINT(DMLVL_DEBUG, 374 "%s(DM_RIGHT_SHARED -> DM_RIGHT_EXCL, DM_RR_WAIT clear)\n", 375 szFuncName); 376 rc = dm_request_right(sid, hanp, hlen, token, 0, 377 DM_RIGHT_EXCL); 378 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 379 380 /* Variation clean up */ 381 rc = dm_release_right(sid, hanp, hlen, token); 382 if (rc == -1) { 383 DMLOG_PRINT(DMLVL_DEBUG, 384 "Unable to clean up variation! (errno = %d)\n", 385 errno); 386 } 387 } 388 } 389 390 /* 391 * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_SHARED, 392 * DM_RR_WAIT set 393 * EXPECTED: rc = -1, errno = EACCES 394 * 395 * This variation uncovered XFS BUG #30 (0 returned instead of -1 and 396 * errno EACCES) 397 */ 398 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 11)) { 399 400 /* Variation set up */ 401 rc = dm_request_right(sid, hanp, hlen, token, 0, 402 DM_RIGHT_SHARED); 403 if (rc == -1) { 404 DMLOG_PRINT(DMLVL_DEBUG, 405 "Unable to set up variation! (errno = %d)\n", 406 errno); 407 DMVAR_SKIP(); 408 } else { 409 /* Variation */ 410 DMLOG_PRINT(DMLVL_DEBUG, 411 "%s(DM_RIGHT_SHARED -> DM_RIGHT_EXCL, DM_RR_WAIT set)\n", 412 szFuncName); 413 rc = dm_request_right(sid, hanp, hlen, token, 414 DM_RR_WAIT, DM_RIGHT_EXCL); 415 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EACCES); 416 417 /* Variation clean up */ 418 rc = dm_release_right(sid, hanp, hlen, token); 419 if (rc == -1) { 420 DMLOG_PRINT(DMLVL_DEBUG, 421 "Unable to clean up variation! (errno = %d)\n", 422 errno); 423 } 424 } 425 } 426 427 /* 428 * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_EXCL 429 * EXPECTED: rc = 0 430 */ 431 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 12)) { 432 433 /* Variation set up */ 434 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 435 if (rc == -1) { 436 DMLOG_PRINT(DMLVL_DEBUG, 437 "Unable to set up variation! (errno = %d)\n", 438 errno); 439 DMVAR_SKIP(); 440 } else { 441 /* Variation */ 442 DMLOG_PRINT(DMLVL_DEBUG, 443 "%s(DM_RIGHT_EXCL -> DM_RIGHT_EXCL)\n", 444 szFuncName); 445 rc = dm_request_right(sid, hanp, hlen, token, 0, 446 DM_RIGHT_SHARED); 447 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 448 449 /* Variation clean up */ 450 rc = dm_release_right(sid, hanp, hlen, token); 451 if (rc == -1) { 452 DMLOG_PRINT(DMLVL_DEBUG, 453 "Unable to clean up variation! (errno = %d)\n", 454 errno); 455 } 456 } 457 } 458 459 /* 460 * TEST : dm_request_right - DM_RIGHT_SHARED from DM_RIGHT_EXCL 461 * EXPECTED: rc = 0 462 */ 463 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 13)) { 464 465 /* Variation set up */ 466 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 467 if (rc == -1) { 468 DMLOG_PRINT(DMLVL_DEBUG, 469 "Unable to set up variation! (errno = %d)\n", 470 errno); 471 DMVAR_SKIP(); 472 } else { 473 /* Variation */ 474 DMLOG_PRINT(DMLVL_DEBUG, 475 "%s(DM_RIGHT_EXCL -> DM_RIGHT_SHARED)\n", 476 szFuncName); 477 rc = dm_request_right(sid, hanp, hlen, token, 0, 478 DM_RIGHT_SHARED); 479 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 480 481 /* Variation clean up */ 482 rc = dm_release_right(sid, hanp, hlen, token); 483 if (rc == -1) { 484 DMLOG_PRINT(DMLVL_DEBUG, 485 "Unable to clean up variation! (errno = %d)\n", 486 errno); 487 } 488 } 489 } 490 491 /* 492 * TEST : dm_request_right - DM_NO_SESSION sid 493 * EXPECTED: rc = -1, errno = EINVAL 494 */ 495 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 14)) { 496 497 /* Variation set up */ 498 499 /* Variation */ 500 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); 501 rc = dm_request_right(DM_NO_SESSION, hanp, hlen, token, 0, 502 DM_RIGHT_SHARED); 503 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 504 505 /* Variation clean up */ 506 } 507 508 /* 509 * TEST : dm_request_right - global handle 510 * EXPECTED: rc = -1, errno = EBADF 511 */ 512 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 15)) { 513 514 /* Variation set up */ 515 516 /* Variation */ 517 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); 518 rc = dm_request_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, 519 token, 0, DM_RIGHT_SHARED); 520 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 521 522 /* Variation clean up */ 523 } 524 525 /* 526 * TEST : dm_request_right - file handle 527 * EXPECTED: rc = 0 528 */ 529 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 16)) { 530 void *fhanp; 531 size_t fhlen; 532 533 /* Variation set up */ 534 rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen); 535 if (rc == -1) { 536 DMLOG_PRINT(DMLVL_DEBUG, 537 "Unable to set up variation! (errno = %d)\n", 538 errno); 539 DMVAR_SKIP(); 540 } else { 541 /* Variation */ 542 DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", 543 szFuncName); 544 rc = dm_request_right(sid, fhanp, fhlen, token, 0, 545 DM_RIGHT_SHARED); 546 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 547 548 /* Variation clean up */ 549 rc = dm_release_right(sid, fhanp, fhlen, token); 550 if (rc == -1) { 551 DMLOG_PRINT(DMLVL_DEBUG, 552 "Unable to clean up variation! (errno = %d)\n", 553 errno); 554 } 555 dm_handle_free(fhanp, fhlen); 556 } 557 } 558 559 /* 560 * TEST : dm_request_right - fs handle 561 * EXPECTED: rc = 0 562 */ 563 if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 17)) { 564 void *fshanp; 565 size_t fshlen; 566 567 /* Variation set up */ 568 rc = dm_path_to_fshandle(DummyFile, &fshanp, &fshlen); 569 if (rc == -1) { 570 DMLOG_PRINT(DMLVL_DEBUG, 571 "Unable to set up variation! (errno = %d)\n", 572 errno); 573 DMVAR_SKIP(); 574 } else { 575 /* Variation */ 576 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 577 rc = dm_request_right(sid, fshanp, fshlen, token, 0, 578 DM_RIGHT_SHARED); 579 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 580 581 /* Variation clean up */ 582 rc = dm_release_right(sid, fshanp, fshlen, token); 583 if (rc == -1) { 584 DMLOG_PRINT(DMLVL_DEBUG, 585 "Unable to clean up variation! (errno = %d)\n", 586 errno); 587 } 588 dm_handle_free(fshanp, fshlen); 589 } 590 } 591 592 szFuncName = "dm_release_right"; 593 594 /* 595 * TEST : dm_release_right - invalid sid 596 * EXPECTED: rc = -1, errno = EINVAL 597 */ 598 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 1)) { 599 600 /* Variation set up */ 601 602 /* Variation */ 603 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); 604 rc = dm_release_right(INVALID_ADDR, hanp, hlen, token); 605 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 606 607 /* Variation clean up */ 608 } 609 610 /* 611 * TEST : dm_release_right - invalid hanp 612 * EXPECTED: rc = -1, errno = EFAULT 613 */ 614 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 2)) { 615 616 /* Variation set up */ 617 618 /* Variation */ 619 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); 620 rc = dm_release_right(sid, (void *)INVALID_ADDR, hlen, token); 621 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 622 623 /* Variation clean up */ 624 } 625 626 /* 627 * TEST : dm_release_right - invalid hlen 628 * EXPECTED: rc = -1, errno = EBADF 629 */ 630 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 3)) { 631 632 /* Variation set up */ 633 634 /* Variation */ 635 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); 636 rc = dm_release_right(sid, hanp, INVALID_ADDR, token); 637 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 638 639 /* Variation clean up */ 640 } 641 642 /* 643 * TEST : dm_release_right - invalid token 644 * EXPECTED: rc = -1, errno = EINVAL 645 */ 646 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 4)) { 647 648 /* Variation set up */ 649 650 /* Variation */ 651 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); 652 rc = dm_release_right(sid, hanp, hlen, INVALID_ADDR); 653 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 654 655 /* Variation clean up */ 656 } 657 658 /* 659 * TEST : dm_release_right - DM_NO_TOKEN 660 * EXPECTED: rc = -1, errno = EINVAL 661 */ 662 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 5)) { 663 664 /* Variation set up */ 665 666 /* Variation */ 667 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN)\n", szFuncName); 668 rc = dm_release_right(sid, hanp, hlen, DM_NO_TOKEN); 669 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 670 671 /* Variation clean up */ 672 } 673 674 /* 675 * TEST : dm_release_right - DM_RIGHT_NULL 676 * EXPECTED: rc = -1, errno = EACCES 677 */ 678 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 6)) { 679 680 /* Variation set up */ 681 682 /* Variation */ 683 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL)\n", szFuncName); 684 rc = dm_release_right(sid, hanp, hlen, token); 685 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EACCES); 686 687 /* Variation clean up */ 688 } 689 690 /* 691 * TEST : dm_release_right - DM_RIGHT_SHARED 692 * EXPECTED: rc = 0 693 */ 694 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 7)) { 695 696 /* Variation set up */ 697 rc = dm_request_right(sid, hanp, hlen, token, 0, 698 DM_RIGHT_SHARED); 699 if (rc == -1) { 700 DMLOG_PRINT(DMLVL_DEBUG, 701 "Unable to set up variation! (errno = %d)\n", 702 errno); 703 DMVAR_SKIP(); 704 } else { 705 /* Variation */ 706 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", 707 szFuncName); 708 rc = dm_release_right(sid, hanp, hlen, token); 709 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 710 711 /* Variation clean up */ 712 } 713 } 714 715 /* 716 * TEST : dm_release_right - DM_RIGHT_EXCL 717 * EXPECTED: rc = 0 718 */ 719 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 8)) { 720 721 /* Variation set up */ 722 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 723 if (rc == -1) { 724 DMLOG_PRINT(DMLVL_DEBUG, 725 "Unable to set up variation! (errno = %d)\n", 726 errno); 727 DMVAR_SKIP(); 728 } else { 729 /* Variation */ 730 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL)\n", 731 szFuncName); 732 rc = dm_release_right(sid, hanp, hlen, token); 733 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 734 735 /* Variation clean up */ 736 } 737 } 738 739 /* 740 * TEST : dm_release_right - DM_NO_SESSION sid 741 * EXPECTED: rc = -1, errno = EINVAL 742 */ 743 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 9)) { 744 745 /* Variation set up */ 746 747 /* Variation */ 748 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); 749 rc = dm_release_right(DM_NO_SESSION, hanp, hlen, token); 750 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 751 752 /* Variation clean up */ 753 } 754 755 /* 756 * TEST : dm_release_right - global handle 757 * EXPECTED: rc = -1, errno = EBADF 758 */ 759 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 10)) { 760 761 /* Variation set up */ 762 763 /* Variation */ 764 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); 765 rc = dm_release_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, 766 token); 767 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 768 769 /* Variation clean up */ 770 } 771 772 /* 773 * TEST : dm_release_right - file handle 774 * EXPECTED: rc = 0 775 */ 776 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 11)) { 777 void *fhanp; 778 size_t fhlen; 779 780 /* Variation set up */ 781 if ((rc == dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { 782 /* No clean up */ 783 } else 784 if ((rc = 785 dm_request_right(sid, fhanp, fhlen, token, 0, 786 DM_RIGHT_SHARED)) == -1) { 787 dm_handle_free(fhanp, fhlen); 788 } 789 if (rc == -1) { 790 DMLOG_PRINT(DMLVL_DEBUG, 791 "Unable to set up variation! (errno = %d)\n", 792 errno); 793 DMVAR_SKIP(); 794 } else { 795 /* Variation */ 796 DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", 797 szFuncName); 798 rc = dm_release_right(sid, fhanp, fhlen, token); 799 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 800 801 /* Variation clean up */ 802 dm_handle_free(fhanp, fhlen); 803 } 804 } 805 806 /* 807 * TEST : dm_release_right - fs handle 808 * EXPECTED: rc = 0 809 */ 810 if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 12)) { 811 void *fshanp; 812 size_t fshlen; 813 814 /* Variation set up */ 815 if ((rc == dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == 816 -1) { 817 /* No clean up */ 818 } else 819 if ((rc = 820 dm_request_right(sid, fshanp, fshlen, token, 0, 821 DM_RIGHT_SHARED)) == -1) { 822 dm_handle_free(fshanp, fshlen); 823 } 824 if (rc == -1) { 825 DMLOG_PRINT(DMLVL_DEBUG, 826 "Unable to set up variation! (errno = %d)\n", 827 errno); 828 DMVAR_SKIP(); 829 } else { 830 /* Variation */ 831 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 832 rc = dm_release_right(sid, fshanp, fshlen, token); 833 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 834 835 /* Variation clean up */ 836 dm_handle_free(fshanp, fshlen); 837 } 838 } 839 840 szFuncName = "dm_query_right"; 841 842 /* 843 * TEST : dm_query_right - invalid sid 844 * EXPECTED: rc = -1, errno = EINVAL 845 */ 846 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 1)) { 847 dm_right_t right; 848 849 /* Variation set up */ 850 851 /* Variation */ 852 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); 853 rc = dm_query_right(INVALID_ADDR, hanp, hlen, token, &right); 854 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 855 856 /* Variation clean up */ 857 } 858 859 /* 860 * TEST : dm_query_right - invalid hanp 861 * EXPECTED: rc = -1, errno = EFAULT 862 */ 863 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 2)) { 864 dm_right_t right; 865 866 /* Variation set up */ 867 868 /* Variation */ 869 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); 870 rc = dm_query_right(sid, (void *)INVALID_ADDR, hlen, token, 871 &right); 872 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 873 874 /* Variation clean up */ 875 } 876 877 /* 878 * TEST : dm_query_right - invalid hlen 879 * EXPECTED: rc = -1, errno = EBADF 880 */ 881 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 3)) { 882 dm_right_t right; 883 884 /* Variation set up */ 885 886 /* Variation */ 887 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); 888 rc = dm_query_right(sid, hanp, INVALID_ADDR, token, &right); 889 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 890 891 /* Variation clean up */ 892 } 893 894 /* 895 * TEST : dm_query_right - invalid token 896 * EXPECTED: rc = -1, errno = EINVAL 897 */ 898 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 4)) { 899 dm_right_t right; 900 901 /* Variation set up */ 902 903 /* Variation */ 904 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); 905 rc = dm_query_right(sid, hanp, hlen, INVALID_ADDR, &right); 906 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 907 908 /* Variation clean up */ 909 } 910 911 /* 912 * TEST : dm_query_right - invalid rightp 913 * EXPECTED: rc = -1, errno = EFAULT 914 */ 915 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 5)) { 916 917 /* Variation set up */ 918 919 /* Variation */ 920 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rightp)\n", szFuncName); 921 rc = dm_query_right(sid, hanp, hlen, token, 922 (dm_right_t *) INVALID_ADDR); 923 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 924 925 /* Variation clean up */ 926 } 927 928 /* 929 * TEST : dm_query_right - DM_NO_TOKEN 930 * EXPECTED: rc = -1, errno = EINVAL 931 */ 932 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 6)) { 933 dm_right_t right; 934 935 /* Variation set up */ 936 937 /* Variation */ 938 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN)\n", szFuncName); 939 rc = dm_query_right(sid, hanp, hlen, DM_NO_TOKEN, &right); 940 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 941 942 /* Variation clean up */ 943 } 944 945 /* 946 * TEST : dm_query_right - DM_RIGHT_SHARED 947 * EXPECTED: rc = 0 948 */ 949 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 7)) { 950 dm_right_t right; 951 952 /* Variation set up */ 953 rc = dm_request_right(sid, hanp, hlen, token, 0, 954 DM_RIGHT_SHARED); 955 if (rc == -1) { 956 DMLOG_PRINT(DMLVL_DEBUG, 957 "Unable to set up variation! (errno = %d)\n", 958 errno); 959 DMVAR_SKIP(); 960 } else { 961 /* Variation */ 962 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", 963 szFuncName); 964 rc = dm_query_right(sid, hanp, hlen, token, &right); 965 if (rc == 0) { 966 if (right == DM_RIGHT_SHARED) { 967 DMLOG_PRINT(DMLVL_DEBUG, 968 "%s passed with expected rc = %d\n", 969 szFuncName, 0); 970 DMVAR_PASS(); 971 } else { 972 DMLOG_PRINT(DMLVL_ERR, 973 "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", 974 szFuncName, 0, right, 975 DM_RIGHT_SHARED); 976 DMVAR_FAIL(); 977 } 978 } else { 979 DMLOG_PRINT(DMLVL_ERR, 980 "%s failed with unexpected rc = %d (errno = %d)\n", 981 szFuncName, rc, errno); 982 DMVAR_FAIL(); 983 } 984 985 /* Variation clean up */ 986 rc = dm_release_right(sid, hanp, hlen, token); 987 if (rc == -1) { 988 DMLOG_PRINT(DMLVL_DEBUG, 989 "Unable to clean up variation! (errno = %d)\n", 990 errno); 991 } 992 } 993 } 994 995 /* 996 * TEST : dm_query_right - DM_RIGHT_EXCL 997 * EXPECTED: rc = 0 998 */ 999 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 8)) { 1000 dm_right_t right; 1001 1002 /* Variation set up */ 1003 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 1004 if (rc == -1) { 1005 DMLOG_PRINT(DMLVL_DEBUG, 1006 "Unable to set up variation! (errno = %d)\n", 1007 errno); 1008 DMVAR_SKIP(); 1009 } else { 1010 /* Variation */ 1011 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", 1012 szFuncName); 1013 rc = dm_query_right(sid, hanp, hlen, token, &right); 1014 if (rc == 0) { 1015 if (right == DM_RIGHT_EXCL) { 1016 DMLOG_PRINT(DMLVL_DEBUG, 1017 "%s passed with expected rc = %d\n", 1018 szFuncName, 0); 1019 DMVAR_PASS(); 1020 } else { 1021 DMLOG_PRINT(DMLVL_ERR, 1022 "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", 1023 szFuncName, 0, right, 1024 DM_RIGHT_EXCL); 1025 DMVAR_FAIL(); 1026 } 1027 } else { 1028 DMLOG_PRINT(DMLVL_ERR, 1029 "%s failed with unexpected rc = %d (errno = %d)\n", 1030 szFuncName, rc, errno); 1031 DMVAR_FAIL(); 1032 } 1033 1034 /* Variation clean up */ 1035 rc = dm_release_right(sid, hanp, hlen, token); 1036 if (rc == -1) { 1037 DMLOG_PRINT(DMLVL_DEBUG, 1038 "Unable to clean up variation! (errno = %d)\n", 1039 errno); 1040 } 1041 } 1042 } 1043 1044 /* 1045 * TEST : dm_query_right - DM_NO_SESSION sid 1046 * EXPECTED: rc = -1, errno = EINVAL 1047 */ 1048 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 9)) { 1049 dm_right_t right; 1050 1051 /* Variation set up */ 1052 1053 /* Variation */ 1054 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); 1055 rc = dm_query_right(DM_NO_SESSION, hanp, hlen, token, &right); 1056 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1057 1058 /* Variation clean up */ 1059 } 1060 1061 /* 1062 * TEST : dm_query_right - global handle 1063 * EXPECTED: rc = -1, errno = EBADF 1064 */ 1065 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 10)) { 1066 dm_right_t right; 1067 1068 /* Variation set up */ 1069 1070 /* Variation */ 1071 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); 1072 rc = dm_query_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, token, 1073 &right); 1074 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1075 1076 /* Variation clean up */ 1077 } 1078 1079 /* 1080 * TEST : dm_query_right - file handle 1081 * EXPECTED: rc = 0 1082 */ 1083 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 11)) { 1084 void *fhanp; 1085 size_t fhlen; 1086 dm_right_t right; 1087 1088 /* Variation set up */ 1089 if ((rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { 1090 /* No clean up */ 1091 } else 1092 if ((rc = 1093 dm_request_right(sid, fhanp, fhlen, token, 0, 1094 DM_RIGHT_SHARED)) == -1) { 1095 dm_handle_free(fhanp, fhlen); 1096 } 1097 if (rc == -1) { 1098 DMLOG_PRINT(DMLVL_DEBUG, 1099 "Unable to set up variation! (errno = %d)\n", 1100 errno); 1101 DMVAR_SKIP(); 1102 } else { 1103 /* Variation */ 1104 DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", 1105 szFuncName); 1106 rc = dm_query_right(sid, fhanp, fhlen, token, &right); 1107 if (rc == 0) { 1108 if (right == DM_RIGHT_SHARED) { 1109 DMLOG_PRINT(DMLVL_DEBUG, 1110 "%s passed with expected rc = %d\n", 1111 szFuncName, 0); 1112 DMVAR_PASS(); 1113 } else { 1114 DMLOG_PRINT(DMLVL_ERR, 1115 "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", 1116 szFuncName, 0, right, 1117 DM_RIGHT_SHARED); 1118 DMVAR_FAIL(); 1119 } 1120 } else { 1121 DMLOG_PRINT(DMLVL_ERR, 1122 "%s failed with unexpected rc = %d (errno = %d)\n", 1123 szFuncName, rc, errno); 1124 DMVAR_FAIL(); 1125 } 1126 1127 /* Variation clean up */ 1128 rc = dm_release_right(sid, fhanp, fhlen, token); 1129 if (rc == -1) { 1130 DMLOG_PRINT(DMLVL_DEBUG, 1131 "Unable to clean up variation! (errno = %d)\n", 1132 errno); 1133 } 1134 dm_handle_free(fhanp, fhlen); 1135 } 1136 } 1137 1138 /* 1139 * TEST : dm_query_right - fs handle 1140 * EXPECTED: rc = 0 1141 */ 1142 if (DMVAR_EXEC(QUERY_RIGHT_BASE + 12)) { 1143 void *fshanp; 1144 size_t fshlen; 1145 dm_right_t right; 1146 1147 /* Variation set up */ 1148 if ((rc = 1149 dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { 1150 /* No clean up */ 1151 } else 1152 if ((rc = 1153 dm_request_right(sid, fshanp, fshlen, token, 0, 1154 DM_RIGHT_SHARED)) == -1) { 1155 dm_handle_free(fshanp, fshlen); 1156 } 1157 if (rc == -1) { 1158 DMLOG_PRINT(DMLVL_DEBUG, 1159 "Unable to set up variation! (errno = %d)\n", 1160 errno); 1161 DMVAR_SKIP(); 1162 } else { 1163 /* Variation */ 1164 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 1165 rc = dm_query_right(sid, fshanp, fshlen, token, &right); 1166 if (rc == 0) { 1167 if (right == DM_RIGHT_SHARED) { 1168 DMLOG_PRINT(DMLVL_DEBUG, 1169 "%s passed with expected rc = %d\n", 1170 szFuncName, 0); 1171 DMVAR_PASS(); 1172 } else { 1173 DMLOG_PRINT(DMLVL_ERR, 1174 "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", 1175 szFuncName, 0, right, 1176 DM_RIGHT_SHARED); 1177 DMVAR_FAIL(); 1178 } 1179 } else { 1180 DMLOG_PRINT(DMLVL_ERR, 1181 "%s failed with unexpected rc = %d (errno = %d)\n", 1182 szFuncName, rc, errno); 1183 DMVAR_FAIL(); 1184 } 1185 1186 /* Variation clean up */ 1187 rc = dm_release_right(sid, fshanp, fshlen, token); 1188 if (rc == -1) { 1189 DMLOG_PRINT(DMLVL_DEBUG, 1190 "Unable to clean up variation! (errno = %d)\n", 1191 errno); 1192 } 1193 dm_handle_free(fshanp, fshlen); 1194 } 1195 } 1196 1197 szFuncName = "dm_upgrade_right"; 1198 1199 /* 1200 * TEST : dm_upgrade_right - invalid sid 1201 * EXPECTED: rc = -1, errno = EINVAL 1202 */ 1203 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 1)) { 1204 1205 /* Variation set up */ 1206 rc = dm_request_right(sid, hanp, hlen, token, 0, 1207 DM_RIGHT_SHARED); 1208 if (rc == -1) { 1209 DMLOG_PRINT(DMLVL_DEBUG, 1210 "Unable to set up variation! (errno = %d)\n", 1211 errno); 1212 DMVAR_SKIP(); 1213 } else { 1214 /* Variation */ 1215 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", 1216 szFuncName); 1217 rc = dm_upgrade_right(INVALID_ADDR, hanp, hlen, token); 1218 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1219 1220 /* Variation clean up */ 1221 rc = dm_release_right(sid, hanp, hlen, token); 1222 if (rc == -1) { 1223 DMLOG_PRINT(DMLVL_DEBUG, 1224 "Unable to clean up variation! (errno = %d)\n", 1225 errno); 1226 } 1227 } 1228 } 1229 1230 /* 1231 * TEST : dm_upgrade_right - invalid hanp 1232 * EXPECTED: rc = -1, errno = EFAULT 1233 */ 1234 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 2)) { 1235 1236 /* Variation set up */ 1237 rc = dm_request_right(sid, hanp, hlen, token, 0, 1238 DM_RIGHT_SHARED); 1239 if (rc == -1) { 1240 DMLOG_PRINT(DMLVL_DEBUG, 1241 "Unable to set up variation! (errno = %d)\n", 1242 errno); 1243 DMVAR_SKIP(); 1244 } else { 1245 /* Variation */ 1246 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", 1247 szFuncName); 1248 rc = dm_upgrade_right(sid, (void *)INVALID_ADDR, hlen, 1249 token); 1250 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 1251 1252 /* Variation clean up */ 1253 rc = dm_release_right(sid, hanp, hlen, token); 1254 if (rc == -1) { 1255 DMLOG_PRINT(DMLVL_DEBUG, 1256 "Unable to clean up variation! (errno = %d)\n", 1257 errno); 1258 } 1259 } 1260 } 1261 1262 /* 1263 * TEST : dm_upgrade_right - invalid hlen 1264 * EXPECTED: rc = -1, errno = EBADF 1265 */ 1266 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 3)) { 1267 1268 /* Variation set up */ 1269 rc = dm_request_right(sid, hanp, hlen, token, 0, 1270 DM_RIGHT_SHARED); 1271 if (rc == -1) { 1272 DMLOG_PRINT(DMLVL_DEBUG, 1273 "Unable to set up variation! (errno = %d)\n", 1274 errno); 1275 DMVAR_SKIP(); 1276 } else { 1277 /* Variation */ 1278 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", 1279 szFuncName); 1280 rc = dm_upgrade_right(sid, hanp, INVALID_ADDR, token); 1281 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1282 1283 /* Variation clean up */ 1284 rc = dm_release_right(sid, hanp, hlen, token); 1285 if (rc == -1) { 1286 DMLOG_PRINT(DMLVL_DEBUG, 1287 "Unable to clean up variation! (errno = %d)\n", 1288 errno); 1289 } 1290 } 1291 } 1292 1293 /* 1294 * TEST : dm_upgrade_right - invalid token 1295 * EXPECTED: rc = -1, errno = EINVAL 1296 */ 1297 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 4)) { 1298 1299 /* Variation set up */ 1300 rc = dm_request_right(sid, hanp, hlen, token, 0, 1301 DM_RIGHT_SHARED); 1302 if (rc == -1) { 1303 DMLOG_PRINT(DMLVL_DEBUG, 1304 "Unable to set up variation! (errno = %d)\n", 1305 errno); 1306 DMVAR_SKIP(); 1307 } else { 1308 /* Variation */ 1309 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", 1310 szFuncName); 1311 rc = dm_upgrade_right(sid, hanp, hlen, INVALID_ADDR); 1312 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1313 1314 /* Variation clean up */ 1315 rc = dm_release_right(sid, hanp, hlen, token); 1316 if (rc == -1) { 1317 DMLOG_PRINT(DMLVL_DEBUG, 1318 "Unable to clean up variation! (errno = %d)\n", 1319 errno); 1320 } 1321 } 1322 } 1323 1324 /* 1325 * TEST : dm_upgrade_right - DM_RIGHT_NULL 1326 * EXPECTED: rc = -1, errno = EPERM 1327 * 1328 * This variation uncovered XFS BUG #31 (EACCES returned instead of 1329 * EPERM) 1330 */ 1331 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 5)) { 1332 1333 /* Variation set up */ 1334 1335 /* Variation */ 1336 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL)\n", szFuncName); 1337 rc = dm_upgrade_right(sid, hanp, hlen, token); 1338 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EPERM); 1339 1340 /* Variation clean up */ 1341 } 1342 1343 /* 1344 * TEST : dm_upgrade_right - DM_RIGHT_SHARED 1345 * EXPECTED: rc = 0 1346 */ 1347 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 6)) { 1348 1349 /* Variation set up */ 1350 rc = dm_request_right(sid, hanp, hlen, token, 0, 1351 DM_RIGHT_SHARED); 1352 if (rc == -1) { 1353 DMLOG_PRINT(DMLVL_DEBUG, 1354 "Unable to set up variation! (errno = %d)\n", 1355 errno); 1356 DMVAR_SKIP(); 1357 } else { 1358 /* Variation */ 1359 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", 1360 szFuncName); 1361 rc = dm_upgrade_right(sid, hanp, hlen, token); 1362 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1363 1364 /* Variation clean up */ 1365 rc = dm_release_right(sid, hanp, hlen, token); 1366 if (rc == -1) { 1367 DMLOG_PRINT(DMLVL_DEBUG, 1368 "Unable to clean up variation! (errno = %d)\n", 1369 errno); 1370 } 1371 } 1372 } 1373 1374 /* 1375 * TEST : dm_upgrade_right - DM_RIGHT_EXCL 1376 * EXPECTED: rc = 0 1377 */ 1378 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 7)) { 1379 1380 /* Variation set up */ 1381 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 1382 if (rc == -1) { 1383 DMLOG_PRINT(DMLVL_DEBUG, 1384 "Unable to set up variation! (errno = %d)\n", 1385 errno); 1386 DMVAR_SKIP(); 1387 } else { 1388 /* Variation */ 1389 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL)\n", 1390 szFuncName); 1391 rc = dm_upgrade_right(sid, hanp, hlen, token); 1392 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1393 1394 /* Variation clean up */ 1395 rc = dm_release_right(sid, hanp, hlen, token); 1396 if (rc == -1) { 1397 DMLOG_PRINT(DMLVL_DEBUG, 1398 "Unable to clean up variation! (errno = %d)\n", 1399 errno); 1400 } 1401 } 1402 } 1403 1404 /* 1405 * TEST : dm_upgrade_right - DM_NO_SESSION sid 1406 * EXPECTED: rc = -1, errno = EINVAL 1407 */ 1408 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 8)) { 1409 1410 /* Variation set up */ 1411 rc = dm_request_right(sid, hanp, hlen, token, 0, 1412 DM_RIGHT_SHARED); 1413 if (rc == -1) { 1414 DMLOG_PRINT(DMLVL_DEBUG, 1415 "Unable to set up variation! (errno = %d)\n", 1416 errno); 1417 DMVAR_SKIP(); 1418 } else { 1419 /* Variation */ 1420 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", 1421 szFuncName); 1422 rc = dm_upgrade_right(DM_NO_SESSION, hanp, hlen, token); 1423 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1424 1425 /* Variation clean up */ 1426 rc = dm_release_right(sid, hanp, hlen, token); 1427 if (rc == -1) { 1428 DMLOG_PRINT(DMLVL_DEBUG, 1429 "Unable to clean up variation! (errno = %d)\n", 1430 errno); 1431 } 1432 } 1433 } 1434 1435 /* 1436 * TEST : dm_upgrade_right - global handle 1437 * EXPECTED: rc = -1, errno = EBADF 1438 */ 1439 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 9)) { 1440 1441 /* Variation set up */ 1442 rc = dm_request_right(sid, hanp, hlen, token, 0, 1443 DM_RIGHT_SHARED); 1444 if (rc == -1) { 1445 DMLOG_PRINT(DMLVL_DEBUG, 1446 "Unable to set up variation! (errno = %d)\n", 1447 errno); 1448 DMVAR_SKIP(); 1449 } else { 1450 /* Variation */ 1451 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", 1452 szFuncName); 1453 rc = dm_upgrade_right(sid, DM_GLOBAL_HANP, 1454 DM_GLOBAL_HLEN, token); 1455 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1456 1457 /* Variation clean up */ 1458 rc = dm_release_right(sid, hanp, hlen, token); 1459 if (rc == -1) { 1460 DMLOG_PRINT(DMLVL_DEBUG, 1461 "Unable to clean up variation! (errno = %d)\n", 1462 errno); 1463 } 1464 } 1465 } 1466 1467 /* 1468 * TEST : dm_upgrade_right - file handle 1469 * EXPECTED: rc = 0 1470 */ 1471 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 10)) { 1472 void *fhanp; 1473 size_t fhlen; 1474 1475 /* Variation set up */ 1476 if ((rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { 1477 /* No clean up */ 1478 } else 1479 if ((rc = 1480 dm_request_right(sid, fhanp, fhlen, token, 0, 1481 DM_RIGHT_SHARED)) == -1) { 1482 dm_handle_free(fhanp, fhlen); 1483 } 1484 if (rc == -1) { 1485 DMLOG_PRINT(DMLVL_DEBUG, 1486 "Unable to set up variation! (errno = %d)\n", 1487 errno); 1488 DMVAR_SKIP(); 1489 } else { 1490 /* Variation */ 1491 DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", 1492 szFuncName); 1493 rc = dm_upgrade_right(sid, fhanp, fhlen, token); 1494 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1495 1496 /* Variation clean up */ 1497 rc = dm_release_right(sid, fhanp, fhlen, token); 1498 if (rc == -1) { 1499 DMLOG_PRINT(DMLVL_DEBUG, 1500 "Unable to clean up variation! (errno = %d)\n", 1501 errno); 1502 } 1503 dm_handle_free(fhanp, fhlen); 1504 } 1505 } 1506 1507 /* 1508 * TEST : dm_upgrade_right - fs handle 1509 * EXPECTED: rc = 0 1510 */ 1511 if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 11)) { 1512 void *fshanp; 1513 size_t fshlen; 1514 1515 /* Variation set up */ 1516 if ((rc = 1517 dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { 1518 /* No clean up */ 1519 } else 1520 if ((rc = 1521 dm_request_right(sid, fshanp, fshlen, token, 0, 1522 DM_RIGHT_SHARED)) == -1) { 1523 dm_handle_free(fshanp, fshlen); 1524 } 1525 if (rc == -1) { 1526 DMLOG_PRINT(DMLVL_DEBUG, 1527 "Unable to set up variation! (errno = %d)\n", 1528 errno); 1529 DMVAR_SKIP(); 1530 } else { 1531 /* Variation */ 1532 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 1533 rc = dm_upgrade_right(sid, fshanp, fshlen, token); 1534 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1535 1536 /* Variation clean up */ 1537 rc = dm_release_right(sid, fshanp, fshlen, token); 1538 if (rc == -1) { 1539 DMLOG_PRINT(DMLVL_DEBUG, 1540 "Unable to clean up variation! (errno = %d)\n", 1541 errno); 1542 } 1543 dm_handle_free(fshanp, fshlen); 1544 } 1545 } 1546 1547 szFuncName = "dm_downgrade_right"; 1548 1549 /* 1550 * TEST : dm_downgrade_right - invalid sid 1551 * EXPECTED: rc = -1, errno = EINVAL 1552 */ 1553 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 1)) { 1554 1555 /* Variation set up */ 1556 rc = dm_request_right(sid, hanp, hlen, token, 0, 1557 DM_RIGHT_SHARED); 1558 if (rc == -1) { 1559 DMLOG_PRINT(DMLVL_DEBUG, 1560 "Unable to set up variation! (errno = %d)\n", 1561 errno); 1562 DMVAR_SKIP(); 1563 } else { 1564 /* Variation */ 1565 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", 1566 szFuncName); 1567 rc = dm_downgrade_right(INVALID_ADDR, hanp, hlen, 1568 token); 1569 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1570 1571 /* Variation clean up */ 1572 rc = dm_release_right(sid, hanp, hlen, token); 1573 if (rc == -1) { 1574 DMLOG_PRINT(DMLVL_DEBUG, 1575 "Unable to clean up variation! (errno = %d)\n", 1576 errno); 1577 } 1578 } 1579 } 1580 1581 /* 1582 * TEST : dm_downgrade_right - invalid hanp 1583 * EXPECTED: rc = -1, errno = EFAULT 1584 */ 1585 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 2)) { 1586 1587 /* Variation set up */ 1588 rc = dm_request_right(sid, hanp, hlen, token, 0, 1589 DM_RIGHT_SHARED); 1590 if (rc == -1) { 1591 DMLOG_PRINT(DMLVL_DEBUG, 1592 "Unable to set up variation! (errno = %d)\n", 1593 errno); 1594 DMVAR_SKIP(); 1595 } else { 1596 /* Variation */ 1597 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", 1598 szFuncName); 1599 rc = dm_downgrade_right(sid, (void *)INVALID_ADDR, hlen, 1600 token); 1601 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); 1602 1603 /* Variation clean up */ 1604 rc = dm_release_right(sid, hanp, hlen, token); 1605 if (rc == -1) { 1606 DMLOG_PRINT(DMLVL_DEBUG, 1607 "Unable to clean up variation! (errno = %d)\n", 1608 errno); 1609 } 1610 } 1611 } 1612 1613 /* 1614 * TEST : dm_downgrade_right - invalid hlen 1615 * EXPECTED: rc = -1, errno = EBADF 1616 */ 1617 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 3)) { 1618 1619 /* Variation set up */ 1620 rc = dm_request_right(sid, hanp, hlen, token, 0, 1621 DM_RIGHT_SHARED); 1622 if (rc == -1) { 1623 DMLOG_PRINT(DMLVL_DEBUG, 1624 "Unable to set up variation! (errno = %d)\n", 1625 errno); 1626 DMVAR_SKIP(); 1627 } else { 1628 /* Variation */ 1629 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", 1630 szFuncName); 1631 rc = dm_downgrade_right(sid, hanp, INVALID_ADDR, token); 1632 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1633 1634 /* Variation clean up */ 1635 rc = dm_release_right(sid, hanp, hlen, token); 1636 if (rc == -1) { 1637 DMLOG_PRINT(DMLVL_DEBUG, 1638 "Unable to clean up variation! (errno = %d)\n", 1639 errno); 1640 } 1641 } 1642 } 1643 1644 /* 1645 * TEST : dm_downgrade_right - invalid token 1646 * EXPECTED: rc = -1, errno = EINVAL 1647 */ 1648 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 4)) { 1649 1650 /* Variation set up */ 1651 rc = dm_request_right(sid, hanp, hlen, token, 0, 1652 DM_RIGHT_SHARED); 1653 if (rc == -1) { 1654 DMLOG_PRINT(DMLVL_DEBUG, 1655 "Unable to set up variation! (errno = %d)\n", 1656 errno); 1657 DMVAR_SKIP(); 1658 } else { 1659 /* Variation */ 1660 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", 1661 szFuncName); 1662 rc = dm_downgrade_right(sid, hanp, hlen, INVALID_ADDR); 1663 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1664 1665 /* Variation clean up */ 1666 rc = dm_release_right(sid, hanp, hlen, token); 1667 if (rc == -1) { 1668 DMLOG_PRINT(DMLVL_DEBUG, 1669 "Unable to clean up variation! (errno = %d)\n", 1670 errno); 1671 } 1672 } 1673 } 1674 1675 /* 1676 * TEST : dm_downgrade_right - DM_RIGHT_NULL 1677 * EXPECTED: rc = -1, errno = EPERM 1678 * 1679 * This variation uncovered XFS BUG #32 (EACCES returned instead of 1680 * EPERM) 1681 */ 1682 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 5)) { 1683 1684 /* Variation set up */ 1685 1686 /* Variation */ 1687 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL)\n", szFuncName); 1688 rc = dm_downgrade_right(sid, hanp, hlen, token); 1689 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EPERM); 1690 1691 /* Variation clean up */ 1692 } 1693 1694 /* 1695 * TEST : dm_downgrade_right - DM_RIGHT_SHARED 1696 * EXPECTED: rc = -1, errno = EPERM 1697 */ 1698 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 6)) { 1699 1700 /* Variation set up */ 1701 rc = dm_request_right(sid, hanp, hlen, token, 0, 1702 DM_RIGHT_SHARED); 1703 if (rc == -1) { 1704 DMLOG_PRINT(DMLVL_DEBUG, 1705 "Unable to set up variation! (errno = %d)\n", 1706 errno); 1707 DMVAR_SKIP(); 1708 } else { 1709 /* Variation */ 1710 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", 1711 szFuncName); 1712 rc = dm_downgrade_right(sid, hanp, hlen, token); 1713 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EPERM); 1714 1715 /* Variation clean up */ 1716 rc = dm_release_right(sid, hanp, hlen, token); 1717 if (rc == -1) { 1718 DMLOG_PRINT(DMLVL_DEBUG, 1719 "Unable to clean up variation! (errno = %d)\n", 1720 errno); 1721 } 1722 } 1723 } 1724 1725 /* 1726 * TEST : dm_downgrade_right - DM_RIGHT_EXCL 1727 * EXPECTED: rc = 0 1728 */ 1729 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 7)) { 1730 1731 /* Variation set up */ 1732 rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); 1733 if (rc == -1) { 1734 DMLOG_PRINT(DMLVL_DEBUG, 1735 "Unable to set up variation! (errno = %d)\n", 1736 errno); 1737 DMVAR_SKIP(); 1738 } else { 1739 /* Variation */ 1740 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL)\n", 1741 szFuncName); 1742 rc = dm_downgrade_right(sid, hanp, hlen, token); 1743 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1744 1745 /* Variation clean up */ 1746 rc = dm_release_right(sid, hanp, hlen, token); 1747 if (rc == -1) { 1748 DMLOG_PRINT(DMLVL_DEBUG, 1749 "Unable to clean up variation! (errno = %d)\n", 1750 errno); 1751 } 1752 } 1753 } 1754 1755 /* 1756 * TEST : dm_downgrade_right - DM_NO_SESSION sid 1757 * EXPECTED: rc = -1, errno = EINVAL 1758 */ 1759 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 8)) { 1760 1761 /* Variation set up */ 1762 rc = dm_request_right(sid, hanp, hlen, token, 0, 1763 DM_RIGHT_SHARED); 1764 if (rc == -1) { 1765 DMLOG_PRINT(DMLVL_DEBUG, 1766 "Unable to set up variation! (errno = %d)\n", 1767 errno); 1768 DMVAR_SKIP(); 1769 } else { 1770 /* Variation */ 1771 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", 1772 szFuncName); 1773 rc = dm_downgrade_right(DM_NO_SESSION, hanp, hlen, 1774 token); 1775 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); 1776 1777 /* Variation clean up */ 1778 rc = dm_release_right(sid, hanp, hlen, token); 1779 if (rc == -1) { 1780 DMLOG_PRINT(DMLVL_DEBUG, 1781 "Unable to clean up variation! (errno = %d)\n", 1782 errno); 1783 } 1784 } 1785 } 1786 1787 /* 1788 * TEST : dm_downgrade_right - global handle 1789 * EXPECTED: rc = -1, errno = EBADF 1790 */ 1791 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 9)) { 1792 1793 /* Variation set up */ 1794 rc = dm_request_right(sid, hanp, hlen, token, 0, 1795 DM_RIGHT_SHARED); 1796 if (rc == -1) { 1797 DMLOG_PRINT(DMLVL_DEBUG, 1798 "Unable to set up variation! (errno = %d)\n", 1799 errno); 1800 DMVAR_SKIP(); 1801 } else { 1802 /* Variation */ 1803 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", 1804 szFuncName); 1805 rc = dm_downgrade_right(sid, DM_GLOBAL_HANP, 1806 DM_GLOBAL_HLEN, token); 1807 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); 1808 1809 /* Variation clean up */ 1810 rc = dm_release_right(sid, hanp, hlen, token); 1811 if (rc == -1) { 1812 DMLOG_PRINT(DMLVL_DEBUG, 1813 "Unable to clean up variation! (errno = %d)\n", 1814 errno); 1815 } 1816 } 1817 } 1818 1819 /* 1820 * TEST : dm_downgrade_right - file handle 1821 * EXPECTED: rc = 0 1822 */ 1823 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 10)) { 1824 void *fhanp; 1825 size_t fhlen; 1826 1827 /* Variation set up */ 1828 if ((rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { 1829 /* No clean up */ 1830 } else 1831 if ((rc = 1832 dm_request_right(sid, fhanp, fhlen, token, 0, 1833 DM_RIGHT_EXCL)) == -1) { 1834 dm_handle_free(fhanp, fhlen); 1835 } 1836 if (rc == -1) { 1837 DMLOG_PRINT(DMLVL_DEBUG, 1838 "Unable to set up variation! (errno = %d)\n", 1839 errno); 1840 DMVAR_SKIP(); 1841 } else { 1842 /* Variation */ 1843 DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", 1844 szFuncName); 1845 rc = dm_downgrade_right(sid, fhanp, fhlen, token); 1846 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1847 1848 /* Variation clean up */ 1849 rc = dm_release_right(sid, fhanp, fhlen, token); 1850 if (rc == -1) { 1851 DMLOG_PRINT(DMLVL_DEBUG, 1852 "Unable to clean up variation! (errno = %d)\n", 1853 errno); 1854 } 1855 dm_handle_free(fhanp, fhlen); 1856 } 1857 } 1858 1859 /* 1860 * TEST : dm_downgrade_right - fs handle 1861 * EXPECTED: rc = 0 1862 */ 1863 if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 11)) { 1864 void *fshanp; 1865 size_t fshlen; 1866 1867 /* Variation set up */ 1868 if ((rc = 1869 dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { 1870 /* No clean up */ 1871 } else 1872 if ((rc = 1873 dm_request_right(sid, fshanp, fshlen, token, 0, 1874 DM_RIGHT_EXCL)) == -1) { 1875 dm_handle_free(fshanp, fshlen); 1876 } 1877 if (rc == -1) { 1878 DMLOG_PRINT(DMLVL_DEBUG, 1879 "Unable to set up variation! (errno = %d)\n", 1880 errno); 1881 DMVAR_SKIP(); 1882 } else { 1883 /* Variation */ 1884 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); 1885 rc = dm_downgrade_right(sid, fshanp, fshlen, token); 1886 DMVAR_ENDPASSEXP(szFuncName, 0, rc); 1887 1888 /* Variation clean up */ 1889 rc = dm_release_right(sid, fshanp, fshlen, token); 1890 if (rc == -1) { 1891 DMLOG_PRINT(DMLVL_DEBUG, 1892 "Unable to clean up variation! (errno = %d)\n", 1893 errno); 1894 } 1895 dm_handle_free(fshanp, fshlen); 1896 } 1897 } 1898 1899} 1900 1901void *Thread(void *parm) 1902{ 1903 int rc; 1904 size_t dmMsgBufLen; 1905 dm_eventmsg_t *dmMsg; 1906 int bMounted = DM_FALSE; 1907 dm_eventtype_t type; 1908 dm_token_t token; 1909 dm_eventset_t events; 1910 dm_response_t response; 1911 1912 do { 1913 /* Loop until message received (wait could be interrupted) */ 1914 do { 1915 DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n"); 1916 dmMsgBufLen = 0; 1917 1918 rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf), 1919 dmMsgBuf, &dmMsgBufLen); 1920 DMLOG_PRINT(DMLVL_DEBUG, 1921 "... dm_get_events returned %d (errno %d)\n", 1922 rc, errno); 1923 } while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0)); 1924 1925 if (rc) { 1926 DMLOG_PRINT(DMLVL_ERR, 1927 "dm_get_events failed with rc = %d, errno = %d\n", 1928 rc, errno); 1929 dm_destroy_session(sid); 1930 DM_EXIT(); 1931 } else { 1932 dmMsg = (dm_eventmsg_t *) dmMsgBuf; 1933 token = dmMsg->ev_token; 1934 type = dmMsg->ev_type; 1935 1936 DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type); 1937 } 1938 1939 if (type == DM_EVENT_MOUNT) { 1940 /* SPECIAL CASE: need to set disposition, events and response */ 1941 dm_mount_event_t *me = 1942 DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *); 1943 void *lhanp = DM_GET_VALUE(me, me_handle1, void *); 1944 size_t lhlen = DM_GET_LEN(me, me_handle1); 1945 1946 DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n"); 1947 DMLOG_PRINT(DMLVL_DEBUG, " Mode: %x\n", me->me_mode); 1948 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n", 1949 lhanp); 1950 DMLOG_PRINT(DMLVL_DEBUG, 1951 " File system handle length: %d\n", lhlen); 1952 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint handle: %p\n", 1953 DM_GET_VALUE(me, me_handle2, void *)); 1954 DMLOG_PRINT(DMLVL_DEBUG, 1955 " Mountpoint handle length: %d\n", 1956 DM_GET_LEN(me, me_handle2)); 1957 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint path: %s\n", 1958 DM_GET_VALUE(me, me_name1, char *)); 1959 DMLOG_PRINT(DMLVL_DEBUG, " Media designator: %s\n", 1960 DM_GET_VALUE(me, me_name2, char *)); 1961 DMLOG_PRINT(DMLVL_DEBUG, " Root handle: %p\n", 1962 DM_GET_VALUE(me, me_roothandle, void *)); 1963 DMLOG_PRINT(DMLVL_DEBUG, " Root handle length: %d\n", 1964 DM_GET_LEN(me, me_roothandle)); 1965 1966 bMounted = dm_handle_is_valid(lhanp, lhlen); 1967 1968 rc = dm_request_right(sid, lhanp, lhlen, token, 1969 DM_RR_WAIT, DM_RIGHT_EXCL); 1970 if (rc == -1) { 1971 DMLOG_PRINT(DMLVL_ERR, 1972 "dm_request_right failed! (rc = %d, errno = %d)\n", 1973 rc, errno); 1974 dm_destroy_session(sid); 1975 DM_EXIT(); 1976 } 1977 1978 DMEV_ZERO(events); 1979 DMEV_SET(DM_EVENT_PREUNMOUNT, events); 1980 DMEV_SET(DM_EVENT_UNMOUNT, events); 1981 DMEV_SET(DM_EVENT_CREATE, events); 1982 rc = dm_set_disp(sid, lhanp, lhlen, token, &events, 1983 DM_EVENT_MAX); 1984 if (rc == -1) { 1985 DMLOG_PRINT(DMLVL_ERR, 1986 "dm_set_disp failed! (rc = %d, errno = %d)\n", 1987 rc, errno); 1988 dm_destroy_session(sid); 1989 DM_EXIT(); 1990 } 1991 1992 rc = dm_set_eventlist(sid, lhanp, lhlen, token, &events, 1993 DM_EVENT_MAX); 1994 if (rc == -1) { 1995 DMLOG_PRINT(DMLVL_ERR, 1996 "dm_set_eventlist failed! (rc = %d, errno = %d)\n", 1997 rc, errno); 1998 dm_destroy_session(sid); 1999 DM_EXIT(); 2000 } 2001 2002 rc = dm_release_right(sid, lhanp, lhlen, token); 2003 if (rc == -1) { 2004 DMLOG_PRINT(DMLVL_ERR, 2005 "dm_request_right failed! (rc = %d, errno = %d)\n", 2006 rc, errno); 2007 dm_destroy_session(sid); 2008 DM_EXIT(); 2009 } 2010 2011 response = DM_RESP_CONTINUE; 2012 } else if (type == DM_EVENT_UNMOUNT) { 2013 dm_namesp_event_t *nse = 2014 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *); 2015 if (nse->ne_retcode == 0) { 2016 bMounted = DM_FALSE; 2017 } 2018 2019 response = DM_RESP_CONTINUE; 2020 } else if (type == DM_EVENT_CREATE) { 2021 dm_namesp_event_t *nse = 2022 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *); 2023 void *hanp = DM_GET_VALUE(nse, ne_handle1, void *); 2024 size_t hlen = DM_GET_LEN(nse, ne_handle1); 2025 2026 if (runTestOnCreate) { 2027 DoTest(token, hanp, hlen); 2028 } 2029 2030 response = DM_RESP_CONTINUE; 2031 } else { 2032 switch (type) { 2033 case DM_EVENT_PREUNMOUNT: 2034 response = DM_RESP_CONTINUE; 2035 break; 2036 2037 default: 2038 { 2039 DMLOG_PRINT(DMLVL_ERR, 2040 "Message is unexpected!\n"); 2041 response = DM_RESP_ABORT; 2042 break; 2043 } 2044 } 2045 } 2046 2047 if (response != DM_RESP_INVALID) { 2048 DMLOG_PRINT(DMLVL_DEBUG, 2049 "Responding to message %d with %d\n", type, 2050 response); 2051 rc = dm_respond_event(sid, token, response, 2052 response == 2053 DM_RESP_ABORT ? ABORT_ERRNO : 0, 2054 0, NULL); 2055 } 2056 } while (bMounted); 2057 2058 pthread_exit(0); 2059} 2060