[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 #include "lsasrv.h"
10
11 typedef struct _LSAP_LOGON_SESSION
12 {
13 LIST_ENTRY Entry;
14 LUID LogonId;
15 } LSAP_LOGON_SESSION, *PLSAP_LOGON_SESSION;
16
17
18 /* GLOBALS *****************************************************************/
19
20 LIST_ENTRY SessionListHead;
21 ULONG SessionCount;
22
23 /* FUNCTIONS ***************************************************************/
24
25 VOID
26 LsapInitLogonSessions(VOID)
27 {
28 InitializeListHead(&SessionListHead);
29 SessionCount = 0;
30 }
31
32
33 static
34 PLSAP_LOGON_SESSION
35 LsapGetLogonSession(IN PLUID LogonId)
36 {
37 PLIST_ENTRY SessionEntry;
38 PLSAP_LOGON_SESSION CurrentSession;
39
40 SessionEntry = SessionListHead.Flink;
41 while (SessionEntry != &SessionListHead)
42 {
43 CurrentSession = CONTAINING_RECORD(SessionEntry,
44 LSAP_LOGON_SESSION,
45 Entry);
46 if (RtlEqualLuid(&CurrentSession->LogonId, LogonId))
47 return CurrentSession;
48
49 SessionEntry = SessionEntry->Flink;
50 }
51
52 return NULL;
53 }
54
55
56 NTSTATUS
57 NTAPI
58 LsapCreateLogonSession(IN PLUID LogonId)
59 {
60 PLSAP_LOGON_SESSION Session;
61
62 TRACE("()\n");
63
64 /* Fail, if a session already exists */
65 if (LsapGetLogonSession(LogonId) != NULL)
66 return STATUS_LOGON_SESSION_COLLISION;
67
68 /* Allocate a new session entry */
69 Session = RtlAllocateHeap(RtlGetProcessHeap(),
70 HEAP_ZERO_MEMORY,
71 sizeof(LSAP_LOGON_SESSION));
72 if (Session == NULL)
73 return STATUS_INSUFFICIENT_RESOURCES;
74
75 /* Initialize the session entry */
76 RtlCopyLuid(&Session->LogonId, LogonId);
77
78 /* Insert the new session into the session list */
79 InsertTailList(&SessionListHead, &Session->Entry);
80 SessionCount++;
81
82 return STATUS_SUCCESS;
83 }
84
85
86 NTSTATUS
87 NTAPI
88 LsapDeleteLogonSession(IN PLUID LogonId)
89 {
90 PLSAP_LOGON_SESSION Session;
91
92 TRACE("()\n");
93
94 /* Fail, if the session does not exist */
95 Session = LsapGetLogonSession(LogonId);
96 if (Session == NULL)
97 return STATUS_NO_SUCH_LOGON_SESSION;
98
99 /* Remove the session entry from the list */
100 RemoveEntryList(&Session->Entry);
101 SessionCount--;
102
103 /* Free the session entry */
104 RtlFreeHeap(RtlGetProcessHeap(), 0, Session);
105
106 return STATUS_SUCCESS;
107 }
108
109 /* EOF */