Commit f3ea5972 authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6:
  cifs: use CreationTime like an i_generation field
  cifs: switch cifs_open and cifs_create to use CIFSSMBUnixSetFileInfo
  cifs: show "acl" in DebugData Features when it's compiled in
  cifs: move "ntlmssp" and "local_leases" options out of experimental code
  cifs: replace some hardcoded values with preprocessor constants
  cifs: remove unnecessary locking around sequence_number
  [CIFS] Fix minor merge conflict in fs/cifs/dir.c
  CIFS: Simplify cifs_open code
  CIFS: Simplify non-posix open stuff (try #2)
  CIFS: Add match_port check during looking for an existing connection (try #4)
  CIFS: Simplify ipv*_connect functions into one (try #4)
  cifs: Support NTLM2 session security during NTLMSSP authentication [try #5]
  cifs: don't overwrite dentry name in d_revalidate
parents f9f265f3 20054bd6
...@@ -64,7 +64,9 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data, ...@@ -64,7 +64,9 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t maxbuf) void *buffer, uint16_t maxbuf)
{ {
const struct TCP_Server_Info *server = cookie_netfs_data; const struct TCP_Server_Info *server = cookie_netfs_data;
const struct sockaddr *sa = (struct sockaddr *) &server->addr.sockAddr; const struct sockaddr *sa = (struct sockaddr *) &server->dstaddr;
const struct sockaddr_in *addr = (struct sockaddr_in *) sa;
const struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) sa;
struct cifs_server_key *key = buffer; struct cifs_server_key *key = buffer;
uint16_t key_len = sizeof(struct cifs_server_key); uint16_t key_len = sizeof(struct cifs_server_key);
...@@ -76,16 +78,16 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data, ...@@ -76,16 +78,16 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
*/ */
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_INET: case AF_INET:
key->family = server->addr.sockAddr.sin_family; key->family = sa->sa_family;
key->port = server->addr.sockAddr.sin_port; key->port = addr->sin_port;
key->addr[0].ipv4_addr = server->addr.sockAddr.sin_addr; key->addr[0].ipv4_addr = addr->sin_addr;
key_len += sizeof(key->addr[0].ipv4_addr); key_len += sizeof(key->addr[0].ipv4_addr);
break; break;
case AF_INET6: case AF_INET6:
key->family = server->addr.sockAddr6.sin6_family; key->family = sa->sa_family;
key->port = server->addr.sockAddr6.sin6_port; key->port = addr6->sin6_port;
key->addr[0].ipv6_addr = server->addr.sockAddr6.sin6_addr; key->addr[0].ipv6_addr = addr6->sin6_addr;
key_len += sizeof(key->addr[0].ipv6_addr); key_len += sizeof(key->addr[0].ipv6_addr);
break; break;
......
...@@ -119,29 +119,27 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) ...@@ -119,29 +119,27 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
"Display Internal CIFS Data Structures for Debugging\n" "Display Internal CIFS Data Structures for Debugging\n"
"---------------------------------------------------\n"); "---------------------------------------------------\n");
seq_printf(m, "CIFS Version %s\n", CIFS_VERSION); seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
seq_printf(m, "Features: "); seq_printf(m, "Features:");
#ifdef CONFIG_CIFS_DFS_UPCALL #ifdef CONFIG_CIFS_DFS_UPCALL
seq_printf(m, "dfs"); seq_printf(m, " dfs");
seq_putc(m, ' ');
#endif #endif
#ifdef CONFIG_CIFS_FSCACHE #ifdef CONFIG_CIFS_FSCACHE
seq_printf(m, "fscache"); seq_printf(m, " fscache");
seq_putc(m, ' ');
#endif #endif
#ifdef CONFIG_CIFS_WEAK_PW_HASH #ifdef CONFIG_CIFS_WEAK_PW_HASH
seq_printf(m, "lanman"); seq_printf(m, " lanman");
seq_putc(m, ' ');
#endif #endif
#ifdef CONFIG_CIFS_POSIX #ifdef CONFIG_CIFS_POSIX
seq_printf(m, "posix"); seq_printf(m, " posix");
seq_putc(m, ' ');
#endif #endif
#ifdef CONFIG_CIFS_UPCALL #ifdef CONFIG_CIFS_UPCALL
seq_printf(m, "spnego"); seq_printf(m, " spnego");
seq_putc(m, ' ');
#endif #endif
#ifdef CONFIG_CIFS_XATTR #ifdef CONFIG_CIFS_XATTR
seq_printf(m, "xattr"); seq_printf(m, " xattr");
#endif
#ifdef CONFIG_CIFS_ACL
seq_printf(m, " acl");
#endif #endif
seq_putc(m, '\n'); seq_putc(m, '\n');
seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid); seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
......
...@@ -98,6 +98,8 @@ struct key * ...@@ -98,6 +98,8 @@ struct key *
cifs_get_spnego_key(struct cifsSesInfo *sesInfo) cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
{ {
struct TCP_Server_Info *server = sesInfo->server; struct TCP_Server_Info *server = sesInfo->server;
struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
char *description, *dp; char *description, *dp;
size_t desc_len; size_t desc_len;
struct key *spnego_key; struct key *spnego_key;
...@@ -127,10 +129,10 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo) ...@@ -127,10 +129,10 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
dp = description + strlen(description); dp = description + strlen(description);
/* add the server address */ /* add the server address */
if (server->addr.sockAddr.sin_family == AF_INET) if (server->dstaddr.ss_family == AF_INET)
sprintf(dp, "ip4=%pI4", &server->addr.sockAddr.sin_addr); sprintf(dp, "ip4=%pI4", &sa->sin_addr);
else if (server->addr.sockAddr.sin_family == AF_INET6) else if (server->dstaddr.ss_family == AF_INET6)
sprintf(dp, "ip6=%pI6", &server->addr.sockAddr6.sin6_addr); sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
else else
goto out; goto out;
......
...@@ -72,6 +72,7 @@ static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, ...@@ -72,6 +72,7 @@ static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
return 0; return 0;
} }
/* must be called with server->srv_mutex held */
int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
__u32 *pexpected_response_sequence_number) __u32 *pexpected_response_sequence_number)
{ {
...@@ -84,14 +85,12 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, ...@@ -84,14 +85,12 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0) if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
return rc; return rc;
spin_lock(&GlobalMid_Lock);
cifs_pdu->Signature.Sequence.SequenceNumber = cifs_pdu->Signature.Sequence.SequenceNumber =
cpu_to_le32(server->sequence_number); cpu_to_le32(server->sequence_number);
cifs_pdu->Signature.Sequence.Reserved = 0; cifs_pdu->Signature.Sequence.Reserved = 0;
*pexpected_response_sequence_number = server->sequence_number++; *pexpected_response_sequence_number = server->sequence_number++;
server->sequence_number++; server->sequence_number++;
spin_unlock(&GlobalMid_Lock);
rc = cifs_calculate_signature(cifs_pdu, server, smb_signature); rc = cifs_calculate_signature(cifs_pdu, server, smb_signature);
if (rc) if (rc)
...@@ -149,6 +148,7 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec, ...@@ -149,6 +148,7 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
return rc; return rc;
} }
/* must be called with server->srv_mutex held */
int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
__u32 *pexpected_response_sequence_number) __u32 *pexpected_response_sequence_number)
{ {
...@@ -162,14 +162,12 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, ...@@ -162,14 +162,12 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0) if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
return rc; return rc;
spin_lock(&GlobalMid_Lock);
cifs_pdu->Signature.Sequence.SequenceNumber = cifs_pdu->Signature.Sequence.SequenceNumber =
cpu_to_le32(server->sequence_number); cpu_to_le32(server->sequence_number);
cifs_pdu->Signature.Sequence.Reserved = 0; cifs_pdu->Signature.Sequence.Reserved = 0;
*pexpected_response_sequence_number = server->sequence_number++; *pexpected_response_sequence_number = server->sequence_number++;
server->sequence_number++; server->sequence_number++;
spin_unlock(&GlobalMid_Lock);
rc = cifs_calc_signature2(iov, n_vec, server, smb_signature); rc = cifs_calc_signature2(iov, n_vec, server, smb_signature);
if (rc) if (rc)
......
...@@ -329,6 +329,8 @@ cifs_alloc_inode(struct super_block *sb) ...@@ -329,6 +329,8 @@ cifs_alloc_inode(struct super_block *sb)
cifs_inode->invalid_mapping = false; cifs_inode->invalid_mapping = false;
cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
cifs_inode->server_eof = 0; cifs_inode->server_eof = 0;
cifs_inode->uniqueid = 0;
cifs_inode->createtime = 0;
/* Can not set i_flags here - they get immediately overwritten /* Can not set i_flags here - they get immediately overwritten
to zero by the VFS */ to zero by the VFS */
...@@ -361,18 +363,19 @@ cifs_evict_inode(struct inode *inode) ...@@ -361,18 +363,19 @@ cifs_evict_inode(struct inode *inode)
static void static void
cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server) cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
{ {
struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
seq_printf(s, ",addr="); seq_printf(s, ",addr=");
switch (server->addr.sockAddr.sin_family) { switch (server->dstaddr.ss_family) {
case AF_INET: case AF_INET:
seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr); seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
break; break;
case AF_INET6: case AF_INET6:
seq_printf(s, "%pI6", seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
&server->addr.sockAddr6.sin6_addr.s6_addr); if (sa6->sin6_scope_id)
if (server->addr.sockAddr6.sin6_scope_id) seq_printf(s, "%%%u", sa6->sin6_scope_id);
seq_printf(s, "%%%u",
server->addr.sockAddr6.sin6_scope_id);
break; break;
default: default:
seq_printf(s, "(unknown)"); seq_printf(s, "(unknown)");
......
...@@ -163,10 +163,7 @@ struct TCP_Server_Info { ...@@ -163,10 +163,7 @@ struct TCP_Server_Info {
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
char *hostname; /* hostname portion of UNC string */ char *hostname; /* hostname portion of UNC string */
struct socket *ssocket; struct socket *ssocket;
union { struct sockaddr_storage dstaddr;
struct sockaddr_in sockAddr;
struct sockaddr_in6 sockAddr6;
} addr;
struct sockaddr_storage srcaddr; /* locally bind to this IP */ struct sockaddr_storage srcaddr; /* locally bind to this IP */
wait_queue_head_t response_q; wait_queue_head_t response_q;
wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/ wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
...@@ -210,7 +207,7 @@ struct TCP_Server_Info { ...@@ -210,7 +207,7 @@ struct TCP_Server_Info {
char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */ char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
/* 16th byte of RFC1001 workstation name is always null */ /* 16th byte of RFC1001 workstation name is always null */
char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
__u32 sequence_number; /* needed for CIFS PDU signature */ __u32 sequence_number; /* for signing, protected by srv_mutex */
struct session_key session_key; struct session_key session_key;
unsigned long lstrp; /* when we got last response from this server */ unsigned long lstrp; /* when we got last response from this server */
u16 dialect; /* dialect index that server chose */ u16 dialect; /* dialect index that server chose */
...@@ -456,6 +453,7 @@ struct cifsInodeInfo { ...@@ -456,6 +453,7 @@ struct cifsInodeInfo {
bool invalid_mapping:1; /* pagecache is invalid */ bool invalid_mapping:1; /* pagecache is invalid */
u64 server_eof; /* current file size on server */ u64 server_eof; /* current file size on server */
u64 uniqueid; /* server inode number */ u64 uniqueid; /* server inode number */
u64 createtime; /* creation time on server */
#ifdef CONFIG_CIFS_FSCACHE #ifdef CONFIG_CIFS_FSCACHE
struct fscache_cookie *fscache; struct fscache_cookie *fscache;
#endif #endif
...@@ -576,6 +574,7 @@ struct cifs_fattr { ...@@ -576,6 +574,7 @@ struct cifs_fattr {
u64 cf_uniqueid; u64 cf_uniqueid;
u64 cf_eof; u64 cf_eof;
u64 cf_bytes; u64 cf_bytes;
u64 cf_createtime;
uid_t cf_uid; uid_t cf_uid;
gid_t cf_gid; gid_t cf_gid;
umode_t cf_mode; umode_t cf_mode;
......
...@@ -401,15 +401,12 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) ...@@ -401,15 +401,12 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) {
cFYI(1, "Kerberos only mechanism, enable extended security"); cFYI(1, "Kerberos only mechanism, enable extended security");
pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
} } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
#ifdef CONFIG_CIFS_EXPERIMENTAL
else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) {
cFYI(1, "NTLMSSP only mechanism, enable extended security"); cFYI(1, "NTLMSSP only mechanism, enable extended security");
pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
} }
#endif
count = 0; count = 0;
for (i = 0; i < CIFS_NUM_PROT; i++) { for (i = 0; i < CIFS_NUM_PROT; i++) {
......
This diff is collapsed.
...@@ -293,10 +293,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, ...@@ -293,10 +293,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
args.uid = NO_CHANGE_64; args.uid = NO_CHANGE_64;
args.gid = NO_CHANGE_64; args.gid = NO_CHANGE_64;
} }
CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args, CIFSSMBUnixSetFileInfo(xid, tcon, &args, fileHandle,
cifs_sb->local_nls, current->tgid);
cifs_sb->mnt_cifs_flags &
CIFS_MOUNT_MAP_SPECIAL_CHR);
} else { } else {
/* BB implement mode setting via Windows security /* BB implement mode setting via Windows security
descriptors e.g. */ descriptors e.g. */
......
...@@ -104,53 +104,6 @@ static inline int cifs_get_disposition(unsigned int flags) ...@@ -104,53 +104,6 @@ static inline int cifs_get_disposition(unsigned int flags)
return FILE_OPEN; return FILE_OPEN;
} }
static inline int cifs_open_inode_helper(struct inode *inode,
struct cifsTconInfo *pTcon, __u32 oplock, FILE_ALL_INFO *buf,
char *full_path, int xid)
{
struct cifsInodeInfo *pCifsInode = CIFS_I(inode);
struct timespec temp;
int rc;
if (pCifsInode->clientCanCacheRead) {
/* we have the inode open somewhere else
no need to discard cache data */
goto client_can_cache;
}
/* BB need same check in cifs_create too? */
/* if not oplocked, invalidate inode pages if mtime or file
size changed */
temp = cifs_NTtimeToUnix(buf->LastWriteTime);
if (timespec_equal(&inode->i_mtime, &temp) &&
(inode->i_size ==
(loff_t)le64_to_cpu(buf->EndOfFile))) {
cFYI(1, "inode unchanged on server");
} else {
if (inode->i_mapping) {
/* BB no need to lock inode until after invalidate
since namei code should already have it locked? */
rc = filemap_write_and_wait(inode->i_mapping);
mapping_set_error(inode->i_mapping, rc);
}
cFYI(1, "invalidating remote inode since open detected it "
"changed");
invalidate_remote_inode(inode);
}
client_can_cache:
if (pTcon->unix_ext)
rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb,
xid);
else
rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
xid, NULL);
cifs_set_oplock_level(pCifsInode, oplock);
return rc;
}
int cifs_posix_open(char *full_path, struct inode **pinode, int cifs_posix_open(char *full_path, struct inode **pinode,
struct super_block *sb, int mode, unsigned int f_flags, struct super_block *sb, int mode, unsigned int f_flags,
__u32 *poplock, __u16 *pnetfid, int xid) __u32 *poplock, __u16 *pnetfid, int xid)
...@@ -213,6 +166,76 @@ int cifs_posix_open(char *full_path, struct inode **pinode, ...@@ -213,6 +166,76 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
return rc; return rc;
} }
static int
cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
struct cifsTconInfo *tcon, unsigned int f_flags, __u32 *poplock,
__u16 *pnetfid, int xid)
{
int rc;
int desiredAccess;
int disposition;
FILE_ALL_INFO *buf;
desiredAccess = cifs_convert_flags(f_flags);
/*********************************************************************
* open flag mapping table:
*
* POSIX Flag CIFS Disposition
* ---------- ----------------
* O_CREAT FILE_OPEN_IF
* O_CREAT | O_EXCL FILE_CREATE
* O_CREAT | O_TRUNC FILE_OVERWRITE_IF
* O_TRUNC FILE_OVERWRITE
* none of the above FILE_OPEN
*
* Note that there is not a direct match between disposition
* FILE_SUPERSEDE (ie create whether or not file exists although
* O_CREAT | O_TRUNC is similar but truncates the existing
* file rather than creating a new file as FILE_SUPERSEDE does
* (which uses the attributes / metadata passed in on open call)
*?
*? O_SYNC is a reasonable match to CIFS writethrough flag
*? and the read write flags match reasonably. O_LARGEFILE
*? is irrelevant because largefile support is always used
*? by this client. Flags O_APPEND, O_DIRECT, O_DIRECTORY,
* O_FASYNC, O_NOFOLLOW, O_NONBLOCK need further investigation
*********************************************************************/
disposition = cifs_get_disposition(f_flags);
/* BB pass O_SYNC flag through on file attributes .. BB */
buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
if (!buf)
return -ENOMEM;
if (tcon->ses->capabilities & CAP_NT_SMBS)
rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
else
rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
if (rc)
goto out;
if (tcon->unix_ext)
rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb,
xid);
else
rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
xid, pnetfid);
out:
kfree(buf);
return rc;
}
struct cifsFileInfo * struct cifsFileInfo *
cifs_new_fileinfo(__u16 fileHandle, struct file *file, cifs_new_fileinfo(__u16 fileHandle, struct file *file,
struct tcon_link *tlink, __u32 oplock) struct tcon_link *tlink, __u32 oplock)
...@@ -317,10 +340,8 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -317,10 +340,8 @@ int cifs_open(struct inode *inode, struct file *file)
struct cifsFileInfo *pCifsFile = NULL; struct cifsFileInfo *pCifsFile = NULL;
struct cifsInodeInfo *pCifsInode; struct cifsInodeInfo *pCifsInode;
char *full_path = NULL; char *full_path = NULL;
int desiredAccess; bool posix_open_ok = false;
int disposition;
__u16 netfid; __u16 netfid;
FILE_ALL_INFO *buf = NULL;
xid = GetXid(); xid = GetXid();
...@@ -358,17 +379,7 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -358,17 +379,7 @@ int cifs_open(struct inode *inode, struct file *file)
file->f_flags, &oplock, &netfid, xid); file->f_flags, &oplock, &netfid, xid);
if (rc == 0) { if (rc == 0) {
cFYI(1, "posix open succeeded"); cFYI(1, "posix open succeeded");
posix_open_ok = true;
pCifsFile = cifs_new_fileinfo(netfid, file, tlink,
oplock);
if (pCifsFile == NULL) {
CIFSSMBClose(xid, tcon, netfid);
rc = -ENOMEM;
}
cifs_fscache_set_inode_cookie(inode, file);
goto out;
} else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
if (tcon->ses->serverNOS) if (tcon->ses->serverNOS)
cERROR(1, "server %s of type %s returned" cERROR(1, "server %s of type %s returned"
...@@ -385,85 +396,25 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -385,85 +396,25 @@ int cifs_open(struct inode *inode, struct file *file)
or DFS errors */ or DFS errors */
} }
desiredAccess = cifs_convert_flags(file->f_flags); if (!posix_open_ok) {
rc = cifs_nt_open(full_path, inode, cifs_sb, tcon,
/********************************************************************* file->f_flags, &oplock, &netfid, xid);
* open flag mapping table: if (rc)
*
* POSIX Flag CIFS Disposition
* ---------- ----------------
* O_CREAT FILE_OPEN_IF
* O_CREAT | O_EXCL FILE_CREATE
* O_CREAT | O_TRUNC FILE_OVERWRITE_IF
* O_TRUNC FILE_OVERWRITE
* none of the above FILE_OPEN
*
* Note that there is not a direct match between disposition
* FILE_SUPERSEDE (ie create whether or not file exists although
* O_CREAT | O_TRUNC is similar but truncates the existing
* file rather than creating a new file as FILE_SUPERSEDE does
* (which uses the attributes / metadata passed in on open call)
*?
*? O_SYNC is a reasonable match to CIFS writethrough flag
*? and the read write flags match reasonably. O_LARGEFILE
*? is irrelevant because largefile support is always used
*? by this client. Flags O_APPEND, O_DIRECT, O_DIRECTORY,
* O_FASYNC, O_NOFOLLOW, O_NONBLOCK need further investigation
*********************************************************************/
disposition = cifs_get_disposition(file->f_flags);
/* BB pass O_SYNC flag through on file attributes .. BB */
/* Also refresh inode by passing in file_info buf returned by SMBOpen
and calling get_inode_info with returned buf (at least helps
non-Unix server case) */
/* BB we can not do this if this is the second open of a file
and the first handle has writebehind data, we might be
able to simply do a filemap_fdatawrite/filemap_fdatawait first */
buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
if (!buf) {
rc = -ENOMEM;
goto out;
}
if (tcon->ses->capabilities & CAP_NT_SMBS)
rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
else
rc = -EIO; /* no NT SMB support fall into legacy open below */
if (rc == -EIO) {
/* Old server, try legacy style OpenX */
rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR);
}
if (rc) {
cFYI(1, "cifs_open returned 0x%x", rc);
goto out; goto out;
} }
rc = cifs_open_inode_helper(inode, tcon, oplock, buf, full_path, xid);
if (rc != 0)
goto out;
pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock); pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock);
if (pCifsFile == NULL) { if (pCifsFile == NULL) {
CIFSSMBClose(xid, tcon, netfid);
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
cifs_fscache_set_inode_cookie(inode, file); cifs_fscache_set_inode_cookie(inode, file);
if (oplock & CIFS_CREATE_ACTION) { if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) {
/* time to set mode which we can not set earlier due to /* time to set mode which we can not set earlier due to
problems creating new read-only files */ problems creating new read-only files */
if (tcon->unix_ext) {
struct cifs_unix_set_info_args args = { struct cifs_unix_set_info_args args = {
.mode = inode->i_mode, .mode = inode->i_mode,
.uid = NO_CHANGE_64, .uid = NO_CHANGE_64,
...@@ -473,15 +424,11 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -473,15 +424,11 @@ int cifs_open(struct inode *inode, struct file *file)
.mtime = NO_CHANGE_64, .mtime = NO_CHANGE_64,
.device = 0, .device = 0,
}; };
CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args, CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid,
cifs_sb->local_nls, pCifsFile->pid);
cifs_sb->mnt_cifs_flags &
CIFS_MOUNT_MAP_SPECIAL_CHR);
}
} }
out: out:
kfree(buf);
kfree(full_path); kfree(full_path);
FreeXid(xid); FreeXid(xid);
cifs_put_tlink(tlink); cifs_put_tlink(tlink);
......
...@@ -518,6 +518,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info, ...@@ -518,6 +518,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
fattr->cf_eof = le64_to_cpu(info->EndOfFile); fattr->cf_eof = le64_to_cpu(info->EndOfFile);
fattr->cf_bytes = le64_to_cpu(info->AllocationSize); fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
fattr->cf_createtime = le64_to_cpu(info->CreationTime);
if (fattr->cf_cifsattrs & ATTR_DIRECTORY) { if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode; fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
...@@ -779,6 +780,10 @@ cifs_find_inode(struct inode *inode, void *opaque) ...@@ -779,6 +780,10 @@ cifs_find_inode(struct inode *inode, void *opaque)
if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid) if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
return 0; return 0;
/* use createtime like an i_generation field */
if (CIFS_I(inode)->createtime != fattr->cf_createtime)
return 0;
/* don't match inode of different type */ /* don't match inode of different type */
if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT)) if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
return 0; return 0;
...@@ -796,6 +801,7 @@ cifs_init_inode(struct inode *inode, void *opaque) ...@@ -796,6 +801,7 @@ cifs_init_inode(struct inode *inode, void *opaque)
struct cifs_fattr *fattr = (struct cifs_fattr *) opaque; struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
CIFS_I(inode)->uniqueid = fattr->cf_uniqueid; CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
CIFS_I(inode)->createtime = fattr->cf_createtime;
return 0; return 0;
} }
......
...@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, ...@@ -160,6 +160,7 @@ cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes); fattr->cf_cifsattrs = le32_to_cpu(info->ExtFileAttributes);
fattr->cf_eof = le64_to_cpu(info->EndOfFile); fattr->cf_eof = le64_to_cpu(info->EndOfFile);
fattr->cf_bytes = le64_to_cpu(info->AllocationSize); fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
fattr->cf_createtime = le64_to_cpu(info->CreationTime);
fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime); fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime); fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime); fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
......
...@@ -420,7 +420,6 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, ...@@ -420,7 +420,6 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
return 0; return 0;
} }
#ifdef CONFIG_CIFS_EXPERIMENTAL
/* BB Move to ntlmssp.c eventually */ /* BB Move to ntlmssp.c eventually */
/* We do not malloc the blob, it is passed in pbuffer, because /* We do not malloc the blob, it is passed in pbuffer, because
...@@ -431,13 +430,14 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, ...@@ -431,13 +430,14 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer; NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer;
__u32 flags; __u32 flags;
memset(pbuffer, 0, sizeof(NEGOTIATE_MESSAGE));
memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8); memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8);
sec_blob->MessageType = NtLmNegotiate; sec_blob->MessageType = NtLmNegotiate;
/* BB is NTLMV2 session security format easier to use here? */ /* BB is NTLMV2 session security format easier to use here? */
flags = NTLMSSP_NEGOTIATE_56 | NTLMSSP_REQUEST_TARGET | flags = NTLMSSP_NEGOTIATE_56 | NTLMSSP_REQUEST_TARGET |
NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
NTLMSSP_NEGOTIATE_NTLM; NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
if (ses->server->secMode & if (ses->server->secMode &
(SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
flags |= NTLMSSP_NEGOTIATE_SIGN; flags |= NTLMSSP_NEGOTIATE_SIGN;
...@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, ...@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
NTLMSSP_NEGOTIATE_EXTENDED_SEC; NTLMSSP_NEGOTIATE_EXTENDED_SEC;
} }
sec_blob->NegotiateFlags |= cpu_to_le32(flags); sec_blob->NegotiateFlags = cpu_to_le32(flags);
sec_blob->WorkstationName.BufferOffset = 0; sec_blob->WorkstationName.BufferOffset = 0;
sec_blob->WorkstationName.Length = 0; sec_blob->WorkstationName.Length = 0;
...@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, ...@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
flags = NTLMSSP_NEGOTIATE_56 | flags = NTLMSSP_NEGOTIATE_56 |
NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO | NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO |
NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
NTLMSSP_NEGOTIATE_NTLM; NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
if (ses->server->secMode & if (ses->server->secMode &
(SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
flags |= NTLMSSP_NEGOTIATE_SIGN; flags |= NTLMSSP_NEGOTIATE_SIGN;
...@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, ...@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE); tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE);
sec_blob->NegotiateFlags |= cpu_to_le32(flags); sec_blob->NegotiateFlags = cpu_to_le32(flags);
sec_blob->LmChallengeResponse.BufferOffset = sec_blob->LmChallengeResponse.BufferOffset =
cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE)); cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE));
...@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, ...@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
sec_blob->WorkstationName.MaximumLength = 0; sec_blob->WorkstationName.MaximumLength = 0;
tmp += 2; tmp += 2;
if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) && if (((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) ||
!calc_seckey(ses)) { (ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
&& !calc_seckey(ses)) {
memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE); memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer); sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer);
sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE); sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE);
...@@ -563,17 +564,6 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, ...@@ -563,17 +564,6 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
return rc; return rc;
} }
static void setup_ntlmssp_neg_req(SESSION_SETUP_ANDX *pSMB,
struct cifsSesInfo *ses)
{
build_ntlmssp_negotiate_blob(&pSMB->req.SecurityBlob[0], ses);
pSMB->req.SecurityBlobLength = cpu_to_le16(sizeof(NEGOTIATE_MESSAGE));
return;
}
#endif
int int
CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
const struct nls_table *nls_cp) const struct nls_table *nls_cp)
...@@ -814,9 +804,7 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, ...@@ -814,9 +804,7 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
rc = -ENOSYS; rc = -ENOSYS;
goto ssetup_exit; goto ssetup_exit;
#endif /* CONFIG_CIFS_UPCALL */ #endif /* CONFIG_CIFS_UPCALL */
} else { } else if (type == RawNTLMSSP) {
#ifdef CONFIG_CIFS_EXPERIMENTAL
if (type == RawNTLMSSP) {
if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) { if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) {
cERROR(1, "NTLMSSP requires Unicode support"); cERROR(1, "NTLMSSP requires Unicode support");
rc = -ENOSYS; rc = -ENOSYS;
...@@ -827,21 +815,26 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, ...@@ -827,21 +815,26 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
capabilities |= CAP_EXTENDED_SECURITY; capabilities |= CAP_EXTENDED_SECURITY;
pSMB->req.Capabilities |= cpu_to_le32(capabilities); pSMB->req.Capabilities |= cpu_to_le32(capabilities);
if (phase == NtLmNegotiate) { switch(phase) {
setup_ntlmssp_neg_req(pSMB, ses); case NtLmNegotiate:
build_ntlmssp_negotiate_blob(
pSMB->req.SecurityBlob, ses);
iov[1].iov_len = sizeof(NEGOTIATE_MESSAGE); iov[1].iov_len = sizeof(NEGOTIATE_MESSAGE);
iov[1].iov_base = &pSMB->req.SecurityBlob[0]; iov[1].iov_base = pSMB->req.SecurityBlob;
} else if (phase == NtLmAuthenticate) { pSMB->req.SecurityBlobLength =
/* 5 is an empirical value, large enought to cpu_to_le16(sizeof(NEGOTIATE_MESSAGE));
* hold authenticate message, max 10 of break;
* av paris, doamin,user,workstation mames, case NtLmAuthenticate:
* flags etc.. /*
* 5 is an empirical value, large enough to hold
* authenticate message plus max 10 of av paris,
* domain, user, workstation names, flags, etc.
*/ */
ntlmsspblob = kmalloc( ntlmsspblob = kzalloc(
5*sizeof(struct _AUTHENTICATE_MESSAGE), 5*sizeof(struct _AUTHENTICATE_MESSAGE),
GFP_KERNEL); GFP_KERNEL);
if (!ntlmsspblob) { if (!ntlmsspblob) {
cERROR(1, "Can't allocate NTLMSSP"); cERROR(1, "Can't allocate NTLMSSP blob");
rc = -ENOMEM; rc = -ENOMEM;
goto ssetup_exit; goto ssetup_exit;
} }
...@@ -852,13 +845,15 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, ...@@ -852,13 +845,15 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
goto ssetup_exit; goto ssetup_exit;
iov[1].iov_len = blob_len; iov[1].iov_len = blob_len;
iov[1].iov_base = ntlmsspblob; iov[1].iov_base = ntlmsspblob;
pSMB->req.SecurityBlobLength = pSMB->req.SecurityBlobLength = cpu_to_le16(blob_len);
cpu_to_le16(blob_len); /*
/* Make sure that we tell the server that we * Make sure that we tell the server that we are using
are using the uid that it just gave us back * the uid that it just gave us back on the response
on the response (challenge) */ * (challenge)
*/
smb_buf->Uid = ses->Suid; smb_buf->Uid = ses->Suid;
} else { break;
default:
cERROR(1, "invalid phase %d", phase); cERROR(1, "invalid phase %d", phase);
rc = -ENOSYS; rc = -ENOSYS;
goto ssetup_exit; goto ssetup_exit;
...@@ -874,12 +869,6 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, ...@@ -874,12 +869,6 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
rc = -ENOSYS; rc = -ENOSYS;
goto ssetup_exit; goto ssetup_exit;
} }
#else
cERROR(1, "secType %d not supported!", type);
rc = -ENOSYS;
goto ssetup_exit;
#endif
}
iov[2].iov_base = str_area; iov[2].iov_base = str_area;
iov[2].iov_len = (long) bcc_ptr - (long) str_area; iov[2].iov_len = (long) bcc_ptr - (long) str_area;
......
...@@ -119,7 +119,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) ...@@ -119,7 +119,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
if (ssocket == NULL) if (ssocket == NULL)
return -ENOTSOCK; /* BB eventually add reconnect code here */ return -ENOTSOCK; /* BB eventually add reconnect code here */
smb_msg.msg_name = (struct sockaddr *) &server->addr.sockAddr; smb_msg.msg_name = (struct sockaddr *) &server->dstaddr;
smb_msg.msg_namelen = sizeof(struct sockaddr); smb_msg.msg_namelen = sizeof(struct sockaddr);
smb_msg.msg_control = NULL; smb_msg.msg_control = NULL;
smb_msg.msg_controllen = 0; smb_msg.msg_controllen = 0;
......
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