Import ncpfs 0.1

This commit is contained in:
ncpfs archive import
2026-04-28 20:39:57 +02:00
parent bcdcf5bb8c
commit 7591e85f7b
25 changed files with 4260 additions and 120 deletions

BIN
.downloads/ncpfs-0.1.tgz Normal file

Binary file not shown.

339
COPYING Normal file
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.

117
LICENSE
View File

@@ -1,117 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 Lesser 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.
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
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 an idea of what it does. Copyright (C) yyyy 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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) year 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

78
Makefile Normal file
View File

@@ -0,0 +1,78 @@
#
# Makefile for the linux ncp-filesystem routines.
#
INCLUDES = -I/usr/src/linux/include
CFLAGS = -Wall -Wstrict-prototypes -O2 -DMODULE -fomit-frame-pointer \
$(INCLUDES) \
# -DDEBUG_NCP=1 -DDEBUG_NCP_MALLOC
# -DDEBUG_NCP_MALLOC
CC = gcc -D__KERNEL__ -I.
AS = as
ARCH = i386
.c.s:
$(CC) $(CFLAGS) -S $<
.c.o:
$(CC) $(CFLAGS) -c $<
.s.o:
$(AS) -o $*.o $<
OBJS= inode.o dir.o file.o sock.o ioctl.o ncplib.o nwcrypt.o
all: ncpfs.o ncpmount
ncpfs.o: $(OBJS)
$(LD) -r -o ncpfs.o $(OBJS)
ncpmount: ncpmount.o
gcc -o ncpmount ncpmount.o
ncpmount.o: ncpmount.c
gcc -c ncpmount.c -Wall -I. -g
ncplib_user.o: ncplib.o
gcc -c ncplib.c -Wall -I. -g -o ncplib_user.o
nwcrypt.o: nwcrypt.c
gcc -c -O2 -Wall nwcrypt.c
ncpumount: ncpumount.o
gcc -o ncpumount ncpumount.o
dep:
$(CPP) -M $(INCLUDES) *.c > .depend
clean:
rm -f *.o *~
realclean: clean
rm -fr ncpmount ncpumount .depend $(DISTFILE) mnt
modules: ncpfs.o
SRCPATH=$(shell pwd)
SRCDIR=$(shell basename $(SRCPATH))
DISTFILE=$(SRCDIR).tgz
BACKUPFILE=ncpfs01.tgz
HOME=/home/me
backup:
(rm -f $(DISTFILE); cd ..; tar cvf - $(SRCDIR) | gzip -1 \
> $(HOME)/tarz/backup/$(BACKUPFILE))
(cd $(HOME)/tarz/backup; ls -l $(BACKUPFILE); mcopy $(BACKUPFILE) a:)
dist: realclean
(cd ..; \
tar cvf - $(SRCDIR) | \
gzip -9 > $(DISTFILE); \
mv $(DISTFILE) $(SRCDIR))
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

90
README Normal file
View File

@@ -0,0 +1,90 @@
This is version 0.1 of ncpfs, a free NetWare client for Linux. For me
it works with 1.3.32 and 1.3.35.
I know that this piece of software is VERY incomplete, as it only
gives you read-only access. I have to apologize for that. But I
thought I should make it publically available, because I have tried to
ask several people about the legal status of the code. I did not get
very satisfying answers. So I publish ncpfs to open it for
criticism. If nobody complains, I will go on working.
To install ncpfs, just type 'make', 'insmod ncpfs.o' and
'ncpmount server mount-point user password'. Please note that your IPX
system has to be configured correctly. There has to be a route to the
internal network of your server. I use tools from the dosemu-0.60.3
distribution to do this. Once again I have to apologize for this
cryptic description, but before I'm sure that I'm allowed to do all
this I will not do more.
I read that Novell is not very open when it comes to technical details
of the Netware Core Protocol. This might be especially true for the
encryption stuff. I took the necessary code from Dr. Dobb's Journal
11/93, Undocumented Corner. I asked Jon Erickson <jon@ddj.com> about
the legal status of this piece of code:
---
Date: Thu, 12 Oct 1995 13:44:18 +0100
From: Volker Lendecke <lendecke>
To: jon@ddj.com
Subject: legal status of your source code?
Hello!
I hope that you're the right one to write to, you are the first on your WWW
server. If you are not, could you please forward this message to the right
person? Thanks.
I'm currently exploring the possibility to write a free (in the GNU GPL
sense) NCP filesystem, which would allow me to access a novell server
transparently. For that I would like to use the encryption functions you
published in DDJ 11/93, Undocumented Corner. I would make some cosmetic
changes, such as other indentations, minor code changes and so on. But I do
not know if that allows me to publish this code under GPL. One alternative
would be to publish a diff against your listing, but that would probably
contain much of your code as well, and it would be very inconvenient for
the average user.
I think that you have some kind of standard procedure for such a
case. Please tell me what I should do.
Many thanks in advance,
Volker
+=================================================================+
! Volker Lendecke Internet: lendecke@namu01.gwdg.de !
! D-37081 Goettingen, Germany !
+=================================================================+
--
I got the following answer:
---
From: Jon Erickson <jon@ddj.com>
X-Mailer: SCO System V Mail (version 3.2)
To: lendecke@namu01.gwdg.de
Subject: Re: legal status of your source code?
Date: Thu, 12 Oct 95 5:42:56 PDT
Volker,
Code from Dr. Dobb's Journal related articles is provided for
anyone to use. Clearly, the author of the article should be
given credit.
Jon Erickson
---
With this answer in mind, I took the code and made it a bit more
C-like. The original seemed to be translated by a mechanical pascal->c
translator. Jon's answer encouraged me to publish nwcrypt.c under the
GPL. If anybody who knows more about copyright and sees any problems
with this, please tell me.

View File

@@ -1,3 +0,0 @@
# ncpfs
Historic import of ncpfs releases: Linux utilities for accessing Novell NetWare/NCP resources, imported from the old ftp.gwdg.de mirror with version tags.

917
dir.c Normal file
View File

