Example #1
0
        private PSObject WrapOutputInPSObject(object item, string path)
        {
            if (item == null)
            {
                throw PSTraceSource.NewArgumentNullException("item");
            }
            PSObject obj2 = new PSObject(item);
            PSObject obj3 = item as PSObject;

            if (obj3 != null)
            {
                obj2.InternalTypeNames = new ConsolidatedString(obj3.InternalTypeNames);
            }
            string providerQualifiedPath = LocationGlobber.GetProviderQualifiedPath(path, this.ProviderInfo);

            obj2.AddOrSetProperty("PSPath", providerQualifiedPath);
            providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSPath", providerQualifiedPath });
            NavigationCmdletProvider provider = this as NavigationCmdletProvider;

            if ((provider != null) && (path != null))
            {
                string str2 = null;
                if (this.PSDriveInfo != null)
                {
                    str2 = provider.GetParentPath(path, this.PSDriveInfo.Root, this.Context);
                }
                else
                {
                    str2 = provider.GetParentPath(path, string.Empty, this.Context);
                }
                string str3 = string.Empty;
                if (!string.IsNullOrEmpty(str2))
                {
                    str3 = LocationGlobber.GetProviderQualifiedPath(str2, this.ProviderInfo);
                }
                obj2.AddOrSetProperty("PSParentPath", str3);
                providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSParentPath", str3 });
                string childName = provider.GetChildName(path, this.Context);
                obj2.AddOrSetProperty("PSChildName", childName);
                providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSChildName", childName });
            }
            if (this.PSDriveInfo != null)
            {
                obj2.AddOrSetProperty(this.PSDriveInfo.GetNotePropertyForProviderCmdlets("PSDrive"));
                providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSDrive", this.PSDriveInfo });
            }
            obj2.AddOrSetProperty(this.ProviderInfo.GetNotePropertyForProviderCmdlets("PSProvider"));
            providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSProvider", this.ProviderInfo });
            return(obj2);
        }
Example #2
0
        private PSObject GetItemAsPSObject(object item, Path path)
        {
            if (item == null)
            {
                throw new Exception("Item can't be null");
            }

            PSObject psObject = PSObject.AsPSObject(item);

            PSObject obj3 = item as PSObject;

            if (obj3 != null)
            {
                psObject.TypeNames.Clear();
                foreach (string str in obj3.TypeNames)
                {
                    psObject.TypeNames.Add(str);
                }
            }

            // Add full path as a property
            string providerFullPath = PathIntrinsics.GetFullProviderPath(ProviderInfo, path);

            psObject.Properties.Add(new PSNoteProperty("PSPath", providerFullPath));

            NavigationCmdletProvider provider = this as NavigationCmdletProvider;

            if ((provider != null) && (path != null))
            {
                string parentPath = null;
                if (PSDriveInfo == null)
                {
                    parentPath = provider.GetParentPath(path, string.Empty, ProviderRuntime);
                }
                else
                {
                    parentPath = provider.GetParentPath(path, PSDriveInfo.Root, ProviderRuntime);
                }

                if (!string.IsNullOrEmpty(parentPath))
                {
                    parentPath = PathIntrinsics.GetFullProviderPath(ProviderInfo, parentPath);
                }
                else
                {
                    parentPath = string.Empty;
                }
                psObject.Properties.Add(new PSNoteProperty("PSParentPath", parentPath));

                string childName = provider.GetChildName(path, ProviderRuntime);
                psObject.Properties.Add(new PSNoteProperty("PSChildName", childName));
            }

            if (PSDriveInfo != null)
            {
                psObject.Properties.Add(new PSNoteProperty("PSDrive", PSDriveInfo));
            }

            psObject.Properties.Add(new PSNoteProperty("PSProvider", ProviderInfo));
            return(psObject);
        }
