First round of merging various UUID structures.
[Samba/gebeck_regimport.git] / source3 / libads / ads_utils.c
blob1aad0bed547ed553ebc2541eae76e00c344e9ecc
1 /*
2 Unix SMB/CIFS implementation.
3 ads (active directory) utility library
5 Copyright (C) Stefan (metze) Metzmacher 2002
6 Copyright (C) Andrew Tridgell 2001
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
25 /*
26 translated the ACB_CTRL Flags to UserFlags (userAccountControl)
27 */
28 uint32 ads_acb2uf(uint16 acb)
30 uint32 uf = 0x00000000;
32 if (acb & ACB_DISABLED) uf |= UF_ACCOUNTDISABLE;
33 if (acb & ACB_HOMDIRREQ) uf |= UF_HOMEDIR_REQUIRED;
34 if (acb & ACB_PWNOTREQ) uf |= UF_PASSWD_NOTREQD;
35 if (acb & ACB_TEMPDUP) uf |= UF_TEMP_DUPLICATE_ACCOUNT;
36 if (acb & ACB_NORMAL) uf |= UF_NORMAL_ACCOUNT;
37 if (acb & ACB_MNS) uf |= UF_MNS_LOGON_ACCOUNT;
38 if (acb & ACB_DOMTRUST) uf |= UF_INTERDOMAIN_TRUST_ACCOUNT;
39 if (acb & ACB_WSTRUST) uf |= UF_WORKSTATION_TRUST_ACCOUNT;
40 if (acb & ACB_SVRTRUST) uf |= UF_SERVER_TRUST_ACCOUNT;
41 if (acb & ACB_PWNOEXP) uf |= UF_DONT_EXPIRE_PASSWD;
42 if (acb & ACB_AUTOLOCK) uf |= UF_LOCKOUT;
44 return uf;
48 translated the UserFlags (userAccountControl) to ACB_CTRL Flags
50 uint16 ads_uf2acb(uint32 uf)
52 uint16 acb = 0x0000;
54 if (uf & UF_ACCOUNTDISABLE) acb |= ACB_DISABLED;
55 if (uf & UF_HOMEDIR_REQUIRED) acb |= ACB_HOMDIRREQ;
56 if (uf & UF_PASSWD_NOTREQD) acb |= ACB_PWNOTREQ;
57 if (uf & UF_MNS_LOGON_ACCOUNT) acb |= ACB_MNS;
58 if (uf & UF_DONT_EXPIRE_PASSWD) acb |= ACB_PWNOEXP;
59 if (uf & UF_LOCKOUT) acb |= ACB_AUTOLOCK;
61 switch (uf & UF_ACCOUNT_TYPE_MASK)
63 case UF_TEMP_DUPLICATE_ACCOUNT: acb |= ACB_TEMPDUP;break;
64 case UF_NORMAL_ACCOUNT: acb |= ACB_NORMAL;break;
65 case UF_INTERDOMAIN_TRUST_ACCOUNT: acb |= ACB_DOMTRUST;break;
66 case UF_WORKSTATION_TRUST_ACCOUNT: acb |= ACB_WSTRUST;break;
67 case UF_SERVER_TRUST_ACCOUNT: acb |= ACB_SVRTRUST;break;
68 /*Fix Me: what should we do here? */
69 default: acb |= ACB_NORMAL;break;
72 return acb;
75 /*
76 get the accountType from the UserFlags
78 uint32 ads_uf2atype(uint32 uf)
80 uint32 atype = 0x00000000;
82 if (uf & UF_NORMAL_ACCOUNT) atype = ATYPE_NORMAL_ACCOUNT;
83 else if (uf & UF_TEMP_DUPLICATE_ACCOUNT) atype = ATYPE_NORMAL_ACCOUNT;
84 else if (uf & UF_SERVER_TRUST_ACCOUNT) atype = ATYPE_WORKSTATION_TRUST;
85 else if (uf & UF_WORKSTATION_TRUST_ACCOUNT) atype = ATYPE_WORKSTATION_TRUST;
86 else if (uf & UF_INTERDOMAIN_TRUST_ACCOUNT) atype = ATYPE_INTERDOMAIN_TRUST;
88 return atype;
91 /*
92 get the accountType from the groupType
94 uint32 ads_gtype2atype(uint32 gtype)
96 uint32 atype = 0x00000000;
98 switch(gtype) {
99 case GTYPE_SECURITY_BUILTIN_LOCAL_GROUP:
100 atype = ATYPE_SECURITY_LOCAL_GROUP;
101 break;
102 case GTYPE_SECURITY_DOMAIN_LOCAL_GROUP:
103 atype = ATYPE_SECURITY_LOCAL_GROUP;
104 break;
105 case GTYPE_SECURITY_GLOBAL_GROUP:
106 atype = ATYPE_SECURITY_GLOBAL_GROUP;
107 break;
109 case GTYPE_DISTRIBUTION_GLOBAL_GROUP:
110 atype = ATYPE_DISTRIBUTION_GLOBAL_GROUP;
111 break;
112 case GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP:
113 atype = ATYPE_DISTRIBUTION_UNIVERSAL_GROUP;
114 break;
115 case GTYPE_DISTRIBUTION_UNIVERSAL_GROUP:
116 atype = ATYPE_DISTRIBUTION_LOCAL_GROUP;
117 break;
120 return atype;
123 /* turn a sAMAccountType into a SID_NAME_USE */
124 enum SID_NAME_USE ads_atype_map(uint32 atype)
126 switch (atype & 0xF0000000) {
127 case ATYPE_GLOBAL_GROUP:
128 return SID_NAME_DOM_GRP;
129 case ATYPE_SECURITY_LOCAL_GROUP:
130 return SID_NAME_ALIAS;
131 case ATYPE_ACCOUNT:
132 return SID_NAME_USER;
133 default:
134 DEBUG(1,("hmm, need to map account type 0x%x\n", atype));
136 return SID_NAME_UNKNOWN;