Esempio n. 1
0
int
initgroups(__const char * user, gid_t gid)
{
  struct group * group;
#ifndef GR_DYNAMIC_GROUP_LIST
  gid_t group_list[GR_MAX_GROUPS];
#else
  gid_t * group_list=NULL;
#endif
  char ** tmp_mem;
  int num_groups;
  int grp_fd;


  if ((grp_fd=open(GROUP_FILE, O_RDONLY))<0)
    return -1;

  num_groups=0;
#ifdef GR_DYNAMIC_GROUP_LIST
  group_list=(gid_t *) realloc(group_list, 1);
#endif
  group_list[num_groups]=gid;
#ifndef GR_DYNAMIC_GROUP_LIST
  while (num_groups<GR_MAX_GROUPS &&
	 (group=__getgrent(grp_fd))!=NULL)
#else
  while ((group=__getgrent(grp_fd))!=NULL)
#endif      
    {
      if (group->gr_gid!=gid);
        {
	  tmp_mem=group->gr_mem;
	  while(*tmp_mem!=NULL)
	    {
	      if (!strcmp(*tmp_mem, user))
		{
		  num_groups++;
#ifdef GR_DYNAMIC_GROUP_LIST  
		  group_list=(gid_t *)realloc(group_list,
					      num_groups*sizeof(gid_t *));
#endif		  
		  group_list[num_groups]=group->gr_gid;
		}
	      tmp_mem++;
	    }
	}
    }
  close(grp_fd);
  return setgroups(num_groups, group_list);
}
Esempio n. 2
0
struct group *getgrnam(const char *name)
{
	int grp_fd;
	struct group *group;

	if (name == NULL) {
		__set_errno(EINVAL);
		return NULL;
	}

	if ((grp_fd = open(_PATH_GROUP, O_RDONLY)) < 0)
		return NULL;

	LOCK;
	while ((group = __getgrent(grp_fd, line_buff, members)) != NULL)
		if (!strcmp(group->gr_name, name)) {
			close(grp_fd);
			UNLOCK;
			return group;
		}

	close(grp_fd);
	UNLOCK;
	return NULL;
}
Esempio n. 3
0
File: grent.c Progetto: 8l/FUZIX
struct group *
getgrent(void)
{
  if (grp_fd==-1)
    return NULL;
  return __getgrent(grp_fd);
}
Esempio n. 4
0
struct group *fgetgrent(FILE * file)
{
	if (file == NULL) {
		errno = EINTR;
		return NULL;
	}

	return __getgrent(fileno(file));
}
Esempio n. 5
0
struct group *fgetgrent(FILE * file)
{
    struct group *grp;

    if (file == NULL) {
	__set_errno(EINTR);
	return NULL;
    }

    LOCK;
    grp = __getgrent(fileno(file), line_buff, members);
    UNLOCK;
    return grp;
}
Esempio n. 6
0
struct group *getgrgid(const gid_t gid)
{
    struct group *group;
    int grp_fd;

    if ((grp_fd = open(_PATH_GROUP, O_RDONLY)) < 0)
	return NULL;

    LOCK;
    while ((group = __getgrent(grp_fd, line_buff, members)) != NULL)
	if (group->gr_gid == gid) {
	    close(grp_fd);
	    UNLOCK;
	    return group;
	}

    close(grp_fd);
    UNLOCK;
    return NULL;
}
Esempio n. 7
0
struct group *getgrnam(const char *name)
{
	int grp_fd;
	struct group *group;

	if (name == NULL) {
		errno = EINVAL;
		return NULL;
	}

	if ((grp_fd = open("/etc/group", O_RDONLY)) < 0)
		return NULL;

	while ((group = __getgrent(grp_fd)) != NULL)
		if (!strcmp(group->gr_name, name)) {
			close(grp_fd);
			return group;
		}

	close(grp_fd);
	return NULL;
}