ReactOS 0.4.15-dev-7674-gc0b4db1
dos8dot3.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for dos8dot3.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI RtlIsValidOemCharacter (IN PWCHAR Char)
 
static BOOLEAN RtlpIsShortIllegal (const WCHAR Char)
 
static USHORT RtlpGetCheckSum (PUNICODE_STRING Name)
 
VOID NTAPI RtlGenerate8dot3Name (IN PUNICODE_STRING Name, IN BOOLEAN AllowExtendedCharacters, IN OUT PGENERATE_NAME_CONTEXT Context, OUT PUNICODE_STRING Name8dot3)
 
 _IRQL_requires_max_ (PASSIVE_LEVEL)
 Queries information details about a security descriptor.
 

Variables

PUSHORT NlsUnicodeToMbOemTable
 
const ULONG RtlpShortIllegals [] = { 0xFFFFFFFF, 0xFC009C04, 0x38000000, 0x10000000 }
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file dos8dot3.c.

Function Documentation

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( PASSIVE_LEVEL  )

Queries information details about a security descriptor.

Computes the quota size of a security descriptor.

Assigns a security descriptor for a new object.

An extended function that assigns a security descriptor for a new object.

Frees a security descriptor.

An extended function that sets new information data to a security descriptor.

Modifies some information data about a security descriptor.

Parameters
[in]SecurityInformationSecurity information details to be queried from a security descriptor.
[out]SecurityDescriptorThe returned security descriptor with security information data.
[in,out]LengthThe returned length of a security descriptor.
[in,out]ObjectsSecurityDescriptorThe returned object security descriptor.
Returns
Returns STATUS_SUCCESS if the operations have been completed successfully and that the specific information about the security descriptor has been queried. STATUS_BUFFER_TOO_SMALL is returned if the buffer size is too small to contain the queried info about the security descriptor.
Parameters
[in]ObjectIf specified, the function will use this arbitrary object that points to an object security descriptor.
[in]SecurityInformationSecurity information details to be set.
[in]SecurityDescriptorA security descriptor where its info is to be changed.
[in,out]ObjectsSecurityDescriptorThe returned pointer to security descriptor objects.
[in]PoolTypePool type for the new security descriptor to allocate.
[in]GenericMappingThe generic mapping of access rights masks.
Returns
See SeSetSecurityDescriptorInfoEx.
Parameters
[in]ObjectIf specified, the function will use this arbitrary object that points to an object security descriptor.
[in]SecurityInformationSecurity information details to be set.
[in]SecurityDescriptorA security descriptor where its info is to be changed.
[in,out]ObjectsSecurityDescriptorThe returned pointer to security descriptor objects.
[in]AutoInheritFlagsFlags bitmask inheritation, influencing how the security descriptor can be inherited and if it can be in the first place.
[in]PoolTypePool type for the new security descriptor to allocate.
[in]GenericMappingThe generic mapping of access rights masks.
Returns
Returns STATUS_SUCCESS if the operations have been completed without problems and that new info has been set to the security descriptor. STATUS_NO_SECURITY_ON_OBJECT is returned if the object does not have a security descriptor. STATUS_INSUFFICIENT_RESOURCES is returned if memory pool allocation for the new security descriptor with new info set has failed.
Parameters
[in]SecurityDescriptorA security descriptor to be freed from memory.
Returns
Returns STATUS_SUCCESS.
Parameters
[in]_ParentDescriptorA security descriptor of the parent object that is being created.
[in]_ExplicitDescriptorAn explicit security descriptor that is applied to a new object.
[out]NewDescriptorThe new allocated security descriptor.
[in]ObjectTypeThe type of the new object.
[in]IsDirectoryObjectSet this to TRUE if the newly created object is a directory object, otherwise set this to FALSE.
[in]AutoInheritFlagsAutomatic inheritance flags that influence how access control entries within ACLs from security descriptors are inherited.
[in]SubjectContextSecurity subject context of the new object.
[in]GenericMappingGeneric mapping of access mask rights.
[in]PoolTypeThis parameter is unused.
Returns
Returns STATUS_SUCCESS if the operations have been completed successfully and that the security descriptor has been assigned to the new object. STATUS_NO_TOKEN is returned if the caller hasn't supplied a valid argument to a security subject context. STATUS_INVALID_OWNER is returned if the caller hasn't supplied a parent descriptor that belongs to the main user (owner). STATUS_INVALID_PRIMARY_GROUP is returned by the same reason as with the previous NTSTATUS code. The two NTSTATUS codes are returned if the calling thread stated that the owner and/or group is defaulted to the parent descriptor (SEF_DEFAULT_OWNER_FROM_PARENT and/or SEF_DEFAULT_GROUP_FROM_PARENT respectively). STATUS_INSUFFICIENT_RESOURCES is returned if memory pool allocation for the descriptor buffer has failed. A failure NTSTATUS is returned otherwise.
Parameters
[in]ParentDescriptorA security descriptor of the parent object that is being created.
[in]ExplicitDescriptorAn explicit security descriptor that is applied to a new object.
[out]NewDescriptorThe new allocated security descriptor.
[in]IsDirectoryObjectSet this to TRUE if the newly created object is a directory object, otherwise set this to FALSE.
[in]SubjectContextSecurity subject context of the new object.
[in]GenericMappingGeneric mapping of access mask rights.
[in]PoolTypeThis parameter is unused.
Returns
See SeAssignSecurityEx.
Parameters
[in]SecurityDescriptorA security descriptor.
[out]QuotaInfoSizeThe returned quota size of the given security descriptor to the caller. The function may return 0 to this parameter if the descriptor doesn't have a group or a discretionary access control list (DACL) even.
Returns
Returns STATUS_SUCCESS if the quota size of a security descriptor has been computed successfully. STATUS_UNKNOWN_REVISION is returned if the security descriptor has an invalid revision.

