net-smb 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,4 +5,8 @@
5
5
  *.so
6
6
  Gemfile.lock
7
7
  Makefile
8
+ Rakefile.local
9
+ tags
8
10
  pkg/*
11
+ test/log
12
+ test/log.*
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ Ruby Net::SMB 0.0.5 (2013-03-09)
2
+ * Add Net::SMB#xattr, Net::SMB::Dir#xattr, Net::SMB::File#xattr
3
+
1
4
  Ruby Net::SMB 0.0.4 (2013-02-28)
2
5
 
3
6
  * Add Net::SMB::Stat
data/README.md CHANGED
@@ -23,7 +23,7 @@ Development Resources
23
23
  Copyright
24
24
  ----------------------------------------------------------------------
25
25
 
26
- Copyright (C) 2013 SATOH Fumiyas @ OSS Technology Corp., Japan
26
+ Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
27
27
 
28
28
  Licensed under the GNU General Public License version 3
29
29
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
3
  * Common header for Net::SMB
4
- * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
4
+ * Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
5
5
  *
6
6
  * This program is free software; you can redistribute it and/or modify
7
7
  * it under the terms of the GNU General Public License as published by
@@ -112,6 +112,8 @@ void Init_net_smbdir(void);
112
112
  void Init_net_smbdirentry(void);
113
113
  void Init_net_smbfile(void);
114
114
 
115
+ VALUE rb_smb_xattr_get(VALUE self, VALUE url_obj, VALUE name_obj);
116
+
115
117
  #define _RB_SMB_H_
116
118
 
117
119
  #endif /* _RB_SMB_H_ */
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
3
  * Net::SMB class
4
- * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
4
+ * Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
5
5
  *
6
6
  * This program is free software; you can redistribute it and/or modify
7
7
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +23,8 @@
23
23
  VALUE rb_cSMB;
24
24
  VALUE rb_eSMBError;
25
25
 
26
+ static ID id_call;
27
+
26
28
  /* ====================================================================== */
27
29
 
28
30
  static void smbcctx_auth_fn(SMBCCTX *smbcctx,
@@ -43,7 +45,7 @@ static void smbcctx_auth_fn(SMBCCTX *smbcctx,
43
45
  }
44
46
 
45
47
  cred_obj = rb_funcall(data->auth_callback,
46
- rb_intern("call"), 2,
48
+ id_call, 2,
47
49
  rb_str_new2(server),
48
50
  rb_str_new2(share));
49
51
 
@@ -268,6 +270,21 @@ static VALUE rb_smb_open(int argc, VALUE *argv, VALUE self)
268
270
  return smbfile;
269
271
  }
270
272
 
273
+ VALUE rb_smb_xattr_get(VALUE self, VALUE url_obj, VALUE name_obj)
274
+ {
275
+ RB_SMB_DATA_FROM_OBJ(self, data);
276
+ const char *url = RSTRING_PTR(url_obj);
277
+ const char *name = RSTRING_PTR(name_obj);
278
+ char value[1024];
279
+
280
+ smbc_getxattr_fn fn = smbc_getFunctionGetxattr(data->smbcctx);
281
+
282
+ if ((*fn)(data->smbcctx, url, name, value, sizeof(value)) < 0) {
283
+ rb_sys_fail_str(url_obj);
284
+ }
285
+
286
+ return rb_str_new2(value);
287
+ }
271
288
 
272
289
  /* ====================================================================== */
273
290
 
@@ -288,10 +305,13 @@ void Init_net_smb(void)
288
305
  rb_define_method(rb_cSMB, "stat", rb_smb_stat, 1);
289
306
  rb_define_method(rb_cSMB, "opendir", rb_smb_opendir, 1);
290
307
  rb_define_method(rb_cSMB, "open", rb_smb_open, -1);
308
+ rb_define_method(rb_cSMB, "xattr", rb_smb_xattr_get, 2);
291
309
 
292
310
  /* Net::SMB::Error */
293
311
  rb_eSMBError = rb_define_class_under(rb_cSMB, "Error", rb_eStandardError);
294
312
 
313
+ id_call = rb_intern("call");
314
+
295
315
  const char *smbc_ver = smbc_version();
296
316
  int smbc_ver_major = atoi(smbc_ver);
