No subject

John Blair jdblair at uab.edu
Mon Oct 13 02:59:34 GMT 1997


Hello,

I tried to post this to the samba list twice already, but it doesn't seem
to have shown up either time.  Posts I made after it have already showed
up, so it must be something about the message itself.  I suspect that the
list processor may limit the size of messages, so this message won't have
any attachements.

Now that I've got that out of the way, I've made some minor modifications
to smbclient to add some features that I thought were missing.  I wondered
if anybody else would be willing to try out this patch and let me know if
you find any bugs.

Here's what I've added:
1) You can now pass 'userid%passwd' syntax in the USER environmental  variable.
2) You can pass the SMB password in the SMBPASSWD environmental  variable.

This two additions avoid the need to pass a password on the command line
(where anybody else can potentially see them) in scripted processes.  Call
me paranoid, but I like to avoid doing that.

3) Support for writing a stream (right now from standard input, but could
be other streams in the future) directly to a file on the remote SMB server.

This last option is similar to the ability of the print command to accept
input from standard input.  It uses the same '-' syntax to represent
standard input.

Here's an example:

ls | smbclient '\\SOMEHOST\SOMESHARE' -N -c 'put - ls.txt'

If the USER and SMBPASSWD environmental variables are set correctly, this
command will write the output of the ls command to the file ls.txt on the
remote share.

Here's an example using perl:

$ENV{'SMBPASSWD'} = "xxxxxx";
$ENV{'USER'} = "someuser";

open(SMB, "|smbclient '\\\\SOMEHOST\\SOMESHARE' -N -c 'put -
somefile.txt'");
print SMB "this is a sample script\r\n";
print SMB "arbitrary data could be sent here\r\n";
close(SMB);

Obviosly, that's not as graceful as writing a perl module to use abstracted
file handles, or using a true smb filesystem.  However, it works on any
system smbclient compiles on, and it was easy.

Internally I implemented the standard input put feature by adding a new
function called 'do_put_stream'.  This is really just the original do_put
code with some modifications to work with an arbitrary length stream rather
than a fixed length file.  The 'do_put' command now just opens a file
(generating errors if necessary) and calls 'do_put_stream'.  You can find
my modifications quickly by searching for 'jdblair'.

All-in-all this syntax was easy to add to smbclient.  I was actually a
little surprised when I noticed that 'put - somefile' wouldn't work-- it
seemed natural, especially after I learned that 'print -' prints the
standard input and 'get rmtfile -' outputs the remote file in the standard
output.  I like it because it eliminates the need to save script output to
a local file before copying it to a remote computer.  Granted, this is not
a lot of overhead-- call me a perfectionist.

The context diff patch file can be retrieved from
ftp://frodo.tucc.uab.edu/pub/samba/client.c.patch .
It will patch the client.c file.  I wrote it using the source code from
version 1.9.17p2.  The patch may apply to earlier versions, but do so at
your own risk.

Also... is there a process for submitting code to the Samba project?  If
other people don't find problems (or if they find problems and they are
fixed) I'd like to see this included in future distributions (or I'll have
to keep patching smbclient, since I have scripts that rely on my mods!).

later,
 -john.

......................................................................
.                                                                    .
.....John.D.Blair...   mailto:jdblair at uab.edu   phoneto:205.975.7123 .
                   .   http://frodo.tucc.uab.edu  faxto:205.975.7129 .
 ..sys|net.admin....                                                 .
 .                     the university computer center            .....
 ..... g.e.e.k.n.i.k...the.university.of.alabama.at.birmingham....




More information about the samba mailing list