Example #1
0
int __freebsd_getgroupmembership(void UNUSED(*retval), void UNUSED(*mdata_),
                                 va_list ap)
{
  int err;
  nss_status_t s;
  gid_t group;
  gid_t *tmpgroups;
  const char *user;
  gid_t *groups;
  int maxgrp, *grpcnt;
  int i;
  long int lstart, lsize;
  user = va_arg(ap, const char *);
  group = va_arg(ap, gid_t);
  groups = va_arg(ap, gid_t *);
  maxgrp = va_arg(ap, int);
  grpcnt = va_arg(ap, int *);
  tmpgroups = malloc(maxgrp * sizeof(gid_t));
  if (tmpgroups == NULL)
    return NSS_STATUS_UNAVAIL;
  /* insert primary membership */
  __gr_addgid(group, groups, maxgrp, grpcnt);
  lstart = 0;
  lsize = maxgrp;
  s = _nss_ldap_initgroups_dyn(user, group, &lstart, &lsize, &tmpgroups, 0, &err);
  if (s == NSS_STATUS_SUCCESS)
  {
    for (i = 0; i < lstart; i++)
      __gr_addgid(tmpgroups[i], groups, maxgrp, grpcnt);
    s = NSS_STATUS_NOTFOUND;
  }
  free(tmpgroups);
  return __nss_compat_result(s, 0);
}
Example #2
0
static int __freebsd_getgroupmembership(void *retval, void *mdata, va_list ap)
{
	int err;
	enum nss_status s;
	const char *user 	= va_arg(ap, const char *);
	gid_t group 		= va_arg(ap, gid_t);
	gid_t *groups 		= va_arg(ap, gid_t *);
	int limit 		= va_arg(ap, int);
	int *size 		= va_arg(ap, int*);
	gid_t *tmpgroups;
	long int lstart, lsize;
	int i;

	tmpgroups = malloc(limit * sizeof(gid_t));
	if (tmpgroups == NULL)
		return NS_TRYAGAIN;

	/* insert primary membership */
	__gr_addgid(group, groups, limit, size);

	lstart = 0;
	lsize = limit;
	s = _nss_ldap_initgroups_dyn(user, group, &lstart, &lsize,
		&tmpgroups, 0, &err);
	if (s == NSS_STATUS_SUCCESS) {
		for (i = 0; i < lstart; i++)
			 __gr_addgid(tmpgroups[i], groups, limit, size);
		s = NSS_STATUS_NOTFOUND;
	}

	free(tmpgroups);

	return __nss_compat_result(s, err);
}