summaryrefslogtreecommitdiffhomepage
path: root/src/object/ntapi_tt_sid.c
blob: a35b9a7bb5181110aa6149b110f9ad079bb65624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_object.h>
#include "ntapi_impl.h"

void __stdcall __ntapi_tt_sid_copy(
	__out	nt_sid *	dst,
	__in	const nt_sid *	src)
{
	int i;

	dst->revision             = src->revision;
	dst->sub_authority_count  = src->sub_authority_count;
	dst->identifier_authority = src->identifier_authority;

	for (i=0; i<src->sub_authority_count; i++)
		dst->sub_authority[i] = src->sub_authority[i];
}

int32_t __stdcall __ntapi_tt_sid_compare(
	__in	const nt_sid *	sida,
	__in	const nt_sid *	sidb)
{
	int			i;
	int32_t			a;
	int32_t			b;
	const unsigned char *	va;
	const unsigned char *	vb;

	if ((a = sida->revision) - (b = sidb->revision))
		return a-b;

	if ((a = sida->sub_authority_count) - (b = sidb->sub_authority_count))
		return a-b;

	va=sida->identifier_authority.value;
	vb=sidb->identifier_authority.value;

	for (i=0; i<6; i++)
		if ((a = va[i]) - (b = vb[i]))
			return a-b;

	for (i=0; i<sida->sub_authority_count; i++)
		if ((a = sida->sub_authority[i]) - (b = sidb->sub_authority[i]))
			return a-b;

	return 0;
}