Definition at line 244 of file dos8dot3.c.

252{
253 static const char Illegal[] = "*?<>|\"+=,;[]:/\\\345";
254 int Dot = -1;
255 int i;
256 char Buffer[12];
258 BOOLEAN GotSpace = FALSE;
260
261 if (!OemName)
262 {
263 OemString.Length = sizeof(Buffer);
264 OemString.MaximumLength = sizeof(Buffer);
265 OemString.Buffer = Buffer;
267 }
268
270 if (!NT_SUCCESS(Status))
271 return FALSE;
272
273 if ((OemName->Length > 12) || (OemName->Buffer == NULL)) return FALSE;
274
275 /* a starting . is invalid, except for . and .. */
276 if (OemName->Buffer[0] == '.')
277 {
278 if (OemName->Length != 1 && (OemName->Length != 2 || OemName->Buffer[1] != '.')) return FALSE;
280
281 return TRUE;
282 }
283
284 for (i = 0; i < OemName->Length; i++)
285 {
286 switch (OemName->Buffer[i])
287 {
288 case ' ':
289 /* leading/trailing spaces not allowed */
290 if (!i || i == OemName->Length-1 || OemName->Buffer[i+1] == '.') return FALSE;
291 GotSpace = TRUE;
292 break;
293
294 case '.':
295 if (Dot != -1) return FALSE;
296 Dot = i;
297 break;
298
299 default:
300 if (strchr(Illegal, OemName->Buffer[i])) return FALSE;
301 break;
302 }
303 }
304 /* check file part is shorter than 8, extension shorter than 3
305 * dot cannot be last in string
306 */
307 if (Dot == -1)
308 {
309 if (OemName->Length > 8) return FALSE;
310 }
311 else
312 {
313 if (Dot > 8 || (OemName->Length - Dot > 4) || Dot == OemName->Length - 1) return FALSE;
314 }
315
316 if (NameContainsSpaces) *NameContainsSpaces = GotSpace;
317
318 return TRUE;
319}
unsigned char BOOLEAN
char * strchr(const char *String, int ch)
Definition: utclib.c:501
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1304
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString(STRING *, const UNICODE_STRING *, BOOLEAN)
_Inout_opt_ POEM_STRING _Out_opt_ PBOOLEAN NameContainsSpaces
Definition: rtlfuncs.h:3091
#define Dot(u, v)
Definition: normal.c:49
STRING OEM_STRING
Definition: umtypes.h:203
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1560

◆ RtlGenerate8dot3Name()

VOID NTAPI RtlGenerate8dot3Name ( IN PUNICODE_STRING  Name,
IN BOOLEAN  AllowExtendedCharacters,
IN OUT PGENERATE_NAME_CONTEXT  Context,
OUT PUNICODE_STRING  Name8dot3 
)

Definition at line 81 of file dos8dot3.c.

85{
86 ULONG Length = Name->Length / sizeof(WCHAR);
87 ULONG IndexLength;
89 ULONG DotPos;
90 WCHAR IndexBuffer[8];
91 WCHAR Char;
92 USHORT Checksum;
93
94 if (!Context->NameLength)
95 {
96 DotPos = Length;
97
98 /* Find last dot in Name */
99 for (Index = 0; Index < Length; Index++)
100 {
101 if (Name->Buffer[Index] == L'.')
102 DotPos = Index;
103 }
104
105 /* Copy name. OEM string length can't exceed 6. */
106 UCHAR OemSizeLeft = 6;
107 for (Index = 0; (Index < DotPos) && OemSizeLeft; Index++)
108 {
109 Char = Name->Buffer[Index];
110
111 if ((Char > L' ') && (Char != L'.') &&
112 ((Char < 127) || (AllowExtendedCharacters && RtlIsValidOemCharacter(&Char))))
113 {
114 if (RtlpIsShortIllegal(Char))
115 Char = L'_';
116 else if (Char >= L'a' && Char <= L'z')
117 Char = RtlpUpcaseUnicodeChar(Char);
118
119 /* Beware of MB OEM codepage */
121 {
122 if (OemSizeLeft < 2)
123 break;
124 OemSizeLeft--;
125 }
126
127 Context->NameBuffer[Context->NameLength] = Char;
128 Context->NameLength++;
129 OemSizeLeft--;
130 }
131 }
132
133 /* Copy extension (4 valid characters max) */
134 Context->ExtensionLength = 0;
135 if (DotPos < Length)
136 {
137 Context->ExtensionBuffer[0] = L'.';
138 Context->ExtensionLength = 1;
139
140 while (DotPos < Length && Context->ExtensionLength < 4)
141 {
142 Char = Name->Buffer[DotPos];
143
144 if ((Char > L' ') && (Char != L'.') &&
145 ((Char < 127) || (AllowExtendedCharacters && RtlIsValidOemCharacter(&Char))))
146 {
147 if (RtlpIsShortIllegal(Char))
148 Char = L'_';
149 else if (Char >= L'a' && Char <= L'z')
150 Char = RtlpUpcaseUnicodeChar(Char);
151
152 Context->ExtensionBuffer[Context->ExtensionLength++] = Char;
153 }
154
155 Char = UNICODE_NULL;
156 ++DotPos;
157 }
158
159 if (Char != UNICODE_NULL)
160 Context->ExtensionBuffer[Context->ExtensionLength - 1] = L'~';
161 }
162
163 if (Context->NameLength <= 2)
164 {
165 Checksum = Context->Checksum = RtlpGetCheckSum(Name);
166
167 for (Index = 0; Index < 4; Index++)
168 {
169 Context->NameBuffer[Context->NameLength + Index] =
170 (Checksum & 0xF) > 9 ? (Checksum & 0xF) + L'A' - 10 : (Checksum & 0xF) + L'0';
171 Checksum >>= 4;
172 }
173
174 Context->CheckSumInserted = TRUE;
175 Context->NameLength += 4;
176 }
177 }
178
179 ++Context->LastIndexValue;
180
181 if (Context->LastIndexValue > 4 && !Context->CheckSumInserted)
182 {
183 Checksum = Context->Checksum = RtlpGetCheckSum(Name);
184
185 for (Index = 2; Index < 6; Index++)
186 {
187 Context->NameBuffer[Index] =
188 (Checksum & 0xF) > 9 ? (Checksum & 0xF) + L'A' - 10 : (Checksum & 0xF) + L'0';
189 Checksum >>= 4;
190 }
191
192 Context->CheckSumInserted = TRUE;
193 Context->NameLength = 6;
194 Context->LastIndexValue = 1;
195 }
196
197 /* Calculate index length and index buffer */
198 Index = Context->LastIndexValue;
199 for (IndexLength = 1; IndexLength <= 7 && Index > 0; IndexLength++)
200 {
201 IndexBuffer[8 - IndexLength] = L'0' + (Index % 10);
202 Index /= 10;
203 }
204
205 IndexBuffer[8 - IndexLength] = L'~';
206
207 /* Reset name length */
208 Name8dot3->Length = 0;
209
210 /* If name present */
211 if (Context->NameLength)
212 {
213 /* Copy name buffer */
214 Length = Context->NameLength * sizeof(WCHAR);
215 RtlCopyMemory(Name8dot3->Buffer, Context->NameBuffer, Length);
216 Name8dot3->Length = Length;
217 }
218
219 /* Copy index buffer */
220 Length = IndexLength * sizeof(WCHAR);
221 RtlCopyMemory(Name8dot3->Buffer + (Name8dot3->Length / sizeof(WCHAR)),
222 IndexBuffer + (8 - IndexLength),
223 Length);
224 Name8dot3->Length += Length;
225
226 /* If extension present */
227 if (Context->ExtensionLength)
228 {
229 /* Copy extension buffer */
230 Length = Context->ExtensionLength * sizeof(WCHAR);
231 RtlCopyMemory(Name8dot3->Buffer + (Name8dot3->Length / sizeof(WCHAR)),
232 Context->ExtensionBuffer,
233 Length);
234 Name8dot3->Length += Length;
235 }
236}
static USHORT RtlpGetCheckSum(PUNICODE_STRING Name)
Definition: dos8dot3.c:35
PUSHORT NlsUnicodeToMbOemTable
Definition: nlsboot.c:22
static BOOLEAN RtlpIsShortIllegal(const WCHAR Char)
Definition: dos8dot3.c:29
BOOLEAN NTAPI RtlIsValidOemCharacter(IN PWCHAR Char)
Definition: unicode.c:514
#define HIBYTE(W)
Definition: jmemdos.c:486
WCHAR NTAPI RtlpUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:160
BOOLEAN NlsMbOemCodePageTag
Definition: nlsboot.c:19
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ BOOLEAN _Inout_ PGENERATE_NAME_CONTEXT _Inout_ PUNICODE_STRING Name8dot3
Definition: rtlfuncs.h:1586
_In_ BOOLEAN AllowExtendedCharacters
Definition: rtlfuncs.h:1584
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ RtlIsValidOemCharacter()

