示例#1
0
        private static DsNameResultItem[] CrackNames(
            SafeDsHandle hDS,
            DsNameFlags flags,
            DsNameFormat formatOffered,
            DsNameFormat formatDesired,
            string[] names)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(names);

            IntPtr ptr = IntPtr.Zero;

            try
            {
                NativeMethods.EnforceSuccess(NativeMethods.DsCrackNames(
                                                 hDS,
                                                 flags,
                                                 formatOffered,
                                                 formatDesired,
                                                 names.Length,
                                                 names,
                                                 out ptr));

                DsNameResult result = Utils.PtrToStructure <DsNameResult>(ptr);

                IEnumerable <DsNameResultItem> items =
                    Utils.ReadNativeArray <DsNameResultItem>(result.rItems, result.cItems);

                return(new List <DsNameResultItem>(items).ToArray());
            }
            finally
            {
                NativeMethods.DsFreeNameResult(ptr);
            }
        }
            /// <summary>
            ///
            /// </summary>
            /// <param name="literalPath"></param>
            /// <param name="session"></param>
            internal UnresolvedPscxPathImpl(string literalPath, SessionState session)
            {
                PscxArgumentException.ThrowIfIsNullOrEmpty(literalPath);
                PscxArgumentException.ThrowIfIsNull(session);

                _providerPath = session.Path.GetUnresolvedProviderPathFromPSPath(literalPath, out _providerInfo, out _driveInfo);
                _isUnresolved = true;
                _sourcePath   = literalPath;
            }
示例#3
0
        private static SafeDsCredentialsHandle MakeCredentials(string user, string domain, string password)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(user);
            PscxArgumentException.ThrowIfIsNullOrEmpty(domain);
            PscxArgumentException.ThrowIfIsNullOrEmpty(password);

            SafeDsCredentialsHandle cred;

            NativeMethods.EnforceSuccess(NativeMethods.DsMakePasswordCredentials(user, domain, password, out cred));

            return(cred);
        }
示例#4
0
        public void Prepend(string value)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(value);
            EnsureValuesLoaded();

            value = value.Trim();

            if (value.Length > 0 && !Contains(value))
            {
                _values.Insert(0, value);
            }
        }
示例#5
0
        public void Remove(string value)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(value);
            EnsureValuesLoaded();

            value = value.Trim();
            int index = IndexOf(value);

            if (index >= 0)
            {
                _values.RemoveAt(index);
            }
        }
示例#6
0
        public static string MakeParsedPath(string unparsed)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(unparsed);

            if (unparsed[unparsed.Length - 1] == '\\')
            {
                unparsed = unparsed.Substring(0, unparsed.Length - 1);
            }

            if (unparsed.StartsWith(UnparsedPathPrefix) && unparsed.Contains(":"))
            {
                return(unparsed.Substring(UnparsedPathPrefix.Length));
            }

            return(unparsed);
        }
示例#7
0
        public static string GetCanonicalName(DirectoryEntry entry)
        {
            string canonicalName = GetPropertyValueAsString(entry, "canonicalName");

            if (string.IsNullOrEmpty(canonicalName))
            {
                using (DirectoryEntry parent = entry.Parent)
                {
                    canonicalName = GetPropertyValueAsString(parent, "canonicalName");
                }

                PscxArgumentException.ThrowIfIsNullOrEmpty(canonicalName,
                                                           Resources.Errors.CannotGetDirectoryEntryCanonicalName,
                                                           entry.Path);

                canonicalName = canonicalName.TrimEnd('/') + '/' +
                                GetPropertyValueAsString(entry, "cn");
            }

            return(canonicalName);
        }
示例#8
0
        protected static string GetDriveQualifiedPath(string path, PSDriveInfo drive)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(path);
            PscxArgumentException.ThrowIfIsNull(drive);

            string qualifiedPath = path;
            bool   unqualified   = true;

            int index = path.IndexOf(':');

            if (index != -1)
            {
                if (string.Equals(path.Substring(0, index), drive.Name, StringComparison.OrdinalIgnoreCase))
                {
                    unqualified = false;
                }
            }
            if (unqualified)
            {
                const char separator = '\\';
                string     format    = "{0}:" + separator + "{1}";

                if (path.StartsWith(separator.ToString(), StringComparison.Ordinal))
                {
                    format = "{0}:{1}";
                }

                // strip root
                if (!String.IsNullOrEmpty(drive.Root))
                {
                    if (path.StartsWith(drive.Root))
                    {
                        path = path.Substring(drive.Root.Length + 1); // grab trailing slash
                    }
                }

                qualifiedPath = string.Format(CultureInfo.InvariantCulture, format, drive.Name, path);
            }
            return(qualifiedPath);
        }
示例#9
0
        protected static string GetProviderQualifiedPath(string path, ProviderInfo provider)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(path);
            PscxArgumentException.ThrowIfIsNull(provider);

            string qualifiedPath       = path;
            bool   isProviderQualified = false;
            int    index = path.IndexOf("::", StringComparison.Ordinal);

            if (index != -1)
            {
                string providerName = path.Substring(0, index);
                if (CompareProviderNames(provider.Name, providerName) == true)
                {
                    isProviderQualified = true;
                }
            }
            if (!isProviderQualified)
            {
                qualifiedPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", GetProviderFullName(provider),
                                              "::", path);
            }
            return(qualifiedPath);
        }
示例#10
0
        public LdapPathItem(string prefix, string name) : this(name)
        {
            PscxArgumentException.ThrowIfIsNullOrEmpty(prefix);

            Prefix = prefix.ToUpperInvariant();
        }