00080 :
00081
00082 Converts a list of workstation names in
UI/Service
format into a list of
00083 canonicalized names in API list
format.
UI/Service list
format allows
00084 multiple delimiters, leading and trailing delimiters. Delimiters are
the
00085 set
"\t,;". API list
format has no leading or trailing delimiters and
00086 elements are delimited by a single comma character.
00087
00088 For each name parsed from UiList,
the name
is canonicalized (which checks
00089 the character set and name length) as a workstation name. If
this fails,
00090 an error
is returned. No information
is returned as to which element
00091 failed canonicalization:
the list should be discarded and a
new one re-input
00092
00093 Arguments:
00094
00095 UiList - The list to canonicalize in
UI/Service list
format
00096 ApiList - The place to store
the canonicalized version of
the list in
00097 API list
format. The list will have a trailing zero character.
00098 BlankIsDelimiter -
TRUE indicates blank should be considered a delimiter
00099 character.
00100
00101 Return Value:
00102
00103
NTSTATUS
00104 Success = STATUS_SUCCESS
00105
List converted ok
00106
00107 Failure = STATUS_INVALID_PARAMETER
00108 UiList parameter
is in error
00109
00110 STATUS_INVALID_COMPUTER_NAME
00111
A name parsed from UiList has an incorrect
format for a
00112 computer (aka workstation) name
00113 --*/
00114
00115 {
00116
NTSTATUS status = STATUS_SUCCESS;
00117 ULONG inLen;
00118 PWSTR input;
00119 PWSTR buffer;
00120 PWSTR output;
00121 ULONG cLen;
00122 ULONG len;
00123 ULONG outLen = 0;
00124 WCHAR element[MAX_COMPUTERNAME_LENGTH+1];
00125 BOOLEAN firstElement =
TRUE;
00126 BOOLEAN ok;
00127
00128
try {
00129
if (ARGUMENT_PRESENT(UiList)) {
00130 inLen = UiList->MaximumLength;
00131 inLen = UiList->Length;
00132 input = UiList->Buffer;
00133
if (inLen &
sizeof(WCHAR)-1) {
00134 status = STATUS_INVALID_PARAMETER;
00135 }
00136 }
00137
RtlInitUnicodeString(ApiList, NULL);
00138 } except (EXCEPTION_EXECUTE_HANDLER) {
00139 status = STATUS_ACCESS_VIOLATION;
00140 }
00141
if (
NT_SUCCESS(status) && ARGUMENT_PRESENT(UiList) && inLen) {
00142 buffer =
RtlAllocateHeap(RtlProcessHeap(), 0, inLen +
sizeof(WCHAR));
00143
if (buffer ==
NULL) {
00144 status = STATUS_NO_MEMORY;
00145 }
else {
00146 ApiList->Buffer = buffer;
00147 ApiList->MaximumLength = (
USHORT)inLen +
sizeof(WCHAR);
00148 output = buffer;
00149 ok =
TRUE;
00150
while (len =
NextElement(&input,
00151 &inLen,
00152 element,
00153
sizeof(element) -
sizeof(element[0]),
00154 BlankIsDelimiter )) {
00155
if (len == (ULONG)-1
L) {
00156 ok =
FALSE;
00157 }
else {
00158 cLen = len/
sizeof(WCHAR);
00159 element[cLen] = 0;
00160 ok =
ValidateName(element, cLen);
00161 }
00162
if (ok) {
00163
if (!firstElement) {
00164 *output++ =
L',';
00165
00166
00167
00168
00169
00170
00171 outLen +=
sizeof(WCHAR);
00172 }
else {
00173 firstElement =
FALSE;
00174 }
00175 wcscpy(output, element);
00176 outLen += len;
00177 output += cLen;
00178 }
else {
00179
RtlFreeHeap(RtlProcessHeap(), 0, buffer);
00180 ApiList->Buffer =
NULL;
00181 status = STATUS_INVALID_COMPUTER_NAME;
00182
break;
00183 }
00184 }
00185 }
00186
if (
NT_SUCCESS(status)) {
00187 ApiList->Length = (
USHORT)outLen;
00188
if (!outLen) {
00189 ApiList->MaximumLength = 0;
00190 ApiList->Buffer =
NULL;
00191
RtlFreeHeap(RtlProcessHeap(), 0, buffer);
00192 }
00193 }
00194 }
00195
return status;
00196 }