|
root / src / util / priv.reef
priv.reef Reef 41 lines 1.3 KB
 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
/******************************************************************************
               __               ____                __
              / /   ___  ____ _/ __/_____________ _/ /__
             / /   / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \
            / /___/  __/ /_/ / __(__  ) /__/ /_/ / /  __/
           /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/

   (C)opyright 2025, Leafscale, LLC -  https://www.leafscale.com

   Project: Zygaena
  Filename: priv.reef
   Authors: Chris Tusa <chris.tusa@leafscale.com>
   License: <see LICENSE file included with this source code>
Description: Privilege detection helpers

******************************************************************************/

module util.priv

import io.file

export
    // Check if we are running as root (UID 0)
    fn is_root(): bool
end export

// Check if we are running as root (UID 0)
// Uses file test to check write permission on system directory
fn is_root(): bool
    // Try to create a temp file in /var/lib/coral - only root can write there
    let test_file = "/var/lib/coral/.root_check"
    if file.writeFile(test_file, "1")
        // Successfully wrote - we have root-level access
        // File will be overwritten next time, no need to delete
        return true
    end if
    return false
end is_root

end module