@@ -180,10 +180,11 @@ public function login($username, $password, $domainKey)
180
180
public function fetchUserData ($ attributes = "" )
181
181
{
182
182
if (empty ($ attributes )) {
183
- $ attributes = ['sn ' , 'objectSid ' , 'givenName ' , 'mail ' , 'telephoneNumber ' ];
183
+ $ attributes = ['sn ' , 'objectSid ' , 'sIDHistory ' , ' givenName ' , 'mail ' , 'telephoneNumber ' ];
184
184
}
185
185
186
186
array_push ($ attributes , 'objectSid ' ); # Push objectsid, regardless of source array, as we need it ALWAYS!
187
+ array_push ($ attributes , 'sIDHistory ' ); # Push sIDHistory, regardless of source array, as we need it ALWAYS!
187
188
188
189
$ search_filter = '(&(objectCategory=person)(samaccountname= ' . $ this ->_username . ')) ' ;
189
190
@@ -194,8 +195,9 @@ public function fetchUserData($attributes = "")
194
195
if ($ entries ['count ' ] > 1 ) {
195
196
return false ;
196
197
}
197
- $ sid = self ::SIDtoString ($ entries [0 ]['objectsid ' ][0 ]);
198
- return array_merge (['sid ' => $ sid ], self ::handleEntry ($ entries [0 ]));
198
+ $ sid = self ::SIDtoString ($ entries [0 ]['objectsid ' ])[0 ];
199
+ $ sidHistory = isset ($ entries [0 ]['sidhistory ' ]) ? self ::SIDtoString ($ entries [0 ]['sidhistory ' ]) : null ;
200
+ return array_merge (['sid ' => $ sid , 'sidhistory ' => $ sidHistory ], self ::handleEntry ($ entries [0 ]));
199
201
} else {
200
202
return false ;
201
203
}
@@ -216,13 +218,14 @@ public function searchUser($searchFor, $attributes = "", $searchFilter = "", $au
216
218
}
217
219
218
220
if (empty ($ attributes )) {
219
- $ attributes = ['sn ' , 'objectSid ' , 'givenName ' , 'mail ' , 'telephoneNumber ' , 'l ' , 'physicalDeliveryOfficeName ' ];
221
+ $ attributes = ['sn ' , 'objectSid ' , 'sIDHistory ' , ' givenName ' , 'mail ' , 'telephoneNumber ' , 'l ' , 'physicalDeliveryOfficeName ' ];
220
222
}
221
223
222
224
array_push ($ attributes , 'objectSid ' ); # Push objectsid, regardless of source array, as we need it ALWAYS!
225
+ array_push ($ attributes , 'sIDHistory ' ); # Push sIDHistory, regardless of source array, as we need it ALWAYS!
223
226
224
227
if (empty ($ searchFilter )) {
225
- $ searchFilter = "(&(objectCategory=person)(|(objectSid=%searchFor%)(samaccountname=*%searchFor%*)(mail=*%searchFor%*)(sn=*%searchFor%*)(givenName=*%searchFor%*)(l=%searchFor%)(physicalDeliveryOfficeName=%searchFor%))) " ;
228
+ $ searchFilter = "(&(objectCategory=person)(|(objectSid=%searchFor%)(sIDHistory=%searchFor%)( samaccountname=*%searchFor%*)(mail=*%searchFor%*)(sn=*%searchFor%*)(givenName=*%searchFor%*)(l=%searchFor%)(physicalDeliveryOfficeName=%searchFor%))) " ;
226
229
}
227
230
228
231
if ($ autodetect ) {
@@ -263,8 +266,9 @@ public function searchUser($searchFor, $attributes = "", $searchFilter = "", $au
263
266
Yii::warning ('No objectsid! ignoring! ' );
264
267
continue ;
265
268
}
266
- $ sid = self ::SIDtoString ($ entry ['objectsid ' ][0 ]);
267
- $ additionalData = ['sid ' => $ sid , 'dn ' => $ entry ['dn ' ], 'domainKey ' => $ i ];
269
+ $ sid = self ::SIDtoString ($ entry ['objectsid ' ])[0 ];
270
+ $ sidHistory = isset ($ entry ['sidhistory ' ]) ? self ::SIDtoString ($ entry ['sidhistory ' ]) : null ;
271
+ $ additionalData = ['sid ' => $ sid , 'sidhistory ' => $ sidHistory , 'dn ' => $ entry ['dn ' ], 'domainKey ' => $ i ];
268
272
if (count ($ this ->domains ) > 1 ) {
269
273
// Enable domainName output if more than one domains configured
270
274
$ additionalData ['domainName ' ] = $ this ->domains [$ i ]['name ' ];
@@ -282,29 +286,36 @@ public function searchUser($searchFor, $attributes = "", $searchFilter = "", $au
282
286
283
287
public static function SIDtoString ($ ADsid )
284
288
{
285
- $ sid = "S- " ;
286
- //$ADguid = $info[0]['objectguid'][0];
287
- $ sidinhex = str_split (bin2hex ($ ADsid ), 2 );
288
- // Byte 0 = Revision Level
289
- $ sid = $ sid . hexdec ($ sidinhex [0 ]) . "- " ;
290
- // Byte 1-7 = 48 Bit Authority
291
- $ sid = $ sid . hexdec ($ sidinhex [6 ] . $ sidinhex [5 ] . $ sidinhex [4 ] . $ sidinhex [3 ] . $ sidinhex [2 ] . $ sidinhex [1 ]);
292
- // Byte 8 count of sub authorities - Get number of sub-authorities
293
- $ subauths = hexdec ($ sidinhex [7 ]);
294
- //Loop through Sub Authorities
295
- for ($ i = 0 ; $ i < $ subauths ; $ i ++) {
296
- $ start = 8 + (4 * $ i );
297
- // X amount of 32Bit (4 Byte) Sub Authorities
298
- $ sid = $ sid . "- " . hexdec ($ sidinhex [$ start + 3 ] . $ sidinhex [$ start + 2 ] . $ sidinhex [$ start + 1 ] . $ sidinhex [$ start ]);
289
+ $ results = [];
290
+ Yii::debug ('Converting SID... ' , __METHOD__ );
291
+ for ($ cnt = 0 ; $ cnt < $ ADsid ['count ' ]; $ cnt ++) {
292
+ Yii::debug ('Run ' . $ cnt , __METHOD__ );
293
+ $ sid = "S- " ;
294
+ //$ADguid = $info[0]['objectguid'][0];
295
+ $ sidinhex = str_split (bin2hex ($ ADsid [$ cnt ]), 2 );
296
+ // Byte 0 = Revision Level
297
+ $ sid = $ sid . hexdec ($ sidinhex [0 ]) . "- " ;
298
+ // Byte 1-7 = 48 Bit Authority
299
+ $ sid = $ sid . hexdec ($ sidinhex [6 ] . $ sidinhex [5 ] . $ sidinhex [4 ] . $ sidinhex [3 ] . $ sidinhex [2 ] . $ sidinhex [1 ]);
300
+ // Byte 8 count of sub authorities - Get number of sub-authorities
301
+ $ subauths = hexdec ($ sidinhex [7 ]);
302
+ //Loop through Sub Authorities
303
+ for ($ i = 0 ; $ i < $ subauths ; $ i ++) {
304
+ $ start = 8 + (4 * $ i );
305
+ // X amount of 32Bit (4 Byte) Sub Authorities
306
+ $ sid = $ sid . "- " . hexdec ($ sidinhex [$ start + 3 ] . $ sidinhex [$ start + 2 ] . $ sidinhex [$ start + 1 ] . $ sidinhex [$ start ]);
307
+ }
308
+ Yii::debug ('Converted SID to: ' . $ sid , __METHOD__ );
309
+ array_push ($ results , $ sid );
299
310
}
300
- return $ sid ;
311
+ return $ results ;
301
312
}
302
313
303
314
public static function handleEntry ($ entry )
304
315
{
305
316
$ newEntry = [];
306
317
foreach ($ entry as $ attr => $ value ) {
307
- if (is_int ($ attr ) || $ attr == 'objectsid ' || !isset ($ value ['count ' ])) {
318
+ if (is_int ($ attr ) || $ attr == 'objectsid ' || $ attr == ' sidhistory ' || !isset ($ value ['count ' ])) {
308
319
continue ;
309
320
}
310
321
$ count = $ value ['count ' ];
0 commit comments