- Initial import into sourceforge.net CVS.

git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/amiga-smbfs/trunk@3 26594b9e-b914-4e86-b7a1-9402bd427170
This commit is contained in:
Olaf Barthel
2005-05-24 13:22:14 +00:00
parent 6de34efe12
commit ed8def5209
25 changed files with 14862 additions and 0 deletions
+563
View File
@@ -0,0 +1,563 @@
smbfs 1.19 (27.11.2000)
- Fixed ACTION_FINDOUTPUT implementation; the memory to hold the
name of the file to be created was released before the file
was created. This could cause garbage to be written to the
output file.
- Fixed ACTION_COPY_DIR implementation; the name of the lock to
be duplicated did not get duplicated.
- Fixed ACTION_EXAMINE_OBJECT and ACTION_EXAMINE_NEXT
implementations; protection bits are now reported 'properly'
with respect to read/write access.
smbfs 1.20 (27.11.2000)
- ACTION_EXAMINE_NEXT now filters out SMB names that include
'/' or ':' characters.
smbfs 1.21 (28.11.2000)
- Modified ACTION_RENAME_DISK to remove the volume node before
changing it. It also sends the appropriate diskremove/diskinserted
input events now.
- Reorganized and rewrote the code to reduce dependencies on
the compiler runtime library.
- Unified error reporting code.
- SMBFS can now be launched from Workbench using the same parameters
you would use when starting it from Shell. Error reporting
has been adapted to show an error requester and to pool error
messages rather than printing them to the console.
smbfs 1.22 (30.11.2000)
- Fixed the test that looks for file/lock access mode collisions.
- No longer changes the case of the password; there is now an
option to make the change.
- Fixed ACTION_SAME_LOCK which was comparing the same lock with
itself.
- Added support for ACTION_EXAMINE_ALL, ACTION_EXAMINE_ALL_END
and ACTION_WRITE_PROTECT packet types.
- No longer allows for files and locks to refer to "." and "..".
The use of the backslash character '\' is also disallowed in
Amiga file/directory names.
smbfs 1.23 (30.11.2000)
- In the ExNext()/ExAll() handling functions local error variables
were shadowing each other. Fixed.
- The error reporting requester now also lists the name of the
service to connect to. This should help in telling different
invocations of the program apart.
- The size of the directory cache is now a configurable option.
- Added a new option which forces all name comparisons to be
done in a case-sensitive fashion.
- Reading/writing data to/from a file in chunks larger than
65535 bytes could fail and cause the file system to hang.
smbfs 1.24 (1.12.2000)
- Added an option to allow hidden files to be omitted from
directory listings.
- Improved upon the error reporting in the code that directly
calls the TCP/IP API functions.
- Reorganized the AmigaDOS packet handling switch..case
list.
- Added support for ACTION_MORE_CACHE packet type. The
cache in this context refers to the directory scanning
cache.
- Improved upon the host lookup error reporting code.
- Added support for file name translation such as via the
CrossDOS translation table files.
smbfs 1.25 (2.12.2000)
- SMBFS now displays some configuration information as soon as
it has successfully connected to the file server and is ready
for action. This output can be suppressed with the new
"QUIET" command line parameter.
- When removing a directory, the error code returned is examined
more closely to see whether the directory was not yet empty.
- When setting the protection bits of a file or directory, the
file system now treats either 'protected from deletion' and
'protected from writing' as indications to mark a file as
write protected. Previously, a file had to be both protected
from deletion and from writing to be treated as write protected.
- Cleaned up the program's data structures and eliminated all
static data that would hold state information. The entire
client side is now completely reentrant.
smbfs 1.26 (3.12.2000)
- File and directory names are no longer duplicated in the
SMB abstraction layer. The strings supplied by the Amiga
file system layer are referenced instead.
- Changed the way the ACTION_MORE_CACHE implementation returns
its result code to be compatible with current practices.
smbfs 1.27 (4.12.2000)
- The changes I made to the file read command in order to allow it
to read more than 65535 bytes at a time did not allow read
attempts at the end of the file to come out properly. Fixed.
- Integrated password encryption code lifted from Samba. Hope
it works as it should, because if it doesn't, I wouldn't know
how to fix it...
smbfs 1.28 (4.12.2000)
- Oh dear, more fixes to the password encryption code and the
connection setup to follow it. This time I managed to test the
code briefly with Samba and password encryption enabled.
Amazingly, it seems to work this time!
smbfs 1.29 (6.12.2000)
- Writes larger than 65535 bytes could stall and slow down the
file system. Fixed. [Thore Böckelmann]
- The ACTION_MORE_CACHE implementation never returned the total
number of cache entries allocated. Fixed. [Thore Böckelmann]
- Plain text passwords didn't seem to work any more after I made
the changes to allow for encrypted passwords to be used. Fixed.
smbfs 1.30 (6.12.2000)
- Changed the structure of the share names by which the file system
refers to the data on the server; they all start with a backslash
now. This seems to help NT and doesn't break the rest.
- For file shares exported using 'share level security', no passwords
will be transmitted.
smbfs 1.31 (7.12.2000)
- The ACTION_EXAMINE and ACTION_EXAMINE_FH implementations now verify
that the name to return will fit into the FileInfoBlock's limited
buffer space.
- Deleting files and directories from a directory currently being
scanned via ACTION_EXAMINE_NEXT or ACTION_EXAMINE_ALL will now cause
the directory scanner to restart. This is ugly, I know, but at least
it won't cause the scanning process to hickup or lose entries
directory entries during its course of duty. The flip side is that
the scanner will probably return some entries twice. There must
be a better way to implement this, but for now, this is it.
- Tried to make device and volume node removal safer.
- SMBFS now always adds a device node to go along with the volume node.
It's safer that way because for every file system you either have a
single device node in the system (and no volume node) or a volume
node *and* a device node. If the device node is missing, there's
typically something wrong and some application software cannot handle
this case properly. SMBFS will attempt to add a new, unique device
node every time it is launched.
- When specifying the name of the file system device to add, SMBFS
now complains if that name already exists.
smbfs 1.32 (8.12.2000)
- File and directory modification dates were always off by six hours and
one second. I don't know how that happens, it doesn't seem to be a bug
in the date conversion routines. I worked around the problem by adding
and subtracting an adjustment value.
smbfs 1.33 (10.12.2000)
- The ACTION_PARENT_DIR implementation did not return a ZERO lock for
the root directory. Fixed. [Rudolph Riedel]
- Replaced the doubly-linked Exec lists with skip lists which
are better suited for the repeated lookup operations that
are so common in the file system. This time the list code
seems to work properly.
- Added -- largely untested -- time and date decoding routines for
directory entries returned by NT.
smbfs 1.34 (10.12.2000)
- Had to take out the skip list code again since it did not seem to
work reliably.
- Further tweaking to the NT date and time decoding code.
smbfs 1.35 (10.12.2000)
- Small modification to the ACTION_EXAMINE_NEXT/ACTION_EXAMINE_ALL code
which tries to work around a strange effect caused by Amiga Samba
returning the contents of an empty drawer.
smbfs 1.36 (11.12.2000)
- More fixes to the NT date and time conversion code and the
strange six hour fixup that seems to be necessary for the
'regular' time conversion to work.
smbfs 1.37 (11.12.2000)
- Replaced the entire 'regular' date and time conversion code. The
strange six hour fixup is no longer necessary.
smbfs 1.38 (11.12.2000)
- Ditched the packet size kludges in "sock.c" and "proc.c" I had put
in there. It seems that only the 'smba_write()'/'smba_read()' code
could trigger it, and that code was fixed quite a while ago.
- Migrated some code changes from the Samba source over to the
directory scanner.
- Maximum transmission size per packet is now the same as the
number the server allowed us to use rather than a fixed number
imposed by VM page sizes.
- Tried to clean up more of the code.
- Discovered that the 'smb_valid_packet()' routine never could have
worked and fixed it so that it now finally does what it should do.
- Better error propagation for some routines in "proc.c".
- More streamlined error testing code.
smbfs 1.39 (11.12.2000)
- Almost fixed several bugs in 'smb_proc_readdir_long()'.
- 'smb_proc_readdir_long()' does not work correctly. It only seems to
work, but will fail if the scanner is to restart before the entire
directory is read. Restored the old behaviour :(
smbfs 1.40 (13.12.2000)
- Took out some more unused and unnecessary code.
- Rewrote the time and date conversion routines.
- Modified the directory reading code so that it no longer relies
upon the last directory entry index which doesn't seem to be
correct most of the time.
- Directory scanning errors are now flagged as such.
smbfs 1.41 (16.12.2000)
- In the SMB abstraction layer, the directory cache is now invalidated
only if the respective action that could have invalidated it succeeds.
- Now clears the directory cache only if the respective action would
have affected the directory being cached.
- In debug mode [Ctrl]+F will display a list of open files and allocated
locks.
- Added very silly support for ACTION_SET_COMMENT packet.
- Found an interesting bug fix for 'smb_proc_readdir_long()' in the
Linux 2.4.0 kernel which seemed worth integrating into the file system.
smbfs 1.42 (19.12.2000)
- Integrated Chris Hertel's broadcast name query code. This means that
the name of the host whose file shares you want to access need no
longer be in the hosts database. However, you still cannot refer to
a host solely by its IP address.
smbfs 1.43 (21.12.2000)
- The integrated broadcase name query code would conflict with the
DNS lookup. Fixed. [Thore Böckelmann]
- The NetBIOS name query code now retries four times to get a response
out of the network.
- Put the mysterious 6 hour time offset fix back in.
smbfs 1.44 (29.12.2000)
- Rewrote the host lookup error reporting code to use the appropriate
API function.
- Discovered that all the functionality required by SMBFS was supported
by the original free AmiTCP 3.0 release. Changed the "bsdsocket.library"
open parameters.
- The ACTION_EXAMINE_OBJECT implementation consistently got the name of
the root directory wrong. Fixed.
smbfs 1.45 (7.1.2001)
- Discovered why file and directory creation dates were wrong by about
six hours. Fixed.
- The order of the parameters passed to the 'ExAll()' filter hook was
wrong. Fixed [Thorsteinn Sveinsson and Matt Sealey].
smbfs 1.46 (1.2.2001)
- Removed the workarounds for the mysterious 'off by six hours' bug.
The time delta value added was consistently wrong.
smbfs 1.47 (18.2.2001)
- The name of the domain/workgroup, the name of the user and the
password to be used can now be preset using environment variables.
- Changed the command line argument template to work better with the
newly introduced environment variable settings.
smbfs 1.48 (3.3.2001)
- Modified the command template so that the final parameter can no
longer cause all other parameters to be swallowed. Also updated
the documentation.
smbfs 1.49 (3.3.2001)
- Handling of ACTION_FINDUPDATE needed improving. It should have
created a file that didn't already exist. It now does [David Gerber].
smbfs 1.50 (4.3.2001)
- ACTION_FINDUPDATE is now associated with a shared lock. It used
to be an exclusive lock [David Gerber].
- The test to follow ACTION_FINDUPDATE that determines whether the
file to open already exists now also tries to 'stat()' the file
in question to find out whether it exists.
smbfs 1.51 (13.3.2001)
- Whoops. The new code to pull data from environment variables didn't
actually check whether the work group name could be set up properly
and thus didn't complain about it either. It now notifies you if
no work group name was provided and none could be found.
smbfs 1.52 (22.6.2001)
- Added another option which allows you to preset the time zone offset
to use when translating between the local time and the SMB server
time. Using the default locale doesn't work for that purpose all the
time since there are so many misconfigured servers out there.
- The ACTION_DIE packet didn't have the desired effect if the file
system didn't have a reason to wait for any resources to be
released again. It just wouldn't quit. Now it does.
- Before it exits, the file system no longer posts a disk change
event if it was launched from Workbench. I found that the steps
taken so far could end up deadlocking Workbench.
smbfs 1.53 (26.6.2001)
- Changed the file name parser; it should now be possible to tie assigns
to files and directories on an smb volume. Since the updated file name
translation code also is a bit smarter about when to use which
file name separator character, accesses to the media should be a
bit faster, too.
- When translating path names, trailing '/' characters are now properly
parsed, i.e. Lock("/",...) should always bring up the parent directory
[Matt Sealey].
- Duplicating a ZERO lock now works as expected.
smbfs 1.54 (27.6.2001)
- Directory and file creation didn't work that properly after applying
the changes I made to the parser. Fixed [Matt Sealey].
smbfs 1.55 (3.3.2002)
- At least samba 2.2.2-12 on linux can send total_data of 0 bytes. This
caused sock.c/smb_receive_trans2() malloc() (==AllocVecPooled) to fail
on smba_readdir(). Fixed [Harry Sintonen].
- Added quickfix against crash if smb_abstraction.c/smb_smba_readdir()
fails. This is by no means a real fix, but at least it doesn't crash
[Harry Sintonen].
- There is definitely something fishy in the smbfs restart/retry scheme,
it just doesn't work properly (all state data has to be, and is,
reset when restarts occur, but still it tries to use the old data as if
nothing happened). Someone should really take a closer look at this
[Harry Sintonen].
smbfs 1.56 (3.9.2002)
- Rewrote the Setup() code which allocates and initializes the device and
volume nodes. Lost all Forbid()..Permit() pairs on the way, making the
code more robust and less weird.
- In proc.c/smb_proc_readdir_long() now specifically watches for the
smb_trans2_request() function return empty data and parameter values.
This is now treated as an attempt to read from an empty directory.
Previously, there was a slight change that the information was
taken seriously even if NULL was returned.
smbfs 1.57 (3.9.2002)
- Ran the code through GCC and rewrote the code to get rid of the compiler
warnings that appeared to have something more serious about them. This
includes, for example, comparisons between signed and unsigned values.
smbfs 1.58 (5.9.2002)
- Rebuilt using my own TCP/IP stack SDK. Rebuilding the code with the
Miami SDK should still be possible, though.
- Changed the way smb_proc_readdir_long() aborts the job if no valid
data is read.
smbfs 1.59 (10.9.2003) [Harry Sintonen <sintonen@iki.fi>]
- Fixed ACTION_DELETE_OBJECT to restart directory scanning, it
searched for wrong object. Fixes the problem where every other
file was skipped when deleting directory.
smbfs 1.60 (11.2.2004) [Peter Riede <Noster-Riede@T-Online.de>]
- Fixed ACTION_SEEK, it doesn't works if followed by ACTION_WRITE.
Fixes the problem by using the SMBlseek packet instead of just
remembering the position in the local FileNode structure
- Fixed ACTION_SETFILESIZE, has returned an errorcode of 37 instead
of 0L on success.
- Added support for the ACTION_LOCK_RECORD and ACTION_UNLOCK_RECORD
packets.
smbfs 1.61 (27.4.2004)
- Reworked the ACTION_SEEK implementation. Turns out that the SMB
lseek packet only seems to work for the Samba server but produces
unpredictable results with Microsoft flavoured servers. The new
code, which helps to avoid trouble with overlapping write access
and seeks, now performs much like the old one except that it
"notifies" the SMB server of the new file position to be used.
Tested both with Samba and Windows XP: works as it should.
smbfs 1.62 (8.5.2004)
- Added sanity checks to the record locking code. For example,
locking a record of length 0 must be considered illegal. Also,
since the protocol deals with 32 bit signed integers for
file position and record length, parameters that are "too large"
and come out as negative values are now rejected.
smbfs 1.63 (9.5.2004)
- Added more sanity checks to the record locking code, this time
to avoid integer overflows.
- Added support for the SMB 'archive' and 'system' file attributes,
which are mapped to the Amiga 'archived' and 'pure' protection
bits.
- Cleaned up the header files.
smbfs 1.64 (13.5.2004)
- ExamineFH() did not fill in the file protection bits. Fixed.
- Ported to AmigaOS4.
smbfs 1.65 (16.5.2004)
- The port numbers of the NetBIOS session and name services are no
longer hard-coded. They are now looked up (netbios-ns/udp and
netbios-ssn/tcp), and if that fails, the hard-coded default port
numbers are used instead.
- Tried to reduce the risk of triggering buffer overflows by replacing
calls to strcpy/strcat. This revealed weaknesses in a number of
places, including the code that fills in the names of the directory
entries.
- Instead of calling memcpy(), the code now invokes exec.library/CopyMem(),
which should be a wee bit faster than what the 'C' runtime library can do.
- Merged with Peter Riede's changes: for small packets to be sent,
SMBwrite is used instead of SMBwritebraw (which greatly enhances
performance), the server max_xmit field is initialized differently
if the session was opened with a SMBtconx packet and ACTION_SEEK
no longer sets the error code to an undefined value in case of
success.
smbfs 1.66 (10.6.2004)
- Added a paranoia check to the ExAll() implementation which should
avoid trouble with extremely short data buffers.
+445
View File
@@ -0,0 +1,445 @@
A SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
==============================================================
1. What is it?
This document briefly describes the SMBFS program, which implements an SMB
file system for AmigaOS. This file system can be used to access files made
available by file servers which implement the SMB protocol, such as 'Microsoft
Windows' or any other platform which supports the free 'Samba' product. These
files can be accessed using shell commands such as 'List', the Workbench or
utilities such as 'Directory Opus' as if the file server were a local disk
drive.
2. What do you need to get started?
You need a TCP/IP stack that supports the AmiTCP V3 API, such as 'Miami', the
original free 'AmiTCP 3.0' release, 'AmiTCP 4.x', 'Miami Deluxe' or 'AmiTCP
Genesis' and the obligatory networking gear. All these items need to be in
good shape and properly configured.
Most important, you need a computer which exports file sharing services using
the SMB protocol.
It often helps to have 'Samba' installed on your Amiga, too, as this can aid
in tracking down bugs and obtaining information which SMBFS cannot obtain all
by itself.
Last but not least, you need to be proficient in configuring and using the
TCP/IP stack; networking knowledge is definitely assumed.
SMBFS requires AmigaOS 2.04 or higher to work.
3. Preparations
You need to know which computer's files you want to share using the SMBFS file
system. That computer must be known by name, it is not sufficient just to know
its IP address. If you know the IP address but cannot refer to the host by its
name then SMBFS will not work. In that case, make sure that you add a host
name entry referring to the IP address to your TCP/IP stack's host database
(e.g. the "AmiTCP:bin/hosts" file or the corresponding page in the stack's
configuration user interface).
The name of the computer to connect to must not be too long. If it is longer
than 16 characters, SMBFS will not work properly.
You need to know which service you want to connect to on the target computer.
You can find out which services are available on a certain computer by using
the Samba 'smbclient' program. For example, if you were to query the services
offered by a machine called 'sourcery' you could enter the following:
samba:bin/smbclient -L sourcery
And you might get the following information:
added interface ip=192.168.0.1 bcast=192.168.0.255 nmask=255.255.255.0
Password: Domain=[ARBEITSGRUPPE] OS=[AmigaOS] Server=[Samba 2.0.7]
Sharename Type Comment
--------- ---- -------
All Disk All volumes in the system
IPC$ IPC IPC Service (Amiga 3000UX)
olsen Disk Home Directories
Server Comment
--------- -------
SOURCERY Amiga 3000UX
Workgroup Master
--------- -------
ARBEITSGRUPPE SOURCERY
The share name to connect to would be "ALL" in this case.
You need to know which login name and which password are required to connect
to the shared resource, and you need to know the name of the workgroup or
domain the file server is a member of.
4. Starting and stopping the file system
SMBFS is an uncommon kind of file system in that you do not use the 'Mount'
command to mount it. In fact, SMBFS is a shell program which can be launched
from the shell, using command line parameters to tell it which resources
should be used. But you can also start it from Workbench: in this case you
would have to put the program's command line options into icon tool types.
By now you should have assembled the following information:
- Name of the computer to connect to; this would be the
file server
- Name of the shared SMB resource to connect to
- Login name and password
That's basically everything you need to know to continue -- unless something
goes wrong, but more on that lateron.
Now you can start the file system. For example, to connect to the file server
called 'sourcery' and the shared 'all' resource it exports, with that computer
being a member of the workgroup 'Arbeitsgruppe', using the login name
'PCGuest' and not providing any password you would enter the following:
Run >NIL: SMBFS Workgroup=Arbeitsgruppe User=PCGuest Service=//sourcery/all
This would cause a new device by the name of "SMBFS:" to be mounted, showing
all files and directories the 'sourcery' server makes available for sharing.
How do you 'unmount' the file system? That's very easy, just check the output
of the 'Status' shell command. You might get the following output:
Process 1: Loaded as command: TURBOTEXT
Process 2: Loaded as command: Work:Tools/Blowup
Process 3: Loaded as command: Work:Tools/Sashimi
Process 4: Loaded as command: Work:CyberTools/CyberGuard
Process 5: Loaded as command: Work:Tools/OpenDevicePatch
Process 6: Loaded as command: CED
Process 7: Loaded as command: Workbench
Process 8: Loaded as command: Status
Process 9: No command loaded
Process 10: Loaded as command: SMBFS '//sourcery/all'
Look at the last line describing process number 10: it shows the name of the
file system program SMBFS and the name of the SMB share it is connected to. To
stop this file system and effectively unmount it, use the shell 'Break'
command; in this case you would enter "Break 10" to stop the file system. Note
that the program may not terminate immediately; it may have to wait until the
last client has released all resources referring to the file system. You may
have to send more than one "Break" command to stop the program.
5. Startup options
The SMBFS program supports a number of command line options, as will be
described below. The command template looks like this:
DOMAIN=WORKGROUP/K,USER=USERNAME/K,PASSWORD/K,CHANGECASE/S,
CASE=CASESENSITIVE/S,OMITHIDDEN/S,QUIET/S,CLIENT=CLIENTNAME/K,
SERVER=SERVERNAME/K,DEVICE=DEVICENAME/K,VOLUME=VOLUMENAME/K,
CACHE=CACHESIZE/N/K,DEBUGLEVEL=DEBUG/N/K,TZ=TIMEZONEOFFSET/N/K,
TRANSLATE=TRANSLATIONFILE/K,SERVICE/A
The individual options serve the following purposes:
DOMAIN=WORKGROUP/K
You must specify the name of the work group or domain which the file server
to connect to is a member of. The name of this workgroup or domain must not
be longer than 16 characters. The name you provide will be translated to
all upper case characters.
You need not provide for a work group or domain name on the command line.
Alternatively, you may configure an environment variable whose contents
will be used instead. The variable could be set up like this:
SetEnv smbfs_workgroup <name of domain or workgroup>
Copy ENV:smbfs_workgroup ENVARC:
You may also use the 'smbfs_domain' environment varilable in place of the
'smbfs_workgroup' variable. The two are aliases for one another, but
smbfs will read only one of the two.
USER=USERNAME/K
To connect to an SMB share you must authenticate yourself by providing a
user name. With this program the user name is optional; if you do not
provide one, SMBFS will use the default, which is "GUEST". The user name
must not be longer than 64 characters. The name you provide will be
translated to all upper case characters.
You need not provide for a user name on the command line. Alternatively,
you may configure an environment variable whose contents will be used
instead. The variable could be set up like this:
SetEnv smbfs_username <your user name>
Copy ENV:smbfs_username ENVARC:
You may also use the 'smbfs_user' environment varilable in place of the
'smbfs_username' variable. The two are aliases for one another, but
smbfs will read only one of the two.
PASSWORD/K
As part of the authentication process required to make the connection to
an SMB share, you must provide for a user name and a password. The
password is optional; if you do not provide one, an empty password will
be transmitted. The password must not be longer than 64 characters.
You need not provide for a password on the command line. Alternatively,
you may configure an environment variable whose contents will be used
instead. The variable could be set up like this:
SetEnv smbfs_password <your password>
Copy ENV:smbfs_password ENVARC:
Keep in mind that passwords like these really should not be exposed by
storing them in environment variables. But then the protocol smbfs uses
is almost as insecure as it gets anyway.
The authentication process only works if the machine you are connecting
to knows about the user name and password you want to use. As of this
writing, smbfs cannot be used for authenticating against a password
server that is not the same machine as the one from which you wish to
import a share.
CHANGECASE/S
By default the password will not be changed to all upper case characters.
If this is required, you should either provide the password in this
form or resort to this option, which will cause it to be translated
to all upper case characters.
CASE=CASESENSITIVE/S
Some file servers treat file and directory names differently which
differ only in whether they are written using upper/lower case
characters. For these servers you should activate the CASESENSITIVE
switch to treat those files properly. There is a catch though: the
AmigaDOS file naming scheme does not follow this model and you may
run into problems when you are trying to use it. By default, the
file system does not treat file and directory names differently
which only differ with respect to the case of letters.
OMITHIDDEN/S
When requesting a directory listing, the server may return some files
and directories tagged as being hidden. By default this file system
will report these 'hidden' entries anyway, but you can request
specifically that what is intended to be hidden should be omitted
from directory listings, too. Note that even though a file may be
hidden you should still be able to open and examine it.
QUIET/S
When started from Shell, SMBFS will print a message as soon as the
connection to the file server has been established. If you do not
want to see that message displayed, use the QUIET parameter. Also,
no such message will appear if the program has been started to run
in the background.
CLIENT=CLIENTNAME/K
SMBFS will attempt to connect to the file server by providing the name
of the computer you connect from. In some cases this may be undesirable
as the computer's name differs from what the file server expects. You
can use the CLIENT parameter to tell SMBFS under which name it should
announce itself to the server. This parameter is optional and will be
translated to all upper case characters; it cannot be longer than 16
characters.
SERVER=SERVERNAME/K
SMBFS will attempt to connect to the file server by providing the name
you specified using the SERVICE command line parameter. In some cases
this may be undesirable as the server's name differs from what you
specified as the share name. You can use the SERVER parameter to tell
SMBFS under which name it should contact the server. This parameter is
optional and will be translated to all upper case characters; it cannot
be longer than 16 characters.
DEVICE=DEVICENAME/K
VOLUME=VOLUMENAME/K
The SMBFS program can announce itself as an AmigaDOS file system by
using one of two different methods.
The first method involves announcing itself only as a file system
device. This should be sufficient in most cases but has a drawback in
that the device will not be usable from Workbench since the file system
will not appear as a disk icon. You tell SMBFS to use a specific device
name by using the DEVICE command line parameter, e.g. "DEVICE=SMBFS:".
Note that device names must be unique, i.e. there must be no other
device by the same name in the system; SMBFS will report an error and
exit if it finds one.
The second method involves announcing itself as a volume. This has the
benefit of making the file system usable from Workbench since a disk
icon will appear for it. You tell SMBFS to use a specific volume name by
using the VOLUME command line parameter, e.g. "VOLUME=Sourcery:".
Both methods have advantages and drawbacks. The drawback of the VOLUME
method is that it may deadlock the native Amiga Samba port as soon as
the file system is mounted. The drawback of the DEVICE method is that
the file system will not be usable from Workbench.
If you wish, you can combine both methods; this is the approach most
other file systems use. And in fact, when you tell SMBFS to add a
volume it will also add a device to go along with it.
The VOLUME and DEVICE keywords are optional; if you omit both, SMBFS
will pretend that you had used the "DEVICE=SMBFS:" parameter.
CACHE=CACHESIZE/N/K
The file system attempts to optimize accesses to the file server when
directory contents are being scanned. These contents are buffered in
a directory cache which by default will hold 170 entries. Since each
entry will require about 255 bytes of storage, the entire 170 entry
cache will occupy more than 40K bytes of memory. You may want to change
this requirement, by making the cache smaller or larger using the
CACHESIZE parameter. The size of the directory cache cannot be smaller
than 10 entries.
DEBUGLEVEL=DEBUG/N/K
By default SMBFS operates in silent mode. It does not report what it is
doing, it just tries to respond to file system requests. To obtain
debugging output you may want to use the DEBUG option and specify a
debug level greater than 0. The larger the number you specify the more
debugging output will be created. Note that all debugging output will be
produced using the operating system's debug output functionality which
requires that you have a capturing program like 'Sashimi' running in the
background.
TZ=TIMEZONEOFFSET/N/K
By default the file system will use the current Locale settings to
translate between the local time and the time used by the SMB
server. For some configurations, however, this is impractical since
the server's time zone is not configured properly. For these
rare cases you may want to hard code a certain time zone offset
using the 'TIMEZONEOFFSET' options. The number you provide must
be the number of minutes to add to the local time in order to
translate it into the corresponding GMT value. For example, in
central Europe using CET, you would use "TZ=-60" since CET is
one hour ahead of GMT.
TRANSLATE=TRANSLATIONFILE/K
The Amiga and the file server SMBFS connects to may not share the same
character set. International characters used in file names on either
side may not come out correctly on the other side. To remedy this
problem, you can resort to file name translation. How the individual
names are to be translated is determined by the contents of a file
name translation table file such as the ones that ship with Workbench
in the "L:FileSystem_Trans" drawer. The first 256 bytes of each such
file must consist of the mapping of Amiga characters to the different
character set, and the second 256 characters must describe a mapping
back from the different character set to the Amiga. In most cases the
"L:FileSystem_Trans/INTL.crossdos" translation table file should be
sufficient. To specify which file contains the translation tables to
use you would use the TRANSLATIONFILE parameter.
SERVICE/A
This is the last parameter to be specified on the command line. It
should refer to the file server you want to connect to and the resource
it exports, e.g. a file system. This parameter must start with two
slashes which must be immediately followed by the file server's name,
which must be followed by the resource to connect to.
For now no special characters are allowed in the name of the service
as no translation is performed like would be the case for file names
on the volume.
The same parameters are also used when starting SMBFS from Workbench. SMBFS
will examine its icon tool types and use these in place of the shell command
line.
6. Known problems
The design of smbfs follows the original file system concept behind the
code which the 'Sharity-Light' file system is based upon. And that is a
Unix file system which differs from Amiga specific file systems in many
ways which can lead to problems which are discussed briefly below:
- Single threaded design
This means that it is not possible for several programs to fairly
share the use of the file system. For example, a program that posts
a long read request can tie up the file system almost exclusively
for itself, and while it is busy all other clients will have to
wait. Same goes for directory scanning.
- Poor scalability
This is associated with the single threaded design. When several
programs are accessing the file system at the same time, overhead
and unfair sharing of resources will drastically reduce the
performance of the file system.
- Separation of file data and metadata
This means that the core of the file system treats the contents of
a directory and the data attached to each file inside that
directory as something different. This is a common concept with
Unix file systems, but it is very different with Amiga file systems.
In smbfs this data separation can cause problems when deleting
files from a directory while that directory is being scanned,
such as how this is being done by the 'Delete' shell command. The
effects of these problems are that a directory may not be deleted
even though it is empty or that for the same directory the same
file may be reported twice in the listing.
While there are no easy solutions for any of these problems, it does not
mean that smbfs is unusable. You just have to be more careful when you
use the file system. For example, if a directory's contents cannot be
deleted due to one of the problems mentioned above, you might want to
retry later.
It should be noted that the problems described above are not inherent
to the original file system design. It's just that transferring that
design to an Amiga file system created the problems.
7. Credits
This file system is based upon prior work by Paal-Kr. Engstad, Volker
Lendecke, Mark A. Shand, Donald J. Becker, Rick Sladkey, Fred N. van Kempen,
Eric Kasten and Rudolf Koenig. It is a direct descendant of the
'Sharity-Light' file system written by Christian Starkjohann.
The password encryption code was lifted from the Samba package. It was
written by Andrew Tridgell and the Samba Team.
8. Author
The 'Sharity-Light' source code was adapted and wrapped into an AmigaOS layer
by Olaf `Olsen' Barthel. If you wish to contact me, please send e-mail to the
following address:
olsen@sourcery.han.de
Or, alternatively, you might want to contact me via my postal address:
Olaf Barthel
Gneisenaustr. 43
D-31275 Lehrte
Federal Republic of Germany
If you want to submit a bug report or an enhancement request, please enclose
sufficient information to allow me to make sense of the problem. That includes
debugging logs produced using the DEBUG option.
9. Source code
SMBFS is distributed under the terms of the GNU General Public License
(version 2). The source code should have accompanied this program; if it
hasn't, please contact the author for a copy.
The program was compiled using the SAS/C 6.58 compiler, with the Miami SDK
providing for the TCP/IP stack API header files.
+339
View File
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
+69
View File
@@ -0,0 +1,69 @@
#
# $Id: GNUmakefile.68k,v 1.1.1.1 2005-05-24 13:22:06 obarthel Exp $
#
# :ts=8
#
# SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
#
# Copyright (C) 2000-2004 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
.c.o:
@echo "Compiling $<"
@gcc -c $(CFLAGS) -o $*.o $<
###############################################################################
PROJECT = smbfs
###############################################################################
WARNINGS = \
-Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
-Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion
CPU = -m68020-60
OPTIONS = -DNDEBUG -fno-builtin -Inetinclude -Iinclude
OPTIMIZE = -O2 -fomit-frame-pointer
DEBUG = -g
###############################################################################
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -Iinclude -I.
LFLAGS = -nostartfiles -nostdlib -L.
###############################################################################
OBJS = main.o proc.o smb_abstraction.o sock.o crypt.o
###############################################################################
LIBS = -lc -ldebug -lamiga
###############################################################################
all: $(PROJECT)
$(PROJECT): $(OBJS)
gcc -o $@.debug $(OBJS) $(CFLAGS) $(LFLAGS) $(LIBS)
strip --strip-all -o $@ $@.debug
protect $@ +e
###############################################################################
clean:
-delete #?.o $(PROJECT)(%|.debug)
+73
View File
@@ -0,0 +1,73 @@
#
# $Id: GNUmakefile.os4,v 1.1.1.1 2005-05-24 13:22:06 obarthel Exp $
#
# :ts=8
#
# SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
#
# Copyright (C) 2000-2004 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
.c.o:
@echo "Compiling $<"
@$(CC) -c $(CFLAGS) -o $*.o $<
###########################################################################
PROJECT = smbfs
###########################################################################
CC = ppc-amigaos-gcc
###########################################################################
#WARNINGS = \
# -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
# -Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion
WARNINGS = \
-Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
-Wundef -Wbad-function-cast -Wmissing-declarations
CPU = -mcpu=604e -msoft-float
OPTIONS = -DNDEBUG -fno-builtin
OPTIMIZE = -O2 -fomit-frame-pointer -fstrength-reduce -finline-functions
DEBUG = -g
###########################################################################
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) \
-I. -I/V/include -I/usr/local/amiga/ppc-amigaos/sys-include -Iinclude -Inetinclude
LFLAGS = -nostartfiles -nostdlib -L.
###########################################################################
OBJS = main.o proc.o smb_abstraction.o sock.o crypt.o
###########################################################################
LIBS = -lc
###########################################################################
all: $(PROJECT)
$(PROJECT): $(OBJS)
@echo "Linking $@"
@$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) -Wl,--cref,-M,-Map=$@.map
ppc-amigaos-strip -R.comment -o $@ $@.debug
+428
View File
@@ -0,0 +1,428 @@
/*
* $Id: assert.c,v 1.1.1.1 2005-05-24 13:22:06 obarthel Exp $
*
* :ts=8
*
* SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
*
* Copyright (C) 2000-2004 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/****************************************************************************/
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#ifdef __SASC
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#else
#include <inline/exec.h>
#include <inline/dos.h>
#endif /* __SASC */
#include <string.h>
extern struct Library * AbsExecBase;
#define SysBase AbsExecBase
extern void kprintf(const char *,...);
extern void __stdargs kputc(char c);
/****************************************************************************/
#include <stdarg.h>
/****************************************************************************/
#define DEBUGLEVEL_OnlyAsserts 0
#define DEBUGLEVEL_Reports 1
#define DEBUGLEVEL_CallTracing 2
/****************************************************************************/
static int indent_level = 0;
int __debug_level = DEBUGLEVEL_CallTracing;
static char program_name[40];
static int program_name_len = 0;
/****************************************************************************/
void
_SETPROGRAMNAME(char *name)
{
if(name != NULL && name[0] != '\0')
{
program_name_len = strlen(name);
if(program_name_len >= sizeof(program_name))
program_name_len = sizeof(program_name)-1;
strncpy(program_name,name,program_name_len);
program_name[program_name_len] = '\0';
}
else
{
program_name_len = 0;
}
}
/****************************************************************************/
int
_SETDEBUGLEVEL(int level)
{
int old_level = __debug_level;
__debug_level = level;
return(old_level);
}
/****************************************************************************/
int
_GETDEBUGLEVEL(void)
{
return(__debug_level);
}
/****************************************************************************/
static int previous_debug_level = -1;
void
_PUSHDEBUGLEVEL(int level)
{
previous_debug_level = _SETDEBUGLEVEL(level);
}
void
_POPDEBUGLEVEL(void)
{
if(previous_debug_level != -1)
{
_SETDEBUGLEVEL(previous_debug_level);
previous_debug_level = -1;
}
}
/****************************************************************************/
void
_INDENT(void)
{
if(program_name_len > 0)
kprintf("(%s) ",program_name);
if(__debug_level >= DEBUGLEVEL_CallTracing)
{
int i;
for(i = 0 ; i < indent_level ; i++)
kprintf(" ");
}
}
/****************************************************************************/
void
_SHOWVALUE(
unsigned long value,
int size,
const char *name,
const char *file,
int line)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
char *fmt;
switch(size)
{
case 1:
fmt = "%s:%ld:%s = %ld, 0x%02lx";
break;
case 2:
fmt = "%s:%ld:%s = %ld, 0x%04lx";
break;
default:
fmt = "%s:%ld:%s = %ld, 0x%08lx";
break;
}
_INDENT();
kprintf(fmt,file,line,name,value,value);
if(size == 1 && value < 256)
{
if(value < ' ' || (value >= 127 && value < 160))
kprintf(", '\\x%02lx'",value);
else
kprintf(", '%lc'",value);
}
kprintf("\n");
}
}
/****************************************************************************/
void
_SHOWPOINTER(
void *pointer,
const char *name,
const char *file,
int line)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
char *fmt;
_INDENT();
if(pointer != NULL)
fmt = "%s:%ld:%s = 0x%08lx\n";
else
fmt = "%s:%ld:%s = NULL\n";
kprintf(fmt,file,line,name,pointer);
}
}
/****************************************************************************/
void
_SHOWSTRING(
const char *string,
const char *name,
const char *file,
int line)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
_INDENT();
kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string);
}
}
/****************************************************************************/
void
_SHOWMSG(
const char *string,
const char *file,
int line)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
_INDENT();
kprintf("%s:%ld:%s\n",file,line,string);
}
}
/****************************************************************************/
void
_DPRINTF_HEADER(
const char *file,
int line)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
_INDENT();
kprintf("%s:%ld:",file,line);
}
}
#ifdef __SASC
static void __asm
putch(register __d0 UBYTE c)
{
if(c != '\0')
kputc(c);
}
#else
static void
putch(UBYTE c __asm("d0"))
{
if(c != '\0')
kputc(c);
}
#endif /* __SASC */
void
_DPRINTF(const char *fmt,...)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
va_list args;
va_start(args,fmt);
RawDoFmt((char *)fmt,args,(VOID (*)())putch,NULL);
va_end(args);
kprintf("\n");
}
}
void
_DLOG(const char *fmt,...)
{
if(__debug_level >= DEBUGLEVEL_Reports)
{
va_list args;
va_start(args,fmt);
RawDoFmt((char *)fmt,args,(VOID (*)())putch,NULL);
va_end(args);
}
}
/****************************************************************************/
void
_ENTER(
const char *file,
int line,
const char *function)
{
if(__debug_level >= DEBUGLEVEL_CallTracing)
{
_INDENT();
kprintf("%s:%ld:Entering %s\n",file,line,function);
}
indent_level++;
}
void
_LEAVE(
const char *file,
int line,
const char *function)
{
indent_level--;
if(__debug_level >= DEBUGLEVEL_CallTracing)
{
_INDENT();
kprintf("%s:%ld: Leaving %s\n",file,line,function);
}
}
void
_RETURN(
const char *file,
int line,
const char *function,
unsigned long result)
{
indent_level--;
if(__debug_level >= DEBUGLEVEL_CallTracing)
{
_INDENT();
kprintf("%s:%ld: Leaving %s (result 0x%08lx, %ld)\n",file,line,function,result,result);
}
}
/****************************************************************************/
void
_ASSERT(
int x,
const char *xs,
const char *file,
int line,
const char *function)
{
#ifdef CONFIRM
{
STATIC BOOL ScrollMode = FALSE;
STATIC BOOL BatchMode = FALSE;
if(BatchMode == FALSE)
{
if(x == 0)
{
kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
file,
line,
xs,
function);
if(ScrollMode == FALSE)
{
ULONG Signals;
SetSignal(0,SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
kprintf(" ^C to continue, ^D to enter scroll mode, ^E to enter batch mode\r");
Signals = Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
if(Signals & SIGBREAKF_CTRL_D)
{
ScrollMode = TRUE;
kprintf("Ok, entering scroll mode\033[K\n");
}
else if (Signals & SIGBREAKF_CTRL_E)
{
BatchMode = TRUE;
kprintf("Ok, entering batch mode\033[K\n");
}
else
{
/* Continue */
kprintf("\033[K\r");
}
}
}
}
}
#else
{
if(x == 0)
{
_INDENT();
kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
file,
line,
xs,
function);
}
}
#endif /* CONFIRM */
}
+121
View File
@@ -0,0 +1,121 @@
/*
* $Id: assert.h,v 1.1.1.1 2005-05-24 13:22:06 obarthel Exp $
*
* :ts=8
*
* SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
*
* Copyright (C) 2000-2004 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ASSERT_H
#define _ASSERT_H 1
/****************************************************************************/
/* IMPORTANT: If DEBUG is redefined, it must happen only here. This
* will cause all modules to depend upon it to be rebuilt
* by the smakefile (that is, provided the smakefile has
* all the necessary dependency lines in place).
*/
/*#define DEBUG*/
/****************************************************************************/
#ifdef ASSERT
#undef ASSERT
#endif /* ASSERT */
#define PUSH_ASSERTS() PUSHDEBUGLEVEL(0)
#define PUSH_REPORTS() PUSHDEBUGLEVEL(1)
#define PUSH_CALLS() PUSHDEBUGLEVEL(2)
#define PUSH_ALL() PUSHDEBUGLEVEL(2)
#define POP() POPDEBUGLEVEL()
#if defined(DEBUG) /*&& defined(__SASC)*/
void _ASSERT(int x,const char *xs,const char *file,int line,const char *function);
void _SHOWVALUE(unsigned long value,int size,const char *name,const char *file,int line);
void _SHOWPOINTER(void *p,const char *name,const char *file,int line);
void _SHOWSTRING(const char *string,const char *name,const char *file,int line);
void _SHOWMSG(const char *msg,const char *file,int line);
void _ENTER(const char *file,int line,const char *function);
void _LEAVE(const char *file,int line,const char *function);
void _RETURN(const char *file,int line,const char *function,unsigned long result);
void _DPRINTF_HEADER(const char *file,int line);
void _DPRINTF(const char *format,...);
void _DLOG(const char *format,...);
int _SETDEBUGLEVEL(int level);
void _PUSHDEBUGLEVEL(int level);
void _POPDEBUGLEVEL(void);
int _GETDEBUGLEVEL(void);
void _SETPROGRAMNAME(char *name);
void _INDENT(void);
#define ASSERT(x) _ASSERT((int)(x),#x,__FILE__,__LINE__,__FUNC__)
#define ENTER() _ENTER(__FILE__,__LINE__,__FUNC__)
#define LEAVE() _LEAVE(__FILE__,__LINE__,__FUNC__)
#define RETURN(r) _RETURN(__FILE__,__LINE__,__FUNC__,(unsigned long)r)
#define SHOWVALUE(v) _SHOWVALUE((ULONG)v,sizeof(v),#v,__FILE__,__LINE__)
#define SHOWPOINTER(p) _SHOWPOINTER(p,#p,__FILE__,__LINE__)
#define SHOWSTRING(s) _SHOWSTRING(s,#s,__FILE__,__LINE__)
#define SHOWMSG(s) _SHOWMSG(s,__FILE__,__LINE__)
#define D(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DPRINTF s; } while(0)
#define PRINTHEADER() _DPRINTF_HEADER(__FILE__,__LINE__)
#define PRINTF(s) _DLOG s
#define LOG(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DLOG("<%s()>:",__FUNC__); _DLOG s; } while(0)
#define SETDEBUGLEVEL(l) _SETDEBUGLEVEL(l)
#define PUSHDEBUGLEVEL(l) _PUSHDEBUGLEVEL(l)
#define POPDEBUGLEVEL() _POPDEBUGLEVEL()
#define SETPROGRAMNAME(n) _SETPROGRAMNAME(n)
#define GETDEBUGLEVEL() _GETDEBUGLEVEL()
#define INDENT() _INDENT()
extern int __debug_level;
#undef DEBUG
#define DEBUG 1
#else
#define ASSERT(x) ((void)0)
#define ENTER() ((void)0)
#define LEAVE() ((void)0)
#define RETURN(r) ((void)0)
#define SHOWVALUE(v) ((void)0)
#define SHOWPOINTER(p) ((void)0)
#define SHOWSTRING(s) ((void)0)
#define SHOWMSG(s) ((void)0)
#define D(s) ((void)0)
#define PRINTHEADER() ((void)0)
#define PRINTF(s) ((void)0)
#define LOG(s) ((void)0)
#define SETDEBUGLEVEL(l) ((void)0)
#define PUSHDEBUGLEVEL(l) ((void)0)
#define POPDEBUGLEVEL() ((void)0)
#define SETPROGRAMNAME(n) ((void)0)
#define GETDEBUGLEVEL() (0)
#define INDENT() ((void)0)
#ifdef DEBUG
#undef DEBUG
#endif /* DEBUG */
#define DEBUG 0
#endif /* DEBUG */
/****************************************************************************/
#endif /* _ASSERT_H */
+712
View File
@@ -0,0 +1,712 @@
/*
* $Id: crypt.c,v 1.1.1.1 2005-05-24 13:22:06 obarthel Exp $
*
* :ts=8
*
* Password encryption routines, lifted from the Samba source code,
* "libsmb/smbencrypt.c", "libsmb/smbdes.c" and "lib/md4.c":
*
* Unix SMB/Netbios implementation.
* Version 1.9.
*
* SMB parameters and setup
*
* A partial implementation of DES designed for use in the
* SMB authentication protocol
*
* An implementation of MD4 designed for use in the SMB authentication protocol
*
* Copyright (C) Andrew Tridgell 1992-1998
* Modified by Jeremy Allison 1995.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "smbfs.h"
/****************************************************************************/
#include <smb/smb.h>
/****************************************************************************/
static void permute (char *out, char *in, const unsigned char * const p, int n);
static void left_shift (char *d, int count, int n);
static void concat (char *out, char *in1, char *in2, int l1, int l2);
static void xor (char *out, char *in1, char *in2, int n);
static void dohash (char *out, char *in, char *key, int forw);
static void str_to_key (unsigned char *str, unsigned char *key);
static void smbhash (unsigned char *out, unsigned char *in, unsigned char *key, int forw);
static void E_P16 (unsigned char *p14, unsigned char *p16);
static void E_P24 (unsigned char *p21, unsigned char *c8, unsigned char *p24);
static int local_wcslen (short *str);
static int local_mbstowcs (short *dst, unsigned char *src, int len);
static void E_md4hash (unsigned char *passwd, unsigned char *p16);
static void smb_owf_encrypt (unsigned char *passwd, unsigned char *c8, unsigned char *p24);
static unsigned long F (unsigned long X, unsigned long Y, unsigned long Z);
static unsigned long G (unsigned long X, unsigned long Y, unsigned long Z);
static unsigned long H (unsigned long X, unsigned long Y, unsigned long Z);
static unsigned long lshift (unsigned long x, int s);
static void mdfour64 (unsigned long *M);
static void copy64 (unsigned long *M, unsigned char *in);
static void copy4 (unsigned char *out, unsigned long x);
static void mdfour (unsigned char *out, unsigned char *in, int n);
/****************************************************************************/
/* NOTES:
This code makes no attempt to be fast! In fact, it is a very
slow implementation
This code is NOT a complete DES implementation. It implements only
the minimum necessary for SMB authentication, as used by all SMB
products (including every copy of Microsoft Windows95 ever sold)
In particular, it can only do a unchained forward DES pass. This
means it is not possible to use this code for encryption/decryption
of data, instead it is only useful as a "hash" algorithm.
There is no entry point into this code that allows normal DES operation.
I believe this means that this code does not come under ITAR
regulations but this is NOT a legal opinion. If you are concerned
about the applicability of ITAR regulations to this code then you
should confirm it for yourself (and maybe let me know if you come
up with a different answer to the one above) */
static const unsigned char perm1[56] =
{
57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27,
19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15,
7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4
};
static const unsigned char perm2[48] =
{
14, 17, 11, 24, 1, 5,
3, 28, 15, 6, 21, 10,
23, 19, 12, 4, 26, 8,
16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55,
30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53,
46, 42, 50, 36, 29, 32
};
static const unsigned char perm3[64] =
{
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7
};
static const unsigned char perm4[48] =
{
32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13,
12, 13, 14, 15, 16, 17,
16, 17, 18, 19, 20, 21,
20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29,
28, 29, 30, 31, 32, 1
};
static const unsigned char perm5[32] =
{
16, 7, 20, 21,
29, 12, 28, 17,
1, 15, 23, 26,
5, 18, 31, 10,
2, 8, 24, 14,
32, 27, 3, 9,
19, 13, 30, 6,
22, 11, 4, 25
};
static const unsigned char perm6[64] =
{
40, 8, 48, 16, 56, 24, 64, 32,
39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30,
37, 5, 45, 13, 53, 21, 61, 29,
36, 4, 44, 12, 52, 20, 60, 28,
35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26,
33, 1, 41, 9, 49, 17, 57, 25
};
static const unsigned char sc[16] =
{
1, 1, 2, 2,
2, 2, 2, 2,
1, 2, 2, 2,
2, 2, 2, 1
};
static const unsigned char sbox[8][4][16] =
{
{
{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7},
{0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},
{4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},
{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}
},
{
{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10},
{3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},
{0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15},
{13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}
},
{
{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8},
{13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1},
{13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7},
{1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}
},
{
{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15},
{13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9},
{10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4},
{3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}
},
{
{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9},
{14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6},
{4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14},
{11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}
},
{
{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11},
{10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8},
{9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6},
{4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}
},
{
{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1},
{13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6},
{1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2},
{6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}
},
{
{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7},
{1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2},
{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}
}
};
static void
permute (char *out, char *in, const unsigned char * const p, int n)
{
int i;
for (i = 0; i < n; i++)
out[i] = in[p[i] - 1];
}
static void
left_shift (char *d, int count, int n)
{
char out[64];
int i;
for (i = 0; i < n; i++)
out[i] = d[(i + count) % n];
for (i = 0; i < n; i++)
d[i] = out[i];
}
static void
concat (char *out, char *in1, char *in2, int l1, int l2)
{
while (l1--)
(*out++) = (*in1++);
while (l2--)
(*out++) = (*in2++);
}
static void
xor (char *out, char *in1, char *in2, int n)
{
int i;
for (i = 0; i < n; i++)
out[i] = in1[i] ^ in2[i];
}
static void
dohash (char *out, char *in, char *key, int forw)
{
int i, j, k;
char pk1[56];
char c[28];
char d[28];
char cd[56];
char ki[16][48];
char pd1[64];
char l[32], r[32];
char rl[64];
permute (pk1, key, perm1, 56);
for (i = 0; i < 28; i++)
c[i] = pk1[i];
for (i = 0; i < 28; i++)
d[i] = pk1[i + 28];
for (i = 0; i < 16; i++)
{
left_shift (c, sc[i], 28);
left_shift (d, sc[i], 28);
concat (cd, c, d, 28, 28);
permute (ki[i], cd, perm2, 48);
}
permute (pd1, in, perm3, 64);
for (j = 0; j < 32; j++)
{
l[j] = pd1[j];
r[j] = pd1[j + 32];
}
for (i = 0; i < 16; i++)
{
char er[48];
char erk[48];
char b[8][6];
char cb[32];
char pcb[32];
char r2[32];
permute (er, r, perm4, 48);
xor (erk, er, ki[forw ? i : 15 - i], 48);
for (j = 0; j < 8; j++)
{
for (k = 0; k < 6; k++)
b[j][k] = erk[j * 6 + k];
}
for (j = 0; j < 8; j++)
{
int m, n;
m = (b[j][0] << 1) | b[j][5];
n = (b[j][1] << 3) | (b[j][2] << 2) | (b[j][3] << 1) | b[j][4];
for (k = 0; k < 4; k++)
b[j][k] = (sbox[j][m][n] & (1 << (3 - k))) ? 1 : 0;
}
for (j = 0; j < 8; j++)
{
for (k = 0; k < 4; k++)
cb[j * 4 + k] = b[j][k];
}
permute (pcb, cb, perm5, 32);
xor (r2, l, pcb, 32);
for (j = 0; j < 32; j++)
l[j] = r[j];
for (j = 0; j < 32; j++)
r[j] = r2[j];
}
concat (rl, r, l, 32, 32);
permute (out, rl, perm6, 64);
}
static void
str_to_key (unsigned char *str, unsigned char *key)
{
int i;
key[0] = str[0] >> 1;
key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2);
key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3);
key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4);
key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5);
key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
key[7] = str[6] & 0x7F;
for (i = 0; i < 8; i++)
key[i] = (key[i] << 1);
}
static void
smbhash (unsigned char *out, unsigned char *in, unsigned char *key, int forw)
{
int i;
char outb[64];
char inb[64];
char keyb[64];
unsigned char key2[8];
str_to_key (key, key2);
for (i = 0; i < 64; i++)
{
inb[i] = (in[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
keyb[i] = (key2[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
outb[i] = 0;
}
dohash (outb, inb, keyb, forw);
for (i = 0; i < 8; i++)
out[i] = 0;
for (i = 0; i < 64; i++)
{
if (outb[i])
out[i / 8] |= (1 << (7 - (i % 8)));
}
}
static void
E_P16 (unsigned char *p14, unsigned char *p16)
{
unsigned char sp8[8] =
{
0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25
};
smbhash (p16, sp8, p14, 1);
smbhash (p16 + 8, sp8, p14 + 7, 1);
}
static void
E_P24 (unsigned char *p21, unsigned char *c8, unsigned char *p24)
{
smbhash (p24, c8, p21, 1);
smbhash (p24 + 8, c8, p21 + 7, 1);
smbhash (p24 + 16, c8, p21 + 14, 1);
}
/****************************************************************************/
/* This implements the X/Open SMB password encryption
It takes a password, a 8 byte "crypt key" and puts 24 bytes of
encrypted password into p24 */
void
smb_encrypt (unsigned char *passwd, unsigned char *c8, unsigned char *p24)
{
unsigned char p14[15], p21[21];
int len;
memset (p21, '\0', sizeof(p21));
memset (p14, '\0', sizeof(p14));
len = strlen(passwd);
if(len > (int)sizeof(p14)-1)
len = sizeof(p14)-1;
memcpy (p14, passwd, len);
StringToUpper ((char *) p14);
E_P16 (p14, p21);
smb_owf_encrypt (p21, c8, p24);
}
/****************************************************************************/
/* Routines for Windows NT MD4 Hash functions. */
static int
local_wcslen (short *str)
{
int len = 0;
while ((*str++) != 0)
len++;
return len;
}
/* Convert a string into an NT UNICODE string.
Note that regardless of processor type
this must be in intel (little-endian)
format. */
static int
local_mbstowcs (short *dst, unsigned char *src, int len)
{
int i;
short val;
for (i = 0; i < len; i++)
{
val = (*src++);
WSET(dst,0,val);
dst++;
if (val == 0)
break;
}
return i;
}
/* Creates the MD4 Hash of the users password in NT UNICODE. */
static void
E_md4hash (unsigned char *passwd, unsigned char *p16)
{
short wpwd[129];
int len;
/* Password cannot be longer than 128 characters */
len = strlen ((char *) passwd);
if (len > 128)
len = 128;
/* Password must be converted to NT unicode */
local_mbstowcs (wpwd, passwd, len);
wpwd[len] = 0; /* Ensure string is null terminated */
/* Calculate length in bytes */
len = local_wcslen (wpwd) * sizeof (short);
mdfour (p16, (unsigned char *) wpwd, len);
}
/* Does the des encryption from the NT or LM MD4 hash. */
static void
smb_owf_encrypt (unsigned char *passwd, unsigned char *c8, unsigned char *p24)
{
unsigned char p21[21];
memset (p21, '\0', sizeof(p21));
memcpy (p21, passwd, 16);
E_P24 (p21, c8, p24);
}
/****************************************************************************/
/* Does the NT MD4 hash then des encryption. */
void
smb_nt_encrypt (unsigned char *passwd, unsigned char *c8, unsigned char *p24)
{
unsigned char p21[21];
memset (p21, '\0', sizeof(p21));
E_md4hash (passwd, p21);
smb_owf_encrypt (p21, c8, p24);
}
/****************************************************************************/
static unsigned long A, B, C, D;
static unsigned long
F(unsigned long X, unsigned long Y, unsigned long Z)
{
return (X & Y) | ((~X) & Z);
}
static unsigned long
G(unsigned long X, unsigned long Y, unsigned long Z)
{
return (X & Y) | (X & Z) | (Y & Z);
}
static unsigned long
H(unsigned long X, unsigned long Y, unsigned long Z)
{
return X ^ Y ^ Z;
}
static unsigned long
lshift (unsigned long x, int s)
{
return (x << s) | (x >> (32 - s));
}
#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + 0x5A827999UL,s)
#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + 0x6ED9EBA1UL,s)
/* this applies md4 to 64 byte chunks */
static void
mdfour64 (unsigned long *M)
{
unsigned long AA, BB, CC, DD;
unsigned long X[16];
memcpy(X,M,sizeof(X));
AA = A;
BB = B;
CC = C;
DD = D;
ROUND1 (A, B, C, D, 0, 3);
ROUND1 (D, A, B, C, 1, 7);
ROUND1 (C, D, A, B, 2, 11);
ROUND1 (B, C, D, A, 3, 19);
ROUND1 (A, B, C, D, 4, 3);
ROUND1 (D, A, B, C, 5, 7);
ROUND1 (C, D, A, B, 6, 11);
ROUND1 (B, C, D, A, 7, 19);
ROUND1 (A, B, C, D, 8, 3);
ROUND1 (D, A, B, C, 9, 7);
ROUND1 (C, D, A, B, 10, 11);
ROUND1 (B, C, D, A, 11, 19);
ROUND1 (A, B, C, D, 12, 3);
ROUND1 (D, A, B, C, 13, 7);
ROUND1 (C, D, A, B, 14, 11);
ROUND1 (B, C, D, A, 15, 19);
ROUND2 (A, B, C, D, 0, 3);
ROUND2 (D, A, B, C, 4, 5);
ROUND2 (C, D, A, B, 8, 9);
ROUND2 (B, C, D, A, 12, 13);
ROUND2 (A, B, C, D, 1, 3);
ROUND2 (D, A, B, C, 5, 5);
ROUND2 (C, D, A, B, 9, 9);
ROUND2 (B, C, D, A, 13, 13);
ROUND2 (A, B, C, D, 2, 3);
ROUND2 (D, A, B, C, 6, 5);
ROUND2 (C, D, A, B, 10, 9);
ROUND2 (B, C, D, A, 14, 13);
ROUND2 (A, B, C, D, 3, 3);
ROUND2 (D, A, B, C, 7, 5);
ROUND2 (C, D, A, B, 11, 9);
ROUND2 (B, C, D, A, 15, 13);
ROUND3 (A, B, C, D, 0, 3);
ROUND3 (D, A, B, C, 8, 9);
ROUND3 (C, D, A, B, 4, 11);
ROUND3 (B, C, D, A, 12, 15);
ROUND3 (A, B, C, D, 2, 3);
ROUND3 (D, A, B, C, 10, 9);
ROUND3 (C, D, A, B, 6, 11);
ROUND3 (B, C, D, A, 14, 15);
ROUND3 (A, B, C, D, 1, 3);
ROUND3 (D, A, B, C, 9, 9);
ROUND3 (C, D, A, B, 5, 11);
ROUND3 (B, C, D, A, 13, 15);
ROUND3 (A, B, C, D, 3, 3);
ROUND3 (D, A, B, C, 11, 9);
ROUND3 (C, D, A, B, 7, 11);
ROUND3 (B, C, D, A, 15, 15);
A += AA;
B += BB;
C += CC;
D += DD;
}
static void
copy64 (unsigned long *M, unsigned char *in)
{
int i;
for (i = 0; i < 16; i++)
{
M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
(in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
}
}
static void
copy4 (unsigned char *out, unsigned long x)
{
out[0] = x & 0xFF;
out[1] = (x >> 8) & 0xFF;
out[2] = (x >> 16) & 0xFF;
out[3] = (x >> 24) & 0xFF;
}
/* produce a md4 message digest from data of length n bytes */
static void
mdfour (unsigned char *out, unsigned char *in, int n)
{
unsigned char buf[128];
unsigned long M[16];
unsigned long b = n * 8;
A = 0x67452301;
B = 0xefcdab89;
C = 0x98badcfe;
D = 0x10325476;
while (n > 64)
{
copy64 (M, in);
mdfour64 (M);
in += 64;
n -= 64;
}
memset (buf, 0, sizeof(buf));
memcpy (buf, in, n);
buf[n] = 0x80;
if (n <= 55)
{
copy4 (buf + 56, b);
copy64 (M, buf);
mdfour64 (M);
}
else
{
copy4 (buf + 120, b);
copy64 (M, buf);
mdfour64 (M);
copy64 (M, buf + 64);
mdfour64 (M);
}
memset (buf, 0, sizeof(buf));
copy64 (M, buf);
copy4 (out, A);
copy4 (out + 4, B);
copy4 (out + 8, C);
copy4 (out + 12, D);
}
+83
View File
@@ -0,0 +1,83 @@
/*
* $Id: smb.h,v 1.1.1.1 2005-05-24 13:22:14 obarthel Exp $
*
* :ts=8
*
* smb.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
*/
#ifndef _LINUX_SMB_H
#define _LINUX_SMB_H
#define SMB_PORT 139
#define SMB_MAXNAMELEN 255
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
/*
* Set/Get values in SMB-byte order
*/
#define PVAL(buf,pos) ((unsigned)BVAL(buf,pos))
#define BVAL(buf,pos) (((unsigned char *)(buf))[pos])
#define WVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
#define DVAL(buf,pos) (WVAL(buf,pos)|WVAL(buf,(pos)+2)<<16)
#define BSET(buf,pos,val) (BVAL(buf,pos)=((val) & 0xFF))
#define WSET(buf,pos,val) do { BVAL(buf,pos)=((val) & 0xFF); BVAL(buf,(pos)+1)=(((unsigned)(val))>>8) & 0xFF; } while (0)
#define DSET(buf,pos,val) do { WSET(buf,pos,(val)); WSET(buf,(pos)+2,((unsigned)(val))>>16); } while (0)
#define smb_base(buf) ((byte *)(((byte *)(buf))+4))
enum smb_protocol
{
PROTOCOL_NONE,
PROTOCOL_CORE,
PROTOCOL_COREPLUS,
PROTOCOL_LANMAN1,
PROTOCOL_LANMAN2,
PROTOCOL_NT1
};
enum smb_conn_state
{
CONN_VALID, /* everything's fine */
CONN_INVALID, /* Something went wrong, but did not
try to reconnect yet. */
CONN_RETRIED /* Tried a reconnection, but was refused */
};
struct smb_dskattr
{
word total;
word allocblocks;
word blocksize;
word free;
};
/*
* Contains all relevant data on a SMB networked file.
*/
struct smb_dirent
{
int opened; /* is it open on the fileserver? */
word fileid; /* What id to handle a file with? */
word attr; /* Attribute fields, DOS value */
time_t atime, mtime, ctime; /* Times, as seen by the server, normalized */
/* to UTC. The ugly conversion happens in */
/* proc.c */
unsigned long size; /* File size. */
char *complete_path; /* Complete path, MS-DOS notation, with '\' */
size_t complete_path_size; /* Number of bytes allocated for name */
int len; /* Namelength. */
};
#endif /* _LINUX_SMB_H */
+84
View File
@@ -0,0 +1,84 @@
/*
* $Id: smb_fs.h,v 1.1.1.1 2005-05-24 13:22:13 obarthel Exp $
*
* :ts=8
*
* smb_fs.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
* Modified for supporting SMBlockingX packets by Peter Riede <Noster-Riede@T-Online.de>
*/
#ifndef _LINUX_SMB_FS_H
#define _LINUX_SMB_FS_H
#include <smb/smb.h>
#include <smb/smb_mount.h>
#include <smb/smb_fs_sb.h>
#include <netinet/in.h>
#define SMB_HEADER_LEN 37 /* includes everything up to, but not
including smb_bcc */
/* This structure is used to pass the arguments to smb_proc_lockingX
*/
struct smb_lkrng
{
off_t offset; /* offset to first byte to be (un)locked */
long len; /* bytesize of the block */
};
/* Macros to get at offsets within smb_lkrng and smb_unlkrng
structures. We cannot define these as actual structures
due to possible differences in structure packing
on different machines/compilers. */
#define SMB_LPID_OFFSET(indx) (10 * (indx))
#define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
#define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
#define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
#define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
#define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
#define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
/*****************************************************************************/
/* proc.c */
byte *smb_encode_smb_length(byte *p, dword len);
dword smb_len(byte *packet);
int smb_proc_open(struct smb_server *server, const char *pathname, int len, struct smb_dirent *entry);
int smb_proc_close(struct smb_server *server, word fileid, dword mtime);
int smb_proc_read(struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, char *data, int fs);
int smb_proc_read_raw(struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, char *data);
int smb_proc_write (struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, const char *data);
int smb_proc_write_raw(struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, const char *data);
int smb_proc_lseek (struct smb_server *server, struct smb_dirent *finfo, off_t offset, int mode, off_t * new_position_ptr);
int smb_proc_lockingX (struct smb_server *server, struct smb_dirent *finfo, struct smb_lkrng *locks, int num_entries, int mode, long timeout);
int smb_proc_create(struct smb_server *server, const char *path, int len, struct smb_dirent *entry);
int smb_proc_mv(struct smb_server *server, const char *opath, const int olen, const char *npath, const int nlen);
int smb_proc_mkdir(struct smb_server *server, const char *path, const int len);
int smb_proc_rmdir(struct smb_server *server, const char *path, const int len);
int smb_proc_unlink(struct smb_server *server, const char *path, const int len);
int smb_proc_trunc(struct smb_server *server, word fid, dword length);
int smb_proc_readdir(struct smb_server *server, char *path, int fpos, int cache_size, struct smb_dirent *entry);
int smb_proc_getattr_core(struct smb_server *server, const char *path, int len, struct smb_dirent *entry);
int smb_proc_getattrE(struct smb_server *server, struct smb_dirent *entry);
int smb_proc_setattr_core(struct smb_server *server, const char *path, int len, struct smb_dirent *new_finfo);
int smb_proc_setattrE(struct smb_server *server, word fid, struct smb_dirent *new_entry);
int smb_proc_dskattr (struct smb_server *server, struct smb_dskattr *attr);
int smb_proc_connect(struct smb_server *server);
/* sock.c */
int smb_catch_keepalive(struct smb_server *server);
int smb_dont_catch_keepalive(struct smb_server *server);
int smb_release(struct smb_server *server);
int smb_connect(struct smb_server *server);
int smb_request(struct smb_server *server);
int smb_trans2_request(struct smb_server *server, int *data_len, int *param_len, char **data, char **param);
int smb_request_read_raw(struct smb_server *server, unsigned char *target, int max_len);
int smb_request_write_raw(struct smb_server *server, unsigned const char *source, int length);
#endif /* _LINUX_SMB_FS_H */
+60
View File
@@ -0,0 +1,60 @@
/*
* $Id: smb_fs.h.1,v 1.1.1.1 2005-05-24 13:22:14 obarthel Exp $
*
* :ts=8
*
* smb_fs.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
*/
#ifndef _LINUX_SMB_FS_H
#define _LINUX_SMB_FS_H
#include <smb/smb.h>
#include <smb/smb_mount.h>
#include <smb/smb_fs_sb.h>
#include <netinet/in.h>
#define SMB_HEADER_LEN 37 /* includes everything up to, but not
including smb_bcc */
/*****************************************************************************/
/* proc.c */
byte *smb_encode_smb_length(byte *p, dword len);
dword smb_len(byte *packet);
int smb_proc_open(struct smb_server *server, const char *pathname, int len, struct smb_dirent *entry);
int smb_proc_close(struct smb_server *server, word fileid, dword mtime);
int smb_proc_read(struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, char *data, int fs);
int smb_proc_read_raw(struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, char *data);
int smb_proc_write(struct smb_server *server, struct smb_dirent *finfo, off_t offset, int count, const char *data);
int smb_proc_write_raw(struct smb_server *server, struct smb_dirent *finfo, off_t offset, long count, const char *data);
int smb_proc_create(struct smb_server *server, const char *path, int len, struct smb_dirent *entry);
int smb_proc_mv(struct smb_server *server, const char *opath, const int olen, const char *npath, const int nlen);
int smb_proc_mkdir(struct smb_server *server, const char *path, const int len);
int smb_proc_rmdir(struct smb_server *server, const char *path, const int len);
int smb_proc_unlink(struct smb_server *server, const char *path, const int len);
int smb_proc_trunc(struct smb_server *server, word fid, dword length);
int smb_proc_readdir(struct smb_server *server, char *path, int fpos, int cache_size, struct smb_dirent *entry);
int smb_proc_getattr_core(struct smb_server *server, const char *path, int len, struct smb_dirent *entry);
int smb_proc_getattrE(struct smb_server *server, struct smb_dirent *entry);
int smb_proc_setattr_core(struct smb_server *server, const char *path, int len, struct smb_dirent *new_finfo);
int smb_proc_setattrE(struct smb_server *server, word fid, struct smb_dirent *new_entry);
int smb_proc_dskattr (struct smb_server *server, struct smb_dskattr *attr);
int smb_proc_connect(struct smb_server *server);
/* sock.c */
int smb_catch_keepalive(struct smb_server *server);
int smb_dont_catch_keepalive(struct smb_server *server);
int smb_release(struct smb_server *server);
int smb_connect(struct smb_server *server);
int smb_request(struct smb_server *server);
int smb_trans2_request(struct smb_server *server, int *data_len, int *param_len, char **data, char **param);
int smb_request_read_raw(struct smb_server *server, unsigned char *target, int max_len);
int smb_request_write_raw(struct smb_server *server, unsigned const char *source, int length);
#endif /* _LINUX_SMB_FS_H */
+50
View File
@@ -0,0 +1,50 @@
/*
* $Id: smb_fs_sb.h,v 1.1.1.1 2005-05-24 13:22:14 obarthel Exp $
*
* :ts=8
*
* smb_fs_sb.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
*/
#ifndef _SMB_FS_SB
#define _SMB_FS_SB
#include <smb/smb.h>
#include <smb/smb_mount.h>
struct smb_server
{
enum smb_protocol protocol; /* The protocol this
connection accepts. */
word max_xmit;
int max_recv; /* added by CS */
word server_uid;
word tid;
struct smb_mount_data mount_data; /* We store the complete information here
to be able to reconnect.
*/
unsigned short rcls; /* The error codes we received */
unsigned short err;
unsigned char *packet;
int security_mode;
unsigned char crypt_key[8];
struct smba_server * abstraction;
enum smb_conn_state state;
/* The following are LANMAN 1.0 options transferred to us in
SMBnegprot */
word maxxmt;
word blkmode;
dword sesskey;
};
#endif
+34
View File
@@ -0,0 +1,34 @@
/*
* $Id: smb_mount.h,v 1.1.1.1 2005-05-24 13:22:14 obarthel Exp $
*
* :ts=8
*
* smb_mount.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
*/
#ifndef _SMB_MOUNT_H
#define _SMB_MOUNT_H
#include <netinet/in.h>
struct smb_mount_data
{
int fd;
struct sockaddr_in addr;
char workgroup_name[17];
char server_name[17];
char client_name[17];
char service[64];
char username[64];
char password[64];
unsigned short max_xmit;
};
#endif
+269
View File
@@ -0,0 +1,269 @@
#ifndef _SMBNO_H_
#define _SMBNO_H_
/* these define the attribute byte as seen by DOS */
#define aRONLY (1L<<0)
#define aHIDDEN (1L<<1)
#define aSYSTEM (1L<<2)
#define aVOLID (1L<<3)
#define aDIR (1L<<4)
#define aARCH (1L<<5)
/* error classes */
#define SUCCESS 0 /* The request was successful. */
#define ERRDOS 0x01 /* Error is from the core DOS operating system set. */
#define ERRSRV 0x02 /* Error is generated by the server network file manager. */
#define ERRHRD 0x03 /* Error is an hardware error. */
#define ERRCMD 0xFF /* Command was not in the "SMB" format. */
/* SMB X/Open error codes for the ERRdos error class */
#define ERRbadfunc 1 /* Invalid function (or system call) */
#define ERRbadfile 2 /* File not found (pathname error) */
#define ERRbadpath 3 /* Directory not found */
#define ERRnofids 4 /* Too many open files */
#define ERRnoaccess 5 /* Access denied */
#define ERRbadfid 6 /* Invalid fid */
#define ERRbadmcb 7 /* Memory control blocks destroyed */
#define ERRnomem 8 /* Out of memory */
#define ERRbadmem 9 /* Invalid memory block address */
#define ERRbadenv 10 /* Invalid environment */
#define ERRbadformat 11 /* Invalid format */
#define ERRbadaccess 12 /* Invalid open mode */
#define ERRbaddata 13 /* Invalid data (only from ioctl call) */
#define ERRres 14 /* reserved */
#define ERRbaddrive 15 /* Invalid drive */
#define ERRremcd 16 /* Attempt to delete current directory */
#define ERRdiffdevice 17 /* rename/move across different filesystems */
#define ERRnofiles 18 /* no more files found in file search */
#define ERRbadshare 32 /* Share mode on file conflict with open mode */
#define ERRlock 33 /* Lock request conflicts with existing lock */
#define ERRfilexists 80 /* File in operation already exists */
#define ERRbadpipe 230 /* Named pipe invalid */
#define ERRpipebusy 231 /* All instances of pipe are busy */
#define ERRpipeclosing 232 /* named pipe close in progress */
#define ERRnotconnected 233 /* No process on other end of named pipe */
#define ERRmoredata 234 /* More data to be returned */
#define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
#define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not suppored */
/* Error codes for the ERRSRV class */
#define ERRerror 1 /* Non specific error code */
#define ERRbadpw 2 /* Bad password */
#define ERRbadtype 3 /* reserved */
#define ERRaccess 4 /* No permissions to do the requested operation */
#define ERRinvnid 5 /* tid invalid */
#define ERRinvnetname 6 /* Invalid servername */
#define ERRinvdevice 7 /* Invalid device */
#define ERRqfull 49 /* Print queue full */
#define ERRqtoobig 50 /* Queued item too big */
#define ERRinvpfid 52 /* Invalid print file in smb_fid */
#define ERRsmbcmd 64 /* Unrecognised command */
#define ERRsrverror 65 /* smb server internal error */
#define ERRfilespecs 67 /* fid and pathname invalid combination */
#define ERRbadlink 68 /* reserved */
#define ERRbadpermits 69 /* Access specified for a file is not valid */
#define ERRbadpid 70 /* reserved */
#define ERRsetattrmode 71 /* attribute mode invalid */
#define ERRpaused 81 /* Message server paused */
#define ERRmsgoff 82 /* Not receiving messages */
#define ERRnoroom 83 /* No room for message */
#define ERRrmuns 87 /* too many remote usernames */
#define ERRtimeout 88 /* operation timed out */
#define ERRnoresource 89 /* No resources currently available for request. */
#define ERRtoomanyuids 90 /* too many userids */
#define ERRbaduid 91 /* bad userid */
#define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
#define ERRuseSTD 251 /* temporarily unable to use raw mode, use std.mode */
#define ERRcontMPX 252 /* resume MPX mode */
#define ERRbadPW /* reserved */
#define ERRnosupport 0xFFFF
/* Error codes for the ERRHRD class */
#define ERRnowrite 19 /* read only media */
#define ERRbadunit 20 /* Unknown device */
#define ERRnotready 21 /* Drive not ready */
#define ERRbadcmd 22 /* Unknown command */
#define ERRdata 23 /* Data (CRC) error */
#define ERRbadreq 24 /* Bad request structure length */
#define ERRseek 25
#define ERRbadmedia 26
#define ERRbadsector 27
#define ERRnopaper 28
#define ERRwrite 29 /* write fault */
#define ERRread 30 /* read fault */
#define ERRgeneral 31 /* General hardware failure */
#define ERRwrongdisk 34
#define ERRFCBunavail 35
#define ERRsharebufexc 36 /* share buffer exceeded */
#define ERRdiskfull 39
/* offsets into message for common items */
#define smb_com 8
#define smb_rcls 9
#define smb_reh 10
#define smb_err 11
#define smb_flg 13
#define smb_flg2 14
#define smb_reb 13
#define smb_tid 28
#define smb_pid 30
#define smb_uid 32
#define smb_mid 34
#define smb_wct 36
#define smb_vwv 37
#define smb_vwv0 37
#define smb_vwv1 39
#define smb_vwv2 41
#define smb_vwv3 43
#define smb_vwv4 45
#define smb_vwv5 47
#define smb_vwv6 49
#define smb_vwv7 51
#define smb_vwv8 53
#define smb_vwv9 55
#define smb_vwv10 57
#define smb_vwv11 59
#define smb_vwv12 61
#define smb_vwv13 63
#define smb_vwv14 65
/* these are the trans2 sub fields for primary requests */
#define smb_tpscnt smb_vwv0
#define smb_tdscnt smb_vwv1
#define smb_mprcnt smb_vwv2
#define smb_mdrcnt smb_vwv3
#define smb_msrcnt smb_vwv4
#define smb_flags smb_vwv5
#define smb_timeout smb_vwv6
#define smb_pscnt smb_vwv9
#define smb_psoff smb_vwv10
#define smb_dscnt smb_vwv11
#define smb_dsoff smb_vwv12
#define smb_suwcnt smb_vwv13
#define smb_setup smb_vwv14
#define smb_setup0 smb_setup
#define smb_setup1 (smb_setup+2)
#define smb_setup2 (smb_setup+4)
/* these are for the secondary requests */
#define smb_spscnt smb_vwv2
#define smb_spsoff smb_vwv3
#define smb_spsdisp smb_vwv4
#define smb_sdscnt smb_vwv5
#define smb_sdsoff smb_vwv6
#define smb_sdsdisp smb_vwv7
#define smb_sfid smb_vwv8
/* and these for responses */
#define smb_tprcnt smb_vwv0
#define smb_tdrcnt smb_vwv1
#define smb_prcnt smb_vwv3
#define smb_proff smb_vwv4
#define smb_prdisp smb_vwv5
#define smb_drcnt smb_vwv6
#define smb_droff smb_vwv7
#define smb_drdisp smb_vwv8
/* the complete */
#define SMBmkdir 0x00 /* create directory */
#define SMBrmdir 0x01 /* delete directory */
#define SMBopen 0x02 /* open file */
#define SMBcreate 0x03 /* create file */
#define SMBclose 0x04 /* close file */
#define SMBflush 0x05 /* flush file */
#define SMBunlink 0x06 /* delete file */
#define SMBmv 0x07 /* rename file */
#define SMBgetatr 0x08 /* get file attributes */
#define SMBsetatr 0x09 /* set file attributes */
#define SMBread 0x0A /* read from file */
#define SMBwrite 0x0B /* write to file */
#define SMBlock 0x0C /* lock byte range */
#define SMBunlock 0x0D /* unlock byte range */
#define SMBctemp 0x0E /* create temporary file */
#define SMBmknew 0x0F /* make new file */
#define SMBchkpth 0x10 /* check directory path */
#define SMBexit 0x11 /* process exit */
#define SMBlseek 0x12 /* seek */
#define SMBtcon 0x70 /* tree connect */
#define SMBtconX 0x75 /* tree connect and X */
#define SMBtdis 0x71 /* tree disconnect */
#define SMBnegprot 0x72 /* negotiate protocol */
#define SMBdskattr 0x80 /* get disk attributes */
#define SMBsearch 0x81 /* search directory */
#define SMBsplopen 0xC0 /* open print spool file */
#define SMBsplwr 0xC1 /* write to print spool file */
#define SMBsplclose 0xC2 /* close print spool file */
#define SMBsplretq 0xC3 /* return print queue */
#define SMBsends 0xD0 /* send single block message */
#define SMBsendb 0xD1 /* send broadcast message */
#define SMBfwdname 0xD2 /* forward user name */
#define SMBcancelf 0xD3 /* cancel forward */
#define SMBgetmac 0xD4 /* get machine name */
#define SMBsendstrt 0xD5 /* send start of multi-block message */
#define SMBsendend 0xD6 /* send end of multi-block message */
#define SMBsendtxt 0xD7 /* send text of multi-block message */
/* Core+ protocol */
#define SMBlockread 0x13 /* Lock a range and read */
#define SMBwriteunlock 0x14 /* Unlock a range then write */
#define SMBreadbraw 0x1a /* read a block of data with no smb header */
#define SMBwritebraw 0x1d /* write a block of data with no smb header */
#define SMBwritec 0x20 /* secondary write request */
#define SMBwriteclose 0x2c /* write a file then close it */
/* dos extended protocol */
#define SMBreadBraw 0x1A /* read block raw */
#define SMBreadBmpx 0x1B /* read block multiplexed */
#define SMBreadBs 0x1C /* read block (secondary response) */
#define SMBwriteBraw 0x1D /* write block raw */
#define SMBwriteBmpx 0x1E /* write block multiplexed */
#define SMBwriteBs 0x1F /* write block (secondary request) */
#define SMBwriteC 0x20 /* write complete response */
#define SMBsetattrE 0x22 /* set file attributes expanded */
#define SMBgetattrE 0x23 /* get file attributes expanded */
#define SMBlockingX 0x24 /* lock/unlock byte ranges and X */
#define SMBtrans 0x25 /* transaction - name, bytes in/out */
#define SMBtranss 0x26 /* transaction (secondary request/response) */
#define SMBioctl 0x27 /* IOCTL */
#define SMBioctls 0x28 /* IOCTL (secondary request/response) */
#define SMBcopy 0x29 /* copy */
#define SMBmove 0x2A /* move */
#define SMBecho 0x2B /* echo */
#define SMBopenX 0x2D /* open and X */
#define SMBreadX 0x2E /* read and X */
#define SMBwriteX 0x2F /* write and X */
#define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */
#define SMBtconX 0x75 /* tree connect and X */
#define SMBffirst 0x82 /* find first */
#define SMBfunique 0x83 /* find unique */
#define SMBfclose 0x84 /* find close */
#define SMBinvalid 0xFE /* invalid command */
/* Extended 2.0 protocol */
#define SMBtrans2 0x32 /* TRANS2 protocol set */
#define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */
#define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */
#define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
#define SMBulogoffX 0x74 /* user logoff */
/* these are the TRANS2 sub commands */
#define TRANSACT2_OPEN 0
#define TRANSACT2_FINDFIRST 1
#define TRANSACT2_FINDNEXT 2
#define TRANSACT2_QFSINFO 3
#define TRANSACT2_SETFSINFO 4
#define TRANSACT2_QPATHINFO 5
#define TRANSACT2_SETPATHINFO 6
#define TRANSACT2_QFILEINFO 7
#define TRANSACT2_SETFILEINFO 8
#define TRANSACT2_FSCTL 9
#define TRANSACT2_IOCTL 10
#define TRANSACT2_FINDNOTIFYFIRST 11
#define TRANSACT2_FINDNOTIFYNEXT 12
#define TRANSACT2_MKDIR 13
#endif /* _SMBNO_H_ */
+6384
View File
File diff suppressed because it is too large Load Diff
+2616
View File
File diff suppressed because it is too large Load Diff
+118
View File
@@ -0,0 +1,118 @@
#
# $Id: smakefile,v 1.1.1.1 2005-05-24 13:22:12 obarthel Exp $
#
# :ts=8
#
# SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
#
# Copyright (C) 2000-2004 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
.c.o:
sc $(CFLAGS) $<
@ctags >tagfiles/$* $<
.asm.o:
asm $(ASMFLAGS) $<
###############################################################################
PROJECT = smbfs
###############################################################################
#############################################################################
#
# Program version
#
#############################################################################
VERSION = 1
###############################################################################
OPTIMIZE = optimize opttime optinline optinlocal optschedule
CPU = any
#CPU = 060
DEBUG = line
#DEBUG = symbolflush noopt define=DEBUG
###############################################################################
CFLAGS = idlen=64 comnest streq strmerge nostkchk \
$(OPTIMIZE) cpu=$(CPU) debug=$(DEBUG) data=faronly \
params=register idir=netinclude idir=include \
gst=system_headers.gst
LFLAGS = smallcode smalldata noicons batch
###############################################################################
OBJS = main.o proc.o smb_abstraction.o sock.o crypt.o
###############################################################################
LIBS = lib:scnb.lib lib:amiga.lib lib:debug.lib
###############################################################################
all: tagfiles system_headers.gst $(PROJECT)
tagfiles:
makedir $@
$(PROJECT): $(OBJS) system_headers.gst Assert.o
slink $(OBJS) to $@.debug lib $(LIBS) Assert.o $(LFLAGS) \
map $(PROJECT).map,fhx fwidth 32 pwidth 32 swidth 32
slink $@.debug to $@ noicons nodebug
@type tagfiles/\#? >t:tags
@copy t:tags ""
@delete >nil: t:tags
system_headers.gst: system_headers.h system_headers.c
gst unload $@
sc $(CFLAGS) nodebug noobjname nogst makegst=$@ system_headers.c
###############################################################################
clean:
-delete \#?.o $(PROJECT)(%|.debug)
realclean: clean
-delete system_headers.gst tags tagfiles \#?.map all
###############################################################################
mkid:
mkid -v \#?.(c|h|a|asm|i) include/smb/\#?.h \
# netinclude/\#?/\#?.h \
# netinclude/\#?.h
update:
mkid -v -u
version:
bumprev $(VERSION) $(PROJECT)
###############################################################################
cvs-tag:
cvs -q tag V$(VERSION)_`type $(PROJECT)_rev.rev`
cvs-update:
cvs update
File diff suppressed because it is too large Load Diff
+86
View File
@@ -0,0 +1,86 @@
/*
* $Id: smb_abstraction.h,v 1.1.1.1 2005-05-24 13:22:13 obarthel Exp $
*
* :ts=8
*
* Name: smb_abstraction.h
* Description: Interface to the smb abstraction layer.
* Author: Christian Starkjohann <cs@hal.kph.tuwien.ac.at>
* Date: 1996-12-31
* Copyright: GNU-GPL
*
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
* Modified to support record locking by Peter Riede <Noster-Riede@T-Online.de>
*/
#ifndef _SMB_ABSTRACTION_H
#define _SMB_ABSTRACTION_H 1
/****************************************************************************/
/* Forward declaration to keep the compiler happy. */
#ifndef _SMB_FS_SB
struct smb_server;
#endif /* _SMB_FS_SB */
/****************************************************************************/
typedef struct smba_connect_parameters
{
char server_ipname[64];
char service[64];
char *server_name;
char *client_name;
char *username;
char *password;
int max_xmit;
} smba_connect_parameters_t;
typedef struct smba_stat
{
unsigned is_dir:1;
unsigned is_wp:1;
unsigned is_hidden:1;
unsigned is_system:1;
unsigned is_archive:1;
int size;
long atime;
long ctime;
long mtime;
} smba_stat_t;
/****************************************************************************/
typedef struct smba_server smba_server_t;
typedef struct smba_file smba_file_t;
/****************************************************************************/
typedef int (*smba_callback_t) (void *d, int fpos, int nextpos, char *name, int eof, smba_stat_t * st);
/****************************************************************************/
int smba_open(smba_server_t *s, char *name, size_t name_size, smba_file_t **file);
void smba_close(smba_file_t *f);
int smba_read(smba_file_t *f, char *data, long len, long offset);
int smba_write(smba_file_t *f, char *data, long len, long offset);
long smba_seek (smba_file_t *f, long offset, long mode, off_t * new_position_ptr);
int smba_lockrec (smba_file_t *f, long offset, long len, long mode, int unlocked, long timeout);
int smba_getattr(smba_file_t *f, smba_stat_t *data);
int smba_setattr(smba_file_t *f, smba_stat_t *data);
int smba_readdir(smba_file_t *f, long offs, void *d, smba_callback_t callback);
int smba_create(smba_file_t *dir, const char *name, smba_stat_t *attr);
int smba_mkdir(smba_file_t *dir, const char *name);
int smba_remove(smba_server_t *s, char *path);
int smba_rmdir(smba_server_t *s, char *path);
int smba_rename(smba_server_t *s, char *from, char *to);
int smba_statfs(smba_server_t *s, long *bsize, long *blocks, long *bfree);
void smb_invalidate_all_inodes(struct smb_server *server);
int smba_start(char *service, char *opt_workgroup, char *opt_username, char *opt_password, char *opt_clientname, char *opt_servername, int opt_cachesize, smba_server_t **result);
void smba_disconnect(smba_server_t *server);
int smba_get_dircache_size(struct smba_server * server);
int smba_change_dircache_size(struct smba_server * server,int cache_size);
/****************************************************************************/
#endif /* _SMB_ABSTRACTION_H */
+159
View File
@@ -0,0 +1,159 @@
/*
* $Id: smbfs.h,v 1.1.1.1 2005-05-24 13:22:12 obarthel Exp $
*
* :ts=4
*
* SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
*
* Copyright (C) 2000-2004 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _SMBFS_H
#define _SMBFS_H 1
/****************************************************************************/
#ifndef _SYSTEM_HEADERS_H
#include "system_headers.h"
#endif /* _SYSTEM_HEADERS_H */
#ifndef _ASSERT_H
#include "assert.h"
#endif /* _ASSERT_H */
/****************************************************************************/
#define SAME (0)
#define OK (0)
#define NOT !
/****************************************************************************/
#ifndef ZERO
#define ZERO ((BPTR)NULL)
#endif /* ZERO */
/****************************************************************************/
#ifndef AMIGA_COMPILER_H
/****************************************************************************/
#if defined(__SASC)
#define FAR __far
#define ASM __asm
#define REG(r,p) register __##r p
#define INLINE __inline
#endif /* __SASC */
#if defined(__GNUC__)
#define FAR
#define ASM
#define REG(r,p) p __asm(#r)
#define INLINE __inline__
#endif /* __GNUC__ */
/****************************************************************************/
#ifndef VARARGS68K
#define VARARGS68K
#endif /* VARARGS68K */
/*****************************************************************************/
#endif /* AMIGA_COMPILER_H */
/*****************************************************************************/
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif /* min */
/****************************************************************************/
#if defined(__SASC)
extern struct Library * FAR AbsExecBase;
#else
#ifndef AbsExecBase
#define AbsExecBase (*(struct Library **)4)
#endif /* AbsExecBase */
#endif /* __SASC */
/****************************************************************************/
extern struct Library * SocketBase;
extern struct Library * SysBase;
extern struct Library * DOSBase;
/****************************************************************************/
#if defined(__amigaos4__)
/****************************************************************************/
extern struct ExecIFace * IExec;
extern struct DOSIFace * IDOS;
extern struct SocketIFace * ISocket;
/****************************************************************************/
#endif /* __amigaos4__ */
/****************************************************************************/
extern int h_errno;
/****************************************************************************/
extern int BroadcastNameQuery(char *name, char *scope, UBYTE *address);
extern LONG CompareNames(STRPTR a,STRPTR b);
extern LONG GetTimeZoneDelta(VOID);
extern STRPTR amitcp_strerror(int error);
extern STRPTR host_strerror(int error);
extern time_t MakeTime(const struct tm * const tm);
extern ULONG GetCurrentTime(VOID);
extern VOID LocalTime(time_t seconds,struct tm * tm);
extern VOID VARARGS68K ReportError(STRPTR fmt,...);
extern VOID StringToUpper(STRPTR s);
extern VOID VARARGS68K SPrintf(STRPTR buffer, STRPTR formatString,...);
/****************************************************************************/
size_t strlcpy(char *dst, const char *src, size_t siz);
size_t strlcat(char *dst, const char *src, size_t siz);
/****************************************************************************/
extern void smb_encrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
extern void smb_nt_encrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
/****************************************************************************/
extern VOID FreeMemory(APTR address);
extern APTR AllocateMemory(ULONG size);
#define malloc(s) AllocateMemory(s)
#define free(m) FreeMemory(m)
/****************************************************************************/
#undef memcpy
#define memcpy(to,from,size) ((void)CopyMem((APTR)(from),(APTR)(to),(ULONG)(size)))
/****************************************************************************/
#endif /* _SMBFS_H */
+6
View File
@@ -0,0 +1,6 @@
#define VERSION 1
#define REVISION 66
#define DATE "10.6.2004"
#define VERS "smbfs 1.66"
#define VSTRING "smbfs 1.66 (10.6.2004)\r\n"
#define VERSTAG "\0$VER: smbfs 1.66 (10.6.2004)"
+1
View File
@@ -0,0 +1 @@
66
+524
View File
@@ -0,0 +1,524 @@
/*
* $Id: sock.c,v 1.1.1.1 2005-05-24 13:22:13 obarthel Exp $
*
* :ts=8
*
* sock.c
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
* Modified by Christian Starkjohann <cs@hal.kph.tuwien.ac.at>
* Modified for use with AmigaOS by Olaf Barthel <olsen@sourcery.han.de>
*/
#include "smbfs.h"
/*****************************************************************************/
#include <smb/smb_fs.h>
#include <smb/smb.h>
#include <smb/smbno.h>
/*****************************************************************************/
#include "smb_abstraction.h"
/*****************************************************************************/
/* smb_receive_raw
fs points to the correct segment, sock != NULL, target != NULL
The smb header is only stored if want_header != 0. */
static int
smb_receive_raw (int sock_fd, unsigned char *target, int max_raw_length, int want_header)
{
int len, result;
int already_read;
unsigned char peek_buf[4];
re_recv:
result = recvfrom (sock_fd, (void *) peek_buf, 4, 0, NULL, NULL);
if (result < 0)
{
LOG (("smb_receive_raw: recv error = %ld\n", errno));
result = (-errno);
goto out;
}
if (result < 4)
{
LOG (("smb_receive_raw: got less than 4 bytes\n"));
result = -EIO;
goto out;
}
switch (peek_buf[0])
{
case 0x00:
case 0x82:
break;
case 0x85:
LOG (("smb_receive_raw: Got SESSION KEEP ALIVE\n"));
goto re_recv;
default:
LOG (("smb_receive_raw: Invalid packet 0x%02lx\n", peek_buf[0]));
result = -EIO;
goto out;
}
/* The length in the RFC NB header is the raw data length */
len = smb_len (peek_buf);
if (len > max_raw_length)
{
LOG (("smb_receive_raw: Received length (%ld) > max_xmit (%ld)!\n", len, max_raw_length));
result = -EIO;
goto out;
}
if (want_header != 0)
{
memcpy (target, peek_buf, 4);
target += 4;
}
already_read = 0;
while (already_read < len)
{
result = recvfrom (sock_fd, (void *) (target + already_read), len - already_read, 0, NULL, NULL);
if (result < 0)
{
LOG (("smb_receive_raw: recvfrom error = %ld\n", errno));
result = (-errno);
goto out;
}
already_read += result;
}
result = already_read;
out:
return result;
}
/* smb_receive
fs points to the correct segment, server != NULL, sock!=NULL */
static int
smb_receive (struct smb_server *server, int sock_fd)
{
byte * packet = server->packet;
int result;
result = smb_receive_raw (sock_fd, packet,
server->max_recv - 4, /* max_xmit in server includes NB header */
1); /* We want the header */
if (result < 0)
{
LOG (("smb_receive: receive error: %ld\n", result));
goto out;
}
server->rcls = *((unsigned char *) (packet + 9));
server->err = WVAL (packet, 11);
if (server->rcls != 0)
LOG (("smb_receive: rcls=%ld, err=%ld\n", server->rcls, server->err));
out:
return result;
}
/* smb_receive's preconditions also apply here. */
static int
smb_receive_trans2 (struct smb_server *server, int sock_fd, int *data_len, int *param_len, char **data, char **param)
{
unsigned char *inbuf = server->packet;
int total_data;
int total_param;
int result;
LOG (("smb_receive_trans2: enter\n"));
(*data_len) = (*param_len) = 0;
(*param) = (*data) = NULL;
result = smb_receive (server, sock_fd);
if (result < 0)
goto fail;
if (server->rcls != 0)
goto fail;
/* parse out the lengths */
total_data = WVAL (inbuf, smb_tdrcnt);
total_param = WVAL (inbuf, smb_tprcnt);
if ((total_data > server->max_xmit) || (total_param > server->max_xmit))
{
LOG (("smb_receive_trans2: data/param too long\n"));
result = -EIO;
goto fail;
}
/* Allocate it, but only if there is something to allocate
in the first place. ZZZ this may not be the proper approach,
and we should return an error for 'no data'. */
if(total_data > 0)
{
(*data) = malloc (total_data);
if ((*data) == NULL)
{
LOG (("smb_receive_trans2: could not alloc data area\n"));
result = -ENOMEM;
goto fail;
}
}
else
{
(*data) = NULL;
}
/* Allocate it, but only if there is something to allocate
in the first place. ZZZ this may not be the proper approach,
and we should return an error for 'no parameters'. */
if(total_param > 0)
{
(*param) = malloc(total_param);
if ((*param) == NULL)
{
LOG (("smb_receive_trans2: could not alloc param area\n"));
result = -ENOMEM;
goto fail;
}
}
else
{
(*param) = NULL;
}
LOG (("smb_rec_trans2: total_data/param: %ld/%ld\n", total_data, total_param));
while (1)
{
if (WVAL (inbuf, smb_prdisp) + WVAL (inbuf, smb_prcnt) > (unsigned int)total_param)
{
LOG (("smb_receive_trans2: invalid parameters\n"));
result = -EIO;
goto fail;
}
if((*param) != NULL)
memcpy ((*param) + WVAL (inbuf, smb_prdisp), smb_base (inbuf) + WVAL (inbuf, smb_proff), WVAL (inbuf, smb_prcnt));
(*param_len) += WVAL (inbuf, smb_prcnt);
if (WVAL (inbuf, smb_drdisp) + WVAL (inbuf, smb_drcnt) > (unsigned int)total_data)
{
LOG (("smb_receive_trans2: invalid data block\n"));
result = -EIO;
goto fail;
}
if((*data) != NULL)
memcpy ((*data) + WVAL (inbuf, smb_drdisp), smb_base (inbuf) + WVAL (inbuf, smb_droff), WVAL (inbuf, smb_drcnt));
(*data_len) += WVAL (inbuf, smb_drcnt);
LOG (("smb_rec_trans2: drcnt/prcnt: %ld/%ld\n", WVAL (inbuf, smb_drcnt), WVAL (inbuf, smb_prcnt)));
/* parse out the total lengths again - they can shrink! */
if ((WVAL (inbuf, smb_tdrcnt) > (unsigned int)total_data) || (WVAL (inbuf, smb_tprcnt) > (unsigned int)total_param))
{
LOG (("smb_receive_trans2: data/params grew!\n"));
result = -EIO;
goto fail;
}
total_data = WVAL (inbuf, smb_tdrcnt);
total_param = WVAL (inbuf, smb_tprcnt);
if (total_data <= (*data_len) && total_param <= (*param_len))
break;
result = smb_receive (server, sock_fd);
if (result < 0)
goto fail;
if (server->rcls != 0)
{
result = -EIO;
goto fail;
}
}
LOG (("smb_receive_trans2: normal exit\n"));
return 0;
fail:
LOG (("smb_receive_trans2: failed exit\n"));
if((*param) != NULL)
free (*param);
if((*data) != NULL)
free (*data);
(*param) = (*data) = NULL;
return result;
}
int
smb_release (struct smb_server *server)
{
int result;
if (server->mount_data.fd >= 0)
CloseSocket (server->mount_data.fd);
server->mount_data.fd = socket (AF_INET, SOCK_STREAM, 0);
if (server->mount_data.fd < 0)
{
result = (-errno);
goto out;
}
result = 0;
out:
return result;
}
int
smb_connect (struct smb_server *server)
{
int sock_fd = server->mount_data.fd;
int result;
if (sock_fd < 0)
{
result = (-EBADF);
goto out;
}
result = connect (sock_fd, (struct sockaddr *)&server->mount_data.addr, sizeof(struct sockaddr_in));
if(result < 0)
result = (-errno);
out:
return(result);
}
/*****************************************************************************
*
* This routine was once taken from nfs, which is for udp. Here TCP does
* most of the ugly stuff for us (thanks, Alan!)
*
****************************************************************************/
int
smb_request (struct smb_server *server)
{
int len, result;
int sock_fd = server->mount_data.fd;
unsigned char *buffer = server->packet;
if ((sock_fd < 0) || (buffer == NULL))
{
LOG (("smb_request: Bad server!\n"));
result = -EBADF;
goto out;
}
if (server->state != CONN_VALID)
{
result = -EIO;
goto out;
}
len = smb_len (buffer) + 4;
LOG (("smb_request: len = %ld cmd = 0x%lx\n", len, buffer[8]));
result = send (sock_fd, (void *) buffer, len, 0);
if (result < 0)
{
LOG (("smb_request: send error = %ld\n", errno));
result = (-errno);
}
else
{
result = smb_receive (server, sock_fd);
}
out:
if (result < 0)
{
server->state = CONN_INVALID;
smb_invalidate_all_inodes (server);
}
LOG (("smb_request: result = %ld\n", result));
return (result);
}
/* This is not really a trans2 request, we assume that you only have
one packet to send. */
int
smb_trans2_request (struct smb_server *server, int *data_len, int *param_len, char **data, char **param)
{
int len, result;
int sock_fd = server->mount_data.fd;
unsigned char *buffer = server->packet;
if (server->state != CONN_VALID)
{
result = -EIO;
goto out;
}
len = smb_len (buffer) + 4;
LOG (("smb_request: len = %ld cmd = 0x%02lx\n", len, buffer[8]));
result = send (sock_fd, (void *) buffer, len, 0);
if (result < 0)
{
LOG (("smb_trans2_request: send error = %ld\n", errno));
result = (-errno);
}
else
{
result = smb_receive_trans2 (server, sock_fd, data_len, param_len, data, param);
}
out:
if (result < 0)
{
server->state = CONN_INVALID;
smb_invalidate_all_inodes (server);
}
LOG (("smb_trans2_request: result = %ld\n", result));
return result;
}
/* target must be in user space */
int
smb_request_read_raw (struct smb_server *server, unsigned char *target, int max_len)
{
int len, result;
int sock_fd = server->mount_data.fd;
unsigned char *buffer = server->packet;
if (server->state != CONN_VALID)
{
result = -EIO;
goto out;
}
len = smb_len (buffer) + 4;
LOG (("smb_request_read_raw: len = %ld cmd = 0x%02lx\n", len, buffer[8]));
LOG (("smb_request_read_raw: target=%lx, max_len=%ld\n", (unsigned int) target, max_len));
LOG (("smb_request_read_raw: buffer=%lx, sock=%lx\n", (unsigned int) buffer, (unsigned int) sock_fd));
result = send (sock_fd, (void *) buffer, len, 0);
LOG (("smb_request_read_raw: send returned %ld\n", result));
if (result < 0)
{
LOG (("smb_request_read_raw: send error = %ld\n", errno));
result = (-errno);
}
else
{
result = smb_receive_raw (sock_fd, target, max_len, 0);
}
out:
if (result < 0)
{
server->state = CONN_INVALID;
smb_invalidate_all_inodes (server);
}
LOG (("smb_request_read_raw: result = %ld\n", result));
return result;
}
/* Source must be in user space. smb_request_write_raw assumes that
the request SMBwriteBraw has been completed successfully, so that
we can send the raw data now. */
int
smb_request_write_raw (struct smb_server *server, unsigned const char *source, int length)
{
int result;
byte nb_header[4];
int sock_fd = server->mount_data.fd;
if (server->state != CONN_VALID)
{
result = -EIO;
goto out;
}
smb_encode_smb_length (nb_header, length);
result = send (sock_fd, (void *) nb_header, 4, 0);
if (result == 4)
{
result = send (sock_fd, (void *) source, length, 0);
if(result < 0)
result = (-errno);
}
else
{
if(result < 0)
result = (-errno);
else
result = -EIO;
}
LOG (("smb_request_write_raw: send returned %ld\n", result));
if (result == length)
result = smb_receive (server, sock_fd);
out:
if (result < 0)
{
server->state = CONN_INVALID;
smb_invalidate_all_inodes (server);
}
if (result > 0)
result = length;
LOG (("smb_request_write_raw: result = %ld\n", result));
return result;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* $Id: system_headers.c,v 1.1.1.1 2005-05-24 13:22:13 obarthel Exp $
*
* :ts=4
*
* SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
*
* Copyright (C) 2000-2003 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*****************************************************************************/
#ifndef _SYSTEM_HEADERS_H
#include "system_headers.h"
#endif /* _SYSTEM_HEADERS_H */
+121
View File
@@ -0,0 +1,121 @@
/*
* $Id: system_headers.h,v 1.1.1.1 2005-05-24 13:22:13 obarthel Exp $
*
* :ts=4
*
* SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
*
* Copyright (C) 2000-2003 by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _SYSTEM_HEADERS_H
#define _SYSTEM_HEADERS_H 1
/*****************************************************************************/
#define __USE_INLINE__
#define __NOGLOBALIFACE__
#define __NOLIBBASE__
/****************************************************************************/
#if defined(__SASC)
#define USE_BUILTIN_MATH
#endif /* __SASC */
/*****************************************************************************/
#define NULL ((APTR)0L)
#include <exec/types.h>
/*****************************************************************************/
#define byte IGNORE_THIS
/*****************************************************************************/
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <dos/dosextens.h>
#include <dos/dosasl.h>
#include <dos/dostags.h>
#include <dos/filehandler.h>
#include <dos/rdargs.h>
#include <dos/exall.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <devices/inputevent.h>
#include <devices/input.h>
#include <libraries/locale.h>
/*#include <bsdsocket/socketbasetags.h>*/
#include <utility/date.h>
#include <utility/tagitem.h>
/*****************************************************************************/
#include <clib/alib_protos.h>
/*****************************************************************************/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/bsdsocket.h>
#include <proto/utility.h>
#include <proto/locale.h>
#include <proto/timer.h>
#include <proto/icon.h>
/*****************************************************************************/
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
/*#include <sys/param.h>*/
/*#include <sys/ioctl.h>*/
#include <sys/stat.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <net/if.h>
#include <unistd.h>
#include <netdb.h>
/*****************************************************************************/
#undef byte
/*****************************************************************************/
#endif /* _SYSTEM_HEADERS_H */