Given the Domain and Login of a user, query the PDC for the user's full name.
<CFX_DOMAINUSER DOMAIN="NORTHGRUM" USER="OSBORRI"> <CFOUTPUT><!-- #UserFullName# --></CFOUTPUT> <CFX_DOMAINUSER DOMAIN="NORTHGRUM" USER="OSBORRI" VAR="FullName"> <CFOUTPUT><!-- #FullName# --></CFOUTPUT> <CFSET Slash=FindOneOf("/\:",CGI.AUTH_USER,1)> <CFIF Slash GT 0> <CFSET Domain=Left(CGI.AUTH_USER,Evaluate("#Slash#-1"))> <CFSET Login=Right(CGI.AUTH_USER,Evaluate("#Len(CGI.AUTH_USER)#-#Slash#"))> <CFX_DOMAINUSER DOMAIN="#Domain#" USER="#Login#" VAR="UserName"> <CFOUTPUT><!-- #Domain#\#Login#=#UserName# --></CFOUTPUT> <CFELSE><CFABORT SHOWERROR="Don't forget your domain when you log in!"></CFIF>
/* CFX_DomainUser Custom ColdFusion Tag Original Coding by Rick Osborne, 9-Sep-1998 Usage: <CFX_DOMAINUSER DOMAIN="(mydomain)" USER="(userlogin)"> Returns: UserFullName *Note: Will return a blank string if the user's name could not be found. Optional: The VAR attribute may be added to the tag to send the result to a specific variable. Example: <CFX_DOMAINUSER DOMAIN="(mydomain)" USER="(userlogin)" VAR="FullName"> This defaults to "UserFullName" if blank or nonexistant. */ #include <windows.h> #include <lm.h> #include <stdio.h> #include "cfx.h" #define TAG_ERROR_HEADER "Error occurred in CFX_DOMAINUSER tag" BOOL GetFullName(LPCSTR UserName,LPCSTR Domain, char *dest ) { //Note: This code taken from the Microsoft Visual C++ 5.0 Help files WCHAR wszUserName[256]; // Unicode user name WCHAR wszDomain[256]; LPBYTE ComputerName; struct _USER_INFO_2 *ui; // User structure MultiByteToWideChar(CP_ACP, 0, UserName, strlen(UserName)+1, wszUserName, sizeof(wszUserName)); MultiByteToWideChar(CP_ACP, 0, Domain, strlen(Domain)+1, wszDomain, sizeof(wszDomain)); NetGetDCName(NULL, wszDomain, &ComputerName); if(NetUserGetInfo((LPWSTR) ComputerName, (LPWSTR) &wszUserName, 2, (LPBYTE *) &ui)) return(FALSE); WideCharToMultiByte(CP_ACP, 0, ui->usri2_full_name, -1, dest, 256, NULL, NULL); return (TRUE); } void ProcessTagRequest(CCFXRequest* pRequest) { char *defaultVar = "UserFullName"; char fullName[256]; *fullName = 0; try { LPCSTR sDomain = pRequest->GetAttribute("DOMAIN"); if(!sDomain || !*sDomain) throw "Required DOMAIN attribute missing."; LPCSTR sUser = pRequest->GetAttribute("USER"); if(!sUser || !*sUser) throw "Required USER attribute missing."; LPCSTR sVar = pRequest->GetAttribute("VAR"); if(!sVar || !*sVar) sVar = defaultVar; BOOL ret = GetFullName(sUser,sDomain,fullName); pRequest->SetVariable(sVar,fullName); } catch(CCFXException* e) { pRequest->ReThrowException(e); } catch(char *cp) { pRequest->ThrowException(TAG_ERROR_HEADER,cp); } catch( ... ) { pRequest->ThrowException(TAG_ERROR_HEADER,"Unexpected error occurred while processing tag."); } }
This tag and all related source code is copyright Rick Osborne, 1998. All related files may be distributed freely without change, except in compliations (such as CDs). Contact me if you would like to be an exception.