Ruby/DL binding to CASA: [BUG] Segmentation fault

N

Nate Younger

Hello,

I am trying to create a binding for CASA(http://developer.novell.com/wiki/index.php/Casa) using Ruby/DL. And I am running into the following problem:

casa.rb:85: [BUG] Segmentation fault
ruby 1.8.4 (2005-12-24) [x86_64-linux]

I'm almost sure its something that I missed. I'm just hoping that some one smarter than me can help me find it. Thanks in advance!

-Nate


casa.rb:

NSSCS_MAX_USERID_LEN = 256
NSSCS_MAX_PWORD_LEN = 128
NSSCS_MAX_SECRET_ID_LEN = 512

SSCS_CRED_TYPE_BASIC_F = 0x0000001
SSCS_CRED_TYPE_BINARY_F = 0x0000002
SSCS_CRED_TYPE_SERVER_F = 0x0000004

USERNAME_TYPE_CN_F = 0x0000000
USERNAME_TYPE_NDS_DN_F = 0x0000001
USERNAME_TYPE_NDS_FDN_F = 0x0000002
USERNAME_TYPE_LDAP_DN_F = 0x0000004
USERNAME_TYPE_EMAIL_F = 0x0000008
USERNAME_TYPE_OTHER_F = 0x0000010


module CASA
require 'dl'
require 'dl/import'
require 'dl/struct'
require 'dl/types'

extend DL::Importable

# Type alias
typealias("uint32_t", "unsigned int")
typealias("int32_t", "int")
typealias("SS_UTF8_T", "unsigned char")

# Struct Type Alias
typealias("SSCS_BASIC_CREDENTIAL", "struct")
typealias("SSCS_SECRET_ID_T", "struct")

SSCS_SECRET_ID = struct([
"uint32_t len",
"SS_UTF8_T id[#{NSSCS_MAX_SECRET_ID_LEN}]"
])

SSCS_BASIC_CREDENTIAL = struct [
"uint32_t unFlags",
"uint32_t unLen",
"SS_UTF8_T username[#{NSSCS_MAX_USERID_LEN}]",
"uint32_t pwordLen",
"SS_UTF8_T password[#{NSSCS_MAX_PWORD_LEN}]"
]

LIB = DL.dlopen('/usr/lib64/libmicasa.so')
SYM = {
:miCASAGetCredential => LIB['miCASAGetCredential','IIPPIPP'],
:miCASASetCredential => LIB['miCASASetCredential','IIPPIPP'],
:miCASARemoveCredential => LIB['miCASAGetCredential','IIPPP']
}


def CASA::get_sscs_secret_id_t(id)
id_bytes = []
id.each_byte { |b| id_bytes << b }

sscs_secret_id_t = SSCS_SECRET_ID.malloc()
sscs_secret_id_t.len = id_bytes.length
sscs_secret_id_t.id = id_bytes

return sscs_secret_id_t
end

def CASA::get_sscs_basic_credential( flags, username, password )
username_bytes = []
username.each_byte { |b| username_bytes << b }
password_bytes = []
password.each_byte { |b| password_bytes << b }

sscs_basic_credential = SSCS_BASIC_CREDENTIAL.malloc()
sscs_basic_credential.unFlags = flags
sscs_basic_credential.unLen = username_bytes.length
sscs_basic_credential.username = username_bytes
sscs_basic_credential.pwordLen = password_bytes.length
sscs_basic_credential.password = password_bytes

return sscs_basic_credential
end

def CASA::get_credential( username, password, secret_id, shared_id = nil )
sec_id = CASA::get_sscs_secret_id_t(secret_id)
basic_cred = CASA::get_sscs_basic_credential( USERNAME_TYPE_CN_F, username, password )

i, ir = SYM[:miCASAGetCredential].call( 0, sec_id, nil, SSCS_CRED_TYPE_BASIC_F, basic_cred, nil )
puts i
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top