Esempio n. 1
0
int	umAddUser(char_t *user, char_t *pass, char_t *group, 
			  bool_t prot, bool_t disabled)
{
	int		row;
	char_t	*password;

	a_assert(user && *user);
	a_assert(pass && *pass);
	a_assert(group && *group);

	trace(3, T("UM: Adding User <%s>\n"), user);

/*
 *	Do not allow duplicates
 */
	if (umUserExists(user)) {
		return UM_ERR_DUPLICATE;
	}

/*
 *	Make sure user name and password contain valid characters
 */
	if (!umCheckName(user)) {
		return UM_ERR_BAD_NAME;
	}

	if (!umCheckName(pass)) {
		return UM_ERR_BAD_PASSWORD;
	}

/*
 *	Make sure group exists
 */
	if (!umGroupExists(group)) {
		return UM_ERR_NOT_FOUND;
	}

/*
 *	Now create the user record
 */
	row = dbAddRow(didUM, UM_USER_TABLENAME);

	if (row < 0) {
		return UM_ERR_GENERAL;
	}

	if (dbWriteStr(didUM, UM_USER_TABLENAME, UM_NAME, row, user) != 0) {
		return UM_ERR_GENERAL;
	}

	password = bstrdup(B_L, pass);
	umEncryptString(password);
	dbWriteStr(didUM, UM_USER_TABLENAME, UM_PASS, row, password);
	bfree(B_L, password);
	dbWriteStr(didUM, UM_USER_TABLENAME, UM_GROUP, row, group);
	dbWriteInt(didUM, UM_USER_TABLENAME, UM_PROT, row, prot); 
	dbWriteInt(didUM, UM_USER_TABLENAME, UM_DISABLE, row, disabled);

	return 0;
}
Esempio n. 2
0
int	umAddGroup(char_t *group, short priv, accessMeth_t am, 
			   bool_t prot, bool_t disabled)
{
	int row;

	a_assert(group && *group);
	trace(3, T("UM: Adding group <%s>\n"), group);
	
/*
 *	Do not allow duplicates
 */
	if (umGroupExists(group)) {
		return UM_ERR_DUPLICATE;
	}

/*
 *	Only allow valid characters in key field
 */
	if (!umCheckName(group)) {
		return UM_ERR_BAD_NAME;
	}

/*
 *	Add a new row to the table
 */
	if ((row = dbAddRow(didUM, UM_GROUP_TABLENAME)) < 0) {
		return UM_ERR_GENERAL;
	}

/*
 *	Write the key field
 */
	if (dbWriteStr(didUM, UM_GROUP_TABLENAME, UM_NAME, row, group) != 0) {
		return UM_ERR_GENERAL;
	}

/*
 *	Write the remaining fields
 */
	dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_PRIVILEGE, row, priv);
	dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_METHOD, row, (int) am);
	dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_PROT, row, prot);
	dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_DISABLE, row, disabled);

	return 0;
}
Esempio n. 3
0
int dbSetTableNrow(int did, char_t *tablename, int nNewRows)
{
    int			nRet, tid, nRows, nColumns;
    dbTable_t	*pTable;

    a_assert(tablename);
    tid = dbGetTableId(0, tablename);
    a_assert(tid >= 0) ;

    if ((tid >= 0) && (tid < dbMaxTables) && (dbListTables[tid] != NULL)) {
        pTable = dbListTables[tid];
    } else {
        return DB_ERR_TABLE_NOT_FOUND;
    }

    nRet = -1;

    a_assert(pTable);
    if (pTable) {
        nColumns = pTable->nColumns;
        nRows = pTable->nRows;
        nRet = 0;

        if (nRows >= nNewRows) {
            /*
             *		If number of rows already allocated exceeds requested number, do nothing
             */
            trace(4, T("DB: Ignoring row set to <%d> in table <%s>\n"),
                  nNewRows, tablename);
        } else {
            trace(4, T("DB: Setting rows to <%d> in table <%s>\n"),
                  nNewRows, tablename);
            while (pTable->nRows < nNewRows) {
                if (dbAddRow(did, tablename) < 0) {
                    return -1;
                }
            }
        }
    }

    return nRet;
}
Esempio n. 4
0
int	umAddAccessLimit(char_t *url, accessMeth_t am, short secure, char_t *group)
{
	int row;

	a_assert(url && *url);
	trace(3, T("UM: Adding Access Limit for <%s>\n"), url);

/*
 *	Do not allow duplicates
 */
	if (umAccessLimitExists(url)) {
		return UM_ERR_DUPLICATE;
	}

/*
 *	Add a new row to the table
 */
	if ((row = dbAddRow(didUM, UM_ACCESS_TABLENAME)) < 0) {
		return UM_ERR_GENERAL;
	}

/*
 *	Write the key field
 */
	if(dbWriteStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, row, url) < 0) {
		return UM_ERR_GENERAL;
	}

/*
 *	Write the remaining fields
 */
	dbWriteInt(didUM, UM_ACCESS_TABLENAME, UM_METHOD, row, (int)am);
	dbWriteInt(didUM, UM_ACCESS_TABLENAME, UM_SECURE, row, (int)secure);
	dbWriteStr(didUM, UM_ACCESS_TABLENAME, UM_GROUP, row, group);

	return 0;
}