Sync with trunk r58740.
[reactos.git] / dll / win32 / samsrv / samsrv.c
1 /*
2 * SAM Server DLL
3 * Copyright (C) 2005 Eric Kohl
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /* INCLUDES *****************************************************************/
21
22 #include "samsrv.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(samsrv);
25
26 /* FUNCTIONS ****************************************************************/
27
28 NTSTATUS
29 NTAPI
30 SamIConnect(IN PSAMPR_SERVER_NAME ServerName,
31 OUT SAMPR_HANDLE *ServerHandle,
32 IN ACCESS_MASK DesiredAccess,
33 IN BOOLEAN Trusted)
34 {
35 PSAM_DB_OBJECT ServerObject;
36 NTSTATUS Status;
37
38 TRACE("SamIConnect(%p %p %lx %ld)\n",
39 ServerName, ServerHandle, DesiredAccess, Trusted);
40
41 /* Map generic access rights */
42 RtlMapGenericMask(&DesiredAccess,
43 pServerMapping);
44
45 /* Open the Server Object */
46 Status = SampOpenDbObject(NULL,
47 NULL,
48 L"SAM",
49 0,
50 SamDbServerObject,
51 DesiredAccess,
52 &ServerObject);
53 if (NT_SUCCESS(Status))
54 {
55 ServerObject->Trusted = Trusted;
56 *ServerHandle = (SAMPR_HANDLE)ServerObject;
57 }
58
59 TRACE("SamIConnect done (Status 0x%08lx)\n", Status);
60
61 return Status;
62 }
63
64
65 NTSTATUS
66 NTAPI
67 SamIInitialize(VOID)
68 {
69 NTSTATUS Status = STATUS_SUCCESS;
70
71 TRACE("SamIInitialize() called\n");
72
73 if (SampIsSetupRunning())
74 {
75 Status = SampInitializeRegistry();
76 if (!NT_SUCCESS(Status))
77 return Status;
78 }
79
80 /* Initialize the SAM database */
81 Status = SampInitDatabase();
82 if (!NT_SUCCESS(Status))
83 return Status;
84
85 /* Start the RPC server */
86 SampStartRpcServer();
87
88 return Status;
89 }
90
91
92 NTSTATUS
93 NTAPI
94 SampInitializeRegistry(VOID)
95 {
96 TRACE("SampInitializeRegistry() called\n");
97
98 SampInitializeSAM();
99
100 return STATUS_SUCCESS;
101 }
102
103
104 VOID
105 NTAPI
106 SamIFree_SAMPR_ENUMERATION_BUFFER(PSAMPR_ENUMERATION_BUFFER Ptr)
107 {
108 ULONG i;
109
110 if (Ptr != NULL)
111 {
112 if (Ptr->Buffer != NULL)
113 {
114 for (i = 0; i < Ptr->EntriesRead; i++)
115 {
116 if (Ptr->Buffer[i].Name.Buffer != NULL)
117 MIDL_user_free(Ptr->Buffer[i].Name.Buffer);
118 }
119
120 MIDL_user_free(Ptr->Buffer);
121 }
122
123 MIDL_user_free(Ptr);
124 }
125 }
126
127
128 VOID
129 NTAPI
130 SamIFree_SAMPR_PSID_ARRAY(PSAMPR_PSID_ARRAY Ptr)
131 {
132 if (Ptr != NULL)
133 {
134 if (Ptr->Sids !=0)
135 {
136 MIDL_user_free(Ptr->Sids);
137 }
138 }
139 }
140
141
142 VOID
143 NTAPI
144 SamIFree_SAMPR_RETURNED_USTRING_ARRAY(PSAMPR_RETURNED_USTRING_ARRAY Ptr)
145 {
146 ULONG i;
147
148 if (Ptr != NULL)
149 {
150 if (Ptr->Element != NULL)
151 {
152 for (i = 0; i < Ptr->Count; i++)
153 {
154 if (Ptr->Element[i].Buffer != NULL)
155 MIDL_user_free(Ptr->Element[i].Buffer);
156 }
157
158 MIDL_user_free(Ptr->Element);
159 Ptr->Element = NULL;
160 Ptr->Count = 0;
161 }
162 }
163 }
164
165
166 VOID
167 NTAPI
168 SamIFree_SAMPR_ULONG_ARRAY(PSAMPR_ULONG_ARRAY Ptr)
169 {
170 if (Ptr != NULL)
171 {
172 if (Ptr->Element != NULL)
173 {
174 MIDL_user_free(Ptr->Element);
175 Ptr->Element = NULL;
176 Ptr->Count = 0;
177 }
178 }
179
180 }
181
182 /* EOF */