static int get_current_groups(gid_t gid, uint32_t *p_ngroups, gid_t **p_groups) { int i; gid_t grp; int ngroups; gid_t *groups = NULL; (*p_ngroups) = 0; (*p_groups) = NULL; /* this looks a little strange, but is needed to cope with systems that put the current egid in the group list returned from getgroups() (tridge) */ save_re_gid(); set_effective_gid(gid); setgid(gid); ngroups = sys_getgroups(0,&grp); if (ngroups <= 0) { goto fail; } if((groups = SMB_MALLOC_ARRAY(gid_t, ngroups+1)) == NULL) { DEBUG(0,("setup_groups malloc fail !\n")); goto fail; } if ((ngroups = sys_getgroups(ngroups,groups)) == -1) { goto fail; } restore_re_gid(); (*p_ngroups) = ngroups; (*p_groups) = groups; DEBUG( 4, ( "get_current_groups: user is in %u groups: ", ngroups)); for (i = 0; i < ngroups; i++ ) { DEBUG( 4, ( "%s%d", (i ? ", " : ""), (int)groups[i] ) ); } DEBUG( 4, ( "\n" ) ); return ngroups; fail: SAFE_FREE(groups); restore_re_gid(); return -1; }
bool push_sec_ctx(void) { struct sec_ctx *ctx_p; /* Check we don't overflow our stack */ if (sec_ctx_stack_ndx == MAX_SEC_CTX_DEPTH) { DEBUG(0, ("Security context stack overflow!\n")); smb_panic("Security context stack overflow!"); } /* Store previous user context */ sec_ctx_stack_ndx++; ctx_p = &sec_ctx_stack[sec_ctx_stack_ndx]; ctx_p->ut.uid = geteuid(); ctx_p->ut.gid = getegid(); DEBUG(4, ("push_sec_ctx(%u, %u) : sec_ctx_stack_ndx = %d\n", (unsigned int)ctx_p->ut.uid, (unsigned int)ctx_p->ut.gid, sec_ctx_stack_ndx )); ctx_p->token = dup_nt_token(NULL, sec_ctx_stack[sec_ctx_stack_ndx-1].token); ctx_p->ut.ngroups = sys_getgroups(0, NULL); if (ctx_p->ut.ngroups != 0) { if (!(ctx_p->ut.groups = SMB_MALLOC_ARRAY(gid_t, ctx_p->ut.ngroups))) { DEBUG(0, ("Out of memory in push_sec_ctx()\n")); TALLOC_FREE(ctx_p->token); return False; } sys_getgroups(ctx_p->ut.ngroups, ctx_p->ut.groups); } else { ctx_p->ut.groups = NULL; } return True; }
BOOL push_sec_ctx(void) { struct sec_ctx *ctx_p; /* Check we don't overflow our stack */ if (sec_ctx_stack_ndx == MAX_SEC_CTX_DEPTH) { DEBUG(0, ("Security context stack overflow!\n")); smb_panic("Security context stack overflow!\n"); } /* Store previous user context */ sec_ctx_stack_ndx++; ctx_p = &sec_ctx_stack[sec_ctx_stack_ndx]; ctx_p->uid = geteuid(); ctx_p->gid = getegid(); DEBUG(3, ("push_sec_ctx(%u, %u) : sec_ctx_stack_ndx = %d\n", (unsigned int)ctx_p->uid, (unsigned int)ctx_p->gid, sec_ctx_stack_ndx )); ctx_p->token = dup_nt_token(sec_ctx_stack[sec_ctx_stack_ndx-1].token); ctx_p->ngroups = sys_getgroups(0, NULL); if (ctx_p->ngroups != 0) { if (!(ctx_p->groups = malloc(ctx_p->ngroups * sizeof(gid_t)))) { DEBUG(0, ("Out of memory in push_sec_ctx()\n")); delete_nt_token(&ctx_p->token); return False; } sys_getgroups(ctx_p->ngroups, ctx_p->groups); } else { ctx_p->groups = NULL; } return True; }
/* Note: it is necessary to treat gidsetsize as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long compat_sys_getgroups(u32 gidsetsize, gid_t __user *grouplist) { return sys_getgroups((int)gidsetsize, grouplist); }