示例#1
0
文件: pack.c 项目: donaghy1/slurm
/* Given a int ptr, it will unpack an array of size_val
 */
int unpack16_array(uint16_t ** valp, uint32_t * size_val, Buf buffer)
{
	uint32_t i = 0;

	if (unpack32(size_val, buffer))
		return SLURM_ERROR;

	*valp = xmalloc((*size_val) * sizeof(uint16_t));
	for (i = 0; i < *size_val; i++) {
		if (unpack16((*valp) + i, buffer))
			return SLURM_ERROR;
	}
	return SLURM_SUCCESS;
}
示例#2
0
文件: pack.c 项目: corburn/slurm
int unpacklongdouble_array(long double **valp, uint32_t* size_val, Buf buffer)
{
	uint32_t i = 0;

	if (unpack32(size_val, buffer))
		return SLURM_ERROR;

	*valp = xmalloc_nz((*size_val) * sizeof(long double));
	for (i = 0; i < *size_val; i++) {
		if (unpacklongdouble((*valp) + i, buffer))
			return SLURM_ERROR;
	}
	return SLURM_SUCCESS;
}
示例#3
0
uint8_t* SshAgentProcessUnlockRequest(SshAgentContext* context, uint8_t* request, int requestSize)
{
    if (context->isLocked == 0)
    {
        return SshAgentMakeErrorReply();
    }
    
    int passwordLength = unpack32(request + 1);
    if (strncmp(context->lockPassword, (char*)request + 5, passwordLength) != 0)
    {
        return SshAgentMakeErrorReply();
    }
    
    context->isLocked = 0;
    free(context->lockPassword);
    context->lockPassword = NULL;
    
    return SshAgentMakeSuccessReply();
}
示例#4
0
uint8_t* SshAgentProcessLockRequest(SshAgentContext* context, uint8_t* request, int requestSize)
{
    if (context->isLocked)
    {
        return SshAgentMakeErrorReply();
    }
    
    int passwordLength = unpack32(request + 1);
    context->lockPassword = malloc(passwordLength + 1);
    if (context->lockPassword == NULL)
    {
        return SshAgentMakeErrorReply();
    }
    memcpy(context->lockPassword, request + 5, passwordLength);
    context->lockPassword[passwordLength] = 0;
    context->isLocked = 1;
    
    return SshAgentMakeSuccessReply();
}
示例#5
0
std::string sha256::hash_string( void )
{
	if ( !_finalized )
		finalize();
	std::string result;
	uint8_t buf[4];
	char tmp[3];
	for ( size_t i = 0 ; i < 8; i++ )
	{
		unpack32( _hash[i], buf );

		for ( size_t j = 0; j < 4; ++j )
		{
			sprintf( tmp, "%02x", uint32_t(buf[j]) );
			result.append( tmp, tmp+2 );
		}
	}

	return result;
}
示例#6
0
uint8_t* SshAgentMakeSignatureReply(SshAgentContext* context, uint8_t* request, int requestSize)
{
    if (context->isLocked)
    {
        return SshAgentMakeErrorReply();
    }
    
    // Find the private key matching the public key from the request.
    int publicBlobIndex = 1;
    uint32_t publicBlobSize = unpack32(request + publicBlobIndex);
    int dataIndex = publicBlobIndex + 4 + publicBlobSize;
    uint32_t dataSize = unpack32(request + dataIndex);
    int flagsIndex = dataIndex + 4 + dataSize;
    uint32_t flags;
    memcpy(&flags, request + flagsIndex, 4);
    
    if (flags != 0)
    {
        return SshAgentMakeErrorReply();
    }
    
    int i;
    for (i = 0; i < context->keyCount; i++)
    {
        ssh_string blob;
        int sshResult = ssh_pki_export_pubkey_blob(context->keys[i], &blob);
        if (sshResult == SSH_OK)
        {
            int cmpResult = memcmp(request + publicBlobIndex, blob, publicBlobSize);
            ssh_string_free(blob);
            if (cmpResult == 0)
            {
                break;
            }
        }
    }
    if (i >= context->keyCount)
    {
        return SshAgentMakeErrorReply();
    }
    
    // Sign the data and return it in a message of the form:
    // messageLength[ SSH2_AGENT_SIGN_RESPONSE signatureBlob]
    ssh_string signatureBlob = SshAgentSign(request + dataIndex + 4, dataSize, context->keys[i], flags);
    if (signatureBlob == NULL)
    {
        return SshAgentMakeErrorReply();
    }
    
    uint32_t signatureBlobLength = unpack32((uint8_t*)signatureBlob);
    int messageLength = 5 + signatureBlobLength;
    uint8_t* message = malloc(messageLength + 4);
    if (message == NULL)
    {
        free(signatureBlob);
        return SshAgentMakeErrorReply();
    }
    pack32(message, messageLength);
    message[4] = SSH2_AGENT_SIGN_RESPONSE;
    memcpy(message + 5, signatureBlob, signatureBlobLength + 4);
    free(signatureBlob);
    
    return message;
}
示例#7
0
文件: pack-test.c 项目: A1ve5/slurm
int main (int argc, char *argv[])
{
	Buf buffer;
	uint16_t test16 = 1234, out16;
	uint32_t test32 = 5678, out32, byte_cnt;
	char testbytes[] = "TEST BYTES", *outbytes;
	char teststring[] = "TEST STRING",  *outstring = NULL;
	char *nullstr = NULL;
	char *data;
	int data_size;
	long double test_double = 1340664754944.2132312, test_double2;
	uint64_t test64;

	buffer = init_buf (0);
        pack16(test16, buffer);
        pack32(test32, buffer);
	pack64((uint64_t)test_double, buffer);

        packstr(testbytes, buffer);
        packstr(teststring, buffer);
	packstr(nullstr, buffer);

	packstr("literal", buffer);
	packstr("", buffer);

        data_size = get_buf_offset(buffer);
        printf("wrote %d bytes\n", data_size);

	/* Pull data off old buffer, destroy it, and create a new one */
	data = xfer_buf_data(buffer);
	buffer = create_buf(data, data_size);

        unpack16(&out16, buffer);
	TEST(out16 != test16, "un/pack16");

        unpack32(&out32, buffer);
	TEST(out32 != test32, "un/pack32");

  	unpack64(&test64, buffer);
	test_double2 = (long double)test64;
	TEST((uint64_t)test_double2 != (uint64_t)test_double, "un/pack double as a uint64");
	/* info("Original\t %Lf", test_double); */
	/* info("uint64\t %ld", test64); */
	/* info("converted LD\t %Lf", test_double2); */

	unpackstr_ptr(&outbytes, &byte_cnt, buffer);
	TEST( ( strcmp(testbytes, outbytes) != 0 ) , "un/packstr_ptr");

	unpackstr_xmalloc(&outstring, &byte_cnt, buffer);
	TEST(strcmp(teststring, outstring) != 0, "un/packstr_xmalloc");
	xfree(outstring);

	unpackstr_xmalloc(&nullstr, &byte_cnt, buffer);
	TEST(nullstr != NULL, "un/packstr of null string.");

	unpackstr_xmalloc(&outstring, &byte_cnt, buffer);
	TEST(strcmp("literal", outstring) != 0, 
			"un/packstr of string literal");
	xfree(outstring);

	unpackstr_xmalloc(&outstring, &byte_cnt, buffer);
	TEST(strcmp("", outstring) != 0, "un/packstr of string \"\" ");

	xfree(outstring);

	free_buf(buffer);
	totals();
	return failed;

}