297
317
  int smbc_ver_minor = (smbc_ver = strchr(smbc_ver, '.')) ? atoi(++smbc_ver) : 0;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
3
  * Net::SMB::Dir class
4
- * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
4
+ * Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
5
5
  *
6
6
  * This program is free software; you can redistribute it and/or modify
7
7
  * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,7 @@ static void rb_smbdir_close_by_data(RB_SMBFILE_DATA *data)
41
41
  smbc_closedir_fn fn = smbc_getFunctionClosedir(data->smbcctx);
42
42
 
43
43
  if ((*fn)(data->smbcctx, data->smbcfile) != 0) {
44
- rb_sys_fail("SMBC_closedir_ctx() failed");
44
+ rb_sys_fail(data->url);
45
45
  }
46
46
  }
47
47
 
@@ -94,7 +94,7 @@ static VALUE rb_smbdir_initialize(VALUE self, VALUE smb_obj, VALUE url_obj)
94
94
  fn = smbc_getFunctionOpendir(smb_data->smbcctx);
95
95
  data->smbcfile = (*fn)(smb_data->smbcctx, url);
96
96
  if (data->smbcfile == NULL) {
97
- rb_sys_fail("SMBC_opendir_ctx() failed");
97
+ rb_sys_fail_str(url_obj);
98
98
  }
99
99
 
100
100
  /* FIXME: Take encoding from argument */
@@ -156,6 +156,13 @@ static VALUE rb_smbdir_stat(VALUE self)
156
156
  return rb_class_new_instance(1, &self, rb_cSMBStat);
157
157
  }
158
158
 
159
+ static VALUE rb_smbdir_xattr_get(VALUE self, VALUE name_obj)
160
+ {
161
+ RB_SMBFILE_DATA_FROM_OBJ(self, data);
162
+
163
+ return rb_smb_xattr_get(data->smb_obj, rb_str_new2(data->url), name_obj);
164
+ }
165
+
159
166
  static VALUE rb_smbdir_tell(VALUE self)
160
167
  {
161
168
  RB_SMBFILE_DATA_FROM_OBJ(self, data);
@@ -169,7 +176,7 @@ static VALUE rb_smbdir_tell(VALUE self)
169
176
  offset = (*fn)(data->smbcctx, data->smbcfile);
170
177
  if (offset == (off_t)-1) {
171
178
  if (errno != 0) {
172
- rb_sys_fail("SMBC_telldir_ctx() failed");
179
+ rb_sys_fail(data->url);
173
180
  }
174
181
  }
175
182
 
@@ -187,7 +194,7 @@ static VALUE rb_smbdir_seek(VALUE self, VALUE offset_num)
187
194
 
188
195
  errno = 0;
189
196
  if ((*fn)(data->smbcctx, data->smbcfile, offset) == -1) {
190
- rb_sys_fail("SMBC_lseekdir_ctx() failed");
197
+ rb_sys_fail(data->url);
191
198
  }
192
199
 
193
200
  return self;
@@ -212,7 +219,7 @@ static VALUE rb_smbdir_read(VALUE self)
212
219
 
213
220
  if (smbcdent == NULL) {
214
221
  if (errno) {
215
- rb_sys_fail("SMBC_readdir_ctx() failed");
222
+ rb_sys_fail(data->url);
216
223
  }
217
224
 
218
225
  return Qnil;
@@ -259,6 +266,7 @@ void Init_net_smbdir(void)
259
266
  rb_define_method(rb_cSMBDir, "close", rb_smbdir_close, 0);
260
267
  rb_define_method(rb_cSMBDir, "closed?", rb_smbdir_closed_p, 0);
261
268
  rb_define_method(rb_cSMBDir, "stat", rb_smbdir_stat, 0);
269
+ rb_define_method(rb_cSMBDir, "xattr", rb_smbdir_xattr_get, 1);
262
270
  rb_define_method(rb_cSMBDir, "tell", rb_smbdir_tell, 0);
263
271
  rb_define_alias(rb_cSMBDir, "pos", "tell");
264
272
  rb_define_method(rb_cSMBDir, "seek", rb_smbdir_seek, 1);
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
3
  * Net::SMB::DirEntry class
4
- * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
4
+ * Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
5
5
  *
6
6
  * This program is free software; you can redistribute it and/or modify
7
7
  * it under the terms of the GNU General Public License as published by
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
3
  * Net::SMB::File class
4
- * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
4
+ * Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
5
5
  *
6
6
  * This program is free software; you can redistribute it and/or modify
7
7
  * it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@ static void rb_smbfile_close_by_data(RB_SMBFILE_DATA *data)
42
42
  smbc_close_fn fn = smbc_getFunctionClose(data->smbcctx);
43
43
 
44
44
  if ((*fn)(data->smbcctx, data->smbcfile) != 0) {
45
- rb_sys_fail("SMBC_close_ctx() failed");
45
+ rb_sys_fail(data->url);
46
46
  }
47
47
  }
48
48
 
@@ -86,7 +86,7 @@ static void rb_smbfile_open_by_data(RB_SMBFILE_DATA *data)
86
86
 
87
87
  data->smbcfile = (*fn)(data->smbcctx, data->url, data->oflags, 0);
88
88
  if (data->smbcfile == NULL) {
89
- rb_sys_fail("SMBC_open_ctx() failed");
89
+ rb_sys_fail(data->url);
90
90
  }
91
91
 
92
92
  RB_SMB_DEBUG("smbcctx=%p smbcfile=%p\n", data->smbcctx, data->smbcfile);
@@ -97,7 +97,7 @@ static void rb_smbfile_seek_by_data(RB_SMBFILE_DATA *data)
97
97
  smbc_lseek_fn fn = smbc_getFunctionLseek(data->smbcctx);
98
98
 
99
99
  if ((*fn)(data->smbcctx, data->smbcfile, data->pos, SEEK_SET) == -1) {
100
- rb_sys_fail("SMBC_lseek_ctx() failed");
100
+ rb_sys_fail(data->url);
101
101
  }
102
102
 
103
103
  data->buffer_used_size = 0;
@@ -240,6 +240,13 @@ static VALUE rb_smbfile_stat(VALUE self)
240
240
  return rb_class_new_instance(1, &self, rb_cSMBStat);
241
241
  }
