net-smb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Rakefile +26 -0
- data/ext/net/smb/extconf.rb +36 -0
- data/ext/net/smb/smb.c +107 -0
- data/lib/net/smb/version.rb +5 -0
- data/net-smb.gemspec +20 -0
- data/test/test_net_smb.rb +22 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
rescue LoadError => e
|
4
|
+
p e
|
5
|
+
end
|
6
|
+
require 'rake/clean'
|
7
|
+
require 'rake/testtask'
|
8
|
+
|
9
|
+
Rake::TestTask.new
|
10
|
+
|
11
|
+
CLEAN.include('ext/**/*.{log,o,so}')
|
12
|
+
CLEAN.include('ext/**/Makefile')
|
13
|
+
CLOBBER.include('lib/**/*.so')
|
14
|
+
|
15
|
+
EXT_PATH = 'net/smb'
|
16
|
+
|
17
|
+
file "lib/#{EXT_PATH}.so" => Dir.glob("ext/#{EXT_PATH}/*.{rb,c,h}") do
|
18
|
+
Dir.chdir("ext/#{EXT_PATH}") do
|
19
|
+
ruby 'extconf.rb'
|
20
|
+
sh ENV['MAKE'] || 'make'
|
21
|
+
end
|
22
|
+
cp "ext/#{EXT_PATH}/#{File.basename(EXT_PATH)}.so", "lib/#{EXT_PATH}.so"
|
23
|
+
end
|
24
|
+
|
25
|
+
task :test => "lib/#{EXT_PATH}.so"
|
26
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
## Perfer $LIBPATH to $DEFLIBPATH
|
4
|
+
alias original_try_link try_link
|
5
|
+
def try_link(*args)
|
6
|
+
deflibpath_saved = $DEFLIBPATH
|
7
|
+
$DEFLIBPATH = ["."]|$LIBPATH|$DEFLIBPATH
|
8
|
+
ret = original_try_link(*args)
|
9
|
+
$DEFLIBPATH = deflibpath_saved
|
10
|
+
return ret
|
11
|
+
end
|
12
|
+
|
13
|
+
$CFLAGS += " " + ENV["CFLAGS"] if ENV["CFLAGS"]
|
14
|
+
$CPPFLAGS += " " + ENV["CPPFLAGS"] if ENV["CPPFLAGS"]
|
15
|
+
$LDFLAGS += " " + ENV["LDFLAGS"] if ENV["LDFLAGS"]
|
16
|
+
|
17
|
+
dir_config "smb"
|
18
|
+
|
19
|
+
h = have_header("libsmbclient.h")
|
20
|
+
l = have_library("smbclient", "smbc_new_context")
|
21
|
+
unless h && l
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
have_func("smbc_set_credentials")
|
26
|
+
|
27
|
+
## Samba 3.2.0+ hide AllowDebugChange variable.
|
28
|
+
if try_link(<<-'EOS')
|
29
|
+
extern int AllowDebugChange;
|
30
|
+
int main(int argc, char **argv) { AllowDebugChange = 0; }
|
31
|
+
EOS
|
32
|
+
$defs << "-DHAVE_SMBC_ALLOWDEBUGCHANGE"
|
33
|
+
end
|
34
|
+
|
35
|
+
create_makefile "smb"
|
36
|
+
|
data/ext/net/smb/smb.c
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <libsmbclient.h>
|
3
|
+
|
4
|
+
struct smbcctx {
|
5
|
+
SMBCCTX *ctx;
|
6
|
+
VALUE auth_callback;
|
7
|
+
};
|
8
|
+
|
9
|
+
#define FALSE_P(value) (NIL_P(value) || (value) == Qfalse)
|
10
|
+
#define TRUE_P(value) !FALSE_P(value)
|
11
|
+
|
12
|
+
#define bool2value(b) ((b) ? Qtrue : Qfalse)
|
13
|
+
#define value2bool(v) ((b) ? Qtrue : Qfalse)
|
14
|
+
|
15
|
+
#define get_smbcctx(self) \
|
16
|
+
struct smbcctx *smbcctx; \
|
17
|
+
Data_Get_Struct((self), struct smbcctx, smbcctx);
|
18
|
+
|
19
|
+
static VALUE eRuntimeError;
|
20
|
+
|
21
|
+
/* ====================================================================== */
|
22
|
+
|
23
|
+
static void smbcctx_gc_mark(struct smbcctx *smbcctx)
|
24
|
+
{
|
25
|
+
rb_gc_mark(smbcctx->auth_callback);
|
26
|
+
}
|
27
|
+
|
28
|
+
static void smbcctx_free(struct smbcctx *smbcctx)
|
29
|
+
{
|
30
|
+
smbc_free_context(smbcctx->ctx, 1);
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE rb_smbcctx_alloc(VALUE klass)
|
34
|
+
{
|
35
|
+
struct smbcctx *smbcctx = ALLOC(struct smbcctx);
|
36
|
+
|
37
|
+
memset(smbcctx, 0, sizeof(struct smbcctx));
|
38
|
+
|
39
|
+
/* FIXME: Unset $HOME to ignore $HOME/.smb/smb.conf */
|
40
|
+
smbcctx->ctx = smbc_new_context();
|
41
|
+
if (smbcctx->ctx == NULL) {
|
42
|
+
rb_sys_fail("Cannot create SMBCCTX");
|
43
|
+
}
|
44
|
+
|
45
|
+
smbcctx->auth_callback = Qnil;
|
46
|
+
|
47
|
+
return Data_Wrap_Struct(klass, smbcctx_gc_mark, smbcctx_free, smbcctx);
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE rb_smbcctx_initialize(VALUE self)
|
51
|
+
{
|
52
|
+
get_smbcctx(self);
|
53
|
+
|
54
|
+
smbc_setDebug(smbcctx->ctx, 0);
|
55
|
+
smbc_setOptionDebugToStderr(smbcctx->ctx, (smbc_bool)1);
|
56
|
+
|
57
|
+
return self;
|
58
|
+
}
|
59
|
+
|
60
|
+
static VALUE rb_smbcctx_debug_get(VALUE self)
|
61
|
+
{
|
62
|
+
get_smbcctx(self);
|
63
|
+
|
64
|
+
return INT2NUM(smbc_getDebug(smbcctx->ctx));
|
65
|
+
}
|
66
|
+
|
67
|
+
static VALUE rb_smbcctx_debug_set(VALUE self, VALUE debug)
|
68
|
+
{
|
69
|
+
get_smbcctx(self);
|
70
|
+
|
71
|
+
smbc_setDebug(smbcctx->ctx, NUM2INT(debug));
|
72
|
+
|
73
|
+
return debug;
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE rb_smbcctx_use_kerberos_get(VALUE self)
|
77
|
+
{
|
78
|
+
get_smbcctx(self);
|
79
|
+
|
80
|
+
return smbc_getOptionUseKerberos(smbcctx->ctx) ? Qtrue : Qfalse;
|
81
|
+
}
|
82
|
+
|
83
|
+
static VALUE rb_smbcctx_use_kerberos_set(VALUE self, VALUE flag)
|
84
|
+
{
|
85
|
+
get_smbcctx(self);
|
86
|
+
|
87
|
+
smbc_setOptionUseKerberos(smbcctx->ctx, (smbc_bool)(TRUE_P(flag) ? 1 : 0));
|
88
|
+
|
89
|
+
return flag;
|
90
|
+
}
|
91
|
+
|
92
|
+
/* ====================================================================== */
|
93
|
+
|
94
|
+
void Init_smb(void)
|
95
|
+
{
|
96
|
+
VALUE rb_mNet = rb_define_module("Net");
|
97
|
+
VALUE rb_mSMB = rb_define_module_under(rb_mNet, "SMB");
|
98
|
+
VALUE rb_cSMBCCTX = rb_define_class_under(rb_mNet, "SMBCCTX", rb_cObject);
|
99
|
+
|
100
|
+
rb_define_alloc_func(rb_cSMBCCTX, rb_smbcctx_alloc);
|
101
|
+
rb_define_method(rb_cSMBCCTX, "initialize", rb_smbcctx_initialize, 0);
|
102
|
+
rb_define_method(rb_cSMBCCTX, "debug", rb_smbcctx_debug_get, 0);
|
103
|
+
rb_define_method(rb_cSMBCCTX, "debug=", rb_smbcctx_debug_set, 1);
|
104
|
+
|
105
|
+
//eRuntimeError = rb_define_class_under(mSMB, "Net::SMB::RuntimeError", rb_eRuntimeError);
|
106
|
+
}
|
107
|
+
|
data/net-smb.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "net/smb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "net-smb"
|
7
|
+
s.version = Net::SMB::VERSION
|
8
|
+
s.authors = ["SATOH Fumiyasu"]
|
9
|
+
s.email = ["fumiyas@osstech.co.jp"]
|
10
|
+
s.homepage = "https://github.com/fumiyas/ruby-net-smb"
|
11
|
+
s.summary = %q{SMB/CIFS client}
|
12
|
+
s.description = %q{SMB/CIFS client}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.extensions = `git ls-files -- ext/*.rb`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'net/smb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module Net
|
5
|
+
|
6
|
+
class SMBTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_all
|
14
|
+
smbcctx = Net::SMBCCTX.new
|
15
|
+
p smbcctx.debug
|
16
|
+
smbcctx.debug = 5
|
17
|
+
p smbcctx.debug
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net-smb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SATOH Fumiyasu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: SMB/CIFS client
|
15
|
+
email:
|
16
|
+
- fumiyas@osstech.co.jp
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/net/smb/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Rakefile
|
25
|
+
- ext/net/smb/extconf.rb
|
26
|
+
- ext/net/smb/smb.c
|
27
|
+
- lib/net/smb/version.rb
|
28
|
+
- net-smb.gemspec
|
29
|
+
- test/test_net_smb.rb
|
30
|
+
homepage: https://github.com/fumiyas/ruby-net-smb
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.11
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: SMB/CIFS client
|
54
|
+
test_files:
|
55
|
+
- test/test_net_smb.rb
|