-static int in_group_p(gid_t g)
-{
- /* return TRUE if we're in the specified group, FALSE otherwise */
- int ngroup;
- int i;
- gid_t grouplist[NGROUPS];
-
- ngroup = getgroups(NGROUPS, grouplist);
- for(i = 0; i < ngroup; i++) {
- if(grouplist[i] == g) {
- return 1;
- }
- }
- return 0;
-}
-
-static int count(char ** vec)
-{
- int i;
-
- for(i = 0; *vec; i++) {
- vec++;
- }
-
- return(i);
-}
-
-static int prepare_binprm(struct linux_binprm *bprm)
-{
- struct stat st;
- int mode;
- int retval, id_change;
-
- if(fstat(bprm->fd, &st) < 0) {
- return(-errno);
- }
-
- mode = st.st_mode;
- if(!S_ISREG(mode)) { /* Must be regular file */
- return(-EACCES);
- }
- if(!(mode & 0111)) { /* Must have at least one execute bit set */
- return(-EACCES);
- }
-
- bprm->e_uid = geteuid();
- bprm->e_gid = getegid();
- id_change = 0;
-
- /* Set-uid? */
- if(mode & S_ISUID) {
- bprm->e_uid = st.st_uid;
- if(bprm->e_uid != geteuid()) {
- id_change = 1;
- }
- }
-
- /* Set-gid? */
- /*
- * If setgid is set but no group execute bit then this
- * is a candidate for mandatory locking, not a setgid
- * executable.
- */
- if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
- bprm->e_gid = st.st_gid;
- if (!in_group_p(bprm->e_gid)) {
- id_change = 1;
- }
- }
-
- memset(bprm->buf, 0, sizeof(bprm->buf));
- retval = lseek(bprm->fd, 0L, SEEK_SET);
- if(retval >= 0) {
- retval = read(bprm->fd, bprm->buf, 128);
- }
- if(retval < 0) {
- perror("prepare_binprm");
- exit(-1);
- /* return(-errno); */
- }
- else {
- return(retval);
- }
-}
-
-unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm,
- struct image_info * info)