2 Unix SMB/CIFS implementation.
4 DRSUAPI utility functions to be used in torture tests
6 Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009
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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "torture/rpc/drsuapi.h"
25 #include "../lib/util/asn1.h"
28 * Decode Attribute OID based on MS documentation
29 * See MS-DRSR.pdf - 5.16.4
31 * On success returns decoded OID and
32 * corresponding prefix_map index (if requested)
34 bool drs_util_oid_from_attid(struct torture_context
*tctx
,
35 const struct drsuapi_DsReplicaOIDMapping_Ctr
*prefix_map
,
41 uint32_t hi_word
, lo_word
;
42 DATA_BLOB bin_oid
= {NULL
, 0};
43 struct drsuapi_DsReplicaOIDMapping
*map_entry
= NULL
;
44 TALLOC_CTX
*mem_ctx
= talloc_named(tctx
, 0, "util_drsuapi_oid_from_attid");
46 /* crack attid value */
47 hi_word
= attid
>> 16;
48 lo_word
= attid
& 0xFFFF;
50 /* check last entry in the prefix map is the special one */
51 map_entry
= &prefix_map
->mappings
[prefix_map
->num_mappings
-1];
53 (map_entry
->id_prefix
== 0)
54 && (*map_entry
->oid
.binary_oid
== 0xFF),
55 "Last entry in Prefix Map is not the special one!");
57 /* locate corresponding prefixMap entry */
59 for (i
= 0; i
< prefix_map
->num_mappings
- 1; i
++) {
61 if (hi_word
== prefix_map
->mappings
[i
].id_prefix
) {
62 map_entry
= &prefix_map
->mappings
[i
];
63 if (map_idx
) *map_idx
= i
;
68 torture_assert(tctx
, map_entry
, "Unable to locate corresponding Prefix Map entry");
70 /* copy partial oid making enough room */
71 bin_oid
.length
= map_entry
->oid
.length
+ 2;
72 bin_oid
.data
= talloc_array(mem_ctx
, uint8_t, bin_oid
.length
);
73 torture_assert(tctx
, bin_oid
.data
, "Not enough memory");
74 memcpy(bin_oid
.data
, map_entry
->oid
.binary_oid
, map_entry
->oid
.length
);
77 bin_oid
.length
= bin_oid
.length
- 1;
78 bin_oid
.data
[bin_oid
.length
-1] = lo_word
;
81 if (lo_word
>= 32768) {
84 bin_oid
.data
[bin_oid
.length
-2] = ((lo_word
/ 128) % 128) + 128; // (0x80 | ((lo_word>>7) & 0x7f))
85 bin_oid
.data
[bin_oid
.length
-1] = lo_word
% 128; // lo_word & 0x7f
89 ber_read_OID_String(tctx
, bin_oid
, _oid
),
90 "Failed to decode binary OID");
97 * Utility function to convert drsuapi_DsAttributeId to String
99 const char * drs_util_DsAttributeId_to_string(enum drsuapi_DsAttributeId r
)
101 const char *val
= NULL
;
104 case DRSUAPI_ATTRIBUTE_objectClass
: val
= "DRSUAPI_ATTRIBUTE_objectClass"; break;
105 case DRSUAPI_ATTRIBUTE_description
: val
= "DRSUAPI_ATTRIBUTE_description"; break;
106 case DRSUAPI_ATTRIBUTE_member
: val
= "DRSUAPI_ATTRIBUTE_member"; break;
107 case DRSUAPI_ATTRIBUTE_instanceType
: val
= "DRSUAPI_ATTRIBUTE_instanceType"; break;
108 case DRSUAPI_ATTRIBUTE_whenCreated
: val
= "DRSUAPI_ATTRIBUTE_whenCreated"; break;
109 case DRSUAPI_ATTRIBUTE_hasMasterNCs
: val
= "DRSUAPI_ATTRIBUTE_hasMasterNCs"; break;
110 case DRSUAPI_ATTRIBUTE_governsID
: val
= "DRSUAPI_ATTRIBUTE_governsID"; break;
111 case DRSUAPI_ATTRIBUTE_attributeID
: val
= "DRSUAPI_ATTRIBUTE_attributeID"; break;
112 case DRSUAPI_ATTRIBUTE_attributeSyntax
: val
= "DRSUAPI_ATTRIBUTE_attributeSyntax"; break;
113 case DRSUAPI_ATTRIBUTE_isSingleValued
: val
= "DRSUAPI_ATTRIBUTE_isSingleValued"; break;
114 case DRSUAPI_ATTRIBUTE_rangeLower
: val
= "DRSUAPI_ATTRIBUTE_rangeLower"; break;
115 case DRSUAPI_ATTRIBUTE_rangeUpper
: val
= "DRSUAPI_ATTRIBUTE_rangeUpper"; break;
116 case DRSUAPI_ATTRIBUTE_dMDLocation
: val
= "DRSUAPI_ATTRIBUTE_dMDLocation"; break;
117 case DRSUAPI_ATTRIBUTE_objectVersion
: val
= "DRSUAPI_ATTRIBUTE_objectVersion"; break;
118 case DRSUAPI_ATTRIBUTE_invocationId
: val
= "DRSUAPI_ATTRIBUTE_invocationId"; break;
119 case DRSUAPI_ATTRIBUTE_showInAdvancedViewOnly
: val
= "DRSUAPI_ATTRIBUTE_showInAdvancedViewOnly"; break;
120 case DRSUAPI_ATTRIBUTE_adminDisplayName
: val
= "DRSUAPI_ATTRIBUTE_adminDisplayName"; break;
121 case DRSUAPI_ATTRIBUTE_adminDescription
: val
= "DRSUAPI_ATTRIBUTE_adminDescription"; break;
122 case DRSUAPI_ATTRIBUTE_oMSyntax
: val
= "DRSUAPI_ATTRIBUTE_oMSyntax"; break;
123 case DRSUAPI_ATTRIBUTE_ntSecurityDescriptor
: val
= "DRSUAPI_ATTRIBUTE_ntSecurityDescriptor"; break;
124 case DRSUAPI_ATTRIBUTE_searchFlags
: val
= "DRSUAPI_ATTRIBUTE_searchFlags"; break;
125 case DRSUAPI_ATTRIBUTE_lDAPDisplayName
: val
= "DRSUAPI_ATTRIBUTE_lDAPDisplayName"; break;
126 case DRSUAPI_ATTRIBUTE_name
: val
= "DRSUAPI_ATTRIBUTE_name"; break;
127 case DRSUAPI_ATTRIBUTE_userAccountControl
: val
= "DRSUAPI_ATTRIBUTE_userAccountControl"; break;
128 case DRSUAPI_ATTRIBUTE_currentValue
: val
= "DRSUAPI_ATTRIBUTE_currentValue"; break;
129 case DRSUAPI_ATTRIBUTE_homeDirectory
: val
= "DRSUAPI_ATTRIBUTE_homeDirectory"; break;
130 case DRSUAPI_ATTRIBUTE_homeDrive
: val
= "DRSUAPI_ATTRIBUTE_homeDrive"; break;
131 case DRSUAPI_ATTRIBUTE_scriptPath
: val
= "DRSUAPI_ATTRIBUTE_scriptPath"; break;
132 case DRSUAPI_ATTRIBUTE_profilePath
: val
= "DRSUAPI_ATTRIBUTE_profilePath"; break;
133 case DRSUAPI_ATTRIBUTE_objectSid
: val
= "DRSUAPI_ATTRIBUTE_objectSid"; break;
134 case DRSUAPI_ATTRIBUTE_schemaIDGUID
: val
= "DRSUAPI_ATTRIBUTE_schemaIDGUID"; break;
135 case DRSUAPI_ATTRIBUTE_dBCSPwd
: val
= "DRSUAPI_ATTRIBUTE_dBCSPwd"; break;
136 case DRSUAPI_ATTRIBUTE_logonHours
: val
= "DRSUAPI_ATTRIBUTE_logonHours"; break;
137 case DRSUAPI_ATTRIBUTE_userWorkstations
: val
= "DRSUAPI_ATTRIBUTE_userWorkstations"; break;
138 case DRSUAPI_ATTRIBUTE_unicodePwd
: val
= "DRSUAPI_ATTRIBUTE_unicodePwd"; break;
139 case DRSUAPI_ATTRIBUTE_ntPwdHistory
: val
= "DRSUAPI_ATTRIBUTE_ntPwdHistory"; break;
140 case DRSUAPI_ATTRIBUTE_priorValue
: val
= "DRSUAPI_ATTRIBUTE_priorValue"; break;
141 case DRSUAPI_ATTRIBUTE_supplementalCredentials
: val
= "DRSUAPI_ATTRIBUTE_supplementalCredentials"; break;
142 case DRSUAPI_ATTRIBUTE_trustAuthIncoming
: val
= "DRSUAPI_ATTRIBUTE_trustAuthIncoming"; break;
143 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing
: val
= "DRSUAPI_ATTRIBUTE_trustAuthOutgoing"; break;
144 case DRSUAPI_ATTRIBUTE_lmPwdHistory
: val
= "DRSUAPI_ATTRIBUTE_lmPwdHistory"; break;
145 case DRSUAPI_ATTRIBUTE_sAMAccountName
: val
= "DRSUAPI_ATTRIBUTE_sAMAccountName"; break;
146 case DRSUAPI_ATTRIBUTE_sAMAccountType
: val
= "DRSUAPI_ATTRIBUTE_sAMAccountType"; break;
147 case DRSUAPI_ATTRIBUTE_fSMORoleOwner
: val
= "DRSUAPI_ATTRIBUTE_fSMORoleOwner"; break;
148 case DRSUAPI_ATTRIBUTE_systemFlags
: val
= "DRSUAPI_ATTRIBUTE_systemFlags"; break;
149 case DRSUAPI_ATTRIBUTE_serverReference
: val
= "DRSUAPI_ATTRIBUTE_serverReference"; break;
150 case DRSUAPI_ATTRIBUTE_serverReferenceBL
: val
= "DRSUAPI_ATTRIBUTE_serverReferenceBL"; break;
151 case DRSUAPI_ATTRIBUTE_initialAuthIncoming
: val
= "DRSUAPI_ATTRIBUTE_initialAuthIncoming"; break;
152 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing
: val
= "DRSUAPI_ATTRIBUTE_initialAuthOutgoing"; break;
153 case DRSUAPI_ATTRIBUTE_wellKnownObjects
: val
= "DRSUAPI_ATTRIBUTE_wellKnownObjects"; break;
154 case DRSUAPI_ATTRIBUTE_dNSHostName
: val
= "DRSUAPI_ATTRIBUTE_dNSHostName"; break;
155 case DRSUAPI_ATTRIBUTE_isMemberOfPartialAttributeSet
: val
= "DRSUAPI_ATTRIBUTE_isMemberOfPartialAttributeSet"; break;
156 case DRSUAPI_ATTRIBUTE_userPrincipalName
: val
= "DRSUAPI_ATTRIBUTE_userPrincipalName"; break;
157 case DRSUAPI_ATTRIBUTE_groupType
: val
= "DRSUAPI_ATTRIBUTE_groupType"; break;
158 case DRSUAPI_ATTRIBUTE_servicePrincipalName
: val
= "DRSUAPI_ATTRIBUTE_servicePrincipalName"; break;
159 case DRSUAPI_ATTRIBUTE_objectCategory
: val
= "DRSUAPI_ATTRIBUTE_objectCategory"; break;
160 case DRSUAPI_ATTRIBUTE_gPLink
: val
= "DRSUAPI_ATTRIBUTE_gPLink"; break;
161 case DRSUAPI_ATTRIBUTE_msDS_Behavior_Version
: val
= "DRSUAPI_ATTRIBUTE_msDS_Behavior_Version"; break;
162 case DRSUAPI_ATTRIBUTE_msDS_KeyVersionNumber
: val
= "DRSUAPI_ATTRIBUTE_msDS_KeyVersionNumber"; break;
163 case DRSUAPI_ATTRIBUTE_msDS_HasDomainNCs
: val
= "DRSUAPI_ATTRIBUTE_msDS_HasDomainNCs"; break;
164 case DRSUAPI_ATTRIBUTE_msDS_hasMasterNCs
: val
= "DRSUAPI_ATTRIBUTE_msDS_hasMasterNCs"; break;
165 default: val
= "UNKNOWN_ENUM_VALUE"; break;