~ubuntu-branches/ubuntu/saucy/libfilesys-smbclient-perl/saucy

« back to all changes in this revision

Viewing changes to .pc/spelling-error-in-pod.patch/SmbClient.pm

  • Committer: Package Import Robot
  • Author(s): Xavier Guimard, gregor herrmann, Nathan Handler, Ansgar Burchardt, Xavier Guimard
  • Date: 2013-01-17 06:17:42 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130117061742-8i0z4k5fhou06ce5
Tags: 3.2-1
[ gregor herrmann ]
* debian/control: Added: ${misc:Depends} to Depends: field.
* debian/control: update {versioned,alternative} (build) dependencies.

[ Nathan Handler ]
* debian/watch: Update to ignore development releases.

[ Ansgar Burchardt ]
* debian/control: Convert Vcs-* fields to Git.

[ Xavier Guimard ]
* Imported Upstream version 3.2
* Update source format to 3.0 (quilt)
* Bump Standards-Version to 3.9.4
* Use debhelper 9.20120312
* Update debian/copyright (years and format)
* Fix upstream license to Artistic or GPL-1+
* Update debian/rules to use "dh $@"
* Add description in 10_Makefile.PL.patch
* Add spelling and pod patch
* Force the use of perl_makemaker in dh
* override_dh_fixperms to change example files mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Filesys::SmbClient;
 
2
 
 
3
# module Filesys::SmbClient : provide function to access Samba filesystem
 
4
# with libsmclient.so
 
5
# Copyright 2000-2012 A.Barbet alian@cpan.org.  All rights reserved.
 
6
 
 
7
# $Log: SmbClient.pm,v $
 
8
# Revision 3.2  2012/12/04 14:49:32  alian
 
9
#
 
10
# release 3.2: implements connection close with smbc_free_context (acca@cpan.org)
 
11
#
 
12
# release 3.1: fix for rt#12221 rt#18757 rt#13173 and bug in configure
 
13
#
 
14
# Revision 3.0  2005/03/04 16:15:00  alian
 
15
# 3.0  2005/03/05 alian
 
16
#  - Update to samba3 API and use SMBCTXX
 
17
#  - Add set_flag method for samba 3.0.11
 
18
#  - Update smb2www-2.cgi to browse workgroup with smb://
 
19
#  - Return 0 not undef at end of file with read/READLINE
 
20
#   (tks to jonathan.segal at genizon.com for report).
 
21
#  - Fix whence bug in seek method (not used before)
 
22
#  - Add some tests for read and seek patched in this version
 
23
#
 
24
# Revision 1.5  2003/11/09 18:28:01  alian
 
25
# Add Copyright section
 
26
#
 
27
# See file CHANGES for others update
 
28
 
 
29
use strict;
 
30
use constant SMBC_WORKGROUP  => 1;
 
31
use constant SMBC_SERVER => 2;
 
32
use constant SMBC_FILE_SHARE => 3;
 
33
use constant SMBC_PRINTER_SHARE => 4;
 
34
use constant SMBC_COMMS_SHARE => 5;
 
35
use constant SMBC_IPC_SHARE =>6;
 
36
use constant SMBC_DIR => 7;
 
37
use constant SMBC_FILE => 8;
 
38
use constant SMBC_LINK => 9;
 
39
use constant MAX_LENGTH_LINE => 4096;
 
40
use constant SMB_CTX_FLAG_USE_KERBEROS => (1 << 0);
 
41
use constant SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS => (1 << 1);
 
42
use constant SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON => (1 << 2);
 
43
 
 
44
use vars qw($AUTOLOAD $VERSION @ISA @EXPORT);
 
45
require Exporter;
 
46
require DynaLoader;
 
47
require AutoLoader;
 
48
use POSIX 'SEEK_SET';
 
49
 
 
50
use Tie::Handle;
 
51
my $DEBUG = 0;
 
52
 
 
53
@ISA = qw(Exporter DynaLoader Tie::Handle);
 
54
@EXPORT = qw(SMBC_DIR SMBC_WORKGROUP SMBC_SERVER SMBC_FILE_SHARE
 
55
             SMBC_PRINTER_SHARE SMBC_COMMS_SHARE SMBC_IPC_SHARE SMBC_FILE
 
56
             SMBC_LINK _write _open _close _read _lseek 
 
57
             SMB_CTX_FLAG_USE_KERBEROS SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS
 
58
             SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON);
 
59
$VERSION = ('$Revision: 3.2 $ ' =~ /(\d+\.\d+)/)[0];
 
