summaryrefslogtreecommitdiffstats
path: root/tests/018/chmod.tl
blob: 93739c48a803bfaf84513fa3c5d27debc5c5df25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(load "../common")
(load "../perm")

(defvarl tgt [*args* 0])

(defmacro mode-bits (st-mode)
  (logand st-mode #xFFF))

(defun cht (init mode expected)
  (let ((ini (dec-perm init))
        (exp (dec-perm expected)))
    (chmod tgt ini)
    (let* ((st (stat tgt))
           (m (logand st.mode #xFFF)))
      (unless (eql m ini)
        (error "failed to set initial mode: expected: ~s, actual: ~s "
               init (enc-perm m))))
    (chmod tgt mode)
    (let* ((st (stat tgt))
           (m (logand st.mode #xFFF)))
      (unless (eql m exp)
        (error "failed to set mode with ~s: expected ~s, actual ~s"
               mode expected (enc-perm m))))))

(remove-path tgt)
(with-stream (s (open-file tgt "w")))
(umask #o022)

(cht "------------" "a+strwx"           "sgtrwxrwxrwx")
(cht "------------" "+strwx"            "sgtrwxr-xr-x")
(cht "------------" "u+s"               "s-----------")
(cht "------------" "g+s"               "-g----------")
(cht "------------" "+t"                "--t---------")
(cht "sgtrwxrwxrwx" "="                 "------------")
(cht "sgtrwxrwxrwx" "u="                "-gt---rwxrwx")
(cht "sgtrwxrwxrwx" "g="                "s-trwx---rwx")
(cht "sgtrwxrwxrwx" "o="                "sg-rwxrwx---")
(cht "------------" "u+s,g+s"           "sg----------")
(cht "------------" "u+r,g+r,o+r,+t,+s" "sgtr--r--r--")
(cht "------------" "+rwx,g-r+w,o-r+w"  "---rwx-wx-wx")
(cht "---------rwx" "u=rwsx"            "s--rwx---rwx")
(cht "---------rwx" "u=rwsx,g=rwx,go-x" "s--rwxrw-rw-")
(cht "---------rwx" "g=o,g-w+s,u=g,o-x" "-g-r-xr-xrw-")
(cht "---------rwx" "o=o"               "---------rwx")
(cht "-----x------" "a+X"               "-----x--x--x")
(cht "-----x------" "=,a+X"             "------------")
(cht "-----x------" "a-x+X"             "------------")
(cht "------------" "u+x-X"             "------------")