示例#1
0
文件: zipsum.c 项目: boyski/Objcmp
/* Clear central directory data about a single file */
static int
clear_one_cd_file(unsigned char **p1, off_t *p2)
{
    unsigned char *data;
    off_t size_left;
    struct cd_file h;
    size_t len;
    int is_zip64;

    data = *p1;
    size_left = *p2;
    memcpy(&h, data, sizeof(h));
    memset(h.mtime, 0, sizeof(h.mtime));
    memset(h.mdate, 0, sizeof(h.mdate));
    memcpy(data, &h, sizeof(h));
    ADVANCE(sizeof(h));
    len = get_u16(h.name_length);
    ADVANCE(len);
    if (clear_file_extra(&data, &size_left, get_u16(h.extra_length), &is_zip64,
			 NULL) != 0)
	return -1;
    len = get_u16(h.comment_length);
    ADVANCE(len);
    *p1 = data;
    *p2 = size_left;
    return 0;
}
示例#2
0
static const char *
next_patt(register const char *pattern, int advance)
{
    wchar_t __nlh_char[1];

    if (CHARAT(pattern) == '[')
    {
	int ch;
	const char *pp = pattern;
	ADVANCE(pp);

	if (CHARAT(pp) == '^')
	    ADVANCE(pp);

	if (CHARAT(pp) == ']')
	    ADVANCE(pp);

	char const *np;
	for (; (ch = next_char(pp, &np)) != '\0'; pp = np)
	    if (ch == ']')
		return (advance ? np : pp);
    }

    next_char(pattern, &pattern);
    return pattern;
}
示例#3
0
/* RFC 3579 */
int radius_put_message_authenticator(RADIUS_PACKET *packet, const char *secret)
{
	int rval;
	u_char md5result[16];
	RADIUS_ATTRIBUTE* attr;
	RADIUS_ATTRIBUTE* end;

	if ((rval = radius_put_raw_attr(packet,
	    RADIUS_TYPE_MESSAGE_AUTHENTICATOR, md5result, sizeof(md5result)))
	    != 0)
		return rval;

	radius_hmac_md5(packet, secret, strlen(secret), (caddr_t)md5result, 0);

	attr = ATTRS_BEGIN(packet->pdata);
	end  = ATTRS_END(packet->pdata);

	for(; attr<end; ADVANCE(attr))
	{
		if (attr->type == RADIUS_TYPE_MESSAGE_AUTHENTICATOR)
		{
			memcpy(attr->data, md5result, sizeof(md5result));
			break;
		}
	}

	return 0;
}
示例#4
0
文件: zipfile.c 项目: boyski/Objcmp
/* Compare central directory data about a single file */
static int
cmp_one_cd_file(const unsigned char **p1, const unsigned char **p2, off_t *p3)
{
    const unsigned char *data1, *data2;
    off_t size_left;
    struct cd_file h1, h2;
    size_t len;
    enum result res;
    int is_zip64;

    data1 = *p1;
    data2 = *p2;
    size_left = *p3;
    memcpy(&h1, data1, sizeof(h1));
    memcpy(&h2, data2, sizeof(h2));
    ADVANCE(sizeof(h1));
    memset(h1.mtime, 0, sizeof(h1.mtime));
    memset(h2.mtime, 0, sizeof(h2.mtime));
    memset(h1.mdate, 0, sizeof(h1.mdate));
    memset(h2.mdate, 0, sizeof(h2.mdate));
    if (memcmp(&h1, &h2, sizeof(h1)) != 0)
	return RES_DIFFERENT;
    len = get_u16(h1.name_length);
    COMPARE_AND_ADVANCE(len);
    res = cmp_file_extra(&data1, &data2, &size_left, get_u16(h1.extra_length),
			 &is_zip64, NULL);
    if (res != RES_SAME)
	return res;
    len = get_u16(h1.comment_length);
    COMPARE_AND_ADVANCE(len);
    *p1 = data1;
    *p2 = data2;
    *p3 = size_left;
    return RES_SAME;
}
示例#5
0
/*
 * To determine the length of the data, set the buf = NULL.
 */
