Пример #1
0
static void
write_children (GString *out,
		MetaBuilder *builder)
{
  GHashTable *strings;
  MetaFile *child, *file;
  GList *l;
  GList *files;

  files = g_list_prepend (NULL, builder->root);

  while (files != NULL)
    {
      file = files->data;
      files = g_list_remove_link (files, files);

      if (file->children == NULL)
	continue; /* No children, skip file */

      strings = string_block_begin ();

      if (file->children_pointer != 0)
	set_uint32 (out, file->children_pointer, out->len);

      append_uint32 (out, g_list_length (file->children), NULL);

      for (l = file->children; l != NULL; l = l->next)
	{
	  child = l->data;

	  /* No mtime, children or metadata, no need for this
	     to be in the file */
	  if (child->last_changed == 0 &&
	      child->children == NULL &&
	      child->data == NULL)
	    continue;

	  append_string (out, child->name, strings);
	  append_uint32 (out, 0, &child->children_pointer);
	  append_uint32 (out, 0, &child->metadata_pointer);
	  append_time_t (out, child->last_changed, builder);

	  if (file->children)
	    files = g_list_append (files, child);
	}

      string_block_end (out, strings);
    }
}
Пример #2
0
static size_t fmt_rrsig(struct rfc1035_reply *r,
			struct rfc1035_rr *rr, time_t now, char *buf)
{
	char	p[RFC1035_MAXNAMESIZE+1];

	char	timebuf[RFC1035_MAXTIMEBUFSIZE+1];

	time_t signature_inception, signature_expiration;

	struct libmail_encode_info lei;

	struct fmt_rrsig_info fri;

	fri.buf=buf;
	fri.n=0;

	rfc1035_type_itostr(rr->rr.rrsig.type_covered, tostr_callback, &fri);

	append_str(&fri, " ", 1);

	append_int32(&fri, rr->rr.rrsig.algorithm);

	append_str(&fri, " ", 1);

	append_int32(&fri, rr->rr.rrsig.labels);

	append_str(&fri, " ", 1);

	rfc1035_fmttime(rr->rr.rrsig.original_ttl, timebuf);

	append_str(&fri, timebuf, strlen(timebuf));

	append_str(&fri, " ", 1);

	if (sizeof(time_t) == 4)
	{
		signature_inception=rr->rr.rrsig.signature_inception;
		signature_expiration=rr->rr.rrsig.signature_expiration;
	}
	else
	{
		time_t now_epoch=(now & ~0xFFFFFFFFLL);

		time_t cur_epoch=now_epoch | rr->rr.rrsig.signature_inception;

		time_t prev_epoch=cur_epoch - 0xFFFFFFFF-1;
		time_t next_epoch=cur_epoch + 0xFFFFFFFF+1;


#define time2diff(a,b) ((a) < (b) ? (b)-(a):(a)-(b))

#define closest2now(now,time1,time2)					\
		(time2diff((now), (time1)) < time2diff((now), (time2))	\
		 ? (time1):(time2))

		signature_inception =
			closest2now(now, closest2now(now,
						     prev_epoch,
						     cur_epoch),
				    next_epoch);

		signature_expiration =
			signature_inception +
			((rr->rr.rrsig.signature_expiration -
			  rr->rr.rrsig.signature_inception)
			 & 0x7FFFFFFF);
	}

	append_time_t(&fri, signature_inception);

	append_str(&fri, " ", 1);

	append_time_t(&fri, signature_expiration);

	append_str(&fri, " ", 1);

	append_int32(&fri, rr->rr.rrsig.key_tag);

	append_str(&fri, " ", 1);

	rfc1035_replyhostname(r, rr->rr.rrsig.signer_name, p);

	append_str(&fri, p, strlen(p));

	append_str(&fri, ". ", 2);

	libmail_encode_start(&lei, "base64", encode_callback_func, &fri);

	libmail_encode(&lei, rr->rr.rrsig.signature,
		       rr->rr.rrsig.signature_len);
	libmail_encode_end(&lei);

	return fri.n;
}