242
242
 
243
+ static VALUE rb_smbfile_xattr_get(VALUE self, VALUE name_obj)
244
+ {
245
+ RB_SMBFILE_DATA_FROM_OBJ(self, data);
246
+
247
+ return rb_smb_xattr_get(data->smb_obj, rb_str_new2(data->url), name_obj);
248
+ }
249
+
243
250
  static VALUE rb_smbfile_pos(VALUE self)
244
251
  {
245
252
  RB_SMBFILE_DATA_FROM_OBJ(self, data);
@@ -265,15 +272,17 @@ static VALUE rb_smbfile_seek(int argc, VALUE *argv, VALUE self)
265
272
  case SEEK_CUR:
266
273
  if (offset < 0 && offset < -data->pos) {
267
274
  errno = EINVAL;
268
- rb_sys_fail("SMBC_lseek_ctx() failed");
275
+ rb_sys_fail(data->url);
269
276
  }
270
277
  data->pos += offset;
271
278
  break;
272
279
  case SEEK_END:
273
- rb_sys_fail("FIXME");
280
+ /* FIXME */
281
+ rb_raise(rb_eNotImpError, "SEEK_END");
274
282
  break;
275
283
  default:
276
- rb_sys_fail("FIXME");
284
+ errno = EINVAL;
285
+ rb_sys_fail(data->url);
277
286
  break;
278
287
  }
279
288
 
@@ -388,6 +397,7 @@ void Init_net_smbfile(void)
388
397
  rb_define_method(rb_cSMBFile, "close", rb_smbfile_close, 0);
389
398
  rb_define_method(rb_cSMBFile, "closed?", rb_smbfile_closed_p, 0);
390
399
  rb_define_method(rb_cSMBFile, "stat", rb_smbfile_stat, 0);
400
+ rb_define_method(rb_cSMBFile, "xattr", rb_smbfile_xattr_get, 1);
391
401
  rb_define_method(rb_cSMBFile, "pos", rb_smbfile_pos, 0);
392
402
  rb_define_alias(rb_cSMBFile, "tell", "pos");