int radius_get_vs_raw_attr_all(const RADIUS_PACKET* packet, u_int32_t vendor,
                               u_int8_t vtype, caddr_t buf, int *length)
{
	int off;
	const RADIUS_ATTRIBUTE* attr;
	const RADIUS_ATTRIBUTE* end;

	attr = ATTRS_BEGIN(packet->pdata);
	end  = ATTRS_END(packet->pdata);

	off = 0;
	for(; attr<end; ADVANCE(attr))
	{
		if(attr->type != RADIUS_TYPE_VENDOR_SPECIFIC)
			continue;
		if(attr->vendor != htonl(vendor))
			continue;
		if(attr->vtype != vtype)
			continue;

		if (buf != NULL) {
			if (off + attr->vlength - 2 <= *length)
				memcpy(off + buf, attr->vdata,
				    attr->vlength - 2);
			else
				return 1;
		}
		off += attr->vlength;
	}
	*length = off;

	return 0;
}
示例#6
0
void dbg_history_dump(char *key)
{
  int cnt;
  char *buf;
  struct head *p;
  if(history_length)
    {
      fprintf(stderr, "***** %s:%lu: history dump start\n", dbg_file_name, dbg_line_number);
      if(histp->addr)
	{
	  cnt = history_length;
	  p = histp;
	}
      else
	{
	  cnt = histp - hist_base;
	  p = hist_base;
	}
      while(cnt--)
	{
	  buf = malloc(strlen(p->file) + strlen(p->in.free.file) + 3*length(long) + 30);
	  sprintf(buf, "(alloc: %s:%lu size: %lu free: %s:%lu)\n",
		  p->file, p->line, (unsigned long)p->size, p->in.free.file, p->in.free.line);
	  if(strstr(buf, key)) fputs(buf, stderr);
	  free(buf);
	  ADVANCE(p);
	}
      fprintf(stderr, "***** %s:%lu: history dump end\n", dbg_file_name, dbg_line_number);
    }
}     
示例#7
0
int radius_get_vs_raw_attr_ptr(const RADIUS_PACKET* packet, u_int32_t vendor,
                           u_int8_t vtype, void** ptr, u_int8_t* length)
{
	const RADIUS_ATTRIBUTE* attr;
	const RADIUS_ATTRIBUTE* end;

	attr = ATTRS_BEGIN(packet->pdata);
	end  = ATTRS_END(packet->pdata);

	for(; attr<end; ADVANCE(attr))
	{
		if(attr->type != RADIUS_TYPE_VENDOR_SPECIFIC)
			continue;
		if(attr->vendor != htonl(vendor))
			continue;
		if(attr->vtype != vtype)
			continue;

		*length = attr->vlength - 2;
		*ptr = (void *)attr->vdata;
		return 0;
	}

	return 1;
}
示例#8
0
static int radius_check_packet_data(const RADIUS_PACKET_DATA* pdata,
                                    size_t length)
{
	const RADIUS_ATTRIBUTE* attr;
	const RADIUS_ATTRIBUTE* end;

	if(length < sizeof(RADIUS_PACKET_DATA))
		return 1;
	if(length > 0xffff)
		return 1;
	if(length != (size_t)ntohs(pdata->length))
		return 1;

	attr = ATTRS_BEGIN(pdata);
	end  = ATTRS_END(pdata);
	for(; attr<end; ADVANCE(attr))
	{
		if(attr->length < 2)
			return 1;
		if(attr->type == RADIUS_TYPE_VENDOR_SPECIFIC)
		{
			if(attr->length < 8)
				return 1;
			if((attr->vendor & htonl(0xff000000U)) != 0)
				return 1;
			if(attr->length != attr->vlength + 6)
				return 1;
		}
	}

	if(attr != end)
		return 1;

	return 0;
}
示例#9
0
void dbg_history_dump(char *key)
{
  int cnt;
  char buf[80];
  struct head *p;
  if(history_length)
    {
      fprintf(stderr, "***** %s:%u: history dump start\n", dbg_file_name, dbg_line_number);
      if(histp->addr)
	{
	  cnt = history_length;
	  p = histp;
	}
      else
	{
	  cnt = histp - hist_base;
	  p = hist_base;
	}
      while(cnt--)
	{
	  snprintf(buf, 80, "(alloc: %s:%u size: %lu free: %s:%u)\n",
		  p->file, p->line, (unsigned long)p->size, p->free.file, p->free.line);
	  ADVANCE(p);
	  if(strstr(buf, key)) fputs(buf, stderr);
	}
      fprintf(stderr, "***** %s:%u: history dump end\n", dbg_file_name, dbg_line_number);
    }
}     
示例#10
0
/*
 * To determine the length of the data, set the buf = NULL.
 */
