Exemplo n.º 1
0
static int32_t camd35_auth_client(struct s_client *cl, uchar *ucrc)
{
	int32_t rc = 1;
	uint32_t crc;
	struct s_auth *account;
	unsigned char md5tmp[MD5_DIGEST_LENGTH];

	if(cl->upwd[0])
		{ return (memcmp(cl->ucrc, ucrc, 4) ? 1 : 0); }
	cl->crypted = 1;
	crc = (((ucrc[0] << 24) | (ucrc[1] << 16) | (ucrc[2] << 8) | ucrc[3]) & 0xffffffffL);
	for(account = cfg.account; (account) && (!cl->upwd[0]); account = account->next)
		if(crc == crc32(0L, MD5((unsigned char *)account->usr, strlen(account->usr), md5tmp), MD5_DIGEST_LENGTH))
		{
			rc = cs_auth_client(cl, account, NULL);
			if(!rc)
			{
				memcpy(cl->ucrc, ucrc, 4);
				cs_strncpy((char *)cl->upwd, account->pwd, sizeof(cl->upwd));
				if (!aes_set_key_alloc(&cl->aes_keys, (char *) MD5(cl->upwd, strlen((char *)cl->upwd), md5tmp)))
				{
					return 1;
				}
				return 0;
			}
		}
	return (rc);
}
Exemplo n.º 2
0
static int32_t camd35_auth_client(struct s_client *cl, uchar *ucrc)
{
	int32_t rc = 1, no_delay = 1;
	uint32_t crc;
	struct s_auth *account;
	unsigned char md5tmp[MD5_DIGEST_LENGTH];

	if(cl->upwd[0])
		{ return (memcmp(cl->ucrc, ucrc, 4) ? 1 : 0); }
	cl->crypted = 1;
	crc = (((ucrc[0] << 24) | (ucrc[1] << 16) | (ucrc[2] << 8) | ucrc[3]) & 0xffffffffL);
	for(account = cfg.account; (account) && (!cl->upwd[0]); account = account->next)
		if(crc == crc32(0L, MD5((unsigned char *)account->usr, strlen(account->usr), md5tmp), MD5_DIGEST_LENGTH))
		{
			rc = cs_auth_client(cl, account, NULL);
			if(!rc)
			{
				memcpy(cl->ucrc, ucrc, 4);
				cs_strncpy((char *)cl->upwd, account->pwd, sizeof(cl->upwd));
				if (!aes_set_key_alloc(&cl->aes_keys, (char *) MD5(cl->upwd, strlen((char *)cl->upwd), md5tmp)))
				{
					return 1;
				}
				
				#ifdef CS_CACHEEX
				if(cl->account->cacheex.mode < 2)
				#endif
				if(!cl->is_udp && cl->tcp_nodelay == 0)
				{
					setsockopt(cl->udp_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&no_delay, sizeof(no_delay));
					cl->tcp_nodelay = 1;
				}
				
				return 0;
			}
		}
	return (rc);
}