Exemplo n.º 1
0
directory_obj *
nis_clone_directory (const directory_obj *src, directory_obj *dest)
{
  char *addr;
  unsigned int size;
  XDR xdrs;

  if (src == NULL)
    return NULL;

  size = xdr_sizeof ((xdrproc_t)_xdr_directory_obj, (char *)src);
  if ((addr = calloc(1, size)) == NULL)
    return NULL;

  xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
  if (!_xdr_directory_obj (&xdrs, (directory_obj *)src))
    {
      xdr_destroy (&xdrs);
      free (addr);
      return NULL;
    }
  xdr_destroy (&xdrs);

  directory_obj *res;
  if (dest == NULL)
    {
      if ((res = calloc (1, sizeof (directory_obj))) == NULL)
	{
	  free (addr);
	  return NULL;
	}
    }
  else
    res = dest;

  xdrmem_create (&xdrs, addr, size, XDR_DECODE);
  if (!_xdr_directory_obj (&xdrs, res))
    {
      xdr_destroy (&xdrs);
      if (res != dest)
	free (res);
      free (addr);
      return NULL;
    }
  xdr_destroy (&xdrs);
  free (addr);

  return res;
}
Exemplo n.º 2
0
static bool_t
xdr_objdata (XDR *xdrs, objdata *objp)
{
  bool_t res = xdr_zotypes (xdrs, &objp->zo_type);
  if (!__builtin_expect (res, TRUE))
    return res;
  switch (objp->zo_type)
    {
    case NIS_DIRECTORY_OBJ:
      return _xdr_directory_obj (xdrs, &objp->objdata_u.di_data);
    case NIS_GROUP_OBJ:
      return xdr_group_obj (xdrs, &objp->objdata_u.gr_data);
    case NIS_TABLE_OBJ:
      return xdr_table_obj (xdrs, &objp->objdata_u.ta_data);
    case NIS_ENTRY_OBJ:
      return xdr_entry_obj (xdrs, &objp->objdata_u.en_data);
    case NIS_LINK_OBJ:
      return xdr_link_obj (xdrs, &objp->objdata_u.li_data);
    case NIS_PRIVATE_OBJ:
      return xdr_bytes (xdrs, &objp->objdata_u.po_data.po_data_val,
			&objp->objdata_u.po_data.po_data_len, ~0);
    case NIS_NO_OBJ:
    case NIS_BOGUS_OBJ:
    default:
      return TRUE;
    }
}
Exemplo n.º 3
0
directory_obj *
readColdStartFile (void)
{
  XDR xdrs;
  FILE *in;
  bool_t status = TRUE;
  directory_obj *obj;

  in = fopen (cold_start_file, "rb");
  if (in == NULL)
    return NULL;

  obj = calloc (1, sizeof (directory_obj));

  if (obj != NULL)
    {
      xdrstdio_create (&xdrs, in, XDR_DECODE);
      status = _xdr_directory_obj (&xdrs, obj);
      xdr_destroy (&xdrs);

      if (!status)
	{
	  nis_free_directory (obj);
	  obj = NULL;
	}
    }

  fclose (in);

  return obj;
}
Exemplo n.º 4
0
bool_t
writeColdStartFile (const directory_obj *obj)
{
  XDR xdrs;
  FILE *out;
  bool_t status;

  out = fopen (cold_start_file, "wb");
  if (out == NULL)
    return FALSE;

  xdrstdio_create (&xdrs, out, XDR_ENCODE);
  status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
  xdr_destroy (&xdrs);
  fclose (out);

  return status;
}