450 |
(t |
(t |
451 |
(gamegrid-add-score-with-update-game-score file score)))) |
(gamegrid-add-score-with-update-game-score file score)))) |
452 |
|
|
453 |
|
|
454 |
|
;; On POSIX systems there are four cases to distinguish: |
455 |
|
|
456 |
|
;; 1. FILE is an absolute filename. Then it should be a file in |
457 |
|
;; temporary file directory. This is the way, |
458 |
|
;; `gamegrid-add-score' was supposed to be used in the past and |
459 |
|
;; is covered here for backward-compatibility. |
460 |
|
;; |
461 |
|
;; 2. The helper program "update-game-score" is setuid and the |
462 |
|
;; file FILE does already exist in a system wide shared game |
463 |
|
;; directory. This should be the normal case on POSIX systems, |
464 |
|
;; if the game was installed system wide. Use |
465 |
|
;; "update-game-score" to add the score to the file in the |
466 |
|
;; shared game directory. |
467 |
|
;; |
468 |
|
;; 3. "update-game-score" is setuid, but the file FILE does *not* |
469 |
|
;; exist in the system wide shared game directory. Use |
470 |
|
;; `gamegrid-add-score-insecure' to create--if necessary--and |
471 |
|
;; update FILE. This is for the case that a user has installed |
472 |
|
;; a game on her own. |
473 |
|
;; |
474 |
|
;; 4. "update-game-score" is not setuid. Use it to create/update |
475 |
|
;; FILE in the user's home directory. There is presumably no |
476 |
|
;; shared game directory. |
477 |
|
|
478 |
(defun gamegrid-add-score-with-update-game-score (file score) |
(defun gamegrid-add-score-with-update-game-score (file score) |
479 |
(let* ((result nil) ;; What is this good for? -- os |
(let* ((result nil) ;; What is this good for? -- os |
480 |
(have-shared-game-dir |
(have-shared-game-dir |
482 |
(expand-file-name "update-game-score" |
(expand-file-name "update-game-score" |
483 |
exec-directory)) |
exec-directory)) |
484 |
#o4000))))) |
#o4000))))) |
485 |
(if (and have-shared-game-dir |
(cond ((file-name-absolute-p file) |
486 |
(file-exists-p (expand-file-name file shared-game-score-directory))) |
(gamegrid-add-score-insecure file score)) |
487 |
;; Use the setuid update-gamescore program to update a |
((and have-shared-game-dir |
488 |
;; system-wide score file. |
(file-exists-p (expand-file-name file shared-game-score-directory))) |
489 |
(gamegrid-add-score-with-update-game-score-1 |
;; Use the setuid "update-game-score" program to update a |
490 |
(expand-file-name file shared-game-score-directory) score) |
;; system-wide score file. |
491 |
;; Else: Add the score to a score file in the user's home |
(gamegrid-add-score-with-update-game-score-1 |
492 |
;; directory. If `have-shared-game-dir' is non-nil, the |
(expand-file-name file shared-game-score-directory) score)) |
493 |
;; "update-gamescore" program is setuid, so don't use it. |
;; Else: Add the score to a score file in the user's home |
494 |
(if have-shared-game-dir |
;; directory. |
495 |
(gamegrid-add-score-insecure file score |
(have-shared-game-dir |
496 |
gamegrid-user-score-file-directory) |
;; If `have-shared-game-dir' is non-nil, then |
497 |
(let ((f (expand-file-name |
;; "update-gamescore" program is setuid, so don't use it. |
498 |
gamegrid-user-score-file-directory))) |
(unless (file-exists-p |
499 |
(when (file-writable-p f) |
(directory-file-name gamegrid-user-score-file-directory)) |
500 |
(unless (eq (car-safe (file-attributes f)) |
(make-directory gamegrid-user-score-file-directory t)) |
501 |
t) |
(gamegrid-add-score-insecure file score |
502 |
(make-directory f)) |
gamegrid-user-score-file-directory)) |
503 |
(setq f (expand-file-name file f)) |
(t (let ((f (expand-file-name |
504 |
(unless (file-exists-p f) |
gamegrid-user-score-file-directory))) |
505 |
(write-region "" nil f nil 'silent nil 'excl))) |
(when (file-writable-p f) |
506 |
(gamegrid-add-score-with-update-game-score-1 f score)))))) |
(unless (eq (car-safe (file-attributes f)) |
507 |
|
t) |
508 |
|
(make-directory f)) |
509 |
|
(setq f (expand-file-name file f)) |
510 |
|
(unless (file-exists-p f) |
511 |
|
(write-region "" nil f nil 'silent nil 'excl))) |
512 |
|
(gamegrid-add-score-with-update-game-score-1 f score)))))) |
513 |
|
|
514 |
(defun gamegrid-add-score-with-update-game-score-1 (target score) |
(defun gamegrid-add-score-with-update-game-score-1 (target score) |
515 |
(let ((default-directory "/") |
(let ((default-directory "/") |