@@ -0,0 +1,917 @@
/*
* dir.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/stat.h>
#include <linux/kernel.h>
#include <linux/malloc.h>
#include <linux/mm.h>
#include <linux/ncp_fs.h>
#include <asm/segment.h>
#include <linux/errno.h>
#include "ncplib.h"
#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
#define ROUND_UP(x) (((x)+3) & ~3)
static int
ncp_dir_read(struct inode *inode, struct file *filp, char *buf, int count);
static int
ncp_readdir(struct inode *inode, struct file *filp,
void *dirent, filldir_t filldir);
static int
ncp_read_volume_list(struct ncp_server *server, int start_with,
int cache_size);
static int
ncp_do_readdir(struct ncp_server *server, struct inode *dir, int fpos,
int cache_size, struct ncp_dirent *entry);
static int
get_pname(struct inode *dir, const char *name, int len,
char **res_path, int *res_len);
static int
get_pname_static(struct inode *dir, const char *name, int len,
char *path, int *res_len);
static struct inode *
ncp_iget(struct inode *dir, char *path, struct ncp_dirent *finfo);
static void
put_pname(char *path);
static struct ncp_inode_info *
ncp_find_inode(struct ncp_server *server, const char *path);
static int
ncp_lookup(struct inode *dir, const char *__name,
int len, struct inode **result);
static int
date_dos2unix(unsigned short time,unsigned short date);
/*
static void
date_unix2dos(int unix_date,unsigned short *time, unsigned short *date);
*/
static inline void
str_upper(char *name)
{
while (*name) {
if (*name >= 'a' && *name <= 'z')
*name -= ('a' - 'A');
name++;
}
}
static inline void
str_lower(char *name)
{
while (*name) {
if (*name >= 'A' && *name <= 'Z')
*name += ('a' - 'A');
name ++;
}
}
static struct file_operations ncp_dir_operations = {
NULL, /* lseek - default */
ncp_dir_read, /* read - bad */
NULL, /* write - bad */
ncp_readdir, /* readdir */
NULL, /* select - default */
ncp_ioctl, /* ioctl - default */
NULL, /* mmap */
NULL, /* no special open code */
NULL, /* no special release code */
NULL /* fsync */
};
struct inode_operations ncp_dir_inode_operations = {
&ncp_dir_operations, /* default directory file ops */
NULL, /* create */
ncp_lookup, /* lookup */
NULL, /* link */
NULL, /* unlink */
NULL, /* symlink */
NULL, /* mkdir */
NULL, /* rmdir */
NULL, /* mknod */
NULL, /* rename */
NULL, /* readlink */
NULL, /* follow_link */
NULL, /* bmap */
NULL, /* truncate */
NULL, /* permission */
NULL /* smap */
};
static int
ncp_dir_read(struct inode *inode, struct file *filp, char *buf, int count)
{
return -EISDIR;
}
/* In ncpfs, we have unique inodes across all mounted filesystems, for
all inodes that are in memory. That's why it's enough to index the
directory cache by the inode number. */
static unsigned long c_ino = 0;
static int c_size;
static int c_seen_eof;
static int c_last_returned_index;
static struct ncp_dirent* c_entry = NULL;
static int
ncp_readdir(struct inode *inode, struct file *filp,
void *dirent, filldir_t filldir)
{
int result, i = 0;
int index = 0;
struct ncp_dirent *entry = NULL;
struct ncp_server *server = NCP_SERVER(inode);
DDPRINTK("ncp_readdir: filp->f_pos = %d\n", (int)filp->f_pos);
DDPRINTK("ncp_readdir: inode->i_ino = %ld, c_ino = %ld\n",
inode->i_ino, c_ino);
if (!inode || !S_ISDIR(inode->i_mode)) {
printk("ncp_readdir: inode is NULL or not a directory\n");
return -EBADF;
}
if (c_entry == NULL)
{
i = sizeof (struct ncp_dirent) * NCP_READDIR_CACHE_SIZE;
c_entry = (struct ncp_dirent *) ncp_kmalloc(i, GFP_KERNEL);
if (c_entry == NULL) {
printk("ncp_readdir: no MEMORY for cache\n");
return -ENOMEM;
}
for (i = 0; i < NCP_READDIR_CACHE_SIZE; i++) {
c_entry[i].path =
(char *) ncp_kmalloc(NCP_MAXNAMELEN + 1,
GFP_KERNEL);
if (c_entry[i].path == NULL) {
DPRINTK("ncp_readdir: could not alloc path\n");
while (--i>=0)
kfree(c_entry[i].path);
kfree(c_entry);
c_entry = NULL;
return -ENOMEM;
}
}
}
if (filp->f_pos == 0) {
ncp_invalid_dir_cache(inode->i_ino);
}
if (inode->i_ino == c_ino) {
for (i = 0; i < c_size; i++) {
if (filp->f_pos == c_entry[i].f_pos) {
entry = &c_entry[i];
c_last_returned_index = i;
index = i;
break;
}
}
if ((entry == NULL) && c_seen_eof)
return 0;
}
if (entry == NULL) {
DPRINTK("ncp_readdir: Not found in cache.\n");
if (inode->i_ino == (int)&(server->root)) {
result = ncp_read_volume_list(server, filp->f_pos,
NCP_READDIR_CACHE_SIZE);
DPRINTK("ncp_read_volume_list returned %d\n", result);
} else {
result = ncp_do_readdir(server, inode, filp->f_pos,
NCP_READDIR_CACHE_SIZE,
c_entry);
DPRINTK("ncp_readdir returned %d\n", result);
}
if (result < 0) {
c_ino = 0;
return result;
}
if (result > 0) {
c_seen_eof = (result < NCP_READDIR_CACHE_SIZE);
c_ino = inode->i_ino;
c_size = result;
entry = c_entry;
c_last_returned_index = 0;
index = 0;
for (i = 0; i < c_size; i++) {
str_lower(c_entry[i].path);
}
}
}
if (entry == NULL) {
/* Nothing found, even from a ncp call */
return 0;
}
while (index < c_size) {
/* We found it. For getwd(), we have to return the
correct inode in d_ino if the inode is currently in
use. Otherwise the inode number does not
matter. (You can argue a lot about this..) */
int path_len;
int len;
struct ncp_inode_info *ino_info;
char complete_path[NCP_MAXPATHLEN];
len = strlen(entry->path);
if ((result = get_pname_static(inode, entry->path, len,
complete_path,
&path_len)) < 0)
return result;
ino_info = ncp_find_inode(server, complete_path);
/* Some programs seem to be confused about a zero
inode number, so we set it to one. Thanks to
Gordon Chaffee for this one. */
if (ino_info == NULL) {
ino_info = (struct ncp_inode_info *) 1;
}
DDPRINTK("ncp_readdir: entry->path = %s\n", entry->path);
DDPRINTK("ncp_readdir: entry->f_pos = %ld\n", entry->f_pos);
if (filldir(dirent, entry->path, len,
entry->f_pos, (ino_t)ino_info) < 0) {
break;
}
if ( (inode->i_ino != c_ino)
|| (entry->f_pos != filp->f_pos)) {
/* Someone has destroyed the cache while we slept
in filldir */
break;
}
filp->f_pos += 1;
index += 1;
entry += 1;
}
return 0;
}
static int
ncp_read_volume_list(struct ncp_server *server, int start_with, int cache_size)
{
struct ncp_dirent *entry = c_entry;
int total_count = 0;
int i;
for (i=0; i<NCP_NUMBER_OF_VOLUMES; i++) {
struct ncp_volume_info info;
if (ncp_get_volume_info_with_number(server, i, &info) != 0) {
return total_count;
}
if (strlen(info.volume_name) > 0) {
if (total_count < start_with) {
DPRINTK("ncp_read_volumes: skipped vol: %s\n",
info.volume_name);
} else if (total_count >= start_with + cache_size) {
return (total_count - start_with);
} else {
DPRINTK("ncp_read_volumes: found vol %s\n",
info.volume_name);
entry->attr = aDIR;
entry->mtime = 0;
entry->ctime = 0;
entry->atime = 0;
entry->size = 1024;
entry->f_pos = total_count;
strcpy(entry->path, info.volume_name);
entry += 1;
}
total_count += 1;
}
}
return (total_count - start_with);
}
static int
ncp_do_readdir(struct ncp_server *server, struct inode *dir, int fpos,
int cache_size, struct ncp_dirent *entry)
{
struct ncp_filesearch_info fsinfo;
struct ncp_file_info finfo;
int total_count = 0;
void doit(int attr) {
if (ncp_file_search_init(server, 0, NCP_FINFO(dir)->path,
&fsinfo) != 0) {
DPRINTK("could not fs init\n");
return;
}
while (ncp_file_search_continue(server, &fsinfo, attr, "*",
&finfo) == 0) {
if (total_count < fpos) {
DPRINTK("ncp_do_readdir: skipped file: %s\n",
finfo.file_name);
} else if (total_count >= fpos + cache_size) {
return;
} else {
DPRINTK("ncp_do_readdir: found file: %s\n",
finfo.file_name);
entry->attr = attr;
entry->mtime =
date_dos2unix(finfo.update_time,
finfo.update_date);
entry->ctime =
date_dos2unix(0, finfo.creation_date);
entry->atime =
date_dos2unix(0, finfo.access_date);
;
entry->size = (attr & aDIR) != 0 ?
1024 : finfo.file_length;
entry->f_pos = total_count;
strcpy(entry->path, finfo.file_name);
entry += 1;
}
total_count += 1;
}
return;
}
doit(0);
doit(aDIR);
return (total_count - fpos);
}
void
ncp_init_dir_cache(void)
{
c_ino = 0;
c_entry = NULL;
}
void
ncp_invalid_dir_cache(unsigned long ino)
{
if (ino == c_ino) {
c_ino = 0;
c_seen_eof = 0;
}
}
void
ncp_free_dir_cache(void)
{
int i;
DPRINTK("ncp_free_dir_cache: enter\n");
if (c_entry == NULL)
return;
for (i = 0; i < NCP_READDIR_CACHE_SIZE; i++) {
ncp_kfree_s(c_entry[i].path, NAME_MAX + 1);
}
ncp_kfree_s(c_entry,
sizeof(struct ncp_dirent) * NCP_READDIR_CACHE_SIZE);
c_entry = NULL;
DPRINTK("ncp_free_dir_cache: exit\n");
}
/* get_pname_static: it expects the res_path to be a preallocated
string of len NCP_MAXPATHLEN. */
static int
get_pname_static(struct inode *dir, const char *name, int len,
char *path, int *res_len)
{
char *parentname = NCP_INOP(dir)->finfo.path;
int parentlen = NCP_INOP(dir)->finfo.len;
#if 1
if (parentlen != strlen(parentname)) {
printk("get_pname: parent->finfo.len = %d instead of %d\n",
parentlen, strlen(parentname));
parentlen = strlen(parentname);
}
#endif
DPRINTK("get_pname_static: parentname = %s, len = %d\n",
parentname, parentlen);
if (len > NCP_MAXNAMELEN) {
return -ENAMETOOLONG;
}
/* Fast cheat for . */
if (len == 0 || (len == 1 && name[0] == '.')) {
memcpy(path, parentname, parentlen + 1);
*res_len = parentlen;
return 0;
}
/* Hmm, what about .. ? */
if (len == 2 && name[0] == '.' && name[1] == '.') {
char *pos = strrchr(parentname, '\\');
if ( (pos == NULL)
&& (parentlen == 0)) {
/* We're at the top */
path[0] = '\\';
path[1] = '\0';
*res_len = 2;
return 0;
}
if (pos == NULL) {
printk("ncp_make_name: Bad parent NCP-name: %s",
parentname);
return -ENODATA;
}
len = pos - parentname;
memcpy(path, parentname, len);
path[len] = '\0';
}
else if (parentlen == 0) {
memcpy(path, name, len);
path[len] = ':';
path[len+1] = '\0';
len = len+1;
}
else
{
if (len + parentlen + 2 > NCP_MAXPATHLEN)
return -ENAMETOOLONG;
memcpy(path, parentname, parentlen);
path[parentlen] = '\\';
memcpy(path + parentlen + 1, name, len);
path[parentlen + 1 + len] = '\0';
len = parentlen + len + 1;
}
*res_len = len;
DPRINTK("get_pname: path = %s, *pathlen = %d\n",
path, *res_len);
return 0;
}
static int
get_pname(struct inode *dir, const char *name, int len,
char **res_path, int *res_len)
{
char result[NCP_MAXPATHLEN];
int result_len;
int res;
if ((res = get_pname_static(dir,name,len,result,&result_len) != 0)) {
return res;
}
if ((*res_path = ncp_kmalloc(result_len+1, GFP_KERNEL)) == NULL) {
printk("get_pname: Out of memory while allocating name.");
return -ENOMEM;
}
strcpy(*res_path, result);
*res_len = result_len;
return 0;
}
static void
put_pname(char *path)
{
ncp_kfree_s(path, 0);
}
/* Insert a NEW ncp_inode_info into the inode tree of our filesystem,
under dir. The caller must assure that it's not already there. We
assume that path is allocated for us. */
static struct inode *
ncp_iget(struct inode *dir, char *path, struct ncp_dirent *finfo)
{
struct inode *inode;
struct ncp_inode_info *new_inode_info;
struct ncp_inode_info *root;
if (!dir) {
printk("ncp_iget: dir is NULL\n");
return NULL;
}
if (!path) {
printk("ncp_iget: path is NULL\n");
return NULL;
}
if (!finfo) {
printk("ncp_iget: finfo is NULL\n");
return NULL;
}
new_inode_info = ncp_kmalloc(sizeof(struct ncp_inode_info),
GFP_KERNEL);
if (new_inode_info == NULL) {
printk("ncp_iget: could not alloc mem for %s\n", path);
return NULL;
}
new_inode_info->state = INODE_LOOKED_UP;
new_inode_info->nused = 0;
new_inode_info->dir = NCP_INOP(dir);
new_inode_info->finfo = *finfo;
new_inode_info->finfo.opened = 0;
new_inode_info->finfo.path = path;
new_inode_info->finfo.len = strlen(path);
NCP_INOP(dir)->nused += 1;
/* We have to link the new inode_info into the doubly linked
list of inode_infos to make a complete linear search
possible. */
root = &(NCP_SERVER(dir)->root);
new_inode_info->prev = root;
new_inode_info->next = root->next;
root->next->prev = new_inode_info;
root->next = new_inode_info;
if (!(inode = iget(dir->i_sb, (int)new_inode_info))) {
printk("ncp_iget: iget failed!");
return NULL;
}
return inode;
}
void
ncp_free_inode_info(struct ncp_inode_info *i)
{
if (i == NULL) {
printk("ncp_free_inode: i == NULL\n");
return;
}
i->state = INODE_CACHED;
while ((i->nused == 0) && (i->state == INODE_CACHED)) {
struct ncp_inode_info *dir = i->dir;
i->next->prev = i->prev;
i->prev->next = i->next;
ncp_kfree_s(i->finfo.path, i->finfo.len+1);
ncp_kfree_s(i, sizeof(struct ncp_inode_info));
if (dir == NULL) return;
(dir->nused)--;
i = dir;
}
}
void
ncp_init_root(struct ncp_server *server)
{
struct ncp_inode_info *root = &(server->root);
DPRINTK("ncp_init_root: server %s\n", server->m.server_name);
root->finfo.opened = 0;
root->finfo.attr = aDIR;
root->finfo.size = 1024;
root->finfo.mtime = 0;
root->finfo.ctime = 0;
root->finfo.atime = 0;
server->root_path = '\0';
root->finfo.path = &(server->root_path);
root->finfo.len = 0;
root->state = INODE_LOOKED_UP;
root->nused = 1;
root->dir = NULL;
root->next = root->prev = root;
return;
}
void
ncp_free_all_inodes(struct ncp_server *server)
{
/* Here nothing should be to do. I do not know whether it's
better to leave some memory allocated or be stuck in an
endless loop */
#if 1
struct ncp_inode_info *root = &(server->root);
if (root->next != root) {
printk("ncp_free_all_inodes: INODES LEFT!!!\n");
}
while (root->next != root) {
printk("ncp_free_all_inodes: freeing inode\n");
ncp_free_inode_info(root->next);
/* In case we have an endless loop.. */
schedule();
}
#endif
return;
}
/* We will search the inode that belongs to this name, currently by a
complete linear search through the inodes belonging to this
filesystem. This has to be fixed. */
static struct ncp_inode_info *
ncp_find_inode(struct ncp_server *server, const char *path)
{
struct ncp_inode_info *result = &(server->root);
if (path == NULL)
return NULL;
do {
if (strcmp(result->finfo.path, path) == 0)
return result;
result = result->next;
} while (result != &(server->root));
return NULL;
}
static int
ncp_lookup(struct inode *dir, const char *__name, int len,
struct inode **result)
{
char *name = NULL;
struct ncp_dirent finfo;
struct ncp_server *server;
struct ncp_inode_info *result_info;
int error;
int found_in_cache;
int path_len;
*result = NULL;
if (!dir || !S_ISDIR(dir->i_mode)) {
printk("ncp_lookup: inode is NULL or not a directory.\n");
iput(dir);
return -ENOENT;
}
DPRINTK("ncp_lookup: %s\n", __name);
server = NCP_SERVER(dir);
/* Fast cheat for . */
if (len == 0 || (len == 1 && __name[0] == '.')) {
*result = dir;
return 0;
}
/* Now we will have to build up an NCP filename. */
if ((error = get_pname(dir, __name, len, &name, &path_len)) < 0) {
iput(dir);
return error;
}
result_info = ncp_find_inode(NCP_SERVER(dir), name);
if (result_info != 0) {
if (result_info->state == INODE_CACHED)
result_info->state = INODE_LOOKED_UP;
put_pname(name);
/* Here we convert the inode_info address into an
inode number */
*result = iget(dir->i_sb, (int)result_info);
iput(dir);
if (*result == NULL) {
return -EACCES;
}
return 0;
}
/* Ok, now we have made our name. We have to build a new
ncp_inode_info struct and insert it into the tree, if it is
a name that exists on the server */
/* If the file is in the dir cache, we do not have to ask the
server. */
found_in_cache = 0;
if (dir->i_ino == c_ino) {
int first = c_last_returned_index;
int i;
i = first;
do {
DDPRINTK("ncp_lookup: trying index: %d, name: %s\n",
i, c_entry[i].path);
if (strcmp(c_entry[i].path, __name) == 0) {
DPRINTK("ncp_lookup: found in cache!\n");
finfo = c_entry[i];
finfo.path = NULL; /* It's not ours! */
found_in_cache = 1;
break;
}
i = (i + 1) % c_size;
DDPRINTK("ncp_lookup: index %d, name %s failed\n",
i, c_entry[i].path);
} while (i != first);
}
if (found_in_cache == 0) {
char this_name[len+1];
memcpy(this_name, __name, len);
this_name[len] = 0;
if (dir->i_ino == (int)&(server->root)) {
/* We want to look up a volume. We only want
to know whether it exists, nothing more. */
int vol_no;
DPRINTK("ncp_lookup: looking up volume %s\n",
this_name);
if (ncp_get_volume_number(server,this_name,
&vol_no)!=0) {
put_pname(name);
iput(dir);
return -ENOENT;
}
finfo.attr = aDIR;
finfo.mtime = 0;
finfo.ctime = 0;
finfo.atime = 0;
finfo.size = 1024;
} else {
struct ncp_file_info ninfo;
if (ncp_get_finfo(server, 0, NCP_FINFO(dir)->path,
this_name, &ninfo) != 0) {
error = -ENOENT;
}
finfo.attr = ninfo.file_attributes;
finfo.mtime = date_dos2unix(ninfo.update_time,
ninfo.update_date);
finfo.ctime = date_dos2unix(0, ninfo.creation_date);
finfo.atime = date_dos2unix(0, ninfo.access_date);
finfo.size = (ninfo.file_attributes & aDIR) != 0
? 1024 : ninfo.file_length;
}
if (error < 0) {
put_pname(name);
iput(dir);
return error;
}
}
if (!(*result = ncp_iget(dir, name, &finfo))) {
put_pname(name);
iput(dir);
return -EACCES;
}
DDPRINTK("ncp_lookup: %s => %lu\n", name, (unsigned long)result_info);
iput(dir);
return 0;
}
/* The following are taken directly from msdos-fs */
/* Linear day numbers of the respective 1sts in non-leap years. */
static int day_n[] = { 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 };
/* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */
extern struct timezone sys_tz;
/*
static int
utc2local(int time)
{
return time - sys_tz.tz_minuteswest*60;
}
*/
static int
local2utc(int time)
{
return time + sys_tz.tz_minuteswest*60;
}
/* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */
static int
date_dos2unix(unsigned short time,unsigned short date)
{
int month,year,secs;
month = ((date >> 5) & 15)-1;
year = date >> 9;
secs = (time & 31)*2+60*((time >> 5) & 63)+(time >> 11)*3600+86400*
((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 &&
month < 2 ? 1 : 0)+3653);
/* days since 1.1.70 plus 80's leap day */
return local2utc(secs);
}
/* Convert linear UNIX date to a MS-DOS time/date pair. */
#if 0
static void
date_unix2dos(int unix_date,unsigned short *time, unsigned short *date)
{
int day,year,nl_day,month;
unix_date = utc2local(unix_date);
*time = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
(((unix_date/3600) % 24) << 11);
day = unix_date/86400-3652;
year = day/365;
if ((year+3)/4+365*year > day) year--;
day -= (year+3)/4+365*year;
if (day == 59 && !(year & 3)) {
nl_day = day;
month = 2;
}
else {
nl_day = (year & 3) || day <= 59 ? day : day-1;
for (month = 0; month < 12; month++)
if (day_n[month] > nl_day) break;
}
*date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9);
}
#endif

