- 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
+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 */