singrdk/base/Applications/utilities/getacl/getacl.sg

88 lines
2.6 KiB
Plaintext

///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: getacl.sg
//
// Note:
//
using FileSystem.Utils;
using System;
using System.Text;
using System.Threading;
using Microsoft.Singularity;
using Microsoft.Singularity.Directory;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.FileSystem;
using Microsoft.Singularity.V1.Services;
using Microsoft.Singularity.Security.SDS;
using Microsoft.Contracts;
using Microsoft.SingSharp.Reflection;
using Microsoft.Singularity.Applications;
using Microsoft.Singularity.Io;
using Microsoft.Singularity.Configuration;
[assembly: Transform(typeof(ApplicationResourceTransform))]
namespace Microsoft.Singularity.Applications
{
[ConsoleCategory(HelpMessage="Examine an acl", DefaultAction=true)]
internal class Parameters
{
[InputEndpoint("data")]
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
[OutputEndpoint("data")]
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
[Endpoint]
public readonly TRef<DirectoryServiceContract.Imp:Start> nsRef;
[StringParameter( "PathName", Mandatory=true, Position=0, HelpMessage="PathName argument.")]
internal string pathName;
reflective internal Parameters();
internal int AppMain() {
return FsGetAcl.AppMain(this);
}
}
public class FsGetAcl
{
internal static int AppMain(Parameters! config)
{
DirectoryServiceContract.Imp ds = ((!)config.nsRef).Acquire();
if (ds == null) {
throw new Exception("Unable to acquire handle to the Directory Service root");
}
ds.RecvSuccess();
ErrorCode errorOut;
Acl acl;
bool ok = SdsUtilsAcl.QueryACL((!)config.pathName, false, ds, out acl, out errorOut);
if (ok) {
if (acl.Node == null)
Console.WriteLine("(null)");
else
Console.WriteLine(acl.Node);
if (acl.Descendant == null)
Console.WriteLine("(null)");
else
Console.WriteLine(acl.Descendant);
}
else Console.WriteLine("getacl failed. reason({0})",SdsUtils.ErrorCodeToString(errorOut));
delete ds;
return ok ? 0 : 1;
}
} // class Test
}