176
file.c Normal file
View File

@@ -0,0 +1,176 @@
/*
* file.c
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <asm/segment.h>
#include <asm/system.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/stat.h>
#include <linux/mm.h>
#include <linux/ncp_fs.h>
#include "ncplib.h"
#include <linux/malloc.h>
static int
ncp_fsync(struct inode *inode, struct file *file)
{
return 0;
}
int
ncp_make_open(struct inode *i, int right)
{
struct ncp_dirent *dirent;
if (i == NULL) {
printk("ncp_make_open: got NULL inode\n");
return -EINVAL;
}
dirent = &(NCP_INOP(i)->finfo);
DPRINTK("ncp_make_open: dirent->opened = %d\n", dirent->opened);
if ((dirent->opened) == 0) {
struct ncp_file_info finfo;
/* tries max. rights */
if (ncp_open_file(NCP_SERVER(i), 0, dirent->path, 0,
AR_READ | AR_WRITE, &finfo) == 0) {
dirent->access = O_RDWR;
}
else if (ncp_open_file(NCP_SERVER(i), 0, dirent->path, 0,
AR_READ, &finfo) == 0) {
dirent->access = O_RDONLY;
} else {
return -EACCES;
}
dirent->opened = 1;
memcpy(&(dirent->file_id), finfo.file_id, NCP_FILE_ID_LEN);
}
if ( ((right == O_RDONLY) && ( (dirent->access == O_RDONLY)
|| (dirent->access == O_RDWR)))
|| ((right == O_WRONLY) && ( (dirent->access == O_WRONLY)
|| (dirent->access == O_RDWR)))
|| ((right == O_RDWR) && (dirent->access == O_RDWR)))
return 0;
return -EACCES;
}
static int
ncp_file_read(struct inode *inode, struct file *file, char *buf, int count)
{
int bufsize, to_read, already_read;
off_t pos;
int errno;
DPRINTK("ncp_file_read: enter %s\n", NCP_FINFO(inode)->path);
if (!inode) {
DPRINTK("ncp_file_read: inode = NULL\n");
return -EINVAL;
}
if (!S_ISREG(inode->i_mode)) {
DPRINTK("ncp_file_read: read from non-file, mode %07o\n",
inode->i_mode);
return -EINVAL;
}
if ((errno = ncp_make_open(inode, O_RDONLY)) != 0)
return errno;
pos = file->f_pos;
if (pos + count > inode->i_size)
count = inode->i_size - pos;
if (count <= 0)
return 0;
bufsize = NCP_SERVER(inode)->buffer_size;
already_read = 0;
/* First read in as much as possible for each bufsize. */
while (already_read < count) {
int read_this_time;
if ((pos % bufsize) != 0) {
to_read = bufsize - (pos % bufsize);
} else {
to_read = bufsize;
}
to_read = min(to_read, count - already_read);
if (ncp_read(NCP_SERVER(inode), NCP_FINFO(inode)->file_id,
pos, to_read, buf, &read_this_time) != 0) {
return -EIO; /* This is not exact, i know.. */
}
pos += read_this_time;
buf += read_this_time;
already_read += read_this_time;
if (read_this_time < to_read) {
break;
}
}
file->f_pos = pos;
if (!IS_RDONLY(inode)) inode->i_atime = CURRENT_TIME;
inode->i_dirt = 1;
DPRINTK("ncp_file_read: exit %s\n", NCP_FINFO(inode)->path);
return already_read;
}
static struct file_operations ncp_file_operations = {
NULL, /* lseek - default */
ncp_file_read, /* read */
NULL, /* write */
NULL, /* readdir - bad */
NULL, /* select - default */
ncp_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* open */
NULL, /* release */
ncp_fsync, /* fsync */
};
struct inode_operations ncp_file_inode_operations = {
&ncp_file_operations, /* default file operations */
NULL, /* create */
NULL, /* lookup */
NULL, /* link */
NULL, /* unlink */
NULL, /* symlink */
NULL, /* mkdir */
NULL, /* rmdir */
NULL, /* mknod */
NULL, /* rename */
NULL, /* readlink */
NULL, /* follow_link */
NULL, /* bmap */
NULL /* truncate */
};

375
inode.c Normal file
View File

@@ -0,0 +1,375 @@
/*
* inode.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
#include <asm/system.h>
#include <asm/segment.h>
#include <linux/sched.h>
#include <linux/ncp_fs.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/locks.h>
#include <linux/fcntl.h>
#include <linux/malloc.h>
#include "ncplib.h"
extern int close_fp(struct file *filp);
static void ncp_put_inode(struct inode *);
static void ncp_read_inode(struct inode *);
static void ncp_put_super(struct super_block *);
static struct super_operations ncp_sops = {
ncp_read_inode, /* read inode */
NULL, /* notify change */
NULL, /* write inode */
ncp_put_inode, /* put inode */
ncp_put_super, /* put superblock */
NULL, /* write superblock */
NULL, /* stat filesystem */
NULL
};
/* ncp_read_inode: Called from iget, it only traverses the allocated
ncp_inode_info's and initializes the inode from the data found
there. It does not allocate or deallocate anything. */
static void
ncp_read_inode(struct inode *inode)
{
/* Our task should be extremely simple here. We only have to
look up the infomation somebody else (ncp_iget) put into
the inode tree. The address of this information is the
inode->i_ino. Just to make sure everything went well, we
check it's there. */
struct ncp_inode_info *inode_info
= (struct ncp_inode_info *)(inode->i_ino);
#if 1
struct ncp_inode_info *root = &(NCP_SERVER(inode)->root);
struct ncp_inode_info *check_info = root;
do {
if (inode_info == check_info) {
if (check_info->state == INODE_LOOKED_UP) {
DDPRINTK("ncp_read_inode: found it!\n");
goto good;
}
else {
printk("ncp_read_inode: "
"state != INODE_LOOKED_UP\n");
return;
}
}
check_info = check_info->next;
} while (check_info != root);
/* Ok, now we're in trouble. The inode info is not there. What
should we do now??? */
printk("ncp_read_inode: inode info not found\n");
return;
good:
#endif
inode_info->state = INODE_VALID;
NCP_INOP(inode) = inode_info;
if (NCP_INOP(inode)->finfo.attr & aDIR)
inode->i_mode = NCP_SERVER(inode)->m.dir_mode;
else
inode->i_mode = NCP_SERVER(inode)->m.file_mode;
DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
inode->i_nlink = 1;
inode->i_uid = NCP_SERVER(inode)->m.uid;
inode->i_gid = NCP_SERVER(inode)->m.gid;
inode->i_size = NCP_INOP(inode)->finfo.size;
inode->i_blksize = 1024;
inode->i_rdev = 0;
if ((inode->i_blksize != 0) && (inode->i_size != 0))
inode->i_blocks =
(inode->i_size - 1) / inode->i_blksize + 1;
else
inode->i_blocks = 0;
inode->i_mtime = NCP_INOP(inode)->finfo.mtime;
inode->i_ctime = NCP_INOP(inode)->finfo.ctime;
inode->i_atime = NCP_INOP(inode)->finfo.atime;
if (S_ISREG(inode->i_mode))
inode->i_op = &ncp_file_inode_operations;
else if (S_ISDIR(inode->i_mode))
inode->i_op = &ncp_dir_inode_operations;
else
inode->i_op = NULL;
}
static void
ncp_put_inode(struct inode *inode)
{
struct ncp_dirent *finfo = NCP_FINFO(inode);
if (finfo->opened != 0) {
if (ncp_close_file(NCP_SERVER(inode), finfo->file_id) != 0) {
/* We can't do anything but complain. */
printk("ncp_put_inode: could not close\n");
}
}
ncp_free_inode_info(NCP_INOP(inode));
if (S_ISDIR(inode->i_mode)) {
DPRINTK("ncp_put_inode: put directory %ld\n",
inode->i_ino);
ncp_invalid_dir_cache(inode->i_ino);
}
clear_inode(inode);
}
struct super_block *
ncp_read_super(struct super_block *sb, void *raw_data, int silent)
{
struct ncp_mount_data *data = (struct ncp_mount_data *) raw_data;
struct ncp_server *server;
struct file *ncp_filp;
struct file *wdog_filp;
kdev_t dev = sb->s_dev;
int error;
if (!data) {
printk("ncp_read_super: missing data argument\n");
sb->s_dev = 0;
return NULL;
}
if (data->version != NCP_MOUNT_VERSION) {
printk("ncp warning: mount version %s than kernel\n",
(data->version < NCP_MOUNT_VERSION) ?
"older" : "newer");
}
if ( (data->ncp_fd >= NR_OPEN)
|| ((ncp_filp = current->files->fd[data->ncp_fd]) == NULL)
|| (!S_ISSOCK(ncp_filp->f_inode->i_mode))) {
printk("ncp_read_super: invalid ncp socket\n");
sb->s_dev = 0;
return NULL;
}
if ( (data->wdog_fd >= NR_OPEN)
|| ((wdog_filp = current->files->fd[data->wdog_fd]) == NULL)
|| (!S_ISSOCK(wdog_filp->f_inode->i_mode))) {
printk("ncp_read_super: invalid wdog socket\n");
sb->s_dev = 0;
return NULL;
}
/* We must malloc our own super-block info */
server = (struct ncp_server *)ncp_kmalloc(sizeof(struct ncp_server),
GFP_KERNEL);
if (server == NULL) {
printk("ncp_read_super: could not alloc ncp_server\n");
return NULL;
}
ncp_filp->f_count += 1;
wdog_filp->f_count += 1;
lock_super(sb);
NCP_SBP(sb) = server;
sb->s_blocksize = 1024; /* Eh... Is this correct? */
sb->s_blocksize_bits = 10;
sb->s_magic = NCP_SUPER_MAGIC;
sb->s_dev = dev;
sb->s_op = &ncp_sops;
server->ncp_filp = ncp_filp;
server->wdog_filp = wdog_filp;
server->lock = 0;
server->wait = NULL;
server->packet = NULL;
server->buffer_size = 0;
server->m = *data;
server->m.file_mode = (server->m.file_mode &
(S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFREG;
server->m.dir_mode = (server->m.dir_mode &
(S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFDIR;
server->packet_size = NCP_PACKET_SIZE;
server->packet = ncp_kmalloc(NCP_PACKET_SIZE, GFP_KERNEL);
if (server->packet == NULL) {
printk("ncpfs: could not alloc packet\n");
error = -ENOMEM;
unlock_super(sb);
goto fail;
}
ncp_init_root(server);
/*
* Make the connection to the server
*/
if (ncp_catch_watchdog(server) != 0) {
printk("ncp_read_super: Could not catch watchdog\n");
error = -EINVAL;
unlock_super(sb);
goto fail;
}
ncp_lock_server(server);
error = ncp_connect(server);
ncp_unlock_server(server);
unlock_super(sb);
if (error < 0) {
sb->s_dev = 0;
printk("ncp_read_super: Failed connection, bailing out "
"(error = %d).\n", -error);
ncp_kfree_s(server->packet, server->packet_size);
ncp_dont_catch_watchdog(server);
goto fail;
}
DPRINTK("ncp_read_super: NCP_SBP(sb) = %x\n", (int)NCP_SBP(sb));
if (!(sb->s_mounted = iget(sb, (int)&(server->root)))) {
sb->s_dev = 0;
printk("ncp_read_super: get root inode failed\n");
goto disconnect;
}
if (ncp_negotiate_buffersize(server, NCP_DEFAULT_BUFSIZE,
&(server->buffer_size)) != 0) {
sb->s_dev = 0;
printk("ncp_read_super: could not get bufsize\n");
goto disconnect;
}
DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
if (ncp_login_user(server, server->m.username,
server->m.password) != 0) {
sb->s_dev = 0;
printk("ncp_read_super: login failed\n");
goto disconnect;
}
MOD_INC_USE_COUNT;
return sb;
disconnect:
ncp_lock_server(server);
ncp_disconnect(server);
ncp_unlock_server(server);
ncp_kfree_s(server->packet, server->packet_size);
ncp_dont_catch_watchdog(server);
fail:
ncp_filp->f_count -= 1;
wdog_filp->f_count -= 1;
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
return NULL;
}
static void
ncp_put_super(struct super_block *sb)
{
struct ncp_server *server = NCP_SBP(sb);
lock_super(sb);
ncp_lock_server(server);
ncp_disconnect(server);
ncp_unlock_server(server);
close_fp(server->ncp_filp);
ncp_dont_catch_watchdog(server);
close_fp(server->wdog_filp);
ncp_free_all_inodes(server);
ncp_kfree_s(server->packet, server->packet_size);
sb->s_dev = 0;
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
NCP_SBP(sb) = NULL;
unlock_super(sb);
MOD_DEC_USE_COUNT;
}
#ifdef DEBUG_NCP_MALLOC
int ncp_malloced;
int ncp_current_malloced;
#endif
#ifdef MODULE
char kernel_version[] = UTS_RELEASE;
/* looks ugly, taken from gcc-info */
/* static void *shut_up_gcc = (&shut_up_gcc, kernel_version);*/
static struct file_system_type ncp_fs_type = {
ncp_read_super, "ncpfs", 0, NULL
};
int
init_module( void)
{
DPRINTK("ncpfs: init_module called\n");
#ifdef DEBUG_NCP_MALLOC
ncp_malloced = 0;
ncp_current_malloced = 0;
#endif
ncp_init_dir_cache();
register_filesystem(&ncp_fs_type);
return 0;
}
void
cleanup_module(void)
{
DPRINTK("ncpfs: cleanup_module called\n");
ncp_free_dir_cache();
unregister_filesystem(&ncp_fs_type);
#ifdef DEBUG_NCP_MALLOC
printk("ncp_malloced: %d\n", ncp_malloced);
printk("ncp_current_malloced: %d\n", ncp_current_malloced);
#endif
}
#endif

88
ioctl.c Normal file
View File

@@ -0,0 +1,88 @@
/*
* ioctl.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
#include <asm/segment.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/ncp_fs.h>
#include <linux/ioctl.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/ncp.h>
int
ncp_ioctl (struct inode * inode, struct file * filp,
unsigned int cmd, unsigned long arg)
{
int result;
struct ncp_ioctl_request request;
struct ncp_server *server;
switch(cmd) {
case NCP_IOC_NCPREQUEST:
if (!suser()) {
return -EPERM;
}
if ((result = verify_area(VERIFY_READ, (char *)arg,
sizeof(request))) != 0) {
return result;
}
memcpy_fromfs(&request, (struct ncp_ioctl_request *)arg,
sizeof(request));
if ( (request.function > 255)
|| (request.size >
NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) {
return -EINVAL;
}
if ((result = verify_area(VERIFY_WRITE, (char *)request.data,
NCP_PACKET_SIZE)) != 0) {
return result;
}
server = NCP_SERVER(inode);
ncp_lock_server(server);
/* FIXME: We hack around in the server's structures
here to be able to use ncp_request */
server->has_subfunction = 0;
server->current_size =
request.size + sizeof(struct ncp_request_header);
memcpy_fromfs(&(server->
packet[sizeof(struct ncp_request_header)]),
request.data, request.size);
ncp_request(server, request.function);
DPRINTK("ncp_ioctl: copy %d bytes\n",
server->reply_size);
memcpy_tofs(request.data, server->packet,
server->reply_size);
ncp_unlock_server(server);
return server->reply_size;
default:
return -EINVAL;
}
return -EINVAL;
}

53
ipxutil.h Normal file
View File

@@ -0,0 +1,53 @@
/*
IPX support library
Copyright (C) 1994, 1995 Ales Dryak <e-mail: A.Dryak@sh.cvut.cz>
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 __IPXUTIL_H__
#define __IPXUTIL_H__
#include <string.h>
#include <linux/ipx.h>
#define IPX_SAP_PTYPE (0x04)
#define IPX_SAP_PORT (0x0452)
#define IPX_SAP_FILE_SERVER (0x004)
#define IPX_BROADCAST_NODE "\xff\xff\xff\xff\xff\xff"
#define IPX_THIS_NODE "\0\0\0\0\0\0"
typedef unsigned long IPXNet;
typedef unsigned short IPXPort;
typedef unsigned char IPXNode[IPX_NODE_LEN];
void ipx_print_node(IPXNode node);
void ipx_print_network(IPXNet net);
void ipx_print_port(IPXPort port);
void ipx_print_saddr(struct sockaddr_ipx* sipx);
static __inline__ void
ipx_assign_node(IPXNode dest, IPXNode src) {
memcpy(dest, src, IPX_NODE_LEN);
}
#endif

1
linux Symbolic link
View File

@@ -0,0 +1 @@
.

101
ncp.h Normal file
View File

@@ -0,0 +1,101 @@
/*
* ncp_fs.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _LINUX_NCP_H
#define _LINUX_NCP_H
#include <linux/types.h>
#define NCP_PTYPE (0x17)
#define NCP_PORT (0x0451)
#define NCP_ALLOC_SLOT_REQUEST (0x1111)
#define NCP_REQUEST (0x2222)
#define NCP_DEALLOC_SLOT_REQUEST (0x5555)
struct ncp_request_header {
__u16 type;
__u8 sequence;
__u8 conn_low;
__u8 task;
__u8 conn_high;
__u8 function;
__u8 data[0]; /* Depends upon request type */
} __attribute__ ((packed));
#define NCP_REPLY (0x3333)
#define NCP_POSITIVE_ACK (0x9999)
struct ncp_reply_header {
__u16 type;
__u8 sequence;
__u8 conn_low;
__u8 task;
__u8 conn_high;
__u8 completion_code;
__u8 connection_state;
__u8 data[0]; /* Depends upon request type */
} __attribute__ ((packed));
#define NCP_BINDERY_USER (0x0001)
#define NCP_BINDERY_NAME_LEN (48)
struct ncp_bindery_object {
__u32 object_id;
__u16 object_type;
__u8 object_name[NCP_BINDERY_NAME_LEN];
};
#define NCP_VOLNAME_LEN (16)
#define NCP_NUMBER_OF_VOLUMES (64)
struct ncp_volume_info {
__u32 total_blocks;
__u32 free_blocks;
__u32 purgeable_blocks;
__u32 not_yet_purgeable_blocks;
__u32 total_dir_entries;
__u32 available_dir_entries;
__u8 sectors_per_block;
char volume_name[NCP_VOLNAME_LEN+1];
};
struct ncp_filesearch_info {
__u8 volume_number;
__u16 directory_id;
__u16 sequence_no;
__u8 access_rights;
};
#define NCP_MAX_FILENAME 14
/* these define the attribute byte as seen by NCP */
#define aRONLY (1L<<0)
#define aHIDDEN (1L<<1)
#define aSYSTEM (1L<<2)
#define aEXECUTE (1L<<3)
#define aDIR (1L<<4)
#define aARCH (1L<<5)
#define AR_READ (0x01)
#define AR_WRITE (0x02)
#define AR_EXCLUSIVE (0x20)
#define NCP_FILE_ID_LEN 6
struct ncp_file_info {
__u8 file_id[NCP_FILE_ID_LEN];
char file_name[NCP_MAX_FILENAME+1];
__u8 file_attributes;
__u8 file_mode;
__u32 file_length;
__u16 creation_date;
__u16 access_date;
__u16 update_date;
__u16 update_time;
};
#endif /* _LINUX_NCP_H */

145
ncp_fs.h Normal file
View File

@@ -0,0 +1,145 @@
/*
* ncp_fs.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _LINUX_NCP_FS_H
#define _LINUX_NCP_FS_H
#include <linux/fs.h>
#include <linux/in.h>
#include <linux/types.h>
#include <linux/ncp_mount.h>
#include <linux/ncp_fs_sb.h>
#include <linux/ncp_fs_i.h>
/*
* ioctl commands
*/
struct ncp_ioctl_request {
unsigned int function;
unsigned int size;
char *data;
};
#define NCP_IOC_NCPREQUEST _IOR('n', 1, unsigned char *)
/*
* The packet size to allocate. One page should be enough.
*/
#define NCP_PACKET_SIZE 4070
#define NCP_MAXPATHLEN 255
#define NCP_MAXNAMELEN 14
#ifdef __KERNEL__
/* The readdir cache size controls how many directory entries are
* cached.
*/
#define NCP_READDIR_CACHE_SIZE 64
#define NCP_MAX_RPC_TIMEOUT (60) /* 6 seconds */
/* Guess, what 0x564c is :-) */
#define NCP_SUPER_MAGIC 0x564c
#define NCP_SBP(sb) ((struct ncp_server *)(sb->u.generic_sbp))
#define NCP_INOP(inode) ((struct ncp_inode_info *)(inode->u.generic_ip))
#define NCP_SERVER(inode) NCP_SBP(inode->i_sb)
#define NCP_FINFO(inode) (&(NCP_INOP(inode)->finfo))
static inline int min(int a, int b) {
return a<b ? a : b;
}
#ifdef DEBUG_NCP_MALLOC
#include <linux/malloc.h>
extern int ncp_malloced;
extern int ncp_current_malloced;
static inline void *
ncp_kmalloc(unsigned int size, int priority)
{
ncp_malloced += 1;
ncp_current_malloced += 1;
return kmalloc(size, priority);
}
static inline void
ncp_kfree_s(void *obj, int size)
{
ncp_current_malloced -= 1;
kfree_s(obj, size);
}
#else /* DEBUG_NCP_MALLOC */
#define ncp_kmalloc(s,p) kmalloc(s,p)
#define ncp_kfree_s(o,s) kfree_s(o,s)
#endif /* DEBUG_NCP_MALLOC */
#if DEBUG_NCP > 0
#define DPRINTK(format, args...) printk(format , ## args)
#else
#define DPRINTK(format, args...)
#endif
#if DEBUG_NCP > 1
#define DDPRINTK(format, args...) printk(format , ## args)
#else
#define DDPRINTK(format, args...)
#endif
/* linux/fs/ncpfs/file.c */
extern struct inode_operations ncp_file_inode_operations;
int ncp_make_open(struct inode *i, int right);
/* linux/fs/ncpfs/dir.c */
extern struct inode_operations ncp_dir_inode_operations;
void ncp_free_inode_info(struct ncp_inode_info *i);
void ncp_free_all_inodes(struct ncp_server *server);
void ncp_init_root(struct ncp_server *server);
int ncp_stat_root(struct ncp_server *server);
void ncp_init_dir_cache(void);
void ncp_invalid_dir_cache(unsigned long ino);
void ncp_invalidate_all_inodes(struct ncp_server *server);
void ncp_free_dir_cache(void);
/* linux/fs/ncpfs/ioctl.c */
int ncp_ioctl (struct inode * inode, struct file * filp,
unsigned int cmd, unsigned long arg);
/* linux/fs/ncpfs/inode.c */
struct super_block *ncp_read_super(struct super_block *sb,
void *raw_data, int silent);
int ncp_notify_change(struct inode *inode, struct iattr *attr);
void ncp_invalidate_connection(struct ncp_server *server);
int ncp_conn_is_valid(struct ncp_server *server);
/* linux/fs/ncpfs/sock.c */
int ncp_request(struct ncp_server *server, int function);
int ncp_connect(struct ncp_server *server);
int ncp_disconnect(struct ncp_server *server);
int ncp_catch_watchdog(struct ncp_server *server);
int ncp_dont_catch_watchdog(struct ncp_server *server);
void ncp_lock_server(struct ncp_server *server);
void ncp_unlock_server(struct ncp_server *server);
/* linux/fs/ncpfs/mmap.c */
int ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma);
#endif /* __KERNEL__ */
#endif /* _LINUX_NCP_FS_H */