int radius_get_raw_attr_all(const RADIUS_PACKET* packet, u_int8_t type,
                            caddr_t buf, int *length)
{
	int off;
	const RADIUS_ATTRIBUTE* attr;
	const RADIUS_ATTRIBUTE* end;

	attr = ATTRS_BEGIN(packet->pdata);
	end  = ATTRS_END(packet->pdata);

	for(off = 0; attr<end; ADVANCE(attr))
	{
		if(attr->type != type)
			continue;
		if (buf != NULL) {
			if (off + attr->length - 2 <= *length)
				memcpy(buf + off, attr->data, attr->length - 2);
			else
				return 1;
		}
		off += attr->length - 2;
	}
	*length = off;

	return 0;
}
示例#11
0
文件: parse.c 项目: jeremyfrench/lsh
/* NOTE: This functions record the fact that it has read to the end of
 * the buffer by setting the position to *beyond* the end of the
 * buffer. */
static int
parse_next_atom(struct simple_buffer *buffer, enum lsh_atom *result)
{
  uint32_t i;

  assert (buffer->pos <=buffer->capacity);

  for(i = 0; i < LEFT; i++)
    {
      if (HERE[i] == ',')
	break;
      if (i == 64)
	/* Atoms can be no larger than 64 characters */
	return 0;
    }

  /* NOTE: ssh-2.0.13, server string "SSH-1.99-2.0.13
   * (non-commercial)", sends USERAUTH_FAILURE messages with strings
   * like "publickey,password,". It's not entirely clear to me if that
   * is allowed for the spec, but it seems safe and straightforward to
   * treat empty atoms as any other unknown atom. */
  if (!i)
    {
      verbose("parse_next_atom: Received an empty atom.\n");
      /* Treat empty atoms as unknown */
      *result = 0;
    }
  else
    *result = lookup_atom(i, HERE);

  ADVANCE(i+1);  /* If the atom was terminated at the end of the
		  * buffer, rather than by a comma, this points beyond
		  * the end of the buffer */
  return 1;
}
示例#12
0
文件: parse.c 项目: jeremyfrench/lsh
int
parse_boolean(struct simple_buffer *buffer, int *result)
{
  if (!LEFT)
    return 0;
  *result = HERE[0];
  ADVANCE(1);
  return 1;
}
示例#13
0
文件: parse.c 项目: jeremyfrench/lsh
void
parse_rest(struct simple_buffer *buffer,
	   uint32_t *length, const uint8_t **start)
{
  *length = LEFT;
  *start = HERE;

  ADVANCE(*length);
}
示例#14
0
文件: parse.c 项目: jeremyfrench/lsh
/* NOTE: This is used in one single place: For copying the cookie in
   received KEYEXCHANGE_INIT messages. */
int
parse_octets(struct simple_buffer *buffer,
	     uint32_t length, uint8_t *start)
{
  if (LEFT < length)
    return 0;
  memcpy(start, HERE, length);
  ADVANCE(length);
  return 1;
}
示例#15
0
文件: parse.c 项目: jeremyfrench/lsh
int
parse_uint32(struct simple_buffer *buffer, uint32_t *result)
{
  if (LEFT < 4)
    return 0;

  *result = READ_UINT32(HERE);
  ADVANCE(4);
  return 1;
}
示例#16
0
文件: parse.c 项目: jeremyfrench/lsh
/* Used by client_x11.c, for parsing xauth */
int
parse_uint16(struct simple_buffer *buffer, uint32_t *result)
{
  if (LEFT < 2)
    return 0;

  *result = READ_UINT16(HERE);
  ADVANCE(2);
  return 1;
}
示例#17
0
文件: parse.c 项目: jeremyfrench/lsh
int
parse_uint8(struct simple_buffer *buffer, unsigned *result)
{
  if (!LEFT)
    return 0;

  *result = HERE[0];
  ADVANCE(1);
  return 1;
}
示例#18
0
文件: conf.c 项目: gonzopancho/nsh
void
conf_print_rtm(FILE *output, struct rt_msghdr *rtm, char *delim, int af)
{
	int i;
	char *cp, flags[64];
	struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL;
	struct sockaddr *sa;
	struct sockaddr_in sin;

	sin.sin_addr.s_addr = htonl(INADDR_BROADCAST);

	cp = ((char *)rtm + rtm->rtm_hdrlen);
	for (i = 1; i; i <<= 1)
		if (i & rtm->rtm_addrs) {
			sa = (struct sockaddr *)cp;
			switch (i) {
			case RTA_DST:
				/* allow arp to get printed with af==AF_LINK */
				if ((sa->sa_family == af) ||
				    (af == AF_LINK && sa->sa_family == AF_INET)) {
					if (rtm->rtm_flags & RTF_REJECT)
						snprintf(flags, sizeof(flags),
						    " reject");
					else
						flags[0] = '\0';
					dst = sa;
				}
				break;
			case RTA_GATEWAY:
				if (sa->sa_family == af)
					gate = sa;
				break;
			case RTA_NETMASK:
				/* netmasks will not have a valid sa_family */
				mask = sa;
				break;
			}
			ADVANCE(cp, sa);
		}
	if (dst && gate && mask && (af == AF_INET || af == AF_INET6)) {
		/*
		 * Suppress printing IPv4 route if it's the default
		 * route and dhcp (dhclient) is enabled.
		 */
		if (!(af == AF_INET && isdefaultroute(dst, mask)
		    && dhclient_isenabled(routename(gate)))) {
			fprintf(output, "%s%s ", delim, netname(dst, mask));
			fprintf(output, "%s%s\n", routename(gate), flags);
		}
	} else if (dst && gate && (af == AF_LINK)) {
		/* print arp */
		fprintf(output, "%s%s ", delim, routename(dst));
		fprintf(output, "%s\n", routename(gate));
	}
}
示例#19
0
文件: keyb.c 项目: jtsiomb/colcycle
static void __interrupt __far kbintr()
{
	unsigned char code;
	int key, press;

	code = inp(KB_PORT);

	if(code >= 128) {
		press = 0;
		code -= 128;

		if(num_pressed > 0) {
			num_pressed--;
		}
	} else {
		press = 1;

		num_pressed++;
	}

	key = scantbl[code];

	if(press) {
		/* append to buffer */
		last_key = key;
		if(buffer_size > 0) {
			buffer[buf_widx] = key;
			ADVANCE(buf_widx);
			/* if the write end overtook the read end, advance the read end
			 * too, to discard the oldest keypress from the buffer
			 */
			if(buf_widx == buf_ridx) {
				ADVANCE(buf_ridx);
			}
		}
	}

	/* and update keystate table */
	keystate[key] = press;

	outp(PIC1_CMD_PORT, OCW2_EOI);	/* send end-of-interrupt */
}
示例#20
0
文件: parse.c 项目: jeremyfrench/lsh
struct lsh_string *
parse_rest_copy(struct simple_buffer *buffer)
{
  uint32_t length = LEFT;
  struct lsh_string *s = ssh_format("%ls", length, HERE);

  ADVANCE(length);
  assert(!LEFT);

  return s;
}
示例#21
0
文件: zipsum.c 项目: boyski/Objcmp
/* Clear per-file extra data;
   Update compressed_size if it is not NULL, otherwise assume compressed_size
   is not present in the zip64 header. */
