Commit d92ff5df authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://cifs.bkbits.net/linux-2.5-with-cifs

into penguin.transmeta.com:/home/penguin/torvalds/repositories/kernel/linux
parents d632a316 3a615de9
...@@ -8,6 +8,8 @@ affs.txt ...@@ -8,6 +8,8 @@ affs.txt
- info and mount options for the Amiga Fast File System. - info and mount options for the Amiga Fast File System.
bfs.txt bfs.txt
- info for the SCO UnixWare Boot Filesystem (BFS). - info for the SCO UnixWare Boot Filesystem (BFS).
cifs.txt
- description of the CIFS filesystem
coda.txt coda.txt
- description of the CODA filesystem. - description of the CODA filesystem.
cramfs.txt cramfs.txt
......
This module, cifs, is a filesystem that implements the SMB/CIFS protocol, which is the
protocol used by Windows based operating systems (including Windows 2000 and its successors)
as well as Samba, OS/2 and many others operating systems and network file server appliances.
The Cifs VFS filesystem module is designed to work well with servers that implement the newer versions
(dialects) of the SMB/CIFS protocol such as Samba, the program written by Andrew Tridgell
that turns any Unix host into a file server for DOS or Windows clients, as well as Windows NT,
Windows 2000 and its successors. It is not designed to handle older smb servers well, those that
implement older versions of the dialect (such as OS/2 or Windows 95), for this purpose use smbfs.
This module can support mounting without a mount helper program. The mount syntax is:
mount //server_ip_address/share_name /mnt -o user=username,password=your_password
where "username", "your_password" and "server_ip_address" and "share_name" should be replaced
with specific values (supplied by the user) e.g.
mount //9.53.216.16/public /mnt -o user=jsmith,password=openup
This cifs implementation is designed to handle network caching (safely) as well as to implement locking,
large file (64 bit access), distributed file system ("dfs") and other advanced protocol features. It
also implements the SNIA standard for Unix extensions to CIFS (when communicating with servers such as
Samba 2.2.3 or later which support it).
For more information contact sfrench@us.ibm.com
Cifs is an SMB client (or gateway). For more info on the SMB/CIFS protocol and Samba, including
documentation, please go to http://www.samba.org/ and then on to your nearest mirror. For more
information about the cifs vfs, go to the project page at:
http://us1.samba.org/samba/Linux_CIFS_client.html
...@@ -950,6 +950,33 @@ CONFIG_VXFS_FS ...@@ -950,6 +950,33 @@ CONFIG_VXFS_FS
module, say M here and read <file:Documentation/modules.txt>. If module, say M here and read <file:Documentation/modules.txt>. If
unsure, say N. unsure, say N.
CIFS (Common Internet File System) support
CONFIG_CIFS
This is the client VFS module for the Common Internet File System
(CIFS) protocol which is the successor to the Server Message Block
(SMB) protocol, the native file sharing mechanism for most early
PC operating systems. CIFS is fully supported by current network
file servers such as Windows 2000 (including Windows NT version 4
and Windows XP) as well by Samba (which provides excellent CIFS
server support for Linux and many other operating systems). For
production systems the smbfs module may be used instead of this
cifs module since smbfs is currently more stable and provides
support for older servers. The intent of this module is to provide the
most advanced network file system function for CIFS compliant servers,
including support for dfs (heirarchical name space), secure per-user
session establishment, safe distributed caching (oplock), optional
packet signing, Unicode and other internationalization improvements, and
optional Winbind (nsswitch) integration. This module is in an early
development stage, so unless you are specifically interested in this
filesystem, just say N.
CIFS Debugging
CONFIG_CIFS_DEBUG
If you are experiencing any problems with the CIFS filesystem, say
Y here. This will result in additional debugging messages to be
written to the system log. Under normal circumstances, this
results in very little overhead.
CONFIG_SMB_FS CONFIG_SMB_FS
SMB (Server Message Block) is the protocol Windows for Workgroups SMB (Server Message Block) is the protocol Windows for Workgroups
(WfW), Windows 95/98, Windows NT and OS/2 Lan Manager use to share (WfW), Windows 95/98, Windows NT and OS/2 Lan Manager use to share
......
...@@ -140,6 +140,8 @@ if [ "$CONFIG_NET" = "y" ]; then ...@@ -140,6 +140,8 @@ if [ "$CONFIG_NET" = "y" ]; then
fi fi
define_tristate CONFIG_EXPORTFS $CONFIG_NFSD define_tristate CONFIG_EXPORTFS $CONFIG_NFSD
dep_tristate 'CIFS support (advanced network filesystem for Samba, Window and other CIFS compliant servers)(EXPERIMENTAL)' CONFIG_CIFS $CONFIG_INET
dep_tristate 'SMB file system support (to mount Windows shares etc.)' CONFIG_SMB_FS $CONFIG_INET dep_tristate 'SMB file system support (to mount Windows shares etc.)' CONFIG_SMB_FS $CONFIG_INET
if [ "$CONFIG_SMB_FS" != "n" ]; then if [ "$CONFIG_SMB_FS" != "n" ]; then
bool ' Use a default NLS' CONFIG_SMB_NLS_DEFAULT bool ' Use a default NLS' CONFIG_SMB_NLS_DEFAULT
......
...@@ -65,6 +65,7 @@ obj-$(CONFIG_LOCKD) += lockd/ ...@@ -65,6 +65,7 @@ obj-$(CONFIG_LOCKD) += lockd/
obj-$(CONFIG_NLS) += nls/ obj-$(CONFIG_NLS) += nls/
obj-$(CONFIG_SYSV_FS) += sysv/ obj-$(CONFIG_SYSV_FS) += sysv/
obj-$(CONFIG_SMB_FS) += smbfs/ obj-$(CONFIG_SMB_FS) += smbfs/
obj-$(CONFIG_CIFS) += cifs/
obj-$(CONFIG_NCP_FS) += ncpfs/ obj-$(CONFIG_NCP_FS) += ncpfs/
obj-$(CONFIG_HPFS_FS) += hpfs/ obj-$(CONFIG_HPFS_FS) += hpfs/
obj-$(CONFIG_NTFS_FS) += ntfs/ obj-$(CONFIG_NTFS_FS) += ntfs/
......
Original Author
===============
Steve French (sfrench@samba.org)
The author wishes to express his appreciation and thanks to:
Andrew Tridgell (Samba team) for his early suggestions about smb/cifs VFS
improvements. Thanks to IBM for allowing me the time and test resources to pursue
this project. Jim McDonough from IBM (and the Samba Team) for his help.
The IBM Linux JFS team for explaining many esoteric Linux filesystem features.
Dave Boutcher of IBM Rochester (author of the OS/400 smb/cifs filesystem client)
for proving years ago that a very good smb/cifs client could be done on a Unix like
operating system. Volker Lendecke, Andrew Tridgell, Urban Widmark, John Newbigin
and others for their work on the Linux smbfs module over the years. Thanks to
the other members of the Storage Network Industry Association CIFS Technical
Workgroup for their work specifying this highly complex protocol and finally
thanks to the Samba team for their technical advice and encouragement.
Version 0.54
------------
Fix problem with captive thread hanging around at unmount time. Adjust to 2.5.42-pre
changes to superblock layout. Remove wasteful allocation of smb buffers (now the send
buffer is reused for responses). Add more oplock handling. Additional minor cleanup.
Version 0.53
------------
More stylistic updates to better match kernel style. Add additional statistics
for filesystem which can be viewed via /proc/fs/cifs. Add more pieces of NTLMv2
and CIFS Packet Signing enablement.
Version 0.52
------------
Replace call to sleep_on with safer wait_on_event.
Make stylistic changes to better match kernel style recommendations.
Remove most typedef usage (except for the PDUs themselves).
Version 0.51
------------
Update mount so the -unc mount option is no longer required (the ip address can be specified
in a UNC style device name. Implementation of readpage/writepage started.
Version 0.50
------------
Fix intermittent problem with incorrect smb header checking on badly
fragmented tcp responses
Version 0.49
------------
Fixes to setting of allocation size and file size.
Version 0.48
------------
Various 2.5.38 fixes. Now works on 2.5.38
Version 0.47
------------
Prepare for 2.5 kernel merge. Remove ifdefs.
Version 0.46
------------
Socket buffer management fixes. Fix dual free.
Version 0.45
------------
Various big endian fixes for hardlinks and symlinks and also for dfs.
Version 0.44
------------
Various big endian fixes for servers with Unix extensions such as Samba
Version 0.43
------------
Various FindNext fixes for incorrect filenames on large directory searches on big endian
clients. basic posix file i/o tests now work on big endian machines, not just le
Version 0.42
------------
SessionSetup and NegotiateProtocol now work from Big Endian machines.
Various Big Endian fixes found during testing on the Linux on 390. Various fixes for compatability with older
versions of 2.4 kernel (now builds and works again on kernels at least as early as 2.4.7).
Version 0.41
------------
Various minor fixes for Connectathon Posix "basic" file i/o test suite. Directory caching fixed so hardlinked
files now return the correct rumber of links on fstat as they are repeatedly linked and unlinked.
Version 0.40
------------
Implemented "Raw" (i.e. not encapsulated in SPNEGO) NTLMSSP (i.e. the Security Provider Interface used to negotiate
session advanced session authentication). Raw NTLMSSP is preferred by Windows 2000 Professional and Windows XP.
Began implementing support for SPNEGO encapsulation of NTLMSSP based session authentication blobs
(which is the mechanism preferred by Windows 2000 server in the absence of Kerberos).
Version 0.38
------------
Introduced optional mount helper utility mount.cifs and made coreq changes to cifs vfs to enable
it. Fixed a few bugs in the DFS code (e.g. bcc two bytes too short and incorrect uid in PDU).
Version 0.37
------------
Rewrote much of connection and mount/unmount logic to handle bugs with
multiple uses to same share, multiple users to same server etc.
Version 0.36
------------
Fixed major problem with dentry corruption (missing call to dput)
Version 0.35
------------
Rewrite of readdir code to fix bug. Various fixes for bigendian machines.
Begin adding oplock support. Multiusermount and oplockEnabled flags added to /proc/fs/cifs
although corresponding function not fully implemented in the vfs yet
Version 0.34
------------
Fixed dentry caching bug, misc. cleanup
Version 0.33
------------
Fixed 2.5 support to handle build and configure changes as well as misc. 2.5 changes. Now can build
on current 2.5 beta version (2.5.24) of the Linux kernel as well as on 2.4 Linux kernels.
Support for STATUS codes (newer 32 bit NT error codes) added. DFS support begun to be added.
Version 0.32
------------
Unix extensions (symlink, readlink, hardlink, chmod and some chgrp and chown) implemented
and tested against Samba 2.2.5
Version 0.31
------------
1) Fixed lockrange to be correct (it was one byte too short)
2) Fixed GETLK (i.e. the fcntl call to test a range of bytes in a file to see if locked) to correctly
show range as locked when there is a conflict with an existing lock.
3) default file perms are now 2767 (indicating support for mandatory locks) instead of 777 for directories
in most cases. Eventually will offer optional ability to query server for the correct perms.
3) Fixed eventual trap when mounting twice to different shares on the same server when the first succeeded
but the second one was invalid and failed (the second one was incorrectly disconnecting the tcp and smb
session)
4) Fixed error logging of valid mount options
5) Removed logging of password field.
6) Moved negotiate, treeDisconnect and uloggoffX (only tConx and SessSetup remain in connect.c) to cifssmb.c
and cleaned them up and made them more consistent with other cifs functions.
7) Server support for Unix extensions is now fully detected and FindFirst is implemented both ways
(with or without Unix exentions) but FindNext and QueryPathInfo with the Unix extensions are not completed,
nor is the symlink support using the Unix extensions
8) Started adding the readlink and follow_link code
Version 0.3
-----------
Initial drop
#
# Makefile for Linux CIFS VFS client
#
obj-$(CONFIG_CIFS) += cifs.o
cifs-objs := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o md4.o md5.o cifs_unicode.o nterr.o
include $(TOPDIR)/Rules.make
This is the CIFS VFS support for Linux. It supports many advanced network filesystem
features such as heirarchical dfs like filesystem, hardlinks, locking and more.
It was designed to comply with the SNIA CIFS Technical Reference (which supersedes
the 1992 X/Open SMB Standard) as well as to perform best practice practical
interoperability with Windows 2000, Windows XP, Samba and equivalent
servers.
For questions or bug reports please contact sfrench@samba.org (sfrench@us.ibm.com)
Build instructions:
==================
extract the kernel from http://www.cifs.bkbits.net/linux-2.5 or
http://www.cifs.bkbits.net/linux-2.4
make menuconfig (or make xconfig)
select cifs from within the network filesystem choices
save and exit
make dep
make modules (or "make" if you did not select CIFS VFS to be built as a module)
Installation instructions:
=========================
If you have built the CIFS vfs as module (successfully)you
simply type "make modules_install" (or if you prefer manually copy the file to
the modules directory e.g. /lib/modules/2.4.10-4GB/kernel/fs/cifs/cifs.o).
If you have built the CIFS vfs into the kernel itself, follow the instructions
for your distribution on how to install a new kernel (usually you
would simply type "make install").
If you do not have the utility mount.cifs (in the Samba 3.0 source tree and on the
CIFS VFS web site) copy it to the directory /sbin (or the same directory in which
mount.smbfs resides). Although no helper software is required, the installation
of mount.cifs is recommended. Eventually the Samba 3.0 utility program "net"
may also be helpful since it may someday provide easier mount syntax for users used
to Windows e.g.
net use <mount point> <UNC name or cifs URL>
and there will likely be other helper programs available ala smbmount to provide
additional optional function in the future. Note that running Winbind on all
of your Linux clients is useful in mapping Uids and Gids consistently to the
proper network user.
Samba Considerations
====================
To get the maximum benefit from the CIFS VFS, we recommend using a server that
supports the SNIA CIFS Unix Extensions standard (e.g. Samba 2.2.5 or Samba 3.0)
but the CIFS vfs works fine with a wide variety of CIFS servers. Note that the
uid, gid and file permissions will display default values if you do not have
a server that supports the Unix extensions for CIFS (such as Samba 2.2.3 or
later). To enable the Unix CIFS Extensions in the Samba server, add the line:
unix extensions = yes
to your smb.conf file on the server. Note that the following smb.conf settings are
also useful (on the Samba server) when the majority of clients are Unix
or Linux:
case sensitive = yes
delete readonly = yes
Some administrators also change the "map archive" and the "create mask" parameters
from their defaults. For more information on these see the manual pages
("man smb.conf") on the Samba server system. Note that the cifs vfs, unlike the
smbfs vfs, does not read the smb.conf on the client system (the few optional settings
are passed in on mount via -o parameters instead).
Use instructions:
================
Once the CIFS VFS support is built into the kernel or installed as a module (cifs.o),
you can use mount syntax like the following to access Samba or Windows servers:
mount -t cifs //9.53.216.11/e$ /mnt -o user=myname,pass=mypassword
after -o the following cifs vfs specific options are supported:
user=<username>
pass=<password>
domain=<domain name>
TCP names (in addition to ip addresses) will be available when the mount helper
(mount.cifs) is complete
Restrictions
============
Servers must support the NTLM SMB dialect (which is the most recent, supported by Samba
and Windows NT, 2000 and XP and many other SMB/CIFS servers) and servers must support
either "pure-TCP" (port 445 TCP/IP CIFS connections) or RFC 1001/1002 support for
"Netbios-Over-TCP/IP." Neither of these is likely to be a problem as most servers
support this. IPv6 support is planned for the future.
Misc /proc/fs/cifs Flags and Debug Info
=======================================
Various experimental features and tracing can be enabled by changing flags in /proc/fs/cifs (after
the cifs module has been installed or built into the kernel, e.g. insmod cifs). To enable
a feature you can set it to 1 e.g. to enable tracing to the kernel message log you can do
"echo 1 > /proc/fs/cifs/cifsFYI" and "echo 1 > /proc/fs/cifs/traceSMB"
Also note that "cat /proc/fs/cifs/DebugData" will display some information about the currently
active sessions and the shares that are mounted. Currently the ntlmv2 enablement and packet
signing will not work since they the implementation is not quite complete, so do not enable
these flags unless you are doing specific testing. Enabling extended security works to
Windows 2000 Workstations and XP but not to Windows 2000 server or Samba since it does not
usually send "raw NTLMSSP" (instead it sends NTLMSSP encapsulated in SPNEGO/GSSAPI, which
support is not complete in the CIFS VFS yet).
version 0.5.3 October 8th, 2002
A Partial List of Known Problems and Missing Features
=====================================================
Contributions are welcome. There are plenty of opportunities
for visible, important contributions to this module. Here
is a partial list of the known problems and missing features:
a) Support for SecurityDescriptors for chmod/chgrp/chown
b) Better pam/winbind integration
c) multi-user mounts - multiplexed sessionsetups over single vc
(ie tcp session) - prettying up needed
d) Kerberos/SPNEGO session setup support - (started)
e)NTLMv2 authentication and MD5-HMAC signing of SMB PDUs - (mostly implemented)
f) oplock support (ie safe CIFS distributed file caching) is not complete.
In addition Directory entry caching relies on a 1 second timer, rather than
using FindNotify or equivalent. - (started)
g) There may be a few additional changes that could be done to take advantage
of recent 2.5 kernel improvements in byte-range locking
h) quota support
i) support for the Linux 2.5 kernel new feature get_xattr and set_xattr
j) finish off the mount helper, mount.cifs - (started)
k) support for memory mapped files only partially works until support for
MS_INVALIDATE implemented. readpage and writepage code not finished (started)
KNOWN BUGS (updated October 8nd, 2002)
====================================
1) symbolic links (Windows reparse points) are recognized but
can not be created remotely. They are implemented for Samba and those that
support the CIFS Unix extensions but Samba has a bug currently handling
symlink text beginning with slash
2) delete of file with read-only attribute set will fail (may be ok)
3) autoreconnection logic is only partially complete.
Misc testing to do
=================
1) check out max path names and max path name components against various server
types.
2) Run POSIX bencharks against cifs
3) Run dbench
4) Finish FSX testing on SMP now that we workaround the Samba bug
/*
* The ASB.1/BER parsing code is derived from ip_nat_snmp_basic.c which was in
* turn derived from the gxsnmp package by Gregory McLean & Jochen Friedrich
*
* Copyright (c) 2000 RP Internet (www.rpi.net.au).
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifs_debug.h"
/*****************************************************************************
*
* Basic ASN.1 decoding routines (gxsnmp author Dirk Wisse)
*
*****************************************************************************/
/* Class */
#define ASN1_UNI 0 /* Universal */
#define ASN1_APL 1 /* Application */
#define ASN1_CTX 2 /* Context */
#define ASN1_PRV 3 /* Private */
/* Tag */
#define ASN1_EOC 0 /* End Of Contents or N/A */
#define ASN1_BOL 1 /* Boolean */
#define ASN1_INT 2 /* Integer */
#define ASN1_BTS 3 /* Bit String */
#define ASN1_OTS 4 /* Octet String */
#define ASN1_NUL 5 /* Null */
#define ASN1_OJI 6 /* Object Identifier */
#define ASN1_OJD 7 /* Object Description */
#define ASN1_EXT 8 /* External */
#define ASN1_SEQ 16 /* Sequence */
#define ASN1_SET 17 /* Set */
#define ASN1_NUMSTR 18 /* Numerical String */
#define ASN1_PRNSTR 19 /* Printable String */
#define ASN1_TEXSTR 20 /* Teletext String */
#define ASN1_VIDSTR 21 /* Video String */
#define ASN1_IA5STR 22 /* IA5 String */
#define ASN1_UNITIM 23 /* Universal Time */
#define ASN1_GENTIM 24 /* General Time */
#define ASN1_GRASTR 25 /* Graphical String */
#define ASN1_VISSTR 26 /* Visible String */
#define ASN1_GENSTR 27 /* General String */
/* Primitive / Constructed methods*/
#define ASN1_PRI 0 /* Primitive */
#define ASN1_CON 1 /* Constructed */
/*
* Error codes.
*/
#define ASN1_ERR_NOERROR 0
#define ASN1_ERR_DEC_EMPTY 2
#define ASN1_ERR_DEC_EOC_MISMATCH 3
#define ASN1_ERR_DEC_LENGTH_MISMATCH 4
#define ASN1_ERR_DEC_BADVALUE 5
#define SPNEGO_OID_LEN 7
#define NTLMSSP_OID_LEN 10
unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 };
unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 };
/*
* ASN.1 context.
*/
struct asn1_ctx {
int error; /* Error condition */
unsigned char *pointer; /* Octet just to be decoded */
unsigned char *begin; /* First octet */
unsigned char *end; /* Octet after last octet */
};
/*
* Octet string (not null terminated)
*/
struct asn1_octstr {
unsigned char *data;
unsigned int len;
};
static void
asn1_open(struct asn1_ctx *ctx, unsigned char *buf, unsigned int len)
{
ctx->begin = buf;
ctx->end = buf + len;
ctx->pointer = buf;
ctx->error = ASN1_ERR_NOERROR;
}
static unsigned char
asn1_octet_decode(struct asn1_ctx *ctx, unsigned char *ch)
{
if (ctx->pointer >= ctx->end) {
ctx->error = ASN1_ERR_DEC_EMPTY;
return 0;
}
*ch = *(ctx->pointer)++;
return 1;
}
static unsigned char
asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
{
unsigned char ch;
*tag = 0;
do {
if (!asn1_octet_decode(ctx, &ch))
return 0;
*tag <<= 7;
*tag |= ch & 0x7F;
} while ((ch & 0x80) == 0x80);
return 1;
}
static unsigned char
asn1_id_decode(struct asn1_ctx *ctx,
unsigned int *cls, unsigned int *con, unsigned int *tag)
{
unsigned char ch;
if (!asn1_octet_decode(ctx, &ch))
return 0;
*cls = (ch & 0xC0) >> 6;
*con = (ch & 0x20) >> 5;
*tag = (ch & 0x1F);
if (*tag == 0x1F) {
if (!asn1_tag_decode(ctx, tag))
return 0;
}
return 1;
}
static unsigned char
asn1_length_decode(struct asn1_ctx *ctx, unsigned int *def, unsigned int *len)
{
unsigned char ch, cnt;
if (!asn1_octet_decode(ctx, &ch))
return 0;
if (ch == 0x80)
*def = 0;
else {
*def = 1;
if (ch < 0x80)
*len = ch;
else {
cnt = (unsigned char) (ch & 0x7F);
*len = 0;
while (cnt > 0) {
if (!asn1_octet_decode(ctx, &ch))
return 0;
*len <<= 8;
*len |= ch;
cnt--;
}
}
}
return 1;
}
static unsigned char
asn1_header_decode(struct asn1_ctx *ctx,
unsigned char **eoc,
unsigned int *cls, unsigned int *con, unsigned int *tag)
{
unsigned int def, len;
if (!asn1_id_decode(ctx, cls, con, tag))
return 0;
if (!asn1_length_decode(ctx, &def, &len))
return 0;
if (def)
*eoc = ctx->pointer + len;
else
*eoc = 0;
return 1;
}
static unsigned char
asn1_eoc_decode(struct asn1_ctx *ctx, unsigned char *eoc)
{
unsigned char ch;
if (eoc == 0) {
if (!asn1_octet_decode(ctx, &ch))
return 0;
if (ch != 0x00) {
ctx->error = ASN1_ERR_DEC_EOC_MISMATCH;
return 0;
}
if (!asn1_octet_decode(ctx, &ch))
return 0;
if (ch != 0x00) {
ctx->error = ASN1_ERR_DEC_EOC_MISMATCH;
return 0;
}
return 1;
} else {
if (ctx->pointer != eoc) {
ctx->error = ASN1_ERR_DEC_LENGTH_MISMATCH;
return 0;
}
return 1;
}
}
/* static unsigned char asn1_null_decode(struct asn1_ctx *ctx,
unsigned char *eoc)
{
ctx->pointer = eoc;
return 1;
}
static unsigned char asn1_long_decode(struct asn1_ctx *ctx,
unsigned char *eoc, long *integer)
{
unsigned char ch;
unsigned int len;
if (!asn1_octet_decode(ctx, &ch))
return 0;
*integer = (signed char) ch;
len = 1;
while (ctx->pointer < eoc) {
if (++len > sizeof(long)) {
ctx->error = ASN1_ERR_DEC_BADVALUE;
return 0;
}
if (!asn1_octet_decode(ctx, &ch))
return 0;
*integer <<= 8;
*integer |= ch;
}
return 1;
}
static unsigned char asn1_uint_decode(struct asn1_ctx *ctx,
unsigned char *eoc,
unsigned int *integer)
{
unsigned char ch;
unsigned int len;
if (!asn1_octet_decode(ctx, &ch))
return 0;
*integer = ch;
if (ch == 0)
len = 0;
else
len = 1;
while (ctx->pointer < eoc) {
if (++len > sizeof(unsigned int)) {
ctx->error = ASN1_ERR_DEC_BADVALUE;
return 0;
}
if (!asn1_octet_decode(ctx, &ch))
return 0;
*integer <<= 8;
*integer |= ch;
}
return 1;
}
static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
unsigned char *eoc,
unsigned long *integer)
{
unsigned char ch;
unsigned int len;
if (!asn1_octet_decode(ctx, &ch))
return 0;
*integer = ch;
if (ch == 0)
len = 0;
else
len = 1;
while (ctx->pointer < eoc) {
if (++len > sizeof(unsigned long)) {
ctx->error = ASN1_ERR_DEC_BADVALUE;
return 0;
}
if (!asn1_octet_decode(ctx, &ch))
return 0;
*integer <<= 8;
*integer |= ch;
}
return 1;
}
static unsigned char
asn1_octets_decode(struct asn1_ctx *ctx,
unsigned char *eoc,
unsigned char **octets, unsigned int *len)
{
unsigned char *ptr;
*len = 0;
*octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
if (*octets == NULL) {
return 0;
}
ptr = *octets;
while (ctx->pointer < eoc) {
if (!asn1_octet_decode(ctx, (unsigned char *) ptr++)) {
kfree(*octets);
*octets = NULL;
return 0;
}
(*len)++;
}
return 1;
} */
static unsigned char
asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
{
unsigned char ch;
*subid = 0;
do {
if (!asn1_octet_decode(ctx, &ch))
return 0;
*subid <<= 7;
*subid |= ch & 0x7F;
} while ((ch & 0x80) == 0x80);
return 1;
}
static unsigned char
asn1_oid_decode(struct asn1_ctx *ctx,
unsigned char *eoc, unsigned long **oid, unsigned int *len)
{
unsigned long subid;
unsigned int size;
unsigned long *optr;
size = eoc - ctx->pointer + 1;
*oid = kmalloc(size * sizeof (unsigned long), GFP_ATOMIC);
if (*oid == NULL) {
return 0;
}
optr = *oid;
if (!asn1_subid_decode(ctx, &subid)) {
kfree(*oid);
*oid = NULL;
return 0;
}
if (subid < 40) {
optr[0] = 0;
optr[1] = subid;
} else if (subid < 80) {
optr[0] = 1;
optr[1] = subid - 40;
} else {
optr[0] = 2;
optr[1] = subid - 80;
}
*len = 2;
optr += 2;
while (ctx->pointer < eoc) {
if (++(*len) > size) {
ctx->error = ASN1_ERR_DEC_BADVALUE;
kfree(*oid);
*oid = NULL;
return 0;
}
if (!asn1_subid_decode(ctx, optr++)) {
kfree(*oid);
*oid = NULL;
return 0;
}
}
return 1;
}
static int
compare_oid(unsigned long *oid1, unsigned int oid1len,
unsigned long *oid2, unsigned int oid2len)
{
int i;
if (oid1len != oid2len)
return 0;
else {
for (i = 0; i < oid1len; i++) {
if (oid1[i] != oid2[i])
return 0;
}
return 1;
}
}
/* BB check for endian conversion issues here */
int
decode_negTokenInit(unsigned char *security_blob, int length,
enum securityEnum *secType)
{
struct asn1_ctx ctx;
unsigned char *end;
unsigned char *sequence_end;
unsigned long *oid;
unsigned int cls, con, tag, oidlen, rc;
int use_ntlmssp = FALSE;
dump_mem(" Received SecBlob ", security_blob, length);
asn1_open(&ctx, security_blob, length);
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1, ("\nError decoding negTokenInit header "));
return 0;
} else if ((cls != ASN1_APL) || (con != ASN1_CON)
|| (tag != ASN1_EOC)) {
cFYI(1, ("\ncls = %d con = %d tag = %d", cls, con, tag));
return 0;
} else {
/* remember to free obj->oid */
rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
if (rc) {
if ((tag == ASN1_OJI) && (cls == ASN1_PRI)) {
rc = asn1_oid_decode(&ctx, end, &oid, &oidlen);
if (rc) {
rc = compare_oid(oid, oidlen,
SPNEGO_OID,
SPNEGO_OID_LEN);
kfree(oid);
}
} else
rc = 0;
}
if (!rc) {
cFYI(1, ("\nError decoding negTokenInit header"));
return 0;
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1, ("\nError decoding negTokenInit "));
return 0;
} else if ((cls != ASN1_CTX) || (con != ASN1_CON)
|| (tag != ASN1_EOC)) {
cFYI(1,
("\ncls = %d con = %d tag = %d end = %p (%d) exit 0",
cls, con, tag, end, *end));
return 0;
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1, ("\nError decoding negTokenInit "));
return 0;
} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
|| (tag != ASN1_SEQ)) {
cFYI(1,
("\ncls = %d con = %d tag = %d end = %p (%d) exit 1",
cls, con, tag, end, *end));
return 0;
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1, ("\nError decoding 2nd part of negTokenInit "));
return 0;
} else if ((cls != ASN1_CTX) || (con != ASN1_CON)
|| (tag != ASN1_EOC)) {
cFYI(1,
("\ncls = %d con = %d tag = %d end = %p (%d) exit 0",
cls, con, tag, end, *end));
return 0;
}
if (asn1_header_decode
(&ctx, &sequence_end, &cls, &con, &tag) == 0) {
cFYI(1, ("\nError decoding 2nd part of negTokenInit "));
return 0;
} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
|| (tag != ASN1_SEQ)) {
cFYI(1,
("\ncls = %d con = %d tag = %d end = %p (%d) exit 1",
cls, con, tag, end, *end));
return 0;
}
while (!asn1_eoc_decode(&ctx, sequence_end)) {
rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
if (!rc) {
cFYI(1,
("\nError 1 decoding negTokenInit header exit 2"));
return 0;
}
if ((tag == ASN1_OJI) && (con == ASN1_PRI)) {
asn1_oid_decode(&ctx, end, &oid, &oidlen);
cFYI(1,
("\nOID len = %d oid = 0x%lx 0x%lx 0x%lx 0x%lx",
oidlen, *oid, *(oid + 1), *(oid + 2),
*(oid + 3)));
rc = compare_oid(oid, oidlen, NTLMSSP_OID,
NTLMSSP_OID_LEN);
kfree(oid);
if (rc)
use_ntlmssp = TRUE;
} else {
cFYI(1,
("\nThis should be an oid what is going on? "));
}
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1,
("\nError decoding last part of negTokenInit exit 3"));
return 0;
} else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { /* tag = 3 indicating mechListMIC */
cFYI(1,
("\nExit 4 cls = %d con = %d tag = %d end = %p (%d)",
cls, con, tag, end, *end));
return 0;
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1,
("\nError decoding last part of negTokenInit exit 5"));
return 0;
} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
|| (tag != ASN1_SEQ)) {
cFYI(1,
("\nExit 6 cls = %d con = %d tag = %d end = %p (%d)",
cls, con, tag, end, *end));
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1,
("\nError decoding last part of negTokenInit exit 7"));
return 0;
} else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
cFYI(1,
("\nExit 8 cls = %d con = %d tag = %d end = %p (%d)",
cls, con, tag, end, *end));
return 0;
}
if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
cFYI(1,
("\nError decoding last part of negTokenInit exit 9"));
return 0;
} else if ((cls != ASN1_UNI) || (con != ASN1_PRI)
|| (tag != ASN1_GENSTR)) {
cFYI(1,
("\nExit 10 cls = %d con = %d tag = %d end = %p (%d)",
cls, con, tag, end, *end));
return 0;
}
cFYI(1, ("\nNeed to call asn1_octets_decode() function for this %s", ctx.pointer)); /* is this UTF-8 or ASCII? */
}
/* if (use_kerberos)
*secType = Kerberos
else */
if (use_ntlmssp) {
*secType = NTLMSSP;
}
return 1;
}
/*
* fs/cifs_debug.c
*
* Copyright (c) International Business Machines Corp., 2000,2002
*
* Modified by Steve French (sfrench@us.ibm.com)
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/ctype.h>
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
void
dump_mem(char *label, void *data, int length)
{
int i, j;
int *intptr = data;
char *charptr = data;
char buf[10], line[80];
printk("%s: dump of %d bytes of data at 0x%p\n\n", label, length, data);
for (i = 0; i < length; i += 16) {
line[0] = 0;
for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
sprintf(buf, " %08x", intptr[i / 4 + j]);
strcat(line, buf);
}
buf[0] = ' ';
buf[2] = 0;
for (j = 0; (j < 16) && (i + j < length); j++) {
buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
strcat(line, buf);
}
printk("%s\n", line);
}
}
#if CONFIG_PROC_FS
int
cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
int count, int *eof, void *data)
{
struct list_head *tmp;
struct cifsSesInfo *ses;
struct cifsTconInfo *tcon;
int i;
int length = 0;
char *buf_start = buf;
printk("\n\nEntering cifs_debug_data_read: buf=0x%p, beginBuffer=0x%p, offset=%ld, count=%d, eof=%d, data=0x%p\n", buf, *beginBuffer, offset, count, *eof, data); /* BB remove */
length =
sprintf(buf,
"Display Internal CIFS Data Structures for Debugging\n"
"---------------------------------------------------\n");
buf += length;
length = sprintf(buf, "Servers: \n");
buf += length;
i = 0;
list_for_each(tmp, &GlobalSMBSessionList) {
i++;
ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
length =
sprintf(buf,
"\n%d) Name: %s Domain: %s HowManyMounts: %d LocalUsersToSameServer: %d\n\t ServerOS: %s ServerNOS: %s Capabilities: 0x%x ",
i, ses->serverName, ses->serverDomain,
atomic_read(&ses->inUse),
atomic_read(&ses->server->socketUseCount),
ses->serverOS, ses->serverNOS, ses->capabilities);
buf += length;
}
sprintf(buf, "\n");
buf++;
printk("\nTotal Buffer so far: %s\n", buf_start);
length = sprintf(buf, "\nShares: \n");
buf += length;
i = 0;
list_for_each(tmp, &GlobalTreeConnectionList) {
i++;
tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
length =
sprintf(buf,
"\n%d) %s UseCount: %d on FS: %s with characteristics: 0x%x Attributes: 0x%x and PathComponentLengthMax: %d",
i, tcon->treeName,
atomic_read(&tcon->useCount),
tcon->nativeFileSystem,
tcon->fsDevInfo.DeviceCharacteristics,
tcon->fsAttrInfo.Attributes,
tcon->fsAttrInfo.MaxPathNameComponentLength);
buf += length;
if (tcon->fsDevInfo.DeviceType == FILE_DEVICE_DISK)
length = sprintf(buf, " type: DISK ");
else if (tcon->fsDevInfo.DeviceType == FILE_DEVICE_CD_ROM)
length = sprintf(buf, " type: CDROM ");
else
length =
sprintf(buf, " type: %d ",
tcon->fsDevInfo.DeviceType);
buf += length;
}
length = sprintf(buf, "\n");
buf += length;
*eof = 1;
/* BB add code to dump additional info such as TCP session info now */
/*
if (offset >= (buf - buf_start))
{
*beginBuffer = buf;
return 0;
}
*beginBuffer = buf + offset;
if ((buf - buf_start - offset) > count)
return count;
else */
return (buf - buf_start - offset);
}
int
cifs_total_xid_read(char *buf, char **beginBuffer, off_t offset,
int length, int *eof, void *data)
{
length =
sprintf(buf,
"Total vfs operations: %d and maximum simultaneous serviced by this filesystem: %d\n",
GlobalCurrentXid,GlobalMaxActiveXid);
return length;
}
int
cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
int length, int *eof, void *data)
{
int item_length;
length =
sprintf(buf,
"Currently Allocated structures\nCIFS Sessions: %d\n",sesInfoAllocCount.counter);
buf += length;
item_length =
sprintf(buf,"Shares (unique mount targets): %d\n",tconInfoAllocCount.counter);
length += item_length;
buf += item_length;
item_length =
sprintf(buf,"Allocated SMB Request and Response Buffers: %d\n",bufAllocCount.counter);
length += item_length;
buf += item_length;
item_length =
sprintf(buf,"Active Operations (MIDs in use): %d\n",midCount.counter);
length += item_length;
return length;
}
struct proc_dir_entry *proc_fs_cifs;
read_proc_t cifs_txanchor_read;
static read_proc_t cifsFYI_read;
static write_proc_t cifsFYI_write;
static read_proc_t oplockEnabled_read;
static write_proc_t oplockEnabled_write;
static read_proc_t traceSMB_read;
static write_proc_t traceSMB_write;
static read_proc_t multiuser_mount_read;
static write_proc_t multiuser_mount_write;
static read_proc_t extended_security_read;
static write_proc_t extended_security_write;
static read_proc_t ntlmv2_enabled_read;
static write_proc_t ntlmv2_enabled_write;
static read_proc_t packet_signing_enabled_read;
static write_proc_t packet_signing_enabled_write;
void
cifs_proc_init(void)
{
struct proc_dir_entry *pde;
proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
if (proc_fs_cifs == NULL)
return;
proc_fs_cifs->owner = THIS_MODULE;
create_proc_read_entry("DebugData", 0, proc_fs_cifs,
cifs_debug_data_read, 0);
create_proc_read_entry("SimultaneousOps", 0, proc_fs_cifs,
cifs_total_xid_read, 0);
create_proc_read_entry("Stats", 0, proc_fs_cifs,
cifs_stats_read, 0);
pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
cifsFYI_read, 0);
if (pde)
pde->write_proc = cifsFYI_write;
pde =
create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
traceSMB_read, 0);
if (pde)
pde->write_proc = traceSMB_write;
pde = create_proc_read_entry("oplockEnabled", 0, proc_fs_cifs,
oplockEnabled_read, 0);
if (pde)
pde->write_proc = oplockEnabled_write;
pde =
create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
multiuser_mount_read, 0);
if (pde)
pde->write_proc = multiuser_mount_write;
pde =
create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
extended_security_read, 0);
if (pde)
pde->write_proc = extended_security_write;
pde =
create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
ntlmv2_enabled_read, 0);
if (pde)
pde->write_proc = ntlmv2_enabled_write;
pde =
create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
packet_signing_enabled_read, 0);
if (pde)
pde->write_proc = packet_signing_enabled_write;
}
void
cifs_proc_clean(void)
{
if (proc_fs_cifs == NULL)
return;
remove_proc_entry("DebugData", proc_fs_cifs);
remove_proc_entry("cifsFYI", proc_fs_cifs);
remove_proc_entry("TraceSMB", proc_fs_cifs);
remove_proc_entry("MaxSimultaneousOps", proc_fs_cifs);
remove_proc_entry("TotalOps", proc_fs_cifs);
remove_proc_entry("MultiuserMount", proc_fs_cifs);
remove_proc_entry("oplockEnabled", proc_fs_cifs);
remove_proc_entry("cifs", proc_root_fs);
}
static int
cifsFYI_read(char *page, char **start, off_t off, int count,
int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", cifsFYI);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
cifsFYI_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
cifsFYI = 0;
else if (c == '1' || c == 'y' || c == 'Y')
cifsFYI = 1;
return count;
}
static int
oplockEnabled_read(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", oplockEnabled);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
oplockEnabled_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
oplockEnabled = 0;
else if (c == '1' || c == 'y' || c == 'Y')
oplockEnabled = 1;
return count;
}
static int
traceSMB_read(char *page, char **start, off_t off, int count,
int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", traceSMB);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
traceSMB_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
traceSMB = 0;
else if (c == '1' || c == 'y' || c == 'Y')
traceSMB = 1;
return count;
}
static int
multiuser_mount_read(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", multiuser_mount);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
multiuser_mount_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
multiuser_mount = 0;
else if (c == '1' || c == 'y' || c == 'Y')
multiuser_mount = 1;
return count;
}
static int
extended_security_read(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", extended_security);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
extended_security_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
extended_security = 0;
else if (c == '1' || c == 'y' || c == 'Y')
extended_security = 1;
return count;
}
static int
ntlmv2_enabled_read(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", ntlmv2_support);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
ntlmv2_enabled_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
ntlmv2_support = 0;
else if (c == '1' || c == 'y' || c == 'Y')
ntlmv2_support = 1;
return count;
}
static int
packet_signing_enabled_read(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len;
len = sprintf(page, "%d\n", sign_CIFS_PDUs);
len -= off;
*start = page + off;
if (len > count)
len = count;
else
*eof = 1;
if (len < 0)
len = 0;
return len;
}
static int
packet_signing_enabled_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
char c;
int rc;
rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
sign_CIFS_PDUs = 0;
else if (c == '1' || c == 'y' || c == 'Y')
sign_CIFS_PDUs = 1;
return count;
}
#endif
/*
*
* Copyright (c) International Business Machines Corp., 2000,2002
* Modified by Steve French (sfrench@us.ibm.com)
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#define CIFS_DEBUG /* BB temporary */
#ifndef _H_CIFS_DEBUG
#define _H_CIFS_DEBUG
void dump_mem(char *label, void *data, int length);
extern int traceSMB; /* flag which enables the function below */
void dump_smb(struct smb_hdr *, int);
/*
* debug ON
* --------
*/
#ifdef CIFS_DEBUG
/* information message: e.g., configuration, major event */
extern int cifsFYI;
#define cFYI(button,prspec)\
{ if (button && cifsFYI) printk prspec; }
/* debug event message: */
#define cEVENT(button,prspec)\
{ if (button) printk prspec; }
/* error event message: e.g., i/o error */
extern int cifsERROR;
#define cERROR(button, prspec)\
{ if (button && cifsERROR) { printk prspec; if (button > 1) BUG(); } }
/*
* debug OFF
* ---------
*/
#else /* _CIFS_DEBUG */
#define cERROR(button,prspec)
#define cEVENT(button,prspec)
#define cFYI(button, prspec)
#endif /* _CIFS_DEBUG */
/*
* statistics
* ----------
*/
#ifdef _CIFS_STATISTICS
#define INCREMENT(x) ((x)++)
#define DECREMENT(x) ((x)--)
#define HIGHWATERMARK(x,y) x = MAX((x), (y))
#else
#define INCREMENT(x)
#define DECREMENT(x)
#define HIGHWATERMARK(x,y)
#endif /* _CIFS_STATISTICS */
#endif /* _H_CIFS_DEBUG */
/*
* fs/cifs/cifs_fs_sb.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
*/
#ifndef _CIFS_FS_SB_H
#define _CIFS_FS_SB_H
struct cifs_sb_info {
struct cifsTconInfo *tcon; /* primary mount */
/* list of implicit mounts beneath this mount point - needed in dfs case */
struct list_head nested_tcon_q;
struct nls_table *local_nls;
};
#endif /* _CIFS_FS_SB_H */
/*
* fs/cifs/cifs_unicode.c
*
* Copyright (c) International Business Machines Corp., 2000,2002
* Modified by Steve French (sfrench@us.ibm.com)
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include "cifs_unicode.h"
#include "cifs_uniupr.h"
#include "cifspdu.h"
#include "cifs_debug.h"
/*
* NAME: toUpper()
*
* FUNCTION: Upper case ASCII string (in place) using the current codepage
*
*/
void
toUpper(const struct nls_table *n, char *mixed_string)
{
int i;
char temp;
for (i = 0; i < strlen(mixed_string); i++) {
temp = mixed_string[i];
mixed_string[i] = n->charset2upper[(int) temp];
}
}
/*
* NAME: cifs_strfromUCS()
*
* FUNCTION: Convert little-endian unicode string to character string
*
*/
int
cifs_strfromUCS_le(char *to, const wchar_t * from, /* LITTLE ENDIAN */
int len, const struct nls_table *codepage)
{
int i;
int outlen = 0;
for (i = 0; (i < len) && from[i]; i++) {
int charlen;
/* 2.4.0 kernel or greater */
charlen =
codepage->uni2char(le16_to_cpu(from[i]), &to[outlen],
NLS_MAX_CHARSET_SIZE);
if (charlen > 0) {
outlen += charlen;
} else {
to[outlen++] = '?';
}
}
to[outlen] = 0;
cEVENT(0, ("cifs_strfromUCS returning %d - '%s'\n", outlen, to));
return outlen;
}
/*
* NAME: cifs_strtoUCS()
*
* FUNCTION: Convert character string to unicode string
*
*/
int
cifs_strtoUCS(wchar_t * to, const char *from, int len,
const struct nls_table *codepage)
{
int charlen;
int i;
cEVENT(0, ("cifs_strtoUCS - '%s'\n", from));
for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
/* works for 2.4.0 kernel or later */
charlen = codepage->char2uni(from, len, &to[i]);
if (charlen < 1) {
cERROR(1,
("cifs_strtoUCS: char2uni returned %d.\n",
charlen));
to[i] = cpu_to_le16(0x003f); /* a question mark */
charlen = 1;
}
to[i] = cpu_to_le16(to[i]);
}
cEVENT(0, (" returning %d\n", i));
to[i] = 0;
return i;
}
/*
* NAME: get_UCSname2()
*
* FUNCTION: Allocate and translate to unicode string
*
*/
/*int
get_UCSname2(struct component_name *uniName, struct dentry *dentry,
struct nls_table *nls_tab)
{
int length = dentry->d_name.len;
if (length > 255)
return ENAMETOOLONG;
uniName->name = kmalloc((length + 1) * sizeof (wchar_t), GFP_KERNEL);
if (uniName->name == NULL)
return ENOSPC;
uniName->namlen = cifs_strtoUCS(uniName->name, dentry->d_name.name,
length, nls_tab);
return 0;
} */
/*
* cifs_unicode: Unicode kernel case support
*
* Function:
* Convert a unicode character to upper or lower case using
* compressed tables.
*
* Copyright (c) International Business Machines Corp., 2000,2002
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* Notes:
* These APIs are based on the C library functions. The semantics
* should match the C functions but with expanded size operands.
*
* The upper/lower functions are based on a table created by mkupr.
* This is a compressed table of upper and lower case conversion.
*
*/
#include <asm/byteorder.h>
#include <linux/types.h>
#include <linux/nls.h>
#define UNIUPR_NOLOWER /* Example to not expand lower case tables */
/* Just define what we want from uniupr.h. We don't want to define the tables
* in each source file.
*/
#ifndef UNICASERANGE_DEFINED
struct UniCaseRange {
wchar_t start;
wchar_t end;
signed char *table;
};
#endif /* UNICASERANGE_DEFINED */
#ifndef UNIUPR_NOUPPER
extern signed char CifsUniUpperTable[512];
extern const struct UniCaseRange CifsUniUpperRange[];
#endif /* UNIUPR_NOUPPER */
#ifndef UNIUPR_NOLOWER
extern signed char UniLowerTable[512];
extern struct UniCaseRange UniLowerRange[];
#endif /* UNIUPR_NOLOWER */
/*
* directory entry argument
*/
struct component_name {
int namlen;
wchar_t *name;
};
#ifdef __KERNEL__
int cifs_strfromUCS_le(char *, const wchar_t *, int, const struct nls_table *);
int cifs_strtoUCS(wchar_t *, const char *, int, const struct nls_table *);
int cifs_UCSname(struct component_name *, struct dentry *,
const struct nls_table *);
void toUpper(const struct nls_table *, char *);
#endif
#define free_UCSname(COMP) kfree((COMP)->name)
/*
* UniStrcat: Concatenate the second string to the first
*
* Returns:
* Address of the first string
*/
static inline wchar_t *
UniStrcat(wchar_t * ucs1, const wchar_t * ucs2)
{
wchar_t *anchor = ucs1; /* save a pointer to start of ucs1 */
while (*ucs1++) ; /* To end of first string */
ucs1--; /* Return to the null */
while ((*ucs1++ = *ucs2++)) ; /* copy string 2 over */
return anchor;
}
/*
* UniStrchr: Find a character in a string
*
* Returns:
* Address of first occurance of character in string
* or NULL if the character is not in the string
*/
static inline wchar_t *
UniStrchr(const wchar_t * ucs, wchar_t uc)
{
while ((*ucs != uc) && *ucs)
ucs++;
if (*ucs == uc)
return (wchar_t *) ucs;
return NULL;
}
/*
* UniStrcmp: Compare two strings
*
* Returns:
* < 0: First string is less than second
* = 0: Strings are equal
* > 0: First string is greater than second
*/
static inline int
UniStrcmp(const wchar_t * ucs1, const wchar_t * ucs2)
{
while ((*ucs1 == *ucs2) && *ucs1) {
ucs1++;
ucs2++;
}
return (int) *ucs1 - (int) *ucs2;
}
/*
* UniStrcpy: Copy a string
*/
static inline wchar_t *
UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
{
wchar_t *anchor = ucs1; /* save the start of result string */
while ((*ucs1++ = *ucs2++)) ;
return anchor;
}
/*
* UniStrlen: Return the length of a string (in 16 bit Unicode chars not bytes)
*/
static inline size_t
UniStrlen(const wchar_t * ucs1)
{
int i = 0;
while (*ucs1++)
i++;
return i;
}
/*
* UniStrnlen: Return the length (in 16 bit Unicode chars not bytes) of a string (length limited)
*/
static inline size_t
UniStrnlen(const wchar_t * ucs1, int maxlen)
{
int i = 0;
while (*ucs1++) {
i++;
if (i >= maxlen)
break;
}
return i;
}
/*
* UniStrncat: Concatenate length limited string
*/
static inline wchar_t *
UniStrncat(wchar_t * ucs1, const wchar_t * ucs2, size_t n)
{
wchar_t *anchor = ucs1; /* save pointer to string 1 */
while (*ucs1++) ;
ucs1--; /* point to null terminator of s1 */
while (n-- && (*ucs1 = *ucs2)) { /* copy s2 after s1 */
ucs1++;
ucs2++;
}
*ucs1 = 0; /* Null terminate the result */
return (anchor);
}
/*
* UniStrncmp: Compare length limited string
*/
static inline int
UniStrncmp(const wchar_t * ucs1, const wchar_t * ucs2, size_t n)
{
if (!n)
return 0; /* Null strings are equal */
while ((*ucs1 == *ucs2) && *ucs1 && --n) {
ucs1++;
ucs2++;
}
return (int) *ucs1 - (int) *ucs2;
}
/*
* UniStrncmp_le: Compare length limited string - native to little-endian
*/
static inline int
UniStrncmp_le(const wchar_t * ucs1, const wchar_t * ucs2, size_t n)
{
if (!n)
return 0; /* Null strings are equal */
while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
ucs1++;
ucs2++;
}
return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
}
/*
* UniStrncpy: Copy length limited string with pad
*/
static inline wchar_t *
UniStrncpy(wchar_t * ucs1, const wchar_t * ucs2, size_t n)
{
wchar_t *anchor = ucs1;
while (n-- && *ucs2) /* Copy the strings */
*ucs1++ = *ucs2++;
n++;
while (n--) /* Pad with nulls */
*ucs1++ = 0;
return anchor;
}
/*
* UniStrncpy_le: Copy length limited string with pad to little-endian
*/
static inline wchar_t *
UniStrncpy_le(wchar_t * ucs1, const wchar_t * ucs2, size_t n)
{
wchar_t *anchor = ucs1;
while (n-- && *ucs2) /* Copy the strings */
*ucs1++ = __le16_to_cpu(*ucs2++);
n++;
while (n--) /* Pad with nulls */
*ucs1++ = 0;
return anchor;
}
/*
* UniStrstr: Find a string in a string
*
* Returns:
* Address of first match found
* NULL if no matching string is found
*/
static inline wchar_t *
UniStrstr(const wchar_t * ucs1, const wchar_t * ucs2)
{
const wchar_t *anchor1 = ucs1;
const wchar_t *anchor2 = ucs2;
while (*ucs1) {
if (*ucs1 == *ucs2) { /* Partial match found */
ucs1++;
ucs2++;
} else {
if (!*ucs2) /* Match found */
return (wchar_t *) anchor1;
ucs1 = ++anchor1; /* No match */
ucs2 = anchor2;
}
}
if (!*ucs2) /* Both end together */
return (wchar_t *) anchor1; /* Match found */
return NULL; /* No match */
}
#ifndef UNIUPR_NOUPPER
/*
* UniToupper: Convert a unicode character to upper case
*/
static inline wchar_t
UniToupper(register wchar_t uc)
{
register const struct UniCaseRange *rp;
if (uc < sizeof (CifsUniUpperTable)) { /* Latin characters */
return uc + CifsUniUpperTable[uc]; /* Use base tables */
} else {
rp = CifsUniUpperRange; /* Use range tables */
while (rp->start) {
if (uc < rp->start) /* Before start of range */
return uc; /* Uppercase = input */
if (uc <= rp->end) /* In range */
return uc + rp->table[uc - rp->start];
rp++; /* Try next range */
}
}
return uc; /* Past last range */
}
/*
* UniStrupr: Upper case a unicode string
*/
static inline wchar_t *
UniStrupr(register wchar_t * upin)
{
register wchar_t *up;
up = upin;
while (*up) { /* For all characters */
*up = UniToupper(*up);
up++;
}
return upin; /* Return input pointer */
}
#endif /* UNIUPR_NOUPPER */
#ifndef UNIUPR_NOLOWER
/*
* UniTolower: Convert a unicode character to lower case
*/
static inline wchar_t
UniTolower(wchar_t uc)
{
register struct UniCaseRange *rp;
if (uc < sizeof (UniLowerTable)) { /* Latin characters */
return uc + UniLowerTable[uc]; /* Use base tables */
} else {
rp = UniLowerRange; /* Use range tables */
while (rp->start) {
if (uc < rp->start) /* Before start of range */
return uc; /* Uppercase = input */
if (uc <= rp->end) /* In range */
return uc + rp->table[uc - rp->start];
rp++; /* Try next range */
}
}
return uc; /* Past last range */
}
/*
* UniStrlwr: Lower case a unicode string
*/
static inline wchar_t *
UniStrlwr(register wchar_t * upin)
{
register wchar_t *up;
up = upin;
while (*up) { /* For all characters */
*up = UniTolower(*up);
up++;
}
return upin; /* Return input pointer */
}
#endif
/*
* Copyright (c) International Business Machines Corp., 2000,2002
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* uniupr.h - Unicode compressed case ranges
*
*/
#ifndef UNIUPR_NOUPPER
/*
* Latin upper case
*/
signed char CifsUniUpperTable[512] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 000-00f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 010-01f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 020-02f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 030-03f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 040-04f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 050-05f */
0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, /* 060-06f */
-32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 0, 0, 0, 0, 0, /* 070-07f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 080-08f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 090-09f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0a0-0af */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0b0-0bf */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0c0-0cf */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0d0-0df */
-32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, /* 0e0-0ef */
-32, -32, -32, -32, -32, -32, -32, 0, -32, -32, -32, -32, -32, -32, -32, 121, /* 0f0-0ff */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 100-10f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 110-11f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 120-12f */
0, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, /* 130-13f */
-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, /* 140-14f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 150-15f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 160-16f */
0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, /* 170-17f */
0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, /* 180-18f */
0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, /* 190-19f */
0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, /* 1a0-1af */
-1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, /* 1b0-1bf */
0, 0, 0, 0, 0, -1, -2, 0, -1, -2, 0, -1, -2, 0, -1, 0, /* 1c0-1cf */
-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -79, 0, -1, /* 1d0-1df */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e0-1ef */
0, 0, -1, -2, 0, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1, /* 1f0-1ff */
};
/* Upper case range - Greek */
static signed char UniCaseRangeU03a0[47] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -38, -37, -37, -37, /* 3a0-3af */
0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, /* 3b0-3bf */
-32, -32, -31, -32, -32, -32, -32, -32, -32, -32, -32, -32, -64,
-63, -63,
};
/* Upper case range - Cyrillic */
static signed char UniCaseRangeU0430[48] = {
-32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, /* 430-43f */
-32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, /* 440-44f */
0, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, 0, -80, -80, /* 450-45f */
};
/* Upper case range - Extended cyrillic */
static signed char UniCaseRangeU0490[61] = {
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 490-49f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 4a0-4af */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 4b0-4bf */
0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1,
};
/* Upper case range - Extended latin and greek */
static signed char UniCaseRangeU1e00[509] = {
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e00-1e0f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e10-1e1f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e20-1e2f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e30-1e3f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e40-1e4f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e50-1e5f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e60-1e6f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e70-1e7f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e80-1e8f */
0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, -59, 0, -1, 0, -1, /* 1e90-1e9f */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ea0-1eaf */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1eb0-1ebf */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ec0-1ecf */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ed0-1edf */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ee0-1eef */
0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, /* 1ef0-1eff */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f00-1f0f */
8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f10-1f1f */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f20-1f2f */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f30-1f3f */
8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f40-1f4f */
0, 8, 0, 8, 0, 8, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f50-1f5f */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f60-1f6f */
74, 74, 86, 86, 86, 86, 100, 100, 0, 0, 112, 112, 126, 126, 0, 0, /* 1f70-1f7f */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f80-1f8f */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f90-1f9f */
8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fa0-1faf */
8, 8, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fb0-1fbf */
0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fc0-1fcf */
8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fd0-1fdf */
8, 8, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fe0-1fef */
0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
/* Upper case range - Wide latin */
static signed char UniCaseRangeUff40[27] = {
0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, /* ff40-ff4f */
-32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
};
/*
* Upper Case Range
*/
const struct UniCaseRange CifsUniUpperRange[] = {
{0x03a0, 0x03ce, UniCaseRangeU03a0},
{0x0430, 0x045f, UniCaseRangeU0430},
{0x0490, 0x04cc, UniCaseRangeU0490},
{0x1e00, 0x1ffc, UniCaseRangeU1e00},
{0xff40, 0xff5a, UniCaseRangeUff40},
{0, 0, 0}
};
#endif
#ifndef UNIUPR_NOLOWER
/*
* Latin lower case
*/
static signed char CifsUniLowerTable[512] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 000-00f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 010-01f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 020-02f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 030-03f */
0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, /* 040-04f */
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0, 0, 0, 0, /* 050-05f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 060-06f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 070-07f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 080-08f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 090-09f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0a0-0af */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0b0-0bf */
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, /* 0c0-0cf */
32, 32, 32, 32, 32, 32, 32, 0, 32, 32, 32, 32, 32, 32, 32, 0, /* 0d0-0df */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0e0-0ef */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0f0-0ff */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 100-10f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 110-11f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 120-12f */
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, /* 130-13f */
0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, /* 140-14f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 150-15f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 160-16f */
1, 0, 1, 0, 1, 0, 1, 0, -121, 1, 0, 1, 0, 1, 0, 0, /* 170-17f */
0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 79, 0, /* 180-18f */
0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, /* 190-19f */
1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, /* 1a0-1af */
0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, /* 1b0-1bf */
0, 0, 0, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 1, 0, 1, /* 1c0-1cf */
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, /* 1d0-1df */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e0-1ef */
0, 2, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1f0-1ff */
};
/* Lower case range - Greek */
static signed char UniCaseRangeL0380[44] = {
0, 0, 0, 0, 0, 0, 38, 0, 37, 37, 37, 0, 64, 0, 63, 63, /* 380-38f */
0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, /* 390-39f */
32, 32, 0, 32, 32, 32, 32, 32, 32, 32, 32, 32,
};
/* Lower case range - Cyrillic */
static signed char UniCaseRangeL0400[48] = {
0, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 0, 80, 80, /* 400-40f */
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, /* 410-41f */
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, /* 420-42f */
};
/* Lower case range - Extended cyrillic */
static signed char UniCaseRangeL0490[60] = {
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 490-49f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 4a0-4af */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 4b0-4bf */
0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
};
/* Lower case range - Extended latin and greek */
static signed char UniCaseRangeL1e00[504] = {
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e00-1e0f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e10-1e1f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e20-1e2f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e30-1e3f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e40-1e4f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e50-1e5f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e60-1e6f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e70-1e7f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1e80-1e8f */
1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, /* 1e90-1e9f */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1ea0-1eaf */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1eb0-1ebf */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1ec0-1ecf */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1ed0-1edf */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, /* 1ee0-1eef */
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, /* 1ef0-1eff */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1f00-1f0f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, 0, 0, /* 1f10-1f1f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1f20-1f2f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1f30-1f3f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, 0, 0, /* 1f40-1f4f */
0, 0, 0, 0, 0, 0, 0, 0, 0, -8, 0, -8, 0, -8, 0, -8, /* 1f50-1f5f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1f60-1f6f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f70-1f7f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1f80-1f8f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1f90-1f9f */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -8, -8, -8, -8, -8, -8, /* 1fa0-1faf */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -74, -74, -9, 0, 0, 0, /* 1fb0-1fbf */
0, 0, 0, 0, 0, 0, 0, 0, -86, -86, -86, -86, -9, 0, 0, 0, /* 1fc0-1fcf */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -100, -100, 0, 0, 0, 0, /* 1fd0-1fdf */
0, 0, 0, 0, 0, 0, 0, 0, -8, -8, -112, -112, -7, 0, 0, 0, /* 1fe0-1fef */
0, 0, 0, 0, 0, 0, 0, 0,
};
/* Lower case range - Wide latin */
static signed char UniCaseRangeLff20[27] = {
0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, /* ff20-ff2f */
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
};
/*
* Lower Case Range
*/
const static struct UniCaseRange CifsUniLowerRange[] = {
0x0380, 0x03ab, UniCaseRangeL0380,
0x0400, 0x042f, UniCaseRangeL0400,
0x0490, 0x04cb, UniCaseRangeL0490,
0x1e00, 0x1ff7, UniCaseRangeL1e00,
0xff20, 0xff3a, UniCaseRangeLff20,
0, 0, 0
};
#endif
/*
* fs/cifs/cifsfs.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* Common Internet FileSystem (CIFS) client
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Note that BB means BUGBUG (ie something to fix eventually) */
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/list.h>
#include <linux/seq_file.h>
#include "cifsfs.h"
#include "cifspdu.h"
#define DECLARE_GLOBALS_HERE
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
#include <linux/mm.h>
#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of all SMB PDUs */
extern struct file_system_type cifs_fs_type;
int cifsFYI = 0;
int cifsERROR = 1;
int traceSMB = 0;
unsigned int oplockEnabled = 0;
unsigned int multiuser_mount = 0;
unsigned int extended_security = 0;
unsigned int ntlmv2_support = 0;
unsigned int sign_CIFS_PDUs = 0;
extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *,
char *);
extern int cifs_umount(struct super_block *, struct cifs_sb_info *);
void cifs_proc_init(void);
void cifs_proc_clean(void);
static int
cifs_read_super(struct super_block *sb, void *data, char *devname, int silent)
{
struct inode *inode;
struct cifs_sb_info *cifs_sb;
int rc = 0;
sb->s_fs_info = kmalloc(sizeof(struct cifs_sb_info),GFP_KERNEL);
cifs_sb = CIFS_SB(sb);
cifs_sb->local_nls = load_nls_default(); /* needed for ASCII cp to Unicode converts */
rc = cifs_mount(sb, cifs_sb, data, devname);
if (rc) {
if (!silent)
cERROR(1,
("cifs_mount failed w/return code = %d\n", rc));
goto out_mount_failed;
}
sb->s_magic = CIFS_MAGIC_NUMBER;
sb->s_op = &cifs_super_ops;
sb->s_blocksize = CIFS_MAX_MSGSIZE; /* BB check SMBSessSetup negotiated size */
sb->s_blocksize_bits = 10; /* 2**10 = CIFS_MAX_MSGSIZE */
inode = iget(sb, ROOT_I);
if (!inode)
goto out_no_root;
sb->s_root = d_alloc_root(inode);
if (!sb->s_root)
goto out_no_root;
return 0;
out_no_root:
cEVENT(1, ("cifs_read_super: get root inode failed\n"));
if (inode)
iput(inode);
/* rc = cifs_umount(sb); BB is CIFS unmount routine needed? */
if (rc) {
cERROR(1, ("cifs_umount failed with return code %d\n", rc));
}
out_mount_failed:
if(cifs_sb)
kfree(cifs_sb);
return -EINVAL;
}
void
cifs_put_super(struct super_block *sb)
{
int rc = 0;
struct cifs_sb_info *cifs_sb;
cFYI(1, ("In cifs_put_super\n"));
cifs_sb = CIFS_SB(sb);
rc = cifs_umount(sb, cifs_sb);
if (rc) {
cERROR(1, ("cifs_umount failed with return code %d\n", rc));
}
if(cifs_sb) {
unload_nls(cifs_sb->local_nls);
kfree(cifs_sb);
}
return;
}
int
cifs_statfs(struct super_block *sb, struct statfs *buf)
{
int xid, rc;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
xid = GetXid();
cifs_sb = CIFS_SB(sb);
pTcon = cifs_sb->tcon;
buf->f_type = CIFS_MAGIC_NUMBER;
/* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */
buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would presumably
be length of total path, note that some servers may be
able to support more than this, but best to be safe
since Win2k and others can not handle very long filenames */
buf->f_files = 0; /* undefined */
buf->f_ffree = -1; /* unlimited */
rc = CIFSSMBQFSInfo(xid, pTcon, buf, cifs_sb->local_nls);
/*
int f_type;
__fsid_t f_fsid;
int f_namelen; */
/* BB get from info put in tcon struct at mount time with call to QFSAttrInfo */
return 0; /* always return success? what if volume is no longer available? */
}
static kmem_cache_t *cifs_inode_cachep;
kmem_cache_t *cifs_req_cachep;
kmem_cache_t *cifs_mid_cachep;
static struct inode *
cifs_alloc_inode(struct super_block *sb)
{
struct cifsInodeInfo *cifs_inode;
cifs_inode =
(struct cifsInodeInfo *) kmem_cache_alloc(cifs_inode_cachep,
SLAB_KERNEL);
if (!cifs_inode)
return NULL;
cifs_inode->cifsAttrs = 0x20; /* default */
atomic_set(&cifs_inode->inUse, 0);
cifs_inode->time = 0;
cifs_inode->clientCanCache = 0;
INIT_LIST_HEAD(&cifs_inode->openFileList);
return &cifs_inode->vfs_inode;
}
static void
cifs_destroy_inode(struct inode *inode)
{
kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
}
/*
* cifs_show_options() is for displaying mount options in /proc/mounts.
* It tries to avoid showing settings that were not changed from their
* defaults.
*/
static int
cifs_show_options(struct seq_file *s, struct vfsmount *m)
{
struct cifs_sb_info *cifs_sb;
cifs_sb = CIFS_SB(m->mnt_sb);
if (cifs_sb)
if (cifs_sb->tcon) {
seq_printf(s, ", TARGET: %s ", cifs_sb->tcon->treeName);
seq_printf(s, "FS TYPE: %s ",
cifs_sb->tcon->nativeFileSystem);
if (cifs_sb->tcon->ses->userName)
seq_printf(s, " USER: %s ",
cifs_sb->tcon->ses->userName);
}
return 0;
}
struct super_operations cifs_super_ops = {
.read_inode = cifs_read_inode,
.put_super = cifs_put_super,
.statfs = cifs_statfs,
.alloc_inode = cifs_alloc_inode,
.destroy_inode = cifs_destroy_inode,
/* .drop_inode = generic_delete_inode,
.delete_inode = cifs_delete_inode, *//* Do not need the above two functions
unless later we add lazy close of inodes or unless the kernel forgets to call
us with the same number of releases (closes) as opens */
.show_options = cifs_show_options,
/* .umount_begin = cifs_umount_begin, *//* consider adding in the future */
};
static struct super_block *
cifs_get_sb(struct file_system_type *fs_type,
int flags, char *dev_name, void *data)
{
int rc;
struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
cFYI(1, ("\nDevname: %s flags: %d ", dev_name, flags));
if (IS_ERR(sb))
return sb;
sb->s_flags = flags;
rc = cifs_read_super(sb, data, dev_name, flags & MS_VERBOSE ? 1 : 0);
if (rc) {
up_write(&sb->s_umount);
deactivate_super(sb);
return ERR_PTR(rc);
}
sb->s_flags |= MS_ACTIVE;
return sb;
}
static struct file_system_type cifs_fs_type = {
.owner = THIS_MODULE,
.name = "cifs",
.get_sb = cifs_get_sb,
.kill_sb = kill_anon_super,
/* .fs_flags */
};
struct inode_operations cifs_dir_inode_ops = {
.create = cifs_create,
.lookup = cifs_lookup,
.unlink = cifs_unlink,
.link = cifs_hardlink,
.mkdir = cifs_mkdir,
.rmdir = cifs_rmdir,
.rename = cifs_rename,
/* revalidate:cifs_revalidate, */
.setattr = cifs_setattr,
.symlink = cifs_symlink,
};
struct inode_operations cifs_file_inode_ops = {
/* revalidate:cifs_revalidate, */
.setattr = cifs_setattr,
.rename = cifs_rename,
};
struct inode_operations cifs_symlink_inode_ops = {
.readlink = cifs_readlink,
.follow_link = cifs_follow_link,
/* BB add the following two eventually */
/* revalidate: cifs_revalidate,
setattr: cifs_notify_change, *//* BB do we need notify change */
};
struct file_operations cifs_file_ops = {
.read = cifs_read,
.write = cifs_write,
.open = cifs_open,
.release = cifs_close,
.lock = cifs_lock,
.fsync = cifs_fsync,
};
struct file_operations cifs_dir_ops = {
.readdir = cifs_readdir,
.release = cifs_closedir,
};
static void
cifs_init_once(void *inode, kmem_cache_t * cachep, unsigned long flags)
{
struct cifsInodeInfo *cifsi = (struct cifsInodeInfo *) inode;
if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
SLAB_CTOR_CONSTRUCTOR) {
inode_init_once(&cifsi->vfs_inode);
INIT_LIST_HEAD(&cifsi->lockList);
}
}
int
cifs_init_inodecache(void)
{
cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
sizeof (struct cifsInodeInfo),
0, SLAB_HWCACHE_ALIGN,
cifs_init_once, NULL);
if (cifs_inode_cachep == NULL)
return -ENOMEM;
return 0;
}
void
cifs_destroy_inodecache(void)
{
if (kmem_cache_destroy(cifs_inode_cachep))
printk(KERN_INFO "cifs_inode_cache: error freeing\n");
}
int
cifs_init_request_bufs(void)
{
cifs_req_cachep = kmem_cache_create("cifs_request",
CIFS_MAX_MSGSIZE +
MAX_CIFS_HDR_SIZE, 0,
SLAB_HWCACHE_ALIGN, NULL, NULL);
if (cifs_req_cachep == NULL)
return -ENOMEM;
return 0;
}
void
cifs_destroy_request_bufs(void)
{
if (kmem_cache_destroy(cifs_req_cachep))
printk(KERN_INFO
"cifs_destroy_request_cache: error not all structures were freed\n");
}
int
cifs_init_mids(void)
{
cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
sizeof (struct mid_q_entry), 0,
SLAB_HWCACHE_ALIGN, NULL, NULL);
if (cifs_mid_cachep == NULL)
return -ENOMEM;
return 0;
}
void
cifs_destroy_mids(void)
{
if (kmem_cache_destroy(cifs_mid_cachep))
printk(KERN_INFO
"cifs_destroy_mids: error not all structures were freed\n");
}
static int __init
init_cifs(void)
{
int rc = 0;
#if CONFIG_PROC_FS
cifs_proc_init();
#endif
INIT_LIST_HEAD(&GlobalServerList); /* BB not implemented yet */
INIT_LIST_HEAD(&GlobalSMBSessionList);
INIT_LIST_HEAD(&GlobalTreeConnectionList);
/*
* Initialize Global counters
*/
atomic_set(&sesInfoAllocCount, 0);
atomic_set(&tconInfoAllocCount, 0);
atomic_set(&bufAllocCount, 0);
atomic_set(&midCount, 0);
GlobalTotalActiveXid = 0;
GlobalMaxActiveXid = 0;
rc = cifs_init_inodecache();
if (!rc) {
rc = cifs_init_mids();
if (!rc) {
rc = cifs_init_request_bufs();
if (!rc) {
rc = register_filesystem(&cifs_fs_type);
if (!rc)
return rc; /* Success */
else
cifs_destroy_request_bufs();
}
cifs_destroy_mids();
}
cifs_destroy_inodecache();
}
#if CONFIG_PROC_FS
cifs_proc_clean();
#endif
return rc;
}
static void __exit
exit_cifs(void)
{
cFYI(0, ("\nIn unregister ie exit_cifs"));
#if CONFIG_PROC_FS
cifs_proc_clean();
#endif
unregister_filesystem(&cifs_fs_type);
cifs_destroy_inodecache();
cifs_destroy_mids();
cifs_destroy_request_bufs();
}
MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
MODULE_DESCRIPTION
("VFS to access servers complying with the SNIA CIFS Specification e.g. Samba and Windows");
module_init(init_cifs)
module_exit(exit_cifs)
/*
* fs/cifs/cifsfs.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _CIFSFS_H
#define _CIFSFS_H
#define ROOT_I 2
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
extern int map_cifs_error(int error_class, int error_code,
int status_codes_negotiated);
extern struct address_space_operations cifs_addr_ops;
/* Functions related to super block operations */
extern struct super_operations cifs_super_ops;
extern void cifs_put_inode(struct inode *);
extern void cifs_read_inode(struct inode *);
extern void cifs_delete_inode(struct inode *);
/* extern void cifs_write_inode(struct inode *); *//* BB not needed yet */
/* Functions related to inodes */
extern struct inode_operations cifs_dir_inode_ops;
extern int cifs_create(struct inode *, struct dentry *, int);
extern struct dentry *cifs_lookup(struct inode *, struct dentry *);
extern int cifs_unlink(struct inode *, struct dentry *);
extern int cifs_hardlink(struct dentry *, struct inode *, struct dentry *);
extern int cifs_mkdir(struct inode *, struct dentry *, int);
extern int cifs_rmdir(struct inode *, struct dentry *);
extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
struct dentry *);
extern int cifs_revalidate(struct dentry *);
extern int cifs_setattr(struct dentry *, struct iattr *);
extern struct inode_operations cifs_file_inode_ops;
extern void cifs_truncate_file(struct inode *);
extern struct inode_operations cifs_symlink_inode_ops;
/* Functions related to files and directories */
extern struct file_operations cifs_file_ops;
extern int cifs_open(struct inode *inode, struct file *file);
extern int cifs_close(struct inode *inode, struct file *file);
extern int cifs_closedir(struct inode *inode, struct file *file);
extern ssize_t cifs_read(struct file *file, char *read_data,
size_t read_size, loff_t * poffset);
extern ssize_t cifs_write(struct file *file, const char *write_data,
size_t write_size, loff_t * poffset);
extern int cifs_lock(struct file *, int, struct file_lock *);
extern int cifs_fsync(struct file *, struct dentry *, int);
extern struct file_operations cifs_dir_ops;
extern int cifs_dir_open(struct inode *inode, struct file *file);
extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir);
/* Functions related to dir entries */
extern struct dentry_operations cifs_dentry_ops;
/* Functions related to symlinks */
extern int cifs_follow_link(struct dentry *direntry, struct nameidata *nd);
extern int cifs_readlink(struct dentry *direntry, char *buffer, int buflen);
extern int cifs_symlink(struct inode *inode, struct dentry *direntry,
const char *symname);
#endif /* _CIFSSMB_H */
/*
* fs/cifs/cifsglob.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
*/
#include <linux/in.h>
#include "cifs_fs_sb.h"
/*
* The sizes of various internal tables and strings
*/
#define MAX_UID_INFO 16
#define MAX_SES_INFO 2
#define MAX_TCON_INFO 4
#define MAX_TREE_SIZE 2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1
#define MAX_SERVER_SIZE 15
#define MAX_SHARE_SIZE 64 /* used to be 20 - this should still be enough */
#define MAX_USERNAME_SIZE 32 /* 22 is to allow for 15 char names + null
termination then *2 for unicode versions */
#define MAX_PASSWORD_SIZE 16
/*
* MAX_REQ is the maximum number of requests that WE will send
* on one NetBIOS handle concurently.
*/
#define MAX_REQ (10)
#define SERVER_NAME_LENGTH 15
#define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
/* used to define string lengths for reversing unicode strings */
/* (256+1)*2 = 514 */
/* (max path length + 1 for null) * 2 for unicode */
#define MAX_NAME 514
#include "cifspdu.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/*
* This information is kept on every Server we know about.
*
* Some things to note:
*
*/
#define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
/*
* CIFS vfs client Status information (based on what we know.)
*/
/* associated with each tcp and smb session */
enum statusEnum {
CifsNew = 0,
CifsGood,
CifsExiting,
CifsNeedReconnect
};
enum securityEnum {
NTLM = 0, /* Legacy NTLM012 auth with NTLM hash */
NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */
RawNTLMSSP, /* NTLMSSP without SPNEGO */
NTLMSSP, /* NTLMSSP via SPNEGO */
Kerberos /* Kerberos via SPNEGO */
};
/*
*****************************************************************
* Except the CIFS PDUs themselves all the
* globally interesting structs should go here
*****************************************************************
*/
struct TCP_Server_Info {
char server_Name[SERVER_NAME_LEN_WITH_NULL]; /* 15 chars + X'20'in 16th */
char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2]; /* Unicode version of server_Name */
struct socket *ssocket;
struct sockaddr_in sockAddr;
wait_queue_head_t response_q;
struct list_head pending_mid_q;
void *Server_NlsInfo; /* BB - placeholder for future NLS info */
unsigned short server_codepage; /* codepage for the server */
unsigned long ip_address; /* IP addr for the server if known */
unsigned long svType; /* computer type */
char versionMajor;
char versionMinor;
int svlocal:1; /* local server or remote */
atomic_t socketUseCount; /* indicates if the server has any open cifs sessions */
enum statusEnum tcpStatus; /* what we think the status is */
struct semaphore tcpSem;
struct task_struct *tsk;
char server_GUID[16];
};
/*
* The following is our shortcut to user information. We surface the uid,
* and name. We always get the password on the fly in case it
* has changed. We also hang a list of sessions owned by this user off here.
*/
struct cifsUidInfo {
struct cifsUidInfo *next1; /* BB replace with list and atomicize */
struct cifsSesInfo *ses; /* list of sessions *//* BB replace with list and atomicize */
struct srSesInfo *sesSR; /* Save/Restore session list */
uid_t linux_uid;
char user[MAX_USERNAME_SIZE + 1]; /* ascii name of user */
/* BB eventually need ptr into PAM or WinBind info */
};
/*
* Session structure. One of these for each uid session with a particular host
*/
struct cifsSesInfo {
struct list_head cifsSessionList;
struct semaphore sesSem;
struct cifsUidInfo *uidInfo; /* pointer to user info */
struct TCP_Server_Info *server; /* pointer to server info */
atomic_t inUse; /* # of CURRENT users of this ses */
enum statusEnum status;
int dialectIndex; /* the negotiated dialect index */
char secMode;
enum securityEnum secType;
unsigned int maxReq; /* Clients should submit no more */
/* than maxReq distinct unanswered SMBs to the server when using */
/* multiplexed reads or writes */
unsigned int maxBuf; /* maxBuf specifies the maximum */
/* message size the server can send or receive for non-raw SMBs */
unsigned int maxRw; /* maxRw specifies the maximum */
/* message size the server can send or receive for */
/* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
char sessid[4]; /* unique token id for this session */
/* (returned on Negotiate */
__u16 ipc_tid; /* special tid for connection to IPC share */
int capabilities;
__u16 timeZone;
char *serverOS; /* name of operating system underlying the server */
char *serverNOS; /* name of network operating system that the server is running */
char *serverDomain; /* security realm of server */
int Suid; /* needed for user level security */
char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for tcp names - will ipv6 and sctp addresses fit here?? */
char userName[MAX_USERNAME_SIZE + 1]; /* BB remove and replace with list of cifsUidInfo structures */
};
/*
* there is one of these for each connection to a resource on a particular
* session
*/
struct cifsTconInfo {
struct list_head cifsConnectionList;
struct list_head openFileList;
struct semaphore tconSem;
struct cifsSesInfo *ses; /* pointer to session associated with */
char treeName[MAX_TREE_SIZE + 1]; /* The ascii or unicode name of this resource depending on the ses->capabilities *//* BB fill in this field */
char *nativeFileSystem;
__u16 tid; /* The 2 byte transaction id */
__u16 Flags; /* optional support bits */
atomic_t useCount; /* how many mounts (explicit or implicit refer to this share */
FILE_SYSTEM_DEVICE_INFO fsDevInfo;
FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* note file system name may be truncated - but very unlikely */
FILE_SYSTEM_UNIX_INFO fsUnixInfo;
/* BB add field for back pointer to sb struct? */
};
/*
* This info hangs off the cifsFileInfo structure. This is used to track
* byte stream locks on the file
*/
struct cifsLockInfo {
struct cifsLockInfo *next;
int start;
int length;
int type;
};
/*
* One of these for each open instance of a file
*/
struct cifsFileInfo {
struct list_head tlist; /* pointer to next fid owned by tcon */
struct list_head flist; /* next fid (file instance) for this inode */
unsigned int uid; /* allows you to find which FileInfo structure */
__u32 pid; /* process id who opened file */
__u16 netfid; /* file id from remote */
/* BB add lock scope info here if needed */ ;
/* lock scope id (0 if none) */
int endOfSearch:1; /* we have reached end of search */
int closePend:1; /* file is marked to close */
};
/*
* One of these for each file inode
*/
struct cifsInodeInfo {
struct list_head lockList;
/* BB add in lists for dirty pages - i.e. write caching info for oplock */
struct list_head openFileList;
__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system etc. */
atomic_t inUse; /* num concurrent users (local openers cifs) of file */
unsigned long time; /* jiffies of last update/check of inode */
int clientCanCache:1; /* oplocked. We need to extend cases beyond this i.e. what
if file read-only or if file locked? or if file on r/o vol? */
struct inode vfs_inode;
};
static inline struct cifsInodeInfo *
CIFS_I(struct inode *inode)
{
return container_of(inode, struct cifsInodeInfo, vfs_inode);
}
static inline struct cifs_sb_info *
CIFS_SB(struct super_block *sb)
{
return sb->s_fs_info;
}
/* one of these for every pending CIFS request to the server */
struct mid_q_entry {
struct list_head qhead; /* mids waiting on reply from this server */
__u16 mid; /* multiplex id */
__u16 pid; /* process id */
__u16 command; /* smb command code */
struct timeval when_sent; /* time when smb sent */
struct cifsSesInfo *ses; /* smb was sent to this server */
struct task_struct *tsk; /* task waiting for response */
struct smb_hdr *resp_buf; /* response buffer */
int midState; /* wish this could be an enum but can not pass that to wait_event */
};
#define MID_FREE 0
#define MID_REQUEST_ALLOCATED 1
#define MID_REQUEST_SUBMITTED 2
#define MID_RESPONSE_RECEIVED 4
struct servers_not_supported { /* @z4a */
struct servers_not_supported *next1; /* @z4a */
char server_Name[SERVER_NAME_LEN_WITH_NULL]; /* @z4a */
/* Server Names in SMB protocol are 15 chars + X'20' */
/* in 16th byte... @z4a */
};
/*
*****************************************************************
* All constants go here
*****************************************************************
*/
#define UID_HASH (16)
/*
* Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
* following to be declared.
*/
/* BB Every global should have an associated mutex for safe update BB */
#ifdef DECLARE_GLOBALS_HERE
#define GLOBAL_EXTERN
#else
#define GLOBAL_EXTERN extern
#endif
/*
* The list of servers that did not respond with NT LM 0.12.
* This list helps improve performance and eliminate the messages indicating
* that we had a communications error talking to the server in this list.
*/
GLOBAL_EXTERN struct servers_not_supported *NotSuppList; /*@z4a */
/*
* The following is a hash table of all the users we know about.
*/
GLOBAL_EXTERN struct smbUidInfo *GlobalUidList[UID_HASH];
GLOBAL_EXTERN struct list_head GlobalServerList; /* BB this one is not implemented yet */
GLOBAL_EXTERN struct list_head GlobalSMBSessionList;
GLOBAL_EXTERN struct list_head GlobalTreeConnectionList;
/*
* Global list of free SMB structures
*/
GLOBAL_EXTERN void *GlobalFreeSMB;
/*
* Global transaction id (XID) information
*/
GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
GLOBAL_EXTERN char Local_System_Name[15];
/*
* Global counters, updated atomically
*/
GLOBAL_EXTERN atomic_t sesInfoAllocCount;
GLOBAL_EXTERN atomic_t tconInfoAllocCount;
/* Various Debug counters to remove someday (BB) */
GLOBAL_EXTERN atomic_t bufAllocCount;
GLOBAL_EXTERN atomic_t midCount;
/* Misc globals */
GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
to be established on existing mount if we
have the uid/password or Kerberos credential
or equivalent for current user */
GLOBAL_EXTERN unsigned int oplockEnabled;
GLOBAL_EXTERN unsigned int extended_security; /* if on, session setup sent
with more secure ntlmssp2 challenge/resp */
GLOBAL_EXTERN unsigned int ntlmv2_support; /* better optional password hash */
GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
/*
* fs/cifs/cifspdu.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _CIFSPDU_H
#define _CIFSPDU_H
#include <net/sock.h>
#define CIFS_PROT 0
#define BAD_PROT CIFS_PROT+1
/* SMB command codes */
#define SMB_COM_CREATE_DIRECTORY 0x00
#define SMB_COM_DELETE_DIRECTORY 0x01
#define SMB_COM_CLOSE 0x04
#define SMB_COM_DELETE 0x06
#define SMB_COM_RENAME 0x07
#define SMB_COM_LOCKING_ANDX 0x24
#define SMB_COM_READ_ANDX 0x2E
#define SMB_COM_WRITE_ANDX 0x2F
#define SMB_COM_TRANSACTION2 0x32
#define SMB_COM_TRANSACTION2_SECONDARY 0x33
#define SMB_COM_TREE_DISCONNECT 0x71
#define SMB_COM_NEGOTIATE 0x72
#define SMB_COM_SESSION_SETUP_ANDX 0x73
#define SMB_COM_LOGOFF_ANDX 0x74
#define SMB_COM_TREE_CONNECT_ANDX 0x75
#define SMB_COM_NT_TRANSACT 0xA0
#define SMB_COM_NT_TRANSACT_SECONDARY 0xA1
#define SMB_COM_NT_CREATE_ANDX 0xA2
#define SMB_COM_NT_RENAME 0xA5
/* Transact2 subcommand codes */
#define TRANS2_OPEN 0x00
#define TRANS2_FIND_FIRST 0x01
#define TRANS2_FIND_NEXT 0x02
#define TRANS2_QUERY_FS_INFORMATION 0x03
#define TRANS2_QUERY_PATH_INFORMATION 0x05
#define TRANS2_SET_PATH_INFORMATION 0x06
#define TRANS2_QUERY_FILE_INFORMATION 0x07
#define TRANS2_SET_FILE_INFORMATION 0x08
#define TRANS2_GET_DFS_REFERRAL 0x10
#define TRANS2_REPORT_DFS_INCOSISTENCY 0x11
/* NT Transact subcommand codes */
#define NT_TRANSACT_CREATE 0x01
#define NT_TRANSACT_IOCTL 0x02
#define NT_TRANSACT_SET_SECURITY_DESC 0x03
#define NT_TRANSACT_NOTIFY_CHANGE 0x04
#define NT_TRANSACT_RENAME 0x05
#define NT_TRANSACT_QUERY_SECURITY_DESC 0x06
#define MAX_CIFS_HDR_SIZE 256 /* chained NTCreateXReadX will probably be biggest */
/* internal cifs vfs structures */
/*****************************************************************
* All constants go here
*****************************************************************
*/
/*
* Starting value for maximum SMB size negotiation
*/
#define CIFS_MAX_MSGSIZE (4*1024)
/*
* Size of encrypted user password in bytes
*/
#define CIFS_ENCPWD_SIZE (16)
/*
* Size of the crypto key returned on the negotiate SMB in bytes
*/
#define CIFS_CRYPTO_KEY_SIZE (8)
/*
* Size of the session key (crypto key encrypted with the password
*/
#define CIFS_SESSION_KEY_SIZE (24)
/*
* Maximum user name length
*/
#define CIFS_UNLEN (20)
/*
* Flags on SMB open
*/
#define SMBOPEN_WRITE_THROUGH 0x4000
#define SMBOPEN_DENY_ALL 0x0010
#define SMBOPEN_DENY_WRITE 0x0020
#define SMBOPEN_DENY_READ 0x0030
#define SMBOPEN_DENY_NONE 0x0040
#define SMBOPEN_READ 0x0000
#define SMBOPEN_WRITE 0x0001
#define SMBOPEN_READWRITE 0x0002
#define SMBOPEN_EXECUTE 0x0003
#define SMBOPEN_OCREATE 0x0010
#define SMBOPEN_OTRUNC 0x0002
#define SMBOPEN_OAPPEND 0x0001
/*
* SMB flag definitions
*/
#define SMBFLG_EXTD_LOCK 0x01 /* server supports lock-read write-unlock primitives */
#define SMBFLG_RCV_POSTED 0x02 /* obsolete */
#define SMBFLG_RSVD 0x04
#define SMBFLG_CASELESS 0x08 /* all pathnames treated as caseless (off implies case sensitive file handling requested) */
#define SMBFLG_CANONICAL_PATH_FORMAT 0x10 /* obsolete */
#define SMBFLG_OLD_OPLOCK 0x20 /* obsolete */
#define SMBFLG_OLD_OPLOCK_NOTIFY 0x40 /* obsolete */
#define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */
/*
* SMB flag2 definitions
*/
#define SMBFLG2_KNOWS_LONG_NAMES 0x0001 /* can send long (non-8.3) path names in response */
#define SMBFLG2_KNOWS_EAS 0x0002
#define SMBFLG2_SECURITY_SIGNATURE 0x0004
#define SMBFLG2_IS_LONG_NAME 0x0040
#define SMBFLG2_EXT_SEC 0x0800
#define SMBFLG2_DFS 0x1000
#define SMBFLG2_PAGING_IO 0x2000
#define SMBFLG2_ERR_STATUS 0x4000
#define SMBFLG2_UNICODE 0x8000
/*
* These are the file access permission bits defined in CIFS for the
* NTCreateAndX as well as the level 0x107
* TRANS2_QUERY_PATH_INFORMATION API. The level 0x107, SMB_QUERY_FILE_ALL_INFO
* responds with the AccessFlags.
* The AccessFlags specifies the access permissions a caller has to the
* file and can have any suitable combination of the following values:
*/
#define FILE_READ_DATA 0x00000001 /* Data can be read from the file */
#define FILE_WRITE_DATA 0x00000002 /* Data can be written to the file */
#define FILE_APPEND_DATA 0x00000004 /* Data can be appended to the file */
#define FILE_READ_EA 0x00000008 /* Extended attributes associated */
/* with the file can be read */
#define FILE_WRITE_EA 0x00000010 /* Extended attributes associated */
/* with the file can be written */
#define FILE_EXECUTE 0x00000020 /*Data can be read into memory from */
/* the file using system paging I/O */
#define FILE_DELETE_CHILD 0x00000040
#define FILE_READ_ATTRIBUTES 0x00000080 /* Attributes associated with the */
/* file can be read */
#define FILE_WRITE_ATTRIBUTES 0x00000100 /* Attributes associated with the */
/* file can be written */
#define DELETE 0x00010000 /* The file can be deleted */
#define READ_CONTROL 0x00020000 /* The access control list and */
/* ownership associated with the */
/* file can be read */
#define WRITE_DAC 0x00040000 /* The access control list and */
/* ownership associated with the */
/* file can be written. */
#define WRITE_OWNER 0x00080000 /* Ownership information associated */
/* with the file can be written */
#define SYNCHRONIZE 0x00100000 /* The file handle can waited on to */
/* synchronize with the completion */
/* of an input/output request */
#define GENERIC_ALL 0x10000000
#define GENERIC_EXECUTE 0x20000000
#define GENERIC_WRITE 0x40000000
#define GENERIC_READ 0x80000000
/* In summary - Relevant file */
/* access flags from CIFS are */
/* file_read_data, file_write_data */
/* file_execute, file_read_attributes */
/* write_dac, and delete. */
/*
* Invalid readdir handle
*/
#define CIFS_NO_HANDLE 0xFFFF
/* IPC$ in ASCII */
#define CIFS_IPC_RESOURCE "\x49\x50\x43\x24"
/* IPC$ in Unicode */
#define CIFS_IPC_UNICODE_RESOURCE "\x00\x49\x00\x50\x00\x43\x00\x24\x00\x00"
/* Unicode Null terminate 2 bytes of 0 */
#define UNICODE_NULL "\x00\x00"
#define ASCII_NULL 0x00
/*
* Server type values (returned on EnumServer API
*/
#define CIFS_SV_TYPE_DC 0x00000008
#define CIFS_SV_TYPE_BACKDC 0x00000010
/*
* Alias type flags (From EnumAlias API call
*/
#define CIFS_ALIAS_TYPE_FILE 0x0001
#define CIFS_SHARE_TYPE_FILE 0x0000
/*
* File Attribute flags
*/
#define ATTR_READONLY 0x0001
#define ATTR_HIDDEN 0x0002
#define ATTR_SYSTEM 0x0004
#define ATTR_VOLUME 0x0008
#define ATTR_DIRECTORY 0x0010
#define ATTR_ARCHIVE 0x0020
#define ATTR_DEVICE 0x0040
#define ATTR_NORMAL 0x0080
#define ATTR_TEMPORARY 0x0100
#define ATTR_SPARSE 0x0200
#define ATTR_REPARSE 0x0400
#define ATTR_COMPRESSED 0x0800
#define ATTR_OFFLINE 0x1000 /* ie file not immediately available - offline storage */
#define ATTR_NOT_CONTENT_INDEXED 0x2000
#define ATTR_ENCRYPTED 0x4000
#define ATTR_POSIX_SEMANTICS 0x01000000
#define ATTR_SEQUENTIAL_SCAN 0x08000000
#define ATTR_RANDOM_ACCESS 0x10000000
#define ATTR_NO_BUFFERING 0x20000000
#define ATTR_WRITE_THROUGH 0x80000000
/* ShareAccess flags */
#define FILE_NO_SHARE 0x00000000
#define FILE_SHARE_READ 0x00000001
#define FILE_SHARE_WRITE 0x00000002
#define FILE_SHARE_DELETE 0x00000004
#define FILE_SHARE_ALL 0x00000007
/* CreateDisposition flags */
#define FILE_SUPERSEDE 0x00000000
#define FILE_OPEN 0x00000001
#define FILE_CREATE 0x00000002
#define FILE_OPEN_IF 0x00000003
#define FILE_OVERWRITE 0x00000004
#define FILE_OVERWRITE_IF 0x00000005
/* CreateOptions */
#define CREATE_NOT_FILE 0x00000001 /* if set, indicates must not be file */
#define CREATE_NOT_DIR 0x00000040 /* if set, indicates must not be directory */
/* ImpersonationLevel flags */
#define SECURITY_ANONYMOUS 0
#define SECURITY_IDENTIFICATION 1
#define SECURITY_IMPERSONATION 2
#define SECURITY_DELEGATION 3
/* SecurityFlags */
#define SECURITY_CONTEXT_TRACKING 0x01
#define SECURITY_EFFECTIVE_ONLY 0x02
/*
* Default PID value, used in all SMBs where the PID is not important
*/
#define CIFS_DFT_PID 0x1234
/*
* We use the same routine for Copy and Move SMBs. This flag is used to
* distinguish
*/
#define CIFS_COPY_OP 1
#define CIFS_RENAME_OP 2
#define GETU16(var) (*((__u16 *)var)) /* BB check for endian issues */
#define GETU32(var) (*((__u32 *)var)) /* BB check for endian issues */
#pragma pack(1)
struct smb_hdr {
__u32 smb_buf_length; /* big endian on wire *//* BB length is only two or three bytes - with one or two byte type preceding it but that is always zero - we could mask the type byte off just in case BB */
__u8 Protocol[4];
__u8 Command;
union {
struct {
__u8 ErrorClass;
__u8 Reserved;
__u16 Error; /* note: treated as little endian (le) on wire */
} DosError;
__u32 CifsError; /* note: le */
} Status;
__u8 Flags;
__u16 Flags2; /* note: le */
__u16 PidHigh; /* note: le */
__u8 SecuritySignature[8]; /* note le */
__u8 pad[2];
__u16 Tid;
__u16 Pid; /* note: le */
__u16 Uid;
__u16 Mid;
__u8 WordCount;
};
/* given a pointer to an smb_hdr retrieve the value of byte count */
#define BCC(smb_var) ( *(__u16 *)((char *)smb_var + sizeof(struct smb_hdr) + (2* smb_var->WordCount) ) )
/* given a pointer to an smb_hdr retrieve the pointer to the byte area */
#define pByteArea(smb_var) ((char *)smb_var + sizeof(struct smb_hdr) + (2* smb_var->WordCount) + 2 )
/*
* Computer Name Length
*/
#define CNLEN 15
/*
* Share Name Length @S8A
* Note: This length is limited by the SMB used to get @S8A
* the Share info. NetShareEnum only returns 13 @S8A
* chars, including the null termination. @S8A
*/
#define SNLEN 12 /*@S8A */
/*
* Comment Length
*/
#define MAXCOMMENTLEN 40
/*
* The OS/2 maximum path name
*/
#define MAX_PATHCONF 256
/*
* SMB frame definitions (following must be packed structs)
* See the SNIA CIFS Specification for details.
*
* The Naming convention is the lower case version of the
* smb command code name for the struct and this is typedef to the
* uppercase version of the same name with the prefix SMB_ removed
* for brevity. Although typedefs are not commonly used for
* structure definitions in the Linux kernel, their use in the
* CIFS standards document, which this code is based on, may
* make this one of the cases where typedefs for structures make
* sense to improve readability for readers of the standards doc.
* Typedefs can always be removed later if they are too distracting
* and they are only used for the CIFSs PDUs themselves, not
* internal cifs vfs structures
*
*/
typedef struct negotiate_req {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount;
unsigned char DialectsArray[1];
} NEGOTIATE_REQ;
typedef struct negotiate_rsp {
struct smb_hdr hdr; /* wct = 17 */
__u16 DialectIndex;
__u8 SecurityMode;
__u16 MaxMpxCount;
__u16 MaxNumberVcs;
__u32 MaxBufferSize;
__u32 MaxRawSize;
__u32 SessionKey;
__u32 Capabilities; /* see below */
__u32 SystemTimeLow;
__u32 SystemTimeHigh;
__u16 ServerTimeZone;
__u8 EncryptionKeyLength;
__u16 ByteCount;
union {
unsigned char EncryptionKey[1]; /* if cap extended security is off */
/* followed by Domain name - if extended security is off */
/* followed by 16 bytes of server GUID */
/* followed by security blob if cap_extended_security negotiated */
struct {
unsigned char GUID[16];
unsigned char SecurityBlob[1];
} extended_response;
} u;
} NEGOTIATE_RSP;
/* SecurityMode bits */
#define SECMODE_USER 0x01 /* off indicates share level security */
#define SECMODE_PW_ENCRYPT 0x02
#define SECMODE_SIGN_ENABLED 0x04 /* SMB security signatures enabled */
#define SECMODE_SIGN_REQUIRED 0x08 /* SMB security signatures required */
/* Negotiate response Capabilities */
#define CAP_RAW_MODE 0x00000001
#define CAP_MPX_MODE 0x00000002
#define CAP_UNICODE 0x00000004
#define CAP_LARGE_FILES 0x00000008
#define CAP_NT_SMBS 0x00000010 /* implies CAP_NT_FIND */
#define CAP_RPC_REMOTE_APIS 0x00000020
#define CAP_STATUS32 0x00000040
#define CAP_LEVEL_II_OPLOCKS 0x00000080
#define CAP_LOCK_AND_READ 0x00000100
#define CAP_NT_FIND 0x00000200
#define CAP_DFS 0x00001000
#define CAP_INFOLEVEL_PASSTHRU 0x00002000
#define CAP_LARGE_READ_X 0x00004000
#define CAP_LARGE_WRITE_X 0x00008000
#define CAP_UNIX 0x00800000
#define CAP_RESERVED 0x02000000
#define CAP_BULK_TRANSFER 0x20000000
#define CAP_COMPRESSED_DATA 0x40000000
#define CAP_EXTENDED_SECURITY 0x80000000
typedef union smb_com_session_setup_andx {
struct { /* request format */
struct smb_hdr hdr; /* wct = 12 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 MaxBufferSize;
__u16 MaxMpxCount;
__u16 VcNumber;
__u32 SessionKey;
__u16 SecurityBlobLength;
__u32 Reserved;
__u32 Capabilities; /* see below */
__u16 ByteCount;
unsigned char SecurityBlob[1]; /* followed by */
/* STRING NativeOS */
/* STRING NativeLanMan */
} req; /* NTLM request format (with extended security */
struct { /* request format */
struct smb_hdr hdr; /* wct = 13 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 MaxBufferSize;
__u16 MaxMpxCount;
__u16 VcNumber;
__u32 SessionKey;
__u16 CaseInsensitivePasswordLength; /* ASCII password length */
__u16 CaseSensitivePasswordLength; /* Unicode password length */
__u32 Reserved; /* see below */
__u32 Capabilities;
__u16 ByteCount;
unsigned char CaseInsensitivePassword[1]; /* followed by: */
/* unsigned char * CaseSensitivePassword; */
/* STRING AccountName */
/* STRING PrimaryDomain */
/* STRING NativeOS */
/* STRING NativeLanMan */
} req_no_secext; /* NTLM request format (without extended security */
struct { /* default (NTLM) response format */
struct smb_hdr hdr; /* wct = 4 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Action; /* see below */
__u16 SecurityBlobLength;
__u16 ByteCount;
unsigned char SecurityBlob[1]; /* followed by */
/* unsigned char * NativeOS; */
/* unsigned char * NativeLanMan; */
/* unsigned char * PrimaryDomain; */
} resp; /* NTLM response format (with or without extended security */
struct { /* request format */
struct smb_hdr hdr; /* wct = 10 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 MaxBufferSize;
__u16 MaxMpxCount;
__u16 VcNumber;
__u32 SessionKey;
__u16 PassswordLength;
__u32 Reserved;
__u16 ByteCount;
unsigned char AccountPassword[1]; /* followed by */
/* STRING AccountName */
/* STRING PrimaryDomain */
/* STRING NativeOS */
/* STRING NativeLanMan */
} old_req; /* pre-NTLM (LANMAN2.1) request format */
struct { /* default (NTLM) response format */
struct smb_hdr hdr; /* wct = 3 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Action; /* see below */
__u16 ByteCount;
unsigned char NativeOS[1]; /* followed by */
/* unsigned char * NativeLanMan; */
/* unsigned char * PrimaryDomain; */
} old_resp; /* pre-NTLM (LANMAN2.1) response format */
} SESSION_SETUP_ANDX;
#define CIFS_NETWORK_OPSYS "CIFS VFS Client for Linux"
/* Capabilities bits (for NTLM SessSetup request) */
#define CAP_UNICODE 0x00000004
#define CAP_LARGE_FILES 0x00000008
#define CAP_NT_SMBS 0x00000010
#define CAP_STATUS32 0x00000040
#define CAP_LEVEL_II_OPLOCKS 0x00000080
#define CAP_NT_FIND 0x00000200 /* reserved should be zero (presumably because NT_SMBs implies the same thing) */
#define CAP_BULK_TRANSFER 0x20000000
#define CAP_EXTENDED_SECURITY 0x80000000
/* Action bits */
#define GUEST_LOGIN 1
typedef struct smb_com_tconx_req {
struct smb_hdr hdr; /* wct = 4 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Flags; /* see below */
__u16 PasswordLength;
__u16 ByteCount;
unsigned char Password[1]; /* followed by */
/* STRING Path *//* \\server\share name */
/* STRING Service */
} TCONX_REQ;
typedef struct smb_com_tconx_rsp {
struct smb_hdr hdr; /* wct = 3 *//* note that Win2000 has sent wct=7 in some cases on responses. Four unspecified words followed OptionalSupport */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 OptionalSupport; /* see below */
__u16 ByteCount;
unsigned char Service[1]; /* always ASCII, not Unicode */
/* STRING NativeFileSystem */
} TCONX_RSP;
/* tree connect Flags */
#define DISCONNECT_TID 0x0001
#define TCON_EXTENDED_SECINFO 0x0008
/* OptionalSupport bits */
#define SMB_SUPPORT_SEARCH_BITS 0x0001 /* must have bits (exclusive searches suppt. */
#define SMB_SHARE_IS_IN_DFS 0x0002
typedef struct smb_com_logoff_andx_req {
struct smb_hdr hdr; /* wct = 2 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 ByteCount;
} LOGOFF_ANDX_REQ;
typedef struct smb_com_logoff_andx_rsp {
struct smb_hdr hdr; /* wct = 2 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 ByteCount;
} LOGOFF_ANDX_RSP;
typedef union smb_com_tree_disconnect { /* as an altetnative can use flag on tree_connect PDU to effect disconnect *//* probably the simplest SMB PDU */
struct {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bcc = 0 */
} req;
struct {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bcc = 0 */
} resp;
} TREE_DISCONNECT;
typedef struct smb_com_close_req {
struct smb_hdr hdr; /* wct = 3 */
__u16 FileID; /* target file attributes */
__u32 LastWriteTime; /* should be zero */
__u16 ByteCount; /* 0 */
} CLOSE_REQ;
typedef struct smb_com_close_rsp {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bct = 0 */
} CLOSE_RSP;
/* OpenFlags */
#define REQ_OPLOCK 0x00000002
#define REQ_BATCHOPLOCK 0x00000004
#define REQ_OPENDIRONLY 0x00000008
typedef struct smb_com_open_req { /* also handles create */
struct smb_hdr hdr; /* wct = 24 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u8 Reserved; /* Must Be Zero */
__u16 NameLength;
__u32 OpenFlags;
__u32 RootDirectoryFid;
__u32 DesiredAccess;
__u64 AllocationSize;
__u32 FileAttributes;
__u32 ShareAccess;
__u32 CreateDisposition;
__u32 CreateOptions;
__u32 ImpersonationLevel;
__u8 SecurityFlags;
__u16 ByteCount;
char fileName[1];
} OPEN_REQ;
typedef struct smb_com_open_rsp {
struct smb_hdr hdr; /* wct = 34 BB */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u8 OplockLevel;
__u16 Fid;
__u32 CreateAction;
__u64 CreationTime;
__u64 LastAccessTime;
__u64 LastWriteTime;
__u64 ChangeTime;
__u32 FileAttributes;
__u64 AllocationSize;
__u64 EndOfFile;
__u16 FileType;
__u16 DeviceState;
__u8 DirectoryFlag;
__u16 ByteCount; /* bct = 0 */
} OPEN_RSP;
typedef struct smb_com_write_req {
struct smb_hdr hdr; /* wct = 14 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Fid;
__u32 OffsetLow;
__u32 Reserved;
__u16 WriteMode;
__u16 Remaining;
__u16 DataLengthHigh;
__u16 DataLengthLow;
__u16 DataOffset;
__u32 OffsetHigh;
__u16 ByteCount;
__u8 Pad; /* BB check for whether padded to DWORD boundary and optimum performance here */
char Data[1];
} WRITE_REQ;
typedef struct smb_com_write_rsp {
struct smb_hdr hdr; /* wct = 6 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Count;
__u16 Remaining;
__u32 Reserved;
__u16 ByteCount;
} WRITE_RSP;
typedef struct smb_com_read_req {
struct smb_hdr hdr; /* wct = 12 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Fid;
__u32 OffsetLow;
__u16 MaxCount;
__u16 MinCount; /* obsolete */
__u32 MaxCountHigh;
__u16 Remaining;
__u32 OffsetHigh;
__u16 ByteCount;
} READ_REQ;
typedef struct smb_com_read_rsp {
struct smb_hdr hdr; /* wct = 12 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Remaining;
__u16 DataCompactionMode;
__u16 Reserved;
__u16 DataLength;
__u16 DataOffset;
__u16 DataLengthHigh;
__u64 Reserved2;
__u16 ByteCount;
__u8 Pad; /* BB check for whether padded to DWORD boundary and optimum performance here */
char Data[1];
} READ_RSP;
typedef struct locking_andx_range {
__u16 Pid;
__u16 Pad;
__u64 Offset;
__u64 Length;
} LOCKING_ANDX_RANGE;
#define LOCKING_ANDX_SHARED_LOCK 0x01
#define LOCKING_ANDX_OPLOCK_RELEASE 0x02
#define LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
#define LOCKING_ANDX_CANCEL_LOCK 0x08
#define LOCKING_ANDX_LARGE_FILES 0x10 /* always on for us */
typedef struct smb_com_lock_req {
struct smb_hdr hdr; /* wct = 8 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 Fid;
__u8 LockType;
__u8 OplockLevel;
__u32 Timeout;
__u16 NumberOfUnlocks;
__u16 NumberOfLocks;
__u16 ByteCount;
LOCKING_ANDX_RANGE Locks[1];
} LOCK_REQ;
typedef struct smb_com_lock_rsp {
struct smb_hdr hdr; /* wct = 2 */
__u8 AndXCommand;
__u8 AndXReserved;
__u16 AndXOffset;
__u16 ByteCount;
} LOCK_RSP;
typedef struct smb_com_rename_req {
struct smb_hdr hdr; /* wct = 1 */
__u16 SearchAttributes; /* target file attributes */
__u16 ByteCount;
__u8 BufferFormat; /* 4 = ASCII or Unicode */
unsigned char OldFileName[1];
/* followed by __u8 BufferFormat2 */
/* followed by NewFileName */
} RENAME_REQ;
#define CREATE_HARD_LINK 0x103
typedef struct smb_com_nt_rename_req { /* A5 - also used for create hardlink */
struct smb_hdr hdr; /* wct = 4 */
__u16 SearchAttributes; /* target file attributes */
__u16 Flags; /* spec says Information Level */
__u32 ClusterCount;
__u16 ByteCount;
__u8 BufferFormat; /* 4 = ASCII or Unicode */
unsigned char OldFileName[1];
/* followed by __u8 BufferFormat2 */
/* followed by NewFileName */
} NT_RENAME_REQ;
typedef struct smb_com_rename_rsp {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bct = 0 */
} RENAME_RSP;
typedef struct smb_com_delete_file_req {
struct smb_hdr hdr; /* wct = 1 */
__u16 SearchAttributes;
__u16 ByteCount;
__u8 BufferFormat; /* 4 = ASCII */
unsigned char fileName[1];
} DELETE_FILE_REQ;
typedef struct smb_com_delete_file_rsp {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bct = 0 */
} DELETE_FILE_RSP;
typedef struct smb_com_delete_directory_req {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount;
__u8 BufferFormat; /* 4 = ASCII */
unsigned char DirName[1];
} DELETE_DIRECTORY_REQ;
typedef struct smb_com_delete_directory_rsp {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bct = 0 */
} DELETE_DIRECTORY_RSP;
typedef struct smb_com_create_directory_req {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount;
__u8 BufferFormat; /* 4 = ASCII */
unsigned char DirName[1];
} CREATE_DIRECTORY_REQ;
typedef struct smb_com_create_directory_rsp {
struct smb_hdr hdr; /* wct = 0 */
__u16 ByteCount; /* bct = 0 */
} CREATE_DIRECTORY_RSP;
typedef struct smb_com_nt_transaction_ioctl_req {
struct smb_hdr hdr; /* wct = 23 */
__u8 MaxSetupCount;
__u16 Reserved;
__u32 TotalParameterCount;
__u32 TotalDataCount;
__u32 MaxParameterCount;
__u32 MaxDataCount;
__u32 ParameterCount;
__u32 ParameterOffset;
__u32 DataCount;
__u32 DataOffset;
__u8 SetupCount; /* four setup words follow subcommand */
/* SNIA spec incorrectly included spurious pad here */
__u16 SubCommand; /* 2 = IOCTL/FSCTL */
__u32 FunctionCode;
__u16 Fid;
__u8 IsFSCTLFlag; /* 1 = File System Control, 0 = device control (IOCTL) */
__u8 IsRootFlag; /* 1 = apply command to root of share (must be DFS share) */
__u16 ByteCount;
__u8 Pad[3];
__u8 Data[1];
} TRANSACT_IOCTL_REQ;
typedef struct smb_com_transaction_ioctl_rsp {
struct smb_hdr hdr; /* wct = 19 */
__u8 Reserved[3];
__u32 TotalParameterCount;
__u32 TotalDataCount;
__u32 ParameterCount;
__u32 ParameterOffset;
__u32 ParameterDisplacement;
__u32 DataCount;
__u32 DataOffset;
__u32 DataDisplacement;
__u8 SetupCount; /* 1 */
__u16 ReturnedDataLen;
__u16 ByteCount;
__u8 Pad[3];
} TRANSACT_IOCTL_RSP;
typedef union smb_com_transaction2 {
struct {
struct smb_hdr hdr; /* wct = 14+ */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount;
__u8 Reserved3;
__u16 SubCommand; /* 1st setup word - can be followed by SetupCount words */
__u16 ByteCount; /* careful - setupcount is not always one */
} req;
struct {
struct smb_hdr hdr; /* wct = 0 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParamterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
__u16 Reserved2; /* parameter word reserved - present for infolevels > 100 */
/* data area follows */
} resp;
} TRANSACTION2;
/* PathInfo/FileInfo infolevels */
#define SMB_INFO_STANDARD 1
#define SMB_INFO_IS_NAME_VALID 6
#define SMB_QUERY_FILE_BASIC_INFO 0x101
#define SMB_QUERY_FILE_STANDARD_INFO 0x102
#define SMB_QUERY_FILE_NAME_INFO 0x104
#define SMB_QUERY_FILE_ALLOCATION_INFO 0x105
#define SMB_QUERY_FILE_END_OF_FILEINFO 0x106
#define SMB_QUERY_FILE_ALL_INFO 0x107
#define SMB_QUERY_ALT_NAME_INFO 0x108
#define SMB_QUERY_FILE_STREAM_INFO 0x109
#define SMB_QUERY_FILE_COMPRESSION_INFO 0x10B
#define SMB_QUERY_FILE_UNIX_BASIC 0x200
#define SMB_QUERY_FILE_UNIX_LINK 0x201
#define SMB_SET_FILE_BASIC_INFO 0x101
#define SMB_SET_FILE_DISPOSITION_INFO 0x102
#define SMB_SET_FILE_ALLOCATION_INFO 0x103
#define SMB_SET_FILE_END_OF_FILE_INFO 0x104
#define SMB_SET_FILE_UNIX_BASIC 0x200
#define SMB_SET_FILE_UNIX_LINK 0x201
#define SMB_SET_FILE_UNIX_HLINK 0x203
#define SMB_SET_FILE_BASIC_INFO2 0x3ec
#define SMB_SET_FILE_ALLOCATION_INFO2 0x3fb
#define SMB_SET_FILE_END_OF_FILE_INFO2 0x3fc
/* Find File infolevels */
#define SMB_FIND_FILE_DIRECTORY_INFO 0x101
#define SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102
#define SMB_FIND_FILE_NAMES_INFO 0x103
#define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
#define SMB_FIND_FILE_UNIX 0x202
typedef struct smb_com_transaction2_qpi_req {
struct smb_hdr hdr; /* wct = 14+ */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount;
__u8 Reserved3;
__u16 SubCommand; /* one setup word */
__u16 ByteCount;
__u8 Pad;
__u16 InformationLevel;
__u32 Reserved4;
char FileName[1];
} TRANSACTION2_QPI_REQ;
typedef struct smb_com_transaction2_qpi_rsp {
struct smb_hdr hdr; /* wct = 10 + SetupCount */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
__u16 Reserved2; /* parameter word reserved - present for infolevels > 100 */
} TRANSACTION2_QPI_RSP;
typedef struct smb_com_transaction2_spi_req {
struct smb_hdr hdr; /* wct = 15 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount;
__u8 Reserved3;
__u16 SubCommand; /* one setup word */
__u16 ByteCount;
__u8 Pad;
__u16 Pad1;
__u16 InformationLevel;
__u32 Reserved4;
char FileName[1];
} TRANSACTION2_SPI_REQ;
typedef struct smb_com_transaction2_spi_rsp {
struct smb_hdr hdr; /* wct = 10 + SetupCount */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
__u16 Reserved2; /* parameter word reserved - present for infolevels > 100 */
} TRANSACTION2_SPI_RSP;
struct smb_com_transaction2_sfi_req {
struct smb_hdr hdr; /* wct = 15 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount;
__u8 Reserved3;
__u16 SubCommand; /* one setup word */
__u16 ByteCount;
__u8 Pad;
__u16 Pad1;
__u16 Fid;
__u16 InformationLevel;
__u16 Reserved4;
};
struct smb_com_transaction2_sfi_rsp {
struct smb_hdr hdr; /* wct = 10 + SetupCount */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
__u16 Reserved2; /* parameter word reserved - present for infolevels > 100 */
};
/*
* Flags on T2 FINDFIRST and FINDNEXT
*/
#define CIFS_SEARCH_CLOSE_ALWAYS 0x0001
#define CIFS_SEARCH_CLOSE_AT_END 0x0002
#define CIFS_SEARCH_RETURN_RESUME 0x0004
#define CIFS_SEARCH_CONTINUE_FROM_LAST 0x0008
#define CIFS_SEARCH_BACKUP_SEARCH 0x0010
/*
* Size of the resume key on FINDFIRST and FINDNEXT calls
*/
#define CIFS_SMB_RESUME_KEY_SIZE 4
typedef struct smb_com_transaction2_ffirst_req {
struct smb_hdr hdr; /* wct = 15 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount; /* one */
__u8 Reserved3;
__u16 SubCommand; /* TRANS2_FIND_FIRST */
__u16 ByteCount;
__u8 Pad;
__u16 SearchAttributes;
__u16 SearchCount;
__u16 SearchFlags;
__u16 InformationLevel;
__u32 SearchStorageType;
char FileName[1];
} TRANSACTION2_FFIRST_REQ;
typedef struct smb_com_transaction2_ffirst_rsp {
struct smb_hdr hdr; /* wct = 10 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
} TRANSACTION2_FFIRST_RSP;
typedef struct smb_com_transaction2_ffirst_rsp_parms {
__u16 SearchHandle;
__u16 SearchCount;
__u16 EndofSearch;
__u16 EAErrorOffset;
__u16 LastNameOffset;
} T2_FFIRST_RSP_PARMS;
typedef struct smb_com_transaction2_fnext_req {
struct smb_hdr hdr; /* wct = 15 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount; /* one */
__u8 Reserved3;
__u16 SubCommand; /* TRANS2_FIND_NEXT */
__u16 ByteCount;
__u8 Pad;
__u16 SearchHandle;
__u16 SearchCount;
__u16 InformationLevel;
__u32 ResumeKey;
__u16 SearchFlags;
char ResumeFileName[1]; /* will be null string actually since we set bit 3 - resume from previous ending place */
} TRANSACTION2_FNEXT_REQ;
typedef struct smb_com_transaction2_fnext_rsp {
struct smb_hdr hdr; /* wct = 10 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
} TRANSACTION2_FNEXT_RSP;
typedef struct smb_com_transaction2_fnext_rsp_parms {
__u16 SearchCount;
__u16 EndofSearch;
__u16 EAErrorOffset;
__u16 LastNameOffset;
} T2_FNEXT_RSP_PARMS;
#define SMB_INFO_ALLOCATION 1
#define SMB_INFO_VOLUME 2
#define SMB_QUERY_FS_VOLUME_INFO 0x102
#define SMB_QUERY_FS_SIZE_INFO 0x103
#define SMB_QUERY_FS_DEVICE_INFO 0x104
#define SMB_QUERY_FS_ATTRIBUTE_INFO 0x105
#define SMB_QUERY_CIFS_UNIX_INFO 0x200
typedef struct smb_com_transaction2_qfsi_req {
struct smb_hdr hdr; /* wct = 14+ */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount;
__u8 Reserved3;
__u16 SubCommand; /* one setup word */
__u16 ByteCount;
__u8 Pad;
__u16 InformationLevel;
} TRANSACTION2_QFSI_REQ;
typedef struct smb_com_transaction_qfsi_rsp {
struct smb_hdr hdr; /* wct = 10 + SetupCount */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* should be zero setup words following */
__u16 ByteCount;
__u8 Pad; /* may be three bytes *//* followed by data area */
} TRANSACTION2_QFSI_RSP;
typedef struct smb_com_transaction2_get_dfs_refer_req {
struct smb_hdr hdr; /* wct = 15 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 MaxParameterCount;
__u16 MaxDataCount;
__u8 MaxSetupCount;
__u8 Reserved;
__u16 Flags;
__u32 Timeout;
__u16 Reserved2;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 DataCount;
__u16 DataOffset;
__u8 SetupCount;
__u8 Reserved3;
__u16 SubCommand; /* one setup word */
__u16 ByteCount;
__u8 Pad[3]; /* Win2K has sent 0x0F01 (max resp length perhaps?) followed by one byte pad - doesnt seem to matter though */
__u16 MaxReferralLevel;
char RequestFileName[1];
} TRANSACTION2_GET_DFS_REFER_REQ;
typedef struct dfs_referral_level_3 {
__u16 VersionNumber;
__u16 ReferralSize;
__u16 ServerType; /* 0x0001 = CIFS server */
__u16 ReferralFlags; /* or proximity - not clear which since always set to zero - SNIA spec says 0x01 means strip off PathConsumed chars before submitting RequestFileName to remote node */
__u16 TimeToLive;
__u16 DfsPathOffset;
__u16 DfsAlternatePathOffset;
__u16 NetworkAddressOffset;
} REFERRAL3;
typedef struct smb_com_transaction_get_dfs_refer_rsp {
struct smb_hdr hdr; /* wct = 10 */
__u16 TotalParameterCount;
__u16 TotalDataCount;
__u16 Reserved;
__u16 ParameterCount;
__u16 ParameterOffset;
__u16 ParameterDisplacement;
__u16 DataCount;
__u16 DataOffset;
__u16 DataDisplacement;
__u8 SetupCount;
__u8 Reserved1; /* zero setup words following */
__u16 ByteCount;
__u8 Pad;
__u16 PathConsumed;
__u16 NumberOfReferrals;
__u16 DFSFlags;
__u16 Pad2;
REFERRAL3 referrals[1]; /* array of level 3 dfs_referral structures */
/* followed by the strings pointed to by the referral structures */
} TRANSACTION2_GET_DFS_REFER_RSP;
/* DFS Flags */
#define DFSREF_REFERRAL_SERVER 0x0001
#define DFSREF_STORAGE_SERVER 0x0002
/* IOCTL information */
/* List of ioctl function codes that look to be of interest to remote clients like this. */
/* Need to do some experimentation to make sure they all work remotely. */
/* Some of the following such as the encryption/compression ones would be */
/* invoked from tools via a specialized hook into the VFS rather than via the */
/* standard vfs entry points */
#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000
#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004
#define FSCTL_REQUEST_BATCH_OPLOCK 0x00090008
#define FSCTL_LOCK_VOLUME 0x00090018
#define FSCTL_UNLOCK_VOLUME 0x0009001C
#define FSCTL_GET_COMPRESSION 0x0009003C
#define FSCTL_SET_COMPRESSION 0x0009C040
#define FSCTL_REQUEST_FILTER_OPLOCK 0x0009008C
#define FSCTL_FILESYS_GET_STATISTICS 0x00090090
#define FSCTL_SET_REPARSE_POINT 0x000900A4
#define FSCTL_GET_REPARSE_POINT 0x000900A8
#define FSCTL_DELETE_REPARSE_POINT 0x000900AC
#define FSCTL_SET_SPARSE 0x000900C4
#define FSCTL_SET_ZERO_DATA 0x000900C8
#define FSCTL_SET_ENCRYPTION 0x000900D7
#define FSCTL_ENCRYPTION_FSCTL_IO 0x000900DB
#define FSCTL_WRITE_RAW_ENCRYPTED 0x000900DF
#define FSCTL_READ_RAW_ENCRYPTED 0x000900E3
#define FSCTL_SIS_COPYFILE 0x00090100
#define FSCTL_SIS_LINK_FILES 0x0009C104
#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
#define IO_REPARSE_TAG_HSM 0xC0000004
#define IO_REPARSE_TAG_SIS 0x80000007
/*
************************************************************************
* All structs for everything above the SMB PDUs themselves
* (such as the T2 level specific data) go here
************************************************************************
*/
/*
* Information on a server
*/
struct serverInfo {
char name[16];
unsigned char versionMajor;
unsigned char versionMinor;
unsigned long type;
unsigned int commentOffset;
};
/*
* The following structure is the format of the data returned on a NetShareEnum
* with level "90" (x5A)
*/
struct shareInfo {
char shareName[13];
char pad;
unsigned short type;
unsigned int commentOffset;
};
struct aliasInfo {
char aliasName[9];
char pad;
unsigned int commentOffset;
unsigned char type[2];
};
struct aliasInfo92 {
int aliasNameOffset;
int serverNameOffset;
int shareNameOffset;
};
typedef struct {
__u64 TotalAllocationUnits;
__u64 FreeAllocationUnits;
__u32 SectorsPerAllocationUnit;
__u32 BytesPerSector;
} FILE_SYSTEM_INFO; /* size info, level 0x103 */
typedef struct {
__u16 MajorVersionNumber;
__u16 MinorVersionNumber;
__u64 Capability;
} FILE_SYSTEM_UNIX_INFO; /* Unix extensions info, level 0x200 */
/* DeviceType Flags */
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_DFS 0x00000006
#define FILE_DEVICE_DISK 0x00000007
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define FILE_DEVICE_NAMED_PIPE 0x00000011
#define FILE_DEVICE_NETWORK 0x00000012
#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
#define FILE_DEVICE_NULL 0x00000015
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
#define FILE_DEVICE_PRINTER 0x00000018
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
#define FILE_DEVICE_STREAMS 0x0000001e
#define FILE_DEVICE_TAPE 0x0000001f
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
typedef struct {
__u32 DeviceType;
__u32 DeviceCharacteristics;
} FILE_SYSTEM_DEVICE_INFO; /* device info, level 0x104 */
typedef struct {
__u32 Attributes;
__u32 MaxPathNameComponentLength;
__u32 FileSystemNameLen;
char FileSystemName[52]; /* do not really need to save this - so potentially get only subset of name */
} FILE_SYSTEM_ATTRIBUTE_INFO;
typedef struct { /* data block encoding of response to level 263 QPathInfo */
__u64 CreationTime;
__u64 LastAccessTime;
__u64 LastWriteTime;
__u64 ChangeTime;
__u32 Attributes;
__u32 Pad1;
__u64 AllocationSize;
__u64 EndOfFile; /* size ie offset to first free byte in file */
__u32 NumberOfLinks; /* hard links */
__u8 DeletePending;
__u8 Directory;
__u16 Pad2;
__u64 IndexNumber;
__u32 EASize;
__u32 AccessFlags;
__u64 IndexNumber1;
__u64 CurrentByteOffset;
__u32 Mode;
__u32 AlignmentRequirement;
__u32 FileNameLength;
char FileName[1];
} FILE_ALL_INFO; /* level 263 QPathInfo */
typedef struct {
__u64 EndOfFile;
__u64 NumOfBytes;
__u64 LastStatusChange; /*SNIA spec says DCE time for the three time fields */
__u64 LastAccessTime;
__u64 LastModificationTime;
__u64 Uid;
__u64 Gid;
__u32 Type;
__u64 DevMajor;
__u64 DevMinor;
__u64 UniqueId;
__u64 Permissions;
__u64 Nlinks;
} FILE_UNIX_BASIC_INFO; /* level 512 QPathInfo */
typedef struct {
char LinkDest[1];
} FILE_UNIX_LINK_INFO; /* level 513 QPathInfo */
/* defines for enumerating possible values of the Unix type field below */
#define UNIX_FILE 0
#define UNIX_DIR 1
#define UNIX_SYMLINK 2
#define UNIX_CHARDEV 3
#define UNIX_BLOCKDEV 4
#define UNIX_FIFO 5
#define UNIX_SOCKET 6
typedef struct {
__u32 NextEntryOffset;
__u32 ResumeKey;
__u64 EndOfFile;
__u64 NumOfBytes;
__u64 LastStatusChange; /*SNIA spec says DCE time for the three time fields */
__u64 LastAccessTime;
__u64 LastModificationTime;
__u64 Uid;
__u64 Gid;
__u32 Type;
__u64 DevMajor;
__u64 DevMinor;
__u64 UniqueId;
__u64 Permissions;
__u64 Nlinks;
char FileName[1];
} FILE_UNIX_INFO;
typedef struct {
__u64 CreationTime;
__u64 LastAccessTime;
__u64 LastWriteTime;
__u64 ChangeTime;
__u32 Attributes;
__u32 Pad;
} FILE_BASIC_INFO; /* size info, level 0x101 */
struct file_allocation_info {
__u64 AllocationSize;
}; /* size info, level 0x103 */
struct file_end_of_file_info {
__u64 FileSize; /* offset to end of file */
}; /* size info, level 0x104 */
typedef struct {
__u32 NextEntryOffset;
__u32 FileIndex;
__u64 CreationTime;
__u64 LastAccessTime;
__u64 LastWriteTime;
__u64 ChangeTime;
__u64 EndOfFile;
__u64 AllocationSize;
__u32 ExtFileAttributes;
__u32 FileNameLength;
char FileName[1];
} FILE_DIRECTORY_INFO; /* level 257 FF response data area */
struct gea {
unsigned char cbName;
char szName[1];
};
struct gealist {
unsigned long cbList;
struct gea list[1];
};
struct fea {
unsigned char fEA;
unsigned char cbName;
unsigned short cbValue;
char szName[1];
};
/* flags for _FEA.fEA */
#define FEA_NEEDEA 0x80 /* need EA bit */
struct fealist {
unsigned long cbList;
struct fea list[1];
};
/* used to hold an arbitrary blob of data */
struct data_blob {
__u8 *data;
size_t length;
void (*free) (struct data_blob * data_blob);
};
#pragma pack() /* resume default structure packing */
#endif /* _CIFSPDU_H */
/*
* fs/cifs/cifsproto.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _CIFSPROTO_H
#define _CIFSPROTO_H
#include <linux/nls.h>
/*
*****************************************************************
* All Prototypes
*****************************************************************
*/
extern struct smb_hdr *buf_get(void);
extern void buf_release(void *);
extern int smb_send(struct socket *, struct smb_hdr *,
unsigned int /* length */ , struct sockaddr *);
extern unsigned int _GetXid(void);
extern void _FreeXid(unsigned int);
#define GetXid() (int)_GetXid(); cFYI(1,("\nCIFS VFS: in %s as Xid: %d with uid: %d",__FUNCTION__, xid,current->fsuid));
#define FreeXid(curr_xid) {_FreeXid(curr_xid); cFYI(1,("\nCIFS VFS: leaving %s (xid = %d) rc = %d\n",__FUNCTION__,curr_xid,rc));}
extern char *build_path_from_dentry(struct dentry *);
extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
extern void renew_parental_timestamps(struct dentry *direntry);
extern void *kcalloc(size_t mem, int type);
extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *,
struct smb_hdr * /* input */ ,
struct smb_hdr * /* out */ ,
int * /* bytes returned */ , const int long_op);
extern int checkSMBhdr(struct smb_hdr *smb, __u16 mid);
extern int checkSMB(struct smb_hdr *smb, __u16 mid, int length);
extern int is_valid_oplock_break(struct smb_hdr *smb);
extern int smbCalcSize(struct smb_hdr *ptr);
extern int decode_negTokenInit(unsigned char *security_blob, int length,
enum securityEnum *secType);
extern int map_smb_to_linux_error(struct smb_hdr *smb);
extern void header_assemble(struct smb_hdr *, char /* command */ ,
const struct cifsTconInfo *, int
/* length of fixed section (word count) in two byte units */
);
extern time_t cifs_NTtimeToUnix(u64 /* utc nanoseconds since 1601 */ );
extern u64 cifs_UnixTimeToNT(time_t);
extern void RevUcode_to_Ucode(char *revUnicode, char *UnicodeName);
extern void Ucode_to_RevUcode(char *Unicode, char *revUnicodeName);
extern void RevUcode_to_Ucode_with_Len(char *revUnicode, char *UnicodeName,
int Len);
extern void Ucode_to_RevUcode_with_Len(char *Unicode, char *revUnicodeName,
int Len);
extern int cifs_get_inode_info(struct inode **pinode,
const unsigned char *search_path,
struct super_block *sb);
extern int cifs_get_inode_info_unix(struct inode **pinode,
const unsigned char *search_path,
struct super_block *sb);
extern int CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses,
char cryptokey[CIFS_CRYPTO_KEY_SIZE]);
extern int CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
char *user, char *domain,
char *session_key, char *ntlm_session_key,
const struct nls_table *);
extern int CIFSSpnegoSessSetup(unsigned int xid, struct cifsSesInfo *ses,
char *user, char *domain,
char *SecurityBlob,
int SecurityBlobLength,
const struct nls_table *);
extern int CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
struct cifsSesInfo *ses,
char *domain,
char *ntlm_session_key,
int *ntlmv2_flag,
const struct nls_table *);
extern int CIFSNTLMSSPAuthSessSetup(unsigned int xid,
struct cifsSesInfo *ses, char *user,
char *domain, char *ntlm_session_key,
char *lanman_session_key,
int ntlmv2_flag,
const struct nls_table *);
extern int CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
const char *tree, struct cifsTconInfo *tcon,
const struct nls_table *);
extern int CIFSFindFirst(const int xid, const struct cifsTconInfo *tcon,
const char *searchName,
FILE_DIRECTORY_INFO * findData,
T2_FFIRST_RSP_PARMS * findParms,
const struct nls_table *nls_codepage,
int *pUnicodeFlag,
int *pUnixFlag /* if Unix extensions used */ );
extern int CIFSFindNext(const int xid, const struct cifsTconInfo *tcon,
FILE_DIRECTORY_INFO * findData,
T2_FNEXT_RSP_PARMS * findParms,
const __u16 searchHandle, const __u32 resumeKey,
int *UnicodeFlag, int *pUnixFlag);
extern int CIFSSMBQPathInfo(const int xid, const struct cifsTconInfo *tcon,
const unsigned char *searchName,
FILE_ALL_INFO * findData,
const struct nls_table *nls_codepage);
extern int CIFSSMBUnixQPathInfo(const int xid,
const struct cifsTconInfo *tcon,
const unsigned char *searchName,
FILE_UNIX_BASIC_INFO * pFindData,
const struct nls_table *nls_codepage);
extern int CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses,
const unsigned char *searchName,
unsigned char **targetUNCs,
int *number_of_UNC_in_array,
const struct nls_table *nls_codepage);
extern int connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
const char *old_path,
const struct nls_table *nls_codepage);
extern int CIFSSMBQFSInfo(const int xid, const struct cifsTconInfo *tcon,
struct statfs *FSData,
const struct nls_table *nls_codepage);
extern int CIFSSMBQFSAttributeInfo(const int xid,
struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage);
extern int CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage);
extern int CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage);
extern int CIFSSMBSetTimes(const int xid, struct cifsTconInfo *tcon,
char *fileName, FILE_BASIC_INFO * data,
const struct nls_table *nls_codepage);
extern int CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon,
char *fileName, __u64 size,int setAllocationSizeFlag,
const struct nls_table *nls_codepage);
extern int CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon,
__u64 size, __u16 fileHandle,__u32 opener_pid, int AllocSizeFlag);
extern int CIFSSMBUnixSetPerms(const int xid, struct cifsTconInfo *pTcon,
char *full_path, __u64 mode, __u64 uid,
__u64 gid, const struct nls_table *nls_codepage);
extern int CIFSSMBMkDir(const int xid, const struct cifsTconInfo *tcon,
const char *newName,
const struct nls_table *nls_codepage);
extern int CIFSSMBRmDir(const int xid, const struct cifsTconInfo *tcon,
const char *name, const struct nls_table *nls_codepage);
extern int CIFSSMBDelFile(const int xid, const struct cifsTconInfo *tcon,
const char *name,
const struct nls_table *nls_codepage);
extern int CIFSSMBRename(const int xid, const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage);
extern int CIFSCreateHardLink(const int xid,
const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage);
extern int CIFSUnixCreateHardLink(const int xid,
const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage);
extern int CIFSUnixCreateSymLink(const int xid,
const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage);
extern int CIFSSMBUnixQuerySymLink(const int xid,
const struct cifsTconInfo *tcon,
const unsigned char *searchName,
char *syminfo, const int buflen,
const struct nls_table *nls_codepage);
extern int CIFSSMBOpen(const int xid, const struct cifsTconInfo *tcon,
const char *fileName, const int disposition,
const int access_flags, const int omode,
__u16 * netfid, int *pOplock,
const struct nls_table *nls_codepage);
extern int CIFSSMBClose(const int xid, const struct cifsTconInfo *tcon,
const int smb_file_id);
extern int CIFSSMBRead(const int xid, const struct cifsTconInfo *tcon,
const int netfid, unsigned int count,
const __u64 lseek, unsigned int *nbytes, char *buf);
extern int CIFSSMBWrite(const int xid, const struct cifsTconInfo *tcon,
const int netfid, const unsigned int count,
const __u64 lseek, unsigned int *nbytes,
const char *buf, const int long_op);
extern int CIFSSMBLock(const int xid, const struct cifsTconInfo *tcon,
const __u16 netfid, const __u64 len,
const __u64 offset, const __u32 numUnlock,
const __u32 numLock, const __u8 lockType,
const int waitFlag);
extern int CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon);
extern int CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses);
extern struct cifsSesInfo *sesInfoAlloc(void);
extern void sesInfoFree(struct cifsSesInfo *);
extern struct cifsTconInfo *tconInfoAlloc(void);
extern void tconInfoFree(struct cifsTconInfo *);
extern int cifs_demultiplex_thread(struct TCP_Server_Info *);
extern int cifs_reconnect(struct TCP_Server_Info *server);
/* BB routines below not implemented yet BB */
extern int CIFSBuildServerList(int xid, char *serverBufferList,
int recordlength, int *entries,
int *totalEntries, int *topoChangedFlag);
extern int CIFSSMBQueryShares(int xid, struct cifsTconInfo *tcon,
struct shareInfo *shareList, int bufferLen,
int *entries, int *totalEntries);
extern int CIFSSMBQueryAlias(int xid, struct cifsTconInfo *tcon,
struct aliasInfo *aliasList, int bufferLen,
int *entries, int *totalEntries);
extern int CIFSSMBAliasInfo(int xid, struct cifsTconInfo *tcon,
char *aliasName, char *serverName,
char *shareName, char *comment);
extern int CIFSSMBGetShareInfo(int xid, struct cifsTconInfo *tcon,
char *share, char *comment);
extern int CIFSSMBGetUserPerms(int xid, struct cifsTconInfo *tcon,
char *userName, char *searchName, int *perms);
extern int CIFSSMBSync(int xid, struct cifsTconInfo *tcon, int netfid, int pid);
extern int CIFSSMBSeek(int xid,
struct cifsTconInfo *tcon,
int netfid,
int pid,
int whence, unsigned long offset, long long *newoffset);
extern int CIFSSMBCopy(int xid,
struct cifsTconInfo *ftcon,
char *fromName,
struct cifsTconInfo *ttcon,
char *toName, int ofun, int flags);
#endif /* _CIFSPROTO_H */
/*
* fs/cifs/cifssmb.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* Contains the routines for constructing the SMB PDUs themselves
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* All SMB/CIFS PDU handling routines go here - except for a few leftovers in connect.c */
#include <linux/fs.h>
#include <linux/kernel.h>
#include <asm/uaccess.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_unicode.h"
#include "cifs_debug.h"
static struct {
int index;
char *name;
} protocols[] = {
{
CIFS_PROT, "\2NT LM 0.12"}, {
BAD_PROT, "\2"}
};
int
smb_init(int smb_command, int wct, const struct cifsTconInfo *tcon,
void **request_buf /* returned */ ,
void **response_buf /* returned */ )
{
int rc = 0;
*request_buf = buf_get();
if (request_buf == 0) {
return -ENOMEM;
}
/* Although the original thought was we needed the response buf for */
/* potential retries of smb operations it turns out we can determine */
/* from the mid flags when the request buffer can be resent without */
/* having to use a second distinct buffer for the response */
*response_buf = *request_buf;
header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon,
wct /*wct */ );
return rc;
}
int
CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses,
char cryptokey[CIFS_CRYPTO_KEY_SIZE])
{
NEGOTIATE_REQ *pSMB;
NEGOTIATE_RSP *pSMBr;
int rc = 0;
int bytes_returned;
rc = smb_init(SMB_COM_NEGOTIATE, 0, 0 /* no tcon yet */ ,
(void **) &pSMB, (void **) &pSMBr);
if (rc)
return rc;
pSMB->hdr.Flags2 |= SMBFLG2_UNICODE;
if (extended_security)
pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
if (sign_CIFS_PDUs) {
pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
}
pSMB->ByteCount = strlen(protocols[0].name) + 1;
strncpy(pSMB->DialectsArray, protocols[0].name, 30); /* null guaranteed to be at end of source and target buffers anyway */
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc == 0) {
ses->dialectIndex = le16_to_cpu(pSMBr->DialectIndex);
ses->secMode = pSMBr->SecurityMode; /* one byte - no need to convert this or EncryptionKeyLen field from le, */
ses->maxReq = le16_to_cpu(pSMBr->MaxMpxCount);
/* probably no need to store and check maxvcs */
ses->maxBuf =
min(le32_to_cpu(pSMBr->MaxBufferSize),
(__u32) CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE);
ses->maxRw = le32_to_cpu(pSMBr->MaxRawSize); /* BB le_to_host needed around here and ff */
cFYI(1, ("\nMax buf = %d ", ses->maxBuf));
GETU32(ses->sessid) = le32_to_cpu(pSMBr->SessionKey);
ses->capabilities = le32_to_cpu(pSMBr->Capabilities);
ses->timeZone = le16_to_cpu(pSMBr->ServerTimeZone); /* BB with UTC do we ever need to be using srvr timezone? */
if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) {
memcpy(cryptokey, pSMBr->u.EncryptionKey,
CIFS_CRYPTO_KEY_SIZE);
} else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC)
&& (pSMBr->EncryptionKeyLength == 0)) {
/* decode security blob */
} else
rc = -EIO;
/* BB might be helpful to save off the domain of server here */
if (pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) {
if (pSMBr->ByteCount < 16)
rc = -EIO;
else if (pSMBr->ByteCount == 16) {
ses->secType = RawNTLMSSP;
if (ses->server->socketUseCount.counter > 1) {
if (memcmp
(ses->server->server_GUID,
pSMBr->u.extended_response.
GUID, 16) != 0) {
cFYI(1,
("UID of server does not match that of previous connection to same ip address"));
memcpy(ses->server->
server_GUID,
pSMBr->u.
extended_response.
GUID, 16);
}
} else
memcpy(ses->server->server_GUID,
pSMBr->u.extended_response.
GUID, 16);
} else {
rc = decode_negTokenInit(pSMBr->u.
extended_response.
SecurityBlob,
pSMBr->ByteCount -
16, &ses->secType);
}
} else
ses->capabilities &= ~CAP_EXTENDED_SECURITY;
if(sign_CIFS_PDUs == FALSE) {
if(ses->secMode & SECMODE_SIGN_REQUIRED)
cERROR(1,("\nServer required CIFS packet signing - enable /proc/fs/cifs/PacketSigningEnabled"));
ses->secMode &= ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED);
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
{
struct smb_hdr *smb_buffer;
struct smb_hdr *smb_buffer_response;
int rc = 0;
int length;
cFYI(1, ("\nIn tree disconnect"));
/*
* If last user of the connection and
* connection alive - disconnect it
* If this is the last connection on the server session disconnect it
* (and inside session disconnect we should check if tcp socket needs to
* be freed and kernel thread woken up).
*/
if (tcon)
down(&tcon->tconSem);
else
return -EIO;
atomic_dec(&tcon->useCount);
if (atomic_read(&tcon->useCount) > 0) {
up(&tcon->tconSem);
return -EBUSY;
}
/* BB remove (from server) list of shares - but with smp safety BB */
/* BB is ses active - do we need to check here - but how? BB */
rc = smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon,
(void **) &smb_buffer, (void **) &smb_buffer_response);
if (rc) {
up(&tcon->tconSem);
return rc;
}
rc = SendReceive(xid, tcon->ses, smb_buffer, smb_buffer_response,
&length, 0);
if (rc)
cFYI(1, (" Tree disconnect failed %d", rc));
if (smb_buffer)
buf_release(smb_buffer);
up(&tcon->tconSem);
return rc;
}
int
CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
{
struct smb_hdr *smb_buffer_response;
LOGOFF_ANDX_REQ *pSMB;
int rc = 0;
int length;
cFYI(1, ("\nIn SMBLogoff for session disconnect"));
if (ses)
down(&ses->sesSem); /* need to add more places where this sem is checked */
else
return -EIO;
atomic_dec(&ses->inUse);
if (atomic_read(&ses->inUse) > 0) {
up(&ses->sesSem);
return -EBUSY;
}
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
rc = smb_init(SMB_COM_LOGOFF_ANDX, 2, 0 /* no tcon anymore */ ,
(void **) &pSMB, (void **) &smb_buffer_response);
if (rc) {
up(&ses->sesSem);
return rc;
}
pSMB->hdr.Uid = ses->Suid;
pSMB->AndXCommand = 0xFF;
rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB,
smb_buffer_response, &length, 0);
if (ses->server) {
atomic_dec(&ses->server->socketUseCount);
if (atomic_read(&ses->server->socketUseCount) == 0)
ses->server->tcpStatus = CifsExiting;
}
if (pSMB)
buf_release(pSMB);
up(&ses->sesSem);
return rc;
}
int
CIFSSMBDelFile(const int xid, const struct cifsTconInfo *tcon,
const char *fileName, const struct nls_table *nls_codepage)
{
DELETE_FILE_REQ *pSMB = NULL;
DELETE_FILE_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->fileName, fileName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fileName, 530);
name_len++; /* trailing null */
strncpy(pSMB->fileName, fileName, name_len);
}
pSMB->SearchAttributes =
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM);
pSMB->ByteCount = name_len + 1;
pSMB->BufferFormat = 0x04;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in RMFile = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBRmDir(const int xid, const struct cifsTconInfo *tcon,
const char *dirName, const struct nls_table *nls_codepage)
{
DELETE_DIRECTORY_REQ *pSMB = NULL;
DELETE_DIRECTORY_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn CIFSSMBRmDir"));
rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len = cifs_strtoUCS((wchar_t *) pSMB->DirName, dirName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(dirName, 530);
name_len++; /* trailing null */
strncpy(pSMB->DirName, dirName, name_len);
}
pSMB->ByteCount = name_len + 1;
pSMB->BufferFormat = 0x04;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in RMDir = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBMkDir(const int xid, const struct cifsTconInfo *tcon,
const char *name, const struct nls_table *nls_codepage)
{
int rc = 0;
CREATE_DIRECTORY_REQ *pSMB = NULL;
CREATE_DIRECTORY_RSP *pSMBr = NULL;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn CIFSSMBMkDir"));
rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len = cifs_strtoUCS((wchar_t *) pSMB->DirName, name, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(name, 530);
name_len++; /* trailing null */
strncpy(pSMB->DirName, name, name_len);
}
pSMB->ByteCount = name_len + 1 /* for buf format */ ;
pSMB->BufferFormat = 0x04;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in RMDir = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBOpen(const int xid, const struct cifsTconInfo *tcon,
const char *fileName, const int openDisposition,
const int access_flags, const int omode, __u16 * netfid,
int *pOplock, const struct nls_table *nls_codepage)
{
int rc = -EACCES;
OPEN_REQ *pSMB = NULL;
OPEN_RSP *pSMBr = NULL;
int bytes_returned;
int name_len;
rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->AndXCommand = 0xFF; /* none */
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
pSMB->ByteCount = 1; /* account for one byte pad to word boundary */
name_len =
cifs_strtoUCS((wchar_t *) (pSMB->fileName + 1),
fileName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
pSMB->NameLength = cpu_to_le16(name_len);
} else { /* BB improve the check for buffer overruns BB */
pSMB->ByteCount = 0; /* no pad */
name_len = strnlen(fileName, 530);
name_len++; /* trailing null */
pSMB->NameLength = cpu_to_le16(name_len);
strncpy(pSMB->fileName, fileName, name_len);
}
if (*pOplock)
pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK);
pSMB->DesiredAccess = cpu_to_le32(access_flags);
pSMB->AllocationSize = 0;
pSMB->FileAttributes = ATTR_NORMAL; /* XP does not handle ATTR_POSIX_SEMANTICS */
/*if ((omode & S_IWUGO) == 0)
pSMB->FileAttributes |= ATTR_READONLY;*/
/* Above line causes problems due to problem with vfs splitting create into
two pieces - need to set mode after file created not while it is being created */
pSMB->FileAttributes = cpu_to_le32(pSMB->FileAttributes);
pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL);
pSMB->CreateDisposition = cpu_to_le32(openDisposition);
pSMB->CreateOptions = cpu_to_le32(CREATE_NOT_DIR); /* BB what are these? BB */
pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); /* BB ?? BB */
pSMB->SecurityFlags =
cpu_to_le32(SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY);
pSMB->ByteCount += name_len;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in Open = %d\n", rc));
} else {
*pOplock = pSMBr->OplockLevel; /* one byte no need to le_to_cpu */
*netfid = pSMBr->Fid; /* cifs fid stays in le */
/* Do we care about the CreateAction in any cases? */
/* BB add code to update inode with file sizes from create response */
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBRead(const int xid, const struct cifsTconInfo *tcon,
const int netfid, const unsigned int count,
const __u64 lseek, unsigned int *nbytes, char *buf)
{
int rc = -EACCES;
READ_REQ *pSMB = NULL;
READ_RSP *pSMBr = NULL;
char *pReadData;
int bytes_returned;
rc = smb_init(SMB_COM_READ_ANDX, 12, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->AndXCommand = 0xFF; /* none */
pSMB->Fid = netfid;
pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF);
pSMB->OffsetHigh = cpu_to_le32(lseek >> 32);
pSMB->Remaining = 0;
pSMB->MaxCount = cpu_to_le16(min(count,
(tcon->ses->maxBuf -
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00));
pSMB->MaxCountHigh = 0;
pSMB->ByteCount = 0; /* no need to do le conversion since it is 0 */
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in read = %d\n", rc));
*nbytes = 0;
} else {
pSMBr->DataLength = le16_to_cpu(pSMBr->DataLength);
*nbytes = pSMBr->DataLength;
/* BB check that DataLength would not go beyond end of SMB BB */
/* if(pSMBr->DataOffset < pSMBr->ByteCount + sizeof(READ_RSP) - 1 *//* BB fix this length check */
if (pSMBr->DataLength > CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE) {
rc = -EIO;
*nbytes = 0;
} else {
pReadData =
(char *) (&pSMBr->hdr.Protocol) +
le16_to_cpu(pSMBr->DataOffset);
copy_to_user(buf, pReadData, pSMBr->DataLength);
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBWrite(const int xid, const struct cifsTconInfo *tcon,
const int netfid, const unsigned int count,
const __u64 offset, unsigned int *nbytes, const char *buf,
const int long_op)
{
int rc = -EACCES;
WRITE_REQ *pSMB = NULL;
WRITE_RSP *pSMBr = NULL;
int bytes_returned;
rc = smb_init(SMB_COM_WRITE_ANDX, 14, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->AndXCommand = 0xFF; /* none */
pSMB->Fid = netfid;
pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF);
pSMB->OffsetHigh = cpu_to_le32(offset >> 32);
pSMB->Remaining = 0;
if (count > ((tcon->ses->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFF00))
pSMB->DataLengthLow =
(tcon->ses->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFF00;
else
pSMB->DataLengthLow = count;
pSMB->DataLengthHigh = 0;
pSMB->DataOffset =
cpu_to_le16((int) &(pSMB->Data) - (int) pSMB->hdr.Protocol);
copy_from_user(pSMB->Data, buf, pSMB->DataLengthLow);
pSMB->ByteCount += pSMB->DataLengthLow + 1 /* pad */ ;
pSMB->DataLengthLow = cpu_to_le16(pSMB->DataLengthLow);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, long_op);
if (rc) {
cERROR(1, ("\nSend error in write = %d\n", rc));
*nbytes = 0;
} else
*nbytes = le16_to_cpu(pSMBr->Count);
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBLock(const int xid, const struct cifsTconInfo *tcon,
const __u16 smb_file_id, const __u64 len,
const __u64 offset, const __u32 numUnlock,
const __u32 numLock, const __u8 lockType, const int waitFlag)
{
int rc = 0;
LOCK_REQ *pSMB = NULL;
LOCK_RSP *pSMBr = NULL;
int bytes_returned;
cFYI(1, ("\nIn CIFSSMBLock"));
rc = smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->NumberOfLocks = cpu_to_le32(numLock);
pSMB->NumberOfUnlocks = cpu_to_le32(numUnlock);
pSMB->LockType = lockType;
pSMB->AndXCommand = 0xFF; /* none */
pSMB->Fid = smb_file_id; /* netfid stays le */
pSMB->Locks[0].Pid = cpu_to_le16(current->pid);
pSMB->Locks[0].Length = cpu_to_le64(len);
pSMB->Locks[0].Offset = cpu_to_le64(offset);
pSMB->ByteCount = sizeof (LOCKING_ANDX_RANGE);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in Lock = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBClose(const int xid, const struct cifsTconInfo *tcon, int smb_file_id)
{
int rc = 0;
CLOSE_REQ *pSMB = NULL;
CLOSE_RSP *pSMBr = NULL;
int bytes_returned;
cFYI(1, ("\nIn CIFSSMBClose"));
rc = smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->FileID = (__u16) smb_file_id;
pSMB->LastWriteTime = 0;
pSMB->ByteCount = 0;
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in Close = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBRename(const int xid, const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage)
{
int rc = 0;
RENAME_REQ *pSMB = NULL;
RENAME_RSP *pSMBr = NULL;
int bytes_returned;
int name_len, name_len2;
cFYI(1, ("\nIn CIFSSMBRename"));
rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->BufferFormat = 0x04;
pSMB->SearchAttributes =
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
ATTR_DIRECTORY);
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->OldFileName, fromName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
pSMB->OldFileName[name_len] = 0; /* pad */
pSMB->OldFileName[name_len + 1] = 0x04; /* strange that protocol requires an ASCII signature byte on Unicode string */
name_len2 =
cifs_strtoUCS((wchar_t *) & pSMB->
OldFileName[name_len + 2], toName, 530,
nls_codepage);
name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
name_len2 *= 2; /* convert to bytes */
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fromName, 530);
name_len++; /* trailing null */
strncpy(pSMB->OldFileName, fromName, name_len);
name_len2 = strnlen(toName, 530);
name_len2++; /* trailing null */
pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */
strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2);
name_len2++; /* trailing null */
name_len2++; /* signature byte */
}
pSMB->ByteCount = 1 /* 1st signature byte */ + name_len + name_len2; /* we could also set search attributes but not needed */
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in RMDir = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSUnixCreateSymLink(const int xid, const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage)
{
TRANSACTION2_SPI_REQ *pSMB = NULL;
TRANSACTION2_SPI_RSP *pSMBr = NULL;
char *data_offset;
int name_len;
int name_len_target;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn Symlink Unix style"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, fromName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fromName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, fromName, name_len);
}
pSMB->ParameterCount = 6 + name_len;
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
(int) &(pSMB->InformationLevel) - (int) pSMB->hdr.Protocol;
pSMB->DataOffset = pSMB->ParameterOffset + pSMB->ParameterCount;
data_offset = (char *) (&pSMB->hdr.Protocol) + pSMB->DataOffset;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len_target =
cifs_strtoUCS((wchar_t *) data_offset, toName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len_target++; /* trailing null */
name_len_target *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len_target = strnlen(toName, 530);
name_len_target++; /* trailing null */
strncpy(data_offset, toName, name_len_target);
}
pSMB->DataCount = name_len_target;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);
pSMB->ByteCount = 3 /* pad */ + pSMB->ParameterCount + pSMB->DataCount;
pSMB->DataCount = cpu_to_le16(pSMB->DataCount);
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->ParameterOffset = cpu_to_le16(pSMB->ParameterOffset);
pSMB->DataOffset = cpu_to_le16(pSMB->DataOffset);
pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1,
("\nSend error in SetPathInfo (create symlink) = %d\n",
rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSUnixCreateHardLink(const int xid, const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage)
{
TRANSACTION2_SPI_REQ *pSMB = NULL;
TRANSACTION2_SPI_RSP *pSMBr = NULL;
char *data_offset;
int name_len;
int name_len_target;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn Create Hard link Unix style"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len = cifs_strtoUCS((wchar_t *) pSMB->FileName, toName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(toName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, toName, name_len);
}
pSMB->ParameterCount = 6 + name_len;
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
(int) &(pSMB->InformationLevel) - (int) pSMB->hdr.Protocol;
pSMB->DataOffset = pSMB->ParameterOffset + pSMB->ParameterCount;
data_offset = (char *) (&pSMB->hdr.Protocol) + pSMB->DataOffset;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len_target =
cifs_strtoUCS((wchar_t *) data_offset, fromName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len_target++; /* trailing null */
name_len_target *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len_target = strnlen(fromName, 530);
name_len_target++; /* trailing null */
strncpy(data_offset, fromName, name_len_target);
}
pSMB->DataCount = name_len_target;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);
pSMB->ByteCount = 3 /* pad */ + pSMB->ParameterCount + pSMB->DataCount;
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->DataCount = cpu_to_le16(pSMB->DataCount);
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->ParameterOffset = cpu_to_le16(pSMB->ParameterOffset);
pSMB->DataOffset = cpu_to_le16(pSMB->DataOffset);
pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in SetPathInfo (hard link) = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSCreateHardLink(const int xid, const struct cifsTconInfo *tcon,
const char *fromName, const char *toName,
const struct nls_table *nls_codepage)
{
int rc = 0;
NT_RENAME_REQ *pSMB = NULL;
RENAME_RSP *pSMBr = NULL;
int bytes_returned;
int name_len, name_len2;
cFYI(1, ("\nIn CIFSCreateHardLink"));
rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->SearchAttributes =
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
ATTR_DIRECTORY);
pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK);
pSMB->ClusterCount = 0;
pSMB->BufferFormat = 0x04;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->OldFileName, fromName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
pSMB->OldFileName[name_len] = 0; /* pad */
pSMB->OldFileName[name_len + 1] = 0x04; /* strange that protocol requires an ASCII signature byte on Unicode string */
name_len2 =
cifs_strtoUCS((wchar_t *) & pSMB->
OldFileName[name_len + 2], toName, 530,
nls_codepage);
name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
name_len2 *= 2; /* convert to bytes */
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fromName, 530);
name_len++; /* trailing null */
strncpy(pSMB->OldFileName, fromName, name_len);
name_len2 = strnlen(toName, 530);
name_len2++; /* trailing null */
pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */
strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2);
name_len2++; /* trailing null */
name_len2++; /* signature byte */
}
pSMB->ByteCount = 1 /* string type byte */ + name_len + name_len2;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in hard link (NT rename) = %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBUnixQuerySymLink(const int xid, const struct cifsTconInfo *tcon,
const unsigned char *searchName,
char *symlinkinfo, const int buflen,
const struct nls_table *nls_codepage)
{
/* SMB_QUERY_FILE_UNIX_LINK */
TRANSACTION2_QPI_REQ *pSMB = NULL;
TRANSACTION2_QPI_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn QPathSymLinkInfo (Unix) the path %s", searchName));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, searchName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(searchName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, searchName, name_len);
}
pSMB->TotalParameterCount =
2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ;
pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
cpu_to_le16((int) &(pSMB->InformationLevel) -
(int) pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION);
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in QuerySymLinkInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = le16_to_cpu(pSMBr->DataOffset);
pSMBr->DataCount = le16_to_cpu(pSMBr->DataCount);
if ((pSMBr->ByteCount < 2) || (pSMBr->DataOffset > 512)) /* BB also check enough total bytes returned */
rc = -EIO; /* bad smb */
else {
if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len = UniStrnlen((wchar_t *) ((char *)
&pSMBr->hdr.
Protocol +
pSMBr->
DataOffset),
min(buflen,
(int) pSMBr->
DataCount) / 2);
cifs_strfromUCS_le(symlinkinfo,
(wchar_t *) ((char *)
&pSMBr->
hdr.
Protocol +
pSMBr->
DataOffset),
name_len, nls_codepage);
} else {
strncpy(symlinkinfo,
(char *) &pSMBr->hdr.Protocol +
pSMBr->DataOffset, min(buflen, (int)
pSMBr->
DataCount));
}
symlinkinfo[buflen] = 0; /* just in case so the calling code does not go off the end of the buffer */
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBQPathInfo(const int xid, const struct cifsTconInfo *tcon,
const unsigned char *searchName,
FILE_ALL_INFO * pFindData,
const struct nls_table *nls_codepage)
{
/* level 263 SMB_QUERY_FILE_ALL_INFO */
TRANSACTION2_QPI_REQ *pSMB = NULL;
TRANSACTION2_QPI_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn QPathInfo path %s", searchName));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, searchName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(searchName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, searchName, name_len);
}
pSMB->TotalParameterCount = 2 /* level */ + 4 /* reserved */ +
name_len /* includes null */ ;
pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset = cpu_to_le16((int) &(pSMB->InformationLevel)
- (int) pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION);
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in QPathInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = le16_to_cpu(pSMBr->DataOffset);
if ((pSMBr->ByteCount < 40) || (pSMBr->DataOffset > 512)) /* BB also check enough total bytes returned */
rc = -EIO; /* bad smb */
else {
memcpy((char *) pFindData,
(char *) &pSMBr->hdr.Protocol +
pSMBr->DataOffset, sizeof (FILE_ALL_INFO));
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBUnixQPathInfo(const int xid, const struct cifsTconInfo *tcon,
const unsigned char *searchName,
FILE_UNIX_BASIC_INFO * pFindData,
const struct nls_table *nls_codepage)
{
/* SMB_QUERY_FILE_UNIX_BASIC */
TRANSACTION2_QPI_REQ *pSMB = NULL;
TRANSACTION2_QPI_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn QPathInfo (Unix) the path %s", searchName));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, searchName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(searchName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, searchName, name_len);
}
pSMB->TotalParameterCount = 2 /* level */ + 4 /* reserved */ +
name_len /* includes null */ ;
pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
cpu_to_le16((int) &(pSMB->InformationLevel) -
(int) pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION);
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in QPathInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = le16_to_cpu(pSMBr->DataOffset);
if ((pSMBr->ByteCount < 40) || (pSMBr->DataOffset > 512)) /* BB also check enough total bytes returned */
rc = -EIO; /* bad smb */
else {
memcpy((char *) pFindData,
(char *) &pSMBr->hdr.Protocol +
pSMBr->DataOffset,
sizeof (FILE_UNIX_BASIC_INFO));
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSFindSingle(const int xid, const struct cifsTconInfo *tcon,
const char *searchName, FILE_ALL_INFO * findData,
const struct nls_table *nls_codepage)
{
/* level 257 SMB_ */
TRANSACTION2_FFIRST_REQ *pSMB = NULL;
TRANSACTION2_FFIRST_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn FindUnique"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, searchName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(searchName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, searchName, name_len);
}
pSMB->TotalParameterCount = 12 + name_len /* includes null */ ;
pSMB->TotalDataCount = 0; /* no EAs */
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
cpu_to_le16((int) &pSMB->InformationLevel -
(int) &pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1; /* one byte, no need to le convert */
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST);
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalDataCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->SearchAttributes =
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
ATTR_DIRECTORY);
pSMB->SearchCount = cpu_to_le16(16); /* BB increase */
pSMB->SearchFlags = cpu_to_le16(1);
pSMB->InformationLevel = cpu_to_le16(SMB_FIND_FILE_DIRECTORY_INFO);
pSMB->SearchStorageType = 0; /* BB what should we set this to? BB */
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in FindFileDirInfo = %d\n", rc));
} else { /* decode response */
/* BB fill in */
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSFindFirst(const int xid, const struct cifsTconInfo *tcon,
const char *searchName, FILE_DIRECTORY_INFO * findData,
T2_FFIRST_RSP_PARMS * findParms,
const struct nls_table *nls_codepage, int *pUnicodeFlag,
int *pUnixFlag)
{
/* level 257 SMB_ */
TRANSACTION2_FFIRST_REQ *pSMB = NULL;
TRANSACTION2_FFIRST_RSP *pSMBr = NULL;
char *response_data;
int rc = 0;
int bytes_returned;
int name_len;
cFYI(1, ("\nIn FindFirst"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, searchName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(searchName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, searchName, name_len);
}
pSMB->TotalParameterCount = 12 + name_len /* includes null */ ;
pSMB->TotalDataCount = 0; /* no EAs */
pSMB->MaxParameterCount = cpu_to_le16(10);
pSMB->MaxDataCount = cpu_to_le16((tcon->ses->maxBuf -
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->ParameterOffset =
cpu_to_le16((int) &pSMB->SearchAttributes -
(int) &pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1; /* one byte no need to make endian neutral */
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST);
pSMB->SearchAttributes =
cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
ATTR_DIRECTORY);
pSMB->SearchCount = cpu_to_le16(CIFS_MAX_MSGSIZE / sizeof (FILE_DIRECTORY_INFO)); /* should this be shrunk even more ? */
pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END);
/* test for Unix extensions */
if (tcon->ses->capabilities & CAP_UNIX) {
pSMB->InformationLevel = cpu_to_le16(SMB_FIND_FILE_UNIX);
*pUnixFlag = TRUE;
} else {
pSMB->InformationLevel =
cpu_to_le16(SMB_FIND_FILE_DIRECTORY_INFO);
*pUnixFlag = FALSE;
}
pSMB->SearchStorageType = 0; /* BB what should we set this to? It is not clear if it matters BB */
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) { /* BB add logic to retry regular search if Unix search rejected unexpectedly by server */
cFYI(1, ("\nError in FindFirst = %d\n", rc));
} else { /* decode response */
/* BB add safety checks for these memcpys */
if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE)
*pUnicodeFlag = TRUE;
else
*pUnicodeFlag = FALSE;
memcpy(findParms,
(char *) &pSMBr->hdr.Protocol +
le16_to_cpu(pSMBr->ParameterOffset),
sizeof (T2_FFIRST_RSP_PARMS));
/* search handle can stay LE and EAoffset not needed so not converted */
findParms->EndofSearch = le16_to_cpu(findParms->EndofSearch);
findParms->LastNameOffset =
le16_to_cpu(findParms->LastNameOffset);
findParms->SearchCount = le16_to_cpu(findParms->SearchCount);
response_data =
(char *) &pSMBr->hdr.Protocol +
le16_to_cpu(pSMBr->DataOffset);
memcpy(findData, response_data, le16_to_cpu(pSMBr->DataCount));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSFindNext(const int xid, const struct cifsTconInfo *tcon,
FILE_DIRECTORY_INFO * findData,
T2_FNEXT_RSP_PARMS * findParms, const __u16 searchHandle,
__u32 resumeKey, int *pUnicodeFlag, int *pUnixFlag)
{
/* level 257 SMB_ */
TRANSACTION2_FNEXT_REQ *pSMB = NULL;
TRANSACTION2_FNEXT_RSP *pSMBr = NULL;
char *response_data;
int rc = 0;
int bytes_returned;
cFYI(1, ("\nIn FindNext"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->TotalParameterCount = 14; /* includes 2 bytes of null string, converted to LE below */
pSMB->TotalDataCount = 0; /* no EAs */
pSMB->MaxParameterCount = cpu_to_le16(8);
pSMB->MaxDataCount =
cpu_to_le16((tcon->ses->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
cpu_to_le16((int) &pSMB->SearchHandle - (int) &pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT);
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->SearchHandle = searchHandle; /* always kept as le */
findParms->SearchCount = 0; /* set to zero in case of error */
pSMB->SearchCount =
cpu_to_le16(CIFS_MAX_MSGSIZE / sizeof (FILE_DIRECTORY_INFO));
/* test for Unix extensions */
if (tcon->ses->capabilities & CAP_UNIX) {
pSMB->InformationLevel = cpu_to_le16(SMB_FIND_FILE_UNIX);
*pUnixFlag = TRUE;
} else {
pSMB->InformationLevel =
cpu_to_le16(SMB_FIND_FILE_DIRECTORY_INFO);
*pUnixFlag = FALSE;
}
pSMB->ResumeKey = resumeKey; /* always kept as le */
pSMB->SearchFlags =
cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END |
CIFS_SEARCH_CONTINUE_FROM_LAST);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
if (rc == -EBADF)
rc = 0; /* search probably was closed at end of search above */
else
cFYI(1, ("\nFindNext returned = %d\n", rc));
} else { /* decode response */
/* BB add safety checks for these memcpys */
if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE)
*pUnicodeFlag = TRUE;
else
*pUnicodeFlag = FALSE;
memcpy(findParms,
(char *) &pSMBr->hdr.Protocol +
le16_to_cpu(pSMBr->ParameterOffset),
sizeof (T2_FNEXT_RSP_PARMS));
findParms->EndofSearch = le16_to_cpu(findParms->EndofSearch);
findParms->LastNameOffset =
le16_to_cpu(findParms->LastNameOffset);
findParms->SearchCount = le16_to_cpu(findParms->SearchCount);
response_data =
(char *) &pSMBr->hdr.Protocol +
le16_to_cpu(pSMBr->DataOffset);
memcpy(findData, response_data, le16_to_cpu(pSMBr->DataCount));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses,
const unsigned char *searchName,
unsigned char **targetUNCs,
int *number_of_UNC_in_array,
const struct nls_table *nls_codepage)
{
/* TRANS2_GET_DFS_REFERRAL */
TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL;
TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL;
int rc = 0;
int bytes_returned;
int name_len;
*number_of_UNC_in_array = 0;
*targetUNCs = NULL;
cFYI(1, ("\nIn GetDFSRefer the path %s", searchName));
if (ses == NULL)
return -ENODEV;
rc = smb_init(SMB_COM_TRANSACTION2, 15, 0, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->hdr.Tid = ses->ipc_tid;
pSMB->hdr.Uid = ses->Suid;
if (ses->capabilities & CAP_STATUS32) {
pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS;
}
if (ses->capabilities & CAP_DFS) {
pSMB->hdr.Flags2 |= SMBFLG2_DFS;
}
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
if (ses->capabilities & CAP_UNICODE) {
pSMB->hdr.Flags2 |= SMBFLG2_UNICODE;
name_len =
cifs_strtoUCS((wchar_t *) pSMB->RequestFileName,
searchName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(searchName, 530);
name_len++; /* trailing null */
strncpy(pSMB->RequestFileName, searchName, name_len);
}
pSMB->ParameterCount = 2 /* level */ + name_len /*includes null */ ;
pSMB->TotalDataCount = 0;
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->MaxParameterCount = 0;
pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
cpu_to_le16((int) &(pSMB->MaxReferralLevel) -
(int) pSMB->hdr.Protocol);
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL);
pSMB->ByteCount = pSMB->ParameterCount + 3 /* pad */ ;
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->MaxReferralLevel = cpu_to_le16(3);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSend error in GetDFSRefer = %d\n", rc));
} else { /* decode response */
/* BB Add logic to parse referrals here */
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBQFSInfo(const int xid, const struct cifsTconInfo *tcon,
struct statfs *FSData, const struct nls_table *nls_codepage)
{
/* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
TRANSACTION2_QFSI_REQ *pSMB = NULL;
TRANSACTION2_QFSI_RSP *pSMBr = NULL;
FILE_SYSTEM_INFO *response_data;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn QFSInfo"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->TotalParameterCount = 2; /* level */
pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->ParameterOffset = cpu_to_le16((int) &(pSMB->InformationLevel)
- (int) pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION);
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in QFSInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = le16_to_cpu(pSMBr->DataOffset);
cFYI(1,
("\nDecoding qfsinfo response. BCC: %d Offset %d\n",
pSMBr->ByteCount, pSMBr->DataOffset));
if ((pSMBr->ByteCount < 24) || (pSMBr->DataOffset > 512)) /* BB also check enough total bytes returned */
rc = -EIO; /* bad smb */
else {
response_data =
(FILE_SYSTEM_INFO
*) (((char *) &pSMBr->hdr.Protocol) +
pSMBr->DataOffset);
FSData->f_bsize =
le32_to_cpu(response_data->BytesPerSector) *
le32_to_cpu(response_data->
SectorsPerAllocationUnit);
FSData->f_blocks =
le64_to_cpu(response_data->TotalAllocationUnits);
FSData->f_bfree = FSData->f_bavail =
le64_to_cpu(response_data->FreeAllocationUnits);
cFYI(1,
("\nBlocks: %ld Free: %ld Block size %ld\n",
FSData->f_blocks, FSData->f_bfree,
FSData->f_bsize));
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBQFSAttributeInfo(int xid, struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage)
{
/* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
TRANSACTION2_QFSI_REQ *pSMB = NULL;
TRANSACTION2_QFSI_RSP *pSMBr = NULL;
FILE_SYSTEM_ATTRIBUTE_INFO *response_data;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn QFSAttributeInfo"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->TotalParameterCount = 2; /* level */
pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->ParameterOffset = cpu_to_le16((int) &(pSMB->InformationLevel)
- (int) pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION);
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in QFSAttributeInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = le16_to_cpu(pSMBr->DataOffset);
if ((pSMBr->ByteCount < 13) || (pSMBr->DataOffset > 512)) { /* BB also check enough bytes returned */
rc = -EIO; /* bad smb */
} else {
response_data =
(FILE_SYSTEM_ATTRIBUTE_INFO
*) (((char *) &pSMBr->hdr.Protocol) +
pSMBr->DataOffset);
memcpy(&tcon->fsAttrInfo, response_data,
sizeof (FILE_SYSTEM_ATTRIBUTE_INFO));
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBQFSDeviceInfo(int xid, struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage)
{
/* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
TRANSACTION2_QFSI_REQ *pSMB = NULL;
TRANSACTION2_QFSI_RSP *pSMBr = NULL;
FILE_SYSTEM_DEVICE_INFO *response_data;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn QFSDeviceInfo"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->TotalParameterCount = 2; /* level */
pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ByteCount = pSMB->TotalParameterCount + 1 /* pad */ ;
pSMB->TotalParameterCount = cpu_to_le16(pSMB->TotalParameterCount);
pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->ParameterOffset =
cpu_to_le16((int) &(pSMB->InformationLevel) -
(int) pSMB->hdr.Protocol);
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION);
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in QFSDeviceInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = le16_to_cpu(pSMBr->DataOffset);
if ((pSMBr->ByteCount < sizeof (FILE_SYSTEM_DEVICE_INFO)) || (pSMBr->DataOffset > 512)) /* BB also check enough bytes returned */
rc = -EIO; /* bad smb */
else {
response_data =
(FILE_SYSTEM_DEVICE_INFO
*) (((char *) &pSMBr->hdr.Protocol) +
pSMBr->DataOffset);
memcpy(&tcon->fsDevInfo, response_data,
sizeof (FILE_SYSTEM_DEVICE_INFO));
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBQFSUnixInfo(int xid, struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage)
{
/* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
TRANSACTION2_QFSI_REQ *pSMB = NULL;
TRANSACTION2_QFSI_RSP *pSMBr = NULL;
FILE_SYSTEM_UNIX_INFO *response_data;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn QFSUnixInfo"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
pSMB->ParameterCount = 2; /* level */
pSMB->TotalDataCount = 0;
pSMB->DataCount = 0;
pSMB->DataOffset = 0;
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ByteCount = pSMB->ParameterCount + 1 /* pad */ ;
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->ParameterOffset =
cpu_to_le16((int) &(pSMB->InformationLevel) -
(int) pSMB->hdr.Protocol);
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION);
pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO);
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cERROR(1, ("\nSend error in QFSUnixInfo = %d\n", rc));
} else { /* decode response */
pSMBr->DataOffset = cpu_to_le16(pSMBr->DataOffset);
if ((pSMBr->ByteCount < 13) || (pSMBr->DataOffset > 512)) { /* BB also check enough bytes returned */
rc = -EIO; /* bad smb */
} else {
response_data =
(FILE_SYSTEM_UNIX_INFO
*) (((char *) &pSMBr->hdr.Protocol) +
pSMBr->DataOffset);
memcpy(&tcon->fsUnixInfo, response_data,
sizeof (FILE_SYSTEM_UNIX_INFO));
}
}
if (pSMB)
buf_release(pSMB);
return rc;
}
/* We can not use write of zero bytes trick to
set file size due to need for large file support. Also note that
this SetPathInfo is preferred to SetFileInfo based method in next
routine which is only needed to work around a sharing violation bug
in Samba which this routine can run into */
int
CIFSSMBSetEOF(int xid, struct cifsTconInfo *tcon, char *fileName,
__u64 size, int SetAllocation, const struct nls_table *nls_codepage)
{
struct smb_com_transaction2_spi_req *pSMB = NULL;
struct smb_com_transaction2_spi_rsp *pSMBr = NULL;
struct file_end_of_file_info *parm_data;
int name_len;
int rc = 0;
int bytes_returned = 0;
cFYI(1, ("\nIn SetEOF"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, fileName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fileName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, fileName, name_len);
}
pSMB->ParameterCount = 6 + name_len;
pSMB->DataCount = sizeof (struct file_end_of_file_info);
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
(int) &(pSMB->InformationLevel) - (int) pSMB->hdr.Protocol;
pSMB->DataOffset = pSMB->ParameterOffset + pSMB->ParameterCount;
if(SetAllocation) {
if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2);
else
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO);
} else /* Set File Size */ {
if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2);
else
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO);
}
parm_data =
(struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) +
pSMB->DataOffset);
pSMB->ParameterOffset = cpu_to_le16(pSMB->ParameterOffset);
pSMB->DataOffset = cpu_to_le16(pSMB->DataOffset);
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);
pSMB->ByteCount = 3 /* pad */ + pSMB->ParameterCount + pSMB->DataCount;
pSMB->DataCount = cpu_to_le16(pSMB->DataCount);
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
parm_data->FileSize = cpu_to_le64(size);
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSetPathInfo (file size) returned %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
__u16 fid, __u32 pid_of_opener, int SetAllocation)
{
struct smb_com_transaction2_sfi_req *pSMB = NULL;
struct smb_com_transaction2_sfi_rsp *pSMBr = NULL;
char *data_offset;
struct file_end_of_file_info *parm_data;
int rc = 0;
int bytes_returned = 0;
__u32 tmp;
cFYI(1, ("\nSetFileSize (via SetFileInfo)"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
tmp = cpu_to_le32(pid_of_opener); /* override pid of current process
so network fid will be valid */
pSMB->hdr.Pid = tmp & 0xFFFF;
tmp >>= 16;
pSMB->hdr.PidHigh = tmp & 0xFFFF;
pSMB->ParameterCount = 6;
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
(int) &(pSMB->Fid) - (int) pSMB->hdr.Protocol;
pSMB->DataOffset = pSMB->ParameterOffset + pSMB->ParameterCount;
data_offset = (char *) (&pSMB->hdr.Protocol) + pSMB->DataOffset;
pSMB->DataCount = sizeof(struct file_end_of_file_info);
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION);
pSMB->ByteCount = 3 /* pad */ + pSMB->ParameterCount + pSMB->DataCount;
pSMB->DataCount = cpu_to_le16(pSMB->DataCount);
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->ParameterOffset = cpu_to_le16(pSMB->ParameterOffset);
pSMB->DataOffset = cpu_to_le16(pSMB->DataOffset);
parm_data =
(struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) +
pSMB->DataOffset);
parm_data->FileSize = size;
pSMB->Fid = fid;
if(SetAllocation) {
if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2);
else
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO);
} else /* Set File Size */ {
if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2);
else
pSMB->InformationLevel =
cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO);
}
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1,
("\nSend error in SetFileInfo (SetFileSize) = %d\n",
rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBSetTimes(int xid, struct cifsTconInfo *tcon, char *fileName,
FILE_BASIC_INFO * data, const struct nls_table *nls_codepage)
{
TRANSACTION2_SPI_REQ *pSMB = NULL;
TRANSACTION2_SPI_RSP *pSMBr = NULL;
int name_len;
int rc = 0;
int bytes_returned = 0;
char *data_offset;
cFYI(1, ("\nIn SetTimes"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, fileName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fileName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, fileName, name_len);
}
pSMB->ParameterCount = 6 + name_len;
pSMB->DataCount = sizeof (FILE_BASIC_INFO);
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
(int) &(pSMB->InformationLevel) - (int) pSMB->hdr.Protocol;
pSMB->DataOffset = pSMB->ParameterOffset + pSMB->ParameterCount;
data_offset = (char *) (&pSMB->hdr.Protocol) + pSMB->DataOffset;
pSMB->ParameterOffset = cpu_to_le16(pSMB->ParameterOffset);
pSMB->DataOffset = cpu_to_le16(pSMB->DataOffset);
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);
pSMB->ByteCount = 3 /* pad */ + pSMB->ParameterCount + pSMB->DataCount;
pSMB->DataCount = cpu_to_le16(pSMB->DataCount);
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->TotalParameterCount = pSMB->ParameterCount;
if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2);
else
pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
memcpy(data_offset, data, sizeof (FILE_BASIC_INFO));
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSetPathInfo (times) returned %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
int
CIFSSMBUnixSetPerms(const int xid, struct cifsTconInfo *tcon,
char *fileName, __u64 mode, __u64 uid, __u64 gid,
const struct nls_table *nls_codepage)
{
TRANSACTION2_SPI_REQ *pSMB = NULL;
TRANSACTION2_SPI_RSP *pSMBr = NULL;
int name_len;
int rc = 0;
int bytes_returned = 0;
FILE_UNIX_BASIC_INFO *data_offset;
cFYI(1, ("\nIn SetUID/GID/Mode"));
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr);
if (rc)
return rc;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len =
cifs_strtoUCS((wchar_t *) pSMB->FileName, fileName, 530
/* find define for this maxpathcomponent */
, nls_codepage);
name_len++; /* trailing null */
name_len *= 2;
} else { /* BB improve the check for buffer overruns BB */
name_len = strnlen(fileName, 530);
name_len++; /* trailing null */
strncpy(pSMB->FileName, fileName, name_len);
}
pSMB->ParameterCount = 6 + name_len;
pSMB->DataCount = sizeof (FILE_UNIX_BASIC_INFO);
pSMB->MaxParameterCount = cpu_to_le16(2);
pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0;
pSMB->Flags = 0;
pSMB->Timeout = 0;
pSMB->Reserved2 = 0;
pSMB->ParameterOffset =
(int) &(pSMB->InformationLevel) - (int) pSMB->hdr.Protocol;
pSMB->DataOffset = pSMB->ParameterOffset + pSMB->ParameterCount;
data_offset =
(FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol +
pSMB->DataOffset);
pSMB->DataOffset = cpu_to_le16(pSMB->DataOffset);
pSMB->ParameterOffset = cpu_to_le16(pSMB->ParameterOffset);
pSMB->SetupCount = 1;
pSMB->Reserved3 = 0;
pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);
pSMB->ByteCount = 3 /* pad */ + pSMB->ParameterCount + pSMB->DataCount;
pSMB->ParameterCount = cpu_to_le16(pSMB->ParameterCount);
pSMB->DataCount = cpu_to_le16(pSMB->DataCount);
pSMB->TotalParameterCount = pSMB->ParameterCount;
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC);
pSMB->Reserved4 = 0;
pSMB->hdr.smb_buf_length += pSMB->ByteCount;
data_offset->Uid = cpu_to_le64(uid);
cFYI(1, ("\nUid = %lld from %lld ", data_offset->Uid, uid));
data_offset->Gid = cpu_to_le64(gid);
cFYI(1, ("\nGid = %lld from %lld ", data_offset->Gid, gid));
data_offset->Permissions = cpu_to_le64(mode);
pSMB->ByteCount = cpu_to_le16(pSMB->ByteCount);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *) pSMBr, &bytes_returned, 0);
if (rc) {
cFYI(1, ("\nSetPathInfo (perms) returned %d\n", rc));
}
if (pSMB)
buf_release(pSMB);
return rc;
}
/*
* fs/cifs/connect.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/net.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/wait.h>
#include <linux/version.h>
#include <linux/ipv6.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_unicode.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
#include "ntlmssp.h"
#include "nterr.h"
#define CIFS_PORT 445
#define RFC1001_PORT 139
extern void SMBencrypt(unsigned char *passwd, unsigned char *c8,
unsigned char *p24);
extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8,
unsigned char *p24);
extern int inet_addr(char *);
struct smb_vol {
char *username;
char *password;
char *domainname;
char *UNC;
char *UNCip;
uid_t linux_uid;
uid_t linux_gid;
mode_t file_mode;
mode_t dir_mode;
int rw;
};
int ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket);
int
cifs_reconnect(struct TCP_Server_Info *server)
{
int rc = 0;
cFYI(1, ("\nReconnecting tcp session "));
/* lock tcp session */
/* mark all smb sessions as reconnecting which use this tcp session */
/* reconnect tcp session */
/* wake up waiters on reconnection */
cFYI(1,
("\nState: 0x%x Flags: 0x%lx", server->ssocket->state,
server->ssocket->flags));
ipv4_connect(&server->sockAddr, &server->ssocket);
return rc;
}
int
cifs_demultiplex_thread(struct TCP_Server_Info *server)
{
int length, total_read;
unsigned int pdu_length;
struct smb_hdr *smb_buffer = NULL;
struct msghdr smb_msg;
mm_segment_t temp_fs;
struct iovec iov;
struct socket *csocket = server->ssocket;
struct list_head *tmp;
struct cifsSesInfo *ses;
struct task_struct *task_to_wake = NULL;
struct mid_q_entry *mid_entry;
char *temp;
daemonize();
server->tsk = current; /* save process info to wake at shutdown */
cFYI(1, ("\nDemultiplex PID: %d", current->pid));
temp_fs = get_fs(); /* we must turn off socket api parm checking */
set_fs(get_ds());
while (server->tcpStatus != CifsExiting) {
if (smb_buffer == NULL)
smb_buffer = buf_get();
else
memset(smb_buffer, 0, sizeof (struct smb_hdr));
if (smb_buffer == NULL) {
cERROR(1,
("\n Error - can not get mem for SMB response buffer "));
return -ENOMEM;
}
iov.iov_base = smb_buffer;
iov.iov_len = sizeof (struct smb_hdr) - 1;
/* 1 byte less above since wct is not always returned in error cases */
smb_msg.msg_iov = &iov;
smb_msg.msg_iovlen = 1;
smb_msg.msg_control = NULL;
smb_msg.msg_controllen = 0;
length =
sock_recvmsg(csocket, &smb_msg,
sizeof (struct smb_hdr) -
1 /* RFC1001 header and SMB header */ ,
MSG_PEEK /* flags see socket.h */ );
if (length < 0) {
if (length == -ECONNRESET) {
cERROR(1, ("\nConnection reset by peer "));
/* BB fix call below */
/* cifs_reconnect(server); */
} else { /* find define for the -512 returned at unmount time */
cFYI(1,
("\nReceived error on sock_recvmsg( peek) with length = %d\n",
length));
}
break;
}
if (length == 0) {
cFYI(1,
("\nZero length peek received - dead session?? "));
/* schedule_timeout(HZ/4);
continue; */
break;
}
pdu_length = 4 + ntohl(smb_buffer->smb_buf_length);
cFYI(1, ("\nPeek length rcvd: %d with smb length: %d", length, pdu_length)); /* BB */
temp = (char *) smb_buffer;
if (length > 3) {
if (temp[0] == (char) 0x85) {
iov.iov_base = smb_buffer;
iov.iov_len = 4;
length = sock_recvmsg(csocket, &smb_msg, 4, 0);
cFYI(0,
("\nReceived 4 byte keep alive packet "));
} else if ((temp[0] == (char) 0x83)
&& (length == 5)) {
/* we get this from Windows 98 instead of error on SMB negprot response */
cERROR(1,
("\nNegative RFC 1002 Session response. Error = 0x%x",
temp[4]));
break;
} else if (temp[0] != (char) 0) {
cERROR(1,
("\nUnknown RFC 1001 frame received not 0x00 nor 0x85"));
dump_mem(" Received Data is: ", temp, length);
break;
} else {
if ((length != sizeof (struct smb_hdr) - 1)
|| (pdu_length >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE)
|| (pdu_length <
sizeof (struct smb_hdr) - 1)
||
(checkSMBhdr
(smb_buffer, smb_buffer->Mid))) {
cERROR(1,
(KERN_ERR
"\nInvalid size or format for SMB found with length %d and pdu_lenght %d\n",
length, pdu_length));
/* BB fix by finding next smb signature - and reading off data until next smb ? BB */
/* BB add reconnect here */
break;
} else { /* length ok */
length = 0;
iov.iov_base = smb_buffer;
iov.iov_len = pdu_length;
for (total_read = 0; total_read < pdu_length; total_read += length) {
/* Should improve check for buffer overflow with bad pdu_length */
/* iov.iov_base = smb_buffer+total_read;
iov.iov_len = pdu_length-total_read; */
length = sock_recvmsg(csocket, &smb_msg,
pdu_length - total_read, 0);
/* cERROR(1,("\nFor iovlen %d Length received: %d with total read %d",
iov.iov_len, length,total_read)); */
if (length == 0) {
cERROR(1,
("\nZero length receive when expecting %d ",
pdu_length - total_read));
/* BB add reconnect here */
break;
}
}
}
dump_smb(smb_buffer, length);
if (checkSMB
(smb_buffer, smb_buffer->Mid, total_read)) {
cERROR(1, ("\n Bad SMB Received "));
continue;
}
task_to_wake = NULL;
list_for_each(tmp, &server->pending_mid_q) {
mid_entry = list_entry(tmp, struct
mid_q_entry,
qhead);
if (mid_entry->mid == smb_buffer->Mid) {
cFYI(1,
(" Mid 0x%x matched - waking up\n ",mid_entry->mid));
task_to_wake = mid_entry->tsk;
mid_entry->resp_buf =
smb_buffer;
mid_entry->midState =
MID_RESPONSE_RECEIVED;
}
}
if (task_to_wake) {
smb_buffer = NULL; /* will be freed by users thread after he is done */
wake_up_process(task_to_wake);
} else if (is_valid_oplock_break(smb_buffer) == FALSE) {
cERROR(1, ("\n No task to wake, unknown frame rcvd!\n"));
}
}
} else {
cFYI(0,
("\nFrame less than four bytes received %d bytes long.",
length));
if (length > 0) {
length = sock_recvmsg(csocket, &smb_msg, length, 0); /* throw away junk frame */
cFYI(1,
(" with junk 0x%x in it\n",
*(__u32 *) smb_buffer));
}
}
}
/* BB add code to lock SMB sessions while releasing */
if(server->ssocket) {
sock_release(csocket);
server->ssocket = NULL;
}
set_fs(temp_fs);
if (smb_buffer) /* buffer usually freed in free_mid - need to free it on error or exit */
buf_release(smb_buffer);
if (list_empty(&server->pending_mid_q)) {
/* loop through server session structures attached to this and mark them dead */
list_for_each(tmp, &GlobalSMBSessionList) {
ses =
list_entry(tmp, struct cifsSesInfo,
cifsSessionList);
if (ses->server == server) {
ses->status = CifsExiting;
ses->server = NULL;
}
}
kfree(server);
} else /* BB need to more gracefully handle the rare negative session
response case because response will be still outstanding */
cERROR(1, ("\nThere are still active MIDs in queue and we are exiting but we can not delete mid_q_entries or TCP_Server_Info structure due to pending requests MEMORY LEAK!!\n ")); /* BB wake up waitors, and/or wait and/or free stale mids and try again? BB */
/* BB Need to fix bug in error path above - perhaps wait until smb requests
time out and then free the tcp per server struct BB */
cFYI(1, ("\nAbout to exit from demultiplex thread\n"));
return 0;
}
int
parse_mount_options(char *options, char *devname, struct smb_vol *vol)
{
char *value;
char *data;
vol->username = NULL;
vol->password = NULL;
vol->domainname = NULL;
vol->UNC = NULL;
vol->UNCip = NULL;
vol->linux_uid = current->uid; /* current->euid instead? */
vol->linux_gid = current->gid;
vol->rw = TRUE;
if (!options)
return 1;
while ((data = strsep(&options, ",")) != NULL) {
if (!*data)
continue;
if ((value = strchr(data, '=')) != NULL)
*value++ = '\0';
if (strnicmp(data, "user", 4) == 0) {
if (!value || !*value) {
printk(KERN_ERR
"CIFS: invalid or missing username");
return 1; /* needs_arg; */
}
if (strnlen(value, 200) < 200) {
vol->username = value;
} else {
printk(KERN_ERR "CIFS: username too long");
return 1;
}
} else if (strnicmp(data, "pass", 4) == 0) {
if (!value || !*value) {
vol->password = NULL;
} else if (strnlen(value, 17) < 17) {
vol->password = value;
} else {
printk(KERN_ERR "CIFS: password too long");
return 1;
}
} else if ((strnicmp(data, "unc", 3) == 0)
|| (strnicmp(data, "target", 6) == 0)
|| (strnicmp(data, "path", 4) == 0)) {
if (!value || !*value) {
printk(KERN_ERR
"CIFS: invalid path to network resource");
return 1; /* needs_arg; */
}
if (strnlen(value, 300) < 300) {
vol->UNC = value;
if (strncmp(vol->UNC, "//", 2) == 0) {
vol->UNC[0] = '\\';
vol->UNC[1] = '\\';
} else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
printk(KERN_ERR
"CIFS: UNC Path does not begin with // or \\\\");
return 1;
}
vol->UNCip = &vol->UNC[2];
} else {
printk(KERN_ERR "CIFS: UNC name too long");
return 1;
}
} else if ((strnicmp(data, "domain", 3) == 0)
|| (strnicmp(data, "workgroup", 5) == 0)) {
if (!value || !*value) {
printk(KERN_ERR "CIFS: invalid domain name");
return 1; /* needs_arg; */
}
if (strnlen(value, 65) < 65) {
vol->domainname = value;
cFYI(1, ("\nDomain name set"));
} else {
printk(KERN_ERR "CIFS: domain name too long");
return 1;
}
} else if (strnicmp(data, "uid", 3) == 0) {
if (value && *value) {
vol->linux_uid =
simple_strtoul(value, &value, 0);
}
} else if (strnicmp(data, "gid", 3) == 0) {
if (value && *value) {
vol->linux_gid =
simple_strtoul(value, &value, 0);
}
} else if (strnicmp(data, "file_mode", 4) == 0) {
if (value && *value) {
vol->file_mode =
simple_strtoul(value, &value, 0);
}
} else if (strnicmp(data, "dir_mode", 3) == 0) {
if (value && *value) {
vol->dir_mode =
simple_strtoul(value, &value, 0);
}
} else if (strnicmp(data, "version", 3) == 0) {
/* ignore */
} else if (strnicmp(data, "rw", 2) == 0) {
vol->rw = TRUE;
} else
printk(KERN_ERR
"CIFS: Unrecognized mount option %s = %s",
data, value);
}
if (vol->UNC == NULL) {
if (strnlen(devname, 300) < 300) {
vol->UNC = devname;
if (strncmp(vol->UNC, "//", 2) == 0) {
vol->UNC[0] = '\\';
vol->UNC[1] = '\\';
} else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
printk(KERN_ERR
"CIFS: UNC Path does not begin with // or \\\\");
return 1;
}
vol->UNCip = &vol->UNC[2];
} else {
printk(KERN_ERR "CIFS: UNC name too long");
return 1;
}
}
return 0;
}
struct cifsSesInfo *
find_tcp_session(__u32 new_target_ip_addr,
char *userName, struct TCP_Server_Info **psrvTcp)
{
struct list_head *tmp;
struct cifsSesInfo *ses;
*psrvTcp = NULL;
list_for_each(tmp, &GlobalSMBSessionList) {
ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
if (ses->server) {
if (ses->server->sockAddr.sin_addr.s_addr ==
new_target_ip_addr) {
/* BB lock server and tcp session and increment use count here?? */
*psrvTcp = ses->server; /* found a match on the TCP session */
/* BB check if reconnection needed */
if (strncmp
(ses->userName, userName,
MAX_USERNAME_SIZE) == 0)
return ses; /* found exact match on both tcp and SMB sessions */
}
}
/* else tcp and smb sessions need reconnection */
}
return NULL;
}
struct cifsTconInfo *
find_unc(__u32 new_target_ip_addr, char *uncName, char *userName)
{
struct list_head *tmp;
struct cifsTconInfo *tcon;
list_for_each(tmp, &GlobalTreeConnectionList) {
cFYI(1, ("\nNext tcon - "));
tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
if (tcon->ses) {
if (tcon->ses->server) {
cFYI(1,
(" old ip addr: %x == new ip %x ?",
tcon->ses->server->sockAddr.sin_addr.
s_addr, new_target_ip_addr));
if (tcon->ses->server->sockAddr.sin_addr.
s_addr == new_target_ip_addr) {
/* BB lock tcon and server and tcp session and increment use count here? */
/* found a match on the TCP session */
/* BB check if reconnection needed */
cFYI(1,
("\nMatched ip, old UNC: %s == new: %s ?",
tcon->treeName, uncName));
if (strncmp
(tcon->treeName, uncName,
MAX_TREE_SIZE) == 0) {
cFYI(1,
("\nMatched UNC, old user: %s == new: %s ?",
tcon->treeName, uncName));
if (strncmp
(tcon->ses->userName,
userName,
MAX_USERNAME_SIZE) == 0)
return tcon;/* also matched user (smb session)*/
}
}
}
}
}
return NULL;
}
int
connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
const char *old_path, const struct nls_table *nls_codepage)
{
char *temp_unc;
int rc = 0;
int num_referrals = 0;
unsigned char *referrals = NULL;
if (pSesInfo->ipc_tid == 0) {
temp_unc =
kmalloc(2 +
strnlen(pSesInfo->serverName,
SERVER_NAME_LEN_WITH_NULL * 2) + 1 +
4 /* IPC$ */ + 1, GFP_KERNEL);
if (temp_unc == NULL)
return -ENOMEM;
temp_unc[0] = '\\';
temp_unc[1] = '\\';
strncpy(temp_unc + 2, pSesInfo->serverName,
SERVER_NAME_LEN_WITH_NULL * 2);
strncpy(temp_unc + 2 +
strnlen(pSesInfo->serverName,
SERVER_NAME_LEN_WITH_NULL * 2), "\\IPC$", 6);
rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage);
cFYI(1,
("\nCIFS Tcon rc = %d ipc_tid = %d\n", rc,
pSesInfo->ipc_tid));
kfree(temp_unc);
}
if (rc == 0)
rc = CIFSGetDFSRefer(xid, pSesInfo, old_path, &referrals,
&num_referrals, nls_codepage);
return -ENODEV; /* BB remove and add return rc; */
}
int
ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket)
{
int rc = 0;
rc = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, csocket);
if (rc < 0) {
cERROR(1, ("Error creating socket. Aborting operation\n"));
return rc;
}
psin_server->sin_family = AF_INET;
psin_server->sin_port = htons(CIFS_PORT);
rc = (*csocket)->ops->connect(*csocket,
(struct sockaddr *) psin_server,
sizeof (struct sockaddr_in), 0
/* Is there a way to fix a polling timeout -
and find out what more of the flags really mean? */
);
if (rc < 0) {
psin_server->sin_port = htons(RFC1001_PORT);
rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
psin_server,
sizeof (struct sockaddr_in), 0);
if (rc < 0) {
cFYI(1, ("Error connecting to socket. %d\n", rc));
sock_release(*csocket);
return rc;
}
}
return rc;
}
int
ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
{
int rc = 0;
rc = sock_create(PF_INET6, SOCK_STREAM,
IPPROTO_TCP /* IPPROTO_IPV6 ? */ , csocket);
if (rc < 0) {
cERROR(1, ("Error creating socket. Aborting operation\n"));
return rc;
}
psin_server->sin6_family = AF_INET6;
psin_server->sin6_port = htons(CIFS_PORT);
rc = (*csocket)->ops->connect(*csocket,
(struct sockaddr *) psin_server,
sizeof (struct sockaddr_in6), 0
/* BB fix the timeout to be shorter - and check flags */
);
if (rc < 0) {
psin_server->sin6_port = htons(RFC1001_PORT);
rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
psin_server,
sizeof (struct sockaddr_in6), 0);
if (rc < 0) {
cFYI(1,
("Error connecting to socket (via ipv6). %d\n",
rc));
sock_release(*csocket);
return rc;
}
}
return rc;
}
int
cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
char *mount_data, char *devname)
{
int rc = 0;
int xid;
int ntlmv2_flag = FALSE;
struct socket *csocket;
struct sockaddr_in sin_server;
/* struct sockaddr_in6 sin_server6; */
struct smb_vol volume_info;
struct cifsSesInfo *pSesInfo = NULL;
struct cifsSesInfo *existingCifsSes = NULL;
struct cifsTconInfo *tcon = NULL;
struct TCP_Server_Info *srvTcp = NULL;
char cryptKey[CIFS_CRYPTO_KEY_SIZE];
char session_key[CIFS_SESSION_KEY_SIZE];
char ntlm_session_key[CIFS_SESSION_KEY_SIZE];
char password_with_pad[CIFS_ENCPWD_SIZE];
xid = GetXid();
cFYI(0, ("\nEntering cifs_mount. Xid: %d with: %s\n", xid, mount_data));
parse_mount_options(mount_data, devname, &volume_info);
if (volume_info.username) {
cFYI(1, ("\nUsername: %s ", volume_info.username));
} else {
cERROR(1, ("\nNo username specified "));
/* Could add ways to allow getting user name from alternate locations */
}
if (volume_info.UNC) {
sin_server.sin_addr.s_addr = inet_addr(volume_info.UNCip);
cFYI(1, ("\nUNC: %s ", volume_info.UNC));
} else {
/* BB we could connect to the DFS root? but which server do we ask? */
cERROR(1,
("\nCIFS mount error: No UNC path (e.g. -o unc=//192.168.1.100/public) specified "));
FreeXid(xid);
return -ENODEV;
}
/* BB add support to use the multiuser_mount flag BB */
existingCifsSes =
find_tcp_session(sin_server.sin_addr.s_addr,
volume_info.username, &srvTcp);
if (srvTcp) {
cFYI(1, ("\nExisting tcp session with server found "));
} else { /* create socket */
rc = ipv4_connect(&sin_server, &csocket);
if (rc < 0) {
cERROR(1,
("Error connecting to IPv4 socket. Aborting operation\n"));
FreeXid(xid);
return rc;
}
srvTcp = kmalloc(sizeof (struct TCP_Server_Info), GFP_KERNEL);
if (srvTcp == NULL) {
rc = -ENOMEM;
sock_release(csocket);
FreeXid(xid);
return rc;
} else {
memset(srvTcp, 0, sizeof (struct TCP_Server_Info));
memcpy(&srvTcp->sockAddr, &sin_server, sizeof (struct sockaddr_in));
/* BB Add code for ipv6 case too */
srvTcp->ssocket = csocket;
init_waitqueue_head(&srvTcp->response_q);
INIT_LIST_HEAD(&srvTcp->pending_mid_q);
kernel_thread((void *) (void *)
cifs_demultiplex_thread, srvTcp,
CLONE_FS | CLONE_FILES | CLONE_VM);
}
}
if (existingCifsSes) {
pSesInfo = existingCifsSes;
cFYI(1, ("\nExisting smb sess found "));
} else if (!rc) {
cFYI(1, ("\nExisting smb sess not found "));
pSesInfo = sesInfoAlloc();
if (pSesInfo == NULL)
rc = -ENOMEM;
else {
pSesInfo->server = srvTcp;
pSesInfo->status = CifsGood;
sprintf(pSesInfo->serverName, "%u.%u.%u.%u",
NIPQUAD(sin_server.sin_addr.s_addr));
}
/* send negotiate protocol smb */
if (!rc)
rc = CIFSSMBNegotiate(xid, pSesInfo, cryptKey);
cFYI(0, ("\nNegotiate rc = %d ", rc));
if (!rc) {
cFYI(1, ("\nSecurity Mode: %x", pSesInfo->secMode));
cFYI(1,
(" Server Capabilities: %x",
pSesInfo->capabilities));
cFYI(1,
(" Time Zone: 0x%x %d\n", pSesInfo->timeZone,
pSesInfo->timeZone));
memset(password_with_pad, 0, CIFS_ENCPWD_SIZE);
if (volume_info.password)
strcpy(password_with_pad, volume_info.password);
if (extended_security
&& (pSesInfo->capabilities & CAP_EXTENDED_SECURITY)
&& (pSesInfo->secType == NTLMSSP)) {
cFYI(1, ("\nNew style sesssetup "));
rc = CIFSSpnegoSessSetup(xid, pSesInfo,
volume_info.
username,
volume_info.
domainname, NULL
/* security blob */
, 0 /* blob length */
, cifs_sb->local_nls);
} else if (extended_security
&& (pSesInfo->
capabilities & CAP_EXTENDED_SECURITY)
&& (pSesInfo->secType == RawNTLMSSP)) {
cFYI(1, ("\nNTLMSSP sesssetup "));
rc = CIFSNTLMSSPNegotiateSessSetup(xid,
pSesInfo,
cryptKey,
volume_info.domainname,
&ntlmv2_flag,
cifs_sb->local_nls);
if (!rc) {
if(ntlmv2_flag) {
cFYI(1,("\nAble to use the more secure NTLM version 2 password hash"));
/* SMBNTv2encrypt( ...); */ /* BB fix this up -
and note that Samba client equivalent looks wrong */
} else
SMBNTencrypt(password_with_pad,cryptKey,ntlm_session_key);
/* for better security the weaker lanman hash not sent
in AuthSessSetup so why bother calculating it */
/* toUpper(cifs_sb->local_nls,
password_with_pad);
SMBencrypt(password_with_pad,
cryptKey, session_key); */
rc = CIFSNTLMSSPAuthSessSetup(xid,
pSesInfo,
volume_info.
username,
volume_info.domainname,
ntlm_session_key,
session_key,
ntlmv2_flag,
cifs_sb->local_nls);
}
} else { /* old style NTLM 0.12 session setup */
SMBNTencrypt(password_with_pad, cryptKey,
ntlm_session_key);
/* Removed following few lines to not send old style password
hash ever - for better security */
/* toUpper(cifs_sb->local_nls, password_with_pad);
SMBencrypt(password_with_pad, cryptKey,session_key);
dump_mem("\nCIFS (Samba encrypt): ", session_key,CIFS_SESSION_KEY_SIZE); */
rc = CIFSSessSetup(xid, pSesInfo,
volume_info.username,
volume_info.
domainname,
session_key,
ntlm_session_key,
cifs_sb->local_nls);
}
if (rc) {
cERROR(1,
("\nSend error in SessSetup = %d\n",
rc));
} else {
cFYI(1,
("CIFS Session Established successfully "));
strncpy(pSesInfo->userName,
volume_info.username,
MAX_USERNAME_SIZE);
atomic_inc(&srvTcp->socketUseCount);
}
}
}
/* search for existing tcon to this server share */
if (!rc) {
tcon =
find_unc(sin_server.sin_addr.s_addr, volume_info.UNC,
volume_info.username);
if (tcon) {
cFYI(1, ("\nFound match on UNC path "));
} else {
tcon = tconInfoAlloc();
if (tcon == NULL)
rc = -ENOMEM;
else {
/* check for null share name ie connect to dfs root */
/* BB check if this works for exactly length three strings */
if ((strchr(volume_info.UNC + 3, '\\') == NULL)
&& (strchr(volume_info.UNC + 3, '/') ==
NULL)) {
rc = connect_to_dfs_path(xid,
pSesInfo,
"",
cifs_sb->
local_nls);
return -ENODEV;
} else {
rc = CIFSTCon(xid, pSesInfo,
volume_info.UNC,
tcon, cifs_sb->local_nls);
cFYI(1, ("\nCIFS Tcon rc = %d\n", rc));
}
if (!rc)
atomic_inc(&pSesInfo->inUse);
}
}
}
if (pSesInfo->capabilities & CAP_LARGE_FILES) {
cFYI(0, ("\nLarge files supported "));
sb->s_maxbytes = (u64) 1 << 63;
} else
sb->s_maxbytes = (u64) 1 << 31; /* 2 GB */
/* on error free sesinfo and tcon struct if needed */
if (rc) {
/* If find_unc succeeded then rc == 0 so we can not end */
if (tcon) /* up here accidently freeing someone elses tcon struct */
tconInfoFree(tcon);
if (existingCifsSes == 0) {
if (pSesInfo) {
if (pSesInfo->server) {
cFYI(0,
("\nAbout to check if we need to do SMBLogoff "));
if (pSesInfo->Suid)
CIFSSMBLogoff(xid, pSesInfo);
wake_up_process(pSesInfo->server->tsk);
schedule_timeout(HZ / 4); /* give captive thread time to exit */
} else
cFYI(1, ("\nNo session or bad tcon"));
sesInfoFree(pSesInfo);
/* pSesInfo = NULL; */
}
}
} else {
atomic_inc(&tcon->useCount);
cifs_sb->tcon = tcon;
tcon->ses = pSesInfo;
/* do not care if following two calls succeed - informational only */
CIFSSMBQFSDeviceInfo(xid, tcon, cifs_sb->local_nls);
CIFSSMBQFSAttributeInfo(xid, tcon, cifs_sb->local_nls);
if (tcon->ses->capabilities & CAP_UNIX)
CIFSSMBQFSUnixInfo(xid, tcon, cifs_sb->local_nls);
}
FreeXid(xid);
return rc;
}
int
CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses, char *user,
char *domain, char session_key[CIFS_SESSION_KEY_SIZE],
char session_key2[CIFS_SESSION_KEY_SIZE],
const struct nls_table *nls_codepage)
{
struct smb_hdr *smb_buffer;
struct smb_hdr *smb_buffer_response;
SESSION_SETUP_ANDX *pSMB;
SESSION_SETUP_ANDX *pSMBr;
char *bcc_ptr;
int rc = 0;
int remaining_words = 0;
int bytes_returned = 0;
int len;
cFYI(1, ("\nIn sesssetup "));
smb_buffer = buf_get();
if (smb_buffer == 0) {
return -ENOMEM;
}
smb_buffer_response = smb_buffer;
pSMBr = pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
/* send SMBsessionSetup here */
header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
0 /* no tCon exists yet */ , 13 /* wct */ );
pSMB->req_no_secext.AndXCommand = 0xFF;
pSMB->req_no_secext.MaxBufferSize = cpu_to_le16(ses->maxBuf);
pSMB->req_no_secext.MaxMpxCount = cpu_to_le16(ses->maxReq);
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
pSMB->req_no_secext.Capabilities =
CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS;
if (ses->capabilities & CAP_UNICODE) {
smb_buffer->Flags2 |= SMBFLG2_UNICODE;
pSMB->req_no_secext.Capabilities |= CAP_UNICODE;
}
if (ses->capabilities & CAP_STATUS32) {
smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
pSMB->req_no_secext.Capabilities |= CAP_STATUS32;
}
if (ses->capabilities & CAP_DFS) {
smb_buffer->Flags2 |= SMBFLG2_DFS;
pSMB->req_no_secext.Capabilities |= CAP_DFS;
}
pSMB->req_no_secext.Capabilities =
cpu_to_le32(pSMB->req_no_secext.Capabilities);
/* pSMB->req_no_secext.CaseInsensitivePasswordLength =
CIFS_SESSION_KEY_SIZE; */
pSMB->req_no_secext.CaseInsensitivePasswordLength = 0;
pSMB->req_no_secext.CaseSensitivePasswordLength =
cpu_to_le16(CIFS_SESSION_KEY_SIZE);
bcc_ptr = pByteArea(smb_buffer);
/* memcpy(bcc_ptr, (char *) session_key, CIFS_SESSION_KEY_SIZE);
bcc_ptr += CIFS_SESSION_KEY_SIZE; */
memcpy(bcc_ptr, (char *) session_key2, CIFS_SESSION_KEY_SIZE);
bcc_ptr += CIFS_SESSION_KEY_SIZE;
if (ses->capabilities & CAP_UNICODE) {
if ((int) bcc_ptr % 2) { /* must be word aligned for Unicode */
*bcc_ptr = 0;
bcc_ptr++;
}
if(user == NULL)
bytes_returned = 0; /* skill null user */
else
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, user, 100, nls_codepage);
bcc_ptr += 2 * bytes_returned; /* convert num 16 bit words to bytes */
bcc_ptr += 2; /* trailing null */
if (domain == NULL)
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr,
"CIFS_LINUX_DOM", 32, nls_codepage);
else
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, domain, 64,
nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
32, nls_codepage);
bcc_ptr += 2 * bytes_returned;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, UTS_RELEASE, 32,
nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
64, nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2;
} else {
if(user != NULL) {
strncpy(bcc_ptr, user, 200);
bcc_ptr += strnlen(user, 200);
}
*bcc_ptr = 0;
bcc_ptr++;
if (domain == NULL) {
strcpy(bcc_ptr, "CIFS_LINUX_DOM");
bcc_ptr += strlen("CIFS_LINUX_DOM") + 1;
} else {
strncpy(bcc_ptr, domain, 64);
bcc_ptr += strnlen(domain, 64);
*bcc_ptr = 0;
bcc_ptr++;
}
strcpy(bcc_ptr, "Linux version ");
bcc_ptr += strlen("Linux version ");
strcpy(bcc_ptr, UTS_RELEASE);
bcc_ptr += strlen(UTS_RELEASE) + 1;
strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
}
BCC(smb_buffer) = (int) bcc_ptr - (int) pByteArea(smb_buffer);
smb_buffer->smb_buf_length += BCC(smb_buffer);
BCC(smb_buffer) = cpu_to_le16(BCC(smb_buffer));
rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
&bytes_returned, 1);
/* dump_mem("\nSessSetup response is: ", smb_buffer_response, 92);*/
if (rc) {
/* rc = map_smb_to_linux_error(smb_buffer_response); now done in SendReceive */
} else if ((smb_buffer_response->WordCount == 3)
|| (smb_buffer_response->WordCount == 4)) {
pSMBr->resp.Action = le16_to_cpu(pSMBr->resp.Action);
if (pSMBr->resp.Action & GUEST_LOGIN)
cFYI(1, (" Guest login")); /* do we want to mark SesInfo struct ? */
if (ses) {
ses->Suid = smb_buffer_response->Uid; /* UID left in wire format (le) */
cFYI(1, ("UID = %d ", ses->Suid));
/* response can have either 3 or 4 word count - Samba sends 3 */
bcc_ptr = pByteArea(smb_buffer_response);
if ((pSMBr->resp.hdr.WordCount == 3)
|| ((pSMBr->resp.hdr.WordCount == 4)
&& (pSMBr->resp.SecurityBlobLength <
pSMBr->resp.ByteCount))) {
if (pSMBr->resp.hdr.WordCount == 4)
bcc_ptr +=
pSMBr->resp.SecurityBlobLength;
if (smb_buffer->Flags2 &= SMBFLG2_UNICODE) {
if ((int) (bcc_ptr) % 2) {
remaining_words =
(BCC(smb_buffer_response)
- 1) / 2;
bcc_ptr++; /* Unicode strings must be word aligned */
} else {
remaining_words =
BCC
(smb_buffer_response) / 2;
}
len =
UniStrnlen((wchar_t *) bcc_ptr,
remaining_words - 1);
/* We look for obvious messed up bcc or strings in response so we do not go off
the end since (at least) WIN2K and Windows XP have a major bug in not null
terminating last Unicode string in response */
ses->serverOS = kcalloc(2 * (len + 1), GFP_KERNEL);
cifs_strfromUCS_le(ses->serverOS,
(wchar_t *)bcc_ptr, len,nls_codepage);
bcc_ptr += 2 * (len + 1);
remaining_words -= len + 1;
ses->serverOS[2 * len] = 0;
ses->serverOS[1 + (2 * len)] = 0;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *)bcc_ptr,
remaining_words
- 1);
ses->serverNOS =kcalloc(2 * (len + 1),GFP_KERNEL);
cifs_strfromUCS_le(ses->serverNOS,
(wchar_t *)bcc_ptr,len,nls_codepage);
bcc_ptr += 2 * (len + 1);
ses->serverNOS[2 * len] = 0;
ses->serverNOS[1 + (2 * len)] = 0;
remaining_words -= len + 1;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
/* last string is not always null terminated (for e.g. for Windows XP & 2000) */
ses->serverDomain =
kcalloc(2*(len+1),GFP_KERNEL);
cifs_strfromUCS_le(ses->serverDomain,
(wchar_t *)bcc_ptr,len,nls_codepage);
bcc_ptr += 2 * (len + 1);
ses->serverDomain[2*len] = 0;
ses->serverDomain[1+(2*len)] = 0;
} /* else no more room so create dummy domain string */
else
ses->serverDomain =
kcalloc(2,
GFP_KERNEL);
} else { /* no room so create dummy domain and NOS string */
ses->serverDomain =
kcalloc(2, GFP_KERNEL);
ses->serverNOS =
kcalloc(2, GFP_KERNEL);
}
} else { /* ASCII */
len = strnlen(bcc_ptr, 1024);
if (((int) bcc_ptr + len) - (int)
pByteArea(smb_buffer_response)
<= BCC(smb_buffer_response)) {
ses->serverOS = kcalloc(len + 1,GFP_KERNEL);
strncpy(ses->serverOS,bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0; /* null terminate the string */
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverNOS = kcalloc(len + 1,GFP_KERNEL);
strncpy(ses->serverNOS, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverDomain = kcalloc(len + 1,GFP_KERNEL);
strncpy(ses->serverDomain, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
} else
cFYI(1,
("Variable field of length %d extends beyond end of smb ",
len));
}
} else {
cERROR(1,
(" Security Blob Length extends beyond end of SMB"));
}
} else {
cERROR(1, ("No session structure passed in."));
}
} else {
cERROR(1,
(" Invalid Word count %d: ",
smb_buffer_response->WordCount));
rc = -EIO;
}
if (smb_buffer)
buf_release(smb_buffer);
return rc;
}
int
CIFSSpnegoSessSetup(unsigned int xid, struct cifsSesInfo *ses,
char *user, char *domain, char *SecurityBlob,
int SecurityBlobLength,
const struct nls_table *nls_codepage)
{
struct smb_hdr *smb_buffer;
struct smb_hdr *smb_buffer_response;
SESSION_SETUP_ANDX *pSMB;
SESSION_SETUP_ANDX *pSMBr;
char *bcc_ptr;
int rc = 0;
int remaining_words = 0;
int bytes_returned = 0;
int len;
cFYI(1, ("\nIn v2 sesssetup "));
smb_buffer = buf_get();
if (smb_buffer == 0) {
return -ENOMEM;
}
smb_buffer_response = smb_buffer;
pSMBr = pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
/* send SMBsessionSetup here */
header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
0 /* no tCon exists yet */ , 12 /* wct */ );
pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
pSMB->req.AndXCommand = 0xFF;
pSMB->req.MaxBufferSize = cpu_to_le16(ses->maxBuf);
pSMB->req.MaxMpxCount = cpu_to_le16(ses->maxReq);
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
pSMB->req.Capabilities =
CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
CAP_EXTENDED_SECURITY;
if (ses->capabilities & CAP_UNICODE) {
smb_buffer->Flags2 |= SMBFLG2_UNICODE;
pSMB->req.Capabilities |= CAP_UNICODE;
}
if (ses->capabilities & CAP_STATUS32) {
smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
pSMB->req.Capabilities |= CAP_STATUS32;
}
if (ses->capabilities & CAP_DFS) {
smb_buffer->Flags2 |= SMBFLG2_DFS;
pSMB->req.Capabilities |= CAP_DFS;
}
pSMB->req.Capabilities = cpu_to_le32(pSMB->req.Capabilities);
pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength);
bcc_ptr = pByteArea(smb_buffer);
memcpy(bcc_ptr, SecurityBlob, SecurityBlobLength);
bcc_ptr += SecurityBlobLength;
if (ses->capabilities & CAP_UNICODE) {
if ((int) bcc_ptr % 2) { /* must be word aligned for Unicode strings */
*bcc_ptr = 0;
bcc_ptr++;
}
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, user, 100, nls_codepage);
bcc_ptr += 2 * bytes_returned; /* convert num of 16 bit words to bytes */
bcc_ptr += 2; /* trailing null */
if (domain == NULL)
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr,
"CIFS_LINUX_DOM", 32, nls_codepage);
else
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, domain, 64,
nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
32, nls_codepage);
bcc_ptr += 2 * bytes_returned;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, UTS_RELEASE, 32,
nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
64, nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2;
} else {
strncpy(bcc_ptr, user, 200);
bcc_ptr += strnlen(user, 200);
*bcc_ptr = 0;
bcc_ptr++;
if (domain == NULL) {
strcpy(bcc_ptr, "CIFS_LINUX_DOM");
bcc_ptr += strlen("CIFS_LINUX_DOM") + 1;
} else {
strncpy(bcc_ptr, domain, 64);
bcc_ptr += strnlen(domain, 64);
*bcc_ptr = 0;
bcc_ptr++;
}
strcpy(bcc_ptr, "Linux version ");
bcc_ptr += strlen("Linux version ");
strcpy(bcc_ptr, UTS_RELEASE);
bcc_ptr += strlen(UTS_RELEASE) + 1;
strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
}
BCC(smb_buffer) = (int) bcc_ptr - (int) pByteArea(smb_buffer);
smb_buffer->smb_buf_length += BCC(smb_buffer);
BCC(smb_buffer) = cpu_to_le16(BCC(smb_buffer));
rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
&bytes_returned, 1);
/* dump_mem("\nSessSetup response is: ", smb_buffer_response, 92); */
if (rc) {
/* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */
} else if ((smb_buffer_response->WordCount == 3)
|| (smb_buffer_response->WordCount == 4)) {
pSMBr->resp.Action = le16_to_cpu(pSMBr->resp.Action);
pSMBr->resp.SecurityBlobLength =
le16_to_cpu(pSMBr->resp.SecurityBlobLength);
if (pSMBr->resp.Action & GUEST_LOGIN)
cFYI(1, (" Guest login")); /* BB do we want to set anything in SesInfo struct ? */
if (ses) {
ses->Suid = smb_buffer_response->Uid; /* UID left in wire format (le) */
cFYI(1, ("UID = %d ", ses->Suid));
bcc_ptr = pByteArea(smb_buffer_response); /* response can have either 3 or 4 word count - Samba sends 3 */
/* BB Fix below to make endian neutral !! */
if ((pSMBr->resp.hdr.WordCount == 3)
|| ((pSMBr->resp.hdr.WordCount == 4)
&& (pSMBr->resp.SecurityBlobLength <
pSMBr->resp.ByteCount))) {
if (pSMBr->resp.hdr.WordCount == 4) {
bcc_ptr +=
pSMBr->resp.SecurityBlobLength;
cFYI(1,
("\nSecurity Blob Length %d ",
pSMBr->resp.SecurityBlobLength));
}
if (smb_buffer->Flags2 &= SMBFLG2_UNICODE) {
if ((int) (bcc_ptr) % 2) {
remaining_words =
(BCC(smb_buffer_response)
- 1) / 2;
bcc_ptr++; /* Unicode strings must be word aligned */
} else {
remaining_words =
BCC
(smb_buffer_response) / 2;
}
len =
UniStrnlen((wchar_t *) bcc_ptr,
remaining_words - 1);
/* We look for obvious messed up bcc or strings in response so we do not go off
the end since (at least) WIN2K and Windows XP have a major bug in not null
terminating last Unicode string in response */
ses->serverOS =
kcalloc(2 * (len + 1), GFP_KERNEL);
cifs_strfromUCS_le(ses->serverOS,
(wchar_t *)
bcc_ptr, len,
nls_codepage);
bcc_ptr += 2 * (len + 1);
remaining_words -= len + 1;
ses->serverOS[2 * len] = 0;
ses->serverOS[1 + (2 * len)] = 0;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *)bcc_ptr,
remaining_words
- 1);
ses->serverNOS =
kcalloc(2 * (len + 1),
GFP_KERNEL);
cifs_strfromUCS_le(ses->serverNOS,
(wchar_t *)bcc_ptr,
len,
nls_codepage);
bcc_ptr += 2 * (len + 1);
ses->serverNOS[2 * len] = 0;
ses->serverNOS[1 + (2 * len)] = 0;
remaining_words -= len + 1;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
/* last string is not always null terminated (for e.g. for Windows XP & 2000) */
ses->serverDomain = kcalloc(2*(len+1),GFP_KERNEL);
cifs_strfromUCS_le(ses->serverDomain,
(wchar_t *)bcc_ptr,
len,
nls_codepage);
bcc_ptr += 2*(len+1);
ses->serverDomain[2*len] = 0;
ses->serverDomain[1+(2*len)] = 0;
} /* else no more room so create dummy domain string */
else
ses->serverDomain =
kcalloc(2,GFP_KERNEL);
} else { /* no room so create dummy domain and NOS string */
ses->serverDomain = kcalloc(2, GFP_KERNEL);
ses->serverNOS = kcalloc(2, GFP_KERNEL);
}
} else { /* ASCII */
len = strnlen(bcc_ptr, 1024);
if (((int) bcc_ptr + len) - (int)
pByteArea(smb_buffer_response)
<= BCC(smb_buffer_response)) {
ses->serverOS = kcalloc(len + 1, GFP_KERNEL);
strncpy(ses->serverOS, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0; /* null terminate the string */
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverNOS = kcalloc(len + 1,GFP_KERNEL);
strncpy(ses->serverNOS, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverDomain = kcalloc(len + 1, GFP_KERNEL);
strncpy(ses->serverDomain, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
} else
cFYI(1,
("Variable field of length %d extends beyond end of smb ",
len));
}
} else {
cERROR(1,
(" Security Blob Length extends beyond end of SMB"));
}
} else {
cERROR(1, ("No session structure passed in."));
}
} else {
cERROR(1,
(" Invalid Word count %d: ",
smb_buffer_response->WordCount));
rc = -EIO;
}
if (smb_buffer)
buf_release(smb_buffer);
return rc;
}
int
CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
struct cifsSesInfo *ses,
char *challenge_from_server,
char *domain, int * pNTLMv2_flag,
const struct nls_table *nls_codepage)
{
struct smb_hdr *smb_buffer;
struct smb_hdr *smb_buffer_response;
SESSION_SETUP_ANDX *pSMB;
SESSION_SETUP_ANDX *pSMBr;
char *bcc_ptr;
int rc = 0;
int remaining_words = 0;
int bytes_returned = 0;
int len;
int SecurityBlobLength = sizeof (NEGOTIATE_MESSAGE);
PNEGOTIATE_MESSAGE SecurityBlob;
PCHALLENGE_MESSAGE SecurityBlob2;
cFYI(1, ("\nIn NTLMSSP sesssetup (negotiate) "));
*pNTLMv2_flag = FALSE;
smb_buffer = buf_get();
if (smb_buffer == 0) {
return -ENOMEM;
}
smb_buffer_response = smb_buffer;
pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response;
/* send SMBsessionSetup here */
header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
0 /* no tCon exists yet */ , 12 /* wct */ );
pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT);
pSMB->req.AndXCommand = 0xFF;
pSMB->req.MaxBufferSize = cpu_to_le16(ses->maxBuf);
pSMB->req.MaxMpxCount = cpu_to_le16(ses->maxReq);
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
pSMB->req.Capabilities =
CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
CAP_EXTENDED_SECURITY;
if (ses->capabilities & CAP_UNICODE) {
smb_buffer->Flags2 |= SMBFLG2_UNICODE;
pSMB->req.Capabilities |= CAP_UNICODE;
}
if (ses->capabilities & CAP_STATUS32) {
smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
pSMB->req.Capabilities |= CAP_STATUS32;
}
if (ses->capabilities & CAP_DFS) {
smb_buffer->Flags2 |= SMBFLG2_DFS;
pSMB->req.Capabilities |= CAP_DFS;
}
pSMB->req.Capabilities = cpu_to_le32(pSMB->req.Capabilities);
bcc_ptr = (char *) &pSMB->req.SecurityBlob;
SecurityBlob = (PNEGOTIATE_MESSAGE) bcc_ptr;
strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8);
SecurityBlob->MessageType = NtLmNegotiate;
SecurityBlob->NegotiateFlags =
NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_OEM |
NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_NTLM | 0x80000000 |
NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NTLMSSP_NEGOTIATE_128;
if(ntlmv2_support)
SecurityBlob->NegotiateFlags |= NTLMSSP_NEGOTIATE_NTLMV2;
/* setup pointers to domain name and workstation name */
bcc_ptr += SecurityBlobLength;
SecurityBlob->WorkstationName.Buffer = 0;
SecurityBlob->WorkstationName.Length = 0;
SecurityBlob->WorkstationName.MaximumLength = 0;
if (domain == NULL) {
SecurityBlob->DomainName.Buffer = 0;
SecurityBlob->DomainName.Length = 0;
SecurityBlob->DomainName.MaximumLength = 0;
} else {
SecurityBlob->NegotiateFlags |=
NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED;
strncpy(bcc_ptr, domain, 63);
SecurityBlob->DomainName.Length = strnlen(domain, 64);
SecurityBlob->DomainName.MaximumLength =
cpu_to_le16(SecurityBlob->DomainName.Length);
SecurityBlob->DomainName.Buffer =
cpu_to_le32((unsigned int) &SecurityBlob->
DomainString -
(unsigned int) &SecurityBlob->Signature);
bcc_ptr += SecurityBlob->DomainName.Length;
SecurityBlobLength += SecurityBlob->DomainName.Length;
SecurityBlob->DomainName.Length =
cpu_to_le16(SecurityBlob->DomainName.Length);
}
if (ses->capabilities & CAP_UNICODE) {
if ((int) bcc_ptr % 2) {
*bcc_ptr = 0;
bcc_ptr++;
}
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
32, nls_codepage);
bcc_ptr += 2 * bytes_returned;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, UTS_RELEASE, 32,
nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2; /* null terminate Linux version */
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
64, nls_codepage);
bcc_ptr += 2 * bytes_returned;
*(bcc_ptr + 1) = 0;
*(bcc_ptr + 2) = 0;
bcc_ptr += 2; /* null terminate network opsys string */
*(bcc_ptr + 1) = 0;
*(bcc_ptr + 2) = 0;
bcc_ptr += 2; /* null domain */
} else { /* ASCII */
strcpy(bcc_ptr, "Linux version ");
bcc_ptr += strlen("Linux version ");
strcpy(bcc_ptr, UTS_RELEASE);
bcc_ptr += strlen(UTS_RELEASE) + 1;
strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
bcc_ptr++; /* empty domain field */
*bcc_ptr = 0;
}
SecurityBlob->NegotiateFlags =
cpu_to_le32(SecurityBlob->NegotiateFlags);
pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength);
BCC(smb_buffer) = (int) bcc_ptr - (int) pByteArea(smb_buffer);
smb_buffer->smb_buf_length += BCC(smb_buffer);
BCC(smb_buffer) = cpu_to_le16(BCC(smb_buffer));
rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
&bytes_returned, 1);
if (smb_buffer_response->Status.CifsError ==
(NT_STATUS_MORE_PROCESSING_REQUIRED))
rc = 0;
if (rc) {
/* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */
} else if ((smb_buffer_response->WordCount == 3)
|| (smb_buffer_response->WordCount == 4)) {
pSMBr->resp.Action = le16_to_cpu(pSMBr->resp.Action);
pSMBr->resp.SecurityBlobLength =
le16_to_cpu(pSMBr->resp.SecurityBlobLength);
if (pSMBr->resp.Action & GUEST_LOGIN)
cFYI(1, (" Guest login"));
/* Do we want to set anything in SesInfo struct when guest login? */
bcc_ptr = pByteArea(smb_buffer_response);
/* response can have either 3 or 4 word count - Samba sends 3 */
SecurityBlob2 = (PCHALLENGE_MESSAGE) bcc_ptr;
if (SecurityBlob2->MessageType != NtLmChallenge) {
cFYI(1,
("\nUnexpected NTLMSSP message type received %d",
SecurityBlob2->MessageType));
} else if (ses) {
ses->Suid = smb_buffer_response->Uid; /* UID left in le format */
cFYI(1, ("UID = %d ", ses->Suid));
if ((pSMBr->resp.hdr.WordCount == 3)
|| ((pSMBr->resp.hdr.WordCount == 4)
&& (pSMBr->resp.SecurityBlobLength <
pSMBr->resp.ByteCount))) {
if (pSMBr->resp.hdr.WordCount == 4) {
bcc_ptr +=
pSMBr->resp.SecurityBlobLength;
cFYI(1,
("\nSecurity Blob Length %d ",
pSMBr->resp.SecurityBlobLength));
}
cFYI(1, ("\nNTLMSSP Challenge rcvd "));
memcpy(challenge_from_server,
SecurityBlob2->Challenge,
CIFS_CRYPTO_KEY_SIZE);
if(SecurityBlob2->NegotiateFlags & NTLMSSP_NEGOTIATE_NTLMV2)
*pNTLMv2_flag = TRUE;
if (smb_buffer->Flags2 &= SMBFLG2_UNICODE) {
if ((int) (bcc_ptr) % 2) {
remaining_words =
(BCC(smb_buffer_response)
- 1) / 2;
bcc_ptr++; /* Unicode strings must be word aligned */
} else {
remaining_words =
BCC
(smb_buffer_response) / 2;
}
len =
UniStrnlen((wchar_t *) bcc_ptr,
remaining_words - 1);
/* We look for obvious messed up bcc or strings in response so we do not go off
the end since (at least) WIN2K and Windows XP have a major bug in not null
terminating last Unicode string in response */
ses->serverOS =
kcalloc(2 * (len + 1), GFP_KERNEL);
cifs_strfromUCS_le(ses->serverOS,
(wchar_t *)
bcc_ptr, len,
nls_codepage);
bcc_ptr += 2 * (len + 1);
remaining_words -= len + 1;
ses->serverOS[2 * len] = 0;
ses->serverOS[1 + (2 * len)] = 0;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *)
bcc_ptr,
remaining_words
- 1);
ses->serverNOS =
kcalloc(2 * (len + 1),
GFP_KERNEL);
cifs_strfromUCS_le(ses->
serverNOS,
(wchar_t *)
bcc_ptr,
len,
nls_codepage);
bcc_ptr += 2 * (len + 1);
ses->serverNOS[2 * len] = 0;
ses->serverNOS[1 +
(2 * len)] = 0;
remaining_words -= len + 1;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
/* last string is not always null terminated (for e.g. for Windows XP & 2000) */
ses->serverDomain =
kcalloc(2 *
(len +
1),
GFP_KERNEL);
cifs_strfromUCS_le
(ses->
serverDomain,
(wchar_t *)
bcc_ptr, len,
nls_codepage);
bcc_ptr +=
2 * (len + 1);
ses->
serverDomain[2
* len]
= 0;
ses->
serverDomain[1
+
(2
*
len)]
= 0;
} /* else no more room so create dummy domain string */
else
ses->serverDomain =
kcalloc(2,
GFP_KERNEL);
} else { /* no room so create dummy domain and NOS string */
ses->serverDomain =
kcalloc(2, GFP_KERNEL);
ses->serverNOS =
kcalloc(2, GFP_KERNEL);
}
} else { /* ASCII */
len = strnlen(bcc_ptr, 1024);
if (((int) bcc_ptr + len) - (int)
pByteArea(smb_buffer_response)
<= BCC(smb_buffer_response)) {
ses->serverOS =
kcalloc(len + 1,
GFP_KERNEL);
strncpy(ses->serverOS,
bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0; /* null terminate string */
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverNOS =
kcalloc(len + 1,
GFP_KERNEL);
strncpy(ses->serverNOS, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverDomain =
kcalloc(len + 1,
GFP_KERNEL);
strncpy(ses->serverDomain, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
} else
cFYI(1,
("Variable field of length %d extends beyond end of smb ",
len));
}
} else {
cERROR(1,
(" Security Blob Length extends beyond end of SMB"));
}
} else {
cERROR(1, ("No session structure passed in."));
}
} else {
cERROR(1,
(" Invalid Word count %d: ",
smb_buffer_response->WordCount));
rc = -EIO;
}
if (smb_buffer)
buf_release(smb_buffer);
return rc;
}
int
CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
char *user, char *domain,
char *ntlm_session_key,
char *lanman_session_key, int ntlmv2_flag,
const struct nls_table *nls_codepage)
{
struct smb_hdr *smb_buffer;
struct smb_hdr *smb_buffer_response;
SESSION_SETUP_ANDX *pSMB;
SESSION_SETUP_ANDX *pSMBr;
char *bcc_ptr;
int rc = 0;
int remaining_words = 0;
int bytes_returned = 0;
int len;
int SecurityBlobLength = sizeof (AUTHENTICATE_MESSAGE);
PAUTHENTICATE_MESSAGE SecurityBlob;
cFYI(1, ("\nIn NTLMSSPSessSetup (Authenticate)"));
smb_buffer = buf_get();
if (smb_buffer == 0) {
return -ENOMEM;
}
smb_buffer_response = smb_buffer;
pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response;
/* send SMBsessionSetup here */
header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
0 /* no tCon exists yet */ , 12 /* wct */ );
pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT);
pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
pSMB->req.AndXCommand = 0xFF;
pSMB->req.MaxBufferSize = cpu_to_le16(ses->maxBuf);
pSMB->req.MaxMpxCount = cpu_to_le16(ses->maxReq);
pSMB->req.hdr.Uid = ses->Suid;
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
pSMB->req.Capabilities =
CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
CAP_EXTENDED_SECURITY;
if (ses->capabilities & CAP_UNICODE) {
smb_buffer->Flags2 |= SMBFLG2_UNICODE;
pSMB->req.Capabilities |= CAP_UNICODE;
}
if (ses->capabilities & CAP_STATUS32) {
smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
pSMB->req.Capabilities |= CAP_STATUS32;
}
if (ses->capabilities & CAP_DFS) {
smb_buffer->Flags2 |= SMBFLG2_DFS;
pSMB->req.Capabilities |= CAP_DFS;
}
pSMB->req.Capabilities = cpu_to_le32(pSMB->req.Capabilities);
bcc_ptr = (char *) &pSMB->req.SecurityBlob;
SecurityBlob = (PAUTHENTICATE_MESSAGE) bcc_ptr;
strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8);
SecurityBlob->MessageType = NtLmAuthenticate;
bcc_ptr += SecurityBlobLength;
SecurityBlob->NegotiateFlags =
NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET |
NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO |
0x80000000 | NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NTLMSSP_NEGOTIATE_128;
if(ntlmv2_flag)
SecurityBlob->NegotiateFlags |= NTLMSSP_NEGOTIATE_NTLMV2;
/* setup pointers to domain name and workstation name */
SecurityBlob->WorkstationName.Buffer = 0;
SecurityBlob->WorkstationName.Length = 0;
SecurityBlob->WorkstationName.MaximumLength = 0;
SecurityBlob->SessionKey.Length = 0;
SecurityBlob->SessionKey.MaximumLength = 0;
SecurityBlob->SessionKey.Buffer = 0;
SecurityBlob->LmChallengeResponse.Length = 0;
SecurityBlob->LmChallengeResponse.MaximumLength = 0;
SecurityBlob->LmChallengeResponse.Buffer = 0;
SecurityBlob->NtChallengeResponse.Length =
cpu_to_le16(CIFS_SESSION_KEY_SIZE);
SecurityBlob->NtChallengeResponse.MaximumLength =
cpu_to_le16(CIFS_SESSION_KEY_SIZE);
memcpy(bcc_ptr, ntlm_session_key, CIFS_SESSION_KEY_SIZE);
SecurityBlob->NtChallengeResponse.Buffer =
cpu_to_le32(SecurityBlobLength);
SecurityBlobLength += CIFS_SESSION_KEY_SIZE;
bcc_ptr += CIFS_SESSION_KEY_SIZE;
if (ses->capabilities & CAP_UNICODE) {
if (domain == NULL) {
SecurityBlob->DomainName.Buffer = 0;
SecurityBlob->DomainName.Length = 0;
SecurityBlob->DomainName.MaximumLength = 0;
} else {
SecurityBlob->DomainName.Length =
cifs_strtoUCS((wchar_t *) bcc_ptr, domain, 64,
nls_codepage);
SecurityBlob->DomainName.Length *= 2;
SecurityBlob->DomainName.MaximumLength =
cpu_to_le16(SecurityBlob->DomainName.Length);
SecurityBlob->DomainName.Buffer =
cpu_to_le32(SecurityBlobLength);
bcc_ptr += SecurityBlob->DomainName.Length;
SecurityBlobLength += SecurityBlob->DomainName.Length;
SecurityBlob->DomainName.Length =
cpu_to_le16(SecurityBlob->DomainName.Length);
}
if (user == NULL) {
SecurityBlob->UserName.Buffer = 0;
SecurityBlob->UserName.Length = 0;
SecurityBlob->UserName.MaximumLength = 0;
} else {
SecurityBlob->UserName.Length =
cifs_strtoUCS((wchar_t *) bcc_ptr, user, 64,
nls_codepage);
SecurityBlob->UserName.Length *= 2;
SecurityBlob->UserName.MaximumLength =
cpu_to_le16(SecurityBlob->UserName.Length);
SecurityBlob->UserName.Buffer =
cpu_to_le32(SecurityBlobLength);
bcc_ptr += SecurityBlob->UserName.Length;
SecurityBlobLength += SecurityBlob->UserName.Length;
SecurityBlob->UserName.Length =
cpu_to_le16(SecurityBlob->UserName.Length);
}
/* SecurityBlob->WorkstationName.Length = cifs_strtoUCS((wchar_t *) bcc_ptr, "AMACHINE",64, nls_codepage);
SecurityBlob->WorkstationName.Length *= 2;
SecurityBlob->WorkstationName.MaximumLength = cpu_to_le16(SecurityBlob->WorkstationName.Length);
SecurityBlob->WorkstationName.Buffer = cpu_to_le32(SecurityBlobLength);
bcc_ptr += SecurityBlob->WorkstationName.Length;
SecurityBlobLength += SecurityBlob->WorkstationName.Length;
SecurityBlob->WorkstationName.Length = cpu_to_le16(SecurityBlob->WorkstationName.Length); */
if ((int) bcc_ptr % 2) {
*bcc_ptr = 0;
bcc_ptr++;
}
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
32, nls_codepage);
bcc_ptr += 2 * bytes_returned;
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, UTS_RELEASE, 32,
nls_codepage);
bcc_ptr += 2 * bytes_returned;
bcc_ptr += 2; /* null term version string */
bytes_returned =
cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
64, nls_codepage);
bcc_ptr += 2 * bytes_returned;
*(bcc_ptr + 1) = 0;
*(bcc_ptr + 2) = 0;
bcc_ptr += 2; /* null terminate network opsys string */
*(bcc_ptr + 1) = 0;
*(bcc_ptr + 2) = 0;
bcc_ptr += 2; /* null domain */
} else { /* ASCII */
if (domain == NULL) {
SecurityBlob->DomainName.Buffer = 0;
SecurityBlob->DomainName.Length = 0;
SecurityBlob->DomainName.MaximumLength = 0;
} else {
SecurityBlob->NegotiateFlags |=
NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED;
strncpy(bcc_ptr, domain, 63);
SecurityBlob->DomainName.Length = strnlen(domain, 64);
SecurityBlob->DomainName.MaximumLength =
cpu_to_le16(SecurityBlob->DomainName.Length);
SecurityBlob->DomainName.Buffer =
cpu_to_le32(SecurityBlobLength);
bcc_ptr += SecurityBlob->DomainName.Length;
SecurityBlobLength += SecurityBlob->DomainName.Length;
SecurityBlob->DomainName.Length =
cpu_to_le16(SecurityBlob->DomainName.Length);
}
if (user == NULL) {
SecurityBlob->UserName.Buffer = 0;
SecurityBlob->UserName.Length = 0;
SecurityBlob->UserName.MaximumLength = 0;
} else {
strncpy(bcc_ptr, user, 63);
SecurityBlob->UserName.Length = strnlen(user, 64);
SecurityBlob->UserName.MaximumLength =
cpu_to_le16(SecurityBlob->UserName.Length);
SecurityBlob->UserName.Buffer =
cpu_to_le32(SecurityBlobLength);
bcc_ptr += SecurityBlob->UserName.Length;
SecurityBlobLength += SecurityBlob->UserName.Length;
SecurityBlob->UserName.Length =
cpu_to_le16(SecurityBlob->UserName.Length);
}
/* BB fill in our workstation name if known BB */
strcpy(bcc_ptr, "Linux version ");
bcc_ptr += strlen("Linux version ");
strcpy(bcc_ptr, UTS_RELEASE);
bcc_ptr += strlen(UTS_RELEASE) + 1;
strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
bcc_ptr++; /* null domain */
*bcc_ptr = 0;
}
SecurityBlob->NegotiateFlags =
cpu_to_le32(SecurityBlob->NegotiateFlags);
pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength);
BCC(smb_buffer) = (int) bcc_ptr - (int) pByteArea(smb_buffer);
smb_buffer->smb_buf_length += BCC(smb_buffer);
BCC(smb_buffer) = cpu_to_le16(BCC(smb_buffer));
rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
&bytes_returned, 1);
if (rc) {
/* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */
} else if ((smb_buffer_response->WordCount == 3)
|| (smb_buffer_response->WordCount == 4)) {
pSMBr->resp.Action = le16_to_cpu(pSMBr->resp.Action);
pSMBr->resp.SecurityBlobLength =
le16_to_cpu(pSMBr->resp.SecurityBlobLength);
if (pSMBr->resp.Action & GUEST_LOGIN)
cFYI(1, (" Guest login")); /* BB do we want to set anything in SesInfo struct ? */
/* if(SecurityBlob2->MessageType != NtLm??){
cFYI("\nUnexpected message type on auth response is %d "));
} */
if (ses) {
cFYI(1,
("Does UID on challenge %d match auth response UID %d ",
ses->Suid, smb_buffer_response->Uid));
ses->Suid = smb_buffer_response->Uid; /* UID left in wire format */
bcc_ptr = pByteArea(smb_buffer_response);
/* response can have either 3 or 4 word count - Samba sends 3 */
if ((pSMBr->resp.hdr.WordCount == 3)
|| ((pSMBr->resp.hdr.WordCount == 4)
&& (pSMBr->resp.SecurityBlobLength <
pSMBr->resp.ByteCount))) {
if (pSMBr->resp.hdr.WordCount == 4) {
bcc_ptr +=
pSMBr->resp.SecurityBlobLength;
cFYI(1,
("\nSecurity Blob Length %d ",
pSMBr->resp.SecurityBlobLength));
}
cFYI(1,
("\nNTLMSSP response to Authenticate "));
if (smb_buffer->Flags2 &= SMBFLG2_UNICODE) {
if ((int) (bcc_ptr) % 2) {
remaining_words =
(BCC(smb_buffer_response)
- 1) / 2;
bcc_ptr++; /* Unicode strings must be word aligned */
} else {
remaining_words = BCC(smb_buffer_response) / 2;
}
len =
UniStrnlen((wchar_t *) bcc_ptr,remaining_words - 1);
/* We look for obvious messed up bcc or strings in response so we do not go off
the end since (at least) WIN2K and Windows XP have a major bug in not null
terminating last Unicode string in response */
ses->serverOS =
kcalloc(2 * (len + 1), GFP_KERNEL);
cifs_strfromUCS_le(ses->serverOS,
(wchar_t *)
bcc_ptr, len,
nls_codepage);
bcc_ptr += 2 * (len + 1);
remaining_words -= len + 1;
ses->serverOS[2 * len] = 0;
ses->serverOS[1 + (2 * len)] = 0;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *)
bcc_ptr,
remaining_words
- 1);
ses->serverNOS =
kcalloc(2 * (len + 1),
GFP_KERNEL);
cifs_strfromUCS_le(ses->
serverNOS,
(wchar_t *)
bcc_ptr,
len,
nls_codepage);
bcc_ptr += 2 * (len + 1);
ses->serverNOS[2 * len] = 0;
ses->serverNOS[1+(2*len)] = 0;
remaining_words -= len + 1;
if (remaining_words > 0) {
len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
/* last string not always null terminated (e.g. for Windows XP & 2000) */
ses->serverDomain =
kcalloc(2 *
(len +
1),
GFP_KERNEL);
cifs_strfromUCS_le
(ses->
serverDomain,
(wchar_t *)
bcc_ptr, len,
nls_codepage);
bcc_ptr +=
2 * (len + 1);
ses->
serverDomain[2
* len]
= 0;
ses->
serverDomain[1
+
(2
*
len)]
= 0;
} /* else no more room so create dummy domain string */
else
ses->serverDomain = kcalloc(2,GFP_KERNEL);
} else { /* no room so create dummy domain and NOS string */
ses->serverDomain = kcalloc(2, GFP_KERNEL);
ses->serverNOS = kcalloc(2, GFP_KERNEL);
}
} else { /* ASCII */
len = strnlen(bcc_ptr, 1024);
if (((int) bcc_ptr + len) -
(int) pByteArea(smb_buffer_response)
<= BCC(smb_buffer_response)) {
ses->serverOS = kcalloc(len + 1,GFP_KERNEL);
strncpy(ses->serverOS,bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0; /* null terminate the string */
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverNOS = kcalloc(len+1,GFP_KERNEL);
strncpy(ses->serverNOS, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
len = strnlen(bcc_ptr, 1024);
ses->serverDomain = kcalloc(len+1,GFP_KERNEL);
strncpy(ses->serverDomain, bcc_ptr, len);
bcc_ptr += len;
bcc_ptr[0] = 0;
bcc_ptr++;
} else
cFYI(1,
("Variable field of length %d extends beyond end of smb ",
len));
}
} else {
cERROR(1,
(" Security Blob Length extends beyond end of SMB"));
}
} else {
cERROR(1, ("No session structure passed in."));
}
} else {
cERROR(1,
(" Invalid Word count %d: ",
smb_buffer_response->WordCount));
rc = -EIO;
}
if (smb_buffer)
buf_release(smb_buffer);
return rc;
}
int
CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
const char *tree, struct cifsTconInfo *tcon,
const struct nls_table *nls_codepage)
{
struct smb_hdr *smb_buffer;
struct smb_hdr *smb_buffer_response;
TCONX_REQ *pSMB;
TCONX_RSP *pSMBr;
char *bcc_ptr;
int rc = 0;
int length;
if (ses == NULL)
return -EIO;
smb_buffer = buf_get();
if (smb_buffer == 0) {
return -ENOMEM;
}
smb_buffer_response = smb_buffer;
header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX,
0 /*no tid */ , 4 /*wct */ );
smb_buffer->Uid = ses->Suid;
pSMB = (TCONX_REQ *) smb_buffer;
pSMBr = (TCONX_RSP *) smb_buffer_response;
pSMB->AndXCommand = 0xFF;
pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO);
pSMB->PasswordLength = cpu_to_le16(1); /* minimum */
bcc_ptr = &(pSMB->Password[0]);
bcc_ptr++; /* skip password */
if(ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
if (ses->capabilities & CAP_STATUS32) {
smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
}
if (ses->capabilities & CAP_DFS) {
smb_buffer->Flags2 |= SMBFLG2_DFS;
}
if (ses->capabilities & CAP_UNICODE) {
smb_buffer->Flags2 |= SMBFLG2_UNICODE;
length =
cifs_strtoUCS((wchar_t *) bcc_ptr, tree, 100, nls_codepage);
bcc_ptr += 2 * length; /* convert num of 16 bit words to bytes */
bcc_ptr += 2; /* skip trailing null */
} else { /* ASCII */
strcpy(bcc_ptr, tree);
bcc_ptr += strlen(tree) + 1;
}
strcpy(bcc_ptr, "?????");
bcc_ptr += strlen("?????");
bcc_ptr += 1;
BCC(smb_buffer) = (int) bcc_ptr - (int) pByteArea(smb_buffer);
smb_buffer->smb_buf_length += BCC(smb_buffer);
BCC(smb_buffer) = cpu_to_le16(BCC(smb_buffer));
rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length, 0);
/* if (rc) rc = map_smb_to_linux_error(smb_buffer_response); */
/* above now done in SendReceive */
if ((rc == 0) && (tcon != NULL)) {
tcon->tid = smb_buffer_response->Tid;
bcc_ptr = pByteArea(smb_buffer_response);
length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2);
/* skip service field (NB: this field is always ASCII) */
bcc_ptr += length + 1;
strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
if (smb_buffer->Flags2 &= SMBFLG2_UNICODE) {
length = UniStrnlen((wchar_t *) bcc_ptr, 512);
if (((int) bcc_ptr + (2 * length)) -
(int) pByteArea(smb_buffer_response) <=
BCC(smb_buffer_response)) {
tcon->nativeFileSystem =
kcalloc(length + 2, GFP_KERNEL);
cifs_strfromUCS_le(tcon->nativeFileSystem,
(wchar_t *) bcc_ptr,
length, nls_codepage);
bcc_ptr += 2 * length;
bcc_ptr[0] = 0; /* null terminate the string */
bcc_ptr[1] = 0;
bcc_ptr += 2;
}
/* else do not bother copying these informational fields */
} else {
length = strnlen(bcc_ptr, 1024);
if (((int) bcc_ptr + length) -
(int) pByteArea(smb_buffer_response) <=
BCC(smb_buffer_response)) {
tcon->nativeFileSystem =
kcalloc(length + 1, GFP_KERNEL);
strncpy(tcon->nativeFileSystem, bcc_ptr,
length);
}
/* else do not bother copying these informational fields */
}
tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport);
cFYI(1, ("\nTcon flags: 0x%x ", tcon->Flags));
} else if ((rc == 0) && tcon == NULL) {
/* all we need to save for IPC$ connection */
ses->ipc_tid = smb_buffer_response->Tid;
}
if (smb_buffer)
buf_release(smb_buffer);
return rc;
}
int
cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
{
int rc = 0;
int xid;
struct cifsSesInfo *ses = NULL;
xid = GetXid();
if (cifs_sb->tcon) {
ses = cifs_sb->tcon->ses; /* save ptr to ses before delete tcon!*/
rc = CIFSSMBTDis(xid, cifs_sb->tcon);
if (rc == -EBUSY) {
FreeXid(xid);
return 0;
}
tconInfoFree(cifs_sb->tcon);
if ((ses) && (ses->server)) {
cFYI(1, ("\nAbout to do SMBLogoff "));
rc = CIFSSMBLogoff(xid, ses);
if (rc == -EBUSY) {
/* BB this looks wrong - why is this here? */
FreeXid(xid);
return 0;
}
/* wake_up_process(ses->server->tsk);*/ /* was worth a try */
schedule_timeout(HZ / 4); /* give captive thread time to exit */
if((ses->server) && (ses->server->ssocket)) {
cFYI(1,("\nWaking up socket by sending it signal "));
send_sig(SIGINT,ses->server->tsk,1);
/* No luck figuring out a better way to_close socket */
/*ses->server->ssocket->sk->prot->close(ses->server->ssocket->sk,0);*/
/* ses->server->ssocket = NULL; */ /* serialize better */
/* sock_wake_async(ses->server->ssocket,3,POLL_HUP); */
}
} else
cFYI(1, ("\nNo session or bad tcon"));
}
/* BB future check active count of tcon and then free if needed BB */
cifs_sb->tcon = NULL;
if (ses) {
schedule_timeout(HZ / 2);
/* if ((ses->server) && (ses->server->ssocket)) {
cFYI(1,("\nReleasing socket "));
sock_release(ses->server->ssocket);
kfree(ses->server);
} */
}
if (ses)
sesInfoFree(ses);
FreeXid(xid);
return rc; /* BB check if we should always return zero here */
}
/*
* fs/cifs/dir.c
*
* vfs operations that deal with dentries
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/slab.h>
#include "cifsfs.h"
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
void
renew_parental_timestamps(struct dentry *direntry)
{
/* BB check if there is a way to get the kernel to do this or if we really need this */
do {
direntry->d_time = jiffies;
direntry = direntry->d_parent;
} while (!IS_ROOT(direntry)); /* BB for DFS case should stop at the root of share which could be lower than root of this mount due to implicit dfs connections */
}
/* Note: caller must free return buffer */
char *
build_path_from_dentry(struct dentry *direntry)
{
struct dentry *temp;
int namelen = 0;
char *full_path;
for (temp = direntry; !IS_ROOT(temp);) {
namelen += (1 + temp->d_name.len);
cFYI(1, (" len %d ", namelen));
temp = temp->d_parent;
}
namelen += 1; /* allow for trailing null */
cFYI(1, ("Final namelength (in build_path): %d ", namelen)); /* BB remove */
full_path = kmalloc(namelen, GFP_KERNEL);
namelen--;
full_path[namelen] = 0; /* trailing null */
for (temp = direntry; !IS_ROOT(temp);) {
namelen -= 1 + temp->d_name.len;
if (namelen < 0) {
break;
} else {
full_path[namelen] = '\\';
strncpy(full_path + namelen + 1, temp->d_name.name,
temp->d_name.len);
cFYI(1, (" name: %s ", full_path + namelen)); /* BB remove */
}
temp = temp->d_parent;
}
if (namelen != 0)
cERROR(1,
("\nWe did not end path lookup where we expected namelen is %d",
namelen));
return full_path;
}
char *
build_wildcard_path_from_dentry(struct dentry *direntry)
{
struct dentry *temp;
int namelen = 0;
char *full_path;
for (temp = direntry; !IS_ROOT(temp);) {
namelen += (1 + temp->d_name.len);
temp = temp->d_parent;
}
namelen += 3; /* allow for trailing null and wildcard (slash and *) */
full_path = kmalloc(namelen, GFP_KERNEL);
namelen--;
full_path[namelen] = 0; /* trailing null */
namelen--;
full_path[namelen] = '*';
namelen--;
full_path[namelen] = '\\';
for (temp = direntry; !IS_ROOT(temp);) {
namelen -= 1 + temp->d_name.len;
if (namelen < 0) {
break;
} else {
full_path[namelen] = '\\';
strncpy(full_path + namelen + 1, temp->d_name.name,
temp->d_name.len);
}
temp = temp->d_parent;
}
if (namelen != 0)
cERROR(1,
("\nWe did not end path lookup where we expected namelen is %d",
namelen));
return full_path;
}
/* Inode operations in similar order to how they appear in the Linux file fs.h */
int
cifs_create(struct inode *inode, struct dentry *direntry, int mode)
{
int rc = -ENOENT;
int xid;
int oplock = FALSE; /* no need to oplock when we are not going to read from the file */
__u16 fileHandle;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
struct inode *newinode = NULL;
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
/* BB add processing for setting the equivalent of mode - e.g. via CreateX with ACLs */
rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OVERWRITE_IF, GENERIC_ALL
/* 0x20197 was used previously */ , mode,
&fileHandle, &oplock, cifs_sb->local_nls);
if (rc) {
cFYI(1, ("\ncifs_create returned 0x%x ", rc));
} else {
if (pTcon->ses->capabilities & CAP_UNIX)
rc = cifs_get_inode_info_unix(&newinode, full_path,
inode->i_sb);
else
rc = cifs_get_inode_info(&newinode, full_path,
inode->i_sb);
if (rc != 0) {
cFYI(1,
("\nCreate worked but get_inode_info failed with rc = %d ",
rc));
/* close handle */
} else {
direntry->d_op = &cifs_dentry_ops;
d_instantiate(direntry, newinode);
}
CIFSSMBClose(xid, pTcon, fileHandle);
/* BB In the future chain close with the NTCreateX to narrow window */
if(newinode)
newinode->i_mode = mode;
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
struct dentry *
cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry)
{
int rc, xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
struct inode *newInode = NULL;
char *full_path = NULL;
xid = GetXid();
cFYI(1,
(" parent inode = 0x%p name is: %s and dentry = 0x%p",
parent_dir_inode, direntry->d_name.name, direntry));
/* BB Add check of incoming data - e.g. frame not longer than maximum SMB - let server check the namelen BB */
/* check whether path exists */
cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
if (direntry->d_inode != NULL) {
cFYI(1, (" non-NULL inode in lookup"));
} else {
cFYI(1, (" NULL inode in lookup"));
}
cFYI(1,
(" Full path: %s inode = 0x%p\n", full_path, direntry->d_inode));
if (pTcon->ses->capabilities & CAP_UNIX)
rc = cifs_get_inode_info_unix(&newInode, full_path,
parent_dir_inode->i_sb);
else
rc = cifs_get_inode_info(&newInode, full_path,
parent_dir_inode->i_sb);
if ((rc == 0) && (newInode != NULL)) {
direntry->d_op = &cifs_dentry_ops;
d_add(direntry, newInode);
/* since paths are not looked up by component - the parent directories are presumed to be good here */
renew_parental_timestamps(direntry);
} else if (rc == -ENOENT) {
rc = 0;
d_add(direntry, NULL);
} else {
cERROR(1,
("Error 0x%x or (%d decimal) on cifs_get_inode_info in lookup\n",
rc, rc));
/* BB special case check for Access Denied - watch security exposure of returning dir info implicitly via different rc if file exists or not but no access BB */
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return ERR_PTR(rc);
}
int
cifs_dir_open(struct inode *inode, struct file *file)
{ /* NB: currently unused since searches are opened in readdir */
int rc = 0;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_wildcard_path_from_dentry(file->f_dentry);
cFYI(1, (" inode = 0x%p and full path is %s\n", inode, full_path));
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
static int
cifs_d_revalidate(struct dentry *direntry, int flags)
{
int isValid = 1;
/* lock_kernel(); *//* surely we do not want to lock the kernel for a whole network round trip which could take seconds */
if (direntry->d_inode) {
cFYI(1,
("In cifs_d_revalidate, name = %s and inode = 0x%p with count %d with time %ld and dentry 0x%p with time %ld\n",
direntry->d_name.name, direntry->d_inode,
direntry->d_inode->i_count.counter,
direntry->d_inode->i_atime, direntry, direntry->d_time));
if (cifs_revalidate(direntry)) {
/* unlock_kernel(); */
return 0;
}
} else {
cFYI(1,
("In cifs_d_revalidate with no inode but name = %s and dentry 0x%p\n",
direntry->d_name.name, direntry));
}
/* unlock_kernel(); */
return isValid;
}
/* static int cifs_d_delete(struct dentry *direntry)
{
int rc = 0;
cFYI(1, ("In cifs d_delete, name = %s\n", direntry->d_name.name));
return rc;
} */
struct dentry_operations cifs_dentry_ops = {
.d_revalidate = cifs_d_revalidate,
/* d_delete: cifs_d_delete, *//* not needed except for debugging */
/* no need for d_hash, d_compare, d_release, d_iput ... yet. BB confirm this BB */
};
/*
* fs/cifs/file.c
*
* vfs operations that deal with files
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/fcntl.h>
#include <linux/version.h>
#include <linux/pagemap.h>
#include <linux/smp_lock.h>
#include <asm/div64.h>
#include "cifsfs.h"
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_unicode.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
int
cifs_open(struct inode *inode, struct file *file)
{
int rc = -EACCES;
int xid, oplock;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
struct cifsFileInfo *pCifsFile;
struct cifsInodeInfo *pCifsInode;
char *full_path = NULL;
int desiredAccess = 0x20197;
int disposition = FILE_OPEN;
__u16 netfid;
xid = GetXid();
cFYI(1, (" inode = 0x%p file flags are %x", inode, file->f_flags));
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(file->f_dentry);
if ((file->f_flags & O_ACCMODE) == O_RDONLY)
desiredAccess = GENERIC_READ;
else if ((file->f_flags & O_ACCMODE) == O_WRONLY)
desiredAccess = GENERIC_WRITE;
else if ((file->f_flags & O_ACCMODE) == O_RDWR)
desiredAccess = GENERIC_ALL;
/* BB check other flags carefully to find equivalent NTCreateX flags */
/*
#define O_CREAT 0100
#define O_EXCL 0200
#define O_NOCTTY 0400
#define O_TRUNC 01000
#define O_APPEND 02000
#define O_NONBLOCK 04000
#define O_NDELAY O_NONBLOCK
#define O_SYNC 010000
#define FASYNC 020000
#define O_DIRECT 040000
#define O_LARGEFILE 0100000
#define O_DIRECTORY 0200000
#define O_NOFOLLOW 0400000
#define O_ATOMICLOOKUP 01000000 */
if (file->f_flags & O_CREAT)
disposition = FILE_OVERWRITE;
/* BB finish adding in oplock support BB */
if (oplockEnabled)
oplock = TRUE;
else
oplock = FALSE;
/* BB pass O_SYNC flag through on file attributes .. BB */
rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, desiredAccess,
-1 /* i.e. dummy value, ignored for time being */,
&netfid, &oplock, cifs_sb->local_nls);
if (rc) {
cFYI(1, ("\ncifs_open returned 0x%x ", rc));
cFYI(1, (" oplock: %d ", oplock));
} else {
file->private_data =
kmalloc(sizeof (struct cifsFileInfo), GFP_KERNEL);
if (file->private_data) {
memset(file->private_data, 0,
sizeof (struct cifsFileInfo));
pCifsFile = (struct cifsFileInfo *) file->private_data;
pCifsFile->netfid = netfid;
pCifsFile->pid = current->pid;
list_add(&pCifsFile->tlist,&pTcon->openFileList);
pCifsInode = CIFS_I(file->f_dentry->d_inode);
list_add(&pCifsFile->flist,&pCifsInode->openFileList);
if(file->f_flags & O_CREAT) {
/* time to set mode which we can not
set earlier due to problems creating new read-only files */
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
CIFSSMBUnixSetPerms(xid, pTcon, full_path, inode->i_mode,
0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF,
cifs_sb->local_nls);
else {/* BB to be implemented via Windows secrty descriptors*/
/* eg CIFSSMBWinSetPerms(xid,pTcon,full_path,mode,-1,-1,local_nls);*/
/* in the meantime we could set the r/o dos attribute
when perms are e.g.:
mode & 0222 == 0 */
}
}
}
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
int
cifs_close(struct inode *inode, struct file *file)
{
int rc = 0;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
struct cifsFileInfo *pSMBFile =
(struct cifsFileInfo *) file->private_data;
cFYI(1, ("\n inode = 0x%p with ", inode));
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
if (pSMBFile) {
list_del(&pSMBFile->flist);
list_del(&pSMBFile->tlist);
rc = CIFSSMBClose(xid, pTcon, pSMBFile->netfid);
kfree(file->private_data);
file->private_data = NULL;
} else
rc = -EBADF;
FreeXid(xid);
return rc;
}
int
cifs_closedir(struct inode *inode, struct file *file)
{
int rc = 0;
int xid;
struct cifsFileInfo *pSMBFileStruct =
(struct cifsFileInfo *) file->private_data;
cFYI(1, ("\nClosedir inode = 0x%p with ", inode));
xid = GetXid();
if (pSMBFileStruct) {
cFYI(1, ("\nFreeing private data in close dir"));
kfree(file->private_data);
file->private_data = NULL;
}
FreeXid(xid);
return rc;
}
int
cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
{
int rc, xid;
__u32 lockType = LOCKING_ANDX_LARGE_FILES;
__u32 numLock = 0;
__u32 numUnlock = 0;
__u64 length;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
length = 1 + pfLock->fl_end - pfLock->fl_start;
rc = -EACCES;
xid = GetXid();
cFYI(1,
("\nLock parm: 0x%x flockflags: 0x%x flocktype: 0x%x start: %lld end: %lld",
cmd, pfLock->fl_flags, pfLock->fl_type, pfLock->fl_start,
pfLock->fl_end));
if (pfLock->fl_flags & FL_POSIX)
cFYI(1, ("\nPosix "));
if (pfLock->fl_flags & FL_FLOCK)
cFYI(1, ("\nFlock "));
if (pfLock->fl_flags & FL_SLEEP)
cFYI(1, ("\nBlocking lock "));
if (pfLock->fl_flags & FL_ACCESS)
cFYI(1, ("\nProcess suspended by mandatory locking "));
if (pfLock->fl_flags & FL_LEASE)
cFYI(1, ("\nLease on file "));
if (pfLock->fl_flags & 0xFFD0)
cFYI(1, ("\n Unknown lock flags "));
if (pfLock->fl_type == F_WRLCK) {
cFYI(1, ("\nF_WRLCK "));
numLock = 1;
} else if (pfLock->fl_type == F_UNLCK) {
cFYI(1, ("\nF_UNLCK "));
numUnlock = 1;
} else if (pfLock->fl_type == F_RDLCK) {
cFYI(1, ("\nF_RDLCK "));
lockType |= LOCKING_ANDX_SHARED_LOCK;
numLock = 1;
} else if (pfLock->fl_type == F_EXLCK) {
cFYI(1, ("\nF_EXLCK "));
numLock = 1;
} else if (pfLock->fl_type == F_SHLCK) {
cFYI(1, ("\nF_SHLCK "));
lockType |= LOCKING_ANDX_SHARED_LOCK;
numLock = 1;
} else
cFYI(1, ("\nUnknown type of lock "));
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
if (file->private_data == NULL) {
FreeXid(xid);
return -EBADF;
}
if (IS_GETLK(cmd)) {
rc = CIFSSMBLock(xid, pTcon,
((struct cifsFileInfo *) file->
private_data)->netfid,
length,
pfLock->fl_start, 0, 1, lockType,
0 /* wait flag */ );
if (rc == 0) {
rc = CIFSSMBLock(xid, pTcon,
((struct cifsFileInfo *) file->
private_data)->netfid,
length,
pfLock->fl_start, 1 /* numUnlock */ ,
0 /* numLock */ , lockType,
0 /* wait flag */ );
pfLock->fl_type = F_UNLCK;
if (rc != 0)
cERROR(1,
("\nError unlocking previously locked range %d during test of lock ",
rc));
rc = 0;
} else {
/* if rc == ERR_SHARING_VIOLATION ? */
rc = 0; /* do not change lock type to unlock since range in use */
}
FreeXid(xid);
return rc;
}
rc = CIFSSMBLock(xid, pTcon,
((struct cifsFileInfo *) file->private_data)->
netfid, length,
pfLock->fl_start, numUnlock, numLock, lockType,
0 /* wait flag */ );
FreeXid(xid);
return rc;
}
ssize_t
cifs_write(struct file * file, const char *write_data,
size_t write_size, loff_t * poffset)
{
int rc = 0;
int bytes_written = 0;
int total_written;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
int xid, long_op;
xid = GetXid();
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
/*cFYI(1,
(" write %d bytes to offset %lld of %s \n", write_size,
*poffset, file->f_dentry->d_name.name)); */
if (file->private_data == NULL) {
FreeXid(xid);
return -EBADF;
}
if (*poffset > file->f_dentry->d_inode->i_size)
long_op = 2; /* writes past end of file can take a long time */
else
long_op = 1;
for (total_written = 0; write_size > total_written;
total_written += bytes_written) {
rc = CIFSSMBWrite(xid, pTcon,
((struct cifsFileInfo *) file->
private_data)->netfid,
write_size - total_written, *poffset,
&bytes_written,
write_data + total_written, long_op);
if (rc || (bytes_written == 0)) {
FreeXid(xid);
if (total_written)
break;
else {
FreeXid(xid);
return rc;
}
} else
*poffset += bytes_written;
long_op = FALSE; /* subsequent writes fast - 15 seconds is plenty */
}
file->f_dentry->d_inode->i_ctime = file->f_dentry->d_inode->i_mtime = CURRENT_TIME;
if (bytes_written > 0) {
if (*poffset > file->f_dentry->d_inode->i_size)
file->f_dentry->d_inode->i_size = *poffset;
}
mark_inode_dirty_sync(file->f_dentry->d_inode);
return total_written;
}
static int
cifs_writepage(struct page *page)
{
struct address_space *mapping = page->mapping;
int rc = -EFAULT;
int bytes_written = 0;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
int xid;
struct inode *inode = page->mapping->host;
loff_t *poffset = NULL;
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
/* figure out which file struct to use
if (file->private_data == NULL) {
FreeXid(xid);
return -EBADF;
}
*/
if (!mapping) {
FreeXid(xid);
return -EFAULT;
}
/* BB fix and add missing call to cifs_writepage_sync here */
inode->i_ctime = inode->i_mtime = CURRENT_TIME; /* BB is this right? */
if ((bytes_written > 0) && (poffset)) {
if (*poffset > inode->i_size)
inode->i_size = *poffset;
}
mark_inode_dirty_sync(inode);
FreeXid(xid);
return rc;
}
static int
cifs_prepare_write(struct file *file, struct page *page, unsigned offset,
unsigned to)
{
return 0; /* eventually add code to flush any incompatible requests */
}
static int
cifs_commit_write(struct file *file, struct page *page, unsigned offset,
unsigned to)
{
long rc = -EFAULT;
lock_kernel();
/* status = cifs_updatepage(file, page, offset, to-offset); */
/* BB add - do we really need to lock the kernel here for so long ? */
unlock_kernel();
return rc;
}
int
cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
{
int xid;
int rc = 0;
xid = GetXid();
/* BB fill in code to flush write behind buffers - when we start supporting oplock */
cFYI(1, (" name: %s datasync: 0x%x ", dentry->d_name.name, datasync));
FreeXid(xid);
return rc;
}
static int
cifs_sync_page(struct page *page)
{
struct address_space *mapping;
struct inode *inode;
unsigned long index = page->index;
unsigned int rpages = 0;
int rc = 0;
mapping = page->mapping;
if (!mapping)
return 0;
inode = mapping->host;
if (!inode)
return 0;
/* fill in rpages then
result = cifs_pagein_inode(inode, index, rpages); *//* BB finish */
cFYI(1, ("\nrpages is %d for sync page of Index %ld ", rpages, index));
if (rc < 0)
return rc;
return 0;
}
ssize_t
cifs_read(struct file * file, char *read_data, size_t read_size,
loff_t * poffset)
{
int rc = -EACCES;
int bytes_read = 0;
int total_read;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
int xid;
xid = GetXid();
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
if (file->private_data == NULL) {
FreeXid(xid);
return -EBADF;
}
for (total_read = 0; read_size > total_read; total_read += bytes_read) {
rc = CIFSSMBRead(xid, pTcon,
((struct cifsFileInfo *) file->
private_data)->netfid,
read_size - total_read, *poffset,
&bytes_read, read_data + total_read);
if (rc || (bytes_read == 0)) {
if (total_read) {
break;
} else {
FreeXid(xid);
return rc;
}
} else
*poffset += bytes_read;
}
FreeXid(xid);
return total_read;
}
static int
cifs_readpage_sync(struct file *file, struct page *page)
{
unsigned int count = PAGE_CACHE_SIZE;
int rc = -EACCES;
int bytes_read = 0;
int total_read = 0;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
int xid;
xid = GetXid();
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
if (file->private_data == NULL) {
FreeXid(xid);
return -EBADF;
}
/* BB finish adding missing here */
cFYI(1,
("\nCount is %d total read %d bytes read %d ", count, total_read,
bytes_read));
FreeXid(xid);
return rc;
}
static int
cifs_readpage(struct file *file, struct page *page)
{
int rc;
page_cache_get(page);
rc = cifs_readpage_sync(file, page);
/* for reads over a certain size we could initiate async read ahead */
page_cache_release(page);
return rc;
}
void
fill_in_inode(struct inode *tmp_inode,
FILE_DIRECTORY_INFO * pfindData, int *pobject_type)
{
struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
pfindData->ExtFileAttributes =
le32_to_cpu(pfindData->ExtFileAttributes);
pfindData->AllocationSize = le64_to_cpu(pfindData->AllocationSize);
pfindData->EndOfFile = le64_to_cpu(pfindData->EndOfFile);
cifsInfo->cifsAttrs = pfindData->ExtFileAttributes;
cifsInfo->time = jiffies;
atomic_inc(&cifsInfo->inUse); /* inc on every refresh of inode info */
/* Linux can not store file creation time unfortunately so we ignore it */
tmp_inode->i_atime =
le64_to_cpu(cifs_NTtimeToUnix(pfindData->LastAccessTime));
tmp_inode->i_mtime =
le64_to_cpu(cifs_NTtimeToUnix(pfindData->LastWriteTime));
tmp_inode->i_ctime =
le64_to_cpu(cifs_NTtimeToUnix(pfindData->ChangeTime));
/* should we treat the dos attribute of read-only as read-only mode bit e.g. 555 */
tmp_inode->i_mode = S_IALLUGO & ~(S_ISUID | S_IXGRP); /* 2767 perms - indicate mandatory locking */
cFYI(0,
("\nCIFS FFIRST: Attributes came in as 0x%x",
pfindData->ExtFileAttributes));
if (pfindData->ExtFileAttributes & ATTR_REPARSE) {
*pobject_type = DT_LNK;
tmp_inode->i_mode |= S_IFLNK; /* BB can this and S_IFREG or S_IFDIR be set at same time as in Windows? */
} else if (pfindData->ExtFileAttributes & ATTR_DIRECTORY) {
*pobject_type = DT_DIR;
tmp_inode->i_mode = S_IRWXUGO; /* override default perms since we do not lock dirs */
tmp_inode->i_mode |= S_IFDIR;
} else {
*pobject_type = DT_REG;
tmp_inode->i_mode |= S_IFREG;
}/* could add code here - to validate if device or weird share type? */
/* can not fill in nlink here as in qpathinfo version and in Unx search */
tmp_inode->i_size = pfindData->EndOfFile;
tmp_inode->i_blocks =
do_div(pfindData->AllocationSize, tmp_inode->i_blksize);
cFYI(1,
("\nFinddata alloc size (from smb) %lld",
pfindData->AllocationSize));
if (pfindData->AllocationSize < pfindData->EndOfFile)
cFYI(1, ("\nServer inconsistency Error: it says allocation size less than end of file "));
cFYI(1,
("\nCIFS FFIRST: Size %ld and blocks %ld and blocksize %ld",
(unsigned long) tmp_inode->i_size, tmp_inode->i_blocks,
tmp_inode->i_blksize));
if (S_ISREG(tmp_inode->i_mode)) {
cFYI(1, (" File inode "));
tmp_inode->i_op = &cifs_file_inode_ops;
tmp_inode->i_fop = &cifs_file_ops;
} else if (S_ISDIR(tmp_inode->i_mode)) {
cFYI(1, (" Directory inode"));
tmp_inode->i_op = &cifs_dir_inode_ops;
tmp_inode->i_fop = &cifs_dir_ops;
} else if (S_ISLNK(tmp_inode->i_mode)) {
cFYI(1, (" Symbolic Link inode "));
tmp_inode->i_op = &cifs_symlink_inode_ops;
} else {
cFYI(1, ("\nInit special inode "));
init_special_inode(tmp_inode, tmp_inode->i_mode,
kdev_t_to_nr(tmp_inode->i_rdev));
}
}
void
unix_fill_in_inode(struct inode *tmp_inode,
FILE_UNIX_INFO * pfindData, int *pobject_type)
{
struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
cifsInfo->time = jiffies;
atomic_inc(&cifsInfo->inUse);
tmp_inode->i_atime =
le64_to_cpu(cifs_NTtimeToUnix(pfindData->LastAccessTime));
tmp_inode->i_mtime =
le64_to_cpu(cifs_NTtimeToUnix(pfindData->LastModificationTime));
tmp_inode->i_ctime =
le64_to_cpu(cifs_NTtimeToUnix(pfindData->LastStatusChange));
/* tmp_inode->i_mtime =
cifs_NTtimeToUnix(pfindData->LastModificationTime);
tmp_inode->i_ctime =
cifs_NTtimeToUnix(pfindData->LastStatusChange); */
tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
pfindData->Type = le32_to_cpu(pfindData->Type);
if (pfindData->Type == UNIX_FILE) {
*pobject_type = DT_REG;
tmp_inode->i_mode |= S_IFREG;
} else if (pfindData->Type == UNIX_SYMLINK) {
*pobject_type = DT_LNK;
tmp_inode->i_mode |= S_IFLNK;
} else if (pfindData->Type == UNIX_DIR) {
*pobject_type = DT_DIR;
tmp_inode->i_mode |= S_IFDIR;
} else if (pfindData->Type == UNIX_CHARDEV) {
*pobject_type = DT_CHR;
tmp_inode->i_mode |= S_IFCHR;
} else if (pfindData->Type == UNIX_BLOCKDEV) {
*pobject_type = DT_BLK;
tmp_inode->i_mode |= S_IFBLK;
} else if (pfindData->Type == UNIX_FIFO) {
*pobject_type = DT_FIFO;
tmp_inode->i_mode |= S_IFIFO;
} else if (pfindData->Type == UNIX_SOCKET) {
*pobject_type = DT_SOCK;
tmp_inode->i_mode |= S_IFSOCK;
}
tmp_inode->i_uid = le64_to_cpu(pfindData->Uid);
tmp_inode->i_gid = le64_to_cpu(pfindData->Gid);
tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks);
pfindData->NumOfBytes = le64_to_cpu(pfindData->NumOfBytes);
pfindData->EndOfFile = le64_to_cpu(pfindData->EndOfFile);
tmp_inode->i_size = pfindData->EndOfFile;
tmp_inode->i_blocks =
do_div(pfindData->NumOfBytes, tmp_inode->i_blksize);
cFYI(0, ("\nFinddata alloc size (from smb) %lld", pfindData->NumOfBytes)); /* BB remove */
if (pfindData->NumOfBytes < pfindData->EndOfFile)
cFYI(0, ("\nServer inconsistency Error: it says allocation size less than end of file ")); /* BB remove */
cFYI(1, ("\nCIFS FFIRST: Size %ld and blocks %ld ", (unsigned long) tmp_inode->i_size, tmp_inode->i_blocks)); /* BB remove */
if (S_ISREG(tmp_inode->i_mode)) {
cFYI(1, (" File inode "));
tmp_inode->i_op = &cifs_file_inode_ops;
tmp_inode->i_fop = &cifs_file_ops;
} else if (S_ISDIR(tmp_inode->i_mode)) {
cFYI(1, (" Directory inode"));
tmp_inode->i_op = &cifs_dir_inode_ops;
tmp_inode->i_fop = &cifs_dir_ops;
} else if (S_ISLNK(tmp_inode->i_mode)) {
cFYI(1, (" Symbolic Link inode "));
tmp_inode->i_op = &cifs_symlink_inode_ops;
/* tmp_inode->i_fop = *//* do not need to set to anything */
} else {
cFYI(1, ("\nInit special inode "));
init_special_inode(tmp_inode, tmp_inode->i_mode,
kdev_t_to_nr(tmp_inode->i_rdev));
}
}
void
construct_dentry(struct qstr *qstring, struct file *file,
struct inode **ptmp_inode, struct dentry **pnew_dentry)
{
struct dentry *tmp_dentry;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
cFYI(1, ("\nFor %s ", qstring->name));
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
qstring->hash = full_name_hash(qstring->name, qstring->len);
tmp_dentry = d_lookup(file->f_dentry, qstring);
if (tmp_dentry) {
cFYI(1, (" existing dentry with inode 0x%p ", tmp_dentry->d_inode)); /* BB remove */
*ptmp_inode = tmp_dentry->d_inode;
/* BB overwrite the old name? i.e. tmp_dentry->d_name and tmp_dentry->d_name.len ?? */
} else {
tmp_dentry = d_alloc(file->f_dentry, qstring);
*ptmp_inode = new_inode(file->f_dentry->d_sb);
cFYI(1, ("\nAlloc new inode %p ", *ptmp_inode));
tmp_dentry->d_op = &cifs_dentry_ops;
cFYI(1, (" instantiate dentry 0x%p with inode 0x%p ",
tmp_dentry, *ptmp_inode));
d_instantiate(tmp_dentry, *ptmp_inode);
d_rehash(tmp_dentry);
}
tmp_dentry->d_time = jiffies;
(*ptmp_inode)->i_blksize =
(pTcon->ses->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;
cFYI(1, ("\ni_blksize = %ld", (*ptmp_inode)->i_blksize));
*pnew_dentry = tmp_dentry;
}
void
cifs_filldir(struct qstr *pqstring, FILE_DIRECTORY_INFO * pfindData,
struct file *file, filldir_t filldir, void *direntry)
{
struct inode *tmp_inode;
struct dentry *tmp_dentry;
int object_type;
pqstring->name = pfindData->FileName;
pqstring->len = pfindData->FileNameLength;
construct_dentry(pqstring, file, &tmp_inode, &tmp_dentry);
fill_in_inode(tmp_inode, pfindData, &object_type);
filldir(direntry, pfindData->FileName, pqstring->len, file->f_pos,
tmp_inode->i_ino, object_type);
dput(tmp_dentry);
}
void
cifs_filldir_unix(struct qstr *pqstring,
FILE_UNIX_INFO * pUnixFindData, struct file *file,
filldir_t filldir, void *direntry)
{
struct inode *tmp_inode;
struct dentry *tmp_dentry;
int object_type;
pqstring->name = pUnixFindData->FileName;
pqstring->len = strnlen(pUnixFindData->FileName, MAX_PATHCONF);
construct_dentry(pqstring, file, &tmp_inode, &tmp_dentry);
unix_fill_in_inode(tmp_inode, pUnixFindData, &object_type);
filldir(direntry, pUnixFindData->FileName, pqstring->len,
file->f_pos, tmp_inode->i_ino, object_type);
dput(tmp_dentry);
}
int
cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
{
int rc = 0;
int xid, i;
int Unicode = FALSE;
int UnixSearch = FALSE;
__u16 searchHandle;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
struct cifsFileInfo *cifsFile = NULL;
char *full_path = NULL;
char *data;
struct qstr qstring;
T2_FFIRST_RSP_PARMS findParms;
T2_FNEXT_RSP_PARMS findNextParms;
FILE_DIRECTORY_INFO *pfindData;
FILE_UNIX_INFO *pfindDataUnix;
xid = GetXid();
data = kmalloc(4096, GFP_KERNEL);
pfindData = (FILE_DIRECTORY_INFO *) data;
cifs_sb = CIFS_SB(file->f_dentry->d_sb);
pTcon = cifs_sb->tcon;
full_path = build_wildcard_path_from_dentry(file->f_dentry);
cFYI(1, ("\nFull path: %s start at: %lld ", full_path, file->f_pos));
switch ((int) file->f_pos) {
case 0:
if (filldir
(direntry, ".", 1, file->f_pos,
file->f_dentry->d_inode->i_ino, DT_DIR) < 0) {
cERROR(1, ("\nFilldir for current dir failed "));
break;
}
file->f_pos++;
/* fallthrough */
case 1:
if (filldir
(direntry, "..", 2, file->f_pos,
file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
cERROR(1, ("\nFilldir for parent dir failed "));
break;
}
file->f_pos++;
/* fallthrough */
case 2:
/* Should we first check if file->private_data is null? */
rc = CIFSFindFirst(xid, pTcon, full_path, pfindData,
&findParms, cifs_sb->local_nls,
&Unicode, &UnixSearch);
cFYI(1,
("Count: %d End: %d ", findParms.SearchCount,
findParms.EndofSearch));
if (rc == 0) {
searchHandle = findParms.SearchHandle;
file->private_data =
kmalloc(sizeof (struct cifsFileInfo), GFP_KERNEL);
if (file->private_data) {
memset(file->private_data, 0,
sizeof (struct cifsFileInfo));
cifsFile =
(struct cifsFileInfo *) file->private_data;
cifsFile->netfid = searchHandle;
}
renew_parental_timestamps(file->f_dentry);
for (i = 2; i < findParms.SearchCount + 2; i++) {
if (UnixSearch == FALSE) {
pfindData->FileNameLength =
le32_to_cpu(pfindData->
FileNameLength);
if (Unicode == TRUE)
pfindData->FileNameLength =
cifs_strfromUCS_le
(pfindData->FileName,
(wchar_t *)
pfindData->FileName,
(pfindData->
FileNameLength) / 2,
cifs_sb->local_nls);
qstring.len = pfindData->FileNameLength;
if (((qstring.len != 1)
|| (pfindData->FileName[0] != '.'))
&& ((qstring.len != 2)
|| (pfindData->
FileName[0] != '.')
|| (pfindData->
FileName[1] != '.'))) {
cifs_filldir(&qstring,
pfindData,
file, filldir,
direntry);
file->f_pos++;
}
} else { /* UnixSearch */
pfindDataUnix =
(FILE_UNIX_INFO *) pfindData;
if (Unicode == TRUE)
qstring.len =
cifs_strfromUCS_le
(pfindDataUnix->
FileName, (wchar_t *)
pfindDataUnix->
FileName,
MAX_PATHCONF,
cifs_sb->local_nls);
else
qstring.len =
strnlen(pfindDataUnix->
FileName,
MAX_PATHCONF);
if (((qstring.len != 1)
|| (pfindDataUnix->
FileName[0] != '.'))
&& ((qstring.len != 2)
|| (pfindDataUnix->
FileName[0] != '.')
|| (pfindDataUnix->
FileName[1] != '.'))) {
cifs_filldir_unix(&qstring,
pfindDataUnix,
file,
filldir,
direntry);
file->f_pos++;
}
}
pfindData = (FILE_DIRECTORY_INFO *) ((char *) pfindData + le32_to_cpu(pfindData->NextEntryOffset)); /* works also for Unix find struct since this is the first field of both */
/* BB also should check to make sure that pointer is not beyond the end of the SMB */
} /* end for loop */
if ((findParms.EndofSearch != 0) && cifsFile) {
cifsFile->endOfSearch = TRUE;
}
} else {
if (cifsFile)
cifsFile->endOfSearch = TRUE;
rc = 0; /* unless parent directory disappeared - do not return error here (eg Access Denied or no more files) */
}
break;
default:
if (file->private_data == NULL) {
rc = -EBADF;
cFYI(1,
("\nReaddir on closed srch, pos = %lld",
file->f_pos));
} else {
cifsFile = (struct cifsFileInfo *) file->private_data;
if (cifsFile->endOfSearch) {
rc = 0;
cFYI(1, ("\nEnd of search "));
break;
}
searchHandle = cifsFile->netfid;
rc = CIFSFindNext(xid, pTcon, pfindData,
&findNextParms, searchHandle, 0,
&Unicode, &UnixSearch);
cFYI(1,
("Count: %d End: %d ",
findNextParms.SearchCount,
findNextParms.EndofSearch));
if ((rc == 0) && (findNextParms.SearchCount != 0)) {
for (i = 0; i < findNextParms.SearchCount; i++) {
pfindData->FileNameLength =
le32_to_cpu(pfindData->
FileNameLength);
if (UnixSearch == FALSE) {
if (Unicode == TRUE)
pfindData->
FileNameLength
=
cifs_strfromUCS_le
(pfindData->
FileName,
(wchar_t *)
pfindData->
FileName,
(pfindData->
FileNameLength)
/ 2,
cifs_sb->
local_nls);
qstring.len =
pfindData->FileNameLength;
if (((qstring.len != 1)
|| (pfindData->
FileName[0] != '.'))
&& ((qstring.len != 2)
|| (pfindData->
FileName[0] != '.')
|| (pfindData->
FileName[1] !=
'.'))) {
cifs_filldir
(&qstring,
pfindData,
file, filldir,
direntry);
file->f_pos++;
}
} else { /* UnixSearch */
pfindDataUnix =
(FILE_UNIX_INFO *)
pfindData;
if (Unicode == TRUE)
qstring.len =
cifs_strfromUCS_le
(pfindDataUnix->
FileName,
(wchar_t *)
pfindDataUnix->
FileName,
MAX_PATHCONF,
cifs_sb->
local_nls);
else
qstring.len =
strnlen
(pfindDataUnix->
FileName,
MAX_PATHCONF);
if (((qstring.len != 1)
|| (pfindDataUnix->
FileName[0] != '.'))
&& ((qstring.len != 2)
|| (pfindDataUnix->
FileName[0] != '.')
|| (pfindDataUnix->
FileName[1] !=
'.'))) {
cifs_filldir_unix
(&qstring,
pfindDataUnix,
file, filldir,
direntry);
file->f_pos++;
}
}
pfindData = (FILE_DIRECTORY_INFO *) ((char *) pfindData + le32_to_cpu(pfindData->NextEntryOffset)); /* works also for Unix find struct since this is the first field of both */
/* BB also should check to make sure that pointer is not beyond the end of the SMB */
} /* end for loop */
if (findNextParms.EndofSearch != 0) {
cifsFile->endOfSearch = TRUE;
}
} else {
cifsFile->endOfSearch = TRUE;
rc = 0; /* unless parent directory disappeared - do not return error here (eg Access Denied or no more files) */
}
}
} /* end switch */
if (data)
kfree(data);
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
struct address_space_operations cifs_addr_ops = {
.readpage = cifs_readpage,
.sync_page = cifs_sync_page,
.writepage = cifs_writepage,
.prepare_write = cifs_prepare_write,
.commit_write = cifs_commit_write
};
/*
* fs/cifs/inode.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/stat.h>
#include <asm/div64.h>
#include "cifsfs.h"
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
int
cifs_get_inode_info_unix(struct inode **pinode,
const unsigned char *search_path,
struct super_block *sb)
{
int xid;
int rc = 0;
FILE_UNIX_BASIC_INFO findData;
struct cifsTconInfo *pTcon;
struct inode *inode;
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
char *tmp_path;
xid = GetXid();
pTcon = cifs_sb->tcon;
cFYI(1, ("\nGetting info on %s ", search_path));
/* we could have done a find first instead but this returns more info */
rc = CIFSSMBUnixQPathInfo(xid, pTcon, search_path, &findData,
cifs_sb->local_nls);
/* dump_mem("\nUnixQPathInfo return data", &findData, sizeof(findData)); */
if (rc) {
if (rc == -EREMOTE) {
/* rc = *//* CIFSGetDFSRefer(xid, pTcon->ses, search_path,
&referrals,
&num_referrals,
cifs_sb->local_nls); */
tmp_path =
kmalloc(strnlen
(pTcon->treeName,
MAX_TREE_SIZE + 1) +
strnlen(search_path, MAX_PATHCONF) + 1,
GFP_KERNEL);
if (tmp_path == NULL) {
FreeXid(xid);
return -ENOMEM;
}
/* have to skip first of the double backslash of UNC name */
strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
strncat(tmp_path, search_path, MAX_PATHCONF);
rc = connect_to_dfs_path(xid, pTcon->ses,
/* treename + */ tmp_path,
cifs_sb->local_nls);
kfree(tmp_path);
/* BB fix up inode etc. */
} else if (rc) {
FreeXid(xid);
return rc;
}
} else {
struct cifsInodeInfo *cifsInfo;
/* get new inode */
if (*pinode == NULL) {
*pinode = new_inode(sb);
cFYI(1, ("\nAlloc new inode %p ", *pinode));
}
inode = *pinode;
/* new_inode = iget(parent_dir_inode->i_sb, findData.IndexNumber); */
/* index number not reliable in response data */
cifsInfo = CIFS_I(inode);
cFYI(1, ("\nOld time %ld ", cifsInfo->time));
cifsInfo->time = jiffies;
cFYI(1, (" New time %ld ", cifsInfo->time));
atomic_inc(&cifsInfo->inUse); /* inc on every refresh of inode */
inode->i_atime =
le64_to_cpu(cifs_NTtimeToUnix(findData.LastAccessTime));
inode->i_mtime =
le64_to_cpu(cifs_NTtimeToUnix
(findData.LastModificationTime));
inode->i_ctime =
le64_to_cpu(cifs_NTtimeToUnix(findData.LastStatusChange));
inode->i_mode = le64_to_cpu(findData.Permissions);
findData.Type = le32_to_cpu(findData.Type);
if (findData.Type == UNIX_FILE) {
inode->i_mode |= S_IFREG;
} else if (findData.Type == UNIX_SYMLINK) {
inode->i_mode |= S_IFLNK;
} else if (findData.Type == UNIX_DIR) {
inode->i_mode |= S_IFDIR;
} else if (findData.Type == UNIX_CHARDEV) {
inode->i_mode |= S_IFCHR;
} else if (findData.Type == UNIX_BLOCKDEV) {
inode->i_mode |= S_IFBLK;
} else if (findData.Type == UNIX_FIFO) {
inode->i_mode |= S_IFIFO;
} else if (findData.Type == UNIX_SOCKET) {
inode->i_mode |= S_IFSOCK;
}
inode->i_uid = le64_to_cpu(findData.Uid);
inode->i_gid = le64_to_cpu(findData.Gid);
inode->i_nlink = le64_to_cpu(findData.Nlinks);
findData.NumOfBytes = le64_to_cpu(findData.NumOfBytes);
findData.EndOfFile = le64_to_cpu(findData.EndOfFile);
inode->i_size = findData.EndOfFile;
inode->i_blksize =
(pTcon->ses->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;
inode->i_blocks = do_div(findData.NumOfBytes, inode->i_blksize);
cFYI(1,
("\nFinddata alloc size (from smb) %lld",
findData.NumOfBytes));
if (findData.NumOfBytes < findData.EndOfFile)
cFYI(1, ("\nServer inconsistency Error: it says allocation size less than end of file "));
cFYI(1,
("\nCIFS FFIRST: Size %ld and blocks %ld ",
(unsigned long) inode->i_size, inode->i_blocks));
if (S_ISREG(inode->i_mode)) {
cFYI(1, (" File inode "));
inode->i_op = &cifs_file_inode_ops;
inode->i_fop = &cifs_file_ops;
} else if (S_ISDIR(inode->i_mode)) {
cFYI(1, (" Directory inode"));
inode->i_op = &cifs_dir_inode_ops;
inode->i_fop = &cifs_dir_ops;
} else if (S_ISLNK(inode->i_mode)) {
cFYI(1, (" Symbolic Link inode "));
inode->i_op = &cifs_symlink_inode_ops;
/* tmp_inode->i_fop = *//* do not need to set to anything */
} else {
cFYI(1, ("\nInit special inode "));
init_special_inode(inode, inode->i_mode,
kdev_t_to_nr(inode->i_rdev));
}
}
FreeXid(xid);
return rc;
}
int
cifs_get_inode_info(struct inode **pinode,
const unsigned char *search_path, struct super_block *sb)
{
int xid;
int rc = 0;
FILE_ALL_INFO findData;
struct cifsTconInfo *pTcon;
struct inode *inode;
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
char *tmp_path;
xid = GetXid();
pTcon = cifs_sb->tcon;
cFYI(1, ("\nGetting info on %s ", search_path));
/* we could have done a find first instead but this returns more info */
rc = CIFSSMBQPathInfo(xid, pTcon, search_path, &findData,
cifs_sb->local_nls);
/* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
if (rc) {
if (rc == -EREMOTE) {
/* BB add call to new func rc = GetDFSReferral(); */
/* rc = *//* CIFSGetDFSRefer(xid, pTcon->ses, search_path,
&referrals,
&num_referrals,
cifs_sb->local_nls); */
tmp_path =
kmalloc(strnlen
(pTcon->treeName,
MAX_TREE_SIZE + 1) +
strnlen(search_path, MAX_PATHCONF) + 1,
GFP_KERNEL);
if (tmp_path == NULL) {
FreeXid(xid);
return -ENOMEM;
}
strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
strncat(tmp_path, search_path, MAX_PATHCONF);
rc = connect_to_dfs_path(xid, pTcon->ses,
/* treename + */ tmp_path,
cifs_sb->local_nls);
kfree(tmp_path);
/* BB fix up inode etc. */
} else if (rc) {
FreeXid(xid);
return rc;
}
} else {
struct cifsInodeInfo *cifsInfo;
/* get new inode */
if (*pinode == NULL) {
*pinode = new_inode(sb);
cFYI(1, ("\nAlloc new inode %p ", *pinode));
}
inode = *pinode;
cifsInfo = CIFS_I(inode);
findData.Attributes = le32_to_cpu(findData.Attributes);
cifsInfo->cifsAttrs = findData.Attributes;
cFYI(1, ("\nOld time %ld ", cifsInfo->time));
cifsInfo->time = jiffies;
cFYI(1, (" New time %ld ", cifsInfo->time));
atomic_inc(&cifsInfo->inUse); /* inc on every refresh of inode */
inode->i_blksize =
(pTcon->ses->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;
/* Linux can not store file creation time unfortunately so we ignore it */
inode->i_atime =
cifs_NTtimeToUnix(le64_to_cpu(findData.LastAccessTime));
inode->i_mtime =
cifs_NTtimeToUnix(le64_to_cpu(findData.LastWriteTime));
inode->i_ctime =
cifs_NTtimeToUnix(le64_to_cpu(findData.ChangeTime));
/* inode->i_mode = S_IRWXUGO; *//* 777 perms */
/* should we treat the dos attribute of read-only as read-only mode bit e.g. 555 */
inode->i_mode = S_IALLUGO & ~(S_ISUID | S_IXGRP); /* 2767 perms indicate mandatory locking - will override for dirs later */
cFYI(0,
("\nAttributes came in as 0x%x\n", findData.Attributes));
if (findData.Attributes & ATTR_REPARSE) {
/* Can IFLNK be set as it basically is on windows with IFREG or IFDIR? */
inode->i_mode |= S_IFLNK;
} else if (findData.Attributes & ATTR_DIRECTORY) {
/* override default perms since we do not do byte range locking on dirs */
inode->i_mode = S_IRWXUGO;
inode->i_mode |= S_IFDIR;
} else {
inode->i_mode |= S_IFREG;
/* BB add code here - validate if device or weird share or device type? */
}
inode->i_size = le64_to_cpu(findData.EndOfFile);
findData.AllocationSize = le64_to_cpu(findData.AllocationSize);
inode->i_blocks =
do_div(findData.AllocationSize, inode->i_blksize);
cFYI(1,
("\n Size %ld and blocks %ld ",
(unsigned long) inode->i_size, inode->i_blocks));
inode->i_nlink = le32_to_cpu(findData.NumberOfLinks);
/* BB fill in uid and gid here? with help from winbind? */
if (S_ISREG(inode->i_mode)) {
cFYI(1, (" File inode "));
inode->i_op = &cifs_file_inode_ops;
inode->i_fop = &cifs_file_ops;
} else if (S_ISDIR(inode->i_mode)) {
cFYI(1, (" Directory inode "));
inode->i_op = &cifs_dir_inode_ops;
inode->i_fop = &cifs_dir_ops;
} else if (S_ISLNK(inode->i_mode)) {
cFYI(1, (" Symbolic Link inode "));
inode->i_op = &cifs_symlink_inode_ops;
} else {
init_special_inode(inode, inode->i_mode,
kdev_t_to_nr(inode->i_rdev));
}
}
FreeXid(xid);
return rc;
}
void
cifs_read_inode(struct inode *inode)
{ /* gets root inode */
struct cifs_sb_info *cifs_sb;
cifs_sb = CIFS_SB(inode->i_sb);
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
cifs_get_inode_info_unix(&inode, "", inode->i_sb);
else
cifs_get_inode_info(&inode, "", inode->i_sb);
}
int
cifs_unlink(struct inode *inode, struct dentry *direntry)
{
int rc = 0;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
struct cifsInodeInfo *cifsInode;
cFYI(1, ("\n cifs_unlink, inode = 0x%p with ", inode));
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
/* BB Should we close the file if it is already open from our client? */
full_path = build_path_from_dentry(direntry);
rc = CIFSSMBDelFile(xid, pTcon, full_path, cifs_sb->local_nls);
if (!rc) {
direntry->d_inode->i_nlink--;
}
cifsInode = CIFS_I(direntry->d_inode);
cifsInode->time = 0; /* will force revalidate to get info when needed */
direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
CURRENT_TIME;
cifsInode = CIFS_I(inode);
cifsInode->time = 0; /* force revalidate of dir as well */
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
int
cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
{
int rc = 0;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
struct inode *newinode = NULL;
cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p\n", mode, inode));
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
/* BB add setting the equivalent of mode via CreateX w/ACLs */
rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls);
if (rc) {
cFYI(1, ("\ncifs_mkdir returned 0x%x ", rc));
} else {
inode->i_nlink++;
if (pTcon->ses->capabilities & CAP_UNIX)
rc = cifs_get_inode_info_unix(&newinode, full_path,
inode->i_sb);
else
rc = cifs_get_inode_info(&newinode, full_path,
inode->i_sb);
direntry->d_op = &cifs_dentry_ops;
d_instantiate(direntry, newinode);
direntry->d_inode->i_nlink = 2;
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode,
0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF,
cifs_sb->local_nls);
else { /* BB to be implemented via Windows secrty descriptors*/
/* eg CIFSSMBWinSetPerms(xid,pTcon,full_path,mode,-1,-1,local_nls);*/
}
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
int
cifs_rmdir(struct inode *inode, struct dentry *direntry)
{
int rc = 0;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
struct cifsInodeInfo *cifsInode;
cFYI(1, ("\nn cifs_rmdir, inode = 0x%p with ", inode));
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls);
if (!rc) {
inode->i_nlink--;
direntry->d_inode->i_size = 0;
direntry->d_inode->i_nlink = 0;
}
cifsInode = CIFS_I(direntry->d_inode);
cifsInode->time = 0; /* force revalidate to go get info when needed */
direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
CURRENT_TIME;
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
int
cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
struct inode *target_inode, struct dentry *target_direntry)
{
char *fromName;
char *toName;
struct cifs_sb_info *cifs_sb_source;
struct cifs_sb_info *cifs_sb_target;
struct cifsTconInfo *pTcon;
int xid;
int rc = 0;
xid = GetXid();
cifs_sb_target = CIFS_SB(target_inode->i_sb);
cifs_sb_source = CIFS_SB(source_inode->i_sb);
pTcon = cifs_sb_source->tcon;
if (pTcon != cifs_sb_target->tcon)
return -EXDEV; /* BB actually could be allowed if same server, but
different share. Might eventually add support for this */
fromName = build_path_from_dentry(source_direntry);
toName = build_path_from_dentry(target_direntry);
rc = CIFSSMBRename(xid, pTcon, fromName, toName,
cifs_sb_source->local_nls);
if (fromName)
kfree(fromName);
if (toName)
kfree(toName);
return rc;
}
int
cifs_revalidate(struct dentry *direntry)
{
int xid;
int rc = 0;
char *full_path;
struct cifs_sb_info *cifs_sb;
struct cifsInodeInfo *cifsInode;
xid = GetXid();
cifs_sb = CIFS_SB(direntry->d_sb);
full_path = build_path_from_dentry(direntry);
cFYI(1,
(" full path: %s for inode 0x%p with count %d dentry: 0x%p d_time %ld at time %ld \n",
full_path, direntry->d_inode,
direntry->d_inode->i_count.counter, direntry,
direntry->d_time, jiffies));
cifsInode = CIFS_I(direntry->d_inode);
if ((time_before(jiffies, cifsInode->time + HZ))
&& (direntry->d_inode->i_nlink == 1)) {
cFYI(1, (" Do not need to revalidate "));
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
cifs_get_inode_info_unix(&direntry->d_inode, full_path,
direntry->d_sb);
else
cifs_get_inode_info(&direntry->d_inode, full_path,
direntry->d_sb);
/* BB if not oplocked, invalidate inode pages if mtime has changed */
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
void
cifs_truncate_file(struct inode *inode)
{ /* BB remove - may not need this function after all BB */
int xid;
int rc = 0;
struct cifsFileInfo *open_file = NULL;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
struct cifsInodeInfo *cifsInode;
struct dentry *dirent;
char *full_path = NULL;
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
if (list_empty(&inode->i_dentry)) {
cERROR(1,
("Can not get pathname from empty dentry in inode 0x%p ",
inode));
FreeXid(xid);
return;
}
dirent = list_entry(inode->i_dentry.next, struct dentry, d_alias);
if (dirent) {
full_path = build_path_from_dentry(dirent);
rc = CIFSSMBSetEOF(xid, pTcon, full_path, inode->i_size,FALSE,
cifs_sb->local_nls);
cFYI(1,("\nSetEOF (truncate) rc = %d",rc));
if(rc == -ETXTBSY) {
cifsInode = CIFS_I(inode);
if(!list_empty(&(cifsInode->openFileList))) {
open_file = list_entry(cifsInode->openFileList.next,
struct cifsFileInfo, flist);
/* We could check if file is open for writing first and
also we could also override the smb pid with the pid
of the file opener when sending the CIFS request */
rc = CIFSSMBSetFileSize(xid, pTcon, inode->i_size,
open_file->netfid,open_file->pid,FALSE);
} else {
cFYI(1,("\nNo open files to get file handle from"));
}
}
if (!rc)
CIFSSMBSetEOF(xid,pTcon,full_path,inode->i_size,TRUE,cifs_sb->local_nls);
/* allocation size setting seems optional so ignore return code */
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return;
}
int
cifs_setattr(struct dentry *direntry, struct iattr *attrs)
{
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
int rc = -EACCES;
struct cifsFileInfo *open_file = NULL;
FILE_BASIC_INFO time_buf;
int set_time = FALSE;
__u64 mode = 0xFFFFFFFFFFFFFFFF;
__u64 uid = 0xFFFFFFFFFFFFFFFF;
__u64 gid = 0xFFFFFFFFFFFFFFFF;
struct cifsInodeInfo *cifsInode;
xid = GetXid();
cFYI(1,
("\nIn cifs_setattr, name = %s attrs->iavalid 0x%x\n",
direntry->d_name.name, attrs->ia_valid));
cifs_sb = CIFS_SB(direntry->d_inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
cifsInode = CIFS_I(direntry->d_inode);
/* BB check if we need to refresh inode from server now ? BB */
cFYI(1, ("\nChanging attributes 0x%x", attrs->ia_valid));
if (attrs->ia_valid & ATTR_SIZE) {
rc = CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size,FALSE,
cifs_sb->local_nls);
cFYI(1,("\nSetEOF (setattrs) rc = %d",rc));
if(rc == -ETXTBSY) {
if(!list_empty(&(cifsInode->openFileList))) {
open_file = list_entry(cifsInode->openFileList.next,
struct cifsFileInfo, flist);
/* We could check if file is open for writing first */
rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size,
open_file->netfid,open_file->pid,FALSE);
} else {
cFYI(1,("\nNo open files to get file handle from"));
}
}
/* Set Allocation Size of file - might not even need to call the
following but might as well and it does not hurt if it fails */
CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE, cifs_sb->local_nls);
if (rc == 0)
vmtruncate(direntry->d_inode, attrs->ia_size);
/* BB add special case to handle sharing violation (due to Samba bug)
by calling SetFileInfo to set the sizes */
}
if (attrs->ia_valid & ATTR_UID) {
cFYI(1, ("\nCIFS - UID changed to %d", attrs->ia_uid));
uid = attrs->ia_uid;
/* entry->uid = cpu_to_le16(attr->ia_uid); */
}
if (attrs->ia_valid & ATTR_GID) {
cFYI(1, ("\nCIFS - GID changed to %d", attrs->ia_gid));
gid = attrs->ia_gid;
/* entry->gid = cpu_to_le16(attr->ia_gid); */
}
if (attrs->ia_valid & ATTR_MODE) {
cFYI(1, ("\nCIFS - Mode changed to 0x%x", attrs->ia_mode));
mode = attrs->ia_mode;
/* entry->mode = cpu_to_le16(attr->ia_mode); */
}
if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX)
&& (attrs->ia_valid & (ATTR_MODE | ATTR_GID | ATTR_UID)))
CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, uid, gid,
cifs_sb->local_nls);
else { /* BB to be implemented - via Windows security descriptors */
/* CIFSSMBWinSetPerms(xid,pTcon,full_path,mode,uid,gid,cifs_sb->local_nls);*/
}
if (attrs->ia_valid & ATTR_ATIME) {
set_time = TRUE;
time_buf.LastAccessTime =
cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
} else
time_buf.LastAccessTime = 0;
if (attrs->ia_valid & ATTR_MTIME) {
set_time = TRUE;
time_buf.LastWriteTime =
cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
} else
time_buf.LastWriteTime = 0;
if (attrs->ia_valid & ATTR_CTIME) {
set_time = TRUE;
cFYI(1, ("\nCIFS - CTIME changed ")); /* BB probably do not need */
time_buf.ChangeTime =
cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
} else
time_buf.ChangeTime = 0;
if (set_time) {
/* BB handle errors better if one attribute not set
(such as size) but time setting works */
time_buf.CreationTime = 0; /* do not change */
time_buf.Attributes = 0; /* BB is this ignored by server?
or do I have to query and reset anyway BB */
rc = CIFSSMBSetTimes(xid, pTcon, full_path, &time_buf,
cifs_sb->local_nls);
}
cifsInode->time = 0; /* force revalidate to get attributes when needed */
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
void
cifs_delete_inode(struct inode *inode)
{
/* Note: called without the big kernel filelock - remember spinlocks! */
cFYI(1, ("In cifs_delete_inode, inode = 0x%p\n", inode));
/* may have to add back in when safe distributed caching of
directories via e.g. FindNotify added */
}
/*
* fs/cifs/link.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/stat.h>
#include "cifsfs.h"
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
int
cifs_hardlink(struct dentry *old_file, struct inode *inode,
struct dentry *direntry)
{
int rc = -EACCES;
int xid;
char *fromName = NULL;
char *toName = NULL;
struct cifs_sb_info *cifs_sb_target;
struct cifsTconInfo *pTcon;
struct cifsInodeInfo *cifsInode;
xid = GetXid();
cifs_sb_target = CIFS_SB(inode->i_sb);
pTcon = cifs_sb_target->tcon;
/* No need to check for cross device links since server will do that - BB note DFS case in future though (when we may have to check) */
fromName = build_path_from_dentry(old_file);
toName = build_path_from_dentry(direntry);
if (cifs_sb_target->tcon->ses->capabilities & CAP_UNIX)
rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName,
cifs_sb_target->local_nls);
else
rc = CIFSCreateHardLink(xid, pTcon, fromName, toName,
cifs_sb_target->local_nls);
/* if (!rc) */
{
/* renew_parental_timestamps(old_file);
inode->i_nlink++;
mark_inode_dirty(inode);
d_instantiate(direntry, inode); */
/* BB add call to either mark inode dirty or refresh its data and timestamp to current time */
}
d_drop(direntry); /* force new lookup from server */
cifsInode = CIFS_I(old_file->d_inode);
cifsInode->time = 0; /* will force revalidate to go get info when needed */
if (fromName)
kfree(fromName);
if (toName)
kfree(toName);
FreeXid(xid);
return rc;
}
int
cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
{
struct inode *inode = direntry->d_inode;
int rc = -EACCES;
int xid;
char *full_path = NULL;
char target_path[257];
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
xid = GetXid();
full_path = build_path_from_dentry(direntry);
cFYI(1, ("\nFull path: %s inode = 0x%p\n", full_path, inode));
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
/* can not call the following line due to EFAULT in vfs_readlink which is presumably expecting a user space buffer */
/* length = cifs_readlink(direntry,target_path, sizeof(target_path) - 1); */
/* BB add read reparse point symlink code and Unix extensions symlink code here BB */
if (pTcon->ses->capabilities & CAP_UNIX)
rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
target_path,
sizeof (target_path) - 1,
cifs_sb->local_nls);
else {
/* rc = CIFSSMBQueryReparseLinkInfo */
/* BB Add code to Query ReparsePoint info */
}
/* BB Anything else to do to handle recursive links? */
/* BB Should we be using page symlink ops here? */
if (rc == 0) {
target_path[256] = 0;
rc = vfs_follow_link(nd, target_path);
}
/* else EACCESS */
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
int
cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
{
int rc = -EOPNOTSUPP;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
struct inode *newinode = NULL;
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
cFYI(1, ("\nFull path: %s ", full_path));
cFYI(1, (" symname is %s\n", symname));
/* BB what if DFS and this volume is on different share? BB */
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
cifs_sb->local_nls);
/* else
rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,cifs_sb_target->local_nls); */
if (rc == 0) {
if (pTcon->ses->capabilities & CAP_UNIX)
rc = cifs_get_inode_info_unix(&newinode, full_path,
inode->i_sb);
else
rc = cifs_get_inode_info(&newinode, full_path,
inode->i_sb);
if (rc != 0) {
cFYI(1,
("\nCreate symlink worked but get_inode_info failed with rc = %d ",
rc));
} else {
direntry->d_op = &cifs_dentry_ops;
d_instantiate(direntry, newinode);
}
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
int
cifs_readlink(struct dentry *direntry, char *pBuffer, int buflen)
{
struct inode *inode = direntry->d_inode;
int rc = -EACCES;
int xid;
struct cifs_sb_info *cifs_sb;
struct cifsTconInfo *pTcon;
char *full_path = NULL;
char tmpbuffer[256];
xid = GetXid();
cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon;
full_path = build_path_from_dentry(direntry);
cFYI(1,
("\nFull path: %s inode = 0x%p pBuffer = 0x%p buflen = %d\n",
full_path, inode, pBuffer, buflen));
/* BB add read reparse point symlink code and Unix extensions symlink code here BB */
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
tmpbuffer,
sizeof (tmpbuffer) - 1,
cifs_sb->local_nls);
else {
/* rc = CIFSSMBQueryReparseLinkInfo */
/* BB Add code to Query ReparsePoint info */
}
/* BB Anything else to do to handle recursive links? */
/* BB Should we be using page ops here? */
/* BB null terminate returned string in pBuffer? BB */
if (buflen > sizeof (tmpbuffer))
buflen = sizeof (tmpbuffer);
if (rc == 0) {
rc = vfs_readlink(direntry, pBuffer, buflen, tmpbuffer);
cFYI(1,
("vfs_readlink called from cifs_readlink returned %d",
rc));
}
if (full_path)
kfree(full_path);
FreeXid(xid);
return rc;
}
/*
Unix SMB/Netbios implementation.
Version 1.9.
a implementation of MD4 designed for use in the SMB authentication protocol
Copyright (C) Andrew Tridgell 1997-1998.
Modified by Steve French (sfrench@us.ibm.com) 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/module.h>
#include <linux/fs.h>
/* NOTE: This code makes no attempt to be fast!
It assumes that a int is at least 32 bits long
*/
static __u32 A, B, C, D;
static __u32
F(__u32 X, __u32 Y, __u32 Z)
{
return (X & Y) | ((~X) & Z);
}
static __u32
G(__u32 X, __u32 Y, __u32 Z)
{
return (X & Y) | (X & Z) | (Y & Z);
}
static __u32
H(__u32 X, __u32 Y, __u32 Z)
{
return X ^ Y ^ Z;
}
static __u32
lshift(__u32 x, int s)
{
x &= 0xFFFFFFFF;
return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
}
#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + (__u32)0x5A827999,s)
#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (__u32)0x6ED9EBA1,s)
/* this applies md4 to 64 byte chunks */
static void
mdfour64(__u32 * M)
{
int j;
__u32 AA, BB, CC, DD;
__u32 X[16];
for (j = 0; j < 16; j++)
X[j] = M[j];
AA = A;
BB = B;
CC = C;
DD = D;
ROUND1(A, B, C, D, 0, 3);
ROUND1(D, A, B, C, 1, 7);
ROUND1(C, D, A, B, 2, 11);
ROUND1(B, C, D, A, 3, 19);
ROUND1(A, B, C, D, 4, 3);
ROUND1(D, A, B, C, 5, 7);
ROUND1(C, D, A, B, 6, 11);
ROUND1(B, C, D, A, 7, 19);
ROUND1(A, B, C, D, 8, 3);
ROUND1(D, A, B, C, 9, 7);
ROUND1(C, D, A, B, 10, 11);
ROUND1(B, C, D, A, 11, 19);
ROUND1(A, B, C, D, 12, 3);
ROUND1(D, A, B, C, 13, 7);
ROUND1(C, D, A, B, 14, 11);
ROUND1(B, C, D, A, 15, 19);
ROUND2(A, B, C, D, 0, 3);
ROUND2(D, A, B, C, 4, 5);
ROUND2(C, D, A, B, 8, 9);
ROUND2(B, C, D, A, 12, 13);
ROUND2(A, B, C, D, 1, 3);
ROUND2(D, A, B, C, 5, 5);
ROUND2(C, D, A, B, 9, 9);
ROUND2(B, C, D, A, 13, 13);
ROUND2(A, B, C, D, 2, 3);
ROUND2(D, A, B, C, 6, 5);
ROUND2(C, D, A, B, 10, 9);
ROUND2(B, C, D, A, 14, 13);
ROUND2(A, B, C, D, 3, 3);
ROUND2(D, A, B, C, 7, 5);
ROUND2(C, D, A, B, 11, 9);
ROUND2(B, C, D, A, 15, 13);
ROUND3(A, B, C, D, 0, 3);
ROUND3(D, A, B, C, 8, 9);
ROUND3(C, D, A, B, 4, 11);
ROUND3(B, C, D, A, 12, 15);
ROUND3(A, B, C, D, 2, 3);
ROUND3(D, A, B, C, 10, 9);
ROUND3(C, D, A, B, 6, 11);
ROUND3(B, C, D, A, 14, 15);
ROUND3(A, B, C, D, 1, 3);
ROUND3(D, A, B, C, 9, 9);
ROUND3(C, D, A, B, 5, 11);
ROUND3(B, C, D, A, 13, 15);
ROUND3(A, B, C, D, 3, 3);
ROUND3(D, A, B, C, 11, 9);
ROUND3(C, D, A, B, 7, 11);
ROUND3(B, C, D, A, 15, 15);
A += AA;
B += BB;
C += CC;
D += DD;
A &= 0xFFFFFFFF;
B &= 0xFFFFFFFF;
C &= 0xFFFFFFFF;
D &= 0xFFFFFFFF;
for (j = 0; j < 16; j++)
X[j] = 0;
}
static void
copy64(__u32 * M, unsigned char *in)
{
int i;
for (i = 0; i < 16; i++)
M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
(in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
}
static void
copy4(unsigned char *out, __u32 x)
{
out[0] = x & 0xFF;
out[1] = (x >> 8) & 0xFF;
out[2] = (x >> 16) & 0xFF;
out[3] = (x >> 24) & 0xFF;
}
/* produce a md4 message digest from data of length n bytes */
void
mdfour(unsigned char *out, unsigned char *in, int n)
{
unsigned char buf[128];
__u32 M[16];
__u32 b = n * 8;
int i;
A = 0x67452301;
B = 0xefcdab89;
C = 0x98badcfe;
D = 0x10325476;
while (n > 64) {
copy64(M, in);
mdfour64(M);
in += 64;
n -= 64;
}
for (i = 0; i < 128; i++)
buf[i] = 0;
memcpy(buf, in, n);
buf[n] = 0x80;
if (n <= 55) {
copy4(buf + 56, b);
copy64(M, buf);
mdfour64(M);
} else {
copy4(buf + 120, b);
copy64(M, buf);
mdfour64(M);
copy64(M, buf + 64);
mdfour64(M);
}
for (i = 0; i < 128; i++)
buf[i] = 0;
copy64(M, buf);
copy4(out, A);
copy4(out + 4, B);
copy4(out + 8, C);
copy4(out + 12, D);
A = B = C = D = 0;
}
/*
* This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish.
*
* Equivalent code is available from RSA Data Security, Inc.
* This code has been tested against that, and is equivalent,
* except that you don't need to include two pages of legalese
* with every copy.
*
* To compute the message digest of a chunk of bytes, declare an
* MD5Context structure, pass it to MD5Init, call MD5Update as
* needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest.
*/
/* This code slightly modified to fit into Samba by
abartlet@samba.org Jun 2001
and to fit the cifs vfs by
Steve French sfrench@us.ibm.com */
#include <linux/fs.h>
#include "md5.h"
static void MD5Transform(__u32 buf[4], __u32 const in[16]);
/*
* Note: this code is harmless on little-endian machines.
*/
static void
byteReverse(unsigned char *buf, unsigned longs)
{
__u32 t;
do {
t = (__u32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(__u32 *) buf = t;
buf += 4;
} while (--longs);
}
/*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
void
MD5Init(struct MD5Context *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
register __u32 t;
/* Update bitcount */
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((__u32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t;
if (len < t) {
memmove(p, buf, len);
return;
}
memmove(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (__u32 *) ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64) {
memmove(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (__u32 *) ctx->in);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
memmove(ctx->in, buf, len);
}
/*
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void
MD5Final(unsigned char digest[16], struct MD5Context *ctx)
{
unsigned int count;
unsigned char *p;
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (__u32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
((__u32 *) ctx->in)[14] = ctx->bits[0];
((__u32 *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (__u32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memmove(digest, ctx->buf, 16);
memset(ctx, 0, sizeof (ctx)); /* In case it's sensitive */
}
/* The four core functions - F1 is optimized somewhat */
/* #define F1(x, y, z) (x & y | ~x & z) */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
static void
MD5Transform(__u32 buf[4], __u32 const in[16])
{
register __u32 a, b, c, d;
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
/***********************************************************************
the rfc 2104 version of hmac_md5 initialisation.
***********************************************************************/
void
hmac_md5_init_rfc2104(unsigned char *key, int key_len,
struct HMACMD5Context *ctx)
{
int i;
/* if key is longer than 64 bytes reset it to key=MD5(key) */
if (key_len > 64) {
unsigned char tk[16];
struct MD5Context tctx;
MD5Init(&tctx);
MD5Update(&tctx, key, key_len);
MD5Final(tk, &tctx);
key = tk;
key_len = 16;
}
/* start out by storing key in pads */
memset(ctx->k_ipad, 0, sizeof (ctx->k_ipad));
memset(ctx->k_opad, 0, sizeof (ctx->k_opad));
memcpy(ctx->k_ipad, key, key_len);
memcpy(ctx->k_opad, key, key_len);
/* XOR key with ipad and opad values */
for (i = 0; i < 64; i++) {
ctx->k_ipad[i] ^= 0x36;
ctx->k_opad[i] ^= 0x5c;
}
MD5Init(&ctx->ctx);
MD5Update(&ctx->ctx, ctx->k_ipad, 64);
}
/***********************************************************************
the microsoft version of hmac_md5 initialisation.
***********************************************************************/
void
hmac_md5_init_limK_to_64(const unsigned char *key, int key_len,
struct HMACMD5Context *ctx)
{
int i;
/* if key is longer than 64 bytes truncate it */
if (key_len > 64) {
key_len = 64;
}
/* start out by storing key in pads */
memset(ctx->k_ipad, 0, sizeof (ctx->k_ipad));
memset(ctx->k_opad, 0, sizeof (ctx->k_opad));
memcpy(ctx->k_ipad, key, key_len);
memcpy(ctx->k_opad, key, key_len);
/* XOR key with ipad and opad values */
for (i = 0; i < 64; i++) {
ctx->k_ipad[i] ^= 0x36;
ctx->k_opad[i] ^= 0x5c;
}
MD5Init(&ctx->ctx);
MD5Update(&ctx->ctx, ctx->k_ipad, 64);
}
/***********************************************************************
update hmac_md5 "inner" buffer
***********************************************************************/
void
hmac_md5_update(const unsigned char *text, int text_len,
struct HMACMD5Context *ctx)
{
MD5Update(&ctx->ctx, text, text_len); /* then text of datagram */
}
/***********************************************************************
finish off hmac_md5 "inner" buffer and generate outer one.
***********************************************************************/
void
hmac_md5_final(unsigned char *digest, struct HMACMD5Context *ctx)
{
struct MD5Context ctx_o;
MD5Final(digest, &ctx->ctx);
MD5Init(&ctx_o);
MD5Update(&ctx_o, ctx->k_opad, 64);
MD5Update(&ctx_o, digest, 16);
MD5Final(digest, &ctx_o);
}
/***********************************************************
single function to calculate an HMAC MD5 digest from data.
use the microsoft hmacmd5 init method because the key is 16 bytes.
************************************************************/
void
hmac_md5(unsigned char key[16], unsigned char *data, int data_len,
unsigned char *digest)
{
struct HMACMD5Context ctx;
hmac_md5_init_limK_to_64(key, 16, &ctx);
if (data_len != 0) {
hmac_md5_update(data, data_len, &ctx);
}
hmac_md5_final(digest, &ctx);
}
#ifndef MD5_H
#define MD5_H
#ifndef HEADER_MD5_H
/* Try to avoid clashes with OpenSSL */
#define HEADER_MD5_H
#endif
struct MD5Context {
__u32 buf[4];
__u32 bits[2];
unsigned char in[64];
};
#endif /* !MD5_H */
#ifndef _HMAC_MD5_H
struct HMACMD5Context {
struct MD5Context ctx;
unsigned char k_ipad[65];
unsigned char k_opad[65];
};
#endif /* _HMAC_MD5_H */
void MD5Init(struct MD5Context *context);
void MD5Update(struct MD5Context *context, unsigned char const *buf,
unsigned len);
void MD5Final(unsigned char digest[16], struct MD5Context *context);
/* The following definitions come from lib/hmacmd5.c */
void hmac_md5_init_rfc2104(unsigned char *key, int key_len,
struct HMACMD5Context *ctx);
void hmac_md5_init_limK_to_64(const unsigned char *key, int key_len,
struct HMACMD5Context *ctx);
void hmac_md5_update(const unsigned char *text, int text_len,
struct HMACMD5Context *ctx);
void hmac_md5_final(unsigned char *digest, struct HMACMD5Context *ctx);
void hmac_md5(unsigned char key[16], unsigned char *data, int data_len,
unsigned char *digest);
/*
* fs/cifs/misc.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/slab.h>
#include <linux/ctype.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
extern kmem_cache_t *cifs_req_cachep;
static DECLARE_MUTEX(GlobalMid_Sem); /* also protects XID globals */
__u16 GlobalMid; /* multiplex id - rotating counter */
/* The xid serves as a useful identifier for each incoming vfs request,
in a similar way to the mid which is useful to track each sent smb,
and CurrentXid can also provide a running counter (although it
will eventually wrap past zero) of the total vfs operations handled
since the cifs fs was mounted */
unsigned int
_GetXid(void)
{
unsigned int xid;
down(&GlobalMid_Sem);
GlobalTotalActiveXid++;
if (GlobalTotalActiveXid > GlobalMaxActiveXid)
GlobalMaxActiveXid = GlobalTotalActiveXid; /* keep high water mark for number of simultaneous vfs ops in our filesystem */
xid = GlobalCurrentXid++;
up(&GlobalMid_Sem);
return xid;
}
void
_FreeXid(unsigned int xid)
{
down(&GlobalMid_Sem);
GlobalTotalActiveXid--;
up(&GlobalMid_Sem);
}
struct cifsSesInfo *
sesInfoAlloc(void)
{
struct cifsSesInfo *ret_buf;
ret_buf =
(struct cifsSesInfo *) kmalloc(sizeof (struct cifsSesInfo),
GFP_KERNEL);
if (ret_buf) {
memset(ret_buf, 0, sizeof (struct cifsSesInfo));
atomic_inc(&sesInfoAllocCount);
list_add(&ret_buf->cifsSessionList, &GlobalSMBSessionList);
init_MUTEX(&ret_buf->sesSem);
}
return ret_buf;
}
void
sesInfoFree(struct cifsSesInfo *buf_to_free)
{
if (buf_to_free == NULL) {
cFYI(1, ("\nNull buffer passed to sesInfoFree"));
return;
}
atomic_dec(&sesInfoAllocCount);
list_del(&buf_to_free->cifsSessionList);
if (buf_to_free->serverOS)
kfree(buf_to_free->serverOS);
if (buf_to_free->serverDomain)
kfree(buf_to_free->serverDomain);
if (buf_to_free->serverNOS)
kfree(buf_to_free->serverNOS);
kfree(buf_to_free);
}
struct cifsTconInfo *
tconInfoAlloc(void)
{
struct cifsTconInfo *ret_buf;
ret_buf =
(struct cifsTconInfo *) kmalloc(sizeof (struct cifsTconInfo),
GFP_KERNEL);
if (ret_buf) {
memset(ret_buf, 0, sizeof (struct cifsTconInfo));
atomic_inc(&tconInfoAllocCount);
list_add(&ret_buf->cifsConnectionList,
&GlobalTreeConnectionList);
INIT_LIST_HEAD(&ret_buf->openFileList);
init_MUTEX(&ret_buf->tconSem);
}
return ret_buf;
}
void
tconInfoFree(struct cifsTconInfo *buf_to_free)
{
if (buf_to_free == NULL) {
cFYI(1, ("\nNull buffer passed to tconInfoFree"));
return;
}
atomic_dec(&tconInfoAllocCount);
list_del(&buf_to_free->cifsConnectionList);
if (buf_to_free->nativeFileSystem)
kfree(buf_to_free->nativeFileSystem);
kfree(buf_to_free);
}
void *
kcalloc(size_t size, int type)
{
void *addr;
addr = kmalloc(size, type);
if (addr)
memset(addr, 0, size);
return addr;
}
struct smb_hdr *
buf_get(void)
{
struct smb_hdr *ret_buf;
/* We could use negotiated size instead of max_msgsize -
but it may be more efficient to always alloc same size
albeit slightly larger */
ret_buf =
(struct smb_hdr *) kmem_cache_alloc(cifs_req_cachep, SLAB_KERNEL);
/* clear the first few header bytes */
if (ret_buf) {
memset(ret_buf, 0, sizeof (struct smb_hdr));
atomic_inc(&bufAllocCount);
}
return ret_buf;
}
void
buf_release(void *buf_to_free)
{
if (buf_to_free == NULL) {
cFYI(1, ("\nNull buffer passed to buf_release"));
return;
}
kmem_cache_free(cifs_req_cachep, buf_to_free);
atomic_dec(&bufAllocCount);
return;
}
void
header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
const struct cifsTconInfo *treeCon, int word_count
/* length of fixed section (word count) in two byte units */
)
{
int i;
__u32 tmp;
char *temp = (char *) buffer;
for (i = 0; i < MAX_CIFS_HDR_SIZE; i++) {
temp[i] = 0; /* BB is this needed ?? */
}
buffer->smb_buf_length =
(2 * word_count) + sizeof (struct smb_hdr) -
4 /* RFC 1001 length field does not count */ +
2 /* for bcc field itself */ ;
/* Note that this is the only network field that has to be converted to big endian and it is done just before we send it */
buffer->Protocol[0] = 0xFF;
buffer->Protocol[1] = 'S';
buffer->Protocol[2] = 'M';
buffer->Protocol[3] = 'B';
buffer->Command = smb_command;
buffer->Flags = 0x00; /* case sensitive */
buffer->Flags2 = SMBFLG2_KNOWS_LONG_NAMES;
tmp = cpu_to_le32(current->pid);
buffer->Pid = tmp & 0xFFFF;
tmp >>= 16;
buffer->PidHigh = tmp & 0xFFFF;
down(&GlobalMid_Sem);
GlobalMid++;
buffer->Mid = GlobalMid;
if (treeCon) {
buffer->Tid = treeCon->tid;
if (treeCon->ses) {
if (treeCon->ses->capabilities & CAP_UNICODE)
buffer->Flags2 |= SMBFLG2_UNICODE;
if (treeCon->ses->capabilities & CAP_STATUS32) {
buffer->Flags2 |= SMBFLG2_ERR_STATUS;
}
buffer->Uid = treeCon->ses->Suid; /* always in LE format */
}
if (treeCon->Flags & SMB_SHARE_IS_IN_DFS)
buffer->Flags2 |= SMBFLG2_DFS;
if(treeCon->ses->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
}
/* endian conversion of flags is now done just before sending */
up(&GlobalMid_Sem);
buffer->WordCount = (char) word_count;
return;
}
int
checkSMBhdr(struct smb_hdr *smb, __u16 mid)
{
/* Make sure that this really is an SMB, that it is a response,
and that the message ids match */
if ((*(unsigned int *) smb->Protocol == cpu_to_le32(0x424d53ff)) && (mid == smb->Mid)) {
if(smb->Flags & SMBFLG_RESPONSE)
return 0;
else {
/* only one valid case where server sends us request */
if(smb->Command == SMB_COM_LOCKING_ANDX)
return 0;
else
cERROR(1, ("\n Rcvd Request not response "));
}
} else { /* bad signature or mid */
if (*(unsigned int *) smb->Protocol != cpu_to_le32(0x424d53ff))
cERROR(1,
("\nBad protocol string signature header %x ",
*(unsigned int *) smb->Protocol));
if (mid != smb->Mid)
cERROR(1, ("\n Mids do not match \n"));
}
cERROR(1, ("\nCIFS: bad smb detected. The Mid=%d\n", smb->Mid));
return 1;
}
int
checkSMB(struct smb_hdr *smb, __u16 mid, int length)
{
cFYI(0,
("\nEntering checkSMB with Length: %x, smb_buf_length: %x ",
length, ntohl(smb->smb_buf_length)));
if ((length < 2 + sizeof (struct smb_hdr))
|| (4 + ntohl(smb->smb_buf_length) >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE)) {
if (length < 2 + sizeof (struct smb_hdr)) {
cERROR(1, ("\n Length less than 2 + sizeof smb_hdr "));
if ((length >= sizeof (struct smb_hdr) - 1)
&& (smb->Status.CifsError != 0))
return 0; /* this is ok - some error cases do not return wct and bcc */
}
if (4 + ntohl(smb->smb_buf_length) >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE)
cERROR(1,
("\n smb_buf_length greater than CIFS_MAX_MSGSIZE ... "));
cERROR(1,
("CIFS: bad smb detected. Illegal length. The mid=%d\n",
smb->Mid));
return 1;
}
if (checkSMBhdr(smb, mid))
return 1;
if ((4 + ntohl(smb->smb_buf_length) != smbCalcSize(smb))
|| (4 + ntohl(smb->smb_buf_length) != length)) {
return 0;
} else {
cERROR(1, ("\nCIFS: smbCalcSize %x ", smbCalcSize(smb)));
cERROR(1,
("CIFS: bad smb size detected. The Mid=%d\n", smb->Mid));
return 1;
}
}
int
is_valid_oplock_break(struct smb_hdr *buf)
{
struct smb_com_lock_req * pSMB = (struct smb_com_lock_req *)buf;
/* could add check for smb response flag 0x80 */
cFYI(1,("\nChecking for oplock break"));
if(pSMB->hdr.Command != SMB_COM_LOCKING_ANDX)
return FALSE;
if(pSMB->hdr.Flags & SMBFLG_RESPONSE)
return FALSE; /* server sends us "request" here */
if(pSMB->hdr.WordCount != 8)
return FALSE;
cFYI(1,(" oplock type 0x%d level 0x%d",pSMB->LockType,pSMB->OplockLevel));
if(!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE))
return FALSE;
/* BB Add following logic:
1) look up tcon based on tid & uid
2) look up inode from tcon->openFileList->file->f_dentry->d_inode
3) flush dirty pages and cached byte range locks and mark inode
4) depending on break type change to r/o caching or no caching
5) send oplock break response to server */
cFYI(1,("\nNeed to process oplock break "));
return TRUE;
}
void
dump_smb(struct smb_hdr *smb_buf, int smb_buf_length)
{
int i, j;
char debug_line[17];
unsigned char *buffer;
if (traceSMB == 0)
return;
buffer = (unsigned char *) smb_buf;
for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
if (i % 8 == 0) { /* we have reached the beginning of line */
printk("\n| ");
j = 0;
}
printk("%0#4x ", buffer[i]);
debug_line[2 * j] = ' ';
if (isprint(buffer[i]))
debug_line[1 + (2 * j)] = buffer[i];
else
debug_line[1 + (2 * j)] = '_';
if (i % 8 == 7) { /* we have reached end of line, time to print ascii */
debug_line[16] = 0;
printk(" | %s", debug_line);
}
}
for (; j < 8; j++) {
printk(" ");
debug_line[2 * j] = ' ';
debug_line[1 + (2 * j)] = ' ';
}
printk(" | %s\n", debug_line);
return;
}
/*
* fs/cifs/netmisc.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* Error mapping routines from Samba libsmb/errormap.c
* Copyright (C) Andrew Tridgell 2001
*
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/net.h>
#include <linux/string.h>
#include <linux/in.h>
#include <linux/ctype.h>
#include <linux/fs.h>
#include <asm/div64.h>
#include <asm/byteorder.h>
#include "cifsfs.h"
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "smberr.h"
#include "cifs_debug.h"
#include "nterr.h"
struct smb_to_posix_error {
__u16 smb_err;
int posix_code;
};
const struct smb_to_posix_error mapping_table_ERRDOS[] = {
{ERRbadfunc, -EINVAL},
{ERRbadfile, -ENOENT},
{ERRbadpath, -ENOENT},
{ERRnofids, -EMFILE},
{ERRnoaccess, -EACCES},
{ERRbadfid, -EBADF},
{ERRbadmcb, -EIO},
{ERRnomem, -ENOMEM},
{ERRbadmem, -EFAULT},
{ERRbadenv, -EFAULT},
{ERRbadformat, -EINVAL},
{ERRbadaccess, -EACCES},
{ERRbaddata, -EIO},
{ERRbaddrive, -ENXIO},
{ERRremcd, -EACCES},
{ERRdiffdevice, -EXDEV},
{ERRnofiles, -ENOENT},
{ERRbadshare, -ETXTBSY},
{ERRlock, -EACCES},
{ERRfilexists, -EINVAL},
{ERRinvparm, -EINVAL},
{ERRdiskfull, -ENOSPC},
{ERRinvnum, -EINVAL},
{ERRdirnotempty, -ENOTEMPTY},
{ERRnotlocked, -ENOLCK},
{ERRalreadyexists, -EEXIST},
{ERRmoredata, -EOVERFLOW},
{ErrQuota, -EDQUOT},
{ErrNotALink, -ENOLINK},
{0, 0}
};
const struct smb_to_posix_error mapping_table_ERRSRV[] = {
{ERRerror, -EIO},
{ERRbadpw, -EACCES},
{ERRbadtype, -EREMOTE},
{ERRaccess, -EACCES},
{ERRinvtid, -ENXIO},
{ERRinvnetname, -ENOENT},
{ERRinvdevice, -ENXIO},
{ERRqfull, -ENOSPC},
{ERRqtoobig, -ENOSPC},
{ERRqeof, -EIO},
{ERRinvpfid, -EBADF},
{ERRsmbcmd, -EBADRQC},
{ERRsrverror, -EIO},
{ERRbadBID, -EIO},
{ERRfilespecs, -EINVAL},
{ERRbadLink, -EIO},
{ERRbadpermits, -EINVAL},
{ERRbadPID, -ESRCH},
{ERRsetattrmode, -EINVAL},
{ERRpaused, -EHOSTDOWN},
{ERRmsgoff, -EHOSTDOWN},
{ERRnoroom, -ENOSPC},
{ERRrmuns, -EUSERS},
{ERRtimeout, -ETIME},
{ERRnoresource, -ENOBUFS},
{ERRtoomanyuids, -EUSERS},
{ERRbaduid, -EACCES},
{ERRusempx, -EIO},
{ERRusestd, -EIO},
{ERR_NOTIFY_ENUM_DIR, -ENOBUFS},
{ERRaccountexpired, -EACCES},
{ERRbadclient, -EACCES},
{ERRbadLogonTime, -EACCES},
{ERRpasswordExpired, -EACCES},
{ERRnosupport, -EINVAL},
{0, 0}
};
const struct smb_to_posix_error mapping_table_ERRHRD[] = {
{0, 0}
};
/* Convert string containing dotted ip address to binary form */
/* returns 0 if invalid address */
/* BB add address family, change rc to status flag and return *//* also see inet_pton */
/* To identify v4 vs. v6 - 1) check for colon (v6 only) 2) then call inet_pton to parse for bad address */
int
inet_addr(char *cp)
{
struct in_addr address;
int value;
int digit;
int i;
char temp;
char bytes[4];
char *end = bytes;
static const int addr_class_max[4] =
{ 0xffffffff, 0xffffff, 0xffff, 0xff };
for (i = 0; i < 4; i++) {
bytes[i] = 0;
}
temp = *cp;
while (TRUE) {
if (!isdigit(temp))
return 0;
value = 0;
digit = 0;
for (;;) {
if (isascii(temp) && isdigit(temp)) {
value = (value * 10) + temp - '0';
temp = *++cp;
digit = 1;
} else
break;
}
if (temp == '.') {
if ((end > bytes + 2) || (value > 255))
return 0;
*end++ = value;
temp = *++cp;
} else
break;
}
/* check for last characters */
if (temp != '\0' && (!isascii(temp) || !isspace(temp)))
if (temp != '\\') {
if (temp != '/')
return 0;
else
(*cp = '\\'); /* switch the slash the expected way */
}
if (value > addr_class_max[end - bytes])
return 0;
address.s_addr = *((int *) bytes) | htonl(value);
return address.s_addr;
}
/*****************************************************************************
convert a NT status code to a dos class/code
*****************************************************************************/
/* NT status -> dos error map */
const static struct {
__u8 dos_class;
__u16 dos_code;
__u32 ntstatus;
} ntstatus_to_dos_map[] = {
{
ERRDOS, ERRgeneral, NT_STATUS_UNSUCCESSFUL}, {
ERRDOS, ERRbadfunc, NT_STATUS_NOT_IMPLEMENTED}, {
ERRDOS, 87, NT_STATUS_INVALID_INFO_CLASS}, {
ERRDOS, 24, NT_STATUS_INFO_LENGTH_MISMATCH}, {
ERRHRD, ERRgeneral, NT_STATUS_ACCESS_VIOLATION}, {
ERRHRD, ERRgeneral, NT_STATUS_IN_PAGE_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_QUOTA}, {
ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_INITIAL_STACK}, {
ERRDOS, 193, NT_STATUS_BAD_INITIAL_PC}, {
ERRDOS, 87, NT_STATUS_INVALID_CID}, {
ERRHRD, ERRgeneral, NT_STATUS_TIMER_NOT_CANCELED}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER}, {
ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_DEVICE}, {
ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE}, {
ERRDOS, ERRbadfunc, NT_STATUS_INVALID_DEVICE_REQUEST}, {
ERRDOS, 38, NT_STATUS_END_OF_FILE}, {
ERRDOS, 34, NT_STATUS_WRONG_VOLUME}, {
ERRDOS, 21, NT_STATUS_NO_MEDIA_IN_DEVICE}, {
ERRHRD, ERRgeneral, NT_STATUS_UNRECOGNIZED_MEDIA}, {
ERRDOS, 27, NT_STATUS_NONEXISTENT_SECTOR},
/* { This NT error code was 'sqashed'
from NT_STATUS_MORE_PROCESSING_REQUIRED to NT_STATUS_OK
during the session setup } */
{
ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY}, {
ERRDOS, 487, NT_STATUS_CONFLICTING_ADDRESSES}, {
ERRDOS, 487, NT_STATUS_NOT_MAPPED_VIEW}, {
ERRDOS, 87, NT_STATUS_UNABLE_TO_FREE_VM}, {
ERRDOS, 87, NT_STATUS_UNABLE_TO_DELETE_SECTION}, {
ERRDOS, 2142, NT_STATUS_INVALID_SYSTEM_SERVICE}, {
ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_INSTRUCTION}, {
ERRDOS, ERRnoaccess, NT_STATUS_INVALID_LOCK_SEQUENCE}, {
ERRDOS, ERRnoaccess, NT_STATUS_INVALID_VIEW_SIZE}, {
ERRDOS, 193, NT_STATUS_INVALID_FILE_FOR_SECTION}, {
ERRDOS, ERRnoaccess, NT_STATUS_ALREADY_COMMITTED},
/* { This NT error code was 'sqashed'
from NT_STATUS_ACCESS_DENIED to NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE
during the session setup } */
{
ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED}, {
ERRDOS, 111, NT_STATUS_BUFFER_TOO_SMALL}, {
ERRDOS, ERRbadfid, NT_STATUS_OBJECT_TYPE_MISMATCH}, {
ERRHRD, ERRgeneral, NT_STATUS_NONCONTINUABLE_EXCEPTION}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_DISPOSITION}, {
ERRHRD, ERRgeneral, NT_STATUS_UNWIND}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_STACK}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_UNWIND_TARGET}, {
ERRDOS, 158, NT_STATUS_NOT_LOCKED}, {
ERRHRD, ERRgeneral, NT_STATUS_PARITY_ERROR}, {
ERRDOS, 487, NT_STATUS_UNABLE_TO_DECOMMIT_VM}, {
ERRDOS, 487, NT_STATUS_NOT_COMMITTED}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_PORT_ATTRIBUTES}, {
ERRHRD, ERRgeneral, NT_STATUS_PORT_MESSAGE_TOO_LONG}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_MIX}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_QUOTA_LOWER}, {
ERRHRD, ERRgeneral, NT_STATUS_DISK_CORRUPT_ERROR}, {
ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_INVALID}, { /* mapping changed since shell does lookup on * and expects file not found */
ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND}, {
ERRDOS, 183, NT_STATUS_OBJECT_NAME_COLLISION}, {
ERRHRD, ERRgeneral, NT_STATUS_HANDLE_NOT_WAITABLE}, {
ERRDOS, ERRbadfid, NT_STATUS_PORT_DISCONNECTED}, {
ERRHRD, ERRgeneral, NT_STATUS_DEVICE_ALREADY_ATTACHED}, {
ERRDOS, 161, NT_STATUS_OBJECT_PATH_INVALID}, {
ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND}, {
ERRDOS, 161, NT_STATUS_OBJECT_PATH_SYNTAX_BAD}, {
ERRHRD, ERRgeneral, NT_STATUS_DATA_OVERRUN}, {
ERRHRD, ERRgeneral, NT_STATUS_DATA_LATE_ERROR}, {
ERRDOS, 23, NT_STATUS_DATA_ERROR}, {
ERRDOS, 23, NT_STATUS_CRC_ERROR}, {
ERRDOS, ERRnomem, NT_STATUS_SECTION_TOO_BIG}, {
ERRDOS, ERRnoaccess, NT_STATUS_PORT_CONNECTION_REFUSED}, {
ERRDOS, ERRbadfid, NT_STATUS_INVALID_PORT_HANDLE}, {
ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION}, {
ERRHRD, ERRgeneral, NT_STATUS_QUOTA_EXCEEDED}, {
ERRDOS, 87, NT_STATUS_INVALID_PAGE_PROTECTION}, {
ERRDOS, 288, NT_STATUS_MUTANT_NOT_OWNED}, {
ERRDOS, 298, NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED}, {
ERRDOS, 87, NT_STATUS_PORT_ALREADY_SET}, {
ERRDOS, 87, NT_STATUS_SECTION_NOT_IMAGE}, {
ERRDOS, 156, NT_STATUS_SUSPEND_COUNT_EXCEEDED}, {
ERRDOS, ERRnoaccess, NT_STATUS_THREAD_IS_TERMINATING}, {
ERRDOS, 87, NT_STATUS_BAD_WORKING_SET_LIMIT}, {
ERRDOS, 87, NT_STATUS_INCOMPATIBLE_FILE_MAP}, {
ERRDOS, 87, NT_STATUS_SECTION_PROTECTION}, {
ERRDOS, 282, NT_STATUS_EAS_NOT_SUPPORTED}, {
ERRDOS, 255, NT_STATUS_EA_TOO_LARGE}, {
ERRHRD, ERRgeneral, NT_STATUS_NONEXISTENT_EA_ENTRY}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_EAS_ON_FILE}, {
ERRHRD, ERRgeneral, NT_STATUS_EA_CORRUPT_ERROR}, {
ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT}, {
ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED}, {
ERRDOS, ERRnoaccess, NT_STATUS_DELETE_PENDING}, {
ERRDOS, ERRunsup, NT_STATUS_CTL_FILE_NOT_SUPPORTED}, {
ERRHRD, ERRgeneral, NT_STATUS_UNKNOWN_REVISION}, {
ERRHRD, ERRgeneral, NT_STATUS_REVISION_MISMATCH}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_OWNER}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_PRIMARY_GROUP}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_IMPERSONATION_TOKEN}, {
ERRHRD, ERRgeneral, NT_STATUS_CANT_DISABLE_MANDATORY}, {
ERRDOS, 2215, NT_STATUS_NO_LOGON_SERVERS}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_LOGON_SESSION}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_PRIVILEGE}, {
ERRDOS, ERRnoaccess, NT_STATUS_PRIVILEGE_NOT_HELD}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_ACCOUNT_NAME}, {
ERRHRD, ERRgeneral, NT_STATUS_USER_EXISTS},
/* { This NT error code was 'sqashed'
from NT_STATUS_NO_SUCH_USER to NT_STATUS_LOGON_FAILURE
during the session setup } */
{
ERRDOS, ERRnoaccess, NT_STATUS_NO_SUCH_USER}, {
ERRHRD, ERRgeneral, NT_STATUS_GROUP_EXISTS}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_GROUP}, {
ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_GROUP}, {
ERRHRD, ERRgeneral, NT_STATUS_MEMBER_NOT_IN_GROUP}, {
ERRHRD, ERRgeneral, NT_STATUS_LAST_ADMIN},
/* { This NT error code was 'sqashed'
from NT_STATUS_WRONG_PASSWORD to NT_STATUS_LOGON_FAILURE
during the session setup } */
{
ERRSRV, ERRbadpw, NT_STATUS_WRONG_PASSWORD}, {
ERRHRD, ERRgeneral, NT_STATUS_ILL_FORMED_PASSWORD}, {
ERRHRD, ERRgeneral, NT_STATUS_PASSWORD_RESTRICTION}, {
ERRDOS, ERRnoaccess, NT_STATUS_LOGON_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_ACCOUNT_RESTRICTION}, {
ERRSRV, 2241, NT_STATUS_INVALID_LOGON_HOURS}, {
ERRSRV, 2240, NT_STATUS_INVALID_WORKSTATION}, {
ERRSRV, 2242, NT_STATUS_PASSWORD_EXPIRED}, {
ERRSRV, 2239, NT_STATUS_ACCOUNT_DISABLED}, {
ERRHRD, ERRgeneral, NT_STATUS_NONE_MAPPED}, {
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_LUIDS_REQUESTED}, {
ERRHRD, ERRgeneral, NT_STATUS_LUIDS_EXHAUSTED}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_SUB_AUTHORITY}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_ACL}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_SID}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_SECURITY_DESCR}, {
ERRDOS, 127, NT_STATUS_PROCEDURE_NOT_FOUND}, {
ERRDOS, 193, NT_STATUS_INVALID_IMAGE_FORMAT}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_TOKEN}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_INHERITANCE_ACL}, {
ERRDOS, 158, NT_STATUS_RANGE_NOT_LOCKED}, {
ERRDOS, 112, NT_STATUS_DISK_FULL}, {
ERRHRD, ERRgeneral, NT_STATUS_SERVER_DISABLED}, {
ERRHRD, ERRgeneral, NT_STATUS_SERVER_NOT_DISABLED}, {
ERRDOS, 68, NT_STATUS_TOO_MANY_GUIDS_REQUESTED}, {
ERRDOS, 259, NT_STATUS_GUIDS_EXHAUSTED}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_ID_AUTHORITY}, {
ERRDOS, 259, NT_STATUS_AGENTS_EXHAUSTED}, {
ERRDOS, 154, NT_STATUS_INVALID_VOLUME_LABEL}, {
ERRDOS, 14, NT_STATUS_SECTION_NOT_EXTENDED}, {
ERRDOS, 487, NT_STATUS_NOT_MAPPED_DATA}, {
ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_DATA_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_TYPE_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_NAME_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_ARRAY_BOUNDS_EXCEEDED}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_DENORMAL_OPERAND}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_DIVIDE_BY_ZERO}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_INEXACT_RESULT}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_INVALID_OPERATION}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_OVERFLOW}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_STACK_CHECK}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOAT_UNDERFLOW}, {
ERRHRD, ERRgeneral, NT_STATUS_INTEGER_DIVIDE_BY_ZERO}, {
ERRDOS, 534, NT_STATUS_INTEGER_OVERFLOW}, {
ERRHRD, ERRgeneral, NT_STATUS_PRIVILEGED_INSTRUCTION}, {
ERRDOS, ERRnomem, NT_STATUS_TOO_MANY_PAGING_FILES}, {
ERRHRD, ERRgeneral, NT_STATUS_FILE_INVALID}, {
ERRHRD, ERRgeneral, NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
/* { This NT error code was 'sqashed'
from NT_STATUS_INSUFFICIENT_RESOURCES to NT_STATUS_INSUFF_SERVER_RESOURCES
during the session setup } */
{
ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES}, {
ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, {
ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, {
ERRDOS, 21, NT_STATUS_DEVICE_POWER_FAILURE}, {
ERRDOS, 487, NT_STATUS_FREE_VM_NOT_AT_BASE}, {
ERRDOS, 487, NT_STATUS_MEMORY_NOT_ALLOCATED}, {
ERRHRD, ERRgeneral, NT_STATUS_WORKING_SET_QUOTA}, {
ERRDOS, 19, NT_STATUS_MEDIA_WRITE_PROTECTED}, {
ERRDOS, 21, NT_STATUS_DEVICE_NOT_READY}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_GROUP_ATTRIBUTES}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_IMPERSONATION_LEVEL}, {
ERRHRD, ERRgeneral, NT_STATUS_CANT_OPEN_ANONYMOUS}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_VALIDATION_CLASS}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_TOKEN_TYPE}, {
ERRDOS, 87, NT_STATUS_BAD_MASTER_BOOT_RECORD}, {
ERRHRD, ERRgeneral, NT_STATUS_INSTRUCTION_MISALIGNMENT}, {
ERRDOS, ERRpipebusy, NT_STATUS_INSTANCE_NOT_AVAILABLE}, {
ERRDOS, ERRpipebusy, NT_STATUS_PIPE_NOT_AVAILABLE}, {
ERRDOS, ERRbadpipe, NT_STATUS_INVALID_PIPE_STATE}, {
ERRDOS, ERRpipebusy, NT_STATUS_PIPE_BUSY}, {
ERRDOS, ERRbadfunc, NT_STATUS_ILLEGAL_FUNCTION}, {
ERRDOS, ERRnotconnected, NT_STATUS_PIPE_DISCONNECTED}, {
ERRDOS, ERRpipeclosing, NT_STATUS_PIPE_CLOSING}, {
ERRHRD, ERRgeneral, NT_STATUS_PIPE_CONNECTED}, {
ERRHRD, ERRgeneral, NT_STATUS_PIPE_LISTENING}, {
ERRDOS, ERRbadpipe, NT_STATUS_INVALID_READ_MODE}, {
ERRDOS, 121, NT_STATUS_IO_TIMEOUT}, {
ERRDOS, 38, NT_STATUS_FILE_FORCED_CLOSED}, {
ERRHRD, ERRgeneral, NT_STATUS_PROFILING_NOT_STARTED}, {
ERRHRD, ERRgeneral, NT_STATUS_PROFILING_NOT_STOPPED}, {
ERRHRD, ERRgeneral, NT_STATUS_COULD_NOT_INTERPRET}, {
ERRDOS, ERRnoaccess, NT_STATUS_FILE_IS_A_DIRECTORY}, {
ERRDOS, ERRunsup, NT_STATUS_NOT_SUPPORTED}, {
ERRDOS, 51, NT_STATUS_REMOTE_NOT_LISTENING}, {
ERRDOS, 52, NT_STATUS_DUPLICATE_NAME}, {
ERRDOS, 53, NT_STATUS_BAD_NETWORK_PATH}, {
ERRDOS, 54, NT_STATUS_NETWORK_BUSY}, {
ERRDOS, 55, NT_STATUS_DEVICE_DOES_NOT_EXIST}, {
ERRDOS, 56, NT_STATUS_TOO_MANY_COMMANDS}, {
ERRDOS, 57, NT_STATUS_ADAPTER_HARDWARE_ERROR}, {
ERRDOS, 58, NT_STATUS_INVALID_NETWORK_RESPONSE}, {
ERRDOS, 59, NT_STATUS_UNEXPECTED_NETWORK_ERROR}, {
ERRDOS, 60, NT_STATUS_BAD_REMOTE_ADAPTER}, {
ERRDOS, 61, NT_STATUS_PRINT_QUEUE_FULL}, {
ERRDOS, 62, NT_STATUS_NO_SPOOL_SPACE}, {
ERRDOS, 63, NT_STATUS_PRINT_CANCELLED}, {
ERRDOS, 64, NT_STATUS_NETWORK_NAME_DELETED}, {
ERRDOS, 65, NT_STATUS_NETWORK_ACCESS_DENIED}, {
ERRDOS, 66, NT_STATUS_BAD_DEVICE_TYPE}, {
ERRDOS, ERRnosuchshare, NT_STATUS_BAD_NETWORK_NAME}, {
ERRDOS, 68, NT_STATUS_TOO_MANY_NAMES}, {
ERRDOS, 69, NT_STATUS_TOO_MANY_SESSIONS}, {
ERRDOS, 70, NT_STATUS_SHARING_PAUSED}, {
ERRDOS, 71, NT_STATUS_REQUEST_NOT_ACCEPTED}, {
ERRDOS, 72, NT_STATUS_REDIRECTOR_PAUSED}, {
ERRDOS, 88, NT_STATUS_NET_WRITE_FAULT}, {
ERRHRD, ERRgeneral, NT_STATUS_PROFILING_AT_LIMIT}, {
ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE}, {
ERRDOS, ERRnoaccess, NT_STATUS_FILE_RENAMED}, {
ERRDOS, 240, NT_STATUS_VIRTUAL_CIRCUIT_CLOSED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SECURITY_ON_OBJECT}, {
ERRHRD, ERRgeneral, NT_STATUS_CANT_WAIT}, {
ERRDOS, ERRpipeclosing, NT_STATUS_PIPE_EMPTY}, {
ERRHRD, ERRgeneral, NT_STATUS_CANT_ACCESS_DOMAIN_INFO}, {
ERRHRD, ERRgeneral, NT_STATUS_CANT_TERMINATE_SELF}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_SERVER_STATE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_DOMAIN_STATE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_DOMAIN_ROLE}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_DOMAIN}, {
ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_EXISTS}, {
ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_LIMIT_EXCEEDED}, {
ERRDOS, 300, NT_STATUS_OPLOCK_NOT_GRANTED}, {
ERRDOS, 301, NT_STATUS_INVALID_OPLOCK_PROTOCOL}, {
ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_DB_CORRUPTION}, {
ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_GENERIC_NOT_MAPPED}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_DESCRIPTOR_FORMAT}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_USER_BUFFER}, {
ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_IO_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_CREATE_ERR}, {
ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_MAP_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_EXTEND_ERR}, {
ERRHRD, ERRgeneral, NT_STATUS_NOT_LOGON_PROCESS}, {
ERRHRD, ERRgeneral, NT_STATUS_LOGON_SESSION_EXISTS}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_1}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_2}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_3}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_4}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_5}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_6}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_7}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_8}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_9}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_10}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_11}, {
ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_12}, {
ERRDOS, ERRbadpath, NT_STATUS_REDIRECTOR_NOT_STARTED}, {
ERRHRD, ERRgeneral, NT_STATUS_REDIRECTOR_STARTED}, {
ERRHRD, ERRgeneral, NT_STATUS_STACK_OVERFLOW}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_PACKAGE}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_FUNCTION_TABLE}, {
ERRDOS, 203, 0xc0000100}, {
ERRDOS, 145, NT_STATUS_DIRECTORY_NOT_EMPTY}, {
ERRHRD, ERRgeneral, NT_STATUS_FILE_CORRUPT_ERROR}, {
ERRDOS, 267, NT_STATUS_NOT_A_DIRECTORY}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_LOGON_SESSION_STATE}, {
ERRHRD, ERRgeneral, NT_STATUS_LOGON_SESSION_COLLISION}, {
ERRDOS, 206, NT_STATUS_NAME_TOO_LONG}, {
ERRDOS, 2401, NT_STATUS_FILES_OPEN}, {
ERRDOS, 2404, NT_STATUS_CONNECTION_IN_USE}, {
ERRHRD, ERRgeneral, NT_STATUS_MESSAGE_NOT_FOUND}, {
ERRDOS, ERRnoaccess, NT_STATUS_PROCESS_IS_TERMINATING}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_LOGON_TYPE}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_GUID_TRANSLATION}, {
ERRHRD, ERRgeneral, NT_STATUS_CANNOT_IMPERSONATE}, {
ERRHRD, ERRgeneral, NT_STATUS_IMAGE_ALREADY_LOADED}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_NOT_PRESENT}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_LID_NOT_EXIST}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_LID_ALREADY_OWNED}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_NOT_LID_OWNER}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_COMMAND}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_LID}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE}, {
ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_SELECTOR}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_LDT}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_SIZE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_OFFSET}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_DESCRIPTOR}, {
ERRDOS, 193, NT_STATUS_INVALID_IMAGE_NE_FORMAT}, {
ERRHRD, ERRgeneral, NT_STATUS_RXACT_INVALID_STATE}, {
ERRHRD, ERRgeneral, NT_STATUS_RXACT_COMMIT_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_MAPPED_FILE_SIZE_ZERO}, {
ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES}, {
ERRHRD, ERRgeneral, NT_STATUS_CANCELLED}, {
ERRDOS, ERRnoaccess, NT_STATUS_CANNOT_DELETE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_COMPUTER_NAME}, {
ERRDOS, ERRnoaccess, NT_STATUS_FILE_DELETED}, {
ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_ACCOUNT}, {
ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_GROUP}, {
ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_USER}, {
ERRHRD, ERRgeneral, NT_STATUS_MEMBERS_PRIMARY_GROUP}, {
ERRDOS, ERRbadfid, NT_STATUS_FILE_CLOSED}, {
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_THREADS}, {
ERRHRD, ERRgeneral, NT_STATUS_THREAD_NOT_IN_PROCESS}, {
ERRHRD, ERRgeneral, NT_STATUS_TOKEN_ALREADY_IN_USE}, {
ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_QUOTA_EXCEEDED}, {
ERRHRD, ERRgeneral, NT_STATUS_COMMITMENT_LIMIT}, {
ERRDOS, 193, NT_STATUS_INVALID_IMAGE_LE_FORMAT}, {
ERRDOS, 193, NT_STATUS_INVALID_IMAGE_NOT_MZ}, {
ERRDOS, 193, NT_STATUS_INVALID_IMAGE_PROTECT}, {
ERRDOS, 193, NT_STATUS_INVALID_IMAGE_WIN_16}, {
ERRHRD, ERRgeneral, NT_STATUS_LOGON_SERVER_CONFLICT}, {
ERRHRD, ERRgeneral, NT_STATUS_TIME_DIFFERENCE_AT_DC}, {
ERRHRD, ERRgeneral, NT_STATUS_SYNCHRONIZATION_REQUIRED}, {
ERRDOS, 126, NT_STATUS_DLL_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_OPEN_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_IO_PRIVILEGE_FAILED}, {
ERRDOS, 182, NT_STATUS_ORDINAL_NOT_FOUND}, {
ERRDOS, 127, NT_STATUS_ENTRYPOINT_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_CONTROL_C_EXIT}, {
ERRDOS, 64, NT_STATUS_LOCAL_DISCONNECT}, {
ERRDOS, 64, NT_STATUS_REMOTE_DISCONNECT}, {
ERRDOS, 51, NT_STATUS_REMOTE_RESOURCES}, {
ERRDOS, 59, NT_STATUS_LINK_FAILED}, {
ERRDOS, 59, NT_STATUS_LINK_TIMEOUT}, {
ERRDOS, 59, NT_STATUS_INVALID_CONNECTION}, {
ERRDOS, 59, NT_STATUS_INVALID_ADDRESS}, {
ERRHRD, ERRgeneral, NT_STATUS_DLL_INIT_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_MISSING_SYSTEMFILE}, {
ERRHRD, ERRgeneral, NT_STATUS_UNHANDLED_EXCEPTION}, {
ERRHRD, ERRgeneral, NT_STATUS_APP_INIT_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_CREATE_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_PAGEFILE}, {
ERRDOS, 124, NT_STATUS_INVALID_LEVEL}, {
ERRDOS, 86, NT_STATUS_WRONG_PASSWORD_CORE}, {
ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_FLOAT_CONTEXT}, {
ERRDOS, 109, NT_STATUS_PIPE_BROKEN}, {
ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_CORRUPT}, {
ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_IO_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_EVENT_PAIR}, {
ERRHRD, ERRgeneral, NT_STATUS_UNRECOGNIZED_VOLUME}, {
ERRHRD, ERRgeneral, NT_STATUS_SERIAL_NO_DEVICE_INITED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_ALIAS}, {
ERRHRD, ERRgeneral, NT_STATUS_MEMBER_NOT_IN_ALIAS}, {
ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_ALIAS}, {
ERRHRD, ERRgeneral, NT_STATUS_ALIAS_EXISTS}, {
ERRHRD, ERRgeneral, NT_STATUS_LOGON_NOT_GRANTED}, {
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_SECRETS}, {
ERRHRD, ERRgeneral, NT_STATUS_SECRET_TOO_LONG}, {
ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_DB_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_FULLSCREEN_MODE}, {
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_CONTEXT_IDS}, {
ERRDOS, ERRnoaccess, NT_STATUS_LOGON_TYPE_NOT_GRANTED}, {
ERRHRD, ERRgeneral, NT_STATUS_NOT_REGISTRY_FILE}, {
ERRHRD, ERRgeneral, NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED}, {
ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_FT_MISSING_MEMBER}, {
ERRHRD, ERRgeneral, NT_STATUS_ILL_FORMED_SERVICE_ENTRY}, {
ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_CHARACTER}, {
ERRHRD, ERRgeneral, NT_STATUS_UNMAPPABLE_CHARACTER}, {
ERRHRD, ERRgeneral, NT_STATUS_UNDEFINED_CHARACTER}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_VOLUME}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_WRONG_CYLINDER}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_UNKNOWN_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_BAD_REGISTERS}, {
ERRHRD, ERRgeneral, NT_STATUS_DISK_RECALIBRATE_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_DISK_OPERATION_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_DISK_RESET_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_SHARED_IRQ_BUSY}, {
ERRHRD, ERRgeneral, NT_STATUS_FT_ORPHANING}, {
ERRHRD, ERRgeneral, 0xc000016e}, {
ERRHRD, ERRgeneral, 0xc000016f}, {
ERRHRD, ERRgeneral, 0xc0000170}, {
ERRHRD, ERRgeneral, 0xc0000171}, {
ERRHRD, ERRgeneral, NT_STATUS_PARTITION_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_BLOCK_LENGTH}, {
ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_PARTITIONED}, {
ERRHRD, ERRgeneral, NT_STATUS_UNABLE_TO_LOCK_MEDIA}, {
ERRHRD, ERRgeneral, NT_STATUS_UNABLE_TO_UNLOAD_MEDIA}, {
ERRHRD, ERRgeneral, NT_STATUS_EOM_OVERFLOW}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_MEDIA}, {
ERRHRD, ERRgeneral, 0xc0000179}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_MEMBER}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_MEMBER}, {
ERRHRD, ERRgeneral, NT_STATUS_KEY_DELETED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_LOG_SPACE}, {
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_SIDS}, {
ERRHRD, ERRgeneral, NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED}, {
ERRHRD, ERRgeneral, NT_STATUS_KEY_HAS_CHILDREN}, {
ERRHRD, ERRgeneral, NT_STATUS_CHILD_MUST_BE_VOLATILE}, {
ERRDOS, 87, NT_STATUS_DEVICE_CONFIGURATION_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_DRIVER_INTERNAL_ERROR}, {
ERRDOS, 22, NT_STATUS_INVALID_DEVICE_STATE}, {
ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_DEVICE_PROTOCOL_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_BACKUP_CONTROLLER}, {
ERRHRD, ERRgeneral, NT_STATUS_LOG_FILE_FULL}, {
ERRDOS, 19, NT_STATUS_TOO_LATE}, {
ERRDOS, ERRnoaccess, NT_STATUS_NO_TRUST_LSA_SECRET},
/* { This NT error code was 'sqashed'
from NT_STATUS_NO_TRUST_SAM_ACCOUNT to NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE
during the session setup } */
{
ERRDOS, ERRnoaccess, NT_STATUS_NO_TRUST_SAM_ACCOUNT}, {
ERRDOS, ERRnoaccess, NT_STATUS_TRUSTED_DOMAIN_FAILURE}, {
ERRDOS, ERRnoaccess, NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_FILE_CORRUPT}, {
ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_CANT_START}, {
ERRDOS, ERRnoaccess, NT_STATUS_TRUST_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_MUTANT_LIMIT_EXCEEDED}, {
ERRDOS, 2455, NT_STATUS_NETLOGON_NOT_STARTED}, {
ERRSRV, 2239, NT_STATUS_ACCOUNT_EXPIRED}, {
ERRHRD, ERRgeneral, NT_STATUS_POSSIBLE_DEADLOCK}, {
ERRHRD, ERRgeneral, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT}, {
ERRHRD, ERRgeneral, NT_STATUS_REMOTE_SESSION_LIMIT}, {
ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_FILE_CHANGED}, {
ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT}, {
ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT}, {
ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
/* { This NT error code was 'sqashed'
from NT_STATUS_DOMAIN_TRUST_INCONSISTENT to NT_STATUS_LOGON_FAILURE
during the session setup } */
{
ERRDOS, ERRnoaccess, NT_STATUS_DOMAIN_TRUST_INCONSISTENT}, {
ERRHRD, ERRgeneral, NT_STATUS_FS_DRIVER_REQUIRED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, {
ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, {
ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, {
ERRDOS, ERRnomem, NT_STATUS_INSUFF_SERVER_RESOURCES}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, {
ERRDOS, 68, NT_STATUS_TOO_MANY_ADDRESSES}, {
ERRDOS, 52, NT_STATUS_ADDRESS_ALREADY_EXISTS}, {
ERRDOS, 64, NT_STATUS_ADDRESS_CLOSED}, {
ERRDOS, 64, NT_STATUS_CONNECTION_DISCONNECTED}, {
ERRDOS, 64, NT_STATUS_CONNECTION_RESET}, {
ERRDOS, 68, NT_STATUS_TOO_MANY_NODES}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_ABORTED}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_TIMED_OUT}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_NO_RELEASE}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_NO_MATCH}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_RESPONDED}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_INVALID_ID}, {
ERRDOS, 59, NT_STATUS_TRANSACTION_INVALID_TYPE}, {
ERRDOS, ERRunsup, NT_STATUS_NOT_SERVER_SESSION}, {
ERRDOS, ERRunsup, NT_STATUS_NOT_CLIENT_SESSION}, {
ERRHRD, ERRgeneral, NT_STATUS_CANNOT_LOAD_REGISTRY_FILE}, {
ERRHRD, ERRgeneral, NT_STATUS_DEBUG_ATTACH_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_SYSTEM_PROCESS_TERMINATED}, {
ERRHRD, ERRgeneral, NT_STATUS_DATA_NOT_ACCEPTED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_BROWSER_SERVERS_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_VDM_HARD_ERROR}, {
ERRHRD, ERRgeneral, NT_STATUS_DRIVER_CANCEL_TIMEOUT}, {
ERRHRD, ERRgeneral, NT_STATUS_REPLY_MESSAGE_MISMATCH}, {
ERRHRD, ERRgeneral, NT_STATUS_MAPPED_ALIGNMENT}, {
ERRDOS, 193, NT_STATUS_IMAGE_CHECKSUM_MISMATCH}, {
ERRHRD, ERRgeneral, NT_STATUS_LOST_WRITEBEHIND_DATA}, {
ERRHRD, ERRgeneral, NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID}, {
ERRSRV, 2242, NT_STATUS_PASSWORD_MUST_CHANGE}, {
ERRHRD, ERRgeneral, NT_STATUS_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_NOT_TINY_STREAM}, {
ERRHRD, ERRgeneral, NT_STATUS_RECOVERY_FAILURE}, {
ERRHRD, ERRgeneral, NT_STATUS_STACK_OVERFLOW_READ}, {
ERRHRD, ERRgeneral, NT_STATUS_FAIL_CHECK}, {
ERRHRD, ERRgeneral, NT_STATUS_DUPLICATE_OBJECTID}, {
ERRHRD, ERRgeneral, NT_STATUS_OBJECTID_EXISTS}, {
ERRHRD, ERRgeneral, NT_STATUS_CONVERT_TO_LARGE}, {
ERRHRD, ERRgeneral, NT_STATUS_RETRY}, {
ERRHRD, ERRgeneral, NT_STATUS_FOUND_OUT_OF_SCOPE}, {
ERRHRD, ERRgeneral, NT_STATUS_ALLOCATE_BUCKET}, {
ERRHRD, ERRgeneral, NT_STATUS_PROPSET_NOT_FOUND}, {
ERRHRD, ERRgeneral, NT_STATUS_MARSHALL_OVERFLOW}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_VARIANT}, {
ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND}, {
ERRDOS, ERRnoaccess, NT_STATUS_ACCOUNT_LOCKED_OUT}, {
ERRDOS, ERRbadfid, NT_STATUS_HANDLE_NOT_CLOSABLE}, {
ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_REFUSED}, {
ERRHRD, ERRgeneral, NT_STATUS_GRACEFUL_DISCONNECT}, {
ERRHRD, ERRgeneral, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED}, {
ERRHRD, ERRgeneral, NT_STATUS_ADDRESS_NOT_ASSOCIATED}, {
ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_INVALID}, {
ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ACTIVE}, {
ERRHRD, ERRgeneral, NT_STATUS_NETWORK_UNREACHABLE}, {
ERRHRD, ERRgeneral, NT_STATUS_HOST_UNREACHABLE}, {
ERRHRD, ERRgeneral, NT_STATUS_PROTOCOL_UNREACHABLE}, {
ERRHRD, ERRgeneral, NT_STATUS_PORT_UNREACHABLE}, {
ERRHRD, ERRgeneral, NT_STATUS_REQUEST_ABORTED}, {
ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ABORTED}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_COMPRESSION_BUFFER}, {
ERRHRD, ERRgeneral, NT_STATUS_USER_MAPPED_FILE}, {
ERRHRD, ERRgeneral, NT_STATUS_AUDIT_FAILED}, {
ERRHRD, ERRgeneral, NT_STATUS_TIMER_RESOLUTION_NOT_SET}, {
ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_COUNT_LIMIT}, {
ERRHRD, ERRgeneral, NT_STATUS_LOGIN_TIME_RESTRICTION}, {
ERRHRD, ERRgeneral, NT_STATUS_LOGIN_WKSTA_RESTRICTION}, {
ERRDOS, 193, NT_STATUS_IMAGE_MP_UP_MISMATCH}, {
ERRHRD, ERRgeneral, 0xc000024a}, {
ERRHRD, ERRgeneral, 0xc000024b}, {
ERRHRD, ERRgeneral, 0xc000024c}, {
ERRHRD, ERRgeneral, 0xc000024d}, {
ERRHRD, ERRgeneral, 0xc000024e}, {
ERRHRD, ERRgeneral, 0xc000024f}, {
ERRHRD, ERRgeneral, NT_STATUS_INSUFFICIENT_LOGON_INFO}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_DLL_ENTRYPOINT}, {
ERRHRD, ERRgeneral, NT_STATUS_BAD_SERVICE_ENTRYPOINT}, {
ERRHRD, ERRgeneral, NT_STATUS_LPC_REPLY_LOST}, {
ERRHRD, ERRgeneral, NT_STATUS_IP_ADDRESS_CONFLICT1}, {
ERRHRD, ERRgeneral, NT_STATUS_IP_ADDRESS_CONFLICT2}, {
ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_QUOTA_LIMIT}, {
ERRSRV, 3, NT_STATUS_PATH_NOT_COVERED}, {
ERRHRD, ERRgeneral, NT_STATUS_NO_CALLBACK_ACTIVE}, {
ERRHRD, ERRgeneral, NT_STATUS_LICENSE_QUOTA_EXCEEDED}, {
ERRHRD, ERRgeneral, NT_STATUS_PWD_TOO_SHORT}, {
ERRHRD, ERRgeneral, NT_STATUS_PWD_TOO_RECENT}, {
ERRHRD, ERRgeneral, NT_STATUS_PWD_HISTORY_CONFLICT}, {
ERRHRD, ERRgeneral, 0xc000025d}, {
ERRHRD, ERRgeneral, NT_STATUS_PLUGPLAY_NO_DEVICE}, {
ERRHRD, ERRgeneral, NT_STATUS_UNSUPPORTED_COMPRESSION}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_HW_PROFILE}, {
ERRHRD, ERRgeneral, NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH}, {
ERRDOS, 182, NT_STATUS_DRIVER_ORDINAL_NOT_FOUND}, {
ERRDOS, 127, NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND}, {
ERRDOS, 288, NT_STATUS_RESOURCE_NOT_OWNED}, {
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_LINKS}, {
ERRHRD, ERRgeneral, NT_STATUS_QUOTA_LIST_INCONSISTENT}, {
ERRHRD, ERRgeneral, NT_STATUS_FILE_IS_OFFLINE}, {
ERRDOS, 21, 0xc000026e}, {
ERRDOS, 161, 0xc0000281}, {
ERRDOS, ERRnoaccess, 0xc000028a}, {
ERRDOS, ERRnoaccess, 0xc000028b}, {
ERRHRD, ERRgeneral, 0xc000028c}, {
ERRDOS, ERRnoaccess, 0xc000028d}, {
ERRDOS, ERRnoaccess, 0xc000028e}, {
ERRDOS, ERRnoaccess, 0xc000028f}, {
ERRDOS, ERRnoaccess, 0xc0000290}, {
ERRDOS, ERRbadfunc, 0xc000029c},};
void
ntstatus_to_dos(__u32 ntstatus, __u8 * eclass, __u16 * ecode)
{
int i;
if (ntstatus == 0) {
*eclass = 0;
*ecode = 0;
return;
}
for (i = 0; ntstatus_to_dos_map[i].ntstatus; i++) {
if (ntstatus == ntstatus_to_dos_map[i].ntstatus) {
*eclass = ntstatus_to_dos_map[i].dos_class;
*ecode = ntstatus_to_dos_map[i].dos_code;
return;
}
}
*eclass = ERRHRD;
*ecode = ERRgeneral;
}
int
map_smb_to_linux_error(struct smb_hdr *smb)
{
int i;
int rc = -EIO; /* if transport error smb error may not be set */
__u8 smberrclass;
__u16 smberrcode;
/* BB if NT Status codes - map NT BB */
/* old style smb error codes */
if (smb->Status.CifsError == 0)
return 0;
if (smb->Flags2 & SMBFLG2_ERR_STATUS) {
/* translate the newer STATUS codes to old style errors and then to POSIX errors */
cFYI(1,
(" !!Mapping cifs error code %d ", smb->Status.CifsError));
smb->Status.CifsError = le32_to_cpu(smb->Status.CifsError);
ntstatus_to_dos(smb->Status.CifsError, &smberrclass,
&smberrcode);
} else {
smberrclass = smb->Status.DosError.ErrorClass;
smb->Status.DosError.Error =
le16_to_cpu(smb->Status.DosError.Error);
smberrcode = smb->Status.DosError.Error;
}
/* old style errors */
cFYI(1, (" !!Mapping smb error code %d ", smberrcode));
/* DOS class smb error codes - map DOS */
/* BB special case reconnect tid and reconnect uid here? */
if (smberrclass == ERRDOS) { /* one byte field no need to byte reverse */
for (i = 0;
i <
sizeof (mapping_table_ERRDOS) /
sizeof (struct smb_to_posix_error); i++) {
if (mapping_table_ERRDOS[i].smb_err == 0)
break;
else if (mapping_table_ERRDOS[i].smb_err == smberrcode) {
rc = mapping_table_ERRDOS[i].posix_code;
break;
}
/* else try the next error mapping one to see if it will match */
}
} else if (smberrclass == ERRSRV) { /* server class of error codes */
for (i = 0;
i <
sizeof (mapping_table_ERRSRV) /
sizeof (struct smb_to_posix_error); i++) {
if (mapping_table_ERRSRV[i].smb_err == 0)
break;
else if (mapping_table_ERRSRV[i].smb_err == smberrcode) {
rc = mapping_table_ERRSRV[i].posix_code;
break;
}
/* else try the next error mapping one to see if it will match */
}
}
/* else ERRHRD class errors or junk - return EIO */
/* BB get smb->error_class and code lookup in table if ERR_STATUS is not
set in this frame else translate newer NT Status code - in both cases
change to equivalent posix error BB */
cFYI(1, (" to POSIX err %d !!", rc));
/* generic corrective action e.g. reconnect SMB session on ERRbaduid could be added */
return rc;
}
/*
* calculate the size of the SMB message based on the fixed header
* portion, the number of word parameters and the data portion of the message
*/
int
smbCalcSize(struct smb_hdr *ptr)
{
return (sizeof (struct smb_hdr) + (int) (2 * ptr->WordCount) +
BCC(ptr));
}
/* The following are taken from fs/ntfs/util.c */
#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
/*
* Convert the NT UTC (based 1601-01-01, in hundred nanosecond units)
* into Unix UTC (based 1970-01-01, in seconds).
*/
time_t
cifs_NTtimeToUnix(u64 ntutc)
{
/* BB what about the timezone? BB */
/* Subtract the NTFS time offset, then convert to 1s intervals. */
u64 t;
t = ntutc - NTFS_TIME_OFFSET;
do_div(t, 10000000);
return (time_t) t;
}
/* Convert the Unix UTC into NT UTC. */
u64
cifs_UnixTimeToNT(time_t t)
{
/* Convert to 100ns intervals and then add the NTFS time offset. */
return (u64) t *10000000 + NTFS_TIME_OFFSET;
}
/*
* Unix SMB/Netbios implementation.
* Version 1.9.
* RPC Pipe client / server routines
* Copyright (C) Luke Kenneth Casson Leighton 1997-2001.
*
* 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.
*/
/* NT error codes - see nterr.h */
#include "nterr.h"
#include <linux/types.h>
#include <linux/fs.h>
struct nt_err_code_struct {
char *nt_errstr;
__u32 nt_errcode;
};
const struct nt_err_code_struct nt_errs[] = {
{"NT_STATUS_OK", NT_STATUS_OK},
{"NT_STATUS_UNSUCCESSFUL", NT_STATUS_UNSUCCESSFUL},
{"NT_STATUS_NOT_IMPLEMENTED", NT_STATUS_NOT_IMPLEMENTED},
{"NT_STATUS_INVALID_INFO_CLASS", NT_STATUS_INVALID_INFO_CLASS},
{"NT_STATUS_INFO_LENGTH_MISMATCH", NT_STATUS_INFO_LENGTH_MISMATCH},
{"NT_STATUS_ACCESS_VIOLATION", NT_STATUS_ACCESS_VIOLATION},
{"STATUS_BUFFER_OVERFLOW", STATUS_BUFFER_OVERFLOW},
{"NT_STATUS_IN_PAGE_ERROR", NT_STATUS_IN_PAGE_ERROR},
{"NT_STATUS_PAGEFILE_QUOTA", NT_STATUS_PAGEFILE_QUOTA},
{"NT_STATUS_INVALID_HANDLE", NT_STATUS_INVALID_HANDLE},
{"NT_STATUS_BAD_INITIAL_STACK", NT_STATUS_BAD_INITIAL_STACK},
{"NT_STATUS_BAD_INITIAL_PC", NT_STATUS_BAD_INITIAL_PC},
{"NT_STATUS_INVALID_CID", NT_STATUS_INVALID_CID},
{"NT_STATUS_TIMER_NOT_CANCELED", NT_STATUS_TIMER_NOT_CANCELED},
{"NT_STATUS_INVALID_PARAMETER", NT_STATUS_INVALID_PARAMETER},
{"NT_STATUS_NO_SUCH_DEVICE", NT_STATUS_NO_SUCH_DEVICE},
{"NT_STATUS_NO_SUCH_FILE", NT_STATUS_NO_SUCH_FILE},
{"NT_STATUS_INVALID_DEVICE_REQUEST",
NT_STATUS_INVALID_DEVICE_REQUEST},
{"NT_STATUS_END_OF_FILE", NT_STATUS_END_OF_FILE},
{"NT_STATUS_WRONG_VOLUME", NT_STATUS_WRONG_VOLUME},
{"NT_STATUS_NO_MEDIA_IN_DEVICE", NT_STATUS_NO_MEDIA_IN_DEVICE},
{"NT_STATUS_UNRECOGNIZED_MEDIA", NT_STATUS_UNRECOGNIZED_MEDIA},
{"NT_STATUS_NONEXISTENT_SECTOR", NT_STATUS_NONEXISTENT_SECTOR},
{"NT_STATUS_MORE_PROCESSING_REQUIRED",
NT_STATUS_MORE_PROCESSING_REQUIRED},
{"NT_STATUS_NO_MEMORY", NT_STATUS_NO_MEMORY},
{"NT_STATUS_CONFLICTING_ADDRESSES",
NT_STATUS_CONFLICTING_ADDRESSES},
{"NT_STATUS_NOT_MAPPED_VIEW", NT_STATUS_NOT_MAPPED_VIEW},
{"NT_STATUS_UNABLE_TO_FREE_VM", NT_STATUS_UNABLE_TO_FREE_VM},
{"NT_STATUS_UNABLE_TO_DELETE_SECTION",
NT_STATUS_UNABLE_TO_DELETE_SECTION},
{"NT_STATUS_INVALID_SYSTEM_SERVICE",
NT_STATUS_INVALID_SYSTEM_SERVICE},
{"NT_STATUS_ILLEGAL_INSTRUCTION", NT_STATUS_ILLEGAL_INSTRUCTION},
{"NT_STATUS_INVALID_LOCK_SEQUENCE",
NT_STATUS_INVALID_LOCK_SEQUENCE},
{"NT_STATUS_INVALID_VIEW_SIZE", NT_STATUS_INVALID_VIEW_SIZE},
{"NT_STATUS_INVALID_FILE_FOR_SECTION",
NT_STATUS_INVALID_FILE_FOR_SECTION},
{"NT_STATUS_ALREADY_COMMITTED", NT_STATUS_ALREADY_COMMITTED},
{"NT_STATUS_ACCESS_DENIED", NT_STATUS_ACCESS_DENIED},
{"NT_STATUS_BUFFER_TOO_SMALL", NT_STATUS_BUFFER_TOO_SMALL},
{"NT_STATUS_OBJECT_TYPE_MISMATCH", NT_STATUS_OBJECT_TYPE_MISMATCH},
{"NT_STATUS_NONCONTINUABLE_EXCEPTION",
NT_STATUS_NONCONTINUABLE_EXCEPTION},
{"NT_STATUS_INVALID_DISPOSITION", NT_STATUS_INVALID_DISPOSITION},
{"NT_STATUS_UNWIND", NT_STATUS_UNWIND},
{"NT_STATUS_BAD_STACK", NT_STATUS_BAD_STACK},
{"NT_STATUS_INVALID_UNWIND_TARGET",
NT_STATUS_INVALID_UNWIND_TARGET},
{"NT_STATUS_NOT_LOCKED", NT_STATUS_NOT_LOCKED},
{"NT_STATUS_PARITY_ERROR", NT_STATUS_PARITY_ERROR},
{"NT_STATUS_UNABLE_TO_DECOMMIT_VM",
NT_STATUS_UNABLE_TO_DECOMMIT_VM},
{"NT_STATUS_NOT_COMMITTED", NT_STATUS_NOT_COMMITTED},
{"NT_STATUS_INVALID_PORT_ATTRIBUTES",
NT_STATUS_INVALID_PORT_ATTRIBUTES},
{"NT_STATUS_PORT_MESSAGE_TOO_LONG",
NT_STATUS_PORT_MESSAGE_TOO_LONG},
{"NT_STATUS_INVALID_PARAMETER_MIX",
NT_STATUS_INVALID_PARAMETER_MIX},
{"NT_STATUS_INVALID_QUOTA_LOWER", NT_STATUS_INVALID_QUOTA_LOWER},
{"NT_STATUS_DISK_CORRUPT_ERROR", NT_STATUS_DISK_CORRUPT_ERROR},
{"NT_STATUS_OBJECT_NAME_INVALID", NT_STATUS_OBJECT_NAME_INVALID},
{"NT_STATUS_OBJECT_NAME_NOT_FOUND",
NT_STATUS_OBJECT_NAME_NOT_FOUND},
{"NT_STATUS_OBJECT_NAME_COLLISION",
NT_STATUS_OBJECT_NAME_COLLISION},
{"NT_STATUS_HANDLE_NOT_WAITABLE", NT_STATUS_HANDLE_NOT_WAITABLE},
{"NT_STATUS_PORT_DISCONNECTED", NT_STATUS_PORT_DISCONNECTED},
{"NT_STATUS_DEVICE_ALREADY_ATTACHED",
NT_STATUS_DEVICE_ALREADY_ATTACHED},
{"NT_STATUS_OBJECT_PATH_INVALID", NT_STATUS_OBJECT_PATH_INVALID},
{"NT_STATUS_OBJECT_PATH_NOT_FOUND",
NT_STATUS_OBJECT_PATH_NOT_FOUND},
{"NT_STATUS_OBJECT_PATH_SYNTAX_BAD",
NT_STATUS_OBJECT_PATH_SYNTAX_BAD},
{"NT_STATUS_DATA_OVERRUN", NT_STATUS_DATA_OVERRUN},
{"NT_STATUS_DATA_LATE_ERROR", NT_STATUS_DATA_LATE_ERROR},
{"NT_STATUS_DATA_ERROR", NT_STATUS_DATA_ERROR},
{"NT_STATUS_CRC_ERROR", NT_STATUS_CRC_ERROR},
{"NT_STATUS_SECTION_TOO_BIG", NT_STATUS_SECTION_TOO_BIG},
{"NT_STATUS_PORT_CONNECTION_REFUSED",
NT_STATUS_PORT_CONNECTION_REFUSED},
{"NT_STATUS_INVALID_PORT_HANDLE", NT_STATUS_INVALID_PORT_HANDLE},
{"NT_STATUS_SHARING_VIOLATION", NT_STATUS_SHARING_VIOLATION},
{"NT_STATUS_QUOTA_EXCEEDED", NT_STATUS_QUOTA_EXCEEDED},
{"NT_STATUS_INVALID_PAGE_PROTECTION",
NT_STATUS_INVALID_PAGE_PROTECTION},
{"NT_STATUS_MUTANT_NOT_OWNED", NT_STATUS_MUTANT_NOT_OWNED},
{"NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED",
NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED},
{"NT_STATUS_PORT_ALREADY_SET", NT_STATUS_PORT_ALREADY_SET},
{"NT_STATUS_SECTION_NOT_IMAGE", NT_STATUS_SECTION_NOT_IMAGE},
{"NT_STATUS_SUSPEND_COUNT_EXCEEDED",
NT_STATUS_SUSPEND_COUNT_EXCEEDED},
{"NT_STATUS_THREAD_IS_TERMINATING",
NT_STATUS_THREAD_IS_TERMINATING},
{"NT_STATUS_BAD_WORKING_SET_LIMIT",
NT_STATUS_BAD_WORKING_SET_LIMIT},
{"NT_STATUS_INCOMPATIBLE_FILE_MAP",
NT_STATUS_INCOMPATIBLE_FILE_MAP},
{"NT_STATUS_SECTION_PROTECTION", NT_STATUS_SECTION_PROTECTION},
{"NT_STATUS_EAS_NOT_SUPPORTED", NT_STATUS_EAS_NOT_SUPPORTED},
{"NT_STATUS_EA_TOO_LARGE", NT_STATUS_EA_TOO_LARGE},
{"NT_STATUS_NONEXISTENT_EA_ENTRY", NT_STATUS_NONEXISTENT_EA_ENTRY},
{"NT_STATUS_NO_EAS_ON_FILE", NT_STATUS_NO_EAS_ON_FILE},
{"NT_STATUS_EA_CORRUPT_ERROR", NT_STATUS_EA_CORRUPT_ERROR},
{"NT_STATUS_FILE_LOCK_CONFLICT", NT_STATUS_FILE_LOCK_CONFLICT},
{"NT_STATUS_LOCK_NOT_GRANTED", NT_STATUS_LOCK_NOT_GRANTED},
{"NT_STATUS_DELETE_PENDING", NT_STATUS_DELETE_PENDING},
{"NT_STATUS_CTL_FILE_NOT_SUPPORTED",
NT_STATUS_CTL_FILE_NOT_SUPPORTED},
{"NT_STATUS_UNKNOWN_REVISION", NT_STATUS_UNKNOWN_REVISION},
{"NT_STATUS_REVISION_MISMATCH", NT_STATUS_REVISION_MISMATCH},
{"NT_STATUS_INVALID_OWNER", NT_STATUS_INVALID_OWNER},
{"NT_STATUS_INVALID_PRIMARY_GROUP",
NT_STATUS_INVALID_PRIMARY_GROUP},
{"NT_STATUS_NO_IMPERSONATION_TOKEN",
NT_STATUS_NO_IMPERSONATION_TOKEN},
{"NT_STATUS_CANT_DISABLE_MANDATORY",
NT_STATUS_CANT_DISABLE_MANDATORY},
{"NT_STATUS_NO_LOGON_SERVERS", NT_STATUS_NO_LOGON_SERVERS},
{"NT_STATUS_NO_SUCH_LOGON_SESSION",
NT_STATUS_NO_SUCH_LOGON_SESSION},
{"NT_STATUS_NO_SUCH_PRIVILEGE", NT_STATUS_NO_SUCH_PRIVILEGE},
{"NT_STATUS_PRIVILEGE_NOT_HELD", NT_STATUS_PRIVILEGE_NOT_HELD},
{"NT_STATUS_INVALID_ACCOUNT_NAME", NT_STATUS_INVALID_ACCOUNT_NAME},
{"NT_STATUS_USER_EXISTS", NT_STATUS_USER_EXISTS},
{"NT_STATUS_NO_SUCH_USER", NT_STATUS_NO_SUCH_USER},
{"NT_STATUS_GROUP_EXISTS", NT_STATUS_GROUP_EXISTS},
{"NT_STATUS_NO_SUCH_GROUP", NT_STATUS_NO_SUCH_GROUP},
{"NT_STATUS_MEMBER_IN_GROUP", NT_STATUS_MEMBER_IN_GROUP},
{"NT_STATUS_MEMBER_NOT_IN_GROUP", NT_STATUS_MEMBER_NOT_IN_GROUP},
{"NT_STATUS_LAST_ADMIN", NT_STATUS_LAST_ADMIN},
{"NT_STATUS_WRONG_PASSWORD", NT_STATUS_WRONG_PASSWORD},
{"NT_STATUS_ILL_FORMED_PASSWORD", NT_STATUS_ILL_FORMED_PASSWORD},
{"NT_STATUS_PASSWORD_RESTRICTION", NT_STATUS_PASSWORD_RESTRICTION},
{"NT_STATUS_LOGON_FAILURE", NT_STATUS_LOGON_FAILURE},
{"NT_STATUS_ACCOUNT_RESTRICTION", NT_STATUS_ACCOUNT_RESTRICTION},
{"NT_STATUS_INVALID_LOGON_HOURS", NT_STATUS_INVALID_LOGON_HOURS},
{"NT_STATUS_INVALID_WORKSTATION", NT_STATUS_INVALID_WORKSTATION},
{"NT_STATUS_PASSWORD_EXPIRED", NT_STATUS_PASSWORD_EXPIRED},
{"NT_STATUS_ACCOUNT_DISABLED", NT_STATUS_ACCOUNT_DISABLED},
{"NT_STATUS_NONE_MAPPED", NT_STATUS_NONE_MAPPED},
{"NT_STATUS_TOO_MANY_LUIDS_REQUESTED",
NT_STATUS_TOO_MANY_LUIDS_REQUESTED},
{"NT_STATUS_LUIDS_EXHAUSTED", NT_STATUS_LUIDS_EXHAUSTED},
{"NT_STATUS_INVALID_SUB_AUTHORITY",
NT_STATUS_INVALID_SUB_AUTHORITY},
{"NT_STATUS_INVALID_ACL", NT_STATUS_INVALID_ACL},
{"NT_STATUS_INVALID_SID", NT_STATUS_INVALID_SID},
{"NT_STATUS_INVALID_SECURITY_DESCR",
NT_STATUS_INVALID_SECURITY_DESCR},
{"NT_STATUS_PROCEDURE_NOT_FOUND", NT_STATUS_PROCEDURE_NOT_FOUND},
{"NT_STATUS_INVALID_IMAGE_FORMAT", NT_STATUS_INVALID_IMAGE_FORMAT},
{"NT_STATUS_NO_TOKEN", NT_STATUS_NO_TOKEN},
{"NT_STATUS_BAD_INHERITANCE_ACL", NT_STATUS_BAD_INHERITANCE_ACL},
{"NT_STATUS_RANGE_NOT_LOCKED", NT_STATUS_RANGE_NOT_LOCKED},
{"NT_STATUS_DISK_FULL", NT_STATUS_DISK_FULL},
{"NT_STATUS_SERVER_DISABLED", NT_STATUS_SERVER_DISABLED},
{"NT_STATUS_SERVER_NOT_DISABLED", NT_STATUS_SERVER_NOT_DISABLED},
{"NT_STATUS_TOO_MANY_GUIDS_REQUESTED",
NT_STATUS_TOO_MANY_GUIDS_REQUESTED},
{"NT_STATUS_GUIDS_EXHAUSTED", NT_STATUS_GUIDS_EXHAUSTED},
{"NT_STATUS_INVALID_ID_AUTHORITY", NT_STATUS_INVALID_ID_AUTHORITY},
{"NT_STATUS_AGENTS_EXHAUSTED", NT_STATUS_AGENTS_EXHAUSTED},
{"NT_STATUS_INVALID_VOLUME_LABEL", NT_STATUS_INVALID_VOLUME_LABEL},
{"NT_STATUS_SECTION_NOT_EXTENDED", NT_STATUS_SECTION_NOT_EXTENDED},
{"NT_STATUS_NOT_MAPPED_DATA", NT_STATUS_NOT_MAPPED_DATA},
{"NT_STATUS_RESOURCE_DATA_NOT_FOUND",
NT_STATUS_RESOURCE_DATA_NOT_FOUND},
{"NT_STATUS_RESOURCE_TYPE_NOT_FOUND",
NT_STATUS_RESOURCE_TYPE_NOT_FOUND},
{"NT_STATUS_RESOURCE_NAME_NOT_FOUND",
NT_STATUS_RESOURCE_NAME_NOT_FOUND},
{"NT_STATUS_ARRAY_BOUNDS_EXCEEDED",
NT_STATUS_ARRAY_BOUNDS_EXCEEDED},
{"NT_STATUS_FLOAT_DENORMAL_OPERAND",
NT_STATUS_FLOAT_DENORMAL_OPERAND},
{"NT_STATUS_FLOAT_DIVIDE_BY_ZERO", NT_STATUS_FLOAT_DIVIDE_BY_ZERO},
{"NT_STATUS_FLOAT_INEXACT_RESULT", NT_STATUS_FLOAT_INEXACT_RESULT},
{"NT_STATUS_FLOAT_INVALID_OPERATION",
NT_STATUS_FLOAT_INVALID_OPERATION},
{"NT_STATUS_FLOAT_OVERFLOW", NT_STATUS_FLOAT_OVERFLOW},
{"NT_STATUS_FLOAT_STACK_CHECK", NT_STATUS_FLOAT_STACK_CHECK},
{"NT_STATUS_FLOAT_UNDERFLOW", NT_STATUS_FLOAT_UNDERFLOW},
{"NT_STATUS_INTEGER_DIVIDE_BY_ZERO",
NT_STATUS_INTEGER_DIVIDE_BY_ZERO},
{"NT_STATUS_INTEGER_OVERFLOW", NT_STATUS_INTEGER_OVERFLOW},
{"NT_STATUS_PRIVILEGED_INSTRUCTION",
NT_STATUS_PRIVILEGED_INSTRUCTION},
{"NT_STATUS_TOO_MANY_PAGING_FILES",
NT_STATUS_TOO_MANY_PAGING_FILES},
{"NT_STATUS_FILE_INVALID", NT_STATUS_FILE_INVALID},
{"NT_STATUS_ALLOTTED_SPACE_EXCEEDED",
NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
{"NT_STATUS_INSUFFICIENT_RESOURCES",
NT_STATUS_INSUFFICIENT_RESOURCES},
{"NT_STATUS_DFS_EXIT_PATH_FOUND", NT_STATUS_DFS_EXIT_PATH_FOUND},
{"NT_STATUS_DEVICE_DATA_ERROR", NT_STATUS_DEVICE_DATA_ERROR},
{"NT_STATUS_DEVICE_NOT_CONNECTED", NT_STATUS_DEVICE_NOT_CONNECTED},
{"NT_STATUS_DEVICE_POWER_FAILURE", NT_STATUS_DEVICE_POWER_FAILURE},
{"NT_STATUS_FREE_VM_NOT_AT_BASE", NT_STATUS_FREE_VM_NOT_AT_BASE},
{"NT_STATUS_MEMORY_NOT_ALLOCATED", NT_STATUS_MEMORY_NOT_ALLOCATED},
{"NT_STATUS_WORKING_SET_QUOTA", NT_STATUS_WORKING_SET_QUOTA},
{"NT_STATUS_MEDIA_WRITE_PROTECTED",
NT_STATUS_MEDIA_WRITE_PROTECTED},
{"NT_STATUS_DEVICE_NOT_READY", NT_STATUS_DEVICE_NOT_READY},
{"NT_STATUS_INVALID_GROUP_ATTRIBUTES",
NT_STATUS_INVALID_GROUP_ATTRIBUTES},
{"NT_STATUS_BAD_IMPERSONATION_LEVEL",
NT_STATUS_BAD_IMPERSONATION_LEVEL},
{"NT_STATUS_CANT_OPEN_ANONYMOUS", NT_STATUS_CANT_OPEN_ANONYMOUS},
{"NT_STATUS_BAD_VALIDATION_CLASS", NT_STATUS_BAD_VALIDATION_CLASS},
{"NT_STATUS_BAD_TOKEN_TYPE", NT_STATUS_BAD_TOKEN_TYPE},
{"NT_STATUS_BAD_MASTER_BOOT_RECORD",
NT_STATUS_BAD_MASTER_BOOT_RECORD},
{"NT_STATUS_INSTRUCTION_MISALIGNMENT",
NT_STATUS_INSTRUCTION_MISALIGNMENT},
{"NT_STATUS_INSTANCE_NOT_AVAILABLE",
NT_STATUS_INSTANCE_NOT_AVAILABLE},
{"NT_STATUS_PIPE_NOT_AVAILABLE", NT_STATUS_PIPE_NOT_AVAILABLE},
{"NT_STATUS_INVALID_PIPE_STATE", NT_STATUS_INVALID_PIPE_STATE},
{"NT_STATUS_PIPE_BUSY", NT_STATUS_PIPE_BUSY},
{"NT_STATUS_ILLEGAL_FUNCTION", NT_STATUS_ILLEGAL_FUNCTION},
{"NT_STATUS_PIPE_DISCONNECTED", NT_STATUS_PIPE_DISCONNECTED},
{"NT_STATUS_PIPE_CLOSING", NT_STATUS_PIPE_CLOSING},
{"NT_STATUS_PIPE_CONNECTED", NT_STATUS_PIPE_CONNECTED},
{"NT_STATUS_PIPE_LISTENING", NT_STATUS_PIPE_LISTENING},
{"NT_STATUS_INVALID_READ_MODE", NT_STATUS_INVALID_READ_MODE},
{"NT_STATUS_IO_TIMEOUT", NT_STATUS_IO_TIMEOUT},
{"NT_STATUS_FILE_FORCED_CLOSED", NT_STATUS_FILE_FORCED_CLOSED},
{"NT_STATUS_PROFILING_NOT_STARTED",
NT_STATUS_PROFILING_NOT_STARTED},
{"NT_STATUS_PROFILING_NOT_STOPPED",
NT_STATUS_PROFILING_NOT_STOPPED},
{"NT_STATUS_COULD_NOT_INTERPRET", NT_STATUS_COULD_NOT_INTERPRET},
{"NT_STATUS_FILE_IS_A_DIRECTORY", NT_STATUS_FILE_IS_A_DIRECTORY},
{"NT_STATUS_NOT_SUPPORTED", NT_STATUS_NOT_SUPPORTED},
{"NT_STATUS_REMOTE_NOT_LISTENING", NT_STATUS_REMOTE_NOT_LISTENING},
{"NT_STATUS_DUPLICATE_NAME", NT_STATUS_DUPLICATE_NAME},
{"NT_STATUS_BAD_NETWORK_PATH", NT_STATUS_BAD_NETWORK_PATH},
{"NT_STATUS_NETWORK_BUSY", NT_STATUS_NETWORK_BUSY},
{"NT_STATUS_DEVICE_DOES_NOT_EXIST",
NT_STATUS_DEVICE_DOES_NOT_EXIST},
{"NT_STATUS_TOO_MANY_COMMANDS", NT_STATUS_TOO_MANY_COMMANDS},
{"NT_STATUS_ADAPTER_HARDWARE_ERROR",
NT_STATUS_ADAPTER_HARDWARE_ERROR},
{"NT_STATUS_INVALID_NETWORK_RESPONSE",
NT_STATUS_INVALID_NETWORK_RESPONSE},
{"NT_STATUS_UNEXPECTED_NETWORK_ERROR",
NT_STATUS_UNEXPECTED_NETWORK_ERROR},
{"NT_STATUS_BAD_REMOTE_ADAPTER", NT_STATUS_BAD_REMOTE_ADAPTER},
{"NT_STATUS_PRINT_QUEUE_FULL", NT_STATUS_PRINT_QUEUE_FULL},
{"NT_STATUS_NO_SPOOL_SPACE", NT_STATUS_NO_SPOOL_SPACE},
{"NT_STATUS_PRINT_CANCELLED", NT_STATUS_PRINT_CANCELLED},
{"NT_STATUS_NETWORK_NAME_DELETED", NT_STATUS_NETWORK_NAME_DELETED},
{"NT_STATUS_NETWORK_ACCESS_DENIED",
NT_STATUS_NETWORK_ACCESS_DENIED},
{"NT_STATUS_BAD_DEVICE_TYPE", NT_STATUS_BAD_DEVICE_TYPE},
{"NT_STATUS_BAD_NETWORK_NAME", NT_STATUS_BAD_NETWORK_NAME},
{"NT_STATUS_TOO_MANY_NAMES", NT_STATUS_TOO_MANY_NAMES},
{"NT_STATUS_TOO_MANY_SESSIONS", NT_STATUS_TOO_MANY_SESSIONS},
{"NT_STATUS_SHARING_PAUSED", NT_STATUS_SHARING_PAUSED},
{"NT_STATUS_REQUEST_NOT_ACCEPTED", NT_STATUS_REQUEST_NOT_ACCEPTED},
{"NT_STATUS_REDIRECTOR_PAUSED", NT_STATUS_REDIRECTOR_PAUSED},
{"NT_STATUS_NET_WRITE_FAULT", NT_STATUS_NET_WRITE_FAULT},
{"NT_STATUS_PROFILING_AT_LIMIT", NT_STATUS_PROFILING_AT_LIMIT},
{"NT_STATUS_NOT_SAME_DEVICE", NT_STATUS_NOT_SAME_DEVICE},
{"NT_STATUS_FILE_RENAMED", NT_STATUS_FILE_RENAMED},
{"NT_STATUS_VIRTUAL_CIRCUIT_CLOSED",
NT_STATUS_VIRTUAL_CIRCUIT_CLOSED},
{"NT_STATUS_NO_SECURITY_ON_OBJECT",
NT_STATUS_NO_SECURITY_ON_OBJECT},
{"NT_STATUS_CANT_WAIT", NT_STATUS_CANT_WAIT},
{"NT_STATUS_PIPE_EMPTY", NT_STATUS_PIPE_EMPTY},
{"NT_STATUS_CANT_ACCESS_DOMAIN_INFO",
NT_STATUS_CANT_ACCESS_DOMAIN_INFO},
{"NT_STATUS_CANT_TERMINATE_SELF", NT_STATUS_CANT_TERMINATE_SELF},
{"NT_STATUS_INVALID_SERVER_STATE", NT_STATUS_INVALID_SERVER_STATE},
{"NT_STATUS_INVALID_DOMAIN_STATE", NT_STATUS_INVALID_DOMAIN_STATE},
{"NT_STATUS_INVALID_DOMAIN_ROLE", NT_STATUS_INVALID_DOMAIN_ROLE},
{"NT_STATUS_NO_SUCH_DOMAIN", NT_STATUS_NO_SUCH_DOMAIN},
{"NT_STATUS_DOMAIN_EXISTS", NT_STATUS_DOMAIN_EXISTS},
{"NT_STATUS_DOMAIN_LIMIT_EXCEEDED",
NT_STATUS_DOMAIN_LIMIT_EXCEEDED},
{"NT_STATUS_OPLOCK_NOT_GRANTED", NT_STATUS_OPLOCK_NOT_GRANTED},
{"NT_STATUS_INVALID_OPLOCK_PROTOCOL",
NT_STATUS_INVALID_OPLOCK_PROTOCOL},
{"NT_STATUS_INTERNAL_DB_CORRUPTION",
NT_STATUS_INTERNAL_DB_CORRUPTION},
{"NT_STATUS_INTERNAL_ERROR", NT_STATUS_INTERNAL_ERROR},
{"NT_STATUS_GENERIC_NOT_MAPPED", NT_STATUS_GENERIC_NOT_MAPPED},
{"NT_STATUS_BAD_DESCRIPTOR_FORMAT",
NT_STATUS_BAD_DESCRIPTOR_FORMAT},
{"NT_STATUS_INVALID_USER_BUFFER", NT_STATUS_INVALID_USER_BUFFER},
{"NT_STATUS_UNEXPECTED_IO_ERROR", NT_STATUS_UNEXPECTED_IO_ERROR},
{"NT_STATUS_UNEXPECTED_MM_CREATE_ERR",
NT_STATUS_UNEXPECTED_MM_CREATE_ERR},
{"NT_STATUS_UNEXPECTED_MM_MAP_ERROR",
NT_STATUS_UNEXPECTED_MM_MAP_ERROR},
{"NT_STATUS_UNEXPECTED_MM_EXTEND_ERR",
NT_STATUS_UNEXPECTED_MM_EXTEND_ERR},
{"NT_STATUS_NOT_LOGON_PROCESS", NT_STATUS_NOT_LOGON_PROCESS},
{"NT_STATUS_LOGON_SESSION_EXISTS", NT_STATUS_LOGON_SESSION_EXISTS},
{"NT_STATUS_INVALID_PARAMETER_1", NT_STATUS_INVALID_PARAMETER_1},
{"NT_STATUS_INVALID_PARAMETER_2", NT_STATUS_INVALID_PARAMETER_2},
{"NT_STATUS_INVALID_PARAMETER_3", NT_STATUS_INVALID_PARAMETER_3},
{"NT_STATUS_INVALID_PARAMETER_4", NT_STATUS_INVALID_PARAMETER_4},
{"NT_STATUS_INVALID_PARAMETER_5", NT_STATUS_INVALID_PARAMETER_5},
{"NT_STATUS_INVALID_PARAMETER_6", NT_STATUS_INVALID_PARAMETER_6},
{"NT_STATUS_INVALID_PARAMETER_7", NT_STATUS_INVALID_PARAMETER_7},
{"NT_STATUS_INVALID_PARAMETER_8", NT_STATUS_INVALID_PARAMETER_8},
{"NT_STATUS_INVALID_PARAMETER_9", NT_STATUS_INVALID_PARAMETER_9},
{"NT_STATUS_INVALID_PARAMETER_10", NT_STATUS_INVALID_PARAMETER_10},
{"NT_STATUS_INVALID_PARAMETER_11", NT_STATUS_INVALID_PARAMETER_11},
{"NT_STATUS_INVALID_PARAMETER_12", NT_STATUS_INVALID_PARAMETER_12},
{"NT_STATUS_REDIRECTOR_NOT_STARTED",
NT_STATUS_REDIRECTOR_NOT_STARTED},
{"NT_STATUS_REDIRECTOR_STARTED", NT_STATUS_REDIRECTOR_STARTED},
{"NT_STATUS_STACK_OVERFLOW", NT_STATUS_STACK_OVERFLOW},
{"NT_STATUS_NO_SUCH_PACKAGE", NT_STATUS_NO_SUCH_PACKAGE},
{"NT_STATUS_BAD_FUNCTION_TABLE", NT_STATUS_BAD_FUNCTION_TABLE},
{"NT_STATUS_DIRECTORY_NOT_EMPTY", NT_STATUS_DIRECTORY_NOT_EMPTY},
{"NT_STATUS_FILE_CORRUPT_ERROR", NT_STATUS_FILE_CORRUPT_ERROR},
{"NT_STATUS_NOT_A_DIRECTORY", NT_STATUS_NOT_A_DIRECTORY},
{"NT_STATUS_BAD_LOGON_SESSION_STATE",
NT_STATUS_BAD_LOGON_SESSION_STATE},
{"NT_STATUS_LOGON_SESSION_COLLISION",
NT_STATUS_LOGON_SESSION_COLLISION},
{"NT_STATUS_NAME_TOO_LONG", NT_STATUS_NAME_TOO_LONG},
{"NT_STATUS_FILES_OPEN", NT_STATUS_FILES_OPEN},
{"NT_STATUS_CONNECTION_IN_USE", NT_STATUS_CONNECTION_IN_USE},
{"NT_STATUS_MESSAGE_NOT_FOUND", NT_STATUS_MESSAGE_NOT_FOUND},
{"NT_STATUS_PROCESS_IS_TERMINATING",
NT_STATUS_PROCESS_IS_TERMINATING},
{"NT_STATUS_INVALID_LOGON_TYPE", NT_STATUS_INVALID_LOGON_TYPE},
{"NT_STATUS_NO_GUID_TRANSLATION", NT_STATUS_NO_GUID_TRANSLATION},
{"NT_STATUS_CANNOT_IMPERSONATE", NT_STATUS_CANNOT_IMPERSONATE},
{"NT_STATUS_IMAGE_ALREADY_LOADED", NT_STATUS_IMAGE_ALREADY_LOADED},
{"NT_STATUS_ABIOS_NOT_PRESENT", NT_STATUS_ABIOS_NOT_PRESENT},
{"NT_STATUS_ABIOS_LID_NOT_EXIST", NT_STATUS_ABIOS_LID_NOT_EXIST},
{"NT_STATUS_ABIOS_LID_ALREADY_OWNED",
NT_STATUS_ABIOS_LID_ALREADY_OWNED},
{"NT_STATUS_ABIOS_NOT_LID_OWNER", NT_STATUS_ABIOS_NOT_LID_OWNER},
{"NT_STATUS_ABIOS_INVALID_COMMAND",
NT_STATUS_ABIOS_INVALID_COMMAND},
{"NT_STATUS_ABIOS_INVALID_LID", NT_STATUS_ABIOS_INVALID_LID},
{"NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE",
NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE},
{"NT_STATUS_ABIOS_INVALID_SELECTOR",
NT_STATUS_ABIOS_INVALID_SELECTOR},
{"NT_STATUS_NO_LDT", NT_STATUS_NO_LDT},
{"NT_STATUS_INVALID_LDT_SIZE", NT_STATUS_INVALID_LDT_SIZE},
{"NT_STATUS_INVALID_LDT_OFFSET", NT_STATUS_INVALID_LDT_OFFSET},
{"NT_STATUS_INVALID_LDT_DESCRIPTOR",
NT_STATUS_INVALID_LDT_DESCRIPTOR},
{"NT_STATUS_INVALID_IMAGE_NE_FORMAT",
NT_STATUS_INVALID_IMAGE_NE_FORMAT},
{"NT_STATUS_RXACT_INVALID_STATE", NT_STATUS_RXACT_INVALID_STATE},
{"NT_STATUS_RXACT_COMMIT_FAILURE", NT_STATUS_RXACT_COMMIT_FAILURE},
{"NT_STATUS_MAPPED_FILE_SIZE_ZERO",
NT_STATUS_MAPPED_FILE_SIZE_ZERO},
{"NT_STATUS_TOO_MANY_OPENED_FILES",
NT_STATUS_TOO_MANY_OPENED_FILES},
{"NT_STATUS_CANCELLED", NT_STATUS_CANCELLED},
{"NT_STATUS_CANNOT_DELETE", NT_STATUS_CANNOT_DELETE},
{"NT_STATUS_INVALID_COMPUTER_NAME",
NT_STATUS_INVALID_COMPUTER_NAME},
{"NT_STATUS_FILE_DELETED", NT_STATUS_FILE_DELETED},
{"NT_STATUS_SPECIAL_ACCOUNT", NT_STATUS_SPECIAL_ACCOUNT},
{"NT_STATUS_SPECIAL_GROUP", NT_STATUS_SPECIAL_GROUP},
{"NT_STATUS_SPECIAL_USER", NT_STATUS_SPECIAL_USER},
{"NT_STATUS_MEMBERS_PRIMARY_GROUP",
NT_STATUS_MEMBERS_PRIMARY_GROUP},
{"NT_STATUS_FILE_CLOSED", NT_STATUS_FILE_CLOSED},
{"NT_STATUS_TOO_MANY_THREADS", NT_STATUS_TOO_MANY_THREADS},
{"NT_STATUS_THREAD_NOT_IN_PROCESS",
NT_STATUS_THREAD_NOT_IN_PROCESS},
{"NT_STATUS_TOKEN_ALREADY_IN_USE", NT_STATUS_TOKEN_ALREADY_IN_USE},
{"NT_STATUS_PAGEFILE_QUOTA_EXCEEDED",
NT_STATUS_PAGEFILE_QUOTA_EXCEEDED},
{"NT_STATUS_COMMITMENT_LIMIT", NT_STATUS_COMMITMENT_LIMIT},
{"NT_STATUS_INVALID_IMAGE_LE_FORMAT",
NT_STATUS_INVALID_IMAGE_LE_FORMAT},
{"NT_STATUS_INVALID_IMAGE_NOT_MZ", NT_STATUS_INVALID_IMAGE_NOT_MZ},
{"NT_STATUS_INVALID_IMAGE_PROTECT",
NT_STATUS_INVALID_IMAGE_PROTECT},
{"NT_STATUS_INVALID_IMAGE_WIN_16", NT_STATUS_INVALID_IMAGE_WIN_16},
{"NT_STATUS_LOGON_SERVER_CONFLICT",
NT_STATUS_LOGON_SERVER_CONFLICT},
{"NT_STATUS_TIME_DIFFERENCE_AT_DC",
NT_STATUS_TIME_DIFFERENCE_AT_DC},
{"NT_STATUS_SYNCHRONIZATION_REQUIRED",
NT_STATUS_SYNCHRONIZATION_REQUIRED},
{"NT_STATUS_DLL_NOT_FOUND", NT_STATUS_DLL_NOT_FOUND},
{"NT_STATUS_OPEN_FAILED", NT_STATUS_OPEN_FAILED},
{"NT_STATUS_IO_PRIVILEGE_FAILED", NT_STATUS_IO_PRIVILEGE_FAILED},
{"NT_STATUS_ORDINAL_NOT_FOUND", NT_STATUS_ORDINAL_NOT_FOUND},
{"NT_STATUS_ENTRYPOINT_NOT_FOUND", NT_STATUS_ENTRYPOINT_NOT_FOUND},
{"NT_STATUS_CONTROL_C_EXIT", NT_STATUS_CONTROL_C_EXIT},
{"NT_STATUS_LOCAL_DISCONNECT", NT_STATUS_LOCAL_DISCONNECT},
{"NT_STATUS_REMOTE_DISCONNECT", NT_STATUS_REMOTE_DISCONNECT},
{"NT_STATUS_REMOTE_RESOURCES", NT_STATUS_REMOTE_RESOURCES},
{"NT_STATUS_LINK_FAILED", NT_STATUS_LINK_FAILED},
{"NT_STATUS_LINK_TIMEOUT", NT_STATUS_LINK_TIMEOUT},
{"NT_STATUS_INVALID_CONNECTION", NT_STATUS_INVALID_CONNECTION},
{"NT_STATUS_INVALID_ADDRESS", NT_STATUS_INVALID_ADDRESS},
{"NT_STATUS_DLL_INIT_FAILED", NT_STATUS_DLL_INIT_FAILED},
{"NT_STATUS_MISSING_SYSTEMFILE", NT_STATUS_MISSING_SYSTEMFILE},
{"NT_STATUS_UNHANDLED_EXCEPTION", NT_STATUS_UNHANDLED_EXCEPTION},
{"NT_STATUS_APP_INIT_FAILURE", NT_STATUS_APP_INIT_FAILURE},
{"NT_STATUS_PAGEFILE_CREATE_FAILED",
NT_STATUS_PAGEFILE_CREATE_FAILED},
{"NT_STATUS_NO_PAGEFILE", NT_STATUS_NO_PAGEFILE},
{"NT_STATUS_INVALID_LEVEL", NT_STATUS_INVALID_LEVEL},
{"NT_STATUS_WRONG_PASSWORD_CORE", NT_STATUS_WRONG_PASSWORD_CORE},
{"NT_STATUS_ILLEGAL_FLOAT_CONTEXT",
NT_STATUS_ILLEGAL_FLOAT_CONTEXT},
{"NT_STATUS_PIPE_BROKEN", NT_STATUS_PIPE_BROKEN},
{"NT_STATUS_REGISTRY_CORRUPT", NT_STATUS_REGISTRY_CORRUPT},
{"NT_STATUS_REGISTRY_IO_FAILED", NT_STATUS_REGISTRY_IO_FAILED},
{"NT_STATUS_NO_EVENT_PAIR", NT_STATUS_NO_EVENT_PAIR},
{"NT_STATUS_UNRECOGNIZED_VOLUME", NT_STATUS_UNRECOGNIZED_VOLUME},
{"NT_STATUS_SERIAL_NO_DEVICE_INITED",
NT_STATUS_SERIAL_NO_DEVICE_INITED},
{"NT_STATUS_NO_SUCH_ALIAS", NT_STATUS_NO_SUCH_ALIAS},
{"NT_STATUS_MEMBER_NOT_IN_ALIAS", NT_STATUS_MEMBER_NOT_IN_ALIAS},
{"NT_STATUS_MEMBER_IN_ALIAS", NT_STATUS_MEMBER_IN_ALIAS},
{"NT_STATUS_ALIAS_EXISTS", NT_STATUS_ALIAS_EXISTS},
{"NT_STATUS_LOGON_NOT_GRANTED", NT_STATUS_LOGON_NOT_GRANTED},
{"NT_STATUS_TOO_MANY_SECRETS", NT_STATUS_TOO_MANY_SECRETS},
{"NT_STATUS_SECRET_TOO_LONG", NT_STATUS_SECRET_TOO_LONG},
{"NT_STATUS_INTERNAL_DB_ERROR", NT_STATUS_INTERNAL_DB_ERROR},
{"NT_STATUS_FULLSCREEN_MODE", NT_STATUS_FULLSCREEN_MODE},
{"NT_STATUS_TOO_MANY_CONTEXT_IDS", NT_STATUS_TOO_MANY_CONTEXT_IDS},
{"NT_STATUS_LOGON_TYPE_NOT_GRANTED",
NT_STATUS_LOGON_TYPE_NOT_GRANTED},
{"NT_STATUS_NOT_REGISTRY_FILE", NT_STATUS_NOT_REGISTRY_FILE},
{"NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED",
NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED},
{"NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR",
NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR},
{"NT_STATUS_FT_MISSING_MEMBER", NT_STATUS_FT_MISSING_MEMBER},
{"NT_STATUS_ILL_FORMED_SERVICE_ENTRY",
NT_STATUS_ILL_FORMED_SERVICE_ENTRY},
{"NT_STATUS_ILLEGAL_CHARACTER", NT_STATUS_ILLEGAL_CHARACTER},
{"NT_STATUS_UNMAPPABLE_CHARACTER", NT_STATUS_UNMAPPABLE_CHARACTER},
{"NT_STATUS_UNDEFINED_CHARACTER", NT_STATUS_UNDEFINED_CHARACTER},
{"NT_STATUS_FLOPPY_VOLUME", NT_STATUS_FLOPPY_VOLUME},
{"NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND",
NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND},
{"NT_STATUS_FLOPPY_WRONG_CYLINDER",
NT_STATUS_FLOPPY_WRONG_CYLINDER},
{"NT_STATUS_FLOPPY_UNKNOWN_ERROR", NT_STATUS_FLOPPY_UNKNOWN_ERROR},
{"NT_STATUS_FLOPPY_BAD_REGISTERS", NT_STATUS_FLOPPY_BAD_REGISTERS},
{"NT_STATUS_DISK_RECALIBRATE_FAILED",
NT_STATUS_DISK_RECALIBRATE_FAILED},
{"NT_STATUS_DISK_OPERATION_FAILED",
NT_STATUS_DISK_OPERATION_FAILED},
{"NT_STATUS_DISK_RESET_FAILED", NT_STATUS_DISK_RESET_FAILED},
{"NT_STATUS_SHARED_IRQ_BUSY", NT_STATUS_SHARED_IRQ_BUSY},
{"NT_STATUS_FT_ORPHANING", NT_STATUS_FT_ORPHANING},
{"NT_STATUS_PARTITION_FAILURE", NT_STATUS_PARTITION_FAILURE},
{"NT_STATUS_INVALID_BLOCK_LENGTH", NT_STATUS_INVALID_BLOCK_LENGTH},
{"NT_STATUS_DEVICE_NOT_PARTITIONED",
NT_STATUS_DEVICE_NOT_PARTITIONED},
{"NT_STATUS_UNABLE_TO_LOCK_MEDIA", NT_STATUS_UNABLE_TO_LOCK_MEDIA},
{"NT_STATUS_UNABLE_TO_UNLOAD_MEDIA",
NT_STATUS_UNABLE_TO_UNLOAD_MEDIA},
{"NT_STATUS_EOM_OVERFLOW", NT_STATUS_EOM_OVERFLOW},
{"NT_STATUS_NO_MEDIA", NT_STATUS_NO_MEDIA},
{"NT_STATUS_NO_SUCH_MEMBER", NT_STATUS_NO_SUCH_MEMBER},
{"NT_STATUS_INVALID_MEMBER", NT_STATUS_INVALID_MEMBER},
{"NT_STATUS_KEY_DELETED", NT_STATUS_KEY_DELETED},
{"NT_STATUS_NO_LOG_SPACE", NT_STATUS_NO_LOG_SPACE},
{"NT_STATUS_TOO_MANY_SIDS", NT_STATUS_TOO_MANY_SIDS},
{"NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED",
NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED},
{"NT_STATUS_KEY_HAS_CHILDREN", NT_STATUS_KEY_HAS_CHILDREN},
{"NT_STATUS_CHILD_MUST_BE_VOLATILE",
NT_STATUS_CHILD_MUST_BE_VOLATILE},
{"NT_STATUS_DEVICE_CONFIGURATION_ERROR",
NT_STATUS_DEVICE_CONFIGURATION_ERROR},
{"NT_STATUS_DRIVER_INTERNAL_ERROR",
NT_STATUS_DRIVER_INTERNAL_ERROR},
{"NT_STATUS_INVALID_DEVICE_STATE", NT_STATUS_INVALID_DEVICE_STATE},
{"NT_STATUS_IO_DEVICE_ERROR", NT_STATUS_IO_DEVICE_ERROR},
{"NT_STATUS_DEVICE_PROTOCOL_ERROR",
NT_STATUS_DEVICE_PROTOCOL_ERROR},
{"NT_STATUS_BACKUP_CONTROLLER", NT_STATUS_BACKUP_CONTROLLER},
{"NT_STATUS_LOG_FILE_FULL", NT_STATUS_LOG_FILE_FULL},
{"NT_STATUS_TOO_LATE", NT_STATUS_TOO_LATE},
{"NT_STATUS_NO_TRUST_LSA_SECRET", NT_STATUS_NO_TRUST_LSA_SECRET},
{"NT_STATUS_NO_TRUST_SAM_ACCOUNT", NT_STATUS_NO_TRUST_SAM_ACCOUNT},
{"NT_STATUS_TRUSTED_DOMAIN_FAILURE",
NT_STATUS_TRUSTED_DOMAIN_FAILURE},
{"NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE",
NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE},
{"NT_STATUS_EVENTLOG_FILE_CORRUPT",
NT_STATUS_EVENTLOG_FILE_CORRUPT},
{"NT_STATUS_EVENTLOG_CANT_START", NT_STATUS_EVENTLOG_CANT_START},
{"NT_STATUS_TRUST_FAILURE", NT_STATUS_TRUST_FAILURE},
{"NT_STATUS_MUTANT_LIMIT_EXCEEDED",
NT_STATUS_MUTANT_LIMIT_EXCEEDED},
{"NT_STATUS_NETLOGON_NOT_STARTED", NT_STATUS_NETLOGON_NOT_STARTED},
{"NT_STATUS_ACCOUNT_EXPIRED", NT_STATUS_ACCOUNT_EXPIRED},
{"NT_STATUS_POSSIBLE_DEADLOCK", NT_STATUS_POSSIBLE_DEADLOCK},
{"NT_STATUS_NETWORK_CREDENTIAL_CONFLICT",
NT_STATUS_NETWORK_CREDENTIAL_CONFLICT},
{"NT_STATUS_REMOTE_SESSION_LIMIT", NT_STATUS_REMOTE_SESSION_LIMIT},
{"NT_STATUS_EVENTLOG_FILE_CHANGED",
NT_STATUS_EVENTLOG_FILE_CHANGED},
{"NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT",
NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT},
{"NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT",
NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT},
{"NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT",
NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
{"NT_STATUS_DOMAIN_TRUST_INCONSISTENT",
NT_STATUS_DOMAIN_TRUST_INCONSISTENT},
{"NT_STATUS_FS_DRIVER_REQUIRED", NT_STATUS_FS_DRIVER_REQUIRED},
{"NT_STATUS_NO_USER_SESSION_KEY", NT_STATUS_NO_USER_SESSION_KEY},
{"NT_STATUS_USER_SESSION_DELETED", NT_STATUS_USER_SESSION_DELETED},
{"NT_STATUS_RESOURCE_LANG_NOT_FOUND",
NT_STATUS_RESOURCE_LANG_NOT_FOUND},
{"NT_STATUS_INSUFF_SERVER_RESOURCES",
NT_STATUS_INSUFF_SERVER_RESOURCES},
{"NT_STATUS_INVALID_BUFFER_SIZE", NT_STATUS_INVALID_BUFFER_SIZE},
{"NT_STATUS_INVALID_ADDRESS_COMPONENT",
NT_STATUS_INVALID_ADDRESS_COMPONENT},
{"NT_STATUS_INVALID_ADDRESS_WILDCARD",
NT_STATUS_INVALID_ADDRESS_WILDCARD},
{"NT_STATUS_TOO_MANY_ADDRESSES", NT_STATUS_TOO_MANY_ADDRESSES},
{"NT_STATUS_ADDRESS_ALREADY_EXISTS",
NT_STATUS_ADDRESS_ALREADY_EXISTS},
{"NT_STATUS_ADDRESS_CLOSED", NT_STATUS_ADDRESS_CLOSED},
{"NT_STATUS_CONNECTION_DISCONNECTED",
NT_STATUS_CONNECTION_DISCONNECTED},
{"NT_STATUS_CONNECTION_RESET", NT_STATUS_CONNECTION_RESET},
{"NT_STATUS_TOO_MANY_NODES", NT_STATUS_TOO_MANY_NODES},
{"NT_STATUS_TRANSACTION_ABORTED", NT_STATUS_TRANSACTION_ABORTED},
{"NT_STATUS_TRANSACTION_TIMED_OUT",
NT_STATUS_TRANSACTION_TIMED_OUT},
{"NT_STATUS_TRANSACTION_NO_RELEASE",
NT_STATUS_TRANSACTION_NO_RELEASE},
{"NT_STATUS_TRANSACTION_NO_MATCH", NT_STATUS_TRANSACTION_NO_MATCH},
{"NT_STATUS_TRANSACTION_RESPONDED",
NT_STATUS_TRANSACTION_RESPONDED},
{"NT_STATUS_TRANSACTION_INVALID_ID",
NT_STATUS_TRANSACTION_INVALID_ID},
{"NT_STATUS_TRANSACTION_INVALID_TYPE",
NT_STATUS_TRANSACTION_INVALID_TYPE},
{"NT_STATUS_NOT_SERVER_SESSION", NT_STATUS_NOT_SERVER_SESSION},
{"NT_STATUS_NOT_CLIENT_SESSION", NT_STATUS_NOT_CLIENT_SESSION},
{"NT_STATUS_CANNOT_LOAD_REGISTRY_FILE",
NT_STATUS_CANNOT_LOAD_REGISTRY_FILE},
{"NT_STATUS_DEBUG_ATTACH_FAILED", NT_STATUS_DEBUG_ATTACH_FAILED},
{"NT_STATUS_SYSTEM_PROCESS_TERMINATED",
NT_STATUS_SYSTEM_PROCESS_TERMINATED},
{"NT_STATUS_DATA_NOT_ACCEPTED", NT_STATUS_DATA_NOT_ACCEPTED},
{"NT_STATUS_NO_BROWSER_SERVERS_FOUND",
NT_STATUS_NO_BROWSER_SERVERS_FOUND},
{"NT_STATUS_VDM_HARD_ERROR", NT_STATUS_VDM_HARD_ERROR},
{"NT_STATUS_DRIVER_CANCEL_TIMEOUT",
NT_STATUS_DRIVER_CANCEL_TIMEOUT},
{"NT_STATUS_REPLY_MESSAGE_MISMATCH",
NT_STATUS_REPLY_MESSAGE_MISMATCH},
{"NT_STATUS_MAPPED_ALIGNMENT", NT_STATUS_MAPPED_ALIGNMENT},
{"NT_STATUS_IMAGE_CHECKSUM_MISMATCH",
NT_STATUS_IMAGE_CHECKSUM_MISMATCH},
{"NT_STATUS_LOST_WRITEBEHIND_DATA",
NT_STATUS_LOST_WRITEBEHIND_DATA},
{"NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID",
NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID},
{"NT_STATUS_PASSWORD_MUST_CHANGE", NT_STATUS_PASSWORD_MUST_CHANGE},
{"NT_STATUS_NOT_FOUND", NT_STATUS_NOT_FOUND},
{"NT_STATUS_NOT_TINY_STREAM", NT_STATUS_NOT_TINY_STREAM},
{"NT_STATUS_RECOVERY_FAILURE", NT_STATUS_RECOVERY_FAILURE},
{"NT_STATUS_STACK_OVERFLOW_READ", NT_STATUS_STACK_OVERFLOW_READ},
{"NT_STATUS_FAIL_CHECK", NT_STATUS_FAIL_CHECK},
{"NT_STATUS_DUPLICATE_OBJECTID", NT_STATUS_DUPLICATE_OBJECTID},
{"NT_STATUS_OBJECTID_EXISTS", NT_STATUS_OBJECTID_EXISTS},
{"NT_STATUS_CONVERT_TO_LARGE", NT_STATUS_CONVERT_TO_LARGE},
{"NT_STATUS_RETRY", NT_STATUS_RETRY},
{"NT_STATUS_FOUND_OUT_OF_SCOPE", NT_STATUS_FOUND_OUT_OF_SCOPE},
{"NT_STATUS_ALLOCATE_BUCKET", NT_STATUS_ALLOCATE_BUCKET},
{"NT_STATUS_PROPSET_NOT_FOUND", NT_STATUS_PROPSET_NOT_FOUND},
{"NT_STATUS_MARSHALL_OVERFLOW", NT_STATUS_MARSHALL_OVERFLOW},
{"NT_STATUS_INVALID_VARIANT", NT_STATUS_INVALID_VARIANT},
{"NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND},
{"NT_STATUS_ACCOUNT_LOCKED_OUT", NT_STATUS_ACCOUNT_LOCKED_OUT},
{"NT_STATUS_HANDLE_NOT_CLOSABLE", NT_STATUS_HANDLE_NOT_CLOSABLE},
{"NT_STATUS_CONNECTION_REFUSED", NT_STATUS_CONNECTION_REFUSED},
{"NT_STATUS_GRACEFUL_DISCONNECT", NT_STATUS_GRACEFUL_DISCONNECT},
{"NT_STATUS_ADDRESS_ALREADY_ASSOCIATED",
NT_STATUS_ADDRESS_ALREADY_ASSOCIATED},
{"NT_STATUS_ADDRESS_NOT_ASSOCIATED",
NT_STATUS_ADDRESS_NOT_ASSOCIATED},
{"NT_STATUS_CONNECTION_INVALID", NT_STATUS_CONNECTION_INVALID},
{"NT_STATUS_CONNECTION_ACTIVE", NT_STATUS_CONNECTION_ACTIVE},
{"NT_STATUS_NETWORK_UNREACHABLE", NT_STATUS_NETWORK_UNREACHABLE},
{"NT_STATUS_HOST_UNREACHABLE", NT_STATUS_HOST_UNREACHABLE},
{"NT_STATUS_PROTOCOL_UNREACHABLE", NT_STATUS_PROTOCOL_UNREACHABLE},
{"NT_STATUS_PORT_UNREACHABLE", NT_STATUS_PORT_UNREACHABLE},
{"NT_STATUS_REQUEST_ABORTED", NT_STATUS_REQUEST_ABORTED},
{"NT_STATUS_CONNECTION_ABORTED", NT_STATUS_CONNECTION_ABORTED},
{"NT_STATUS_BAD_COMPRESSION_BUFFER",
NT_STATUS_BAD_COMPRESSION_BUFFER},
{"NT_STATUS_USER_MAPPED_FILE", NT_STATUS_USER_MAPPED_FILE},
{"NT_STATUS_AUDIT_FAILED", NT_STATUS_AUDIT_FAILED},
{"NT_STATUS_TIMER_RESOLUTION_NOT_SET",
NT_STATUS_TIMER_RESOLUTION_NOT_SET},
{"NT_STATUS_CONNECTION_COUNT_LIMIT",
NT_STATUS_CONNECTION_COUNT_LIMIT},
{"NT_STATUS_LOGIN_TIME_RESTRICTION",
NT_STATUS_LOGIN_TIME_RESTRICTION},
{"NT_STATUS_LOGIN_WKSTA_RESTRICTION",
NT_STATUS_LOGIN_WKSTA_RESTRICTION},
{"NT_STATUS_IMAGE_MP_UP_MISMATCH", NT_STATUS_IMAGE_MP_UP_MISMATCH},
{"NT_STATUS_INSUFFICIENT_LOGON_INFO",
NT_STATUS_INSUFFICIENT_LOGON_INFO},
{"NT_STATUS_BAD_DLL_ENTRYPOINT", NT_STATUS_BAD_DLL_ENTRYPOINT},
{"NT_STATUS_BAD_SERVICE_ENTRYPOINT",
NT_STATUS_BAD_SERVICE_ENTRYPOINT},
{"NT_STATUS_LPC_REPLY_LOST", NT_STATUS_LPC_REPLY_LOST},
{"NT_STATUS_IP_ADDRESS_CONFLICT1", NT_STATUS_IP_ADDRESS_CONFLICT1},
{"NT_STATUS_IP_ADDRESS_CONFLICT2", NT_STATUS_IP_ADDRESS_CONFLICT2},
{"NT_STATUS_REGISTRY_QUOTA_LIMIT", NT_STATUS_REGISTRY_QUOTA_LIMIT},
{"NT_STATUS_PATH_NOT_COVERED", NT_STATUS_PATH_NOT_COVERED},
{"NT_STATUS_NO_CALLBACK_ACTIVE", NT_STATUS_NO_CALLBACK_ACTIVE},
{"NT_STATUS_LICENSE_QUOTA_EXCEEDED",
NT_STATUS_LICENSE_QUOTA_EXCEEDED},
{"NT_STATUS_PWD_TOO_SHORT", NT_STATUS_PWD_TOO_SHORT},
{"NT_STATUS_PWD_TOO_RECENT", NT_STATUS_PWD_TOO_RECENT},
{"NT_STATUS_PWD_HISTORY_CONFLICT", NT_STATUS_PWD_HISTORY_CONFLICT},
{"NT_STATUS_PLUGPLAY_NO_DEVICE", NT_STATUS_PLUGPLAY_NO_DEVICE},
{"NT_STATUS_UNSUPPORTED_COMPRESSION",
NT_STATUS_UNSUPPORTED_COMPRESSION},
{"NT_STATUS_INVALID_HW_PROFILE", NT_STATUS_INVALID_HW_PROFILE},
{"NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH",
NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH},
{"NT_STATUS_DRIVER_ORDINAL_NOT_FOUND",
NT_STATUS_DRIVER_ORDINAL_NOT_FOUND},
{"NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND",
NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND},
{"NT_STATUS_RESOURCE_NOT_OWNED", NT_STATUS_RESOURCE_NOT_OWNED},
{"NT_STATUS_TOO_MANY_LINKS", NT_STATUS_TOO_MANY_LINKS},
{"NT_STATUS_QUOTA_LIST_INCONSISTENT",
NT_STATUS_QUOTA_LIST_INCONSISTENT},
{"NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE},
{"NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES},
{"STATUS_MORE_ENTRIES", STATUS_MORE_ENTRIES},
{"STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED},
{NULL, 0}
};
/*****************************************************************************
Print an error message from the status code
*****************************************************************************/
void
print_status(__u32 status_code)
{
int idx = 0;
printk("\nStatus code returned: 0x%08x", status_code);
while (nt_errs[idx].nt_errstr != NULL) {
if (((nt_errs[idx].nt_errcode) & 0xFFFFFF) ==
(status_code & 0xFFFFFF)) {
printk(nt_errs[idx].nt_errstr);
}
idx++;
}
return;
}
/*
Unix SMB/Netbios implementation.
Version 1.9.
NT error code constants
Copyright (C) Andrew Tridgell 1992-2000
Copyright (C) John H Terpstra 1996-2000
Copyright (C) Luke Kenneth Casson Leighton 1996-2000
Copyright (C) Paul Ashton 1998-2000
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 _NTERR_H
#define _NTERR_H
/* Win32 Status codes. */
#define STATUS_BUFFER_OVERFLOW 0x80000005
#define STATUS_MORE_ENTRIES 0x0105
#define ERROR_INVALID_PARAMETER 0x0057
#define ERROR_INSUFFICIENT_BUFFER 0x007a
#define STATUS_1804 0x070c
#define STATUS_NOTIFY_ENUM_DIR 0x010c
/* Win32 Error codes extracted using a loop in smbclient then printing a
netmon sniff to a file. */
#define NT_STATUS_OK 0x0000
#define STATUS_SOME_UNMAPPED 0x0107
#define STATUS_BUFFER_OVERFLOW 0x80000005
#define NT_STATUS_NO_MORE_ENTRIES 0x8000001a
#define NT_STATUS_UNSUCCESSFUL 0xC0000000 | 0x0001
#define NT_STATUS_NOT_IMPLEMENTED 0xC0000000 | 0x0002
#define NT_STATUS_INVALID_INFO_CLASS 0xC0000000 | 0x0003
#define NT_STATUS_INFO_LENGTH_MISMATCH 0xC0000000 | 0x0004
#define NT_STATUS_ACCESS_VIOLATION 0xC0000000 | 0x0005
#define NT_STATUS_IN_PAGE_ERROR 0xC0000000 | 0x0006
#define NT_STATUS_PAGEFILE_QUOTA 0xC0000000 | 0x0007
#define NT_STATUS_INVALID_HANDLE 0xC0000000 | 0x0008
#define NT_STATUS_BAD_INITIAL_STACK 0xC0000000 | 0x0009
#define NT_STATUS_BAD_INITIAL_PC 0xC0000000 | 0x000a
#define NT_STATUS_INVALID_CID 0xC0000000 | 0x000b
#define NT_STATUS_TIMER_NOT_CANCELED 0xC0000000 | 0x000c
#define NT_STATUS_INVALID_PARAMETER 0xC0000000 | 0x000d
#define NT_STATUS_NO_SUCH_DEVICE 0xC0000000 | 0x000e
#define NT_STATUS_NO_SUCH_FILE 0xC0000000 | 0x000f
#define NT_STATUS_INVALID_DEVICE_REQUEST 0xC0000000 | 0x0010
#define NT_STATUS_END_OF_FILE 0xC0000000 | 0x0011
#define NT_STATUS_WRONG_VOLUME 0xC0000000 | 0x0012
#define NT_STATUS_NO_MEDIA_IN_DEVICE 0xC0000000 | 0x0013
#define NT_STATUS_UNRECOGNIZED_MEDIA 0xC0000000 | 0x0014
#define NT_STATUS_NONEXISTENT_SECTOR 0xC0000000 | 0x0015
#define NT_STATUS_MORE_PROCESSING_REQUIRED 0xC0000000 | 0x0016
#define NT_STATUS_NO_MEMORY 0xC0000000 | 0x0017
#define NT_STATUS_CONFLICTING_ADDRESSES 0xC0000000 | 0x0018
#define NT_STATUS_NOT_MAPPED_VIEW 0xC0000000 | 0x0019
#define NT_STATUS_UNABLE_TO_FREE_VM 0x80000000 | 0x001a
#define NT_STATUS_UNABLE_TO_DELETE_SECTION 0xC0000000 | 0x001b
#define NT_STATUS_INVALID_SYSTEM_SERVICE 0xC0000000 | 0x001c
#define NT_STATUS_ILLEGAL_INSTRUCTION 0xC0000000 | 0x001d
#define NT_STATUS_INVALID_LOCK_SEQUENCE 0xC0000000 | 0x001e
#define NT_STATUS_INVALID_VIEW_SIZE 0xC0000000 | 0x001f
#define NT_STATUS_INVALID_FILE_FOR_SECTION 0xC0000000 | 0x0020
#define NT_STATUS_ALREADY_COMMITTED 0xC0000000 | 0x0021
#define NT_STATUS_ACCESS_DENIED 0xC0000000 | 0x0022
#define NT_STATUS_BUFFER_TOO_SMALL 0xC0000000 | 0x0023
#define NT_STATUS_OBJECT_TYPE_MISMATCH 0xC0000000 | 0x0024
#define NT_STATUS_NONCONTINUABLE_EXCEPTION 0xC0000000 | 0x0025
#define NT_STATUS_INVALID_DISPOSITION 0xC0000000 | 0x0026
#define NT_STATUS_UNWIND 0xC0000000 | 0x0027
#define NT_STATUS_BAD_STACK 0xC0000000 | 0x0028
#define NT_STATUS_INVALID_UNWIND_TARGET 0xC0000000 | 0x0029
#define NT_STATUS_NOT_LOCKED 0xC0000000 | 0x002a
#define NT_STATUS_PARITY_ERROR 0xC0000000 | 0x002b
#define NT_STATUS_UNABLE_TO_DECOMMIT_VM 0xC0000000 | 0x002c
#define NT_STATUS_NOT_COMMITTED 0xC0000000 | 0x002d
#define NT_STATUS_INVALID_PORT_ATTRIBUTES 0xC0000000 | 0x002e
#define NT_STATUS_PORT_MESSAGE_TOO_LONG 0xC0000000 | 0x002f
#define NT_STATUS_INVALID_PARAMETER_MIX 0xC0000000 | 0x0030
#define NT_STATUS_INVALID_QUOTA_LOWER 0xC0000000 | 0x0031
#define NT_STATUS_DISK_CORRUPT_ERROR 0xC0000000 | 0x0032
#define NT_STATUS_OBJECT_NAME_INVALID 0xC0000000 | 0x0033
#define NT_STATUS_OBJECT_NAME_NOT_FOUND 0xC0000000 | 0x0034
#define NT_STATUS_OBJECT_NAME_COLLISION 0xC0000000 | 0x0035
#define NT_STATUS_HANDLE_NOT_WAITABLE 0xC0000000 | 0x0036
#define NT_STATUS_PORT_DISCONNECTED 0xC0000000 | 0x0037
#define NT_STATUS_DEVICE_ALREADY_ATTACHED 0xC0000000 | 0x0038
#define NT_STATUS_OBJECT_PATH_INVALID 0xC0000000 | 0x0039
#define NT_STATUS_OBJECT_PATH_NOT_FOUND 0xC0000000 | 0x003a
#define NT_STATUS_OBJECT_PATH_SYNTAX_BAD 0xC0000000 | 0x003b
#define NT_STATUS_DATA_OVERRUN 0xC0000000 | 0x003c
#define NT_STATUS_DATA_LATE_ERROR 0xC0000000 | 0x003d
#define NT_STATUS_DATA_ERROR 0xC0000000 | 0x003e
#define NT_STATUS_CRC_ERROR 0xC0000000 | 0x003f
#define NT_STATUS_SECTION_TOO_BIG 0xC0000000 | 0x0040
#define NT_STATUS_PORT_CONNECTION_REFUSED 0xC0000000 | 0x0041
#define NT_STATUS_INVALID_PORT_HANDLE 0xC0000000 | 0x0042
#define NT_STATUS_SHARING_VIOLATION 0xC0000000 | 0x0043
#define NT_STATUS_QUOTA_EXCEEDED 0xC0000000 | 0x0044
#define NT_STATUS_INVALID_PAGE_PROTECTION 0xC0000000 | 0x0045
#define NT_STATUS_MUTANT_NOT_OWNED 0xC0000000 | 0x0046
#define NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED 0xC0000000 | 0x0047
#define NT_STATUS_PORT_ALREADY_SET 0xC0000000 | 0x0048
#define NT_STATUS_SECTION_NOT_IMAGE 0xC0000000 | 0x0049
#define NT_STATUS_SUSPEND_COUNT_EXCEEDED 0xC0000000 | 0x004a
#define NT_STATUS_THREAD_IS_TERMINATING 0xC0000000 | 0x004b
#define NT_STATUS_BAD_WORKING_SET_LIMIT 0xC0000000 | 0x004c
#define NT_STATUS_INCOMPATIBLE_FILE_MAP 0xC0000000 | 0x004d
#define NT_STATUS_SECTION_PROTECTION 0xC0000000 | 0x004e
#define NT_STATUS_EAS_NOT_SUPPORTED 0xC0000000 | 0x004f
#define NT_STATUS_EA_TOO_LARGE 0xC0000000 | 0x0050
#define NT_STATUS_NONEXISTENT_EA_ENTRY 0xC0000000 | 0x0051
#define NT_STATUS_NO_EAS_ON_FILE 0xC0000000 | 0x0052
#define NT_STATUS_EA_CORRUPT_ERROR 0xC0000000 | 0x0053
#define NT_STATUS_FILE_LOCK_CONFLICT 0xC0000000 | 0x0054
#define NT_STATUS_LOCK_NOT_GRANTED 0xC0000000 | 0x0055
#define NT_STATUS_DELETE_PENDING 0xC0000000 | 0x0056
#define NT_STATUS_CTL_FILE_NOT_SUPPORTED 0xC0000000 | 0x0057
#define NT_STATUS_UNKNOWN_REVISION 0xC0000000 | 0x0058
#define NT_STATUS_REVISION_MISMATCH 0xC0000000 | 0x0059
#define NT_STATUS_INVALID_OWNER 0xC0000000 | 0x005a
#define NT_STATUS_INVALID_PRIMARY_GROUP 0xC0000000 | 0x005b
#define NT_STATUS_NO_IMPERSONATION_TOKEN 0xC0000000 | 0x005c
#define NT_STATUS_CANT_DISABLE_MANDATORY 0xC0000000 | 0x005d
#define NT_STATUS_NO_LOGON_SERVERS 0xC0000000 | 0x005e
#define NT_STATUS_NO_SUCH_LOGON_SESSION 0xC0000000 | 0x005f
#define NT_STATUS_NO_SUCH_PRIVILEGE 0xC0000000 | 0x0060
#define NT_STATUS_PRIVILEGE_NOT_HELD 0xC0000000 | 0x0061
#define NT_STATUS_INVALID_ACCOUNT_NAME 0xC0000000 | 0x0062
#define NT_STATUS_USER_EXISTS 0xC0000000 | 0x0063
#define NT_STATUS_NO_SUCH_USER 0xC0000000 | 0x0064
#define NT_STATUS_GROUP_EXISTS 0xC0000000 | 0x0065
#define NT_STATUS_NO_SUCH_GROUP 0xC0000000 | 0x0066
#define NT_STATUS_MEMBER_IN_GROUP 0xC0000000 | 0x0067
#define NT_STATUS_MEMBER_NOT_IN_GROUP 0xC0000000 | 0x0068
#define NT_STATUS_LAST_ADMIN 0xC0000000 | 0x0069
#define NT_STATUS_WRONG_PASSWORD 0xC0000000 | 0x006a
#define NT_STATUS_ILL_FORMED_PASSWORD 0xC0000000 | 0x006b
#define NT_STATUS_PASSWORD_RESTRICTION 0xC0000000 | 0x006c
#define NT_STATUS_LOGON_FAILURE 0xC0000000 | 0x006d
#define NT_STATUS_ACCOUNT_RESTRICTION 0xC0000000 | 0x006e
#define NT_STATUS_INVALID_LOGON_HOURS 0xC0000000 | 0x006f
#define NT_STATUS_INVALID_WORKSTATION 0xC0000000 | 0x0070
#define NT_STATUS_PASSWORD_EXPIRED 0xC0000000 | 0x0071
#define NT_STATUS_ACCOUNT_DISABLED 0xC0000000 | 0x0072
#define NT_STATUS_NONE_MAPPED 0xC0000000 | 0x0073
#define NT_STATUS_TOO_MANY_LUIDS_REQUESTED 0xC0000000 | 0x0074
#define NT_STATUS_LUIDS_EXHAUSTED 0xC0000000 | 0x0075
#define NT_STATUS_INVALID_SUB_AUTHORITY 0xC0000000 | 0x0076
#define NT_STATUS_INVALID_ACL 0xC0000000 | 0x0077
#define NT_STATUS_INVALID_SID 0xC0000000 | 0x0078
#define NT_STATUS_INVALID_SECURITY_DESCR 0xC0000000 | 0x0079
#define NT_STATUS_PROCEDURE_NOT_FOUND 0xC0000000 | 0x007a
#define NT_STATUS_INVALID_IMAGE_FORMAT 0xC0000000 | 0x007b
#define NT_STATUS_NO_TOKEN 0xC0000000 | 0x007c
#define NT_STATUS_BAD_INHERITANCE_ACL 0xC0000000 | 0x007d
#define NT_STATUS_RANGE_NOT_LOCKED 0xC0000000 | 0x007e
#define NT_STATUS_DISK_FULL 0xC0000000 | 0x007f
#define NT_STATUS_SERVER_DISABLED 0xC0000000 | 0x0080
#define NT_STATUS_SERVER_NOT_DISABLED 0xC0000000 | 0x0081
#define NT_STATUS_TOO_MANY_GUIDS_REQUESTED 0xC0000000 | 0x0082
#define NT_STATUS_GUIDS_EXHAUSTED 0xC0000000 | 0x0083
#define NT_STATUS_INVALID_ID_AUTHORITY 0xC0000000 | 0x0084
#define NT_STATUS_AGENTS_EXHAUSTED 0xC0000000 | 0x0085
#define NT_STATUS_INVALID_VOLUME_LABEL 0xC0000000 | 0x0086
#define NT_STATUS_SECTION_NOT_EXTENDED 0xC0000000 | 0x0087
#define NT_STATUS_NOT_MAPPED_DATA 0xC0000000 | 0x0088
#define NT_STATUS_RESOURCE_DATA_NOT_FOUND 0xC0000000 | 0x0089
#define NT_STATUS_RESOURCE_TYPE_NOT_FOUND 0xC0000000 | 0x008a
#define NT_STATUS_RESOURCE_NAME_NOT_FOUND 0xC0000000 | 0x008b
#define NT_STATUS_ARRAY_BOUNDS_EXCEEDED 0xC0000000 | 0x008c
#define NT_STATUS_FLOAT_DENORMAL_OPERAND 0xC0000000 | 0x008d
#define NT_STATUS_FLOAT_DIVIDE_BY_ZERO 0xC0000000 | 0x008e
#define NT_STATUS_FLOAT_INEXACT_RESULT 0xC0000000 | 0x008f
#define NT_STATUS_FLOAT_INVALID_OPERATION 0xC0000000 | 0x0090
#define NT_STATUS_FLOAT_OVERFLOW 0xC0000000 | 0x0091
#define NT_STATUS_FLOAT_STACK_CHECK 0xC0000000 | 0x0092
#define NT_STATUS_FLOAT_UNDERFLOW 0xC0000000 | 0x0093
#define NT_STATUS_INTEGER_DIVIDE_BY_ZERO 0xC0000000 | 0x0094
#define NT_STATUS_INTEGER_OVERFLOW 0xC0000000 | 0x0095
#define NT_STATUS_PRIVILEGED_INSTRUCTION 0xC0000000 | 0x0096
#define NT_STATUS_TOO_MANY_PAGING_FILES 0xC0000000 | 0x0097
#define NT_STATUS_FILE_INVALID 0xC0000000 | 0x0098
#define NT_STATUS_ALLOTTED_SPACE_EXCEEDED 0xC0000000 | 0x0099
#define NT_STATUS_INSUFFICIENT_RESOURCES 0xC0000000 | 0x009a
#define NT_STATUS_DFS_EXIT_PATH_FOUND 0xC0000000 | 0x009b
#define NT_STATUS_DEVICE_DATA_ERROR 0xC0000000 | 0x009c
#define NT_STATUS_DEVICE_NOT_CONNECTED 0xC0000000 | 0x009d
#define NT_STATUS_DEVICE_POWER_FAILURE 0xC0000000 | 0x009e
#define NT_STATUS_FREE_VM_NOT_AT_BASE 0xC0000000 | 0x009f
#define NT_STATUS_MEMORY_NOT_ALLOCATED 0xC0000000 | 0x00a0
#define NT_STATUS_WORKING_SET_QUOTA 0xC0000000 | 0x00a1
#define NT_STATUS_MEDIA_WRITE_PROTECTED 0xC0000000 | 0x00a2
#define NT_STATUS_DEVICE_NOT_READY 0xC0000000 | 0x00a3
#define NT_STATUS_INVALID_GROUP_ATTRIBUTES 0xC0000000 | 0x00a4
#define NT_STATUS_BAD_IMPERSONATION_LEVEL 0xC0000000 | 0x00a5
#define NT_STATUS_CANT_OPEN_ANONYMOUS 0xC0000000 | 0x00a6
#define NT_STATUS_BAD_VALIDATION_CLASS 0xC0000000 | 0x00a7
#define NT_STATUS_BAD_TOKEN_TYPE 0xC0000000 | 0x00a8
#define NT_STATUS_BAD_MASTER_BOOT_RECORD 0xC0000000 | 0x00a9
#define NT_STATUS_INSTRUCTION_MISALIGNMENT 0xC0000000 | 0x00aa
#define NT_STATUS_INSTANCE_NOT_AVAILABLE 0xC0000000 | 0x00ab
#define NT_STATUS_PIPE_NOT_AVAILABLE 0xC0000000 | 0x00ac
#define NT_STATUS_INVALID_PIPE_STATE 0xC0000000 | 0x00ad
#define NT_STATUS_PIPE_BUSY 0xC0000000 | 0x00ae
#define NT_STATUS_ILLEGAL_FUNCTION 0xC0000000 | 0x00af
#define NT_STATUS_PIPE_DISCONNECTED 0xC0000000 | 0x00b0
#define NT_STATUS_PIPE_CLOSING 0xC0000000 | 0x00b1
#define NT_STATUS_PIPE_CONNECTED 0xC0000000 | 0x00b2
#define NT_STATUS_PIPE_LISTENING 0xC0000000 | 0x00b3
#define NT_STATUS_INVALID_READ_MODE 0xC0000000 | 0x00b4
#define NT_STATUS_IO_TIMEOUT 0xC0000000 | 0x00b5
#define NT_STATUS_FILE_FORCED_CLOSED 0xC0000000 | 0x00b6
#define NT_STATUS_PROFILING_NOT_STARTED 0xC0000000 | 0x00b7
#define NT_STATUS_PROFILING_NOT_STOPPED 0xC0000000 | 0x00b8
#define NT_STATUS_COULD_NOT_INTERPRET 0xC0000000 | 0x00b9
#define NT_STATUS_FILE_IS_A_DIRECTORY 0xC0000000 | 0x00ba
#define NT_STATUS_NOT_SUPPORTED 0xC0000000 | 0x00bb
#define NT_STATUS_REMOTE_NOT_LISTENING 0xC0000000 | 0x00bc
#define NT_STATUS_DUPLICATE_NAME 0xC0000000 | 0x00bd
#define NT_STATUS_BAD_NETWORK_PATH 0xC0000000 | 0x00be
#define NT_STATUS_NETWORK_BUSY 0xC0000000 | 0x00bf
#define NT_STATUS_DEVICE_DOES_NOT_EXIST 0xC0000000 | 0x00c0
#define NT_STATUS_TOO_MANY_COMMANDS 0xC0000000 | 0x00c1
#define NT_STATUS_ADAPTER_HARDWARE_ERROR 0xC0000000 | 0x00c2
#define NT_STATUS_INVALID_NETWORK_RESPONSE 0xC0000000 | 0x00c3
#define NT_STATUS_UNEXPECTED_NETWORK_ERROR 0xC0000000 | 0x00c4
#define NT_STATUS_BAD_REMOTE_ADAPTER 0xC0000000 | 0x00c5
#define NT_STATUS_PRINT_QUEUE_FULL 0xC0000000 | 0x00c6
#define NT_STATUS_NO_SPOOL_SPACE 0xC0000000 | 0x00c7
#define NT_STATUS_PRINT_CANCELLED 0xC0000000 | 0x00c8
#define NT_STATUS_NETWORK_NAME_DELETED 0xC0000000 | 0x00c9
#define NT_STATUS_NETWORK_ACCESS_DENIED 0xC0000000 | 0x00ca
#define NT_STATUS_BAD_DEVICE_TYPE 0xC0000000 | 0x00cb
#define NT_STATUS_BAD_NETWORK_NAME 0xC0000000 | 0x00cc
#define NT_STATUS_TOO_MANY_NAMES 0xC0000000 | 0x00cd
#define NT_STATUS_TOO_MANY_SESSIONS 0xC0000000 | 0x00ce
#define NT_STATUS_SHARING_PAUSED 0xC0000000 | 0x00cf
#define NT_STATUS_REQUEST_NOT_ACCEPTED 0xC0000000 | 0x00d0
#define NT_STATUS_REDIRECTOR_PAUSED 0xC0000000 | 0x00d1
#define NT_STATUS_NET_WRITE_FAULT 0xC0000000 | 0x00d2
#define NT_STATUS_PROFILING_AT_LIMIT 0xC0000000 | 0x00d3
#define NT_STATUS_NOT_SAME_DEVICE 0xC0000000 | 0x00d4
#define NT_STATUS_FILE_RENAMED 0xC0000000 | 0x00d5
#define NT_STATUS_VIRTUAL_CIRCUIT_CLOSED 0xC0000000 | 0x00d6
#define NT_STATUS_NO_SECURITY_ON_OBJECT 0xC0000000 | 0x00d7
#define NT_STATUS_CANT_WAIT 0xC0000000 | 0x00d8
#define NT_STATUS_PIPE_EMPTY 0xC0000000 | 0x00d9
#define NT_STATUS_CANT_ACCESS_DOMAIN_INFO 0xC0000000 | 0x00da
#define NT_STATUS_CANT_TERMINATE_SELF 0xC0000000 | 0x00db
#define NT_STATUS_INVALID_SERVER_STATE 0xC0000000 | 0x00dc
#define NT_STATUS_INVALID_DOMAIN_STATE 0xC0000000 | 0x00dd
#define NT_STATUS_INVALID_DOMAIN_ROLE 0xC0000000 | 0x00de
#define NT_STATUS_NO_SUCH_DOMAIN 0xC0000000 | 0x00df
#define NT_STATUS_DOMAIN_EXISTS 0xC0000000 | 0x00e0
#define NT_STATUS_DOMAIN_LIMIT_EXCEEDED 0xC0000000 | 0x00e1
#define NT_STATUS_OPLOCK_NOT_GRANTED 0xC0000000 | 0x00e2
#define NT_STATUS_INVALID_OPLOCK_PROTOCOL 0xC0000000 | 0x00e3
#define NT_STATUS_INTERNAL_DB_CORRUPTION 0xC0000000 | 0x00e4
#define NT_STATUS_INTERNAL_ERROR 0xC0000000 | 0x00e5
#define NT_STATUS_GENERIC_NOT_MAPPED 0xC0000000 | 0x00e6
#define NT_STATUS_BAD_DESCRIPTOR_FORMAT 0xC0000000 | 0x00e7
#define NT_STATUS_INVALID_USER_BUFFER 0xC0000000 | 0x00e8
#define NT_STATUS_UNEXPECTED_IO_ERROR 0xC0000000 | 0x00e9
#define NT_STATUS_UNEXPECTED_MM_CREATE_ERR 0xC0000000 | 0x00ea
#define NT_STATUS_UNEXPECTED_MM_MAP_ERROR 0xC0000000 | 0x00eb
#define NT_STATUS_UNEXPECTED_MM_EXTEND_ERR 0xC0000000 | 0x00ec
#define NT_STATUS_NOT_LOGON_PROCESS 0xC0000000 | 0x00ed
#define NT_STATUS_LOGON_SESSION_EXISTS 0xC0000000 | 0x00ee
#define NT_STATUS_INVALID_PARAMETER_1 0xC0000000 | 0x00ef
#define NT_STATUS_INVALID_PARAMETER_2 0xC0000000 | 0x00f0
#define NT_STATUS_INVALID_PARAMETER_3 0xC0000000 | 0x00f1
#define NT_STATUS_INVALID_PARAMETER_4 0xC0000000 | 0x00f2
#define NT_STATUS_INVALID_PARAMETER_5 0xC0000000 | 0x00f3
#define NT_STATUS_INVALID_PARAMETER_6 0xC0000000 | 0x00f4
#define NT_STATUS_INVALID_PARAMETER_7 0xC0000000 | 0x00f5
#define NT_STATUS_INVALID_PARAMETER_8 0xC0000000 | 0x00f6
#define NT_STATUS_INVALID_PARAMETER_9 0xC0000000 | 0x00f7
#define NT_STATUS_INVALID_PARAMETER_10 0xC0000000 | 0x00f8
#define NT_STATUS_INVALID_PARAMETER_11 0xC0000000 | 0x00f9
#define NT_STATUS_INVALID_PARAMETER_12 0xC0000000 | 0x00fa
#define NT_STATUS_REDIRECTOR_NOT_STARTED 0xC0000000 | 0x00fb
#define NT_STATUS_REDIRECTOR_STARTED 0xC0000000 | 0x00fc
#define NT_STATUS_STACK_OVERFLOW 0xC0000000 | 0x00fd
#define NT_STATUS_NO_SUCH_PACKAGE 0xC0000000 | 0x00fe
#define NT_STATUS_BAD_FUNCTION_TABLE 0xC0000000 | 0x00ff
#define NT_STATUS_DIRECTORY_NOT_EMPTY 0xC0000000 | 0x0101
#define NT_STATUS_FILE_CORRUPT_ERROR 0xC0000000 | 0x0102
#define NT_STATUS_NOT_A_DIRECTORY 0xC0000000 | 0x0103
#define NT_STATUS_BAD_LOGON_SESSION_STATE 0xC0000000 | 0x0104
#define NT_STATUS_LOGON_SESSION_COLLISION 0xC0000000 | 0x0105
#define NT_STATUS_NAME_TOO_LONG 0xC0000000 | 0x0106
#define NT_STATUS_FILES_OPEN 0xC0000000 | 0x0107
#define NT_STATUS_CONNECTION_IN_USE 0xC0000000 | 0x0108
#define NT_STATUS_MESSAGE_NOT_FOUND 0xC0000000 | 0x0109
#define NT_STATUS_PROCESS_IS_TERMINATING 0xC0000000 | 0x010a
#define NT_STATUS_INVALID_LOGON_TYPE 0xC0000000 | 0x010b
#define NT_STATUS_NO_GUID_TRANSLATION 0xC0000000 | 0x010c
#define NT_STATUS_CANNOT_IMPERSONATE 0xC0000000 | 0x010d
#define NT_STATUS_IMAGE_ALREADY_LOADED 0xC0000000 | 0x010e
#define NT_STATUS_ABIOS_NOT_PRESENT 0xC0000000 | 0x010f
#define NT_STATUS_ABIOS_LID_NOT_EXIST 0xC0000000 | 0x0110
#define NT_STATUS_ABIOS_LID_ALREADY_OWNED 0xC0000000 | 0x0111
#define NT_STATUS_ABIOS_NOT_LID_OWNER 0xC0000000 | 0x0112
#define NT_STATUS_ABIOS_INVALID_COMMAND 0xC0000000 | 0x0113
#define NT_STATUS_ABIOS_INVALID_LID 0xC0000000 | 0x0114
#define NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE 0xC0000000 | 0x0115
#define NT_STATUS_ABIOS_INVALID_SELECTOR 0xC0000000 | 0x0116
#define NT_STATUS_NO_LDT 0xC0000000 | 0x0117
#define NT_STATUS_INVALID_LDT_SIZE 0xC0000000 | 0x0118
#define NT_STATUS_INVALID_LDT_OFFSET 0xC0000000 | 0x0119
#define NT_STATUS_INVALID_LDT_DESCRIPTOR 0xC0000000 | 0x011a
#define NT_STATUS_INVALID_IMAGE_NE_FORMAT 0xC0000000 | 0x011b
#define NT_STATUS_RXACT_INVALID_STATE 0xC0000000 | 0x011c
#define NT_STATUS_RXACT_COMMIT_FAILURE 0xC0000000 | 0x011d
#define NT_STATUS_MAPPED_FILE_SIZE_ZERO 0xC0000000 | 0x011e
#define NT_STATUS_TOO_MANY_OPENED_FILES 0xC0000000 | 0x011f
#define NT_STATUS_CANCELLED 0xC0000000 | 0x0120
#define NT_STATUS_CANNOT_DELETE 0xC0000000 | 0x0121
#define NT_STATUS_INVALID_COMPUTER_NAME 0xC0000000 | 0x0122
#define NT_STATUS_FILE_DELETED 0xC0000000 | 0x0123
#define NT_STATUS_SPECIAL_ACCOUNT 0xC0000000 | 0x0124
#define NT_STATUS_SPECIAL_GROUP 0xC0000000 | 0x0125
#define NT_STATUS_SPECIAL_USER 0xC0000000 | 0x0126
#define NT_STATUS_MEMBERS_PRIMARY_GROUP 0xC0000000 | 0x0127
#define NT_STATUS_FILE_CLOSED 0xC0000000 | 0x0128
#define NT_STATUS_TOO_MANY_THREADS 0xC0000000 | 0x0129
#define NT_STATUS_THREAD_NOT_IN_PROCESS 0xC0000000 | 0x012a
#define NT_STATUS_TOKEN_ALREADY_IN_USE 0xC0000000 | 0x012b
#define NT_STATUS_PAGEFILE_QUOTA_EXCEEDED 0xC0000000 | 0x012c
#define NT_STATUS_COMMITMENT_LIMIT 0xC0000000 | 0x012d
#define NT_STATUS_INVALID_IMAGE_LE_FORMAT 0xC0000000 | 0x012e
#define NT_STATUS_INVALID_IMAGE_NOT_MZ 0xC0000000 | 0x012f
#define NT_STATUS_INVALID_IMAGE_PROTECT 0xC0000000 | 0x0130
#define NT_STATUS_INVALID_IMAGE_WIN_16 0xC0000000 | 0x0131
#define NT_STATUS_LOGON_SERVER_CONFLICT 0xC0000000 | 0x0132
#define NT_STATUS_TIME_DIFFERENCE_AT_DC 0xC0000000 | 0x0133
#define NT_STATUS_SYNCHRONIZATION_REQUIRED 0xC0000000 | 0x0134
#define NT_STATUS_DLL_NOT_FOUND 0xC0000000 | 0x0135
#define NT_STATUS_OPEN_FAILED 0xC0000000 | 0x0136
#define NT_STATUS_IO_PRIVILEGE_FAILED 0xC0000000 | 0x0137
#define NT_STATUS_ORDINAL_NOT_FOUND 0xC0000000 | 0x0138
#define NT_STATUS_ENTRYPOINT_NOT_FOUND 0xC0000000 | 0x0139
#define NT_STATUS_CONTROL_C_EXIT 0xC0000000 | 0x013a
#define NT_STATUS_LOCAL_DISCONNECT 0xC0000000 | 0x013b
#define NT_STATUS_REMOTE_DISCONNECT 0xC0000000 | 0x013c
#define NT_STATUS_REMOTE_RESOURCES 0xC0000000 | 0x013d
#define NT_STATUS_LINK_FAILED 0xC0000000 | 0x013e
#define NT_STATUS_LINK_TIMEOUT 0xC0000000 | 0x013f
#define NT_STATUS_INVALID_CONNECTION 0xC0000000 | 0x0140
#define NT_STATUS_INVALID_ADDRESS 0xC0000000 | 0x0141
#define NT_STATUS_DLL_INIT_FAILED 0xC0000000 | 0x0142
#define NT_STATUS_MISSING_SYSTEMFILE 0xC0000000 | 0x0143
#define NT_STATUS_UNHANDLED_EXCEPTION 0xC0000000 | 0x0144
#define NT_STATUS_APP_INIT_FAILURE 0xC0000000 | 0x0145
#define NT_STATUS_PAGEFILE_CREATE_FAILED 0xC0000000 | 0x0146
#define NT_STATUS_NO_PAGEFILE 0xC0000000 | 0x0147
#define NT_STATUS_INVALID_LEVEL 0xC0000000 | 0x0148
#define NT_STATUS_WRONG_PASSWORD_CORE 0xC0000000 | 0x0149
#define NT_STATUS_ILLEGAL_FLOAT_CONTEXT 0xC0000000 | 0x014a
#define NT_STATUS_PIPE_BROKEN 0xC0000000 | 0x014b
#define NT_STATUS_REGISTRY_CORRUPT 0xC0000000 | 0x014c
#define NT_STATUS_REGISTRY_IO_FAILED 0xC0000000 | 0x014d
#define NT_STATUS_NO_EVENT_PAIR 0xC0000000 | 0x014e
#define NT_STATUS_UNRECOGNIZED_VOLUME 0xC0000000 | 0x014f
#define NT_STATUS_SERIAL_NO_DEVICE_INITED 0xC0000000 | 0x0150
#define NT_STATUS_NO_SUCH_ALIAS 0xC0000000 | 0x0151
#define NT_STATUS_MEMBER_NOT_IN_ALIAS 0xC0000000 | 0x0152
#define NT_STATUS_MEMBER_IN_ALIAS 0xC0000000 | 0x0153
#define NT_STATUS_ALIAS_EXISTS 0xC0000000 | 0x0154
#define NT_STATUS_LOGON_NOT_GRANTED 0xC0000000 | 0x0155
#define NT_STATUS_TOO_MANY_SECRETS 0xC0000000 | 0x0156
#define NT_STATUS_SECRET_TOO_LONG 0xC0000000 | 0x0157
#define NT_STATUS_INTERNAL_DB_ERROR 0xC0000000 | 0x0158
#define NT_STATUS_FULLSCREEN_MODE 0xC0000000 | 0x0159
#define NT_STATUS_TOO_MANY_CONTEXT_IDS 0xC0000000 | 0x015a
#define NT_STATUS_LOGON_TYPE_NOT_GRANTED 0xC0000000 | 0x015b
#define NT_STATUS_NOT_REGISTRY_FILE 0xC0000000 | 0x015c
#define NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED 0xC0000000 | 0x015d
#define NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR 0xC0000000 | 0x015e
#define NT_STATUS_FT_MISSING_MEMBER 0xC0000000 | 0x015f
#define NT_STATUS_ILL_FORMED_SERVICE_ENTRY 0xC0000000 | 0x0160
#define NT_STATUS_ILLEGAL_CHARACTER 0xC0000000 | 0x0161
#define NT_STATUS_UNMAPPABLE_CHARACTER 0xC0000000 | 0x0162
#define NT_STATUS_UNDEFINED_CHARACTER 0xC0000000 | 0x0163
#define NT_STATUS_FLOPPY_VOLUME 0xC0000000 | 0x0164
#define NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND 0xC0000000 | 0x0165
#define NT_STATUS_FLOPPY_WRONG_CYLINDER 0xC0000000 | 0x0166
#define NT_STATUS_FLOPPY_UNKNOWN_ERROR 0xC0000000 | 0x0167
#define NT_STATUS_FLOPPY_BAD_REGISTERS 0xC0000000 | 0x0168
#define NT_STATUS_DISK_RECALIBRATE_FAILED 0xC0000000 | 0x0169
#define NT_STATUS_DISK_OPERATION_FAILED 0xC0000000 | 0x016a
#define NT_STATUS_DISK_RESET_FAILED 0xC0000000 | 0x016b
#define NT_STATUS_SHARED_IRQ_BUSY 0xC0000000 | 0x016c
#define NT_STATUS_FT_ORPHANING 0xC0000000 | 0x016d
#define NT_STATUS_PARTITION_FAILURE 0xC0000000 | 0x0172
#define NT_STATUS_INVALID_BLOCK_LENGTH 0xC0000000 | 0x0173
#define NT_STATUS_DEVICE_NOT_PARTITIONED 0xC0000000 | 0x0174
#define NT_STATUS_UNABLE_TO_LOCK_MEDIA 0xC0000000 | 0x0175
#define NT_STATUS_UNABLE_TO_UNLOAD_MEDIA 0xC0000000 | 0x0176
#define NT_STATUS_EOM_OVERFLOW 0xC0000000 | 0x0177
#define NT_STATUS_NO_MEDIA 0xC0000000 | 0x0178
#define NT_STATUS_NO_SUCH_MEMBER 0xC0000000 | 0x017a
#define NT_STATUS_INVALID_MEMBER 0xC0000000 | 0x017b
#define NT_STATUS_KEY_DELETED 0xC0000000 | 0x017c
#define NT_STATUS_NO_LOG_SPACE 0xC0000000 | 0x017d
#define NT_STATUS_TOO_MANY_SIDS 0xC0000000 | 0x017e
#define NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED 0xC0000000 | 0x017f
#define NT_STATUS_KEY_HAS_CHILDREN 0xC0000000 | 0x0180
#define NT_STATUS_CHILD_MUST_BE_VOLATILE 0xC0000000 | 0x0181
#define NT_STATUS_DEVICE_CONFIGURATION_ERROR 0xC0000000 | 0x0182
#define NT_STATUS_DRIVER_INTERNAL_ERROR 0xC0000000 | 0x0183
#define NT_STATUS_INVALID_DEVICE_STATE 0xC0000000 | 0x0184
#define NT_STATUS_IO_DEVICE_ERROR 0xC0000000 | 0x0185
#define NT_STATUS_DEVICE_PROTOCOL_ERROR 0xC0000000 | 0x0186
#define NT_STATUS_BACKUP_CONTROLLER 0xC0000000 | 0x0187
#define NT_STATUS_LOG_FILE_FULL 0xC0000000 | 0x0188
#define NT_STATUS_TOO_LATE 0xC0000000 | 0x0189
#define NT_STATUS_NO_TRUST_LSA_SECRET 0xC0000000 | 0x018a
#define NT_STATUS_NO_TRUST_SAM_ACCOUNT 0xC0000000 | 0x018b
#define NT_STATUS_TRUSTED_DOMAIN_FAILURE 0xC0000000 | 0x018c
#define NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE 0xC0000000 | 0x018d
#define NT_STATUS_EVENTLOG_FILE_CORRUPT 0xC0000000 | 0x018e
#define NT_STATUS_EVENTLOG_CANT_START 0xC0000000 | 0x018f
#define NT_STATUS_TRUST_FAILURE 0xC0000000 | 0x0190
#define NT_STATUS_MUTANT_LIMIT_EXCEEDED 0xC0000000 | 0x0191
#define NT_STATUS_NETLOGON_NOT_STARTED 0xC0000000 | 0x0192
#define NT_STATUS_ACCOUNT_EXPIRED 0xC0000000 | 0x0193
#define NT_STATUS_POSSIBLE_DEADLOCK 0xC0000000 | 0x0194
#define NT_STATUS_NETWORK_CREDENTIAL_CONFLICT 0xC0000000 | 0x0195
#define NT_STATUS_REMOTE_SESSION_LIMIT 0xC0000000 | 0x0196
#define NT_STATUS_EVENTLOG_FILE_CHANGED 0xC0000000 | 0x0197
#define NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT 0xC0000000 | 0x0198
#define NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT 0xC0000000 | 0x0199
#define NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT 0xC0000000 | 0x019a
#define NT_STATUS_DOMAIN_TRUST_INCONSISTENT 0xC0000000 | 0x019b
#define NT_STATUS_FS_DRIVER_REQUIRED 0xC0000000 | 0x019c
#define NT_STATUS_NO_USER_SESSION_KEY 0xC0000000 | 0x0202
#define NT_STATUS_USER_SESSION_DELETED 0xC0000000 | 0x0203
#define NT_STATUS_RESOURCE_LANG_NOT_FOUND 0xC0000000 | 0x0204
#define NT_STATUS_INSUFF_SERVER_RESOURCES 0xC0000000 | 0x0205
#define NT_STATUS_INVALID_BUFFER_SIZE 0xC0000000 | 0x0206
#define NT_STATUS_INVALID_ADDRESS_COMPONENT 0xC0000000 | 0x0207
#define NT_STATUS_INVALID_ADDRESS_WILDCARD 0xC0000000 | 0x0208
#define NT_STATUS_TOO_MANY_ADDRESSES 0xC0000000 | 0x0209
#define NT_STATUS_ADDRESS_ALREADY_EXISTS 0xC0000000 | 0x020a
#define NT_STATUS_ADDRESS_CLOSED 0xC0000000 | 0x020b
#define NT_STATUS_CONNECTION_DISCONNECTED 0xC0000000 | 0x020c
#define NT_STATUS_CONNECTION_RESET 0xC0000000 | 0x020d
#define NT_STATUS_TOO_MANY_NODES 0xC0000000 | 0x020e
#define NT_STATUS_TRANSACTION_ABORTED 0xC0000000 | 0x020f
#define NT_STATUS_TRANSACTION_TIMED_OUT 0xC0000000 | 0x0210
#define NT_STATUS_TRANSACTION_NO_RELEASE 0xC0000000 | 0x0211
#define NT_STATUS_TRANSACTION_NO_MATCH 0xC0000000 | 0x0212
#define NT_STATUS_TRANSACTION_RESPONDED 0xC0000000 | 0x0213
#define NT_STATUS_TRANSACTION_INVALID_ID 0xC0000000 | 0x0214
#define NT_STATUS_TRANSACTION_INVALID_TYPE 0xC0000000 | 0x0215
#define NT_STATUS_NOT_SERVER_SESSION 0xC0000000 | 0x0216
#define NT_STATUS_NOT_CLIENT_SESSION 0xC0000000 | 0x0217
#define NT_STATUS_CANNOT_LOAD_REGISTRY_FILE 0xC0000000 | 0x0218
#define NT_STATUS_DEBUG_ATTACH_FAILED 0xC0000000 | 0x0219
#define NT_STATUS_SYSTEM_PROCESS_TERMINATED 0xC0000000 | 0x021a
#define NT_STATUS_DATA_NOT_ACCEPTED 0xC0000000 | 0x021b
#define NT_STATUS_NO_BROWSER_SERVERS_FOUND 0xC0000000 | 0x021c
#define NT_STATUS_VDM_HARD_ERROR 0xC0000000 | 0x021d
#define NT_STATUS_DRIVER_CANCEL_TIMEOUT 0xC0000000 | 0x021e
#define NT_STATUS_REPLY_MESSAGE_MISMATCH 0xC0000000 | 0x021f
#define NT_STATUS_MAPPED_ALIGNMENT 0xC0000000 | 0x0220
#define NT_STATUS_IMAGE_CHECKSUM_MISMATCH 0xC0000000 | 0x0221
#define NT_STATUS_LOST_WRITEBEHIND_DATA 0xC0000000 | 0x0222
#define NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID 0xC0000000 | 0x0223
#define NT_STATUS_PASSWORD_MUST_CHANGE 0xC0000000 | 0x0224
#define NT_STATUS_NOT_FOUND 0xC0000000 | 0x0225
#define NT_STATUS_NOT_TINY_STREAM 0xC0000000 | 0x0226
#define NT_STATUS_RECOVERY_FAILURE 0xC0000000 | 0x0227
#define NT_STATUS_STACK_OVERFLOW_READ 0xC0000000 | 0x0228
#define NT_STATUS_FAIL_CHECK 0xC0000000 | 0x0229
#define NT_STATUS_DUPLICATE_OBJECTID 0xC0000000 | 0x022a
#define NT_STATUS_OBJECTID_EXISTS 0xC0000000 | 0x022b
#define NT_STATUS_CONVERT_TO_LARGE 0xC0000000 | 0x022c
#define NT_STATUS_RETRY 0xC0000000 | 0x022d
#define NT_STATUS_FOUND_OUT_OF_SCOPE 0xC0000000 | 0x022e
#define NT_STATUS_ALLOCATE_BUCKET 0xC0000000 | 0x022f
#define NT_STATUS_PROPSET_NOT_FOUND 0xC0000000 | 0x0230
#define NT_STATUS_MARSHALL_OVERFLOW 0xC0000000 | 0x0231
#define NT_STATUS_INVALID_VARIANT 0xC0000000 | 0x0232
#define NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND 0xC0000000 | 0x0233
#define NT_STATUS_ACCOUNT_LOCKED_OUT 0xC0000000 | 0x0234
#define NT_STATUS_HANDLE_NOT_CLOSABLE 0xC0000000 | 0x0235
#define NT_STATUS_CONNECTION_REFUSED 0xC0000000 | 0x0236
#define NT_STATUS_GRACEFUL_DISCONNECT 0xC0000000 | 0x0237
#define NT_STATUS_ADDRESS_ALREADY_ASSOCIATED 0xC0000000 | 0x0238
#define NT_STATUS_ADDRESS_NOT_ASSOCIATED 0xC0000000 | 0x0239
#define NT_STATUS_CONNECTION_INVALID 0xC0000000 | 0x023a
#define NT_STATUS_CONNECTION_ACTIVE 0xC0000000 | 0x023b
#define NT_STATUS_NETWORK_UNREACHABLE 0xC0000000 | 0x023c
#define NT_STATUS_HOST_UNREACHABLE 0xC0000000 | 0x023d
#define NT_STATUS_PROTOCOL_UNREACHABLE 0xC0000000 | 0x023e
#define NT_STATUS_PORT_UNREACHABLE 0xC0000000 | 0x023f
#define NT_STATUS_REQUEST_ABORTED 0xC0000000 | 0x0240
#define NT_STATUS_CONNECTION_ABORTED 0xC0000000 | 0x0241
#define NT_STATUS_BAD_COMPRESSION_BUFFER 0xC0000000 | 0x0242
#define NT_STATUS_USER_MAPPED_FILE 0xC0000000 | 0x0243
#define NT_STATUS_AUDIT_FAILED 0xC0000000 | 0x0244
#define NT_STATUS_TIMER_RESOLUTION_NOT_SET 0xC0000000 | 0x0245
#define NT_STATUS_CONNECTION_COUNT_LIMIT 0xC0000000 | 0x0246
#define NT_STATUS_LOGIN_TIME_RESTRICTION 0xC0000000 | 0x0247
#define NT_STATUS_LOGIN_WKSTA_RESTRICTION 0xC0000000 | 0x0248
#define NT_STATUS_IMAGE_MP_UP_MISMATCH 0xC0000000 | 0x0249
#define NT_STATUS_INSUFFICIENT_LOGON_INFO 0xC0000000 | 0x0250
#define NT_STATUS_BAD_DLL_ENTRYPOINT 0xC0000000 | 0x0251
#define NT_STATUS_BAD_SERVICE_ENTRYPOINT 0xC0000000 | 0x0252
#define NT_STATUS_LPC_REPLY_LOST 0xC0000000 | 0x0253
#define NT_STATUS_IP_ADDRESS_CONFLICT1 0xC0000000 | 0x0254
#define NT_STATUS_IP_ADDRESS_CONFLICT2 0xC0000000 | 0x0255
#define NT_STATUS_REGISTRY_QUOTA_LIMIT 0xC0000000 | 0x0256
#define NT_STATUS_PATH_NOT_COVERED 0xC0000000 | 0x0257
#define NT_STATUS_NO_CALLBACK_ACTIVE 0xC0000000 | 0x0258
#define NT_STATUS_LICENSE_QUOTA_EXCEEDED 0xC0000000 | 0x0259
#define NT_STATUS_PWD_TOO_SHORT 0xC0000000 | 0x025a
#define NT_STATUS_PWD_TOO_RECENT 0xC0000000 | 0x025b
#define NT_STATUS_PWD_HISTORY_CONFLICT 0xC0000000 | 0x025c
#define NT_STATUS_PLUGPLAY_NO_DEVICE 0xC0000000 | 0x025e
#define NT_STATUS_UNSUPPORTED_COMPRESSION 0xC0000000 | 0x025f
#define NT_STATUS_INVALID_HW_PROFILE 0xC0000000 | 0x0260
#define NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH 0xC0000000 | 0x0261
#define NT_STATUS_DRIVER_ORDINAL_NOT_FOUND 0xC0000000 | 0x0262
#define NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND 0xC0000000 | 0x0263
#define NT_STATUS_RESOURCE_NOT_OWNED 0xC0000000 | 0x0264
#define NT_STATUS_TOO_MANY_LINKS 0xC0000000 | 0x0265
#define NT_STATUS_QUOTA_LIST_INCONSISTENT 0xC0000000 | 0x0266
#define NT_STATUS_FILE_IS_OFFLINE 0xC0000000 | 0x0267
#define NT_STATUS_NO_SUCH_JOB 0xC0000000 | 0xEDE /* scheduler */
#endif /* _NTERR_H */
/*
* fs/cifs/ntlmssp.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma pack(1)
#define NTLMSSP_SIGNATURE "NTLMSSP"
/* Message Types */
#define NtLmNegotiate 1
#define NtLmChallenge 2
#define NtLmAuthenticate 3
#define UnknownMessage 8
/* Negotiate Flags */
#define NTLMSSP_NEGOTIATE_UNICODE 0x01 // Text strings are in unicode
#define NTLMSSP_NEGOTIATE_OEM 0x02 // Text strings are in OEM
#define NTLMSSP_REQUEST_TARGET 0x04 // Server return its auth realm
#define NTLMSSP_NEGOTIATE_SIGN 0x0010 // Request signature capability
#define NTLMSSP_NEGOTIATE_SEAL 0x0020 // Request confidentiality
#define NTLMSSP_NEGOTIATE_DGRAM 0x0040
#define NTLMSSP_NEGOTIATE_LM_KEY 0x0080 // Use LM session key for sign/seal
#define NTLMSSP_NEGOTIATE_NTLM 0x0200 // NTLM authentication
#define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000
#define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000
#define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 // client/server on same machine
#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 // Sign for all security levels
#define NTLMSSP_NEGOTIATE_NTLMV2 0x80000
#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000
#define NTLMSSP_NEGOTIATE_128 0x20000000
#define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000
/* server only negotiate flags */
#define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000 /* NEGOTIATE_DOMAIN 0x1000 ? */
#define NTLMSSP_TARGET_TYPE_SERVER 0x20000 /* NEGOTIATE_WORKSTATION 0x2000 ? */
/* Although typedefs are not commonly used for structure definitions */
/* in the Linux kernel, in this particular case they are useful */
/* to more closely match the standards document for NTLMSSP from */
/* OpenGroup and to make the code more closely match the standard in */
/* appearance */
typedef struct _SECURITY_BUFFER {
__u16 Length;
__u16 MaximumLength;
__u32 Buffer; /* offset to buffer */
} SECURITY_BUFFER;
typedef struct _NEGOTIATE_MESSAGE {
__u8 Signature[sizeof (NTLMSSP_SIGNATURE)];
__u32 MessageType;
__u32 NegotiateFlags;
SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */
char DomainString[0];
/* followed by WorkstationString */
} NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE;
typedef struct _CHALLENGE_MESSAGE {
__u8 Signature[sizeof (NTLMSSP_SIGNATURE)];
__u32 MessageType;
SECURITY_BUFFER TargetName;
__u32 NegotiateFlags;
__u8 Challenge[CIFS_CRYPTO_KEY_SIZE];
__u8 Reserved[8];
SECURITY_BUFFER TargetInfoArray;
} CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE;
typedef struct _AUTHENTICATE_MESSAGE {
__u8 Signature[sizeof (NTLMSSP_SIGNATURE)];
__u32 MessageType;
SECURITY_BUFFER LmChallengeResponse;
SECURITY_BUFFER NtChallengeResponse;
SECURITY_BUFFER DomainName;
SECURITY_BUFFER UserName;
SECURITY_BUFFER WorkstationName;
SECURITY_BUFFER SessionKey;
__u32 NegotiateFlags;
char UserString[0];
} AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
#pragma pack() /* resume default structure packing */
/*
Unix SMB/Netbios implementation.
Version 1.9.
a partial implementation of DES designed for use in the
SMB authentication protocol
Copyright (C) Andrew Tridgell 1998
Modified by Steve French (sfrench@us.ibm.com) 2002
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.
*/
/* NOTES:
This code makes no attempt to be fast! In fact, it is a very
slow implementation
This code is NOT a complete DES implementation. It implements only
the minimum necessary for SMB authentication, as used by all SMB
products (including every copy of Microsoft Windows95 ever sold)
In particular, it can only do a unchained forward DES pass. This
means it is not possible to use this code for encryption/decryption
of data, instead it is only useful as a "hash" algorithm.
There is no entry point into this code that allows normal DES operation.
I believe this means that this code does not come under ITAR
regulations but this is NOT a legal opinion. If you are concerned
about the applicability of ITAR regulations to this code then you
should confirm it for yourself (and maybe let me know if you come
up with a different answer to the one above)
*/
#define uchar unsigned char
static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27,
19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15,
7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4
};
static uchar perm2[48] = { 14, 17, 11, 24, 1, 5,
3, 28, 15, 6, 21, 10,
23, 19, 12, 4, 26, 8,
16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55,
30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53,
46, 42, 50, 36, 29, 32
};
static uchar perm3[64] = { 58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7
};
static uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13,
12, 13, 14, 15, 16, 17,
16, 17, 18, 19, 20, 21,
20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29,
28, 29, 30, 31, 32, 1
};
static uchar perm5[32] = { 16, 7, 20, 21,
29, 12, 28, 17,
1, 15, 23, 26,
5, 18, 31, 10,
2, 8, 24, 14,
32, 27, 3, 9,
19, 13, 30, 6,
22, 11, 4, 25
};
static uchar perm6[64] = { 40, 8, 48, 16, 56, 24, 64, 32,
39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30,
37, 5, 45, 13, 53, 21, 61, 29,
36, 4, 44, 12, 52, 20, 60, 28,
35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26,
33, 1, 41, 9, 49, 17, 57, 25
};
static uchar sc[16] = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
static uchar sbox[8][4][16] = {
{{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7},
{0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},
{4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},
{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}},
{{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10},
{3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},
{0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15},
{13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}},
{{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8},
{13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1},
{13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7},
{1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}},
{{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15},
{13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9},
{10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4},
{3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}},
{{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9},
{14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6},
{4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14},
{11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}},
{{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11},
{10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8},
{9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6},
{4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}},
{{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1},
{13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6},
{1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2},
{6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}},
{{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7},
{1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2},
{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}
};
static void
permute(char *out, char *in, uchar * p, int n)
{
int i;
for (i = 0; i < n; i++)
out[i] = in[p[i] - 1];
}
static void
lshift(char *d, int count, int n)
{
char out[64];
int i;
for (i = 0; i < n; i++)
out[i] = d[(i + count) % n];
for (i = 0; i < n; i++)
d[i] = out[i];
}
static void
concat(char *out, char *in1, char *in2, int l1, int l2)
{
while (l1--)
*out++ = *in1++;
while (l2--)
*out++ = *in2++;
}
static void
xor(char *out, char *in1, char *in2, int n)
{
int i;
for (i = 0; i < n; i++)
out[i] = in1[i] ^ in2[i];
}
static void
dohash(char *out, char *in, char *key, int forw)
{
int i, j, k;
char pk1[56];
char c[28];
char d[28];
char cd[56];
char ki[16][48];
char pd1[64];
char l[32], r[32];
char rl[64];
permute(pk1, key, perm1, 56);
for (i = 0; i < 28; i++)
c[i] = pk1[i];
for (i = 0; i < 28; i++)
d[i] = pk1[i + 28];
for (i = 0; i < 16; i++) {
lshift(c, sc[i], 28);
lshift(d, sc[i], 28);
concat(cd, c, d, 28, 28);
permute(ki[i], cd, perm2, 48);
}
permute(pd1, in, perm3, 64);
for (j = 0; j < 32; j++) {
l[j] = pd1[j];
r[j] = pd1[j + 32];
}
for (i = 0; i < 16; i++) {
char er[48];
char erk[48];
char b[8][6];
char cb[32];
char pcb[32];
char r2[32];
permute(er, r, perm4, 48);
xor(erk, er, ki[forw ? i : 15 - i], 48);
for (j = 0; j < 8; j++)
for (k = 0; k < 6; k++)
b[j][k] = erk[j * 6 + k];
for (j = 0; j < 8; j++) {
int m, n;
m = (b[j][0] << 1) | b[j][5];
n = (b[j][1] << 3) | (b[j][2] << 2) | (b[j][3] <<
1) | b[j][4];
for (k = 0; k < 4; k++)
b[j][k] =
(sbox[j][m][n] & (1 << (3 - k))) ? 1 : 0;
}
for (j = 0; j < 8; j++)
for (k = 0; k < 4; k++)
cb[j * 4 + k] = b[j][k];
permute(pcb, cb, perm5, 32);
xor(r2, l, pcb, 32);
for (j = 0; j < 32; j++)
l[j] = r[j];
for (j = 0; j < 32; j++)
r[j] = r2[j];
}
concat(rl, r, l, 32, 32);
permute(out, rl, perm6, 64);
}
static void
str_to_key(unsigned char *str, unsigned char *key)
{
int i;
key[0] = str[0] >> 1;
key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2);
key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3);
key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4);
key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5);
key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
key[7] = str[6] & 0x7F;
for (i = 0; i < 8; i++) {
key[i] = (key[i] << 1);
}
}
static void
smbhash(unsigned char *out, unsigned char *in, unsigned char *key, int forw)
{
int i;
char outb[64];
char inb[64];
char keyb[64];
unsigned char key2[8];
str_to_key(key, key2);
for (i = 0; i < 64; i++) {
inb[i] = (in[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
keyb[i] = (key2[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
outb[i] = 0;
}
dohash(outb, inb, keyb, forw);
for (i = 0; i < 8; i++) {
out[i] = 0;
}
for (i = 0; i < 64; i++) {
if (outb[i])
out[i / 8] |= (1 << (7 - (i % 8)));
}
}
void
E_P16(unsigned char *p14, unsigned char *p16)
{
unsigned char sp8[8] =
{ 0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
smbhash(p16, sp8, p14, 1);
smbhash(p16 + 8, sp8, p14 + 7, 1);
}
void
E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24)
{
smbhash(p24, c8, p21, 1);
smbhash(p24 + 8, c8, p21 + 7, 1);
smbhash(p24 + 16, c8, p21 + 14, 1);
}
void
D_P16(unsigned char *p14, unsigned char *in, unsigned char *out)
{
smbhash(out, in, p14, 0);
smbhash(out + 8, in + 8, p14 + 7, 0);
}
void
E_old_pw_hash(unsigned char *p14, unsigned char *in, unsigned char *out)
{
smbhash(out, in, p14, 1);
smbhash(out + 8, in + 8, p14 + 7, 1);
}
void
cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key)
{
unsigned char buf[8];
smbhash(buf, in, key, 1);
smbhash(out, buf, key + 9, 1);
}
void
cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key)
{
unsigned char buf[8];
static unsigned char key2[8];
smbhash(buf, in, key, 1);
key2[0] = key[7];
smbhash(out, buf, key2, 1);
}
void
cred_hash3(unsigned char *out, unsigned char *in, unsigned char *key, int forw)
{
static unsigned char key2[8];
smbhash(out, in, key, forw);
key2[0] = key[7];
smbhash(out + 8, in + 8, key2, forw);
}
void
SamOEMhash(unsigned char *data, unsigned char *key, int val)
{
unsigned char s_box[256];
unsigned char index_i = 0;
unsigned char index_j = 0;
unsigned char j = 0;
int ind;
for (ind = 0; ind < 256; ind++) {
s_box[ind] = (unsigned char) ind;
}
for (ind = 0; ind < 256; ind++) {
unsigned char tc;
j += (s_box[ind] + key[ind % 16]);
tc = s_box[ind];
s_box[ind] = s_box[j];
s_box[j] = tc;
}
for (ind = 0; ind < (val ? 516 : 16); ind++) {
unsigned char tc;
unsigned char t;
index_i++;
index_j += s_box[index_i];
tc = s_box[index_i];
s_box[index_i] = s_box[index_j];
s_box[index_j] = tc;
t = s_box[index_i] + s_box[index_j];
data[ind] = data[ind] ^ s_box[t];
}
}
/*
Unix SMB/Netbios implementation.
Version 1.9.
SMB parameters and setup
Copyright (C) Andrew Tridgell 1992-2000
Copyright (C) Luke Kenneth Casson Leighton 1996-2000
Modified by Jeremy Allison 1995.
Modified by Steve French (sfrench@us.ibm.com) 2002
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.
*/
extern int DEBUGLEVEL;
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/random.h>
#include "cifs_unicode.h"
#include "cifspdu.h"
#include "md5.h"
#include "cifs_debug.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* following came from the other byteorder.h to avoid include conflicts */
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val)))
#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((__u32)(val)))
/*The following definitions come from lib/md4.c */
void mdfour(unsigned char *out, unsigned char *in, int n);
/*The following definitions come from libsmb/smbdes.c */
void E_P16(unsigned char *p14, unsigned char *p16);
void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out);
void E_old_pw_hash(unsigned char *p14, unsigned char *in, unsigned char *out);
void cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key);
void cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key);
void cred_hash3(unsigned char *out, unsigned char *in, unsigned char *key,
int forw);
void SamOEMhash(unsigned char *data, unsigned char *key, int val);
/*The following definitions come from libsmb/smbencrypt.c */
void SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
void E_md4hash(const unsigned char *passwd, unsigned char *p16);
void nt_lm_owf_gen(char *pwd, unsigned char nt_p16[16], unsigned char p16[16]);
void SMBOWFencrypt(unsigned char passwd[16], unsigned char *c8,
unsigned char p24[24]);
void NTLMSSPOWFencrypt(unsigned char passwd[8],
unsigned char *ntlmchalresp, unsigned char p24[24]);
void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
int make_oem_passwd_hash(char data[516], const char *passwd,
unsigned char old_pw_hash[16], int unicode);
int decode_pw_buffer(char in_buffer[516], char *new_pwrd,
int new_pwrd_size, __u32 * new_pw_len);
/*
This implements the X/Open SMB password encryption
It takes a password, a 8 byte "crypt key" and puts 24 bytes of
encrypted password into p24 */
/* Note that password must be uppercased and null terminated */
void
SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24)
{
unsigned char p14[15], p21[21];
memset(p21, '\0', 21);
memset(p14, '\0', 14);
strncpy((char *) p14, (char *) passwd, 14);
/* strupper((char *)p14); *//* BB at least uppercase the easy range */
E_P16(p14, p21);
SMBOWFencrypt(p21, c8, p24);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("SMBencrypt: lm#, challenge, response\n"));
dump_data(100, (char *) p21, 16);
dump_data(100, (char *) c8, 8);
dump_data(100, (char *) p24, 24);
#endif
}
/* Routines for Windows NT MD4 Hash functions. */
static int
_my_wcslen(__u16 * str)
{
int len = 0;
while (*str++ != 0)
len++;
return len;
}
/*
* Convert a string into an NT UNICODE string.
* Note that regardless of processor type
* this must be in intel (little-endian)
* format.
*/
static int
_my_mbstowcs(__u16 * dst, const unsigned char *src, int len)
{ /* not a very good conversion routine - change/fix */
int i;
__u16 val;
for (i = 0; i < len; i++) {
val = *src;
SSVAL(dst, 0, val);
dst++;
src++;
if (val == 0)
break;
}
return i;
}
/*
* Creates the MD4 Hash of the users password in NT UNICODE.
*/
void
E_md4hash(const unsigned char *passwd, unsigned char *p16)
{
int len;
__u16 wpwd[129];
/* Password cannot be longer than 128 characters */
len = strlen((char *) passwd);
if (len > 128)
len = 128;
/* Password must be converted to NT unicode */
_my_mbstowcs(wpwd, passwd, len);
wpwd[len] = 0; /* Ensure string is null terminated */
/* Calculate length in bytes */
len = _my_wcslen(wpwd) * sizeof (__u16);
mdfour(p16, (unsigned char *) wpwd, len);
}
/* Does both the NT and LM owfs of a user's password */
void
nt_lm_owf_gen(char *pwd, unsigned char nt_p16[16], unsigned char p16[16])
{
char passwd[514];
memset(passwd, '\0', 514);
if (strlen(pwd) < 513)
strcpy(passwd, pwd);
else
memcpy(passwd, pwd, 512);
/* Calculate the MD4 hash (NT compatible) of the password */
memset(nt_p16, '\0', 16);
E_md4hash(passwd, nt_p16);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("nt_lm_owf_gen: pwd, nt#\n"));
dump_data(120, passwd, strlen(passwd));
dump_data(100, (char *) nt_p16, 16);
#endif
/* Mangle the passwords into Lanman format */
passwd[14] = '\0';
/* strupper(passwd); */
/* Calculate the SMB (lanman) hash functions of the password */
memset(p16, '\0', 16);
E_P16((unsigned char *) passwd, (unsigned char *) p16);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("nt_lm_owf_gen: pwd, lm#\n"));
dump_data(120, passwd, strlen(passwd));
dump_data(100, (char *) p16, 16);
#endif
/* clear out local copy of user's password (just being paranoid). */
memset(passwd, '\0', sizeof (passwd));
}
/* Does the NTLMv2 owfs of a user's password */
void
ntv2_owf_gen(const unsigned char owf[16], const char *user_n,
const char *domain_n, unsigned char kr_buf[16],
const struct nls_table *nls_codepage)
{
wchar_t user_u[1024];
wchar_t dom_u[1024];
struct HMACMD5Context ctx;
/* push_ucs2(NULL, user_u, user_n, (user_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER);
push_ucs2(NULL, dom_u, domain_n, (domain_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER); */
/* do not think it is supposed to be uppercased */
int user_l = cifs_strtoUCS(user_u, user_n, 511, nls_codepage);
int domain_l = cifs_strtoUCS(dom_u, domain_n, 511, nls_codepage);
user_l++; /* trailing null */
domain_l++;
hmac_md5_init_limK_to_64(owf, 16, &ctx);
hmac_md5_update((const unsigned char *) user_u, user_l * 2, &ctx);
hmac_md5_update((const unsigned char *) dom_u, domain_l * 2, &ctx);
hmac_md5_final(kr_buf, &ctx);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("ntv2_owf_gen: user, domain, owfkey, kr\n"));
dump_data(100, user_u, user_l * 2);
dump_data(100, dom_u, domain_l * 2);
dump_data(100, owf, 16);
dump_data(100, kr_buf, 16);
#endif
}
/* Does the des encryption from the NT or LM MD4 hash. */
void
SMBOWFencrypt(unsigned char passwd[16], unsigned char *c8,
unsigned char p24[24])
{
unsigned char p21[21];
memset(p21, '\0', 21);
memcpy(p21, passwd, 16);
E_P24(p21, c8, p24);
}
/* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */
void
NTLMSSPOWFencrypt(unsigned char passwd[8],
unsigned char *ntlmchalresp, unsigned char p24[24])
{
unsigned char p21[21];
memset(p21, '\0', 21);
memcpy(p21, passwd, 8);
memset(p21 + 8, 0xbd, 8);
E_P24(p21, ntlmchalresp, p24);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("NTLMSSPOWFencrypt: p21, c8, p24\n"));
dump_data(100, (char *) p21, 21);
dump_data(100, (char *) ntlmchalresp, 8);
dump_data(100, (char *) p24, 24);
#endif
}
/* Does the NT MD4 hash then des encryption. */
void
SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24)
{
unsigned char p21[21];
memset(p21, '\0', 21);
E_md4hash(passwd, p21);
SMBOWFencrypt(p21, c8, p24);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("SMBNTencrypt: nt#, challenge, response\n"));
dump_data(100, (char *) p21, 16);
dump_data(100, (char *) c8, 8);
dump_data(100, (char *) p24, 24);
#endif
}
int
make_oem_passwd_hash(char data[516], const char *passwd,
unsigned char old_pw_hash[16], int unicode)
{
int new_pw_len = strlen(passwd) * (unicode ? 2 : 1);
if (new_pw_len > 512) {
cERROR(1,
("CIFS make_oem_passwd_hash: new password is too long.\n"));
return FALSE;
}
/*
* Now setup the data area.
* We need to generate a random fill
* for this area to make it harder to
* decrypt. JRA.
*
*/
get_random_bytes(data, sizeof (data));
if (unicode) {
/* Note that passwd should be in DOS oem character set. */
/* dos_struni2( &data[512 - new_pw_len], passwd, 512); */
cifs_strtoUCS((wchar_t *) & data[512 - new_pw_len], passwd, 512, /* struct nls_table */
load_nls_default());
/* BB call unload_nls now or get nls differntly */
} else {
/* Note that passwd should be in DOS oem character set. */
strcpy(&data[512 - new_pw_len], passwd);
}
SIVAL(data, 512, new_pw_len);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("make_oem_passwd_hash\n"));
dump_data(100, data, 516);
#endif
SamOEMhash((unsigned char *) data, (unsigned char *) old_pw_hash, TRUE);
return TRUE;
}
/* Does the md5 encryption from the NT hash for NTLMv2. */
void
SMBOWFencrypt_ntv2(const unsigned char kr[16],
const struct data_blob srv_chal,
const struct data_blob cli_chal, unsigned char resp_buf[16])
{
struct HMACMD5Context ctx;
hmac_md5_init_limK_to_64(kr, 16, &ctx);
hmac_md5_update(srv_chal.data, srv_chal.length, &ctx);
hmac_md5_update(cli_chal.data, cli_chal.length, &ctx);
hmac_md5_final(resp_buf, &ctx);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("SMBOWFencrypt_ntv2: srv_chal, cli_chal, resp_buf\n"));
dump_data(100, srv_chal.data, srv_chal.length);
dump_data(100, cli_chal.data, cli_chal.length);
dump_data(100, resp_buf, 16);
#endif
}
void
SMBsesskeygen_ntv2(const unsigned char kr[16],
const unsigned char *nt_resp, __u8 sess_key[16])
{
struct HMACMD5Context ctx;
hmac_md5_init_limK_to_64(kr, 16, &ctx);
hmac_md5_update(nt_resp, 16, &ctx);
hmac_md5_final((unsigned char *) sess_key, &ctx);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("SMBsesskeygen_ntv2:\n"));
dump_data(100, sess_key, 16);
#endif
}
void
SMBsesskeygen_ntv1(const unsigned char kr[16],
const unsigned char *nt_resp, __u8 sess_key[16])
{
mdfour((unsigned char *) sess_key, (unsigned char *) kr, 16);
#ifdef DEBUG_PASSWORD
DEBUG(100, ("SMBsesskeygen_ntv1:\n"));
dump_data(100, sess_key, 16);
#endif
}
/***********************************************************
encode a password buffer. The caller gets to figure out
what to put in it.
************************************************************/
int
encode_pw_buffer(char buffer[516], char *new_pw, int new_pw_length)
{
get_random_bytes(buffer, sizeof (buffer));
memcpy(&buffer[512 - new_pw_length], new_pw, new_pw_length);
/*
* The length of the new password is in the last 4 bytes of
* the data buffer.
*/
SIVAL(buffer, 512, new_pw_length);
return TRUE;
}
/***********************************************************
SMB signing - setup the MAC key.
************************************************************/
void
cli_calculate_mac_key(__u8 * mac_key, int *pmac_key_len,
const char *ntpasswd, const unsigned char resp[24])
{
/* Get first 16 bytes. */
E_md4hash(ntpasswd, mac_key);
memcpy(mac_key + 16, resp, 24);
*pmac_key_len = 40;
/* Reset the sequence number in case we had a previous (aborted) attempt */
/* cli->sign_info.send_seq_num = 0; */
}
/***********************************************************
SMB signing - calculate a MAC to send.
************************************************************/
void
cli_caclulate_sign_mac(struct smb_hdr *outbuf, __u8 * mac_key,
int mac_key_len, __u32 * send_seq_num,
__u32 * reply_seq_num)
{
unsigned char calc_md5_mac[16];
struct MD5Context md5_ctx;
/* if (!cli->sign_info.use_smb_signing) {
return;
} */
/*
* Firstly put the sequence number into the first 4 bytes.
* and zero out the next 4 bytes.
*/
/*
SIVAL(outbuf, smb_ss_field, *send_seq_num);
SIVAL(outbuf, smb_ss_field + 4, 0); */
/* Calculate the 16 byte MAC and place first 8 bytes into the field. */
MD5Init(&md5_ctx);
MD5Update(&md5_ctx, mac_key, mac_key_len);
MD5Update(&md5_ctx, outbuf->Protocol,
be32_to_cpu(outbuf->smb_buf_length));
MD5Final(calc_md5_mac, &md5_ctx);
memcpy(outbuf->SecuritySignature, calc_md5_mac, 8);
(*send_seq_num)++;
*reply_seq_num = *send_seq_num;
(*send_seq_num)++;
}
/*
* fs/cifs/smberr.h
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* See Error Codes section of the SNIA CIFS Specification
* for more information
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define SUCCESS 0 /* The request was successful. */
#define ERRDOS 0x01 /* Error is from the core DOS operating system set */
#define ERRSRV 0x02 /* Error is generated by the file server daemon */
#define ERRHRD 0x03 /* Error is a hardware error. */
#define ERRCMD 0xFF /* Command was not in the "SMB" format. */
/* The following error codes may be generated with the SUCCESS error class.*/
#define SUCCESS 0 /* The request was successful. */
/* The following error codes may be generated with the ERRDOS error class.*/
#define ERRbadfunc 1 /* Invalid function. The server did not recognize or could not perform a system call generated by the server, e.g., set the DIRECTORY attribute on a data file, invalid seek mode. */
#define ERRbadfile 2 /*File not found. The last component of a file's pathname could not be found. */
#define ERRbadpath 3 /* Directory invalid. A directory component in a pathname could not be found. */
#define ERRnofids 4 /* Too many open files. The server has no file handles available. */
#define ERRnoaccess 5 /* Access denied, the client's context does not permit the requested function. This includes the following conditions: invalid rename command, write to Fid open for read only, read on Fid open for write only, attempt to delete a non-empty directory */
#define ERRbadfid 6 /* Invalid file handle. The file handle specified was not recognized by the server. */
#define ERRbadmcb 7 /* Memory control blocks destroyed. */
#define ERRnomem 8 /* Insufficient server memory to perform the requested function. */
#define ERRbadmem 9 /* Invalid memory block address. */
#define ERRbadenv 10 /* Invalid environment. */
#define ERRbadformat 11 /* Invalid format. */
#define ERRbadaccess 12 /* Invalid open mode. */
#define ERRbaddata 13 /* Invalid data (generated only by IOCTL calls within the server). */
#define ERRbaddrive 15 /* Invalid drive specified. */
#define ERRremcd 16 /* A Delete Directory request attempted to remove the server's current directory. */
#define ERRdiffdevice 17 /* Not same device (e.g., a cross volume rename was attempted */
#define ERRnofiles 18 /* A File Search command can find no more files matching the specified criteria. */
#define ERRgeneral 31
#define ERRbadshare 32 /* The sharing mode specified for an Open conflicts with existing FIDs on the file. */
#define ERRlock 33 /* A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process. */
#define ERRunsup 50
#define ERRnosuchshare 67
#define ERRfilexists 80 /* The file named in the request already exists. */
#define ERRinvparm 87
#define ERRdiskfull 112
#define ERRinvnum 123
#define ERRdirnotempty 145
#define ERRnotlocked 158
#define ERRalreadyexists 183
#define ERRbadpipe 230
#define ERRpipebusy 231
#define ERRpipeclosing 232
#define ERRnotconnected 233
#define ERRmoredata 234
#define ErrQuota 0x200 /* The operation would cause a quota limit to be exceeded. */
#define ErrNotALink 0x201 /* A link operation was performed on a pathname that
was not a link. */
/* Following error codes may be generated with the ERRSRV error
class.*/
#define ERRerror 1 /* Non-specific error code. It is returned under the following conditions: resource other than disk space exhausted (e.g. TIDs), first SMB command was not negotiate, multiple negotiates attempted, and internal server error. */
#define ERRbadpw 2 /* Bad password - name/password pair in a TreeConnect or Session Setup are invalid. */
#define ERRbadtype 3 /* used for indicating DFS referral needed */
#define ERRaccess 4 /* The client does not have the necessary access rights within the specified context for requested function. */
#define ERRinvtid 5 /* The Tid specified in a command was invalid. */
#define ERRinvnetname 6 /* Invalid network name in tree connect. */
#define ERRinvdevice 7 /* Invalid device - printer request made to non-printer connection or non-printer request made to printer connection. */
#define ERRqfull 49 /* Print queue full (files) -- returned by open print file. */
#define ERRqtoobig 50 /* Print queue full -- no space. */
#define ERRqeof 51 /* EOF on print queue dump */
#define ERRinvpfid 52 /* Invalid print file FID. */
#define ERRsmbcmd 64 /* The server did not recognize the command received. */
#define ERRsrverror 65 /* The server encountered an internal error, e.g., system file unavailable. */
#define ERRbadBID 66 /* (obsolete) */
#define ERRfilespecs 67 /* The Fid and pathname parameters contained an invalid combination of values. */
#define ERRbadLink 68 /* (obsolete) */
#define ERRbadpermits 69 /* The access permissions specified for a file or directory are not a valid combination. */
#define ERRbadPID 70
#define ERRsetattrmode 71 /* attribute (mode) is invalid */
#define ERRpaused 81 /* Server is paused */
#define ERRmsgoff 82 /* reserved - messaging off */
#define ERRnoroom 83 /* reserved - no room for message */
#define ERRrmuns 87 /* reserved - too many remote names */
#define ERRtimeout 88 /* operation timed out */
#define ERRnoresource 89 /* No resources available for request */
#define ERRtoomanyuids 90 /* Too many UIDs active on this session */
#define ERRbaduid 91 /* The UID is not known as a valid user */
#define ERRusempx 250 /* temporarily unable to use raw */
#define ERRusestd 251 /* temporarily unable to use either raw or mpx */
#define ERR_NOTIFY_ENUM_DIR 1024
#define ERRaccountexpired 2239
#define ERRbadclient 2240
#define ERRbadLogonTime 2241
#define ERRpasswordExpired 2242
#define ERRnosupport 0xFFFF
/*
* fs/cifs/transport.c
*
* Copyright (c) International Business Machines Corp., 2002
* Author(s): Steve French (sfrench@us.ibm.com)
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/wait.h>
#include <linux/net.h>
#include <linux/version.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
#include "cifspdu.h"
#include "cifsglob.h"
#include "cifsproto.h"
#include "cifs_debug.h"
extern kmem_cache_t *cifs_mid_cachep;
struct mid_q_entry *
AllocMidQEntry(struct smb_hdr *smb_buffer, struct cifsSesInfo *ses)
{
struct mid_q_entry *temp;
/* BB add spinlock to protect midq for each session BB */
if (ses == NULL) {
cERROR(1, ("\nNull session passed in to AllocMidQEntry "));
return NULL;
}
temp = kmalloc(sizeof (struct mid_q_entry), GFP_KERNEL);
temp = (struct mid_q_entry *) kmem_cache_alloc(cifs_mid_cachep,
SLAB_KERNEL);
if (temp == NULL)
return temp;
else {
memset(temp, 0, sizeof (struct mid_q_entry));
temp->mid = smb_buffer->Mid; /* always LE */
temp->pid = current->pid;
temp->command = smb_buffer->Command;
cFYI(1, ("\nFor smb_command %d", temp->command));
do_gettimeofday(&temp->when_sent);
temp->ses = ses;
temp->tsk = current;
}
if (ses->status == CifsGood) {
list_add_tail(&temp->qhead, &ses->server->pending_mid_q);
atomic_inc(&midCount);
temp->midState = MID_REQUEST_ALLOCATED;
} else { /* BB add reconnect code here BB */
cERROR(1,
("\nNeed to reconnect after session died to server\n"));
if (temp)
kmem_cache_free(cifs_mid_cachep, temp);
return NULL;
}
return temp;
}
void
DeleteMidQEntry(struct mid_q_entry *midEntry)
{
/* BB add spinlock to protect midq for each session BB */
midEntry->midState = MID_FREE;
buf_release(midEntry->resp_buf);
list_del(&midEntry->qhead);
kmem_cache_free(cifs_mid_cachep, midEntry);
atomic_dec(&midCount);
}
int
smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer,
unsigned int smb_buf_length, struct sockaddr *sin)
{
int rc = 0;
struct msghdr smb_msg;
struct iovec iov;
mm_segment_t temp_fs;
if(ssocket == NULL)
return -ENOTSOCK; /* BB eventually add reconnect code here */
/* ssocket->sk->allocation = GFP_BUFFER; *//* BB is this spurious? */
iov.iov_base = smb_buffer;
iov.iov_len = smb_buf_length + 4;
smb_msg.msg_name = sin;
smb_msg.msg_namelen = sizeof (struct sockaddr);
smb_msg.msg_iov = &iov;
smb_msg.msg_iovlen = 1;
smb_msg.msg_control = NULL;
smb_msg.msg_controllen = 0;
smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; /* BB add more flags? */
/* smb header is converted in header_assemble. bcc and rest of SMB word area,
and byte area if necessary, is converted to littleendian in cifssmb.c and RFC1001
len is converted to bigendian in smb_send */
if (smb_buf_length > 12)
smb_buffer->Flags2 = cpu_to_le16(smb_buffer->Flags2);
/* if(smb_buffer->Flags2 & SMBFLG2_SECURITY_SIGNATURE)
sign_smb(smb_buffer); */ /* BB enable when signing tested more */
smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length);
cFYI(1, ("\nSending smb of length %d ", smb_buf_length));
dump_smb(smb_buffer, smb_buf_length + 4);
temp_fs = get_fs(); /* we must turn off socket api parm checking */
set_fs(get_ds());
rc = sock_sendmsg(ssocket, &smb_msg, smb_buf_length + 4);
set_fs(temp_fs);
if (rc < 0) {
cERROR(1,
("\nError %d sending data on socket to server.\n", rc));
} else
rc = 0;
return rc;
}
int
SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
struct smb_hdr *in_buf, struct smb_hdr *out_buf,
int *pbytes_returned, const int long_op)
{
int rc = 0;
int receive_len;
long timeout;
struct mid_q_entry *midQ;
midQ = AllocMidQEntry(in_buf, ses);
if (midQ == NULL)
return -EIO; /* reconnect should be done, if possible, in AllocMidQEntry */
if (in_buf->smb_buf_length > CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE) {
cERROR(1,
("\nIllegal length, greater than maximum frame, %d ",
in_buf->smb_buf_length));
DeleteMidQEntry(midQ);
return -EIO;
}
midQ->midState = MID_REQUEST_SUBMITTED;
rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length,
(struct sockaddr *) &(ses->server->sockAddr));
cFYI(1, ("\ncifs smb_send rc %d", rc)); /* BB remove */
/* BB add code to wait for response and copy to out_buf */
if (long_op > 1) /* writes past end of file can take a looooooong time */
timeout = 300 * HZ;
else if (long_op == 1)
timeout = 60 * HZ;
else
timeout = 15 * HZ;
/* wait for 15 seconds or until woken up due to response arriving or due to
last connection to this server being unmounted */
/* timeout = interruptible_sleep_on_timeout(&ses->server->response_q,timeout); */
/* Replace above line with wait_event to get rid of sleep_on per lk guidelines */
timeout = wait_event_interruptible_timeout(ses->server->response_q,
midQ->
midState &
MID_RESPONSE_RECEIVED,
15 * HZ);
cFYI(1,
(" with timeout %ld and Out_buf: %p midQ->resp_buf: %p ", timeout,
out_buf, midQ->resp_buf));
if (signal_pending(current)) {
cERROR(1, (KERN_ERR "\nCIFS: caught signal"));
DeleteMidQEntry(midQ);
return -EINTR;
} else {
if (midQ->resp_buf)
receive_len =
be32_to_cpu(midQ->resp_buf->smb_buf_length);
else {
DeleteMidQEntry(midQ);
return -EIO;
}
}
if (timeout == 0) {
cFYI(1,
("\nTimeout on receive. Assume response SMB is invalid.\n"));
rc = -ETIMEDOUT;
} else if (receive_len > CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE) {
cERROR(1,
("\nFrame too large received. Length: %d Xid: %d\n",
receive_len, xid));
rc = -EIO;
} else { /* rcvd frame is ok */
if (midQ->resp_buf && out_buf
&& (midQ->midState == MID_RESPONSE_RECEIVED)) {
memcpy(out_buf, midQ->resp_buf,
receive_len +
4 /* include 4 byte RFC1001 header */ );
/* convert the length back to a form that we can use */
dump_smb(out_buf, 92);
out_buf->smb_buf_length =
be32_to_cpu(out_buf->smb_buf_length);
if (out_buf->smb_buf_length > 12)
out_buf->Flags2 = le16_to_cpu(out_buf->Flags2);
if (out_buf->smb_buf_length > 28)
out_buf->Pid = le16_to_cpu(out_buf->Pid);
if (out_buf->smb_buf_length > 28)
out_buf->PidHigh =
le16_to_cpu(out_buf->PidHigh);
*pbytes_returned = out_buf->smb_buf_length;
/* BB special case reconnect tid and reconnect uid here? */
rc = map_smb_to_linux_error(out_buf); /* BB watch endianness here BB */
/* convert ByteCount if necessary */
if (receive_len >=
sizeof (struct smb_hdr) -
4 /* do not count RFC1001 header */ +
(2 * out_buf->WordCount) + 2 /* bcc */ )
BCC(out_buf) = le16_to_cpu(BCC(out_buf));
} else
rc = -EIO;
}
DeleteMidQEntry(midQ); /* BB what if process is killed ? - BB add background daemon to clean up Mid entries from killed processes BB test killing process with active mid */
return rc;
}
...@@ -12,7 +12,7 @@ fi ...@@ -12,7 +12,7 @@ fi
# msdos and Joliet want NLS # msdos and Joliet want NLS
if [ "$CONFIG_JOLIET" = "y" -o "$CONFIG_FAT_FS" != "n" \ if [ "$CONFIG_JOLIET" = "y" -o "$CONFIG_FAT_FS" != "n" \
-o "$CONFIG_NTFS_FS" != "n" -o "$CONFIG_NCPFS_NLS" = "y" \ -o "$CONFIG_NTFS_FS" != "n" -o "$CONFIG_NCPFS_NLS" = "y" \
-o "$CONFIG_SMB_NLS" = "y" -o "$CONFIG_JFS_FS" != "n" ]; then -o "$CONFIG_SMB_NLS" = "y" -o "$CONFIG_JFS_FS" != "n" -o "$CONFIG_CIFS" != "n"]; then
define_bool CONFIG_NLS y define_bool CONFIG_NLS y
else else
define_bool CONFIG_NLS n define_bool CONFIG_NLS n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment