newentry->allowed = 0;
newentry->denied = 0;
newentry->next = NULL;
-
+
return newentry;
}
{
GRSTgaclCred *cred;
GRSTgaclPerm i;
-
+
fputs("<entry>\n", fp);
for (cred = entry->firstcred; cred != NULL; cred = cred->next)
if (xmlStrcmp(cur->name, (const xmlChar *) "entry") != 0) return NULL;
cur = cur->xmlChildrenNode;
-
+
entry = GRSTgaclEntryNew();
while (cur != NULL)
xmlDocPtr doc;
xmlNodePtr cur;
GRSTgaclAcl *acl;
- GRSTgaclEntry *entry;
-
+
doc = xmlParseFile(filename);
if (doc == NULL) return NULL;
-
+
cur = xmlDocGetRootElement(doc);
-
- if (xmlStrcmp(cur->name, (const xmlChar *) "gacl"))
+ if (cur == NULL) return NULL;
+
+ if (!xmlStrcmp(cur->name, (const xmlChar *) "Policy")) { acl=GRSTxacmlAclParse(doc, cur, acl);}
+ else if (!xmlStrcmp(cur->name, (const xmlChar *) "gacl")) {acl=GRSTgaclAclParse(doc, cur, acl);}
+ else /* ACL format not recognised */
{
free(doc);
free(cur);
return NULL;
}
+
+ xmlFreeDoc(doc);
+ return acl;
+}
+
+GRSTgaclAcl *GRSTgaclAclParse(xmlDocPtr doc, xmlNodePtr cur, GRSTgaclAcl *acl)
+{
+ GRSTgaclEntry *entry;
+
cur = cur->xmlChildrenNode;
acl = GRSTgaclAclNew();
-
+
while (cur != NULL)
{
entry = GRSTgaclEntryParse(cur);
}
GRSTgaclAclAddEntry(acl, entry);
-
+
cur=cur->next;
}
- xmlFreeDoc(doc);
return acl;
}
-
int GRSTgaclFileIsAcl(char *pathandfile)
-/* Return 1 if filename in *pathandfile starts GRST_ACL_FILE
+/* Return 1 if filename in *pathandfile starts GRST_ACL_FILE
Return 0 otherwise. */
-{
+{
char *filename;
-
+
filename = rindex(pathandfile, '/');
if (filename == NULL) filename = pathandfile;
else filename++;
-
+
return (strncmp(filename, GRST_ACL_FILE, sizeof(GRST_ACL_FILE) - 1) == 0);
}
int len;
char *path, *file, *p;
struct stat statbuf;
-
+
len = strlen(pathandfile);
if (len == 0) return NULL;
path = malloc(len + sizeof(GRST_ACL_FILE) + 2);
strcpy(path, pathandfile);
- if ((stat(path, &statbuf) == 0) &&
+ if ((stat(path, &statbuf) == 0) &&
S_ISDIR(statbuf.st_mode) &&
(path[len-1] != '/'))
{
GRSTgaclAcl *GRSTxacmlAclLoadFile(char *filename)
{
- xmlDocPtr doc;
+xmlDocPtr doc;
xmlNodePtr cur;
GRSTgaclAcl *acl;
- GRSTgaclEntry *entry;
-#ifdef XACML_DEBUG
- debugfile=fopen(XACML_DEBUG_FILE, "w");
- fprintf (debugfile, "Loading acl..\n");
-#endif
+
doc = xmlParseFile(filename);
if (doc == NULL) return NULL;
cur = xmlDocGetRootElement(doc);
if (cur == NULL) return NULL;
-
- if (xmlStrcmp(cur->name, (const xmlChar *) "Policy"))
+
+ if (!xmlStrcmp(cur->name, (const xmlChar *) "Policy")) { acl=GRSTxacmlAclParse(doc, cur, acl);}
+ else if (!xmlStrcmp(cur->name, (const xmlChar *) "gacl")) {acl=GRSTgaclAclParse(doc, cur, acl);}
+ else /* ACL format not recognised */
{
free(doc);
free(cur);
return NULL;
}
-#ifdef XACML_DEBUG
- fprintf (debugfile, "Error Checks done, load acl\n");
-#endif
+
+ xmlFreeDoc(doc);
+ return acl;
+}
+
+GRSTgaclAcl *GRSTxacmlAclParse(xmlDocPtr doc, xmlNodePtr cur, GRSTgaclAcl *acl){
+
+ GRSTgaclEntry *entry;
+
+ #ifdef XACML_DEBUG
+ debugfile=fopen(XACML_DEBUG_FILE, "w");
+ fprintf (debugfile, "ACL loaded..\n");
+ fprintf (debugfile, "Parsing XACML\n");
+ #endif
+
// Have an XACML policy file.
// Skip <Target> tag and set cur to first <Rule> tag
cur = cur->xmlChildrenNode->next;
while (cur != NULL){
-
- if ( xmlStrcmp(cur->name, (const xmlChar *)"Rule") == 0 ){ // IF statement not needed?
-#ifdef XACML_DEBUG
+ if ( !xmlStrcmp(cur->name, (const xmlChar *)"Rule") )
+ { // IF statement not needed?
+ #ifdef XACML_DEBUG
fprintf (debugfile, "Rule %s found\n", xmlNodeGetContent(cur->properties->children) );
fprintf (debugfile, "Parsing Entry for this rule\n");
-#endif
+ #endif
entry = GRSTxacmlEntryParse(cur);
- if (entry == NULL){
+ if (entry == NULL)
+ {
GRSTgaclAclFree(acl);
xmlFreeDoc(doc);
return NULL;
}
else GRSTgaclAclAddEntry(acl, entry);
-#ifdef XACML_DEBUG
+
+ #ifdef XACML_DEBUG
fprintf (debugfile, "Entry read in\n\n");
-#endif
+ #endif
}
+
// If the current and next Rules are part of the same entry then advance two Rules
// If not then advance 1
if (cur->next != NULL)
+ {
if ( strncmp(xmlNodeGetContent(cur->properties->children), // RuleId of this Rule
xmlNodeGetContent(cur->next->properties->children), // RuleId of next Rule
- 6) == 0) {
-#ifdef XACML_DEBUG
- fprintf (debugfile, "skipping next rule %s, should have been caught previously\n\n", xmlNodeGetContent(cur->next->properties->children) );
-#endif
- cur=cur->next;
- } // Check first 6 characters i.e. Entry1**/
+ 6) == 0)
+ {
+ #ifdef XACML_DEBUG
+ fprintf (debugfile, "skipping next rule %s, should have been caught previously\n\n", xmlNodeGetContent(cur->next->properties->children) );
+ #endif
+ cur=cur->next;
+ } // Check first 6 characters i.e. Entry1**/
+ }
+
cur=cur->next;
}
-#ifdef XACML_DEBUG
+
+ #ifdef XACML_DEBUG
fprintf (debugfile, "Finished loading ACL - Fanfare!\n");
fclose(debugfile);
-#endif
- xmlFreeDoc(doc);
+ #endif
+
return acl;
}
+
int GRSTxacmlFileIsAcl(char *pathandfile)
/* Return 1 if filename in *pathandfile starts GRST_ACL_FILE
Return 0 otherwise. */