windows-nt/Source/XPSP1/NT/base/screg/sc/lib/util.cxx
2020-09-26 16:20:57 +08:00

90 lines
1.5 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*++
Copyright (c) 1992 Microsoft Corporation
Module Name:
util.c
Abstract:
Contains miscellaneous utility functions used by the Service
Controller:
ScIsValidServiceName
Author:
Rita Wong (ritaw) 15-Mar-1992
Environment:
User Mode -Win32
Revision History:
11-Apr-1992 JohnRo
Added an assertion check.
Include <sclib.h> so compiler checks prototypes.
20-May-1992 JohnRo
winsvc.h and related file cleanup.
--*/
#include <stdlib.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windef.h>
#include <scdebug.h> // SC_ASSERT().
#include <sclib.h> // My prototype.
#include <valid.h> // MAX_SERVICE_NAME_LENGTH
BOOL
ScIsValidServiceName(
IN LPCWSTR ServiceName
)
/*++
Routine Description:
This function validates a given service name. The name length
cannot be greater than 256 characters, and must not contain any
forward-slash, or back-slash.
Arguments:
ServiceName - Supplies the service name to be validated.
Return Value:
TRUE - The name is valid.
FALSE - The name is invalid.
--*/
{
LPCWSTR IllegalChars = L"\\/";
DWORD NameLength;
SC_ASSERT( ServiceName != NULL ); // Avoid memory access fault in wcslen().
if (*ServiceName == 0) {
return FALSE;
}
if ((NameLength = (DWORD) wcslen(ServiceName)) > MAX_SERVICE_NAME_LENGTH) {
return FALSE;
}
if (wcscspn(ServiceName, IllegalChars) < NameLength) {
return FALSE;
}
return TRUE;
}