60
 
 
61
bootstrap Filesys::SmbClient $VERSION;
 
62
 
 
63
my %commandes =
 
64
  (
 
65
   "close"            => \&_close,
 
66
   "closedir"         => \&_closedir,
 
67
   "fstat"            => \&_fstat,
 
68
   "opendir"          => \&_opendir,
 
69
   "print_file"       => \&_print_file,
 
70
   "stat"             => \&_stat,
 
71
   "rename"           => \&_rename,
 
72
   "rmdir"            => \&_rmdir,
 
73
   "unlink"           => \&_unlink,
 
74
   "unlink_print_job" => \&_unlink_print_job,
 
75
  );
 
76
 
 
77
#------------------------------------------------------------------------------
 
78
# AUTOLOAD
 
79
#------------------------------------------------------------------------------
 
80
sub AUTOLOAD  {
 
81
  my $self =shift;
 
82
  my $attr = $AUTOLOAD;
 
83
  $attr =~ s/.*:://;
 
84
  return unless $attr =~ /[^A-Z]/;
 
85
  die "Method undef ->$attr()\n" unless defined($commandes{$attr});
 
86
  return $commandes{$attr}->($self->{context}, @_);
 
87
}
 
88
 
 
89
#------------------------------------------------------------------------------
 
90
# TIEHANDLE
 
91
#------------------------------------------------------------------------------
 
92
sub TIEHANDLE {
 
93
  require 5.005_64;
 
94
  my ($class,$fn,$mode,@args) = @_;
 
95
  $mode = '0666' if (!$mode);
 
96
  my $self = new($class, @args);
 
97
  print "Filesys::SmbClient TIEHANDLE\n" if ($DEBUG);
 
98
  if ($fn) {
 
99
    $self->{FD} = _open($self->{context}, $fn, $mode) or return undef; }
 
100
  return $self;
 
101
}
 
102
 
 
103
#------------------------------------------------------------------------------
 
104
# OPEN
 
105
#------------------------------------------------------------------------------
 
106
sub OPEN {
 
107
  my ($class,$fn,$mode) = @_;
 
108
  $mode = '0666' if (!$mode);
 
109
  print "OPEN\n"  if ($DEBUG);
 
110
  $class->{FD} = _open($class->{context}, $fn, $mode) or return undef;
 
111
  $class;
 
112
}
 
113
 
 
114
#------------------------------------------------------------------------------
 
115
# FILENO
 
116
#------------------------------------------------------------------------------
 
117
sub FILENO {
 
118
  my $class = shift;
 
119
  return $class->{FD};
 
120
}
 
121
 
 
122
#------------------------------------------------------------------------------
 
123
# WRITE
 
124
#------------------------------------------------------------------------------
 
125
sub WRITE {
 
126
  my ($self,$buffer,$length,$offset) = @_;
 
127
  print "Filesys::SmbClient WRITE\n"  if ($DEBUG);
 
128
  $buffer = substr($buffer,0,$length) if ($length);
 
129
  SEEK($self,$offset, SEEK_SET) if ($offset);
 
130
  my $lg = _write($self->{context}, $self->{FD}, $buffer, $length);
 
131
  return ($lg == -1) ? undef : $lg;
 
132
}
 
133
 
 
134
#------------------------------------------------------------------------------
 
135
# SEEK
 
136
#------------------------------------------------------------------------------
 
137
sub SEEK {
 
138
  my ($self,$offset,$whence) = @_;
 
139
  print "Filesys::SmbClient SEEK\n"  if ($DEBUG);
 
140
  return _lseek($self->{context}, $self->{FD}, $offset, $whence);
 
141
}
 
142
 
 
143
#------------------------------------------------------------------------------
 
144
# READ
 
145
#------------------------------------------------------------------------------
 
146
sub READ {
 
147
  my $self = shift;
 
148
  print "Filesys::SmbClient READ\n" if ($DEBUG);
 
149
  my $buf = \$_[0];
 
150
  my $lg = ($_[1] ? $_[1] : MAX_LENGTH_LINE);
 
151
  # 
 
152
  defined($$buf = _read($self->{context}, $self->{FD}, $lg)) or return undef;
 
153
#  $$buf = _read($self->{context}, $self->{FD}, $lg) or return undef;
 
154
  return length($$buf);
 
155
}
 
156
 
 
157
#------------------------------------------------------------------------------
 
158
# READLINE
 
159
#------------------------------------------------------------------------------
 
