コード例 #1
0
 public bool Exists()
 {
     if (!this.m_initialized)
     {
         string ex = Strings.DagFswInternalErrorFswObjectNotInitialized.ToString();
         if (this.m_initializationException != null)
         {
             ex = this.m_initializationException.Message;
         }
         throw new DagFswNotInitializedException(ex);
     }
     if (this.m_exists == null)
     {
         try
         {
             string text;
             byte[] securityDescriptorBinaryForm;
             NetShare.GetShareInfoWithSecurity(this.WitnessServerFqdn, this.ShareName, out text, out this.m_existingShareRemark, out this.m_shareType, out this.m_sharePermissions, out this.m_shareMaxUses, out securityDescriptorBinaryForm);
             this.m_existingWitnessDirectory = NonRootLocalLongFullPath.Parse(text);
             TaskLogger.Trace("Found existing witness share \\\\{0}\\{1} pointing to {2} (expecting {3})", new object[]
             {
                 this.WitnessServer,
                 this.ShareName,
                 text,
                 this.m_witnessDirectory.ToString()
             });
             if (this.m_existingWitnessDirectory != this.WitnessDirectory)
             {
                 throw new DagFswSharePointsToWrongDirectoryException(this.ShareName, this.WitnessServerFqdn, this.m_existingWitnessDirectory.ToString(), this.WitnessDirectory.ToString());
             }
             this.m_existingSecurity = new DirectorySecurity();
             this.m_existingSecurity.SetSecurityDescriptorBinaryForm(securityDescriptorBinaryForm);
             this.m_exists = new bool?(true);
         }
         catch (Win32Exception ex2)
         {
             if ((long)ex2.NativeErrorCode == 2310L)
             {
                 this.m_exists = new bool?(false);
             }
             else
             {
                 if (ex2.NativeErrorCode == 5)
                 {
                     throw new DagFswInsufficientPermissionsToAccessFswException(this.WitnessServerFqdn, ex2);
                 }
                 throw new DagFswServerNotAccessibleException(this.WitnessServerFqdn, ex2);
             }
         }
     }
     return(this.m_exists.Value);
 }
コード例 #2
0
 public void Delete(bool forceDelete)
 {
     if (this.Exists())
     {
         if (!this.m_isJustCreated)
         {
             if (!forceDelete)
             {
                 return;
             }
         }
         try
         {
             TaskLogger.Trace("Attempting to delete witness share \\\\{0}\\{1}. Just created: {2}, forced: {3}", new object[]
             {
                 this.WitnessServer,
                 this.ShareName,
                 this.m_isJustCreated,
                 forceDelete
             });
             NetShare.DeleteShare(this.WitnessServerFqdn, this.ShareName);
             WmiWrapper.RemoveDirectory(this.WitnessServerFqdn, this.WitnessDirectory.ToString());
             this.m_exists = new bool?(false);
             TaskLogger.Trace("Attempt to delete witness share \\\\{0}\\{1} succeeded.", new object[]
             {
                 this.WitnessServer,
                 this.ShareName
             });
         }
         catch (WmiException ex)
         {
             throw new DagFswUnableToRemoveWitnessDirectoryException(this.WitnessServerFqdn, this.WitnessDirectory.ToString(), ex);
         }
         catch (Win32Exception ex2)
         {
             if ((long)ex2.NativeErrorCode == 2310L)
             {
                 this.m_exists = new bool?(false);
             }
             else
             {
                 if (ex2.NativeErrorCode == 5)
                 {
                     throw new DagFswInsufficientPermissionsToDeleteFswException(this.WitnessServerFqdn, this.FileShareWitnessShare.ToString(), ex2);
                 }
                 throw new DagFswServerNotAccessibleToDeleteFswException(this.WitnessServerFqdn, this.FileShareWitnessShare.ToString(), ex2);
             }
         }
     }
 }
コード例 #3
0
        public void Create()
        {
            FileShareWitnessCheckResult fileShareWitnessCheckResult = this.Check();

            if (fileShareWitnessCheckResult != FileShareWitnessCheckResult.FswOK)
            {
                FileSystemSecurity fileSystemSecurity = new DirectorySecurity();
                foreach (FileSystemAccessRule rule in this.AccessRules)
                {
                    fileSystemSecurity.AddAccessRule(rule);
                }
                switch (fileShareWitnessCheckResult)
                {
                case FileShareWitnessCheckResult.FswDoesNotExist:
                    try
                    {
                        TaskLogger.Trace("Attempting to create new witness share \\\\{0}\\{1}.", new object[]
                        {
                            this.WitnessServer,
                            this.ShareName
                        });
                        WmiWrapper.CreateDirectory(this.WitnessServerFqdn, this.WitnessDirectory.ToString());
                        int num;
                        NetShare.AddShare(string.Format(FileShareWitness.s_hostNameFormat, this.WitnessServerFqdn), null, this.ShareName, this.WitnessDirectory.ToString(), this.m_shareRemark, fileSystemSecurity.GetSecurityDescriptorBinaryForm(), out num);
                        this.m_existingShareRemark      = this.m_shareRemark;
                        this.m_shareType                = 0U;
                        this.m_sharePermissions         = 1;
                        this.m_shareMaxUses             = -1;
                        this.m_existingWitnessDirectory = this.WitnessDirectory;
                        this.m_existingSecurity         = fileSystemSecurity;
                        this.m_exists        = new bool?(true);
                        this.m_isJustCreated = true;
                        TaskLogger.Trace("Attempt to create new witness share \\\\{0}\\{1} succeeded.", new object[]
                        {
                            this.WitnessServer,
                            this.ShareName
                        });
                        return;
                    }
                    catch (WmiException ex)
                    {
                        throw new DagFswUnableToCreateWitnessDirectoryException(this.WitnessServerFqdn, this.WitnessDirectory.ToString(), ex);
                    }
                    catch (Win32Exception ex2)
                    {
                        throw new DagFswUnableToCreateWitnessShareException(this.WitnessServerFqdn, this.FileShareWitnessShare.ToString(), ex2);
                    }
                    break;

                case FileShareWitnessCheckResult.FswWrongDirectory:
                    goto IL_1C1;

                case FileShareWitnessCheckResult.FswWrongPermissions:
                    break;

                default:
                    return;
                }
                fileSystemSecurity = this.m_existingSecurity;
                foreach (FileSystemAccessRule rule2 in this.AccessRules)
                {
                    fileSystemSecurity.AddAccessRule(rule2);
                }
                try
                {
IL_1C1:
                    TaskLogger.Trace("Attempting to modify permissions on witness share \\\\{0}\\{1}.", new object[]
                    {
                        this.WitnessServer,
                        this.ShareName
                    });
                    NetShare.SetShareInfo(this.WitnessServerFqdn, this.ShareName, this.WitnessDirectory.ToString(), this.m_shareRemark, this.m_shareType, this.m_sharePermissions, -1, fileSystemSecurity.GetSecurityDescriptorBinaryForm());
                    this.m_existingWitnessDirectory = this.WitnessDirectory;
                    this.m_existingSecurity         = fileSystemSecurity;
                    this.m_shareMaxUses             = -1;
                    this.m_exists = new bool?(true);
                    TaskLogger.Trace("Attempt to modify permissions on witness share \\\\{0}\\{1} succeeded.", new object[]
                    {
                        this.WitnessServer,
                        this.ShareName
                    });
                }
                catch (Win32Exception ex3)
                {
                    throw new DagFswUnableToUpdateWitnessShareException(this.WitnessServerFqdn, this.FileShareWitnessShare.ToString(), ex3);
                }
            }
        }