[ros-diffs] [pschweitzer] 34631: - Implemented FsRtlIsHpfsDbcsLegal and updated its comments - Added its prototype to ntifs.h - Fixed its kernel export - Fixed a bug in FsRtlIsFatDbcsLegal, that leads the function to accept names with multiples dots - Fixed a bug in FsRtlIsFatDbcsLegal, that leads the function to accept names finished with a space - Fixed two other minors bugs in FsRtlIsFatDbcsLegal - Fixed build...

pschweitzer at svn.reactos.org pschweitzer at svn.reactos.org
Mon Jul 21 12:22:07 CEST 2008


Author: pschweitzer
Date: Mon Jul 21 05:22:06 2008
New Revision: 34631

URL: http://svn.reactos.org/svn/reactos?rev=34631&view=rev
Log:
- Implemented FsRtlIsHpfsDbcsLegal and updated its comments
- Added its prototype to ntifs.h
- Fixed its kernel export
- Fixed a bug in FsRtlIsFatDbcsLegal, that leads the function to accept names with multiples dots
- Fixed a bug in FsRtlIsFatDbcsLegal, that leads the function to accept names finished with a space
- Fixed two other minors bugs in FsRtlIsFatDbcsLegal
- Fixed build...

Modified:
    branches/pierre-fsd/include/ddk/ntifs.h
    branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c
    branches/pierre-fsd/ntoskrnl/ntoskrnl_arm.def
    branches/pierre-fsd/ntoskrnl/ntoskrnl_i386.def

Modified: branches/pierre-fsd/include/ddk/ntifs.h
URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/include/ddk/ntifs.h?rev=34631&r1=34630&r2=34631&view=diff
==============================================================================
--- branches/pierre-fsd/include/ddk/ntifs.h [iso-8859-1] (original)
+++ branches/pierre-fsd/include/ddk/ntifs.h [iso-8859-1] Mon Jul 21 05:22:06 2008
@@ -2966,6 +2966,16 @@
 NTKERNELAPI
 BOOLEAN
 NTAPI