160
sub READLINE {
 
161
  my $self = shift;
 
162
  print "Filesys::SmbClient READLINE\n" if ($DEBUG);
 
163
  # Check if we have \n on old string
 
164
  my $buf = $self->{_BUFFER};
 
165
  if ($buf && $buf=~m!^([^\n]*\n)(.*)$!ms) {
 
166
    print "Gave ->$1<- and take ->$2<-\n" if ($self->{params}->{debug});
 
167
    my $p = $1;
 
168
    $self->{_BUFFER} = $2;
 
169
    return wantarray() ? ($p,$self->READLINE) : $p;
 
170
  }
 
171
  # Read while we haven't \n or eof
 
172
  my $part;
 
173
  READ($self,$part,MAX_LENGTH_LINE);
 
174
  while ($part and $part!~m!\n!ms and $self->{_FD}) {
 
175
    $buf.=$part;
 
176
    $part = $self->read($self->{_FD}, @_);
 
177
  }
 
178
  $buf.= $part if ($part);
 
179
  # eof
 
180
  return (wantarray() ? "" : undef) if (!$buf);
 
181
  # Return first line and save rest in $self->{_BUFFER}
 
182
  if ($buf=~m!^([^\n]*\n)(.*)$!ms) {
 
183
    print "Give ->$1<- and take ->$2<-\n" if ($self->{params}->{debug});
 
184
    $self->{_BUFFER} = $2;
 
185
    return wantarray() ? ($1,$self->READLINE) : $1;
 
186
  }
 
187
  undef $self->{_BUFFER};
 
188
  return wantarray() ? ($buf,$self->READLINE) : $buf;
 
189
}
 
190
 
 
191
#------------------------------------------------------------------------------
 
192
# GETC
 
193
#------------------------------------------------------------------------------
 
194
sub GETC {
 
195
  my $self = shift;
 
196
  my $c;
 
197
  print "Filesys::SmbClient GETC\n" if ($DEBUG);
 
198
  if ($self->{_BUFFER}) {
 
199
    print "Filesys::SmbClient GETC using $self->{_BUFFER}\n" 
 
200
      if ($self->{params}->{debug});
 
201
    $c = substr($self->{_BUFFER},0,1);
 
202
    $self->{_BUFFER} = substr($self->{_BUFFER},1);
 
203
    return $c;
 
204
  }
 
205
  READ($self,$c,1) or return undef;
 
206
  return $c;
 
207
}
 
208
 
 
209
#------------------------------------------------------------------------------
 
210
# CLOSE
 
211
#------------------------------------------------------------------------------
 
212
sub CLOSE {
 
213
  my $self = shift;
 
214
  print "Filesys::SmbClient CLOSE\n" if ($DEBUG);
 
215
  _close($self->{context}, $self->{FD});
 
216
}
 
217
 
 
218
#------------------------------------------------------------------------------
 
219
# UNTIE
 
220
#------------------------------------------------------------------------------
 
221
sub UNTIE {
 
222
  require 5.005_64;
 
223
  my $self=shift;
 
224
  print "Filesys::SmbClient UNTIE\n" if ($DEBUG);
 
225
  CLOSE($self);
 
226
  undef($self->{_BUFFER});
 
227
}
 
228
 
 
229
#------------------------------------------------------------------------------
 
230
# new
 
231
#------------------------------------------------------------------------------
 