BOOLEAN NTAPI RtlIsValidOemCharacter ( IN PWCHAR  Char)

Definition at line 514 of file unicode.c.

515{
516 WCHAR UnicodeChar;
517 WCHAR OemChar;
518
519 /* If multi-byte code page present */
521 {
523
524 OemChar = NlsUnicodeToMbOemTable[*Char];
525
526 /* If character has Lead Byte */
527 Offset = NlsOemLeadByteInfo[HIBYTE(OemChar)];
528 if (Offset)
529 {
530 /* Use DBCS table */
531 UnicodeChar = NlsOemLeadByteInfo[Offset + LOBYTE(OemChar)];
532 }
533 else
534 {
535 UnicodeChar = NlsOemToUnicodeTable[OemChar];
536 }
537
538 /* Upcase */
539 UnicodeChar = RtlpUpcaseUnicodeChar(UnicodeChar);
540
541 /* Receive OEM character from the table */
542 OemChar = NlsUnicodeToMbOemTable[UnicodeChar];
543 }
544 else
545 {
546 /* Receive Unicode character from the table */
548
549 /* Receive OEM character from the table */
550 OemChar = NlsUnicodeToOemTable[UnicodeChar];
551 }
552
553 /* Not valid character, failed */
554 if (OemChar == NlsOemDefaultChar)
555 {
556 DPRINT1("\\u%04x is not valid for OEM\n", *Char);
557 return FALSE;
558 }
559
560 *Char = UnicodeChar;
561
562 return TRUE;
563}
#define DPRINT1
Definition: precomp.h:8
#define LOBYTE(W)
Definition: jmemdos.c:487
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
USHORT NlsOemDefaultChar
Definition: nlsboot.c:25
PWCHAR NlsOemToUnicodeTable
Definition: nlsboot.c:20
PUSHORT NlsUnicodeToMbOemTable
Definition: nlsboot.c:22
PUSHORT NlsOemLeadByteInfo
Definition: nlsboot.c:23
BOOLEAN NlsMbOemCodePageTag
Definition: nlsboot.c:19
PCHAR NlsUnicodeToOemTable
Definition: nlsboot.c:21

