partial implementation of AuthzInitializeContextFromSid(), AuthzGetInformationFromCon...
[reactos.git] / reactos / lib / authz / clictx.c
1 /*
2 * ReactOS Authorization Framework
3 * Copyright (C) 2005 - 2006 ReactOS Team
4 *
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.
9 *
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.
14 *
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
18 */
19 /* $Id: aclui.c 18173 2005-09-30 18:54:48Z weiden $
20 *
21 * PROJECT: ReactOS Authorization Framework
22 * FILE: lib/authz/clictx.c
23 * PURPOSE: Authorization Framework
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
25 *
26 * UPDATE HISTORY:
27 * 10/07/2005 Created
28 */
29 #include <precomp.h>
30
31
32 /*
33 * @unimplemented
34 */
35 AUTHZAPI
36 BOOL
37 WINAPI
38 AuthzInitializeContextFromSid(IN DWORD Flags,
39 IN PSID UserSid,
40 IN AUTHZ_RESOURCE_MANAGER_HANDLE AuthzResourceManager,
41 IN PLARGE_INTEGER pExpirationTime,
42 IN LUID Identifier,
43 IN PVOID DynamicGroupArgs,
44 OUT PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext)
45 {
46 BOOL Ret = FALSE;
47
48 if (AuthzResourceManager != NULL && pExpirationTime != NULL && pAuthzClientContext != NULL &&
49 UserSid != NULL && IsValidSid(UserSid) && !(Flags & (AUTHZ_SKIP_TOKEN_GROUPS | AUTHZ_REQUIRE_S4U_LOGON)))
50 {
51 PAUTHZ_CLIENT_CONTEXT ClientCtx;
52 //PAUTHZ_RESMAN ResMan = (PAUTHZ_RESMAN)AuthzResourceManager;
53
54 VALIDATE_RESMAN_HANDLE(AuthzResourceManager);
55
56 ClientCtx = (PAUTHZ_CLIENT_CONTEXT)LocalAlloc(LMEM_FIXED,
57 sizeof(AUTHZ_CLIENT_CONTEXT));
58 if (ClientCtx != NULL)
59 {
60 DWORD SidLen;
61
62 /* initialize the client context structure */
63 #if DBG
64 ClientCtx->Tag = CLIENTCTX_TAG;
65 #endif
66
67 /* simply copy the SID */
68 SidLen = GetLengthSid(UserSid);
69 ClientCtx->UserSid = (PSID)LocalAlloc(LMEM_FIXED,
70 SidLen);
71 if (ClientCtx->UserSid == NULL)
72 {
73 LocalFree((HLOCAL)ClientCtx);
74 goto FailNoMemory;
75 }
76 CopySid(SidLen,
77 ClientCtx->UserSid,
78 UserSid);
79
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;
85
86 /* return the client context handle */
87 *pAuthzClientContext = (AUTHZ_CLIENT_CONTEXT_HANDLE)ClientCtx;
88 Ret = TRUE;
89 }
90 else
91 {
92 FailNoMemory:
93 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
94 }
95 }
96 else
97 SetLastError(ERROR_INVALID_PARAMETER);
98
99 return Ret;
100 }
101
102
103 /*
104 * @unimplemented
105 */
106 AUTHZAPI
107 BOOL
108 WINAPI
109 AuthzGetInformationFromContext(IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
110 IN AUTHZ_CONTEXT_INFORMATION_CLASS InfoClass,
111 IN DWORD BufferSize,
112 OUT PDWORD pSizeRequired,
113 OUT PVOID Buffer)
114 {
115 BOOL Ret = FALSE;
116
117 if (hAuthzClientContext != NULL && pSizeRequired != NULL)
118 {
119 PAUTHZ_CLIENT_CONTEXT ClientCtx = (PAUTHZ_CLIENT_CONTEXT)hAuthzClientContext;
120
121 VALIDATE_CLIENTCTX_HANDLE(hAuthzClientContext);
122
123 switch (InfoClass)
124 {
125 case AuthzContextInfoUserSid:
126 {
127 DWORD SidLen = GetLengthSid(ClientCtx->UserSid);
128 *pSizeRequired = SidLen;
129 if (BufferSize < SidLen)
130 {
131 SetLastError(ERROR_INSUFFICIENT_BUFFER);
132 }
133 else
134 {
135 Ret = CopySid(SidLen,
136 (PSID)Buffer,
137 ClientCtx->UserSid);
138 }
139 break;
140 }
141
142 case AuthzContextInfoGroupsSids:
143 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
144 break;
145
146 case AuthzContextInfoRestrictedSids:
147 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
148 break;
149
150 case AuthzContextInfoPrivileges:
151 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
152 break;
153
154 case AuthzContextInfoExpirationTime:
155 *pSizeRequired = sizeof(LARGE_INTEGER);
156 if (BufferSize < sizeof(LARGE_INTEGER) || Buffer == NULL)
157 {
158 SetLastError(ERROR_INSUFFICIENT_BUFFER);
159 }
160 else
161 {
162 *((PLARGE_INTEGER)Buffer) = ClientCtx->ExpirationTime;
163 Ret = TRUE;
164 }
165 break;
166
167 case AuthzContextInfoServerContext:
168 *pSizeRequired = sizeof(AUTHZ_CLIENT_CONTEXT_HANDLE);
169 if (BufferSize < sizeof(AUTHZ_CLIENT_CONTEXT_HANDLE) || Buffer == NULL)
170 {
171 SetLastError(ERROR_INSUFFICIENT_BUFFER);
172 }
173 else
174 {
175 *((PAUTHZ_CLIENT_CONTEXT_HANDLE)Buffer) = ClientCtx->ServerContext;
176 Ret = TRUE;
177 }
178 break;
179
180 case AuthzContextInfoIdentifier:
181 *pSizeRequired = sizeof(LUID);
182 if (BufferSize < sizeof(LUID) || Buffer == NULL)
183 {
184 SetLastError(ERROR_INSUFFICIENT_BUFFER);
185 }
186 else
187 {
188 *((PLUID)Buffer) = ClientCtx->Luid;
189 Ret = TRUE;
190 }
191 break;
192
193 default:
194 SetLastError(ERROR_INVALID_PARAMETER);
195 break;
196 }
197 }
198 else
199 SetLastError(ERROR_INVALID_PARAMETER);
200
201 return Ret;
202 }
203
204
205 /*
206 * @implemented
207 */
208 AUTHZAPI
209 BOOL
210 WINAPI
211 AuthzFreeContext(IN AUTHZ_CLIENT_CONTEXT_HANDLE AuthzClientContext)
212 {
213 BOOL Ret = FALSE;
214
215 if (AuthzClientContext != NULL)
216 {
217 PAUTHZ_CLIENT_CONTEXT ClientCtx = (PAUTHZ_CLIENT_CONTEXT)AuthzClientContext;
218
219 VALIDATE_CLIENTCTX_HANDLE(AuthzClientContext);
220
221 if (ClientCtx->UserSid != NULL)
222 {
223 LocalFree((HLOCAL)ClientCtx->UserSid);
224 }
225
226 LocalFree((HLOCAL)ClientCtx);
227 Ret = TRUE;
228 }
229 else
230 SetLastError(ERROR_INVALID_PARAMETER);
231
232 return Ret;
233 }