From c31f585ae684a284b2f01e776ec71d8c70983c6e Mon Sep 17 00:00:00 2001
From: Andrew McNab
Attribute URIs must take the form scheme:path" + "
For example dn:/DC=com/DC=example/CN=name or " + "fqan:/voname/groupname or https://host.name/listname or dns:host.name.pattern or ip:ip.number.pattern\n
\n"); + admin_continue(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, &bp); + return; + } // Create the credential - cred=GRSTgaclCredNew(type); - if (strcmp(type, "person")==0) GRSTgaclCredAddValue(cred,"dn", value); - else if (strcmp(type, "dn-list")==0) GRSTgaclCredAddValue(cred, "url", value); - else if (strcmp(type, "voms")==0) GRSTgaclCredAddValue(cred, "fqan", value); - else if (strcmp(type, "dns")==0) GRSTgaclCredAddValue(cred, "hostname", value); - else if (strcmp(type, "any-user")==0) {} // namevalue not entered for any-user credential - else{ - GRSThttpError ("500 Invalid input - credential type not valid"); - return; - } + cred=GRSTgaclCredCreate(cred_auri_1, NULL); // Create and empty entry, add the credential and get permissions entry = GRSTgaclEntryNew(); @@ -297,8 +292,6 @@ void edit_entry_form(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help GRSTgaclAcl *acl; GRSTgaclEntry *entry; GRSTgaclCred *cred; - GRSTgaclNamevalue *namevalue; - // struct _GACLnamevalue *namevalue; GRSThttpBody bp; if (!GRSTgaclPermHasAdmin(perm)) GRSThttpError ("403 Forbidden"); @@ -327,13 +320,13 @@ void edit_entry_form(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help while (cred!=NULL){ // Start with the first namevalue in the credential - namevalue=cred->firstname; - GRSTgaclCredTableAdd(user, entry, cred, namevalue, cred_no, entry_no, admin, timestamp, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); + GRSTgaclCredTableAdd(user, entry, cred, cred_no, entry_no, admin, timestamp, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); // Change to next credential cred=cred->next; cred_no++; } GRSTgaclCredTableEnd (entry, entry_no, admin, timestamp, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); + GRSThttpPrintf (&bp, "\n", cred_no-1); EndForm(&bp); admin_continue(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, &bp); @@ -343,12 +336,11 @@ void edit_entry_form(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help void edit_entry(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_uri, char *dir_path, char *file, char *dir_uri, char *admin_file){ //Processes the information entered into the form from edit_entry_form() and updates the entry corresponding to entry_no*/ - int entry_no, cred_no, i; + int entry_no, cred_no, i, last_cred_no; GRSTgaclAcl *acl; GRSTgaclEntry *entry; GRSTgaclCred *cred; - GRSTgaclNamevalue *namevalue; - char variable[30]; + char variable[30], *cred_auri_i, *p; GRSThttpBody bp; if (!GRSTgaclPermHasAdmin(perm)) GRSThttpError ("403 Forbidden"); @@ -357,28 +349,62 @@ void edit_entry(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_uri, acl = GRSTgaclAclLoadFile(GRSTgaclFileFindAclname(dir_path)); // Get pointer to the entry and perform checks - entry_no=atol(GRSThttpGetCGI("entry_no")); - entry = GACLreturnEntry(acl, entry_no); + entry_no = atol(GRSThttpGetCGI("entry_no")); + entry = GACLreturnEntry(acl, entry_no); + last_cred_no = atol(GRSThttpGetCGI("entry_no")); + if(entry==NULL || entry_no<1 || entry_no>GACLentriesInAcl(acl) ){ GRSThttpError ("500 Unable to read from ACL file"); return; } - // Start with the first credential and update each one - cred=entry->firstcred; - cred_no=1; - - while (cred!=NULL){ - if (strcmp(cred->type, "any-user")!=0){ - namevalue=cred->firstname; - sprintf(variable, "cred%d_value", cred_no); - namevalue->value=GRSThttpGetCGI(variable); - } - //Change to next credential*/ - cred=cred->next; - cred_no++; - } - + // Reset the first credential and add in each one as they are found + entry->firstcred = NULL; + cred_no = 1; + + for (cred_no = 1; cred_no <= last_cred_no; ++cred_no) + { + sprintf(variable, "cred_auri_%d", cred_no); + cred_auri_i = GRSThttpGetCGI(variable); + + if (cred_auri_i[0] != '\0') + { + /* check AURI for scheme:path form */ + + for (p=cred_auri_i; *p != '\0'; ++p) if (!isalnum(*p) && (*p != '-') && (*p != '_')) break; + + if ((p == cred_auri_i) || (*p != ':')) + { + StartHTML(&bp, dir_uri, dir_path); + GRSThttpPrintf (&bp, "ERROR: CANNOT SAVE CHANGES\n\n
Attribute URIs must take the form scheme:path" + "
For example dn:/DC=com/DC=example/CN=name or " + "fqan:/voname/groupname or https://host.name/listname or dns:host.name.pattern or ip:ip.number.pattern\n
\n"); + admin_continue(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, &bp); + return; + } + + if (entry->firstcred == NULL) + { + entry->firstcred = GRSTgaclCredCreate(cred_auri_i, NULL); + cred = entry->firstcred; + } + else + { + cred->next = GRSTgaclCredCreate(cred_auri_i, NULL); + cred = cred->next; + } + } + } + + if (entry->firstcred == NULL) + { + StartHTML(&bp, dir_uri, dir_path); + GRSThttpPrintf (&bp, "ERROR: CANNOT SAVE CHANGES\n\n
Each entry must include at least one valid credential (Attribute URI)\n
\n");
+ admin_continue(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, &bp);
+ return;
+ }
+
+
// Update permissions
GACLeditGetPerms(entry);
check_acl_save(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, user, acl, &bp);
@@ -393,7 +419,6 @@ void add_cred_form(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_u
GRSTgaclAcl *acl;
GRSTgaclEntry* entry;
GRSTgaclCred* cred;
- GRSTgaclNamevalue* namevalue;
if (!GRSTgaclPermHasAdmin(perm)) GRSThttpError ("403 Forbidden");
@@ -410,7 +435,7 @@ void add_cred_form(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_u
if (strcmp(GRSThttpGetCGI("cmd"), "add_cred_form")==0){ //if not a new entry check to see if Attribute URIs must take the form scheme:path"
+ " For example dn:/DC=com/DC=example/CN=name or "
+ "fqan:/voname/groupname or https://host.name/listname or dns:host.name.pattern or ip:ip.number.pattern\n \n");
+ admin_continue(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, &bp);
+ return;
+ }
+
+ cred=GRSTgaclCredCreate(cred_auri_1, NULL);
GRSTgaclEntryAddCred(entry, cred);
check_acl_save(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, user, acl, &bp);
@@ -532,7 +562,6 @@ void del_entry_sure(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_
GRSTgaclAcl *acl;
GRSTgaclEntry *entry;
GRSTgaclCred *cred;
- GRSTgaclNamevalue *namevalue;
int entry_no, cred_no, allow, deny, i, timestamp;
GRSThttpBody bp;
@@ -565,8 +594,7 @@ void del_entry_sure(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_
GRSTgaclCredTableStart(&bp);
while (cred!=NULL){
// Start with the first namevalue in the credential
- namevalue=cred->firstname;
- GRSTgaclCredTableAdd(user, entry, cred, namevalue, cred_no, entry_no, 0, 0, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
+ GRSTgaclCredTableAdd(user, entry, cred, cred_no, entry_no, 0, 0, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
// Change to next credential
cred=cred->next;
cred_no++;
@@ -587,7 +615,6 @@ void del_cred_sure(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_u
GRSTgaclAcl *acl;
GRSTgaclEntry *entry;
GRSTgaclCred *cred;
- GRSTgaclNamevalue *namevalue;
int entry_no, cred_no, allow, deny, timestamp, i;
GRSThttpBody bp;
@@ -626,7 +653,7 @@ void del_cred_sure(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_u
// Print the credential out
GRSTgaclCredTableStart(&bp);
- GRSTgaclCredTableAdd(user, entry, cred, cred->firstname, cred_no, entry_no, 0, 0, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
+ GRSTgaclCredTableAdd(user, entry, cred, cred_no, entry_no, 0, 0, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
GRSTgaclCredTableEnd (entry, entry_no, 0, 0, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
GRSThttpPrintf (&bp,"
\n");
admin_continue(dn, perm, help_uri, dir_path, file, dir_uri, admin_file, &bp);
@@ -427,7 +452,7 @@ void add_cred_form(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_u
GRSThttpPrintf (&bp, " \n", entry_no);
GRSTgaclCredTableStart(&bp);
- GRSTgaclCredTableAdd(user, entry, cred, namevalue, 0, 0, 0, timestamp, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
+ GRSTgaclCredTableAdd(user, entry, cred, 0, 0, 0, timestamp, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
GRSTgaclCredTableEnd (entry, 0, 0, timestamp, &bp, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
EndForm(&bp);
@@ -443,7 +468,7 @@ void add_cred(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_uri, c
GRSTgaclEntry *entry;
GRSTgaclCred *cred;
GRSThttpBody bp;
- char *type, *value;
+ char *cred_auri_1, *p;
if (!GRSTgaclPermHasAdmin(perm)) GRSThttpError ("403 Forbidden");
@@ -458,18 +483,23 @@ void add_cred(GRSTgaclUser *user, char *dn, GRSTgaclPerm perm, char *help_uri, c
}
// Create new credential and add it to entry
- type=GRSThttpGetCGI("type");
- value=GRSThttpGetCGI("cred0_value");
- cred=GRSTgaclCredNew(type);
- if (strcmp(type, "person") ==0) GRSTgaclCredAddValue(cred,"dn", value);
- else if (strcmp(type, "dn-list") ==0) GRSTgaclCredAddValue(cred, "url", value);
- else if (strcmp(type, "voms") ==0) GRSTgaclCredAddValue(cred, "fqan", value);
- else if (strcmp(type, "dns") ==0) GRSTgaclCredAddValue(cred, "hostname", value);
- else if (strcmp(type, "any-user")==0) {}// namevalue not entered for any-user credential
- else{
- GRSThttpError ("500 Credential type not valid");
- return;
- }
+ cred_auri_1=GRSThttpGetCGI("cred_auri_1");
+
+ /* check AURI for scheme:path form */
+
+ for (p=cred_auri_1; *p != '\0'; ++p) if (!isalnum(*p) && (*p != '-') && (*p != '_')) break;
+
+ if ((p == cred_auri_1) || (*p != ':'))
+ {
+ StartHTML(&bp, dir_uri, dir_path);
+ GRSThttpPrintf (&bp, "ERROR: CANNOT SAVE CHANGES\n\n
\n");
@@ -761,67 +788,61 @@ void EndForm(GRSThttpBody *bp){
void GRSTgaclCredTableStart(GRSThttpBody *bp){
//Starts an HTML table of credentials by setting the column widths and inputting the headings
GRSThttpPrintf (bp,"");
- GRSThttpPrintf (bp,"
");
+ GRSThttpPrintf (bp,"Credential No. Type Value ");
return;
}
-void GRSTgaclCredTableAdd(GRSTgaclUser *user, GRSTgaclEntry *entry, GRSTgaclCred *cred, GRSTgaclNamevalue *namevalue, int cred_no, int entry_no, int admin, int timestamp, GRSThttpBody *bp, char *dn, GRSTgaclPerm perm, char *help_uri, char *dir_path, char *file, char *dir_uri, char *admin_file){
+void GRSTgaclCredTableAdd(GRSTgaclUser *user, GRSTgaclEntry *entry, GRSTgaclCred *cred, int cred_no, int entry_no, int admin, int timestamp, GRSThttpBody *bp, char *dn, GRSTgaclPerm perm, char *help_uri, char *dir_path, char *file, char *dir_uri, char *admin_file)
+{
// Adds the credential "cred" to a table started byGRSTgaclCredTableStart allowing the user to edit if appropriate
char* cmd = GRSThttpGetCGI("cmd");
int edit_values=0, new_cred=0, allow_new_person=1;
- int site_admin=GRSTgaclDNlistHasUser(getenv("REDIRECT_GRST_ADMIN_LIST"), user);
+ int site_admin=GRSTgaclUserHasAURI(user, getenv("REDIRECT_GRST_ADMIN_LIST"));
if (strcmp(cmd, "new_entry_form")==0 || strcmp(cmd, "add_cred_form")==0) new_cred=1;
- if (new_cred || strcmp(cmd, "edit_entry_form")==0) edit_values=1;
+ if (new_cred || (strcmp(cmd, "edit_entry_form") == 0)) edit_values=1;
- if (new_cred) { /*Print out type and descriptor*/
- if (strcmp(cmd, "add_cred_form")==0){ /*if not a new entry check to see if Credential No. Attribute URI New ");
- GRSThttpPrintf(bp,"");
- GRSThttpPrintf (bp, " ");
- }
-
- else { //Print out type and descriptor for existing cred
+ cred_no = 1;
+ }
+ else
+ { //Print out type and descriptor for existing cred
- GRSThttpPrintf(bp,"%d", cred_no);
- if (admin) GRSThttpPrintf (bp,"(Delete)", dir_uri,admin_file,dir_uri, entry_no, cred_no, timestamp);
- GRSThttpPrintf(bp, " %s ", cred->type);
- }
+ GRSThttpPrintf(bp," ");
@@ -843,7 +864,7 @@ void GRSTgaclCredTableEnd(GRSTgaclEntry* entry, int entry_no, int admin, int tim
if (admin) GRSThttpPrintf (bp,"Add Credential", dir_uri,admin_file,dir_uri, entry_no, timestamp);
- GRSThttpPrintf (bp, "\n%d", cred_no);
+ if (admin) GRSThttpPrintf (bp,"(Delete)", dir_uri,admin_file,dir_uri, entry_no, cred_no, timestamp);
+ GRSThttpPrintf(bp, " ");
+ }
- if (strcmp(cred->type, "any-user")==0) GRSThttpPrintf (bp, " "); /* Do not print out namevalue for any-user credential*/
- else{
- if (edit_values){ // Place namevalue in an editable box if appropriate
- GRSThttpPrintf (bp, " auri, "gacl:any-user")==0) GRSThttpPrintf (bp, " %s", cred->auri);
+ else
+ {
+ if (edit_values)
+ { // Place AURI in an editable box if appropriate
+ GRSThttpPrintf (bp, " value, bp);
+ StringHTMLEncode(cred->auri, bp);
GRSThttpPrintf (bp, "\">");
- }
- else if (strcmp(cred->type, "dn-list")==0){
+ }
+ else if ((strncmp(cred->auri, "http://", 7) == 0) ||
+ (strncmp(cred->auri, "https://", 8) == 0))
+ {
GRSThttpPrintf(bp, " value, bp);
+ StringHTMLEncode(cred->auri, bp);
GRSThttpPrintf(bp, " \">");
- StringHTMLEncode(namevalue->value, bp);
+ StringHTMLEncode(cred->auri, bp);
GRSThttpPrintf(bp, "");
}
- else { GRSThttpPrintf(bp, " "); StringHTMLEncode(namevalue->value, bp);}
-
- }
+ else
+ {
+ GRSThttpPrintf(bp, " ");
+ StringHTMLEncode(cred->auri, bp);
+ }
+ }
//Print out warning symbol if cred being printed relates to current user - but NOT for users in site admin list
if (GRSTgaclUserHasCred(user, cred) && !site_admin) GRSThttpPrintf(bp, " <--");
GRSThttpPrintf(bp, " ");
+ GRSThttpPrintf (bp, " \n");
if (blank_perms==1)entry->allowed=entry->denied=GRST_PERM_NONE;
@@ -896,7 +917,7 @@ void check_acl_save(char *dn, GRSTgaclPerm perm, char *help_uri, char *dir_path,
// check users permissions in the new ACL
- if (!GRSTgaclDNlistHasUser(getenv("REDIRECT_GRST_ADMIN_LIST"), user))
+ if (!GRSTgaclUserHasAURI(user, getenv("REDIRECT_GRST_ADMIN_LIST")))
{
new_perm = GRSTgaclAclTestUser(acl, user);
if (new_perm != perm){
diff --git a/org.gridsite.core/src/grst_admin_main.c b/org.gridsite.core/src/grst_admin_main.c
index a9e9f0e..069a2f4 100644
--- a/org.gridsite.core/src/grst_admin_main.c
+++ b/org.gridsite.core/src/grst_admin_main.c
@@ -195,10 +195,10 @@ void justfooter(char *dn, GRSTgaclPerm perm, char *help_uri, char *dir_path,
int main()
{
- int i, gsiproxylimit_i = 1;
+ int i, gsiproxylimit_i = 1, delegation = 0;
char *cmd, *dir_uri, *file, *dir_path, *admin_file, *dn = NULL,
*help_uri, *p, *content_type, *request_uri, *button,
- *grst_cred_0, *gsiproxylimit, *dn_lists, buf[12];
+ *grst_auri_i, *grst_valid_i, *gsiproxylimit, buf[12];
GRSTgaclCred *cred;
GRSTgaclUser *user = NULL;
GRSTgaclAcl *acl;
@@ -219,56 +219,54 @@ int main()
GRSTgaclInit();
- grst_cred_0 = getenv("GRST_CRED_0");
+ gsiproxylimit = getenv("REDIRECT_GRST_GSIPROXY_LIMIT");
+ if (gsiproxylimit != NULL) sscanf(gsiproxylimit, "%d", &gsiproxylimit_i);
+
+ grst_auri_i = getenv("GRST_CRED_AURI_0");
+ grst_valid_i = getenv("GRST_CRED_VALID_0");
- if ((grst_cred_0 != NULL) && (cred = GRSTx509CompactToCred(grst_cred_0)))
+ if ((grst_auri_i != NULL) && (strncmp(grst_auri_i, "dn:", 3) == 0))
{
- gsiproxylimit = getenv("REDIRECT_GRST_GSIPROXY_LIMIT");
- if (gsiproxylimit != NULL) sscanf(gsiproxylimit, "%d", &gsiproxylimit_i);
-
- if (GRSTgaclCredGetDelegation(cred) <= gsiproxylimit_i)
- {
+ dn = &grst_auri_i[3];
+
+ sscanf(grst_valid_i,
+ "notbefore=%*ld notafter=%*ld delegation=%d nist-loa=%*d",
+ &delegation);
+
+ if (delegation <= gsiproxylimit_i)
+ {
+ cred = GRSTgaclCredCreate(grst_auri_i, NULL);
user = GRSTgaclUserNew(cred);
- if ((p = index(grst_cred_0, ' ')) &&
- (p = index(++p, ' ')) &&
- (p = index(++p, ' ')) &&
- (p = index(++p, ' '))) dn = &p[1];
- }
- /* User has a cert so check for voms attributes */
- for(i=1; ; i++)
- {
- sprintf (buf, "GRST_CRED_%d", i);
+ /* User has a cert so check for VOMS attributes etc */
+ for (i=1; ; i++)
+ {
+ sprintf (buf, "GRST_CRED_%d", i);
+ grst_auri_i = getenv(buf);
+ if (grst_auri_i == NULL) break;
+
+ cred = GRSTgaclCredCreate(grst_auri_i, NULL);
+ GRSTgaclUserAddCred(user, cred);
+ }
- grst_cred_0 = getenv(buf);
- if (grst_cred_0==NULL) break;
-
- if (cred=GRSTx509CompactToCred(grst_cred_0))
- GRSTgaclUserAddCred(user, cred);
+ /* no more VOMS attributes etc found */
}
- /* no more voms attributes found found */
}
else if ((dn = getenv("SSL_CLIENT_S_DN")) != NULL)
{
- cred = GRSTgaclCredNew("person");
- GRSTgaclCredAddValue(cred, "dn", dn);
+ cred = GRSTgaclCredCreate("dn:", dn);
user = GRSTgaclUserNew(cred);
}
- dn_lists = getenv("REDIRECT_GRST_DN_LISTS");
- if (dn_lists == NULL) dn_lists = getenv("GRST_DN_LISTS");
- if (dn_lists != NULL) GRSTgaclUserSetDNlists(user, dn_lists);
-
- if (GRSTgaclDNlistHasUser(getenv("REDIRECT_GRST_ADMIN_LIST"),
- user)) perm = GRST_PERM_ALL;
+ if (GRSTgaclUserHasAURI(user, getenv("REDIRECT_GRST_ADMIN_LIST")))
+ perm = GRST_PERM_ALL;
else
{
p = getenv("REMOTE_HOST");
if (p != NULL)
{
- cred = GRSTgaclCredNew("dns");
- GRSTgaclCredAddValue(cred, "hostname", p);
+ cred = GRSTgaclCredCreate("dns:", p);
if (user == NULL) user = GRSTgaclUserNew(cred);
else GRSTgaclUserAddCred(user, cred);
diff --git a/org.gridsite.core/src/grst_gacl.c b/org.gridsite.core/src/grst_gacl.c
index 539a44e..c093497 100644
--- a/org.gridsite.core/src/grst_gacl.c
+++ b/org.gridsite.core/src/grst_gacl.c
@@ -298,12 +298,12 @@ int GRSTgaclEntryDelCred(GRSTgaclEntry *entry, GRSTgaclCred *cred)
int GRSTgaclCredPrint(GRSTgaclCred *cred, FILE *fp)
/*
- GRSTgaclCredPrint - print a credential and any name-value pairs is contains
+ GRSTgaclCredPrint - print a credential and the AURI value it contains
*/
{
- char *q;
+ char *q;
- if (cred->auri != NULL)
+ if ((cred->auri != NULL) && (cred->auri[0] != '\0'))
{
fprintf(fp, "