[Mono-list] Changing owner, group and permissions

Jonathan Pryor jonpryor at vt.edu
Tue Apr 13 00:15:19 EDT 2010


On Tue, 2010-04-13 at 15:53 +1200, Srdan Dukic wrote:
> I have a mono program (runs as root) which (as a part of its
> functionality) goes and creates a directory. This directory should
> have a non-root owner, a non-root group and I would like to specify
> what permissions are on the directory. 
>
> From my understanding of the documentation, there are two ways of
> doing this: System.IO.Directory.Create(DirectorySecurity) method and
> Mono.Unix.UnixDirectoryInfo.Create(FileAccessPermissions).

As per the source [0], Directory.Create() doesn't do anything.  Other
methods which accept a DirectorySecurity argument (like
Directory.SetAccessControl()) throw NotImplementedException.

In short, I don't think that'll work. :-)

Which leaves UnixDirectoryInfo.Create(FileAccessPermissions) for
creation.

Setting owner and group can be handled via
UnixFileSystemInfo.SetOwner()[1].

Setting permissions on the directory can be done via
UnixFileSystemInfo.FileAccessPermissions [2] or
UnixFileSystemInfo.Protection [3].

 - Jon

[0]
http://anonsvn.mono-project.com/source/trunk/mcs/class/corlib/System.IO/Directory.cs
[1]
http://www.go-mono.com/docs/index.aspx?link=M:Mono.Unix.UnixFileSystemInfo.SetOwner
[2]
http://www.go-mono.com/docs/index.aspx?link=P:Mono.Unix.UnixFileSystemInfo.FileAccessPermissions
[3]
http://www.go-mono.com/docs/index.aspx?link=P:Mono.Unix.UnixFileSystemInfo.Protection




More information about the Mono-list mailing list