232
sub new   {
 
233
  my $class = shift;
 
234
  my $self = {};
 
235
  my @l; 
 
236
  bless $self, $class;
 
237
  my %vars;
 
238
  if (@_) {
 
239
    %vars =@_;
 
240
    if (!$vars{'workgroup'}) { $vars{'workgroup'}=""; }
 
241
    if (!$vars{'username'})  { $vars{'username'}=""; }
 
242
    if (!$vars{'password'})  { $vars{'password'}=""; }
 
243
    if (!$vars{'debug'})     { $vars{'debug'}=0; }
 
244
    push(@l, $vars{'username'});
 
245
    push(@l, $vars{'password'});
 
246
    push(@l, $vars{'workgroup'});
 
247
    push(@l, $vars{'debug'});
 
248
    print "Filesys::SmbClient new>",join(" ", @l),"\n" if $vars{'debug'};
 
249
    $self->{params}= \%vars;
 
250
  }
 
251
  else { @l =("","","",0); }
 
252
  # Here is a temporary hack:
 
253
  # Actually libsmbclient will segfault if it can't find file
 
254
  # $ENV{HOME}/.smb/smb.conf so I will test if it exist,
 
255
  # and create it if no file is found. A empty file is enough ...
 
256
  # In cgi environnement, $ENV{HOME} can be unset because
 
257
  # nobody is not a real user. So I will set $ENV{HOME} to dir /tmp
 
258
  if (!$ENV{HOME}) {$ENV{HOME}="/tmp";}
 
259
  if (!-e "$ENV{HOME}/.smb/smb.conf") {
 
260
    print STDERR "you don't have a $ENV{HOME}/.smb/smb.conf, ",
 
261
      "I will create it (empty file)\n";
 
262
    mkdir "$ENV{HOME}/.smb",0755 unless (-e "$ENV{HOME}/.smb");
 
263
    open(F,">$ENV{HOME}/.smb/smb.conf") || 
 
264
      die "Can't create $ENV{HOME}/.smb/smb.conf : $!\n";
 
265
    close(F);
 
266
  }
 
267
  # End of temporary hack
 
268
 
 
269
  $self->{context} = _init(@l);
 
270
  $vars{'flags'} && _set_flags($self->{context}, $vars{'flags'});
 
271
  die 'You must have a samba configuration file '.
 
272
    '($HOME/.smb/smb.conf , even if it is empty' unless $self->{context};
 
273
  return $self;
 
274
}
 
275
 
 
276
#------------------------------------------------------------------------------
 
277
# set_flag
 
278
#------------------------------------------------------------------------------
 
279
sub set_flag {
 
280
  my $self = shift;
 
281
  my $flag = shift;
 
282
  _set_flags($self->{context}, $flag);
 
283
}
 
284
 
 
285
 
 
286
#------------------------------------------------------------------------------
 
287
# readdir_struct
 
288
#------------------------------------------------------------------------------
 
289
sub readdir_struct  {
 
290
  my $self=shift;
 
291
  if (wantarray()) {
 
292
    my @tab;
 
293
    while (my @l  = _readdir($self->{context}, $_[0])) { push(@tab,\@l); }
 
294
    return @tab;
 
295
  } else {
 
296
    my @l = _readdir($self->{context}, $_[0]);
 
297
    return \@l if (@l);
 
298
  }
 
299
}
 
300
 
 
301
#------------------------------------------------------------------------------
 
302
# readdir
 
303
#------------------------------------------------------------------------------
 
304
sub readdir {
 
305
  my $self=shift;
 
306
  if (wantarray()) {
 
307
    my @tab;
 
308
    while (my @l  = _readdir($self->{context}, $_[0])) { push(@tab,$l[1]);}
 
309
    return @tab;
 
310
  } else {
 
311
    my @l =_readdir($self->{context}, $_[0]);
 
312
    return $l[1];
 
313
  }
 
314
}
 
315
 
 
316
#------------------------------------------------------------------------------
 
317
# open
 
318
#------------------------------------------------------------------------------
 
319
sub open  {
 
320
  my ($self,$file,$perms)=@_;
 
321
  $perms = '0666' if (!$perms);
 
322
  $self->{_FD} = _open($self->{context}, $file, $perms);
 
323
  print "Filesys::SmbClient open <$self->{_FD}>\n" 
 
324
    if ($self->{params}->{debug});
 
325
  return $self->{_FD};
 
326
}
 
327
 
 
328
#------------------------------------------------------------------------------
 
329
# seek
 
330
#------------------------------------------------------------------------------
 
331
sub seek {
 
332
  my ($self,$fd,$offset,$whence) = @_;
 
333
  return -1 if ($fd == -1);
 
334
  print "Filesys::SmbClient seek\n" if ($self->{params}->{debug});
 
335
  $whence = SEEK_SET if (!$whence);
 
336
  warn "Whence diff from SEEK_SET not implemented in smb"
 
337
    if ($whence ne SEEK_SET);
 
338
  return _lseek($self->{context}, $fd, $offset, SEEK_SET);
 
339
}
 
340
 
 
341
#------------------------------------------------------------------------------
 
342
# write
 
343
#------------------------------------------------------------------------------
 
344
sub write  {
 
345
  my $self = shift;
 
346
  my $fd = shift;
 
347
  print "Filesys::SmbClient write ".$self.' '.$fd.' '.join(" ",@_)."\n"
 
348
    if ($self->{params}->{debug});
 
349
  my $buffer = join("",@_);
 
350
  return _write($self->{context}, $fd, $buffer, length($buffer));
 
351
}
 
352
 
 
353
#------------------------------------------------------------------------------
 
354
# read
 
355
#------------------------------------------------------------------------------
 
356
sub read  {
 
357
  my ($self,$fd,$lg)=@_;
 
358
  $lg = MAX_LENGTH_LINE if (!$lg);
 
359
  return _read($self->{context}, $fd, $lg);
 
360
}
 
361
 
 
362
#------------------------------------------------------------------------------
 
363
# mkdir
 
364
#------------------------------------------------------------------------------
 
365
sub mkdir  {
 
366
  my ($self,$dir,$mode)=@_;
 
367
  $mode = '0755' if (!$mode);
 
368
  return _mkdir($self->{context}, $dir, $mode);
 
369
}
 
370
 
 
371
#------------------------------------------------------------------------------
 
372
# rmdir_recurse
 
373
#------------------------------------------------------------------------------
 
374
sub rmdir_recurse  {
 
375
  my $self=shift;
 
376
  my $url = shift;
 
377
  my $fd = $self->opendir($url) || return undef;
 
378
  my @f = $self->readdir_struct($fd);
 
379
  $self->closedir($fd);
 
380
  foreach my $v (@f) {
 
381
    next if ($v->[1] eq '.' or $v->[1] eq '..');
 
382
    my $u = $url."/".$v->[1];
 
383
    if ($v->[0] == SMBC_FILE) { $self->unlink($u); }
 
384
    elsif ($v->[0] == SMBC_DIR) { $self->rmdir_recurse($u); }
 
385
  }
 
386
  return $self->rmdir($url);
 
387
}
 
388
 
 
389
#------------------------------------------------------------------------------
 
390
# shutdown
 
391
#------------------------------------------------------------------------------
 
392
sub shutdown  {
 
393
  my ($self, $flag)=@_;
 
394
  return _shutdown($self->{context}, $flag);
 
395
}
 
396
 
 
397
1;
 
398
 
 
399
__END__
 
400
 
 
401
#------------------------------------------------------------------------------
 
402
 
 
403
=pod
 
404
 
 
405
=head1 NAME
 
406
 
 
407
Filesys::SmbClient - Interface for access Samba filesystem with libsmclient.so
 
408
 
 
409
=head1 SYNOPSIS
 
410
 
 
411
  use POSIX;
 
412
  use Filesys::SmbClient;
 
413
  
 
414
  my $smb = new Filesys::SmbClient(username  => "alian",
 
415
                                   password  => "speed",
 
416
                                   workgroup => "alian",
 
417
                                   debug     => 10);
 
418
  
 
419
  # Read a file
 
420
  my $fd = $smb->open("smb://jupiter/doc/general.css", '0666');
 
421
  while (defined(my $l= $smb->read($fd,50))) {print $l; }
 
422
  $smb->close(fd);
 
423
  
 
424
  # ...
 
425
 
 
426
See section EXAMPLE for others scripts.
 
427
 
 
428
=head1 DESCRIPTION
 
429
 
 
430
Provide interface to access routine defined in libsmbclient.so provided with
 
431
Samba.
 
432
 
 
433
Since 3.0 release of this package, you need a least samba-3.0.2.
 
434
For prior release of Samba, use Filesys::SmbClient version 1.x.
 
435
 
 
436
For old and 2.x release, this library is available on Samba source, but is not
 
437
build by default.
 
438
Do "make bin/libsmbclient.so" in sources directory of Samba to build 
 
439
this libraries. Then copy source/include/libsmbclient.h to
 
440
/usr/local/samba/include and source/bin/libsmbclient.so to
 
441
/usr/local/samba/lib before install this module.
 
442
 
 
443
If you want to use filehandle with this module, you need Perl 5.6 or later.
 
444
 
 
445
When a path is used, his scheme is :
 
446
 
 
447
  smb://server/share/rep/doc
 
448
 
 
449
=head1 VERSION
 
450
 
 
451
$Revision: 3.2 $
 
452
 
 
453
=head1 FONCTIONS
 
454
 
 
455
=over
 
456
 
 
457
=item new %hash
 
458
 
 
459
Init connection
 
460
Hash can have this keys:
 
461
 
 
462
=over
 
463
 
 
464
=item *
 
465
 
 
466
username
 
467
 
 
468
=item *
 
469
 
 
470
password
 
471
 
 
472
=item *
 
473
 
 
474
workgroup
 
475
 
 
476
=item *
 
477
 
 
478
debug
 
479
 
 
480
=item *
 
481
 
 
482
flags : See set_flag
 
483
 
 
484
=back
 