+FsRtlIsHpfsDbcsLegal (
+    IN ANSI_STRING  DbcsName,
+    IN BOOLEAN      WildCardsPermissible,
+    IN BOOLEAN      PathNamePermissible,
+    IN BOOLEAN      LeadingBackslashPermissible)
+);
+
+NTKERNELAPI
+BOOLEAN
+NTAPI
 FsRtlIsNameInExpression (
     IN PUNICODE_STRING  Expression,
     IN PUNICODE_STRING  Name,

Modified: branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c
URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c?rev=34631&r1=34630&r2=34631&view=diff
==============================================================================
--- branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c [iso-8859-1] (original)
+++ branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c [iso-8859-1] Mon Jul 21 05:22:06 2008
@@ -61,7 +61,7 @@
     for (i = 0; i < Name.Length / sizeof(CHAR); i++)
     {
         /* First make sure the character it's not the Lead DBCS */
-        if (FsRtlIsLeadDbcsCharacter(Name->Buffer[i]))
+        if (FsRtlIsLeadDbcsCharacter(Name.Buffer[i]))
         {
             i++;
         }
@@ -196,7 +196,8 @@
                     IN BOOLEAN LeadingBackslashPermissible)
 {
     ANSI_STRING FirstPart, RemainingPart, Name;
-    ULONG i, LastDot = 0;
+    BOOLEAN LastDot;
+    ULONG i;
 
     /* Just quit if the string is empty */
     if (!DbcsName.Length)
@@ -217,6 +218,9 @@
     FsRtlDissectDbcs(DbcsName, &FirstPart, &RemainingPart);
     while (FirstPart.Length > 0)
     {
+        /* Reset dots count */
+        LastDot = FALSE;
+
         /* Accept special filename if wildcards are allowed */
         if (WildCardsPermissible && (FirstPart.Length == 1 || FirstPart.Length == 2) && FirstPart.Buffer[0] == '.')
         {
@@ -234,7 +238,7 @@
         }
 
         /* Filename must be 8.3 filename */
-        if (FirstPart.Length < 3 || FirstPart.Length > 12)
+        if (FirstPart.Length / sizeof(CHAR) < 3 || FirstPart.Length / sizeof(CHAR) > 12)
             return FALSE;
 
         if (!WildCardsPermissible && FsRtlDoesDbcsContainWildCards(&FirstPart))
@@ -245,23 +249,27 @@
          *   0x00-0x1F, 0x22, 0x2B, 0x2C, 0x2F, 0x3A, 0x3B, 0x3D, 0x5B, 0x5D, 0x7C */
         for (i = 0; i < FirstPart.Length / sizeof(CHAR); i++)
         {
-            if ((FirstPart.Buffer[i] < 0x1F) || (FirstPart.Buffer[i] == 0x22) ||
-                (FirstPart.Buffer[i] == 0x2B) || (FirstPart.Buffer[i] == 0x2C) ||
-                (FirstPart.Buffer[i] == 0x2F) || (FirstPart.Buffer[i] == 0x3A) ||
-                (FirstPart.Buffer[i] == 0x3B) || (FirstPart.Buffer[i] == 0x3D) ||
-                (FirstPart.Buffer[i] == 0x5B) || (FirstPart.Buffer[i] == 0x5D) ||
-                (FirstPart.Buffer[i] == 0x7C))
+            /* First make sure the character it's not the Lead DBCS */
+            if (FsRtlIsLeadDbcsCharacter(FirstPart.Buffer[i]))
+            {
+                i++;
+            }
+            else if ((FirstPart.Buffer[i] < 0x1F) || (FirstPart.Buffer[i] == 0x22) ||
+                     (FirstPart.Buffer[i] == 0x2B) || (FirstPart.Buffer[i] == 0x2C) ||
+                     (FirstPart.Buffer[i] == 0x2F) || (FirstPart.Buffer[i] == 0x3A) ||
+                     (FirstPart.Buffer[i] == 0x3B) || (FirstPart.Buffer[i] == 0x3D) ||
+                     (FirstPart.Buffer[i] == 0x5B) || (FirstPart.Buffer[i] == 0x5D) ||
+                     (FirstPart.Buffer[i] == 0x7C))
             {
                 return FALSE;
             }
-            /* First make sure the character it's not the Lead DBCS */
-            if (FsRtlIsLeadDbcsCharacter(Name->Buffer[i]))
-            {
-                i++;
-            }
             else if (FirstPart.Buffer[i] == '.')
             {
-                LastDot = i;
+                /* Filename can only contain one dot */
+                if (LastDot)
+                    return FALSE;
+
+                LastDot = TRUE;
 
                 /* We mustn't have spaces before dot or at the end of the filename
                  * and no dot at the beginning of the filename */
@@ -271,11 +279,15 @@
                 if (i > 0)
                     if (FirstPart.Buffer[i - 1] == ' ')
                         return FALSE;
-            }
-        }
-
-        /* Filename must be 8.3 filename and not 3.8 filename */
-        if (LastDot && ((FirstPart.Length / sizeof(CHAR) - 1) - LastDot > 3))
+
+                /* Filename must be 8.3 filename and not 3.8 filename */
+                if ((FirstPart.Length / sizeof(CHAR) - 1) - i > 3)
+                    return FALSE;
+            }
+        }
+
+        /* Filename mustn't finish with a space */
+        if (FirstPart.Buffer[FirstPart.Length / sizeof(CHAR) - 1] == ' ')
             return FALSE;
 
         EndLoop:
@@ -296,21 +308,24 @@
 
 /*++
  * @name FsRtlIsHpfsDbcsLegal
- * @unimplemented
- *
- * FILLME
+ * @implemented
+ *
+ * Returns TRUE if the given DbcsName is a valid HPFS filename
  *
  * @param DbcsName
- *        FILLME
+ *        The filename to check. It can also contains pathname.
  *
  * @param WildCardsPermissible
- *        FILLME
+ *        If this is set to FALSE and if filename contains wildcard, the function 
+ *        will fail
  *
  * @param PathNamePermissible
- *        FILLME
+ *        If this is set to FALSE and if the filename comes with a pathname, the
+ *        function will fail
  *
  * @param LeadingBackslashPermissible
- *        FILLME
+ *        If this is set to FALSE and if the filename starts with a backslash, the
+ *        function will fail
  *
  * @return TRUE if the DbcsName is legal, FALSE otherwise
  *
@@ -318,12 +333,94 @@
  *
  *--*/
 BOOLEAN
-STDCALL
+NTAPI
 FsRtlIsHpfsDbcsLegal(IN ANSI_STRING DbcsName,
                      IN BOOLEAN WildCardsPermissible,
                      IN BOOLEAN PathNamePermissible,
                      IN BOOLEAN LeadingBackslashPermissible)
 {
-    KEBUGCHECK(0);
-    return FALSE;
+    ANSI_STRING FirstPart, RemainingPart, Name;
+    ULONG i;
+
+    /* Just quit if the string is empty */
+    if (!DbcsName.Length)
+        return FALSE;
+
+    /* DbcsName wasn't supposed to be started with \ */
+    if (!LeadingBackslashPermissible && DbcsName.Buffer[0] == '\\')
+        return FALSE;
+    /* DbcsName was allowed to be started with \, but now, remove it */
+    else if (LeadingBackslashPermissible && DbcsName.Buffer[0] == '\\')
+    {
+        DbcsName.Buffer = DbcsName.Buffer + 1;
+        DbcsName.Length = DbcsName.Length - 1;
+        DbcsName.MaximumLength = DbcsName.MaximumLength - 1;
+    }
+
+    /* Extract first part of the DbcsName to work on */
+    FsRtlDissectDbcs(DbcsName, &FirstPart, &RemainingPart);
+    while (FirstPart.Length > 0)
+    {
+        /* Accept special filename if wildcards are allowed */
+        if (WildCardsPermissible && (FirstPart.Length == 1 || FirstPart.Length == 2) && FirstPart.Buffer[0] == '.')
+        {
+            if (FirstPart.Length == 2)
+            {
+                if (FirstPart.Buffer[1] == '.')
+                {
+                    goto EndLoop;
+                }
+            }
+            else
+            {
+                goto EndLoop;
+            }
+        }
+
+        /* Filename must be 255 bytes maximum */
+        if (FirstPart.Length > 255)
+            return FALSE;
+
+        if (!WildCardsPermissible && FsRtlDoesDbcsContainWildCards(&FirstPart))
+            return FALSE;
+
+        /* Now, we will parse the filename to find everything bad in
+         * It mustn't contain:
+         *   0x00-0x1F, 0x22, 0x2A, 0x2F, 0x3A, 0x3C, 0x3E, 0x3F, 0x7C */
+        for (i = 0; i < FirstPart.Length / sizeof(CHAR); i++)
+        {
+            /* First make sure the character it's not the Lead DBCS */
+            if (FsRtlIsLeadDbcsCharacter(FirstPart.Buffer[i]))
+            {
+                i++;
+            }
+            else if ((FirstPart.Buffer[i] < 0x1F) || (FirstPart.Buffer[i] == 0x22) ||
+                     (FirstPart.Buffer[i] == 0x2A) || (FirstPart.Buffer[i] == 0x2F) ||
+                     (FirstPart.Buffer[i] == 0x3A) || (FirstPart.Buffer[i] == 0x3C) ||
+                     (FirstPart.Buffer[i] == 0x3E) || (FirstPart.Buffer[i] == 0x3F) ||
+                     (FirstPart.Buffer[i] == 0x7C))
+            {
+                return FALSE;
+            }
+        }
+
+        /* Filename mustn't finish with a space or a dot */
+        if ((FirstPart.Buffer[FirstPart.Length / sizeof(CHAR) - 1] == ' ') ||
+            (FirstPart.Buffer[FirstPart.Length / sizeof(CHAR) - 1] == '.'))
+            return FALSE;
+
+        EndLoop:
+        /* Preparing next loop */
+        Name.Buffer = RemainingPart.Buffer;
+        Name.Length = RemainingPart.Length;
+        Name.MaximumLength = RemainingPart.MaximumLength;
+
+        /* Call once again our dissect function */
+        FsRtlDissectDbcs(Name, &FirstPart, &RemainingPart);
+
+        /* We found a pathname, it wasn't allowed */
+        if (FirstPart.Length > 0 && !PathNamePermissible)
+            return FALSE;
+    }
+    return TRUE;
 }

Modified: branches/pierre-fsd/ntoskrnl/ntoskrnl_arm.def
URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/ntoskrnl_arm.def?rev=34631&r1=34630&r2=34631&view=diff
==============================================================================
--- branches/pierre-fsd/ntoskrnl/ntoskrnl_arm.def [iso-8859-1] (original)
+++ branches/pierre-fsd/ntoskrnl/ntoskrnl_arm.def [iso-8859-1] Mon Jul 21 05:22:06 2008
@@ -217,7 +217,7 @@
 FsRtlInsertPerStreamContext
 FsRtlIsDbcsInExpression
 FsRtlIsFatDbcsLegal at 20
-FsRtlIsHpfsDbcsLegal
+FsRtlIsHpfsDbcsLegal at 20
 FsRtlIsNameInExpression
 FsRtlIsNtstatusExpected
 FsRtlIsPagingFile

Modified: branches/pierre-fsd/ntoskrnl/ntoskrnl_i386.def
URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/ntoskrnl_i386.def?rev=34631&r1=34630&r2=34631&view=diff
==============================================================================
--- branches/pierre-fsd/ntoskrnl/ntoskrnl_i386.def [iso-8859-1] (original)
+++ branches/pierre-fsd/ntoskrnl/ntoskrnl_i386.def [iso-8859-1] Mon Jul 21 05:22:06 2008
@@ -234,7 +234,7 @@
 FsRtlInsertPerStreamContext
 FsRtlIsDbcsInExpression
 FsRtlIsFatDbcsLegal at 20
-FsRtlIsHpfsDbcsLegal
+FsRtlIsHpfsDbcsLegal at 20
 FsRtlIsNameInExpression at 16
 FsRtlIsNtstatusExpected at 4
 FsRtlIsPagingFile



More information about the Ros-diffs mailing list