?? um.c
字號:
a_assert(group && *group);
row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0);
if (row >= 0) {
return dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_DISABLE, row,
(int) !enabled);
} else {
return UM_ERR_NOT_FOUND;
}
}
/******************************************************************************/
/*
* Returns the protected setting for a given group
* Returns FALSE if user is not found
*/
bool_t umGetGroupProtected(char_t *group)
{
int protect, row;
a_assert(group && *group);
protect = 0;
row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0);
if (row >= 0) {
dbReadInt(didUM, UM_GROUP_TABLENAME, UM_PROT, row, &protect);
}
return (bool_t) protect;
}
/******************************************************************************/
/*
* Sets the protected setting for a given group
*/
int umSetGroupProtected(char_t *group, bool_t protect)
{
int row;
a_assert(group && *group);
row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0);
if (row >= 0) {
return dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_PROT, row,
(int) protect);
} else {
return UM_ERR_NOT_FOUND;
}
}
/******************************************************************************/
/*
* umAddAccessLimit() adds an access limit to the "access" table
*/
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;
}
/******************************************************************************/
/*
* umDeleteAccessLimit()
*/
int umDeleteAccessLimit(char_t *url)
{
int row;
a_assert(url && *url);
trace(3, T("UM: Deleting Access Limit for <%s>\n"), url);
/*
* Find the row of the access limit to delete
*/
if ((row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0)) < 0) {
return UM_ERR_NOT_FOUND;
}
return dbDeleteRow(didUM, UM_ACCESS_TABLENAME, row);
}
/******************************************************************************/
/*
* umGetFirstGroup() - return a pointer to the first non-blank access limit
*/
char_t *umGetFirstAccessLimit()
{
return umGetFirstRowData(UM_ACCESS_TABLENAME, UM_NAME);
}
/******************************************************************************/
/*
* umGetNextAccessLimit() - return a pointer to the first non-blank
* access limit following the given one
*/
char_t *umGetNextAccessLimit(char_t *urlLast)
{
return umGetNextRowData(UM_ACCESS_TABLENAME, UM_NAME, urlLast);
}
/******************************************************************************/
/*
* umAccessLimitExists() returns TRUE if this access limit exists
*/
bool_t umAccessLimitExists(char_t *url)
{
a_assert(url && *url);
if (dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0) < 0) {
return FALSE;
} else {
return TRUE;
}
}
/******************************************************************************/
/*
* umGetAccessLimit() returns the Access Method for the URL
*/
accessMeth_t umGetAccessLimitMethod(char_t *url)
{
int am, row;
am = (int) AM_INVALID;
row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0);
if (row >= 0) {
dbReadInt(didUM, UM_ACCESS_TABLENAME, UM_METHOD, row, &am);
}
return (accessMeth_t) am;
}
/******************************************************************************/
/*
* umSetAccessLimitMethod() - set Access Method for Access Limit
*/
int umSetAccessLimitMethod(char_t *url, accessMeth_t am)
{
int row;
a_assert(url && *url);
row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0);
if (row >= 0) {
return dbWriteInt(didUM, UM_ACCESS_TABLENAME, UM_METHOD, row, (int) am);
} else {
return UM_ERR_NOT_FOUND;
}
}
/******************************************************************************/
/*
* umGetAccessLimitSecure() - returns secure switch for access limit
*/
short umGetAccessLimitSecure(char_t *url)
{
int secure, row;
a_assert(url && *url);
secure = -1;
row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0);
if (row >= 0) {
dbReadInt(didUM, UM_ACCESS_TABLENAME, UM_SECURE, row, &secure);
}
return (short)secure;
}
/******************************************************************************/
/*
* umSetAccessLimitSecure() - sets the secure flag for the URL
*/
int umSetAccessLimitSecure(char_t *url, short secure)
{
int row;
a_assert(url && *url);
row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0);
if (row >= 0) {
return dbWriteInt(didUM, UM_ACCESS_TABLENAME, UM_SECURE, row,
(int)secure);
} else {
return UM_ERR_NOT_FOUND;
}
}
/******************************************************************************/
/*
* umGetAccessLimitGroup() - returns the user group of the access limit
*/
char_t *umGetAccessLimitGroup(char_t *url)
{
char_t *group;
int row;
a_assert(url && *url);
group = NULL;
row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0);
if (row >= 0) {
dbReadStr(didUM, UM_ACCESS_TABLENAME, UM_GROUP, row, &group);
}
return group;
}
/******************************************************************************/
/*
* umSetAccessLimitGroup() - sets the user group for the access limit.
*/
int umSetAccessLimitGroup(char_t *url, char_t *group)
{
int row;
a_assert(url && *url);
row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0);
if (row >= 0) {
return dbWriteStr(didUM, UM_ACCESS_TABLENAME, UM_GROUP, row, group);
} else {
return UM_ERR_NOT_FOUND;
}
}
/******************************************************************************/
/*
* Returns the access limit to use for a given URL, by checking for URLs up
* the directory tree. Creates a new string that must be deleted.
*/
char_t *umGetAccessLimit(char_t *url)
{
char_t *urlRet, *urlCheck, *lastChar;
int len;
a_assert(url && *url);
urlRet = NULL;
urlCheck = bstrdup(B_L, url);
a_assert(urlCheck);
len = gstrlen(urlCheck);
/*
* Scan back through URL to see if there is a "parent" access limit
*/
while (len && !urlRet) {
if (umAccessLimitExists(urlCheck)) {
urlRet = bstrdup(B_L, urlCheck);
} else {
/*
* Trim the end portion of the URL to the previous directory marker
*/
lastChar = urlCheck + len;
lastChar--;
while ((lastChar >= urlCheck) && ((*lastChar == '/') ||
(*lastChar == '\\'))) {
*lastChar = 0;
lastChar--;
}
while ((lastChar >= urlCheck) && (*lastChar != '/') &&
(*lastChar != '\\')) {
*lastChar = 0;
lastChar--;
}
len = gstrlen(urlCheck);
}
}
bfree (B_L, urlCheck);
return urlRet;
}
/******************************************************************************/
/*
* Returns the access method to use for a given URL
*/
accessMeth_t umGetAccessMethodForURL(char_t *url)
{
accessMeth_t amRet;
char_t *urlHavingLimit, *group;
urlHavingLimit = umGetAccessLimit(url);
if (urlHavingLimit) {
group = umGetAccessLimitGroup(urlHavingLimit);
if (group && *group) {
amRet = umGetGroupAccessMethod(group);
} else {
amRet = umGetAccessLimitMethod(urlHavingLimit);
}
bfree(B_L, urlHavingLimit);
} else {
amRet = AM_FULL;
}
return amRet;
}
/******************************************************************************/
/*
* Returns TRUE if user can access URL
*/
bool_t umUserCanAccessURL(char_t *user, char_t *url)
{
accessMeth_t amURL;
char_t *group, *usergroup, *urlHavingLimit;
short priv;
a_assert(user && *user);
a_assert(url && *url);
/*
* Make sure user exists
*/
if (!umUserExists(user)) {
return FALSE;
}
/*
* Make sure user is enabled
*/
if (!umGetUserEnabled(user)) {
return FALSE;
}
/*
* Make sure user has sufficient privileges (any will do)
*/
usergroup = umGetUserGroup(user);
priv = umGetGroupPrivilege(usergroup);
if (priv == 0) {
return FALSE;
}
/*
* Make sure user's group is enabled
*/
if (!umGetGroupEnabled(usergroup)) {
return FALSE;
}
/*
* The access method of the user group must not be AM_NONE
*/
if (umGetGroupAccessMethod(usergroup) == AM_NONE) {
return FALSE;
}
/*
* Check to see if there is an Access Limit for this URL
*/
urlHavingLimit = umGetAccessLimit(url);
if (urlHavingLimit) {
amURL = umGetAccessLimitMethod(urlHavingLimit);
group = umGetAccessLimitGroup(urlHavingLimit);
bfree(B_L, urlHavingLimit);
} else {
/*
* If there isn't an access limit for the URL, user has full access
*/
return TRUE;
}
/*
* If the access method for the URL is AM_NONE then
* the file "doesn't exist".
*/
if (amURL == AM_NONE) {
return FALSE;
}
/*
* If Access Limit has a group specified, then the user must be a
* member of that group
*/
if (group && *group) {
#ifdef qHierarchicalAccess
/*
* If we are compiling with the hierarchical access extensions, we
* instead call the user-provided function that checks to see whether
* the current user's access level is greater than or equal to the
* access level required for this URL.
*/
return dmfCanAccess(usergroup, group);
#else
if (usergroup && (gstrcmp(group, usergroup) != 0)) {
return FALSE;
}
#endif
}
/*
* Otherwise, user can access the URL
*/
return TRUE;
}
/******************************************************************************/
/*
* Returns TRUE if given name has only valid chars
*/
static bool_t umCheckName(char_t *name)
{
a_assert(name && *name);
if (name && *name) {
while (*name) {
if (gisspace(*name)) {
return FALSE;
}
name++;
}
return TRUE;
}
return FALSE;
}
/******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -