s3:ntlm_auth: make logs more consistent with length check
[Samba.git] / libcli / security / dom_sid.h
blob5e1c5d909585aa2ed814d86dc1c5fe126e19ae5d
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Stefan (metze) Metzmacher 2002-2004
6 Copyright (C) Andrew Tridgell 1992-2004
7 Copyright (C) Jeremy Allison 1999
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _DOM_SID_H_
24 #define _DOM_SID_H_
26 #include "replace.h"
27 #include <talloc.h>
28 #include "lib/util/data_blob.h"
29 #include "librpc/gen_ndr/security.h"
31 /* Some well-known SIDs */
32 extern const struct dom_sid global_sid_World_Domain;
33 extern const struct dom_sid global_sid_World;
34 extern const struct dom_sid global_sid_Local_Authority;
35 extern const struct dom_sid global_sid_Creator_Owner_Domain;
36 extern const struct dom_sid global_sid_NT_Authority;
37 extern const struct dom_sid global_sid_Enterprise_DCs;
38 extern const struct dom_sid global_sid_System;
39 extern const struct dom_sid global_sid_NULL;
40 extern const struct dom_sid global_sid_Self;
41 extern const struct dom_sid global_sid_Authenticated_Users;
42 extern const struct dom_sid global_sid_Network;
43 extern const struct dom_sid global_sid_Asserted_Identity;
44 extern const struct dom_sid global_sid_Asserted_Identity_Service;
45 extern const struct dom_sid global_sid_Asserted_Identity_Authentication_Authority;
46 extern const struct dom_sid global_sid_Fresh_Public_Key_Identity;
47 extern const struct dom_sid global_sid_Creator_Owner;
48 extern const struct dom_sid global_sid_Creator_Group;
49 extern const struct dom_sid global_sid_Owner_Rights;
50 extern const struct dom_sid global_sid_Anonymous;
51 extern const struct dom_sid global_sid_Compounded_Authentication;
52 extern const struct dom_sid global_sid_Claims_Valid;
53 extern const struct dom_sid global_sid_Builtin;
54 extern const struct dom_sid global_sid_Builtin_Administrators;
55 extern const struct dom_sid global_sid_Builtin_Users;
56 extern const struct dom_sid global_sid_Builtin_Guests;
57 extern const struct dom_sid global_sid_Builtin_Power_Users;
58 extern const struct dom_sid global_sid_Builtin_Account_Operators;
59 extern const struct dom_sid global_sid_Builtin_Server_Operators;
60 extern const struct dom_sid global_sid_Builtin_Print_Operators;
61 extern const struct dom_sid global_sid_Builtin_Backup_Operators;
62 extern const struct dom_sid global_sid_Builtin_Replicator;
63 extern const struct dom_sid global_sid_Builtin_PreWin2kAccess;
64 extern const struct dom_sid global_sid_Unix_Users;
65 extern const struct dom_sid global_sid_Unix_Groups;
66 extern const struct dom_sid global_sid_Unix_NFS;
67 extern const struct dom_sid global_sid_Unix_NFS_Users;
68 extern const struct dom_sid global_sid_Unix_NFS_Groups;
69 extern const struct dom_sid global_sid_Unix_NFS_Mode;
70 extern const struct dom_sid global_sid_Unix_NFS_Other;
71 extern const struct dom_sid global_sid_Samba_SMB3;
73 extern const struct dom_sid global_sid_Samba_NPA_Flags;
74 #define SAMBA_NPA_FLAGS_NEED_IDLE 1
75 #define SAMBA_NPA_FLAGS_WINBIND_OFF 2
77 struct auth_SidAttr;
78 enum lsa_SidType;
80 NTSTATUS dom_sid_lookup_predefined_name(const char *name,
81 const struct dom_sid **sid,
82 enum lsa_SidType *type,
83 const struct dom_sid **authority_sid,
84 const char **authority_name);
85 NTSTATUS dom_sid_lookup_predefined_sid(const struct dom_sid *sid,
86 const char **name,
87 enum lsa_SidType *type,
88 const struct dom_sid **authority_sid,
89 const char **authority_name);
90 bool dom_sid_lookup_is_predefined_domain(const char *domain);
92 int dom_sid_compare_auth(const struct dom_sid *sid1,
93 const struct dom_sid *sid2);
94 int dom_sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid2);
95 int dom_sid_compare_domain(const struct dom_sid *sid1,
96 const struct dom_sid *sid2);
97 bool dom_sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2);
98 bool sid_append_rid(struct dom_sid *sid, uint32_t rid);
99 bool string_to_sid(struct dom_sid *sidout, const char *sidstr);
100 bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
101 const char **endp);
102 bool dom_sid_parse(const char *sidstr, struct dom_sid *ret);
103 struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr);
104 struct dom_sid *dom_sid_parse_length(TALLOC_CTX *mem_ctx, const DATA_BLOB *sid);
105 struct dom_sid *dom_sid_dup(TALLOC_CTX *mem_ctx, const struct dom_sid *dom_sid);
106 struct dom_sid *dom_sid_add_rid(TALLOC_CTX *mem_ctx,
107 const struct dom_sid *domain_sid,
108 uint32_t rid);
109 NTSTATUS dom_sid_split_rid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
110 struct dom_sid **domain, uint32_t *rid);
111 bool dom_sid_in_domain(const struct dom_sid *domain_sid,
112 const struct dom_sid *sid);
113 bool dom_sid_has_account_domain(const struct dom_sid *sid);
114 bool dom_sid_is_valid_account_domain(const struct dom_sid *sid);
116 #define DOM_SID_STR_BUFLEN (15*11+25)
117 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
119 struct dom_sid_buf { char buf[DOM_SID_STR_BUFLEN]; };
120 char *dom_sid_str_buf(const struct dom_sid *sid, struct dom_sid_buf *dst);
122 const char *sid_type_lookup(uint32_t sid_type);
123 const struct security_token *get_system_token(void);
124 bool sid_compose(struct dom_sid *dst, const struct dom_sid *domain_sid, uint32_t rid);
125 bool sid_split_rid(struct dom_sid *sid, uint32_t *rid);
126 bool sid_peek_rid(const struct dom_sid *sid, uint32_t *rid);
127 bool sid_peek_check_rid(const struct dom_sid *exp_dom_sid, const struct dom_sid *sid, uint32_t *rid);
128 void sid_copy(struct dom_sid *dst, const struct dom_sid *src);
129 ssize_t sid_parse(const uint8_t *inbuf, size_t len, struct dom_sid *sid);
130 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
131 struct dom_sid **sids, uint32_t *num);
132 NTSTATUS add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
133 struct dom_sid **sids, uint32_t *num_sids);
134 NTSTATUS add_sid_to_array_attrs(TALLOC_CTX *mem_ctx,
135 const struct dom_sid *sid, uint32_t attrs,
136 struct auth_SidAttr **sids, uint32_t *num);
137 NTSTATUS add_sid_to_array_attrs_unique(TALLOC_CTX *mem_ctx,
138 const struct dom_sid *sid, uint32_t attrs,
139 struct auth_SidAttr **sids, uint32_t *num_sids);
140 void del_sid_from_array(const struct dom_sid *sid, struct dom_sid **sids,
141 uint32_t *num);
142 bool add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
143 uint32_t rid, uint32_t **pp_rids, size_t *p_num);
144 bool is_null_sid(const struct dom_sid *sid);
145 bool sids_contains_sid(const struct dom_sid *sids,
146 const uint32_t num_sids,
147 const struct dom_sid *sid);
148 bool sid_attrs_contains_sid(const struct auth_SidAttr *sids,
149 const uint32_t num_sids,
150 const struct dom_sid *sid);
151 bool sids_contains_sid_attrs(const struct auth_SidAttr *sids,
152 const uint32_t num_sids,
153 const struct dom_sid *sid,
154 uint32_t attrs);
156 #endif /*_DOM_SID_H_*/