static void setup(void) { tst_require_root(); tst_sig(FORK, DEF_HANDLER, NULL); ltpuser = getpwnam("nobody"); if (ltpuser == NULL) tst_brkm(TBROK, NULL, "getpwnam(\"nobody\") failed"); if (setgid(ltpuser->pw_gid) == -1) { tst_brkm(TBROK | TERRNO, NULL, "setgid failed to set the effective gid to %d", ltpuser->pw_gid); } if (setuid(ltpuser->pw_uid) == -1) { tst_brkm(TBROK | TERRNO, NULL, "setuid failed to to set the effective uid to %d", ltpuser->pw_uid); } root = get_group_by_name("root"); ltpgroup = get_group_by_gid(ltpuser->pw_gid); bin = get_group_by_name("bin"); TEST_PAUSE; }
/** * Tests wether the owner of this process is in the group 'name'. * * @returns 0 if the owner of this process is not in the group, non-0 otherwise **/ int system_user_in_group(const char *name) { gid_t* list = (gid_t*) malloc(MAX_GROUPS * sizeof(gid_t)); int num_groups, i=0, found=0; unsigned int gid; if (NULL==list) { perror("Cannot allocate group list structure"); exit(EXIT_FAILURE); } gid = get_group_by_name(name); if (0==gid) { fprintf(stderr, "No %s group found\n", name); return 0; } num_groups = getgroups(MAX_GROUPS, list); while (i<num_groups) { if (list[i]==gid) { found = 1; i = num_groups; } i++; } free(list); return found; }
static void setup(void) { tst_require_root(); tst_sig(FORK, DEF_HANDLER, NULL); ltpuser = getpwnam("nobody"); if (ltpuser == NULL) tst_brkm(TBROK, NULL, "getpwnam(\"nobody\") failed"); SAFE_SETGID(NULL, ltpuser->pw_gid); SAFE_SETUID(NULL, ltpuser->pw_uid); root = get_group_by_name("root"); ltpgroup = get_group_by_gid(ltpuser->pw_gid); bin = get_group_by_name("bin"); TEST_PAUSE; }
/** * Checks for the existence of 'groupname' on this system * * @returns 0 if there is no group, the group id otherwise **/ int system_has_group(const char * name) { return get_group_by_name(name); }
/** * Checks for the existence of the 'audio' group on this system * * @returns 0 if there is no 'audio' group, the group id otherwise **/ int system_has_audiogroup() { return get_group_by_name("audio") || get_group_by_name ("jackuser"); }
static void handle_add_request( GROUP_LIST* groups, char* msg, char* ip , unsigned short port_number){ unsigned short len; int packet_header_offset; char* group_name; GROUP_T *group; GROUP_T* new_group; MEMBER_T* new_member; packet_header_offset = sizeof(unsigned short) + sizeof(char); memcpy(&len, msg, sizeof(unsigned short)); len = ntohs(len); group_name = (char*) malloc( sizeof(char) * (len + 1)); // len + 1 bytes including the '\0' if(!group_name){ /* * Server is out of memory.Send a negative reply.We only need to change * the \type field of the packet's header */ msg[2] = ADD_REPLY_NEGATIVE; return ; } // copy group name from the packet strncpy( group_name, msg + packet_header_offset, len ); group_name[len] = '\0'; new_member = create_member(ip , port_number); if( !new_member){ // not enough memory free(group_name); msg[2] = ADD_REPLY_NEGATIVE; return; } group = get_group_by_name(groups, group_name); if(!group){ /* * No such group.First create a new members list and add the new member to the * list.Then create a new group and add it to the groups' list */ int flag; MEMBER_LIST* member_list = create_member_list(); if( !member_list){ free(group_name); free(new_member); msg[2] = ADD_REPLY_NEGATIVE; return ; } // add member to the list flag = add_member(member_list,new_member); if( !flag){ // not added free(member_list); free(new_member); free(group_name); msg[2] = ADD_REPLY_NEGATIVE; return ; } // now create a new group and add it to the groups list new_group = create_group( group_name, member_list); if( !new_group){ free(new_member); free(member_list); free(group_name); msg[2] = ADD_REPLY_NEGATIVE; return; } // add it to the groups' list add_group(groups, new_group); msg[2] = ADD_REPLY_POSITIVE; return; } else{ // group is found.Add the member to the group add_member( group->members, new_member); // positive reply msg[2] = ADD_REPLY_POSITIVE; } free(group_name); return ; }