Консультация № 146247
06.10.2008, 19:36
0.00 руб.
0 1 1
Доброго времени суток товарищи эксперты, подскажите пожалуйста, как зная SID польщователя получить его имя?

Обсуждение

Неизвестный
07.10.2008, 00:31
общий
это ответ
Здравствуйте, Chip!
Читайте MSDN:
LookupAccountSid

Функция LookupAccountSid получает идентификатор безопасности (SID) как входные данные. Она возвращает имя аккаунта для этого SID, а так же имя первого домена, где этот SID был найден.



Приложение:
BOOL LookupAccountSid(
LPCTSTR lpSystemName,
PSID lpSid,
LPTSTR lpName,
LPDWORD cchName,
LPTSTR lpReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);

Parameters
lpSystemName
[in] Pointer to a null-terminated character string that specifies the target computer. This string can be the name of a remote computer. If this string is NULL, the account name translation begins on the local system. If the name cannot be resolved on the local system, this function will try to resolve the name using domain controllers trusted by the local system. Generally, specify a value for lpSystemName only when the account is in an untrusted domain and the name of a computer in that domain is known.
lpSid
[in] Pointer to the SID to look up.
lpName
[out] Pointer to a buffer that receives a null-terminated string that contains the account name that corresponds to the lpSid parameter.
cchName
[in, out] On input, specifies the size, in TCHARs, of the lpName buffer. If the function fails because the buffer is too small or if cchName is zero, cchName receives the required buffer size, including the terminating null character.
lpReferencedDomainName
[out] Pointer to a buffer that receives a null-terminated string that contains the name of the domain where the account name was found.

Windows Server 2003, Windows 2000 Server, and Windows NT Server: The domain name returned for most accounts in the security database of the local computer is the name of the domain for which the server is a domain controller.


Windows XP, Windows 2000 Professional, and Windows NT Workstation: The domain name returned for most accounts in the security database of the local computer is the name of the computer as of the last start of the system (backslashes are excluded). If the name of the computer changes, the old name continues to be returned as the domain name until the system is restarted.
Some accounts are predefined by the system. The domain name returned for these accounts is BUILTIN.

cchReferencedDomainName
[in, out] On input, specifies the size, in TCHARs, of the lpReferencedDomainName buffer. If the function fails because the buffer is too small or if cchReferencedDomainName is zero, cchReferencedDomainName receives the required buffer size, including the terminating null character.
peUse
[out] Pointer to a variable that receives a SID_NAME_USE value that indicates the type of the account.
Return Values
If the function succeeds, the function returns nonzero.

If the function fails, it returns zero. To get extended error information, call GetLastError.

Remarks
The LookupAccountSid function attempts to find a name for the specified SID by first checking a list of well-known SIDs. If the supplied SID does not correspond to a well-known SID, the function checks built-in and administratively defined local accounts. Next, the function checks the primary domain. Security identifiers not recognized by the primary domain are checked against the trusted domains that correspond to their SID prefixes.

If the function cannot find an account name for the SID, the LookupAccountSid function fails and GetLastError returns ERROR_NONE_MAPPED. This can occur if a network time-out prevents the function from finding the name. It also occurs for SIDs that have no corresponding account name, such as a logon SID that identifies a logon session.

In addition to looking up SIDs for local accounts, local domain accounts, and explicitly trusted domain accounts, LookupAccountSid can look up SIDs for any account in any domain in the forest, including SIDs that appear only in the SIDhistory field of an account in the forest. The SIDhistory field stores former SIDs of an account that has been moved from another domain. To look up a SID, LookupAccountSid queries the global catalog of the forest.

Windows NT 4.0: Forest lookup and account lookup by SIDhistory are not supported.

Requirements
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 3.1 and later.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 3.1 and later.
Header Declared in Winbase.h; include Windows.h.

Library Link to Advapi32.lib.

DLL Requires Advapi32.dll.
Unicode Implemented as LookupAccountSidW (Unicode) and LookupAccountSidA (ANSI).

Форма ответа