lib: Make sid_parse return the parsed length
[ambi/samba-autobuild/.git] / libcli / security / dom_sid.h
1 /*
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4
5    Copyright (C) Stefan (metze) Metzmacher      2002-2004
6    Copyright (C) Andrew Tridgell                1992-2004
7    Copyright (C) Jeremy Allison                 1999
8
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.
13
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.
18
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/>.
21 */
22
23 #ifndef _DOM_SID_H_
24 #define _DOM_SID_H_
25
26 #include "librpc/gen_ndr/security.h"
27
28 /* Some well-known SIDs */
29 extern const struct dom_sid global_sid_World_Domain;
30 extern const struct dom_sid global_sid_World;
31 extern const struct dom_sid global_sid_Local_Authority;
32 extern const struct dom_sid global_sid_Creator_Owner_Domain;
33 extern const struct dom_sid global_sid_NT_Authority;
34 extern const struct dom_sid global_sid_Enterprise_DCs;
35 extern const struct dom_sid global_sid_System;
36 extern const struct dom_sid global_sid_NULL;
37 extern const struct dom_sid global_sid_Authenticated_Users;
38 extern const struct dom_sid global_sid_Network;
39 extern const struct dom_sid global_sid_Asserted_Identity;
40 extern const struct dom_sid global_sid_Asserted_Identity_Service;
41 extern const struct dom_sid global_sid_Asserted_Identity_Authentication_Authority;
42 extern const struct dom_sid global_sid_Creator_Owner;
43 extern const struct dom_sid global_sid_Creator_Group;
44 extern const struct dom_sid global_sid_Owner_Rights;
45 extern const struct dom_sid global_sid_Anonymous;
46 extern const struct dom_sid global_sid_Builtin;
47 extern const struct dom_sid global_sid_Builtin_Administrators;
48 extern const struct dom_sid global_sid_Builtin_Users;
49 extern const struct dom_sid global_sid_Builtin_Guests;
50 extern const struct dom_sid global_sid_Builtin_Power_Users;
51 extern const struct dom_sid global_sid_Builtin_Account_Operators;
52 extern const struct dom_sid global_sid_Builtin_Server_Operators;
53 extern const struct dom_sid global_sid_Builtin_Print_Operators;
54 extern const struct dom_sid global_sid_Builtin_Backup_Operators;
55 extern const struct dom_sid global_sid_Builtin_Replicator;
56 extern const struct dom_sid global_sid_Builtin_PreWin2kAccess;
57 extern const struct dom_sid global_sid_Unix_Users;
58 extern const struct dom_sid global_sid_Unix_Groups;
59 extern const struct dom_sid global_sid_Unix_NFS;
60 extern const struct dom_sid global_sid_Unix_NFS_Users;
61 extern const struct dom_sid global_sid_Unix_NFS_Groups;
62 extern const struct dom_sid global_sid_Unix_NFS_Mode;
63 extern const struct dom_sid global_sid_Unix_NFS_Other;
64
65 enum lsa_SidType;
66
67 NTSTATUS dom_sid_lookup_predefined_name(const char *name,
68                                         const struct dom_sid **sid,
69                                         enum lsa_SidType *type,
70                                         const struct dom_sid **authority_sid,
71                                         const char **authority_name);
72 NTSTATUS dom_sid_lookup_predefined_sid(const struct dom_sid *sid,
73                                        const char **name,
74                                        enum lsa_SidType *type,
75                                        const struct dom_sid **authority_sid,
76                                        const char **authority_name);
77 bool dom_sid_lookup_is_predefined_domain(const char *domain);
78
79 int dom_sid_compare_auth(const struct dom_sid *sid1,
80                          const struct dom_sid *sid2);
81 int dom_sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid2);
82 int dom_sid_compare_domain(const struct dom_sid *sid1,
83                            const struct dom_sid *sid2);
84 bool dom_sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2);
85 bool sid_append_rid(struct dom_sid *sid, uint32_t rid);
86 bool string_to_sid(struct dom_sid *sidout, const char *sidstr);
87 bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
88                         const char **endp);
89 bool dom_sid_parse(const char *sidstr, struct dom_sid *ret);
90 struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr);
91 struct dom_sid *dom_sid_parse_length(TALLOC_CTX *mem_ctx, const DATA_BLOB *sid);
92 struct dom_sid *dom_sid_dup(TALLOC_CTX *mem_ctx, const struct dom_sid *dom_sid);
93 struct dom_sid *dom_sid_add_rid(TALLOC_CTX *mem_ctx,
94                                 const struct dom_sid *domain_sid,
95                                 uint32_t rid);
96 NTSTATUS dom_sid_split_rid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
97                            struct dom_sid **domain, uint32_t *rid);
98 bool dom_sid_in_domain(const struct dom_sid *domain_sid,
99                        const struct dom_sid *sid);
100 bool dom_sid_is_valid_account_domain(const struct dom_sid *sid);
101
102 #define DOM_SID_STR_BUFLEN (15*11+25)
103 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
104
105 struct dom_sid_buf { char buf[DOM_SID_STR_BUFLEN]; };
106 char *dom_sid_str_buf(const struct dom_sid *sid, struct dom_sid_buf *dst);
107
108 const char *sid_type_lookup(uint32_t sid_type);
109 const struct security_token *get_system_token(void);
110 bool sid_compose(struct dom_sid *dst, const struct dom_sid *domain_sid, uint32_t rid);
111 bool sid_split_rid(struct dom_sid *sid, uint32_t *rid);
112 bool sid_peek_rid(const struct dom_sid *sid, uint32_t *rid);
113 bool sid_peek_check_rid(const struct dom_sid *exp_dom_sid, const struct dom_sid *sid, uint32_t *rid);
114 void sid_copy(struct dom_sid *dst, const struct dom_sid *src);
115 struct sid_parse_ret { ssize_t len; };
116 struct sid_parse_ret sid_parse(
117         const uint8_t *inbuf, size_t len, struct dom_sid *sid);
118 int sid_compare_domain(const struct dom_sid *sid1, const struct dom_sid *sid2);
119 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
120                           struct dom_sid **sids, uint32_t *num);
121 NTSTATUS add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
122                                  struct dom_sid **sids, uint32_t *num_sids);
123 void del_sid_from_array(const struct dom_sid *sid, struct dom_sid **sids,
124                         uint32_t *num);
125 bool add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
126                              uint32_t rid, uint32_t **pp_rids, size_t *p_num);
127 bool is_null_sid(const struct dom_sid *sid);
128
129 #endif /*_DOM_SID_H_*/
130