Beispiel #1
0
        public virtual void TestStaticMapParsing()
        {
            FilePath tempStaticMapFile     = FilePath.CreateTempFile("nfs-", ".map");
            string   staticMapFileContents = "uid 10 100\n" + "gid 10 200\n" + "uid 11 201 # comment at the end of a line\n"
                                             + "uid 12 301\n" + "# Comment at the beginning of a line\n" + "    # Comment that starts late in the line\n"
                                             + "uid 10000 10001# line without whitespace before comment\n" + "uid 13 302\n"
                                             + "gid\t11\t201\n" + "\n" + "gid 12 202\n" + "uid 4294967294 123\n" + "gid 4294967295 321";

            // Tabs instead of spaces.
            // Entirely empty line.
            CreateStaticMapFile(tempStaticMapFile, staticMapFileContents);
            ShellBasedIdMapping.StaticMapping parsedMap = ShellBasedIdMapping.ParseStaticMap(
                tempStaticMapFile);
            Assert.Equal(10, (int)parsedMap.uidMapping[100]);
            Assert.Equal(11, (int)parsedMap.uidMapping[201]);
            Assert.Equal(12, (int)parsedMap.uidMapping[301]);
            Assert.Equal(13, (int)parsedMap.uidMapping[302]);
            Assert.Equal(10, (int)parsedMap.gidMapping[200]);
            Assert.Equal(11, (int)parsedMap.gidMapping[201]);
            Assert.Equal(12, (int)parsedMap.gidMapping[202]);
            Assert.Equal(10000, (int)parsedMap.uidMapping[10001]);
            // Ensure pass-through of unmapped IDs works.
            Assert.Equal(1000, (int)parsedMap.uidMapping[1000]);
            Assert.Equal(-2, (int)parsedMap.uidMapping[123]);
            Assert.Equal(-1, (int)parsedMap.gidMapping[321]);
        }
 /// <exception cref="System.IO.IOException"/>
 private void UpdateStaticMapping()
 {
     lock (this)
     {
         bool init = (staticMapping == null);
         //
         // if the static mapping file
         //   - was modified after last update, load the map again;
         //   - did not exist but was added since last update, load the map;
         //   - existed before but deleted since last update, clear the map
         //
         if (staticMappingFile.Exists())
         {
             // check modification time, reload the file if the last modification
             // time changed since prior load.
             long lmTime = staticMappingFile.LastModified();
             if (lmTime != lastModificationTimeStaticMap)
             {
                 Log.Info(init ? "Using " : "Reloading " + "'" + staticMappingFile + "' for static UID/GID mapping..."
                          );
                 lastModificationTimeStaticMap = lmTime;
                 staticMapping = ParseStaticMap(staticMappingFile);
             }
         }
         else
         {
             if (init)
             {
                 staticMapping = new ShellBasedIdMapping.StaticMapping(new Dictionary <int, int>(),
                                                                       new Dictionary <int, int>());
             }
             if (lastModificationTimeStaticMap != 0 || init)
             {
                 // print the following log at initialization or when the static
                 // mapping file was deleted after prior load
                 Log.Info("Not doing static UID/GID mapping because '" + staticMappingFile + "' does not exist."
                          );
             }
             lastModificationTimeStaticMap = 0;
             staticMapping.Clear();
         }
     }
 }