2 * ReactOS Authorization Framework
3 * Copyright (C) 2005 - 2006 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /* $Id: aclui.c 18173 2005-09-30 18:54:48Z weiden $
21 * PROJECT: ReactOS Authorization Framework
22 * FILE: lib/authz/clictx.c
23 * PURPOSE: Authorization Framework
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
38 AuthzInitializeContextFromSid(IN DWORD Flags
,
40 IN AUTHZ_RESOURCE_MANAGER_HANDLE AuthzResourceManager
,
41 IN PLARGE_INTEGER pExpirationTime
,
43 IN PVOID DynamicGroupArgs
,
44 OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext
)
48 if (AuthzResourceManager
!= NULL
&& pExpirationTime
!= NULL
&& pAuthzClientContext
!= NULL
&&
49 UserSid
!= NULL
&& IsValidSid(UserSid
) && !(Flags
& (AUTHZ_SKIP_TOKEN_GROUPS
| AUTHZ_REQUIRE_S4U_LOGON
)))
51 PAUTHZ_CLIENT_CONTEXT ClientCtx
;
52 //PAUTHZ_RESMAN ResMan = (PAUTHZ_RESMAN)AuthzResourceManager;
54 VALIDATE_RESMAN_HANDLE(AuthzResourceManager
);
56 ClientCtx
= (PAUTHZ_CLIENT_CONTEXT
)LocalAlloc(LMEM_FIXED
,
57 sizeof(AUTHZ_CLIENT_CONTEXT
));
58 if (ClientCtx
!= NULL
)
62 /* initialize the client context structure */
64 ClientCtx
->Tag
= CLIENTCTX_TAG
;
67 /* simply copy the SID */
68 SidLen
= GetLengthSid(UserSid
);
69 ClientCtx
->UserSid
= (PSID
)LocalAlloc(LMEM_FIXED
,
71 if (ClientCtx
->UserSid
== NULL
)
73 LocalFree((HLOCAL
)ClientCtx
);
80 ClientCtx
->AuthzResourceManager
= AuthzResourceManager
;
81 ClientCtx
->Luid
= Identifier
;
82 ClientCtx
->ExpirationTime
.QuadPart
= (pExpirationTime
!= NULL
? pExpirationTime
->QuadPart
: 0);
83 ClientCtx
->ServerContext
= NULL
; /* FIXME */
84 ClientCtx
->DynamicGroupArgs
= DynamicGroupArgs
;
86 /* return the client context handle */
87 *pAuthzClientContext
= (AUTHZ_CLIENT_CONTEXT_HANDLE
)ClientCtx
;
93 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
97 SetLastError(ERROR_INVALID_PARAMETER
);
109 AuthzGetInformationFromContext(IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext
,
110 IN AUTHZ_CONTEXT_INFORMATION_CLASS InfoClass
,
112 OUT PDWORD pSizeRequired
,
117 if (hAuthzClientContext
!= NULL
&& pSizeRequired
!= NULL
)
119 PAUTHZ_CLIENT_CONTEXT ClientCtx
= (PAUTHZ_CLIENT_CONTEXT
)hAuthzClientContext
;
121 VALIDATE_CLIENTCTX_HANDLE(hAuthzClientContext
);
125 case AuthzContextInfoUserSid
:
127 DWORD SidLen
= GetLengthSid(ClientCtx
->UserSid
);
128 *pSizeRequired
= SidLen
;
129 if (BufferSize
< SidLen
)
131 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
135 Ret
= CopySid(SidLen
,
142 case AuthzContextInfoGroupsSids
:
143 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
146 case AuthzContextInfoRestrictedSids
:
147 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
150 case AuthzContextInfoPrivileges
:
151 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
154 case AuthzContextInfoExpirationTime
:
155 *pSizeRequired
= sizeof(LARGE_INTEGER
);
156 if (BufferSize
< sizeof(LARGE_INTEGER
) || Buffer
== NULL
)
158 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
162 *((PLARGE_INTEGER
)Buffer
) = ClientCtx
->ExpirationTime
;
167 case AuthzContextInfoServerContext
:
168 *pSizeRequired
= sizeof(AUTHZ_CLIENT_CONTEXT_HANDLE
);
169 if (BufferSize
< sizeof(AUTHZ_CLIENT_CONTEXT_HANDLE
) || Buffer
== NULL
)
171 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
175 *((PAUTHZ_CLIENT_CONTEXT_HANDLE
)Buffer
) = ClientCtx
->ServerContext
;
180 case AuthzContextInfoIdentifier
:
181 *pSizeRequired
= sizeof(LUID
);
182 if (BufferSize
< sizeof(LUID
) || Buffer
== NULL
)
184 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
188 *((PLUID
)Buffer
) = ClientCtx
->Luid
;
194 SetLastError(ERROR_INVALID_PARAMETER
);
199 SetLastError(ERROR_INVALID_PARAMETER
);
211 AuthzFreeContext(IN AUTHZ_CLIENT_CONTEXT_HANDLE AuthzClientContext
)
215 if (AuthzClientContext
!= NULL
)
217 PAUTHZ_CLIENT_CONTEXT ClientCtx
= (PAUTHZ_CLIENT_CONTEXT
)AuthzClientContext
;
219 VALIDATE_CLIENTCTX_HANDLE(AuthzClientContext
);
221 if (ClientCtx
->UserSid
!= NULL
)
223 LocalFree((HLOCAL
)ClientCtx
->UserSid
);
226 LocalFree((HLOCAL
)ClientCtx
);
230 SetLastError(ERROR_INVALID_PARAMETER
);