summaryrefslogtreecommitdiff
path: root/sid.mli
blob: 9012df80ff64114d20a15247c2e573f12316df68 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(* SPDX-License-Identifier: LGPL-3.0-only *)

type t
type sub_auths = Stdint.Uint32.t array

val create : ?sa:Stdint.Uint32.t array -> Stdint.Uint64.t -> t option
(** [create sas ia] constructs a SID with the identifier authority [ia]
    and, optionally, the subauthorities [sas]. The operation will return
    [None] if [sa] contains more than fifteen subauthorities. *)

val create_unsafe : Stdint.Uint32.t array -> Stdint.Uint64.t -> t
(** [create_unsafe sas ia] constructs a SID with the identifier authority [ia]
    and, optionally, the sub authorities [sas] without validating the inputs.
    Use with caution. *)

val equal : t -> t -> bool
(** [equal sa sb] tests whether [sa] and [sb] are identical. *)

val equal_sub_auths : Stdint.Uint32.t array -> Stdint.Uint32.t array -> bool
(** [equal_sub_auths sa sb] tests whether [sa] and [sb] have identical
    subauthorities. *)

val get_ident_auth : t -> Stdint.Uint64.t
(** [get_ident_auth s] get the identifier authority of SID [s]. *)

val get_sub_auths : t -> sub_auths
(** [get_ident_auth s] get the subauthorities array of SID [s]. *)

(** Conversions to and from the {e string format syntax} (MS-DTYP 2.4.2.1). *)
module StringFmt :
  sig
    val decode : string -> (t, string) result
    (** [decode b] parse string buffer [b] into a SID. *)

    val encode : t -> string
    (** [encode s] convert SID [s] to its string representation. *)
  end

(** Conversion to and from the {e packet representation} (MS-DTYP 2.4.2.2). *)
module PacketRep :
  sig
    type endian = Big | Little
    val decode : ?endian:endian -> bytes -> (t, string) result
    (** [decode endian b] decode the byte buffer [b] as a SID. *)

    val encode : ?endian:endian -> t -> bytes
    (** [encode endian s] convert SID [s] to the packet representation
        encoding subauthorities in endianness [endian]. *)
  end

(** Pre-defined SID constansts and constructors with fixed identifier
    authority (MS-DTYP 2.4.2.4). *)
module WellKnown :
  sig
    val null : t
    val everyone : t
    val world : t
    val local : t
    val creator_owner_id : t
    val creator_group_id : t
    val elite : t

    module Prefix :
      sig
        type toplevel_auth = ?sa:sub_auths -> unit -> t

        val security_null_sid_authority    : toplevel_auth
        val security_world_sid_authority   : ?sa:sub_auths -> unit -> t
        val security_local_sid_authority   : ?sa:sub_auths -> unit -> t
        val security_creator_sid_authority : ?sa:sub_auths -> unit -> t
        val security_nt_authority          : ?sa:sub_auths -> unit -> t
        val security_app_package_authority      : ?sa:sub_auths -> unit -> t
        val security_mandatory_label_authority  : ?sa:sub_auths -> unit -> t
        val security_scoped_policy_id_authority : ?sa:sub_auths -> unit -> t
        val security_authentication_authority   : ?sa:sub_auths -> unit -> t
      end
  end

val of_string : string -> (t, string) result
(** [of_string b] is an alias for [StringFmt.decode b]. *)

val to_string : t -> string
(** [to_string s] is an alias for [StringFmt.encode s]. *)