connect.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148
  1. /*
  2. * fs/cifs/connect.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2005
  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. #include <linux/fs.h>
  22. #include <linux/net.h>
  23. #include <linux/string.h>
  24. #include <linux/list.h>
  25. #include <linux/wait.h>
  26. #include <linux/ipv6.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/ctype.h>
  29. #include <linux/utsname.h>
  30. #include <linux/mempool.h>
  31. #include <linux/delay.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/processor.h>
  34. #include "cifspdu.h"
  35. #include "cifsglob.h"
  36. #include "cifsproto.h"
  37. #include "cifs_unicode.h"
  38. #include "cifs_debug.h"
  39. #include "cifs_fs_sb.h"
  40. #include "ntlmssp.h"
  41. #include "nterr.h"
  42. #include "rfc1002pdu.h"
  43. #define CIFS_PORT 445
  44. #define RFC1001_PORT 139
  45. extern void SMBencrypt(unsigned char *passwd, unsigned char *c8,
  46. unsigned char *p24);
  47. extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8,
  48. unsigned char *p24);
  49. extern mempool_t *cifs_req_poolp;
  50. struct smb_vol {
  51. char *username;
  52. char *password;
  53. char *domainname;
  54. char *UNC;
  55. char *UNCip;
  56. char *in6_addr; /* ipv6 address as human readable form of in6_addr */
  57. char *iocharset; /* local code page for mapping to and from Unicode */
  58. char source_rfc1001_name[16]; /* netbios name of client */
  59. uid_t linux_uid;
  60. gid_t linux_gid;
  61. mode_t file_mode;
  62. mode_t dir_mode;
  63. unsigned rw:1;
  64. unsigned retry:1;
  65. unsigned intr:1;
  66. unsigned setuids:1;
  67. unsigned noperm:1;
  68. unsigned no_psx_acl:1; /* set if posix acl support should be disabled */
  69. unsigned no_xattr:1; /* set if xattr (EA) support should be disabled*/
  70. unsigned server_ino:1; /* use inode numbers from server ie UniqueId */
  71. unsigned direct_io:1;
  72. unsigned remap:1; /* set to remap seven reserved chars in filenames */
  73. unsigned int rsize;
  74. unsigned int wsize;
  75. unsigned int sockopt;
  76. unsigned short int port;
  77. };
  78. static int ipv4_connect(struct sockaddr_in *psin_server,
  79. struct socket **csocket,
  80. char * netb_name);
  81. static int ipv6_connect(struct sockaddr_in6 *psin_server,
  82. struct socket **csocket);
  83. /*
  84. * cifs tcp session reconnection
  85. *
  86. * mark tcp session as reconnecting so temporarily locked
  87. * mark all smb sessions as reconnecting for tcp session
  88. * reconnect tcp session
  89. * wake up waiters on reconnection? - (not needed currently)
  90. */
  91. int
  92. cifs_reconnect(struct TCP_Server_Info *server)
  93. {
  94. int rc = 0;
  95. struct list_head *tmp;
  96. struct cifsSesInfo *ses;
  97. struct cifsTconInfo *tcon;
  98. struct mid_q_entry * mid_entry;
  99. spin_lock(&GlobalMid_Lock);
  100. if(server->tcpStatus == CifsExiting) {
  101. /* the demux thread will exit normally
  102. next time through the loop */
  103. spin_unlock(&GlobalMid_Lock);
  104. return rc;
  105. } else
  106. server->tcpStatus = CifsNeedReconnect;
  107. spin_unlock(&GlobalMid_Lock);
  108. server->maxBuf = 0;
  109. cFYI(1, ("Reconnecting tcp session "));
  110. /* before reconnecting the tcp session, mark the smb session (uid)
  111. and the tid bad so they are not used until reconnected */
  112. read_lock(&GlobalSMBSeslock);
  113. list_for_each(tmp, &GlobalSMBSessionList) {
  114. ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
  115. if (ses->server) {
  116. if (ses->server == server) {
  117. ses->status = CifsNeedReconnect;
  118. ses->ipc_tid = 0;
  119. }
  120. }
  121. /* else tcp and smb sessions need reconnection */
  122. }
  123. list_for_each(tmp, &GlobalTreeConnectionList) {
  124. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  125. if((tcon) && (tcon->ses) && (tcon->ses->server == server)) {
  126. tcon->tidStatus = CifsNeedReconnect;
  127. }
  128. }
  129. read_unlock(&GlobalSMBSeslock);
  130. /* do not want to be sending data on a socket we are freeing */
  131. down(&server->tcpSem);
  132. if(server->ssocket) {
  133. cFYI(1,("State: 0x%x Flags: 0x%lx", server->ssocket->state,
  134. server->ssocket->flags));
  135. server->ssocket->ops->shutdown(server->ssocket,SEND_SHUTDOWN);
  136. cFYI(1,("Post shutdown state: 0x%x Flags: 0x%lx", server->ssocket->state,
  137. server->ssocket->flags));
  138. sock_release(server->ssocket);
  139. server->ssocket = NULL;
  140. }
  141. spin_lock(&GlobalMid_Lock);
  142. list_for_each(tmp, &server->pending_mid_q) {
  143. mid_entry = list_entry(tmp, struct
  144. mid_q_entry,
  145. qhead);
  146. if(mid_entry) {
  147. if(mid_entry->midState == MID_REQUEST_SUBMITTED) {
  148. /* Mark other intransit requests as needing
  149. retry so we do not immediately mark the
  150. session bad again (ie after we reconnect
  151. below) as they timeout too */
  152. mid_entry->midState = MID_RETRY_NEEDED;
  153. }
  154. }
  155. }
  156. spin_unlock(&GlobalMid_Lock);
  157. up(&server->tcpSem);
  158. while ((server->tcpStatus != CifsExiting) && (server->tcpStatus != CifsGood))
  159. {
  160. if(server->protocolType == IPV6) {
  161. rc = ipv6_connect(&server->addr.sockAddr6,&server->ssocket);
  162. } else {
  163. rc = ipv4_connect(&server->addr.sockAddr,
  164. &server->ssocket,
  165. server->workstation_RFC1001_name);
  166. }
  167. if(rc) {
  168. set_current_state(TASK_INTERRUPTIBLE);
  169. schedule_timeout(3 * HZ);
  170. } else {
  171. atomic_inc(&tcpSesReconnectCount);
  172. spin_lock(&GlobalMid_Lock);
  173. if(server->tcpStatus != CifsExiting)
  174. server->tcpStatus = CifsGood;
  175. server->sequence_number = 0;
  176. spin_unlock(&GlobalMid_Lock);
  177. /* atomic_set(&server->inFlight,0);*/
  178. wake_up(&server->response_q);
  179. }
  180. }
  181. return rc;
  182. }
  183. static int
  184. cifs_demultiplex_thread(struct TCP_Server_Info *server)
  185. {
  186. int length;
  187. unsigned int pdu_length, total_read;
  188. struct smb_hdr *smb_buffer = NULL;
  189. struct smb_hdr *bigbuf = NULL;
  190. struct smb_hdr *smallbuf = NULL;
  191. struct msghdr smb_msg;
  192. struct kvec iov;
  193. struct socket *csocket = server->ssocket;
  194. struct list_head *tmp;
  195. struct cifsSesInfo *ses;
  196. struct task_struct *task_to_wake = NULL;
  197. struct mid_q_entry *mid_entry;
  198. char *temp;
  199. int isLargeBuf = FALSE;
  200. daemonize("cifsd");
  201. allow_signal(SIGKILL);
  202. current->flags |= PF_MEMALLOC;
  203. server->tsk = current; /* save process info to wake at shutdown */
  204. cFYI(1, ("Demultiplex PID: %d", current->pid));
  205. write_lock(&GlobalSMBSeslock);
  206. atomic_inc(&tcpSesAllocCount);
  207. length = tcpSesAllocCount.counter;
  208. write_unlock(&GlobalSMBSeslock);
  209. if(length > 1) {
  210. mempool_resize(cifs_req_poolp,
  211. length + cifs_min_rcv,
  212. GFP_KERNEL);
  213. }
  214. while (server->tcpStatus != CifsExiting) {
  215. if (bigbuf == NULL) {
  216. bigbuf = cifs_buf_get();
  217. if(bigbuf == NULL) {
  218. cERROR(1,("No memory for large SMB response"));
  219. msleep(3000);
  220. /* retry will check if exiting */
  221. continue;
  222. }
  223. } else if(isLargeBuf) {
  224. /* we are reusing a dirtry large buf, clear its start */
  225. memset(bigbuf, 0, sizeof (struct smb_hdr));
  226. }
  227. if (smallbuf == NULL) {
  228. smallbuf = cifs_small_buf_get();
  229. if(smallbuf == NULL) {
  230. cERROR(1,("No memory for SMB response"));
  231. msleep(1000);
  232. /* retry will check if exiting */
  233. continue;
  234. }
  235. /* beginning of smb buffer is cleared in our buf_get */
  236. } else /* if existing small buf clear beginning */
  237. memset(smallbuf, 0, sizeof (struct smb_hdr));
  238. isLargeBuf = FALSE;
  239. smb_buffer = smallbuf;
  240. iov.iov_base = smb_buffer;
  241. iov.iov_len = 4;
  242. smb_msg.msg_control = NULL;
  243. smb_msg.msg_controllen = 0;
  244. length =
  245. kernel_recvmsg(csocket, &smb_msg,
  246. &iov, 1, 4, 0 /* BB see socket.h flags */);
  247. if(server->tcpStatus == CifsExiting) {
  248. break;
  249. } else if (server->tcpStatus == CifsNeedReconnect) {
  250. cFYI(1,("Reconnecting after server stopped responding"));
  251. cifs_reconnect(server);
  252. cFYI(1,("call to reconnect done"));
  253. csocket = server->ssocket;
  254. continue;
  255. } else if ((length == -ERESTARTSYS) || (length == -EAGAIN)) {
  256. msleep(1); /* minimum sleep to prevent looping
  257. allowing socket to clear and app threads to set
  258. tcpStatus CifsNeedReconnect if server hung */
  259. continue;
  260. } else if (length <= 0) {
  261. if(server->tcpStatus == CifsNew) {
  262. cFYI(1,("tcp session abended prematurely (after SMBnegprot)"));
  263. /* some servers kill the TCP session rather than
  264. returning an SMB negprot error, in which
  265. case reconnecting here is not going to help,
  266. and so simply return error to mount */
  267. break;
  268. }
  269. if(length == -EINTR) {
  270. cFYI(1,("cifsd thread killed"));
  271. break;
  272. }
  273. cFYI(1,("Reconnecting after unexpected peek error %d",length));
  274. cifs_reconnect(server);
  275. csocket = server->ssocket;
  276. wake_up(&server->response_q);
  277. continue;
  278. } else if (length > 3) {
  279. pdu_length = ntohl(smb_buffer->smb_buf_length);
  280. /* Only read pdu_length after below checks for too short (due
  281. to e.g. int overflow) and too long ie beyond end of buf */
  282. cFYI(1,("rfc1002 length(big endian)0x%x)",
  283. pdu_length+4));
  284. temp = (char *) smb_buffer;
  285. if (temp[0] == (char) RFC1002_SESSION_KEEP_ALIVE) {
  286. cFYI(0,("Received 4 byte keep alive packet"));
  287. } else if (temp[0] ==
  288. (char) RFC1002_POSITIVE_SESSION_RESPONSE) {
  289. cFYI(1,("Good RFC 1002 session rsp"));
  290. } else if (temp[0] ==
  291. (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
  292. /* we get this from Windows 98 instead of
  293. an error on SMB negprot response */
  294. cFYI(1,("Negative RFC 1002 Session Response Error 0x%x)",temp[4]));
  295. if(server->tcpStatus == CifsNew) {
  296. /* if nack on negprot (rather than
  297. ret of smb negprot error) reconnecting
  298. not going to help, ret error to mount */
  299. break;
  300. } else {
  301. /* give server a second to
  302. clean up before reconnect attempt */
  303. msleep(1000);
  304. /* always try 445 first on reconnect
  305. since we get NACK on some if we ever
  306. connected to port 139 (the NACK is
  307. since we do not begin with RFC1001
  308. session initialize frame) */
  309. server->addr.sockAddr.sin_port =
  310. htons(CIFS_PORT);
  311. cifs_reconnect(server);
  312. csocket = server->ssocket;
  313. wake_up(&server->response_q);
  314. continue;
  315. }
  316. } else if (temp[0] != (char) 0) {
  317. cERROR(1,("Unknown RFC 1002 frame"));
  318. cifs_dump_mem(" Received Data: ", temp, length);
  319. cifs_reconnect(server);
  320. csocket = server->ssocket;
  321. continue;
  322. } else {
  323. if((pdu_length > CIFSMaxBufSize +
  324. MAX_CIFS_HDR_SIZE - 4) ||
  325. (pdu_length < sizeof (struct smb_hdr) - 1 - 4)) {
  326. cERROR(1,
  327. ("Invalid size SMB length %d and pdu_length %d",
  328. length, pdu_length+4));
  329. cifs_reconnect(server);
  330. csocket = server->ssocket;
  331. wake_up(&server->response_q);
  332. continue;
  333. } else { /* length ok */
  334. if(pdu_length > MAX_CIFS_HDR_SIZE - 4) {
  335. isLargeBuf = TRUE;
  336. memcpy(bigbuf, smallbuf, 4);
  337. smb_buffer = bigbuf;
  338. }
  339. length = 0;
  340. iov.iov_base = 4 + (char *)smb_buffer;
  341. iov.iov_len = pdu_length;
  342. for (total_read = 0;
  343. total_read < pdu_length;
  344. total_read += length) {
  345. length = kernel_recvmsg(csocket, &smb_msg,
  346. &iov, 1,
  347. pdu_length - total_read, 0);
  348. if (length == 0) {
  349. cERROR(1,
  350. ("Zero length receive when expecting %d ",
  351. pdu_length - total_read));
  352. cifs_reconnect(server);
  353. csocket = server->ssocket;
  354. wake_up(&server->response_q);
  355. continue;
  356. }
  357. }
  358. length += 4; /* account for rfc1002 hdr */
  359. }
  360. dump_smb(smb_buffer, length);
  361. if (checkSMB
  362. (smb_buffer, smb_buffer->Mid, total_read+4)) {
  363. cERROR(1, ("Bad SMB Received "));
  364. continue;
  365. }
  366. /* BB FIXME - add checkTrans2SMBSecondary() */
  367. task_to_wake = NULL;
  368. spin_lock(&GlobalMid_Lock);
  369. list_for_each(tmp, &server->pending_mid_q) {
  370. mid_entry = list_entry(tmp, struct
  371. mid_q_entry,
  372. qhead);
  373. if ((mid_entry->mid == smb_buffer->Mid)
  374. && (mid_entry->midState ==
  375. MID_REQUEST_SUBMITTED)
  376. && (mid_entry->command ==
  377. smb_buffer->Command)) {
  378. cFYI(1,("Found Mid 0x%x wake up"
  379. ,mid_entry->mid));
  380. task_to_wake = mid_entry->tsk;
  381. mid_entry->resp_buf =
  382. smb_buffer;
  383. mid_entry->midState =
  384. MID_RESPONSE_RECEIVED;
  385. if(isLargeBuf)
  386. mid_entry->largeBuf = 1;
  387. else
  388. mid_entry->largeBuf = 0;
  389. }
  390. }
  391. spin_unlock(&GlobalMid_Lock);
  392. if (task_to_wake) {
  393. if(isLargeBuf)
  394. bigbuf = NULL;
  395. else
  396. smallbuf = NULL;
  397. smb_buffer = NULL; /* will be freed by users thread after he is done */
  398. wake_up_process(task_to_wake);
  399. } else if (is_valid_oplock_break(smb_buffer) == FALSE) {
  400. cERROR(1, ("No task to wake, unknown frame rcvd!"));
  401. cifs_dump_mem("Received Data is: ",temp,sizeof(struct smb_hdr));
  402. }
  403. }
  404. } else {
  405. cFYI(1,
  406. ("Frame less than four bytes received %d bytes long.",
  407. length));
  408. cifs_reconnect(server);
  409. csocket = server->ssocket;
  410. wake_up(&server->response_q);
  411. continue;
  412. }
  413. }
  414. spin_lock(&GlobalMid_Lock);
  415. server->tcpStatus = CifsExiting;
  416. server->tsk = NULL;
  417. atomic_set(&server->inFlight, 0);
  418. spin_unlock(&GlobalMid_Lock);
  419. /* Although there should not be any requests blocked on
  420. this queue it can not hurt to be paranoid and try to wake up requests
  421. that may haven been blocked when more than 50 at time were on the wire
  422. to the same server - they now will see the session is in exit state
  423. and get out of SendReceive. */
  424. wake_up_all(&server->request_q);
  425. /* give those requests time to exit */
  426. msleep(125);
  427. if(server->ssocket) {
  428. sock_release(csocket);
  429. server->ssocket = NULL;
  430. }
  431. /* buffer usuallly freed in free_mid - need to free it here on exit */
  432. if (bigbuf != NULL)
  433. cifs_buf_release(bigbuf);
  434. if (smallbuf != NULL)
  435. cifs_small_buf_release(smallbuf);
  436. read_lock(&GlobalSMBSeslock);
  437. if (list_empty(&server->pending_mid_q)) {
  438. /* loop through server session structures attached to this and
  439. mark them dead */
  440. list_for_each(tmp, &GlobalSMBSessionList) {
  441. ses =
  442. list_entry(tmp, struct cifsSesInfo,
  443. cifsSessionList);
  444. if (ses->server == server) {
  445. ses->status = CifsExiting;
  446. ses->server = NULL;
  447. }
  448. }
  449. read_unlock(&GlobalSMBSeslock);
  450. } else {
  451. spin_lock(&GlobalMid_Lock);
  452. list_for_each(tmp, &server->pending_mid_q) {
  453. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  454. if (mid_entry->midState == MID_REQUEST_SUBMITTED) {
  455. cFYI(1,
  456. ("Clearing Mid 0x%x - waking up ",mid_entry->mid));
  457. task_to_wake = mid_entry->tsk;
  458. if(task_to_wake) {
  459. wake_up_process(task_to_wake);
  460. }
  461. }
  462. }
  463. spin_unlock(&GlobalMid_Lock);
  464. read_unlock(&GlobalSMBSeslock);
  465. /* 1/8th of sec is more than enough time for them to exit */
  466. msleep(125);
  467. }
  468. if (list_empty(&server->pending_mid_q)) {
  469. /* mpx threads have not exited yet give them
  470. at least the smb send timeout time for long ops */
  471. cFYI(1, ("Wait for exit from demultiplex thread"));
  472. msleep(46);
  473. /* if threads still have not exited they are probably never
  474. coming home not much else we can do but free the memory */
  475. }
  476. kfree(server);
  477. write_lock(&GlobalSMBSeslock);
  478. atomic_dec(&tcpSesAllocCount);
  479. length = tcpSesAllocCount.counter;
  480. write_unlock(&GlobalSMBSeslock);
  481. if(length > 0) {
  482. mempool_resize(cifs_req_poolp,
  483. length + cifs_min_rcv,
  484. GFP_KERNEL);
  485. }
  486. msleep(250);
  487. return 0;
  488. }
  489. static int
  490. cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
  491. {
  492. char *value;
  493. char *data;
  494. unsigned int temp_len, i, j;
  495. char separator[2];
  496. separator[0] = ',';
  497. separator[1] = 0;
  498. memset(vol->source_rfc1001_name,0x20,15);
  499. for(i=0;i < strnlen(system_utsname.nodename,15);i++) {
  500. /* does not have to be a perfect mapping since the field is
  501. informational, only used for servers that do not support
  502. port 445 and it can be overridden at mount time */
  503. vol->source_rfc1001_name[i] =
  504. toupper(system_utsname.nodename[i]);
  505. }
  506. vol->source_rfc1001_name[15] = 0;
  507. vol->linux_uid = current->uid; /* current->euid instead? */
  508. vol->linux_gid = current->gid;
  509. vol->dir_mode = S_IRWXUGO;
  510. /* 2767 perms indicate mandatory locking support */
  511. vol->file_mode = S_IALLUGO & ~(S_ISUID | S_IXGRP);
  512. /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */
  513. vol->rw = TRUE;
  514. if (!options)
  515. return 1;
  516. if(strncmp(options,"sep=",4) == 0) {
  517. if(options[4] != 0) {
  518. separator[0] = options[4];
  519. options += 5;
  520. } else {
  521. cFYI(1,("Null separator not allowed"));
  522. }
  523. }
  524. while ((data = strsep(&options, separator)) != NULL) {
  525. if (!*data)
  526. continue;
  527. if ((value = strchr(data, '=')) != NULL)
  528. *value++ = '\0';
  529. if (strnicmp(data, "user_xattr",10) == 0) {/*parse before user*/
  530. vol->no_xattr = 0;
  531. } else if (strnicmp(data, "nouser_xattr",12) == 0) {
  532. vol->no_xattr = 1;
  533. } else if (strnicmp(data, "user", 4) == 0) {
  534. if (!value || !*value) {
  535. printk(KERN_WARNING
  536. "CIFS: invalid or missing username\n");
  537. return 1; /* needs_arg; */
  538. }
  539. if (strnlen(value, 200) < 200) {
  540. vol->username = value;
  541. } else {
  542. printk(KERN_WARNING "CIFS: username too long\n");
  543. return 1;
  544. }
  545. } else if (strnicmp(data, "pass", 4) == 0) {
  546. if (!value) {
  547. vol->password = NULL;
  548. continue;
  549. } else if(value[0] == 0) {
  550. /* check if string begins with double comma
  551. since that would mean the password really
  552. does start with a comma, and would not
  553. indicate an empty string */
  554. if(value[1] != separator[0]) {
  555. vol->password = NULL;
  556. continue;
  557. }
  558. }
  559. temp_len = strlen(value);
  560. /* removed password length check, NTLM passwords
  561. can be arbitrarily long */
  562. /* if comma in password, the string will be
  563. prematurely null terminated. Commas in password are
  564. specified across the cifs mount interface by a double
  565. comma ie ,, and a comma used as in other cases ie ','
  566. as a parameter delimiter/separator is single and due
  567. to the strsep above is temporarily zeroed. */
  568. /* NB: password legally can have multiple commas and
  569. the only illegal character in a password is null */
  570. if ((value[temp_len] == 0) &&
  571. (value[temp_len+1] == separator[0])) {
  572. /* reinsert comma */
  573. value[temp_len] = separator[0];
  574. temp_len+=2; /* move after the second comma */
  575. while(value[temp_len] != 0) {
  576. if (value[temp_len] == separator[0]) {
  577. if (value[temp_len+1] ==
  578. separator[0]) {
  579. /* skip second comma */
  580. temp_len++;
  581. } else {
  582. /* single comma indicating start
  583. of next parm */
  584. break;
  585. }
  586. }
  587. temp_len++;
  588. }
  589. if(value[temp_len] == 0) {
  590. options = NULL;
  591. } else {
  592. value[temp_len] = 0;
  593. /* point option to start of next parm */
  594. options = value + temp_len + 1;
  595. }
  596. /* go from value to value + temp_len condensing
  597. double commas to singles. Note that this ends up
  598. allocating a few bytes too many, which is ok */
  599. vol->password = kcalloc(1, temp_len, GFP_KERNEL);
  600. if(vol->password == NULL) {
  601. printk("CIFS: no memory for pass\n");
  602. return 1;
  603. }
  604. for(i=0,j=0;i<temp_len;i++,j++) {
  605. vol->password[j] = value[i];
  606. if(value[i] == separator[0]
  607. && value[i+1] == separator[0]) {
  608. /* skip second comma */
  609. i++;
  610. }
  611. }
  612. vol->password[j] = 0;
  613. } else {
  614. vol->password = kcalloc(1, temp_len+1, GFP_KERNEL);
  615. if(vol->password == NULL) {
  616. printk("CIFS: no memory for pass\n");
  617. return 1;
  618. }
  619. strcpy(vol->password, value);
  620. }
  621. } else if (strnicmp(data, "ip", 2) == 0) {
  622. if (!value || !*value) {
  623. vol->UNCip = NULL;
  624. } else if (strnlen(value, 35) < 35) {
  625. vol->UNCip = value;
  626. } else {
  627. printk(KERN_WARNING "CIFS: ip address too long\n");
  628. return 1;
  629. }
  630. } else if ((strnicmp(data, "unc", 3) == 0)
  631. || (strnicmp(data, "target", 6) == 0)
  632. || (strnicmp(data, "path", 4) == 0)) {
  633. if (!value || !*value) {
  634. printk(KERN_WARNING
  635. "CIFS: invalid path to network resource\n");
  636. return 1; /* needs_arg; */
  637. }
  638. if ((temp_len = strnlen(value, 300)) < 300) {
  639. vol->UNC = kmalloc(temp_len+1,GFP_KERNEL);
  640. if(vol->UNC == NULL)
  641. return 1;
  642. strcpy(vol->UNC,value);
  643. if (strncmp(vol->UNC, "//", 2) == 0) {
  644. vol->UNC[0] = '\\';
  645. vol->UNC[1] = '\\';
  646. } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
  647. printk(KERN_WARNING
  648. "CIFS: UNC Path does not begin with // or \\\\ \n");
  649. return 1;
  650. }
  651. } else {
  652. printk(KERN_WARNING "CIFS: UNC name too long\n");
  653. return 1;
  654. }
  655. } else if ((strnicmp(data, "domain", 3) == 0)
  656. || (strnicmp(data, "workgroup", 5) == 0)) {
  657. if (!value || !*value) {
  658. printk(KERN_WARNING "CIFS: invalid domain name\n");
  659. return 1; /* needs_arg; */
  660. }
  661. /* BB are there cases in which a comma can be valid in
  662. a domain name and need special handling? */
  663. if (strnlen(value, 65) < 65) {
  664. vol->domainname = value;
  665. cFYI(1, ("Domain name set"));
  666. } else {
  667. printk(KERN_WARNING "CIFS: domain name too long\n");
  668. return 1;
  669. }
  670. } else if (strnicmp(data, "iocharset", 9) == 0) {
  671. if (!value || !*value) {
  672. printk(KERN_WARNING "CIFS: invalid iocharset specified\n");
  673. return 1; /* needs_arg; */
  674. }
  675. if (strnlen(value, 65) < 65) {
  676. if(strnicmp(value,"default",7))
  677. vol->iocharset = value;
  678. /* if iocharset not set load_nls_default used by caller */
  679. cFYI(1, ("iocharset set to %s",value));
  680. } else {
  681. printk(KERN_WARNING "CIFS: iocharset name too long.\n");
  682. return 1;
  683. }
  684. } else if (strnicmp(data, "uid", 3) == 0) {
  685. if (value && *value) {
  686. vol->linux_uid =
  687. simple_strtoul(value, &value, 0);
  688. }
  689. } else if (strnicmp(data, "gid", 3) == 0) {
  690. if (value && *value) {
  691. vol->linux_gid =
  692. simple_strtoul(value, &value, 0);
  693. }
  694. } else if (strnicmp(data, "file_mode", 4) == 0) {
  695. if (value && *value) {
  696. vol->file_mode =
  697. simple_strtoul(value, &value, 0);
  698. }
  699. } else if (strnicmp(data, "dir_mode", 4) == 0) {
  700. if (value && *value) {
  701. vol->dir_mode =
  702. simple_strtoul(value, &value, 0);
  703. }
  704. } else if (strnicmp(data, "dirmode", 4) == 0) {
  705. if (value && *value) {
  706. vol->dir_mode =
  707. simple_strtoul(value, &value, 0);
  708. }
  709. } else if (strnicmp(data, "port", 4) == 0) {
  710. if (value && *value) {
  711. vol->port =
  712. simple_strtoul(value, &value, 0);
  713. }
  714. } else if (strnicmp(data, "rsize", 5) == 0) {
  715. if (value && *value) {
  716. vol->rsize =
  717. simple_strtoul(value, &value, 0);
  718. }
  719. } else if (strnicmp(data, "wsize", 5) == 0) {
  720. if (value && *value) {
  721. vol->wsize =
  722. simple_strtoul(value, &value, 0);
  723. }
  724. } else if (strnicmp(data, "sockopt", 5) == 0) {
  725. if (value && *value) {
  726. vol->sockopt =
  727. simple_strtoul(value, &value, 0);
  728. }
  729. } else if (strnicmp(data, "netbiosname", 4) == 0) {
  730. if (!value || !*value || (*value == ' ')) {
  731. cFYI(1,("invalid (empty) netbiosname specified"));
  732. } else {
  733. memset(vol->source_rfc1001_name,0x20,15);
  734. for(i=0;i<15;i++) {
  735. /* BB are there cases in which a comma can be
  736. valid in this workstation netbios name (and need
  737. special handling)? */
  738. /* We do not uppercase netbiosname for user */
  739. if (value[i]==0)
  740. break;
  741. else
  742. vol->source_rfc1001_name[i] = value[i];
  743. }
  744. /* The string has 16th byte zero still from
  745. set at top of the function */
  746. if((i==15) && (value[i] != 0))
  747. printk(KERN_WARNING "CIFS: netbiosname longer than 15 and was truncated.\n");
  748. }
  749. } else if (strnicmp(data, "credentials", 4) == 0) {
  750. /* ignore */
  751. } else if (strnicmp(data, "version", 3) == 0) {
  752. /* ignore */
  753. } else if (strnicmp(data, "guest",5) == 0) {
  754. /* ignore */
  755. } else if (strnicmp(data, "rw", 2) == 0) {
  756. vol->rw = TRUE;
  757. } else if ((strnicmp(data, "suid", 4) == 0) ||
  758. (strnicmp(data, "nosuid", 6) == 0) ||
  759. (strnicmp(data, "exec", 4) == 0) ||
  760. (strnicmp(data, "noexec", 6) == 0) ||
  761. (strnicmp(data, "nodev", 5) == 0) ||
  762. (strnicmp(data, "noauto", 6) == 0) ||
  763. (strnicmp(data, "dev", 3) == 0)) {
  764. /* The mount tool or mount.cifs helper (if present)
  765. uses these opts to set flags, and the flags are read
  766. by the kernel vfs layer before we get here (ie
  767. before read super) so there is no point trying to
  768. parse these options again and set anything and it
  769. is ok to just ignore them */
  770. continue;
  771. } else if (strnicmp(data, "ro", 2) == 0) {
  772. vol->rw = FALSE;
  773. } else if (strnicmp(data, "hard", 4) == 0) {
  774. vol->retry = 1;
  775. } else if (strnicmp(data, "soft", 4) == 0) {
  776. vol->retry = 0;
  777. } else if (strnicmp(data, "perm", 4) == 0) {
  778. vol->noperm = 0;
  779. } else if (strnicmp(data, "noperm", 6) == 0) {
  780. vol->noperm = 1;
  781. } else if (strnicmp(data, "mapchars", 8) == 0) {
  782. vol->remap = 1;
  783. } else if (strnicmp(data, "nomapchars", 10) == 0) {
  784. vol->remap = 0;
  785. } else if (strnicmp(data, "setuids", 7) == 0) {
  786. vol->setuids = 1;
  787. } else if (strnicmp(data, "nosetuids", 9) == 0) {
  788. vol->setuids = 0;
  789. } else if (strnicmp(data, "nohard", 6) == 0) {
  790. vol->retry = 0;
  791. } else if (strnicmp(data, "nosoft", 6) == 0) {
  792. vol->retry = 1;
  793. } else if (strnicmp(data, "nointr", 6) == 0) {
  794. vol->intr = 0;
  795. } else if (strnicmp(data, "intr", 4) == 0) {
  796. vol->intr = 1;
  797. } else if (strnicmp(data, "serverino",7) == 0) {
  798. vol->server_ino = 1;
  799. } else if (strnicmp(data, "noserverino",9) == 0) {
  800. vol->server_ino = 0;
  801. } else if (strnicmp(data, "acl",3) == 0) {
  802. vol->no_psx_acl = 0;
  803. } else if (strnicmp(data, "noacl",5) == 0) {
  804. vol->no_psx_acl = 1;
  805. } else if (strnicmp(data, "direct",6) == 0) {
  806. vol->direct_io = 1;
  807. } else if (strnicmp(data, "forcedirectio",13) == 0) {
  808. vol->direct_io = 1;
  809. } else if (strnicmp(data, "in6_addr",8) == 0) {
  810. if (!value || !*value) {
  811. vol->in6_addr = NULL;
  812. } else if (strnlen(value, 49) == 48) {
  813. vol->in6_addr = value;
  814. } else {
  815. printk(KERN_WARNING "CIFS: ip v6 address not 48 characters long\n");
  816. return 1;
  817. }
  818. } else if (strnicmp(data, "noac", 4) == 0) {
  819. printk(KERN_WARNING "CIFS: Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
  820. } else
  821. printk(KERN_WARNING "CIFS: Unknown mount option %s\n",data);
  822. }
  823. if (vol->UNC == NULL) {
  824. if(devname == NULL) {
  825. printk(KERN_WARNING "CIFS: Missing UNC name for mount target\n");
  826. return 1;
  827. }
  828. if ((temp_len = strnlen(devname, 300)) < 300) {
  829. vol->UNC = kmalloc(temp_len+1,GFP_KERNEL);
  830. if(vol->UNC == NULL)
  831. return 1;
  832. strcpy(vol->UNC,devname);
  833. if (strncmp(vol->UNC, "//", 2) == 0) {
  834. vol->UNC[0] = '\\';
  835. vol->UNC[1] = '\\';
  836. } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
  837. printk(KERN_WARNING "CIFS: UNC Path does not begin with // or \\\\ \n");
  838. return 1;
  839. }
  840. } else {
  841. printk(KERN_WARNING "CIFS: UNC name too long\n");
  842. return 1;
  843. }
  844. }
  845. if(vol->UNCip == NULL)
  846. vol->UNCip = &vol->UNC[2];
  847. return 0;
  848. }
  849. static struct cifsSesInfo *
  850. cifs_find_tcp_session(struct in_addr * target_ip_addr,
  851. struct in6_addr *target_ip6_addr,
  852. char *userName, struct TCP_Server_Info **psrvTcp)
  853. {
  854. struct list_head *tmp;
  855. struct cifsSesInfo *ses;
  856. *psrvTcp = NULL;
  857. read_lock(&GlobalSMBSeslock);
  858. list_for_each(tmp, &GlobalSMBSessionList) {
  859. ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
  860. if (ses->server) {
  861. if((target_ip_addr &&
  862. (ses->server->addr.sockAddr.sin_addr.s_addr
  863. == target_ip_addr->s_addr)) || (target_ip6_addr
  864. && memcmp(&ses->server->addr.sockAddr6.sin6_addr,
  865. target_ip6_addr,sizeof(*target_ip6_addr)))){
  866. /* BB lock server and tcp session and increment use count here?? */
  867. *psrvTcp = ses->server; /* found a match on the TCP session */
  868. /* BB check if reconnection needed */
  869. if (strncmp
  870. (ses->userName, userName,
  871. MAX_USERNAME_SIZE) == 0){
  872. read_unlock(&GlobalSMBSeslock);
  873. return ses; /* found exact match on both tcp and SMB sessions */
  874. }
  875. }
  876. }
  877. /* else tcp and smb sessions need reconnection */
  878. }
  879. read_unlock(&GlobalSMBSeslock);
  880. return NULL;
  881. }
  882. static struct cifsTconInfo *
  883. find_unc(__be32 new_target_ip_addr, char *uncName, char *userName)
  884. {
  885. struct list_head *tmp;
  886. struct cifsTconInfo *tcon;
  887. read_lock(&GlobalSMBSeslock);
  888. list_for_each(tmp, &GlobalTreeConnectionList) {
  889. cFYI(1, ("Next tcon - "));
  890. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  891. if (tcon->ses) {
  892. if (tcon->ses->server) {
  893. cFYI(1,
  894. (" old ip addr: %x == new ip %x ?",
  895. tcon->ses->server->addr.sockAddr.sin_addr.
  896. s_addr, new_target_ip_addr));
  897. if (tcon->ses->server->addr.sockAddr.sin_addr.
  898. s_addr == new_target_ip_addr) {
  899. /* BB lock tcon and server and tcp session and increment use count here? */
  900. /* found a match on the TCP session */
  901. /* BB check if reconnection needed */
  902. cFYI(1,("Matched ip, old UNC: %s == new: %s ?",
  903. tcon->treeName, uncName));
  904. if (strncmp
  905. (tcon->treeName, uncName,
  906. MAX_TREE_SIZE) == 0) {
  907. cFYI(1,
  908. ("Matched UNC, old user: %s == new: %s ?",
  909. tcon->treeName, uncName));
  910. if (strncmp
  911. (tcon->ses->userName,
  912. userName,
  913. MAX_USERNAME_SIZE) == 0) {
  914. read_unlock(&GlobalSMBSeslock);
  915. return tcon;/* also matched user (smb session)*/
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. read_unlock(&GlobalSMBSeslock);
  923. return NULL;
  924. }
  925. int
  926. connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
  927. const char *old_path, const struct nls_table *nls_codepage,
  928. int remap)
  929. {
  930. unsigned char *referrals = NULL;
  931. unsigned int num_referrals;
  932. int rc = 0;
  933. rc = get_dfs_path(xid, pSesInfo,old_path, nls_codepage,
  934. &num_referrals, &referrals, remap);
  935. /* BB Add in code to: if valid refrl, if not ip address contact
  936. the helper that resolves tcp names, mount to it, try to
  937. tcon to it unmount it if fail */
  938. if(referrals)
  939. kfree(referrals);
  940. return rc;
  941. }
  942. int
  943. get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
  944. const char *old_path, const struct nls_table *nls_codepage,
  945. unsigned int *pnum_referrals,
  946. unsigned char ** preferrals, int remap)
  947. {
  948. char *temp_unc;
  949. int rc = 0;
  950. *pnum_referrals = 0;
  951. if (pSesInfo->ipc_tid == 0) {
  952. temp_unc = kmalloc(2 /* for slashes */ +
  953. strnlen(pSesInfo->serverName,SERVER_NAME_LEN_WITH_NULL * 2)
  954. + 1 + 4 /* slash IPC$ */ + 2,
  955. GFP_KERNEL);
  956. if (temp_unc == NULL)
  957. return -ENOMEM;
  958. temp_unc[0] = '\\';
  959. temp_unc[1] = '\\';
  960. strcpy(temp_unc + 2, pSesInfo->serverName);
  961. strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$");
  962. rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage);
  963. cFYI(1,
  964. ("CIFS Tcon rc = %d ipc_tid = %d", rc,pSesInfo->ipc_tid));
  965. kfree(temp_unc);
  966. }
  967. if (rc == 0)
  968. rc = CIFSGetDFSRefer(xid, pSesInfo, old_path, preferrals,
  969. pnum_referrals, nls_codepage, remap);
  970. return rc;
  971. }
  972. /* See RFC1001 section 14 on representation of Netbios names */
  973. static void rfc1002mangle(char * target,char * source, unsigned int length)
  974. {
  975. unsigned int i,j;
  976. for(i=0,j=0;i<(length);i++) {
  977. /* mask a nibble at a time and encode */
  978. target[j] = 'A' + (0x0F & (source[i] >> 4));
  979. target[j+1] = 'A' + (0x0F & source[i]);
  980. j+=2;
  981. }
  982. }
  983. static int
  984. ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
  985. char * netbios_name)
  986. {
  987. int rc = 0;
  988. int connected = 0;
  989. __be16 orig_port = 0;
  990. if(*csocket == NULL) {
  991. rc = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, csocket);
  992. if (rc < 0) {
  993. cERROR(1, ("Error %d creating socket",rc));
  994. *csocket = NULL;
  995. return rc;
  996. } else {
  997. /* BB other socket options to set KEEPALIVE, NODELAY? */
  998. cFYI(1,("Socket created"));
  999. (*csocket)->sk->sk_allocation = GFP_NOFS;
  1000. }
  1001. }
  1002. psin_server->sin_family = AF_INET;
  1003. if(psin_server->sin_port) { /* user overrode default port */
  1004. rc = (*csocket)->ops->connect(*csocket,
  1005. (struct sockaddr *) psin_server,
  1006. sizeof (struct sockaddr_in),0);
  1007. if (rc >= 0)
  1008. connected = 1;
  1009. }
  1010. if(!connected) {
  1011. /* save original port so we can retry user specified port
  1012. later if fall back ports fail this time */
  1013. orig_port = psin_server->sin_port;
  1014. /* do not retry on the same port we just failed on */
  1015. if(psin_server->sin_port != htons(CIFS_PORT)) {
  1016. psin_server->sin_port = htons(CIFS_PORT);
  1017. rc = (*csocket)->ops->connect(*csocket,
  1018. (struct sockaddr *) psin_server,
  1019. sizeof (struct sockaddr_in),0);
  1020. if (rc >= 0)
  1021. connected = 1;
  1022. }
  1023. }
  1024. if (!connected) {
  1025. psin_server->sin_port = htons(RFC1001_PORT);
  1026. rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
  1027. psin_server, sizeof (struct sockaddr_in),0);
  1028. if (rc >= 0)
  1029. connected = 1;
  1030. }
  1031. /* give up here - unless we want to retry on different
  1032. protocol families some day */
  1033. if (!connected) {
  1034. if(orig_port)
  1035. psin_server->sin_port = orig_port;
  1036. cFYI(1,("Error %d connecting to server via ipv4",rc));
  1037. sock_release(*csocket);
  1038. *csocket = NULL;
  1039. return rc;
  1040. }
  1041. /* Eventually check for other socket options to change from
  1042. the default. sock_setsockopt not used because it expects
  1043. user space buffer */
  1044. (*csocket)->sk->sk_rcvtimeo = 7 * HZ;
  1045. /* send RFC1001 sessinit */
  1046. if(psin_server->sin_port == htons(RFC1001_PORT)) {
  1047. /* some servers require RFC1001 sessinit before sending
  1048. negprot - BB check reconnection in case where second
  1049. sessinit is sent but no second negprot */
  1050. struct rfc1002_session_packet * ses_init_buf;
  1051. struct smb_hdr * smb_buf;
  1052. ses_init_buf = kcalloc(1, sizeof(struct rfc1002_session_packet), GFP_KERNEL);
  1053. if(ses_init_buf) {
  1054. ses_init_buf->trailer.session_req.called_len = 32;
  1055. rfc1002mangle(ses_init_buf->trailer.session_req.called_name,
  1056. DEFAULT_CIFS_CALLED_NAME,16);
  1057. ses_init_buf->trailer.session_req.calling_len = 32;
  1058. /* calling name ends in null (byte 16) from old smb
  1059. convention. */
  1060. if(netbios_name && (netbios_name[0] !=0)) {
  1061. rfc1002mangle(ses_init_buf->trailer.session_req.calling_name,
  1062. netbios_name,16);
  1063. } else {
  1064. rfc1002mangle(ses_init_buf->trailer.session_req.calling_name,
  1065. "LINUX_CIFS_CLNT",16);
  1066. }
  1067. ses_init_buf->trailer.session_req.scope1 = 0;
  1068. ses_init_buf->trailer.session_req.scope2 = 0;
  1069. smb_buf = (struct smb_hdr *)ses_init_buf;
  1070. /* sizeof RFC1002_SESSION_REQUEST with no scope */
  1071. smb_buf->smb_buf_length = 0x81000044;
  1072. rc = smb_send(*csocket, smb_buf, 0x44,
  1073. (struct sockaddr *)psin_server);
  1074. kfree(ses_init_buf);
  1075. }
  1076. /* else the negprot may still work without this
  1077. even though malloc failed */
  1078. }
  1079. return rc;
  1080. }
  1081. static int
  1082. ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
  1083. {
  1084. int rc = 0;
  1085. int connected = 0;
  1086. __be16 orig_port = 0;
  1087. if(*csocket == NULL) {
  1088. rc = sock_create_kern(PF_INET6, SOCK_STREAM, IPPROTO_TCP, csocket);
  1089. if (rc < 0) {
  1090. cERROR(1, ("Error %d creating ipv6 socket",rc));
  1091. *csocket = NULL;
  1092. return rc;
  1093. } else {
  1094. /* BB other socket options to set KEEPALIVE, NODELAY? */
  1095. cFYI(1,("ipv6 Socket created"));
  1096. (*csocket)->sk->sk_allocation = GFP_NOFS;
  1097. }
  1098. }
  1099. psin_server->sin6_family = AF_INET6;
  1100. if(psin_server->sin6_port) { /* user overrode default port */
  1101. rc = (*csocket)->ops->connect(*csocket,
  1102. (struct sockaddr *) psin_server,
  1103. sizeof (struct sockaddr_in6),0);
  1104. if (rc >= 0)
  1105. connected = 1;
  1106. }
  1107. if(!connected) {
  1108. /* save original port so we can retry user specified port
  1109. later if fall back ports fail this time */
  1110. orig_port = psin_server->sin6_port;
  1111. /* do not retry on the same port we just failed on */
  1112. if(psin_server->sin6_port != htons(CIFS_PORT)) {
  1113. psin_server->sin6_port = htons(CIFS_PORT);
  1114. rc = (*csocket)->ops->connect(*csocket,
  1115. (struct sockaddr *) psin_server,
  1116. sizeof (struct sockaddr_in6),0);
  1117. if (rc >= 0)
  1118. connected = 1;
  1119. }
  1120. }
  1121. if (!connected) {
  1122. psin_server->sin6_port = htons(RFC1001_PORT);
  1123. rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
  1124. psin_server, sizeof (struct sockaddr_in6),0);
  1125. if (rc >= 0)
  1126. connected = 1;
  1127. }
  1128. /* give up here - unless we want to retry on different
  1129. protocol families some day */
  1130. if (!connected) {
  1131. if(orig_port)
  1132. psin_server->sin6_port = orig_port;
  1133. cFYI(1,("Error %d connecting to server via ipv6",rc));
  1134. sock_release(*csocket);
  1135. *csocket = NULL;
  1136. return rc;
  1137. }
  1138. /* Eventually check for other socket options to change from
  1139. the default. sock_setsockopt not used because it expects
  1140. user space buffer */
  1141. (*csocket)->sk->sk_rcvtimeo = 7 * HZ;
  1142. return rc;
  1143. }
  1144. int
  1145. cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
  1146. char *mount_data, const char *devname)
  1147. {
  1148. int rc = 0;
  1149. int xid;
  1150. int address_type = AF_INET;
  1151. struct socket *csocket = NULL;
  1152. struct sockaddr_in sin_server;
  1153. struct sockaddr_in6 sin_server6;
  1154. struct smb_vol volume_info;
  1155. struct cifsSesInfo *pSesInfo = NULL;
  1156. struct cifsSesInfo *existingCifsSes = NULL;
  1157. struct cifsTconInfo *tcon = NULL;
  1158. struct TCP_Server_Info *srvTcp = NULL;
  1159. xid = GetXid();
  1160. /* cFYI(1, ("Entering cifs_mount. Xid: %d with: %s", xid, mount_data)); */
  1161. memset(&volume_info,0,sizeof(struct smb_vol));
  1162. if (cifs_parse_mount_options(mount_data, devname, &volume_info)) {
  1163. if(volume_info.UNC)
  1164. kfree(volume_info.UNC);
  1165. if(volume_info.password)
  1166. kfree(volume_info.password);
  1167. FreeXid(xid);
  1168. return -EINVAL;
  1169. }
  1170. if (volume_info.username) {
  1171. /* BB fixme parse for domain name here */
  1172. cFYI(1, ("Username: %s ", volume_info.username));
  1173. } else {
  1174. cifserror("No username specified ");
  1175. /* In userspace mount helper we can get user name from alternate
  1176. locations such as env variables and files on disk */
  1177. if(volume_info.UNC)
  1178. kfree(volume_info.UNC);
  1179. if(volume_info.password)
  1180. kfree(volume_info.password);
  1181. FreeXid(xid);
  1182. return -EINVAL;
  1183. }
  1184. if (volume_info.UNCip && volume_info.UNC) {
  1185. rc = cifs_inet_pton(AF_INET, volume_info.UNCip,&sin_server.sin_addr.s_addr);
  1186. if(rc <= 0) {
  1187. /* not ipv4 address, try ipv6 */
  1188. rc = cifs_inet_pton(AF_INET6,volume_info.UNCip,&sin_server6.sin6_addr.in6_u);
  1189. if(rc > 0)
  1190. address_type = AF_INET6;
  1191. } else {
  1192. address_type = AF_INET;
  1193. }
  1194. if(rc <= 0) {
  1195. /* we failed translating address */
  1196. if(volume_info.UNC)
  1197. kfree(volume_info.UNC);
  1198. if(volume_info.password)
  1199. kfree(volume_info.password);
  1200. FreeXid(xid);
  1201. return -EINVAL;
  1202. }
  1203. cFYI(1, ("UNC: %s ip: %s", volume_info.UNC, volume_info.UNCip));
  1204. /* success */
  1205. rc = 0;
  1206. } else if (volume_info.UNCip){
  1207. /* BB using ip addr as server name connect to the DFS root below */
  1208. cERROR(1,("Connecting to DFS root not implemented yet"));
  1209. if(volume_info.UNC)
  1210. kfree(volume_info.UNC);
  1211. if(volume_info.password)
  1212. kfree(volume_info.password);
  1213. FreeXid(xid);
  1214. return -EINVAL;
  1215. } else /* which servers DFS root would we conect to */ {
  1216. cERROR(1,
  1217. ("CIFS mount error: No UNC path (e.g. -o unc=//192.168.1.100/public) specified "));
  1218. if(volume_info.UNC)
  1219. kfree(volume_info.UNC);
  1220. if(volume_info.password)
  1221. kfree(volume_info.password);
  1222. FreeXid(xid);
  1223. return -EINVAL;
  1224. }
  1225. /* this is needed for ASCII cp to Unicode converts */
  1226. if(volume_info.iocharset == NULL) {
  1227. cifs_sb->local_nls = load_nls_default();
  1228. /* load_nls_default can not return null */
  1229. } else {
  1230. cifs_sb->local_nls = load_nls(volume_info.iocharset);
  1231. if(cifs_sb->local_nls == NULL) {
  1232. cERROR(1,("CIFS mount error: iocharset %s not found",volume_info.iocharset));
  1233. if(volume_info.UNC)
  1234. kfree(volume_info.UNC);
  1235. if(volume_info.password)
  1236. kfree(volume_info.password);
  1237. FreeXid(xid);
  1238. return -ELIBACC;
  1239. }
  1240. }
  1241. if(address_type == AF_INET)
  1242. existingCifsSes = cifs_find_tcp_session(&sin_server.sin_addr,
  1243. NULL /* no ipv6 addr */,
  1244. volume_info.username, &srvTcp);
  1245. else if(address_type == AF_INET6)
  1246. existingCifsSes = cifs_find_tcp_session(NULL /* no ipv4 addr */,
  1247. &sin_server6.sin6_addr,
  1248. volume_info.username, &srvTcp);
  1249. else {
  1250. if(volume_info.UNC)
  1251. kfree(volume_info.UNC);
  1252. if(volume_info.password)
  1253. kfree(volume_info.password);
  1254. FreeXid(xid);
  1255. return -EINVAL;
  1256. }
  1257. if (srvTcp) {
  1258. cFYI(1, ("Existing tcp session with server found "));
  1259. } else { /* create socket */
  1260. if(volume_info.port)
  1261. sin_server.sin_port = htons(volume_info.port);
  1262. else
  1263. sin_server.sin_port = 0;
  1264. rc = ipv4_connect(&sin_server,&csocket,volume_info.source_rfc1001_name);
  1265. if (rc < 0) {
  1266. cERROR(1,
  1267. ("Error connecting to IPv4 socket. Aborting operation"));
  1268. if(csocket != NULL)
  1269. sock_release(csocket);
  1270. if(volume_info.UNC)
  1271. kfree(volume_info.UNC);
  1272. if(volume_info.password)
  1273. kfree(volume_info.password);
  1274. FreeXid(xid);
  1275. return rc;
  1276. }
  1277. srvTcp = kmalloc(sizeof (struct TCP_Server_Info), GFP_KERNEL);
  1278. if (srvTcp == NULL) {
  1279. rc = -ENOMEM;
  1280. sock_release(csocket);
  1281. if(volume_info.UNC)
  1282. kfree(volume_info.UNC);
  1283. if(volume_info.password)
  1284. kfree(volume_info.password);
  1285. FreeXid(xid);
  1286. return rc;
  1287. } else {
  1288. memset(srvTcp, 0, sizeof (struct TCP_Server_Info));
  1289. memcpy(&srvTcp->addr.sockAddr, &sin_server, sizeof (struct sockaddr_in));
  1290. atomic_set(&srvTcp->inFlight,0);
  1291. /* BB Add code for ipv6 case too */
  1292. srvTcp->ssocket = csocket;
  1293. srvTcp->protocolType = IPV4;
  1294. init_waitqueue_head(&srvTcp->response_q);
  1295. init_waitqueue_head(&srvTcp->request_q);
  1296. INIT_LIST_HEAD(&srvTcp->pending_mid_q);
  1297. /* at this point we are the only ones with the pointer
  1298. to the struct since the kernel thread not created yet
  1299. so no need to spinlock this init of tcpStatus */
  1300. srvTcp->tcpStatus = CifsNew;
  1301. init_MUTEX(&srvTcp->tcpSem);
  1302. rc = (int)kernel_thread((void *)(void *)cifs_demultiplex_thread, srvTcp,
  1303. CLONE_FS | CLONE_FILES | CLONE_VM);
  1304. if(rc < 0) {
  1305. rc = -ENOMEM;
  1306. sock_release(csocket);
  1307. if(volume_info.UNC)
  1308. kfree(volume_info.UNC);
  1309. if(volume_info.password)
  1310. kfree(volume_info.password);
  1311. FreeXid(xid);
  1312. return rc;
  1313. } else
  1314. rc = 0;
  1315. memcpy(srvTcp->workstation_RFC1001_name, volume_info.source_rfc1001_name,16);
  1316. srvTcp->sequence_number = 0;
  1317. }
  1318. }
  1319. if (existingCifsSes) {
  1320. pSesInfo = existingCifsSes;
  1321. cFYI(1, ("Existing smb sess found "));
  1322. if(volume_info.password)
  1323. kfree(volume_info.password);
  1324. /* volume_info.UNC freed at end of function */
  1325. } else if (!rc) {
  1326. cFYI(1, ("Existing smb sess not found "));
  1327. pSesInfo = sesInfoAlloc();
  1328. if (pSesInfo == NULL)
  1329. rc = -ENOMEM;
  1330. else {
  1331. pSesInfo->server = srvTcp;
  1332. sprintf(pSesInfo->serverName, "%u.%u.%u.%u",
  1333. NIPQUAD(sin_server.sin_addr.s_addr));
  1334. }
  1335. if (!rc){
  1336. /* volume_info.password freed at unmount */
  1337. if (volume_info.password)
  1338. pSesInfo->password = volume_info.password;
  1339. if (volume_info.username)
  1340. strncpy(pSesInfo->userName,
  1341. volume_info.username,MAX_USERNAME_SIZE);
  1342. if (volume_info.domainname)
  1343. strncpy(pSesInfo->domainName,
  1344. volume_info.domainname,MAX_USERNAME_SIZE);
  1345. pSesInfo->linux_uid = volume_info.linux_uid;
  1346. down(&pSesInfo->sesSem);
  1347. rc = cifs_setup_session(xid,pSesInfo, cifs_sb->local_nls);
  1348. up(&pSesInfo->sesSem);
  1349. if(!rc)
  1350. atomic_inc(&srvTcp->socketUseCount);
  1351. } else
  1352. if(volume_info.password)
  1353. kfree(volume_info.password);
  1354. }
  1355. /* search for existing tcon to this server share */
  1356. if (!rc) {
  1357. if((volume_info.rsize) && (volume_info.rsize <= CIFSMaxBufSize))
  1358. cifs_sb->rsize = volume_info.rsize;
  1359. else
  1360. cifs_sb->rsize = srvTcp->maxBuf - MAX_CIFS_HDR_SIZE; /* default */
  1361. if((volume_info.wsize) && (volume_info.wsize <= CIFSMaxBufSize))
  1362. cifs_sb->wsize = volume_info.wsize;
  1363. else
  1364. cifs_sb->wsize = CIFSMaxBufSize; /* default */
  1365. if(cifs_sb->rsize < PAGE_CACHE_SIZE) {
  1366. cifs_sb->rsize = PAGE_CACHE_SIZE;
  1367. cERROR(1,("Attempt to set readsize for mount to less than one page (4096)"));
  1368. }
  1369. cifs_sb->mnt_uid = volume_info.linux_uid;
  1370. cifs_sb->mnt_gid = volume_info.linux_gid;
  1371. cifs_sb->mnt_file_mode = volume_info.file_mode;
  1372. cifs_sb->mnt_dir_mode = volume_info.dir_mode;
  1373. cFYI(1,("file mode: 0x%x dir mode: 0x%x",cifs_sb->mnt_file_mode,cifs_sb->mnt_dir_mode));
  1374. if(volume_info.noperm)
  1375. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
  1376. if(volume_info.setuids)
  1377. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
  1378. if(volume_info.server_ino)
  1379. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
  1380. if(volume_info.remap)
  1381. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
  1382. if(volume_info.no_xattr)
  1383. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
  1384. if(volume_info.direct_io) {
  1385. cERROR(1,("mounting share using direct i/o"));
  1386. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
  1387. }
  1388. tcon =
  1389. find_unc(sin_server.sin_addr.s_addr, volume_info.UNC,
  1390. volume_info.username);
  1391. if (tcon) {
  1392. cFYI(1, ("Found match on UNC path "));
  1393. /* we can have only one retry value for a connection
  1394. to a share so for resources mounted more than once
  1395. to the same server share the last value passed in
  1396. for the retry flag is used */
  1397. tcon->retry = volume_info.retry;
  1398. } else {
  1399. tcon = tconInfoAlloc();
  1400. if (tcon == NULL)
  1401. rc = -ENOMEM;
  1402. else {
  1403. /* check for null share name ie connect to dfs root */
  1404. /* BB check if this works for exactly length three strings */
  1405. if ((strchr(volume_info.UNC + 3, '\\') == NULL)
  1406. && (strchr(volume_info.UNC + 3, '/') ==
  1407. NULL)) {
  1408. rc = connect_to_dfs_path(xid, pSesInfo,
  1409. "", cifs_sb->local_nls,
  1410. cifs_sb->mnt_cifs_flags &
  1411. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1412. if(volume_info.UNC)
  1413. kfree(volume_info.UNC);
  1414. FreeXid(xid);
  1415. return -ENODEV;
  1416. } else {
  1417. rc = CIFSTCon(xid, pSesInfo,
  1418. volume_info.UNC,
  1419. tcon, cifs_sb->local_nls);
  1420. cFYI(1, ("CIFS Tcon rc = %d", rc));
  1421. }
  1422. if (!rc) {
  1423. atomic_inc(&pSesInfo->inUse);
  1424. tcon->retry = volume_info.retry;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. if(pSesInfo) {
  1430. if (pSesInfo->capabilities & CAP_LARGE_FILES) {
  1431. sb->s_maxbytes = (u64) 1 << 63;
  1432. } else
  1433. sb->s_maxbytes = (u64) 1 << 31; /* 2 GB */
  1434. }
  1435. sb->s_time_gran = 100;
  1436. /* on error free sesinfo and tcon struct if needed */
  1437. if (rc) {
  1438. /* if session setup failed, use count is zero but
  1439. we still need to free cifsd thread */
  1440. if(atomic_read(&srvTcp->socketUseCount) == 0) {
  1441. spin_lock(&GlobalMid_Lock);
  1442. srvTcp->tcpStatus = CifsExiting;
  1443. spin_unlock(&GlobalMid_Lock);
  1444. if(srvTcp->tsk)
  1445. send_sig(SIGKILL,srvTcp->tsk,1);
  1446. }
  1447. /* If find_unc succeeded then rc == 0 so we can not end */
  1448. if (tcon) /* up accidently freeing someone elses tcon struct */
  1449. tconInfoFree(tcon);
  1450. if (existingCifsSes == NULL) {
  1451. if (pSesInfo) {
  1452. if ((pSesInfo->server) &&
  1453. (pSesInfo->status == CifsGood)) {
  1454. int temp_rc;
  1455. temp_rc = CIFSSMBLogoff(xid, pSesInfo);
  1456. /* if the socketUseCount is now zero */
  1457. if((temp_rc == -ESHUTDOWN) &&
  1458. (pSesInfo->server->tsk))
  1459. send_sig(SIGKILL,pSesInfo->server->tsk,1);
  1460. } else
  1461. cFYI(1, ("No session or bad tcon"));
  1462. sesInfoFree(pSesInfo);
  1463. /* pSesInfo = NULL; */
  1464. }
  1465. }
  1466. } else {
  1467. atomic_inc(&tcon->useCount);
  1468. cifs_sb->tcon = tcon;
  1469. tcon->ses = pSesInfo;
  1470. /* do not care if following two calls succeed - informational only */
  1471. CIFSSMBQFSDeviceInfo(xid, tcon);
  1472. CIFSSMBQFSAttributeInfo(xid, tcon);
  1473. if (tcon->ses->capabilities & CAP_UNIX) {
  1474. if(!CIFSSMBQFSUnixInfo(xid, tcon)) {
  1475. if(!volume_info.no_psx_acl) {
  1476. if(CIFS_UNIX_POSIX_ACL_CAP &
  1477. le64_to_cpu(tcon->fsUnixInfo.Capability))
  1478. cFYI(1,("server negotiated posix acl support"));
  1479. sb->s_flags |= MS_POSIXACL;
  1480. }
  1481. }
  1482. }
  1483. }
  1484. /* volume_info.password is freed above when existing session found
  1485. (in which case it is not needed anymore) but when new sesion is created
  1486. the password ptr is put in the new session structure (in which case the
  1487. password will be freed at unmount time) */
  1488. if(volume_info.UNC)
  1489. kfree(volume_info.UNC);
  1490. FreeXid(xid);
  1491. return rc;
  1492. }
  1493. static int
  1494. CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
  1495. char session_key[CIFS_SESSION_KEY_SIZE],
  1496. const struct nls_table *nls_codepage)
  1497. {
  1498. struct smb_hdr *smb_buffer;
  1499. struct smb_hdr *smb_buffer_response;
  1500. SESSION_SETUP_ANDX *pSMB;
  1501. SESSION_SETUP_ANDX *pSMBr;
  1502. char *bcc_ptr;
  1503. char *user;
  1504. char *domain;
  1505. int rc = 0;
  1506. int remaining_words = 0;
  1507. int bytes_returned = 0;
  1508. int len;
  1509. __u32 capabilities;
  1510. __u16 count;
  1511. cFYI(1, ("In sesssetup "));
  1512. if(ses == NULL)
  1513. return -EINVAL;
  1514. user = ses->userName;
  1515. domain = ses->domainName;
  1516. smb_buffer = cifs_buf_get();
  1517. if (smb_buffer == NULL) {
  1518. return -ENOMEM;
  1519. }
  1520. smb_buffer_response = smb_buffer;
  1521. pSMBr = pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
  1522. /* send SMBsessionSetup here */
  1523. header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
  1524. NULL /* no tCon exists yet */ , 13 /* wct */ );
  1525. pSMB->req_no_secext.AndXCommand = 0xFF;
  1526. pSMB->req_no_secext.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
  1527. pSMB->req_no_secext.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
  1528. if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  1529. smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  1530. capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
  1531. CAP_LARGE_WRITE_X | CAP_LARGE_READ_X;
  1532. if (ses->capabilities & CAP_UNICODE) {
  1533. smb_buffer->Flags2 |= SMBFLG2_UNICODE;
  1534. capabilities |= CAP_UNICODE;
  1535. }
  1536. if (ses->capabilities & CAP_STATUS32) {
  1537. smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
  1538. capabilities |= CAP_STATUS32;
  1539. }
  1540. if (ses->capabilities & CAP_DFS) {
  1541. smb_buffer->Flags2 |= SMBFLG2_DFS;
  1542. capabilities |= CAP_DFS;
  1543. }
  1544. pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities);
  1545. pSMB->req_no_secext.CaseInsensitivePasswordLength =
  1546. cpu_to_le16(CIFS_SESSION_KEY_SIZE);
  1547. pSMB->req_no_secext.CaseSensitivePasswordLength =
  1548. cpu_to_le16(CIFS_SESSION_KEY_SIZE);
  1549. bcc_ptr = pByteArea(smb_buffer);
  1550. memcpy(bcc_ptr, (char *) session_key, CIFS_SESSION_KEY_SIZE);
  1551. bcc_ptr += CIFS_SESSION_KEY_SIZE;
  1552. memcpy(bcc_ptr, (char *) session_key, CIFS_SESSION_KEY_SIZE);
  1553. bcc_ptr += CIFS_SESSION_KEY_SIZE;
  1554. if (ses->capabilities & CAP_UNICODE) {
  1555. if ((long) bcc_ptr % 2) { /* must be word aligned for Unicode */
  1556. *bcc_ptr = 0;
  1557. bcc_ptr++;
  1558. }
  1559. if(user == NULL)
  1560. bytes_returned = 0; /* skill null user */
  1561. else
  1562. bytes_returned =
  1563. cifs_strtoUCS((wchar_t *) bcc_ptr, user, 100,
  1564. nls_codepage);
  1565. /* convert number of 16 bit words to bytes */
  1566. bcc_ptr += 2 * bytes_returned;
  1567. bcc_ptr += 2; /* trailing null */
  1568. if (domain == NULL)
  1569. bytes_returned =
  1570. cifs_strtoUCS((wchar_t *) bcc_ptr,
  1571. "CIFS_LINUX_DOM", 32, nls_codepage);
  1572. else
  1573. bytes_returned =
  1574. cifs_strtoUCS((wchar_t *) bcc_ptr, domain, 64,
  1575. nls_codepage);
  1576. bcc_ptr += 2 * bytes_returned;
  1577. bcc_ptr += 2;
  1578. bytes_returned =
  1579. cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
  1580. 32, nls_codepage);
  1581. bcc_ptr += 2 * bytes_returned;
  1582. bytes_returned =
  1583. cifs_strtoUCS((wchar_t *) bcc_ptr, system_utsname.release,
  1584. 32, nls_codepage);
  1585. bcc_ptr += 2 * bytes_returned;
  1586. bcc_ptr += 2;
  1587. bytes_returned =
  1588. cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
  1589. 64, nls_codepage);
  1590. bcc_ptr += 2 * bytes_returned;
  1591. bcc_ptr += 2;
  1592. } else {
  1593. if(user != NULL) {
  1594. strncpy(bcc_ptr, user, 200);
  1595. bcc_ptr += strnlen(user, 200);
  1596. }
  1597. *bcc_ptr = 0;
  1598. bcc_ptr++;
  1599. if (domain == NULL) {
  1600. strcpy(bcc_ptr, "CIFS_LINUX_DOM");
  1601. bcc_ptr += strlen("CIFS_LINUX_DOM") + 1;
  1602. } else {
  1603. strncpy(bcc_ptr, domain, 64);
  1604. bcc_ptr += strnlen(domain, 64);
  1605. *bcc_ptr = 0;
  1606. bcc_ptr++;
  1607. }
  1608. strcpy(bcc_ptr, "Linux version ");
  1609. bcc_ptr += strlen("Linux version ");
  1610. strcpy(bcc_ptr, system_utsname.release);
  1611. bcc_ptr += strlen(system_utsname.release) + 1;
  1612. strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
  1613. bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
  1614. }
  1615. count = (long) bcc_ptr - (long) pByteArea(smb_buffer);
  1616. smb_buffer->smb_buf_length += count;
  1617. pSMB->req_no_secext.ByteCount = cpu_to_le16(count);
  1618. rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
  1619. &bytes_returned, 1);
  1620. if (rc) {
  1621. /* rc = map_smb_to_linux_error(smb_buffer_response); now done in SendReceive */
  1622. } else if ((smb_buffer_response->WordCount == 3)
  1623. || (smb_buffer_response->WordCount == 4)) {
  1624. __u16 action = le16_to_cpu(pSMBr->resp.Action);
  1625. __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength);
  1626. if (action & GUEST_LOGIN)
  1627. cFYI(1, (" Guest login")); /* do we want to mark SesInfo struct ? */
  1628. ses->Suid = smb_buffer_response->Uid; /* UID left in wire format (le) */
  1629. cFYI(1, ("UID = %d ", ses->Suid));
  1630. /* response can have either 3 or 4 word count - Samba sends 3 */
  1631. bcc_ptr = pByteArea(smb_buffer_response);
  1632. if ((pSMBr->resp.hdr.WordCount == 3)
  1633. || ((pSMBr->resp.hdr.WordCount == 4)
  1634. && (blob_len < pSMBr->resp.ByteCount))) {
  1635. if (pSMBr->resp.hdr.WordCount == 4)
  1636. bcc_ptr += blob_len;
  1637. if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
  1638. if ((long) (bcc_ptr) % 2) {
  1639. remaining_words =
  1640. (BCC(smb_buffer_response) - 1) /2;
  1641. bcc_ptr++; /* Unicode strings must be word aligned */
  1642. } else {
  1643. remaining_words =
  1644. BCC(smb_buffer_response) / 2;
  1645. }
  1646. len =
  1647. UniStrnlen((wchar_t *) bcc_ptr,
  1648. remaining_words - 1);
  1649. /* We look for obvious messed up bcc or strings in response so we do not go off
  1650. the end since (at least) WIN2K and Windows XP have a major bug in not null
  1651. terminating last Unicode string in response */
  1652. ses->serverOS = kcalloc(1, 2 * (len + 1), GFP_KERNEL);
  1653. if(ses->serverOS == NULL)
  1654. goto sesssetup_nomem;
  1655. cifs_strfromUCS_le(ses->serverOS,
  1656. (wchar_t *)bcc_ptr, len,nls_codepage);
  1657. bcc_ptr += 2 * (len + 1);
  1658. remaining_words -= len + 1;
  1659. ses->serverOS[2 * len] = 0;
  1660. ses->serverOS[1 + (2 * len)] = 0;
  1661. if (remaining_words > 0) {
  1662. len = UniStrnlen((wchar_t *)bcc_ptr,
  1663. remaining_words-1);
  1664. ses->serverNOS = kcalloc(1, 2 * (len + 1),GFP_KERNEL);
  1665. if(ses->serverNOS == NULL)
  1666. goto sesssetup_nomem;
  1667. cifs_strfromUCS_le(ses->serverNOS,
  1668. (wchar_t *)bcc_ptr,len,nls_codepage);
  1669. bcc_ptr += 2 * (len + 1);
  1670. ses->serverNOS[2 * len] = 0;
  1671. ses->serverNOS[1 + (2 * len)] = 0;
  1672. if(strncmp(ses->serverNOS,
  1673. "NT LAN Manager 4",16) == 0) {
  1674. cFYI(1,("NT4 server"));
  1675. ses->flags |= CIFS_SES_NT4;
  1676. }
  1677. remaining_words -= len + 1;
  1678. if (remaining_words > 0) {
  1679. len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
  1680. /* last string is not always null terminated (for e.g. for Windows XP & 2000) */
  1681. ses->serverDomain =
  1682. kcalloc(1, 2*(len+1),GFP_KERNEL);
  1683. if(ses->serverDomain == NULL)
  1684. goto sesssetup_nomem;
  1685. cifs_strfromUCS_le(ses->serverDomain,
  1686. (wchar_t *)bcc_ptr,len,nls_codepage);
  1687. bcc_ptr += 2 * (len + 1);
  1688. ses->serverDomain[2*len] = 0;
  1689. ses->serverDomain[1+(2*len)] = 0;
  1690. } /* else no more room so create dummy domain string */
  1691. else
  1692. ses->serverDomain =
  1693. kcalloc(1, 2, GFP_KERNEL);
  1694. } else { /* no room so create dummy domain and NOS string */
  1695. /* if these kcallocs fail not much we
  1696. can do, but better to not fail the
  1697. sesssetup itself */
  1698. ses->serverDomain =
  1699. kcalloc(1, 2, GFP_KERNEL);
  1700. ses->serverNOS =
  1701. kcalloc(1, 2, GFP_KERNEL);
  1702. }
  1703. } else { /* ASCII */
  1704. len = strnlen(bcc_ptr, 1024);
  1705. if (((long) bcc_ptr + len) - (long)
  1706. pByteArea(smb_buffer_response)
  1707. <= BCC(smb_buffer_response)) {
  1708. ses->serverOS = kcalloc(1, len + 1,GFP_KERNEL);
  1709. if(ses->serverOS == NULL)
  1710. goto sesssetup_nomem;
  1711. strncpy(ses->serverOS,bcc_ptr, len);
  1712. bcc_ptr += len;
  1713. bcc_ptr[0] = 0; /* null terminate the string */
  1714. bcc_ptr++;
  1715. len = strnlen(bcc_ptr, 1024);
  1716. ses->serverNOS = kcalloc(1, len + 1,GFP_KERNEL);
  1717. if(ses->serverNOS == NULL)
  1718. goto sesssetup_nomem;
  1719. strncpy(ses->serverNOS, bcc_ptr, len);
  1720. bcc_ptr += len;
  1721. bcc_ptr[0] = 0;
  1722. bcc_ptr++;
  1723. len = strnlen(bcc_ptr, 1024);
  1724. ses->serverDomain = kcalloc(1, len + 1,GFP_KERNEL);
  1725. if(ses->serverDomain == NULL)
  1726. goto sesssetup_nomem;
  1727. strncpy(ses->serverDomain, bcc_ptr, len);
  1728. bcc_ptr += len;
  1729. bcc_ptr[0] = 0;
  1730. bcc_ptr++;
  1731. } else
  1732. cFYI(1,
  1733. ("Variable field of length %d extends beyond end of smb ",
  1734. len));
  1735. }
  1736. } else {
  1737. cERROR(1,
  1738. (" Security Blob Length extends beyond end of SMB"));
  1739. }
  1740. } else {
  1741. cERROR(1,
  1742. (" Invalid Word count %d: ",
  1743. smb_buffer_response->WordCount));
  1744. rc = -EIO;
  1745. }
  1746. sesssetup_nomem: /* do not return an error on nomem for the info strings,
  1747. since that could make reconnection harder, and
  1748. reconnection might be needed to free memory */
  1749. if (smb_buffer)
  1750. cifs_buf_release(smb_buffer);
  1751. return rc;
  1752. }
  1753. static int
  1754. CIFSSpnegoSessSetup(unsigned int xid, struct cifsSesInfo *ses,
  1755. char *SecurityBlob,int SecurityBlobLength,
  1756. const struct nls_table *nls_codepage)
  1757. {
  1758. struct smb_hdr *smb_buffer;
  1759. struct smb_hdr *smb_buffer_response;
  1760. SESSION_SETUP_ANDX *pSMB;
  1761. SESSION_SETUP_ANDX *pSMBr;
  1762. char *bcc_ptr;
  1763. char *user;
  1764. char *domain;
  1765. int rc = 0;
  1766. int remaining_words = 0;
  1767. int bytes_returned = 0;
  1768. int len;
  1769. __u32 capabilities;
  1770. __u16 count;
  1771. cFYI(1, ("In spnego sesssetup "));
  1772. if(ses == NULL)
  1773. return -EINVAL;
  1774. user = ses->userName;
  1775. domain = ses->domainName;
  1776. smb_buffer = cifs_buf_get();
  1777. if (smb_buffer == NULL) {
  1778. return -ENOMEM;
  1779. }
  1780. smb_buffer_response = smb_buffer;
  1781. pSMBr = pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
  1782. /* send SMBsessionSetup here */
  1783. header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
  1784. NULL /* no tCon exists yet */ , 12 /* wct */ );
  1785. pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
  1786. pSMB->req.AndXCommand = 0xFF;
  1787. pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
  1788. pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
  1789. if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  1790. smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  1791. capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
  1792. CAP_EXTENDED_SECURITY;
  1793. if (ses->capabilities & CAP_UNICODE) {
  1794. smb_buffer->Flags2 |= SMBFLG2_UNICODE;
  1795. capabilities |= CAP_UNICODE;
  1796. }
  1797. if (ses->capabilities & CAP_STATUS32) {
  1798. smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
  1799. capabilities |= CAP_STATUS32;
  1800. }
  1801. if (ses->capabilities & CAP_DFS) {
  1802. smb_buffer->Flags2 |= SMBFLG2_DFS;
  1803. capabilities |= CAP_DFS;
  1804. }
  1805. pSMB->req.Capabilities = cpu_to_le32(capabilities);
  1806. pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength);
  1807. bcc_ptr = pByteArea(smb_buffer);
  1808. memcpy(bcc_ptr, SecurityBlob, SecurityBlobLength);
  1809. bcc_ptr += SecurityBlobLength;
  1810. if (ses->capabilities & CAP_UNICODE) {
  1811. if ((long) bcc_ptr % 2) { /* must be word aligned for Unicode strings */
  1812. *bcc_ptr = 0;
  1813. bcc_ptr++;
  1814. }
  1815. bytes_returned =
  1816. cifs_strtoUCS((wchar_t *) bcc_ptr, user, 100, nls_codepage);
  1817. bcc_ptr += 2 * bytes_returned; /* convert num of 16 bit words to bytes */
  1818. bcc_ptr += 2; /* trailing null */
  1819. if (domain == NULL)
  1820. bytes_returned =
  1821. cifs_strtoUCS((wchar_t *) bcc_ptr,
  1822. "CIFS_LINUX_DOM", 32, nls_codepage);
  1823. else
  1824. bytes_returned =
  1825. cifs_strtoUCS((wchar_t *) bcc_ptr, domain, 64,
  1826. nls_codepage);
  1827. bcc_ptr += 2 * bytes_returned;
  1828. bcc_ptr += 2;
  1829. bytes_returned =
  1830. cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
  1831. 32, nls_codepage);
  1832. bcc_ptr += 2 * bytes_returned;
  1833. bytes_returned =
  1834. cifs_strtoUCS((wchar_t *) bcc_ptr, system_utsname.release, 32,
  1835. nls_codepage);
  1836. bcc_ptr += 2 * bytes_returned;
  1837. bcc_ptr += 2;
  1838. bytes_returned =
  1839. cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
  1840. 64, nls_codepage);
  1841. bcc_ptr += 2 * bytes_returned;
  1842. bcc_ptr += 2;
  1843. } else {
  1844. strncpy(bcc_ptr, user, 200);
  1845. bcc_ptr += strnlen(user, 200);
  1846. *bcc_ptr = 0;
  1847. bcc_ptr++;
  1848. if (domain == NULL) {
  1849. strcpy(bcc_ptr, "CIFS_LINUX_DOM");
  1850. bcc_ptr += strlen("CIFS_LINUX_DOM") + 1;
  1851. } else {
  1852. strncpy(bcc_ptr, domain, 64);
  1853. bcc_ptr += strnlen(domain, 64);
  1854. *bcc_ptr = 0;
  1855. bcc_ptr++;
  1856. }
  1857. strcpy(bcc_ptr, "Linux version ");
  1858. bcc_ptr += strlen("Linux version ");
  1859. strcpy(bcc_ptr, system_utsname.release);
  1860. bcc_ptr += strlen(system_utsname.release) + 1;
  1861. strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
  1862. bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
  1863. }
  1864. count = (long) bcc_ptr - (long) pByteArea(smb_buffer);
  1865. smb_buffer->smb_buf_length += count;
  1866. pSMB->req.ByteCount = cpu_to_le16(count);
  1867. rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
  1868. &bytes_returned, 1);
  1869. if (rc) {
  1870. /* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */
  1871. } else if ((smb_buffer_response->WordCount == 3)
  1872. || (smb_buffer_response->WordCount == 4)) {
  1873. __u16 action = le16_to_cpu(pSMBr->resp.Action);
  1874. __u16 blob_len =
  1875. le16_to_cpu(pSMBr->resp.SecurityBlobLength);
  1876. if (action & GUEST_LOGIN)
  1877. cFYI(1, (" Guest login")); /* BB do we want to set anything in SesInfo struct ? */
  1878. if (ses) {
  1879. ses->Suid = smb_buffer_response->Uid; /* UID left in wire format (le) */
  1880. cFYI(1, ("UID = %d ", ses->Suid));
  1881. bcc_ptr = pByteArea(smb_buffer_response); /* response can have either 3 or 4 word count - Samba sends 3 */
  1882. /* BB Fix below to make endian neutral !! */
  1883. if ((pSMBr->resp.hdr.WordCount == 3)
  1884. || ((pSMBr->resp.hdr.WordCount == 4)
  1885. && (blob_len <
  1886. pSMBr->resp.ByteCount))) {
  1887. if (pSMBr->resp.hdr.WordCount == 4) {
  1888. bcc_ptr +=
  1889. blob_len;
  1890. cFYI(1,
  1891. ("Security Blob Length %d ",
  1892. blob_len));
  1893. }
  1894. if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
  1895. if ((long) (bcc_ptr) % 2) {
  1896. remaining_words =
  1897. (BCC(smb_buffer_response)
  1898. - 1) / 2;
  1899. bcc_ptr++; /* Unicode strings must be word aligned */
  1900. } else {
  1901. remaining_words =
  1902. BCC
  1903. (smb_buffer_response) / 2;
  1904. }
  1905. len =
  1906. UniStrnlen((wchar_t *) bcc_ptr,
  1907. remaining_words - 1);
  1908. /* We look for obvious messed up bcc or strings in response so we do not go off
  1909. the end since (at least) WIN2K and Windows XP have a major bug in not null
  1910. terminating last Unicode string in response */
  1911. ses->serverOS =
  1912. kcalloc(1, 2 * (len + 1), GFP_KERNEL);
  1913. cifs_strfromUCS_le(ses->serverOS,
  1914. (wchar_t *)
  1915. bcc_ptr, len,
  1916. nls_codepage);
  1917. bcc_ptr += 2 * (len + 1);
  1918. remaining_words -= len + 1;
  1919. ses->serverOS[2 * len] = 0;
  1920. ses->serverOS[1 + (2 * len)] = 0;
  1921. if (remaining_words > 0) {
  1922. len = UniStrnlen((wchar_t *)bcc_ptr,
  1923. remaining_words
  1924. - 1);
  1925. ses->serverNOS =
  1926. kcalloc(1, 2 * (len + 1),
  1927. GFP_KERNEL);
  1928. cifs_strfromUCS_le(ses->serverNOS,
  1929. (wchar_t *)bcc_ptr,
  1930. len,
  1931. nls_codepage);
  1932. bcc_ptr += 2 * (len + 1);
  1933. ses->serverNOS[2 * len] = 0;
  1934. ses->serverNOS[1 + (2 * len)] = 0;
  1935. remaining_words -= len + 1;
  1936. if (remaining_words > 0) {
  1937. len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
  1938. /* last string is not always null terminated (for e.g. for Windows XP & 2000) */
  1939. ses->serverDomain = kcalloc(1, 2*(len+1),GFP_KERNEL);
  1940. cifs_strfromUCS_le(ses->serverDomain,
  1941. (wchar_t *)bcc_ptr,
  1942. len,
  1943. nls_codepage);
  1944. bcc_ptr += 2*(len+1);
  1945. ses->serverDomain[2*len] = 0;
  1946. ses->serverDomain[1+(2*len)] = 0;
  1947. } /* else no more room so create dummy domain string */
  1948. else
  1949. ses->serverDomain =
  1950. kcalloc(1, 2,GFP_KERNEL);
  1951. } else { /* no room so create dummy domain and NOS string */
  1952. ses->serverDomain = kcalloc(1, 2, GFP_KERNEL);
  1953. ses->serverNOS = kcalloc(1, 2, GFP_KERNEL);
  1954. }
  1955. } else { /* ASCII */
  1956. len = strnlen(bcc_ptr, 1024);
  1957. if (((long) bcc_ptr + len) - (long)
  1958. pByteArea(smb_buffer_response)
  1959. <= BCC(smb_buffer_response)) {
  1960. ses->serverOS = kcalloc(1, len + 1, GFP_KERNEL);
  1961. strncpy(ses->serverOS, bcc_ptr, len);
  1962. bcc_ptr += len;
  1963. bcc_ptr[0] = 0; /* null terminate the string */
  1964. bcc_ptr++;
  1965. len = strnlen(bcc_ptr, 1024);
  1966. ses->serverNOS = kcalloc(1, len + 1,GFP_KERNEL);
  1967. strncpy(ses->serverNOS, bcc_ptr, len);
  1968. bcc_ptr += len;
  1969. bcc_ptr[0] = 0;
  1970. bcc_ptr++;
  1971. len = strnlen(bcc_ptr, 1024);
  1972. ses->serverDomain = kcalloc(1, len + 1, GFP_KERNEL);
  1973. strncpy(ses->serverDomain, bcc_ptr, len);
  1974. bcc_ptr += len;
  1975. bcc_ptr[0] = 0;
  1976. bcc_ptr++;
  1977. } else
  1978. cFYI(1,
  1979. ("Variable field of length %d extends beyond end of smb ",
  1980. len));
  1981. }
  1982. } else {
  1983. cERROR(1,
  1984. (" Security Blob Length extends beyond end of SMB"));
  1985. }
  1986. } else {
  1987. cERROR(1, ("No session structure passed in."));
  1988. }
  1989. } else {
  1990. cERROR(1,
  1991. (" Invalid Word count %d: ",
  1992. smb_buffer_response->WordCount));
  1993. rc = -EIO;
  1994. }
  1995. if (smb_buffer)
  1996. cifs_buf_release(smb_buffer);
  1997. return rc;
  1998. }
  1999. static int
  2000. CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
  2001. struct cifsSesInfo *ses, int * pNTLMv2_flag,
  2002. const struct nls_table *nls_codepage)
  2003. {
  2004. struct smb_hdr *smb_buffer;
  2005. struct smb_hdr *smb_buffer_response;
  2006. SESSION_SETUP_ANDX *pSMB;
  2007. SESSION_SETUP_ANDX *pSMBr;
  2008. char *bcc_ptr;
  2009. char *domain;
  2010. int rc = 0;
  2011. int remaining_words = 0;
  2012. int bytes_returned = 0;
  2013. int len;
  2014. int SecurityBlobLength = sizeof (NEGOTIATE_MESSAGE);
  2015. PNEGOTIATE_MESSAGE SecurityBlob;
  2016. PCHALLENGE_MESSAGE SecurityBlob2;
  2017. __u32 negotiate_flags, capabilities;
  2018. __u16 count;
  2019. cFYI(1, ("In NTLMSSP sesssetup (negotiate) "));
  2020. if(ses == NULL)
  2021. return -EINVAL;
  2022. domain = ses->domainName;
  2023. *pNTLMv2_flag = FALSE;
  2024. smb_buffer = cifs_buf_get();
  2025. if (smb_buffer == NULL) {
  2026. return -ENOMEM;
  2027. }
  2028. smb_buffer_response = smb_buffer;
  2029. pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
  2030. pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response;
  2031. /* send SMBsessionSetup here */
  2032. header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
  2033. NULL /* no tCon exists yet */ , 12 /* wct */ );
  2034. pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
  2035. pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT);
  2036. pSMB->req.AndXCommand = 0xFF;
  2037. pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
  2038. pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
  2039. if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  2040. smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  2041. capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
  2042. CAP_EXTENDED_SECURITY;
  2043. if (ses->capabilities & CAP_UNICODE) {
  2044. smb_buffer->Flags2 |= SMBFLG2_UNICODE;
  2045. capabilities |= CAP_UNICODE;
  2046. }
  2047. if (ses->capabilities & CAP_STATUS32) {
  2048. smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
  2049. capabilities |= CAP_STATUS32;
  2050. }
  2051. if (ses->capabilities & CAP_DFS) {
  2052. smb_buffer->Flags2 |= SMBFLG2_DFS;
  2053. capabilities |= CAP_DFS;
  2054. }
  2055. pSMB->req.Capabilities = cpu_to_le32(capabilities);
  2056. bcc_ptr = (char *) &pSMB->req.SecurityBlob;
  2057. SecurityBlob = (PNEGOTIATE_MESSAGE) bcc_ptr;
  2058. strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8);
  2059. SecurityBlob->MessageType = NtLmNegotiate;
  2060. negotiate_flags =
  2061. NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_OEM |
  2062. NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_NTLM | 0x80000000 |
  2063. /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN | */ NTLMSSP_NEGOTIATE_128;
  2064. if(sign_CIFS_PDUs)
  2065. negotiate_flags |= NTLMSSP_NEGOTIATE_SIGN;
  2066. if(ntlmv2_support)
  2067. negotiate_flags |= NTLMSSP_NEGOTIATE_NTLMV2;
  2068. /* setup pointers to domain name and workstation name */
  2069. bcc_ptr += SecurityBlobLength;
  2070. SecurityBlob->WorkstationName.Buffer = 0;
  2071. SecurityBlob->WorkstationName.Length = 0;
  2072. SecurityBlob->WorkstationName.MaximumLength = 0;
  2073. if (domain == NULL) {
  2074. SecurityBlob->DomainName.Buffer = 0;
  2075. SecurityBlob->DomainName.Length = 0;
  2076. SecurityBlob->DomainName.MaximumLength = 0;
  2077. } else {
  2078. __u16 len;
  2079. negotiate_flags |= NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED;
  2080. strncpy(bcc_ptr, domain, 63);
  2081. len = strnlen(domain, 64);
  2082. SecurityBlob->DomainName.MaximumLength =
  2083. cpu_to_le16(len);
  2084. SecurityBlob->DomainName.Buffer =
  2085. cpu_to_le32((long) &SecurityBlob->
  2086. DomainString -
  2087. (long) &SecurityBlob->Signature);
  2088. bcc_ptr += len;
  2089. SecurityBlobLength += len;
  2090. SecurityBlob->DomainName.Length =
  2091. cpu_to_le16(len);
  2092. }
  2093. if (ses->capabilities & CAP_UNICODE) {
  2094. if ((long) bcc_ptr % 2) {
  2095. *bcc_ptr = 0;
  2096. bcc_ptr++;
  2097. }
  2098. bytes_returned =
  2099. cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
  2100. 32, nls_codepage);
  2101. bcc_ptr += 2 * bytes_returned;
  2102. bytes_returned =
  2103. cifs_strtoUCS((wchar_t *) bcc_ptr, system_utsname.release, 32,
  2104. nls_codepage);
  2105. bcc_ptr += 2 * bytes_returned;
  2106. bcc_ptr += 2; /* null terminate Linux version */
  2107. bytes_returned =
  2108. cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
  2109. 64, nls_codepage);
  2110. bcc_ptr += 2 * bytes_returned;
  2111. *(bcc_ptr + 1) = 0;
  2112. *(bcc_ptr + 2) = 0;
  2113. bcc_ptr += 2; /* null terminate network opsys string */
  2114. *(bcc_ptr + 1) = 0;
  2115. *(bcc_ptr + 2) = 0;
  2116. bcc_ptr += 2; /* null domain */
  2117. } else { /* ASCII */
  2118. strcpy(bcc_ptr, "Linux version ");
  2119. bcc_ptr += strlen("Linux version ");
  2120. strcpy(bcc_ptr, system_utsname.release);
  2121. bcc_ptr += strlen(system_utsname.release) + 1;
  2122. strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
  2123. bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
  2124. bcc_ptr++; /* empty domain field */
  2125. *bcc_ptr = 0;
  2126. }
  2127. SecurityBlob->NegotiateFlags = cpu_to_le32(negotiate_flags);
  2128. pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength);
  2129. count = (long) bcc_ptr - (long) pByteArea(smb_buffer);
  2130. smb_buffer->smb_buf_length += count;
  2131. pSMB->req.ByteCount = cpu_to_le16(count);
  2132. rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
  2133. &bytes_returned, 1);
  2134. if (smb_buffer_response->Status.CifsError ==
  2135. cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))
  2136. rc = 0;
  2137. if (rc) {
  2138. /* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */
  2139. } else if ((smb_buffer_response->WordCount == 3)
  2140. || (smb_buffer_response->WordCount == 4)) {
  2141. __u16 action = le16_to_cpu(pSMBr->resp.Action);
  2142. __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength);
  2143. if (action & GUEST_LOGIN)
  2144. cFYI(1, (" Guest login"));
  2145. /* Do we want to set anything in SesInfo struct when guest login? */
  2146. bcc_ptr = pByteArea(smb_buffer_response);
  2147. /* response can have either 3 or 4 word count - Samba sends 3 */
  2148. SecurityBlob2 = (PCHALLENGE_MESSAGE) bcc_ptr;
  2149. if (SecurityBlob2->MessageType != NtLmChallenge) {
  2150. cFYI(1,
  2151. ("Unexpected NTLMSSP message type received %d",
  2152. SecurityBlob2->MessageType));
  2153. } else if (ses) {
  2154. ses->Suid = smb_buffer_response->Uid; /* UID left in le format */
  2155. cFYI(1, ("UID = %d ", ses->Suid));
  2156. if ((pSMBr->resp.hdr.WordCount == 3)
  2157. || ((pSMBr->resp.hdr.WordCount == 4)
  2158. && (blob_len <
  2159. pSMBr->resp.ByteCount))) {
  2160. if (pSMBr->resp.hdr.WordCount == 4) {
  2161. bcc_ptr += blob_len;
  2162. cFYI(1,
  2163. ("Security Blob Length %d ",
  2164. blob_len));
  2165. }
  2166. cFYI(1, ("NTLMSSP Challenge rcvd "));
  2167. memcpy(ses->server->cryptKey,
  2168. SecurityBlob2->Challenge,
  2169. CIFS_CRYPTO_KEY_SIZE);
  2170. if(SecurityBlob2->NegotiateFlags & cpu_to_le32(NTLMSSP_NEGOTIATE_NTLMV2))
  2171. *pNTLMv2_flag = TRUE;
  2172. if((SecurityBlob2->NegotiateFlags &
  2173. cpu_to_le32(NTLMSSP_NEGOTIATE_ALWAYS_SIGN))
  2174. || (sign_CIFS_PDUs > 1))
  2175. ses->server->secMode |=
  2176. SECMODE_SIGN_REQUIRED;
  2177. if ((SecurityBlob2->NegotiateFlags &
  2178. cpu_to_le32(NTLMSSP_NEGOTIATE_SIGN)) && (sign_CIFS_PDUs))
  2179. ses->server->secMode |=
  2180. SECMODE_SIGN_ENABLED;
  2181. if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
  2182. if ((long) (bcc_ptr) % 2) {
  2183. remaining_words =
  2184. (BCC(smb_buffer_response)
  2185. - 1) / 2;
  2186. bcc_ptr++; /* Unicode strings must be word aligned */
  2187. } else {
  2188. remaining_words =
  2189. BCC
  2190. (smb_buffer_response) / 2;
  2191. }
  2192. len =
  2193. UniStrnlen((wchar_t *) bcc_ptr,
  2194. remaining_words - 1);
  2195. /* We look for obvious messed up bcc or strings in response so we do not go off
  2196. the end since (at least) WIN2K and Windows XP have a major bug in not null
  2197. terminating last Unicode string in response */
  2198. ses->serverOS =
  2199. kcalloc(1, 2 * (len + 1), GFP_KERNEL);
  2200. cifs_strfromUCS_le(ses->serverOS,
  2201. (wchar_t *)
  2202. bcc_ptr, len,
  2203. nls_codepage);
  2204. bcc_ptr += 2 * (len + 1);
  2205. remaining_words -= len + 1;
  2206. ses->serverOS[2 * len] = 0;
  2207. ses->serverOS[1 + (2 * len)] = 0;
  2208. if (remaining_words > 0) {
  2209. len = UniStrnlen((wchar_t *)
  2210. bcc_ptr,
  2211. remaining_words
  2212. - 1);
  2213. ses->serverNOS =
  2214. kcalloc(1, 2 * (len + 1),
  2215. GFP_KERNEL);
  2216. cifs_strfromUCS_le(ses->
  2217. serverNOS,
  2218. (wchar_t *)
  2219. bcc_ptr,
  2220. len,
  2221. nls_codepage);
  2222. bcc_ptr += 2 * (len + 1);
  2223. ses->serverNOS[2 * len] = 0;
  2224. ses->serverNOS[1 +
  2225. (2 * len)] = 0;
  2226. remaining_words -= len + 1;
  2227. if (remaining_words > 0) {
  2228. len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
  2229. /* last string is not always null terminated (for e.g. for Windows XP & 2000) */
  2230. ses->serverDomain =
  2231. kcalloc(1, 2 *
  2232. (len +
  2233. 1),
  2234. GFP_KERNEL);
  2235. cifs_strfromUCS_le
  2236. (ses->
  2237. serverDomain,
  2238. (wchar_t *)
  2239. bcc_ptr, len,
  2240. nls_codepage);
  2241. bcc_ptr +=
  2242. 2 * (len + 1);
  2243. ses->
  2244. serverDomain[2
  2245. * len]
  2246. = 0;
  2247. ses->
  2248. serverDomain[1
  2249. +
  2250. (2
  2251. *
  2252. len)]
  2253. = 0;
  2254. } /* else no more room so create dummy domain string */
  2255. else
  2256. ses->serverDomain =
  2257. kcalloc(1, 2,
  2258. GFP_KERNEL);
  2259. } else { /* no room so create dummy domain and NOS string */
  2260. ses->serverDomain =
  2261. kcalloc(1, 2, GFP_KERNEL);
  2262. ses->serverNOS =
  2263. kcalloc(1, 2, GFP_KERNEL);
  2264. }
  2265. } else { /* ASCII */
  2266. len = strnlen(bcc_ptr, 1024);
  2267. if (((long) bcc_ptr + len) - (long)
  2268. pByteArea(smb_buffer_response)
  2269. <= BCC(smb_buffer_response)) {
  2270. ses->serverOS =
  2271. kcalloc(1, len + 1,
  2272. GFP_KERNEL);
  2273. strncpy(ses->serverOS,
  2274. bcc_ptr, len);
  2275. bcc_ptr += len;
  2276. bcc_ptr[0] = 0; /* null terminate string */
  2277. bcc_ptr++;
  2278. len = strnlen(bcc_ptr, 1024);
  2279. ses->serverNOS =
  2280. kcalloc(1, len + 1,
  2281. GFP_KERNEL);
  2282. strncpy(ses->serverNOS, bcc_ptr, len);
  2283. bcc_ptr += len;
  2284. bcc_ptr[0] = 0;
  2285. bcc_ptr++;
  2286. len = strnlen(bcc_ptr, 1024);
  2287. ses->serverDomain =
  2288. kcalloc(1, len + 1,
  2289. GFP_KERNEL);
  2290. strncpy(ses->serverDomain, bcc_ptr, len);
  2291. bcc_ptr += len;
  2292. bcc_ptr[0] = 0;
  2293. bcc_ptr++;
  2294. } else
  2295. cFYI(1,
  2296. ("Variable field of length %d extends beyond end of smb ",
  2297. len));
  2298. }
  2299. } else {
  2300. cERROR(1,
  2301. (" Security Blob Length extends beyond end of SMB"));
  2302. }
  2303. } else {
  2304. cERROR(1, ("No session structure passed in."));
  2305. }
  2306. } else {
  2307. cERROR(1,
  2308. (" Invalid Word count %d: ",
  2309. smb_buffer_response->WordCount));
  2310. rc = -EIO;
  2311. }
  2312. if (smb_buffer)
  2313. cifs_buf_release(smb_buffer);
  2314. return rc;
  2315. }
  2316. static int
  2317. CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
  2318. char *ntlm_session_key, int ntlmv2_flag,
  2319. const struct nls_table *nls_codepage)
  2320. {
  2321. struct smb_hdr *smb_buffer;
  2322. struct smb_hdr *smb_buffer_response;
  2323. SESSION_SETUP_ANDX *pSMB;
  2324. SESSION_SETUP_ANDX *pSMBr;
  2325. char *bcc_ptr;
  2326. char *user;
  2327. char *domain;
  2328. int rc = 0;
  2329. int remaining_words = 0;
  2330. int bytes_returned = 0;
  2331. int len;
  2332. int SecurityBlobLength = sizeof (AUTHENTICATE_MESSAGE);
  2333. PAUTHENTICATE_MESSAGE SecurityBlob;
  2334. __u32 negotiate_flags, capabilities;
  2335. __u16 count;
  2336. cFYI(1, ("In NTLMSSPSessSetup (Authenticate)"));
  2337. if(ses == NULL)
  2338. return -EINVAL;
  2339. user = ses->userName;
  2340. domain = ses->domainName;
  2341. smb_buffer = cifs_buf_get();
  2342. if (smb_buffer == NULL) {
  2343. return -ENOMEM;
  2344. }
  2345. smb_buffer_response = smb_buffer;
  2346. pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
  2347. pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response;
  2348. /* send SMBsessionSetup here */
  2349. header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
  2350. NULL /* no tCon exists yet */ , 12 /* wct */ );
  2351. pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT);
  2352. pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
  2353. pSMB->req.AndXCommand = 0xFF;
  2354. pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
  2355. pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
  2356. pSMB->req.hdr.Uid = ses->Suid;
  2357. if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  2358. smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  2359. capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
  2360. CAP_EXTENDED_SECURITY;
  2361. if (ses->capabilities & CAP_UNICODE) {
  2362. smb_buffer->Flags2 |= SMBFLG2_UNICODE;
  2363. capabilities |= CAP_UNICODE;
  2364. }
  2365. if (ses->capabilities & CAP_STATUS32) {
  2366. smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
  2367. capabilities |= CAP_STATUS32;
  2368. }
  2369. if (ses->capabilities & CAP_DFS) {
  2370. smb_buffer->Flags2 |= SMBFLG2_DFS;
  2371. capabilities |= CAP_DFS;
  2372. }
  2373. pSMB->req.Capabilities = cpu_to_le32(capabilities);
  2374. bcc_ptr = (char *) &pSMB->req.SecurityBlob;
  2375. SecurityBlob = (PAUTHENTICATE_MESSAGE) bcc_ptr;
  2376. strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8);
  2377. SecurityBlob->MessageType = NtLmAuthenticate;
  2378. bcc_ptr += SecurityBlobLength;
  2379. negotiate_flags =
  2380. NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET |
  2381. NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO |
  2382. 0x80000000 | NTLMSSP_NEGOTIATE_128;
  2383. if(sign_CIFS_PDUs)
  2384. negotiate_flags |= /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN |*/ NTLMSSP_NEGOTIATE_SIGN;
  2385. if(ntlmv2_flag)
  2386. negotiate_flags |= NTLMSSP_NEGOTIATE_NTLMV2;
  2387. /* setup pointers to domain name and workstation name */
  2388. SecurityBlob->WorkstationName.Buffer = 0;
  2389. SecurityBlob->WorkstationName.Length = 0;
  2390. SecurityBlob->WorkstationName.MaximumLength = 0;
  2391. SecurityBlob->SessionKey.Length = 0;
  2392. SecurityBlob->SessionKey.MaximumLength = 0;
  2393. SecurityBlob->SessionKey.Buffer = 0;
  2394. SecurityBlob->LmChallengeResponse.Length = 0;
  2395. SecurityBlob->LmChallengeResponse.MaximumLength = 0;
  2396. SecurityBlob->LmChallengeResponse.Buffer = 0;
  2397. SecurityBlob->NtChallengeResponse.Length =
  2398. cpu_to_le16(CIFS_SESSION_KEY_SIZE);
  2399. SecurityBlob->NtChallengeResponse.MaximumLength =
  2400. cpu_to_le16(CIFS_SESSION_KEY_SIZE);
  2401. memcpy(bcc_ptr, ntlm_session_key, CIFS_SESSION_KEY_SIZE);
  2402. SecurityBlob->NtChallengeResponse.Buffer =
  2403. cpu_to_le32(SecurityBlobLength);
  2404. SecurityBlobLength += CIFS_SESSION_KEY_SIZE;
  2405. bcc_ptr += CIFS_SESSION_KEY_SIZE;
  2406. if (ses->capabilities & CAP_UNICODE) {
  2407. if (domain == NULL) {
  2408. SecurityBlob->DomainName.Buffer = 0;
  2409. SecurityBlob->DomainName.Length = 0;
  2410. SecurityBlob->DomainName.MaximumLength = 0;
  2411. } else {
  2412. __u16 len =
  2413. cifs_strtoUCS((wchar_t *) bcc_ptr, domain, 64,
  2414. nls_codepage);
  2415. len *= 2;
  2416. SecurityBlob->DomainName.MaximumLength =
  2417. cpu_to_le16(len);
  2418. SecurityBlob->DomainName.Buffer =
  2419. cpu_to_le32(SecurityBlobLength);
  2420. bcc_ptr += len;
  2421. SecurityBlobLength += len;
  2422. SecurityBlob->DomainName.Length =
  2423. cpu_to_le16(len);
  2424. }
  2425. if (user == NULL) {
  2426. SecurityBlob->UserName.Buffer = 0;
  2427. SecurityBlob->UserName.Length = 0;
  2428. SecurityBlob->UserName.MaximumLength = 0;
  2429. } else {
  2430. __u16 len =
  2431. cifs_strtoUCS((wchar_t *) bcc_ptr, user, 64,
  2432. nls_codepage);
  2433. len *= 2;
  2434. SecurityBlob->UserName.MaximumLength =
  2435. cpu_to_le16(len);
  2436. SecurityBlob->UserName.Buffer =
  2437. cpu_to_le32(SecurityBlobLength);
  2438. bcc_ptr += len;
  2439. SecurityBlobLength += len;
  2440. SecurityBlob->UserName.Length =
  2441. cpu_to_le16(len);
  2442. }
  2443. /* SecurityBlob->WorkstationName.Length = cifs_strtoUCS((wchar_t *) bcc_ptr, "AMACHINE",64, nls_codepage);
  2444. SecurityBlob->WorkstationName.Length *= 2;
  2445. SecurityBlob->WorkstationName.MaximumLength = cpu_to_le16(SecurityBlob->WorkstationName.Length);
  2446. SecurityBlob->WorkstationName.Buffer = cpu_to_le32(SecurityBlobLength);
  2447. bcc_ptr += SecurityBlob->WorkstationName.Length;
  2448. SecurityBlobLength += SecurityBlob->WorkstationName.Length;
  2449. SecurityBlob->WorkstationName.Length = cpu_to_le16(SecurityBlob->WorkstationName.Length); */
  2450. if ((long) bcc_ptr % 2) {
  2451. *bcc_ptr = 0;
  2452. bcc_ptr++;
  2453. }
  2454. bytes_returned =
  2455. cifs_strtoUCS((wchar_t *) bcc_ptr, "Linux version ",
  2456. 32, nls_codepage);
  2457. bcc_ptr += 2 * bytes_returned;
  2458. bytes_returned =
  2459. cifs_strtoUCS((wchar_t *) bcc_ptr, system_utsname.release, 32,
  2460. nls_codepage);
  2461. bcc_ptr += 2 * bytes_returned;
  2462. bcc_ptr += 2; /* null term version string */
  2463. bytes_returned =
  2464. cifs_strtoUCS((wchar_t *) bcc_ptr, CIFS_NETWORK_OPSYS,
  2465. 64, nls_codepage);
  2466. bcc_ptr += 2 * bytes_returned;
  2467. *(bcc_ptr + 1) = 0;
  2468. *(bcc_ptr + 2) = 0;
  2469. bcc_ptr += 2; /* null terminate network opsys string */
  2470. *(bcc_ptr + 1) = 0;
  2471. *(bcc_ptr + 2) = 0;
  2472. bcc_ptr += 2; /* null domain */
  2473. } else { /* ASCII */
  2474. if (domain == NULL) {
  2475. SecurityBlob->DomainName.Buffer = 0;
  2476. SecurityBlob->DomainName.Length = 0;
  2477. SecurityBlob->DomainName.MaximumLength = 0;
  2478. } else {
  2479. __u16 len;
  2480. negotiate_flags |= NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED;
  2481. strncpy(bcc_ptr, domain, 63);
  2482. len = strnlen(domain, 64);
  2483. SecurityBlob->DomainName.MaximumLength =
  2484. cpu_to_le16(len);
  2485. SecurityBlob->DomainName.Buffer =
  2486. cpu_to_le32(SecurityBlobLength);
  2487. bcc_ptr += len;
  2488. SecurityBlobLength += len;
  2489. SecurityBlob->DomainName.Length = cpu_to_le16(len);
  2490. }
  2491. if (user == NULL) {
  2492. SecurityBlob->UserName.Buffer = 0;
  2493. SecurityBlob->UserName.Length = 0;
  2494. SecurityBlob->UserName.MaximumLength = 0;
  2495. } else {
  2496. __u16 len;
  2497. strncpy(bcc_ptr, user, 63);
  2498. len = strnlen(user, 64);
  2499. SecurityBlob->UserName.MaximumLength =
  2500. cpu_to_le16(len);
  2501. SecurityBlob->UserName.Buffer =
  2502. cpu_to_le32(SecurityBlobLength);
  2503. bcc_ptr += len;
  2504. SecurityBlobLength += len;
  2505. SecurityBlob->UserName.Length = cpu_to_le16(len);
  2506. }
  2507. /* BB fill in our workstation name if known BB */
  2508. strcpy(bcc_ptr, "Linux version ");
  2509. bcc_ptr += strlen("Linux version ");
  2510. strcpy(bcc_ptr, system_utsname.release);
  2511. bcc_ptr += strlen(system_utsname.release) + 1;
  2512. strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
  2513. bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
  2514. bcc_ptr++; /* null domain */
  2515. *bcc_ptr = 0;
  2516. }
  2517. SecurityBlob->NegotiateFlags = cpu_to_le32(negotiate_flags);
  2518. pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength);
  2519. count = (long) bcc_ptr - (long) pByteArea(smb_buffer);
  2520. smb_buffer->smb_buf_length += count;
  2521. pSMB->req.ByteCount = cpu_to_le16(count);
  2522. rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
  2523. &bytes_returned, 1);
  2524. if (rc) {
  2525. /* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */
  2526. } else if ((smb_buffer_response->WordCount == 3)
  2527. || (smb_buffer_response->WordCount == 4)) {
  2528. __u16 action = le16_to_cpu(pSMBr->resp.Action);
  2529. __u16 blob_len =
  2530. le16_to_cpu(pSMBr->resp.SecurityBlobLength);
  2531. if (action & GUEST_LOGIN)
  2532. cFYI(1, (" Guest login")); /* BB do we want to set anything in SesInfo struct ? */
  2533. /* if(SecurityBlob2->MessageType != NtLm??){
  2534. cFYI("Unexpected message type on auth response is %d "));
  2535. } */
  2536. if (ses) {
  2537. cFYI(1,
  2538. ("Does UID on challenge %d match auth response UID %d ",
  2539. ses->Suid, smb_buffer_response->Uid));
  2540. ses->Suid = smb_buffer_response->Uid; /* UID left in wire format */
  2541. bcc_ptr = pByteArea(smb_buffer_response);
  2542. /* response can have either 3 or 4 word count - Samba sends 3 */
  2543. if ((pSMBr->resp.hdr.WordCount == 3)
  2544. || ((pSMBr->resp.hdr.WordCount == 4)
  2545. && (blob_len <
  2546. pSMBr->resp.ByteCount))) {
  2547. if (pSMBr->resp.hdr.WordCount == 4) {
  2548. bcc_ptr +=
  2549. blob_len;
  2550. cFYI(1,
  2551. ("Security Blob Length %d ",
  2552. blob_len));
  2553. }
  2554. cFYI(1,
  2555. ("NTLMSSP response to Authenticate "));
  2556. if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
  2557. if ((long) (bcc_ptr) % 2) {
  2558. remaining_words =
  2559. (BCC(smb_buffer_response)
  2560. - 1) / 2;
  2561. bcc_ptr++; /* Unicode strings must be word aligned */
  2562. } else {
  2563. remaining_words = BCC(smb_buffer_response) / 2;
  2564. }
  2565. len =
  2566. UniStrnlen((wchar_t *) bcc_ptr,remaining_words - 1);
  2567. /* We look for obvious messed up bcc or strings in response so we do not go off
  2568. the end since (at least) WIN2K and Windows XP have a major bug in not null
  2569. terminating last Unicode string in response */
  2570. ses->serverOS =
  2571. kcalloc(1, 2 * (len + 1), GFP_KERNEL);
  2572. cifs_strfromUCS_le(ses->serverOS,
  2573. (wchar_t *)
  2574. bcc_ptr, len,
  2575. nls_codepage);
  2576. bcc_ptr += 2 * (len + 1);
  2577. remaining_words -= len + 1;
  2578. ses->serverOS[2 * len] = 0;
  2579. ses->serverOS[1 + (2 * len)] = 0;
  2580. if (remaining_words > 0) {
  2581. len = UniStrnlen((wchar_t *)
  2582. bcc_ptr,
  2583. remaining_words
  2584. - 1);
  2585. ses->serverNOS =
  2586. kcalloc(1, 2 * (len + 1),
  2587. GFP_KERNEL);
  2588. cifs_strfromUCS_le(ses->
  2589. serverNOS,
  2590. (wchar_t *)
  2591. bcc_ptr,
  2592. len,
  2593. nls_codepage);
  2594. bcc_ptr += 2 * (len + 1);
  2595. ses->serverNOS[2 * len] = 0;
  2596. ses->serverNOS[1+(2*len)] = 0;
  2597. remaining_words -= len + 1;
  2598. if (remaining_words > 0) {
  2599. len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
  2600. /* last string not always null terminated (e.g. for Windows XP & 2000) */
  2601. ses->serverDomain =
  2602. kcalloc(1, 2 *
  2603. (len +
  2604. 1),
  2605. GFP_KERNEL);
  2606. cifs_strfromUCS_le
  2607. (ses->
  2608. serverDomain,
  2609. (wchar_t *)
  2610. bcc_ptr, len,
  2611. nls_codepage);
  2612. bcc_ptr +=
  2613. 2 * (len + 1);
  2614. ses->
  2615. serverDomain[2
  2616. * len]
  2617. = 0;
  2618. ses->
  2619. serverDomain[1
  2620. +
  2621. (2
  2622. *
  2623. len)]
  2624. = 0;
  2625. } /* else no more room so create dummy domain string */
  2626. else
  2627. ses->serverDomain = kcalloc(1, 2,GFP_KERNEL);
  2628. } else { /* no room so create dummy domain and NOS string */
  2629. ses->serverDomain = kcalloc(1, 2, GFP_KERNEL);
  2630. ses->serverNOS = kcalloc(1, 2, GFP_KERNEL);
  2631. }
  2632. } else { /* ASCII */
  2633. len = strnlen(bcc_ptr, 1024);
  2634. if (((long) bcc_ptr + len) -
  2635. (long) pByteArea(smb_buffer_response)
  2636. <= BCC(smb_buffer_response)) {
  2637. ses->serverOS = kcalloc(1, len + 1,GFP_KERNEL);
  2638. strncpy(ses->serverOS,bcc_ptr, len);
  2639. bcc_ptr += len;
  2640. bcc_ptr[0] = 0; /* null terminate the string */
  2641. bcc_ptr++;
  2642. len = strnlen(bcc_ptr, 1024);
  2643. ses->serverNOS = kcalloc(1, len+1,GFP_KERNEL);
  2644. strncpy(ses->serverNOS, bcc_ptr, len);
  2645. bcc_ptr += len;
  2646. bcc_ptr[0] = 0;
  2647. bcc_ptr++;
  2648. len = strnlen(bcc_ptr, 1024);
  2649. ses->serverDomain = kcalloc(1, len+1,GFP_KERNEL);
  2650. strncpy(ses->serverDomain, bcc_ptr, len);
  2651. bcc_ptr += len;
  2652. bcc_ptr[0] = 0;
  2653. bcc_ptr++;
  2654. } else
  2655. cFYI(1,
  2656. ("Variable field of length %d extends beyond end of smb ",
  2657. len));
  2658. }
  2659. } else {
  2660. cERROR(1,
  2661. (" Security Blob Length extends beyond end of SMB"));
  2662. }
  2663. } else {
  2664. cERROR(1, ("No session structure passed in."));
  2665. }
  2666. } else {
  2667. cERROR(1,
  2668. (" Invalid Word count %d: ",
  2669. smb_buffer_response->WordCount));
  2670. rc = -EIO;
  2671. }
  2672. if (smb_buffer)
  2673. cifs_buf_release(smb_buffer);
  2674. return rc;
  2675. }
  2676. int
  2677. CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
  2678. const char *tree, struct cifsTconInfo *tcon,
  2679. const struct nls_table *nls_codepage)
  2680. {
  2681. struct smb_hdr *smb_buffer;
  2682. struct smb_hdr *smb_buffer_response;
  2683. TCONX_REQ *pSMB;
  2684. TCONX_RSP *pSMBr;
  2685. unsigned char *bcc_ptr;
  2686. int rc = 0;
  2687. int length;
  2688. __u16 count;
  2689. if (ses == NULL)
  2690. return -EIO;
  2691. smb_buffer = cifs_buf_get();
  2692. if (smb_buffer == NULL) {
  2693. return -ENOMEM;
  2694. }
  2695. smb_buffer_response = smb_buffer;
  2696. header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX,
  2697. NULL /*no tid */ , 4 /*wct */ );
  2698. smb_buffer->Uid = ses->Suid;
  2699. pSMB = (TCONX_REQ *) smb_buffer;
  2700. pSMBr = (TCONX_RSP *) smb_buffer_response;
  2701. pSMB->AndXCommand = 0xFF;
  2702. pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO);
  2703. pSMB->PasswordLength = cpu_to_le16(1); /* minimum */
  2704. bcc_ptr = &pSMB->Password[0];
  2705. bcc_ptr++; /* skip password */
  2706. if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  2707. smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  2708. if (ses->capabilities & CAP_STATUS32) {
  2709. smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS;
  2710. }
  2711. if (ses->capabilities & CAP_DFS) {
  2712. smb_buffer->Flags2 |= SMBFLG2_DFS;
  2713. }
  2714. if (ses->capabilities & CAP_UNICODE) {
  2715. smb_buffer->Flags2 |= SMBFLG2_UNICODE;
  2716. length =
  2717. cifs_strtoUCS((wchar_t *) bcc_ptr, tree, 100, nls_codepage);
  2718. bcc_ptr += 2 * length; /* convert num of 16 bit words to bytes */
  2719. bcc_ptr += 2; /* skip trailing null */
  2720. } else { /* ASCII */
  2721. strcpy(bcc_ptr, tree);
  2722. bcc_ptr += strlen(tree) + 1;
  2723. }
  2724. strcpy(bcc_ptr, "?????");
  2725. bcc_ptr += strlen("?????");
  2726. bcc_ptr += 1;
  2727. count = bcc_ptr - &pSMB->Password[0];
  2728. pSMB->hdr.smb_buf_length += count;
  2729. pSMB->ByteCount = cpu_to_le16(count);
  2730. rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length, 0);
  2731. /* if (rc) rc = map_smb_to_linux_error(smb_buffer_response); */
  2732. /* above now done in SendReceive */
  2733. if ((rc == 0) && (tcon != NULL)) {
  2734. tcon->tidStatus = CifsGood;
  2735. tcon->tid = smb_buffer_response->Tid;
  2736. bcc_ptr = pByteArea(smb_buffer_response);
  2737. length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2);
  2738. /* skip service field (NB: this field is always ASCII) */
  2739. bcc_ptr += length + 1;
  2740. strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
  2741. if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
  2742. length = UniStrnlen((wchar_t *) bcc_ptr, 512);
  2743. if ((bcc_ptr + (2 * length)) -
  2744. pByteArea(smb_buffer_response) <=
  2745. BCC(smb_buffer_response)) {
  2746. if(tcon->nativeFileSystem)
  2747. kfree(tcon->nativeFileSystem);
  2748. tcon->nativeFileSystem =
  2749. kcalloc(1, length + 2, GFP_KERNEL);
  2750. cifs_strfromUCS_le(tcon->nativeFileSystem,
  2751. (wchar_t *) bcc_ptr,
  2752. length, nls_codepage);
  2753. bcc_ptr += 2 * length;
  2754. bcc_ptr[0] = 0; /* null terminate the string */
  2755. bcc_ptr[1] = 0;
  2756. bcc_ptr += 2;
  2757. }
  2758. /* else do not bother copying these informational fields */
  2759. } else {
  2760. length = strnlen(bcc_ptr, 1024);
  2761. if ((bcc_ptr + length) -
  2762. pByteArea(smb_buffer_response) <=
  2763. BCC(smb_buffer_response)) {
  2764. if(tcon->nativeFileSystem)
  2765. kfree(tcon->nativeFileSystem);
  2766. tcon->nativeFileSystem =
  2767. kcalloc(1, length + 1, GFP_KERNEL);
  2768. strncpy(tcon->nativeFileSystem, bcc_ptr,
  2769. length);
  2770. }
  2771. /* else do not bother copying these informational fields */
  2772. }
  2773. tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport);
  2774. cFYI(1, ("Tcon flags: 0x%x ", tcon->Flags));
  2775. } else if ((rc == 0) && tcon == NULL) {
  2776. /* all we need to save for IPC$ connection */
  2777. ses->ipc_tid = smb_buffer_response->Tid;
  2778. }
  2779. if (smb_buffer)
  2780. cifs_buf_release(smb_buffer);
  2781. return rc;
  2782. }
  2783. int
  2784. cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
  2785. {
  2786. int rc = 0;
  2787. int xid;
  2788. struct cifsSesInfo *ses = NULL;
  2789. struct task_struct *cifsd_task;
  2790. xid = GetXid();
  2791. if (cifs_sb->tcon) {
  2792. ses = cifs_sb->tcon->ses; /* save ptr to ses before delete tcon!*/
  2793. rc = CIFSSMBTDis(xid, cifs_sb->tcon);
  2794. if (rc == -EBUSY) {
  2795. FreeXid(xid);
  2796. return 0;
  2797. }
  2798. tconInfoFree(cifs_sb->tcon);
  2799. if ((ses) && (ses->server)) {
  2800. /* save off task so we do not refer to ses later */
  2801. cifsd_task = ses->server->tsk;
  2802. cFYI(1, ("About to do SMBLogoff "));
  2803. rc = CIFSSMBLogoff(xid, ses);
  2804. if (rc == -EBUSY) {
  2805. FreeXid(xid);
  2806. return 0;
  2807. } else if (rc == -ESHUTDOWN) {
  2808. cFYI(1,("Waking up socket by sending it signal"));
  2809. if(cifsd_task)
  2810. send_sig(SIGKILL,cifsd_task,1);
  2811. rc = 0;
  2812. } /* else - we have an smb session
  2813. left on this socket do not kill cifsd */
  2814. } else
  2815. cFYI(1, ("No session or bad tcon"));
  2816. }
  2817. cifs_sb->tcon = NULL;
  2818. if (ses) {
  2819. set_current_state(TASK_INTERRUPTIBLE);
  2820. schedule_timeout(HZ / 2);
  2821. }
  2822. if (ses)
  2823. sesInfoFree(ses);
  2824. FreeXid(xid);
  2825. return rc; /* BB check if we should always return zero here */
  2826. }
  2827. int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
  2828. struct nls_table * nls_info)
  2829. {
  2830. int rc = 0;
  2831. char ntlm_session_key[CIFS_SESSION_KEY_SIZE];
  2832. int ntlmv2_flag = FALSE;
  2833. int first_time = 0;
  2834. /* what if server changes its buffer size after dropping the session? */
  2835. if(pSesInfo->server->maxBuf == 0) /* no need to send on reconnect */ {
  2836. rc = CIFSSMBNegotiate(xid, pSesInfo);
  2837. if(rc == -EAGAIN) /* retry only once on 1st time connection */ {
  2838. rc = CIFSSMBNegotiate(xid, pSesInfo);
  2839. if(rc == -EAGAIN)
  2840. rc = -EHOSTDOWN;
  2841. }
  2842. if(rc == 0) {
  2843. spin_lock(&GlobalMid_Lock);
  2844. if(pSesInfo->server->tcpStatus != CifsExiting)
  2845. pSesInfo->server->tcpStatus = CifsGood;
  2846. else
  2847. rc = -EHOSTDOWN;
  2848. spin_unlock(&GlobalMid_Lock);
  2849. }
  2850. first_time = 1;
  2851. }
  2852. if (!rc) {
  2853. pSesInfo->capabilities = pSesInfo->server->capabilities;
  2854. if(linuxExtEnabled == 0)
  2855. pSesInfo->capabilities &= (~CAP_UNIX);
  2856. /* pSesInfo->sequence_number = 0;*/
  2857. cFYI(1,("Security Mode: 0x%x Capabilities: 0x%x Time Zone: %d",
  2858. pSesInfo->server->secMode,
  2859. pSesInfo->server->capabilities,
  2860. pSesInfo->server->timeZone));
  2861. if (extended_security
  2862. && (pSesInfo->capabilities & CAP_EXTENDED_SECURITY)
  2863. && (pSesInfo->server->secType == NTLMSSP)) {
  2864. cFYI(1, ("New style sesssetup "));
  2865. rc = CIFSSpnegoSessSetup(xid, pSesInfo,
  2866. NULL /* security blob */,
  2867. 0 /* blob length */,
  2868. nls_info);
  2869. } else if (extended_security
  2870. && (pSesInfo->capabilities & CAP_EXTENDED_SECURITY)
  2871. && (pSesInfo->server->secType == RawNTLMSSP)) {
  2872. cFYI(1, ("NTLMSSP sesssetup "));
  2873. rc = CIFSNTLMSSPNegotiateSessSetup(xid,
  2874. pSesInfo,
  2875. &ntlmv2_flag,
  2876. nls_info);
  2877. if (!rc) {
  2878. if(ntlmv2_flag) {
  2879. char * v2_response;
  2880. cFYI(1,("Can use more secure NTLM version 2 password hash"));
  2881. if(CalcNTLMv2_partial_mac_key(pSesInfo,
  2882. nls_info)) {
  2883. rc = -ENOMEM;
  2884. goto ss_err_exit;
  2885. } else
  2886. v2_response = kmalloc(16 + 64 /* blob */, GFP_KERNEL);
  2887. if(v2_response) {
  2888. CalcNTLMv2_response(pSesInfo,v2_response);
  2889. /* if(first_time)
  2890. cifs_calculate_ntlmv2_mac_key(
  2891. pSesInfo->server->mac_signing_key,
  2892. response, ntlm_session_key, */
  2893. kfree(v2_response);
  2894. /* BB Put dummy sig in SessSetup PDU? */
  2895. } else {
  2896. rc = -ENOMEM;
  2897. goto ss_err_exit;
  2898. }
  2899. } else {
  2900. SMBNTencrypt(pSesInfo->password,
  2901. pSesInfo->server->cryptKey,
  2902. ntlm_session_key);
  2903. if(first_time)
  2904. cifs_calculate_mac_key(
  2905. pSesInfo->server->mac_signing_key,
  2906. ntlm_session_key,
  2907. pSesInfo->password);
  2908. }
  2909. /* for better security the weaker lanman hash not sent
  2910. in AuthSessSetup so we no longer calculate it */
  2911. rc = CIFSNTLMSSPAuthSessSetup(xid,
  2912. pSesInfo,
  2913. ntlm_session_key,
  2914. ntlmv2_flag,
  2915. nls_info);
  2916. }
  2917. } else { /* old style NTLM 0.12 session setup */
  2918. SMBNTencrypt(pSesInfo->password,
  2919. pSesInfo->server->cryptKey,
  2920. ntlm_session_key);
  2921. if(first_time)
  2922. cifs_calculate_mac_key(
  2923. pSesInfo->server->mac_signing_key,
  2924. ntlm_session_key, pSesInfo->password);
  2925. rc = CIFSSessSetup(xid, pSesInfo,
  2926. ntlm_session_key, nls_info);
  2927. }
  2928. if (rc) {
  2929. cERROR(1,("Send error in SessSetup = %d",rc));
  2930. } else {
  2931. cFYI(1,("CIFS Session Established successfully"));
  2932. pSesInfo->status = CifsGood;
  2933. }
  2934. }
  2935. ss_err_exit:
  2936. return rc;
  2937. }