////////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: Node.sg
//
// Note:
//
using System;
using System.Text;
using System.Collections;
using System.Threading;
using Microsoft.SingSharp;
using Microsoft.Singularity;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.Directory;
using Microsoft.Singularity.Security;
#if !SINGULARITY_PROCESS
namespace Microsoft.Singularity.Directory
#else
using Microsoft.Singularity;
using Microsoft.Singularity.V1.Services;
namespace Microsoft.Application.DSP
#endif
{
public abstract class Node
{
// base class for all node types in name space
private string nodeName;
///
/// The policy object controlling the access to this node
///
private AclCore! core;
private IAclPolicy! policy;
///
/// ACLs here are not persistent.
///
private Acl acl = Acl.nullAcl;
private IAclRule rule = null;
private readonly NodeType nodeType;
protected Node(NodeType nodeType, string! name, AclCore! core, IAclPolicy! policy)
{
this.nodeType = nodeType;
this.nodeName = name;
this.core = core;
this.policy = policy;
}
protected Node(NodeType nodeType, string! name, Node! parent)
{
this.nodeType = nodeType;
this.nodeName = parent.nodeName + "/" + name;
this.core = parent.core;
this.policy = parent.policy;
}
private Acl GetObjectAcl()
{
lock (this) {
if (acl.val != null) {
if (rule == null || rule.Valid)
return acl;
}
acl = policy.LookupAndExpand(nodeName, out rule);
return acl;
}
}
public bool CheckAccess(AccessMode! permission, Principal pr)
{
Acl acl = GetObjectAcl();
return core.CheckAccess(acl, permission, pr);
}
public bool CheckAccess(AccessMode! permission, Principal pr, Endpoint*! in ExHeap ep)
{
Acl acl = GetObjectAcl();
if (!core.CheckAccess(acl, permission, pr))
return false;
Principal pr2 = AclCore.EndpointPeer(ep);
if (pr.Equal(pr2))
return true;
return core.CheckAccess(acl, permission, AclCore.EndpointPeer(ep));
}
public Acl GetInstanceAcl()
{
lock (this) {
if (rule == null)
return acl;
}
return Acl.nullAcl;
}
public void SetInstanceAcl(Acl acl)
{
lock (this) {
this.acl = acl;
this.rule = null;
}
}
public string! FullName { get { return nodeName; } }
///
/// null on success, the service argument if it failed.
///
public abstract ServiceContract.Exp Bind(StringBuilder! p,
Principal pr,
out bool success,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link,
[Claims]
ServiceContract.Exp! service);
/// CreateAndBindFile
///
/// true if success false if it fails.
///
public abstract FileContract.Imp CreateAndBindFile(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// CreateDirectory
///
/// true if success false if it fails.
///
public abstract bool CreateDirectory(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// CreateFile
///
/// true if success false if it fails.
///
public abstract bool CreateFile(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// CreateFile
///
/// true if success false if it fails.
///
public abstract bool CreateLink(StringBuilder! p,
Principal pr,
string! value,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// DeleteDirectory
///
/// true if success false if it fails.
///
public abstract bool DeleteDirectory(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// DeleteFileusing Microsoft.SingSharp;
///
/// true if success false if it fails.
///
public abstract bool DeleteFile(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// DeleteLink
///
/// true if success false if it fails.
///
public abstract bool DeleteLink(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// GetLinkValue
///
/// true if success false if it fails.
///
public abstract bool GetLinkValue(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
///
/// The endpoint on success, null, if it fails.
///
public abstract ServiceProviderContract.Imp:Start Deregister(StringBuilder! path,
Principal pr,
DirectoryServiceContract.Exp! ep,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
///
/// true if success false if it fails.
///
public abstract bool GetAttributes(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link,
out long length,
out NodeType nodeType
);
///
/// null on success, the imp argument if it failed.
///
public abstract NotifyContract.Imp Notify(StringBuilder! pathSpec,
Principal pr,
string! pattern,
bool sendExisting,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link,
[Claims] NotifyContract.Imp! notifyImp);
/// QueryACL
///
/// true if success false if it fails.
///
public abstract bool QueryACL(StringBuilder! p,
Principal pr,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link,
out Acl acl
);
/// Register
///
/// true if success false if it fails.
///
public abstract ServiceProviderContract.Imp Register(StringBuilder! p,
Principal pr,
[Claims]ServiceProviderContract.Imp! sp,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
/// StoreACL
///
/// true if success false if it fails.
///
public abstract bool StoreACL(StringBuilder! p,
Principal pr,
Acl acl,
out bool linkFound,
out ErrorCode error,
out bool reparse,
out string link
);
public NodeType Type
{
get
{
return this.nodeType;
}
}
}
}