From 5f6dc6263803643a37c3398a5d4a5cc81aa83b21 Mon Sep 17 00:00:00 2001 From: Shiv Kaushal Date: Mon, 23 May 2005 13:01:26 +0000 Subject: [PATCH] gaclAclLoad and xacmlAclLoad now both the same --> they detect ACL type and call correct function - could use macro redefinition? --- org.gridsite.core/src/grst_gacl.c | 45 +++++++++++++--------- org.gridsite.core/src/grst_xacml.c | 73 +++++++++++++++++++++++------------- org.gridsite.core/src/xacmlexample.c | 4 +- 3 files changed, 75 insertions(+), 47 deletions(-) diff --git a/org.gridsite.core/src/grst_gacl.c b/org.gridsite.core/src/grst_gacl.c index 13b46c8..bec17c5 100644 --- a/org.gridsite.core/src/grst_gacl.c +++ b/org.gridsite.core/src/grst_gacl.c @@ -305,7 +305,7 @@ GRSTgaclEntry *GRSTgaclEntryNew(void) newentry->allowed = 0; newentry->denied = 0; newentry->next = NULL; - + return newentry; } @@ -376,7 +376,7 @@ int GRSTgaclEntryPrint(GRSTgaclEntry *entry, FILE *fp) { GRSTgaclCred *cred; GRSTgaclPerm i; - + fputs("\n", fp); for (cred = entry->firstcred; cred != NULL; cred = cred->next) @@ -589,7 +589,7 @@ static GRSTgaclEntry *GRSTgaclEntryParse(xmlNodePtr cur) if (xmlStrcmp(cur->name, (const xmlChar *) "entry") != 0) return NULL; cur = cur->xmlChildrenNode; - + entry = GRSTgaclEntryNew(); while (cur != NULL) @@ -636,24 +636,35 @@ GRSTgaclAcl *GRSTgaclAclLoadFile(char *filename) 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); @@ -665,24 +676,22 @@ GRSTgaclAcl *GRSTgaclAclLoadFile(char *filename) } 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); } @@ -694,14 +703,14 @@ char *GRSTgaclFileFindAclname(char *pathandfile) 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] != '/')) { diff --git a/org.gridsite.core/src/grst_xacml.c b/org.gridsite.core/src/grst_xacml.c index 6beff98..937c01a 100644 --- a/org.gridsite.core/src/grst_xacml.c +++ b/org.gridsite.core/src/grst_xacml.c @@ -229,29 +229,39 @@ static GRSTgaclEntry *GRSTxacmlEntryParse(xmlNodePtr cur) 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 tag and set cur to first tag cur = cur->xmlChildrenNode->next; @@ -260,46 +270,55 @@ GRSTgaclAcl *GRSTxacmlAclLoadFile(char *filename) 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. */ diff --git a/org.gridsite.core/src/xacmlexample.c b/org.gridsite.core/src/xacmlexample.c index 07baafa..fe86e8a 100644 --- a/org.gridsite.core/src/xacmlexample.c +++ b/org.gridsite.core/src/xacmlexample.c @@ -122,7 +122,7 @@ int main() GRSTgaclAclPrint(acl1, stdout); - GRSTxacmlAclSave(acl1, "example.gacl"); + GRSTgaclAclSave(acl1, "example.xacml"); puts("gridacl.out saved"); @@ -130,7 +130,7 @@ int main() /* load the ACL back off the disk, print and test it */ - acl2 = GRSTxacmlAclLoadFile("example.gacl"); + acl2 = GRSTxacmlAclLoadFile("example.xacml"); puts("gridacl.out loaded"); -- 1.8.2.3