static int
clear_file_extra(unsigned char **p1, off_t *p2, size_t extra_len, int *is_zip64,
		 unsigned long long *compressed_size)
{
    unsigned char *data;
    off_t size_left;

    data = *p1;
    size_left = *p2;
    while (extra_len >= sizeof(struct extra_header)) {
	struct extra_header eh;
	size_t len;

	memcpy(&eh, data, sizeof(eh));
	ADVANCE(sizeof(eh));
	len = get_u16(eh.data_size);
	if (extra_len < sizeof(eh) + len)
	    return -1;
	extra_len -= sizeof(eh) + len;
	if (memcmp(eh.id, eh_id_zip64, sizeof(eh_id_zip64)) == 0) {
	    *is_zip64 = 1;
	    if (compressed_size != NULL)
		*compressed_size = get_u64(data + 8);
	    ADVANCE(len);
	} else if (memcmp(eh.id, eh_id_ext_timestamp,
			  sizeof(eh_id_ext_timestamp)) == 0) {
	    if (len < 1)
		return -1;
	    ADVANCE(1);		/* Time presence flags */
	    memset(data, 0, len - 1);	/* mtime, atime, ctime - if present */
	    ADVANCE(len - 1);
	} else
	    ADVANCE(len);
    }
    if (extra_len != 0)
	return -1;
    *p1 = data;
    *p2 = size_left;
    return 0;
}
示例#22
0
static void
rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
{
    struct sockaddr *sa;
    int i;

    memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));
    for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
	if ((rtinfo->rti_addrs & (1 << i)) == 0)
	    continue;
	rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
	ADVANCE(cp, sa);
    }
}
示例#23
0
文件: startup.c 项目: MarginC/kame
/* 
 * Extract addresses from the given buffer
 */
void
xaddress(const int rti_addrs, char *cp, char *cplim, struct rt_addrinfo *rtinfo)
{
	register struct sockaddr *sa;
	register int i;

	bzero((char *)rtinfo, sizeof(struct rt_addrinfo));
	for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
		if ((rti_addrs & (1 << i)) == 0)
			continue;
		rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
		ADVANCE(cp, sa);
	}
}
示例#24
0
void extractAddresses(int iAddrMask, caddr_t cp, caddr_t cplim, struct sockaddr **pAddresses)
{
    struct sockaddr *sa;

    for (int i = 0; i < RTAX_MAX && cp < cplim; i++) {
        if (!(iAddrMask & (1 << i)))
            continue;

        sa = (struct sockaddr *)cp;

        pAddresses[i] = sa;

        ADVANCE(cp, sa);
    }
}
示例#25
0
文件: keyb.c 项目: jtsiomb/colcycle
int kb_getkey(void)
{
	int res;

	if(buffer) {
		if(buf_ridx == buf_widx) {
			return -1;
		}
		res = buffer[buf_ridx];
		ADVANCE(buf_ridx);
	} else {
		res = last_key;
		last_key = -1;
	}
	return res;
}
示例#26
0
文件: parse.c 项目: jeremyfrench/lsh
int
parse_string(struct simple_buffer *buffer,
	     uint32_t *length, const uint8_t **start)
{
  uint32_t l;

  if (!parse_uint32(buffer, &l))
    return 0;

  if (LEFT < l)
    return 0;

  *length = l;
  *start = HERE;
  ADVANCE(l);
  return 1;
}
示例#27
0
void
conf_print_rtm(FILE *output, struct rt_msghdr *rtm, char *delim, int af)
{
	int i;
	char *cp;
	struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL;
	struct sockaddr *sa;

	cp = ((char *)rtm + rtm->rtm_hdrlen);
	for (i = 1; i; i <<= 1)
		if (i & rtm->rtm_addrs) {
			sa = (struct sockaddr *)cp;
			switch (i) {
			case RTA_DST:
				/* allow arp to get printed with af==AF_LINK */
				if ((sa->sa_family == af) ||
				    (af == AF_LINK && sa->sa_family == AF_INET))
					dst = sa;
				break;
			case RTA_GATEWAY:
				if (sa->sa_family == af)
					gate = sa;
				break;
			case RTA_NETMASK:
				/* netmasks will not have a valid sa_family */
				mask = sa;
				break;
			}
			ADVANCE(cp, sa);
		}
	if (dst && mask && gate && (af == AF_INET || af == AF_INET6)) {
		/*
		 * suppress printing IP route if it's the default
		 * v4 route and dhcp (dhclient) is enabled
		 */
		if (!(isdefaultroute4(dst) && dhclient_isenabled(routename(gate)))) {
			fprintf(output, "%s%s ", delim, netname(dst, mask));
			fprintf(output, "%s\n", routename(gate));
		}
	} else
	if (dst && gate && (af == AF_LINK))
		/* print arp */
		fprintf(output, "%s%s %s\n", delim, routename(dst),
		    routename(gate));
}
示例#28
0
static void
get_addrs(int type, char *cp, struct sockaddr **sa)
{
	int i;

	for (i = 0; i < RTAX_MAX; i++) {
		if (type & (1 << i)) {
			sa[i] = (struct sockaddr *)cp;
#ifdef DEBUG
			printf ("got %d %d %s\n", i, sa[i]->sa_family,
			    inet_ntoa(((struct sockaddr_in *)sa[i])->
				sin_addr));
#endif
			ADVANCE(cp, sa[i]);
		} else
			sa[i] = NULL;
	}
}
示例#29
0
文件: zipfile.c 项目: boyski/Objcmp
/* Compare per-file extra data;
   Update compressed_size if it is not NULL, otherwise assume compressed_size
   is not present in the zip64 header. */
static enum result
cmp_file_extra(const unsigned char **p1, const unsigned char **p2, off_t *p3,
	       size_t extra_len, int *is_zip64,
	       unsigned long long *compressed_size)
{
    const unsigned char *data1, *data2;
    off_t size_left;

    data1 = *p1;
    data2 = *p2;
    size_left = *p3;
    while (extra_len >= sizeof(struct extra_header)) {
	struct extra_header eh;
	size_t len;

	memcpy(&eh, data1, sizeof(eh));
	COMPARE_AND_ADVANCE(sizeof(eh));
	len = get_u16(eh.data_size);
	if (extra_len < sizeof(eh) + len)
	    return RES_UNKNOWN;
	extra_len -= sizeof(eh) + len;
	if (memcmp(eh.id, eh_id_zip64, sizeof(eh_id_zip64)) == 0) {
	    *is_zip64 = 1;
	    if (compressed_size != NULL)
		*compressed_size = get_u64(data1 + 8);
	    COMPARE_AND_ADVANCE(len);
	} else if (memcmp(eh.id, eh_id_ext_timestamp,
			  sizeof(eh_id_ext_timestamp)) == 0) {
	    if (len < 1)
		return RES_UNKNOWN;
	    COMPARE_AND_ADVANCE(1);	/* Time presence flags */
	    ADVANCE(len - 1);	/* mtime, atime, ctime - if present */
	} else
	    COMPARE_AND_ADVANCE(len);
    }
    if (extra_len != 0)
	return RES_UNKNOWN;
    *p1 = data1;
    *p2 = data2;
    *p3 = size_left;
    return RES_SAME;
}
示例#30
0
int radius_get_raw_attr(const RADIUS_PACKET* packet, u_int8_t type,
                        void* buf, u_int8_t* length)
{
	const RADIUS_ATTRIBUTE* attr;
	const RADIUS_ATTRIBUTE* end;

	attr = ATTRS_BEGIN(packet->pdata);
	end  = ATTRS_END(packet->pdata);

	for(; attr<end; ADVANCE(attr))
	{
		if(attr->type != type)
			continue;
		*length = attr->length - 2;
		memcpy(buf, attr->data, attr->length - 2);
		return 0;
	}

	return 1;
}