1 /* $Id: misc.c,v 1.15 2004/05/13 20:42:28 navaraf Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/sec/misc.c
6 * PURPOSE: Miscellaneous security functions
21 AreAllAccessesGranted(DWORD GrantedAccess
,
24 return((BOOL
)RtlAreAllAccessesGranted(GrantedAccess
,
33 AreAnyAccessesGranted(DWORD GrantedAccess
,
36 return((BOOL
)RtlAreAnyAccessesGranted(GrantedAccess
,
41 /******************************************************************************
42 * GetFileSecurityA [ADVAPI32.@]
44 * Obtains Specified information about the security of a file or directory.
47 * lpFileName [I] Name of the file to get info for
48 * RequestedInformation [I] SE_ flags from "winnt.h"
49 * pSecurityDescriptor [O] Destination for security information
50 * nLength [I] Length of pSecurityDescriptor
51 * lpnLengthNeeded [O] Destination for length of returned security information
54 * Success: TRUE. pSecurityDescriptor contains the requested information.
55 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
58 * The information returned is constrained by the callers access rights and
64 GetFileSecurityA (LPCSTR lpFileName
,
65 SECURITY_INFORMATION RequestedInformation
,
66 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
68 LPDWORD lpnLengthNeeded
)
70 DPRINT("GetFileSecurityA: stub\n");
78 GetFileSecurityW (LPCWSTR lpFileName
,
79 SECURITY_INFORMATION RequestedInformation
,
80 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
81 DWORD nLength
, LPDWORD lpnLengthNeeded
)
83 DPRINT("GetFileSecurityW: stub\n");
91 GetKernelObjectSecurity(HANDLE Handle
,
92 SECURITY_INFORMATION RequestedInformation
,
93 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
95 LPDWORD lpnLengthNeeded
)
99 Status
= NtQuerySecurityObject(Handle
,
100 RequestedInformation
,
104 if (!NT_SUCCESS(Status
))
106 SetLastError(RtlNtStatusToDosError(Status
));
113 /******************************************************************************
114 * SetFileSecurityA [ADVAPI32.@]
115 * Sets the security of a file or directory
120 SetFileSecurityA (LPCSTR lpFileName
,
121 SECURITY_INFORMATION RequestedInformation
,
122 PSECURITY_DESCRIPTOR pSecurityDescriptor
)
124 DPRINT("SetFileSecurityA : stub\n");
133 SetKernelObjectSecurity(HANDLE Handle
,
134 SECURITY_INFORMATION SecurityInformation
,
135 PSECURITY_DESCRIPTOR SecurityDescriptor
)
139 Status
= NtSetSecurityObject(Handle
,
142 if (!NT_SUCCESS(Status
))
144 SetLastError(RtlNtStatusToDosError(Status
));
155 MapGenericMask(PDWORD AccessMask
,
156 PGENERIC_MAPPING GenericMapping
)
158 RtlMapGenericMask(AccessMask
,
167 ImpersonateLoggedOnUser(HANDLE hToken
)
169 SECURITY_QUALITY_OF_SERVICE Qos
;
170 OBJECT_ATTRIBUTES ObjectAttributes
;
177 /* Get the token type */
178 Status
= NtQueryInformationToken (hToken
,
183 if (!NT_SUCCESS(Status
))
185 SetLastError (RtlNtStatusToDosError (Status
));
189 if (Type
== TokenPrimary
)
191 /* Create a duplicate impersonation token */
192 Qos
.Length
= sizeof(SECURITY_QUALITY_OF_SERVICE
);
193 Qos
.ImpersonationLevel
= SecurityImpersonation
;
194 Qos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
195 Qos
.EffectiveOnly
= FALSE
;
197 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
198 ObjectAttributes
.RootDirectory
= NULL
;
199 ObjectAttributes
.ObjectName
= NULL
;
200 ObjectAttributes
.Attributes
= 0;
201 ObjectAttributes
.SecurityDescriptor
= NULL
;
202 ObjectAttributes
.SecurityQualityOfService
= &Qos
;
204 Status
= NtDuplicateToken (hToken
,
205 TOKEN_IMPERSONATE
| TOKEN_QUERY
,
210 if (!NT_SUCCESS(Status
))
212 SetLastError (RtlNtStatusToDosError (Status
));
220 /* User the original impersonation token */
225 /* Impersonate the the current thread */
226 Status
= NtSetInformationThread (NtCurrentThread (),
227 ThreadImpersonationToken
,
231 if (Duplicated
== TRUE
)
236 if (!NT_SUCCESS(Status
))
238 SetLastError (RtlNtStatusToDosError (Status
));
250 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
254 Status
= RtlImpersonateSelf(ImpersonationLevel
);
255 if (!NT_SUCCESS(Status
))
257 SetLastError(RtlNtStatusToDosError(Status
));
273 Status
= NtSetInformationThread(NtCurrentThread(),
274 ThreadImpersonationToken
,
277 if (!NT_SUCCESS(Status
))
279 SetLastError(RtlNtStatusToDosError(Status
));
286 /******************************************************************************
287 * GetUserNameA [ADVAPI32.@]
289 * Get the current user name.
292 * lpszName [O] Destination for the user name.
293 * lpSize [I/O] Size of lpszName.
296 * Success: The length of the user name, including terminating NUL.
297 * Failure: ERROR_MORE_DATA if *lpSize is too small.
302 GetUserNameA( LPSTR lpszName
, LPDWORD lpSize
)
305 // char name[] = { "Administrator" };
307 /* We need to include the null character when determining the size of the buffer. */
308 // len = strlen(name) + 1;
309 // if (len > *lpSize)
311 // SetLastError(ERROR_MORE_DATA);
317 // strcpy(lpszName, name);
321 /******************************************************************************
322 * GetUserNameW [ADVAPI32.@]
329 GetUserNameW( LPWSTR lpszName
, LPDWORD lpSize
)
331 // char name[] = { "Administrator" };
333 // DWORD len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
335 // if (len > *lpSize)
337 // SetLastError(ERROR_MORE_DATA);
343 // MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, len );
348 /******************************************************************************
349 * LookupAccountSidA [ADVAPI32.@]
354 LookupAccountSidA (LPCSTR lpSystemName
,
358 LPSTR lpReferencedDomainName
,
359 LPDWORD cchReferencedDomainName
,
362 DPRINT1("LookupAccountSidA is unimplemented, but returns success\n");
367 /******************************************************************************
368 * LookupAccountSidW [ADVAPI32.@]
373 LookupAccountSidW (LPCWSTR lpSystemName
,
377 LPWSTR lpReferencedDomainName
,
378 LPDWORD cchReferencedDomainName
,
381 DPRINT1("LookupAccountSidW is unimplemented, but returns success\n");
386 /**********************************************************************
387 * LookupPrivilegeValueA EXPORTED
392 LookupPrivilegeValueA (LPCSTR lpSystemName
,
396 UNICODE_STRING SystemName
;
401 if (lpSystemName
!= NULL
)
403 RtlCreateUnicodeStringFromAsciiz (&SystemName
,
404 (LPSTR
)lpSystemName
);
407 /* Check the privilege name is not NULL */
410 SetLastError (ERROR_INVALID_PARAMETER
);
414 RtlCreateUnicodeStringFromAsciiz (&Name
,
417 Result
= LookupPrivilegeValueW ((lpSystemName
!= NULL
) ? SystemName
.Buffer
: NULL
,
421 RtlFreeUnicodeString (&Name
);
424 if (lpSystemName
!= NULL
)
426 RtlFreeUnicodeString (&SystemName
);
433 /**********************************************************************
434 * LookupPrivilegeValueW EXPORTED
439 LookupPrivilegeValueW (LPCWSTR lpSystemName
,
447 /**********************************************************************
448 * LookupPrivilegeDisplayNameA EXPORTED
453 LookupPrivilegeDisplayNameA (LPCSTR lpSystemName
,
456 LPDWORD cbDisplayName
,
457 LPDWORD lpLanguageId
)
459 SetLastError (ERROR_CALL_NOT_IMPLEMENTED
);
464 /**********************************************************************
465 * LookupPrivilegeDisplayNameW EXPORTED
470 LookupPrivilegeDisplayNameW (LPCWSTR lpSystemName
,
472 LPWSTR lpDisplayName
,
473 LPDWORD cbDisplayName
,
474 LPDWORD lpLanguageId
)
476 SetLastError (ERROR_CALL_NOT_IMPLEMENTED
);
481 /**********************************************************************
482 * LookupPrivilegeNameA EXPORTED
487 LookupPrivilegeNameA (LPCSTR lpSystemName
,
492 SetLastError (ERROR_CALL_NOT_IMPLEMENTED
);
497 /**********************************************************************
498 * LookupPrivilegeNameW EXPORTED
503 LookupPrivilegeNameW (LPCWSTR lpSystemName
,
508 SetLastError (ERROR_CALL_NOT_IMPLEMENTED
);