21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Discussion<br />

The Win32 API function LookupAccountName( ) is used to find the SID that corresponds<br />

to a name. You can use it to obtain information about a name on either the<br />

local system or a remote system. While it might seem that mapping a name to a SID<br />

is a simple operation, LookupAccountName( ) actually requires a large number of arguments<br />

to allow it to complete its work.<br />

LookupAccountName( ) has the following signature:<br />

BOOL LookupAccountName(LPCTSTR lpSystemName, LPCTSTR lpAccountName, PSID Sid,<br />

LPDWORD cbSid, LPTSTR ReferencedDomainName,<br />

LPDWORD cbReferencedDomainName, PSID_NAME_USE peUse);<br />

This function has the following arguments:<br />

lpSystemName<br />

String representing the name of the remote system on which to look up the<br />

name. If you specify this argument as NULL, the lookup will be done on the local<br />

system.<br />

lpAccountName<br />

String representing the name of the user or group to look up. This argument may<br />

not be specified as NULL.<br />

Sid<br />

Buffer into which the SID will be written. Initially, you may specify this argument<br />

as NULL to determine how large a buffer is required to hold the SID.<br />

cbSid<br />

Pointer to an integer that both specifies the size of the buffer to receive the SID,<br />

and receives the size of the buffer required for the SID.<br />

ReferencedDomainName<br />

Buffer into which the domain name where the user or group name was found is<br />

to be written. Initially, you may specify this argument as NULL to determine how<br />

large a buffer is required to hold the domain name.<br />

cbReferencedDomainName<br />

Pointer to an integer that both specifies the size of the buffer to receive the<br />

domain name, and receives the size of the buffer required for the domain name.<br />

peUse<br />

Pointer to an enumeration that receives the type of SID to which the looked-up<br />

name corresponds. The most commonly returned values are SidTypeUser (1) and<br />

SidTypeGroup (2).<br />

The following function, SpcLookupName( ), is essentially a wrapper around<br />

LookupAccountName( ). It handles the nuances of performing user and group name<br />

lookup, including allocating the necessary buffers and error conditions. If the name<br />

is successfully found, the return will be a pointer to a dynamically allocated SID<br />

structure, which you must later free using LocalFree( ). If the name could not be<br />

376 | Chapter 8: Authentication and Key Exchange<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!