/*++ Copyright (c) 1991-92 Microsoft Corporation Module Name: getconfg.c Abstract: This module contains routines for manipulating configuration information. The following functions available are: NetpGetComputerName NetpGetDomainId Currently configuration information is kept in NT.CFG. Later it will be kept by the configuration manager. Author: Dan Lafferty (danl) 09-Apr-1991 Environment: User Mode -Win32 Revision History: 09-Apr-1991 danl created 27-Sep-1991 JohnRo Fixed somebody's attempt to do UNICODE. 20-Mar-1992 JohnRo Get rid of old config helper callers. Fixed NTSTATUS vs. NET_API_STATUS bug. 07-May-1992 JohnRo Enable win32 registry for NET tree by calling GetComputerName(). Avoid DbgPrint if possible. 08-May-1992 JohnRo Use equates. 08-May-1992 JohnRo Added conditional debug output of computer name. --*/ // These must be included first: #include // (temporary for config.h) #include // (temporary for config.h) #include // (temporary for config.h) #include // IN, VOID, etc. #include // NET_API_STATUS. // These may be included in any order: #include // LPNET_CONFIG_HANDLE, NetpOpenConfigData, etc. #include // SECT_NT_WKSTA, etc. #include // IF_DEBUG(). #include // NetApiBufferFree(). #include // NO_ERROR, NERR_ and ERROR_ equates. #include // NetpAssert(). #include // LOCAL_DOMAIN_TYPE_PRIMARY #include // PREFIX_ equates. #include // ATOL(), STRLEN(), TCHAR_SPACE, etc. #include // LocalAlloc(). // // Local Function Prototypes // static NET_API_STATUS TmppGetNextValueToken( IN LPTSTR Value, IN OUT LPDWORD ParseContext, OUT LPDWORD ResultValue ); /****************************************************************************/ NET_API_STATUS NetpGetComputerName ( IN LPTSTR *ComputerNamePtr ) /*++ Routine Description: This routine obtains the computer name from a persistent database. Currently that database is the NT.CFG file. This routine makes no assumptions on the length of the computername. Therefore, it allocates the storage for the name using NetApiBufferAllocate. It is necessary for the user to free that space using NetApiBufferFree when finished. Arguments: ComputerNamePtr - This is a pointer to the location where the pointer to the computer name is to be placed. Return Value: NERR_Success - If the operation was successful. It will return assorted Net or Win32 error messages if not. --*/ { NET_API_STATUS ApiStatus; DWORD NameSize = MAX_COMPUTERNAME_LENGTH + 1; // updated by win32 API. // // Check for caller's errors. // if (ComputerNamePtr == NULL) { return (ERROR_INVALID_PARAMETER); } // // Allocate space for computer name. // ApiStatus = NetApiBufferAllocate( (MAX_COMPUTERNAME_LENGTH + 1) * sizeof(WCHAR), (LPVOID *) ComputerNamePtr); if (ApiStatus != NO_ERROR) { return (ApiStatus); } NetpAssert( *ComputerNamePtr != NULL ); // // Ask system what current computer name is. // if ( !GetComputerName( *ComputerNamePtr, &NameSize ) ) { ApiStatus = (NET_API_STATUS) GetLastError(); NetpAssert( ApiStatus != NO_ERROR ); (VOID) NetApiBufferFree( *ComputerNamePtr ); // BUGBUG? return (ApiStatus); } NetpAssert( STRLEN( *ComputerNamePtr ) <= MAX_COMPUTERNAME_LENGTH ); // // All done. // IF_DEBUG( CONFIG ) { NetpKdPrint(( PREFIX_NETLIB "NetpGetComputerName: name is " FORMAT_LPTSTR ".\n", *ComputerNamePtr )); } return (NO_ERROR); } /****************************************************************************/ NET_API_STATUS NetpGetDomainId ( OUT PSID *RetDomainId) /*++ Routine Description: This routine obtains the domain id from LSA. Arguments: RetDomainId - This is a pointer to the location where the pointer to the domain id is to be placed. This must be freed via LocalFree(). Return Value: NERR_Success - If the operation was successful. It will return assorted Net or Win32 error messages if not. --*/ { return NetpGetLocalDomainId( LOCAL_DOMAIN_TYPE_PRIMARY, RetDomainId ); } static NET_API_STATUS TmppGetNextValueToken( IN LPTSTR Value, IN OUT LPDWORD ParseContext, OUT LPDWORD ResultValue ) /*++ Routine Description: This routine is used to isolate the next token in a configuration file value line. This token is parsed as a number. Arguments: Value - Supplies the value line being parsed. ParseContext - Is a pointer to a context state value. The first time this routine is called for a particular Value line, the value pointed to should be zero. Thereafter, the value returned from the previous call should be passed. ResultValue - Returns the numeric value of the token. Return Value: NO_ERROR - indicates the next token has been isolated. ERROR_NO_MORE_ITEMS - Indicates there were no more tokens in the Value line. --*/ { DWORD i, j; DWORD ValueLength = STRLEN(Value); NetpAssert( ParseContext != NULL ); NetpAssert( ResultValue != NULL ); NetpAssert( Value != NULL ); // // Get to the beginning of the next token // for ( i = *ParseContext; (i < ValueLength) && ( (Value[i] == TCHAR_SPACE) || (Value[i] == TCHAR_TAB) ); i++ ) /*NULLBODY*/ ; // // see if we ran off the end of the string.. // if (i == ValueLength) { return ERROR_NO_MORE_ITEMS; } // // Now search for the end of the token // for ( j = i + 1; (j < ValueLength) && (Value[j] != TCHAR_SPACE) && (Value[j] != TCHAR_TAB); j++ ) /*NULLBODY*/ ; *ParseContext = j; // // Convert resulting token to a DWORD. // *ResultValue = (DWORD) ATOL( &Value[i] ); return NO_ERROR; } // TmppGetNextValueToken