- Sync up Mm interface with WinLdr branch (introduce the concept of a memory type...
[reactos.git] / reactos / dll / win32 / lsasrv / lsarpc.c
1 /* INCLUDES ****************************************************************/
2
3 #define WIN32_NO_STATUS
4 #include <windows.h>
5 #include <ntsecapi.h>
6 #define NTOS_MODE_USER
7 #include <ndk/ntndk.h>
8
9 #include "lsa_s.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 #define POLICY_DELETE (RTL_HANDLE_VALID << 1)
15 typedef struct _LSAR_POLICY_HANDLE
16 {
17 ULONG Flags;
18 LONG RefCount;
19 ACCESS_MASK AccessGranted;
20 } LSAR_POLICY_HANDLE, *PLSAR_POLICY_HANDLE;
21
22 static RTL_CRITICAL_SECTION PolicyHandleTableLock;
23 static RTL_HANDLE_TABLE PolicyHandleTable;
24
25 /* FUNCTIONS ***************************************************************/
26
27 static NTSTATUS
28 ReferencePolicyHandle(IN LSA_HANDLE ObjectHandle,
29 IN ACCESS_MASK DesiredAccess,
30 OUT PLSAR_POLICY_HANDLE *Policy)
31 {
32 PLSAR_POLICY_HANDLE ReferencedPolicy;
33 NTSTATUS Status = STATUS_SUCCESS;
34
35 RtlEnterCriticalSection(&PolicyHandleTableLock);
36
37 if (RtlIsValidIndexHandle(&PolicyHandleTable,
38 (ULONG)ObjectHandle,
39 (PRTL_HANDLE_TABLE_ENTRY*)&ReferencedPolicy) &&
40 !(ReferencedPolicy->Flags & POLICY_DELETE))
41 {
42 if (RtlAreAllAccessesGranted(ReferencedPolicy->AccessGranted,
43 DesiredAccess))
44 {
45 ReferencedPolicy->RefCount++;
46 *Policy = ReferencedPolicy;
47 }
48 else
49 Status = STATUS_ACCESS_DENIED;
50 }
51 else
52 Status = STATUS_INVALID_HANDLE;
53
54 RtlLeaveCriticalSection(&PolicyHandleTableLock);
55
56 return Status;
57 }
58
59 static VOID
60 DereferencePolicyHandle(IN OUT PLSAR_POLICY_HANDLE Policy,
61 IN BOOLEAN Delete)
62 {
63 RtlEnterCriticalSection(&PolicyHandleTableLock);
64
65 if (Delete)
66 {
67 Policy->Flags |= POLICY_DELETE;
68 Policy->RefCount--;
69
70 ASSERT(Policy->RefCount != 0);
71 }
72
73 if (--Policy->RefCount == 0)
74 {
75 ASSERT(Policy->Flags & POLICY_DELETE);
76 RtlFreeHandle(&PolicyHandleTable,
77 (PRTL_HANDLE_TABLE_ENTRY)Policy);
78 }
79
80 RtlLeaveCriticalSection(&PolicyHandleTableLock);
81 }
82
83 VOID
84 LsarStartRpcServer(VOID)
85 {
86 RPC_STATUS Status;
87
88 RtlInitializeCriticalSection(&PolicyHandleTableLock);
89 RtlInitializeHandleTable(0x1000,
90 sizeof(LSAR_POLICY_HANDLE),
91 &PolicyHandleTable);
92
93 DPRINT("LsarStartRpcServer() called");
94
95 Status = RpcServerUseProtseqEpW(L"ncacn_np",
96 10,
97 L"\\pipe\\lsarpc",
98 NULL);
99 if (Status != RPC_S_OK)
100 {
101 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
102 return;
103 }
104
105 Status = RpcServerRegisterIf(lsarpc_ServerIfHandle,
106 NULL,
107 NULL);
108 if (Status != RPC_S_OK)
109 {
110 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status);
111 return;
112 }
113
114 Status = RpcServerListen(1, 20, TRUE);
115 if (Status != RPC_S_OK)
116 {
117 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status);
118 return;
119 }
120
121 DPRINT("LsarStartRpcServer() done\n");
122 }
123
124 /* Function 0 */
125 NTSTATUS
126 LsarClose(IN handle_t BindingHandle,
127 IN unsigned long ObjectHandle)
128 {
129 PLSAR_POLICY_HANDLE Policy = NULL;
130 NTSTATUS Status;
131
132 DPRINT("LsarClose(0x%p) called!\n", ObjectHandle);
133
134 Status = ReferencePolicyHandle((LSA_HANDLE)ObjectHandle,
135 0,
136 &Policy);
137 if (NT_SUCCESS(Status))
138 {
139 /* delete the handle */
140 DereferencePolicyHandle(Policy,
141 TRUE);
142 }
143
144 return Status;
145 }
146
147 /* Function 1 */
148 NTSTATUS
149 LsarDelete(IN handle_t BindingHandle,
150 IN unsigned long ObjectHandle)
151 {
152 DPRINT1("LsarDelete(0x%p) UNIMPLEMENTED!\n", ObjectHandle);
153 return STATUS_ACCESS_DENIED;
154 }
155
156 /* EOF */