| 487 | |
| 488 | #ifdef CHDIR |
| 489 | void |
| 490 | chdirx(const char *dir, boolean wr) |
| 491 | { |
| 492 | if (dir /* User specified directory? */ |
| 493 | #ifdef HACKDIR |
| 494 | && strcmp(dir, HACKDIR) /* and not the default? */ |
| 495 | #endif |
| 496 | ) { |
| 497 | #ifdef SECURE |
| 498 | (void) setgid(getgid()); |
| 499 | (void) setuid(getuid()); /* Ron Wessels */ |
| 500 | #endif |
| 501 | } else { |
| 502 | /* non-default data files is a sign that scores may not be |
| 503 | * compatible, or perhaps that a binary not fitting this |
| 504 | * system's layout is being used. |
| 505 | */ |
| 506 | #ifdef VAR_PLAYGROUND |
| 507 | int len = strlen(VAR_PLAYGROUND); |
| 508 | |
| 509 | /* FIXME: this allocation never gets freed. |
| 510 | */ |
| 511 | gf.fqn_prefix[SCOREPREFIX] = (char *) alloc(len + 2); |
| 512 | Strcpy(gf.fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND); |
| 513 | if (gf.fqn_prefix[SCOREPREFIX][len - 1] != '/') { |
| 514 | gf.fqn_prefix[SCOREPREFIX][len] = '/'; |
| 515 | gf.fqn_prefix[SCOREPREFIX][len + 1] = '\0'; |
| 516 | } |
| 517 | #endif |
| 518 | } |
| 519 | |
| 520 | #ifdef HACKDIR |
| 521 | if (!dir) |
| 522 | dir = HACKDIR; |
| 523 | #endif |
| 524 | |
| 525 | if (dir && chdir(dir) < 0) { |
| 526 | perror(dir); |
| 527 | error("Cannot chdir to %s.", dir); |
| 528 | /*NOTREACHED*/ |
| 529 | } |
| 530 | |
| 531 | /* warn the player if we can't write the record file |
| 532 | * perhaps we should also test whether . is writable |
| 533 | * unfortunately the access system-call is worthless. |
| 534 | */ |
| 535 | if (wr) { |
| 536 | #ifdef VAR_PLAYGROUND |
| 537 | /* FIXME: if termination cleanup ever frees fqn_prefix[0..N-1], |
| 538 | * these will need to use dupstr() so that they have distinct |
| 539 | * values that can be freed separately. Or perhaps freeing |
| 540 | * fqn_prefix[j] can check [j+1] through [N-1] for duplicated |
| 541 | * pointer and just set the value to Null. |
| 542 | */ |
| 543 | gf.fqn_prefix[LEVELPREFIX] = gf.fqn_prefix[SCOREPREFIX]; |
| 544 | gf.fqn_prefix[SAVEPREFIX] = gf.fqn_prefix[SCOREPREFIX]; |
| 545 | gf.fqn_prefix[BONESPREFIX] = gf.fqn_prefix[SCOREPREFIX]; |
| 546 | gf.fqn_prefix[LOCKPREFIX] = gf.fqn_prefix[SCOREPREFIX]; |