//////////////////////////////////////////////////////////////////////////////// // // 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; using Microsoft.Singularity.Security.SDS; #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 ISdsAcl! aclT; /// /// ACLs here are not persistent. /// private IEffectiveAclRef aclRef = null; private readonly NodeType nodeType; protected Node(NodeType nodeType, string! name, AclCore! core, ISdsAcl! aclT) { this.nodeType = nodeType; this.nodeName = name; this.core = core; this.aclT = aclT; } protected Node(NodeType nodeType, string! name, Node! parent) { this.nodeType = nodeType; if (parent.nodeName[parent.nodeName.Length - 1] == '/') this.nodeName = parent.nodeName + name; else this.nodeName = parent.nodeName + "/" + name; this.core = parent.core; this.aclT = parent.aclT; } public string GetAclPattern() { // this depends on the atomicity of pointer writes string aclPattern; if (this.aclRef != null && this.aclRef.GetCached(out aclPattern)) return aclPattern; return aclT.GetEffective(nodeName, out this.aclRef); } public bool CheckAccess(AccessMode! permission, Principal pr) { string ap = GetAclPattern(); return core.CheckAccess(ap, permission, pr); } public bool CheckAccess(AccessMode! permission, Principal pr, Endpoint*! in ExHeap ep) { string ap = GetAclPattern(); if (!core.CheckAccess(ap, permission, pr)) return false; Principal pr2 = AclCore.EndpointPeer(ep); if (pr.Equal(pr2)) return true; return core.CheckAccess(ap, permission, AclCore.EndpointPeer(ep)); } public Acl GetInstanceAcl() { return aclT.Get(nodeName); } public void SetInstanceAcl(Acl acl) { aclT.Set(nodeName, acl); } public void ClearAcl() { aclT.Clear(nodeName); } public string! FullName { get { return nodeName; } } /// /// null on success, the service argument if it failed. /// public abstract ServiceContract.Exp Bind(StringBuilder! p, string! fullPath, Principal pr, int curpos, out int position, out bool success, out bool linkFound, out ErrorCode error, out bool reparse, out string link, out string linkPrefix, [Claims] ServiceContract.Exp! service); /// CreateAndBindFile /// /// true if success false if it fails. /// public abstract FileContract.Imp CreateAndBindFile(StringBuilder! p, Principal pr, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, out bool linkFound, out ErrorCode error, out bool reparse, out string link, ref FileAttributesRecord fileAttributes ); /// /// null on success, the imp argument if it failed. /// public abstract NotifyContract.Imp Notify(StringBuilder! pathSpec, Principal pr, string! pattern, bool sendExisting, int curpos, out int position, 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, bool effective, Principal pr, int curpos, out int position, 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, int curpos, out int position, 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, int curpos, out int position, out bool linkFound, out ErrorCode error, out bool reparse, out string link ); public NodeType Type { get { return this.nodeType; } } } }