Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
static struct hash *accessControlInit(struct sqlConnection *conn)
/* Return a hash associating restricted table/track names in the given db/conn
 * with virtual hosts, or NULL if there is no tableAccessControl table and no
 * forbiddenTrackList (see getFullTrackList). */
{
struct hash *acHash = NULL;
if (sqlTableExists(conn, "tableAccessControl"))
    {
    struct sqlResult *sr = NULL;
    char **row = NULL;
    acHash = newHash(0);
    sr = sqlGetResult(conn, "NOSQLINJ select name,host from tableAccessControl");
    while ((row = sqlNextRow(sr)) != NULL)
	hashAddSlName(acHash, row[0], chopAtFirstDot(row[1]));
    sqlFreeResult(&sr);
    }
if (forbiddenTrackList != NULL)
    {
    if (acHash == NULL)
	acHash = newHash(0);
    struct trackDb *tdb;
    for (tdb = forbiddenTrackList;  tdb != NULL;  tdb = tdb->next)
	{
	char *tbOff = cloneString(trackDbSetting(tdb, "tableBrowser"));
	if (isEmpty(tbOff))
	    errAbort("bug: tdb for %s is in forbiddenTrackList without 'tableBrowser off' setting",
		     tdb->track);
	hashAddSlName(acHash, tdb->table, "-");
	// skip "off" and look for additional table names:
	nextWord(&tbOff);
	char *tbl;
	while ((tbl = nextWord(&tbOff)) != NULL)
	    hashAddSlName(acHash, tbl, "-");
	}
    }
return acHash;
}