Referenced by RtlGenerate8dot3Name(), and START_TEST().

◆ RtlpGetCheckSum()

static USHORT RtlpGetCheckSum ( PUNICODE_STRING  Name)
static

Definition at line 35 of file dos8dot3.c.

36{
37 PWCHAR CurrentChar;
39 USHORT Saved;
41
42 if (!Name->Length)
43 return 0;
44
45 if (Name->Length == sizeof(WCHAR))
46 return Name->Buffer[0];
47
48 CurrentChar = Name->Buffer;
49 Hash = (*CurrentChar << 8) + *(CurrentChar + 1);
50
51 if (Name->Length == 2 * sizeof(WCHAR))
52 return Hash;
53
54 Saved = Hash;
55 Length = 2;
56
57 do
58 {
59 CurrentChar += 2;
60 Hash = (Hash << 7) + *CurrentChar;
61 Hash = (Saved >> 1) + (Hash << 8);
62
63 if (Length + 1 < Name->Length / sizeof(WCHAR))
64 {
65 Hash += *(CurrentChar + 1);
66 }
67
68 Saved = Hash;
69 Length += 2;
70 }
71 while (Length < Name->Length / sizeof(WCHAR));
72
73 return Hash;
74}
static int Hash(const char *)
Definition: reader.c:2257
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by RtlGenerate8dot3Name().

◆ RtlpIsShortIllegal()

static BOOLEAN RtlpIsShortIllegal ( const WCHAR  Char)
static

Definition at line 29 of file dos8dot3.c.

30{
31 return (Char < 128 && (RtlpShortIllegals[Char / 32] & (1 << (Char % 32))));
32}
const ULONG RtlpShortIllegals[]
Definition: dos8dot3.c:20

Referenced by RtlGenerate8dot3Name().

Variable Documentation

◆ NlsUnicodeToMbOemTable

PUSHORT NlsUnicodeToMbOemTable
extern

Definition at line 22 of file nlsboot.c.

Referenced by RtlGenerate8dot3Name().

◆ RtlpShortIllegals

const ULONG RtlpShortIllegals[] = { 0xFFFFFFFF, 0xFC009C04, 0x38000000, 0x10000000 }

Definition at line 20 of file dos8dot3.c.

Referenced by RtlpIsShortIllegal().