环境和权限 [英] Environment and Permissions

查看:61
本文介绍了环境和权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在类上有一个简单的包装器静态测试方法,用于扩展指定字符串上的

环境变量:


公共静态字符串ExpandEnvironmentStr(string Str)

{

返回Environment.ExpandEnvironmentVariables(Str);

}


出于某些明显的安全相关原因,它崩溃了以下

例外:


An发生了'System.Security.SecurityException'类型未处理的异常
mscorlib.dll中的



其他信息:请求获得类型

System.Security.Permissions.EnvironmentPermission,mscorlib,

Version = 1.0.5000.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 failed。

作为安全新手我只是不能从MS doc'中找出这个

的含义以及如何使用EnvironmentPermission来修复它。该博士的唯一

完全迷惑了我。我需要做的就是能够从

环境类中读取内容(扩展变量和检索特殊文件夹,

等)。所有的MS doc'的例子都说这样的话......这根本不会对我有所帮助。我需要知道如何保证它的安全。


//< - 保证这些信息的安全! - >


我是否需要在AssemlyInfo.cs

文件中使用某种程序集权限属性或此方法的某种属性?如果是这样,什么?可以有人

请向我解释一下并给我举例说明吗?我很困惑。


非常感谢提前,


-

John Bowman
Verona,WI
18*******@charter.net

Hi All,

I''ve got a simple wrapper static test method on a class to expand the
environment variables on a specified string:

public static string ExpandEnvironmentStr(string Str)
{
return Environment.ExpandEnvironmentVariables(Str);
}

For some apparently security related reason it crashes with the following
exception:

An unhandled exception of type ''System.Security.SecurityException'' occurred
in mscorlib.dll

Additional information: Request for the permission of type
System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
Being a security newbe I just can''t figure out from the MS doc''s what this
means and how to use the EnvironmentPermission to fix it. The doc''s only
confused me completely. All I need to do is be able to read stuff from the
Environment class (expanding variables and retreiving special folders,
etc.). All the MS doc''s examples say something like this... which doesn''t
help me at all. I need to know HOW to keep it secure.

// <-- Keep this information secure! -->

Do I need some kind of assembly permission attribute in the AssemlyInfo.cs
file or some kind of attribute on this method? If so, what? Can someone
please explain this to me and give me working example? I''m baffled.

Many thanks in advance,

--
John Bowman
Verona, WI
18*******@charter.net

推荐答案

" John Bowman" < JM ****** @ charter.net>写在消息

新闻:uP ************** @ TK2MSFTNGP09.phx.gbl ...
"John Bowman" <jm******@charter.net> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
大家好,环境变量:

公共静态字符串ExpandEnvironmentStr(string Str)
{
返回Environment.ExpandEnvironmentVariables(Str);
}
对于一些明显与安全相关的原因,它会因以下
异常崩溃:

mscorlib.dll中出现未处理的System.Security.SecurityException类型的异常

附加信息:请求获得类型
类型的权限.Security.Permissions.EnvironmentPermission,mscorlib,
Version = 1.0.5000.0,Culture = neutral,PublicKeyToken = b77a5c561934e089
失败。

作为一名安全新手,我就是不能从MS doc中了解这是什么意思以及如何使用EnvironmentPermission来修复i吨。医生只是完全迷惑了我。我需要做的就是能够从
Environment类中读取内容(扩展变量和检索特殊文件夹,
等)。所有MS doc的例子都说这样......这对我没有任何帮助。我需要知道如何保证它的安全。

//< - 保证这些信息的安全! - >

我是否需要在AssemlyInfo.cs
文件中使用某种程序集权限属性或此方法的某种属性?如果是这样,什么?有人可以向我解释一下并告诉我工作实例吗?我很困惑。

非常感谢,

-
John Bowman
Verona,WI
18 ******* @ charter.net




假设您从文件共享/ Intranet站点运行,代码访问

安全(CAS)设置只允许您读取USERNAME环境

变量而不是其他任何内容。如果你在本地复制程序,你应该是

能够让程序正常执行。这是因为非本地代码是

,权限少于本地代码。


但是,假设您实际上需要能够从非本地代码运行本地

机器你需要以某种方式调整CAS策略,以便为这个站点或程序集提供额外的权限

。有几种方法可以做到这一点。


CAS根据执行代码的信息分配权限

(就像它在哪里来源一样)正在运行或由谁创作它)

此信息称为证据。


机器上的CAS策略对此证据执行测试并指定

基于代码传递的权限组(称为权限集)

此测试。证据测试到permissoin集的映射称为

