12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <assert.h>
- #include <string.h>
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #ifdef HAVE_GRP_H
- #include <grp.h>
- #endif
- #include "lub/string.h"
- #include "lub/db.h"
- #include "clish/shell.h"
- CLISH_HOOK_ACCESS(clish_hook_access)
- {
- int allowed = -1;
- #ifdef HAVE_GRP_H
- int num_groups;
- long ngroups_max;
- gid_t *group_list;
- int i;
- char *tmp_access, *full_access;
- char *saveptr = NULL;
- assert(access);
- full_access = lub_string_dup(access);
- ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
- group_list = (gid_t *)malloc(ngroups_max * sizeof(gid_t));
-
- num_groups = getgroups(ngroups_max, group_list);
- assert(num_groups != -1);
-
-
-
- for (tmp_access = strtok_r(full_access, ":", &saveptr);
- tmp_access; tmp_access = strtok_r(NULL, ":", &saveptr)) {
-
- if (0 == strcmp("*", tmp_access)) {
- allowed = 0;
- break;
- }
-
- for (i = 0; i < num_groups; i++) {
- struct group *ptr = lub_db_getgrgid(group_list[i]);
- if (!ptr)
- continue;
- if (0 == strcmp(ptr->gr_name, tmp_access)) {
-
- allowed = 0;
- free(ptr);
- break;
- }
- free(ptr);
- }
- if (!allowed)
- break;
- }
- lub_string_free(full_access);
- free(group_list);
- #endif
- clish_shell = clish_shell;
- return allowed;
- }
|