Example #3
0
		internal WSManHelper(NavigationCmdletProvider provider)
		{
			this.CredSSP_RUri = "winrm/config/client/auth";
			this.CredSSP_XMLNmsp = "http://schemas.microsoft.com/wbem/wsman/1/config/client/auth";
			this.CredSSP_SNode = "/cfg:Auth/cfg:CredSSP";
			this.Client_uri = "winrm/config/client";
			this.urlprefix_node = "/cfg:Client/cfg:URLPrefix";
			this.Client_XMLNmsp = "http://schemas.microsoft.com/wbem/wsman/1/config/client";
			this.Service_Uri = "winrm/config/service";
			this.Service_UrlPrefix_Node = "/cfg:Service/cfg:URLPrefix";
			this.Service_XMLNmsp = "http://schemas.microsoft.com/wbem/wsman/1/config/service";
			this.Service_CredSSP_Uri = "winrm/config/service/auth";
			this.Service_CredSSP_XMLNmsp = "http://schemas.microsoft.com/wbem/wsman/1/config/service/auth";
			this.Registry_Path_Credentials_Delegation = "SOFTWARE\\Policies\\Microsoft\\Windows";
			this.Key_Allow_Fresh_Credentials = "AllowFreshCredentials";
			this.Key_Concatenate_Defaults_AllowFresh = "ConcatenateDefaults_AllowFresh";
			this.Delegate = "delegate";
			this.keyAllowcredssp = "AllowCredSSP";
			this.ALIAS_WQL = "wql";
			this.ALIAS_ASSOCIATION = "association";
			this.ALIAS_SELECTOR = "selector";
			this.URI_WQL_DIALECT = "http://schemas.microsoft.com/wbem/wsman/1/WQL";
			this.URI_SELECTOR_DIALECT = "http://schemas.dmtf.org/wbem/wsman/1/wsman/SelectorFilter";
			this.URI_ASSOCIATION_DIALECT = " http://schemas.dmtf.org/wbem/wsman/1/cimbinding/associationFilter";
			this._provider = provider;
            this._resourceMgr = new ResourceManager("Microsoft.WSMan.Management.WsManResources", Assembly.GetExecutingAssembly());
		}
Example #4
0
 internal WSManHelper(NavigationCmdletProvider provider)
 {
     _provider = provider;
 }
        internal string ContractRelativePath(
            string path,
            string basePath,
            bool allowNonExistingPaths,
            CmdletProviderContext context)
        {
            this.Context = context;
            switch (path)
            {
            case "":
                return(string.Empty);

            case null:
                throw CmdletProvider.providerBaseTracer.NewArgumentNullException(nameof(path));

            default:
                if (basePath == null)
                {
                    basePath = string.Empty;
                }
                CmdletProvider.providerBaseTracer.WriteLine("basePath = {0}", (object)basePath);
                bool   flag = false;
                string str1 = path;
                string str2 = basePath;
                if (!string.Equals(context.ProviderInstance.ProviderInfo.FullName, "ActiveDirectory", StringComparison.OrdinalIgnoreCase))
                {
                    str1 = path.Replace('/', '\\');
                    str2 = basePath.Replace('/', '\\');
                }
                string str3 = path;
                if (path.EndsWith('\\'.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    path = path.TrimEnd('\\');
                    flag = true;
                }
                basePath = basePath.TrimEnd('\\');
                string str4;
                if (string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase) && !str3.EndsWith(string.Concat((object)'\\'), StringComparison.OrdinalIgnoreCase))
                {
                    str4 = this.MakePath("..", this.GetChildName(path));
                }
                else if (!str1.StartsWith(str2, StringComparison.OrdinalIgnoreCase) && basePath.Length > 0)
                {
                    str4 = string.Empty;
                    string commonBase = this.GetCommonBase(str1, str2);
                    int    count      = this.TokenizePathToStack(str2, commonBase).Count;
                    if (string.IsNullOrEmpty(commonBase))
                    {
                        --count;
                    }
                    for (int index = 0; index < count; ++index)
                    {
                        str4 = this.MakePath("..", str4);
                    }
                    if (!string.IsNullOrEmpty(commonBase))
                    {
                        if (string.Equals(str1, commonBase, StringComparison.OrdinalIgnoreCase) && !str1.EndsWith(string.Concat((object)'\\'), StringComparison.OrdinalIgnoreCase))
                        {
                            string childName = this.GetChildName(path);
                            str4 = this.MakePath(this.MakePath("..", str4), childName);
                        }
                        else
                        {
                            foreach (string child in this.TokenizePathToStack(str1, commonBase).ToArray())
                            {
                                str4 = this.MakePath(str4, child);
                            }
                        }
                    }
                }
                else
                {
                    Stack <string> stack       = this.TokenizePathToStack(path, basePath);
                    Stack <string> stringStack = new Stack <string>();
                    Stack <string> normalizedPathStack;
                    try
                    {
                        normalizedPathStack = NavigationCmdletProvider.NormalizeThePath(stack, path, basePath, allowNonExistingPaths);
                    }
                    catch (ArgumentException ex)
                    {
                        this.WriteError(new ErrorRecord((Exception)ex, ex.GetType().FullName, ErrorCategory.InvalidArgument, (object)null));
                        str4 = (string)null;
                        goto label_27;
                    }
                    str4 = this.CreateNormalizedRelativePathFromStack(normalizedPathStack);
                }
label_27:
                if (flag)
                {
                    str4 += (string)(object)'\\';
                }
                CmdletProvider.providerBaseTracer.WriteLine("result = {0}", (object)str4);
                return(str4);
            }
        }