485
 
 
486
Return instance of Filesys::SmbClient on succes, die with error else.
 
487
 
 
488
Example:
 
489
 
 
490
  my $smb = new Filesys::SmbClient(username  => "alian",
 
491
                                   password  => "speed", 
 
492
                                   workgroup => "alian",
 
493
                                   debug     => 10);
 
494
 
 
495
 
 
496
=item set_flag
 
497
 
 
498
Set flag for smb connection. See _SMBCCTX->flags in libsmclient.h
 
499
Flag can be:
 
500
 
 
501
=over
 
502
 
 
503
=item SMB_CTX_FLAG_USE_KERBEROS
 
504
 
 
505
=item SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS
 
506
 
 
507
=item SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON
 
508
 
 
509
=back
 
510
 
 
511
=back
 
512
 
 
513
=head2 Tie Filesys::SmbClient filehandle
 
514
 
 
515
This didn't work before 5.005_64. Why, I don't know.
 
516
When you have tied a filehandle with Filesys::SmbClient,
 
517
you can call classic methods for filehandle:
 
518
print, printf, seek, syswrite, getc, open, close, read.
 
519
See perldoc for usage.
 
520
 
 
521
Example:
 
522
 
 
523
  local *FD;
 
524
  tie(*FD, 'Filesys::SmbClient');
 
525
  open(FD,"smb://jupiter/doc/test")
 
526
    or print "Can't open file:", $!, "\n";
 
527
  while(<FD>) { print $_; }
 
528
  close(FD);
 
529
 
 
530
or
 
531
 
 
532
  local *FD;
 
533
  tie(*FD, 'Filesys::SmbClient');
 
534
  open(FD,">smb://jupiter/doc/test")
 
535
    or print "Can't create file:", $!, "\n";
 
536
  print FD "Samba test","\n";
 
537
  printf FD "%s", "And that work !\n";
 
538
  close(FD);
 
539
 
 
540
 
 
541
=head2 Directory
 
542
 
 
543
=over
 
544
 
 
545
=item mkdir FILENAME, MODE
 
546
 
 
547
Create directory $fname with permissions set to $mode.
 
548
Return 1 on success, else 0 is return and errno and $! is set.
 
549
 
 
550
Example:
 
551
 
 
552
  $smb->mkdir("smb://jupiter/doc/toto",'0666') 
 
553
    or print "Error mkdir: ", $!, "\n";
 
554
 
 
555
=item rmdir FILENAME
 
556
 
 
557
Erase directory $fname. Return 1 on success, else 0 is return
 
558
and errno and $! is set. ($fname must be empty, else see 
 
559
rmdir_recurse).
 
560
 
 
561
Example:
 
562
 
 
563
  $smb->rmdir("smb://jupiter/doc/toto")
 
564
    or print "Error rmdir: ", $!, "\n";
 
565
 
 
566
=item rmdir_recurse FILENAME
 
567
 
 
568
Erase directory $fname. Return 1 on success, else 0 is return
 
569
and errno and $! is set. Il $fname is not empty, all files and
 
570
dir will be deleted.
 
571
 
 
572
Example:
 
573
 
 
574
  $smb->rmdir_recurse("smb://jupiter/doc/toto")
 
575
    or print "Error rmdir_recurse: ", $!, "\n";
 
576
 
 
577
=item opendir FILENAME
 
578
 
 
579
Open directory $fname. Return file descriptor on succes, else 0 is
 
580
return and $! is set.
 
581
 
 
582
=item readdir FILEHANDLE
 
583
 
 
584
Read a directory. In a list context, return the full content of
 
585
the directory $fd, else return next element. Each elem is
 
586
a name of a directory or files.
 
587
 
 
588
Return undef at end of directory.
 
589
 
 
590
Example:
 
591
 
 
592
  my $fd = $smb->opendir("smb://jupiter/doc");
 
593
  foreach my $n ($smb->readdir($fd)) {print $n,"\n";}
 
594
  close($fd);
 
595
 
 
596
=item readdir_struct FILEHANDLE
 
597
 
 
598
Read a directory. In a list context, return the full content of
 
599
the directory FILEHANDLE, else return next element. Each element
 
600
is a ref to an array with type, name and comment. Type can be :
 
601
 
 
602
=over
 
603
 
 
604
=item SMBC_WORKGROUP
 
605
 
 
606
=item SMBC_SERVER
 
607
 
 
608
=item SMBC_FILE_SHARE
 
609
 
 
610
=item SMBC_PRINTER_SHARE
 
