boolean cartTrackDbIsAccessDenied(char *db, char *table) /* Return TRUE if useAccessControl=TRUE was passed to cartTrackDbInit and * if access to table is denied (at least on this host) by 'tableBrowser off' * or by the tableAccessControl table. */ { static char *currentHost = NULL; static struct hash *dbToAcHash = NULL; if (!useAC) return FALSE; struct slName *enabledHosts = NULL; struct slName *sln = NULL; if (dbToAcHash == NULL) dbToAcHash = hashNew(0); struct hash *acHash = hashFindVal(dbToAcHash, db); if (acHash == NULL) { struct sqlConnection *conn = hAllocConn(db); acHash = accessControlInit(conn); hFreeConn(&conn); hashAdd(dbToAcHash, db, acHash); } if (acHash == NULL) return FALSE; enabledHosts = (struct slName *)hashFindVal(acHash, table); if (enabledHosts == NULL) return FALSE; if (currentHost == NULL) { currentHost = cloneString(cgiServerName()); if (currentHost == NULL) { warn("accessControl: unable to determine current host"); return FALSE; } else chopAtFirstDot(currentHost); } for (sln = enabledHosts; sln != NULL; sln = sln->next) { if (sameString(currentHost, sln->name)) return FALSE; } return TRUE; }
boolean accessControlDenied(char *db, char *table) /* Return TRUE if table access is restricted to some host(s) other than * the one we're running on. */ { static char *currentHost = NULL; struct slName *enabledHosts = NULL; struct slName *sln = NULL; static struct hash *dbToAcHash = NULL; if (dbToAcHash == NULL) dbToAcHash = hashNew(0); struct hash *acHash = hashFindVal(dbToAcHash, db); if (acHash == NULL) { struct sqlConnection *conn = hAllocConn(db); acHash = accessControlInit(conn); hFreeConn(&conn); hashAdd(dbToAcHash, db, acHash); } if (acHash == NULL) return FALSE; enabledHosts = (struct slName *)hashFindVal(acHash, table); if (enabledHosts == NULL) return FALSE; if (currentHost == NULL) { currentHost = cloneString(cgiServerName()); if (currentHost == NULL) { warn("accessControl: unable to determine current host"); return FALSE; } else chopAtFirstDot(currentHost); } for (sln = enabledHosts; sln != NULL; sln = sln->next) { if (sameString(currentHost, sln->name)) return FALSE; } return TRUE; }