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