[LSASRV]
[reactos.git] / reactos / dll / win32 / lsasrv / session.c
1 /*
2 * PROJECT: Local Security Authority Server DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/lsasrv/session.c
5 * PURPOSE: Logon session management routines
6 * COPYRIGHT: Copyright 2013 Eric Kohl
7 */
8
9 /* INCLUDES ****************************************************************/
10
11 #include "lsasrv.h"
12
13 WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
14
15 typedef struct _LSAP_LOGON_SESSION
16 {
17 LIST_ENTRY Entry;
18 LUID LogonId;
19 } LSAP_LOGON_SESSION, *PLSAP_LOGON_SESSION;
20
21
22 /* GLOBALS *****************************************************************/
23
24 LIST_ENTRY SessionListHead;
25 ULONG SessionCount;
26
27 /* FUNCTIONS ***************************************************************/
28
29 VOID
30 LsapInitLogonSessions(VOID)
31 {
32 InitializeListHead(&SessionListHead);
33 SessionCount = 0;
34 }
35
36
37 static
38 PLSAP_LOGON_SESSION
39 LsapGetLogonSession(IN PLUID LogonId)
40 {
41 PLIST_ENTRY SessionEntry;
42 PLSAP_LOGON_SESSION CurrentSession;
43
44 SessionEntry = SessionListHead.Flink;
45 while (SessionEntry != &SessionListHead)
46 {
47 CurrentSession = CONTAINING_RECORD(SessionEntry,
48 LSAP_LOGON_SESSION,
49 Entry);
50 if (RtlEqualLuid(&CurrentSession->LogonId, LogonId))
51 return CurrentSession;
52
53 SessionEntry = SessionEntry->Flink;
54 }
55
56 return NULL;
57 }
58
59
60 NTSTATUS
61 NTAPI
62 LsapCreateLogonSession(IN PLUID LogonId)
63 {
64 PLSAP_LOGON_SESSION Session;
65
66 TRACE("()\n");
67
68 /* Fail, if a session already exists */
69 if (LsapGetLogonSession(LogonId) != NULL)
70 return STATUS_LOGON_SESSION_COLLISION;
71
72 /* Allocate a new session entry */
73 Session = RtlAllocateHeap(RtlGetProcessHeap(),
74 HEAP_ZERO_MEMORY,
75 sizeof(LSAP_LOGON_SESSION));
76 if (Session == NULL)
77 return STATUS_INSUFFICIENT_RESOURCES;
78
79 /* Initialize the session entry */
80 RtlCopyLuid(&Session->LogonId, LogonId);
81
82 /* Insert the new session into the session list */
83 InsertTailList(&SessionListHead, &Session->Entry);
84 SessionCount++;
85
86 return STATUS_SUCCESS;
87 }
88
89
90 NTSTATUS
91 NTAPI
92 LsapDeleteLogonSession(IN PLUID LogonId)
93 {
94 PLSAP_LOGON_SESSION Session;
95
96 TRACE("()\n");
97
98 /* Fail, if the session does not exist */
99 Session = LsapGetLogonSession(LogonId);
100 if (Session == NULL)
101 return STATUS_NO_SUCH_LOGON_SESSION;
102
103 /* Remove the session entry from the list */
104 RemoveEntryList(&Session->Entry);
105 SessionCount--;
106
107 /* Free the session entry */
108 RtlFreeHeap(RtlGetProcessHeap(), 0, Session);
109
110 return STATUS_SUCCESS;
111 }
112
113 /* EOF */