Beispiel #1
0
/*
 *	add_trans -- Add a transform payload onto the set of transforms.
 *
 *	Inputs:
 *
 *	finished	0 if adding a new transform; 1 if finalising.
 *	length	(output) length of entire transform payload.
 *	cipher	The encryption algorithm
 *	keylen	Key length for variable length keys (0=fixed key length)
 *	hash	Hash algorithm
 *	auth	Authentication method
 *	group	DH Group number
 *	lifetime	Lifetime in seconds (0=no lifetime)
 *
 *	Returns:
 *
 *	Pointer to new set of transform payloads.
 *
 *	This function can either be called with finished = 0, in which case
 *	cipher, keylen, hash, auth, group and lifetime must be specified, and
 *	the function will return NULL, OR it can be called with finished = 1
 *	in which case cipher, keylen, hash, auth, group and lifetime are
 *	ignored and the function will return a pointer to the finished
 *	payload and will set *length to the length of this payload.
 */
unsigned char*add_trans(int finished, size_t *length,
			unsigned cipher, unsigned keylen, unsigned hash,
			unsigned auth,
			unsigned group, unsigned lifetime, unsigned lifesize,
			int gss_id_flag, unsigned char *gss_data,
			size_t gss_data_len)
{

	static int first_transform = 1;
	static unsigned char *trans_start = NULL;       /* Start of set of transforms */
	static size_t cur_offset;                       /* Start of current transform */
	static size_t end_offset;                       /* End of transforms */
	static unsigned trans_no = 1;
	unsigned char *trans;                           /* Transform payload */
	size_t len;                                     /* Transform length */

/*
 * Construct a transform if we are not finalising.
 * Set next to 3 (more transforms), and increment trans_no for next time round.
 */
	if (!finished) {
		trans = make_trans(&len, 3, trans_no, cipher, keylen, hash,
				   auth,
				   group, lifetime, lifesize, gss_id_flag,
				   gss_data,
				   gss_data_len);
		trans_no++;
		if (first_transform) {
			cur_offset = 0;
			end_offset = len;
			trans_start = Malloc(end_offset);
			memcpy(trans_start, trans, len);
			first_transform = 0;
		} else {
			cur_offset = end_offset;
			end_offset += len;
			trans_start = Realloc(trans_start, end_offset);
			memcpy(trans_start + cur_offset, trans, len);
		}
		return NULL;
	} else {
		struct isakmp_transform* hdr =
			(struct isakmp_transform*) (trans_start + cur_offset); /* Overlay */

		first_transform = 1;
		hdr->isat_np = 0; /* No more transforms */
		*length = end_offset;
		return trans_start;
	}
}
Beispiel #2
0
void
read_qif (char *filename)
{
	FILE *f;
	char buf[1000];
	char *p;
	int month, mday, year;
	struct trans *trans;
	char obuf[1000];

	if ((f = fopen (filename, "r")) == NULL)
		fatal ("can't open %s\n", filename);

	if (fgets (buf, sizeof buf, f) == NULL)
		fatal ("unexpected EOF\n");
	trim (buf);

	if (sscanf (buf, "!Type:%s", acct_id) != 1)
		fatal ("%d: invalid QIF: %s\n", linenum, buf);

	linenum = 0;
	trans = NULL;

	trans_list = NULL;
	trans_list_tailp = &trans_list;

	while (1) {
		if (fgets (buf, sizeof buf, f) == NULL)
			break;
		linenum++;

		if (trans == NULL) {
			trans = make_trans ();
			trans->input_seq = ntrans;
		}

		p = trim (buf);
		switch (*p) {
		case 0:
			break;

		case '^':
			*trans_list_tailp = trans;
			trans_list_tailp = &trans->next;
			ntrans++;
			trans = NULL;
			break;
		case 'D':
			if (sscanf (buf, "D%d/%d/%d",
				    &month, &mday, &year) != 3) {
				fatal ("%d: invalid date: %s\n", linenum, buf);
			}

			if (year < 1900)
				fatal ("%d: invalid year %s\n", linenum, buf);
			
			sprintf (obuf, "%04d-%02d-%02d 12:00:00",
				 year, month, mday);
			trans->posted = xstrdup (obuf);
			break;
		case 'T':
			trans->amount = parse_number (buf + 1);
			break;
		case 'N': // check number
			trans->ref = xstrdup (buf + 1);
			break;
		case 'P': // payee
			trans->name = xstrdup (buf + 1);
			break;
		case 'M': // memo
			trans->memo = xstrdup (buf + 1);
			break;
		default:
			fatal ("%d: unknown opcode: %s\n", linenum, buf);
			break;
		}
	}

	process_trans ();
}