59
ncp_fs_i.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* ncp_fs_i.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
*
*/
#ifndef _LINUX_NCP_FS_I
#define _LINUX_NCP_FS_I
#include <linux/ncp.h>
#ifdef __KERNEL__
/*
* Contains all relevant data on a NCP networked file.
*/
struct ncp_dirent {
int opened; /* is it open on the fileserver? */
__u8 file_id[NCP_FILE_ID_LEN];
__u32 attr; /* Attribute fields, NCP value. Either
only lower 8 bits used or upper
bits contain extended attributs */
__u32 size; /* File size. */
time_t atime, /* Times, as seen by the server, normalized */
mtime, /* to UTC. The ugly conversion happens in */
ctime; /* proc.c */
__u16 access; /* Access bits. */
__u16 next_search; /* Next search index, for proc_readdir */
unsigned long f_pos; /* for ncp_readdir */
char *path; /* Complete path, MS-DOS notation, with '\' */
int len; /* Namelength. */
};
enum ncp_inode_state {
INODE_VALID = 19, /* Inode currently in use */
INODE_LOOKED_UP, /* directly before iget */
INODE_CACHED, /* in a path to an inode which is in use */
INODE_INVALID
};
/*
* ncp fs inode data (in memory only)
*/
struct ncp_inode_info {
enum ncp_inode_state state;
int nused; /* for directories:
number of references in memory */
struct ncp_inode_info *dir;
struct ncp_inode_info *next, *prev;
struct ncp_dirent finfo;
};
#endif
#endif

61
ncp_fs_sb.h Normal file
View File

@@ -0,0 +1,61 @@
/*
* ncp_fs_sb.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _NCP_FS_SB
#define _NCP_FS_SB
#include <linux/ncp_mount.h>
#include <linux/types.h>
#ifdef __KERNEL__
#define NCP_DEFAULT_BUFSIZE 1024
struct ncp_server {
struct ncp_mount_data m; /* Nearly all of the mount data is of
interest for us later, so we store
it completely. */
struct file *ncp_filp; /* File pointer to ncp socket */
struct file *wdog_filp; /* File pointer to wdog socket */
void *data_ready; /* The wdog socket gets a new
data_ready callback. We store the
old one for checking purposes and
to reset it on unmounting. */
u8 sequence;
u8 task;
u16 connection; /* Remote connection number */
u8 completion; /* Status message from server */
u8 conn_status; /* Bit 4 = 1 ==> Server going down, no
requests allowed anymore */
int buffer_size; /* Negotiated bufsize */
int reply_size; /* Size of last reply */
int packet_size;
unsigned char *packet; /* Here we prepare requests and
receive replies */
int lock; /* To prevent mismatch in protocols. */
struct wait_queue *wait;
int current_size; /* for packet preparation */
int has_subfunction;
int ncp_reply_size;
struct ncp_inode_info root;
char root_path; /* '\0' */
};
#endif /* __KERNEL__ */
#endif

49
ncp_mount.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* ncp_mount.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _LINUX_NCP_MOUNT_H
#define _LINUX_NCP_MOUNT_H
#include <linux/types.h>
#include <linux/ipx.h>
#include <linux/ncp.h>
#include <linux/ncp_fs_i.h>
#define NCP_MOUNT_VERSION 1
#define NCP_USERNAME_LEN (NCP_BINDERY_NAME_LEN)
#define NCP_PASSWORD_LEN 20
/* Values for flags */
#define NCP_MOUNT_SOFT 0x0001
#define NCP_MOUNT_INTR 0x0002
struct ncp_mount_data {
int version;
unsigned int ncp_fd; /* The socket to the ncp port */
unsigned int wdog_fd; /* Watchdog packets come here */
unsigned int message_fd; /* Not used yet, maybe for messages */
uid_t mounted_uid; /* Who may umount() this filesystem? */
struct sockaddr_ipx serv_addr;
unsigned char server_name[49];
unsigned char username[NCP_USERNAME_LEN+1];
unsigned char password[NCP_PASSWORD_LEN+1];
unsigned int time_out; /* How long should I wait after
sending a NCP request? */
unsigned int retry_count; /* And how often should I retry? */
unsigned int flags;
uid_t uid;
gid_t gid;
mode_t file_mode;
mode_t dir_mode;
};
#endif

14
ncpfs-0.1.lsm Normal file
View File

@@ -0,0 +1,14 @@
Begin3
Title: ncpfs
Version: 0.1
Entered-date: 19. October 1995
Description: With ncpfs you can mount volumes of your novell
server under Linux.
Keywords: filesystem kernel ncp novell
Author: lendecke@namu01.gwdg.de (Volker Lendecke)
Maintained-by: lendecke@namu01.gwdg.de (Volker Lendecke)
Primary-site: linux01.gwdg.de:/pub/smbfs
~30k ncpfs-0.1.tgz
~ 1k ncpfs-0.1.lsm
Copying-policy: GPL
End

598
ncplib.c Normal file
View File

