Skip to content

Instantly share code, notes, and snippets.

@bararchy
Created June 28, 2016 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bararchy/abb0750f8bda54382211ec0f147ece15 to your computer and use it in GitHub Desktop.
Save bararchy/abb0750f8bda54382211ec0f147ece15 to your computer and use it in GitHub Desktop.
Krb5 Bindings
@[Link("krb5")]
lib LibKRB
fun krb5_init_context(buff : UInt8*) : UInt32
fun krb5_free_context(buff : UInt8*) : Void
end
class Krb5
def initialize
ctx = Pointer(UInt8)
ret = LibKRB.krb5_init_context(ctx)
raise "krb5_init_context() failed" if ret == 0
end
end
puts Krb5.new
module FFI::Krb5
extend FFI::Library
ffi_lib "krb5"
attach_function :krb5_init_context, [:buffer_out], :uint
attach_function :krb5_free_context, [:pointer], :void
end
## What you pass to krb5_init_context is really a pointer to a pointer. You
## can now use that this way:
buf = FFI::Buffer.new(:pointer)
res = FFI::Krb5.krb5_init_context(buf)
puts res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment