2 Unix SMB/CIFS implementation.
3 helper mapping functions for the SAMDB server
5 Copyright (C) Stefan (metze) Metzmacher 2002
6 Copyright (C) Andrew Tridgell 2004
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.
24 #include "librpc/gen_ndr/samr.h"
25 #include "dsdb/common/flags.h"
28 translated the ACB_CTRL Flags to UserFlags (userAccountControl)
30 /* mapping between ADS userAccountControl and SAMR acct_flags */
34 } acct_flags_map[] = {
35 { UF_ACCOUNTDISABLE, ACB_DISABLED },
36 { UF_HOMEDIR_REQUIRED, ACB_HOMDIRREQ },
37 { UF_PASSWD_NOTREQD, ACB_PWNOTREQ },
38 { UF_TEMP_DUPLICATE_ACCOUNT, ACB_TEMPDUP },
39 { UF_NORMAL_ACCOUNT, ACB_NORMAL },
40 { UF_MNS_LOGON_ACCOUNT, ACB_MNS },
41 { UF_INTERDOMAIN_TRUST_ACCOUNT, ACB_DOMTRUST },
42 { UF_WORKSTATION_TRUST_ACCOUNT, ACB_WSTRUST },
43 { UF_SERVER_TRUST_ACCOUNT, ACB_SVRTRUST },
44 { UF_DONT_EXPIRE_PASSWD, ACB_PWNOEXP },
45 { UF_LOCKOUT, ACB_AUTOLOCK },
46 { UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED, ACB_ENC_TXT_PWD_ALLOWED },
47 { UF_SMARTCARD_REQUIRED, ACB_SMARTCARD_REQUIRED },
48 { UF_TRUSTED_FOR_DELEGATION, ACB_TRUSTED_FOR_DELEGATION },
49 { UF_NOT_DELEGATED, ACB_NOT_DELEGATED },
50 { UF_USE_DES_KEY_ONLY, ACB_USE_DES_KEY_ONLY},
51 { UF_DONT_REQUIRE_PREAUTH, ACB_DONT_REQUIRE_PREAUTH },
52 { UF_PASSWORD_EXPIRED, ACB_PW_EXPIRED },
53 { UF_NO_AUTH_DATA_REQUIRED, ACB_NO_AUTH_DATA_REQD }
56 uint32_t samdb_acb2uf(uint32_t acb)
59 for (i=0;i<ARRAY_SIZE(acct_flags_map);i++) {
60 if (acct_flags_map[i].acb & acb) {
61 ret |= acct_flags_map[i].uf;
68 translated the UserFlags (userAccountControl) to ACB_CTRL Flags
70 uint32_t samdb_uf2acb(uint32_t uf)
74 for (i=0;i<ARRAY_SIZE(acct_flags_map);i++) {
75 if (acct_flags_map[i].uf & uf) {
76 ret |= acct_flags_map[i].acb;
83 get the accountType from the UserFlags
85 uint32_t samdb_uf2atype(uint32_t uf)
87 uint32_t atype = 0x00000000;
89 if (uf & UF_NORMAL_ACCOUNT) atype = ATYPE_NORMAL_ACCOUNT;
90 else if (uf & UF_TEMP_DUPLICATE_ACCOUNT) atype = ATYPE_NORMAL_ACCOUNT;
91 else if (uf & UF_SERVER_TRUST_ACCOUNT) atype = ATYPE_WORKSTATION_TRUST;
92 else if (uf & UF_WORKSTATION_TRUST_ACCOUNT) atype = ATYPE_WORKSTATION_TRUST;
93 else if (uf & UF_INTERDOMAIN_TRUST_ACCOUNT) atype = ATYPE_INTERDOMAIN_TRUST;
99 get the accountType from the groupType
101 uint32_t samdb_gtype2atype(uint32_t gtype)
103 uint32_t atype = 0x00000000;
106 case GTYPE_SECURITY_BUILTIN_LOCAL_GROUP:
107 atype = ATYPE_SECURITY_LOCAL_GROUP;
109 case GTYPE_SECURITY_DOMAIN_LOCAL_GROUP:
110 atype = ATYPE_SECURITY_LOCAL_GROUP;
112 case GTYPE_SECURITY_GLOBAL_GROUP:
113 atype = ATYPE_SECURITY_GLOBAL_GROUP;
116 case GTYPE_DISTRIBUTION_GLOBAL_GROUP:
117 atype = ATYPE_DISTRIBUTION_GLOBAL_GROUP;
119 case GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP:
120 atype = ATYPE_DISTRIBUTION_UNIVERSAL_GROUP;
122 case GTYPE_DISTRIBUTION_UNIVERSAL_GROUP:
123 atype = ATYPE_DISTRIBUTION_LOCAL_GROUP;
130 /* turn a sAMAccountType into a SID_NAME_USE */
131 enum lsa_SidType samdb_atype_map(uint32_t atype)
133 switch (atype & 0xF0000000) {
134 case ATYPE_GLOBAL_GROUP:
135 return SID_NAME_DOM_GRP;
136 case ATYPE_SECURITY_LOCAL_GROUP:
137 return SID_NAME_ALIAS;
139 return SID_NAME_USER;
141 DEBUG(1,("hmm, need to map account type 0x%x\n", atype));
143 return SID_NAME_UNKNOWN;