WNT Client/Server SDK Tony Vaccaro CS699 Project Presentation Primary Objective Develop a basic client/server application that would demonstrate several of the primitive but essential functions required to implement robust client/server solutions. Communication System: Transport and Protocol Security Mechanism Multi-Threaded Capability Multi-User Operation Project Description A Software Development Kit (SDK) that could be used as a design center for implementation of a complete client/server based solution. Suitable for development of solutions where simple remote management of a system or resource is required. Applications can issue commands and obtain system specific information from remote hosts for desktop management applications. Commands and information could include any that are supported by the Win32 API. Software Components Three basic software components: WNT Agent (server) Installed as a service program on a Windows NT host system and starts at boot time. Developed in C with Visual C++. WNT Agent Test (client) A Win32 console based application. Runs on local host or remote work stations. Developed in C with Visual C++. Client/Server SDK Setup Responsible for installing and uninstalling all components. Sets-up registry parameters. Developed with InstallShield. Software Engineering Approach Project followed a traditional “waterfall” model of program development. Report includes: Functional section that specifies the primary capabilities of server, client, and setup programs. Design section that specifies the overall system architecture, data-flow, and data dictionaries. A development section that describes the tools used to obtain software metrics, perform integrated debugging and to maintain source control. A system test section that outlines the test cases used to verify specific areas of program functionality. Server Functionality WNT service application started automatically at system boot time. Interfaces with a host server using Win32 function calls and with remote clients using the Windows Sockets (WinSock) API. Capable of servicing multiple concurrent client connections and service requests. Implements a security mechanism that both identifies and authenticates clients requesting connection. Implements a common messaging protocol that is used when transmitting and receiving data with clients. Implements an event logging facility that facilitates troubleshooting and maintenance activities. Extensible, allowing the addition of new commands and service routines. Client Functionality Implemented as a command line (non-GUI) based program. Communicates with the Agent service program using the TCP/IP transport protocol. Uses the messaging protocol supported by the Agent service when transferring data and commands. Command Syntax Return Get Agent Information “100|ProcessId” “0|Agent_Status_Command_Success |Agent Info (string)<EoM>\n"” Is able to display the constructed command syntax sent to the Agent service as well as the resulting response data. Is capable of establishing connection with the Agent service through use of the supported security mechanism. Sending and Receiving Data Structures Sending char* Hexify(char* bData, int iLength) { int i; char* cHexBuf; cHexBuf = (char*) malloc((iLength*2) + 1); memset(cHexBuf, '\0', (iLength*2) + 1); // Grab a new buffer // Clear it // Convert each “char” of binary data to two hex chars for (i = 0; i < iLength; i++) { sprintf (cHexBuf + (i*2), "%02x", (UCHAR) bData[i]); } return cHexBuf; } Receiving // cast a char pointer to the TestInfo structure pTestInfo = (char *) &sAgentTestInfo; // Loop till End - De-Hexify the data while (*pHexData != '\0') { // Get 2 characters memcpy(cTemp, pHexData, 2); // Save the byte in TestInfo structure *pTestInfo = (UCHAR) strtol(cTemp, NULL, 16); // Bump the pointers pHexData += 2; pTestInfo ++; } Figure 3 SERVER ARCHITECTURE Agent WNT System Services Win32 API Agent service parameters START AGENT SERVICE MAIN Service Control Manager Starts/Stops Agent Thread Global Data Store System Info dir paths Thread Initialize Critical Sections and WaitForSingleObj Config Get System and Config File Dirs dir paths Thread Create Client Comm Thread System Directories Win32 API Config Parse Data files Winnt Config Log Event Get System Info Client Communication Thread Config File Client Communication Thread Connect to Client Event Messagss Client File Socket Handles Thread Create Process Request Thread Socket Create Listen Socket Socket write/read/close/ accept socket Client Validate Client Winnt Log Errors Args passed: client name socket handle PassKey (seed) and Msg Thread Lock Rand Crit Section Client Process Request Thread Execute Client Command Socket Read/Write Socket Client Create PassKey Winnt Log Errors PassKey Swapped PassKey Misc Endian Little Swap Socket Handle filename Socket Get Thread ID Socket Read/Write/ Close Socket Thread Exit Thread Client Load Agent Test Structure ClientCmd Hexify Data ClientCmd Create Beep Thread Revcheck Get File Versions Winnt Log Errors Client Specified File Figure 4 CLIENT ARCHITECTURE AgentTest Input Arguments; Remote Server and Password MAIN Socket Handle and Message Comm Code AgenTest AgenTest Get Process ID Comm string AgenTest Display Commands AgenTest Get Command Code AgenTest Build Command Send Message User Input Process Info Win32 System Service Commands Display Output Encrypted Password Socket Handle Socket Handle Seed Password PassKey AgenTest AgenTest Receive Message AgenTest Close Socket Remote IP AgenTest Connect to Remote Server AgenTest Client Connect Remote IP AgenTest Get Host by Name AgenTest Encrypt Password Create PassKey Socket Handle Socket Handle AgenTest Create Socket AgenTest Bind IP and Port to Socket Figure 5 Monitor Metric Details – Server Program Figure 6 Monitor Metric Details – Client Program Component SERVER DATA-FLOW DIAGRAM Service Params Start Agent Service SCM Thread Dispatched Event Message Event Viewer Logs Event Log Start Event Locate Client Config files Config files Directory Path Parse Client Security Data ClientData Client name & seed Get System Information Node, machine, & versions Init Critical Sections: Socket, DB, and RandNum Start Sockets and Create TCP Socket Communication Thread Socket Communication Thread Create Socket and Listen on Port: 4988 A Client Data Structure Global Data A Incoming Client Request on Port 4988 (TCP Network) Return server socket to listen state; ready to accept new client requests Accept Socket Socket handle Client name and server socket descriptor Client Data Structure Validate Client Socket handle, client name, Seed value (for password encryption) Invalid Client Create Process Request Thread H Process Request Thread; Socket Handle, Client name, and Seed value passed Read Socket Buffer Close Socket if 0 Length Read Socket Handle Socket Data Destroy this thread Socket Handle Parse and Decode Client’s Command Command Command Execution Routines B C D E F G CLIENTCMD Module Abstract and Data Dictionary ClientCmd includes a set of functions that perform command specific processing for client requests received by the Agent. Entity Name Type THREADPARAMS Structure ThreadCountInfo Structure Hexify Function BeepThread Function Beeper Function Description (int) iThreadCount – max number of threads PTHREADCOUNTINFO pThreadCountInfo - Pointer to global threadcountinfo struct (int) iThreadCount - counts active Beep threads (BOOL) ar_bBeepStop[MAX_THREADS] – stores stop flags Converts a buffer of binary data to ASCII Hex characters. Inputs: Pointer to binary buffer and length of buffer. Outputs: Pointer to ASCII Hex buffer Prepares thread parameters and creates a worker thread which continually beeps until a system modal MessageBox is acknowledged. Inputs: PTHREADCOUNTINFO, a pointer to a thread info structure. Outputs: Pointer to a status string to return to the client. Runs as a worker thread and continually beeps to indicate the existence of the thread. Inputs: A pointer the ThreadParams structure Outputs: None AGENT Module Abstract and Data Dictionary The purpose of the Agent module is to request the WNT Service Control Manager (SCM) to start the Agent service, prepare configuration data, initialize critical sections, and launch the client communication thread to wait for incoming service requests. Entity Name Type MAIN Function StartAgent Function Description The main routine. First called at program startup. Inputs: argc - The number of arguments in 'argv'. argv - a pointer to an 'array' of passed arguments. Outputs: None This routine starts the Agent functions Inputs: None Outputs: None REVCHECK Module Abstract and Data Dictionary The purpose of the Revcheck module is to retrieve the file version from a specified file’s GetFileVersionInfo structure. Entity Name GetFileVer Type Function Description Retrieves the file version from the GetFileVersionInfo structure. Inputs: LPSTR strFileName - name of file LPSTR strFileVersion - gets loaded with the version Outputs: Returns TRUE if a version is found System Test Matrix TEST CASE DESCRIPTION SUCCESS CRITERA* Kit Installation and Setup Invoke Setup wizard to install all components of the kit. Kit UnInstallation Invoke WNTInfoAgent uninstall from Add/Remove Programs applet. Agent and Client Security 100 Level Command Connect with Agent using proper client authorization and password. Attempt to connect with Agent using improper client authorization and password. Issue 100 Level Command to Agent from Client. 101 Level Command Issue 101 Level Command to Agent from Client. 102 Level Command Issue 102 Level Command to Agent from Client. 103 Level Command 104 Level Command Issue 103 Level Command to Agent from Client with valid file path and name. Issue 103 Level Command to Agent from Client. 900 Level Command Issue the 900 Level Command to the Agent from the Client. Agent and Client programs are installed in user selected folders, correct registry parameters are entered, Agent service starts, and Client program executes. Startup event is logged in the event viewer Uninstall can be invoked from Add/Remove Programs applet. All files and folders are removed from target system. Client is granted access to the server using the correct password and/or client name authorization. Client is denied access without the correct password and/or client name authorization. Agent returns the correct current version of the running agent to the client and the client outputs the version string. Agent returns the correct server information to the client and the client outputs the information string Agent launches Beeper worker thread on host server and presents MessageBox. Agent cancels worker when user clicks OK. Agent returns the correct file version for the specified file and the Client properly displays the output. Agent returns test structure contents to Client and Client properly displays output. Agent shuts-down. Shutdown event is logged in the event viewer. Multi-thread and multi-user Tests Use 16 clients to concurrently connect with the Agent and issue 102 Level Commands. Agent establishes connection with each client and launches a corresponding beep thread for each. Also, threads are destroyed and connections closed when each thread is cancelled. PASS X X X X X X X X X X FAIL CDROM Media Layout Visual C++ Project Files for the Server and Client Following Setup start agent from START\Programs\CS699\SpAgentTest Debug version runs as a console application, Release version runs as an installed WNT Service MS Word Project Proposal and Report in Docs folder MS Power Point presentation in Presentation folder Kit Setup Wizard. Double click on Setup.exe or use run from START menu. Source Code Files for all project programs. View with any text editor or from Visual C++