393
403
  rb_define_method(rb_cSMBFile, "seek", rb_smbfile_seek, -1);
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
3
  * Net::SMB::Stat class
4
- * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
4
+ * Copyright (C) 2012-2013 SATOH Fumiyas @ OSS Technology Corp., Japan
5
5
  *
6
6
  * This program is free software; you can redistribute it and/or modify
7
7
  * it under the terms of the GNU General Public License as published by
@@ -70,7 +70,7 @@ static VALUE rb_smbstat_initialize(int argc, VALUE *argv, VALUE self)
70
70
  const char *url = StringValueCStr(url_obj);
71
71
  smbc_stat_fn fn = smbc_getFunctionStat(smb_data->smbcctx);
72
72
  if ((*fn)(smb_data->smbcctx, url, &data->stat)) {
73
- rb_sys_fail("SMBC_stat_ctx() failed");
73
+ rb_sys_fail_str(url_obj);
74
74
  }
75
75
  }
76
76
  else if (rb_obj_is_kind_of(smb_or_file_obj, rb_cSMBFile)) {
@@ -78,7 +78,7 @@ static VALUE rb_smbstat_initialize(int argc, VALUE *argv, VALUE self)
78
78
  smbc_fstat_fn fn = smbc_getFunctionFstat(smbfile_data->smbcctx);
79
79
 
80
80
  if ((*fn)(smbfile_data->smbcctx, smbfile_data->smbcfile, &data->stat)) {
81
- rb_sys_fail("SMBC_fstat_ctx() failed");
81
+ rb_sys_fail(smbfile_data->url);
82
82
  }
83
83
  }
84
84
  else if (rb_obj_is_kind_of(smb_or_file_obj, rb_cSMBDir)) {
@@ -91,12 +91,12 @@ static VALUE rb_smbstat_initialize(int argc, VALUE *argv, VALUE self)
91
91
  smbc_fstatdir_fn fn = smbc_getFunctionFstatdir(smbfile_data->smbcctx);
92
92
 
93
93
  if ((*fn)(smbfile_data->smbcctx, smbfile_data->smbcfile, &data->stat)) {
94
- rb_sys_fail("SMBC_fstatdir_ctx() failed");
94
+ rb_sys_fail(smbfile_data->url);
95
95
  }
96
96
  #else
97
97
  smbc_stat_fn fn = smbc_getFunctionStat(smbfile_data->smbcctx);
98
98
  if ((*fn)(smbfile_data->smbcctx, smbfile_data->url, &data->stat)) {
99
- rb_sys_fail("SMBC_stat_ctx() failed");
99
+ rb_sys_fail(smbfile_data->url);
100
100
  }
101
101
  #endif
102
102
  }
@@ -1,5 +1,5 @@
1
1
  module Net #:nodoc:
2
2
  class SMB #:nodoc:
3
- VERSION = "0.0.4" #:nodoc:
3
+ VERSION = "0.0.5" #:nodoc:
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ cache directory = %$(TEST_SAMBA_VAR_DIR)
6
6
  pid directory = %$(TEST_SAMBA_VAR_DIR)
7
7
  ncalrpc dir = %$(TEST_SAMBA_VAR_DIR)
8
8
 
9
+ netbios name = localhost
9
10
  map to guest = BAD USER
10
11
  stat cache = no
11
12
 
@@ -415,6 +415,24 @@ class SMBTest < Test::Unit::TestCase
415
415
  end
416
416
  end
417
417
 
418
+ def test_smb_xattr
419
+ smb = self.smb
420
+
421
+ owner = "LOCALHOST\\#{@@username}"
422
+
423
+ smb.opendir(@@share_public) do |smbdir|
424
+ while dent = smbdir.read
425
+ next if (dent.name =~ /^\.\.?$/)
426
+ next if (dent.name =~ /\.noaccess$/)
427
+
428
+ assert_equal(owner, smb.xattr(dent.url, 'system.nt_sec_desc.owner+'))
429
+ assert_raise(Errno::EINVAL) do
430
+ assert_equal(owner, smb.xattr(dent.url, 'invalid-xattr-name'))
431
+ end
432
+ end
433
+ end
434
+ end
435
+
418
436
  def test_file_open_read_close
419
437
  smb = self.smb
420
438
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-smb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler