Exemplo n.º 1
0
VALUE group_putsgent(VALUE self, VALUE io)
{
#ifdef GSHADOW
  struct sgrp sgroup, *tmp_sgrp;
  VALUE path;
  long i = 0;

  Check_EU_Type(self, rb_cGshadow);
  Check_Writes(io, FMODE_WRITABLE);

  path = RFILE_PATH(io);

  rewind(RFILE_FPTR(io));
  SGRP_NAME(&sgroup)  = RSTRING_PTR(rb_ivar_get(self, id_name));

  while ( (tmp_sgrp = fgetsgent(RFILE_FPTR(io))) )
    if ( !strcmp(SGRP_NAME(tmp_sgrp), SGRP_NAME(&sgroup)) )
      rb_raise(rb_eArgError, "%s is already mentioned in %s:%ld",
	       RSTRING_PTR(rb_ivar_get(self, id_name)), StringValuePtr(path), ++i );

  sgroup.sg_passwd = RSTRING_PTR(rb_ivar_get(self, id_passwd));
  sgroup.sg_adm    = setup_char_members( rb_iv_get(self,"@admins") );
  sgroup.sg_mem    = setup_char_members( rb_iv_get(self, "@members") );

  if ( putsgent(&sgroup,RFILE_FPTR(io)) )
    eu_errno(RFILE_PATH(io));

  free_char_members(sgroup.sg_adm, RARRAY_LEN( rb_iv_get(self, "@admins") ));
  free_char_members(sgroup.sg_mem, RARRAY_LEN( rb_iv_get(self, "@members") ));

  return Qtrue;
#else
  return Qnil;
#endif
}
Exemplo n.º 2
0
static int
do_test (void)
{
  FILE *fp = tmpfile ();
  if (fp == NULL)
    {
      puts ("cannot open temporary file");
      return 1;
    }

  for (size_t i = 0; i < ndata; ++i)
    if (putsgent (&data[i], fp) != 0)
      {
	printf ("putsgent call %zu failed\n", i + 1);
	return 1;
      }

  rewind (fp);

  int result = 0;
  int seen = -1;
  struct sgrp *g;
  while ((g = fgetsgent (fp)) != NULL)
    {
      ++seen;
      if (strcmp (g->sg_namp, data[seen].sg_namp) != 0)
	{
	  printf ("sg_namp of entry %d does not match: %s vs %s\n",
		  seen + 1, g->sg_namp, data[seen].sg_namp);
	  result = 1;
	}
      if (strcmp (g->sg_passwd, data[seen].sg_passwd) != 0)
	{
	  printf ("sg_passwd of entry %d does not match: %s vs %s\n",
		  seen + 1, g->sg_passwd, data[seen].sg_passwd);
	  result = 1;
	}
      if (g->sg_adm == NULL)
	{
	  printf ("sg_adm of entry %d is NULL\n", seen + 1);
	  result = 1;
	}
      else
	{
	  int i = 1;
	  char **sp1 = g->sg_adm;
	  char **sp2 = data[seen].sg_adm;
	  while (*sp1 != NULL && *sp2 != NULL)
	    {
	      if (strcmp (*sp1, *sp2) != 0)
		{
		  printf ("sg_adm[%d] of entry %d does not match: %s vs %s\n",
			  i, seen + 1, *sp1, *sp2);
		  result = 1;
		}
	      ++sp1;
	      ++sp2;
	      ++i;
	    }
	  if (*sp1 == NULL && *sp2 != NULL)
	    {
	      printf ("sg_adm of entry %d has too few entries\n", seen + 1);
	      result = 1;
	    }
	  else if (*sp1 != NULL && *sp2 == NULL)
	    {
	      printf ("sg_adm of entry %d has too many entries\n", seen + 1);
	      result = 1;
	    }
	}
      if (g->sg_mem == NULL)
	{
	  printf ("sg_mem of entry %d is NULL\n", seen + 1);
	  result = 1;
	}
      else
	{
	  int i = 1;
	  char **sp1 = g->sg_mem;
	  char **sp2 = data[seen].sg_mem;
	  while (*sp1 != NULL && *sp2 != NULL)
	    {
	      if (strcmp (*sp1, *sp2) != 0)
		{
		  printf ("sg_mem[%d] of entry %d does not match: %s vs %s\n",
			  i, seen + 1, *sp1, *sp2);
		  result = 1;
		}
	      ++sp1;
	      ++sp2;
	      ++i;
	    }
	  if (*sp1 == NULL && *sp2 != NULL)
	    {
	      printf ("sg_mem of entry %d has too few entries\n", seen + 1);
	      result = 1;
	    }
	  else if (*sp1 != NULL && *sp2 == NULL)
	    {
	      printf ("sg_mem of entry %d has too many entries\n", seen + 1);
	      result = 1;
	    }
	}
    }

  fclose (fp);

  return result;
}
Exemplo n.º 3
0
struct sgrp *getsgent (void)
{
#ifdef	USE_NIS
	int nis_1_group = 0;
	struct sgrp *val;
	char buf[BUFSIZ];
#endif
	if (!shadow)
		setsgent ();

#ifdef	USE_NIS
      again:
	/*
	 * See if we are reading from the local file.
	 */

	if (nis_state == native || nis_state == native2) {

		/*
		 * Get the next entry from the shadow group file.  Return
		 * NULL right away if there is none.
		 */

		if (!(val = fgetsgent (shadow)))
			return 0;

		/*
		 * If this entry began with a NIS escape character, we have
		 * to see if this is just a single group, or if the entire
		 * map is being asked for.
		 */

		if (IS_NISCHAR (val->sg_name[0])) {
			if (val->sg_name[1])
				nis_1_group = 1;
			else
				nis_state = start;
		}

		/*
		 * If this isn't a NIS group and this isn't an escape to go
		 * use a NIS map, it must be a regular local group.
		 */

		if (nis_1_group == 0 && nis_state != start)
			return val;

		/*
		 * If this is an escape to use an NIS map, switch over to
		 * that bunch of code.
		 */

		if (nis_state == start)
			goto again;

		/*
		 * NEEDSWORK.  Here we substitute pieces-parts of this entry.
		 */

		return 0;
	} else {
		if (nis_bound == 0) {
			if (bind_nis ()) {
				nis_state = native2;
				goto again;
			}
		}
		if (nis_state == start) {
			if (yp_first (nis_domain, "gshadow.byname", &nis_key,
				      &nis_keylen, &nis_val, &nis_vallen)) {
				nis_state = native2;
				goto again;
			}
			nis_state = middle;
		} else if (nis_state == middle) {
			if (yp_next (nis_domain, "gshadow.byname", nis_key,
				     nis_keylen, &nis_key, &nis_keylen,
				     &nis_val, &nis_vallen)) {
				nis_state = native2;
				goto again;
			}
		}
		return sgetsgent (nis_val);
	}
#else
	return (fgetsgent (shadow));
#endif
}