@@ -0,0 +1,598 @@
#include "ncplib.h"
#include "nwcrypt.h"
typedef __u8 byte;
typedef __u16 word;
typedef __u32 dword;
#ifdef __KERNEL__
#define ncp_printf DPRINTK
#else
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define ncp_printf printf
static void
assert_server_locked(struct ncp_server *server);
static void
assert_server_not_locked(struct ncp_server *server)
{
if (server->lock != 0) {
ncp_printf("ncpfs: server already locked!\n");
}
}
static void
ncp_lock_server(struct ncp_server *server)
{
assert_server_not_locked(server);
server->lock = 1;
}
static void
ncp_unlock_server(struct ncp_server *server)
{
assert_server_locked(server);
server->lock = 0;
}
static int
ncp_request(struct ncp_server *server, int function) {
struct ncp_reply_header *reply
= (struct ncp_reply_header *)(server->packet);
struct ncp_ioctl_request request;
int result;
assert_server_locked(server);
if (server->has_subfunction != 0) {
*(word *)(server->packet) = server->current_size - 2;
}
request.function = function;
request.size = server->current_size;
request.data = server->packet;
if ((result = ioctl(server->mount_fid, NCP_IOC_NCPREQUEST,
&request)) < 0) {
return result;
}
server->ncp_reply_size = result - sizeof(struct ncp_reply_header);
return reply->completion_code;
}
static inline int
min(int a, int b) {
if (a<b)
return a;
else
return b;
}
#endif
static void
assert_server_locked(struct ncp_server *server)
{
if (server->lock == 0) {
ncp_printf("ncpfs: server not locked!\n");
}
}
static void
ncp_add_byte(struct ncp_server *server, byte x)
{
assert_server_locked(server);
*(byte *)(&(server->packet[server->current_size])) = x;
server->current_size += 1;
return;
}
static void
ncp_add_word(struct ncp_server *server, word x)
{
assert_server_locked(server);
*(word *)(&(server->packet[server->current_size])) = x;
server->current_size += 2;
return;
}
static void
ncp_add_dword(struct ncp_server *server, dword x)
{
assert_server_locked(server);
*(dword *)(&(server->packet[server->current_size])) = x;
server->current_size += 4;
return;
}
static void
ncp_add_mem(struct ncp_server *server, const char *source, int size)
{
assert_server_locked(server);
memcpy(&(server->packet[server->current_size]), source, size);
server->current_size += size;
return;
}
static void
ncp_add_pstring(struct ncp_server *server, const char *s)
{
int len = strlen(s);
assert_server_locked(server);
if (len > 255) {
ncp_printf("ncpfs: string too long: %s\n", s);
len = 255;
}
ncp_add_byte(server, len);
ncp_add_mem(server, s, len);
return;
}
static void
ncp_init_request(struct ncp_server *server)
{
ncp_lock_server(server);
#ifdef __KERNEL__
server->current_size = sizeof(struct ncp_request_header);
#else
server->current_size = 0;
server->packet = server->ncp_data;
#endif
server->has_subfunction = 0;
}
static void
ncp_init_request_s(struct ncp_server *server, int subfunction)
{
ncp_init_request(server);
ncp_add_word(server, 0); /* preliminary size */
ncp_add_byte(server, subfunction);
server->has_subfunction = 1;
}
static char *
ncp_reply_data(struct ncp_server *server, int offset)
{
return &(server->packet[sizeof(struct ncp_reply_header) + offset]);
}
static byte
ncp_reply_byte(struct ncp_server *server, int offset)
{
return *(byte *)(ncp_reply_data(server, offset));
}
static word
ncp_reply_word(struct ncp_server *server, int offset)
{
return *(word *)(ncp_reply_data(server, offset));
}
static dword
ncp_reply_dword(struct ncp_server *server, int offset)
{
return *(dword *)(ncp_reply_data(server, offset));
}
int
ncp_negotiate_buffersize(struct ncp_server *server,
int size, int *target) {
int result;
ncp_init_request(server);
ncp_add_word(server, htons(size));
if ((result = ncp_request(server, 33)) < 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
*target =min(ntohs(ncp_reply_word(server, 0)), size);
ncp_unlock_server(server);
return 0;
}
/*
* result is a 8-byte buffer
*/
int
ncp_get_encryption_key(struct ncp_server *server,
char *target)
{
int result;
ncp_init_request_s(server, 23);
if ((result = ncp_request(server, 23)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
if (server->ncp_reply_size < 8) {
ncp_printf("ncp_reply_size %d < 8\n",
server->ncp_reply_size);
ncp_unlock_server(server);
return result;
}
memcpy(target, ncp_reply_data(server, 0), 8);
ncp_unlock_server(server);
return 0;
}
int
ncp_get_bindery_object_id(struct ncp_server *server,
int object_type, char *object_name,
struct ncp_bindery_object *target)
{
int result;
ncp_init_request_s(server, 53);
ncp_add_word(server, ntohs(object_type));
ncp_add_pstring(server, object_name);
if ((result = ncp_request(server, 23)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
if (server->ncp_reply_size < 54) {
ncp_printf("ncp_reply_size %d < 54\n",
server->ncp_reply_size);
ncp_unlock_server(server);
return result;
}
target->object_id = ntohl(ncp_reply_dword(server, 0));
target->object_type = ntohs(ncp_reply_word (server, 4));
memcpy(target->object_name, ncp_reply_data(server, 6), 48);
ncp_unlock_server(server);
return 0;
}
int
ncp_login_encrypted(struct ncp_server *server,
struct ncp_bindery_object *object,
unsigned char *key,
unsigned char *passwd)
{
dword tmpID = htonl(object->object_id);
unsigned char buf[128];
unsigned char encrypted[8];
int result;
shuffle((byte *)&tmpID, passwd, strlen(passwd), buf);
nw_encrypt(key, buf, encrypted);
ncp_init_request_s(server, 24);
ncp_add_mem(server, encrypted, 8);
ncp_add_word(server, htons(object->object_type));
ncp_add_pstring(server, object->object_name);
if ((result = ncp_request(server, 23)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
ncp_unlock_server(server);
return 0;
}
int
ncp_login_user(struct ncp_server *server,
unsigned char *username,
unsigned char *password)
{
int result;
unsigned char ncp_key[8];
struct ncp_bindery_object user;
if ((result = ncp_get_encryption_key(server, ncp_key)) != 0) {
return result;
}
if ((result = ncp_get_bindery_object_id(server, NCP_BINDERY_USER,
username, &user)) != 0) {
return result;
}
if ((result = ncp_login_encrypted(server, &user,
ncp_key, password)) != 0) {
return result;
}
return 0;
}
int
ncp_get_volume_info_with_number(struct ncp_server *server, int n,
struct ncp_volume_info *target)
{
int result;
int len;
ncp_init_request_s(server, 44);
ncp_add_byte(server, n);
if ((result = ncp_request(server, 22)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
target->total_blocks = ncp_reply_dword(server, 0);
target->free_blocks = ncp_reply_dword(server, 4);
target->purgeable_blocks = ncp_reply_dword(server, 8);
target->not_yet_purgeable_blocks = ncp_reply_dword(server, 12);
target->total_dir_entries = ncp_reply_dword(server, 16);
target->available_dir_entries = ncp_reply_dword(server, 20);
target->sectors_per_block = ncp_reply_byte(server, 28);
memset(&(target->volume_name), 0, sizeof(target->volume_name));
len = ncp_reply_byte(server, 29);
if (len > NCP_VOLNAME_LEN) {
ncp_printf("ncpfs: volume name too long: %d\n", len);
ncp_unlock_server(server);
return -EIO;
}
memcpy(&(target->volume_name), ncp_reply_data(server, 30), len);
ncp_unlock_server(server);
return 0;
}
int
ncp_get_volume_number(struct ncp_server *server, const char *name, int *target)
{
int result;
ncp_init_request_s(server, 5);
ncp_add_pstring(server, name);
if ((result = ncp_request(server, 22)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
*target = ncp_reply_byte(server, 0);
ncp_unlock_server(server);
return 0;
}
int
ncp_file_search_init(struct ncp_server *server,
int dir_handle, const char *path,
struct ncp_filesearch_info *target)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, dir_handle);
ncp_add_pstring(server, path);
if ((result = ncp_request(server, 62)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
target->volume_number = ncp_reply_byte(server, 0);
target->directory_id = ntohs(ncp_reply_word(server, 1));
target->sequence_no = ntohs(ncp_reply_word(server, 3));
target->access_rights = ncp_reply_byte(server, 5);
ncp_unlock_server(server);
return 0;
}
int
ncp_file_search_continue(struct ncp_server *server,
struct ncp_filesearch_info *fsinfo,
int attributes, const char *name,
struct ncp_file_info *target)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, fsinfo->volume_number);
ncp_add_word(server, htons(fsinfo->directory_id));
ncp_add_word(server, htons(fsinfo->sequence_no));
ncp_add_byte(server, attributes);
ncp_add_pstring(server, name);
if ((result = ncp_request(server, 63)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
fsinfo->sequence_no = ntohs(ncp_reply_word(server, 0));
memset(&(target->file_name), 0, sizeof(target->file_name));
memcpy(&(target->file_name), ncp_reply_data(server, 4),
NCP_MAX_FILENAME);
target->file_attributes = ncp_reply_byte(server, 18);
target->file_mode = ncp_reply_byte(server, 19);
target->file_length = ntohl(ncp_reply_dword(server, 20));
target->creation_date = ntohs(ncp_reply_word(server, 24));
target->access_date = ntohs(ncp_reply_word(server, 26));
target->update_date = ntohs(ncp_reply_word(server, 28));
target->update_time = ntohs(ncp_reply_word(server, 30));
ncp_unlock_server(server);
return 0;
}
int
ncp_get_finfo(struct ncp_server *server,
int dir_handle, const char *path, const char *name,
struct ncp_file_info *target)
{
int result;
struct ncp_filesearch_info fsinfo;
if ((result = ncp_file_search_init(server, dir_handle, path,
&fsinfo)) != 0) {
return result;
}
if ((result = ncp_file_search_continue(server, &fsinfo, 0, name,
target)) == 0) {
return result;
}
if ((result = ncp_file_search_init(server, dir_handle, path,
&fsinfo)) != 0) {
return result;
}
return ncp_file_search_continue(server, &fsinfo, aDIR, name, target);
}
int
ncp_open_file(struct ncp_server *server,
int dir_handle, const char *path,
int attr, int access,
struct ncp_file_info *target)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, dir_handle);
ncp_add_byte(server, attr);
ncp_add_byte(server, access);
ncp_add_pstring(server, path);
if ((result = ncp_request(server, 76)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
memcpy(&(target->file_id), ncp_reply_data(server, 0),
NCP_FILE_ID_LEN);
memset(&(target->file_name), 0, sizeof(target->file_name));
memcpy(&(target->file_name), ncp_reply_data(server, 8),
NCP_MAX_FILENAME);
target->file_attributes = ncp_reply_byte(server, 22);
target->file_mode = ncp_reply_byte(server, 23);
target->file_length = ntohl(ncp_reply_dword(server, 24));
target->creation_date = ntohs(ncp_reply_word(server, 28));
target->access_date = ntohs(ncp_reply_word(server, 30));
target->update_date = ntohs(ncp_reply_word(server, 32));
target->update_time = ntohs(ncp_reply_word(server, 34));
ncp_unlock_server(server);
return 0;
}
int
ncp_close_file(struct ncp_server *server, const char *file_id)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 0);
ncp_add_mem(server, file_id, 6);
if ((result = ncp_request(server, 66)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
ncp_unlock_server(server);
return 0;
}
#ifndef __KERNEL__
int
ncp_read(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_read,
char *target, int *bytes_read)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 0);
ncp_add_mem(server, file_id, 6);
ncp_add_dword(server, htonl(offset));
ncp_add_word(server, htons(to_read));
if ((result = ncp_request(server, 72)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
*bytes_read = ntohs(ncp_reply_word(server, 0));
memcpy(target, ncp_reply_data(server, 2), *bytes_read);
ncp_unlock_server(server);
return 0;
}
#else
/* We have to read into user space */
int
ncp_read(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_read,
char *target, int *bytes_read)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 0);
ncp_add_mem(server, file_id, 6);
ncp_add_dword(server, htonl(offset));
ncp_add_word(server, htons(to_read));
if ((result = ncp_request(server, 72)) != 0) {
ncp_printf("ncp_request_error: %d\n", result);
ncp_unlock_server(server);
return result;
}
*bytes_read = ntohs(ncp_reply_word(server, 0));
memcpy_tofs(target, ncp_reply_data(server, 2), *bytes_read);
ncp_unlock_server(server);
return 0;
}
#endif

102
ncplib.h Normal file
View File

@@ -0,0 +1,102 @@
#ifndef _NCPLIB_H
#define _NCPLIB_H
#ifdef __KERNEL__
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <linux/fs.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_fs_sb.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/malloc.h>
#include <linux/stat.h>
#include <linux/fcntl.h>
#include <asm/segment.h>
#include <asm/string.h>
#else
#include <linux/types.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
struct ncp_server {
int current_size;
int has_subfunction;
int mount_fid;
int ncp_reply_size;
char *packet;
int lock;
char ncp_data[NCP_PACKET_SIZE];
};
#endif __KERNEL__
#include <linux/ncp.h>
int
ncp_negotiate_buffersize(struct ncp_server *server, int size,
int *target);
int
ncp_get_encryption_key(struct ncp_server *server,
char *target);
int
ncp_get_bindery_object_id(struct ncp_server *server,
int object_type, char *object_name,
struct ncp_bindery_object *target);
int
ncp_login_encrypted(struct ncp_server *server,
struct ncp_bindery_object *object,
unsigned char *key,
unsigned char *passwd);
int
ncp_login_user(struct ncp_server *server,
unsigned char *username,
unsigned char *password);
int
ncp_get_volume_info_with_number(struct ncp_server *server, int n,
struct ncp_volume_info *target);
int
ncp_get_volume_number(struct ncp_server *server, const char *name,
int *target);
int
ncp_file_search_init(struct ncp_server *server,
int dir_handle, const char *path,
struct ncp_filesearch_info *target);
int
ncp_file_search_continue(struct ncp_server *server,
struct ncp_filesearch_info *fsinfo,
int attributes, const char *path,
struct ncp_file_info *target);
int
ncp_get_finfo(struct ncp_server *server,
int dir_handle, const char *path, const char *name,
struct ncp_file_info *target);
int
ncp_open_file(struct ncp_server *server,
int dir_handle, const char *path,
int attr, int access,
struct ncp_file_info *target);
int
ncp_close_file(struct ncp_server *server, const char *file_id);
int
ncp_read(struct ncp_server *server, const char *file_id,
__u32 start, __u16 to_read,
char *target, int *bytes_read);
#endif /* _NCPLIB_H */

332
ncpmount.c Normal file
View File

@@ -0,0 +1,332 @@
/*
* ncpmount.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
/* #include <sys/wait.h> */ /* generates a warning here */
extern pid_t waitpid(pid_t, int *, int);
#include <sys/errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <mntent.h>
#include <linux/ipx.h>
#include <linux/fs.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_mount.h>
#include "ipxutil.h"
static char *progname;
static char *mount_point;
static char *server_name;
struct sap_query {
unsigned short query_type; /* net order */
unsigned short server_type; /* net order */
};
struct sap_server_ident {
unsigned short server_type;
char server_name[48];
IPXNet server_network;
IPXNode server_node;
IPXPort server_port;
unsigned short intermediate_network;
} __attribute__ ((packed));
void
ipx_fprint_node(FILE* file,IPXNode node)
{
fprintf(file,"%02X%02X%02X%02X%02X%02X",
(unsigned char)node[0],
(unsigned char)node[1],
(unsigned char)node[2],
(unsigned char)node[3],
(unsigned char)node[4],
(unsigned char)node[5]
);
}
void
ipx_fprint_network(FILE* file,IPXNet net)
{
fprintf(file,"%08lX",ntohl(net));
}
void
ipx_fprint_port(FILE* file,IPXPort port)
{
fprintf(file,"%04X",ntohs(port));
}
void
ipx_fprint_saddr(FILE* file,struct sockaddr_ipx* sipx)
{
ipx_fprint_network(file,sipx->sipx_network);
fprintf(file,":");
ipx_fprint_node(file,sipx->sipx_node);
fprintf(file,":");
ipx_fprint_port(file,sipx->sipx_port);
}
void
ipx_print_node(IPXNode node)
{
ipx_fprint_node(stdout,node);
}
void
ipx_print_network(IPXNet net)
{
ipx_fprint_network(stdout,net);
}
void
ipx_print_port(IPXPort port)
{
ipx_fprint_port(stdout,port);
}
void
ipx_print_saddr(struct sockaddr_ipx* sipx)
{
ipx_fprint_saddr(stdout,sipx);
}
int
ipx_sap_find_server(char *name, int server_type, int timeout,
struct sockaddr_ipx *result)
{
struct sockaddr_ipx ipxs;
char data[1024];
int sock;
int opt;
int res = -1;
int name_len = strlen(name);
fd_set rd, wr, ex;
struct timeval tv;
if (name_len > 48) {
return -1;
}
sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX);
if (sock==-1) {
return -1;
}
opt=1;
/* Permit broadcast output */
if(setsockopt(sock,SOL_SOCKET,SO_BROADCAST, &opt,sizeof(opt))==-1)
{
perror("setsockopt");
goto finished;
}
memset(&ipxs, 0, sizeof(ipxs));
ipxs.sipx_family=AF_IPX;
ipxs.sipx_network=htonl(0x0);
ipxs.sipx_port=htons(0x0);
ipxs.sipx_type=IPX_SAP_PTYPE;
if(bind(sock,(struct sockaddr*)&ipxs,sizeof(ipxs))==-1)
{
perror("bind");
goto finished;
}
*(unsigned short *)data = htons(0x0001);
*(unsigned short *)&(data[2]) = htons(server_type);
memset(&ipxs, 0, sizeof(ipxs));
ipxs.sipx_family=AF_IPX;
ipxs.sipx_network=htonl(0x0);
ipx_assign_node(ipxs.sipx_node, IPX_BROADCAST_NODE);
ipxs.sipx_port=htons(IPX_SAP_PORT);
ipxs.sipx_type=IPX_SAP_PTYPE;
if (sendto(sock, data, 4, 0,
(struct sockaddr *)&ipxs, sizeof(ipxs)) < 0) {
perror("sendto");
goto finished;
}
FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&ex);
FD_SET(sock, &rd);
tv.tv_sec = timeout;
tv.tv_usec = 0;
if (select(sock+1, &rd, &wr, &ex, &tv) == -1) {
perror("select");
goto finished;
}
if (FD_ISSET(sock, &rd)) {
int len = recv(sock, data, 1024, 0);
int i;
struct sap_server_ident *ident;
for (i = 2; i < len; i += 64) {
ident = (struct sap_server_ident *)(data+i);
if ( (strncmp(name,ident->server_name,name_len)==0)
&& (name_len < 48)
&& (ident->server_name[name_len] == '\0'))
{
result->sipx_family = AF_IPX;
result->sipx_network =
ident->server_network;
result->sipx_port = ident->server_port;
ipx_assign_node(result->sipx_node,
ident->server_node);
res = 0;
goto finished;
}
}
}
finished:
close(sock);
return res;
}
int ipx_sscanf_node(char *buf, unsigned char node[6])
{
int i;
int n[6];
if ((i = sscanf(buf, "%2x%2x%2x%2x%2x%2x",
&(n[0]), &(n[1]), &(n[2]),
&(n[3]), &(n[4]), &(n[5]))) != 6) {
return i;
}
for (i=0; i<6; i++) {
node[i] = n[i];
}
return 6;
}
int
main(int argc, char **argv)
{
struct ncp_mount_data data;
struct stat st;
struct sockaddr_ipx addr;
int ncp_sock, wdog_sock;
int flags;
progname = argv[0];
if (geteuid() != 0) {
fprintf(stderr, "%s must be installed suid root\n", progname);
exit(1);
}
memset(&data, 0, sizeof(struct ncp_mount_data));
if (argc != 5) {
fprintf(stderr, "usage: %s server mount-point"
" user password\n", progname);
exit(1);
}
server_name = argv[1];
mount_point = argv[2];
if (stat(mount_point, &st) == -1) {
fprintf(stderr, "could not find mount point %s: %s\n",
mount_point, strerror(errno));
exit(1);
}
ncp_sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (ncp_sock == -1) {
fprintf(stderr, "could not open ncp socket: %s\n",
strerror(errno));
exit(1);
}
wdog_sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (wdog_sock == -1) {
fprintf(stderr, "could not open wdog socket: %s\n",
strerror(errno));
exit(1);
}
addr.sipx_type = NCP_PTYPE;
if (bind(ncp_sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
fprintf(stderr, "bind(ncp_sock, ): %s\n",
strerror(errno));
exit(1);
}
if (bind(wdog_sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
fprintf(stderr, "bind(wdog_sock, ): %s\n",
strerror(errno));
exit(1);
}
if (ipx_sap_find_server(server_name, IPX_SAP_FILE_SERVER,
3, &addr) != 0) {
fprintf(stderr, "could not find server %s\n", server_name);
exit(1);
}
printf("server: ");
ipx_fprint_saddr(stdout, &addr);
printf("\n");
data.version = NCP_MOUNT_VERSION;
data.ncp_fd = ncp_sock;
data.wdog_fd = wdog_sock;
data.mounted_uid = getuid();
data.serv_addr = addr;
strcpy(data.server_name, server_name);
data.time_out = 20; /* 2 seconds */
data.retry_count = 2;
data.uid = 501; /* me */
data.gid = 100; /* users */
data.file_mode = data.dir_mode = S_IRWXU|S_IRWXG|S_IRWXO;
strcpy(data.username, argv[3]);
strcpy(data.password, argv[4]);
flags = MS_MGC_VAL;
if (mount(NULL, mount_point, "ncpfs", flags, (char *)&data) < 0) {
perror("mount error");
fprintf(stderr, "Maybe you should try your password in "
"upper case\n");
return -1;
}
close(ncp_sock);
close(wdog_sock);
return 0;
}

141
nwcrypt.c Normal file
View File

@@ -0,0 +1,141 @@
/*$*********************************************************
$*
$* This code has been taken from DDJ 11/93, from an
$* article by Pawel Szczerbina. Please read the file
$* README for my questions about the legal status of
$* this code.
$*
$* Password encryption routines follow.
$* Converted to C from Barry Nance's Pascal
$* prog published in the March -93 issue of Byte.
$*
$* Adapted to be useable for ncpfs by
$* Volker Lendecke <lendecke@namu01.gwdg.de> in
$* October 1995.
$*
$**********************************************************/
/******************* Data types ***************************/
typedef unsigned char buf32[32];
typedef unsigned char buf16[16];
typedef unsigned char buf8[8];
typedef unsigned char buf4[4];
typedef unsigned char u8;
static u8 encrypttable[256] =
{0x7,0x8,0x0,0x8,0x6,0x4,0xE,0x4,0x5,0xC,0x1,0x7,0xB,0xF,0xA,0x8,
0xF,0x8,0xC,0xC,0x9,0x4,0x1,0xE,0x4,0x6,0x2,0x4,0x0,0xA,0xB,0x9,
0x2,0xF,0xB,0x1,0xD,0x2,0x1,0x9,0x5,0xE,0x7,0x0,0x0,0x2,0x6,0x6,
0x0,0x7,0x3,0x8,0x2,0x9,0x3,0xF,0x7,0xF,0xC,0xF,0x6,0x4,0xA,0x0,
0x2,0x3,0xA,0xB,0xD,0x8,0x3,0xA,0x1,0x7,0xC,0xF,0x1,0x8,0x9,0xD,
0x9,0x1,0x9,0x4,0xE,0x4,0xC,0x5,0x5,0xC,0x8,0xB,0x2,0x3,0x9,0xE,
0x7,0x7,0x6,0x9,0xE,0xF,0xC,0x8,0xD,0x1,0xA,0x6,0xE,0xD,0x0,0x7,
0x7,0xA,0x0,0x1,0xF,0x5,0x4,0xB,0x7,0xB,0xE,0xC,0x9,0x5,0xD,0x1,
0xB,0xD,0x1,0x3,0x5,0xD,0xE,0x6,0x3,0x0,0xB,0xB,0xF,0x3,0x6,0x4,
0x9,0xD,0xA,0x3,0x1,0x4,0x9,0x4,0x8,0x3,0xB,0xE,0x5,0x0,0x5,0x2,
0xC,0xB,0xD,0x5,0xD,0x5,0xD,0x2,0xD,0x9,0xA,0xC,0xA,0x0,0xB,0x3,
0x5,0x3,0x6,0x9,0x5,0x1,0xE,0xE,0x0,0xE,0x8,0x2,0xD,0x2,0x2,0x0,
0x4,0xF,0x8,0x5,0x9,0x6,0x8,0x6,0xB,0xA,0xB,0xF,0x0,0x7,0x2,0x8,
0xC,0x7,0x3,0xA,0x1,0x4,0x2,0x5,0xF,0x7,0xA,0xC,0xE,0x5,0x9,0x3,
0xE,0x7,0x1,0x2,0xE,0x1,0xF,0x4,0xA,0x6,0xC,0x6,0xF,0x4,0x3,0x0,
0xC,0x0,0x3,0x6,0xF,0x8,0x7,0xB,0x2,0xD,0xC,0x6,0xA,0xA,0x8,0xD};
static buf32 encryptkeys =
{0x48,0x93,0x46,0x67,0x98,0x3D,0xE6,0x8D,
0xB7,0x10,0x7A,0x26,0x5A,0xB9,0xB1,0x35,
0x6B,0x0F,0xD5,0x70,0xAE,0xFB,0xAD,0x11,
0xF4,0x47,0xDC,0xA7,0xEC,0xCF,0x50,0xC0};
static void
shuffle1(buf32 temp, unsigned char *target)
{
short b4;
unsigned char b3;
int s, b2, i;
b4 = 0;
for (b2 = 0; b2 <= 1; ++b2)
{
for (s = 0; s <= 31; ++s)
{
b3 = (temp[s]+b4) ^ (temp[(s+b4)&31] - encryptkeys[s]);
b4 = b4 + b3;
temp[s] = b3;
}
}
for (i = 0; i <= 15; ++i) {
target[i] = encrypttable[temp[ 2*i ]]
| (encrypttable[temp[ 2*i + 1]] << 4);
}
}
void
shuffle(unsigned char *lon, const unsigned char *buf, int buflen,
unsigned char *target)
{
int b2, d, s;
buf32 temp;
while ( (buflen > 0)
&& (buf[buflen - 1] == 0)) {
buflen = buflen - 1;
}
for (s = 0; s < 32; s++) {
temp[s] = 0;
}
d = 0;
while (buflen >= 32)
{
for (s = 0; s <= 31; ++s)
{
temp[s] = temp[s] ^ buf[d];
d = d + 1;
}
buflen = buflen - 32;
}
b2 = d;
if (buflen > 0)
{
for (s = 0; s <= 31; ++s)
{
if (d + buflen == b2)
{
b2 = d;
temp[s] = temp[s] ^ encryptkeys[s];
} else {
temp[s] = temp[s] ^ buf[b2];
b2 = b2 + 1;
}
}
}
for (s = 0; s <= 31; ++s)
temp[s] = temp[s] ^ lon[s & 3];
shuffle1(temp,target);
}
void
nw_encrypt(unsigned char *fra,unsigned char *buf,unsigned char *til)
{
buf32 k;
int s;
shuffle(&(fra[0]), buf, 16, &(k[ 0]));
shuffle(&(fra[4]), buf, 16, &(k[16]));
for (s = 0; s <= 15; ++s)
k[s] = k[s] ^ k[31 - s];
for (s = 0; s <= 7; ++s)
til[s] = k[s] ^ k[15 - s];
}

5
nwcrypt.h Normal file
View File

@@ -0,0 +1,5 @@
void
shuffle(unsigned char *lon, const unsigned char *buf, int buflen,
unsigned char *target);
void
nw_encrypt(unsigned char *fra,unsigned char *buf,unsigned char *til);

533
sock.c Normal file
View File

@@ -0,0 +1,533 @@
/*
* linux/fs/ncp/sock.c
*
* Copyright (C) 1992, 1993 Rick Sladkey
*
* Modified 1995 by Volker Lendecke to be usable for ncp
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <linux/sched.h>
#include <linux/ncp_fs.h>
#include <linux/errno.h>
#include <linux/socket.h>
#include <linux/fcntl.h>
#include <linux/stat.h>
#include <asm/segment.h>
#include <linux/in.h>
#include <linux/net.h>
#include <linux/mm.h>
#include <linux/netdevice.h>
#include <linux/ipx.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_fs_sb.h>
#include <net/sock.h>
#define _S(nr) (1<<((nr)-1))
static void
ncp_wdog_data_ready(struct sock *sk, int len)
{
struct socket *sock = sk->socket;
if (!sk->dead)
{
unsigned char packet_buf[2];
struct sockaddr_ipx sender;
int addr_len;
int result;
unsigned short fs;
fs = get_fs();
set_fs(get_ds());
result = sock->ops->recvfrom(sock, (void *)packet_buf, 2, 1, 0,
(struct sockaddr *)&sender,
&addr_len);
if ( (result != 2)
|| (packet_buf[1] != '?')
/* How to check connection number here? */
)
{
/* Error, throw away the complete packet */
sock->ops->recvfrom(sock, (void *)packet_buf, 2, 1, 0,
(struct sockaddr *)&sender,
&addr_len);
printk("ncpfs: got strange packet on watchdog "
"socket\n");
} else {
int result;
DPRINTK("ncpfs: got watchdog from:\n");
DPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X,"
" conn:%02X,type:%c\n",
htonl(sender.sipx_network),
sender.sipx_node[0], sender.sipx_node[1],
sender.sipx_node[2], sender.sipx_node[3],
sender.sipx_node[4], sender.sipx_node[5],
ntohs(sender.sipx_port),
packet_buf[0], packet_buf[1]);
packet_buf[1] = 'Y';
result = sock->ops->
sendto(sock, (void *)packet_buf, 2, 1, 0,
(struct sockaddr *)&sender,
sizeof(sender));
printk("send result: %d\n", result);
}
set_fs(fs);
}
}
int
ncp_catch_watchdog(struct ncp_server *server)
{
struct file *file;
struct inode *inode;
struct socket *sock;
struct sock *sk;
if ( (server == NULL)
|| ((file = server->wdog_filp) == NULL)
|| ((inode = file->f_inode) == NULL)
|| (!S_ISSOCK(inode->i_mode))) {
printk("ncp_catch_watchdog: did not get valid server!\n");
server->data_ready = NULL;
return -EINVAL;
}
sock = &(inode->u.socket_i);
if (sock->type != SOCK_DGRAM) {
printk("ncp_catch_watchdog: did not get SOCK_STREAM\n");
server->data_ready = NULL;
return -EINVAL;
}
sk = (struct sock *)(sock->data);
if (sk == NULL) {
printk("ncp_catch_watchdog: sk == NULL");
server->data_ready = NULL;
return -EINVAL;
}
DDPRINTK("ncp_catch_watchdog.: sk->d_r = %x, server->d_r = %x\n",
(unsigned int)(sk->data_ready),
(unsigned int)(server->data_ready));
if (sk->data_ready == ncp_wdog_data_ready) {
printk("ncp_catch_watchdog: already done\n");
return -EINVAL;
}
server->data_ready = sk->data_ready;
sk->data_ready = ncp_wdog_data_ready;
return 0;
}
int
ncp_dont_catch_watchdog(struct ncp_server *server)
{
struct file *file;
struct inode *inode;
struct socket *sock;
struct sock *sk;
if ( (server == NULL)
|| ((file = server->wdog_filp) == NULL)
|| ((inode = file->f_inode) == NULL)
|| (!S_ISSOCK(inode->i_mode))) {
printk("ncp_dont_catch_watchdog: "
"did not get valid server!\n");
return -EINVAL;
}
sock = &(inode->u.socket_i);
if (sock->type != SOCK_DGRAM) {
printk("ncp_dont_catch_watchdog: did not get SOCK_STREAM\n");
return -EINVAL;
}
sk = (struct sock *)(sock->data);
if (sk == NULL) {
printk("ncp_dont_catch_watchdog: sk == NULL");
return -EINVAL;
}
if (server->data_ready == NULL) {
printk("ncp_dont_catch_watchdog: "
"server->data_ready == NULL\n");
return -EINVAL;
}
if (sk->data_ready != ncp_wdog_data_ready) {
printk("ncp_dont_catch_watchdog: "
"sk->data_callback != ncp_data_callback\n");
return -EINVAL;
}
DDPRINTK("ncp_dont_catch_watchdog: sk->d_r = %x, server->d_r = %x\n",
(unsigned int)(sk->data_ready),
(unsigned int)(server->data_ready));
sk->data_ready = server->data_ready;
server->data_ready = NULL;
return 0;
}
#define NCP_SLACK_SPACE 1024
#define _S(nr) (1<<((nr)-1))
static int
do_ncp_rpc_call(struct ncp_server *server, int size)
{
struct file *file;
struct inode *inode;
struct socket *sock;
unsigned short fs;
int result;
char *start = server->packet;
select_table wait_table;
struct select_table_entry entry;
int (*select) (struct inode *, struct file *, int, select_table *);
int init_timeout, max_timeout;
int timeout;
int retrans;
int major_timeout_seen;
char *server_name;
int n;
int addrlen;
unsigned long old_mask;
/* We have to check the result, so store the complete header */
struct ncp_request_header request =
*((struct ncp_request_header *)(server->packet));
struct ncp_reply_header reply;
file = server->ncp_filp;
inode = file->f_inode;
select = file->f_op->select;
sock = &inode->u.socket_i;
if (!sock) {
printk("ncp_rpc_call: socki_lookup failed\n");
return -EBADF;
}
init_timeout = server->m.time_out;
max_timeout = NCP_MAX_RPC_TIMEOUT*HZ/10;
retrans = server->m.retry_count;
major_timeout_seen = 0;
server_name = server->m.server_name;
old_mask = current->blocked;
current->blocked |= ~(_S(SIGKILL)
#if 0
| _S(SIGSTOP)
#endif
| ((server->m.flags & NCP_MOUNT_INTR)
? ((current->sig->action[SIGINT - 1].sa_handler == SIG_DFL
? _S(SIGINT) : 0)
| (current->sig->action[SIGQUIT - 1].sa_handler == SIG_DFL
? _S(SIGQUIT) : 0))
: 0));
fs = get_fs();
set_fs(get_ds());
for (n = 0, timeout = init_timeout; ; n++, timeout <<= 1) {
DDPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
htonl(server->m.serv_addr.sipx_network),
server->m.serv_addr.sipx_node[0],
server->m.serv_addr.sipx_node[1],
server->m.serv_addr.sipx_node[2],
server->m.serv_addr.sipx_node[3],
server->m.serv_addr.sipx_node[4],
server->m.serv_addr.sipx_node[5],
ntohs(server->m.serv_addr.sipx_port));
DDPRINTK("ncpfs: req.typ: %04X, con: %d, tsk: %d, "
"seq: %d\n",
request.type,
(request.conn_high << 8) + request.conn_low,
request.task,
request.sequence);
DDPRINTK("ncpfs: req.func: %d\n",
request.function);
result = sock->ops->
sendto(sock, (void *) start, size, 0, 0,
(struct sockaddr *)&(server->m.serv_addr),
sizeof(server->m.serv_addr));
if (result < 0) {
printk("ncp_rpc_call: send error = %d\n", result);
break;
}
re_select:
wait_table.nr = 0;
wait_table.entry = &entry;
current->state = TASK_INTERRUPTIBLE;
if ( !select(inode, file, SEL_IN, &wait_table)
&& !select(inode, file, SEL_IN, NULL)) {
if (timeout > max_timeout) {
/* JEJB/JSP 2/7/94
* This is useful to see if the system is
* hanging */
printk("NCP max timeout reached on %s\n",
server_name);
timeout = max_timeout;
}
current->timeout = jiffies + timeout;
schedule();
remove_wait_queue(entry.wait_address, &entry.wait);
current->state = TASK_RUNNING;
if (current->signal & ~current->blocked) {
current->timeout = 0;
result = -ERESTARTSYS;
break;
}
if (!current->timeout) {
if (n < retrans)
continue;
if (server->m.flags & NCP_MOUNT_SOFT) {
printk("NCP server %s not responding, "
"timed out\n", server_name);
result = -EIO;
break;
}
n = 0;
timeout = init_timeout;
init_timeout <<= 1;
if (!major_timeout_seen) {
printk("NCP server %s not responding, "
"still trying\n", server_name);
}
major_timeout_seen = 1;
continue;
}
else
current->timeout = 0;
}
else if (wait_table.nr)
remove_wait_queue(entry.wait_address, &entry.wait);
current->state = TASK_RUNNING;
addrlen = 0;
/* Get the header from the next packet using a peek, so keep it
* on the recv queue. If it is wrong, it will be some reply
* we don't now need, so discard it */
result = sock->ops->recvfrom(sock, (void *)&reply,
sizeof(reply), 1, MSG_PEEK,
NULL, &addrlen);
if (result < 0) {
if (result == -EAGAIN) {
DPRINTK("ncp_rpc_call: bad select ready\n");
goto re_select;
}
if (result == -ECONNREFUSED) {
DPRINTK("ncp_rpc_call: server playing coy\n");
goto re_select;
}
if (result != -ERESTARTSYS) {
printk("ncp_rpc_call: recv error = %d\n",
-result);
}
break;
}
if ( (result == sizeof(reply))
&& (reply.type == NCP_POSITIVE_ACK)) {
/* Throw away the packet */
DPRINTK("ncp_rpc_call: got positive acknowledge\n");
(void)sock->ops->recvfrom(sock, (void *)&reply,
sizeof(reply), 1, 0, NULL,
&addrlen);
goto re_select;
}
DDPRINTK("ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
"seq: %d\n",
reply.type,
(reply.conn_high << 8) + reply.conn_low,
reply.task,
reply.sequence);
if ( (result >= sizeof(reply))
&& (reply.type == NCP_REPLY)
&& ( (request.type == NCP_ALLOC_SLOT_REQUEST)
|| ( (reply.sequence == request.sequence)
&& (reply.conn_low == request.conn_low)
/* seem to get wrong task from NW311 && (reply.task == request.task)*/
&& (reply.conn_high == request.conn_high)))) {
if (major_timeout_seen)
printk("NCP server %s OK\n", server_name);
break;
}
/* JEJB/JSP 2/7/94
* we have xid mismatch, so discard the packet and start
* again. What a hack! but I can't call recvfrom with
* a null buffer yet. */
(void)sock->ops->recvfrom(sock, (void *)&reply,
sizeof(reply), 1, 0, NULL,
&addrlen);
#if 1
printk("ncp_rpc_call: reply mismatch\n");
#endif
goto re_select;
}
/*
* we have the correct reply, so read into the correct place and
* return it
*/
result=sock->ops->recvfrom(sock, (void *)start,
server->packet_size, 1, 0, NULL,
&addrlen);
if (result < 0) {
printk("NCP: notice message: result=%d\n", result);
} else if (result < sizeof(struct ncp_reply_header)) {
printk("NCP: just caught a too small read memory size..., "
"email to NET channel\n");
printk("NCP: result=%d,addrlen=%d\n", result, addrlen);
result = -EIO;
}
current->blocked = old_mask;
set_fs(fs);
return result;
}
/*
* We need the server to be locked here, so check!
*/
static int
ncp_do_request(struct ncp_server *server, int size)
{
if (server->lock == 0) {
printk("ncpfs: Server not locked!\n");
return -EIO;
}
return do_ncp_rpc_call(server, size);
}
/* ncp_do_request assures that at least a complete reply header is
* received. It assumes that server->current_size contains the ncp
* request size */
int
ncp_request(struct ncp_server *server, int function)
{
struct ncp_request_header *h
= (struct ncp_request_header *)(server->packet);
struct ncp_reply_header *reply
= (struct ncp_reply_header *)(server->packet);
int request_size = server->current_size
- sizeof(struct ncp_request_header);
int result;
if (server->has_subfunction != 0) {
*(__u16 *)&(h->data[0]) = request_size - 2;
}
h->type = NCP_REQUEST;
server->sequence += 1;
h->sequence = server->sequence;
h->conn_low = (server->connection) & 0xff;
h->conn_high = ((server->connection) & 0xff00) >> 8;
h->task = (current->pid) & 0xff;
h->function = function;
if ((result = ncp_do_request(server, request_size + sizeof(*h))) < 0) {
return result;
}
server->completion = reply->completion_code;
server->conn_status = reply->connection_state;
server->reply_size = result;
server->ncp_reply_size = result - sizeof(struct ncp_reply_header);
return reply->completion_code;
}
int
ncp_connect(struct ncp_server *server)
{
struct ncp_request_header *h
= (struct ncp_request_header *)(server->packet);
int result;
h->type = NCP_ALLOC_SLOT_REQUEST;
server->sequence = 0;
h->sequence = server->sequence;
h->conn_low = 0xff;
h->conn_high = 0xff;
h->task = (current->pid) & 0xff;
h->function = 0;
if ((result = ncp_do_request(server, sizeof(*h))) < 0) {
return result;
}
server->sequence = 0;
server->connection = h->conn_low + (h->conn_high * 256);
return 0;
}
int
ncp_disconnect(struct ncp_server *server)
{
struct ncp_request_header *h
= (struct ncp_request_header *)(server->packet);
h->type = NCP_DEALLOC_SLOT_REQUEST;
server->sequence += 1;
h->sequence = server->sequence;
h->conn_low = (server->connection) & 0xff;
h->conn_high = ((server->connection) & 0xff00) >> 8;
h->task = (current->pid) & 0xff;
h->function = 0;
return ncp_do_request(server, sizeof(*h));
}
void
ncp_lock_server(struct ncp_server *server)
{
while (server->lock)
sleep_on(&server->wait);
server->lock = 1;
}
void
ncp_unlock_server(struct ncp_server *server)
{
if (server->lock != 1) {
printk("ncp_unlock_server: was not locked!\n");
}
server->lock = 0;
wake_up(&server->wait);
}

3
startnet Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
ipx_interface add -p eth0 EtherII abcd
ipx_route add 1234 abcd 00001b038b11