611
 
 
612
=item SMBC_COMMS_SHARE
 
613
 
 
614
=item SMBC_IPC_SHARE
 
615
 
 
616
=item SMBC_DIR
 
617
 
 
618
=item SMBC_FILE
 
619
 
 
620
=item SMBC_LINK
 
621
 
 
622
=back
 
623
 
 
624
Return undef at end of directory.
 
625
 
 
626
Example:
 
627
 
 
628
  my $fd = $smb->opendir("smb://jupiter/doc");
 
629
  while (my $f = $smb->readdir_struct($fd)) {
 
630
    if ($f->[0] == SMBC_DIR) {print "Directory ",$f->[1],"\n";}
 
631
    elsif ($f->[0] == SMBC_FILE) {print "File ",$f->[1],"\n";}
 
632
    # ...
 
633
  }
 
634
  close($fd);
 
635
 
 
636
=item closedir FILEHANDLE
 
637
 
 
638
Close directory $fd.
 
639
 
 
640
=back
 
641
 
 
642
=head2 Files
 
643
 
 
644
=over
 
645
 
 
646
=item stat FILENAME
 
647
 
 
648
Stat a file FILENAME. Return a list with info on success,
 
649
else an empty list is return and $! is set.
 
650
 
 
651
List is made with:
 
652
 
 
653
=over
 
654
 
 
655
=item *
 
656
 
 
657
device
 
658
 
 
659
=item *
 
660
 
 
661
inode
 
662
 
 
663
=item *
 
664
 
 
665
protection
 
666
 
 
667
=item *
 
668
 
 
669
number of hard links
 
670
 
 
671
=item *
 
672
 
 
673
user ID of owner
 
674
 
 
675
=item *
 
676
 
 
677
group ID of owner
 
678
 
 
679
=item *
 
680
 
 
681
device type (if inode device)
 
682
 
 
683
=item *
 
684
 
 
685
total size, in bytes
 
686
 
 
687
=item *
 
688
 
 
689
blocksize for filesystem I/O
 
690
 
 
691
=item *
 
692
 
 
693
number of blocks allocated
 
694
 
 
695
=item *
 
696
 
 
697
time of last access
 
698
 
 
699
=item *
 
700
 
 
701
time of last modification
 
702
 
 
703
=item *
 
704
 
 
705
time of last change
 
706
 
 
707
=back
 
708
 
 
709
Example:
 
710
 
 
711
  my @tab = $smb->stat("smb://jupiter/doc/tata");
 
