Esempio n. 1
0
void MakeHash(const BYTE *data, int len, char *hashStr)
{
    CBlowFish	bl((BYTE *)"ipmsg", 5);
    BYTE		*buf = new BYTE [len + 8];

    bl.Encrypt(data, buf, len);
    bin2hexstr(buf + len - 8, 8, hashStr);
    delete [] buf;
}
Esempio n. 2
0
BOOL GenUserNameDigest(char *org_name, const BYTE *key, char *new_name)
{
    if (org_name != new_name) strncpyz(new_name, org_name, MAX_NAMEBUF);

    BYTE	val[8];
    int		len = strlen(new_name);

    if (!GenUserNameDigestVal(key, val)) return	FALSE;

    if (len + 20 > MAX_NAMEBUF) len = MAX_NAMEBUF - 20;

    new_name += len;
    *new_name++ = '-';
    *new_name++ = '<';
    new_name += bin2hexstr(val, 8, new_name);
    *new_name++ = '>';
    *new_name   = 0;

    return	TRUE;
}
Esempio n. 3
0
int clif_iface_attach(struct clif_data *clifd,
		      struct sockaddr_un *from,
		      socklen_t fromlen,
		      char *ibuf, UNUSED int ilen,
		      char *rbuf, int rlen)
{
	struct ctrl_dst *dst;
	char *tlv, *str, *tokenize;
	const char *delim = ",";
	int i, tlv_count = 0;

	dst = malloc(sizeof(*dst));
	if (dst == NULL)
		return cmd_failed;
	memset(dst, 0, sizeof(*dst));
	memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
	dst->addrlen = fromlen;
	dst->debug_level = MSG_INFO;

	/*
	 * There are two cases here one, the user provided
	 * no string in which case we must send DCBX events
	 * to be compatible with legacy clients. Two the
	 * user sent a comma seperated string of tlv module
	 * ids it expects events from
	 */
	/* set default string to DCBX Events */
	if (ibuf[1] == '\0') {
		u32 hex = LLDP_MOD_DCBX;
		tlv = malloc(sizeof(char) * (8 + 2));
		if (!tlv)
			goto err_tlv;
		tlv[0] = 'A';
		tlv[9] = 0;
		bin2hexstr((u8*)&hex, 4, &tlv[1], 8);
	} else
		tlv = strdup(ibuf);

	str = tlv;
	str++;
	/* Count number of TLV Modules */
	tokenize = strtok(str, delim);
	tlv_count++;
	do {
		tokenize = strtok(NULL, delim);
		tlv_count++;
	} while (tokenize);

	dst->tlv_types = malloc(sizeof(u32) * tlv_count);
	if (!dst->tlv_types)
		goto err_types;
	memset(dst->tlv_types, 0, sizeof(u32) * tlv_count);

	/* Populate tlv_types from comma separated string */
	tokenize = strtok(str, delim);
	for (i=0; tokenize; i++) {
		char *myend;

		dst->tlv_types[i] = strtol(tokenize, &myend, 16);
		if (*myend)		/* No hexnumber for module id */
			goto err_types;
		tokenize = strtok(NULL, delim);
	}

	/* Insert Termination Pattern */
	dst->tlv_types[i] = ~0;
	free(tlv);

	/* Insert new node at beginning */
	dst->next = clifd->ctrl_dst;
	clifd->ctrl_dst = dst;
	LLDPAD_DBG("CTRL_IFACE monitor attached\n");
	snprintf(rbuf, rlen, "%c", ATTACH_CMD);

	return cmd_success;
err_types:
	free(tlv);
err_tlv:
	free(dst);
	LLDPAD_DBG("CTRL_IFACE monitor attach error\n");
	snprintf(rbuf, rlen, "%c", ATTACH_CMD);

	return cmd_failed;
}