9 tVFS_ACL gVFS_ACL_EveryoneRWX = { {1,-1}, {0,VFS_PERM_ALL} };
10 tVFS_ACL gVFS_ACL_EveryoneRW = { {1,-1}, {0,VFS_PERM_ALL^VFS_PERM_EXECUTE} };
11 tVFS_ACL gVFS_ACL_EveryoneRX = { {1,-1}, {0,VFS_PERM_READ|VFS_PERM_EXECUTE} };
12 tVFS_ACL gVFS_ACL_EveryoneRO = { {1,-1}, {0,VFS_PERM_READ} };
16 * \fn int VFS_CheckACL(tVFS_Node *Node, Uint Permissions)
17 * \brief Checks the permissions on a file
19 int VFS_CheckACL(tVFS_Node *Node, Uint Permissions)
22 int uid = Threads_GetUID();
23 int gid = Threads_GetGID();
25 // Root can do anything
26 if(uid == 0) return 1;
28 // Root only file?, fast return
29 if( Node->NumACLs == 0 ) return 0;
31 // Check Deny Permissions
32 for(i=0;i<Node->NumACLs;i++)
34 if(!Node->ACLs[i].Inv) continue; // Ignore ALLOWs
35 if(Node->ACLs[i].ID != -1)
37 if(!Node->ACLs[i].Group && Node->ACLs[i].ID != uid) continue;
38 if(Node->ACLs[i].Group && Node->ACLs[i].ID != gid) continue;
41 if(Node->ACLs[i].Perms & Permissions) return 0;
44 // Check for allow permissions
45 for(i=0;i<Node->NumACLs;i++)
47 if(Node->ACLs[i].Inv) continue; // Ignore DENYs
48 if(Node->ACLs[i].ID != -1)
50 if(!Node->ACLs[i].Group && Node->ACLs[i].ID != uid) continue;
51 if(Node->ACLs[i].Group && Node->ACLs[i].ID != gid) continue;
54 if((Node->ACLs[i].Perms & Permissions) == Permissions) return 1;
60 * \fn int VFS_GetACL(int FD, tVFS_ACL *Dest)
62 int VFS_GetACL(int FD, tVFS_ACL *Dest)
65 tVFS_Handle *h = VFS_GetHandle(FD);
72 // Root can do anything
73 if(Dest->Group == 0 && Dest->ID == 0) {
79 // Root only file?, fast return
80 if( h->Node->NumACLs == 0 ) {
86 // Check Deny Permissions
87 for(i=0;i<h->Node->NumACLs;i++)
89 if(h->Node->ACLs[i].Group != Dest->Group) continue;
90 if(h->Node->ACLs[i].ID != Dest->ID) continue;
92 Dest->Inv = h->Node->ACLs[i].Inv;
93 Dest->Perms = h->Node->ACLs[i].Perms;
104 * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
105 * \brief Converts UNIX permissions to three Acess ACL entries
107 tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
109 tVFS_ACL *ret = malloc(sizeof(tVFS_ACL)*3);
112 if(!ret) return NULL;
115 ret[0].Group = 0; ret[0].ID = Owner;
116 ret[0].Inv = 0; ret[0].Perms = 0;
117 if(Mode & 0400) ret[0].Perms |= VFS_PERM_READ;
118 if(Mode & 0200) ret[0].Perms |= VFS_PERM_WRITE;
119 if(Mode & 0100) ret[0].Perms |= VFS_PERM_EXECUTE;
122 ret[1].Group = 1; ret[1].ID = Group;
123 ret[1].Inv = 0; ret[1].Perms = 0;
124 if(Mode & 0040) ret[1].Perms |= VFS_PERM_READ;
125 if(Mode & 0020) ret[1].Perms |= VFS_PERM_WRITE;
126 if(Mode & 0010) ret[1].Perms |= VFS_PERM_EXECUTE;
129 ret[2].Group = 1; ret[2].ID = Group;
130 ret[2].Inv = 0; ret[2].Perms = 0;
131 if(Mode & 0004) ret[2].Perms |= VFS_PERM_READ;
132 if(Mode & 0002) ret[2].Perms |= VFS_PERM_WRITE;
133 if(Mode & 0001) ret[2].Perms |= VFS_PERM_EXECUTE;
141 EXPORTV(gVFS_ACL_EveryoneRWX);
142 EXPORTV(gVFS_ACL_EveryoneRW);
143 EXPORTV(gVFS_ACL_EveryoneRX);
145 EXPORT(VFS_UnixToAcessACL);