代码组。您可以在运行时安全策略

部分的.NET

配置实用程序(mscorcfg.msc)中查看所有此策略配置。


基本配置主要基于IE Zone(LocalMachine,

需要在Local Intranet代码组下添加代码组。根据网站,URL或stong名称或您的程序集测试

证据,并将其映射到

一个权限集,该权限集将授予您的代码所需的权限。您可以

创建一个自定义访问环境块的自定义访问权限

但您现在可以将其设置为FullTrust。一个自定义的更好,因为它

意味着你的代码只能访问它需要做的事情(

最小特权的原则)。

问候


Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk



Assuming you are running from a file share / Intranet site, the Code Access
Security (CAS) settings only allow you to read the USERNAME environment
variable and nothing else. If you copy the program locally you should be
able to have the program execute normally. This is because non-local code is
given fewer permissions than local code.

However, assuming you actually need to be able to run from the non-local
machine you need to adjust CAS policy in some way to give extra permissions
to this site or assembly. There are a couple of ways to do this.

CAS assigns permissions based on the information about the executing code
(like its origin in terms of where it is running from or who authored it)
this information is called Evidence.

The CAS policy on a machine performs tests on this evidence and assigns
groups of permissions (called Permission Sets) based on the code passing
this test. The mapping of a test of evidence to a permissoin set is called a
code group. You can see all of this policy configuration in the .NET
configuration utility (mscorcfg.msc) under the Runtime Security Policy
section.

The basic configuration is principally based on IE Zone (LocalMachine,
Intranet, Internet, etc). Your code is executing from the Intranet to you
need to add a code group under the Local Intranet codegroup. Make a test of
evidence based on the site, URL or stong name or your assembly and map it to
a permission set that will grant your code the rights it needs. You could
create a custom one that grants unrestricted access to the environment block
but you could set it to FullTrust for now. A custom one is better as it
means your code only has access to the things it needs to do (principle of
least privilege).

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk


理查德,


谢谢对于解释,这是我学习曲线的一个开始。但是我已经和这个程序的互联网没什么关系了。它只能在本地安装和执行
。这甚至目前正在开发

系统,我为了测试/调试而获得了Admin权限。

此外,当我使用评估程序集时;在.NET 1.1

配置工具下,它声称我的程序集得到Unrestricted权限。

所以我仍然不知道如何正确编码。我之前使用了

Environment.GetFolderaPath()和Environment.NewLine等,而且从来没有

有问题。


还有什么帮助?


John


" Richard Blewett [DevelopMentor]" < richard at nospam dotnetconsult dot co <​​br />
dot uk>在消息新闻中写道:eu ************* @ TK2MSFTNGP09.phx.gbl ...
Richard,

Thanks for the explanations, it is a start in my learning curve. But I''ve
got nothing to do with the Internet for this program. It will ONLY be
installed and executed locally. This is even currently on a development
system where I''ve got Admin priviledges for the sake of testing/debugging.
Furthermore, when I use the "Evaluate Assembly" tool under the .NET 1.1
Configuration tool, it claims my assembly gets "Unrestricted" permissions.
So I still don''t have a clue as to how to properly code this. I''ve used
Environment.GetFolderaPath() and Environment.NewLine, etc. before and never
had a problem.

Any more help?

John

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:eu*************@TK2MSFTNGP09.phx.gbl...
" John Bowman" < JM ****** @ charter.net>在消息中写道
新闻:uP ************** @ TK2MSFTNGP09.phx.gbl ...
"John Bowman" <jm******@charter.net> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
大家好,
环境变量:

public static string ExpandEnvironmentStr(string Str)
{
返回Environment.ExpandEnvironmentVariables(Str);
}
对于一些明显与安全相关的原因,它崩溃时出现以下
异常:
mscorlib.dll中出现未处理的类型''System.Security.SecurityException''


附加信息:请求获得类型的权限
System.Security.Permissions .EnvironmentPermission,mscorlib,
Version = 1.0.5000.0,Culture = neutral,PublicKeyToken = b77a5c561934e089
失败。

作为一名安全新手,我无法从中找到答案MS doc'这意味着什么,以及如何使用EnvironmentPermission来修复它。医生们只是完全迷惑了我。我需要做的就是能够从Environment类中读取内容(扩展变量和检索特殊的文件夹等)。所有MS doc的例子都说这样......
对我来说根本没有帮助。我需要知道如何保证它的安全。

//< - 保证这些信息的安全! - >

我是否需要在AssemlyInfo.cs文件中使用某种程序集权限属性或此方法的某种属性?如果是这样,
什么?有人可以向我解释一下并告诉我工作实例吗?
我很困惑。

非常感谢提前,

-
John Bowman
Verona,WI
18*******@charter.net
Hi All,

I''ve got a simple wrapper static test method on a class to expand the
environment variables on a specified string:

public static string ExpandEnvironmentStr(string Str)
{
return Environment.ExpandEnvironmentVariables(Str);
}

For some apparently security related reason it crashes with the following
exception:

An unhandled exception of type ''System.Security.SecurityException''
occurred in mscorlib.dll

Additional information: Request for the permission of type
System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.
Being a security newbe I just can''t figure out from the MS doc''s what
this means and how to use the EnvironmentPermission to fix it. The doc''s
only confused me completely. All I need to do is be able to read stuff
from the Environment class (expanding variables and retreiving special
folders, etc.). All the MS doc''s examples say something like this...
which doesn''t help me at all. I need to know HOW to keep it secure.

// <-- Keep this information secure! -->

Do I need some kind of assembly permission attribute in the
AssemlyInfo.cs file or some kind of attribute on this method? If so,
what? Can someone please explain this to me and give me working example?
I''m baffled.

Many thanks in advance,

--
John Bowman
Verona, WI
18*******@charter.net



假设您从文件共享/ Intranet站点运行,代码访问安全性(CAS)设置只允许您阅读USERNAME
环境变量和没有其他的。如果您在本地复制程序,则
应该能够使程序正常执行。这是因为非本地代码的权限少于本地代码。

但是,假设您确实需要能够从非本地机器运行,那么您需要以某种方式调整CAS策略以为此站点或程序集提供额外的
权限。有几种方法可以做到这一点。

CAS根据有关执行代码的信息分配权限
(就其运行位置或其来源而言)谁创作了它?
这些信息称为证据。

机器上的CAS策略对此证据进行测试并根据以下内容分配权限组(称为权限集)。代码传递
这个测试。证据测试到permissoin集的映射称为代码组。您可以在运行时安全策略部分的.NET
配置实用程序(mscorcfg.msc)中查看所有此策略配置。

基本配置主要基于IE区域(LocalMachine,
Intranet,Internet等)。您的代码正在从Intranet执行到您需要在Local Intranet代码组下添加代码组。根据网站,URL或stong名称或您的程序集进行测试,并将其映射到权限集,该权限集将授予您的代码所需的权限。您可以创建一个自定义访问
环境块的自定义访问权限,但您现在可以将其设置为FullTrust。自定义的
更好,因为它意味着您的代码只能访问它所需要的东西(最小特权原则)。

问候

http://www.dotnetconsult.co。英国/博客
http://www.dotnetconsult.co.uk



" John Bowman" < JM ****** @ charter.net>在消息中写道

新闻:OZ ************** @ TK2MSFTNGP09.phx.gbl ...
"John Bowman" <jm******@charter.net> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Richard,
感谢您的解释,这是我学习曲线的一个开始。但是我和这个程序的互联网没什么关系。它只能在本地安装和执行。这甚至是目前在一个开发系统中,我为了测试/调试而获得了管理员权限。
此外,当我使用评估程序集时在.NET 1.1
配置工具下,它声称我的程序集得到Unrestricted权限。
所以我仍然不知道如何正确编码。我之前使用了
Environment.GetFolderaPath()和Environment.NewLine等,而且从未遇到过问题。

还有什么帮助?

John
Richard,

Thanks for the explanations, it is a start in my learning curve. But I''ve
got nothing to do with the Internet for this program. It will ONLY be
installed and executed locally. This is even currently on a development
system where I''ve got Admin priviledges for the sake of testing/debugging.
Furthermore, when I use the "Evaluate Assembly" tool under the .NET 1.1
Configuration tool, it claims my assembly gets "Unrestricted" permissions.
So I still don''t have a clue as to how to properly code this. I''ve used
Environment.GetFolderaPath() and Environment.NewLine, etc. before and
never had a problem.

Any more help?

John




嗯 - 所以评估装配工具说你有全信心吗?那么它应该是
工作。


创建一个控制台应用程序,其中包含以下代码,并确保

正确执行,然后将它复制到你正在尝试的应用程序的相同位置

运行并在那里试用


使用系统;


class program

{

static void Main(string [] args)

{

Console .WriteLine(Environment.ExpandEnvironmentVar iables("%windir%"));

}

}


问候


Richard Blewett - DevelopMentor
http ://www.dotnetconsult.co.uk/weblog
http: //www.dotnetconsult.co.uk


这篇关于环境和权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