simple_access_check.c revision 225d845476b6136be9b77f528ed986bba7a7f732
/*
SSSD
Simple access control
Copyright (C) Sumit Bose <sbose@redhat.com> 2010
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "providers/simple/simple_access.h"
#include "util/sss_utf8.h"
bool *access_granted)
{
int i, j;
const char *user_attrs[] = { SYSDB_MEMBEROF,
NULL };
const char *group_attrs[] = { SYSDB_NAME,
NULL };
struct ldb_message *msg;
struct ldb_message_element *el;
char **groups;
const char *primary_group;
bool matched;
*access_granted = false;
/* First, check whether the user is in the allowed users list */
username));
/* Do not return immediately on explicit allow
* We need to make sure none of the user's groups
* are denied.
*/
*access_granted = true;
}
}
} else if (!ctx->allow_groups) {
/* If neither allow rule is in place, we'll assume allowed
* unless a deny rule disables us below.
*/
*access_granted = true;
}
/* Next check whether this user has been specifically denied */
username));
/* Return immediately on explicit denial */
*access_granted = false;
return EOK;
}
}
}
/* There are no group restrictions, so just return
* here with whatever we've decided.
*/
return EOK;
}
/* Now get a list of this user's groups and check those against the
* simple_allow_groups list.
*/
if (!tmp_ctx) {
goto done;
}
goto done;
}
/* Construct a list of the user's groups */
/* Get the groups from the memberOf entries
* Allocate the array with room for both the NULL
* terminator and the primary group
*/
if (!groups) {
goto done;
}
for (j = 0; j < el->num_values; j++) {
&groups[j]);
goto done;
}
}
} else {
/* User is not a member of any groups except primary */
if (!groups) {
goto done;
}
j = 0;
}
/* Get the user's primary group */
if (!gid) {
goto done;
}
/* We have to treat this as non-fatal, because the primary
* group may be local to the machine and not available in
* our ID provider.
*/
} else {
if (!primary_group) {
goto done;
}
if (!groups[j]) {
goto done;
}
j++;
}
/* Now process allow and deny group rules
* If access was already granted above, we'll skip
* this redundant rule check
*/
matched = false;
for (i = 0; ctx->allow_groups[i]; i++) {
for(j = 0; groups[j]; j++) {
matched = true;
break;
}
}
/* If any group has matched, we can skip out on the
* processing early
*/
if (matched) {
*access_granted = true;
break;
}
}
}
/* Finally, process the deny group rules */
if (ctx->deny_groups) {
matched = false;
for (i = 0; ctx->deny_groups[i]; i++) {
for(j = 0; groups[j]; j++) {
matched = true;
break;
}
}
/* If any group has matched, we can skip out on the
* processing early
*/
if (matched) {
*access_granted = false;
break;
}
}
}
done:
return ret;
}