1 /* 2 * PROJECT: Local Security Authority Server DLL 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/win32/lsasrv/lsasrv.c 5 * PURPOSE: Main file 6 * COPYRIGHT: Copyright 2006-2009 Eric Kohl 7 */ 8 9 /* INCLUDES ****************************************************************/ 10 11 #include "lsasrv.h" 12 13 NT_PRODUCT_TYPE LsapProductType = NtProductWinNt; 14 15 /* FUNCTIONS ***************************************************************/ 16 17 VOID 18 NTAPI 19 LsaIFree_LSAPR_ACCOUNT_ENUM_BUFFER( 20 IN PLSAPR_ACCOUNT_ENUM_BUFFER Ptr) 21 { 22 ULONG i; 23 24 if (Ptr == NULL) 25 return; 26 27 if (Ptr->Information != NULL) 28 { 29 for (i = 0; i < Ptr->EntriesRead; i++) 30 midl_user_free(Ptr->Information[i].Sid); 31 32 midl_user_free(Ptr->Information); 33 } 34 35 midl_user_free(Ptr); 36 } 37 38 39 VOID 40 NTAPI 41 LsaIFree_LSAPR_CR_CIPHER_VALUE( 42 IN PLSAPR_CR_CIPHER_VALUE Ptr) 43 { 44 if (Ptr != NULL) 45 midl_user_free(Ptr); 46 } 47 48 49 VOID 50 NTAPI 51 LsaIFree_LSAPR_POLICY_INFORMATION(IN POLICY_INFORMATION_CLASS InformationClass, 52 IN PLSAPR_POLICY_INFORMATION PolicyInformation) 53 { 54 if (PolicyInformation != NULL) 55 { 56 switch (InformationClass) 57 { 58 case PolicyAuditLogInformation: /* 1 */ 59 break; 60 61 case PolicyAuditEventsInformation: /* 2 */ 62 if (PolicyInformation->PolicyAuditEventsInfo.EventAuditingOptions != NULL) 63 midl_user_free(PolicyInformation->PolicyAuditEventsInfo.EventAuditingOptions); 64 break; 65 66 case PolicyPrimaryDomainInformation: /* 3 */ 67 if (PolicyInformation->PolicyPrimaryDomInfo.Name.Buffer != NULL) 68 midl_user_free(PolicyInformation->PolicyPrimaryDomInfo.Name.Buffer); 69 70 if (PolicyInformation->PolicyPrimaryDomInfo.Sid != NULL) 71 midl_user_free(PolicyInformation->PolicyPrimaryDomInfo.Sid); 72 break; 73 74 case PolicyPdAccountInformation: /* 4 */ 75 if (PolicyInformation->PolicyPdAccountInfo.Name.Buffer != NULL) 76 midl_user_free(PolicyInformation->PolicyPdAccountInfo.Name.Buffer); 77 break; 78 79 case PolicyAccountDomainInformation: /* 5 */ 80 if (PolicyInformation->PolicyAccountDomainInfo.DomainName.Buffer != NULL) 81 midl_user_free(PolicyInformation->PolicyAccountDomainInfo.DomainName.Buffer); 82 83 if (PolicyInformation->PolicyAccountDomainInfo.Sid != NULL) 84 midl_user_free(PolicyInformation->PolicyAccountDomainInfo.Sid); 85 break; 86 87 case PolicyLsaServerRoleInformation: /* 6 */ 88 break; 89 90 case PolicyReplicaSourceInformation: /* 7 */ 91 if (PolicyInformation->PolicyReplicaSourceInfo.ReplicaSource.Buffer != NULL) 92 midl_user_free(PolicyInformation->PolicyReplicaSourceInfo.ReplicaSource.Buffer); 93 94 if (PolicyInformation->PolicyReplicaSourceInfo.ReplicaAccountName.Buffer != NULL) 95 midl_user_free(PolicyInformation->PolicyReplicaSourceInfo.ReplicaAccountName.Buffer); 96 break; 97 98 case PolicyDefaultQuotaInformation: /* 8 */ 99 break; 100 101 case PolicyModificationInformation: /* 9 */ 102 break; 103 104 case PolicyAuditFullSetInformation: /* 10 (0xA) */ 105 break; 106 107 case PolicyAuditFullQueryInformation: /* 11 (0xB) */ 108 break; 109 110 case PolicyDnsDomainInformation: /* 12 (0xC) */ 111 if (PolicyInformation->PolicyDnsDomainInfo.Name.Buffer != NULL) 112 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.Name.Buffer); 113 114 if (PolicyInformation->PolicyDnsDomainInfo.DnsDomainName.Buffer != NULL) 115 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.DnsDomainName.Buffer); 116 117 if (PolicyInformation->PolicyDnsDomainInfo.DnsForestName.Buffer != NULL) 118 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.DnsForestName.Buffer); 119 120 if (PolicyInformation->PolicyDnsDomainInfo.Sid != NULL) 121 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.Sid); 122 break; 123 124 case PolicyDnsDomainInformationInt: /* 13 (0xD) */ 125 if (PolicyInformation->PolicyDnsDomainInfoInt.Name.Buffer != NULL) 126 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.Name.Buffer); 127 128 if (PolicyInformation->PolicyDnsDomainInfoInt.DnsDomainName.Buffer != NULL) 129 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.DnsDomainName.Buffer); 130 131 if (PolicyInformation->PolicyDnsDomainInfoInt.DnsForestName.Buffer != NULL) 132 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.DnsForestName.Buffer); 133 134 if (PolicyInformation->PolicyDnsDomainInfoInt.Sid != NULL) 135 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.Sid); 136 break; 137 138 case PolicyLocalAccountDomainInformation: /* 14 (0xE) */ 139 if (PolicyInformation->PolicyLocalAccountDomainInfo.DomainName.Buffer != NULL) 140 midl_user_free(PolicyInformation->PolicyLocalAccountDomainInfo.DomainName.Buffer); 141 142 if (PolicyInformation->PolicyLocalAccountDomainInfo.Sid != NULL) 143 midl_user_free(PolicyInformation->PolicyLocalAccountDomainInfo.Sid); 144 break; 145 146 default: 147 ERR("Invalid InformationClass: %lu\n", InformationClass); 148 break; 149 } 150 151 midl_user_free(PolicyInformation); 152 } 153 } 154 155 156 VOID 157 NTAPI 158 LsaIFree_LSAPR_PRIVILEGE_ENUM_BUFFER( 159 IN PLSAPR_PRIVILEGE_ENUM_BUFFER Ptr) 160 { 161 ULONG i; 162 163 if (Ptr != NULL) 164 { 165 if (Ptr->Privileges != NULL) 166 { 167 for (i = 0; i < Ptr->Entries; i++) 168 { 169 if (Ptr->Privileges[i].Name.Buffer != NULL) 170 midl_user_free(Ptr->Privileges[i].Name.Buffer); 171 } 172 173 midl_user_free(Ptr->Privileges); 174 } 175 } 176 } 177 178 179 VOID 180 NTAPI 181 LsaIFree_LSAPR_PRIVILEGE_SET(IN PLSAPR_PRIVILEGE_SET Ptr) 182 { 183 if (Ptr != NULL) 184 { 185 midl_user_free(Ptr); 186 } 187 } 188 189 190 VOID 191 NTAPI 192 LsaIFree_LSAPR_REFERENCED_DOMAIN_LIST( 193 IN PLSAPR_REFERENCED_DOMAIN_LIST Ptr) 194 { 195 ULONG i; 196 197 if (Ptr != NULL) 198 { 199 if (Ptr->Domains != NULL) 200 { 201 for (i = 0; i < Ptr->Entries; i++) 202 { 203 if (Ptr->Domains[i].Name.Buffer != NULL) 204 midl_user_free(Ptr->Domains[i].Name.Buffer); 205 206 if (Ptr->Domains[i].Sid != NULL) 207 midl_user_free(Ptr->Domains[i].Sid); 208 } 209 210 midl_user_free(Ptr->Domains); 211 } 212 213 midl_user_free(Ptr); 214 } 215 } 216 217 218 VOID 219 NTAPI 220 LsaIFree_LSAPR_SR_SECURITY_DESCRIPTOR( 221 IN PLSAPR_SR_SECURITY_DESCRIPTOR Ptr) 222 { 223 if (Ptr != NULL) 224 { 225 if (Ptr->SecurityDescriptor != NULL) 226 midl_user_free(Ptr->SecurityDescriptor); 227 228 midl_user_free(Ptr); 229 } 230 } 231 232 233 VOID 234 NTAPI 235 LsaIFree_LSAPR_TRANSLATED_NAMES( 236 IN PLSAPR_TRANSLATED_NAMES Ptr) 237 { 238 ULONG i; 239 240 if (Ptr != NULL) 241 { 242 if (Ptr->Names != NULL) 243 { 244 for (i = 0; i < Ptr->Entries; i++) 245 { 246 if (Ptr->Names[i].Name.Buffer != NULL) 247 midl_user_free(Ptr->Names[i].Name.Buffer); 248 } 249 250 midl_user_free(Ptr->Names); 251 } 252 253 midl_user_free(Ptr); 254 } 255 } 256 257 258 VOID 259 NTAPI 260 LsaIFree_LSAPR_TRANSLATED_SIDS( 261 IN PLSAPR_TRANSLATED_SIDS Ptr) 262 { 263 if (Ptr != NULL) 264 { 265 if (Ptr->Sids != NULL) 266 midl_user_free(Ptr->Sids); 267 268 midl_user_free(Ptr); 269 } 270 } 271 272 273 NTSTATUS 274 WINAPI 275 LsapInitLsa(VOID) 276 { 277 NTSTATUS Status; 278 BOOLEAN PrivilegeEnabled; 279 280 TRACE("LsapInitLsa()\n"); 281 282 /* Get the product type */ 283 RtlGetNtProductType(&LsapProductType); 284 285 /* Initialize the well known SIDs */ 286 LsapInitSids(); 287 288 /* Initialize the SRM server */ 289 Status = LsapRmInitializeServer(); 290 if (!NT_SUCCESS(Status)) 291 { 292 ERR("LsapRmInitializeServer() failed (Status 0x%08lx)\n", Status); 293 return Status; 294 } 295 296 /* Initialize the LSA database */ 297 LsapInitDatabase(); 298 299 /* Initialize logon sessions */ 300 LsapInitLogonSessions(); 301 302 /* Initialize the notification list */ 303 LsapInitNotificationList(); 304 305 /* Initialize registered authentication packages */ 306 Status = LsapInitAuthPackages(); 307 if (!NT_SUCCESS(Status)) 308 { 309 ERR("LsapInitAuthPackages() failed (Status 0x%08lx)\n", Status); 310 return Status; 311 } 312 313 /* Enable the token creation privilege for the rest of our lifetime */ 314 Status = RtlAdjustPrivilege(SE_CREATE_TOKEN_PRIVILEGE, TRUE, FALSE, &PrivilegeEnabled); 315 if (!NT_SUCCESS(Status)) 316 { 317 ERR("RtlAdjustPrivilege(SE_CREATE_TOKEN_PRIVILEGE) failed, ignoring (Status 0x%08lx)\n", Status); 318 } 319 320 /* Start the authentication LPC port thread */ 321 Status = StartAuthenticationPort(); 322 if (!NT_SUCCESS(Status)) 323 { 324 ERR("StartAuthenticationPort() failed (Status 0x%08lx)\n", Status); 325 return Status; 326 } 327 328 /* Start the RPC server */ 329 Status = LsarStartRpcServer(); 330 if (!NT_SUCCESS(Status)) 331 { 332 ERR("LsarStartRpcServer() failed (Status 0x%08lx)\n", Status); 333 return Status; 334 } 335 336 return STATUS_SUCCESS; 337 } 338 339 340 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len) 341 { 342 return RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len); 343 } 344 345 346 void __RPC_USER midl_user_free(void __RPC_FAR * ptr) 347 { 348 RtlFreeHeap(RtlGetProcessHeap(), 0, ptr); 349 } 350 351 /* EOF */ 352