| Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 1 | /* | 
 | 2 |  *   fs/cifs/ntlmssp.h | 
 | 3 |  * | 
 | 4 |  *   Copyright (c) International Business Machines  Corp., 2006 | 
 | 5 |  *   Author(s): Steve French (sfrench@us.ibm.com) | 
 | 6 |  * | 
 | 7 |  *   This library is free software; you can redistribute it and/or modify | 
 | 8 |  *   it under the terms of the GNU Lesser General Public License as published | 
 | 9 |  *   by the Free Software Foundation; either version 2.1 of the License, or | 
 | 10 |  *   (at your option) any later version. | 
 | 11 |  * | 
 | 12 |  *   This library is distributed in the hope that it will be useful, | 
 | 13 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 14 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See | 
 | 15 |  *   the GNU Lesser General Public License for more details. | 
 | 16 |  * | 
 | 17 |  *   You should have received a copy of the GNU Lesser General Public License | 
 | 18 |  *   along with this library; if not, write to the Free Software | 
 | 19 |  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
 | 20 |  */ | 
 | 21 |  | 
 | 22 | #include "cifspdu.h" | 
 | 23 | #include "cifsglob.h" | 
 | 24 | #include "cifsproto.h" | 
 | 25 | #include "cifs_unicode.h" | 
 | 26 | #include "cifs_debug.h" | 
 | 27 | #include "ntlmssp.h" | 
 | 28 | #include "nterr.h" | 
 | 29 |  | 
 | 30 | #ifdef CONFIG_CIFS_EXPERIMENTAL | 
 | 31 | static __u32 cifs_ssetup_hdr(struct cifsSesInfo *ses, SESSION_SETUP_ANDX *pSMB) | 
 | 32 | { | 
 | 33 | 	__u32 capabilities = 0; | 
 | 34 |  | 
 | 35 | 	/* init fields common to all four types of SessSetup */ | 
 | 36 | 	/* note that header is initialized to zero in header_assemble */ | 
 | 37 | 	pSMB->req.AndXCommand = 0xFF; | 
 | 38 | 	pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); | 
 | 39 | 	pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq); | 
 | 40 |  | 
 | 41 | 	/* Now no need to set SMBFLG_CASELESS or obsolete CANONICAL PATH */ | 
 | 42 |  | 
 | 43 | 	/* BB verify whether signing required on neg or just on auth frame  | 
 | 44 | 	   (and NTLM case) */ | 
 | 45 |  | 
 | 46 | 	capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | | 
 | 47 | 			CAP_LARGE_WRITE_X | CAP_LARGE_READ_X; | 
 | 48 |  | 
 | 49 | 	if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 
 | 50 | 		pSMB->req.hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | 
 | 51 |  | 
 | 52 | 	if (ses->capabilities & CAP_UNICODE) { | 
 | 53 | 		pSMB->req.hdr.Flags2 |= SMBFLG2_UNICODE; | 
 | 54 | 		capabilities |= CAP_UNICODE; | 
 | 55 | 	} | 
 | 56 | 	if (ses->capabilities & CAP_STATUS32) { | 
 | 57 | 		pSMB->req.hdr.Flags2 |= SMBFLG2_ERR_STATUS; | 
 | 58 | 		capabilities |= CAP_STATUS32; | 
 | 59 | 	} | 
 | 60 | 	if (ses->capabilities & CAP_DFS) { | 
 | 61 | 		pSMB->req.hdr.Flags2 |= SMBFLG2_DFS; | 
 | 62 | 		capabilities |= CAP_DFS; | 
 | 63 | 	} | 
 | 64 |  | 
 | 65 | 	/* BB check whether to init vcnum BB */ | 
 | 66 | 	return capabilities; | 
 | 67 | } | 
 | 68 | int  | 
 | 69 | CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, const int type, | 
 | 70 | 		  int * pNTLMv2_flg, const struct nls_table *nls_cp) | 
 | 71 | { | 
 | 72 | 	int rc = 0; | 
 | 73 | 	int wct; | 
 | 74 | 	struct smb_hdr *smb_buffer; | 
 | 75 | 	char *bcc_ptr; | 
 | 76 | 	SESSION_SETUP_ANDX *pSMB; | 
 | 77 | 	__u32 capabilities; | 
 | 78 |  | 
 | 79 | 	if(ses == NULL) | 
 | 80 | 		return -EINVAL; | 
 | 81 |  | 
 | 82 | 	cFYI(1,("SStp type: %d",type)); | 
 | 83 | 	if(type < CIFS_NTLM) { | 
 | 84 | #ifndef CONFIG_CIFS_WEAK_PW_HASH | 
 | 85 | 		/* LANMAN and plaintext are less secure and off by default. | 
 | 86 | 		So we make this explicitly be turned on in kconfig (in the | 
 | 87 | 		build) and turned on at runtime (changed from the default) | 
 | 88 | 		in proc/fs/cifs or via mount parm.  Unfortunately this is | 
 | 89 | 		needed for old Win (e.g. Win95), some obscure NAS and OS/2 */ | 
 | 90 | 		return -EOPNOTSUPP; | 
 | 91 | #endif | 
 | 92 | 		wct = 10; /* lanman 2 style sessionsetup */ | 
 | 93 | 	} else if(type < CIFS_NTLMSSP_NEG) | 
 | 94 | 		wct = 13; /* old style NTLM sessionsetup */ | 
 | 95 | 	else /* same size for negotiate or auth, NTLMSSP or extended security */ | 
 | 96 | 		wct = 12; | 
 | 97 |  | 
 | 98 | 	rc = small_smb_init_no_tc(SMB_COM_SESSION_SETUP_ANDX, wct, ses, | 
 | 99 | 			    (void **)&smb_buffer); | 
 | 100 | 	if(rc) | 
 | 101 | 		return rc; | 
 | 102 |  | 
 | 103 | 	pSMB = (SESSION_SETUP_ANDX *)smb_buffer; | 
 | 104 |  | 
 | 105 | 	capabilities = cifs_ssetup_hdr(ses, pSMB); | 
 | 106 | 	bcc_ptr = pByteArea(smb_buffer); | 
 | 107 | 	if(type > CIFS_NTLM) { | 
 | 108 | 		pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; | 
 | 109 | 		capabilities |= CAP_EXTENDED_SECURITY; | 
 | 110 | 		pSMB->req.Capabilities = cpu_to_le32(capabilities); | 
 | 111 | 		/* BB set password lengths */ | 
 | 112 | 	} else if(type < CIFS_NTLM) /* lanman */ { | 
 | 113 | 		/* no capabilities flags in old lanman negotiation */ | 
 | 114 | 		/* pSMB->old_req.PasswordLength = */ /* BB fixme BB */ | 
 | 115 | 	} else /* type CIFS_NTLM */ { | 
 | 116 | 		pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities); | 
 | 117 | 		pSMB->req_no_secext.CaseInsensitivePasswordLength = | 
 | 118 | 			cpu_to_le16(CIFS_SESSION_KEY_SIZE); | 
 | 119 | 		pSMB->req_no_secext.CaseSensitivePasswordLength = | 
 | 120 | 			cpu_to_le16(CIFS_SESSION_KEY_SIZE); | 
 | 121 | 	} | 
 | 122 |  | 
 | 123 |  | 
 | 124 | /*	rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buf_type, 0); */ | 
| Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 125 | 	/* SMB request buf freed in SendReceive2 */ | 
| Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 126 |  | 
 | 127 | 	return rc; | 
 | 128 | } | 
 | 129 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |