"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/packages/capsicum/cap_rights.pony" (1 Nov 2019, 2803 Bytes) of package /linux/misc/ponyc-0.33.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Pony source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use "files"
    2 
    3 type CapRights is CapRights0
    4 
    5 class CapRights0
    6   """
    7   Version 0 of the capsicum cap_rights_t structure.
    8   """
    9   var _r0: U64 = 0
   10   var _r1: U64 = 0
   11 
   12   new create() =>
   13     """
   14     Initialises with no rights.
   15     """
   16     clear()
   17 
   18   new from(caps: FileCaps box) =>
   19     """
   20     Initialises with the rights from a FileCaps.
   21     """
   22     clear()
   23 
   24     if caps(FileCreate) then set(Cap.creat()) end
   25     if caps(FileChmod) then set(Cap.fchmod()) end
   26     if caps(FileChown) then set(Cap.fchown()) end
   27 
   28     if caps(FileLink) then
   29       set(Cap.linkat())
   30       set(Cap.symlinkat())
   31     end
   32 
   33     if caps(FileLookup) then set(Cap.lookup()) end
   34     if caps(FileMkdir) then set(Cap.mkdirat()) end
   35     if caps(FileRead) then set(Cap.read()) end
   36     if caps(FileRemove) then set(Cap.unlinkat()) end
   37     if caps(FileRename) then set(Cap.renameat()) end
   38     if caps(FileSeek) then set(Cap.seek()) end
   39 
   40     if caps(FileStat) then
   41       set(Cap.fstat())
   42       set(Cap.fstatfs())
   43       set(Cap.fcntl())
   44     end
   45 
   46     if caps(FileSync) then set(Cap.fsync()) end
   47     if caps(FileTime) then set(Cap.futimes()) end
   48     if caps(FileTruncate) then set(Cap.ftruncate()) end
   49     if caps(FileWrite) then set(Cap.write()) end
   50     if caps(FileExec) then set(Cap.fexecve()) end
   51 
   52   new descriptor(fd: I32) =>
   53     """
   54     Initialises with the rights on the given file descriptor.
   55     """
   56     ifdef freebsd or "capsicum" then
   57       @__cap_rights_get[I32](_version(), fd, addressof _r0)
   58     end
   59 
   60   fun ref set(cap: U64) =>
   61     ifdef freebsd or "capsicum" then
   62       @__cap_rights_set[None](addressof _r0, cap, U64(0))
   63     end
   64 
   65   fun ref unset(cap: U64) =>
   66     ifdef freebsd or "capsicum" then
   67       @__cap_rights_clear[None](addressof _r0, cap, U64(0))
   68     end
   69 
   70   fun limit(fd: I32): Bool =>
   71     """
   72     Limits the fd to the encoded rights.
   73     """
   74     ifdef freebsd or "capsicum" then
   75       @cap_rights_limit[I32](fd, addressof _r0) == 0
   76     else
   77       true
   78     end
   79 
   80   fun ref merge(that: CapRights0) =>
   81     """
   82     Merge the rights in that into this.
   83     """
   84     ifdef freebsd or "capsicum" then
   85       @cap_rights_merge[None](addressof _r0, addressof that._r0)
   86     end
   87 
   88   fun ref remove(that: CapRights0) =>
   89     """
   90     Remove the rights in that from this.
   91     """
   92     ifdef freebsd or "capsicum" then
   93       @cap_rights_remove[None](addressof _r0, addressof that._r0)
   94     end
   95 
   96   fun ref clear() =>
   97     """
   98     Clear all rights.
   99     """
  100     ifdef freebsd or "capsicum" then
  101       @__cap_rights_init[Pointer[U64]](I32(0), addressof _r0, U64(0))
  102     end
  103 
  104   fun contains(that: CapRights0): Bool =>
  105     """
  106     Check that this is a superset of the rights in that.
  107     """
  108     ifdef freebsd or "capsicum" then
  109       @cap_rights_contains[Bool](addressof _r0, addressof that._r0)
  110     else
  111       true
  112     end
  113 
  114   fun _version(): I32 => 0