712
  if ($#tab == 0) { print "Erreur in stat:", $!, "\n"; }
 
713
  else {
 
714
    for (10..12) {$tab[$_] = localtime($tab[$_]);}
 
715
    print join("\n",@tab);
 
716
  }
 
717
 
 
718
=item fstat FILEHANDLE
 
719
 
 
720
Like stat, but on a file handle
 
721
 
 
722
=item rename OLDNAME,NEWNAME
 
723
 
 
724
Changes the name of a file; an existing file NEWNAME will be clobbered.
 
725
Returns true for success, false otherwise, with $! set.
 
726
 
 
727
Example:
 
728
 
 
729
  $smb->rename("smb://jupiter/doc/toto","smb://jupiter/doc/tata")
 
730
    or print "Can't rename file:", $!, "\n";
 
731
 
 
732
=item unlink FILENAME
 
733
 
 
734
Unlink FILENAME. Return 1 on success, else 0 is return
 
735
and errno and $! is set.
 
736
 
 
737
Example:
 
738
 
 
739
  $smb->unlink("smb://jupiter/doc/test") 
 
740
    or print "Can't unlink file:", $!, "\n";
 
741
 
 
742
 
 
743
=item open FILENAME
 
744
 
 
745
=item open FILENAME, MODE
 
746
 
 
747
Open file $fname with perm $mode. Return file descriptor
 
748
on success, else 0 is return and $! is set.
 
749
 
 
750
Example:
 
751
 
 
752
  my $fd = $smb->open("smb://jupiter/doc/test", 0666) 
 
753
    or print "Can't read file:", $!, "\n";
 
754
  
 
755
  my $fd = $smb->open(">smb://jupiter/doc/test", 0666) 
 
756
    or print "Can't create file:", $!, "\n";
 
757
  
 
758
  my $fd = $smb->open(">>smb://jupiter/doc/test", 0666) 
 
759
    or print "Can't append to file:", $!, "\n";
 
760
 
 
761
=item read FILEHANDLE
 
762
 
 
763
=item read FILEHANDLE, LENGTH
 
764
 
 
765
Read $count bytes of data on file descriptor $fd. It lenght is not set,
 
766
4096 bytes will be read.
 
767
 
 
768
Return buffer read on success, undef at end of file,
 
769
-1 is return on error and $! is set.
 
770
 
 
771
FILEHANDLE must be open with open of this module.
 
772
 
 
773
=item write FILEHANDLE, $buf
 
774
 
 
775
=item write FILEHANDLE, @buf
 
776
 
 
777
Write $buf or @buf on file descriptor $fd.
 
778
Return number of bytes wrote, else -1 is return and errno and $! is set.
 
779
 
 
780
Example:
 
781
 
 
782
  my $fd = $smb->open(">smb://jupiter/doc/test", 0666) 
 
783
    or print "Can't create file:", $!, "\n";
 
784
  $smb->write($fd, "A test of write call") 
 
785
    or print $!,"\n";
 
786
  $smb->close($fd);
 
787
 
 
788
FILEHANDLE must be open with open of this module.
 
789
 
 
790
=item seek FILEHANDLE, POS
 
791
 
 
792
Sets FILEHANDLE's position, just like the "fseek"
 
793
call of "stdio".  FILEHANDLE may be an expression
 
794
whose value gives the name of the filehandle.  The
 
795
values for WHENCE is always SEEK_SET beacause others
 
796
didn't work on libsmbclient.so
 
797
 
 
798
FILEHANDLE must be open with open of this module.
 
799
 
 
800
=item close FILEHANDLE
 
801
 
 
802
Close file FILEHANDLE. Return 0 on success, else -1 is return and
 
803
errno and $! is set.
 
804
 
 
805
=back
 
806
 
 
807
=item shutdown flag
 
808
 
 
809
A wrapper around `libsmbclient's `smbc_free_context'.
 
810
 
 
811
Close open files, release Samba connection, delete context,
 
812
aquired during open_* calls.
 
813
 
 
814
Example:
 
815
 
 
816
    $smb->shutdown(0); # Gracefully close connection
 
817
    $sbm->shutdown(1); # Forcibly close files and connection
 
818
 
 
819
NOTE:
 
820
    shutdown(1) may cause complaints about talloc memory
 
821
    leaks, if there are currently no open files.
 
822
 
 
823
=head2 Print method
 
824
 
 
825
=over
 
826
 
 
827
=item unlink_print_job PRINTER_URL, IDJOB
 
828
 
 
829
Remove job number IDJOB on printer PRINTER_URL
 
830
 
 
831
=item print_file DOCUMENT_URL, PRINTER_URL
 
832
 
 
833
Print file DOCUMENT_URL on PRINTER_URL
 
834
 
 
835
=back
 
836
 
 
837
=head1 TODO
 
838
 
 
839
=over 
 
840
 
 
841
=item *
 
842
 
 
843
chown
 
844
 
 
845
=item *
 
846
 
 
847
chmod
 
848
 
 
849
=item *
 
850
 
 
851
open_print_job
 
852
 
 
853
=item *
 
854
 
 
855
telldir
 
856
 
 
857
=item *
 
858
 
 
859
lseekdir
 
860
 
 
861
=back
 
862
 
 
863
=head1 EXAMPLE
 
864
 
 
865
This module come with some scripts:
 
866
 
 
867
=over
 
868
 
 
869
=item t/*.t
 
870
 
 
871
Just for check that this module is ok :-)
 
872
 
 
873
=item smb2www-2.cgi
 
874
 
 
875
A CGI interface with these features:
 
876
 
 
877
=over
 
878
 
 
879
=item *
 
880
 
 
881
browse workgroup ,share, dir
 
882
 
 
883
=item *
 
884
 
 
885
read file
 
886
 
 
887
=item *
 
888
 
 
889
upload file
 
890
 
 
891
=item *
 
892
 
 
893
create directory
 
894
 
 
895
=item *
 
896
 
 
897
unlink file, directory
 
898
 
 
899
=back
 
900
 
 
901
=back
 
902
 
 
903
=head1 COPYRIGHT
 
904
 
 
905
The Filesys-SmbClient module is Copyright (c) 1999-2003 Alain BARBET, France,
 
906
alian at cpan.org. All rights reserved.
 
907
 
 
908
You may distribute under the terms of either the GNU General
 
909
Public License or the Artistic License, as specified
 
910
in the Perl README file.
 
911
 
 
912
=cut