samba-4.13-redhat.patch 438 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525
  1. From 4e5d178f9367f4e51b387b7d4df1e8407b15fafc Mon Sep 17 00:00:00 2001
  2. From: Andreas Schneider <asn@samba.org>
  3. Date: Mon, 13 Jul 2020 16:15:03 +0200
  4. Subject: [PATCH 001/104] libcli:smb2: Do not leak ptext on error
  5. Signed-off-by: Andreas Schneider <asn@samba.org>
  6. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  7. ---
  8. libcli/smb/smb2_signing.c | 1 +
  9. 1 file changed, 1 insertion(+)
  10. diff --git a/libcli/smb/smb2_signing.c b/libcli/smb/smb2_signing.c
  11. index cc03607d789..4d430f56df5 100644
  12. --- a/libcli/smb/smb2_signing.c
  13. +++ b/libcli/smb/smb2_signing.c
  14. @@ -520,6 +520,7 @@ NTSTATUS smb2_signing_encrypt_pdu(struct smb2_signing_key *encryption_key,
  15. ctext = talloc_size(talloc_tos(), ctext_size);
  16. if (ctext == NULL) {
  17. + TALLOC_FREE(ptext);
  18. status = NT_STATUS_NO_MEMORY;
  19. goto out;
  20. }
  21. --
  22. 2.29.2
  23. From 1310c58c3b8b9c7fcb0c811a9ef24b3bbe8c16f1 Mon Sep 17 00:00:00 2001
  24. From: Andreas Schneider <asn@samba.org>
  25. Date: Mon, 13 Jul 2020 17:23:37 +0200
  26. Subject: [PATCH 002/104] libcli:smb2: Use talloc NULL context if we don't have
  27. a stackframe
  28. If we execute this code from python we don't have a talloc stackframe
  29. around and segfault with talloc_tos().
  30. To fix the crash we use the NULL context as we take care for freeing the
  31. memory as soon as possible.
  32. Signed-off-by: Andreas Schneider <asn@samba.org>
  33. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  34. ---
  35. libcli/smb/smb2_signing.c | 30 ++++++++++++++++++++++++++----
  36. 1 file changed, 26 insertions(+), 4 deletions(-)
  37. diff --git a/libcli/smb/smb2_signing.c b/libcli/smb/smb2_signing.c
  38. index 4d430f56df5..6ece5f2e4d3 100644
  39. --- a/libcli/smb/smb2_signing.c
  40. +++ b/libcli/smb/smb2_signing.c
  41. @@ -511,14 +511,25 @@ NTSTATUS smb2_signing_encrypt_pdu(struct smb2_signing_key *encryption_key,
  42. uint8_t *ctext = NULL;
  43. size_t len = 0;
  44. int i;
  45. + TALLOC_CTX *tmp_ctx = NULL;
  46. - ptext = talloc_size(talloc_tos(), ptext_size);
  47. + /*
  48. + * If we come from python bindings, we don't have a stackframe
  49. + * around, so use the NULL context.
  50. + *
  51. + * This is fine as we make sure we free the memory.
  52. + */
  53. + if (talloc_stackframe_exists()) {
  54. + tmp_ctx = talloc_tos();
  55. + }
  56. +
  57. + ptext = talloc_size(tmp_ctx, ptext_size);
  58. if (ptext == NULL) {
  59. status = NT_STATUS_NO_MEMORY;
  60. goto out;
  61. }
  62. - ctext = talloc_size(talloc_tos(), ctext_size);
  63. + ctext = talloc_size(tmp_ctx, ctext_size);
  64. if (ctext == NULL) {
  65. TALLOC_FREE(ptext);
  66. status = NT_STATUS_NO_MEMORY;
  67. @@ -710,16 +721,27 @@ NTSTATUS smb2_signing_decrypt_pdu(struct smb2_signing_key *decryption_key,
  68. uint8_t *ptext = NULL;
  69. size_t len = 0;
  70. int i;
  71. + TALLOC_CTX *tmp_ctx = NULL;
  72. +
  73. + /*
  74. + * If we come from python bindings, we don't have a stackframe
  75. + * around, so use the NULL context.
  76. + *
  77. + * This is fine as we make sure we free the memory.
  78. + */
  79. + if (talloc_stackframe_exists()) {
  80. + tmp_ctx = talloc_tos();
  81. + }
  82. /* GnuTLS doesn't have a iovec API for decryption yet */
  83. - ptext = talloc_size(talloc_tos(), ptext_size);
  84. + ptext = talloc_size(tmp_ctx, ptext_size);
  85. if (ptext == NULL) {
  86. status = NT_STATUS_NO_MEMORY;
  87. goto out;
  88. }
  89. - ctext = talloc_size(talloc_tos(), ctext_size);
  90. + ctext = talloc_size(tmp_ctx, ctext_size);
  91. if (ctext == NULL) {
  92. TALLOC_FREE(ptext);
  93. status = NT_STATUS_NO_MEMORY;
  94. --
  95. 2.29.2
  96. From ff15d93d1009a23428b9c11090836624255924cd Mon Sep 17 00:00:00 2001
  97. From: Stefan Metzmacher <metze@samba.org>
  98. Date: Wed, 6 Nov 2019 17:37:45 +0100
  99. Subject: [PATCH 003/104] auth:creds: Introduce CRED_SMB_CONF
  100. We have several places where we check '> CRED_UNINITIALISED',
  101. so we better don't use CRED_UNINITIALISED for values from
  102. our smb.conf.
  103. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  104. Reviewed-by: Andreas Schneider <asn@samba.org>
  105. ---
  106. auth/credentials/credentials.c | 6 +++---
  107. auth/credentials/credentials.h | 1 +
  108. auth/credentials/pycredentials.c | 1 +
  109. python/samba/tests/credentials.py | 4 ++--
  110. 4 files changed, 7 insertions(+), 5 deletions(-)
  111. diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
  112. index 81f9dbb9eb3..80a31b248ae 100644
  113. --- a/auth/credentials/credentials.c
  114. +++ b/auth/credentials/credentials.c
  115. @@ -902,12 +902,12 @@ _PUBLIC_ void cli_credentials_set_conf(struct cli_credentials *cred,
  116. if (lpcfg_parm_is_cmdline(lp_ctx, "workgroup")) {
  117. cli_credentials_set_domain(cred, lpcfg_workgroup(lp_ctx), CRED_SPECIFIED);
  118. } else {
  119. - cli_credentials_set_domain(cred, lpcfg_workgroup(lp_ctx), CRED_UNINITIALISED);
  120. + cli_credentials_set_domain(cred, lpcfg_workgroup(lp_ctx), CRED_SMB_CONF);
  121. }
  122. if (lpcfg_parm_is_cmdline(lp_ctx, "netbios name")) {
  123. cli_credentials_set_workstation(cred, lpcfg_netbios_name(lp_ctx), CRED_SPECIFIED);
  124. } else {
  125. - cli_credentials_set_workstation(cred, lpcfg_netbios_name(lp_ctx), CRED_UNINITIALISED);
  126. + cli_credentials_set_workstation(cred, lpcfg_netbios_name(lp_ctx), CRED_SMB_CONF);
  127. }
  128. if (realm != NULL && strlen(realm) == 0) {
  129. realm = NULL;
  130. @@ -915,7 +915,7 @@ _PUBLIC_ void cli_credentials_set_conf(struct cli_credentials *cred,
  131. if (lpcfg_parm_is_cmdline(lp_ctx, "realm")) {
  132. cli_credentials_set_realm(cred, realm, CRED_SPECIFIED);
  133. } else {
  134. - cli_credentials_set_realm(cred, realm, CRED_UNINITIALISED);
  135. + cli_credentials_set_realm(cred, realm, CRED_SMB_CONF);
  136. }
  137. sep = lpcfg_winbind_separator(lp_ctx);
  138. diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
  139. index 9fe6a82b1ea..7154c2a008c 100644
  140. --- a/auth/credentials/credentials.h
  141. +++ b/auth/credentials/credentials.h
  142. @@ -42,6 +42,7 @@ struct db_context;
  143. /* In order of priority */
  144. enum credentials_obtained {
  145. CRED_UNINITIALISED = 0, /* We don't even have a guess yet */
  146. + CRED_SMB_CONF, /* Current value should be used, which comes from smb.conf */
  147. CRED_CALLBACK, /* Callback should be used to obtain value */
  148. CRED_GUESS_ENV, /* Current value should be used, which was guessed */
  149. CRED_GUESS_FILE, /* A guess from a file (or file pointed at in env variable) */
  150. diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
  151. index a5d0f9e051c..68edc282741 100644
  152. --- a/auth/credentials/pycredentials.c
  153. +++ b/auth/credentials/pycredentials.c
  154. @@ -1275,6 +1275,7 @@ MODULE_INIT_FUNC(credentials)
  155. return NULL;
  156. PyModule_AddObject(m, "UNINITIALISED", PyLong_FromLong(CRED_UNINITIALISED));
  157. + PyModule_AddObject(m, "SMB_CONF", PyLong_FromLong(CRED_SMB_CONF));
  158. PyModule_AddObject(m, "CALLBACK", PyLong_FromLong(CRED_CALLBACK));
  159. PyModule_AddObject(m, "GUESS_ENV", PyLong_FromLong(CRED_GUESS_ENV));
  160. PyModule_AddObject(m, "GUESS_FILE", PyLong_FromLong(CRED_GUESS_FILE));
  161. diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
  162. index d2a81506de3..6454ac9ff7c 100644
  163. --- a/python/samba/tests/credentials.py
  164. +++ b/python/samba/tests/credentials.py
  165. @@ -332,7 +332,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir):
  166. os.environ["USER"] = "env_user"
  167. creds.guess(lp)
  168. realm = "realm.example.com"
  169. - creds.set_realm(realm, credentials.UNINITIALISED)
  170. + creds.set_realm(realm, credentials.SMB_CONF)
  171. creds.parse_string("user")
  172. self.assertEqual(creds.get_username(), "user")
  173. self.assertEqual(creds.get_domain(), lp.get("workgroup").upper())
  174. @@ -360,7 +360,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir):
  175. os.environ["USER"] = "env_user"
  176. creds.guess(lp)
  177. realm = "realm.example.com"
  178. - creds.set_realm(realm, credentials.UNINITIALISED)
  179. + creds.set_realm(realm, credentials.SMB_CONF)
  180. self.assertEqual(creds.get_username(), "env_user")
  181. self.assertEqual(creds.get_domain(), lp.get("workgroup").upper())
  182. self.assertEqual(creds.get_realm(), realm.upper())
  183. --
  184. 2.29.2
  185. From cc5e70efc8b9f45054d7e57002f59ac38c4c687f Mon Sep 17 00:00:00 2001
  186. From: Andreas Schneider <asn@samba.org>
  187. Date: Thu, 10 Oct 2019 14:18:23 +0200
  188. Subject: [PATCH 004/104] param: Add 'server smb encrypt' parameter
  189. And this also makes 'smb encrypt' a synonym of that.
  190. Signed-off-by: Andreas Schneider <asn@samba.org>
  191. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  192. ---
  193. .../smbdotconf/security/serversmbencrypt.xml | 241 ++++++++++++++++++
  194. docs-xml/smbdotconf/security/smbencrypt.xml | 241 +-----------------
  195. source3/param/loadparm.c | 2 +-
  196. source3/smbd/service.c | 4 +-
  197. source3/smbd/smb2_negprot.c | 2 +-
  198. source3/smbd/smb2_sesssetup.c | 4 +-
  199. source3/smbd/smb2_tcon.c | 4 +-
  200. source3/smbd/trans2.c | 2 +-
  201. 8 files changed, 257 insertions(+), 243 deletions(-)
  202. create mode 100644 docs-xml/smbdotconf/security/serversmbencrypt.xml
  203. diff --git a/docs-xml/smbdotconf/security/serversmbencrypt.xml b/docs-xml/smbdotconf/security/serversmbencrypt.xml
  204. new file mode 100644
  205. index 00000000000..714aacbf1ca
  206. --- /dev/null
  207. +++ b/docs-xml/smbdotconf/security/serversmbencrypt.xml
  208. @@ -0,0 +1,241 @@
  209. +<samba:parameter name="server smb encrypt"
  210. + context="S"
  211. + type="enum"
  212. + enumlist="enum_smb_signing_vals"
  213. + xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
  214. +<description>
  215. + <para>
  216. + This parameter controls whether a remote client is allowed or required
  217. + to use SMB encryption. It has different effects depending on whether
  218. + the connection uses SMB1 or SMB2 and newer:
  219. + </para>
  220. +
  221. + <itemizedlist>
  222. + <listitem>
  223. + <para>
  224. + If the connection uses SMB1, then this option controls the use
  225. + of a Samba-specific extension to the SMB protocol introduced in
  226. + Samba 3.2 that makes use of the Unix extensions.
  227. + </para>
  228. + </listitem>
  229. +
  230. + <listitem>
  231. + <para>
  232. + If the connection uses SMB2 or newer, then this option controls
  233. + the use of the SMB-level encryption that is supported in SMB
  234. + version 3.0 and above and available in Windows 8 and newer.
  235. + </para>
  236. + </listitem>
  237. + </itemizedlist>
  238. +
  239. + <para>
  240. + This parameter can be set globally and on a per-share bases.
  241. + Possible values are
  242. +
  243. + <emphasis>off</emphasis>,
  244. + <emphasis>if_required</emphasis>,
  245. + <emphasis>desired</emphasis>,
  246. + and
  247. + <emphasis>required</emphasis>.
  248. + A special value is <emphasis>default</emphasis> which is
  249. + the implicit default setting of <emphasis>if_required</emphasis>.
  250. + </para>
  251. +
  252. + <variablelist>
  253. + <varlistentry>
  254. + <term><emphasis>Effects for SMB1</emphasis></term>
  255. + <listitem>
  256. + <para>
  257. + The Samba-specific encryption of SMB1 connections is an
  258. + extension to the SMB protocol negotiated as part of the UNIX
  259. + extensions. SMB encryption uses the GSSAPI (SSPI on Windows)
  260. + ability to encrypt and sign every request/response in a SMB
  261. + protocol stream. When enabled it provides a secure method of
  262. + SMB/CIFS communication, similar to an ssh protected session, but
  263. + using SMB/CIFS authentication to negotiate encryption and
  264. + signing keys. Currently this is only supported smbclient of by
  265. + Samba 3.2 and newer, and hopefully soon Linux CIFSFS and MacOS/X
  266. + clients. Windows clients do not support this feature.
  267. + </para>
  268. +
  269. + <para>This may be set on a per-share
  270. + basis, but clients may chose to encrypt the entire session, not
  271. + just traffic to a specific share. If this is set to mandatory
  272. + then all traffic to a share <emphasis>must</emphasis>
  273. + be encrypted once the connection has been made to the share.
  274. + The server would return "access denied" to all non-encrypted
  275. + requests on such a share. Selecting encrypted traffic reduces
  276. + throughput as smaller packet sizes must be used (no huge UNIX
  277. + style read/writes allowed) as well as the overhead of encrypting
  278. + and signing all the data.
  279. + </para>
  280. +
  281. + <para>
  282. + If SMB encryption is selected, Windows style SMB signing (see
  283. + the <smbconfoption name="server signing"/> option) is no longer
  284. + necessary, as the GSSAPI flags use select both signing and
  285. + sealing of the data.
  286. + </para>
  287. +
  288. + <para>
  289. + When set to auto or default, SMB encryption is offered, but not
  290. + enforced. When set to mandatory, SMB encryption is required and
  291. + if set to disabled, SMB encryption can not be negotiated.
  292. + </para>
  293. + </listitem>
  294. + </varlistentry>
  295. +
  296. + <varlistentry>
  297. + <term><emphasis>Effects for SMB2 and newer</emphasis></term>
  298. + <listitem>
  299. + <para>
  300. + Native SMB transport encryption is available in SMB version 3.0
  301. + or newer. It is only offered by Samba if
  302. + <emphasis>server max protocol</emphasis> is set to
  303. + <emphasis>SMB3</emphasis> or newer.
  304. + Clients supporting this type of encryption include
  305. + Windows 8 and newer,
  306. + Windows server 2012 and newer,
  307. + and smbclient of Samba 4.1 and newer.
  308. + </para>
  309. +
  310. + <para>
  311. + The protocol implementation offers various options:
  312. + </para>
  313. +
  314. + <itemizedlist>
  315. + <listitem>
  316. + <para>
  317. + The capability to perform SMB encryption can be
  318. + negotiated during protocol negotiation.
  319. + </para>
  320. + </listitem>
  321. +
  322. + <listitem>
  323. + <para>
  324. + Data encryption can be enabled globally. In that case,
  325. + an encryption-capable connection will have all traffic
  326. + in all its sessions encrypted. In particular all share
  327. + connections will be encrypted.
  328. + </para>
  329. + </listitem>
  330. +
  331. + <listitem>
  332. + <para>
  333. + Data encryption can also be enabled per share if not
  334. + enabled globally. For an encryption-capable connection,
  335. + all connections to an encryption-enabled share will be
  336. + encrypted.
  337. + </para>
  338. + </listitem>
  339. +
  340. + <listitem>
  341. + <para>
  342. + Encryption can be enforced. This means that session
  343. + setups will be denied on non-encryption-capable
  344. + connections if data encryption has been enabled
  345. + globally. And tree connections will be denied for
  346. + non-encryption capable connections to shares with data
  347. + encryption enabled.
  348. + </para>
  349. + </listitem>
  350. + </itemizedlist>
  351. +
  352. + <para>
  353. + These features can be controlled with settings of
  354. + <emphasis>server smb encrypt</emphasis> as follows:
  355. + </para>
  356. +
  357. + <itemizedlist>
  358. + <listitem>
  359. + <para>
  360. + Leaving it as default, explicitly setting
  361. + <emphasis>default</emphasis>, or setting it to
  362. + <emphasis>if_required</emphasis> globally will enable
  363. + negotiation of encryption but will not turn on
  364. + data encryption globally or per share.
  365. + </para>
  366. + </listitem>
  367. +
  368. + <listitem>
  369. + <para>
  370. + Setting it to <emphasis>desired</emphasis> globally
  371. + will enable negotiation and will turn on data encryption
  372. + on sessions and share connections for those clients
  373. + that support it.
  374. + </para>
  375. + </listitem>
  376. +
  377. + <listitem>
  378. + <para>
  379. + Setting it to <emphasis>required</emphasis> globally
  380. + will enable negotiation and turn on data encryption
  381. + on sessions and share connections. Clients that do
  382. + not support encryption will be denied access to the
  383. + server.
  384. + </para>
  385. + </listitem>
  386. +
  387. + <listitem>
  388. + <para>
  389. + Setting it to <emphasis>off</emphasis> globally will
  390. + completely disable the encryption feature for all
  391. + connections. Setting <parameter>server smb encrypt =
  392. + required</parameter> for individual shares (while it's
  393. + globally off) will deny access to this shares for all
  394. + clients.
  395. + </para>
  396. + </listitem>
  397. +
  398. + <listitem>
  399. + <para>
  400. + Setting it to <emphasis>desired</emphasis> on a share
  401. + will turn on data encryption for this share for clients
  402. + that support encryption if negotiation has been
  403. + enabled globally.
  404. + </para>
  405. + </listitem>
  406. +
  407. + <listitem>
  408. + <para>
  409. + Setting it to <emphasis>required</emphasis> on a share
  410. + will enforce data encryption for this share if
  411. + negotiation has been enabled globally. I.e. clients that
  412. + do not support encryption will be denied access to the
  413. + share.
  414. + </para>
  415. + <para>
  416. + Note that this allows per-share enforcing to be
  417. + controlled in Samba differently from Windows:
  418. + In Windows, <emphasis>RejectUnencryptedAccess</emphasis>
  419. + is a global setting, and if it is set, all shares with
  420. + data encryption turned on
  421. + are automatically enforcing encryption. In order to
  422. + achieve the same effect in Samba, one
  423. + has to globally set <emphasis>server smb encrypt</emphasis> to
  424. + <emphasis>if_required</emphasis>, and then set all shares
  425. + that should be encrypted to
  426. + <emphasis>required</emphasis>.
  427. + Additionally, it is possible in Samba to have some
  428. + shares with encryption <emphasis>required</emphasis>
  429. + and some other shares with encryption only
  430. + <emphasis>desired</emphasis>, which is not possible in
  431. + Windows.
  432. + </para>
  433. + </listitem>
  434. +
  435. + <listitem>
  436. + <para>
  437. + Setting it to <emphasis>off</emphasis> or
  438. + <emphasis>if_required</emphasis> for a share has
  439. + no effect.
  440. + </para>
  441. + </listitem>
  442. + </itemizedlist>
  443. + </listitem>
  444. + </varlistentry>
  445. + </variablelist>
  446. +</description>
  447. +
  448. +<value type="default">default</value>
  449. +</samba:parameter>
  450. diff --git a/docs-xml/smbdotconf/security/smbencrypt.xml b/docs-xml/smbdotconf/security/smbencrypt.xml
  451. index 32a22cb58f5..798e616b765 100644
  452. --- a/docs-xml/smbdotconf/security/smbencrypt.xml
  453. +++ b/docs-xml/smbdotconf/security/smbencrypt.xml
  454. @@ -1,241 +1,14 @@
  455. <samba:parameter name="smb encrypt"
  456. - context="S"
  457. - type="enum"
  458. - enumlist="enum_smb_signing_vals"
  459. - xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
  460. + context="S"
  461. + type="enum"
  462. + enumlist="enum_smb_signing_vals"
  463. + function="server_smb_encrypt"
  464. + synonym="1"
  465. + xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
  466. <description>
  467. <para>
  468. - This parameter controls whether a remote client is allowed or required
  469. - to use SMB encryption. It has different effects depending on whether
  470. - the connection uses SMB1 or SMB2 and newer:
  471. + This is a synonym for <smbconfoption name="server smb encrypt"/>.
  472. </para>
  473. -
  474. - <itemizedlist>
  475. - <listitem>
  476. - <para>
  477. - If the connection uses SMB1, then this option controls the use
  478. - of a Samba-specific extension to the SMB protocol introduced in
  479. - Samba 3.2 that makes use of the Unix extensions.
  480. - </para>
  481. - </listitem>
  482. -
  483. - <listitem>
  484. - <para>
  485. - If the connection uses SMB2 or newer, then this option controls
  486. - the use of the SMB-level encryption that is supported in SMB
  487. - version 3.0 and above and available in Windows 8 and newer.
  488. - </para>
  489. - </listitem>
  490. - </itemizedlist>
  491. -
  492. - <para>
  493. - This parameter can be set globally and on a per-share bases.
  494. - Possible values are
  495. - <emphasis>off</emphasis> (or <emphasis>disabled</emphasis>),
  496. - <emphasis>enabled</emphasis> (or <emphasis>auto</emphasis>, or
  497. - <emphasis>if_required</emphasis>),
  498. - <emphasis>desired</emphasis>,
  499. - and
  500. - <emphasis>required</emphasis>
  501. - (or <emphasis>mandatory</emphasis>).
  502. - A special value is <emphasis>default</emphasis> which is
  503. - the implicit default setting of <emphasis>enabled</emphasis>.
  504. - </para>
  505. -
  506. - <variablelist>
  507. - <varlistentry>
  508. - <term><emphasis>Effects for SMB1</emphasis></term>
  509. - <listitem>
  510. - <para>
  511. - The Samba-specific encryption of SMB1 connections is an
  512. - extension to the SMB protocol negotiated as part of the UNIX
  513. - extensions. SMB encryption uses the GSSAPI (SSPI on Windows)
  514. - ability to encrypt and sign every request/response in a SMB
  515. - protocol stream. When enabled it provides a secure method of
  516. - SMB/CIFS communication, similar to an ssh protected session, but
  517. - using SMB/CIFS authentication to negotiate encryption and
  518. - signing keys. Currently this is only supported smbclient of by
  519. - Samba 3.2 and newer, and hopefully soon Linux CIFSFS and MacOS/X
  520. - clients. Windows clients do not support this feature.
  521. - </para>
  522. -
  523. - <para>This may be set on a per-share
  524. - basis, but clients may chose to encrypt the entire session, not
  525. - just traffic to a specific share. If this is set to mandatory
  526. - then all traffic to a share <emphasis>must</emphasis>
  527. - be encrypted once the connection has been made to the share.
  528. - The server would return "access denied" to all non-encrypted
  529. - requests on such a share. Selecting encrypted traffic reduces
  530. - throughput as smaller packet sizes must be used (no huge UNIX
  531. - style read/writes allowed) as well as the overhead of encrypting
  532. - and signing all the data.
  533. - </para>
  534. -
  535. - <para>
  536. - If SMB encryption is selected, Windows style SMB signing (see
  537. - the <smbconfoption name="server signing"/> option) is no longer
  538. - necessary, as the GSSAPI flags use select both signing and
  539. - sealing of the data.
  540. - </para>
  541. -
  542. - <para>
  543. - When set to auto or default, SMB encryption is offered, but not
  544. - enforced. When set to mandatory, SMB encryption is required and
  545. - if set to disabled, SMB encryption can not be negotiated.
  546. - </para>
  547. - </listitem>
  548. - </varlistentry>
  549. -
  550. - <varlistentry>
  551. - <term><emphasis>Effects for SMB2</emphasis></term>
  552. - <listitem>
  553. - <para>
  554. - Native SMB transport encryption is available in SMB version 3.0
  555. - or newer. It is only offered by Samba if
  556. - <emphasis>server max protocol</emphasis> is set to
  557. - <emphasis>SMB3</emphasis> or newer.
  558. - Clients supporting this type of encryption include
  559. - Windows 8 and newer,
  560. - Windows server 2012 and newer,
  561. - and smbclient of Samba 4.1 and newer.
  562. - </para>
  563. -
  564. - <para>
  565. - The protocol implementation offers various options:
  566. - </para>
  567. -
  568. - <itemizedlist>
  569. - <listitem>
  570. - <para>
  571. - The capability to perform SMB encryption can be
  572. - negotiated during protocol negotiation.
  573. - </para>
  574. - </listitem>
  575. -
  576. - <listitem>
  577. - <para>
  578. - Data encryption can be enabled globally. In that case,
  579. - an encryption-capable connection will have all traffic
  580. - in all its sessions encrypted. In particular all share
  581. - connections will be encrypted.
  582. - </para>
  583. - </listitem>
  584. -
  585. - <listitem>
  586. - <para>
  587. - Data encryption can also be enabled per share if not
  588. - enabled globally. For an encryption-capable connection,
  589. - all connections to an encryption-enabled share will be
  590. - encrypted.
  591. - </para>
  592. - </listitem>
  593. -
  594. - <listitem>
  595. - <para>
  596. - Encryption can be enforced. This means that session
  597. - setups will be denied on non-encryption-capable
  598. - connections if data encryption has been enabled
  599. - globally. And tree connections will be denied for
  600. - non-encryption capable connections to shares with data
  601. - encryption enabled.
  602. - </para>
  603. - </listitem>
  604. - </itemizedlist>
  605. -
  606. - <para>
  607. - These features can be controlled with settings of
  608. - <emphasis>smb encrypt</emphasis> as follows:
  609. - </para>
  610. -
  611. - <itemizedlist>
  612. - <listitem>
  613. - <para>
  614. - Leaving it as default, explicitly setting
  615. - <emphasis>default</emphasis>, or setting it to
  616. - <emphasis>enabled</emphasis> globally will enable
  617. - negotiation of encryption but will not turn on
  618. - data encryption globally or per share.
  619. - </para>
  620. - </listitem>
  621. -
  622. - <listitem>
  623. - <para>
  624. - Setting it to <emphasis>desired</emphasis> globally
  625. - will enable negotiation and will turn on data encryption
  626. - on sessions and share connections for those clients
  627. - that support it.
  628. - </para>
  629. - </listitem>
  630. -
  631. - <listitem>
  632. - <para>
  633. - Setting it to <emphasis>required</emphasis> globally
  634. - will enable negotiation and turn on data encryption
  635. - on sessions and share connections. Clients that do
  636. - not support encryption will be denied access to the
  637. - server.
  638. - </para>
  639. - </listitem>
  640. -
  641. - <listitem>
  642. - <para>
  643. - Setting it to <emphasis>off</emphasis> globally will
  644. - completely disable the encryption feature for all
  645. - connections. Setting <parameter>smb encrypt =
  646. - required</parameter> for individual shares (while it's
  647. - globally off) will deny access to this shares for all
  648. - clients.
  649. - </para>
  650. - </listitem>
  651. -
  652. - <listitem>
  653. - <para>
  654. - Setting it to <emphasis>desired</emphasis> on a share
  655. - will turn on data encryption for this share for clients
  656. - that support encryption if negotiation has been
  657. - enabled globally.
  658. - </para>
  659. - </listitem>
  660. -
  661. - <listitem>
  662. - <para>
  663. - Setting it to <emphasis>required</emphasis> on a share
  664. - will enforce data encryption for this share if
  665. - negotiation has been enabled globally. I.e. clients that
  666. - do not support encryption will be denied access to the
  667. - share.
  668. - </para>
  669. - <para>
  670. - Note that this allows per-share enforcing to be
  671. - controlled in Samba differently from Windows:
  672. - In Windows, <emphasis>RejectUnencryptedAccess</emphasis>
  673. - is a global setting, and if it is set, all shares with
  674. - data encryption turned on
  675. - are automatically enforcing encryption. In order to
  676. - achieve the same effect in Samba, one
  677. - has to globally set <emphasis>smb encrypt</emphasis> to
  678. - <emphasis>enabled</emphasis>, and then set all shares
  679. - that should be encrypted to
  680. - <emphasis>required</emphasis>.
  681. - Additionally, it is possible in Samba to have some
  682. - shares with encryption <emphasis>required</emphasis>
  683. - and some other shares with encryption only
  684. - <emphasis>desired</emphasis>, which is not possible in
  685. - Windows.
  686. - </para>
  687. - </listitem>
  688. -
  689. - <listitem>
  690. - <para>
  691. - Setting it to <emphasis>off</emphasis> or
  692. - <emphasis>enabled</emphasis> for a share has
  693. - no effect.
  694. - </para>
  695. - </listitem>
  696. - </itemizedlist>
  697. - </listitem>
  698. - </varlistentry>
  699. - </variablelist>
  700. </description>
  701. <value type="default">default</value>
  702. diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
  703. index a3abaa2ec67..c0070b716a5 100644
  704. --- a/source3/param/loadparm.c
  705. +++ b/source3/param/loadparm.c
  706. @@ -241,7 +241,7 @@ static const struct loadparm_service _sDefault =
  707. .aio_write_size = 1,
  708. .map_readonly = MAP_READONLY_NO,
  709. .directory_name_cache_size = 100,
  710. - .smb_encrypt = SMB_SIGNING_DEFAULT,
  711. + .server_smb_encrypt = SMB_SIGNING_DEFAULT,
  712. .kernel_share_modes = true,
  713. .durable_handles = true,
  714. .check_parent_directory_delete_on_close = false,
  715. diff --git a/source3/smbd/service.c b/source3/smbd/service.c
  716. index ed38121f292..a263c33b7e2 100644
  717. --- a/source3/smbd/service.c
  718. +++ b/source3/smbd/service.c
  719. @@ -567,9 +567,9 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
  720. conn->case_preserve = lp_preserve_case(snum);
  721. conn->short_case_preserve = lp_short_preserve_case(snum);
  722. - conn->encrypt_level = lp_smb_encrypt(snum);
  723. + conn->encrypt_level = lp_server_smb_encrypt(snum);
  724. if (conn->encrypt_level > SMB_SIGNING_OFF) {
  725. - if (lp_smb_encrypt(-1) == SMB_SIGNING_OFF) {
  726. + if (lp_server_smb_encrypt(-1) == SMB_SIGNING_OFF) {
  727. if (conn->encrypt_level == SMB_SIGNING_REQUIRED) {
  728. DBG_ERR("Service [%s] requires encryption, but "
  729. "it is disabled globally!\n",
  730. diff --git a/source3/smbd/smb2_negprot.c b/source3/smbd/smb2_negprot.c
  731. index 4071f42b5e0..674942b71de 100644
  732. --- a/source3/smbd/smb2_negprot.c
  733. +++ b/source3/smbd/smb2_negprot.c
  734. @@ -335,7 +335,7 @@ NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req)
  735. }
  736. if ((protocol >= PROTOCOL_SMB2_24) &&
  737. - (lp_smb_encrypt(-1) != SMB_SIGNING_OFF) &&
  738. + (lp_server_smb_encrypt(-1) != SMB_SIGNING_OFF) &&
  739. (in_capabilities & SMB2_CAP_ENCRYPTION)) {
  740. capabilities |= SMB2_CAP_ENCRYPTION;
  741. }
  742. diff --git a/source3/smbd/smb2_sesssetup.c b/source3/smbd/smb2_sesssetup.c
  743. index 2b6b3a820d4..8957411e167 100644
  744. --- a/source3/smbd/smb2_sesssetup.c
  745. +++ b/source3/smbd/smb2_sesssetup.c
  746. @@ -292,12 +292,12 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbXsrv_session *session,
  747. x->global->signing_flags = SMBXSRV_SIGNING_REQUIRED;
  748. }
  749. - if ((lp_smb_encrypt(-1) >= SMB_SIGNING_DESIRED) &&
  750. + if ((lp_server_smb_encrypt(-1) >= SMB_SIGNING_DESIRED) &&
  751. (xconn->smb2.client.capabilities & SMB2_CAP_ENCRYPTION)) {
  752. x->global->encryption_flags = SMBXSRV_ENCRYPTION_DESIRED;
  753. }
  754. - if (lp_smb_encrypt(-1) == SMB_SIGNING_REQUIRED) {
  755. + if (lp_server_smb_encrypt(-1) == SMB_SIGNING_REQUIRED) {
  756. x->global->encryption_flags = SMBXSRV_ENCRYPTION_REQUIRED |
  757. SMBXSRV_ENCRYPTION_DESIRED;
  758. }
  759. diff --git a/source3/smbd/smb2_tcon.c b/source3/smbd/smb2_tcon.c
  760. index 76112d04889..0dd3c653b4b 100644
  761. --- a/source3/smbd/smb2_tcon.c
  762. +++ b/source3/smbd/smb2_tcon.c
  763. @@ -302,13 +302,13 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
  764. TALLOC_FREE(proxy);
  765. }
  766. - if ((lp_smb_encrypt(snum) >= SMB_SIGNING_DESIRED) &&
  767. + if ((lp_server_smb_encrypt(snum) >= SMB_SIGNING_DESIRED) &&
  768. (conn->smb2.server.cipher != 0))
  769. {
  770. encryption_desired = true;
  771. }
  772. - if (lp_smb_encrypt(snum) == SMB_SIGNING_REQUIRED) {
  773. + if (lp_server_smb_encrypt(snum) == SMB_SIGNING_REQUIRED) {
  774. encryption_desired = true;
  775. encryption_required = true;
  776. }
  777. diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
  778. index 7acde285a90..b745e0906b1 100644
  779. --- a/source3/smbd/trans2.c
  780. +++ b/source3/smbd/trans2.c
  781. @@ -4484,7 +4484,7 @@ static void call_trans2setfsinfo(connection_struct *conn,
  782. return;
  783. }
  784. - if (lp_smb_encrypt(SNUM(conn)) == SMB_SIGNING_OFF) {
  785. + if (lp_server_smb_encrypt(SNUM(conn)) == SMB_SIGNING_OFF) {
  786. reply_nterror(
  787. req,
  788. NT_STATUS_NOT_SUPPORTED);
  789. --
  790. 2.29.2
  791. From d78374a9e26428a48b3c6a2aa1d4280751620fb9 Mon Sep 17 00:00:00 2001
  792. From: Andreas Schneider <asn@samba.org>
  793. Date: Thu, 28 May 2020 10:04:19 +0200
  794. Subject: [PATCH 005/104] param: Create and use enum_smb_encryption_vals
  795. Signed-off-by: Andreas Schneider <asn@samba.org>
  796. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  797. ---
  798. .../smbdotconf/security/serversmbencrypt.xml | 2 +-
  799. docs-xml/smbdotconf/security/smbencrypt.xml | 2 +-
  800. lib/param/param_table.c | 23 +++++++++++++++++++
  801. libcli/smb/smb_constants.h | 9 ++++++++
  802. 4 files changed, 34 insertions(+), 2 deletions(-)
  803. diff --git a/docs-xml/smbdotconf/security/serversmbencrypt.xml b/docs-xml/smbdotconf/security/serversmbencrypt.xml
  804. index 714aacbf1ca..5f38b46419e 100644
  805. --- a/docs-xml/smbdotconf/security/serversmbencrypt.xml
  806. +++ b/docs-xml/smbdotconf/security/serversmbencrypt.xml
  807. @@ -1,7 +1,7 @@
  808. <samba:parameter name="server smb encrypt"
  809. context="S"
  810. type="enum"
  811. - enumlist="enum_smb_signing_vals"
  812. + enumlist="enum_smb_encryption_vals"
  813. xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
  814. <description>
  815. <para>
  816. diff --git a/docs-xml/smbdotconf/security/smbencrypt.xml b/docs-xml/smbdotconf/security/smbencrypt.xml
  817. index 798e616b765..60271200c0a 100644
  818. --- a/docs-xml/smbdotconf/security/smbencrypt.xml
  819. +++ b/docs-xml/smbdotconf/security/smbencrypt.xml
  820. @@ -1,7 +1,7 @@
  821. <samba:parameter name="smb encrypt"
  822. context="S"
  823. type="enum"
  824. - enumlist="enum_smb_signing_vals"
  825. + enumlist="enum_smb_encryption_vals"
  826. function="server_smb_encrypt"
  827. synonym="1"
  828. xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
  829. diff --git a/lib/param/param_table.c b/lib/param/param_table.c
  830. index 47b85de1f87..e2f737279dc 100644
  831. --- a/lib/param/param_table.c
  832. +++ b/lib/param/param_table.c
  833. @@ -138,6 +138,29 @@ static const struct enum_list enum_smb_signing_vals[] = {
  834. {-1, NULL}
  835. };
  836. +static const struct enum_list enum_smb_encryption_vals[] = {
  837. + {SMB_ENCRYPTION_DEFAULT, "default"},
  838. + {SMB_ENCRYPTION_OFF, "No"},
  839. + {SMB_ENCRYPTION_OFF, "False"},
  840. + {SMB_ENCRYPTION_OFF, "0"},
  841. + {SMB_ENCRYPTION_OFF, "Off"},
  842. + {SMB_ENCRYPTION_OFF, "disabled"},
  843. + {SMB_ENCRYPTION_IF_REQUIRED, "if_required"},
  844. + {SMB_ENCRYPTION_IF_REQUIRED, "Yes"},
  845. + {SMB_ENCRYPTION_IF_REQUIRED, "True"},
  846. + {SMB_ENCRYPTION_IF_REQUIRED, "1"},
  847. + {SMB_ENCRYPTION_IF_REQUIRED, "On"},
  848. + {SMB_ENCRYPTION_IF_REQUIRED, "enabled"},
  849. + {SMB_ENCRYPTION_IF_REQUIRED, "auto"},
  850. + {SMB_ENCRYPTION_DESIRED, "desired"},
  851. + {SMB_ENCRYPTION_REQUIRED, "required"},
  852. + {SMB_ENCRYPTION_REQUIRED, "mandatory"},
  853. + {SMB_ENCRYPTION_REQUIRED, "force"},
  854. + {SMB_ENCRYPTION_REQUIRED, "forced"},
  855. + {SMB_ENCRYPTION_REQUIRED, "enforced"},
  856. + {-1, NULL}
  857. +};
  858. +
  859. static const struct enum_list enum_mdns_name_values[] = {
  860. {MDNS_NAME_NETBIOS, "netbios"},
  861. {MDNS_NAME_MDNS, "mdns"},
  862. diff --git a/libcli/smb/smb_constants.h b/libcli/smb/smb_constants.h
  863. index b424b13cde4..2fb1fd7189e 100644
  864. --- a/libcli/smb/smb_constants.h
  865. +++ b/libcli/smb/smb_constants.h
  866. @@ -106,6 +106,15 @@ enum smb_signing_setting {
  867. SMB_SIGNING_REQUIRED = 3,
  868. };
  869. +/* This MUST align with 'enum smb_signing_setting' */
  870. +enum smb_encryption_setting {
  871. + SMB_ENCRYPTION_DEFAULT = SMB_SIGNING_DEFAULT,
  872. + SMB_ENCRYPTION_OFF = SMB_SIGNING_OFF,
  873. + SMB_ENCRYPTION_IF_REQUIRED = SMB_SIGNING_IF_REQUIRED,
  874. + SMB_ENCRYPTION_DESIRED = SMB_SIGNING_DESIRED,
  875. + SMB_ENCRYPTION_REQUIRED = SMB_SIGNING_REQUIRED,
  876. +};
  877. +
  878. /* types of buffers in core SMB protocol */
  879. #define SMB_DATA_BLOCK 0x1
  880. #define SMB_ASCII4 0x4
  881. --
  882. 2.29.2
  883. From e2e0decfb117a8d6bb1428509f770315849e972b Mon Sep 17 00:00:00 2001
  884. From: Andreas Schneider <asn@samba.org>
  885. Date: Tue, 26 May 2020 09:34:54 +0200
  886. Subject: [PATCH 006/104] s3:smbd: Use 'enum smb_encryption_setting' values
  887. Signed-off-by: Andreas Schneider <asn@samba.org>
  888. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  889. ---
  890. source3/param/loadparm.c | 2 +-
  891. source3/smbd/service.c | 8 ++++----
  892. source3/smbd/smb2_negprot.c | 2 +-
  893. source3/smbd/smb2_sesssetup.c | 4 ++--
  894. source3/smbd/smb2_tcon.c | 4 ++--
  895. source3/smbd/trans2.c | 3 ++-
  896. 6 files changed, 12 insertions(+), 11 deletions(-)
  897. diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
  898. index c0070b716a5..4ad541301b3 100644
  899. --- a/source3/param/loadparm.c
  900. +++ b/source3/param/loadparm.c
  901. @@ -241,7 +241,7 @@ static const struct loadparm_service _sDefault =
  902. .aio_write_size = 1,
  903. .map_readonly = MAP_READONLY_NO,
  904. .directory_name_cache_size = 100,
  905. - .server_smb_encrypt = SMB_SIGNING_DEFAULT,
  906. + .server_smb_encrypt = SMB_ENCRYPTION_DEFAULT,
  907. .kernel_share_modes = true,
  908. .durable_handles = true,
  909. .check_parent_directory_delete_on_close = false,
  910. diff --git a/source3/smbd/service.c b/source3/smbd/service.c
  911. index a263c33b7e2..43803e721c2 100644
  912. --- a/source3/smbd/service.c
  913. +++ b/source3/smbd/service.c
  914. @@ -568,16 +568,16 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
  915. conn->short_case_preserve = lp_short_preserve_case(snum);
  916. conn->encrypt_level = lp_server_smb_encrypt(snum);
  917. - if (conn->encrypt_level > SMB_SIGNING_OFF) {
  918. - if (lp_server_smb_encrypt(-1) == SMB_SIGNING_OFF) {
  919. - if (conn->encrypt_level == SMB_SIGNING_REQUIRED) {
  920. + if (conn->encrypt_level > SMB_ENCRYPTION_OFF) {
  921. + if (lp_server_smb_encrypt(-1) == SMB_ENCRYPTION_OFF) {
  922. + if (conn->encrypt_level == SMB_ENCRYPTION_REQUIRED) {
  923. DBG_ERR("Service [%s] requires encryption, but "
  924. "it is disabled globally!\n",
  925. lp_const_servicename(snum));
  926. status = NT_STATUS_ACCESS_DENIED;
  927. goto err_root_exit;
  928. }
  929. - conn->encrypt_level = SMB_SIGNING_OFF;
  930. + conn->encrypt_level = SMB_ENCRYPTION_OFF;
  931. }
  932. }
  933. diff --git a/source3/smbd/smb2_negprot.c b/source3/smbd/smb2_negprot.c
  934. index 674942b71de..99303f1b07b 100644
  935. --- a/source3/smbd/smb2_negprot.c
  936. +++ b/source3/smbd/smb2_negprot.c
  937. @@ -335,7 +335,7 @@ NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req)
  938. }
  939. if ((protocol >= PROTOCOL_SMB2_24) &&
  940. - (lp_server_smb_encrypt(-1) != SMB_SIGNING_OFF) &&
  941. + (lp_server_smb_encrypt(-1) != SMB_ENCRYPTION_OFF) &&
  942. (in_capabilities & SMB2_CAP_ENCRYPTION)) {
  943. capabilities |= SMB2_CAP_ENCRYPTION;
  944. }
  945. diff --git a/source3/smbd/smb2_sesssetup.c b/source3/smbd/smb2_sesssetup.c
  946. index 8957411e167..907dd92321e 100644
  947. --- a/source3/smbd/smb2_sesssetup.c
  948. +++ b/source3/smbd/smb2_sesssetup.c
  949. @@ -292,12 +292,12 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbXsrv_session *session,
  950. x->global->signing_flags = SMBXSRV_SIGNING_REQUIRED;
  951. }
  952. - if ((lp_server_smb_encrypt(-1) >= SMB_SIGNING_DESIRED) &&
  953. + if ((lp_server_smb_encrypt(-1) >= SMB_ENCRYPTION_DESIRED) &&
  954. (xconn->smb2.client.capabilities & SMB2_CAP_ENCRYPTION)) {
  955. x->global->encryption_flags = SMBXSRV_ENCRYPTION_DESIRED;
  956. }
  957. - if (lp_server_smb_encrypt(-1) == SMB_SIGNING_REQUIRED) {
  958. + if (lp_server_smb_encrypt(-1) == SMB_ENCRYPTION_REQUIRED) {
  959. x->global->encryption_flags = SMBXSRV_ENCRYPTION_REQUIRED |
  960. SMBXSRV_ENCRYPTION_DESIRED;
  961. }
  962. diff --git a/source3/smbd/smb2_tcon.c b/source3/smbd/smb2_tcon.c
  963. index 0dd3c653b4b..d7e0cf90f47 100644
  964. --- a/source3/smbd/smb2_tcon.c
  965. +++ b/source3/smbd/smb2_tcon.c
  966. @@ -302,13 +302,13 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
  967. TALLOC_FREE(proxy);
  968. }
  969. - if ((lp_server_smb_encrypt(snum) >= SMB_SIGNING_DESIRED) &&
  970. + if ((lp_server_smb_encrypt(snum) >= SMB_ENCRYPTION_DESIRED) &&
  971. (conn->smb2.server.cipher != 0))
  972. {
  973. encryption_desired = true;
  974. }
  975. - if (lp_server_smb_encrypt(snum) == SMB_SIGNING_REQUIRED) {
  976. + if (lp_server_smb_encrypt(snum) == SMB_ENCRYPTION_REQUIRED) {
  977. encryption_desired = true;
  978. encryption_required = true;
  979. }
  980. diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
  981. index b745e0906b1..2f2fdcb7260 100644
  982. --- a/source3/smbd/trans2.c
  983. +++ b/source3/smbd/trans2.c
  984. @@ -4484,7 +4484,8 @@ static void call_trans2setfsinfo(connection_struct *conn,
  985. return;
  986. }
  987. - if (lp_server_smb_encrypt(SNUM(conn)) == SMB_SIGNING_OFF) {
  988. + if (lp_server_smb_encrypt(SNUM(conn)) ==
  989. + SMB_ENCRYPTION_OFF) {
  990. reply_nterror(
  991. req,
  992. NT_STATUS_NOT_SUPPORTED);
  993. --
  994. 2.29.2
  995. From a461b9e0348f2f082cc59b601271ca5b3283df09 Mon Sep 17 00:00:00 2001
  996. From: Andreas Schneider <asn@samba.org>
  997. Date: Thu, 9 Apr 2020 10:38:41 +0200
  998. Subject: [PATCH 007/104] docs-xml: Add 'client smb encrypt'
  999. Signed-off-by: Andreas Schneider <asn@samba.org>
  1000. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1001. ---
  1002. .../smbdotconf/security/clientsmbencrypt.xml | 126 ++++++++++++++++++
  1003. lib/param/loadparm.c | 4 +
  1004. source3/param/loadparm.c | 2 +
  1005. 3 files changed, 132 insertions(+)
  1006. create mode 100644 docs-xml/smbdotconf/security/clientsmbencrypt.xml
  1007. diff --git a/docs-xml/smbdotconf/security/clientsmbencrypt.xml b/docs-xml/smbdotconf/security/clientsmbencrypt.xml
  1008. new file mode 100644
  1009. index 00000000000..05df152e734
  1010. --- /dev/null
  1011. +++ b/docs-xml/smbdotconf/security/clientsmbencrypt.xml
  1012. @@ -0,0 +1,126 @@
  1013. +<samba:parameter name="client smb encrypt"
  1014. + context="G"
  1015. + type="enum"
  1016. + enumlist="enum_smb_encryption_vals"
  1017. + xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
  1018. +<description>
  1019. + <para>
  1020. + This parameter controls whether a client should try or is required
  1021. + to use SMB encryption. It has different effects depending on whether
  1022. + the connection uses SMB1 or SMB3:
  1023. + </para>
  1024. +
  1025. + <itemizedlist>
  1026. + <listitem>
  1027. + <para>
  1028. + If the connection uses SMB1, then this option controls the use
  1029. + of a Samba-specific extension to the SMB protocol introduced in
  1030. + Samba 3.2 that makes use of the Unix extensions.
  1031. + </para>
  1032. + </listitem>
  1033. +
  1034. + <listitem>
  1035. + <para>
  1036. + If the connection uses SMB2 or newer, then this option controls
  1037. + the use of the SMB-level encryption that is supported in SMB
  1038. + version 3.0 and above and available in Windows 8 and newer.
  1039. + </para>
  1040. + </listitem>
  1041. + </itemizedlist>
  1042. +
  1043. + <para>
  1044. + This parameter can be set globally. Possible values are
  1045. +
  1046. + <emphasis>off</emphasis>,
  1047. + <emphasis>if_required</emphasis>,
  1048. + <emphasis>desired</emphasis>,
  1049. + and
  1050. + <emphasis>required</emphasis>.
  1051. + A special value is <emphasis>default</emphasis> which is
  1052. + the implicit default setting of <emphasis>if_required</emphasis>.
  1053. + </para>
  1054. +
  1055. + <variablelist>
  1056. + <varlistentry>
  1057. + <term><emphasis>Effects for SMB1</emphasis></term>
  1058. + <listitem>
  1059. + <para>
  1060. + The Samba-specific encryption of SMB1 connections is an
  1061. + extension to the SMB protocol negotiated as part of the UNIX
  1062. + extensions. SMB encryption uses the GSSAPI (SSPI on Windows)
  1063. + ability to encrypt and sign every request/response in a SMB
  1064. + protocol stream. When enabled it provides a secure method of
  1065. + SMB/CIFS communication, similar to an ssh protected session, but
  1066. + using SMB/CIFS authentication to negotiate encryption and
  1067. + signing keys. Currently this is only supported smbclient of by
  1068. + Samba 3.2 and newer. Windows does not support this feature.
  1069. + </para>
  1070. +
  1071. + <para>
  1072. + When set to default, SMB encryption is probed, but not
  1073. + enforced. When set to required, SMB encryption is required and
  1074. + if set to disabled, SMB encryption can not be negotiated.
  1075. + </para>
  1076. + </listitem>
  1077. + </varlistentry>
  1078. +
  1079. + <varlistentry>
  1080. + <term><emphasis>Effects for SMB3 and newer</emphasis></term>
  1081. + <listitem>
  1082. + <para>
  1083. + Native SMB transport encryption is available in SMB version 3.0
  1084. + or newer. It is only used by Samba if
  1085. + <emphasis>client max protocol</emphasis> is set to
  1086. + <emphasis>SMB3</emphasis> or newer.
  1087. + </para>
  1088. +
  1089. + <para>
  1090. + These features can be controlled with settings of
  1091. + <emphasis>client smb encrypt</emphasis> as follows:
  1092. + </para>
  1093. +
  1094. + <itemizedlist>
  1095. + <listitem>
  1096. + <para>
  1097. + Leaving it as default, explicitly setting
  1098. + <emphasis>default</emphasis>, or setting it to
  1099. + <emphasis>if_required</emphasis> globally will enable
  1100. + negotiation of encryption but will not turn on
  1101. + data encryption globally.
  1102. + </para>
  1103. + </listitem>
  1104. +
  1105. + <listitem>
  1106. + <para>
  1107. + Setting it to <emphasis>desired</emphasis> globally
  1108. + will enable negotiation and will turn on data encryption
  1109. + on sessions and share connections for those servers
  1110. + that support it.
  1111. + </para>
  1112. + </listitem>
  1113. +
  1114. + <listitem>
  1115. + <para>
  1116. + Setting it to <emphasis>required</emphasis> globally
  1117. + will enable negotiation and turn on data encryption
  1118. + on sessions and share connections. Clients that do
  1119. + not support encryption will be denied access to the
  1120. + server.
  1121. + </para>
  1122. + </listitem>
  1123. +
  1124. + <listitem>
  1125. + <para>
  1126. + Setting it to <emphasis>off</emphasis> globally will
  1127. + completely disable the encryption feature for all
  1128. + connections.
  1129. + </para>
  1130. + </listitem>
  1131. + </itemizedlist>
  1132. + </listitem>
  1133. + </varlistentry>
  1134. + </variablelist>
  1135. +</description>
  1136. +
  1137. +<value type="default">default</value>
  1138. +</samba:parameter>
  1139. diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
  1140. index 006caabc092..67f5709b213 100644
  1141. --- a/lib/param/loadparm.c
  1142. +++ b/lib/param/loadparm.c
  1143. @@ -3079,6 +3079,10 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
  1144. lpcfg_do_global_parameter(
  1145. lp_ctx, "ldap max search request size", "256000");
  1146. + lpcfg_do_global_parameter(lp_ctx,
  1147. + "client smb encrypt",
  1148. + "default");
  1149. +
  1150. for (i = 0; parm_table[i].label; i++) {
  1151. if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
  1152. lp_ctx->flags[i] |= FLAG_DEFAULT;
  1153. diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
  1154. index 4ad541301b3..6418a42b6eb 100644
  1155. --- a/source3/param/loadparm.c
  1156. +++ b/source3/param/loadparm.c
  1157. @@ -960,6 +960,8 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
  1158. Globals.ldap_max_authenticated_request_size = 16777216;
  1159. Globals.ldap_max_search_request_size = 256000;
  1160. + Globals.client_smb_encrypt = SMB_ENCRYPTION_DEFAULT;
  1161. +
  1162. /* Now put back the settings that were set with lp_set_cmdline() */
  1163. apply_lp_set_cmdline();
  1164. }
  1165. --
  1166. 2.29.2
  1167. From d55143fc3090b43390fdf14ff45d9c2971fc43d2 Mon Sep 17 00:00:00 2001
  1168. From: Andreas Schneider <asn@samba.org>
  1169. Date: Wed, 22 Jul 2020 17:48:25 +0200
  1170. Subject: [PATCH 008/104] lib:param: Add lpcfg_parse_enum_vals()
  1171. Signed-off-by: Andreas Schneider <asn@samba.org>
  1172. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1173. ---
  1174. lib/param/loadparm.c | 30 ++++++++++++++++++++++++++++++
  1175. lib/param/loadparm.h | 2 ++
  1176. 2 files changed, 32 insertions(+)
  1177. diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
  1178. index 67f5709b213..b1410791c60 100644
  1179. --- a/lib/param/loadparm.c
  1180. +++ b/lib/param/loadparm.c
  1181. @@ -3675,3 +3675,33 @@ char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
  1182. raw_value,
  1183. lp_sub->private_data);
  1184. }
  1185. +
  1186. +/**
  1187. + * @brief Parse a string value of a given parameter to its integer enum value.
  1188. + *
  1189. + * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
  1190. + *
  1191. + * @param[in] param_value The parameter value (e.g. 'required').
  1192. + *
  1193. + * @return The integer value of the enum the param_value matches or INT32_MIN
  1194. + * on error.
  1195. + */
  1196. +int32_t lpcfg_parse_enum_vals(const char *param_name,
  1197. + const char *param_value)
  1198. +{
  1199. + struct parm_struct *parm = NULL;
  1200. + int32_t ret = INT32_MIN;
  1201. + bool ok;
  1202. +
  1203. + parm = lpcfg_parm_struct(NULL, param_name);
  1204. + if (parm == NULL) {
  1205. + return INT32_MIN;
  1206. + }
  1207. +
  1208. + ok = lp_set_enum_parm(parm, param_value, &ret);
  1209. + if (!ok) {
  1210. + return INT32_MIN;
  1211. + }
  1212. +
  1213. + return ret;
  1214. +}
  1215. diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
  1216. index 323fcf84523..e66ce2324b4 100644
  1217. --- a/lib/param/loadparm.h
  1218. +++ b/lib/param/loadparm.h
  1219. @@ -316,6 +316,8 @@ bool lp_do_section(const char *pszSectionName, void *userdata);
  1220. bool store_lp_set_cmdline(const char *pszParmName, const char *pszParmValue);
  1221. int num_parameters(void);
  1222. +int32_t lpcfg_parse_enum_vals(const char *param_name,
  1223. + const char *param_value);
  1224. struct loadparm_substitution;
  1225. #ifdef LOADPARM_SUBSTITUTION_INTERNALS
  1226. --
  1227. 2.29.2
  1228. From d01ae8111553a71b80988eeb737e8b80bc765b20 Mon Sep 17 00:00:00 2001
  1229. From: Andreas Schneider <asn@samba.org>
  1230. Date: Wed, 9 Oct 2019 09:38:08 +0200
  1231. Subject: [PATCH 009/104] libcli:smb: Add smb_signing_setting_translate()
  1232. Signed-off-by: Andreas Schneider <asn@samba.org>
  1233. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1234. ---
  1235. libcli/smb/smb_util.h | 7 ++++
  1236. libcli/smb/test_util_translate.c | 64 ++++++++++++++++++++++++++++++++
  1237. libcli/smb/util.c | 20 ++++++++++
  1238. libcli/smb/wscript | 5 +++
  1239. selftest/tests.py | 2 +
  1240. 5 files changed, 98 insertions(+)
  1241. create mode 100644 libcli/smb/test_util_translate.c
  1242. diff --git a/libcli/smb/smb_util.h b/libcli/smb/smb_util.h
  1243. index 8861741c92f..15bdbe856d1 100644
  1244. --- a/libcli/smb/smb_util.h
  1245. +++ b/libcli/smb/smb_util.h
  1246. @@ -24,6 +24,9 @@
  1247. #include "smb_constants.h"
  1248. #include <talloc.h>
  1249. +#ifndef _SMB_UTIL_H
  1250. +#define _SMB_UTIL_H
  1251. +
  1252. const char *smb_protocol_types_string(enum protocol_types protocol);
  1253. char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib);
  1254. uint32_t unix_perms_to_wire(mode_t perms);
  1255. @@ -46,3 +49,7 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2,
  1256. const uint8_t *buf, size_t buf_len,
  1257. const uint8_t *position,
  1258. size_t *_consumed);
  1259. +
  1260. +enum smb_signing_setting smb_signing_setting_translate(const char *str);
  1261. +
  1262. +#endif /* _SMB_UTIL_H */
  1263. diff --git a/libcli/smb/test_util_translate.c b/libcli/smb/test_util_translate.c
  1264. new file mode 100644
  1265. index 00000000000..4b81984affa
  1266. --- /dev/null
  1267. +++ b/libcli/smb/test_util_translate.c
  1268. @@ -0,0 +1,64 @@
  1269. +/*
  1270. + * Unix SMB/CIFS implementation.
  1271. + *
  1272. + * Copyright (C) 2020 Andreas Schneider <asn@samba.org>
  1273. + *
  1274. + * This program is free software; you can redistribute it and/or modify
  1275. + * it under the terms of the GNU General Public License as published by
  1276. + * the Free Software Foundation; either version 3 of the License, or
  1277. + * (at your option) any later version.
  1278. + *
  1279. + * This program is distributed in the hope that it will be useful,
  1280. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1281. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1282. + * GNU General Public License for more details.
  1283. + *
  1284. + * You should have received a copy of the GNU General Public License
  1285. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1286. + */
  1287. +
  1288. +#include <stdarg.h>
  1289. +#include <stddef.h>
  1290. +#include <stdint.h>
  1291. +#include <setjmp.h>
  1292. +#include <cmocka.h>
  1293. +
  1294. +#include "lib/replace/replace.h"
  1295. +#include <talloc.h>
  1296. +
  1297. +#include "libcli/smb/util.c"
  1298. +
  1299. +static void test_smb_signing_setting_translate(void **state)
  1300. +{
  1301. + enum smb_signing_setting signing_state;
  1302. +
  1303. + signing_state = smb_signing_setting_translate("wurst");
  1304. + assert_int_equal(signing_state, SMB_SIGNING_REQUIRED);
  1305. +
  1306. + signing_state = smb_signing_setting_translate("off");
  1307. + assert_int_equal(signing_state, SMB_SIGNING_OFF);
  1308. +
  1309. + signing_state = smb_signing_setting_translate("if_required");
  1310. + assert_int_equal(signing_state, SMB_SIGNING_IF_REQUIRED);
  1311. +
  1312. + signing_state = smb_signing_setting_translate("mandatory");
  1313. + assert_int_equal(signing_state, SMB_SIGNING_REQUIRED);
  1314. +
  1315. +}
  1316. +
  1317. +int main(int argc, char *argv[])
  1318. +{
  1319. + int rc;
  1320. + const struct CMUnitTest tests[] = {
  1321. + cmocka_unit_test(test_smb_signing_setting_translate),
  1322. + };
  1323. +
  1324. + if (argc == 2) {
  1325. + cmocka_set_test_filter(argv[1]);
  1326. + }
  1327. + cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
  1328. +
  1329. + rc = cmocka_run_group_tests(tests, NULL, NULL);
  1330. +
  1331. + return rc;
  1332. +}
  1333. diff --git a/libcli/smb/util.c b/libcli/smb/util.c
  1334. index 6fdf35fbbf3..da0e4db2bf3 100644
  1335. --- a/libcli/smb/util.c
  1336. +++ b/libcli/smb/util.c
  1337. @@ -22,6 +22,7 @@
  1338. #include "includes.h"
  1339. #include "libcli/smb/smb_common.h"
  1340. #include "system/filesys.h"
  1341. +#include "lib/param/loadparm.h"
  1342. const char *smb_protocol_types_string(enum protocol_types protocol)
  1343. {
  1344. @@ -428,3 +429,22 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2,
  1345. return internal_bytes_pull_str(mem_ctx, _str, ucs2, true,
  1346. buf, buf_len, position, _consumed);
  1347. }
  1348. +
  1349. +/**
  1350. + * @brief Translate SMB signing settings as string to an enum.
  1351. + *
  1352. + * @param[in] str The string to translate.
  1353. + *
  1354. + * @return A corresponding enum @smb_signing_setting tranlated from the string.
  1355. + */
  1356. +enum smb_signing_setting smb_signing_setting_translate(const char *str)
  1357. +{
  1358. + enum smb_signing_setting signing_state = SMB_SIGNING_REQUIRED;
  1359. + int32_t val = lpcfg_parse_enum_vals("client signing", str);
  1360. +
  1361. + if (val != INT32_MIN) {
  1362. + signing_state = val;
  1363. + }
  1364. +
  1365. + return signing_state;
  1366. +}
  1367. diff --git a/libcli/smb/wscript b/libcli/smb/wscript
  1368. index 86e377f570b..c047fd33278 100644
  1369. --- a/libcli/smb/wscript
  1370. +++ b/libcli/smb/wscript
  1371. @@ -72,3 +72,8 @@ def build(bld):
  1372. source='test_smb1cli_session.c',
  1373. deps='cmocka cli_smb_common',
  1374. for_selftest=True)
  1375. +
  1376. + bld.SAMBA_BINARY('test_util_translate',
  1377. + source='test_util_translate.c',
  1378. + deps='cmocka cli_smb_common',
  1379. + for_selftest=True)
  1380. diff --git a/selftest/tests.py b/selftest/tests.py
  1381. index 6918e1306c3..20981754db4 100644
  1382. --- a/selftest/tests.py
  1383. +++ b/selftest/tests.py
  1384. @@ -376,6 +376,8 @@ plantestsuite("samba.unittests.lib_util_modules", "none",
  1385. plantestsuite("samba.unittests.smb1cli_session", "none",
  1386. [os.path.join(bindir(), "default/libcli/smb/test_smb1cli_session")])
  1387. +plantestsuite("samba.unittests.smb_util_translate", "none",
  1388. + [os.path.join(bindir(), "default/libcli/smb/test_util_translate")])
  1389. plantestsuite("samba.unittests.talloc_keep_secret", "none",
  1390. [os.path.join(bindir(), "default/lib/util/test_talloc_keep_secret")])
  1391. --
  1392. 2.29.2
  1393. From 4cef2825a3363a38fbfbff5f172053145f62f100 Mon Sep 17 00:00:00 2001
  1394. From: Andreas Schneider <asn@samba.org>
  1395. Date: Tue, 26 May 2020 08:39:34 +0200
  1396. Subject: [PATCH 010/104] libcli:smb: Add smb_encryption_setting_translate()
  1397. Add encryption enum and function to avoid confusion when reading the
  1398. code.
  1399. Signed-off-by: Andreas Schneider <asn@samba.org>
  1400. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1401. ---
  1402. libcli/smb/smb_util.h | 1 +
  1403. libcli/smb/test_util_translate.c | 19 +++++++++++++++++++
  1404. libcli/smb/util.c | 20 ++++++++++++++++++++
  1405. 3 files changed, 40 insertions(+)
  1406. diff --git a/libcli/smb/smb_util.h b/libcli/smb/smb_util.h
  1407. index 15bdbe856d1..2a727db8b6f 100644
  1408. --- a/libcli/smb/smb_util.h
  1409. +++ b/libcli/smb/smb_util.h
  1410. @@ -51,5 +51,6 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2,
  1411. size_t *_consumed);
  1412. enum smb_signing_setting smb_signing_setting_translate(const char *str);
  1413. +enum smb_encryption_setting smb_encryption_setting_translate(const char *str);
  1414. #endif /* _SMB_UTIL_H */
  1415. diff --git a/libcli/smb/test_util_translate.c b/libcli/smb/test_util_translate.c
  1416. index 4b81984affa..b300af52c09 100644
  1417. --- a/libcli/smb/test_util_translate.c
  1418. +++ b/libcli/smb/test_util_translate.c
  1419. @@ -46,11 +46,30 @@ static void test_smb_signing_setting_translate(void **state)
  1420. }
  1421. +static void test_smb_encryption_setting_translate(void **state)
  1422. +{
  1423. + enum smb_encryption_setting encryption_state;
  1424. +
  1425. + encryption_state = smb_encryption_setting_translate("wurst");
  1426. + assert_int_equal(encryption_state, SMB_ENCRYPTION_REQUIRED);
  1427. +
  1428. + encryption_state = smb_encryption_setting_translate("off");
  1429. + assert_int_equal(encryption_state, SMB_ENCRYPTION_OFF);
  1430. +
  1431. + encryption_state = smb_encryption_setting_translate("if_required");
  1432. + assert_int_equal(encryption_state, SMB_ENCRYPTION_IF_REQUIRED);
  1433. +
  1434. + encryption_state = smb_encryption_setting_translate("mandatory");
  1435. + assert_int_equal(encryption_state, SMB_ENCRYPTION_REQUIRED);
  1436. +
  1437. +}
  1438. +
  1439. int main(int argc, char *argv[])
  1440. {
  1441. int rc;
  1442. const struct CMUnitTest tests[] = {
  1443. cmocka_unit_test(test_smb_signing_setting_translate),
  1444. + cmocka_unit_test(test_smb_encryption_setting_translate),
  1445. };
  1446. if (argc == 2) {
  1447. diff --git a/libcli/smb/util.c b/libcli/smb/util.c
  1448. index da0e4db2bf3..ac2887ee5c4 100644
  1449. --- a/libcli/smb/util.c
  1450. +++ b/libcli/smb/util.c
  1451. @@ -448,3 +448,23 @@ enum smb_signing_setting smb_signing_setting_translate(const char *str)
  1452. return signing_state;
  1453. }
  1454. +
  1455. +/**
  1456. + * @brief Translate SMB encryption settings as string to an enum.
  1457. + *
  1458. + * @param[in] str The string to translate.
  1459. + *
  1460. + * @return A corresponding enum @smb_encryption_setting tranlated from the
  1461. + * string.
  1462. + */
  1463. +enum smb_encryption_setting smb_encryption_setting_translate(const char *str)
  1464. +{
  1465. + enum smb_encryption_setting encryption_state = SMB_ENCRYPTION_REQUIRED;
  1466. + int32_t val = lpcfg_parse_enum_vals("client smb encrypt", str);
  1467. +
  1468. + if (val != INT32_MIN) {
  1469. + encryption_state = val;
  1470. + }
  1471. +
  1472. + return encryption_state;
  1473. +}
  1474. --
  1475. 2.29.2
  1476. From a0cb6b810b655298ce5b87d8e36d1089460feca7 Mon Sep 17 00:00:00 2001
  1477. From: Andreas Schneider <asn@samba.org>
  1478. Date: Wed, 9 Oct 2019 09:47:59 +0200
  1479. Subject: [PATCH 011/104] s3:lib: Use smb_signing_setting_translate for cmdline
  1480. parsing
  1481. The function will be removed soon.
  1482. Signed-off-by: Andreas Schneider <asn@samba.org>
  1483. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1484. ---
  1485. source3/lib/util_cmdline.c | 17 +++--------------
  1486. source3/wscript_build | 2 +-
  1487. 2 files changed, 4 insertions(+), 15 deletions(-)
  1488. diff --git a/source3/lib/util_cmdline.c b/source3/lib/util_cmdline.c
  1489. index 90ee67c4cb7..bc1f1c3ed25 100644
  1490. --- a/source3/lib/util_cmdline.c
  1491. +++ b/source3/lib/util_cmdline.c
  1492. @@ -28,6 +28,7 @@
  1493. #include "librpc/gen_ndr/samr.h"
  1494. #include "auth/credentials/credentials.h"
  1495. #include "auth/gensec/gensec.h"
  1496. +#include "libcli/smb/smb_util.h"
  1497. /**************************************************************************n
  1498. Code to cope with username/password auth options from the commandline.
  1499. @@ -240,20 +241,8 @@ void set_cmdline_auth_info_password(struct user_auth_info *auth_info,
  1500. bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info,
  1501. const char *arg)
  1502. {
  1503. - auth_info->signing_state = SMB_SIGNING_DEFAULT;
  1504. - if (strequal(arg, "off") || strequal(arg, "no") ||
  1505. - strequal(arg, "false")) {
  1506. - auth_info->signing_state = SMB_SIGNING_OFF;
  1507. - } else if (strequal(arg, "on") || strequal(arg, "yes") ||
  1508. - strequal(arg, "if_required") ||
  1509. - strequal(arg, "true") || strequal(arg, "auto")) {
  1510. - auth_info->signing_state = SMB_SIGNING_IF_REQUIRED;
  1511. - } else if (strequal(arg, "force") || strequal(arg, "required") ||
  1512. - strequal(arg, "forced")) {
  1513. - auth_info->signing_state = SMB_SIGNING_REQUIRED;
  1514. - } else {
  1515. - return false;
  1516. - }
  1517. + auth_info->signing_state = smb_signing_setting_translate(arg);
  1518. +
  1519. return true;
  1520. }
  1521. diff --git a/source3/wscript_build b/source3/wscript_build
  1522. index 5a07eddac44..6a08afe4a25 100644
  1523. --- a/source3/wscript_build
  1524. +++ b/source3/wscript_build
  1525. @@ -279,7 +279,7 @@ bld.SAMBA3_LIBRARY('popt_samba3_cmdline',
  1526. bld.SAMBA3_LIBRARY('util_cmdline',
  1527. source='lib/util_cmdline.c',
  1528. - deps='secrets3 samba-credentials',
  1529. + deps='secrets3 samba-credentials cli_smb_common',
  1530. private_library=True)
  1531. bld.SAMBA3_LIBRARY('cmdline_contexts',
  1532. --
  1533. 2.29.2
  1534. From ef521e6b44710fb3ed567d36fa56687b677fe58a Mon Sep 17 00:00:00 2001
  1535. From: Andreas Schneider <asn@samba.org>
  1536. Date: Thu, 23 Jul 2020 07:47:18 +0200
  1537. Subject: [PATCH 012/104] auth:creds: Remove unused credentials autoproto
  1538. header
  1539. Signed-off-by: Andreas Schneider <asn@samba.org>
  1540. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1541. ---
  1542. auth/credentials/credentials_krb5.c | 1 -
  1543. auth/credentials/credentials_secrets.c | 1 -
  1544. auth/credentials/wscript_build | 1 -
  1545. source4/auth/kerberos/kerberos_util.c | 1 -
  1546. source4/auth/tests/kerberos.c | 1 -
  1547. 5 files changed, 5 deletions(-)
  1548. diff --git a/auth/credentials/credentials_krb5.c b/auth/credentials/credentials_krb5.c
  1549. index 20e677e521a..259b35b73b0 100644
  1550. --- a/auth/credentials/credentials_krb5.c
  1551. +++ b/auth/credentials/credentials_krb5.c
  1552. @@ -27,7 +27,6 @@
  1553. #include "auth/kerberos/kerberos.h"
  1554. #include "auth/credentials/credentials.h"
  1555. #include "auth/credentials/credentials_internal.h"
  1556. -#include "auth/credentials/credentials_proto.h"
  1557. #include "auth/credentials/credentials_krb5.h"
  1558. #include "auth/kerberos/kerberos_credentials.h"
  1559. #include "auth/kerberos/kerberos_srv_keytab.h"
  1560. diff --git a/auth/credentials/credentials_secrets.c b/auth/credentials/credentials_secrets.c
  1561. index 54f3ce2d078..52a89d4d5b4 100644
  1562. --- a/auth/credentials/credentials_secrets.c
  1563. +++ b/auth/credentials/credentials_secrets.c
  1564. @@ -29,7 +29,6 @@
  1565. #include "system/filesys.h"
  1566. #include "auth/credentials/credentials.h"
  1567. #include "auth/credentials/credentials_internal.h"
  1568. -#include "auth/credentials/credentials_proto.h"
  1569. #include "auth/credentials/credentials_krb5.h"
  1570. #include "auth/kerberos/kerberos_util.h"
  1571. #include "param/param.h"
  1572. diff --git a/auth/credentials/wscript_build b/auth/credentials/wscript_build
  1573. index f5aba1de248..564a04fe8dd 100644
  1574. --- a/auth/credentials/wscript_build
  1575. +++ b/auth/credentials/wscript_build
  1576. @@ -2,7 +2,6 @@
  1577. bld.SAMBA_LIBRARY('samba-credentials',
  1578. source='credentials.c',
  1579. - autoproto='credentials_proto.h',
  1580. public_headers='credentials.h',
  1581. pc_files='samba-credentials.pc',
  1582. deps='LIBCRYPTO samba-errors events LIBCLI_AUTH samba-security CREDENTIALS_SECRETS CREDENTIALS_KRB5',
  1583. diff --git a/source4/auth/kerberos/kerberos_util.c b/source4/auth/kerberos/kerberos_util.c
  1584. index ffef24f285c..544d9d853cc 100644
  1585. --- a/source4/auth/kerberos/kerberos_util.c
  1586. +++ b/source4/auth/kerberos/kerberos_util.c
  1587. @@ -24,7 +24,6 @@
  1588. #include "system/kerberos.h"
  1589. #include "auth/kerberos/kerberos.h"
  1590. #include "auth/credentials/credentials.h"
  1591. -#include "auth/credentials/credentials_proto.h"
  1592. #include "auth/credentials/credentials_krb5.h"
  1593. #include "auth/kerberos/kerberos_credentials.h"
  1594. #include "auth/kerberos/kerberos_util.h"
  1595. diff --git a/source4/auth/tests/kerberos.c b/source4/auth/tests/kerberos.c
  1596. index 7711eac2afa..d9be3562adb 100644
  1597. --- a/source4/auth/tests/kerberos.c
  1598. +++ b/source4/auth/tests/kerberos.c
  1599. @@ -10,7 +10,6 @@
  1600. #include "system/kerberos.h"
  1601. #include "auth/kerberos/kerberos.h"
  1602. #include "auth/credentials/credentials.h"
  1603. -#include "auth/credentials/credentials_proto.h"
  1604. #include "auth/credentials/credentials_krb5.h"
  1605. #include "auth/kerberos/kerberos_credentials.h"
  1606. #include "auth/kerberos/kerberos_util.h"
  1607. --
  1608. 2.29.2
  1609. From 6fafcebb8bd6311a736d995af6641e68e43e03a1 Mon Sep 17 00:00:00 2001
  1610. From: Andreas Schneider <asn@samba.org>
  1611. Date: Tue, 26 May 2020 09:32:44 +0200
  1612. Subject: [PATCH 013/104] auth:creds: Add
  1613. cli_credentials_(get|set)_smb_signing()
  1614. Signed-off-by: Andreas Schneider <asn@samba.org>
  1615. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1616. ---
  1617. auth/credentials/credentials.c | 45 +++++++++++++++++++++++++
  1618. auth/credentials/credentials.h | 7 ++++
  1619. auth/credentials/credentials_internal.h | 4 +++
  1620. 3 files changed, 56 insertions(+)
  1621. diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
  1622. index 80a31b248ae..365a6def7ea 100644
  1623. --- a/auth/credentials/credentials.c
  1624. +++ b/auth/credentials/credentials.c
  1625. @@ -44,6 +44,8 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
  1626. cred->winbind_separator = '\\';
  1627. + cred->signing_state = SMB_SIGNING_DEFAULT;
  1628. +
  1629. return cred;
  1630. }
  1631. @@ -922,6 +924,12 @@ _PUBLIC_ void cli_credentials_set_conf(struct cli_credentials *cred,
  1632. if (sep != NULL && sep[0] != '\0') {
  1633. cred->winbind_separator = *lpcfg_winbind_separator(lp_ctx);
  1634. }
  1635. +
  1636. + if (cred->signing_state_obtained <= CRED_SMB_CONF) {
  1637. + /* Will be set to default for invalid smb.conf values */
  1638. + cred->signing_state = lpcfg_client_signing(lp_ctx);
  1639. + cred->signing_state_obtained = CRED_SMB_CONF;
  1640. + }
  1641. }
  1642. /**
  1643. @@ -1304,6 +1312,43 @@ _PUBLIC_ bool cli_credentials_parse_password_fd(struct cli_credentials *credenti
  1644. return true;
  1645. }
  1646. +/**
  1647. + * @brief Set the SMB signing state to request for a SMB connection.
  1648. + *
  1649. + * @param[in] creds The credentials structure to update.
  1650. + *
  1651. + * @param[in] signing_state The signing state to set.
  1652. + *
  1653. + * @param obtained This way the described signing state was specified.
  1654. + *
  1655. + * @return true if we could set the signing state, false otherwise.
  1656. + */
  1657. +_PUBLIC_ bool cli_credentials_set_smb_signing(struct cli_credentials *creds,
  1658. + enum smb_signing_setting signing_state,
  1659. + enum credentials_obtained obtained)
  1660. +{
  1661. + if (obtained >= creds->signing_state_obtained) {
  1662. + creds->signing_state_obtained = obtained;
  1663. + creds->signing_state = signing_state;
  1664. + return true;
  1665. + }
  1666. +
  1667. + return false;
  1668. +}
  1669. +
  1670. +/**
  1671. + * @brief Obtain the SMB signing state from a credentials structure.
  1672. + *
  1673. + * @param[in] creds The credential structure to obtain the SMB signing state
  1674. + * from.
  1675. + *
  1676. + * @return The SMB singing state.
  1677. + */
  1678. +_PUBLIC_ enum smb_signing_setting
  1679. +cli_credentials_get_smb_signing(struct cli_credentials *creds)
  1680. +{
  1681. + return creds->signing_state;
  1682. +}
  1683. /**
  1684. * Encrypt a data blob using the session key and the negotiated encryption
  1685. diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
  1686. index 7154c2a008c..422391ad585 100644
  1687. --- a/auth/credentials/credentials.h
  1688. +++ b/auth/credentials/credentials.h
  1689. @@ -38,6 +38,7 @@ struct gssapi_creds_container;
  1690. struct smb_krb5_context;
  1691. struct keytab_container;
  1692. struct db_context;
  1693. +enum smb_signing_setting;
  1694. /* In order of priority */
  1695. enum credentials_obtained {
  1696. @@ -290,6 +291,12 @@ void *_cli_credentials_callback_data(struct cli_credentials *cred);
  1697. #define cli_credentials_callback_data_void(_cred) \
  1698. _cli_credentials_callback_data(_cred)
  1699. +bool cli_credentials_set_smb_signing(struct cli_credentials *cred,
  1700. + enum smb_signing_setting signing_state,
  1701. + enum credentials_obtained obtained);
  1702. +enum smb_signing_setting
  1703. +cli_credentials_get_smb_signing(struct cli_credentials *cred);
  1704. +
  1705. /**
  1706. * Return attached NETLOGON credentials
  1707. */
  1708. diff --git a/auth/credentials/credentials_internal.h b/auth/credentials/credentials_internal.h
  1709. index 68f1f25dce1..9cde0000b5f 100644
  1710. --- a/auth/credentials/credentials_internal.h
  1711. +++ b/auth/credentials/credentials_internal.h
  1712. @@ -24,6 +24,7 @@
  1713. #include "../lib/util/data_blob.h"
  1714. #include "librpc/gen_ndr/misc.h"
  1715. +#include "libcli/smb/smb_constants.h"
  1716. struct cli_credentials {
  1717. enum credentials_obtained workstation_obtained;
  1718. @@ -36,6 +37,7 @@ struct cli_credentials {
  1719. enum credentials_obtained principal_obtained;
  1720. enum credentials_obtained keytab_obtained;
  1721. enum credentials_obtained server_gss_creds_obtained;
  1722. + enum credentials_obtained signing_state_obtained;
  1723. /* Threshold values (essentially a MAX() over a number of the
  1724. * above) for the ccache and GSS credentials, to ensure we
  1725. @@ -117,6 +119,8 @@ struct cli_credentials {
  1726. char winbind_separator;
  1727. bool password_will_be_nt_hash;
  1728. +
  1729. + enum smb_signing_setting signing_state;
  1730. };
  1731. #endif /* __CREDENTIALS_INTERNAL_H__ */
  1732. --
  1733. 2.29.2
  1734. From 64e2c99501677bfe52212c9ea99ec3512cf62f6e Mon Sep 17 00:00:00 2001
  1735. From: Andreas Schneider <asn@samba.org>
  1736. Date: Wed, 3 Jun 2020 11:56:01 +0200
  1737. Subject: [PATCH 014/104] auth:creds: Add python bindings for
  1738. (get|set)_smb_signing
  1739. Signed-off-by: Andreas Schneider <asn@samba.org>
  1740. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1741. ---
  1742. auth/credentials/pycredentials.c | 63 +++++++++++++++++++++++++++++++
  1743. python/samba/tests/credentials.py | 6 +++
  1744. 2 files changed, 69 insertions(+)
  1745. diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
  1746. index 68edc282741..846c418419f 100644
  1747. --- a/auth/credentials/pycredentials.c
  1748. +++ b/auth/credentials/pycredentials.c
  1749. @@ -34,6 +34,7 @@
  1750. #include "auth/credentials/credentials_internal.h"
  1751. #include "system/kerberos.h"
  1752. #include "auth/kerberos/kerberos.h"
  1753. +#include "libcli/smb/smb_constants.h"
  1754. void initcredentials(void);
  1755. @@ -929,6 +930,52 @@ static PyObject *py_creds_encrypt_netr_crypt_password(PyObject *self,
  1756. Py_RETURN_NONE;
  1757. }
  1758. +static PyObject *py_creds_get_smb_signing(PyObject *self, PyObject *unused)
  1759. +{
  1760. + enum smb_signing_setting signing_state;
  1761. + struct cli_credentials *creds = NULL;
  1762. +
  1763. + creds = PyCredentials_AsCliCredentials(self);
  1764. + if (creds == NULL) {
  1765. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  1766. + return NULL;
  1767. + }
  1768. +
  1769. + signing_state = cli_credentials_get_smb_signing(creds);
  1770. + return PyLong_FromLong(signing_state);
  1771. +}
  1772. +
  1773. +static PyObject *py_creds_set_smb_signing(PyObject *self, PyObject *args)
  1774. +{
  1775. + enum smb_signing_setting signing_state;
  1776. + struct cli_credentials *creds = NULL;
  1777. + enum credentials_obtained obt = CRED_SPECIFIED;
  1778. +
  1779. + creds = PyCredentials_AsCliCredentials(self);
  1780. + if (creds == NULL) {
  1781. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  1782. + return NULL;
  1783. + }
  1784. + if (!PyArg_ParseTuple(args, "i|i", &signing_state, &obt)) {
  1785. + return NULL;
  1786. + }
  1787. +
  1788. + switch (signing_state) {
  1789. + case SMB_SIGNING_DEFAULT:
  1790. + case SMB_SIGNING_OFF:
  1791. + case SMB_SIGNING_IF_REQUIRED:
  1792. + case SMB_SIGNING_DESIRED:
  1793. + case SMB_SIGNING_REQUIRED:
  1794. + break;
  1795. + default:
  1796. + PyErr_Format(PyExc_TypeError, "Invalid signing state value");
  1797. + return NULL;
  1798. + }
  1799. +
  1800. + cli_credentials_set_smb_signing(creds, signing_state, obt);
  1801. + Py_RETURN_NONE;
  1802. +}
  1803. +
  1804. static PyMethodDef py_creds_methods[] = {
  1805. {
  1806. .ml_name = "get_username",
  1807. @@ -1209,6 +1256,16 @@ static PyMethodDef py_creds_methods[] = {
  1808. "Encrypt the supplied password using the session key and\n"
  1809. "the negotiated encryption algorithm in place\n"
  1810. "i.e. it overwrites the original data"},
  1811. + {
  1812. + .ml_name = "get_smb_signing",
  1813. + .ml_meth = py_creds_get_smb_signing,
  1814. + .ml_flags = METH_NOARGS,
  1815. + },
  1816. + {
  1817. + .ml_name = "set_smb_signing",
  1818. + .ml_meth = py_creds_set_smb_signing,
  1819. + .ml_flags = METH_VARARGS,
  1820. + },
  1821. { .ml_name = NULL }
  1822. };
  1823. @@ -1295,6 +1352,12 @@ MODULE_INIT_FUNC(credentials)
  1824. PyModule_AddObject(m, "CLI_CRED_NTLM_AUTH", PyLong_FromLong(CLI_CRED_NTLM_AUTH));
  1825. PyModule_AddObject(m, "CLI_CRED_CLEAR_AUTH", PyLong_FromLong(CLI_CRED_CLEAR_AUTH));
  1826. + PyModule_AddObject(m, "SMB_SIGNING_DEFAULT", PyLong_FromLong(SMB_SIGNING_DEFAULT));
  1827. + PyModule_AddObject(m, "SMB_SIGNING_OFF", PyLong_FromLong(SMB_SIGNING_OFF));
  1828. + PyModule_AddObject(m, "SMB_SIGNING_IF_REQUIRED", PyLong_FromLong(SMB_SIGNING_IF_REQUIRED));
  1829. + PyModule_AddObject(m, "SMB_SIGNING_DESIRED", PyLong_FromLong(SMB_SIGNING_DESIRED));
  1830. + PyModule_AddObject(m, "SMB_SIGNING_REQUIRED", PyLong_FromLong(SMB_SIGNING_REQUIRED));
  1831. +
  1832. Py_INCREF(&PyCredentials);
  1833. PyModule_AddObject(m, "Credentials", (PyObject *)&PyCredentials);
  1834. Py_INCREF(&PyCredentialCacheContainer);
  1835. diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
  1836. index 6454ac9ff7c..e5f8122fa21 100644
  1837. --- a/python/samba/tests/credentials.py
  1838. +++ b/python/samba/tests/credentials.py
  1839. @@ -456,3 +456,9 @@ class CredentialsTests(samba.tests.TestCaseInTempDir):
  1840. self.assertEqual(creds.get_principal(), "user@samba.org")
  1841. self.assertEqual(creds.is_anonymous(), False)
  1842. self.assertEqual(creds.authentication_requested(), True)
  1843. +
  1844. + def test_smb_signing(self):
  1845. + creds = credentials.Credentials()
  1846. + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_DEFAULT)
  1847. + creds.set_smb_signing(credentials.SMB_SIGNING_REQUIRED)
  1848. + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_REQUIRED)
  1849. --
  1850. 2.29.2
  1851. From 1280505f1396925851db5a29f2465d9c31d45f88 Mon Sep 17 00:00:00 2001
  1852. From: Andreas Schneider <asn@samba.org>
  1853. Date: Thu, 28 May 2020 16:31:35 +0200
  1854. Subject: [PATCH 015/104] auth:creds: Add
  1855. cli_credentials_(get|set)_smb_ipc_signing()
  1856. Signed-off-by: Andreas Schneider <asn@samba.org>
  1857. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1858. ---
  1859. auth/credentials/credentials.c | 51 +++++++++++++++++++++++++
  1860. auth/credentials/credentials.h | 6 +++
  1861. auth/credentials/credentials_internal.h | 3 ++
  1862. 3 files changed, 60 insertions(+)
  1863. diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
  1864. index 365a6def7ea..dc5d51f1424 100644
  1865. --- a/auth/credentials/credentials.c
  1866. +++ b/auth/credentials/credentials.c
  1867. @@ -46,6 +46,12 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
  1868. cred->signing_state = SMB_SIGNING_DEFAULT;
  1869. + /*
  1870. + * The default value of lpcfg_client_ipc_signing() is REQUIRED, so use
  1871. + * the same value here.
  1872. + */
  1873. + cred->ipc_signing_state = SMB_SIGNING_REQUIRED;
  1874. +
  1875. return cred;
  1876. }
  1877. @@ -930,6 +936,12 @@ _PUBLIC_ void cli_credentials_set_conf(struct cli_credentials *cred,
  1878. cred->signing_state = lpcfg_client_signing(lp_ctx);
  1879. cred->signing_state_obtained = CRED_SMB_CONF;
  1880. }
  1881. +
  1882. + if (cred->ipc_signing_state_obtained <= CRED_SMB_CONF) {
  1883. + /* Will be set to required for invalid smb.conf values */
  1884. + cred->ipc_signing_state = lpcfg_client_ipc_signing(lp_ctx);
  1885. + cred->ipc_signing_state_obtained = CRED_SMB_CONF;
  1886. + }
  1887. }
  1888. /**
  1889. @@ -1350,6 +1362,45 @@ cli_credentials_get_smb_signing(struct cli_credentials *creds)
  1890. return creds->signing_state;
  1891. }
  1892. +/**
  1893. + * @brief Set the SMB IPC signing state to request for a SMB connection.
  1894. + *
  1895. + * @param[in] creds The credentials structure to update.
  1896. + *
  1897. + * @param[in] signing_state The signing state to set.
  1898. + *
  1899. + * @param obtained This way the described signing state was specified.
  1900. + *
  1901. + * @return true if we could set the signing state, false otherwise.
  1902. + */
  1903. +_PUBLIC_ bool
  1904. +cli_credentials_set_smb_ipc_signing(struct cli_credentials *creds,
  1905. + enum smb_signing_setting ipc_signing_state,
  1906. + enum credentials_obtained obtained)
  1907. +{
  1908. + if (obtained >= creds->ipc_signing_state_obtained) {
  1909. + creds->ipc_signing_state_obtained = obtained;
  1910. + creds->ipc_signing_state = ipc_signing_state;
  1911. + return true;
  1912. + }
  1913. +
  1914. + return false;
  1915. +}
  1916. +
  1917. +/**
  1918. + * @brief Obtain the SMB IPC signing state from a credentials structure.
  1919. + *
  1920. + * @param[in] creds The credential structure to obtain the SMB IPC signing
  1921. + * state from.
  1922. + *
  1923. + * @return The SMB singing state.
  1924. + */
  1925. +_PUBLIC_ enum smb_signing_setting
  1926. +cli_credentials_get_smb_ipc_signing(struct cli_credentials *creds)
  1927. +{
  1928. + return creds->ipc_signing_state;
  1929. +}
  1930. +
  1931. /**
  1932. * Encrypt a data blob using the session key and the negotiated encryption
  1933. * algorithm
  1934. diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
  1935. index 422391ad585..25bec916278 100644
  1936. --- a/auth/credentials/credentials.h
  1937. +++ b/auth/credentials/credentials.h
  1938. @@ -297,6 +297,12 @@ bool cli_credentials_set_smb_signing(struct cli_credentials *cred,
  1939. enum smb_signing_setting
  1940. cli_credentials_get_smb_signing(struct cli_credentials *cred);
  1941. +bool cli_credentials_set_smb_ipc_signing(struct cli_credentials *cred,
  1942. + enum smb_signing_setting ipc_signing_state,
  1943. + enum credentials_obtained obtained);
  1944. +enum smb_signing_setting
  1945. +cli_credentials_get_smb_ipc_signing(struct cli_credentials *cred);
  1946. +
  1947. /**
  1948. * Return attached NETLOGON credentials
  1949. */
  1950. diff --git a/auth/credentials/credentials_internal.h b/auth/credentials/credentials_internal.h
  1951. index 9cde0000b5f..54e8271471f 100644
  1952. --- a/auth/credentials/credentials_internal.h
  1953. +++ b/auth/credentials/credentials_internal.h
  1954. @@ -38,6 +38,7 @@ struct cli_credentials {
  1955. enum credentials_obtained keytab_obtained;
  1956. enum credentials_obtained server_gss_creds_obtained;
  1957. enum credentials_obtained signing_state_obtained;
  1958. + enum credentials_obtained ipc_signing_state_obtained;
  1959. /* Threshold values (essentially a MAX() over a number of the
  1960. * above) for the ccache and GSS credentials, to ensure we
  1961. @@ -121,6 +122,8 @@ struct cli_credentials {
  1962. bool password_will_be_nt_hash;
  1963. enum smb_signing_setting signing_state;
  1964. +
  1965. + enum smb_signing_setting ipc_signing_state;
  1966. };
  1967. #endif /* __CREDENTIALS_INTERNAL_H__ */
  1968. --
  1969. 2.29.2
  1970. From 32209d254bb7bd3bd6ad3af14f219cee306a19a3 Mon Sep 17 00:00:00 2001
  1971. From: Andreas Schneider <asn@samba.org>
  1972. Date: Wed, 3 Jun 2020 12:32:46 +0200
  1973. Subject: [PATCH 016/104] auth:creds: Add python bindings for
  1974. (get|set)_smb_ipc_signing
  1975. Signed-off-by: Andreas Schneider <asn@samba.org>
  1976. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  1977. ---
  1978. auth/credentials/pycredentials.c | 56 +++++++++++++++++++++++++++++++
  1979. python/samba/tests/credentials.py | 6 ++++
  1980. 2 files changed, 62 insertions(+)
  1981. diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
  1982. index 846c418419f..1a83c506088 100644
  1983. --- a/auth/credentials/pycredentials.c
  1984. +++ b/auth/credentials/pycredentials.c
  1985. @@ -976,6 +976,52 @@ static PyObject *py_creds_set_smb_signing(PyObject *self, PyObject *args)
  1986. Py_RETURN_NONE;
  1987. }
  1988. +static PyObject *py_creds_get_smb_ipc_signing(PyObject *self, PyObject *unused)
  1989. +{
  1990. + enum smb_signing_setting signing_state;
  1991. + struct cli_credentials *creds = NULL;
  1992. +
  1993. + creds = PyCredentials_AsCliCredentials(self);
  1994. + if (creds == NULL) {
  1995. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  1996. + return NULL;
  1997. + }
  1998. +
  1999. + signing_state = cli_credentials_get_smb_ipc_signing(creds);
  2000. + return PyLong_FromLong(signing_state);
  2001. +}
  2002. +
  2003. +static PyObject *py_creds_set_smb_ipc_signing(PyObject *self, PyObject *args)
  2004. +{
  2005. + enum smb_signing_setting signing_state;
  2006. + struct cli_credentials *creds = NULL;
  2007. + enum credentials_obtained obt = CRED_SPECIFIED;
  2008. +
  2009. + creds = PyCredentials_AsCliCredentials(self);
  2010. + if (creds == NULL) {
  2011. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  2012. + return NULL;
  2013. + }
  2014. + if (!PyArg_ParseTuple(args, "i|i", &signing_state, &obt)) {
  2015. + return NULL;
  2016. + }
  2017. +
  2018. + switch (signing_state) {
  2019. + case SMB_SIGNING_DEFAULT:
  2020. + case SMB_SIGNING_OFF:
  2021. + case SMB_SIGNING_IF_REQUIRED:
  2022. + case SMB_SIGNING_DESIRED:
  2023. + case SMB_SIGNING_REQUIRED:
  2024. + break;
  2025. + default:
  2026. + PyErr_Format(PyExc_TypeError, "Invalid signing state value");
  2027. + return NULL;
  2028. + }
  2029. +
  2030. + cli_credentials_set_smb_ipc_signing(creds, signing_state, obt);
  2031. + Py_RETURN_NONE;
  2032. +}
  2033. +
  2034. static PyMethodDef py_creds_methods[] = {
  2035. {
  2036. .ml_name = "get_username",
  2037. @@ -1266,6 +1312,16 @@ static PyMethodDef py_creds_methods[] = {
  2038. .ml_meth = py_creds_set_smb_signing,
  2039. .ml_flags = METH_VARARGS,
  2040. },
  2041. + {
  2042. + .ml_name = "get_smb_ipc_signing",
  2043. + .ml_meth = py_creds_get_smb_ipc_signing,
  2044. + .ml_flags = METH_NOARGS,
  2045. + },
  2046. + {
  2047. + .ml_name = "set_smb_ipc_signing",
  2048. + .ml_meth = py_creds_set_smb_ipc_signing,
  2049. + .ml_flags = METH_VARARGS,
  2050. + },
  2051. { .ml_name = NULL }
  2052. };
  2053. diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
  2054. index e5f8122fa21..8edf13ce6ff 100644
  2055. --- a/python/samba/tests/credentials.py
  2056. +++ b/python/samba/tests/credentials.py
  2057. @@ -462,3 +462,9 @@ class CredentialsTests(samba.tests.TestCaseInTempDir):
  2058. self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_DEFAULT)
  2059. creds.set_smb_signing(credentials.SMB_SIGNING_REQUIRED)
  2060. self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_REQUIRED)
  2061. +
  2062. + def test_smb_ipc_signing(self):
  2063. + creds = credentials.Credentials()
  2064. + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_REQUIRED)
  2065. + creds.set_smb_ipc_signing(credentials.SMB_SIGNING_OFF)
  2066. + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF)
  2067. --
  2068. 2.29.2
  2069. From d0a1bf1a75426c1d334349a6a4f8e44c80c1915b Mon Sep 17 00:00:00 2001
  2070. From: Andreas Schneider <asn@samba.org>
  2071. Date: Thu, 28 May 2020 16:10:52 +0200
  2072. Subject: [PATCH 017/104] auth:creds: Add
  2073. cli_credentials_(get|set)_smb_encryption()
  2074. Signed-off-by: Andreas Schneider <asn@samba.org>
  2075. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2076. ---
  2077. auth/credentials/credentials.c | 45 +++++++++++++++++++++++++
  2078. auth/credentials/credentials.h | 7 ++++
  2079. auth/credentials/credentials_internal.h | 3 ++
  2080. 3 files changed, 55 insertions(+)
  2081. diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
  2082. index dc5d51f1424..9168b92d3ec 100644
  2083. --- a/auth/credentials/credentials.c
  2084. +++ b/auth/credentials/credentials.c
  2085. @@ -51,6 +51,7 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
  2086. * the same value here.
  2087. */
  2088. cred->ipc_signing_state = SMB_SIGNING_REQUIRED;
  2089. + cred->encryption_state = SMB_ENCRYPTION_DEFAULT;
  2090. return cred;
  2091. }
  2092. @@ -942,6 +943,12 @@ _PUBLIC_ void cli_credentials_set_conf(struct cli_credentials *cred,
  2093. cred->ipc_signing_state = lpcfg_client_ipc_signing(lp_ctx);
  2094. cred->ipc_signing_state_obtained = CRED_SMB_CONF;
  2095. }
  2096. +
  2097. + if (cred->encryption_state_obtained <= CRED_SMB_CONF) {
  2098. + /* Will be set to default for invalid smb.conf values */
  2099. + cred->encryption_state = lpcfg_client_smb_encrypt(lp_ctx);
  2100. + cred->encryption_state_obtained = CRED_SMB_CONF;
  2101. + }
  2102. }
  2103. /**
  2104. @@ -1401,6 +1408,44 @@ cli_credentials_get_smb_ipc_signing(struct cli_credentials *creds)
  2105. return creds->ipc_signing_state;
  2106. }
  2107. +/**
  2108. + * @brief Set the SMB encryption state to request for a SMB connection.
  2109. + *
  2110. + * @param[in] creds The credentials structure to update.
  2111. + *
  2112. + * @param[in] encryption_state The encryption state to set.
  2113. + *
  2114. + * @param obtained This way the described encryption state was specified.
  2115. + *
  2116. + * @return true if we could set the encryption state, false otherwise.
  2117. + */
  2118. +_PUBLIC_ bool cli_credentials_set_smb_encryption(struct cli_credentials *creds,
  2119. + enum smb_encryption_setting encryption_state,
  2120. + enum credentials_obtained obtained)
  2121. +{
  2122. + if (obtained >= creds->encryption_state_obtained) {
  2123. + creds->encryption_state_obtained = obtained;
  2124. + creds->encryption_state = encryption_state;
  2125. + return true;
  2126. + }
  2127. +
  2128. + return false;
  2129. +}
  2130. +
  2131. +/**
  2132. + * @brief Obtain the SMB encryption state from a credentials structure.
  2133. + *
  2134. + * @param[in] creds The credential structure to obtain the SMB encryption state
  2135. + * from.
  2136. + *
  2137. + * @return The SMB singing state.
  2138. + */
  2139. +_PUBLIC_ enum smb_encryption_setting
  2140. +cli_credentials_get_smb_encryption(struct cli_credentials *creds)
  2141. +{
  2142. + return creds->encryption_state;
  2143. +}
  2144. +
  2145. /**
  2146. * Encrypt a data blob using the session key and the negotiated encryption
  2147. * algorithm
  2148. diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
  2149. index 25bec916278..7d0cf53194b 100644
  2150. --- a/auth/credentials/credentials.h
  2151. +++ b/auth/credentials/credentials.h
  2152. @@ -39,6 +39,7 @@ struct smb_krb5_context;
  2153. struct keytab_container;
  2154. struct db_context;
  2155. enum smb_signing_setting;
  2156. +enum smb_encryption_setting;
  2157. /* In order of priority */
  2158. enum credentials_obtained {
  2159. @@ -303,6 +304,12 @@ bool cli_credentials_set_smb_ipc_signing(struct cli_credentials *cred,
  2160. enum smb_signing_setting
  2161. cli_credentials_get_smb_ipc_signing(struct cli_credentials *cred);
  2162. +bool cli_credentials_set_smb_encryption(struct cli_credentials *cred,
  2163. + enum smb_encryption_setting encryption_state,
  2164. + enum credentials_obtained obtained);
  2165. +enum smb_encryption_setting
  2166. +cli_credentials_get_smb_encryption(struct cli_credentials *cred);
  2167. +
  2168. /**
  2169. * Return attached NETLOGON credentials
  2170. */
  2171. diff --git a/auth/credentials/credentials_internal.h b/auth/credentials/credentials_internal.h
  2172. index 54e8271471f..3b86b742448 100644
  2173. --- a/auth/credentials/credentials_internal.h
  2174. +++ b/auth/credentials/credentials_internal.h
  2175. @@ -39,6 +39,7 @@ struct cli_credentials {
  2176. enum credentials_obtained server_gss_creds_obtained;
  2177. enum credentials_obtained signing_state_obtained;
  2178. enum credentials_obtained ipc_signing_state_obtained;
  2179. + enum credentials_obtained encryption_state_obtained;
  2180. /* Threshold values (essentially a MAX() over a number of the
  2181. * above) for the ccache and GSS credentials, to ensure we
  2182. @@ -124,6 +125,8 @@ struct cli_credentials {
  2183. enum smb_signing_setting signing_state;
  2184. enum smb_signing_setting ipc_signing_state;
  2185. +
  2186. + enum smb_encryption_setting encryption_state;
  2187. };
  2188. #endif /* __CREDENTIALS_INTERNAL_H__ */
  2189. --
  2190. 2.29.2
  2191. From 36ab2aa54102aa9cce92ac8ebf250db4d460324e Mon Sep 17 00:00:00 2001
  2192. From: Andreas Schneider <asn@samba.org>
  2193. Date: Wed, 3 Jun 2020 12:38:30 +0200
  2194. Subject: [PATCH 018/104] auth:creds: Add python bindings for
  2195. (get|set)_smb_encryption
  2196. Signed-off-by: Andreas Schneider <asn@samba.org>
  2197. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2198. ---
  2199. auth/credentials/pycredentials.c | 62 +++++++++++++++++++++++++++++++
  2200. python/samba/tests/credentials.py | 6 +++
  2201. 2 files changed, 68 insertions(+)
  2202. diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
  2203. index 1a83c506088..628aae6500b 100644
  2204. --- a/auth/credentials/pycredentials.c
  2205. +++ b/auth/credentials/pycredentials.c
  2206. @@ -1022,6 +1022,52 @@ static PyObject *py_creds_set_smb_ipc_signing(PyObject *self, PyObject *args)
  2207. Py_RETURN_NONE;
  2208. }
  2209. +static PyObject *py_creds_get_smb_encryption(PyObject *self, PyObject *unused)
  2210. +{
  2211. + enum smb_encryption_setting encryption_state;
  2212. + struct cli_credentials *creds = NULL;
  2213. +
  2214. + creds = PyCredentials_AsCliCredentials(self);
  2215. + if (creds == NULL) {
  2216. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  2217. + return NULL;
  2218. + }
  2219. +
  2220. + encryption_state = cli_credentials_get_smb_encryption(creds);
  2221. + return PyLong_FromLong(encryption_state);
  2222. +}
  2223. +
  2224. +static PyObject *py_creds_set_smb_encryption(PyObject *self, PyObject *args)
  2225. +{
  2226. + enum smb_encryption_setting encryption_state;
  2227. + struct cli_credentials *creds = NULL;
  2228. + enum credentials_obtained obt = CRED_SPECIFIED;
  2229. +
  2230. + creds = PyCredentials_AsCliCredentials(self);
  2231. + if (creds == NULL) {
  2232. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  2233. + return NULL;
  2234. + }
  2235. + if (!PyArg_ParseTuple(args, "i|i", &encryption_state, &obt)) {
  2236. + return NULL;
  2237. + }
  2238. +
  2239. + switch (encryption_state) {
  2240. + case SMB_ENCRYPTION_DEFAULT:
  2241. + case SMB_ENCRYPTION_OFF:
  2242. + case SMB_ENCRYPTION_IF_REQUIRED:
  2243. + case SMB_ENCRYPTION_DESIRED:
  2244. + case SMB_ENCRYPTION_REQUIRED:
  2245. + break;
  2246. + default:
  2247. + PyErr_Format(PyExc_TypeError, "Invalid encryption state value");
  2248. + return NULL;
  2249. + }
  2250. +
  2251. + cli_credentials_set_smb_encryption(creds, encryption_state, obt);
  2252. + Py_RETURN_NONE;
  2253. +}
  2254. +
  2255. static PyMethodDef py_creds_methods[] = {
  2256. {
  2257. .ml_name = "get_username",
  2258. @@ -1322,6 +1368,16 @@ static PyMethodDef py_creds_methods[] = {
  2259. .ml_meth = py_creds_set_smb_ipc_signing,
  2260. .ml_flags = METH_VARARGS,
  2261. },
  2262. + {
  2263. + .ml_name = "get_smb_encryption",
  2264. + .ml_meth = py_creds_get_smb_encryption,
  2265. + .ml_flags = METH_NOARGS,
  2266. + },
  2267. + {
  2268. + .ml_name = "set_smb_encryption",
  2269. + .ml_meth = py_creds_set_smb_encryption,
  2270. + .ml_flags = METH_VARARGS,
  2271. + },
  2272. { .ml_name = NULL }
  2273. };
  2274. @@ -1414,6 +1470,12 @@ MODULE_INIT_FUNC(credentials)
  2275. PyModule_AddObject(m, "SMB_SIGNING_DESIRED", PyLong_FromLong(SMB_SIGNING_DESIRED));
  2276. PyModule_AddObject(m, "SMB_SIGNING_REQUIRED", PyLong_FromLong(SMB_SIGNING_REQUIRED));
  2277. + PyModule_AddObject(m, "SMB_ENCRYPTION_DEFAULT", PyLong_FromLong(SMB_ENCRYPTION_DEFAULT));
  2278. + PyModule_AddObject(m, "SMB_ENCRYPTION_OFF", PyLong_FromLong(SMB_ENCRYPTION_OFF));
  2279. + PyModule_AddObject(m, "SMB_ENCRYPTION_IF_REQUIRED", PyLong_FromLong(SMB_ENCRYPTION_IF_REQUIRED));
  2280. + PyModule_AddObject(m, "SMB_ENCRYPTION_DESIRED", PyLong_FromLong(SMB_ENCRYPTION_DESIRED));
  2281. + PyModule_AddObject(m, "SMB_ENCRYPTION_REQUIRED", PyLong_FromLong(SMB_ENCRYPTION_REQUIRED));
  2282. +
  2283. Py_INCREF(&PyCredentials);
  2284. PyModule_AddObject(m, "Credentials", (PyObject *)&PyCredentials);
  2285. Py_INCREF(&PyCredentialCacheContainer);
  2286. diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
  2287. index 8edf13ce6ff..e0a6248d37a 100644
  2288. --- a/python/samba/tests/credentials.py
  2289. +++ b/python/samba/tests/credentials.py
  2290. @@ -468,3 +468,9 @@ class CredentialsTests(samba.tests.TestCaseInTempDir):
  2291. self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_REQUIRED)
  2292. creds.set_smb_ipc_signing(credentials.SMB_SIGNING_OFF)
  2293. self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF)
  2294. +
  2295. + def test_smb_encryption(self):
  2296. + creds = credentials.Credentials()
  2297. + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_DEFAULT)
  2298. + creds.set_smb_encryption(credentials.SMB_ENCRYPTION_REQUIRED)
  2299. + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_REQUIRED)
  2300. --
  2301. 2.29.2
  2302. From f866d9e80964e16307a8376ed448d0ca3a987538 Mon Sep 17 00:00:00 2001
  2303. From: Andreas Schneider <asn@samba.org>
  2304. Date: Thu, 4 Jun 2020 11:19:53 +0200
  2305. Subject: [PATCH 019/104] auth:creds: Add python bindings for
  2306. cli_credentials_set_conf()
  2307. Signed-off-by: Andreas Schneider <asn@samba.org>
  2308. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2309. ---
  2310. auth/credentials/pycredentials.c | 41 +++++++++++++++++++++++++++++++
  2311. python/samba/tests/credentials.py | 33 +++++++++++++++++++++++++
  2312. 2 files changed, 74 insertions(+)
  2313. diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
  2314. index 628aae6500b..17c90573f09 100644
  2315. --- a/auth/credentials/pycredentials.c
  2316. +++ b/auth/credentials/pycredentials.c
  2317. @@ -621,6 +621,42 @@ static PyObject *py_creds_set_forced_sasl_mech(PyObject *self, PyObject *args)
  2318. Py_RETURN_NONE;
  2319. }
  2320. +static PyObject *py_creds_set_conf(PyObject *self, PyObject *args)
  2321. +{
  2322. + PyObject *py_lp_ctx = Py_None;
  2323. + struct loadparm_context *lp_ctx;
  2324. + TALLOC_CTX *mem_ctx;
  2325. + struct cli_credentials *creds;
  2326. +
  2327. + creds = PyCredentials_AsCliCredentials(self);
  2328. + if (creds == NULL) {
  2329. + PyErr_Format(PyExc_TypeError, "Credentials expected");
  2330. + return NULL;
  2331. + }
  2332. +
  2333. + if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx)) {
  2334. + return NULL;
  2335. + }
  2336. +
  2337. + mem_ctx = talloc_new(NULL);
  2338. + if (mem_ctx == NULL) {
  2339. + PyErr_NoMemory();
  2340. + return NULL;
  2341. + }
  2342. +
  2343. + lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
  2344. + if (lp_ctx == NULL) {
  2345. + talloc_free(mem_ctx);
  2346. + return NULL;
  2347. + }
  2348. +
  2349. + cli_credentials_set_conf(creds, lp_ctx);
  2350. +
  2351. + talloc_free(mem_ctx);
  2352. +
  2353. + Py_RETURN_NONE;
  2354. +}
  2355. +
  2356. static PyObject *py_creds_guess(PyObject *self, PyObject *args)
  2357. {
  2358. PyObject *py_lp_ctx = Py_None;
  2359. @@ -1279,6 +1315,11 @@ static PyMethodDef py_creds_methods[] = {
  2360. .ml_meth = py_creds_set_krb_forwardable,
  2361. .ml_flags = METH_VARARGS,
  2362. },
  2363. + {
  2364. + .ml_name = "set_conf",
  2365. + .ml_meth = py_creds_set_conf,
  2366. + .ml_flags = METH_VARARGS,
  2367. + },
  2368. {
  2369. .ml_name = "guess",
  2370. .ml_meth = py_creds_guess,
  2371. diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py
  2372. index e0a6248d37a..6187bded0b6 100644
  2373. --- a/python/samba/tests/credentials.py
  2374. +++ b/python/samba/tests/credentials.py
  2375. @@ -463,14 +463,47 @@ class CredentialsTests(samba.tests.TestCaseInTempDir):
  2376. creds.set_smb_signing(credentials.SMB_SIGNING_REQUIRED)
  2377. self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_REQUIRED)
  2378. + def test_smb_signing_set_conf(self):
  2379. + lp = samba.tests.env_loadparm()
  2380. +
  2381. + creds = credentials.Credentials()
  2382. + creds.set_conf(lp)
  2383. + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_DEFAULT)
  2384. + creds.set_smb_signing(credentials.SMB_SIGNING_OFF)
  2385. + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_OFF)
  2386. + creds.set_conf(lp)
  2387. + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_OFF)
  2388. +
  2389. def test_smb_ipc_signing(self):
  2390. creds = credentials.Credentials()
  2391. self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_REQUIRED)
  2392. creds.set_smb_ipc_signing(credentials.SMB_SIGNING_OFF)
  2393. self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF)
  2394. + def test_smb_ipc_signing_set_conf(self):
  2395. + lp = samba.tests.env_loadparm()
  2396. +
  2397. + creds = credentials.Credentials()
  2398. + creds.set_conf(lp)
  2399. + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_REQUIRED)
  2400. + creds.set_smb_ipc_signing(credentials.SMB_SIGNING_OFF)
  2401. + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF)
  2402. + creds.set_conf(lp)
  2403. + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF)
  2404. +
  2405. def test_smb_encryption(self):
  2406. creds = credentials.Credentials()
  2407. self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_DEFAULT)
  2408. creds.set_smb_encryption(credentials.SMB_ENCRYPTION_REQUIRED)
  2409. self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_REQUIRED)
  2410. +
  2411. + def test_smb_encryption_set_conf(self):
  2412. + lp = samba.tests.env_loadparm()
  2413. +
  2414. + creds = credentials.Credentials()
  2415. + creds.set_conf(lp)
  2416. + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_DEFAULT)
  2417. + creds.set_smb_encryption(credentials.SMB_ENCRYPTION_OFF)
  2418. + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_OFF)
  2419. + creds.set_conf(lp)
  2420. + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_OFF)
  2421. --
  2422. 2.29.2
  2423. From 3f55ee05f024eacdd43fbbfb941703f8555df7c7 Mon Sep 17 00:00:00 2001
  2424. From: Andreas Schneider <asn@samba.org>
  2425. Date: Thu, 23 Jul 2020 08:14:23 +0200
  2426. Subject: [PATCH 020/104] auth:creds: Bump library version
  2427. We added new functions so bump the version.
  2428. Signed-off-by: Andreas Schneider <asn@samba.org>
  2429. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2430. ---
  2431. auth/credentials/wscript_build | 2 +-
  2432. 1 file changed, 1 insertion(+), 1 deletion(-)
  2433. diff --git a/auth/credentials/wscript_build b/auth/credentials/wscript_build
  2434. index 564a04fe8dd..1e3302e3e48 100644
  2435. --- a/auth/credentials/wscript_build
  2436. +++ b/auth/credentials/wscript_build
  2437. @@ -5,7 +5,7 @@ bld.SAMBA_LIBRARY('samba-credentials',
  2438. public_headers='credentials.h',
  2439. pc_files='samba-credentials.pc',
  2440. deps='LIBCRYPTO samba-errors events LIBCLI_AUTH samba-security CREDENTIALS_SECRETS CREDENTIALS_KRB5',
  2441. - vnum='0.0.1'
  2442. + vnum='0.1.0'
  2443. )
  2444. bld.SAMBA_SUBSYSTEM('CREDENTIALS_KRB5',
  2445. --
  2446. 2.29.2
  2447. From 492030e0e6179bdc0311e8d03b89b1cb01de1a3e Mon Sep 17 00:00:00 2001
  2448. From: Andreas Schneider <asn@samba.org>
  2449. Date: Wed, 27 May 2020 11:10:30 +0200
  2450. Subject: [PATCH 021/104] s3:lib: Use cli_credential_(get|set)_smb_signing()
  2451. Signed-off-by: Andreas Schneider <asn@samba.org>
  2452. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2453. ---
  2454. source3/lib/util_cmdline.c | 18 ++++++++++++------
  2455. 1 file changed, 12 insertions(+), 6 deletions(-)
  2456. diff --git a/source3/lib/util_cmdline.c b/source3/lib/util_cmdline.c
  2457. index bc1f1c3ed25..6038ec11515 100644
  2458. --- a/source3/lib/util_cmdline.c
  2459. +++ b/source3/lib/util_cmdline.c
  2460. @@ -40,7 +40,6 @@ struct user_auth_info {
  2461. struct loadparm_context *lp_ctx;
  2462. bool got_username;
  2463. bool got_pass;
  2464. - int signing_state;
  2465. bool smb_encrypt;
  2466. bool use_machine_account;
  2467. bool use_pw_nt_hash;
  2468. @@ -70,7 +69,6 @@ struct user_auth_info *user_auth_info_init(TALLOC_CTX *mem_ctx)
  2469. cli_credentials_set_conf(result->creds, result->lp_ctx);
  2470. - result->signing_state = SMB_SIGNING_DEFAULT;
  2471. return result;
  2472. }
  2473. @@ -241,15 +239,23 @@ void set_cmdline_auth_info_password(struct user_auth_info *auth_info,
  2474. bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info,
  2475. const char *arg)
  2476. {
  2477. - auth_info->signing_state = smb_signing_setting_translate(arg);
  2478. + enum smb_signing_setting signing_state =
  2479. + smb_signing_setting_translate(arg);
  2480. + bool ok;
  2481. - return true;
  2482. + ok = cli_credentials_set_smb_signing(auth_info->creds,
  2483. + signing_state,
  2484. + CRED_SPECIFIED);
  2485. +
  2486. + return ok;
  2487. }
  2488. void set_cmdline_auth_info_signing_state_raw(struct user_auth_info *auth_info,
  2489. int signing_state)
  2490. {
  2491. - auth_info->signing_state = signing_state;
  2492. + cli_credentials_set_smb_signing(auth_info->creds,
  2493. + signing_state,
  2494. + CRED_SPECIFIED);
  2495. }
  2496. int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
  2497. @@ -257,7 +263,7 @@ int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
  2498. if (auth_info->smb_encrypt) {
  2499. return SMB_SIGNING_REQUIRED;
  2500. }
  2501. - return auth_info->signing_state;
  2502. + return cli_credentials_get_smb_signing(auth_info->creds);
  2503. }
  2504. void set_cmdline_auth_info_use_ccache(struct user_auth_info *auth_info, bool b)
  2505. --
  2506. 2.29.2
  2507. From 6164c45feff5daf0e751526d1f7bd599c61b2a0e Mon Sep 17 00:00:00 2001
  2508. From: Andreas Schneider <asn@samba.org>
  2509. Date: Wed, 10 Jun 2020 12:45:34 +0200
  2510. Subject: [PATCH 022/104] s3:lib: Set smb encryption also via cli creds API
  2511. Signed-off-by: Andreas Schneider <asn@samba.org>
  2512. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2513. ---
  2514. source3/lib/util_cmdline.c | 3 +++
  2515. 1 file changed, 3 insertions(+)
  2516. diff --git a/source3/lib/util_cmdline.c b/source3/lib/util_cmdline.c
  2517. index 6038ec11515..9c9e2f0ac0f 100644
  2518. --- a/source3/lib/util_cmdline.c
  2519. +++ b/source3/lib/util_cmdline.c
  2520. @@ -377,6 +377,9 @@ void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info)
  2521. /* This should only be used by lib/popt_common.c JRA */
  2522. void set_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info)
  2523. {
  2524. + cli_credentials_set_smb_encryption(auth_info->creds,
  2525. + SMB_ENCRYPTION_REQUIRED,
  2526. + CRED_SPECIFIED);
  2527. auth_info->smb_encrypt = true;
  2528. }
  2529. --
  2530. 2.29.2
  2531. From ddb7926bba603afbc1a588d1b6da9f9a625881ac Mon Sep 17 00:00:00 2001
  2532. From: Andreas Schneider <asn@samba.org>
  2533. Date: Thu, 13 Aug 2020 10:40:23 +0200
  2534. Subject: [PATCH 023/104] python: Remove unused sign argument from
  2535. smb_connection()
  2536. Signed-off-by: Andreas Schneider <asn@samba.org>
  2537. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2538. ---
  2539. python/samba/netcmd/gpo.py | 9 ++++-----
  2540. 1 file changed, 4 insertions(+), 5 deletions(-)
  2541. diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py
  2542. index 1e2c2918ebe..ad60cda0690 100644
  2543. --- a/python/samba/netcmd/gpo.py
  2544. +++ b/python/samba/netcmd/gpo.py
  2545. @@ -382,13 +382,13 @@ def create_directory_hier(conn, remotedir):
  2546. if not conn.chkpath(path):
  2547. conn.mkdir(path)
  2548. -def smb_connection(dc_hostname, service, lp, creds, sign=False):
  2549. +def smb_connection(dc_hostname, service, lp, creds):
  2550. # SMB connect to DC
  2551. try:
  2552. # the SMB bindings rely on having a s3 loadparm
  2553. s3_lp = s3param.get_context()
  2554. s3_lp.load(lp.configfile)
  2555. - conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds, sign=sign)
  2556. + conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds, sign=True)
  2557. except Exception:
  2558. raise CommandError("Error connecting to '%s' using SMB" % dc_hostname)
  2559. return conn
  2560. @@ -998,7 +998,7 @@ class cmd_fetch(GPOCommand):
  2561. # SMB connect to DC
  2562. conn = smb_connection(dc_hostname, service, lp=self.lp,
  2563. - creds=self.creds, sign=True)
  2564. + creds=self.creds)
  2565. # Copy GPT
  2566. tmpdir, gpodir = self.construct_tmpdir(tmpdir, gpo)
  2567. @@ -1629,8 +1629,7 @@ class cmd_admxload(Command):
  2568. conn = smb_connection(dc_hostname,
  2569. 'sysvol',
  2570. lp=self.lp,
  2571. - creds=self.creds,
  2572. - sign=True)
  2573. + creds=self.creds)
  2574. smb_dir = '\\'.join([self.lp.get('realm').lower(),
  2575. 'Policies', 'PolicyDefinitions'])
  2576. --
  2577. 2.29.2
  2578. From 8683eacfb9c053115a84be025bbd64471c55d1c8 Mon Sep 17 00:00:00 2001
  2579. From: Andreas Schneider <asn@samba.org>
  2580. Date: Wed, 3 Jun 2020 14:02:37 +0200
  2581. Subject: [PATCH 024/104] python: Set smb signing via the creds API
  2582. Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
  2583. Signed-off-by: Andreas Schneider <asn@samba.org>
  2584. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2585. ---
  2586. python/samba/gpclass.py | 7 +++++++
  2587. python/samba/netcmd/domain_backup.py | 10 +++++++++-
  2588. python/samba/netcmd/gpo.py | 6 ++++++
  2589. 3 files changed, 22 insertions(+), 1 deletion(-)
  2590. diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py
  2591. index cc574e12a42..1781a55a618 100644
  2592. --- a/python/samba/gpclass.py
  2593. +++ b/python/samba/gpclass.py
  2594. @@ -38,6 +38,7 @@ from tempfile import NamedTemporaryFile
  2595. from samba.dcerpc import preg
  2596. from samba.dcerpc import misc
  2597. from samba.ndr import ndr_pack, ndr_unpack
  2598. +from samba.credentials import SMB_SIGNING_REQUIRED
  2599. try:
  2600. from enum import Enum
  2601. @@ -421,7 +422,13 @@ def check_refresh_gpo_list(dc_hostname, lp, creds, gpos):
  2602. # the SMB bindings rely on having a s3 loadparm
  2603. s3_lp = s3param.get_context()
  2604. s3_lp.load(lp.configfile)
  2605. +
  2606. + # Force signing for the connection
  2607. + saved_signing_state = creds.get_smb_signing()
  2608. + creds.set_smb_signing(SMB_SIGNING_REQUIRED)
  2609. conn = libsmb.Conn(dc_hostname, 'sysvol', lp=s3_lp, creds=creds, sign=True)
  2610. + # Reset signing state
  2611. + creds.set_smb_signing(saved_signing_state)
  2612. cache_path = lp.cache_path('gpo_cache')
  2613. for gpo in gpos:
  2614. if not gpo.file_sys_path:
  2615. diff --git a/python/samba/netcmd/domain_backup.py b/python/samba/netcmd/domain_backup.py
  2616. index a3dc7fb454f..a9e0ba5bc67 100644
  2617. --- a/python/samba/netcmd/domain_backup.py
  2618. +++ b/python/samba/netcmd/domain_backup.py
  2619. @@ -54,6 +54,7 @@ from subprocess import CalledProcessError
  2620. from samba import sites
  2621. from samba.dsdb import _dsdb_load_udv_v2
  2622. from samba.ndr import ndr_pack
  2623. +from samba.credentials import SMB_SIGNING_REQUIRED
  2624. # work out a SID (based on a free RID) to use when the domain gets restored.
  2625. @@ -115,7 +116,14 @@ def smb_sysvol_conn(server, lp, creds):
  2626. # the SMB bindings rely on having a s3 loadparm
  2627. s3_lp = s3param.get_context()
  2628. s3_lp.load(lp.configfile)
  2629. - return libsmb.Conn(server, "sysvol", lp=s3_lp, creds=creds, sign=True)
  2630. +
  2631. + # Force signing for the connection
  2632. + saved_signing_state = creds.get_smb_signing()
  2633. + creds.set_smb_signing(SMB_SIGNING_REQUIRED)
  2634. + conn = libsmb.Conn(server, "sysvol", lp=s3_lp, creds=creds, sign=True)
  2635. + # Reset signing state
  2636. + creds.set_smb_signing(saved_signing_state)
  2637. + return conn
  2638. def get_timestamp():
  2639. diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py
  2640. index ad60cda0690..0f2f6520fc3 100644
  2641. --- a/python/samba/netcmd/gpo.py
  2642. +++ b/python/samba/netcmd/gpo.py
  2643. @@ -62,6 +62,7 @@ from samba.gp_parse.gp_csv import GPAuditCsvParser
  2644. from samba.gp_parse.gp_inf import GptTmplInfParser
  2645. from samba.gp_parse.gp_aas import GPAasParser
  2646. from samba import param
  2647. +from samba.credentials import SMB_SIGNING_REQUIRED
  2648. def attr_default(msg, attrname, default):
  2649. @@ -384,6 +385,9 @@ def create_directory_hier(conn, remotedir):
  2650. def smb_connection(dc_hostname, service, lp, creds):
  2651. # SMB connect to DC
  2652. + # Force signing for the smb connection
  2653. + saved_signing_state = creds.get_smb_signing()
  2654. + creds.set_smb_signing(SMB_SIGNING_REQUIRED)
  2655. try:
  2656. # the SMB bindings rely on having a s3 loadparm
  2657. s3_lp = s3param.get_context()
  2658. @@ -391,6 +395,8 @@ def smb_connection(dc_hostname, service, lp, creds):
  2659. conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds, sign=True)
  2660. except Exception:
  2661. raise CommandError("Error connecting to '%s' using SMB" % dc_hostname)
  2662. + # Reset signing state
  2663. + creds.set_smb_signing(saved_signing_state)
  2664. return conn
  2665. --
  2666. 2.29.2
  2667. From 86212ac5fb8d5f0710f23dde362dc35d908e3047 Mon Sep 17 00:00:00 2001
  2668. From: Andreas Schneider <asn@samba.org>
  2669. Date: Thu, 28 May 2020 17:22:12 +0200
  2670. Subject: [PATCH 025/104] s3:libsmb: Introduce CLI_FULL_CONNECTION_IPC
  2671. Signed-off-by: Andreas Schneider <asn@samba.org>
  2672. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2673. ---
  2674. examples/winexe/winexe.c | 2 +-
  2675. source3/include/client.h | 1 +
  2676. source3/libnet/libnet_join.c | 6 +++---
  2677. source3/libsmb/cliconnect.c | 3 ++-
  2678. source3/rpc_server/spoolss/srv_spoolss_nt.c | 4 +++-
  2679. source3/rpcclient/cmd_spoolss.c | 2 +-
  2680. source3/rpcclient/rpcclient.c | 2 +-
  2681. source3/utils/mdfind.c | 2 +-
  2682. source3/utils/net_ads.c | 3 ++-
  2683. source3/utils/net_util.c | 9 +++++++--
  2684. source3/utils/netlookup.c | 4 +++-
  2685. 11 files changed, 25 insertions(+), 13 deletions(-)
  2686. diff --git a/examples/winexe/winexe.c b/examples/winexe/winexe.c
  2687. index fc6b15f8e52..bb9c27e2e6d 100644
  2688. --- a/examples/winexe/winexe.c
  2689. +++ b/examples/winexe/winexe.c
  2690. @@ -1919,7 +1919,7 @@ int main(int argc, const char *argv[])
  2691. "IPC$",
  2692. "?????",
  2693. options.credentials,
  2694. - 0,
  2695. + CLI_FULL_CONNECTION_IPC,
  2696. 0);
  2697. if (!NT_STATUS_IS_OK(status)) {
  2698. diff --git a/source3/include/client.h b/source3/include/client.h
  2699. index 6a3b1b02ff3..19a738900b7 100644
  2700. --- a/source3/include/client.h
  2701. +++ b/source3/include/client.h
  2702. @@ -121,5 +121,6 @@ struct file_info {
  2703. #define CLI_FULL_CONNECTION_FORCE_ASCII 0x0100
  2704. #define CLI_FULL_CONNECTION_FORCE_SMB1 0x0400
  2705. #define CLI_FULL_CONNECTION_DISABLE_SMB1 0x0800
  2706. +#define CLI_FULL_CONNECTION_IPC 0x1000
  2707. #endif /* _CLIENT_H */
  2708. diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
  2709. index 34938603606..392e3eff74f 100644
  2710. --- a/source3/libnet/libnet_join.c
  2711. +++ b/source3/libnet/libnet_join.c
  2712. @@ -1068,7 +1068,7 @@ static NTSTATUS libnet_join_connect_dc_ipc(const char *dc,
  2713. bool use_ccache = false;
  2714. bool pw_nt_hash = false;
  2715. struct cli_credentials *creds = NULL;
  2716. - int flags = 0;
  2717. + int flags = CLI_FULL_CONNECTION_IPC;
  2718. NTSTATUS status;
  2719. if (use_kerberos && pass) {
  2720. @@ -1684,7 +1684,7 @@ NTSTATUS libnet_join_ok(struct messaging_context *msg_ctx,
  2721. struct netlogon_creds_CredentialState *creds = NULL;
  2722. uint32_t netlogon_flags = 0;
  2723. NTSTATUS status;
  2724. - int flags = 0;
  2725. + int flags = CLI_FULL_CONNECTION_IPC;
  2726. if (!dc_name) {
  2727. TALLOC_FREE(frame);
  2728. @@ -1734,7 +1734,7 @@ NTSTATUS libnet_join_ok(struct messaging_context *msg_ctx,
  2729. NULL, 0,
  2730. "IPC$", "IPC",
  2731. anon_creds,
  2732. - 0,
  2733. + flags,
  2734. SMB_SIGNING_OFF);
  2735. }
  2736. diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
  2737. index 1fb1f0127b9..f20146378e3 100644
  2738. --- a/source3/libsmb/cliconnect.c
  2739. +++ b/source3/libsmb/cliconnect.c
  2740. @@ -2788,7 +2788,7 @@ static struct tevent_req *cli_start_connection_send(
  2741. }
  2742. state->ev = ev;
  2743. - if (signing_state == SMB_SIGNING_IPC_DEFAULT) {
  2744. + if (flags & CLI_FULL_CONNECTION_IPC) {
  2745. state->min_protocol = lp_client_ipc_min_protocol();
  2746. state->max_protocol = lp_client_ipc_max_protocol();
  2747. } else {
  2748. @@ -3673,6 +3673,7 @@ struct cli_state *get_ipc_connect(char *server,
  2749. uint32_t flags = CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK;
  2750. flags |= CLI_FULL_CONNECTION_FORCE_SMB1;
  2751. + flags |= CLI_FULL_CONNECTION_IPC;
  2752. nt_status = cli_full_connection_creds(&cli, NULL, server, server_ss, 0, "IPC$", "IPC",
  2753. get_cmdline_auth_info_creds(user_info),
  2754. diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
  2755. index 10c1b1d54f2..f578f1c4131 100644
  2756. --- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
  2757. +++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
  2758. @@ -2482,7 +2482,9 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct c
  2759. /* setup the connection */
  2760. ret = cli_full_connection_creds( pp_cli, lp_netbios_name(), remote_machine,
  2761. &rm_addr, 0, "IPC$", "IPC",
  2762. - anon_creds, 0, SMB_SIGNING_OFF);
  2763. + anon_creds,
  2764. + CLI_FULL_CONNECTION_IPC,
  2765. + SMB_SIGNING_OFF);
  2766. TALLOC_FREE(anon_creds);
  2767. if ( !NT_STATUS_IS_OK( ret ) ) {
  2768. DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
  2769. diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
  2770. index a7e0c673a65..7198a451ab7 100644
  2771. --- a/source3/rpcclient/cmd_spoolss.c
  2772. +++ b/source3/rpcclient/cmd_spoolss.c
  2773. @@ -3537,7 +3537,7 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
  2774. "IPC$", "IPC",
  2775. get_cmdline_auth_info_creds(
  2776. popt_get_cmdline_auth_info()),
  2777. - 0, /* flags */
  2778. + CLI_FULL_CONNECTION_IPC,
  2779. get_cmdline_auth_info_signing_state(
  2780. popt_get_cmdline_auth_info()));
  2781. diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
  2782. index 67a1066fc15..c86474d08f1 100644
  2783. --- a/source3/rpcclient/rpcclient.c
  2784. +++ b/source3/rpcclient/rpcclient.c
  2785. @@ -1019,7 +1019,7 @@ out_free:
  2786. static int opt_port = 0;
  2787. int result = 0;
  2788. TALLOC_CTX *frame = talloc_stackframe();
  2789. - uint32_t flags = 0;
  2790. + uint32_t flags = CLI_FULL_CONNECTION_IPC;
  2791. struct dcerpc_binding *binding = NULL;
  2792. enum dcerpc_transport_t transport;
  2793. uint32_t bflags = 0;
  2794. diff --git a/source3/utils/mdfind.c b/source3/utils/mdfind.c
  2795. index 2f952c29b4f..a3c879e75fb 100644
  2796. --- a/source3/utils/mdfind.c
  2797. +++ b/source3/utils/mdfind.c
  2798. @@ -70,7 +70,7 @@ int main(int argc, char **argv)
  2799. const char *mds_query = NULL;
  2800. struct cli_state *cli = NULL;
  2801. char *basepath = NULL;
  2802. - uint32_t flags = 0;
  2803. + uint32_t flags = CLI_FULL_CONNECTION_IPC;
  2804. int signing_state = SMB_SIGNING_IPC_DEFAULT;
  2805. uint64_t *cnids = NULL;
  2806. size_t ncnids;
  2807. diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
  2808. index e5db844c2f2..28ef6dc9974 100644
  2809. --- a/source3/utils/net_ads.c
  2810. +++ b/source3/utils/net_ads.c
  2811. @@ -2437,7 +2437,8 @@ static int net_ads_printer_publish(struct net_context *c, int argc, const char *
  2812. nt_status = cli_full_connection_creds(&cli, lp_netbios_name(), servername,
  2813. &server_ss, 0,
  2814. "IPC$", "IPC",
  2815. - creds, 0,
  2816. + creds,
  2817. + CLI_FULL_CONNECTION_IPC,
  2818. SMB_SIGNING_IPC_DEFAULT);
  2819. if (NT_STATUS_IS_ERR(nt_status)) {
  2820. diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
  2821. index c566ecc9000..d01b2d8c771 100644
  2822. --- a/source3/utils/net_util.c
  2823. +++ b/source3/utils/net_util.c
  2824. @@ -110,6 +110,7 @@ NTSTATUS connect_to_service(struct net_context *c,
  2825. NTSTATUS nt_status;
  2826. enum smb_signing_setting signing_setting = SMB_SIGNING_DEFAULT;
  2827. struct cli_credentials *creds = NULL;
  2828. + int flags = 0;
  2829. creds = net_context_creds(c, c);
  2830. if (creds == NULL) {
  2831. @@ -119,12 +120,14 @@ NTSTATUS connect_to_service(struct net_context *c,
  2832. if (strequal(service_type, "IPC")) {
  2833. signing_setting = SMB_SIGNING_IPC_DEFAULT;
  2834. + flags |= CLI_FULL_CONNECTION_IPC;
  2835. }
  2836. nt_status = cli_full_connection_creds(cli_ctx, NULL, server_name,
  2837. server_ss, c->opt_port,
  2838. service_name, service_type,
  2839. - creds, 0,
  2840. + creds,
  2841. + flags,
  2842. signing_setting);
  2843. if (!NT_STATUS_IS_OK(nt_status)) {
  2844. d_fprintf(stderr, _("Could not connect to server %s\n"),
  2845. @@ -195,7 +198,9 @@ NTSTATUS connect_to_ipc_anonymous(struct net_context *c,
  2846. nt_status = cli_full_connection_creds(cli_ctx, c->opt_requester_name,
  2847. server_name, server_ss, c->opt_port,
  2848. "IPC$", "IPC",
  2849. - anon_creds, 0, SMB_SIGNING_OFF);
  2850. + anon_creds,
  2851. + CLI_FULL_CONNECTION_IPC,
  2852. + SMB_SIGNING_OFF);
  2853. if (NT_STATUS_IS_OK(nt_status)) {
  2854. return nt_status;
  2855. diff --git a/source3/utils/netlookup.c b/source3/utils/netlookup.c
  2856. index 6cea2ee306c..2241beb331f 100644
  2857. --- a/source3/utils/netlookup.c
  2858. +++ b/source3/utils/netlookup.c
  2859. @@ -98,7 +98,9 @@ static struct con_struct *create_cs(struct net_context *c,
  2860. nt_status = cli_full_connection_creds(&cs->cli, lp_netbios_name(), lp_netbios_name(),
  2861. &loopback_ss, 0,
  2862. "IPC$", "IPC",
  2863. - anon_creds, 0, SMB_SIGNING_OFF);
  2864. + anon_creds,
  2865. + CLI_FULL_CONNECTION_IPC,
  2866. + SMB_SIGNING_OFF);
  2867. if (!NT_STATUS_IS_OK(nt_status)) {
  2868. DEBUG(2,("create_cs: Connect failed. Error was %s\n", nt_errstr(nt_status)));
  2869. --
  2870. 2.29.2
  2871. From 834dae6a34aaef7dccfb84821ec3fa7013b07d15 Mon Sep 17 00:00:00 2001
  2872. From: Andreas Schneider <asn@samba.org>
  2873. Date: Thu, 28 May 2020 17:29:25 +0200
  2874. Subject: [PATCH 026/104] s3:pylibsmb: Add ipc=True support for
  2875. CLI_FULL_CONNECTION_IPC
  2876. Signed-off-by: Andreas Schneider <asn@samba.org>
  2877. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2878. ---
  2879. source3/libsmb/pylibsmb.c | 13 +++++++++++--
  2880. 1 file changed, 11 insertions(+), 2 deletions(-)
  2881. diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
  2882. index 3fcc3424a57..3579a040830 100644
  2883. --- a/source3/libsmb/pylibsmb.c
  2884. +++ b/source3/libsmb/pylibsmb.c
  2885. @@ -445,6 +445,8 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  2886. int signing_state = SMB_SIGNING_DEFAULT;
  2887. PyObject *py_force_smb1 = Py_False;
  2888. bool force_smb1 = false;
  2889. + PyObject *py_ipc = Py_False;
  2890. + bool use_ipc = false;
  2891. struct tevent_req *req;
  2892. bool ret;
  2893. int flags = 0;
  2894. @@ -452,6 +454,7 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  2895. static const char *kwlist[] = {
  2896. "host", "share", "lp", "creds",
  2897. "multi_threaded", "sign", "force_smb1",
  2898. + "ipc",
  2899. NULL
  2900. };
  2901. @@ -462,12 +465,13 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  2902. }
  2903. ret = ParseTupleAndKeywords(
  2904. - args, kwds, "ssO|O!OOO", kwlist,
  2905. + args, kwds, "ssO|O!OOOO", kwlist,
  2906. &host, &share, &py_lp,
  2907. py_type_Credentials, &creds,
  2908. &py_multi_threaded,
  2909. &py_sign,
  2910. - &py_force_smb1);
  2911. + &py_force_smb1,
  2912. + &py_ipc);
  2913. Py_DECREF(py_type_Credentials);
  2914. @@ -493,6 +497,11 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  2915. flags = CLI_FULL_CONNECTION_FORCE_SMB1;
  2916. }
  2917. + use_ipc = PyObject_IsTrue(py_ipc);
  2918. + if (use_ipc) {
  2919. + flags |= CLI_FULL_CONNECTION_IPC;
  2920. + }
  2921. +
  2922. if (multi_threaded) {
  2923. #ifdef HAVE_PTHREAD
  2924. ret = py_cli_state_setup_mt_ev(self);
  2925. --
  2926. 2.29.2
  2927. From 072dfd83ee6513658e0ec818fb548f70648d6a41 Mon Sep 17 00:00:00 2001
  2928. From: Andreas Schneider <asn@samba.org>
  2929. Date: Fri, 24 Jul 2020 09:47:11 +0200
  2930. Subject: [PATCH 027/104] python:tests: Mark libsmb connection as an IPC
  2931. connection
  2932. Signed-off-by: Andreas Schneider <asn@samba.org>
  2933. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2934. ---
  2935. python/samba/tests/dcerpc/raw_testcase.py | 2 +-
  2936. 1 file changed, 1 insertion(+), 1 deletion(-)
  2937. diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py
  2938. index ba7440df13b..2c028d381db 100644
  2939. --- a/python/samba/tests/dcerpc/raw_testcase.py
  2940. +++ b/python/samba/tests/dcerpc/raw_testcase.py
  2941. @@ -43,7 +43,7 @@ class smb_pipe_socket(object):
  2942. lp3 = s3param.get_context()
  2943. lp3.load(lp.configfile)
  2944. self.smbconn = libsmb.Conn(target_hostname, 'IPC$', lp3,
  2945. - creds=creds, sign=True)
  2946. + creds=creds, ipc=True, sign=True)
  2947. self.smbfid = self.smbconn.create(pipename,
  2948. DesiredAccess=0x12019f,
  2949. ShareAccess=0x7,
  2950. --
  2951. 2.29.2
  2952. From ceb25f6cb4fd07cd736085030a02aefbcb012e34 Mon Sep 17 00:00:00 2001
  2953. From: Andreas Schneider <asn@samba.org>
  2954. Date: Mon, 17 Aug 2020 12:52:39 +0200
  2955. Subject: [PATCH 028/104] python:tests: Set smb ipc signing via the creds API
  2956. Signed-off-by: Andreas Schneider <asn@samba.org>
  2957. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2958. ---
  2959. python/samba/tests/dcerpc/raw_testcase.py | 4 ++++
  2960. 1 file changed, 4 insertions(+)
  2961. diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py
  2962. index 2c028d381db..d6f5de7440a 100644
  2963. --- a/python/samba/tests/dcerpc/raw_testcase.py
  2964. +++ b/python/samba/tests/dcerpc/raw_testcase.py
  2965. @@ -36,14 +36,18 @@ from samba.ntstatus import (
  2966. from samba import NTSTATUSError
  2967. from samba.samba3 import param as s3param
  2968. from samba.samba3 import libsmb_samba_internal as libsmb
  2969. +from samba.credentials import SMB_SIGNING_REQUIRED
  2970. class smb_pipe_socket(object):
  2971. def __init__(self, target_hostname, pipename, creds, impersonation_level, lp):
  2972. lp3 = s3param.get_context()
  2973. lp3.load(lp.configfile)
  2974. + saved_signing_state = creds.get_smb_ipc_signing()
  2975. + creds.set_smb_ipc_signing(SMB_SIGNING_REQUIRED)
  2976. self.smbconn = libsmb.Conn(target_hostname, 'IPC$', lp3,
  2977. creds=creds, ipc=True, sign=True)
  2978. + creds.set_smb_ipc_signing(saved_signing_state)
  2979. self.smbfid = self.smbconn.create(pipename,
  2980. DesiredAccess=0x12019f,
  2981. ShareAccess=0x7,
  2982. --
  2983. 2.29.2
  2984. From d3fe919fa5b952d075353f0d5c5366cabd5ef976 Mon Sep 17 00:00:00 2001
  2985. From: Andreas Schneider <asn@samba.org>
  2986. Date: Thu, 28 May 2020 17:59:19 +0200
  2987. Subject: [PATCH 029/104] s3:libsmb: Use 'enum smb_signing_setting' in
  2988. cliconnect.c
  2989. Signed-off-by: Andreas Schneider <asn@samba.org>
  2990. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  2991. ---
  2992. source3/libsmb/cliconnect.c | 14 +++++++-------
  2993. source3/libsmb/proto.h | 10 +++++-----
  2994. 2 files changed, 12 insertions(+), 12 deletions(-)
  2995. diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
  2996. index f20146378e3..bb20aa59385 100644
  2997. --- a/source3/libsmb/cliconnect.c
  2998. +++ b/source3/libsmb/cliconnect.c
  2999. @@ -2631,7 +2631,7 @@ static NTSTATUS cli_connect_sock_recv(struct tevent_req *req,
  3000. struct cli_connect_nb_state {
  3001. const char *desthost;
  3002. - int signing_state;
  3003. + enum smb_signing_setting signing_state;
  3004. int flags;
  3005. struct cli_state *cli;
  3006. };
  3007. @@ -2642,7 +2642,7 @@ static struct tevent_req *cli_connect_nb_send(
  3008. TALLOC_CTX *mem_ctx, struct tevent_context *ev,
  3009. const char *host, const struct sockaddr_storage *dest_ss,
  3010. uint16_t port, int name_type, const char *myname,
  3011. - int signing_state, int flags)
  3012. + enum smb_signing_setting signing_state, int flags)
  3013. {
  3014. struct tevent_req *req, *subreq;
  3015. struct cli_connect_nb_state *state;
  3016. @@ -2727,7 +2727,7 @@ static NTSTATUS cli_connect_nb_recv(struct tevent_req *req,
  3017. NTSTATUS cli_connect_nb(const char *host, const struct sockaddr_storage *dest_ss,
  3018. uint16_t port, int name_type, const char *myname,
  3019. - int signing_state, int flags, struct cli_state **pcli)
  3020. + enum smb_signing_setting signing_state, int flags, struct cli_state **pcli)
  3021. {
  3022. struct tevent_context *ev;
  3023. struct tevent_req *req;
  3024. @@ -2776,7 +2776,7 @@ static struct tevent_req *cli_start_connection_send(
  3025. TALLOC_CTX *mem_ctx, struct tevent_context *ev,
  3026. const char *my_name, const char *dest_host,
  3027. const struct sockaddr_storage *dest_ss, int port,
  3028. - int signing_state, int flags)
  3029. + enum smb_signing_setting signing_state, int flags)
  3030. {
  3031. struct tevent_req *req, *subreq;
  3032. struct cli_start_connection_state *state;
  3033. @@ -2881,7 +2881,7 @@ NTSTATUS cli_start_connection(struct cli_state **output_cli,
  3034. const char *my_name,
  3035. const char *dest_host,
  3036. const struct sockaddr_storage *dest_ss, int port,
  3037. - int signing_state, int flags)
  3038. + enum smb_signing_setting signing_state, int flags)
  3039. {
  3040. struct tevent_context *ev;
  3041. struct tevent_req *req;
  3042. @@ -3361,7 +3361,7 @@ struct tevent_req *cli_full_connection_creds_send(
  3043. const struct sockaddr_storage *dest_ss, int port,
  3044. const char *service, const char *service_type,
  3045. struct cli_credentials *creds,
  3046. - int flags, int signing_state)
  3047. + int flags, enum smb_signing_setting signing_state)
  3048. {
  3049. struct tevent_req *req, *subreq;
  3050. struct cli_full_connection_creds_state *state;
  3051. @@ -3520,7 +3520,7 @@ NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3052. const char *service, const char *service_type,
  3053. struct cli_credentials *creds,
  3054. int flags,
  3055. - int signing_state)
  3056. + enum smb_signing_setting signing_state)
  3057. {
  3058. struct tevent_context *ev;
  3059. struct tevent_req *req;
  3060. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  3061. index d214cdabca4..995187e21b4 100644
  3062. --- a/source3/libsmb/proto.h
  3063. +++ b/source3/libsmb/proto.h
  3064. @@ -86,12 +86,12 @@ NTSTATUS cli_tree_connect(struct cli_state *cli, const char *share,
  3065. NTSTATUS cli_tdis(struct cli_state *cli);
  3066. NTSTATUS cli_connect_nb(const char *host, const struct sockaddr_storage *dest_ss,
  3067. uint16_t port, int name_type, const char *myname,
  3068. - int signing_state, int flags, struct cli_state **pcli);
  3069. + enum smb_signing_setting signing_state, int flags, struct cli_state **pcli);
  3070. NTSTATUS cli_start_connection(struct cli_state **output_cli,
  3071. const char *my_name,
  3072. const char *dest_host,
  3073. const struct sockaddr_storage *dest_ss, int port,
  3074. - int signing_state, int flags);
  3075. + enum smb_signing_setting signing_state, int flags);
  3076. NTSTATUS cli_smb1_setup_encryption(struct cli_state *cli,
  3077. struct cli_credentials *creds);
  3078. struct tevent_req *cli_full_connection_creds_send(
  3079. @@ -100,7 +100,7 @@ struct tevent_req *cli_full_connection_creds_send(
  3080. const struct sockaddr_storage *dest_ss, int port,
  3081. const char *service, const char *service_type,
  3082. struct cli_credentials *creds,
  3083. - int flags, int signing_state);
  3084. + int flags, enum smb_signing_setting signing_state);
  3085. NTSTATUS cli_full_connection_creds_recv(struct tevent_req *req,
  3086. struct cli_state **output_cli);
  3087. NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3088. @@ -110,7 +110,7 @@ NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3089. const char *service, const char *service_type,
  3090. struct cli_credentials *creds,
  3091. int flags,
  3092. - int signing_state);
  3093. + enum smb_signing_setting signing_state);
  3094. NTSTATUS cli_raw_tcon(struct cli_state *cli,
  3095. const char *service, const char *pass, const char *dev,
  3096. uint16_t *max_xmit, uint16_t *tid);
  3097. @@ -177,7 +177,7 @@ extern struct GUID cli_state_client_guid;
  3098. struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
  3099. int fd,
  3100. const char *remote_name,
  3101. - int signing_state,
  3102. + enum smb_signing_setting signing_state,
  3103. int flags);
  3104. void cli_nt_pipes_close(struct cli_state *cli);
  3105. void cli_shutdown(struct cli_state *cli);
  3106. --
  3107. 2.29.2
  3108. From 0ec1b432bf807efe37fdedf346724e787742e3aa Mon Sep 17 00:00:00 2001
  3109. From: Andreas Schneider <asn@samba.org>
  3110. Date: Thu, 28 May 2020 18:11:31 +0200
  3111. Subject: [PATCH 030/104] s3:client: Turn off smb signing for message op
  3112. Signed-off-by: Andreas Schneider <asn@samba.org>
  3113. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  3114. ---
  3115. python/samba/gpclass.py | 2 +-
  3116. python/samba/netcmd/domain_backup.py | 2 +-
  3117. python/samba/netcmd/gpo.py | 2 +-
  3118. python/samba/tests/dcerpc/raw_testcase.py | 2 +-
  3119. source3/client/client.c | 5 ++++-
  3120. source3/libsmb/pylibsmb.c | 20 +++++++++-----------
  3121. 6 files changed, 17 insertions(+), 16 deletions(-)
  3122. diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py
  3123. index 1781a55a618..2c00f5349a0 100644
  3124. --- a/python/samba/gpclass.py
  3125. +++ b/python/samba/gpclass.py
  3126. @@ -426,7 +426,7 @@ def check_refresh_gpo_list(dc_hostname, lp, creds, gpos):
  3127. # Force signing for the connection
  3128. saved_signing_state = creds.get_smb_signing()
  3129. creds.set_smb_signing(SMB_SIGNING_REQUIRED)
  3130. - conn = libsmb.Conn(dc_hostname, 'sysvol', lp=s3_lp, creds=creds, sign=True)
  3131. + conn = libsmb.Conn(dc_hostname, 'sysvol', lp=s3_lp, creds=creds)
  3132. # Reset signing state
  3133. creds.set_smb_signing(saved_signing_state)
  3134. cache_path = lp.cache_path('gpo_cache')
  3135. diff --git a/python/samba/netcmd/domain_backup.py b/python/samba/netcmd/domain_backup.py
  3136. index a9e0ba5bc67..2977b071ec3 100644
  3137. --- a/python/samba/netcmd/domain_backup.py
  3138. +++ b/python/samba/netcmd/domain_backup.py
  3139. @@ -120,7 +120,7 @@ def smb_sysvol_conn(server, lp, creds):
  3140. # Force signing for the connection
  3141. saved_signing_state = creds.get_smb_signing()
  3142. creds.set_smb_signing(SMB_SIGNING_REQUIRED)
  3143. - conn = libsmb.Conn(server, "sysvol", lp=s3_lp, creds=creds, sign=True)
  3144. + conn = libsmb.Conn(server, "sysvol", lp=s3_lp, creds=creds)
  3145. # Reset signing state
  3146. creds.set_smb_signing(saved_signing_state)
  3147. return conn
  3148. diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py
  3149. index 0f2f6520fc3..bbaa0c17881 100644
  3150. --- a/python/samba/netcmd/gpo.py
  3151. +++ b/python/samba/netcmd/gpo.py
  3152. @@ -392,7 +392,7 @@ def smb_connection(dc_hostname, service, lp, creds):
  3153. # the SMB bindings rely on having a s3 loadparm
  3154. s3_lp = s3param.get_context()
  3155. s3_lp.load(lp.configfile)
  3156. - conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds, sign=True)
  3157. + conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds)
  3158. except Exception:
  3159. raise CommandError("Error connecting to '%s' using SMB" % dc_hostname)
  3160. # Reset signing state
  3161. diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py
  3162. index d6f5de7440a..34785e2a2a7 100644
  3163. --- a/python/samba/tests/dcerpc/raw_testcase.py
  3164. +++ b/python/samba/tests/dcerpc/raw_testcase.py
  3165. @@ -46,7 +46,7 @@ class smb_pipe_socket(object):
  3166. saved_signing_state = creds.get_smb_ipc_signing()
  3167. creds.set_smb_ipc_signing(SMB_SIGNING_REQUIRED)
  3168. self.smbconn = libsmb.Conn(target_hostname, 'IPC$', lp3,
  3169. - creds=creds, ipc=True, sign=True)
  3170. + creds=creds, ipc=True)
  3171. creds.set_smb_ipc_signing(saved_signing_state)
  3172. self.smbfid = self.smbconn.create(pipename,
  3173. DesiredAccess=0x12019f,
  3174. diff --git a/source3/client/client.c b/source3/client/client.c
  3175. index 8c7ceb644aa..56309efcea7 100644
  3176. --- a/source3/client/client.c
  3177. +++ b/source3/client/client.c
  3178. @@ -6164,7 +6164,10 @@ static int do_message_op(struct user_auth_info *a_info)
  3179. status = cli_connect_nb(desthost, have_ip ? &dest_ss : NULL,
  3180. port ? port : NBT_SMB_PORT, name_type,
  3181. - lp_netbios_name(), SMB_SIGNING_DEFAULT, 0, &cli);
  3182. + lp_netbios_name(),
  3183. + SMB_SIGNING_OFF,
  3184. + 0,
  3185. + &cli);
  3186. if (!NT_STATUS_IS_OK(status)) {
  3187. d_printf("Connection to %s failed. Error %s\n", desthost, nt_errstr(status));
  3188. return 1;
  3189. diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
  3190. index 3579a040830..f8a4d56cf53 100644
  3191. --- a/source3/libsmb/pylibsmb.c
  3192. +++ b/source3/libsmb/pylibsmb.c
  3193. @@ -440,9 +440,7 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3194. PyObject *py_lp = Py_None;
  3195. PyObject *py_multi_threaded = Py_False;
  3196. bool multi_threaded = false;
  3197. - PyObject *py_sign = Py_False;
  3198. - bool sign = false;
  3199. - int signing_state = SMB_SIGNING_DEFAULT;
  3200. + enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT;
  3201. PyObject *py_force_smb1 = Py_False;
  3202. bool force_smb1 = false;
  3203. PyObject *py_ipc = Py_False;
  3204. @@ -453,7 +451,7 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3205. static const char *kwlist[] = {
  3206. "host", "share", "lp", "creds",
  3207. - "multi_threaded", "sign", "force_smb1",
  3208. + "multi_threaded", "force_smb1",
  3209. "ipc",
  3210. NULL
  3211. };
  3212. @@ -465,11 +463,10 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3213. }
  3214. ret = ParseTupleAndKeywords(
  3215. - args, kwds, "ssO|O!OOOO", kwlist,
  3216. + args, kwds, "ssO|O!OOO", kwlist,
  3217. &host, &share, &py_lp,
  3218. py_type_Credentials, &creds,
  3219. &py_multi_threaded,
  3220. - &py_sign,
  3221. &py_force_smb1,
  3222. &py_ipc);
  3223. @@ -480,13 +477,8 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3224. }
  3225. multi_threaded = PyObject_IsTrue(py_multi_threaded);
  3226. - sign = PyObject_IsTrue(py_sign);
  3227. force_smb1 = PyObject_IsTrue(py_force_smb1);
  3228. - if (sign) {
  3229. - signing_state = SMB_SIGNING_REQUIRED;
  3230. - }
  3231. -
  3232. if (force_smb1) {
  3233. /*
  3234. * As most of the cli_*_send() function
  3235. @@ -532,6 +524,12 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3236. cli_creds = PyCredentials_AsCliCredentials(creds);
  3237. }
  3238. + if (use_ipc) {
  3239. + signing_state = cli_credentials_get_smb_ipc_signing(cli_creds);
  3240. + } else {
  3241. + signing_state = cli_credentials_get_smb_signing(cli_creds);
  3242. + }
  3243. +
  3244. req = cli_full_connection_creds_send(
  3245. NULL, self->ev, "myname", host, NULL, 0, share, "?????",
  3246. cli_creds, flags, signing_state);
  3247. --
  3248. 2.29.2
  3249. From dd6a89dd02e675e1b836042e4a4dec31667ac58c Mon Sep 17 00:00:00 2001
  3250. From: Andreas Schneider <asn@samba.org>
  3251. Date: Thu, 28 May 2020 18:20:02 +0200
  3252. Subject: [PATCH 031/104] s3:libsmb: Remove signing_state from
  3253. cli_full_connection_creds_send()
  3254. Signed-off-by: Andreas Schneider <asn@samba.org>
  3255. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  3256. ---
  3257. source3/libsmb/cliconnect.c | 11 +++++++++--
  3258. source3/libsmb/proto.h | 2 +-
  3259. source3/libsmb/pylibsmb.c | 9 +--------
  3260. 3 files changed, 11 insertions(+), 11 deletions(-)
  3261. diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
  3262. index bb20aa59385..0ff9c283e39 100644
  3263. --- a/source3/libsmb/cliconnect.c
  3264. +++ b/source3/libsmb/cliconnect.c
  3265. @@ -3361,10 +3361,11 @@ struct tevent_req *cli_full_connection_creds_send(
  3266. const struct sockaddr_storage *dest_ss, int port,
  3267. const char *service, const char *service_type,
  3268. struct cli_credentials *creds,
  3269. - int flags, enum smb_signing_setting signing_state)
  3270. + int flags)
  3271. {
  3272. struct tevent_req *req, *subreq;
  3273. struct cli_full_connection_creds_state *state;
  3274. + enum smb_signing_setting signing_state;
  3275. req = tevent_req_create(mem_ctx, &state,
  3276. struct cli_full_connection_creds_state);
  3277. @@ -3379,6 +3380,12 @@ struct tevent_req *cli_full_connection_creds_send(
  3278. state->creds = creds;
  3279. state->flags = flags;
  3280. + if (flags & CLI_FULL_CONNECTION_IPC) {
  3281. + signing_state = cli_credentials_get_smb_ipc_signing(creds);
  3282. + } else {
  3283. + signing_state = cli_credentials_get_smb_signing(creds);
  3284. + }
  3285. +
  3286. subreq = cli_start_connection_send(
  3287. state, ev, my_name, dest_host, dest_ss, port,
  3288. signing_state, flags);
  3289. @@ -3532,7 +3539,7 @@ NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3290. }
  3291. req = cli_full_connection_creds_send(
  3292. ev, ev, my_name, dest_host, dest_ss, port, service,
  3293. - service_type, creds, flags, signing_state);
  3294. + service_type, creds, flags);
  3295. if (req == NULL) {
  3296. goto fail;
  3297. }
  3298. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  3299. index 995187e21b4..bef04d32638 100644
  3300. --- a/source3/libsmb/proto.h
  3301. +++ b/source3/libsmb/proto.h
  3302. @@ -100,7 +100,7 @@ struct tevent_req *cli_full_connection_creds_send(
  3303. const struct sockaddr_storage *dest_ss, int port,
  3304. const char *service, const char *service_type,
  3305. struct cli_credentials *creds,
  3306. - int flags, enum smb_signing_setting signing_state);
  3307. + int flags);
  3308. NTSTATUS cli_full_connection_creds_recv(struct tevent_req *req,
  3309. struct cli_state **output_cli);
  3310. NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3311. diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
  3312. index f8a4d56cf53..c7a2d73afcb 100644
  3313. --- a/source3/libsmb/pylibsmb.c
  3314. +++ b/source3/libsmb/pylibsmb.c
  3315. @@ -440,7 +440,6 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3316. PyObject *py_lp = Py_None;
  3317. PyObject *py_multi_threaded = Py_False;
  3318. bool multi_threaded = false;
  3319. - enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT;
  3320. PyObject *py_force_smb1 = Py_False;
  3321. bool force_smb1 = false;
  3322. PyObject *py_ipc = Py_False;
  3323. @@ -524,15 +523,9 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
  3324. cli_creds = PyCredentials_AsCliCredentials(creds);
  3325. }
  3326. - if (use_ipc) {
  3327. - signing_state = cli_credentials_get_smb_ipc_signing(cli_creds);
  3328. - } else {
  3329. - signing_state = cli_credentials_get_smb_signing(cli_creds);
  3330. - }
  3331. -
  3332. req = cli_full_connection_creds_send(
  3333. NULL, self->ev, "myname", host, NULL, 0, share, "?????",
  3334. - cli_creds, flags, signing_state);
  3335. + cli_creds, flags);
  3336. if (!py_tevent_req_wait_exc(self, req)) {
  3337. return -1;
  3338. }
  3339. --
  3340. 2.29.2
  3341. From b31e224159fe25e8cf84e7d2ef8bc53934ddd209 Mon Sep 17 00:00:00 2001
  3342. From: Andreas Schneider <asn@samba.org>
  3343. Date: Thu, 4 Jun 2020 14:59:14 +0200
  3344. Subject: [PATCH 032/104] s3:libsmb: Remove signing_state from
  3345. cli_full_connection_creds()
  3346. Signed-off-by: Andreas Schneider <asn@samba.org>
  3347. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  3348. ---
  3349. examples/fuse/smb2mount.c | 3 +--
  3350. examples/winexe/winexe.c | 4 +---
  3351. source3/libnet/libnet_join.c | 9 +++------
  3352. source3/libsmb/cliconnect.c | 6 ++----
  3353. source3/libsmb/libsmb_server.c | 8 +-------
  3354. source3/libsmb/proto.h | 3 +--
  3355. source3/rpc_server/spoolss/srv_spoolss_nt.c | 3 +--
  3356. source3/rpcclient/cmd_spoolss.c | 5 +----
  3357. source3/rpcclient/rpcclient.c | 3 +--
  3358. source3/torture/locktest2.c | 11 +++++++++--
  3359. source3/torture/torture.c | 6 ++----
  3360. source3/utils/mdfind.c | 3 +--
  3361. source3/utils/net_ads.c | 3 +--
  3362. source3/utils/net_util.c | 8 ++------
  3363. source3/utils/netlookup.c | 3 +--
  3364. source3/utils/smbcacls.c | 3 +--
  3365. source3/utils/smbcquotas.c | 4 +---
  3366. 17 files changed, 30 insertions(+), 55 deletions(-)
  3367. diff --git a/examples/fuse/smb2mount.c b/examples/fuse/smb2mount.c
  3368. index ea1d9a11e0b..6206c3a9701 100644
  3369. --- a/examples/fuse/smb2mount.c
  3370. +++ b/examples/fuse/smb2mount.c
  3371. @@ -37,8 +37,7 @@ static struct cli_state *connect_one(const struct user_auth_info *auth_info,
  3372. NULL, port,
  3373. share, "?????",
  3374. get_cmdline_auth_info_creds(auth_info),
  3375. - flags,
  3376. - get_cmdline_auth_info_signing_state(auth_info));
  3377. + flags);
  3378. if (!NT_STATUS_IS_OK(nt_status)) {
  3379. DBG_ERR("cli_full_connection failed! (%s)\n",
  3380. nt_errstr(nt_status));
  3381. diff --git a/examples/winexe/winexe.c b/examples/winexe/winexe.c
  3382. index bb9c27e2e6d..03e7ec85198 100644
  3383. --- a/examples/winexe/winexe.c
  3384. +++ b/examples/winexe/winexe.c
  3385. @@ -360,7 +360,6 @@ static NTSTATUS winexe_svc_upload(
  3386. "ADMIN$",
  3387. "?????",
  3388. credentials,
  3389. - 0,
  3390. 0);
  3391. if (!NT_STATUS_IS_OK(status)) {
  3392. DBG_WARNING("cli_full_connection_creds failed: %s\n",
  3393. @@ -1919,8 +1918,7 @@ int main(int argc, const char *argv[])
  3394. "IPC$",
  3395. "?????",
  3396. options.credentials,
  3397. - CLI_FULL_CONNECTION_IPC,
  3398. - 0);
  3399. + CLI_FULL_CONNECTION_IPC);
  3400. if (!NT_STATUS_IS_OK(status)) {
  3401. DBG_WARNING("cli_full_connection_creds failed: %s\n",
  3402. diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
  3403. index 392e3eff74f..f3bf27e6c00 100644
  3404. --- a/source3/libnet/libnet_join.c
  3405. +++ b/source3/libnet/libnet_join.c
  3406. @@ -1095,8 +1095,7 @@ static NTSTATUS libnet_join_connect_dc_ipc(const char *dc,
  3407. NULL, 0,
  3408. "IPC$", "IPC",
  3409. creds,
  3410. - flags,
  3411. - SMB_SIGNING_IPC_DEFAULT);
  3412. + flags);
  3413. if (!NT_STATUS_IS_OK(status)) {
  3414. TALLOC_FREE(frame);
  3415. return status;
  3416. @@ -1716,8 +1715,7 @@ NTSTATUS libnet_join_ok(struct messaging_context *msg_ctx,
  3417. NULL, 0,
  3418. "IPC$", "IPC",
  3419. cli_creds,
  3420. - flags,
  3421. - SMB_SIGNING_IPC_DEFAULT);
  3422. + flags);
  3423. if (!NT_STATUS_IS_OK(status)) {
  3424. struct cli_credentials *anon_creds = NULL;
  3425. @@ -1734,8 +1732,7 @@ NTSTATUS libnet_join_ok(struct messaging_context *msg_ctx,
  3426. NULL, 0,
  3427. "IPC$", "IPC",
  3428. anon_creds,
  3429. - flags,
  3430. - SMB_SIGNING_OFF);
  3431. + flags);
  3432. }
  3433. if (!NT_STATUS_IS_OK(status)) {
  3434. diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
  3435. index 0ff9c283e39..b24743d789b 100644
  3436. --- a/source3/libsmb/cliconnect.c
  3437. +++ b/source3/libsmb/cliconnect.c
  3438. @@ -3526,8 +3526,7 @@ NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3439. const struct sockaddr_storage *dest_ss, int port,
  3440. const char *service, const char *service_type,
  3441. struct cli_credentials *creds,
  3442. - int flags,
  3443. - enum smb_signing_setting signing_state)
  3444. + int flags)
  3445. {
  3446. struct tevent_context *ev;
  3447. struct tevent_req *req;
  3448. @@ -3684,8 +3683,7 @@ struct cli_state *get_ipc_connect(char *server,
  3449. nt_status = cli_full_connection_creds(&cli, NULL, server, server_ss, 0, "IPC$", "IPC",
  3450. get_cmdline_auth_info_creds(user_info),
  3451. - flags,
  3452. - SMB_SIGNING_DEFAULT);
  3453. + flags);
  3454. if (NT_STATUS_IS_OK(nt_status)) {
  3455. return cli;
  3456. diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
  3457. index 3d1cd602f6c..33dc8419deb 100644
  3458. --- a/source3/libsmb/libsmb_server.c
  3459. +++ b/source3/libsmb/libsmb_server.c
  3460. @@ -785,7 +785,6 @@ SMBC_attr_server(TALLOC_CTX *ctx,
  3461. pp_workgroup, pp_username, pp_password);
  3462. if (!ipc_srv) {
  3463. struct cli_credentials *creds = NULL;
  3464. - int signing_state = SMB_SIGNING_DEFAULT;
  3465. /* We didn't find a cached connection. Get the password */
  3466. if (!*pp_password || (*pp_password)[0] == '\0') {
  3467. @@ -812,16 +811,11 @@ SMBC_attr_server(TALLOC_CTX *ctx,
  3468. return NULL;
  3469. }
  3470. - if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
  3471. - signing_state = SMB_SIGNING_REQUIRED;
  3472. - }
  3473. -
  3474. nt_status = cli_full_connection_creds(&ipc_cli,
  3475. lp_netbios_name(), server,
  3476. NULL, 0, "IPC$", "?????",
  3477. creds,
  3478. - flags,
  3479. - signing_state);
  3480. + flags);
  3481. if (! NT_STATUS_IS_OK(nt_status)) {
  3482. TALLOC_FREE(creds);
  3483. DEBUG(1,("cli_full_connection failed! (%s)\n",
  3484. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  3485. index bef04d32638..850cf12c8a6 100644
  3486. --- a/source3/libsmb/proto.h
  3487. +++ b/source3/libsmb/proto.h
  3488. @@ -109,8 +109,7 @@ NTSTATUS cli_full_connection_creds(struct cli_state **output_cli,
  3489. const struct sockaddr_storage *dest_ss, int port,
  3490. const char *service, const char *service_type,
  3491. struct cli_credentials *creds,
  3492. - int flags,
  3493. - enum smb_signing_setting signing_state);
  3494. + int flags);
  3495. NTSTATUS cli_raw_tcon(struct cli_state *cli,
  3496. const char *service, const char *pass, const char *dev,
  3497. uint16_t *max_xmit, uint16_t *tid);
  3498. diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
  3499. index f578f1c4131..906fab2adb5 100644
  3500. --- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
  3501. +++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
  3502. @@ -2483,8 +2483,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct c
  3503. ret = cli_full_connection_creds( pp_cli, lp_netbios_name(), remote_machine,
  3504. &rm_addr, 0, "IPC$", "IPC",
  3505. anon_creds,
  3506. - CLI_FULL_CONNECTION_IPC,
  3507. - SMB_SIGNING_OFF);
  3508. + CLI_FULL_CONNECTION_IPC);
  3509. TALLOC_FREE(anon_creds);
  3510. if ( !NT_STATUS_IS_OK( ret ) ) {
  3511. DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
  3512. diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
  3513. index 7198a451ab7..02889a0a666 100644
  3514. --- a/source3/rpcclient/cmd_spoolss.c
  3515. +++ b/source3/rpcclient/cmd_spoolss.c
  3516. @@ -3537,10 +3537,7 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
  3517. "IPC$", "IPC",
  3518. get_cmdline_auth_info_creds(
  3519. popt_get_cmdline_auth_info()),
  3520. - CLI_FULL_CONNECTION_IPC,
  3521. - get_cmdline_auth_info_signing_state(
  3522. - popt_get_cmdline_auth_info()));
  3523. -
  3524. + CLI_FULL_CONNECTION_IPC);
  3525. if ( !NT_STATUS_IS_OK(nt_status) )
  3526. return WERR_GEN_FAILURE;
  3527. diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
  3528. index c86474d08f1..2ead6cc7ba5 100644
  3529. --- a/source3/rpcclient/rpcclient.c
  3530. +++ b/source3/rpcclient/rpcclient.c
  3531. @@ -1206,8 +1206,7 @@ out_free:
  3532. "IPC$", "IPC",
  3533. get_cmdline_auth_info_creds(
  3534. popt_get_cmdline_auth_info()),
  3535. - flags,
  3536. - SMB_SIGNING_IPC_DEFAULT);
  3537. + flags);
  3538. if (!NT_STATUS_IS_OK(nt_status)) {
  3539. DEBUG(0,("Cannot connect to server. Error was %s\n", nt_errstr(nt_status)));
  3540. diff --git a/source3/torture/locktest2.c b/source3/torture/locktest2.c
  3541. index 84c335f959f..92ddb7629b9 100644
  3542. --- a/source3/torture/locktest2.c
  3543. +++ b/source3/torture/locktest2.c
  3544. @@ -217,8 +217,15 @@ static struct cli_state *connect_one(char *share)
  3545. slprintf(myname,sizeof(myname), "lock-%lu-%u", (unsigned long)getpid(), count++);
  3546. - nt_status = cli_full_connection_creds(&c, myname, server_n, NULL, 0, share, "?????",
  3547. - creds, 0, SMB_SIGNING_DEFAULT);
  3548. + nt_status = cli_full_connection_creds(&c,
  3549. + myname,
  3550. + server_n,
  3551. + NULL,
  3552. + 0,
  3553. + share,
  3554. + "?????",
  3555. + creds,
  3556. + 0);
  3557. TALLOC_FREE(creds);
  3558. if (!NT_STATUS_IS_OK(nt_status)) {
  3559. DEBUG(0, ("cli_full_connection failed with error %s\n", nt_errstr(nt_status)));
  3560. diff --git a/source3/torture/torture.c b/source3/torture/torture.c
  3561. index 2a3133373e9..a4edeefd628 100644
  3562. --- a/source3/torture/torture.c
  3563. +++ b/source3/torture/torture.c
  3564. @@ -345,8 +345,7 @@ static bool torture_open_connection_share(struct cli_state **c,
  3565. sharename,
  3566. "?????",
  3567. torture_creds,
  3568. - flags,
  3569. - signing_state);
  3570. + flags);
  3571. if (!NT_STATUS_IS_OK(status)) {
  3572. printf("failed to open share connection: //%s/%s port:%d - %s\n",
  3573. hostname, sharename, port_to_use, nt_errstr(status));
  3574. @@ -1523,8 +1522,7 @@ static bool run_tcon_devtype_test(int dummy)
  3575. NULL, /* service */
  3576. NULL, /* service_type */
  3577. torture_creds,
  3578. - flags,
  3579. - signing_state);
  3580. + flags);
  3581. if (!NT_STATUS_IS_OK(status)) {
  3582. printf("could not open connection\n");
  3583. diff --git a/source3/utils/mdfind.c b/source3/utils/mdfind.c
  3584. index a3c879e75fb..2ac4fde7daf 100644
  3585. --- a/source3/utils/mdfind.c
  3586. +++ b/source3/utils/mdfind.c
  3587. @@ -153,8 +153,7 @@ int main(int argc, char **argv)
  3588. "IPC$",
  3589. "IPC",
  3590. creds,
  3591. - flags,
  3592. - SMB_SIGNING_IPC_DEFAULT);
  3593. + flags);
  3594. if (!NT_STATUS_IS_OK(status)) {
  3595. DBG_ERR("Cannot connect to server: %s\n", nt_errstr(status));
  3596. goto fail;
  3597. diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
  3598. index 28ef6dc9974..7f5b9c3a440 100644
  3599. --- a/source3/utils/net_ads.c
  3600. +++ b/source3/utils/net_ads.c
  3601. @@ -2438,8 +2438,7 @@ static int net_ads_printer_publish(struct net_context *c, int argc, const char *
  3602. &server_ss, 0,
  3603. "IPC$", "IPC",
  3604. creds,
  3605. - CLI_FULL_CONNECTION_IPC,
  3606. - SMB_SIGNING_IPC_DEFAULT);
  3607. + CLI_FULL_CONNECTION_IPC);
  3608. if (NT_STATUS_IS_ERR(nt_status)) {
  3609. d_fprintf(stderr, _("Unable to open a connection to %s to "
  3610. diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
  3611. index d01b2d8c771..b139fb2d0da 100644
  3612. --- a/source3/utils/net_util.c
  3613. +++ b/source3/utils/net_util.c
  3614. @@ -108,7 +108,6 @@ NTSTATUS connect_to_service(struct net_context *c,
  3615. const char *service_type)
  3616. {
  3617. NTSTATUS nt_status;
  3618. - enum smb_signing_setting signing_setting = SMB_SIGNING_DEFAULT;
  3619. struct cli_credentials *creds = NULL;
  3620. int flags = 0;
  3621. @@ -119,7 +118,6 @@ NTSTATUS connect_to_service(struct net_context *c,
  3622. }
  3623. if (strequal(service_type, "IPC")) {
  3624. - signing_setting = SMB_SIGNING_IPC_DEFAULT;
  3625. flags |= CLI_FULL_CONNECTION_IPC;
  3626. }
  3627. @@ -127,8 +125,7 @@ NTSTATUS connect_to_service(struct net_context *c,
  3628. server_ss, c->opt_port,
  3629. service_name, service_type,
  3630. creds,
  3631. - flags,
  3632. - signing_setting);
  3633. + flags);
  3634. if (!NT_STATUS_IS_OK(nt_status)) {
  3635. d_fprintf(stderr, _("Could not connect to server %s\n"),
  3636. server_name);
  3637. @@ -199,8 +196,7 @@ NTSTATUS connect_to_ipc_anonymous(struct net_context *c,
  3638. server_name, server_ss, c->opt_port,
  3639. "IPC$", "IPC",
  3640. anon_creds,
  3641. - CLI_FULL_CONNECTION_IPC,
  3642. - SMB_SIGNING_OFF);
  3643. + CLI_FULL_CONNECTION_IPC);
  3644. if (NT_STATUS_IS_OK(nt_status)) {
  3645. return nt_status;
  3646. diff --git a/source3/utils/netlookup.c b/source3/utils/netlookup.c
  3647. index 2241beb331f..aaf78b0977a 100644
  3648. --- a/source3/utils/netlookup.c
  3649. +++ b/source3/utils/netlookup.c
  3650. @@ -99,8 +99,7 @@ static struct con_struct *create_cs(struct net_context *c,
  3651. &loopback_ss, 0,
  3652. "IPC$", "IPC",
  3653. anon_creds,
  3654. - CLI_FULL_CONNECTION_IPC,
  3655. - SMB_SIGNING_OFF);
  3656. + CLI_FULL_CONNECTION_IPC);
  3657. if (!NT_STATUS_IS_OK(nt_status)) {
  3658. DEBUG(2,("create_cs: Connect failed. Error was %s\n", nt_errstr(nt_status)));
  3659. diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
  3660. index f3209c31877..5983ebbd0a5 100644
  3661. --- a/source3/utils/smbcacls.c
  3662. +++ b/source3/utils/smbcacls.c
  3663. @@ -778,8 +778,7 @@ static struct cli_state *connect_one(const struct user_auth_info *auth_info,
  3664. NULL, 0,
  3665. share, "?????",
  3666. get_cmdline_auth_info_creds(auth_info),
  3667. - flags,
  3668. - get_cmdline_auth_info_signing_state(auth_info));
  3669. + flags);
  3670. if (!NT_STATUS_IS_OK(nt_status)) {
  3671. DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
  3672. return NULL;
  3673. diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c
  3674. index 954d6eba804..fea066ce468 100644
  3675. --- a/source3/utils/smbcquotas.c
  3676. +++ b/source3/utils/smbcquotas.c
  3677. @@ -527,9 +527,7 @@ static struct cli_state *connect_one(const char *share)
  3678. share, "?????",
  3679. get_cmdline_auth_info_creds(
  3680. popt_get_cmdline_auth_info()),
  3681. - flags,
  3682. - get_cmdline_auth_info_signing_state(
  3683. - popt_get_cmdline_auth_info()));
  3684. + flags);
  3685. if (!NT_STATUS_IS_OK(nt_status)) {
  3686. DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
  3687. return NULL;
  3688. --
  3689. 2.29.2
  3690. From 49430d65ac0e11cdfec07c55b72f030c959f576f Mon Sep 17 00:00:00 2001
  3691. From: Stefan Metzmacher <metze@samba.org>
  3692. Date: Mon, 8 Jun 2020 08:04:24 +0200
  3693. Subject: [PATCH 033/104] s3:libsmb: Add encryption support to
  3694. cli_full_connection_creds*()
  3695. Pair-Programmed-With: Andreas Schneider <asn@samba.org>
  3696. Signed-off-by: Andreas Schneider <asn@samba.org>
  3697. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  3698. Reviewed-by: Andreas Schneider <asn@samba.org>
  3699. ---
  3700. source3/libsmb/cliconnect.c | 166 ++++++++++++++++++++++++++++++++++++
  3701. 1 file changed, 166 insertions(+)
  3702. diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
  3703. index b24743d789b..abfd18bfaf1 100644
  3704. --- a/source3/libsmb/cliconnect.c
  3705. +++ b/source3/libsmb/cliconnect.c
  3706. @@ -3352,6 +3352,10 @@ static int cli_full_connection_creds_state_destructor(
  3707. static void cli_full_connection_creds_conn_done(struct tevent_req *subreq);
  3708. static void cli_full_connection_creds_sess_start(struct tevent_req *req);
  3709. static void cli_full_connection_creds_sess_done(struct tevent_req *subreq);
  3710. +static void cli_full_connection_creds_enc_start(struct tevent_req *req);
  3711. +static void cli_full_connection_creds_enc_tcon(struct tevent_req *subreq);
  3712. +static void cli_full_connection_creds_enc_ver(struct tevent_req *subreq);
  3713. +static void cli_full_connection_creds_enc_done(struct tevent_req *subreq);
  3714. static void cli_full_connection_creds_tcon_start(struct tevent_req *req);
  3715. static void cli_full_connection_creds_tcon_done(struct tevent_req *subreq);
  3716. @@ -3366,6 +3370,8 @@ struct tevent_req *cli_full_connection_creds_send(
  3717. struct tevent_req *req, *subreq;
  3718. struct cli_full_connection_creds_state *state;
  3719. enum smb_signing_setting signing_state;
  3720. + enum smb_encryption_setting encryption_state =
  3721. + cli_credentials_get_smb_encryption(creds);
  3722. req = tevent_req_create(mem_ctx, &state,
  3723. struct cli_full_connection_creds_state);
  3724. @@ -3386,6 +3392,16 @@ struct tevent_req *cli_full_connection_creds_send(
  3725. signing_state = cli_credentials_get_smb_signing(creds);
  3726. }
  3727. + if (encryption_state == SMB_ENCRYPTION_REQUIRED) {
  3728. + if (flags & CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK) {
  3729. + encryption_state = SMB_ENCRYPTION_DESIRED;
  3730. + }
  3731. + }
  3732. +
  3733. + if (encryption_state >= SMB_ENCRYPTION_DESIRED) {
  3734. + signing_state = SMB_SIGNING_REQUIRED;
  3735. + }
  3736. +
  3737. subreq = cli_start_connection_send(
  3738. state, ev, my_name, dest_host, dest_ss, port,
  3739. signing_state, flags);
  3740. @@ -3460,6 +3476,156 @@ static void cli_full_connection_creds_sess_done(struct tevent_req *subreq)
  3741. return;
  3742. }
  3743. + cli_full_connection_creds_enc_start(req);
  3744. +}
  3745. +
  3746. +static void cli_full_connection_creds_enc_start(struct tevent_req *req)
  3747. +{
  3748. + struct cli_full_connection_creds_state *state = tevent_req_data(
  3749. + req, struct cli_full_connection_creds_state);
  3750. + enum smb_encryption_setting encryption_state =
  3751. + cli_credentials_get_smb_encryption(state->creds);
  3752. + struct tevent_req *subreq = NULL;
  3753. + NTSTATUS status;
  3754. +
  3755. + if (encryption_state < SMB_ENCRYPTION_DESIRED) {
  3756. + cli_full_connection_creds_tcon_start(req);
  3757. + return;
  3758. + }
  3759. +
  3760. + if (smbXcli_conn_protocol(state->cli->conn) >= PROTOCOL_SMB2_02) {
  3761. + status = smb2cli_session_encryption_on(state->cli->smb2.session);
  3762. + if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
  3763. + if (encryption_state < SMB_ENCRYPTION_REQUIRED) {
  3764. + cli_full_connection_creds_tcon_start(req);
  3765. + return;
  3766. + }
  3767. + d_printf("Encryption required and "
  3768. + "server doesn't support "
  3769. + "SMB3 encryption - failing connect\n");
  3770. + tevent_req_nterror(req, status);
  3771. + return;
  3772. + } else if (!NT_STATUS_IS_OK(status)) {
  3773. + d_printf("Encryption required and "
  3774. + "setup failed with error %s.\n",
  3775. + nt_errstr(status));
  3776. + tevent_req_nterror(req, status);
  3777. + return;
  3778. + }
  3779. +
  3780. + cli_full_connection_creds_tcon_start(req);
  3781. + return;
  3782. + }
  3783. +
  3784. + if (!SERVER_HAS_UNIX_CIFS(state->cli)) {
  3785. + if (encryption_state < SMB_ENCRYPTION_REQUIRED) {
  3786. + cli_full_connection_creds_tcon_start(req);
  3787. + return;
  3788. + }
  3789. +
  3790. + status = NT_STATUS_NOT_SUPPORTED;
  3791. + d_printf("Encryption required and "
  3792. + "server doesn't support "
  3793. + "SMB1 Unix Extensions - failing connect\n");
  3794. + tevent_req_nterror(req, status);
  3795. + return;
  3796. + }
  3797. +
  3798. + /*
  3799. + * We do a tcon on IPC$ just to setup the encryption,
  3800. + * the real tcon will be encrypted then.
  3801. + */
  3802. + subreq = cli_tree_connect_send(state, state->ev, state->cli,
  3803. + "IPC$", "IPC", NULL);
  3804. + if (tevent_req_nomem(subreq, req)) {
  3805. + return;
  3806. + }
  3807. + tevent_req_set_callback(subreq, cli_full_connection_creds_enc_tcon, req);
  3808. +}
  3809. +
  3810. +static void cli_full_connection_creds_enc_tcon(struct tevent_req *subreq)
  3811. +{
  3812. + struct tevent_req *req = tevent_req_callback_data(
  3813. + subreq, struct tevent_req);
  3814. + struct cli_full_connection_creds_state *state = tevent_req_data(
  3815. + req, struct cli_full_connection_creds_state);
  3816. + NTSTATUS status;
  3817. +
  3818. + status = cli_tree_connect_recv(subreq);
  3819. + TALLOC_FREE(subreq);
  3820. + if (tevent_req_nterror(req, status)) {
  3821. + return;
  3822. + }
  3823. +
  3824. + subreq = cli_unix_extensions_version_send(state, state->ev, state->cli);
  3825. + if (tevent_req_nomem(subreq, req)) {
  3826. + return;
  3827. + }
  3828. + tevent_req_set_callback(subreq, cli_full_connection_creds_enc_ver, req);
  3829. +}
  3830. +
  3831. +static void cli_full_connection_creds_enc_ver(struct tevent_req *subreq)
  3832. +{
  3833. + struct tevent_req *req = tevent_req_callback_data(
  3834. + subreq, struct tevent_req);
  3835. + struct cli_full_connection_creds_state *state = tevent_req_data(
  3836. + req, struct cli_full_connection_creds_state);
  3837. + enum smb_encryption_setting encryption_state =
  3838. + cli_credentials_get_smb_encryption(state->creds);
  3839. + uint16_t major, minor;
  3840. + uint32_t caplow, caphigh;
  3841. + NTSTATUS status;
  3842. +
  3843. + status = cli_unix_extensions_version_recv(subreq,
  3844. + &major, &minor,
  3845. + &caplow,
  3846. + &caphigh);
  3847. + TALLOC_FREE(subreq);
  3848. + if (!NT_STATUS_IS_OK(status)) {
  3849. + if (encryption_state < SMB_ENCRYPTION_REQUIRED) {
  3850. + cli_full_connection_creds_tcon_start(req);
  3851. + return;
  3852. + }
  3853. + DEBUG(10, ("%s: cli_unix_extensions_version "
  3854. + "returned %s\n", __func__, nt_errstr(status)));
  3855. + tevent_req_nterror(req, NT_STATUS_UNKNOWN_REVISION);
  3856. + return;
  3857. + }
  3858. +
  3859. + if (!(caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)) {
  3860. + if (encryption_state < SMB_ENCRYPTION_REQUIRED) {
  3861. + cli_full_connection_creds_tcon_start(req);
  3862. + return;
  3863. + }
  3864. + DEBUG(10, ("%s: CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP "
  3865. + "not supported\n", __func__));
  3866. + tevent_req_nterror(req, NT_STATUS_UNSUPPORTED_COMPRESSION);
  3867. + return;
  3868. + }
  3869. +
  3870. + subreq = cli_smb1_setup_encryption_send(state, state->ev,
  3871. + state->cli,
  3872. + state->creds);
  3873. + if (tevent_req_nomem(subreq, req)) {
  3874. + return;
  3875. + }
  3876. + tevent_req_set_callback(subreq,
  3877. + cli_full_connection_creds_enc_done,
  3878. + req);
  3879. +}
  3880. +
  3881. +static void cli_full_connection_creds_enc_done(struct tevent_req *subreq)
  3882. +{
  3883. + struct tevent_req *req = tevent_req_callback_data(
  3884. + subreq, struct tevent_req);
  3885. + NTSTATUS status;
  3886. +
  3887. + status = cli_smb1_setup_encryption_recv(subreq);
  3888. + TALLOC_FREE(subreq);
  3889. + if (tevent_req_nterror(req, status)) {
  3890. + return;
  3891. + }
  3892. +
  3893. cli_full_connection_creds_tcon_start(req);
  3894. }
  3895. --
  3896. 2.29.2
  3897. From cc6eca3fe233c16d879f9a76aae022320e7044d7 Mon Sep 17 00:00:00 2001
  3898. From: Andreas Schneider <asn@samba.org>
  3899. Date: Wed, 10 Jun 2020 11:26:00 +0200
  3900. Subject: [PATCH 034/104] python: Add a test for SMB encryption
  3901. Signed-off-by: Andreas Schneider <asn@samba.org>
  3902. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  3903. ---
  3904. python/samba/tests/libsmb.py | 37 ++++++++++++++++++++++++++++++++++++
  3905. 1 file changed, 37 insertions(+)
  3906. diff --git a/python/samba/tests/libsmb.py b/python/samba/tests/libsmb.py
  3907. index e8f8e7fe94d..81d4e482644 100644
  3908. --- a/python/samba/tests/libsmb.py
  3909. +++ b/python/samba/tests/libsmb.py
  3910. @@ -21,10 +21,12 @@ from samba.samba3 import libsmb_samba_internal as libsmb
  3911. from samba.dcerpc import security
  3912. from samba.samba3 import param as s3param
  3913. from samba import credentials
  3914. +from samba.credentials import SMB_ENCRYPTION_REQUIRED
  3915. import samba.tests
  3916. import threading
  3917. import sys
  3918. import os
  3919. +import random
  3920. class LibsmbTestCase(samba.tests.TestCase):
  3921. @@ -77,6 +79,41 @@ class LibsmbTestCase(samba.tests.TestCase):
  3922. if t.exc:
  3923. raise t.exc[0](t.exc[1])
  3924. + def test_SMB3EncryptionRequired(self):
  3925. + test_dir = 'testing_%d' % random.randint(0, 0xFFFF)
  3926. +
  3927. + lp = s3param.get_context()
  3928. + lp.load(os.getenv("SMB_CONF_PATH"))
  3929. +
  3930. + creds = credentials.Credentials()
  3931. + creds.guess(lp)
  3932. + creds.set_username(os.getenv("USERNAME"))
  3933. + creds.set_password(os.getenv("PASSWORD"))
  3934. + creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  3935. +
  3936. + c = libsmb.Conn(os.getenv("SERVER_IP"), "tmp",
  3937. + lp, creds)
  3938. +
  3939. + c.mkdir(test_dir)
  3940. + c.rmdir(test_dir)
  3941. +
  3942. + def test_SMB1EncryptionRequired(self):
  3943. + test_dir = 'testing_%d' % random.randint(0, 0xFFFF)
  3944. +
  3945. + lp = s3param.get_context()
  3946. + lp.load(os.getenv("SMB_CONF_PATH"))
  3947. +
  3948. + creds = credentials.Credentials()
  3949. + creds.guess(lp)
  3950. + creds.set_username(os.getenv("USERNAME"))
  3951. + creds.set_password(os.getenv("PASSWORD"))
  3952. + creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  3953. +
  3954. + c = libsmb.Conn(os.getenv("SERVER_IP"), "tmp",
  3955. + lp, creds, force_smb1=True)
  3956. +
  3957. + c.mkdir(test_dir)
  3958. + c.rmdir(test_dir)
  3959. if __name__ == "__main__":
  3960. import unittest
  3961. --
  3962. 2.29.2
  3963. From 3bb0f6be56244767f78e8d0e085f2f7555585225 Mon Sep 17 00:00:00 2001
  3964. From: Andreas Schneider <asn@samba.org>
  3965. Date: Wed, 10 Jun 2020 12:31:02 +0200
  3966. Subject: [PATCH 035/104] s3:net: Use cli_credentials_set_smb_encryption()
  3967. Signed-off-by: Andreas Schneider <asn@samba.org>
  3968. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  3969. ---
  3970. source3/utils/net_util.c | 16 ++++++----------
  3971. 1 file changed, 6 insertions(+), 10 deletions(-)
  3972. diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
  3973. index b139fb2d0da..5829d891075 100644
  3974. --- a/source3/utils/net_util.c
  3975. +++ b/source3/utils/net_util.c
  3976. @@ -148,16 +148,6 @@ NTSTATUS connect_to_service(struct net_context *c,
  3977. return nt_status;
  3978. }
  3979. - if (c->smb_encrypt) {
  3980. - nt_status = cli_cm_force_encryption_creds(*cli_ctx,
  3981. - creds,
  3982. - service_name);
  3983. - if (!NT_STATUS_IS_OK(nt_status)) {
  3984. - cli_shutdown(*cli_ctx);
  3985. - *cli_ctx = NULL;
  3986. - }
  3987. - }
  3988. -
  3989. return nt_status;
  3990. }
  3991. @@ -577,6 +567,12 @@ struct cli_credentials *net_context_creds(struct net_context *c,
  3992. CRED_SPECIFIED);
  3993. }
  3994. + if (c->smb_encrypt) {
  3995. + cli_credentials_set_smb_encryption(creds,
  3996. + SMB_ENCRYPTION_REQUIRED,
  3997. + CRED_SPECIFIED);
  3998. + }
  3999. +
  4000. return creds;
  4001. }
  4002. --
  4003. 2.29.2
  4004. From 16aaa2f7395d235f72582a5190c9bf5d90578b9d Mon Sep 17 00:00:00 2001
  4005. From: Andreas Schneider <asn@samba.org>
  4006. Date: Wed, 10 Jun 2020 12:40:13 +0200
  4007. Subject: [PATCH 036/104] s3:libsmb: Use cli_credentials_set_smb_encryption()
  4008. This also adds a SMBC_ENCRYPTLEVEL_DEFAULT to 'enum
  4009. smbc_smb_encrypt_level' in order to use the smb.conf default value.
  4010. Signed-off-by: Andreas Schneider <asn@samba.org>
  4011. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4012. ---
  4013. source3/include/libsmbclient.h | 1 +
  4014. source3/libsmb/ABI/smbclient-0.7.0.sigs | 188 ++++++++++++++++++++++++
  4015. source3/libsmb/libsmb_context.c | 4 +-
  4016. source3/libsmb/libsmb_server.c | 72 +++------
  4017. source3/libsmb/wscript | 2 +-
  4018. 5 files changed, 216 insertions(+), 51 deletions(-)
  4019. create mode 100644 source3/libsmb/ABI/smbclient-0.7.0.sigs
  4020. diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
  4021. index c47e7c2a872..84c98089251 100644
  4022. --- a/source3/include/libsmbclient.h
  4023. +++ b/source3/include/libsmbclient.h
  4024. @@ -225,6 +225,7 @@ typedef enum smbc_share_mode
  4025. */
  4026. typedef enum smbc_smb_encrypt_level
  4027. {
  4028. + SMBC_ENCRYPTLEVEL_DEFAULT = -1,
  4029. SMBC_ENCRYPTLEVEL_NONE = 0,
  4030. SMBC_ENCRYPTLEVEL_REQUEST = 1,
  4031. SMBC_ENCRYPTLEVEL_REQUIRE = 2
  4032. diff --git a/source3/libsmb/ABI/smbclient-0.7.0.sigs b/source3/libsmb/ABI/smbclient-0.7.0.sigs
  4033. new file mode 100644
  4034. index 00000000000..ee758e21b50
  4035. --- /dev/null
  4036. +++ b/source3/libsmb/ABI/smbclient-0.7.0.sigs
  4037. @@ -0,0 +1,188 @@
  4038. +smbc_chmod: int (const char *, mode_t)
  4039. +smbc_close: int (int)
  4040. +smbc_closedir: int (int)
  4041. +smbc_creat: int (const char *, mode_t)
  4042. +smbc_fgetxattr: int (int, const char *, const void *, size_t)
  4043. +smbc_flistxattr: int (int, char *, size_t)
  4044. +smbc_free_context: int (SMBCCTX *, int)
  4045. +smbc_fremovexattr: int (int, const char *)
  4046. +smbc_fsetxattr: int (int, const char *, const void *, size_t, int)
  4047. +smbc_fstat: int (int, struct stat *)
  4048. +smbc_fstatvfs: int (int, struct statvfs *)
  4049. +smbc_ftruncate: int (int, off_t)
  4050. +smbc_getDebug: int (SMBCCTX *)
  4051. +smbc_getFunctionAddCachedServer: smbc_add_cached_srv_fn (SMBCCTX *)
  4052. +smbc_getFunctionAuthData: smbc_get_auth_data_fn (SMBCCTX *)
  4053. +smbc_getFunctionAuthDataWithContext: smbc_get_auth_data_with_context_fn (SMBCCTX *)
  4054. +smbc_getFunctionCheckServer: smbc_check_server_fn (SMBCCTX *)
  4055. +smbc_getFunctionChmod: smbc_chmod_fn (SMBCCTX *)
  4056. +smbc_getFunctionClose: smbc_close_fn (SMBCCTX *)
  4057. +smbc_getFunctionClosedir: smbc_closedir_fn (SMBCCTX *)
  4058. +smbc_getFunctionCreat: smbc_creat_fn (SMBCCTX *)
  4059. +smbc_getFunctionFstat: smbc_fstat_fn (SMBCCTX *)
  4060. +smbc_getFunctionFstatVFS: smbc_fstatvfs_fn (SMBCCTX *)
  4061. +smbc_getFunctionFstatdir: smbc_fstatdir_fn (SMBCCTX *)
  4062. +smbc_getFunctionFtruncate: smbc_ftruncate_fn (SMBCCTX *)
  4063. +smbc_getFunctionGetCachedServer: smbc_get_cached_srv_fn (SMBCCTX *)
  4064. +smbc_getFunctionGetdents: smbc_getdents_fn (SMBCCTX *)
  4065. +smbc_getFunctionGetxattr: smbc_getxattr_fn (SMBCCTX *)
  4066. +smbc_getFunctionListPrintJobs: smbc_list_print_jobs_fn (SMBCCTX *)
  4067. +smbc_getFunctionListxattr: smbc_listxattr_fn (SMBCCTX *)
  4068. +smbc_getFunctionLseek: smbc_lseek_fn (SMBCCTX *)
  4069. +smbc_getFunctionLseekdir: smbc_lseekdir_fn (SMBCCTX *)
  4070. +smbc_getFunctionMkdir: smbc_mkdir_fn (SMBCCTX *)
  4071. +smbc_getFunctionNotify: smbc_notify_fn (SMBCCTX *)
  4072. +smbc_getFunctionOpen: smbc_open_fn (SMBCCTX *)
  4073. +smbc_getFunctionOpenPrintJob: smbc_open_print_job_fn (SMBCCTX *)
  4074. +smbc_getFunctionOpendir: smbc_opendir_fn (SMBCCTX *)
  4075. +smbc_getFunctionPrintFile: smbc_print_file_fn (SMBCCTX *)
  4076. +smbc_getFunctionPurgeCachedServers: smbc_purge_cached_fn (SMBCCTX *)
  4077. +smbc_getFunctionRead: smbc_read_fn (SMBCCTX *)
  4078. +smbc_getFunctionReaddir: smbc_readdir_fn (SMBCCTX *)
  4079. +smbc_getFunctionReaddirPlus: smbc_readdirplus_fn (SMBCCTX *)
  4080. +smbc_getFunctionReaddirPlus2: smbc_readdirplus2_fn (SMBCCTX *)
  4081. +smbc_getFunctionRemoveCachedServer: smbc_remove_cached_srv_fn (SMBCCTX *)
  4082. +smbc_getFunctionRemoveUnusedServer: smbc_remove_unused_server_fn (SMBCCTX *)
  4083. +smbc_getFunctionRemovexattr: smbc_removexattr_fn (SMBCCTX *)
  4084. +smbc_getFunctionRename: smbc_rename_fn (SMBCCTX *)
  4085. +smbc_getFunctionRmdir: smbc_rmdir_fn (SMBCCTX *)
  4086. +smbc_getFunctionSetxattr: smbc_setxattr_fn (SMBCCTX *)
  4087. +smbc_getFunctionSplice: smbc_splice_fn (SMBCCTX *)
  4088. +smbc_getFunctionStat: smbc_stat_fn (SMBCCTX *)
  4089. +smbc_getFunctionStatVFS: smbc_statvfs_fn (SMBCCTX *)
  4090. +smbc_getFunctionTelldir: smbc_telldir_fn (SMBCCTX *)
  4091. +smbc_getFunctionUnlink: smbc_unlink_fn (SMBCCTX *)
  4092. +smbc_getFunctionUnlinkPrintJob: smbc_unlink_print_job_fn (SMBCCTX *)
  4093. +smbc_getFunctionUtimes: smbc_utimes_fn (SMBCCTX *)
  4094. +smbc_getFunctionWrite: smbc_write_fn (SMBCCTX *)
  4095. +smbc_getNetbiosName: const char *(SMBCCTX *)
  4096. +smbc_getOptionBrowseMaxLmbCount: int (SMBCCTX *)
  4097. +smbc_getOptionCaseSensitive: smbc_bool (SMBCCTX *)
  4098. +smbc_getOptionDebugToStderr: smbc_bool (SMBCCTX *)
  4099. +smbc_getOptionFallbackAfterKerberos: smbc_bool (SMBCCTX *)
  4100. +smbc_getOptionFullTimeNames: smbc_bool (SMBCCTX *)
  4101. +smbc_getOptionNoAutoAnonymousLogin: smbc_bool (SMBCCTX *)
  4102. +smbc_getOptionOneSharePerServer: smbc_bool (SMBCCTX *)
  4103. +smbc_getOptionOpenShareMode: smbc_share_mode (SMBCCTX *)
  4104. +smbc_getOptionSmbEncryptionLevel: smbc_smb_encrypt_level (SMBCCTX *)
  4105. +smbc_getOptionUrlEncodeReaddirEntries: smbc_bool (SMBCCTX *)
  4106. +smbc_getOptionUseCCache: smbc_bool (SMBCCTX *)
  4107. +smbc_getOptionUseKerberos: smbc_bool (SMBCCTX *)
  4108. +smbc_getOptionUseNTHash: smbc_bool (SMBCCTX *)
  4109. +smbc_getOptionUserData: void *(SMBCCTX *)
  4110. +smbc_getPort: uint16_t (SMBCCTX *)
  4111. +smbc_getServerCacheData: struct smbc_server_cache *(SMBCCTX *)
  4112. +smbc_getTimeout: int (SMBCCTX *)
  4113. +smbc_getUser: const char *(SMBCCTX *)
  4114. +smbc_getWorkgroup: const char *(SMBCCTX *)
  4115. +smbc_getdents: int (unsigned int, struct smbc_dirent *, int)
  4116. +smbc_getxattr: int (const char *, const char *, const void *, size_t)
  4117. +smbc_init: int (smbc_get_auth_data_fn, int)
  4118. +smbc_init_context: SMBCCTX *(SMBCCTX *)
  4119. +smbc_lgetxattr: int (const char *, const char *, const void *, size_t)
  4120. +smbc_list_print_jobs: int (const char *, smbc_list_print_job_fn)
  4121. +smbc_listxattr: int (const char *, char *, size_t)
  4122. +smbc_llistxattr: int (const char *, char *, size_t)
  4123. +smbc_lremovexattr: int (const char *, const char *)
  4124. +smbc_lseek: off_t (int, off_t, int)
  4125. +smbc_lseekdir: int (int, off_t)
  4126. +smbc_lsetxattr: int (const char *, const char *, const void *, size_t, int)
  4127. +smbc_mkdir: int (const char *, mode_t)
  4128. +smbc_new_context: SMBCCTX *(void)
  4129. +smbc_notify: int (int, smbc_bool, uint32_t, unsigned int, smbc_notify_callback_fn, void *)
  4130. +smbc_open: int (const char *, int, mode_t)
  4131. +smbc_open_print_job: int (const char *)
  4132. +smbc_opendir: int (const char *)
  4133. +smbc_option_get: void *(SMBCCTX *, char *)
  4134. +smbc_option_set: void (SMBCCTX *, char *, ...)
  4135. +smbc_print_file: int (const char *, const char *)
  4136. +smbc_read: ssize_t (int, void *, size_t)
  4137. +smbc_readdir: struct smbc_dirent *(unsigned int)
  4138. +smbc_readdirplus: const struct libsmb_file_info *(unsigned int)
  4139. +smbc_readdirplus2: const struct libsmb_file_info *(unsigned int, struct stat *)
  4140. +smbc_removexattr: int (const char *, const char *)
  4141. +smbc_rename: int (const char *, const char *)
  4142. +smbc_rmdir: int (const char *)
  4143. +smbc_setConfiguration: int (SMBCCTX *, const char *)
  4144. +smbc_setDebug: void (SMBCCTX *, int)
  4145. +smbc_setFunctionAddCachedServer: void (SMBCCTX *, smbc_add_cached_srv_fn)
  4146. +smbc_setFunctionAuthData: void (SMBCCTX *, smbc_get_auth_data_fn)
  4147. +smbc_setFunctionAuthDataWithContext: void (SMBCCTX *, smbc_get_auth_data_with_context_fn)
  4148. +smbc_setFunctionCheckServer: void (SMBCCTX *, smbc_check_server_fn)
  4149. +smbc_setFunctionChmod: void (SMBCCTX *, smbc_chmod_fn)
  4150. +smbc_setFunctionClose: void (SMBCCTX *, smbc_close_fn)
  4151. +smbc_setFunctionClosedir: void (SMBCCTX *, smbc_closedir_fn)
  4152. +smbc_setFunctionCreat: void (SMBCCTX *, smbc_creat_fn)
  4153. +smbc_setFunctionFstat: void (SMBCCTX *, smbc_fstat_fn)
  4154. +smbc_setFunctionFstatVFS: void (SMBCCTX *, smbc_fstatvfs_fn)
  4155. +smbc_setFunctionFstatdir: void (SMBCCTX *, smbc_fstatdir_fn)
  4156. +smbc_setFunctionFtruncate: void (SMBCCTX *, smbc_ftruncate_fn)
  4157. +smbc_setFunctionGetCachedServer: void (SMBCCTX *, smbc_get_cached_srv_fn)
  4158. +smbc_setFunctionGetdents: void (SMBCCTX *, smbc_getdents_fn)
  4159. +smbc_setFunctionGetxattr: void (SMBCCTX *, smbc_getxattr_fn)
  4160. +smbc_setFunctionListPrintJobs: void (SMBCCTX *, smbc_list_print_jobs_fn)
  4161. +smbc_setFunctionListxattr: void (SMBCCTX *, smbc_listxattr_fn)
  4162. +smbc_setFunctionLseek: void (SMBCCTX *, smbc_lseek_fn)
  4163. +smbc_setFunctionLseekdir: void (SMBCCTX *, smbc_lseekdir_fn)
  4164. +smbc_setFunctionMkdir: void (SMBCCTX *, smbc_mkdir_fn)
  4165. +smbc_setFunctionNotify: void (SMBCCTX *, smbc_notify_fn)
  4166. +smbc_setFunctionOpen: void (SMBCCTX *, smbc_open_fn)
  4167. +smbc_setFunctionOpenPrintJob: void (SMBCCTX *, smbc_open_print_job_fn)
  4168. +smbc_setFunctionOpendir: void (SMBCCTX *, smbc_opendir_fn)
  4169. +smbc_setFunctionPrintFile: void (SMBCCTX *, smbc_print_file_fn)
  4170. +smbc_setFunctionPurgeCachedServers: void (SMBCCTX *, smbc_purge_cached_fn)
  4171. +smbc_setFunctionRead: void (SMBCCTX *, smbc_read_fn)
  4172. +smbc_setFunctionReaddir: void (SMBCCTX *, smbc_readdir_fn)
  4173. +smbc_setFunctionReaddirPlus: void (SMBCCTX *, smbc_readdirplus_fn)
  4174. +smbc_setFunctionReaddirPlus2: void (SMBCCTX *, smbc_readdirplus2_fn)
  4175. +smbc_setFunctionRemoveCachedServer: void (SMBCCTX *, smbc_remove_cached_srv_fn)
  4176. +smbc_setFunctionRemoveUnusedServer: void (SMBCCTX *, smbc_remove_unused_server_fn)
  4177. +smbc_setFunctionRemovexattr: void (SMBCCTX *, smbc_removexattr_fn)
  4178. +smbc_setFunctionRename: void (SMBCCTX *, smbc_rename_fn)
  4179. +smbc_setFunctionRmdir: void (SMBCCTX *, smbc_rmdir_fn)
  4180. +smbc_setFunctionSetxattr: void (SMBCCTX *, smbc_setxattr_fn)
  4181. +smbc_setFunctionSplice: void (SMBCCTX *, smbc_splice_fn)
  4182. +smbc_setFunctionStat: void (SMBCCTX *, smbc_stat_fn)
  4183. +smbc_setFunctionStatVFS: void (SMBCCTX *, smbc_statvfs_fn)
  4184. +smbc_setFunctionTelldir: void (SMBCCTX *, smbc_telldir_fn)
  4185. +smbc_setFunctionUnlink: void (SMBCCTX *, smbc_unlink_fn)
  4186. +smbc_setFunctionUnlinkPrintJob: void (SMBCCTX *, smbc_unlink_print_job_fn)
  4187. +smbc_setFunctionUtimes: void (SMBCCTX *, smbc_utimes_fn)
  4188. +smbc_setFunctionWrite: void (SMBCCTX *, smbc_write_fn)
  4189. +smbc_setLogCallback: void (SMBCCTX *, void *, smbc_debug_callback_fn)
  4190. +smbc_setNetbiosName: void (SMBCCTX *, const char *)
  4191. +smbc_setOptionBrowseMaxLmbCount: void (SMBCCTX *, int)
  4192. +smbc_setOptionCaseSensitive: void (SMBCCTX *, smbc_bool)
  4193. +smbc_setOptionDebugToStderr: void (SMBCCTX *, smbc_bool)
  4194. +smbc_setOptionFallbackAfterKerberos: void (SMBCCTX *, smbc_bool)
  4195. +smbc_setOptionFullTimeNames: void (SMBCCTX *, smbc_bool)
  4196. +smbc_setOptionNoAutoAnonymousLogin: void (SMBCCTX *, smbc_bool)
  4197. +smbc_setOptionOneSharePerServer: void (SMBCCTX *, smbc_bool)
  4198. +smbc_setOptionOpenShareMode: void (SMBCCTX *, smbc_share_mode)
  4199. +smbc_setOptionProtocols: smbc_bool (SMBCCTX *, const char *, const char *)
  4200. +smbc_setOptionSmbEncryptionLevel: void (SMBCCTX *, smbc_smb_encrypt_level)
  4201. +smbc_setOptionUrlEncodeReaddirEntries: void (SMBCCTX *, smbc_bool)
  4202. +smbc_setOptionUseCCache: void (SMBCCTX *, smbc_bool)
  4203. +smbc_setOptionUseKerberos: void (SMBCCTX *, smbc_bool)
  4204. +smbc_setOptionUseNTHash: void (SMBCCTX *, smbc_bool)
  4205. +smbc_setOptionUserData: void (SMBCCTX *, void *)
  4206. +smbc_setPort: void (SMBCCTX *, uint16_t)
  4207. +smbc_setServerCacheData: void (SMBCCTX *, struct smbc_server_cache *)
  4208. +smbc_setTimeout: void (SMBCCTX *, int)
  4209. +smbc_setUser: void (SMBCCTX *, const char *)
  4210. +smbc_setWorkgroup: void (SMBCCTX *, const char *)
  4211. +smbc_set_context: SMBCCTX *(SMBCCTX *)
  4212. +smbc_set_credentials: void (const char *, const char *, const char *, smbc_bool, const char *)
  4213. +smbc_set_credentials_with_fallback: void (SMBCCTX *, const char *, const char *, const char *)
  4214. +smbc_setxattr: int (const char *, const char *, const void *, size_t, int)
  4215. +smbc_stat: int (const char *, struct stat *)
  4216. +smbc_statvfs: int (char *, struct statvfs *)
  4217. +smbc_telldir: off_t (int)
  4218. +smbc_unlink: int (const char *)
  4219. +smbc_unlink_print_job: int (const char *, int)
  4220. +smbc_urldecode: int (char *, char *, size_t)
  4221. +smbc_urlencode: int (char *, char *, int)
  4222. +smbc_utime: int (const char *, struct utimbuf *)
  4223. +smbc_utimes: int (const char *, struct timeval *)
  4224. +smbc_version: const char *(void)
  4225. +smbc_write: ssize_t (int, const void *, size_t)
  4226. diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c
  4227. index eaa0cdeca93..ea741f41c7d 100644
  4228. --- a/source3/libsmb/libsmb_context.c
  4229. +++ b/source3/libsmb/libsmb_context.c
  4230. @@ -171,7 +171,7 @@ smbc_new_context(void)
  4231. smbc_setOptionFullTimeNames(context, False);
  4232. smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE);
  4233. - smbc_setOptionSmbEncryptionLevel(context, SMBC_ENCRYPTLEVEL_NONE);
  4234. + smbc_setOptionSmbEncryptionLevel(context, SMBC_ENCRYPTLEVEL_DEFAULT);
  4235. smbc_setOptionUseCCache(context, True);
  4236. smbc_setOptionCaseSensitive(context, False);
  4237. smbc_setOptionBrowseMaxLmbCount(context, 3); /* # LMBs to query */
  4238. @@ -474,6 +474,8 @@ smbc_option_get(SMBCCTX *context,
  4239. } else if (strcmp(option_name, "smb_encrypt_level") == 0) {
  4240. switch(smbc_getOptionSmbEncryptionLevel(context))
  4241. {
  4242. + case SMBC_ENCRYPTLEVEL_DEFAULT:
  4243. + return discard_const_p(void, "default");
  4244. case 0:
  4245. return discard_const_p(void, "none");
  4246. case 1:
  4247. diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
  4248. index 33dc8419deb..eb58d7c6ac9 100644
  4249. --- a/source3/libsmb/libsmb_server.c
  4250. +++ b/source3/libsmb/libsmb_server.c
  4251. @@ -284,6 +284,29 @@ static struct cli_credentials *SMBC_auth_credentials(TALLOC_CTX *mem_ctx,
  4252. return NULL;
  4253. }
  4254. + switch (context->internal->smb_encryption_level) {
  4255. + case SMBC_ENCRYPTLEVEL_DEFAULT:
  4256. + /* Use the config option */
  4257. + break;
  4258. + case SMBC_ENCRYPTLEVEL_NONE:
  4259. + cli_credentials_set_smb_encryption(creds,
  4260. + SMB_ENCRYPTION_OFF,
  4261. + CRED_SPECIFIED);
  4262. + break;
  4263. + case SMBC_ENCRYPTLEVEL_REQUEST:
  4264. + cli_credentials_set_smb_encryption(creds,
  4265. + SMB_ENCRYPTION_DESIRED,
  4266. + CRED_SPECIFIED);
  4267. + break;
  4268. + case SMBC_ENCRYPTLEVEL_REQUIRE:
  4269. + default:
  4270. + cli_credentials_set_smb_encryption(creds,
  4271. + SMB_ENCRYPTION_REQUIRED,
  4272. + CRED_SPECIFIED);
  4273. + break;
  4274. + }
  4275. +
  4276. +
  4277. return creds;
  4278. }
  4279. @@ -625,30 +648,6 @@ SMBC_server_internal(TALLOC_CTX *ctx,
  4280. smbXcli_tcon_set_fs_attributes(tcon, fs_attrs);
  4281. }
  4282. - if (context->internal->smb_encryption_level) {
  4283. - /* Attempt encryption. */
  4284. - status = cli_cm_force_encryption_creds(c,
  4285. - creds,
  4286. - share);
  4287. - if (!NT_STATUS_IS_OK(status)) {
  4288. -
  4289. - /*
  4290. - * context->smb_encryption_level == 1
  4291. - * means don't fail if encryption can't be negotiated,
  4292. - * == 2 means fail if encryption can't be negotiated.
  4293. - */
  4294. -
  4295. - DEBUG(4,(" SMB encrypt failed\n"));
  4296. -
  4297. - if (context->internal->smb_encryption_level == 2) {
  4298. - cli_shutdown(c);
  4299. - errno = EPERM;
  4300. - return NULL;
  4301. - }
  4302. - }
  4303. - DEBUG(4,(" SMB encrypt ok\n"));
  4304. - }
  4305. -
  4306. /*
  4307. * Ok, we have got a nice connection
  4308. * Let's allocate a server structure.
  4309. @@ -825,31 +824,6 @@ SMBC_attr_server(TALLOC_CTX *ctx,
  4310. }
  4311. talloc_steal(ipc_cli, creds);
  4312. - if (context->internal->smb_encryption_level) {
  4313. - /* Attempt encryption. */
  4314. - nt_status = cli_cm_force_encryption_creds(ipc_cli,
  4315. - creds,
  4316. - "IPC$");
  4317. - if (!NT_STATUS_IS_OK(nt_status)) {
  4318. -
  4319. - /*
  4320. - * context->smb_encryption_level ==
  4321. - * 1 means don't fail if encryption can't be
  4322. - * negotiated, == 2 means fail if encryption
  4323. - * can't be negotiated.
  4324. - */
  4325. -
  4326. - DEBUG(4,(" SMB encrypt failed on IPC$\n"));
  4327. -
  4328. - if (context->internal->smb_encryption_level == 2) {
  4329. - cli_shutdown(ipc_cli);
  4330. - errno = EPERM;
  4331. - return NULL;
  4332. - }
  4333. - }
  4334. - DEBUG(4,(" SMB encrypt ok on IPC$\n"));
  4335. - }
  4336. -
  4337. ipc_srv = SMB_MALLOC_P(SMBCSRV);
  4338. if (!ipc_srv) {
  4339. errno = ENOMEM;
  4340. diff --git a/source3/libsmb/wscript b/source3/libsmb/wscript
  4341. index ec4a516b2ee..61503d0a98b 100644
  4342. --- a/source3/libsmb/wscript
  4343. +++ b/source3/libsmb/wscript
  4344. @@ -26,5 +26,5 @@ def build(bld):
  4345. public_headers='../include/libsmbclient.h',
  4346. abi_directory='ABI',
  4347. abi_match='smbc_*',
  4348. - vnum='0.6.0',
  4349. + vnum='0.7.0',
  4350. pc_files='smbclient.pc')
  4351. --
  4352. 2.29.2
  4353. From eaa0bdc5931b82f9adbb65070252208be26a9d28 Mon Sep 17 00:00:00 2001
  4354. From: Andreas Schneider <asn@samba.org>
  4355. Date: Wed, 10 Jun 2020 12:43:33 +0200
  4356. Subject: [PATCH 037/104] s3:client: Remove unused smb encryption code
  4357. Signed-off-by: Andreas Schneider <asn@samba.org>
  4358. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4359. ---
  4360. source3/client/smbspool.c | 10 ----------
  4361. 1 file changed, 10 deletions(-)
  4362. diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c
  4363. index f56dc323b6e..16a8d44c069 100644
  4364. --- a/source3/client/smbspool.c
  4365. +++ b/source3/client/smbspool.c
  4366. @@ -584,16 +584,6 @@ smb_complete_connection(struct cli_state **output_cli,
  4367. return nt_status;
  4368. }
  4369. -#if 0
  4370. - /* Need to work out how to specify this on the URL. */
  4371. - if (smb_encrypt) {
  4372. - if (!cli_cm_force_encryption_creds(cli, creds, share)) {
  4373. - fprintf(stderr, "ERROR: encryption setup failed\n");
  4374. - cli_shutdown(cli);
  4375. - return NULL;
  4376. - }
  4377. - }
  4378. -#endif
  4379. *output_cli = cli;
  4380. return NT_STATUS_OK;
  4381. --
  4382. 2.29.2
  4383. From 63179da4a51fefc5d938339360d579f725875389 Mon Sep 17 00:00:00 2001
  4384. From: Andreas Schneider <asn@samba.org>
  4385. Date: Wed, 10 Jun 2020 12:47:05 +0200
  4386. Subject: [PATCH 038/104] s3:utils: Remove obsolete force encryption from
  4387. smbacls
  4388. Signed-off-by: Andreas Schneider <asn@samba.org>
  4389. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4390. ---
  4391. source3/utils/smbcacls.c | 10 ----------
  4392. 1 file changed, 10 deletions(-)
  4393. diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
  4394. index 5983ebbd0a5..8fd9fcc5780 100644
  4395. --- a/source3/utils/smbcacls.c
  4396. +++ b/source3/utils/smbcacls.c
  4397. @@ -784,16 +784,6 @@ static struct cli_state *connect_one(const struct user_auth_info *auth_info,
  4398. return NULL;
  4399. }
  4400. - if (get_cmdline_auth_info_smb_encrypt(auth_info)) {
  4401. - nt_status = cli_cm_force_encryption_creds(c,
  4402. - get_cmdline_auth_info_creds(auth_info),
  4403. - share);
  4404. - if (!NT_STATUS_IS_OK(nt_status)) {
  4405. - cli_shutdown(c);
  4406. - c = NULL;
  4407. - }
  4408. - }
  4409. -
  4410. return c;
  4411. }
  4412. --
  4413. 2.29.2
  4414. From f113666b62c0fbe960f9ac22aea63241b56ffc61 Mon Sep 17 00:00:00 2001
  4415. From: Andreas Schneider <asn@samba.org>
  4416. Date: Wed, 10 Jun 2020 12:48:18 +0200
  4417. Subject: [PATCH 039/104] s3:utils: Remove obsolete force encryption from
  4418. mdfind
  4419. Signed-off-by: Andreas Schneider <asn@samba.org>
  4420. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4421. ---
  4422. source3/utils/mdfind.c | 7 -------
  4423. 1 file changed, 7 deletions(-)
  4424. diff --git a/source3/utils/mdfind.c b/source3/utils/mdfind.c
  4425. index 2ac4fde7daf..ef2657e4fa5 100644
  4426. --- a/source3/utils/mdfind.c
  4427. +++ b/source3/utils/mdfind.c
  4428. @@ -159,13 +159,6 @@ int main(int argc, char **argv)
  4429. goto fail;
  4430. }
  4431. - if (get_cmdline_auth_info_smb_encrypt(auth)) {
  4432. - status = cli_cm_force_encryption_creds(cli, creds, "IPC$");
  4433. - if (!NT_STATUS_IS_OK(status)) {
  4434. - goto fail;
  4435. - }
  4436. - }
  4437. -
  4438. status = cli_rpc_pipe_open_noauth_transport(cli,
  4439. NCACN_NP,
  4440. &ndr_table_mdssvc,
  4441. --
  4442. 2.29.2
  4443. From 4f3770237e1a3d41c725560d9e5c14786b98d2f9 Mon Sep 17 00:00:00 2001
  4444. From: Andreas Schneider <asn@samba.org>
  4445. Date: Wed, 10 Jun 2020 12:49:28 +0200
  4446. Subject: [PATCH 040/104] s3:utils: Remove obsolete force encryption from
  4447. smbcquotas
  4448. Signed-off-by: Andreas Schneider <asn@samba.org>
  4449. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4450. ---
  4451. source3/utils/smbcquotas.c | 11 -----------
  4452. 1 file changed, 11 deletions(-)
  4453. diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c
  4454. index fea066ce468..4ceac7b3ab0 100644
  4455. --- a/source3/utils/smbcquotas.c
  4456. +++ b/source3/utils/smbcquotas.c
  4457. @@ -533,17 +533,6 @@ static struct cli_state *connect_one(const char *share)
  4458. return NULL;
  4459. }
  4460. - if (get_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info())) {
  4461. - nt_status = cli_cm_force_encryption_creds(c,
  4462. - get_cmdline_auth_info_creds(
  4463. - popt_get_cmdline_auth_info()),
  4464. - share);
  4465. - if (!NT_STATUS_IS_OK(nt_status)) {
  4466. - cli_shutdown(c);
  4467. - return NULL;
  4468. - }
  4469. - }
  4470. -
  4471. return c;
  4472. }
  4473. --
  4474. 2.29.2
  4475. From b897f3360dae5737d646dbce9f7571b1cfb070b0 Mon Sep 17 00:00:00 2001
  4476. From: Andreas Schneider <asn@samba.org>
  4477. Date: Wed, 10 Jun 2020 12:51:18 +0200
  4478. Subject: [PATCH 041/104] s3:rpcclient: Remove obsolete force encryption from
  4479. rpcclient
  4480. Signed-off-by: Andreas Schneider <asn@samba.org>
  4481. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4482. ---
  4483. source3/rpcclient/rpcclient.c | 11 -----------
  4484. 1 file changed, 11 deletions(-)
  4485. diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
  4486. index 2ead6cc7ba5..575a42ebf70 100644
  4487. --- a/source3/rpcclient/rpcclient.c
  4488. +++ b/source3/rpcclient/rpcclient.c
  4489. @@ -1214,17 +1214,6 @@ out_free:
  4490. goto done;
  4491. }
  4492. - if (get_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info())) {
  4493. - nt_status = cli_cm_force_encryption_creds(cli,
  4494. - get_cmdline_auth_info_creds(
  4495. - popt_get_cmdline_auth_info()),
  4496. - "IPC$");
  4497. - if (!NT_STATUS_IS_OK(nt_status)) {
  4498. - result = 1;
  4499. - goto done;
  4500. - }
  4501. - }
  4502. -
  4503. #if 0 /* COMMENT OUT FOR TESTING */
  4504. memset(cmdline_auth_info.password,'X',sizeof(cmdline_auth_info.password));
  4505. #endif
  4506. --
  4507. 2.29.2
  4508. From b01458095b5e815c09eb71fb597598e9f34ee342 Mon Sep 17 00:00:00 2001
  4509. From: Andreas Schneider <asn@samba.org>
  4510. Date: Mon, 6 Jul 2020 10:58:36 +0200
  4511. Subject: [PATCH 042/104] examples: Remove obsolete force encryption from
  4512. smb2mount
  4513. Signed-off-by: Andreas Schneider <asn@samba.org>
  4514. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4515. ---
  4516. examples/fuse/smb2mount.c | 11 -----------
  4517. 1 file changed, 11 deletions(-)
  4518. diff --git a/examples/fuse/smb2mount.c b/examples/fuse/smb2mount.c
  4519. index 6206c3a9701..c64be573462 100644
  4520. --- a/examples/fuse/smb2mount.c
  4521. +++ b/examples/fuse/smb2mount.c
  4522. @@ -44,17 +44,6 @@ static struct cli_state *connect_one(const struct user_auth_info *auth_info,
  4523. return NULL;
  4524. }
  4525. - if (get_cmdline_auth_info_smb_encrypt(auth_info)) {
  4526. - nt_status = cli_cm_force_encryption_creds(
  4527. - c,
  4528. - get_cmdline_auth_info_creds(auth_info),
  4529. - share);
  4530. - if (!NT_STATUS_IS_OK(nt_status)) {
  4531. - cli_shutdown(c);
  4532. - c = NULL;
  4533. - }
  4534. - }
  4535. -
  4536. return c;
  4537. }
  4538. --
  4539. 2.29.2
  4540. From 66eb5d32234f2e7700a43504158507a6f828c50b Mon Sep 17 00:00:00 2001
  4541. From: Andreas Schneider <asn@samba.org>
  4542. Date: Mon, 6 Jul 2020 11:05:59 +0200
  4543. Subject: [PATCH 043/104] s3:libsmb: Make cli_cm_force_encryption_creds()
  4544. static
  4545. Signed-off-by: Andreas Schneider <asn@samba.org>
  4546. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4547. ---
  4548. source3/libsmb/clidfs.c | 6 +++---
  4549. source3/libsmb/proto.h | 3 ---
  4550. 2 files changed, 3 insertions(+), 6 deletions(-)
  4551. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  4552. index 4495a027830..aff998f6187 100644
  4553. --- a/source3/libsmb/clidfs.c
  4554. +++ b/source3/libsmb/clidfs.c
  4555. @@ -43,9 +43,9 @@
  4556. Ensure a connection is encrypted.
  4557. ********************************************************************/
  4558. -NTSTATUS cli_cm_force_encryption_creds(struct cli_state *c,
  4559. - struct cli_credentials *creds,
  4560. - const char *sharename)
  4561. +static NTSTATUS cli_cm_force_encryption_creds(struct cli_state *c,
  4562. + struct cli_credentials *creds,
  4563. + const char *sharename)
  4564. {
  4565. uint16_t major, minor;
  4566. uint32_t caplow, caphigh;
  4567. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  4568. index 850cf12c8a6..eeabcaa7463 100644
  4569. --- a/source3/libsmb/proto.h
  4570. +++ b/source3/libsmb/proto.h
  4571. @@ -123,9 +123,6 @@ struct cli_state *get_ipc_connect_master_ip(TALLOC_CTX *ctx,
  4572. /* The following definitions come from libsmb/clidfs.c */
  4573. -NTSTATUS cli_cm_force_encryption_creds(struct cli_state *c,
  4574. - struct cli_credentials *creds,
  4575. - const char *sharename);
  4576. NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  4577. struct cli_state *referring_cli,
  4578. const char *server,
  4579. --
  4580. 2.29.2
  4581. From 3b8e9646f0a79e2cbb977b8c1d0fc5f28a9b7490 Mon Sep 17 00:00:00 2001
  4582. From: Andreas Schneider <asn@samba.org>
  4583. Date: Thu, 13 Aug 2020 16:16:55 +0200
  4584. Subject: [PATCH 044/104] s4:libcli: Return NTSTATUS errors for
  4585. smb_composite_connect_send()
  4586. Signed-off-by: Andreas Schneider <asn@samba.org>
  4587. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4588. ---
  4589. source4/libcli/smb_composite/connect.c | 40 +++++++++++++++++++-------
  4590. 1 file changed, 29 insertions(+), 11 deletions(-)
  4591. diff --git a/source4/libcli/smb_composite/connect.c b/source4/libcli/smb_composite/connect.c
  4592. index 582d43ef173..ad50ae0ac81 100644
  4593. --- a/source4/libcli/smb_composite/connect.c
  4594. +++ b/source4/libcli/smb_composite/connect.c
  4595. @@ -420,15 +420,25 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
  4596. struct connect_state *state;
  4597. c = talloc_zero(mem_ctx, struct composite_context);
  4598. - if (c == NULL) goto failed;
  4599. -
  4600. - c->event_ctx = event_ctx;
  4601. - if (c->event_ctx == NULL) goto failed;
  4602. + if (c == NULL) {
  4603. + goto nomem;
  4604. + }
  4605. state = talloc_zero(c, struct connect_state);
  4606. - if (state == NULL) goto failed;
  4607. + if (state == NULL) {
  4608. + goto nomem;
  4609. + }
  4610. +
  4611. + c->event_ctx = event_ctx;
  4612. + if (c->event_ctx == NULL) {
  4613. + composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
  4614. + return c;
  4615. + }
  4616. - if (io->in.gensec_settings == NULL) goto failed;
  4617. + if (io->in.gensec_settings == NULL) {
  4618. + composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
  4619. + return c;
  4620. + }
  4621. state->io = io;
  4622. c->state = COMPOSITE_STATE_IN_PROGRESS;
  4623. @@ -449,12 +459,14 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
  4624. &io->in.options,
  4625. &state->transport);
  4626. if (!NT_STATUS_IS_OK(status)) {
  4627. - goto failed;
  4628. + composite_error(c, status);
  4629. + return c;
  4630. }
  4631. status = connect_send_session(c, io);
  4632. if (!NT_STATUS_IS_OK(status)) {
  4633. - goto failed;
  4634. + composite_error(c, status);
  4635. + return c;
  4636. }
  4637. return c;
  4638. @@ -468,15 +480,18 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
  4639. io->in.socket_options,
  4640. &state->calling,
  4641. &state->called);
  4642. - if (state->creq == NULL) goto failed;
  4643. + if (state->creq == NULL) {
  4644. + composite_error(c, NT_STATUS_NO_MEMORY);
  4645. + return c;
  4646. + }
  4647. state->stage = CONNECT_SOCKET;
  4648. state->creq->async.private_data = c;
  4649. state->creq->async.fn = composite_handler;
  4650. return c;
  4651. -failed:
  4652. - talloc_free(c);
  4653. +nomem:
  4654. + TALLOC_FREE(c);
  4655. return NULL;
  4656. }
  4657. @@ -506,5 +521,8 @@ NTSTATUS smb_composite_connect(struct smb_composite_connect *io, TALLOC_CTX *mem
  4658. struct tevent_context *ev)
  4659. {
  4660. struct composite_context *c = smb_composite_connect_send(io, mem_ctx, resolve_ctx, ev);
  4661. + if (c == NULL) {
  4662. + return NT_STATUS_NO_MEMORY;
  4663. + }
  4664. return smb_composite_connect_recv(c, mem_ctx);
  4665. }
  4666. --
  4667. 2.29.2
  4668. From cecd31a2451e20046c0202837269fb533e3118a7 Mon Sep 17 00:00:00 2001
  4669. From: Andreas Schneider <asn@samba.org>
  4670. Date: Tue, 7 Jul 2020 12:54:26 +0200
  4671. Subject: [PATCH 045/104] s4:libcli: Return if encryption is requested for SMB1
  4672. Signed-off-by: Andreas Schneider <asn@samba.org>
  4673. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4674. ---
  4675. source4/libcli/smb_composite/sesssetup.c | 7 +++++++
  4676. 1 file changed, 7 insertions(+)
  4677. diff --git a/source4/libcli/smb_composite/sesssetup.c b/source4/libcli/smb_composite/sesssetup.c
  4678. index 6ee4929e8d7..51e121bdce6 100644
  4679. --- a/source4/libcli/smb_composite/sesssetup.c
  4680. +++ b/source4/libcli/smb_composite/sesssetup.c
  4681. @@ -620,10 +620,17 @@ struct composite_context *smb_composite_sesssetup_send(struct smbcli_session *se
  4682. struct composite_context *c;
  4683. struct sesssetup_state *state;
  4684. NTSTATUS status;
  4685. + enum smb_encryption_setting encryption_state =
  4686. + cli_credentials_get_smb_encryption(io->in.credentials);
  4687. c = composite_create(session, session->transport->ev);
  4688. if (c == NULL) return NULL;
  4689. + if (encryption_state > SMB_ENCRYPTION_DESIRED) {
  4690. + composite_error(c, NT_STATUS_PROTOCOL_NOT_SUPPORTED);
  4691. + return c;
  4692. + }
  4693. +
  4694. state = talloc_zero(c, struct sesssetup_state);
  4695. if (composite_nomem(state, c)) return c;
  4696. c->private_data = state;
  4697. --
  4698. 2.29.2
  4699. From ed5b2f36fec30ae7b277620cb82f01a07f027e0e Mon Sep 17 00:00:00 2001
  4700. From: Andreas Schneider <asn@samba.org>
  4701. Date: Tue, 7 Jul 2020 12:29:39 +0200
  4702. Subject: [PATCH 046/104] s3:libcli: Split out smb2_connect_tcon_start()
  4703. Signed-off-by: Andreas Schneider <asn@samba.org>
  4704. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4705. ---
  4706. source4/libcli/smb2/connect.c | 13 ++++++++++++-
  4707. 1 file changed, 12 insertions(+), 1 deletion(-)
  4708. diff --git a/source4/libcli/smb2/connect.c b/source4/libcli/smb2/connect.c
  4709. index 6fc3993a4e8..95ff05eac8f 100644
  4710. --- a/source4/libcli/smb2/connect.c
  4711. +++ b/source4/libcli/smb2/connect.c
  4712. @@ -237,6 +237,7 @@ static void smb2_connect_session_start(struct tevent_req *req)
  4713. tevent_req_set_callback(subreq, smb2_connect_session_done, req);
  4714. }
  4715. +static void smb2_connect_tcon_start(struct tevent_req *req);
  4716. static void smb2_connect_tcon_done(struct tevent_req *subreq);
  4717. static void smb2_connect_session_done(struct tevent_req *subreq)
  4718. @@ -248,7 +249,6 @@ static void smb2_connect_session_done(struct tevent_req *subreq)
  4719. tevent_req_data(req,
  4720. struct smb2_connect_state);
  4721. NTSTATUS status;
  4722. - uint32_t timeout_msec;
  4723. status = smb2_session_setup_spnego_recv(subreq);
  4724. TALLOC_FREE(subreq);
  4725. @@ -289,6 +289,17 @@ static void smb2_connect_session_done(struct tevent_req *subreq)
  4726. return;
  4727. }
  4728. + smb2_connect_tcon_start(req);
  4729. +}
  4730. +
  4731. +static void smb2_connect_tcon_start(struct tevent_req *req)
  4732. +{
  4733. + struct smb2_connect_state *state =
  4734. + tevent_req_data(req,
  4735. + struct smb2_connect_state);
  4736. + struct tevent_req *subreq = NULL;
  4737. + uint32_t timeout_msec;
  4738. +
  4739. timeout_msec = state->transport->options.request_timeout * 1000;
  4740. subreq = smb2cli_tcon_send(state, state->ev,
  4741. --
  4742. 2.29.2
  4743. From 7eb81b6448064d8beee3972471723b90ea9307ec Mon Sep 17 00:00:00 2001
  4744. From: Andreas Schneider <asn@samba.org>
  4745. Date: Tue, 7 Jul 2020 12:44:26 +0200
  4746. Subject: [PATCH 047/104] s4:libcli: Add smb2_connect_enc_start()
  4747. Signed-off-by: Andreas Schneider <asn@samba.org>
  4748. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4749. ---
  4750. source4/libcli/smb2/connect.c | 38 +++++++++++++++++++++++++++++++++++
  4751. 1 file changed, 38 insertions(+)
  4752. diff --git a/source4/libcli/smb2/connect.c b/source4/libcli/smb2/connect.c
  4753. index 95ff05eac8f..3a3ecdf20e8 100644
  4754. --- a/source4/libcli/smb2/connect.c
  4755. +++ b/source4/libcli/smb2/connect.c
  4756. @@ -237,6 +237,7 @@ static void smb2_connect_session_start(struct tevent_req *req)
  4757. tevent_req_set_callback(subreq, smb2_connect_session_done, req);
  4758. }
  4759. +static void smb2_connect_enc_start(struct tevent_req *req);
  4760. static void smb2_connect_tcon_start(struct tevent_req *req);
  4761. static void smb2_connect_tcon_done(struct tevent_req *subreq);
  4762. @@ -289,6 +290,43 @@ static void smb2_connect_session_done(struct tevent_req *subreq)
  4763. return;
  4764. }
  4765. + smb2_connect_enc_start(req);
  4766. +}
  4767. +
  4768. +static void smb2_connect_enc_start(struct tevent_req *req)
  4769. +{
  4770. + struct smb2_connect_state *state =
  4771. + tevent_req_data(req,
  4772. + struct smb2_connect_state);
  4773. + enum smb_encryption_setting encryption_state =
  4774. + cli_credentials_get_smb_encryption(state->credentials);
  4775. + NTSTATUS status;
  4776. +
  4777. + if (encryption_state < SMB_ENCRYPTION_DESIRED) {
  4778. + smb2_connect_tcon_start(req);
  4779. + return;
  4780. + }
  4781. +
  4782. + status = smb2cli_session_encryption_on(state->session->smbXcli);
  4783. + if (!NT_STATUS_IS_OK(status)) {
  4784. + if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
  4785. + if (encryption_state < SMB_ENCRYPTION_REQUIRED) {
  4786. + smb2_connect_tcon_start(req);
  4787. + return;
  4788. + }
  4789. +
  4790. + DBG_ERR("Encryption required and server doesn't support "
  4791. + "SMB3 encryption - failing connect\n");
  4792. + tevent_req_nterror(req, status);
  4793. + return;
  4794. + }
  4795. +
  4796. + DBG_ERR("Encryption required and setup failed with error %s.\n",
  4797. + nt_errstr(status));
  4798. + tevent_req_nterror(req, NT_STATUS_PROTOCOL_NOT_SUPPORTED);
  4799. + return;
  4800. + }
  4801. +
  4802. smb2_connect_tcon_start(req);
  4803. }
  4804. --
  4805. 2.29.2
  4806. From b5b0c28d597d8ef98b632e4616d2d2cdaaad37a9 Mon Sep 17 00:00:00 2001
  4807. From: Andreas Schneider <asn@samba.org>
  4808. Date: Fri, 24 Jul 2020 10:18:52 +0200
  4809. Subject: [PATCH 048/104] s4:libcli: Require signing for SMB encryption
  4810. Signed-off-by: Andreas Schneider <asn@samba.org>
  4811. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4812. ---
  4813. source4/libcli/smb2/connect.c | 9 ++++++++-
  4814. 1 file changed, 8 insertions(+), 1 deletion(-)
  4815. diff --git a/source4/libcli/smb2/connect.c b/source4/libcli/smb2/connect.c
  4816. index 3a3ecdf20e8..9540704491e 100644
  4817. --- a/source4/libcli/smb2/connect.c
  4818. +++ b/source4/libcli/smb2/connect.c
  4819. @@ -31,6 +31,7 @@
  4820. #include "param/param.h"
  4821. #include "auth/credentials/credentials.h"
  4822. #include "../libcli/smb/smbXcli_base.h"
  4823. +#include "smb2_constants.h"
  4824. struct smb2_connect_state {
  4825. struct tevent_context *ev;
  4826. @@ -76,6 +77,8 @@ struct tevent_req *smb2_connect_send(TALLOC_CTX *mem_ctx,
  4827. struct smb2_connect_state *state;
  4828. struct composite_context *creq;
  4829. static const char *default_ports[] = { "445", "139", NULL };
  4830. + enum smb_encryption_setting encryption_state =
  4831. + cli_credentials_get_smb_encryption(credentials);
  4832. req = tevent_req_create(mem_ctx, &state,
  4833. struct smb2_connect_state);
  4834. @@ -99,6 +102,10 @@ struct tevent_req *smb2_connect_send(TALLOC_CTX *mem_ctx,
  4835. state->ports = default_ports;
  4836. }
  4837. + if (encryption_state >= SMB_ENCRYPTION_DESIRED) {
  4838. + state->options.signing = SMB_SIGNING_REQUIRED;
  4839. + }
  4840. +
  4841. make_nbt_name_client(&state->calling,
  4842. cli_credentials_get_workstation(credentials));
  4843. @@ -116,7 +123,7 @@ struct tevent_req *smb2_connect_send(TALLOC_CTX *mem_ctx,
  4844. status = smb2_transport_raw_init(state, ev,
  4845. existing_conn,
  4846. - options,
  4847. + &state->options,
  4848. &state->transport);
  4849. if (tevent_req_nterror(req, status)) {
  4850. return tevent_req_post(req, ev);
  4851. --
  4852. 2.29.2
  4853. From ee95e01cdc3917fc371b3145dcbe6d23ffc054b1 Mon Sep 17 00:00:00 2001
  4854. From: Andreas Schneider <asn@samba.org>
  4855. Date: Tue, 7 Jul 2020 14:27:07 +0200
  4856. Subject: [PATCH 049/104] python:tests: Add test for SMB encrypted DCERPC
  4857. connection
  4858. Signed-off-by: Andreas Schneider <asn@samba.org>
  4859. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  4860. Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
  4861. Autobuild-Date(master): Wed Aug 19 17:46:28 UTC 2020 on sn-devel-184
  4862. ---
  4863. python/samba/tests/dcerpc/binding.py | 82 ++++++++++++++++++++++++++++
  4864. selftest/tests.py | 1 +
  4865. 2 files changed, 83 insertions(+)
  4866. create mode 100644 python/samba/tests/dcerpc/binding.py
  4867. diff --git a/python/samba/tests/dcerpc/binding.py b/python/samba/tests/dcerpc/binding.py
  4868. new file mode 100644
  4869. index 00000000000..8e0d6a5ef0a
  4870. --- /dev/null
  4871. +++ b/python/samba/tests/dcerpc/binding.py
  4872. @@ -0,0 +1,82 @@
  4873. +#
  4874. +# Unix SMB/CIFS implementation.
  4875. +# Copyright (c) 2020 Andreas Schneider <asn@samba.org>
  4876. +#
  4877. +# This program is free software; you can redistribute it and/or modify
  4878. +# it under the terms of the GNU General Public License as published by
  4879. +# the Free Software Foundation; either version 3 of the License, or
  4880. +# (at your option) any later version.
  4881. +#
  4882. +# This program is distributed in the hope that it will be useful,
  4883. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  4884. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4885. +# GNU General Public License for more details.
  4886. +#
  4887. +# You should have received a copy of the GNU General Public License
  4888. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  4889. +#
  4890. +
  4891. +"""Tests for samba.dcerpc., credentials and binding strings"""
  4892. +
  4893. +import samba.tests
  4894. +from samba.tests import RpcInterfaceTestCase, TestCase
  4895. +from samba.dcerpc import lsa
  4896. +import samba.dcerpc.security as security
  4897. +from samba.credentials import Credentials, SMB_ENCRYPTION_REQUIRED
  4898. +from samba import NTSTATUSError
  4899. +
  4900. +class RpcBindingTests(RpcInterfaceTestCase):
  4901. + def setUp(self):
  4902. + super(RpcBindingTests, self).setUp()
  4903. +
  4904. + def get_user_creds(self):
  4905. + c = Credentials()
  4906. + c.guess()
  4907. + domain = samba.tests.env_get_var_value('DOMAIN')
  4908. + username = samba.tests.env_get_var_value('USERNAME')
  4909. + password = samba.tests.env_get_var_value('PASSWORD')
  4910. + c.set_domain(domain)
  4911. + c.set_username(username)
  4912. + c.set_password(password)
  4913. + return c
  4914. +
  4915. + def test_smb3_dcerpc_encryption(self):
  4916. + creds = self.get_user_creds()
  4917. + creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  4918. +
  4919. + lp = self.get_loadparm()
  4920. + lp.set('client ipc max protocol', 'SMB3')
  4921. + lp.set('client ipc min protocol', 'SMB3')
  4922. +
  4923. + binding_string = ("ncacn_np:%s" % (samba.tests.env_get_var_value('SERVER')))
  4924. + lsa_conn = lsa.lsarpc(binding_string, lp, creds)
  4925. +
  4926. + objectAttr = lsa.ObjectAttribute()
  4927. + objectAttr.sec_qos = lsa.QosInfo()
  4928. +
  4929. + pol_handle = lsa_conn.OpenPolicy2('',
  4930. + objectAttr,
  4931. + security.SEC_FLAG_MAXIMUM_ALLOWED)
  4932. + self.assertIsNotNone(pol_handle)
  4933. +
  4934. + def test_smb2_dcerpc_encryption(self):
  4935. + creds = self.get_user_creds()
  4936. + creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  4937. +
  4938. + lp = self.get_loadparm()
  4939. + lp.set('client ipc max protocol', 'SMB2')
  4940. + lp.set('client ipc min protocol', 'SMB2')
  4941. +
  4942. + binding_string = ("ncacn_np:%s" % (samba.tests.env_get_var_value('SERVER')))
  4943. + self.assertRaises(NTSTATUSError, lsa.lsarpc, binding_string, lp, creds)
  4944. +
  4945. + def test_smb1_dcerpc_encryption(self):
  4946. + creds = self.get_user_creds()
  4947. + creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  4948. +
  4949. + lp = self.get_loadparm()
  4950. + lp.set('client ipc max protocol', 'NT1')
  4951. + lp.set('client ipc min protocol', 'NT1')
  4952. +
  4953. + binding_string = ("ncacn_np:%s" % (samba.tests.env_get_var_value('SERVER')))
  4954. + self.assertRaises(NTSTATUSError, lsa.lsarpc, binding_string, lp, creds)
  4955. diff --git a/selftest/tests.py b/selftest/tests.py
  4956. index 20981754db4..adcb5b53189 100644
  4957. --- a/selftest/tests.py
  4958. +++ b/selftest/tests.py
  4959. @@ -92,6 +92,7 @@ planpythontestsuite(
  4960. extra_path=[os.path.join(samba4srcdir, "..", "buildtools"),
  4961. os.path.join(samba4srcdir, "..", "third_party", "waf")])
  4962. planpythontestsuite("fileserver", "samba.tests.smbd_fuzztest")
  4963. +planpythontestsuite("nt4_dc_smb1", "samba.tests.dcerpc.binding")
  4964. def cmdline(script, *args):
  4965. --
  4966. 2.29.2
  4967. From fefa1d0236c67b2a93328eb9e0eac21da22235b2 Mon Sep 17 00:00:00 2001
  4968. From: Stefan Metzmacher <metze@samba.org>
  4969. Date: Fri, 4 Sep 2020 10:47:54 +0200
  4970. Subject: [PATCH 050/104] auth:gensec: Add gensec_security_sasl_names()
  4971. Pair-Programmed-With: Andreas Schneider <asn@samba.org>
  4972. Signed-off-by: Andreas Schneider <asn@samba.org>
  4973. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  4974. (cherry picked from commit b34e8dc8982b625d946e2ac8794ee41311bc41c2)
  4975. ---
  4976. auth/gensec/gensec.h | 2 +
  4977. auth/gensec/gensec_start.c | 87 ++++++++++++++++++++++++++++++++++++++
  4978. 2 files changed, 89 insertions(+)
  4979. diff --git a/auth/gensec/gensec.h b/auth/gensec/gensec.h
  4980. index d424067d02c..fe26fff171a 100644
  4981. --- a/auth/gensec/gensec.h
  4982. +++ b/auth/gensec/gensec.h
  4983. @@ -308,6 +308,8 @@ const struct gensec_security_ops **gensec_use_kerberos_mechs(TALLOC_CTX *mem_ctx
  4984. NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
  4985. const char *sasl_name);
  4986. +const char **gensec_security_sasl_names(struct gensec_security *gensec_security,
  4987. + TALLOC_CTX *mem_ctx);
  4988. int gensec_setting_int(struct gensec_settings *settings, const char *mechanism, const char *name, int default_value);
  4989. bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism, const char *name, bool default_value);
  4990. diff --git a/auth/gensec/gensec_start.c b/auth/gensec/gensec_start.c
  4991. index d2d62d6652e..4eb45643714 100644
  4992. --- a/auth/gensec/gensec_start.c
  4993. +++ b/auth/gensec/gensec_start.c
  4994. @@ -299,6 +299,93 @@ const struct gensec_security_ops *gensec_security_by_name(struct gensec_security
  4995. return NULL;
  4996. }
  4997. +static const char **gensec_security_sasl_names_from_ops(
  4998. + struct gensec_security *gensec_security,
  4999. + TALLOC_CTX *mem_ctx,
  5000. + const struct gensec_security_ops * const *ops)
  5001. +{
  5002. + const char **sasl_names = NULL;
  5003. + size_t i, sasl_names_count = 0;
  5004. +
  5005. + if (ops == NULL) {
  5006. + return NULL;
  5007. + }
  5008. +
  5009. + sasl_names = talloc_array(mem_ctx, const char *, 1);
  5010. + if (sasl_names == NULL) {
  5011. + return NULL;
  5012. + }
  5013. +
  5014. + for (i = 0; ops[i] != NULL; i++) {
  5015. + enum gensec_role role = GENSEC_SERVER;
  5016. + const char **tmp = NULL;
  5017. +
  5018. + if (ops[i]->sasl_name == NULL) {
  5019. + continue;
  5020. + }
  5021. +
  5022. + if (gensec_security != NULL) {
  5023. + if (!gensec_security_ops_enabled(ops[i],
  5024. + gensec_security)) {
  5025. + continue;
  5026. + }
  5027. +
  5028. + role = gensec_security->gensec_role;
  5029. + }
  5030. +
  5031. + switch (role) {
  5032. + case GENSEC_CLIENT:
  5033. + if (ops[i]->client_start == NULL) {
  5034. + continue;
  5035. + }
  5036. + break;
  5037. + case GENSEC_SERVER:
  5038. + if (ops[i]->server_start == NULL) {
  5039. + continue;
  5040. + }
  5041. + break;
  5042. + }
  5043. +
  5044. + tmp = talloc_realloc(mem_ctx,
  5045. + sasl_names,
  5046. + const char *,
  5047. + sasl_names_count + 2);
  5048. + if (tmp == NULL) {
  5049. + TALLOC_FREE(sasl_names);
  5050. + return NULL;
  5051. + }
  5052. + sasl_names = tmp;
  5053. +
  5054. + sasl_names[sasl_names_count] = ops[i]->sasl_name;
  5055. + sasl_names_count++;
  5056. + }
  5057. + sasl_names[sasl_names_count] = NULL;
  5058. +
  5059. + return sasl_names;
  5060. +}
  5061. +
  5062. +/**
  5063. + * @brief Get the sasl names from the gensec security context.
  5064. + *
  5065. + * @param[in] gensec_security The gensec security context.
  5066. + *
  5067. + * @param[in] mem_ctx The memory context to allocate memory on.
  5068. + *
  5069. + * @return An allocated array with sasl names, NULL on error.
  5070. + */
  5071. +_PUBLIC_
  5072. +const char **gensec_security_sasl_names(struct gensec_security *gensec_security,
  5073. + TALLOC_CTX *mem_ctx)
  5074. +{
  5075. + const struct gensec_security_ops **ops = NULL;
  5076. +
  5077. + ops = gensec_security_mechs(gensec_security, mem_ctx);
  5078. +
  5079. + return gensec_security_sasl_names_from_ops(gensec_security,
  5080. + mem_ctx,
  5081. + ops);
  5082. +}
  5083. +
  5084. /**
  5085. * Return a unique list of security subsystems from those specified in
  5086. * the list of SASL names.
  5087. --
  5088. 2.29.2
  5089. From adf58a175cea99c0b0147d3b3275563c7155edfa Mon Sep 17 00:00:00 2001
  5090. From: Stefan Metzmacher <metze@samba.org>
  5091. Date: Fri, 4 Sep 2020 10:48:27 +0200
  5092. Subject: [PATCH 051/104] s4:ldap_server: Use samba_server_gensec_start() in
  5093. ldapsrv_backend_Init()
  5094. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  5095. Reviewed-by: Andreas Schneider <asn@samba.org>
  5096. (cherry picked from commit 5e3363e0b82193700f91a9bae5080aae0b744e5c)
  5097. ---
  5098. source4/dsdb/samdb/ldb_modules/rootdse.c | 4 +-
  5099. source4/ldap_server/ldap_backend.c | 49 +++++++++++-------------
  5100. 2 files changed, 25 insertions(+), 28 deletions(-)
  5101. diff --git a/source4/dsdb/samdb/ldb_modules/rootdse.c b/source4/dsdb/samdb/ldb_modules/rootdse.c
  5102. index 55340fa4f1e..4be9550747c 100644
  5103. --- a/source4/dsdb/samdb/ldb_modules/rootdse.c
  5104. +++ b/source4/dsdb/samdb/ldb_modules/rootdse.c
  5105. @@ -230,7 +230,7 @@ static int rootdse_add_dynamic(struct rootdse_context *ac, struct ldb_message *m
  5106. struct ldb_context *ldb;
  5107. struct rootdse_private_data *priv = talloc_get_type(ldb_module_get_private(ac->module), struct rootdse_private_data);
  5108. const char * const *attrs = ac->req->op.search.attrs;
  5109. - char **server_sasl;
  5110. + const char **server_sasl = NULL;
  5111. const struct dsdb_schema *schema;
  5112. int *val;
  5113. struct ldb_control *edn_control;
  5114. @@ -341,7 +341,7 @@ static int rootdse_add_dynamic(struct rootdse_context *ac, struct ldb_message *m
  5115. }
  5116. server_sasl = talloc_get_type(ldb_get_opaque(ldb, "supportedSASLMechanisms"),
  5117. - char *);
  5118. + const char *);
  5119. if (server_sasl && do_attribute(attrs, "supportedSASLMechanisms")) {
  5120. for (i = 0; server_sasl && server_sasl[i]; i++) {
  5121. char *sasl_name = talloc_strdup(msg, server_sasl[i]);
  5122. diff --git a/source4/ldap_server/ldap_backend.c b/source4/ldap_server/ldap_backend.c
  5123. index 2839082daef..915d9b94f9b 100644
  5124. --- a/source4/ldap_server/ldap_backend.c
  5125. +++ b/source4/ldap_server/ldap_backend.c
  5126. @@ -33,6 +33,7 @@
  5127. #include "ldb_wrap.h"
  5128. #include "lib/tsocket/tsocket.h"
  5129. #include "libcli/ldap/ldap_proto.h"
  5130. +#include "source4/auth/auth.h"
  5131. static int map_ldb_error(TALLOC_CTX *mem_ctx, int ldb_err,
  5132. const char *add_err_string, const char **errstring)
  5133. @@ -199,37 +200,33 @@ int ldapsrv_backend_Init(struct ldapsrv_connection *conn,
  5134. }
  5135. if (conn->server_credentials) {
  5136. - char **sasl_mechs = NULL;
  5137. - const struct gensec_security_ops * const *backends = gensec_security_all();
  5138. - const struct gensec_security_ops **ops
  5139. - = gensec_use_kerberos_mechs(conn, backends, conn->server_credentials);
  5140. - unsigned int i, j = 0;
  5141. - for (i = 0; ops && ops[i]; i++) {
  5142. - if (!lpcfg_parm_bool(conn->lp_ctx, NULL, "gensec", ops[i]->name, ops[i]->enabled))
  5143. - continue;
  5144. -
  5145. - if (ops[i]->sasl_name && ops[i]->server_start) {
  5146. - char *sasl_name = talloc_strdup(conn, ops[i]->sasl_name);
  5147. -
  5148. - if (!sasl_name) {
  5149. - return LDB_ERR_OPERATIONS_ERROR;
  5150. - }
  5151. - sasl_mechs = talloc_realloc(conn, sasl_mechs, char *, j + 2);
  5152. - if (!sasl_mechs) {
  5153. - return LDB_ERR_OPERATIONS_ERROR;
  5154. - }
  5155. - sasl_mechs[j] = sasl_name;
  5156. - talloc_steal(sasl_mechs, sasl_name);
  5157. - sasl_mechs[j+1] = NULL;
  5158. - j++;
  5159. - }
  5160. + struct gensec_security *gensec_security = NULL;
  5161. + const char **sasl_mechs = NULL;
  5162. + NTSTATUS status;
  5163. +
  5164. + status = samba_server_gensec_start(conn,
  5165. + conn->connection->event.ctx,
  5166. + conn->connection->msg_ctx,
  5167. + conn->lp_ctx,
  5168. + conn->server_credentials,
  5169. + "ldap",
  5170. + &gensec_security);
  5171. + if (!NT_STATUS_IS_OK(status)) {
  5172. + DBG_ERR("samba_server_gensec_start failed: %s\n",
  5173. + nt_errstr(status));
  5174. + return LDB_ERR_OPERATIONS_ERROR;
  5175. }
  5176. - talloc_unlink(conn, ops);
  5177. /* ldb can have a different lifetime to conn, so we
  5178. need to ensure that sasl_mechs lives as long as the
  5179. ldb does */
  5180. - talloc_steal(conn->ldb, sasl_mechs);
  5181. + sasl_mechs = gensec_security_sasl_names(gensec_security,
  5182. + conn->ldb);
  5183. + TALLOC_FREE(gensec_security);
  5184. + if (sasl_mechs == NULL) {
  5185. + DBG_ERR("Failed to get sasl mechs!\n");
  5186. + return LDB_ERR_OPERATIONS_ERROR;
  5187. + }
  5188. ldb_set_opaque(conn->ldb, "supportedSASLMechanisms", sasl_mechs);
  5189. }
  5190. --
  5191. 2.29.2
  5192. From e887d94b47aca3609fd158efe0f4654101c5e02b Mon Sep 17 00:00:00 2001
  5193. From: Stefan Metzmacher <metze@samba.org>
  5194. Date: Fri, 4 Sep 2020 14:39:15 +0200
  5195. Subject: [PATCH 052/104] auth:gensec: Make gensec_use_kerberos_mechs() a
  5196. static function
  5197. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  5198. Reviewed-by: Andreas Schneider <asn@samba.org>
  5199. (cherry picked from commit 2186d4131ad4c7961d0c830bf9d48f3d06d27924)
  5200. ---
  5201. auth/gensec/gensec.h | 3 ---
  5202. auth/gensec/gensec_start.c | 7 ++++---
  5203. 2 files changed, 4 insertions(+), 6 deletions(-)
  5204. diff --git a/auth/gensec/gensec.h b/auth/gensec/gensec.h
  5205. index fe26fff171a..8bece3c3458 100644
  5206. --- a/auth/gensec/gensec.h
  5207. +++ b/auth/gensec/gensec.h
  5208. @@ -302,9 +302,6 @@ NTSTATUS gensec_wrap(struct gensec_security *gensec_security,
  5209. const struct gensec_security_ops * const *gensec_security_all(void);
  5210. bool gensec_security_ops_enabled(const struct gensec_security_ops *ops, struct gensec_security *security);
  5211. -const struct gensec_security_ops **gensec_use_kerberos_mechs(TALLOC_CTX *mem_ctx,
  5212. - const struct gensec_security_ops * const *old_gensec_list,
  5213. - struct cli_credentials *creds);
  5214. NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
  5215. const char *sasl_name);
  5216. diff --git a/auth/gensec/gensec_start.c b/auth/gensec/gensec_start.c
  5217. index 4eb45643714..ebcab76999a 100644
  5218. --- a/auth/gensec/gensec_start.c
  5219. +++ b/auth/gensec/gensec_start.c
  5220. @@ -83,9 +83,10 @@ bool gensec_security_ops_enabled(const struct gensec_security_ops *ops, struct g
  5221. * more compplex.
  5222. */
  5223. -_PUBLIC_ const struct gensec_security_ops **gensec_use_kerberos_mechs(TALLOC_CTX *mem_ctx,
  5224. - const struct gensec_security_ops * const *old_gensec_list,
  5225. - struct cli_credentials *creds)
  5226. +static const struct gensec_security_ops **gensec_use_kerberos_mechs(
  5227. + TALLOC_CTX *mem_ctx,
  5228. + const struct gensec_security_ops * const *old_gensec_list,
  5229. + struct cli_credentials *creds)
  5230. {
  5231. const struct gensec_security_ops **new_gensec_list;
  5232. int i, j, num_mechs_in;
  5233. --
  5234. 2.29.2
  5235. From 08dc4775dbf72a1e8068d392360be158d8305bfa Mon Sep 17 00:00:00 2001
  5236. From: Stefan Metzmacher <metze@samba.org>
  5237. Date: Fri, 4 Sep 2020 14:41:43 +0200
  5238. Subject: [PATCH 053/104] auth:gensec: Pass use_kerberos and keep_schannel to
  5239. gensec_use_kerberos_mechs()
  5240. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  5241. Reviewed-by: Andreas Schneider <asn@samba.org>
  5242. (cherry picked from commit a33a40bbc848e5691869cf264009d23a03128f31)
  5243. ---
  5244. auth/gensec/gensec_start.c | 26 ++++++++++++++------------
  5245. 1 file changed, 14 insertions(+), 12 deletions(-)
  5246. diff --git a/auth/gensec/gensec_start.c b/auth/gensec/gensec_start.c
  5247. index ebcab76999a..8d1b41fec74 100644
  5248. --- a/auth/gensec/gensec_start.c
  5249. +++ b/auth/gensec/gensec_start.c
  5250. @@ -86,19 +86,11 @@ bool gensec_security_ops_enabled(const struct gensec_security_ops *ops, struct g
  5251. static const struct gensec_security_ops **gensec_use_kerberos_mechs(
  5252. TALLOC_CTX *mem_ctx,
  5253. const struct gensec_security_ops * const *old_gensec_list,
  5254. - struct cli_credentials *creds)
  5255. + enum credentials_use_kerberos use_kerberos,
  5256. + bool keep_schannel)
  5257. {
  5258. const struct gensec_security_ops **new_gensec_list;
  5259. int i, j, num_mechs_in;
  5260. - enum credentials_use_kerberos use_kerberos = CRED_AUTO_USE_KERBEROS;
  5261. - bool keep_schannel = false;
  5262. -
  5263. - if (creds) {
  5264. - use_kerberos = cli_credentials_get_kerberos_state(creds);
  5265. - if (cli_credentials_get_netlogon_creds(creds) != NULL) {
  5266. - keep_schannel = true;
  5267. - }
  5268. - }
  5269. for (num_mechs_in=0; old_gensec_list && old_gensec_list[num_mechs_in]; num_mechs_in++) {
  5270. /* noop */
  5271. @@ -163,18 +155,28 @@ _PUBLIC_ const struct gensec_security_ops **gensec_security_mechs(
  5272. struct gensec_security *gensec_security,
  5273. TALLOC_CTX *mem_ctx)
  5274. {
  5275. - struct cli_credentials *creds = NULL;
  5276. const struct gensec_security_ops * const *backends = gensec_security_all();
  5277. + enum credentials_use_kerberos use_kerberos = CRED_AUTO_USE_KERBEROS;
  5278. + bool keep_schannel = false;
  5279. if (gensec_security != NULL) {
  5280. + struct cli_credentials *creds = NULL;
  5281. +
  5282. creds = gensec_get_credentials(gensec_security);
  5283. + if (creds != NULL) {
  5284. + use_kerberos = cli_credentials_get_kerberos_state(creds);
  5285. + if (cli_credentials_get_netlogon_creds(creds) != NULL) {
  5286. + keep_schannel = true;
  5287. + }
  5288. + }
  5289. if (gensec_security->settings->backends) {
  5290. backends = gensec_security->settings->backends;
  5291. }
  5292. }
  5293. - return gensec_use_kerberos_mechs(mem_ctx, backends, creds);
  5294. + return gensec_use_kerberos_mechs(mem_ctx, backends,
  5295. + use_kerberos, keep_schannel);
  5296. }
  5297. --
  5298. 2.29.2
  5299. From bc505a449449267085778ec51c5362e256837edb Mon Sep 17 00:00:00 2001
  5300. From: Stefan Metzmacher <metze@samba.org>
  5301. Date: Fri, 4 Sep 2020 17:00:45 +0200
  5302. Subject: [PATCH 054/104] auth:gensec: If Kerberos is required, keep schannel
  5303. for machine account auth
  5304. Signed-off-by: Stefan Metzmacher <metze@samba.org>
  5305. Signed-off-by: Andreas Schneider <asn@samba.org>
  5306. (cherry picked from commit 515cffb1f20eacb041ff7b3d43f8a122a82ddfbd)
  5307. ---
  5308. auth/gensec/gensec_start.c | 9 +++++++++
  5309. 1 file changed, 9 insertions(+)
  5310. diff --git a/auth/gensec/gensec_start.c b/auth/gensec/gensec_start.c
  5311. index 8d1b41fec74..3f42d611140 100644
  5312. --- a/auth/gensec/gensec_start.c
  5313. +++ b/auth/gensec/gensec_start.c
  5314. @@ -168,6 +168,15 @@ _PUBLIC_ const struct gensec_security_ops **gensec_security_mechs(
  5315. if (cli_credentials_get_netlogon_creds(creds) != NULL) {
  5316. keep_schannel = true;
  5317. }
  5318. +
  5319. + /*
  5320. + * Even if Kerberos is set to REQUIRED, keep the
  5321. + * schannel auth mechanism that machine accounts are
  5322. + * able to authenticate via netlogon.
  5323. + */
  5324. + if (gensec_security->gensec_role == GENSEC_SERVER) {
  5325. + keep_schannel = true;
  5326. + }
  5327. }
  5328. if (gensec_security->settings->backends) {
  5329. --
  5330. 2.29.2
  5331. From 9b7a189e038e3f783a2b23302f0ee4657ef18057 Mon Sep 17 00:00:00 2001
  5332. From: Andreas Schneider <asn@samba.org>
  5333. Date: Fri, 4 Sep 2020 12:21:21 +0200
  5334. Subject: [PATCH 055/104] auth:creds: Add cli_credentials_init_server()
  5335. Signed-off-by: Andreas Schneider <asn@samba.org>
  5336. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  5337. (cherry picked from commit 2c00bea2aefdcc69608dffdafa7ce581d31f9354)
  5338. ---
  5339. auth/credentials/credentials.c | 25 +++++++++++++++++++++++++
  5340. auth/credentials/credentials.h | 2 ++
  5341. 2 files changed, 27 insertions(+)
  5342. diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
  5343. index 9168b92d3ec..77c35dd104b 100644
  5344. --- a/auth/credentials/credentials.c
  5345. +++ b/auth/credentials/credentials.c
  5346. @@ -56,6 +56,31 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
  5347. return cred;
  5348. }
  5349. +_PUBLIC_
  5350. +struct cli_credentials *cli_credentials_init_server(TALLOC_CTX *mem_ctx,
  5351. + struct loadparm_context *lp_ctx)
  5352. +{
  5353. + struct cli_credentials *server_creds = NULL;
  5354. + NTSTATUS status;
  5355. +
  5356. + server_creds = cli_credentials_init(mem_ctx);
  5357. + if (server_creds == NULL) {
  5358. + return NULL;
  5359. + }
  5360. +
  5361. + cli_credentials_set_conf(server_creds, lp_ctx);
  5362. +
  5363. + status = cli_credentials_set_machine_account(server_creds, lp_ctx);
  5364. + if (!NT_STATUS_IS_OK(status)) {
  5365. + DEBUG(1, ("Failed to obtain server credentials: %s\n",
  5366. + nt_errstr(status)));
  5367. + TALLOC_FREE(server_creds);
  5368. + return NULL;
  5369. + }
  5370. +
  5371. + return server_creds;
  5372. +}
  5373. +
  5374. _PUBLIC_ void cli_credentials_set_callback_data(struct cli_credentials *cred,
  5375. void *callback_data)
  5376. {
  5377. diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
  5378. index 7d0cf53194b..438bcdce232 100644
  5379. --- a/auth/credentials/credentials.h
  5380. +++ b/auth/credentials/credentials.h
  5381. @@ -76,6 +76,8 @@ bool cli_credentials_set_workstation(struct cli_credentials *cred,
  5382. enum credentials_obtained obtained);
  5383. bool cli_credentials_is_anonymous(struct cli_credentials *cred);
  5384. struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx);
  5385. +struct cli_credentials *cli_credentials_init_server(TALLOC_CTX *mem_ctx,
  5386. + struct loadparm_context *lp_ctx);
  5387. void cli_credentials_set_anonymous(struct cli_credentials *cred);
  5388. bool cli_credentials_wrong_password(struct cli_credentials *cred);
  5389. const char *cli_credentials_get_password(struct cli_credentials *cred);
  5390. --
  5391. 2.29.2
  5392. From 013d5eb87f3ddcda6df5c76796bede7a85c42207 Mon Sep 17 00:00:00 2001
  5393. From: Andreas Schneider <asn@samba.org>
  5394. Date: Fri, 4 Sep 2020 12:21:36 +0200
  5395. Subject: [PATCH 056/104] s4:rpc_server: Use cli_credentials_init_server()
  5396. Signed-off-by: Andreas Schneider <asn@samba.org>
  5397. (cherry picked from commit 6c94ebf77fdb7383be2042f5e20ba2ef598cd4a4)
  5398. ---
  5399. source4/rpc_server/dcerpc_server.c | 17 +++--------------
  5400. 1 file changed, 3 insertions(+), 14 deletions(-)
  5401. diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c
  5402. index 084857a44bf..e64148ef788 100644
  5403. --- a/source4/rpc_server/dcerpc_server.c
  5404. +++ b/source4/rpc_server/dcerpc_server.c
  5405. @@ -673,25 +673,14 @@ NTSTATUS dcesrv_gensec_prepare(TALLOC_CTX *mem_ctx,
  5406. struct cli_credentials *server_creds = NULL;
  5407. struct imessaging_context *imsg_ctx =
  5408. dcesrv_imessaging_context(call->conn);
  5409. - NTSTATUS status;
  5410. - server_creds = cli_credentials_init(call->auth_state);
  5411. - if (!server_creds) {
  5412. + server_creds = cli_credentials_init_server(call->auth_state,
  5413. + call->conn->dce_ctx->lp_ctx);
  5414. + if (server_creds == NULL) {
  5415. DEBUG(1, ("Failed to init server credentials\n"));
  5416. return NT_STATUS_NO_MEMORY;
  5417. }
  5418. - cli_credentials_set_conf(server_creds, call->conn->dce_ctx->lp_ctx);
  5419. -
  5420. - status = cli_credentials_set_machine_account(server_creds,
  5421. - call->conn->dce_ctx->lp_ctx);
  5422. - if (!NT_STATUS_IS_OK(status)) {
  5423. - DEBUG(1, ("Failed to obtain server credentials: %s\n",
  5424. - nt_errstr(status)));
  5425. - talloc_free(server_creds);
  5426. - return status;
  5427. - }
  5428. -
  5429. return samba_server_gensec_start(mem_ctx,
  5430. call->event_ctx,
  5431. imsg_ctx,
  5432. --
  5433. 2.29.2
  5434. From 6e6030dca006e829150e6b64db0485e3c9895485 Mon Sep 17 00:00:00 2001
  5435. From: Andreas Schneider <asn@samba.org>
  5436. Date: Mon, 7 Sep 2020 09:19:43 +0200
  5437. Subject: [PATCH 057/104] s4:smb_server: Use cli_credentials_init_server() for
  5438. negprot
  5439. Signed-off-by: Andreas Schneider <asn@samba.org>
  5440. Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
  5441. Autobuild-Date(master): Mon Sep 7 13:22:26 UTC 2020 on sn-devel-184
  5442. (cherry picked from commit 0b742ec6a0558397d5cf01b99a401f8e2bc0e2e0)
  5443. ---
  5444. source4/smb_server/smb/negprot.c | 28 ++++++++++++++--------------
  5445. source4/smb_server/smb2/negprot.c | 25 +++++++++++++------------
  5446. 2 files changed, 27 insertions(+), 26 deletions(-)
  5447. diff --git a/source4/smb_server/smb/negprot.c b/source4/smb_server/smb/negprot.c
  5448. index a6177a72019..04b69dd9883 100644
  5449. --- a/source4/smb_server/smb/negprot.c
  5450. +++ b/source4/smb_server/smb/negprot.c
  5451. @@ -374,22 +374,22 @@ static void reply_nt1(struct smbsrv_request *req, uint16_t choice)
  5452. DATA_BLOB blob = data_blob_null;
  5453. const char *oid;
  5454. NTSTATUS nt_status;
  5455. -
  5456. - server_credentials
  5457. - = cli_credentials_init(req);
  5458. - if (!server_credentials) {
  5459. - smbsrv_terminate_connection(req->smb_conn, "Failed to init server credentials\n");
  5460. - return;
  5461. - }
  5462. -
  5463. - cli_credentials_set_conf(server_credentials, req->smb_conn->lp_ctx);
  5464. - nt_status = cli_credentials_set_machine_account(server_credentials, req->smb_conn->lp_ctx);
  5465. - if (!NT_STATUS_IS_OK(nt_status)) {
  5466. - DEBUG(10, ("Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(nt_status)));
  5467. +
  5468. + server_credentials =
  5469. + cli_credentials_init_server(req, req->smb_conn->lp_ctx);
  5470. + if (server_credentials == NULL) {
  5471. + DBG_DEBUG("Failed to obtain server credentials, "
  5472. + "perhaps a standalone server?\n");
  5473. /*
  5474. - * We keep the server_credentials as anonymous
  5475. - * this is required for the spoolss.notify test
  5476. + * Create anon server credentials for for the
  5477. + * spoolss.notify test.
  5478. */
  5479. + server_credentials = cli_credentials_init_anon(req);
  5480. + if (server_credentials == NULL) {
  5481. + smbsrv_terminate_connection(req->smb_conn,
  5482. + "Failed to init server credentials\n");
  5483. + return;
  5484. + }
  5485. }
  5486. nt_status = samba_server_gensec_start(req,
  5487. diff --git a/source4/smb_server/smb2/negprot.c b/source4/smb_server/smb2/negprot.c
  5488. index 4aaaf46793b..c433eb194bd 100644
  5489. --- a/source4/smb_server/smb2/negprot.c
  5490. +++ b/source4/smb_server/smb2/negprot.c
  5491. @@ -39,20 +39,21 @@ static NTSTATUS smb2srv_negprot_secblob(struct smb2srv_request *req, DATA_BLOB *
  5492. NTSTATUS nt_status;
  5493. struct cli_credentials *server_credentials;
  5494. - server_credentials = cli_credentials_init(req);
  5495. - if (!server_credentials) {
  5496. - smbsrv_terminate_connection(req->smb_conn, "Failed to init server credentials\n");
  5497. - return NT_STATUS_NO_MEMORY;
  5498. - }
  5499. -
  5500. - cli_credentials_set_conf(server_credentials, req->smb_conn->lp_ctx);
  5501. - nt_status = cli_credentials_set_machine_account(server_credentials, req->smb_conn->lp_ctx);
  5502. - if (!NT_STATUS_IS_OK(nt_status)) {
  5503. - DEBUG(10, ("Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(nt_status)));
  5504. + server_credentials =
  5505. + cli_credentials_init_server(req, req->smb_conn->lp_ctx);
  5506. + if (server_credentials == NULL) {
  5507. + DBG_DEBUG("Failed to obtain server credentials, "
  5508. + "perhaps a standalone server?\n");
  5509. /*
  5510. - * We keep the server_credentials as anonymous
  5511. - * this is required for the spoolss.notify test
  5512. + * Create anon server credentials for for the
  5513. + * spoolss.notify test.
  5514. */
  5515. + server_credentials = cli_credentials_init_anon(req);
  5516. + if (server_credentials == NULL) {
  5517. + smbsrv_terminate_connection(req->smb_conn,
  5518. + "Failed to init server credentials\n");
  5519. + return NT_STATUS_NO_MEMORY;
  5520. + }
  5521. }
  5522. req->smb_conn->negotiate.server_credentials = talloc_steal(req->smb_conn, server_credentials);
  5523. --
  5524. 2.29.2
  5525. From f9f25b7690c2e234ea2e631f05c1fb0180776842 Mon Sep 17 00:00:00 2001
  5526. From: Andreas Schneider <asn@samba.org>
  5527. Date: Tue, 8 Sep 2020 10:15:22 +0200
  5528. Subject: [PATCH 058/104] selftest: Rename 'smb encrypt' to 'server smb
  5529. encrypt'
  5530. This makes it more clear what we want. 'smb encrypt' is a synonym for
  5531. 'server smb encrypt'.
  5532. Signed-off-by: Andreas Schneider <asn@samba.org>
  5533. Reviewed-by: Jeremy Allison <jra@samba.org>
  5534. (cherry picked from commit c75e8ff47b4d79b37240f9461ddae10a4f03c892)
  5535. ---
  5536. selftest/target/Samba3.pm | 6 +++---
  5537. 1 file changed, 3 insertions(+), 3 deletions(-)
  5538. diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
  5539. index e141f102ef1..c070086ca49 100755
  5540. --- a/selftest/target/Samba3.pm
  5541. +++ b/selftest/target/Samba3.pm
  5542. @@ -1178,7 +1178,7 @@ sub setup_simpleserver
  5543. ntlm auth = yes
  5544. vfs objects = xattr_tdb streams_depot
  5545. change notify = no
  5546. - smb encrypt = off
  5547. + server smb encrypt = off
  5548. [vfs_aio_pthread]
  5549. path = $prefix_abs/share
  5550. @@ -1245,7 +1245,7 @@ sub setup_simpleserver
  5551. [enc_desired]
  5552. path = $prefix_abs/share
  5553. vfs objects =
  5554. - smb encrypt = desired
  5555. + server smb encrypt = desired
  5556. [hidenewfiles]
  5557. path = $prefix_abs/share
  5558. @@ -2351,7 +2351,7 @@ sub provision($$)
  5559. [tmpenc]
  5560. path = $shrdir
  5561. comment = encrypt smb username is [%U]
  5562. - smb encrypt = required
  5563. + server smb encrypt = required
  5564. vfs objects = dirsort
  5565. [tmpguest]
  5566. path = $shrdir
  5567. --
  5568. 2.29.2
  5569. From 2fc16a8d11f48424fc2fff0380fb623f552ece5f Mon Sep 17 00:00:00 2001
  5570. From: Andreas Schneider <asn@samba.org>
  5571. Date: Tue, 8 Sep 2020 12:30:08 +0200
  5572. Subject: [PATCH 059/104] selftest: Move enc_desired to provision to have it in
  5573. 'fileserver' too
  5574. Signed-off-by: Andreas Schneider <asn@samba.org>
  5575. Reviewed-by: Jeremy Allison <jra@samba.org>
  5576. (cherry picked from commit 1b67943f938ae774360dc3db73db940f9982243b)
  5577. ---
  5578. selftest/target/Samba3.pm | 11 ++++++-----
  5579. 1 file changed, 6 insertions(+), 5 deletions(-)
  5580. diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
  5581. index c070086ca49..fa3ca8962a5 100755
  5582. --- a/selftest/target/Samba3.pm
  5583. +++ b/selftest/target/Samba3.pm
  5584. @@ -1242,11 +1242,6 @@ sub setup_simpleserver
  5585. hide files = /hidefile/
  5586. hide dot files = yes
  5587. -[enc_desired]
  5588. - path = $prefix_abs/share
  5589. - vfs objects =
  5590. - server smb encrypt = desired
  5591. -
  5592. [hidenewfiles]
  5593. path = $prefix_abs/share
  5594. hide new files timeout = 5
  5595. @@ -2833,7 +2828,13 @@ sub provision($$)
  5596. [delete_readonly]
  5597. path = $prefix_abs/share
  5598. delete readonly = yes
  5599. +
  5600. +[enc_desired]
  5601. + path = $prefix_abs/share
  5602. + vfs objects =
  5603. + server smb encrypt = desired
  5604. ";
  5605. +
  5606. close(CONF);
  5607. my $net = Samba::bindir_path($self, "net");
  5608. --
  5609. 2.29.2
  5610. From 299d7d6868e9590693e465cbc0c10abe8b7fc5a0 Mon Sep 17 00:00:00 2001
  5611. From: Andreas Schneider <asn@samba.org>
  5612. Date: Tue, 8 Sep 2020 10:15:20 +0200
  5613. Subject: [PATCH 060/104] s3:tests: Add smbclient tests for 'client smb
  5614. encrypt'
  5615. Signed-off-by: Andreas Schneider <asn@samba.org>
  5616. Reviewed-by: Jeremy Allison <jra@samba.org>
  5617. (cherry picked from commit e7577ab6cbc83b496ac091c3e425c7c7fea29cdb)
  5618. ---
  5619. selftest/knownfail.d/smbclient-encryption | 2 +
  5620. selftest/target/Samba3.pm | 5 ++
  5621. .../script/tests/test_smbclient_encryption.sh | 72 +++++++++++++++++++
  5622. source3/selftest/tests.py | 6 ++
  5623. 4 files changed, 85 insertions(+)
  5624. create mode 100644 selftest/knownfail.d/smbclient-encryption
  5625. create mode 100755 source3/script/tests/test_smbclient_encryption.sh
  5626. diff --git a/selftest/knownfail.d/smbclient-encryption b/selftest/knownfail.d/smbclient-encryption
  5627. new file mode 100644
  5628. index 00000000000..972096bdc8b
  5629. --- /dev/null
  5630. +++ b/selftest/knownfail.d/smbclient-encryption
  5631. @@ -0,0 +1,2 @@
  5632. +^samba3.blackbox.smbclient.encryption.smbclient.smb3.client.encrypt.required...LOCALSHARE4.enc_desired..simpleserver
  5633. +^samba3.blackbox.smbclient.encryption.smbclient.smb3.client.encrypt.required...LOCALSHARE4.tmp..simpleserver
  5634. diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
  5635. index fa3ca8962a5..ffc19c7d5a2 100755
  5636. --- a/selftest/target/Samba3.pm
  5637. +++ b/selftest/target/Samba3.pm
  5638. @@ -2833,6 +2833,11 @@ sub provision($$)
  5639. path = $prefix_abs/share
  5640. vfs objects =
  5641. server smb encrypt = desired
  5642. +
  5643. +[enc_off]
  5644. + path = $prefix_abs/share
  5645. + vfs objects =
  5646. + server smb encrypt = off
  5647. ";
  5648. close(CONF);
  5649. diff --git a/source3/script/tests/test_smbclient_encryption.sh b/source3/script/tests/test_smbclient_encryption.sh
  5650. new file mode 100755
  5651. index 00000000000..9a717cdac4f
  5652. --- /dev/null
  5653. +++ b/source3/script/tests/test_smbclient_encryption.sh
  5654. @@ -0,0 +1,72 @@
  5655. +#!/bin/sh
  5656. +
  5657. +if [ $# -lt 5 ]; then
  5658. +cat <<EOF
  5659. +Usage: test_smbclient_encryption.sh USERNAME PASSWORD SERVER SMBCLIENT TARGET
  5660. +EOF
  5661. +exit 1;
  5662. +fi
  5663. +
  5664. +USERNAME="$1"
  5665. +PASSWORD="$2"
  5666. +SERVER="$3"
  5667. +SMBCLIENT="$VALGRIND $4"
  5668. +TARGET="$5"
  5669. +shift 5
  5670. +
  5671. +incdir=`dirname $0`/../../../testprogs/blackbox
  5672. +. $incdir/subunit.sh
  5673. +
  5674. +failed=0
  5675. +
  5676. +#
  5677. +# Server configuration for fileserver:
  5678. +#
  5679. +# global: 'server smb encrypt = default'
  5680. +# enc_desired: 'server smb encrypt = desired'
  5681. +# tmpenc: 'server smb encrypt = required'
  5682. +# tmp: has the global default 'server smb encrypt'
  5683. +#
  5684. +# Server configuration for simpleserver:
  5685. +#
  5686. +# global: 'server smb encrypt = off'
  5687. +# enc_desired: 'server smb encrypt = desired'
  5688. +# tmpenc: 'server smb encrypt = required'
  5689. +# tmp: has the global default 'server smb encrypt'
  5690. +#
  5691. +
  5692. +testit "smbclient.smb3.client.encrypt.desired[//$SERVER/enc_desired]" $SMBCLIENT //$SERVER/enc_desired -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=desired -c 'ls; quit' || failed=`expr $failed + 1`
  5693. +if [ "$TARGET" = "fileserver" ]; then
  5694. + testit "smbclient.smb3.client.encrypt.desired[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=desired -c 'ls; quit' || failed=`expr $failed + 1`
  5695. +elif [ "$TARGET" = "simpleserver" ]; then # Encryption is globally disabled
  5696. + testit_expect_failure "smbclient.smb3.client.encrypt.desired[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=desired -c 'ls; quit' || failed=`expr $failed + 1`
  5697. +fi
  5698. +testit "smbclient.smb3.client.encrypt.desired[//$SERVER/tmp]" $SMBCLIENT //$SERVER/tmp -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=desired -c 'ls; quit' || failed=`expr $failed + 1`
  5699. +
  5700. +testit "smbclient.smb3.client.encrypt.if_required[//$SERVER/enc_desired]" $SMBCLIENT //$SERVER/enc_desired -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=if_required -c 'ls; quit' || failed=`expr $failed + 1`
  5701. +if [ "$TARGET" = "fileserver" ]; then
  5702. + testit "smbclient.smb3.client.encrypt.if_required[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=if_required -c 'ls; quit' || failed=`expr $failed + 1`
  5703. +elif [ "$TARGET" = "simpleserver" ]; then # Encryption is globally disabled
  5704. + testit_expect_failure "smbclient.smb3.client.encrypt.if_required[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=if_required -c 'ls; quit' || failed=`expr $failed + 1`
  5705. +fi
  5706. +testit "smbclient.smb3.client.encrypt.if_required[//$SERVER/tmp]" $SMBCLIENT //$SERVER/tmp -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=if_required -c 'ls; quit' || failed=`expr $failed + 1`
  5707. +
  5708. +if [ "$TARGET" = "fileserver" ]; then
  5709. + testit "smbclient.smb3.client.encrypt.required[//$SERVER/enc_desired]" $SMBCLIENT //$SERVER/enc_desired -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=required -c 'ls; quit' || failed=`expr $failed + 1`
  5710. + testit "smbclient.smb3.client.encrypt.required[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=required -c 'ls; quit' || failed=`expr $failed + 1`
  5711. + testit "smbclient.smb3.client.encrypt.required[//$SERVER/tmp]" $SMBCLIENT //$SERVER/tmp -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=required -c 'ls; quit' || failed=`expr $failed + 1`
  5712. +elif [ "$TARGET" = "simpleserver" ]; then # Encryption is globally disabled
  5713. + testit_expect_failure "smbclient.smb3.client.encrypt.required[//$SERVER/enc_desired]" $SMBCLIENT //$SERVER/enc_desired -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=required -c 'ls; quit' || failed=`expr $failed + 1`
  5714. + testit_expect_failure "smbclient.smb3.client.encrypt.required[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=required -c 'ls; quit' || failed=`expr $failed + 1`
  5715. + testit_expect_failure "smbclient.smb3.client.encrypt.required[//$SERVER/tmp]" $SMBCLIENT //$SERVER/tmp -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=required -c 'ls; quit' || failed=`expr $failed + 1`
  5716. +fi
  5717. +
  5718. +testit "smbclient.smb3.client.encrypt.off[//$SERVER/enc_desired]" $SMBCLIENT //$SERVER/enc_desired -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=off -c 'ls; quit' || failed=`expr $failed + 1`
  5719. +if [ "$TARGET" = "fileserver" ]; then
  5720. + testit "smbclient.smb3.client.encrypt.off[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=off -c 'ls; quit' || failed=`expr $failed + 1`
  5721. +elif [ "$TARGET" = "simpleserver" ]; then # Encryption is globally disabled
  5722. + testit_expect_failure "smbclient.smb3.client.encrypt.off[//$SERVER/tmpenc]" $SMBCLIENT //$SERVER/tmpenc -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=off -c 'ls; quit' || failed=`expr $failed + 1`
  5723. +fi
  5724. +testit "smbclient.smb3.client.encrypt.off[//$SERVER/tmp]" $SMBCLIENT //$SERVER/tmp -U$USERNAME%$PASSWORD -mSMB3 --option=clientsmbencrypt=off -c 'ls; quit' || failed=`expr $failed + 1`
  5725. +
  5726. +testok $0 $failed
  5727. diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
  5728. index 27dc7587b17..46bf274227c 100755
  5729. --- a/source3/selftest/tests.py
  5730. +++ b/source3/selftest/tests.py
  5731. @@ -1040,6 +1040,12 @@ plantestsuite("samba3.blackbox.smbclient.encryption_off", "simpleserver",
  5732. "$USERNAME", "$PASSWORD", "$SERVER",
  5733. smbclient3])
  5734. +for env in ['fileserver', 'simpleserver']:
  5735. + plantestsuite("samba3.blackbox.smbclient.encryption", env,
  5736. + [os.path.join(samba3srcdir, "script/tests/test_smbclient_encryption.sh"),
  5737. + "$USERNAME", "$PASSWORD", "$SERVER",
  5738. + smbclient3, env])
  5739. +
  5740. plantestsuite("samba3.blackbox.rpcclient_netsessenum", "ad_member",
  5741. [os.path.join(samba3srcdir,
  5742. "script/tests/test_rpcclient_netsessenum.sh"),
  5743. --
  5744. 2.29.2
  5745. From d996ccf7dc53046f92827ddab72aac6e92dd3a77 Mon Sep 17 00:00:00 2001
  5746. From: Andreas Schneider <asn@samba.org>
  5747. Date: Thu, 27 Aug 2020 15:19:27 +0200
  5748. Subject: [PATCH 061/104] s3:client: Remove global smb_encrypt
  5749. Signed-off-by: Andreas Schneider <asn@samba.org>
  5750. Reviewed-by: Jeremy Allison <jra@samba.org>
  5751. (cherry picked from commit 1189b20cb7ea09cfed5c246cf977442a51ef72cb)
  5752. ---
  5753. source3/client/client.c | 25 ++++++++++++++++---------
  5754. 1 file changed, 16 insertions(+), 9 deletions(-)
  5755. diff --git a/source3/client/client.c b/source3/client/client.c
  5756. index 56309efcea7..60d4fb3c5ee 100644
  5757. --- a/source3/client/client.c
  5758. +++ b/source3/client/client.c
  5759. @@ -96,9 +96,6 @@ static unsigned int put_total_time_ms = 0;
  5760. /* totals globals */
  5761. static double dir_total;
  5762. -/* encrypted state. */
  5763. -static bool smb_encrypt;
  5764. -
  5765. /* root cli_state connection */
  5766. struct cli_state *cli;
  5767. @@ -2758,7 +2755,7 @@ static int cmd_posix_encrypt(void)
  5768. d_printf("posix_encrypt failed with error %s\n", nt_errstr(status));
  5769. } else {
  5770. d_printf("encryption on\n");
  5771. - smb_encrypt = true;
  5772. + set_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info());
  5773. }
  5774. return 0;
  5775. @@ -5283,6 +5280,9 @@ int cmd_iosize(void)
  5776. TALLOC_CTX *ctx = talloc_tos();
  5777. char *buf;
  5778. int iosize;
  5779. + bool smb_encrypt =
  5780. + get_cmdline_auth_info_smb_encrypt(
  5781. + popt_get_cmdline_auth_info());
  5782. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  5783. if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
  5784. @@ -5546,6 +5546,9 @@ static int process_command_string(const char *cmd_in)
  5785. TALLOC_CTX *ctx = talloc_tos();
  5786. char *cmd = talloc_strdup(ctx, cmd_in);
  5787. int rc = 0;
  5788. + bool smb_encrypt =
  5789. + get_cmdline_auth_info_smb_encrypt(
  5790. + popt_get_cmdline_auth_info());
  5791. if (!cmd) {
  5792. return 1;
  5793. @@ -5999,6 +6002,9 @@ static int process(const char *base_directory)
  5794. {
  5795. int rc = 0;
  5796. NTSTATUS status;
  5797. + bool smb_encrypt =
  5798. + get_cmdline_auth_info_smb_encrypt(
  5799. + popt_get_cmdline_auth_info());
  5800. status = cli_cm_open(talloc_tos(), NULL,
  5801. desthost,
  5802. @@ -6037,6 +6043,9 @@ static int process(const char *base_directory)
  5803. static int do_host_query(const char *query_host)
  5804. {
  5805. NTSTATUS status;
  5806. + bool smb_encrypt =
  5807. + get_cmdline_auth_info_smb_encrypt(
  5808. + popt_get_cmdline_auth_info());
  5809. status = cli_cm_open(talloc_tos(), NULL,
  5810. query_host,
  5811. @@ -6114,6 +6123,9 @@ static int do_tar_op(const char *base_directory)
  5812. {
  5813. struct tar *tar_ctx = tar_get_ctx();
  5814. int ret = 0;
  5815. + bool smb_encrypt =
  5816. + get_cmdline_auth_info_smb_encrypt(
  5817. + popt_get_cmdline_auth_info());
  5818. /* do we already have a connection? */
  5819. if (!cli) {
  5820. @@ -6459,9 +6471,6 @@ int main(int argc,char *argv[])
  5821. case 'q':
  5822. quiet=true;
  5823. break;
  5824. - case 'e':
  5825. - smb_encrypt=true;
  5826. - break;
  5827. case 'B':
  5828. return(do_smb_browse());
  5829. @@ -6531,8 +6540,6 @@ int main(int argc,char *argv[])
  5830. /* Ensure we have a password (or equivalent). */
  5831. popt_common_credentials_post();
  5832. - smb_encrypt = get_cmdline_auth_info_smb_encrypt(
  5833. - popt_get_cmdline_auth_info());
  5834. max_protocol = lp_client_max_protocol();
  5835. --
  5836. 2.29.2
  5837. From b923ea7625de03e23a999a3cb844d81dcd25316f Mon Sep 17 00:00:00 2001
  5838. From: Andreas Schneider <asn@samba.org>
  5839. Date: Thu, 27 Aug 2020 15:24:27 +0200
  5840. Subject: [PATCH 062/104] s3:libsmb: Remove force_encrypt from cli_cm_open()
  5841. Signed-off-by: Andreas Schneider <asn@samba.org>
  5842. Reviewed-by: Jeremy Allison <jra@samba.org>
  5843. (cherry picked from commit a9fbc8dae878ddfa54153e91cc1128c307816b76)
  5844. ---
  5845. source3/client/client.c | 21 ++++-----------------
  5846. source3/lib/netapi/cm.c | 1 -
  5847. source3/libsmb/clidfs.c | 4 ++--
  5848. source3/libsmb/proto.h | 1 -
  5849. 4 files changed, 6 insertions(+), 21 deletions(-)
  5850. diff --git a/source3/client/client.c b/source3/client/client.c
  5851. index 60d4fb3c5ee..3a610086511 100644
  5852. --- a/source3/client/client.c
  5853. +++ b/source3/client/client.c
  5854. @@ -5546,9 +5546,6 @@ static int process_command_string(const char *cmd_in)
  5855. TALLOC_CTX *ctx = talloc_tos();
  5856. char *cmd = talloc_strdup(ctx, cmd_in);
  5857. int rc = 0;
  5858. - bool smb_encrypt =
  5859. - get_cmdline_auth_info_smb_encrypt(
  5860. - popt_get_cmdline_auth_info());
  5861. if (!cmd) {
  5862. return 1;
  5863. @@ -5561,7 +5558,6 @@ static int process_command_string(const char *cmd_in)
  5864. status = cli_cm_open(talloc_tos(), NULL,
  5865. desthost,
  5866. service, popt_get_cmdline_auth_info(),
  5867. - smb_encrypt,
  5868. max_protocol,
  5869. have_ip ? &dest_ss : NULL, port,
  5870. name_type,
  5871. @@ -6002,14 +5998,11 @@ static int process(const char *base_directory)
  5872. {
  5873. int rc = 0;
  5874. NTSTATUS status;
  5875. - bool smb_encrypt =
  5876. - get_cmdline_auth_info_smb_encrypt(
  5877. - popt_get_cmdline_auth_info());
  5878. status = cli_cm_open(talloc_tos(), NULL,
  5879. desthost,
  5880. service, popt_get_cmdline_auth_info(),
  5881. - smb_encrypt, max_protocol,
  5882. + max_protocol,
  5883. have_ip ? &dest_ss : NULL, port,
  5884. name_type, &cli);
  5885. if (!NT_STATUS_IS_OK(status)) {
  5886. @@ -6043,14 +6036,11 @@ static int process(const char *base_directory)
  5887. static int do_host_query(const char *query_host)
  5888. {
  5889. NTSTATUS status;
  5890. - bool smb_encrypt =
  5891. - get_cmdline_auth_info_smb_encrypt(
  5892. - popt_get_cmdline_auth_info());
  5893. status = cli_cm_open(talloc_tos(), NULL,
  5894. query_host,
  5895. "IPC$", popt_get_cmdline_auth_info(),
  5896. - smb_encrypt, max_protocol,
  5897. + max_protocol,
  5898. have_ip ? &dest_ss : NULL, port,
  5899. name_type, &cli);
  5900. if (!NT_STATUS_IS_OK(status)) {
  5901. @@ -6097,7 +6087,7 @@ static int do_host_query(const char *query_host)
  5902. status = cli_cm_open(talloc_tos(), NULL,
  5903. query_host,
  5904. "IPC$", popt_get_cmdline_auth_info(),
  5905. - smb_encrypt, max_proto,
  5906. + max_proto,
  5907. have_ip ? &dest_ss : NULL, NBT_SMB_PORT,
  5908. name_type, &cli);
  5909. if (!NT_STATUS_IS_OK(status)) {
  5910. @@ -6123,9 +6113,6 @@ static int do_tar_op(const char *base_directory)
  5911. {
  5912. struct tar *tar_ctx = tar_get_ctx();
  5913. int ret = 0;
  5914. - bool smb_encrypt =
  5915. - get_cmdline_auth_info_smb_encrypt(
  5916. - popt_get_cmdline_auth_info());
  5917. /* do we already have a connection? */
  5918. if (!cli) {
  5919. @@ -6134,7 +6121,7 @@ static int do_tar_op(const char *base_directory)
  5920. status = cli_cm_open(talloc_tos(), NULL,
  5921. desthost,
  5922. service, popt_get_cmdline_auth_info(),
  5923. - smb_encrypt, max_protocol,
  5924. + max_protocol,
  5925. have_ip ? &dest_ss : NULL, port,
  5926. name_type, &cli);
  5927. if (!NT_STATUS_IS_OK(status)) {
  5928. diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c
  5929. index 1b8f2a4e97a..0fd31ef3d5a 100644
  5930. --- a/source3/lib/netapi/cm.c
  5931. +++ b/source3/lib/netapi/cm.c
  5932. @@ -110,7 +110,6 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
  5933. status = cli_cm_open(ctx, NULL,
  5934. server_name, "IPC$",
  5935. auth_info,
  5936. - false,
  5937. lp_client_ipc_max_protocol(),
  5938. NULL, 0, 0x20, &cli_ipc);
  5939. if (!NT_STATUS_IS_OK(status)) {
  5940. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  5941. index aff998f6187..4825b8f3fae 100644
  5942. --- a/source3/libsmb/clidfs.c
  5943. +++ b/source3/libsmb/clidfs.c
  5944. @@ -383,7 +383,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  5945. const char *server,
  5946. const char *share,
  5947. const struct user_auth_info *auth_info,
  5948. - bool force_encrypt,
  5949. int max_protocol,
  5950. const struct sockaddr_storage *dest_ss,
  5951. int port,
  5952. @@ -393,6 +392,8 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  5953. /* Try to reuse an existing connection in this list. */
  5954. struct cli_state *c = cli_cm_find(referring_cli, server, share);
  5955. NTSTATUS status;
  5956. + bool force_encrypt =
  5957. + get_cmdline_auth_info_smb_encrypt(auth_info);
  5958. if (c) {
  5959. *pcli = c;
  5960. @@ -962,7 +963,6 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  5961. smbXcli_conn_remote_name(rootcli->conn),
  5962. "IPC$",
  5963. dfs_auth_info,
  5964. - cli_state_is_encryption_on(rootcli),
  5965. smbXcli_conn_protocol(rootcli->conn),
  5966. NULL, /* dest_ss not needed, we reuse the transport */
  5967. 0,
  5968. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  5969. index eeabcaa7463..bb3e9e6874e 100644
  5970. --- a/source3/libsmb/proto.h
  5971. +++ b/source3/libsmb/proto.h
  5972. @@ -128,7 +128,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  5973. const char *server,
  5974. const char *share,
  5975. const struct user_auth_info *auth_info,
  5976. - bool force_encrypt,
  5977. int max_protocol,
  5978. const struct sockaddr_storage *dest_ss,
  5979. int port,
  5980. --
  5981. 2.29.2
  5982. From 2fd26f4c208556cd2f28f0c54fe11cea044c7881 Mon Sep 17 00:00:00 2001
  5983. From: Andreas Schneider <asn@samba.org>
  5984. Date: Thu, 27 Aug 2020 15:26:39 +0200
  5985. Subject: [PATCH 063/104] s3:libsmb: Remove force_encrypt from cli_cm_connect()
  5986. Signed-off-by: Andreas Schneider <asn@samba.org>
  5987. Reviewed-by: Jeremy Allison <jra@samba.org>
  5988. (cherry picked from commit d27e237cf37fb254646d94827935d9c302c379ff)
  5989. ---
  5990. source3/libsmb/clidfs.c | 7 ++-----
  5991. 1 file changed, 2 insertions(+), 5 deletions(-)
  5992. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  5993. index 4825b8f3fae..b0032005398 100644
  5994. --- a/source3/libsmb/clidfs.c
  5995. +++ b/source3/libsmb/clidfs.c
  5996. @@ -287,7 +287,6 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  5997. const char *server,
  5998. const char *share,
  5999. const struct user_auth_info *auth_info,
  6000. - bool force_encrypt,
  6001. int max_protocol,
  6002. const struct sockaddr_storage *dest_ss,
  6003. int port,
  6004. @@ -296,6 +295,8 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  6005. {
  6006. struct cli_state *cli = NULL;
  6007. NTSTATUS status;
  6008. + bool force_encrypt =
  6009. + get_cmdline_auth_info_smb_encrypt(auth_info);
  6010. status = do_connect(ctx, server, share,
  6011. auth_info,
  6012. @@ -392,8 +393,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6013. /* Try to reuse an existing connection in this list. */
  6014. struct cli_state *c = cli_cm_find(referring_cli, server, share);
  6015. NTSTATUS status;
  6016. - bool force_encrypt =
  6017. - get_cmdline_auth_info_smb_encrypt(auth_info);
  6018. if (c) {
  6019. *pcli = c;
  6020. @@ -414,7 +413,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6021. server,
  6022. share,
  6023. auth_info,
  6024. - force_encrypt,
  6025. max_protocol,
  6026. dest_ss,
  6027. port,
  6028. @@ -1020,7 +1018,6 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  6029. dfs_refs[count].server,
  6030. dfs_refs[count].share,
  6031. dfs_auth_info,
  6032. - cli_state_is_encryption_on(rootcli),
  6033. smbXcli_conn_protocol(rootcli->conn),
  6034. NULL, /* dest_ss */
  6035. 0, /* port */
  6036. --
  6037. 2.29.2
  6038. From 3db1056dc42765aa3043b6ea0fd0389a34a41145 Mon Sep 17 00:00:00 2001
  6039. From: Andreas Schneider <asn@samba.org>
  6040. Date: Thu, 27 Aug 2020 15:28:28 +0200
  6041. Subject: [PATCH 064/104] s3:libsmb: Remove force_encrypt from clidfs
  6042. do_connect()
  6043. Signed-off-by: Andreas Schneider <asn@samba.org>
  6044. Reviewed-by: Jeremy Allison <jra@samba.org>
  6045. (cherry picked from commit 615a9a68166bdeb0ab7dbacf395c6125ec70f288)
  6046. ---
  6047. source3/libsmb/clidfs.c | 9 ++++-----
  6048. 1 file changed, 4 insertions(+), 5 deletions(-)
  6049. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  6050. index b0032005398..5503506de97 100644
  6051. --- a/source3/libsmb/clidfs.c
  6052. +++ b/source3/libsmb/clidfs.c
  6053. @@ -107,7 +107,6 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6054. const char *server,
  6055. const char *share,
  6056. const struct user_auth_info *auth_info,
  6057. - bool force_encrypt,
  6058. int max_protocol,
  6059. const struct sockaddr_storage *dest_ss,
  6060. int port,
  6061. @@ -123,6 +122,8 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6062. enum protocol_types protocol = PROTOCOL_NONE;
  6063. int signing_state = get_cmdline_auth_info_signing_state(auth_info);
  6064. struct cli_credentials *creds = NULL;
  6065. + bool force_encrypt =
  6066. + get_cmdline_auth_info_smb_encrypt(auth_info);
  6067. if (force_encrypt) {
  6068. signing_state = SMB_SIGNING_REQUIRED;
  6069. @@ -233,7 +234,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6070. cli_shutdown(c);
  6071. return do_connect(ctx, newserver,
  6072. newshare, auth_info,
  6073. - force_encrypt, max_protocol,
  6074. + max_protocol,
  6075. NULL, port, name_type, pcli);
  6076. }
  6077. @@ -295,12 +296,10 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  6078. {
  6079. struct cli_state *cli = NULL;
  6080. NTSTATUS status;
  6081. - bool force_encrypt =
  6082. - get_cmdline_auth_info_smb_encrypt(auth_info);
  6083. status = do_connect(ctx, server, share,
  6084. auth_info,
  6085. - force_encrypt, max_protocol,
  6086. + max_protocol,
  6087. dest_ss, port, name_type, &cli);
  6088. if (!NT_STATUS_IS_OK(status)) {
  6089. --
  6090. 2.29.2
  6091. From 8b234932ec76052258078d08071c33fefd5f3a0e Mon Sep 17 00:00:00 2001
  6092. From: Andreas Schneider <asn@samba.org>
  6093. Date: Thu, 27 Aug 2020 15:52:11 +0200
  6094. Subject: [PATCH 065/104] s3:libsmb: Remove force_encrypt from
  6095. cli_check_msdfs_proxy()
  6096. Signed-off-by: Andreas Schneider <asn@samba.org>
  6097. Reviewed-by: Jeremy Allison <jra@samba.org>
  6098. (cherry picked from commit 4ddec1ca257fff418847c5d1e83a3fb7cb5ade1a)
  6099. ---
  6100. source3/libsmb/clidfs.c | 17 ++++++++++++-----
  6101. source3/libsmb/libsmb_server.c | 4 ----
  6102. source3/libsmb/proto.h | 1 -
  6103. 3 files changed, 12 insertions(+), 10 deletions(-)
  6104. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  6105. index 5503506de97..736c565a7a8 100644
  6106. --- a/source3/libsmb/clidfs.c
  6107. +++ b/source3/libsmb/clidfs.c
  6108. @@ -230,7 +230,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6109. if (smbXcli_conn_dfs_supported(c->conn) &&
  6110. cli_check_msdfs_proxy(ctx, c, sharename,
  6111. &newserver, &newshare,
  6112. - force_encrypt, creds)) {
  6113. + creds)) {
  6114. cli_shutdown(c);
  6115. return do_connect(ctx, newserver,
  6116. newshare, auth_info,
  6117. @@ -1176,7 +1176,6 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
  6118. const char *sharename,
  6119. char **pp_newserver,
  6120. char **pp_newshare,
  6121. - bool force_encrypt,
  6122. struct cli_credentials *creds)
  6123. {
  6124. struct client_dfs_referral *refs = NULL;
  6125. @@ -1188,6 +1187,8 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
  6126. char *newextrapath = NULL;
  6127. NTSTATUS status;
  6128. const char *remote_name;
  6129. + enum smb_encryption_setting encryption_state =
  6130. + cli_credentials_get_smb_encryption(creds);
  6131. if (!cli || !sharename) {
  6132. return false;
  6133. @@ -1223,11 +1224,17 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
  6134. return false;
  6135. }
  6136. - if (force_encrypt) {
  6137. + if (encryption_state >= SMB_ENCRYPTION_DESIRED) {
  6138. status = cli_cm_force_encryption_creds(cli, creds, "IPC$");
  6139. if (!NT_STATUS_IS_OK(status)) {
  6140. - cli_state_restore_tcon(cli, orig_tcon);
  6141. - return false;
  6142. + switch (encryption_state) {
  6143. + case SMB_ENCRYPTION_DESIRED:
  6144. + break;
  6145. + case SMB_ENCRYPTION_REQUIRED:
  6146. + default:
  6147. + cli_state_restore_tcon(cli, orig_tcon);
  6148. + return false;
  6149. + }
  6150. }
  6151. }
  6152. diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
  6153. index eb58d7c6ac9..5a1055ba773 100644
  6154. --- a/source3/libsmb/libsmb_server.c
  6155. +++ b/source3/libsmb/libsmb_server.c
  6156. @@ -587,10 +587,6 @@ SMBC_server_internal(TALLOC_CTX *ctx,
  6157. if (smbXcli_conn_dfs_supported(c->conn) &&
  6158. cli_check_msdfs_proxy(ctx, c, share,
  6159. &newserver, &newshare,
  6160. - /* FIXME: cli_check_msdfs_proxy() does
  6161. - not support smbc_smb_encrypt_level type */
  6162. - context->internal->smb_encryption_level ?
  6163. - true : false,
  6164. creds)) {
  6165. cli_shutdown(c);
  6166. srv = SMBC_server_internal(ctx, context, connect_if_not_found,
  6167. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  6168. index bb3e9e6874e..f2b0a8c5ff8 100644
  6169. --- a/source3/libsmb/proto.h
  6170. +++ b/source3/libsmb/proto.h
  6171. @@ -161,7 +161,6 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
  6172. const char *sharename,
  6173. char **pp_newserver,
  6174. char **pp_newshare,
  6175. - bool force_encrypt,
  6176. struct cli_credentials *creds);
  6177. /* The following definitions come from libsmb/clientgen.c */
  6178. --
  6179. 2.29.2
  6180. From b1324ba3361e66ca4bdf5b0cb0e1d8c8084955d4 Mon Sep 17 00:00:00 2001
  6181. From: Andreas Schneider <asn@samba.org>
  6182. Date: Tue, 18 Aug 2020 17:15:09 +0200
  6183. Subject: [PATCH 066/104] s3:libsmb: Pass cli_credentials to clidfs
  6184. do_connect()
  6185. Signed-off-by: Andreas Schneider <asn@samba.org>
  6186. Reviewed-by: Jeremy Allison <jra@samba.org>
  6187. (cherry picked from commit 276563de06f2071ec2ed9a8b73f92215ab621bba)
  6188. ---
  6189. selftest/knownfail.d/smbclient-encryption | 2 --
  6190. source3/libsmb/clidfs.c | 34 +++++++++++++----------
  6191. 2 files changed, 20 insertions(+), 16 deletions(-)
  6192. delete mode 100644 selftest/knownfail.d/smbclient-encryption
  6193. diff --git a/selftest/knownfail.d/smbclient-encryption b/selftest/knownfail.d/smbclient-encryption
  6194. deleted file mode 100644
  6195. index 972096bdc8b..00000000000
  6196. --- a/selftest/knownfail.d/smbclient-encryption
  6197. +++ /dev/null
  6198. @@ -1,2 +0,0 @@
  6199. -^samba3.blackbox.smbclient.encryption.smbclient.smb3.client.encrypt.required...LOCALSHARE4.enc_desired..simpleserver
  6200. -^samba3.blackbox.smbclient.encryption.smbclient.smb3.client.encrypt.required...LOCALSHARE4.tmp..simpleserver
  6201. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  6202. index 736c565a7a8..d536e0597af 100644
  6203. --- a/source3/libsmb/clidfs.c
  6204. +++ b/source3/libsmb/clidfs.c
  6205. @@ -106,7 +106,7 @@ static NTSTATUS cli_cm_force_encryption_creds(struct cli_state *c,
  6206. static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6207. const char *server,
  6208. const char *share,
  6209. - const struct user_auth_info *auth_info,
  6210. + struct cli_credentials *creds,
  6211. int max_protocol,
  6212. const struct sockaddr_storage *dest_ss,
  6213. int port,
  6214. @@ -120,12 +120,12 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6215. NTSTATUS status;
  6216. int flags = 0;
  6217. enum protocol_types protocol = PROTOCOL_NONE;
  6218. - int signing_state = get_cmdline_auth_info_signing_state(auth_info);
  6219. - struct cli_credentials *creds = NULL;
  6220. - bool force_encrypt =
  6221. - get_cmdline_auth_info_smb_encrypt(auth_info);
  6222. + enum smb_signing_setting signing_state =
  6223. + cli_credentials_get_smb_signing(creds);
  6224. + enum smb_encryption_setting encryption_state =
  6225. + cli_credentials_get_smb_encryption(creds);
  6226. - if (force_encrypt) {
  6227. + if (encryption_state >= SMB_ENCRYPTION_DESIRED) {
  6228. signing_state = SMB_SIGNING_REQUIRED;
  6229. }
  6230. @@ -192,13 +192,12 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6231. smb2cli_conn_set_max_credits(c->conn, DEFAULT_SMB2_MAX_CREDITS);
  6232. }
  6233. - creds = get_cmdline_auth_info_creds(auth_info);
  6234. -
  6235. status = cli_session_setup_creds(c, creds);
  6236. if (!NT_STATUS_IS_OK(status)) {
  6237. /* If a password was not supplied then
  6238. * try again with a null username. */
  6239. - if (force_encrypt || smbXcli_conn_signing_mandatory(c->conn) ||
  6240. + if (encryption_state == SMB_ENCRYPTION_REQUIRED ||
  6241. + smbXcli_conn_signing_mandatory(c->conn) ||
  6242. cli_credentials_authentication_requested(creds) ||
  6243. cli_credentials_is_anonymous(creds) ||
  6244. !NT_STATUS_IS_OK(status = cli_session_setup_anon(c)))
  6245. @@ -233,7 +232,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6246. creds)) {
  6247. cli_shutdown(c);
  6248. return do_connect(ctx, newserver,
  6249. - newshare, auth_info,
  6250. + newshare, creds,
  6251. max_protocol,
  6252. NULL, port, name_type, pcli);
  6253. }
  6254. @@ -247,13 +246,19 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  6255. return status;
  6256. }
  6257. - if (force_encrypt) {
  6258. + if (encryption_state >= SMB_ENCRYPTION_DESIRED) {
  6259. status = cli_cm_force_encryption_creds(c,
  6260. creds,
  6261. sharename);
  6262. if (!NT_STATUS_IS_OK(status)) {
  6263. - cli_shutdown(c);
  6264. - return status;
  6265. + switch (encryption_state) {
  6266. + case SMB_ENCRYPTION_DESIRED:
  6267. + break;
  6268. + case SMB_ENCRYPTION_REQUIRED:
  6269. + default:
  6270. + cli_shutdown(c);
  6271. + return status;
  6272. + }
  6273. }
  6274. }
  6275. @@ -295,10 +300,11 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  6276. struct cli_state **pcli)
  6277. {
  6278. struct cli_state *cli = NULL;
  6279. + struct cli_credentials *creds = get_cmdline_auth_info_creds(auth_info);
  6280. NTSTATUS status;
  6281. status = do_connect(ctx, server, share,
  6282. - auth_info,
  6283. + creds,
  6284. max_protocol,
  6285. dest_ss, port, name_type, &cli);
  6286. --
  6287. 2.29.2
  6288. From 5997be2fc0d9b25c7a81d1d21e3cc1cd3f55e66f Mon Sep 17 00:00:00 2001
  6289. From: Andreas Schneider <asn@samba.org>
  6290. Date: Tue, 18 Aug 2020 17:18:16 +0200
  6291. Subject: [PATCH 067/104] s3:libsmb: Pass cli_credentials to cli_cm_connect()
  6292. Signed-off-by: Andreas Schneider <asn@samba.org>
  6293. Reviewed-by: Jeremy Allison <jra@samba.org>
  6294. (cherry picked from commit c8349111243fec81a2b95484e56a6d6bebaba80e)
  6295. ---
  6296. source3/libsmb/clidfs.c | 9 +++++----
  6297. 1 file changed, 5 insertions(+), 4 deletions(-)
  6298. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  6299. index d536e0597af..a2c6f5fe5ec 100644
  6300. --- a/source3/libsmb/clidfs.c
  6301. +++ b/source3/libsmb/clidfs.c
  6302. @@ -292,7 +292,7 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  6303. struct cli_state *referring_cli,
  6304. const char *server,
  6305. const char *share,
  6306. - const struct user_auth_info *auth_info,
  6307. + struct cli_credentials *creds,
  6308. int max_protocol,
  6309. const struct sockaddr_storage *dest_ss,
  6310. int port,
  6311. @@ -300,7 +300,6 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  6312. struct cli_state **pcli)
  6313. {
  6314. struct cli_state *cli = NULL;
  6315. - struct cli_credentials *creds = get_cmdline_auth_info_creds(auth_info);
  6316. NTSTATUS status;
  6317. status = do_connect(ctx, server, share,
  6318. @@ -397,6 +396,7 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6319. {
  6320. /* Try to reuse an existing connection in this list. */
  6321. struct cli_state *c = cli_cm_find(referring_cli, server, share);
  6322. + struct cli_credentials *creds = get_cmdline_auth_info_creds(auth_info);
  6323. NTSTATUS status;
  6324. if (c) {
  6325. @@ -417,7 +417,7 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6326. referring_cli,
  6327. server,
  6328. share,
  6329. - auth_info,
  6330. + creds,
  6331. max_protocol,
  6332. dest_ss,
  6333. port,
  6334. @@ -886,6 +886,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  6335. struct smbXcli_tcon *root_tcon = NULL;
  6336. struct smbXcli_tcon *target_tcon = NULL;
  6337. struct cli_dfs_path_split *dfs_refs = NULL;
  6338. + struct cli_credentials *creds = get_cmdline_auth_info_creds(dfs_auth_info);
  6339. if ( !rootcli || !path || !targetcli ) {
  6340. return NT_STATUS_INVALID_PARAMETER;
  6341. @@ -1022,7 +1023,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  6342. status = cli_cm_connect(ctx, rootcli,
  6343. dfs_refs[count].server,
  6344. dfs_refs[count].share,
  6345. - dfs_auth_info,
  6346. + creds,
  6347. smbXcli_conn_protocol(rootcli->conn),
  6348. NULL, /* dest_ss */
  6349. 0, /* port */
  6350. --
  6351. 2.29.2
  6352. From 62109132050092a5b4ac81d80cb358e563da605c Mon Sep 17 00:00:00 2001
  6353. From: Andreas Schneider <asn@samba.org>
  6354. Date: Tue, 18 Aug 2020 17:26:54 +0200
  6355. Subject: [PATCH 068/104] s3:libsmb: Pass cli_credentials to cli_cm_open()
  6356. Signed-off-by: Andreas Schneider <asn@samba.org>
  6357. Reviewed-by: Jeremy Allison <jra@samba.org>
  6358. (cherry picked from commit df1623abd7267916696e2e60c146ef8fa6c9dfc9)
  6359. ---
  6360. source3/client/client.c | 23 ++++++++++++++++++-----
  6361. source3/lib/netapi/cm.c | 4 +++-
  6362. source3/libsmb/clidfs.c | 25 ++++++++++++-------------
  6363. source3/libsmb/proto.h | 18 +++++++++---------
  6364. 4 files changed, 42 insertions(+), 28 deletions(-)
  6365. diff --git a/source3/client/client.c b/source3/client/client.c
  6366. index 3a610086511..c54b5065b44 100644
  6367. --- a/source3/client/client.c
  6368. +++ b/source3/client/client.c
  6369. @@ -5546,6 +5546,8 @@ static int process_command_string(const char *cmd_in)
  6370. TALLOC_CTX *ctx = talloc_tos();
  6371. char *cmd = talloc_strdup(ctx, cmd_in);
  6372. int rc = 0;
  6373. + struct cli_credentials *creds =
  6374. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6375. if (!cmd) {
  6376. return 1;
  6377. @@ -5557,7 +5559,8 @@ static int process_command_string(const char *cmd_in)
  6378. status = cli_cm_open(talloc_tos(), NULL,
  6379. desthost,
  6380. - service, popt_get_cmdline_auth_info(),
  6381. + service,
  6382. + creds,
  6383. max_protocol,
  6384. have_ip ? &dest_ss : NULL, port,
  6385. name_type,
  6386. @@ -5998,10 +6001,13 @@ static int process(const char *base_directory)
  6387. {
  6388. int rc = 0;
  6389. NTSTATUS status;
  6390. + struct cli_credentials *creds =
  6391. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6392. status = cli_cm_open(talloc_tos(), NULL,
  6393. desthost,
  6394. - service, popt_get_cmdline_auth_info(),
  6395. + service,
  6396. + creds,
  6397. max_protocol,
  6398. have_ip ? &dest_ss : NULL, port,
  6399. name_type, &cli);
  6400. @@ -6036,10 +6042,13 @@ static int process(const char *base_directory)
  6401. static int do_host_query(const char *query_host)
  6402. {
  6403. NTSTATUS status;
  6404. + struct cli_credentials *creds =
  6405. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6406. status = cli_cm_open(talloc_tos(), NULL,
  6407. query_host,
  6408. - "IPC$", popt_get_cmdline_auth_info(),
  6409. + "IPC$",
  6410. + creds,
  6411. max_protocol,
  6412. have_ip ? &dest_ss : NULL, port,
  6413. name_type, &cli);
  6414. @@ -6086,7 +6095,8 @@ static int do_host_query(const char *query_host)
  6415. d_printf("Reconnecting with SMB1 for workgroup listing.\n");
  6416. status = cli_cm_open(talloc_tos(), NULL,
  6417. query_host,
  6418. - "IPC$", popt_get_cmdline_auth_info(),
  6419. + "IPC$",
  6420. + creds,
  6421. max_proto,
  6422. have_ip ? &dest_ss : NULL, NBT_SMB_PORT,
  6423. name_type, &cli);
  6424. @@ -6113,6 +6123,8 @@ static int do_tar_op(const char *base_directory)
  6425. {
  6426. struct tar *tar_ctx = tar_get_ctx();
  6427. int ret = 0;
  6428. + struct cli_credentials *creds =
  6429. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6430. /* do we already have a connection? */
  6431. if (!cli) {
  6432. @@ -6120,7 +6132,8 @@ static int do_tar_op(const char *base_directory)
  6433. status = cli_cm_open(talloc_tos(), NULL,
  6434. desthost,
  6435. - service, popt_get_cmdline_auth_info(),
  6436. + service,
  6437. + creds,
  6438. max_protocol,
  6439. have_ip ? &dest_ss : NULL, port,
  6440. name_type, &cli);
  6441. diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c
  6442. index 0fd31ef3d5a..943f7498e8c 100644
  6443. --- a/source3/lib/netapi/cm.c
  6444. +++ b/source3/lib/netapi/cm.c
  6445. @@ -71,6 +71,7 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
  6446. struct cli_state *cli_ipc = NULL;
  6447. struct client_ipc_connection *p;
  6448. NTSTATUS status;
  6449. + struct cli_credentials *creds = NULL;
  6450. if (!ctx || !pp || !server_name) {
  6451. return WERR_INVALID_PARAMETER;
  6452. @@ -106,10 +107,11 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
  6453. if (ctx->use_ccache) {
  6454. set_cmdline_auth_info_use_ccache(auth_info, true);
  6455. }
  6456. + creds = get_cmdline_auth_info_creds(auth_info);
  6457. status = cli_cm_open(ctx, NULL,
  6458. server_name, "IPC$",
  6459. - auth_info,
  6460. + creds,
  6461. lp_client_ipc_max_protocol(),
  6462. NULL, 0, 0x20, &cli_ipc);
  6463. if (!NT_STATUS_IS_OK(status)) {
  6464. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  6465. index a2c6f5fe5ec..ef75fb36a45 100644
  6466. --- a/source3/libsmb/clidfs.c
  6467. +++ b/source3/libsmb/clidfs.c
  6468. @@ -384,19 +384,18 @@ static struct cli_state *cli_cm_find(struct cli_state *cli,
  6469. ****************************************************************************/
  6470. NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6471. - struct cli_state *referring_cli,
  6472. - const char *server,
  6473. - const char *share,
  6474. - const struct user_auth_info *auth_info,
  6475. - int max_protocol,
  6476. - const struct sockaddr_storage *dest_ss,
  6477. - int port,
  6478. - int name_type,
  6479. - struct cli_state **pcli)
  6480. + struct cli_state *referring_cli,
  6481. + const char *server,
  6482. + const char *share,
  6483. + struct cli_credentials *creds,
  6484. + int max_protocol,
  6485. + const struct sockaddr_storage *dest_ss,
  6486. + int port,
  6487. + int name_type,
  6488. + struct cli_state **pcli)
  6489. {
  6490. /* Try to reuse an existing connection in this list. */
  6491. struct cli_state *c = cli_cm_find(referring_cli, server, share);
  6492. - struct cli_credentials *creds = get_cmdline_auth_info_creds(auth_info);
  6493. NTSTATUS status;
  6494. if (c) {
  6495. @@ -404,11 +403,11 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6496. return NT_STATUS_OK;
  6497. }
  6498. - if (auth_info == NULL) {
  6499. + if (creds == NULL) {
  6500. /* Can't do a new connection
  6501. * without auth info. */
  6502. d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
  6503. - "without auth info\n",
  6504. + "without client credentials\n",
  6505. server, share );
  6506. return NT_STATUS_INVALID_PARAMETER;
  6507. }
  6508. @@ -966,7 +965,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  6509. rootcli,
  6510. smbXcli_conn_remote_name(rootcli->conn),
  6511. "IPC$",
  6512. - dfs_auth_info,
  6513. + creds,
  6514. smbXcli_conn_protocol(rootcli->conn),
  6515. NULL, /* dest_ss not needed, we reuse the transport */
  6516. 0,
  6517. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  6518. index f2b0a8c5ff8..0b8cf2a6036 100644
  6519. --- a/source3/libsmb/proto.h
  6520. +++ b/source3/libsmb/proto.h
  6521. @@ -124,15 +124,15 @@ struct cli_state *get_ipc_connect_master_ip(TALLOC_CTX *ctx,
  6522. /* The following definitions come from libsmb/clidfs.c */
  6523. NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  6524. - struct cli_state *referring_cli,
  6525. - const char *server,
  6526. - const char *share,
  6527. - const struct user_auth_info *auth_info,
  6528. - int max_protocol,
  6529. - const struct sockaddr_storage *dest_ss,
  6530. - int port,
  6531. - int name_type,
  6532. - struct cli_state **pcli);
  6533. + struct cli_state *referring_cli,
  6534. + const char *server,
  6535. + const char *share,
  6536. + struct cli_credentials *creds,
  6537. + int max_protocol,
  6538. + const struct sockaddr_storage *dest_ss,
  6539. + int port,
  6540. + int name_type,
  6541. + struct cli_state **pcli);
  6542. void cli_cm_display(struct cli_state *c);
  6543. struct client_dfs_referral;
  6544. NTSTATUS cli_dfs_get_referral_ex(TALLOC_CTX *ctx,
  6545. --
  6546. 2.29.2
  6547. From 9500031d977b874b32085df3ff7f5b0ae28514c6 Mon Sep 17 00:00:00 2001
  6548. From: Andreas Schneider <asn@samba.org>
  6549. Date: Tue, 18 Aug 2020 17:42:25 +0200
  6550. Subject: [PATCH 069/104] s3:libsmb: Pass cli_credentials to
  6551. cli_resolve_path(), using helper variables.
  6552. Signed-off-by: Andreas Schneider <asn@samba.org>
  6553. Signed-off-by: Jeremy Allison <jra@samba.org>
  6554. (cherry picked from commit 5245ab3c4dacc88d5cbe3bb1e3e339e4fb77a4db)
  6555. ---
  6556. source3/client/client.c | 148 +++++++++++++++++++++++++++-------
  6557. source3/libsmb/clidfs.c | 5 +-
  6558. source3/libsmb/libsmb_dir.c | 43 ++++++++--
  6559. source3/libsmb/libsmb_file.c | 13 ++-
  6560. source3/libsmb/libsmb_stat.c | 6 +-
  6561. source3/libsmb/libsmb_xattr.c | 13 ++-
  6562. source3/libsmb/proto.h | 2 +-
  6563. source3/utils/smbcacls.c | 5 +-
  6564. 8 files changed, 188 insertions(+), 47 deletions(-)
  6565. diff --git a/source3/client/client.c b/source3/client/client.c
  6566. index c54b5065b44..13e48f80a01 100644
  6567. --- a/source3/client/client.c
  6568. +++ b/source3/client/client.c
  6569. @@ -298,9 +298,14 @@ static int do_dskattr(void)
  6570. struct cli_state *targetcli = NULL;
  6571. char *targetpath = NULL;
  6572. TALLOC_CTX *ctx = talloc_tos();
  6573. + struct cli_credentials *creds =
  6574. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6575. NTSTATUS status;
  6576. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(), cli,
  6577. + status = cli_resolve_path(ctx,
  6578. + "",
  6579. + creds,
  6580. + cli,
  6581. client_get_cur_dir(), &targetcli,
  6582. &targetpath);
  6583. if (!NT_STATUS_IS_OK(status)) {
  6584. @@ -390,6 +395,8 @@ static int do_cd(const char *new_dir)
  6585. uint32_t attributes;
  6586. int ret = 1;
  6587. TALLOC_CTX *ctx = talloc_stackframe();
  6588. + struct cli_credentials *creds =
  6589. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6590. NTSTATUS status;
  6591. newdir = talloc_strdup(ctx, new_dir);
  6592. @@ -432,7 +439,8 @@ static int do_cd(const char *new_dir)
  6593. new_cd = client_clean_name(ctx, new_cd);
  6594. client_set_cur_dir(new_cd);
  6595. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6596. + status = cli_resolve_path(ctx, "",
  6597. + creds,
  6598. cli, new_cd, &targetcli, &targetpath);
  6599. if (!NT_STATUS_IS_OK(status)) {
  6600. d_printf("cd %s: %s\n", new_cd, nt_errstr(status));
  6601. @@ -809,6 +817,8 @@ NTSTATUS do_list(const char *mask,
  6602. TALLOC_CTX *ctx = talloc_tos();
  6603. struct cli_state *targetcli = NULL;
  6604. char *targetpath = NULL;
  6605. + struct cli_credentials *creds =
  6606. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6607. NTSTATUS ret_status = NT_STATUS_OK;
  6608. NTSTATUS status = NT_STATUS_OK;
  6609. @@ -832,7 +842,7 @@ NTSTATUS do_list(const char *mask,
  6610. /* check for dfs */
  6611. status = cli_resolve_path(ctx, "",
  6612. - popt_get_cmdline_auth_info(),
  6613. + creds,
  6614. cli, head, &targetcli, &targetpath);
  6615. if (!NT_STATUS_IS_OK(status)) {
  6616. d_printf("do_list: [%s] %s\n", head,
  6617. @@ -1042,6 +1052,8 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
  6618. struct cli_state *targetcli = NULL;
  6619. char *targetname = NULL;
  6620. char *lname = NULL;
  6621. + struct cli_credentials *creds =
  6622. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6623. NTSTATUS status;
  6624. lname = talloc_strdup(ctx, lname_in);
  6625. @@ -1056,7 +1068,8 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
  6626. }
  6627. }
  6628. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6629. + status = cli_resolve_path(ctx, "",
  6630. + creds,
  6631. cli, rname, &targetcli, &targetname);
  6632. if (!NT_STATUS_IS_OK(status)) {
  6633. d_printf("Failed to open %s: %s\n", rname, nt_errstr(status));
  6634. @@ -1413,9 +1426,12 @@ static bool do_mkdir(const char *name)
  6635. TALLOC_CTX *ctx = talloc_tos();
  6636. struct cli_state *targetcli;
  6637. char *targetname = NULL;
  6638. + struct cli_credentials *creds =
  6639. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6640. NTSTATUS status;
  6641. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6642. + status = cli_resolve_path(ctx, "",
  6643. + creds,
  6644. cli, name, &targetcli, &targetname);
  6645. if (!NT_STATUS_IS_OK(status)) {
  6646. d_printf("mkdir %s: %s\n", name, nt_errstr(status));
  6647. @@ -1474,6 +1490,8 @@ static int cmd_mkdir(void)
  6648. TALLOC_CTX *ctx = talloc_tos();
  6649. char *mask = NULL;
  6650. char *buf = NULL;
  6651. + struct cli_credentials *creds =
  6652. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6653. NTSTATUS status;
  6654. mask = talloc_strdup(ctx, client_get_cur_dir());
  6655. @@ -1510,7 +1528,8 @@ static int cmd_mkdir(void)
  6656. }
  6657. status = cli_resolve_path(ctx, "",
  6658. - popt_get_cmdline_auth_info(), cli, mask,
  6659. + creds,
  6660. + cli, mask,
  6661. &targetcli, &targetname);
  6662. if (!NT_STATUS_IS_OK(status)) {
  6663. return 1;
  6664. @@ -1824,9 +1843,12 @@ static int do_put(const char *rname, const char *lname, bool reput)
  6665. struct cli_state *targetcli;
  6666. char *targetname = NULL;
  6667. struct push_state state;
  6668. + struct cli_credentials *creds =
  6669. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6670. NTSTATUS status;
  6671. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6672. + status = cli_resolve_path(ctx, "",
  6673. + creds,
  6674. cli, rname, &targetcli, &targetname);
  6675. if (!NT_STATUS_IS_OK(status)) {
  6676. d_printf("Failed to open %s: %s\n", rname, nt_errstr(status));
  6677. @@ -2601,6 +2623,8 @@ static int cmd_wdel(void)
  6678. uint32_t attribute;
  6679. struct cli_state *targetcli;
  6680. char *targetname = NULL;
  6681. + struct cli_credentials *creds =
  6682. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6683. NTSTATUS status;
  6684. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6685. @@ -2626,7 +2650,8 @@ static int cmd_wdel(void)
  6686. return 1;
  6687. }
  6688. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6689. + status = cli_resolve_path(ctx, "",
  6690. + creds,
  6691. cli, mask, &targetcli, &targetname);
  6692. if (!NT_STATUS_IS_OK(status)) {
  6693. d_printf("cmd_wdel %s: %s\n", mask, nt_errstr(status));
  6694. @@ -2652,6 +2677,8 @@ static int cmd_open(void)
  6695. char *targetname = NULL;
  6696. struct cli_state *targetcli;
  6697. uint16_t fnum = (uint16_t)-1;
  6698. + struct cli_credentials *creds =
  6699. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6700. NTSTATUS status;
  6701. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6702. @@ -2671,7 +2698,8 @@ static int cmd_open(void)
  6703. return 1;
  6704. }
  6705. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6706. + status = cli_resolve_path(ctx, "",
  6707. + creds,
  6708. cli, mask, &targetcli, &targetname);
  6709. if (!NT_STATUS_IS_OK(status)) {
  6710. d_printf("open %s: %s\n", mask, nt_errstr(status));
  6711. @@ -2773,6 +2801,8 @@ static int cmd_posix_open(void)
  6712. struct cli_state *targetcli;
  6713. mode_t mode;
  6714. uint16_t fnum;
  6715. + struct cli_credentials *creds =
  6716. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6717. NTSTATUS status;
  6718. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6719. @@ -2797,7 +2827,8 @@ static int cmd_posix_open(void)
  6720. }
  6721. mode = (mode_t)strtol(buf, (char **)NULL, 8);
  6722. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6723. + status = cli_resolve_path(ctx, "",
  6724. + creds,
  6725. cli, mask, &targetcli, &targetname);
  6726. if (!NT_STATUS_IS_OK(status)) {
  6727. d_printf("posix_open %s: %s\n", mask, nt_errstr(status));
  6728. @@ -2832,6 +2863,8 @@ static int cmd_posix_mkdir(void)
  6729. char *targetname = NULL;
  6730. struct cli_state *targetcli;
  6731. mode_t mode;
  6732. + struct cli_credentials *creds =
  6733. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6734. NTSTATUS status;
  6735. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6736. @@ -2856,7 +2889,8 @@ static int cmd_posix_mkdir(void)
  6737. }
  6738. mode = (mode_t)strtol(buf, (char **)NULL, 8);
  6739. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6740. + status = cli_resolve_path(ctx, "",
  6741. + creds,
  6742. cli, mask, &targetcli, &targetname);
  6743. if (!NT_STATUS_IS_OK(status)) {
  6744. d_printf("posix_mkdir %s: %s\n", mask, nt_errstr(status));
  6745. @@ -2880,6 +2914,8 @@ static int cmd_posix_unlink(void)
  6746. char *buf = NULL;
  6747. char *targetname = NULL;
  6748. struct cli_state *targetcli;
  6749. + struct cli_credentials *creds =
  6750. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6751. NTSTATUS status;
  6752. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6753. @@ -2898,7 +2934,8 @@ static int cmd_posix_unlink(void)
  6754. return 1;
  6755. }
  6756. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6757. + status = cli_resolve_path(ctx, "",
  6758. + creds,
  6759. cli, mask, &targetcli, &targetname);
  6760. if (!NT_STATUS_IS_OK(status)) {
  6761. d_printf("posix_unlink %s: %s\n", mask, nt_errstr(status));
  6762. @@ -2923,6 +2960,8 @@ static int cmd_posix_rmdir(void)
  6763. char *buf = NULL;
  6764. char *targetname = NULL;
  6765. struct cli_state *targetcli;
  6766. + struct cli_credentials *creds =
  6767. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6768. NTSTATUS status;
  6769. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6770. @@ -2941,7 +2980,8 @@ static int cmd_posix_rmdir(void)
  6771. return 1;
  6772. }
  6773. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6774. + status = cli_resolve_path(ctx, "",
  6775. + creds,
  6776. cli, mask, &targetcli, &targetname);
  6777. if (!NT_STATUS_IS_OK(status)) {
  6778. d_printf("posix_rmdir %s: %s\n", mask, nt_errstr(status));
  6779. @@ -3230,6 +3270,8 @@ static int cmd_rmdir(void)
  6780. char *buf = NULL;
  6781. char *targetname = NULL;
  6782. struct cli_state *targetcli;
  6783. + struct cli_credentials *creds =
  6784. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6785. NTSTATUS status;
  6786. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6787. @@ -3248,7 +3290,8 @@ static int cmd_rmdir(void)
  6788. return 1;
  6789. }
  6790. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6791. + status = cli_resolve_path(ctx, "",
  6792. + creds,
  6793. cli, mask, &targetcli, &targetname);
  6794. if (!NT_STATUS_IS_OK(status)) {
  6795. d_printf("rmdir %s: %s\n", mask, nt_errstr(status));
  6796. @@ -3277,6 +3320,8 @@ static int cmd_link(void)
  6797. char *buf2 = NULL;
  6798. char *targetname = NULL;
  6799. struct cli_state *targetcli;
  6800. + struct cli_credentials *creds =
  6801. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6802. NTSTATUS status;
  6803. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
  6804. @@ -3307,7 +3352,8 @@ static int cmd_link(void)
  6805. return 1;
  6806. }
  6807. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6808. + status = cli_resolve_path(ctx, "",
  6809. + creds,
  6810. cli, oldname, &targetcli, &targetname);
  6811. if (!NT_STATUS_IS_OK(status)) {
  6812. d_printf("link %s: %s\n", oldname, nt_errstr(status));
  6813. @@ -3340,6 +3386,8 @@ static int cmd_readlink(void)
  6814. char *targetname = NULL;
  6815. char *linkname = NULL;
  6816. struct cli_state *targetcli;
  6817. + struct cli_credentials *creds =
  6818. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6819. NTSTATUS status;
  6820. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
  6821. @@ -3358,7 +3406,8 @@ static int cmd_readlink(void)
  6822. return 1;
  6823. }
  6824. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6825. + status = cli_resolve_path(ctx, "",
  6826. + creds,
  6827. cli, name, &targetcli, &targetname);
  6828. if (!NT_STATUS_IS_OK(status)) {
  6829. d_printf("readlink %s: %s\n", name, nt_errstr(status));
  6830. @@ -3397,6 +3446,8 @@ static int cmd_symlink(void)
  6831. char *buf = NULL;
  6832. char *buf2 = NULL;
  6833. struct cli_state *newcli;
  6834. + struct cli_credentials *creds =
  6835. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6836. NTSTATUS status;
  6837. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
  6838. @@ -3419,7 +3470,8 @@ static int cmd_symlink(void)
  6839. }
  6840. /* New name must be present in share namespace. */
  6841. status = cli_resolve_path(ctx, "",
  6842. - popt_get_cmdline_auth_info(), cli, newname,
  6843. + creds,
  6844. + cli, newname,
  6845. &newcli, &newname);
  6846. if (!NT_STATUS_IS_OK(status)) {
  6847. d_printf("link %s: %s\n", newname,
  6848. @@ -3455,6 +3507,8 @@ static int cmd_chmod(void)
  6849. char *targetname = NULL;
  6850. struct cli_state *targetcli;
  6851. mode_t mode;
  6852. + struct cli_credentials *creds =
  6853. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6854. NTSTATUS status;
  6855. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
  6856. @@ -3476,7 +3530,8 @@ static int cmd_chmod(void)
  6857. mode = (mode_t)strtol(buf, NULL, 8);
  6858. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6859. + status = cli_resolve_path(ctx, "",
  6860. + creds,
  6861. cli, src, &targetcli, &targetname);
  6862. if (!NT_STATUS_IS_OK(status)) {
  6863. d_printf("chmod %s: %s\n", src, nt_errstr(status));
  6864. @@ -3620,6 +3675,8 @@ static int cmd_getfacl(void)
  6865. size_t num_dir_acls = 0;
  6866. size_t expected_buflen;
  6867. uint16_t i;
  6868. + struct cli_credentials *creds =
  6869. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6870. NTSTATUS status;
  6871. if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
  6872. @@ -3638,7 +3695,8 @@ static int cmd_getfacl(void)
  6873. return 1;
  6874. }
  6875. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6876. + status = cli_resolve_path(ctx, "",
  6877. + creds,
  6878. cli, src, &targetcli, &targetname);
  6879. if (!NT_STATUS_IS_OK(status)) {
  6880. d_printf("stat %s: %s\n", src, nt_errstr(status));
  6881. @@ -3803,6 +3861,8 @@ static int cmd_geteas(void)
  6882. NTSTATUS status;
  6883. size_t i, num_eas;
  6884. struct ea_struct *eas;
  6885. + struct cli_credentials *creds =
  6886. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6887. if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
  6888. d_printf("geteas filename\n");
  6889. @@ -3820,7 +3880,8 @@ static int cmd_geteas(void)
  6890. return 1;
  6891. }
  6892. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6893. + status = cli_resolve_path(ctx, "",
  6894. + creds,
  6895. cli, src, &targetcli, &targetname);
  6896. if (!NT_STATUS_IS_OK(status)) {
  6897. d_printf("stat %s: %s\n", src, nt_errstr(status));
  6898. @@ -3859,6 +3920,8 @@ static int cmd_setea(void)
  6899. char *eavalue = NULL;
  6900. char *targetname = NULL;
  6901. struct cli_state *targetcli;
  6902. + struct cli_credentials *creds =
  6903. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6904. NTSTATUS status;
  6905. if (!next_token_talloc(ctx, &cmd_ptr, &name, NULL)
  6906. @@ -3881,7 +3944,8 @@ static int cmd_setea(void)
  6907. return 1;
  6908. }
  6909. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6910. + status = cli_resolve_path(ctx, "",
  6911. + creds,
  6912. cli, src, &targetcli, &targetname);
  6913. if (!NT_STATUS_IS_OK(status)) {
  6914. d_printf("stat %s: %s\n", src, nt_errstr(status));
  6915. @@ -3913,6 +3977,8 @@ static int cmd_stat(void)
  6916. SMB_STRUCT_STAT sbuf;
  6917. struct tm *lt;
  6918. time_t tmp_time;
  6919. + struct cli_credentials *creds =
  6920. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6921. NTSTATUS status;
  6922. if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
  6923. @@ -3931,7 +3997,8 @@ static int cmd_stat(void)
  6924. return 1;
  6925. }
  6926. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6927. + status = cli_resolve_path(ctx, "",
  6928. + creds,
  6929. cli, src, &targetcli, &targetname);
  6930. if (!NT_STATUS_IS_OK(status)) {
  6931. d_printf("stat %s: %s\n", src, nt_errstr(status));
  6932. @@ -4020,6 +4087,8 @@ static int cmd_chown(void)
  6933. char *buf, *buf2, *buf3;
  6934. struct cli_state *targetcli;
  6935. char *targetname = NULL;
  6936. + struct cli_credentials *creds =
  6937. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6938. NTSTATUS status;
  6939. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
  6940. @@ -4043,7 +4112,8 @@ static int cmd_chown(void)
  6941. if (src == NULL) {
  6942. return 1;
  6943. }
  6944. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6945. + status = cli_resolve_path(ctx, "",
  6946. + creds,
  6947. cli, src, &targetcli, &targetname);
  6948. if (!NT_STATUS_IS_OK(status)) {
  6949. d_printf("chown %s: %s\n", src, nt_errstr(status));
  6950. @@ -4077,6 +4147,8 @@ static int cmd_rename(void)
  6951. struct cli_state *targetcli;
  6952. char *targetsrc;
  6953. char *targetdest;
  6954. + struct cli_credentials *creds =
  6955. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6956. NTSTATUS status;
  6957. bool replace = false;
  6958. @@ -4115,14 +4187,16 @@ static int cmd_rename(void)
  6959. replace = true;
  6960. }
  6961. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6962. + status = cli_resolve_path(ctx, "",
  6963. + creds,
  6964. cli, src, &targetcli, &targetsrc);
  6965. if (!NT_STATUS_IS_OK(status)) {
  6966. d_printf("rename %s: %s\n", src, nt_errstr(status));
  6967. return 1;
  6968. }
  6969. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6970. + status = cli_resolve_path(ctx, "",
  6971. + creds,
  6972. cli, dest, &targetcli, &targetdest);
  6973. if (!NT_STATUS_IS_OK(status)) {
  6974. d_printf("rename %s: %s\n", dest, nt_errstr(status));
  6975. @@ -4179,6 +4253,8 @@ static int cmd_scopy(void)
  6976. off_t written = 0;
  6977. struct scopy_timing st;
  6978. int rc = 0;
  6979. + struct cli_credentials *creds =
  6980. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  6981. NTSTATUS status;
  6982. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
  6983. @@ -4211,14 +4287,16 @@ static int cmd_scopy(void)
  6984. return 1;
  6985. }
  6986. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6987. + status = cli_resolve_path(ctx, "",
  6988. + creds,
  6989. cli, src, &targetcli, &targetsrc);
  6990. if (!NT_STATUS_IS_OK(status)) {
  6991. d_printf("scopy %s: %s\n", src, nt_errstr(status));
  6992. return 1;
  6993. }
  6994. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  6995. + status = cli_resolve_path(ctx, "",
  6996. + creds,
  6997. cli, dest, &targetcli, &targetdest);
  6998. if (!NT_STATUS_IS_OK(status)) {
  6999. d_printf("scopy %s: %s\n", dest, nt_errstr(status));
  7000. @@ -4317,6 +4395,8 @@ static int cmd_hardlink(void)
  7001. char *buf, *buf2;
  7002. struct cli_state *targetcli;
  7003. char *targetname;
  7004. + struct cli_credentials *creds =
  7005. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  7006. NTSTATUS status;
  7007. if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
  7008. @@ -4349,7 +4429,8 @@ static int cmd_hardlink(void)
  7009. return 1;
  7010. }
  7011. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  7012. + status = cli_resolve_path(ctx, "",
  7013. + creds,
  7014. cli, src, &targetcli, &targetname);
  7015. if (!NT_STATUS_IS_OK(status)) {
  7016. d_printf("hardlink %s: %s\n", src, nt_errstr(status));
  7017. @@ -5023,9 +5104,13 @@ static int cmd_show_connect( void )
  7018. TALLOC_CTX *ctx = talloc_tos();
  7019. struct cli_state *targetcli;
  7020. char *targetpath;
  7021. + struct cli_credentials *creds =
  7022. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  7023. NTSTATUS status;
  7024. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(), cli,
  7025. + status = cli_resolve_path(ctx, "",
  7026. + creds,
  7027. + cli,
  7028. client_get_cur_dir(), &targetcli,
  7029. &targetpath);
  7030. if (!NT_STATUS_IS_OK(status)) {
  7031. @@ -5685,6 +5770,8 @@ static char **remote_completion(const char *text, int len)
  7032. struct cli_state *targetcli = NULL;
  7033. int i;
  7034. struct completion_remote info = { NULL, NULL, 1, 0, NULL, 0 };
  7035. + struct cli_credentials *creds =
  7036. + get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
  7037. NTSTATUS status;
  7038. /* can't have non-static initialisation on Sun CC, so do it
  7039. @@ -5745,7 +5832,8 @@ static char **remote_completion(const char *text, int len)
  7040. goto cleanup;
  7041. }
  7042. - status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
  7043. + status = cli_resolve_path(ctx, "",
  7044. + creds,
  7045. cli, dirmask, &targetcli, &targetpath);
  7046. if (!NT_STATUS_IS_OK(status)) {
  7047. goto cleanup;
  7048. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  7049. index ef75fb36a45..e6695159a96 100644
  7050. --- a/source3/libsmb/clidfs.c
  7051. +++ b/source3/libsmb/clidfs.c
  7052. @@ -859,7 +859,7 @@ struct cli_dfs_path_split {
  7053. NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  7054. const char *mountpt,
  7055. - const struct user_auth_info *dfs_auth_info,
  7056. + struct cli_credentials *creds,
  7057. struct cli_state *rootcli,
  7058. const char *path,
  7059. struct cli_state **targetcli,
  7060. @@ -885,7 +885,6 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  7061. struct smbXcli_tcon *root_tcon = NULL;
  7062. struct smbXcli_tcon *target_tcon = NULL;
  7063. struct cli_dfs_path_split *dfs_refs = NULL;
  7064. - struct cli_credentials *creds = get_cmdline_auth_info_creds(dfs_auth_info);
  7065. if ( !rootcli || !path || !targetcli ) {
  7066. return NT_STATUS_INVALID_PARAMETER;
  7067. @@ -1130,7 +1129,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  7068. if (!strequal(*pp_targetpath, "\\") && !strequal(*pp_targetpath, "/")) {
  7069. status = cli_resolve_path(ctx,
  7070. newmount,
  7071. - dfs_auth_info,
  7072. + creds,
  7073. *targetcli,
  7074. *pp_targetpath,
  7075. &newcli,
  7076. diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
  7077. index 12abb734c2d..0326f27125b 100644
  7078. --- a/source3/libsmb/libsmb_dir.c
  7079. +++ b/source3/libsmb/libsmb_dir.c
  7080. @@ -911,6 +911,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
  7081. */
  7082. char *targetpath;
  7083. struct cli_state *targetcli;
  7084. + struct cli_credentials *creds = NULL;
  7085. NTSTATUS status;
  7086. /* We connect to the server and list the directory */
  7087. @@ -943,8 +944,12 @@ SMBC_opendir_ctx(SMBCCTX *context,
  7088. return NULL;
  7089. }
  7090. + creds = get_cmdline_auth_info_creds(
  7091. + context->internal->auth_info);
  7092. +
  7093. status = cli_resolve_path(
  7094. - frame, "", context->internal->auth_info,
  7095. + frame, "",
  7096. + creds,
  7097. srv->cli, path, &targetcli, &targetpath);
  7098. if (!NT_STATUS_IS_OK(status)) {
  7099. d_printf("Could not resolve %s\n", path);
  7100. @@ -1543,6 +1548,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
  7101. char *targetpath = NULL;
  7102. uint16_t port = 0;
  7103. struct cli_state *targetcli = NULL;
  7104. + struct cli_credentials *creds = NULL;
  7105. TALLOC_CTX *frame = talloc_stackframe();
  7106. NTSTATUS status;
  7107. @@ -1595,8 +1601,11 @@ SMBC_mkdir_ctx(SMBCCTX *context,
  7108. }
  7109. + creds = get_cmdline_auth_info_creds(context->internal->auth_info);
  7110. +
  7111. /*d_printf(">>>mkdir: resolving %s\n", path);*/
  7112. - status = cli_resolve_path(frame, "", context->internal->auth_info,
  7113. + status = cli_resolve_path(frame, "",
  7114. + creds,
  7115. srv->cli, path, &targetcli, &targetpath);
  7116. if (!NT_STATUS_IS_OK(status)) {
  7117. d_printf("Could not resolve %s\n", path);
  7118. @@ -1654,6 +1663,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
  7119. char *targetpath = NULL;
  7120. uint16_t port = 0;
  7121. struct cli_state *targetcli = NULL;
  7122. + struct cli_credentials *creds = NULL;
  7123. TALLOC_CTX *frame = talloc_stackframe();
  7124. NTSTATUS status;
  7125. @@ -1706,8 +1716,11 @@ SMBC_rmdir_ctx(SMBCCTX *context,
  7126. }
  7127. + creds = get_cmdline_auth_info_creds(context->internal->auth_info),
  7128. +
  7129. /*d_printf(">>>rmdir: resolving %s\n", path);*/
  7130. - status = cli_resolve_path(frame, "", context->internal->auth_info,
  7131. + status = cli_resolve_path(frame, "",
  7132. + creds,
  7133. srv->cli, path, &targetcli, &targetpath);
  7134. if (!NT_STATUS_IS_OK(status)) {
  7135. d_printf("Could not resolve %s\n", path);
  7136. @@ -1959,6 +1972,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
  7137. char *path = NULL;
  7138. uint32_t attr;
  7139. uint16_t port = 0;
  7140. + struct cli_credentials *creds = NULL;
  7141. TALLOC_CTX *frame = talloc_stackframe();
  7142. NTSTATUS status;
  7143. @@ -2010,8 +2024,11 @@ SMBC_chmod_ctx(SMBCCTX *context,
  7144. return -1; /* errno set by SMBC_server */
  7145. }
  7146. + creds = get_cmdline_auth_info_creds(context->internal->auth_info);
  7147. +
  7148. /*d_printf(">>>unlink: resolving %s\n", path);*/
  7149. - status = cli_resolve_path(frame, "", context->internal->auth_info,
  7150. + status = cli_resolve_path(frame, "",
  7151. + creds,
  7152. srv->cli, path, &targetcli, &targetpath);
  7153. if (!NT_STATUS_IS_OK(status)) {
  7154. d_printf("Could not resolve %s\n", path);
  7155. @@ -2152,6 +2169,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
  7156. uint16_t port = 0;
  7157. struct cli_state *targetcli = NULL;
  7158. SMBCSRV *srv = NULL;
  7159. + struct cli_credentials *creds = NULL;
  7160. TALLOC_CTX *frame = talloc_stackframe();
  7161. NTSTATUS status;
  7162. @@ -2204,8 +2222,11 @@ SMBC_unlink_ctx(SMBCCTX *context,
  7163. }
  7164. + creds = get_cmdline_auth_info_creds(context->internal->auth_info);
  7165. +
  7166. /*d_printf(">>>unlink: resolving %s\n", path);*/
  7167. - status = cli_resolve_path(frame, "", context->internal->auth_info,
  7168. + status = cli_resolve_path(frame, "",
  7169. + creds,
  7170. srv->cli, path, &targetcli, &targetpath);
  7171. if (!NT_STATUS_IS_OK(status)) {
  7172. d_printf("Could not resolve %s\n", path);
  7173. @@ -2282,6 +2303,8 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
  7174. SMBCSRV *srv = NULL;
  7175. uint16_t port1 = 0;
  7176. uint16_t port2 = 0;
  7177. + struct cli_credentials *ocreds = NULL;
  7178. + struct cli_credentials *ncreds = NULL;
  7179. TALLOC_CTX *frame = talloc_stackframe();
  7180. NTSTATUS status;
  7181. @@ -2375,7 +2398,10 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
  7182. password1);
  7183. /*d_printf(">>>rename: resolving %s\n", path1);*/
  7184. - status = cli_resolve_path(frame, "", ocontext->internal->auth_info,
  7185. + ocreds = get_cmdline_auth_info_creds(ocontext->internal->auth_info);
  7186. +
  7187. + status = cli_resolve_path(frame, "",
  7188. + ocreds,
  7189. srv->cli, path1, &targetcli1, &targetpath1);
  7190. if (!NT_STATUS_IS_OK(status)) {
  7191. d_printf("Could not resolve %s\n", path1);
  7192. @@ -2392,7 +2418,10 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
  7193. /*d_printf(">>>rename: resolved path as %s\n", targetpath1);*/
  7194. /*d_printf(">>>rename: resolving %s\n", path2);*/
  7195. - status = cli_resolve_path(frame, "", ncontext->internal->auth_info,
  7196. + ncreds = get_cmdline_auth_info_creds(ncontext->internal->auth_info);
  7197. +
  7198. + status = cli_resolve_path(frame, "",
  7199. + ncreds,
  7200. srv->cli, path2, &targetcli2, &targetpath2);
  7201. if (!NT_STATUS_IS_OK(status)) {
  7202. d_printf("Could not resolve %s\n", path2);
  7203. diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
  7204. index 0791df36690..a44925e0e0e 100644
  7205. --- a/source3/libsmb/libsmb_file.c
  7206. +++ b/source3/libsmb/libsmb_file.c
  7207. @@ -103,6 +103,8 @@ SMBC_open_ctx(SMBCCTX *context,
  7208. if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') {
  7209. status = NT_STATUS_OBJECT_PATH_INVALID;
  7210. } else {
  7211. + struct cli_credentials *creds = NULL;
  7212. +
  7213. file = SMB_MALLOC_P(SMBCFILE);
  7214. if (!file) {
  7215. errno = ENOMEM;
  7216. @@ -112,9 +114,12 @@ SMBC_open_ctx(SMBCCTX *context,
  7217. ZERO_STRUCTP(file);
  7218. + creds = get_cmdline_auth_info_creds(
  7219. + context->internal->auth_info);
  7220. /*d_printf(">>>open: resolving %s\n", path);*/
  7221. status = cli_resolve_path(
  7222. - frame, "", context->internal->auth_info,
  7223. + frame, "",
  7224. + creds,
  7225. srv->cli, path, &targetcli, &targetpath);
  7226. if (!NT_STATUS_IS_OK(status)) {
  7227. d_printf("Could not resolve %s\n", path);
  7228. @@ -461,6 +466,7 @@ SMBC_getatr(SMBCCTX * context,
  7229. struct timespec change_time_ts = {0};
  7230. time_t write_time = 0;
  7231. SMB_INO_T ino = 0;
  7232. + struct cli_credentials *creds = NULL;
  7233. TALLOC_CTX *frame = talloc_stackframe();
  7234. NTSTATUS status;
  7235. @@ -490,7 +496,10 @@ SMBC_getatr(SMBCCTX * context,
  7236. }
  7237. DEBUG(4,("SMBC_getatr: sending qpathinfo\n"));
  7238. - status = cli_resolve_path(frame, "", context->internal->auth_info,
  7239. + creds = get_cmdline_auth_info_creds(context->internal->auth_info);
  7240. +
  7241. + status = cli_resolve_path(frame, "",
  7242. + creds,
  7243. srv->cli, fixedpath,
  7244. &targetcli, &targetpath);
  7245. if (!NT_STATUS_IS_OK(status)) {
  7246. diff --git a/source3/libsmb/libsmb_stat.c b/source3/libsmb/libsmb_stat.c
  7247. index 790934bd565..1260928d0ff 100644
  7248. --- a/source3/libsmb/libsmb_stat.c
  7249. +++ b/source3/libsmb/libsmb_stat.c
  7250. @@ -242,6 +242,7 @@ SMBC_fstat_ctx(SMBCCTX *context,
  7251. struct cli_state *targetcli = NULL;
  7252. SMB_INO_T ino = 0;
  7253. uint16_t port = 0;
  7254. + struct cli_credentials *creds = NULL;
  7255. TALLOC_CTX *frame = talloc_stackframe();
  7256. NTSTATUS status;
  7257. @@ -279,8 +280,11 @@ SMBC_fstat_ctx(SMBCCTX *context,
  7258. return -1;
  7259. }
  7260. + creds = get_cmdline_auth_info_creds(context->internal->auth_info);
  7261. +
  7262. /*d_printf(">>>fstat: resolving %s\n", path);*/
  7263. - status = cli_resolve_path(frame, "", context->internal->auth_info,
  7264. + status = cli_resolve_path(frame, "",
  7265. + creds,
  7266. file->srv->cli, path,
  7267. &targetcli, &targetpath);
  7268. if (!NT_STATUS_IS_OK(status)) {
  7269. diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c
  7270. index d1b6548eb90..8b74d0a39e3 100644
  7271. --- a/source3/libsmb/libsmb_xattr.c
  7272. +++ b/source3/libsmb/libsmb_xattr.c
  7273. @@ -860,13 +860,18 @@ cacl_get(SMBCCTX *context,
  7274. if (ipc_cli && (all || some_nt || all_nt_acls)) {
  7275. char *targetpath = NULL;
  7276. struct cli_state *targetcli = NULL;
  7277. + struct cli_credentials *creds = NULL;
  7278. NTSTATUS status;
  7279. /* Point to the portion after "system.nt_sec_desc." */
  7280. name += 19; /* if (all) this will be invalid but unused */
  7281. + creds = get_cmdline_auth_info_creds(
  7282. + context->internal->auth_info);
  7283. +
  7284. status = cli_resolve_path(
  7285. - ctx, "", context->internal->auth_info,
  7286. + ctx, "",
  7287. + creds,
  7288. cli, filename, &targetcli, &targetpath);
  7289. if (!NT_STATUS_IS_OK(status)) {
  7290. DEBUG(5, ("cacl_get Could not resolve %s\n",
  7291. @@ -1511,6 +1516,7 @@ cacl_set(SMBCCTX *context,
  7292. bool numeric = True;
  7293. char *targetpath = NULL;
  7294. struct cli_state *targetcli = NULL;
  7295. + struct cli_credentials *creds = NULL;
  7296. NTSTATUS status;
  7297. /* the_acl will be null for REMOVE_ALL operations */
  7298. @@ -1540,7 +1546,10 @@ cacl_set(SMBCCTX *context,
  7299. return -1;
  7300. }
  7301. - status = cli_resolve_path(ctx, "", context->internal->auth_info,
  7302. + creds = get_cmdline_auth_info_creds(context->internal->auth_info);
  7303. +
  7304. + status = cli_resolve_path(ctx, "",
  7305. + creds,
  7306. cli, filename, &targetcli, &targetpath);
  7307. if (!NT_STATUS_IS_OK(status)) {
  7308. DEBUG(5,("cacl_set: Could not resolve %s\n", filename));
  7309. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  7310. index 0b8cf2a6036..517738dbcd7 100644
  7311. --- a/source3/libsmb/proto.h
  7312. +++ b/source3/libsmb/proto.h
  7313. @@ -150,7 +150,7 @@ NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
  7314. size_t *consumed);
  7315. NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  7316. const char *mountpt,
  7317. - const struct user_auth_info *dfs_auth_info,
  7318. + struct cli_credentials *creds,
  7319. struct cli_state *rootcli,
  7320. const char *path,
  7321. struct cli_state **targetcli,
  7322. diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
  7323. index 8fd9fcc5780..4989ec633c3 100644
  7324. --- a/source3/utils/smbcacls.c
  7325. +++ b/source3/utils/smbcacls.c
  7326. @@ -806,6 +806,7 @@ int main(int argc, char *argv[])
  7327. than going via LSA calls to resolve them */
  7328. int numeric = 0;
  7329. struct cli_state *targetcli = NULL;
  7330. + struct cli_credentials *creds = NULL;
  7331. char *targetfile = NULL;
  7332. NTSTATUS status;
  7333. @@ -1069,9 +1070,11 @@ int main(int argc, char *argv[])
  7334. }
  7335. }
  7336. + creds = get_cmdline_auth_info_creds(popt_get_cmdline_auth_info()),
  7337. +
  7338. status = cli_resolve_path(frame,
  7339. "",
  7340. - popt_get_cmdline_auth_info(),
  7341. + creds,
  7342. cli,
  7343. filename,
  7344. &targetcli,
  7345. --
  7346. 2.29.2
  7347. From e3ce5ba85266a08bd201c851e8fd59b71322d03e Mon Sep 17 00:00:00 2001
  7348. From: Andreas Schneider <asn@samba.org>
  7349. Date: Thu, 27 Aug 2020 16:40:49 +0200
  7350. Subject: [PATCH 070/104] s3:client: Remove global max_protocol
  7351. Signed-off-by: Andreas Schneider <asn@samba.org>
  7352. Reviewed-by: Jeremy Allison <jra@samba.org>
  7353. (cherry picked from commit d07f28645f37c1f976017d5b89864791a18d1943)
  7354. ---
  7355. source3/client/client.c | 13 +++++--------
  7356. 1 file changed, 5 insertions(+), 8 deletions(-)
  7357. diff --git a/source3/client/client.c b/source3/client/client.c
  7358. index 13e48f80a01..902cdec8b64 100644
  7359. --- a/source3/client/client.c
  7360. +++ b/source3/client/client.c
  7361. @@ -61,7 +61,6 @@ static int io_bufsize = 0; /* we use the default size */
  7362. static int io_timeout = (CLIENT_TIMEOUT/1000); /* Per operation timeout (in seconds). */
  7363. static int name_type = 0x20;
  7364. -static int max_protocol = -1;
  7365. static int process_tok(char *tok);
  7366. static int cmd_help(void);
  7367. @@ -5646,7 +5645,7 @@ static int process_command_string(const char *cmd_in)
  7368. desthost,
  7369. service,
  7370. creds,
  7371. - max_protocol,
  7372. + lp_client_max_protocol(),
  7373. have_ip ? &dest_ss : NULL, port,
  7374. name_type,
  7375. &cli);
  7376. @@ -6096,7 +6095,7 @@ static int process(const char *base_directory)
  7377. desthost,
  7378. service,
  7379. creds,
  7380. - max_protocol,
  7381. + lp_client_max_protocol(),
  7382. have_ip ? &dest_ss : NULL, port,
  7383. name_type, &cli);
  7384. if (!NT_STATUS_IS_OK(status)) {
  7385. @@ -6137,7 +6136,7 @@ static int do_host_query(const char *query_host)
  7386. query_host,
  7387. "IPC$",
  7388. creds,
  7389. - max_protocol,
  7390. + lp_client_max_protocol(),
  7391. have_ip ? &dest_ss : NULL, port,
  7392. name_type, &cli);
  7393. if (!NT_STATUS_IS_OK(status)) {
  7394. @@ -6172,7 +6171,7 @@ static int do_host_query(const char *query_host)
  7395. if (port != NBT_SMB_PORT ||
  7396. smbXcli_conn_protocol(cli->conn) > PROTOCOL_NT1)
  7397. {
  7398. - int max_proto = MIN(max_protocol, PROTOCOL_NT1);
  7399. + int max_proto = MIN(lp_client_max_protocol(), PROTOCOL_NT1);
  7400. /*
  7401. * Workgroups simply don't make sense over anything
  7402. @@ -6222,7 +6221,7 @@ static int do_tar_op(const char *base_directory)
  7403. desthost,
  7404. service,
  7405. creds,
  7406. - max_protocol,
  7407. + lp_client_max_protocol(),
  7408. have_ip ? &dest_ss : NULL, port,
  7409. name_type, &cli);
  7410. if (!NT_STATUS_IS_OK(status)) {
  7411. @@ -6629,8 +6628,6 @@ int main(int argc,char *argv[])
  7412. /* Ensure we have a password (or equivalent). */
  7413. popt_common_credentials_post();
  7414. - max_protocol = lp_client_max_protocol();
  7415. -
  7416. if (tar_to_process(tar_ctx)) {
  7417. if (cmdstr)
  7418. process_command_string(cmdstr);
  7419. --
  7420. 2.29.2
  7421. From 156a763a247480a88ab79f8822a2f34670a0c63b Mon Sep 17 00:00:00 2001
  7422. From: Andreas Schneider <asn@samba.org>
  7423. Date: Thu, 27 Aug 2020 16:43:46 +0200
  7424. Subject: [PATCH 071/104] s3:libsmb: Remove max_protocol from cli_cm_open()
  7425. Signed-off-by: Andreas Schneider <asn@samba.org>
  7426. Reviewed-by: Jeremy Allison <jra@samba.org>
  7427. (cherry picked from commit 4aac9daf095e7c2de6a27697a13385ee87a4b634)
  7428. ---
  7429. source3/client/client.c | 7 -------
  7430. source3/lib/netapi/cm.c | 1 -
  7431. source3/libsmb/clidfs.c | 4 +---
  7432. source3/libsmb/proto.h | 1 -
  7433. 4 files changed, 1 insertion(+), 12 deletions(-)
  7434. diff --git a/source3/client/client.c b/source3/client/client.c
  7435. index 902cdec8b64..82764c5ca16 100644
  7436. --- a/source3/client/client.c
  7437. +++ b/source3/client/client.c
  7438. @@ -5645,7 +5645,6 @@ static int process_command_string(const char *cmd_in)
  7439. desthost,
  7440. service,
  7441. creds,
  7442. - lp_client_max_protocol(),
  7443. have_ip ? &dest_ss : NULL, port,
  7444. name_type,
  7445. &cli);
  7446. @@ -6095,7 +6094,6 @@ static int process(const char *base_directory)
  7447. desthost,
  7448. service,
  7449. creds,
  7450. - lp_client_max_protocol(),
  7451. have_ip ? &dest_ss : NULL, port,
  7452. name_type, &cli);
  7453. if (!NT_STATUS_IS_OK(status)) {
  7454. @@ -6136,7 +6134,6 @@ static int do_host_query(const char *query_host)
  7455. query_host,
  7456. "IPC$",
  7457. creds,
  7458. - lp_client_max_protocol(),
  7459. have_ip ? &dest_ss : NULL, port,
  7460. name_type, &cli);
  7461. if (!NT_STATUS_IS_OK(status)) {
  7462. @@ -6171,8 +6168,6 @@ static int do_host_query(const char *query_host)
  7463. if (port != NBT_SMB_PORT ||
  7464. smbXcli_conn_protocol(cli->conn) > PROTOCOL_NT1)
  7465. {
  7466. - int max_proto = MIN(lp_client_max_protocol(), PROTOCOL_NT1);
  7467. -
  7468. /*
  7469. * Workgroups simply don't make sense over anything
  7470. * else but port 139 and SMB1.
  7471. @@ -6184,7 +6179,6 @@ static int do_host_query(const char *query_host)
  7472. query_host,
  7473. "IPC$",
  7474. creds,
  7475. - max_proto,
  7476. have_ip ? &dest_ss : NULL, NBT_SMB_PORT,
  7477. name_type, &cli);
  7478. if (!NT_STATUS_IS_OK(status)) {
  7479. @@ -6221,7 +6215,6 @@ static int do_tar_op(const char *base_directory)
  7480. desthost,
  7481. service,
  7482. creds,
  7483. - lp_client_max_protocol(),
  7484. have_ip ? &dest_ss : NULL, port,
  7485. name_type, &cli);
  7486. if (!NT_STATUS_IS_OK(status)) {
  7487. diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c
  7488. index 943f7498e8c..3f4e188b396 100644
  7489. --- a/source3/lib/netapi/cm.c
  7490. +++ b/source3/lib/netapi/cm.c
  7491. @@ -112,7 +112,6 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
  7492. status = cli_cm_open(ctx, NULL,
  7493. server_name, "IPC$",
  7494. creds,
  7495. - lp_client_ipc_max_protocol(),
  7496. NULL, 0, 0x20, &cli_ipc);
  7497. if (!NT_STATUS_IS_OK(status)) {
  7498. cli_ipc = NULL;
  7499. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  7500. index e6695159a96..fb1a0c72e6d 100644
  7501. --- a/source3/libsmb/clidfs.c
  7502. +++ b/source3/libsmb/clidfs.c
  7503. @@ -388,7 +388,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  7504. const char *server,
  7505. const char *share,
  7506. struct cli_credentials *creds,
  7507. - int max_protocol,
  7508. const struct sockaddr_storage *dest_ss,
  7509. int port,
  7510. int name_type,
  7511. @@ -417,7 +416,7 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  7512. server,
  7513. share,
  7514. creds,
  7515. - max_protocol,
  7516. + lp_client_max_protocol(),
  7517. dest_ss,
  7518. port,
  7519. name_type,
  7520. @@ -965,7 +964,6 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  7521. smbXcli_conn_remote_name(rootcli->conn),
  7522. "IPC$",
  7523. creds,
  7524. - smbXcli_conn_protocol(rootcli->conn),
  7525. NULL, /* dest_ss not needed, we reuse the transport */
  7526. 0,
  7527. 0x20,
  7528. diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
  7529. index 517738dbcd7..8aaaff2cb1e 100644
  7530. --- a/source3/libsmb/proto.h
  7531. +++ b/source3/libsmb/proto.h
  7532. @@ -128,7 +128,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  7533. const char *server,
  7534. const char *share,
  7535. struct cli_credentials *creds,
  7536. - int max_protocol,
  7537. const struct sockaddr_storage *dest_ss,
  7538. int port,
  7539. int name_type,
  7540. --
  7541. 2.29.2
  7542. From 2ad30b082df42e010ca88e7a84471629476e00b9 Mon Sep 17 00:00:00 2001
  7543. From: Andreas Schneider <asn@samba.org>
  7544. Date: Thu, 27 Aug 2020 16:45:12 +0200
  7545. Subject: [PATCH 072/104] s3:libcmb: Remove max_protocol from cli_cm_connect()
  7546. Signed-off-by: Andreas Schneider <asn@samba.org>
  7547. Reviewed-by: Jeremy Allison <jra@samba.org>
  7548. (cherry picked from commit 2159582610ecc932047b85a77ec321b3d3ac806f)
  7549. ---
  7550. source3/libsmb/clidfs.c | 5 +----
  7551. 1 file changed, 1 insertion(+), 4 deletions(-)
  7552. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  7553. index fb1a0c72e6d..023dd4d2757 100644
  7554. --- a/source3/libsmb/clidfs.c
  7555. +++ b/source3/libsmb/clidfs.c
  7556. @@ -293,7 +293,6 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  7557. const char *server,
  7558. const char *share,
  7559. struct cli_credentials *creds,
  7560. - int max_protocol,
  7561. const struct sockaddr_storage *dest_ss,
  7562. int port,
  7563. int name_type,
  7564. @@ -304,7 +303,7 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  7565. status = do_connect(ctx, server, share,
  7566. creds,
  7567. - max_protocol,
  7568. + lp_client_max_protocol(),
  7569. dest_ss, port, name_type, &cli);
  7570. if (!NT_STATUS_IS_OK(status)) {
  7571. @@ -416,7 +415,6 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
  7572. server,
  7573. share,
  7574. creds,
  7575. - lp_client_max_protocol(),
  7576. dest_ss,
  7577. port,
  7578. name_type,
  7579. @@ -1020,7 +1018,6 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
  7580. dfs_refs[count].server,
  7581. dfs_refs[count].share,
  7582. creds,
  7583. - smbXcli_conn_protocol(rootcli->conn),
  7584. NULL, /* dest_ss */
  7585. 0, /* port */
  7586. 0x20,
  7587. --
  7588. 2.29.2
  7589. From 4cc3243a8cf7c18129ad41ea52abc325aef55f06 Mon Sep 17 00:00:00 2001
  7590. From: Andreas Schneider <asn@samba.org>
  7591. Date: Thu, 27 Aug 2020 16:46:29 +0200
  7592. Subject: [PATCH 073/104] s3:libsmb: Remove max_protocol from clidfs
  7593. do_connect()
  7594. The if check for max_protocol == 0 is part of lp_client_max_protocol().
  7595. Signed-off-by: Andreas Schneider <asn@samba.org>
  7596. Reviewed-by: Jeremy Allison <jra@samba.org>
  7597. (cherry picked from commit 50b59b4c28bc816094a4ca97f64450860e2495b2)
  7598. ---
  7599. source3/libsmb/clidfs.c | 8 +-------
  7600. 1 file changed, 1 insertion(+), 7 deletions(-)
  7601. diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
  7602. index 023dd4d2757..ee5becf76a6 100644
  7603. --- a/source3/libsmb/clidfs.c
  7604. +++ b/source3/libsmb/clidfs.c
  7605. @@ -107,7 +107,6 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  7606. const char *server,
  7607. const char *share,
  7608. struct cli_credentials *creds,
  7609. - int max_protocol,
  7610. const struct sockaddr_storage *dest_ss,
  7611. int port,
  7612. int name_type,
  7613. @@ -167,14 +166,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  7614. return status;
  7615. }
  7616. - if (max_protocol == 0) {
  7617. - max_protocol = PROTOCOL_LATEST;
  7618. - }
  7619. DEBUG(4,(" session request ok\n"));
  7620. status = smbXcli_negprot(c->conn, c->timeout,
  7621. lp_client_min_protocol(),
  7622. - max_protocol);
  7623. + lp_client_max_protocol());
  7624. if (!NT_STATUS_IS_OK(status)) {
  7625. d_printf("protocol negotiation failed: %s\n",
  7626. @@ -233,7 +229,6 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
  7627. cli_shutdown(c);
  7628. return do_connect(ctx, newserver,
  7629. newshare, creds,
  7630. - max_protocol,
  7631. NULL, port, name_type, pcli);
  7632. }
  7633. @@ -303,7 +298,6 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
  7634. status = do_connect(ctx, server, share,
  7635. creds,
  7636. - lp_client_max_protocol(),
  7637. dest_ss, port, name_type, &cli);
  7638. if (!NT_STATUS_IS_OK(status)) {
  7639. --
  7640. 2.29.2
  7641. From bfd80fa8f7a476b2fb37bd435697700ad032cc70 Mon Sep 17 00:00:00 2001
  7642. From: Andreas Schneider <asn@samba.org>
  7643. Date: Mon, 10 Aug 2020 15:47:35 +0200
  7644. Subject: [PATCH 074/104] s3:include: Move loadparm prototypes to own header
  7645. file
  7646. Signed-off-by: Andreas Schneider <asn@samba.org>
  7647. Reviewed-by: Jeremy Allison <jra@samba.org>
  7648. (cherry picked from commit d4d8218b9618dd289f54b41f13d7015f1b3994fd)
  7649. ---
  7650. source3/include/includes.h | 3 +
  7651. source3/include/proto.h | 167 -------------------------------
  7652. source3/param/loadparm.h | 200 +++++++++++++++++++++++++++++++++++++
  7653. 3 files changed, 203 insertions(+), 167 deletions(-)
  7654. create mode 100644 source3/param/loadparm.h
  7655. diff --git a/source3/include/includes.h b/source3/include/includes.h
  7656. index 8fa65cc3122..c94f919ed59 100644
  7657. --- a/source3/include/includes.h
  7658. +++ b/source3/include/includes.h
  7659. @@ -293,6 +293,9 @@ typedef char fstring[FSTRING_LEN];
  7660. #endif
  7661. #include "lib/param/loadparm.h"
  7662. +#include "source3/param/loadparm.h"
  7663. +/* Automatically generated by generate_param.py. */
  7664. +#include "source3/param/param_proto.h"
  7665. /* String routines */
  7666. diff --git a/source3/include/proto.h b/source3/include/proto.h
  7667. index 12aa392abae..b9a6cb7f116 100644
  7668. --- a/source3/include/proto.h
  7669. +++ b/source3/include/proto.h
  7670. @@ -739,173 +739,6 @@ NTSTATUS trust_pw_change(struct netlogon_creds_cli_context *context,
  7671. const char *dcname,
  7672. bool force);
  7673. -/* The following definitions come from param/loadparm.c */
  7674. -
  7675. -const struct loadparm_substitution *loadparm_s3_global_substitution(void);
  7676. -
  7677. -char *lp_parm_substituted_string(TALLOC_CTX *mem_ctx,
  7678. - const struct loadparm_substitution *lp_sub,
  7679. - int snum,
  7680. - const char *type,
  7681. - const char *option,
  7682. - const char *def);
  7683. -
  7684. -#include "source3/param/param_proto.h"
  7685. -
  7686. -char *lp_servicename(TALLOC_CTX *ctx, const struct loadparm_substitution *, int);
  7687. -const char *lp_const_servicename(int);
  7688. -bool lp_autoloaded(int);
  7689. -const char *lp_dnsdomain(void);
  7690. -int lp_winbind_max_domain_connections(void);
  7691. -bool lp_idmap_range(const char *domain_name, uint32_t *low, uint32_t *high);
  7692. -bool lp_idmap_default_range(uint32_t *low, uint32_t *high);
  7693. -const char *lp_idmap_backend(const char *domain_name);
  7694. -const char *lp_idmap_default_backend (void);
  7695. -int lp_security(void);
  7696. -int lp_client_max_protocol(void);
  7697. -int lp_client_ipc_min_protocol(void);
  7698. -int lp_client_ipc_max_protocol(void);
  7699. -int lp_client_ipc_signing(void);
  7700. -int lp_smb2_max_credits(void);
  7701. -int lp_cups_encrypt(void);
  7702. -bool lp_widelinks(int );
  7703. -int lp_rpc_low_port(void);
  7704. -int lp_rpc_high_port(void);
  7705. -bool lp_lanman_auth(void);
  7706. -enum samba_weak_crypto lp_weak_crypto(void);
  7707. -
  7708. -int lp_wi_scan_global_parametrics(
  7709. - const char *regex, size_t max_matches,
  7710. - bool (*cb)(const char *string, regmatch_t matches[],
  7711. - void *private_data),
  7712. - void *private_data);
  7713. -
  7714. -const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def);
  7715. -struct loadparm_service;
  7716. -const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type,
  7717. - const char *option, const char *def);
  7718. -const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def);
  7719. -int lp_parm_int(int snum, const char *type, const char *option, int def);
  7720. -unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def);
  7721. -unsigned long long lp_parm_ulonglong(int snum, const char *type,
  7722. - const char *option,
  7723. - unsigned long long def);
  7724. -bool lp_parm_bool(int snum, const char *type, const char *option, bool def);
  7725. -struct enum_list;
  7726. -int lp_parm_enum(int snum, const char *type, const char *option,
  7727. - const struct enum_list *_enum, int def);
  7728. -char *canonicalize_servicename(TALLOC_CTX *ctx, const char *src);
  7729. -bool lp_add_home(const char *pszHomename, int iDefaultService,
  7730. - const char *user, const char *pszHomedir);
  7731. -int lp_add_service(const char *pszService, int iDefaultService);
  7732. -bool lp_add_printer(const char *pszPrintername, int iDefaultService);
  7733. -bool lp_parameter_is_valid(const char *pszParmName);
  7734. -bool lp_parameter_is_global(const char *pszParmName);
  7735. -bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
  7736. - bool *inverse);
  7737. -bool lp_canonicalize_parameter_with_value(const char *parm_name,
  7738. - const char *val,
  7739. - const char **canon_parm,
  7740. - const char **canon_val);
  7741. -void show_parameter_list(void);
  7742. -bool lp_invert_boolean(const char *str, const char **inverse_str);
  7743. -bool lp_canonicalize_boolean(const char *str, const char**canon_str);
  7744. -bool process_registry_service(const char *service_name);
  7745. -bool process_registry_shares(void);
  7746. -bool lp_config_backend_is_registry(void);
  7747. -bool lp_config_backend_is_file(void);
  7748. -bool lp_file_list_changed(void);
  7749. -const char *lp_ldap_machine_suffix(TALLOC_CTX *ctx);
  7750. -const char *lp_ldap_user_suffix(TALLOC_CTX *ctx);
  7751. -const char *lp_ldap_group_suffix(TALLOC_CTX *ctx);
  7752. -const char *lp_ldap_idmap_suffix(TALLOC_CTX *ctx);
  7753. -struct parm_struct;
  7754. -/* Return a pointer to a service by name. */
  7755. -struct loadparm_service *lp_service(const char *pszServiceName);
  7756. -struct loadparm_service *lp_servicebynum(int snum);
  7757. -struct loadparm_service *lp_default_loadparm_service(void);
  7758. -void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm);
  7759. -void *lp_local_ptr_by_snum(int snum, struct parm_struct *parm);
  7760. -bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue);
  7761. -bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue);
  7762. -bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal);
  7763. -bool lp_snum_ok(int iService);
  7764. -void lp_add_one_printer(const char *name, const char *comment,
  7765. - const char *location, void *pdata);
  7766. -bool lp_loaded(void);
  7767. -void lp_killunused(struct smbd_server_connection *sconn,
  7768. - bool (*snumused) (struct smbd_server_connection *, int));
  7769. -void lp_kill_all_services(void);
  7770. -void lp_killservice(int iServiceIn);
  7771. -const char* server_role_str(uint32_t role);
  7772. -enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
  7773. - SMB_STRUCT_STAT *psbuf,
  7774. - const char *servicename,
  7775. - int snum,
  7776. - char **lines,
  7777. - int numlines,
  7778. - char **pp_sharepath,
  7779. - char **pp_comment,
  7780. - char **pp_cp_share_name,
  7781. - struct security_descriptor **ppsd,
  7782. - bool *pallow_guest);
  7783. -int load_usershare_service(const char *servicename);
  7784. -int load_usershare_shares(struct smbd_server_connection *sconn,
  7785. - bool (*snumused) (struct smbd_server_connection *, int));
  7786. -void gfree_loadparm(void);
  7787. -bool lp_load_initial_only(const char *pszFname);
  7788. -bool lp_load_global(const char *file_name);
  7789. -bool lp_load_with_shares(const char *file_name);
  7790. -bool lp_load_client(const char *file_name);
  7791. -bool lp_load_global_no_reinit(const char *file_name);
  7792. -bool lp_load_no_reinit(const char *file_name);
  7793. -bool lp_load_client_no_reinit(const char *file_name);
  7794. -bool lp_load_with_registry_shares(const char *pszFname);
  7795. -int lp_numservices(void);
  7796. -void lp_dump(FILE *f, bool show_defaults, int maxtoprint);
  7797. -void lp_dump_one(FILE * f, bool show_defaults, int snum);
  7798. -int lp_servicenumber(const char *pszServiceName);
  7799. -const char *volume_label(TALLOC_CTX *ctx, int snum);
  7800. -bool lp_domain_master(void);
  7801. -bool lp_preferred_master(void);
  7802. -void lp_remove_service(int snum);
  7803. -void lp_copy_service(int snum, const char *new_name);
  7804. -int lp_default_server_announce(void);
  7805. -const char *lp_printername(TALLOC_CTX *ctx,
  7806. - const struct loadparm_substitution *lp_sub,
  7807. - int snum);
  7808. -void lp_set_logfile(const char *name);
  7809. -int lp_maxprintjobs(int snum);
  7810. -const char *lp_printcapname(void);
  7811. -bool lp_disable_spoolss( void );
  7812. -void lp_set_spoolss_state( uint32_t state );
  7813. -uint32_t lp_get_spoolss_state( void );
  7814. -struct smb_signing_state;
  7815. -void set_use_sendfile(int snum, bool val);
  7816. -void lp_set_mangling_method(const char *new_method);
  7817. -bool lp_posix_pathnames(void);
  7818. -void lp_set_posix_pathnames(void);
  7819. -enum brl_flavour lp_posix_cifsu_locktype(files_struct *fsp);
  7820. -void lp_set_posix_default_cifsx_readwrite_locktype(enum brl_flavour val);
  7821. -int lp_min_receive_file_size(void);
  7822. -void widelinks_warning(int snum);
  7823. -const char *lp_ncalrpc_dir(void);
  7824. -void _lp_set_server_role(int server_role);
  7825. -
  7826. -/* The following definitions come from param/loadparm_ctx.c */
  7827. -
  7828. -const struct loadparm_s3_helpers *loadparm_s3_helpers(void);
  7829. -
  7830. -/* The following definitions come from param/loadparm_server_role.c */
  7831. -
  7832. -int lp_server_role(void);
  7833. -void set_server_role(void);
  7834. -
  7835. -/* The following definitions come from param/util.c */
  7836. -
  7837. -uint32_t get_int_param( const char* param );
  7838. -char* get_string_param( const char* param );
  7839. -
  7840. /* The following definitions come from lib/server_contexts.c */
  7841. struct tevent_context *global_event_context(void);
  7842. void global_event_context_free(void);
  7843. diff --git a/source3/param/loadparm.h b/source3/param/loadparm.h
  7844. new file mode 100644
  7845. index 00000000000..7686877ccf1
  7846. --- /dev/null
  7847. +++ b/source3/param/loadparm.h
  7848. @@ -0,0 +1,200 @@
  7849. +/*
  7850. + *
  7851. + * Unix SMB/CIFS implementation.
  7852. + *
  7853. + * Type definitions for loadparm
  7854. + *
  7855. + * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
  7856. + * This program is free software: you can redistribute it and/or modify
  7857. + * it under the terms of the GNU General Public License as published by
  7858. + * the Free Software Foundation, either version 3 of the License, or
  7859. + * (at your option) any later version.
  7860. + *
  7861. + * This program is distributed in the hope that it will be useful,
  7862. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7863. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7864. + * GNU General Public License for more details.
  7865. + *
  7866. + * You should have received a copy of the GNU General Public License
  7867. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  7868. + */
  7869. +
  7870. +#ifndef _S3_LOADPARM_H
  7871. +#define _S3_LOADPARM_H
  7872. +
  7873. +#include <talloc.h>
  7874. +#include <regex.h>
  7875. +
  7876. +/* Forward declarations */
  7877. +typedef struct stat_ex SMB_STRUCT_STAT;
  7878. +typedef struct files_struct files_struct;
  7879. +struct smbd_server_connection;
  7880. +struct security_descriptor;
  7881. +
  7882. +/* The following definitions come from param/loadparm.c */
  7883. +
  7884. +const struct loadparm_substitution *loadparm_s3_global_substitution(void);
  7885. +
  7886. +char *lp_parm_substituted_string(TALLOC_CTX *mem_ctx,
  7887. + const struct loadparm_substitution *lp_sub,
  7888. + int snum,
  7889. + const char *type,
  7890. + const char *option,
  7891. + const char *def);
  7892. +
  7893. +char *lp_servicename(TALLOC_CTX *ctx, const struct loadparm_substitution *, int);
  7894. +const char *lp_const_servicename(int);
  7895. +bool lp_autoloaded(int);
  7896. +const char *lp_dnsdomain(void);
  7897. +int lp_winbind_max_domain_connections(void);
  7898. +bool lp_idmap_range(const char *domain_name, uint32_t *low, uint32_t *high);
  7899. +bool lp_idmap_default_range(uint32_t *low, uint32_t *high);
  7900. +const char *lp_idmap_backend(const char *domain_name);
  7901. +const char *lp_idmap_default_backend (void);
  7902. +int lp_security(void);
  7903. +int lp_client_max_protocol(void);
  7904. +int lp_client_ipc_min_protocol(void);
  7905. +int lp_client_ipc_max_protocol(void);
  7906. +int lp_client_ipc_signing(void);
  7907. +int lp_smb2_max_credits(void);
  7908. +int lp_cups_encrypt(void);
  7909. +bool lp_widelinks(int );
  7910. +int lp_rpc_low_port(void);
  7911. +int lp_rpc_high_port(void);
  7912. +bool lp_lanman_auth(void);
  7913. +enum samba_weak_crypto lp_weak_crypto(void);
  7914. +
  7915. +int lp_wi_scan_global_parametrics(
  7916. + const char *regex, size_t max_matches,
  7917. + bool (*cb)(const char *string, regmatch_t matches[],
  7918. + void *private_data),
  7919. + void *private_data);
  7920. +
  7921. +const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def);
  7922. +struct loadparm_service;
  7923. +const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type,
  7924. + const char *option, const char *def);
  7925. +const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def);
  7926. +int lp_parm_int(int snum, const char *type, const char *option, int def);
  7927. +unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def);
  7928. +unsigned long long lp_parm_ulonglong(int snum, const char *type,
  7929. + const char *option,
  7930. + unsigned long long def);
  7931. +bool lp_parm_bool(int snum, const char *type, const char *option, bool def);
  7932. +struct enum_list;
  7933. +int lp_parm_enum(int snum, const char *type, const char *option,
  7934. + const struct enum_list *_enum, int def);
  7935. +char *canonicalize_servicename(TALLOC_CTX *ctx, const char *src);
  7936. +bool lp_add_home(const char *pszHomename, int iDefaultService,
  7937. + const char *user, const char *pszHomedir);
  7938. +int lp_add_service(const char *pszService, int iDefaultService);
  7939. +bool lp_add_printer(const char *pszPrintername, int iDefaultService);
  7940. +bool lp_parameter_is_valid(const char *pszParmName);
  7941. +bool lp_parameter_is_global(const char *pszParmName);
  7942. +bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
  7943. + bool *inverse);
  7944. +bool lp_canonicalize_parameter_with_value(const char *parm_name,
  7945. + const char *val,
  7946. + const char **canon_parm,
  7947. + const char **canon_val);
  7948. +void show_parameter_list(void);
  7949. +bool lp_invert_boolean(const char *str, const char **inverse_str);
  7950. +bool lp_canonicalize_boolean(const char *str, const char**canon_str);
  7951. +bool process_registry_service(const char *service_name);
  7952. +bool process_registry_shares(void);
  7953. +bool lp_config_backend_is_registry(void);
  7954. +bool lp_config_backend_is_file(void);
  7955. +bool lp_file_list_changed(void);
  7956. +const char *lp_ldap_machine_suffix(TALLOC_CTX *ctx);
  7957. +const char *lp_ldap_user_suffix(TALLOC_CTX *ctx);
  7958. +const char *lp_ldap_group_suffix(TALLOC_CTX *ctx);
  7959. +const char *lp_ldap_idmap_suffix(TALLOC_CTX *ctx);
  7960. +struct parm_struct;
  7961. +/* Return a pointer to a service by name. */
  7962. +struct loadparm_service *lp_service(const char *pszServiceName);
  7963. +struct loadparm_service *lp_servicebynum(int snum);
  7964. +struct loadparm_service *lp_default_loadparm_service(void);
  7965. +void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm);
  7966. +void *lp_local_ptr_by_snum(int snum, struct parm_struct *parm);
  7967. +bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue);
  7968. +bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue);
  7969. +bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal);
  7970. +bool lp_snum_ok(int iService);
  7971. +void lp_add_one_printer(const char *name, const char *comment,
  7972. + const char *location, void *pdata);
  7973. +bool lp_loaded(void);
  7974. +void lp_killunused(struct smbd_server_connection *sconn,
  7975. + bool (*snumused) (struct smbd_server_connection *, int));
  7976. +void lp_kill_all_services(void);
  7977. +void lp_killservice(int iServiceIn);
  7978. +const char* server_role_str(uint32_t role);
  7979. +enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
  7980. + SMB_STRUCT_STAT *psbuf,
  7981. + const char *servicename,
  7982. + int snum,
  7983. + char **lines,
  7984. + int numlines,
  7985. + char **pp_sharepath,
  7986. + char **pp_comment,
  7987. + char **pp_cp_share_name,
  7988. + struct security_descriptor **ppsd,
  7989. + bool *pallow_guest);
  7990. +int load_usershare_service(const char *servicename);
  7991. +int load_usershare_shares(struct smbd_server_connection *sconn,
  7992. + bool (*snumused) (struct smbd_server_connection *, int));
  7993. +void gfree_loadparm(void);
  7994. +bool lp_load_initial_only(const char *pszFname);
  7995. +bool lp_load_global(const char *file_name);
  7996. +bool lp_load_with_shares(const char *file_name);
  7997. +bool lp_load_client(const char *file_name);
  7998. +bool lp_load_global_no_reinit(const char *file_name);
  7999. +bool lp_load_no_reinit(const char *file_name);
  8000. +bool lp_load_client_no_reinit(const char *file_name);
  8001. +bool lp_load_with_registry_shares(const char *pszFname);
  8002. +int lp_numservices(void);
  8003. +void lp_dump(FILE *f, bool show_defaults, int maxtoprint);
  8004. +void lp_dump_one(FILE * f, bool show_defaults, int snum);
  8005. +int lp_servicenumber(const char *pszServiceName);
  8006. +const char *volume_label(TALLOC_CTX *ctx, int snum);
  8007. +bool lp_domain_master(void);
  8008. +bool lp_preferred_master(void);
  8009. +void lp_remove_service(int snum);
  8010. +void lp_copy_service(int snum, const char *new_name);
  8011. +int lp_default_server_announce(void);
  8012. +const char *lp_printername(TALLOC_CTX *ctx,
  8013. + const struct loadparm_substitution *lp_sub,
  8014. + int snum);
  8015. +void lp_set_logfile(const char *name);
  8016. +int lp_maxprintjobs(int snum);
  8017. +const char *lp_printcapname(void);
  8018. +bool lp_disable_spoolss( void );
  8019. +void lp_set_spoolss_state( uint32_t state );
  8020. +uint32_t lp_get_spoolss_state( void );
  8021. +struct smb_signing_state;
  8022. +void set_use_sendfile(int snum, bool val);
  8023. +void lp_set_mangling_method(const char *new_method);
  8024. +bool lp_posix_pathnames(void);
  8025. +void lp_set_posix_pathnames(void);
  8026. +enum brl_flavour lp_posix_cifsu_locktype(files_struct *fsp);
  8027. +void lp_set_posix_default_cifsx_readwrite_locktype(enum brl_flavour val);
  8028. +int lp_min_receive_file_size(void);
  8029. +void widelinks_warning(int snum);
  8030. +const char *lp_ncalrpc_dir(void);
  8031. +void _lp_set_server_role(int server_role);
  8032. +uint32_t lp_get_async_dns_timeout(void);
  8033. +
  8034. +/* The following definitions come from param/loadparm_ctx.c */
  8035. +
  8036. +const struct loadparm_s3_helpers *loadparm_s3_helpers(void);
  8037. +
  8038. +/* The following definitions come from param/loadparm_server_role.c */
  8039. +
  8040. +int lp_server_role(void);
  8041. +void set_server_role(void);
  8042. +
  8043. +/* The following definitions come from param/util.c */
  8044. +
  8045. +uint32_t get_int_param( const char* param );
  8046. +char *get_string_param( const char* param );
  8047. +
  8048. +#endif /* _S3_LOADPARM_H */
  8049. --
  8050. 2.29.2
  8051. From ad73140f7e08472179ac7598cfea780a207f0570 Mon Sep 17 00:00:00 2001
  8052. From: Andreas Schneider <asn@samba.org>
  8053. Date: Tue, 11 Aug 2020 10:41:07 +0200
  8054. Subject: [PATCH 075/104] s3:lib: Move interface prototypes to own header file
  8055. Signed-off-by: Andreas Schneider <asn@samba.org>
  8056. Reviewed-by: Jeremy Allison <jra@samba.org>
  8057. Autobuild-User(master): Jeremy Allison <jra@samba.org>
  8058. Autobuild-Date(master): Fri Oct 9 20:36:13 UTC 2020 on sn-devel-184
  8059. (cherry picked from commit 925cc9aafbe17cb2cbd89f468fac70f96ae89475)
  8060. ---
  8061. source3/include/proto.h | 21 +------------------
  8062. source3/lib/interface.h | 46 +++++++++++++++++++++++++++++++++++++++++
  8063. 2 files changed, 47 insertions(+), 20 deletions(-)
  8064. create mode 100644 source3/lib/interface.h
  8065. diff --git a/source3/include/proto.h b/source3/include/proto.h
  8066. index b9a6cb7f116..1bbd8e9d526 100644
  8067. --- a/source3/include/proto.h
  8068. +++ b/source3/include/proto.h
  8069. @@ -84,26 +84,7 @@ NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx,
  8070. struct connection_struct *conn,
  8071. struct files_struct **_fsp);
  8072. -/* The following definitions come from lib/interface.c */
  8073. -
  8074. -bool ismyaddr(const struct sockaddr *ip);
  8075. -bool ismyip_v4(struct in_addr ip);
  8076. -bool is_local_net(const struct sockaddr *from);
  8077. -void setup_linklocal_scope_id(struct sockaddr *pss);
  8078. -bool is_local_net_v4(struct in_addr from);
  8079. -int iface_count(void);
  8080. -int iface_count_v4_nl(void);
  8081. -const struct in_addr *first_ipv4_iface(void);
  8082. -struct interface *get_interface(int n);
  8083. -const struct sockaddr_storage *iface_n_sockaddr_storage(int n);
  8084. -const struct in_addr *iface_n_ip_v4(int n);
  8085. -const struct in_addr *iface_n_bcast_v4(int n);
  8086. -const struct sockaddr_storage *iface_n_bcast(int n);
  8087. -const struct sockaddr_storage *iface_ip(const struct sockaddr *ip);
  8088. -bool iface_local(const struct sockaddr *ip);
  8089. -void load_interfaces(void);
  8090. -void gfree_interfaces(void);
  8091. -bool interfaces_changed(void);
  8092. +#include "source3/lib/interface.h"
  8093. /* The following definitions come from lib/ldap_debug_handler.c */
  8094. diff --git a/source3/lib/interface.h b/source3/lib/interface.h
  8095. new file mode 100644
  8096. index 00000000000..f45435b4a81
  8097. --- /dev/null
  8098. +++ b/source3/lib/interface.h
  8099. @@ -0,0 +1,46 @@
  8100. +/*
  8101. + *
  8102. + * Unix SMB/CIFS implementation.
  8103. + *
  8104. + * Type definitions for interfaces
  8105. + *
  8106. + * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
  8107. + * This program is free software: you can redistribute it and/or modify
  8108. + * it under the terms of the GNU General Public License as published by
  8109. + * the Free Software Foundation, either version 3 of the License, or
  8110. + * (at your option) any later version.
  8111. + *
  8112. + * This program is distributed in the hope that it will be useful,
  8113. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8114. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8115. + * GNU General Public License for more details.
  8116. + *
  8117. + * You should have received a copy of the GNU General Public License
  8118. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  8119. + */
  8120. +
  8121. +#ifndef _INTERFACE_H
  8122. +#define _INTERFACE_H
  8123. +
  8124. +#include <system/network.h>
  8125. +
  8126. +bool ismyaddr(const struct sockaddr *ip);
  8127. +bool ismyip_v4(struct in_addr ip);
  8128. +bool is_local_net(const struct sockaddr *from);
  8129. +void setup_linklocal_scope_id(struct sockaddr *pss);
  8130. +bool is_local_net_v4(struct in_addr from);
  8131. +int iface_count(void);
  8132. +int iface_count_v4_nl(void);
  8133. +const struct in_addr *first_ipv4_iface(void);
  8134. +struct interface *get_interface(int n);
  8135. +const struct sockaddr_storage *iface_n_sockaddr_storage(int n);
  8136. +const struct in_addr *iface_n_ip_v4(int n);
  8137. +const struct in_addr *iface_n_bcast_v4(int n);
  8138. +const struct sockaddr_storage *iface_n_bcast(int n);
  8139. +const struct sockaddr_storage *iface_ip(const struct sockaddr *ip);
  8140. +bool iface_local(const struct sockaddr *ip);
  8141. +void load_interfaces(void);
  8142. +void gfree_interfaces(void);
  8143. +bool interfaces_changed(void);
  8144. +
  8145. +#endif /* _INTERFACE_H */
  8146. --
  8147. 2.29.2
  8148. From bd958477d69c820766a30f818163cda9f9d171a3 Mon Sep 17 00:00:00 2001
  8149. From: Andreas Schneider <asn@samba.org>
  8150. Date: Fri, 7 Feb 2020 16:48:16 +0100
  8151. Subject: [PATCH 076/104] idl: Add SID_SAMBA_SMB3
  8152. Signed-off-by: Andreas Schneider <asn@samba.org>
  8153. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8154. (cherry picked from commit 56879ec5876625346df89110f62d52e3fd5b8934)
  8155. ---
  8156. librpc/idl/security.idl | 3 +++
  8157. 1 file changed, 3 insertions(+)
  8158. diff --git a/librpc/idl/security.idl b/librpc/idl/security.idl
  8159. index a92e8f1518e..06bf7449a70 100644
  8160. --- a/librpc/idl/security.idl
  8161. +++ b/librpc/idl/security.idl
  8162. @@ -282,6 +282,9 @@ interface security
  8163. const string SID_SAMBA_UNIX_USER_OWNER = "S-1-22-1";
  8164. const string SID_SAMBA_UNIX_GROUP_OWNER = "S-1-22-2";
  8165. + /* Information passing via security token */
  8166. + const string SID_SAMBA_SMB3 = "S-1-22-1397571891";
  8167. +
  8168. /* SECURITY_NT_SERVICE */
  8169. const string NAME_NT_SERVICE = "NT SERVICE";
  8170. --
  8171. 2.29.2
  8172. From 6b4e237ea0900e2ac7f46b889fd95d1d04db5bff Mon Sep 17 00:00:00 2001
  8173. From: Andreas Schneider <asn@samba.org>
  8174. Date: Fri, 7 Feb 2020 16:48:29 +0100
  8175. Subject: [PATCH 077/104] s3:smbd: Add SMB3 connection information to session
  8176. info
  8177. Signed-off-by: Andreas Schneider <asn@samba.org>
  8178. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8179. (cherry picked from commit 905c2b9722a64ee57f3fbcff51e6bb591c6e3edc)
  8180. ---
  8181. source3/include/vfs.h | 1 +
  8182. source3/smbd/pipes.c | 82 +++++++++++++++++++++++++++++++++++++-
  8183. source3/smbd/smb2_server.c | 5 +++
  8184. 3 files changed, 87 insertions(+), 1 deletion(-)
  8185. diff --git a/source3/include/vfs.h b/source3/include/vfs.h
  8186. index d527f850628..c0d60636c31 100644
  8187. --- a/source3/include/vfs.h
  8188. +++ b/source3/include/vfs.h
  8189. @@ -411,6 +411,7 @@ typedef struct files_struct {
  8190. bool use_ofd_locks : 1;
  8191. bool closing : 1;
  8192. bool lock_failure_seen : 1;
  8193. + bool encryption_required : 1;
  8194. } fsp_flags;
  8195. struct tevent_timer *update_write_time_event;
  8196. diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c
  8197. index 2dd38bb7ab3..d51a3de9497 100644
  8198. --- a/source3/smbd/pipes.c
  8199. +++ b/source3/smbd/pipes.c
  8200. @@ -30,13 +30,16 @@
  8201. #include "smbd/globals.h"
  8202. #include "libcli/security/security.h"
  8203. #include "rpc_server/srv_pipe_hnd.h"
  8204. +#include "auth/auth_util.h"
  8205. NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
  8206. struct files_struct **pfsp)
  8207. {
  8208. + struct smbXsrv_connection *xconn = smb_req->xconn;
  8209. struct connection_struct *conn = smb_req->conn;
  8210. struct files_struct *fsp;
  8211. struct smb_filename *smb_fname = NULL;
  8212. + struct auth_session_info *session_info = conn->session_info;
  8213. NTSTATUS status;
  8214. status = file_new(smb_req, conn, &fsp);
  8215. @@ -68,10 +71,87 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
  8216. return status;
  8217. }
  8218. + if (smb_req->smb2req != NULL && smb_req->smb2req->was_encrypted) {
  8219. + struct security_token *security_token = NULL;
  8220. + uint16_t dialect = xconn->smb2.server.dialect;
  8221. + uint16_t srv_smb_encrypt = 0x0002;
  8222. + uint16_t cipher = xconn->smb2.server.cipher;
  8223. + char smb3_sid_str[SID_MAX_SIZE];
  8224. + struct dom_sid smb3_dom_sid;
  8225. + struct dom_sid smb3_sid;
  8226. + uint32_t i;
  8227. + bool ok;
  8228. + int rc;
  8229. +
  8230. + session_info = copy_session_info(fsp, conn->session_info);
  8231. + if (session_info == NULL) {
  8232. + DBG_ERR("Failed to copy session info\n");
  8233. + file_free(smb_req, fsp);
  8234. + return NT_STATUS_NO_MEMORY;
  8235. + }
  8236. + security_token = session_info->security_token;
  8237. +
  8238. + ok = dom_sid_parse(SID_SAMBA_SMB3, &smb3_dom_sid);
  8239. + if (!ok) {
  8240. + file_free(smb_req, fsp);
  8241. + return NT_STATUS_BUFFER_TOO_SMALL;
  8242. + }
  8243. +
  8244. + /*
  8245. + * Security check:
  8246. + *
  8247. + * Make sure we don't have a SMB3 SID in the security token!
  8248. + */
  8249. + for (i = 0; i < security_token->num_sids; i++) {
  8250. + int cmp;
  8251. +
  8252. + cmp = dom_sid_compare_domain(&security_token->sids[i],
  8253. + &smb3_dom_sid);
  8254. + if (cmp == 0) {
  8255. + DBG_ERR("ERROR: An SMB3 SID has already been "
  8256. + "detected in the security token!\n");
  8257. + file_free(smb_req, fsp);
  8258. + return NT_STATUS_ACCESS_DENIED;
  8259. + }
  8260. + }
  8261. +
  8262. + rc = snprintf(smb3_sid_str,
  8263. + sizeof(smb3_sid_str),
  8264. + "%s-%u-%u-%u",
  8265. + SID_SAMBA_SMB3,
  8266. + dialect,
  8267. + srv_smb_encrypt,
  8268. + cipher);
  8269. + if (rc < 0) {
  8270. + DBG_ERR("Buffer too small\n");
  8271. + file_free(smb_req, fsp);
  8272. + return NT_STATUS_BUFFER_TOO_SMALL;
  8273. + }
  8274. +
  8275. + ok = dom_sid_parse(smb3_sid_str, &smb3_sid);
  8276. + if (!ok) {
  8277. + DBG_ERR("Failed to parse SMB3 SID\n");
  8278. + file_free(smb_req, fsp);
  8279. + return NT_STATUS_INVALID_PARAMETER;
  8280. + }
  8281. +
  8282. + status = add_sid_to_array_unique(security_token,
  8283. + &smb3_sid,
  8284. + &security_token->sids,
  8285. + &security_token->num_sids);
  8286. + if (!NT_STATUS_IS_OK(status)) {
  8287. + DBG_ERR("Failed to add SMB3 SID to security token\n");
  8288. + file_free(smb_req, fsp);
  8289. + return status;
  8290. + }
  8291. +
  8292. + fsp->fsp_flags.encryption_required = true;
  8293. + }
  8294. +
  8295. status = np_open(fsp, name,
  8296. conn->sconn->remote_address,
  8297. conn->sconn->local_address,
  8298. - conn->session_info,
  8299. + session_info,
  8300. conn->sconn->ev_ctx,
  8301. conn->sconn->msg_ctx,
  8302. conn->sconn->dce_ctx,
  8303. diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c
  8304. index cf9de185c1f..cd24b7d2ed5 100644
  8305. --- a/source3/smbd/smb2_server.c
  8306. +++ b/source3/smbd/smb2_server.c
  8307. @@ -3232,6 +3232,11 @@ NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req)
  8308. return smbd_smb2_request_error(req,
  8309. NT_STATUS_FILE_CLOSED);
  8310. }
  8311. + } else {
  8312. + if (fsp->fsp_flags.encryption_required && !req->was_encrypted) {
  8313. + return smbd_smb2_request_error(req,
  8314. + NT_STATUS_ACCESS_DENIED);
  8315. + }
  8316. }
  8317. }
  8318. --
  8319. 2.29.2
  8320. From 466c2d98005e1e0a3c3aa7b17779031b426b5da6 Mon Sep 17 00:00:00 2001
  8321. From: Andreas Schneider <asn@samba.org>
  8322. Date: Thu, 12 Mar 2020 14:11:56 +0100
  8323. Subject: [PATCH 078/104] librpc: Add dcerpc helper
  8324. dcerpc_is_transport_encrypted()
  8325. Signed-off-by: Andreas Schneider <asn@samba.org>
  8326. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8327. (cherry picked from commit 8bbe5c8c94aaf75d715f558c363e5b2de49f7bf9)
  8328. ---
  8329. librpc/rpc/dcerpc_helper.c | 137 +++++++++++++++++++++++++++++++++++++
  8330. librpc/rpc/dcerpc_helper.h | 26 +++++++
  8331. librpc/wscript_build | 9 +++
  8332. 3 files changed, 172 insertions(+)
  8333. create mode 100644 librpc/rpc/dcerpc_helper.c
  8334. create mode 100644 librpc/rpc/dcerpc_helper.h
  8335. diff --git a/librpc/rpc/dcerpc_helper.c b/librpc/rpc/dcerpc_helper.c
  8336. new file mode 100644
  8337. index 00000000000..c5443764628
  8338. --- /dev/null
  8339. +++ b/librpc/rpc/dcerpc_helper.c
  8340. @@ -0,0 +1,137 @@
  8341. +/*
  8342. + * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
  8343. + *
  8344. + * This program is free software: you can redistribute it and/or modify
  8345. + * it under the terms of the GNU General Public License as published by
  8346. + * the Free Software Foundation, either version 3 of the License, or
  8347. + * (at your option) any later version.
  8348. + *
  8349. + * This program is distributed in the hope that it will be useful,
  8350. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8351. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8352. + * GNU General Public License for more details.
  8353. + *
  8354. + * You should have received a copy of the GNU General Public License
  8355. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  8356. + */
  8357. +
  8358. +#include "includes.h"
  8359. +#include "librpc/gen_ndr/security.h"
  8360. +#include "librpc/gen_ndr/auth.h"
  8361. +#include "lib/crypto/gnutls_helpers.h"
  8362. +#include "libcli/security/dom_sid.h"
  8363. +#include "libcli/smb/smb2_constants.h"
  8364. +
  8365. +#include "dcerpc_helper.h"
  8366. +
  8367. +static bool smb3_sid_parse(const struct dom_sid *sid,
  8368. + uint16_t *pdialect,
  8369. + uint16_t *pencrypt,
  8370. + uint16_t *pcipher)
  8371. +{
  8372. + uint16_t dialect;
  8373. + uint16_t encrypt;
  8374. + uint16_t cipher;
  8375. +
  8376. + if (sid->sub_auths[0] != 1397571891) {
  8377. + return false;
  8378. + }
  8379. +
  8380. + dialect = sid->sub_auths[1];
  8381. + if (dialect > 0x03ff) {
  8382. + return false;
  8383. + }
  8384. +
  8385. + encrypt = sid->sub_auths[2];
  8386. + if (encrypt > 0x0002) {
  8387. + return false;
  8388. + }
  8389. +
  8390. + cipher = sid->sub_auths[3];
  8391. + if (cipher > SMB2_ENCRYPTION_AES128_GCM) {
  8392. + return false;
  8393. + }
  8394. +
  8395. + if (pdialect != NULL) {
  8396. + *pdialect = dialect;
  8397. + }
  8398. +
  8399. + if (pencrypt != NULL) {
  8400. + *pencrypt = encrypt;
  8401. + }
  8402. +
  8403. + if (pcipher != NULL) {
  8404. + *pcipher = cipher;
  8405. + }
  8406. +
  8407. + return true;
  8408. +}
  8409. +
  8410. +bool dcerpc_is_transport_encrypted(struct auth_session_info *session_info)
  8411. +{
  8412. + struct security_token *token = session_info->security_token;
  8413. + struct dom_sid smb3_dom_sid;
  8414. + const struct dom_sid *smb3_sid = NULL;
  8415. + uint16_t dialect = 0;
  8416. + uint16_t encrypt = 0;
  8417. + uint16_t cipher = 0;
  8418. + uint32_t i;
  8419. + bool ok;
  8420. +
  8421. + ok = dom_sid_parse(SID_SAMBA_SMB3, &smb3_dom_sid);
  8422. + if (!ok) {
  8423. + return false;
  8424. + }
  8425. +
  8426. + for (i = 0; i < token->num_sids; i++) {
  8427. + int cmp;
  8428. +
  8429. + /* There is only one SMB3 SID allowed! */
  8430. + cmp = dom_sid_compare_domain(&token->sids[i], &smb3_dom_sid);
  8431. + if (cmp == 0) {
  8432. + if (smb3_sid == NULL) {
  8433. + smb3_sid = &token->sids[i];
  8434. + } else {
  8435. + DBG_ERR("ERROR: The SMB3 SID has been detected "
  8436. + "multiple times\n");
  8437. + return false;
  8438. + }
  8439. + }
  8440. + }
  8441. +
  8442. + if (smb3_sid == NULL) {
  8443. + return false;
  8444. + }
  8445. +
  8446. + ok = smb3_sid_parse(smb3_sid, &dialect, &encrypt, &cipher);
  8447. + if (!ok) {
  8448. + DBG_ERR("Failed to parse SMB3 SID!\n");
  8449. + return false;
  8450. + }
  8451. +
  8452. + DBG_DEBUG("SMB SID - dialect: %#04x, encrypt: %#04x, cipher: %#04x\n",
  8453. + dialect,
  8454. + encrypt,
  8455. + cipher);
  8456. +
  8457. + if (dialect < SMB3_DIALECT_REVISION_300) {
  8458. + DBG_DEBUG("Invalid SMB3 dialect!\n");
  8459. + return false;
  8460. + }
  8461. +
  8462. + if (encrypt != DCERPC_SMB_ENCRYPTION_REQUIRED) {
  8463. + DBG_DEBUG("Invalid SMB3 encryption!\n");
  8464. + return false;
  8465. + }
  8466. +
  8467. + switch (cipher) {
  8468. + case SMB2_ENCRYPTION_AES128_CCM:
  8469. + case SMB2_ENCRYPTION_AES128_GCM:
  8470. + break;
  8471. + default:
  8472. + DBG_DEBUG("Invalid SMB3 cipher!\n");
  8473. + return false;
  8474. + }
  8475. +
  8476. + return true;
  8477. +}
  8478. diff --git a/librpc/rpc/dcerpc_helper.h b/librpc/rpc/dcerpc_helper.h
  8479. new file mode 100644
  8480. index 00000000000..c0f09ee494e
  8481. --- /dev/null
  8482. +++ b/librpc/rpc/dcerpc_helper.h
  8483. @@ -0,0 +1,26 @@
  8484. +/*
  8485. + * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
  8486. + *
  8487. + * This program is free software: you can redistribute it and/or modify
  8488. + * it under the terms of the GNU General Public License as published by
  8489. + * the Free Software Foundation, either version 3 of the License, or
  8490. + * (at your option) any later version.
  8491. + *
  8492. + * This program is distributed in the hope that it will be useful,
  8493. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8494. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8495. + * GNU General Public License for more details.
  8496. + *
  8497. + * You should have received a copy of the GNU General Public License
  8498. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  8499. + */
  8500. +
  8501. +#ifndef _DCERPC_HELPER_H
  8502. +#define _DCERPC_HELPER_H
  8503. +
  8504. +#define DCERPC_SMB_ENCRYPTION_OFF 0x0000
  8505. +#define DCERPC_SMB_ENCRYPTION_REQUIRED 0x0002
  8506. +
  8507. +bool dcerpc_is_transport_encrypted(struct auth_session_info *session_info);
  8508. +
  8509. +#endif /* _DCERPC_HELPER_H */
  8510. diff --git a/librpc/wscript_build b/librpc/wscript_build
  8511. index 27b180fa63d..109a1834841 100644
  8512. --- a/librpc/wscript_build
  8513. +++ b/librpc/wscript_build
  8514. @@ -669,6 +669,15 @@ bld.SAMBA_LIBRARY('dcerpc-server-core',
  8515. autoproto='rpc/dcesrv_core_proto.h',
  8516. vnum='0.0.1')
  8517. +bld.SAMBA_SUBSYSTEM('DCERPC_HELPER',
  8518. + source='rpc/dcerpc_helper.c',
  8519. + public_deps='''
  8520. + samba-hostconfig
  8521. + samba-security
  8522. + gnutls
  8523. + GNUTLS_HELPERS
  8524. + ''')
  8525. +
  8526. bld.SAMBA_SUBSYSTEM('NDR_WINBIND',
  8527. source='gen_ndr/ndr_winbind.c',
  8528. public_deps='ndr NDR_LSA'
  8529. --
  8530. 2.29.2
  8531. From cc8a5479152c6131362e9ca9cfe6e5bab2a71af3 Mon Sep 17 00:00:00 2001
  8532. From: Andreas Schneider <asn@samba.org>
  8533. Date: Fri, 28 Aug 2020 16:31:17 +0200
  8534. Subject: [PATCH 079/104] s3:smbd: Use defines to set 'srv_smb_encrypt'
  8535. Signed-off-by: Andreas Schneider <asn@samba.org>
  8536. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8537. (cherry picked from commit 5f1a73be6311c68a21a550c0de5078baeb78f4ee)
  8538. ---
  8539. source3/smbd/pipes.c | 3 ++-
  8540. 1 file changed, 2 insertions(+), 1 deletion(-)
  8541. diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c
  8542. index d51a3de9497..785cbb23b5f 100644
  8543. --- a/source3/smbd/pipes.c
  8544. +++ b/source3/smbd/pipes.c
  8545. @@ -31,6 +31,7 @@
  8546. #include "libcli/security/security.h"
  8547. #include "rpc_server/srv_pipe_hnd.h"
  8548. #include "auth/auth_util.h"
  8549. +#include "librpc/rpc/dcerpc_helper.h"
  8550. NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
  8551. struct files_struct **pfsp)
  8552. @@ -74,7 +75,7 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
  8553. if (smb_req->smb2req != NULL && smb_req->smb2req->was_encrypted) {
  8554. struct security_token *security_token = NULL;
  8555. uint16_t dialect = xconn->smb2.server.dialect;
  8556. - uint16_t srv_smb_encrypt = 0x0002;
  8557. + uint16_t srv_smb_encrypt = DCERPC_SMB_ENCRYPTION_REQUIRED;
  8558. uint16_t cipher = xconn->smb2.server.cipher;
  8559. char smb3_sid_str[SID_MAX_SIZE];
  8560. struct dom_sid smb3_dom_sid;
  8561. --
  8562. 2.29.2
  8563. From dad6dc0e5a202d48a930504768394343823d5c42 Mon Sep 17 00:00:00 2001
  8564. From: Andreas Schneider <asn@samba.org>
  8565. Date: Tue, 12 Nov 2019 16:56:45 +0100
  8566. Subject: [PATCH 080/104] s3:rpc_server: Allow to use RC4 for setting passwords
  8567. Signed-off-by: Andreas Schneider <asn@samba.org>
  8568. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8569. (cherry picked from commit c6a21e1897985f267bcfc681179cea95165c3c57)
  8570. ---
  8571. source3/rpc_server/samr/srv_samr_chgpasswd.c | 3 +
  8572. source3/rpc_server/samr/srv_samr_nt.c | 78 +++++++++++++++++++-
  8573. source3/rpc_server/wscript_build | 2 +-
  8574. 3 files changed, 81 insertions(+), 2 deletions(-)
  8575. diff --git a/source3/rpc_server/samr/srv_samr_chgpasswd.c b/source3/rpc_server/samr/srv_samr_chgpasswd.c
  8576. index cb9837ecf01..e326745169e 100644
  8577. --- a/source3/rpc_server/samr/srv_samr_chgpasswd.c
  8578. +++ b/source3/rpc_server/samr/srv_samr_chgpasswd.c
  8579. @@ -769,11 +769,13 @@ static NTSTATUS check_oem_password(const char *user,
  8580. .size = 16,
  8581. };
  8582. + GNUTLS_FIPS140_SET_LAX_MODE();
  8583. rc = gnutls_cipher_init(&cipher_hnd,
  8584. GNUTLS_CIPHER_ARCFOUR_128,
  8585. &enc_key,
  8586. NULL);
  8587. if (rc < 0) {
  8588. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8589. return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  8590. }
  8591. @@ -781,6 +783,7 @@ static NTSTATUS check_oem_password(const char *user,
  8592. password_encrypted,
  8593. 516);
  8594. gnutls_cipher_deinit(cipher_hnd);
  8595. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8596. if (rc < 0) {
  8597. return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  8598. }
  8599. diff --git a/source3/rpc_server/samr/srv_samr_nt.c b/source3/rpc_server/samr/srv_samr_nt.c
  8600. index 5ffc3331185..77cb18b6a88 100644
  8601. --- a/source3/rpc_server/samr/srv_samr_nt.c
  8602. +++ b/source3/rpc_server/samr/srv_samr_nt.c
  8603. @@ -46,6 +46,8 @@
  8604. #include "rpc_server/srv_access_check.h"
  8605. #include "../lib/tsocket/tsocket.h"
  8606. #include "lib/util/base64.h"
  8607. +#include "param/param.h"
  8608. +#include "librpc/rpc/dcerpc_helper.h"
  8609. #include "lib/crypto/gnutls_helpers.h"
  8610. #include <gnutls/gnutls.h>
  8611. @@ -1887,6 +1889,7 @@ NTSTATUS _samr_ChangePasswordUser2(struct pipes_struct *p,
  8612. char *user_name = NULL;
  8613. char *rhost;
  8614. const char *wks = NULL;
  8615. + bool encrypted;
  8616. DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
  8617. @@ -1915,6 +1918,12 @@ NTSTATUS _samr_ChangePasswordUser2(struct pipes_struct *p,
  8618. return NT_STATUS_NO_MEMORY;
  8619. }
  8620. + encrypted = dcerpc_is_transport_encrypted(p->session_info);
  8621. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8622. + !encrypted) {
  8623. + return NT_STATUS_ACCESS_DENIED;
  8624. + }
  8625. +
  8626. /*
  8627. * UNIX username case mangling not required, pass_oem_change
  8628. * is case insensitive.
  8629. @@ -1948,6 +1957,7 @@ NTSTATUS _samr_OemChangePasswordUser2(struct pipes_struct *p,
  8630. char *user_name = NULL;
  8631. const char *wks = NULL;
  8632. char *rhost;
  8633. + bool encrypted;
  8634. DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__));
  8635. @@ -1985,6 +1995,12 @@ NTSTATUS _samr_OemChangePasswordUser2(struct pipes_struct *p,
  8636. return NT_STATUS_NO_MEMORY;
  8637. }
  8638. + encrypted = dcerpc_is_transport_encrypted(p->session_info);
  8639. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8640. + !encrypted) {
  8641. + return NT_STATUS_ACCESS_DENIED;
  8642. + }
  8643. +
  8644. status = pass_oem_change(user_name,
  8645. rhost,
  8646. r->in.password->data,
  8647. @@ -5200,8 +5216,13 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
  8648. char *rhost;
  8649. DATA_BLOB session_key;
  8650. struct dom_sid_buf buf;
  8651. + struct loadparm_context *lp_ctx = NULL;
  8652. + bool encrypted;
  8653. - DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
  8654. + lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
  8655. + if (lp_ctx == NULL) {
  8656. + return NT_STATUS_NO_MEMORY;
  8657. + }
  8658. /* This is tricky. A WinXP domain join sets
  8659. (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
  8660. @@ -5390,13 +5411,27 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
  8661. break;
  8662. case 23:
  8663. + encrypted =
  8664. + dcerpc_is_transport_encrypted(p->session_info);
  8665. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8666. + !encrypted) {
  8667. + status = NT_STATUS_ACCESS_DENIED;
  8668. + break;
  8669. + }
  8670. +
  8671. status = session_extract_session_key(p->session_info, &session_key, KEY_USE_16BYTES);
  8672. if(!NT_STATUS_IS_OK(status)) {
  8673. break;
  8674. }
  8675. + /*
  8676. + * This can be allowed as it requires a session key
  8677. + * which we only have if we have a SMB session.
  8678. + */
  8679. + GNUTLS_FIPS140_SET_LAX_MODE();
  8680. status = arc4_decrypt_data(session_key,
  8681. info->info23.password.data,
  8682. 516);
  8683. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8684. if(!NT_STATUS_IS_OK(status)) {
  8685. break;
  8686. }
  8687. @@ -5412,14 +5447,27 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
  8688. break;
  8689. case 24:
  8690. + encrypted =
  8691. + dcerpc_is_transport_encrypted(p->session_info);
  8692. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8693. + !encrypted) {
  8694. + status = NT_STATUS_ACCESS_DENIED;
  8695. + break;
  8696. + }
  8697. status = session_extract_session_key(p->session_info, &session_key, KEY_USE_16BYTES);
  8698. if(!NT_STATUS_IS_OK(status)) {
  8699. break;
  8700. }
  8701. + /*
  8702. + * This can be allowed as it requires a session key
  8703. + * which we only have if we have a SMB session.
  8704. + */
  8705. + GNUTLS_FIPS140_SET_LAX_MODE();
  8706. status = arc4_decrypt_data(session_key,
  8707. info->info24.password.data,
  8708. 516);
  8709. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8710. if(!NT_STATUS_IS_OK(status)) {
  8711. break;
  8712. }
  8713. @@ -5434,12 +5482,26 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
  8714. break;
  8715. case 25:
  8716. + encrypted =
  8717. + dcerpc_is_transport_encrypted(p->session_info);
  8718. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8719. + !encrypted) {
  8720. + status = NT_STATUS_ACCESS_DENIED;
  8721. + break;
  8722. + }
  8723. +
  8724. status = session_extract_session_key(p->session_info, &session_key, KEY_USE_16BYTES);
  8725. if(!NT_STATUS_IS_OK(status)) {
  8726. break;
  8727. }
  8728. + /*
  8729. + * This can be allowed as it requires a session key
  8730. + * which we only have if we have a SMB session.
  8731. + */
  8732. + GNUTLS_FIPS140_SET_LAX_MODE();
  8733. status = decode_rc4_passwd_buffer(&session_key,
  8734. &info->info25.password);
  8735. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8736. if (!NT_STATUS_IS_OK(status)) {
  8737. break;
  8738. }
  8739. @@ -5454,12 +5516,26 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
  8740. break;
  8741. case 26:
  8742. + encrypted =
  8743. + dcerpc_is_transport_encrypted(p->session_info);
  8744. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8745. + !encrypted) {
  8746. + status = NT_STATUS_ACCESS_DENIED;
  8747. + break;
  8748. + }
  8749. +
  8750. status = session_extract_session_key(p->session_info, &session_key, KEY_USE_16BYTES);
  8751. if(!NT_STATUS_IS_OK(status)) {
  8752. break;
  8753. }
  8754. + /*
  8755. + * This can be allowed as it requires a session key
  8756. + * which we only have if we have a SMB session.
  8757. + */
  8758. + GNUTLS_FIPS140_SET_LAX_MODE();
  8759. status = decode_rc4_passwd_buffer(&session_key,
  8760. &info->info26.password);
  8761. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8762. if (!NT_STATUS_IS_OK(status)) {
  8763. break;
  8764. }
  8765. diff --git a/source3/rpc_server/wscript_build b/source3/rpc_server/wscript_build
  8766. index 2af02ad6fa8..eb91ac09384 100644
  8767. --- a/source3/rpc_server/wscript_build
  8768. +++ b/source3/rpc_server/wscript_build
  8769. @@ -85,7 +85,7 @@ bld.SAMBA3_SUBSYSTEM('RPC_SAMR',
  8770. source='''samr/srv_samr_nt.c
  8771. samr/srv_samr_util.c
  8772. samr/srv_samr_chgpasswd.c''',
  8773. - deps='PLAINTEXT_AUTH SRV_ACCESS_CHECK')
  8774. + deps='PLAINTEXT_AUTH SRV_ACCESS_CHECK DCERPC_HELPER')
  8775. bld.SAMBA3_SUBSYSTEM('RPC_SPOOLSS',
  8776. source='''spoolss/srv_spoolss_nt.c
  8777. --
  8778. 2.29.2
  8779. From 2932bdeff6ad18a36b2b64ab59d72ff1040acd09 Mon Sep 17 00:00:00 2001
  8780. From: Andreas Schneider <asn@samba.org>
  8781. Date: Fri, 15 Nov 2019 13:49:40 +0100
  8782. Subject: [PATCH 081/104] s4:rpc_server: Allow to use RC4 for setting passwords
  8783. Signed-off-by: Andreas Schneider <asn@samba.org>
  8784. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8785. (cherry picked from commit a9c532c6d3e85fbe49b7040254cfc66ab54074bc)
  8786. ---
  8787. source4/rpc_server/samr/samr_password.c | 30 +++++++++++++++++++++++++
  8788. source4/rpc_server/wscript_build | 2 +-
  8789. 2 files changed, 31 insertions(+), 1 deletion(-)
  8790. diff --git a/source4/rpc_server/samr/samr_password.c b/source4/rpc_server/samr/samr_password.c
  8791. index 52a644176e2..83b104fbd0e 100644
  8792. --- a/source4/rpc_server/samr/samr_password.c
  8793. +++ b/source4/rpc_server/samr/samr_password.c
  8794. @@ -31,6 +31,8 @@
  8795. #include "../lib/util/util_ldb.h"
  8796. #include "rpc_server/samr/proto.h"
  8797. #include "auth/auth_sam.h"
  8798. +#include "lib/param/loadparm.h"
  8799. +#include "librpc/rpc/dcerpc_helper.h"
  8800. #include "lib/crypto/gnutls_helpers.h"
  8801. #include <gnutls/gnutls.h>
  8802. @@ -129,6 +131,8 @@ NTSTATUS dcesrv_samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call,
  8803. struct dom_sid *user_objectSid = NULL;
  8804. gnutls_cipher_hd_t cipher_hnd = NULL;
  8805. gnutls_datum_t lm_session_key;
  8806. + struct loadparm_context *lp_ctx = dce_call->conn->dce_ctx->lp_ctx;
  8807. + bool encrypted;
  8808. int rc;
  8809. if (pwbuf == NULL) {
  8810. @@ -144,6 +148,12 @@ NTSTATUS dcesrv_samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call,
  8811. return NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER;
  8812. }
  8813. + encrypted = dcerpc_is_transport_encrypted(session_info);
  8814. + if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8815. + !encrypted) {
  8816. + return NT_STATUS_ACCESS_DENIED;
  8817. + }
  8818. +
  8819. /* Connect to a SAMDB with system privileges for fetching the old pw
  8820. * hashes. */
  8821. sam_ctx = samdb_connect(mem_ctx,
  8822. @@ -188,11 +198,13 @@ NTSTATUS dcesrv_samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call,
  8823. .size = sizeof(lm_pwd->hash),
  8824. };
  8825. + GNUTLS_FIPS140_SET_LAX_MODE();
  8826. rc = gnutls_cipher_init(&cipher_hnd,
  8827. GNUTLS_CIPHER_ARCFOUR_128,
  8828. &lm_session_key,
  8829. NULL);
  8830. if (rc < 0) {
  8831. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8832. status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  8833. goto failed;
  8834. }
  8835. @@ -201,6 +213,7 @@ NTSTATUS dcesrv_samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call,
  8836. pwbuf->data,
  8837. 516);
  8838. gnutls_cipher_deinit(cipher_hnd);
  8839. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8840. if (rc < 0) {
  8841. status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  8842. goto failed;
  8843. @@ -607,7 +620,17 @@ NTSTATUS samr_set_password(struct dcesrv_call_state *dce_call,
  8844. DATA_BLOB session_key = data_blob(NULL, 0);
  8845. gnutls_cipher_hd_t cipher_hnd = NULL;
  8846. gnutls_datum_t _session_key;
  8847. + struct auth_session_info *session_info =
  8848. + dcesrv_call_session_info(dce_call);
  8849. + struct loadparm_context *lp_ctx = dce_call->conn->dce_ctx->lp_ctx;
  8850. int rc;
  8851. + bool encrypted;
  8852. +
  8853. + encrypted = dcerpc_is_transport_encrypted(session_info);
  8854. + if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  8855. + !encrypted) {
  8856. + return NT_STATUS_ACCESS_DENIED;
  8857. + }
  8858. nt_status = dcesrv_transport_session_key(dce_call, &session_key);
  8859. if (!NT_STATUS_IS_OK(nt_status)) {
  8860. @@ -621,11 +644,17 @@ NTSTATUS samr_set_password(struct dcesrv_call_state *dce_call,
  8861. .size = session_key.length,
  8862. };
  8863. + /*
  8864. + * This is safe to support as we only have a session key
  8865. + * over a SMB connection which we force to be encrypted.
  8866. + */
  8867. + GNUTLS_FIPS140_SET_LAX_MODE();
  8868. rc = gnutls_cipher_init(&cipher_hnd,
  8869. GNUTLS_CIPHER_ARCFOUR_128,
  8870. &_session_key,
  8871. NULL);
  8872. if (rc < 0) {
  8873. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8874. nt_status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  8875. goto out;
  8876. }
  8877. @@ -634,6 +663,7 @@ NTSTATUS samr_set_password(struct dcesrv_call_state *dce_call,
  8878. pwbuf->data,
  8879. 516);
  8880. gnutls_cipher_deinit(cipher_hnd);
  8881. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8882. if (rc < 0) {
  8883. nt_status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  8884. goto out;
  8885. diff --git a/source4/rpc_server/wscript_build b/source4/rpc_server/wscript_build
  8886. index de55ad6239a..c9c1978f223 100644
  8887. --- a/source4/rpc_server/wscript_build
  8888. +++ b/source4/rpc_server/wscript_build
  8889. @@ -87,7 +87,7 @@ bld.SAMBA_MODULE('dcesrv_samr',
  8890. autoproto='samr/proto.h',
  8891. subsystem='dcerpc_server',
  8892. init_function='dcerpc_server_samr_init',
  8893. - deps='samdb DCERPC_COMMON ndr-standard auth4_sam GNUTLS_HELPERS'
  8894. + deps='samdb DCERPC_COMMON ndr-standard auth4_sam GNUTLS_HELPERS DCERPC_HELPER'
  8895. )
  8896. --
  8897. 2.29.2
  8898. From 959978865400d20fe1b2f9b5343fbec7c0b1109a Mon Sep 17 00:00:00 2001
  8899. From: Isaac Boukris <iboukris@gmail.com>
  8900. Date: Thu, 20 Aug 2020 12:45:49 +0200
  8901. Subject: [PATCH 082/104] lib:crypto: Add py binding for set_relax/strict fips
  8902. mode
  8903. Signed-off-by: Isaac Boukris <iboukris@gmail.com>
  8904. Reviewed-by: Andreas Schneider <asn@samba.org>
  8905. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8906. (cherry picked from commit 32d4c75d6cbf9153068a0487347097707afb356a)
  8907. ---
  8908. lib/crypto/py_crypto.c | 16 ++++++++++++++++
  8909. 1 file changed, 16 insertions(+)
  8910. diff --git a/lib/crypto/py_crypto.c b/lib/crypto/py_crypto.c
  8911. index 32b946eee8f..ad18d3ada0f 100644
  8912. --- a/lib/crypto/py_crypto.c
  8913. +++ b/lib/crypto/py_crypto.c
  8914. @@ -24,6 +24,7 @@
  8915. #include <gnutls/gnutls.h>
  8916. #include <gnutls/crypto.h>
  8917. +#include "lib/crypto/gnutls_helpers.h"
  8918. static PyObject *py_crypto_arcfour_crypt_blob(PyObject *module, PyObject *args)
  8919. {
  8920. @@ -85,12 +86,27 @@ static PyObject *py_crypto_arcfour_crypt_blob(PyObject *module, PyObject *args)
  8921. return result;
  8922. }
  8923. +static PyObject *py_crypto_set_relax_mode(PyObject *module)
  8924. +{
  8925. + GNUTLS_FIPS140_SET_LAX_MODE();
  8926. +
  8927. + Py_RETURN_NONE;
  8928. +}
  8929. +
  8930. +static PyObject *py_crypto_set_strict_mode(PyObject *module)
  8931. +{
  8932. + GNUTLS_FIPS140_SET_STRICT_MODE();
  8933. +
  8934. + Py_RETURN_NONE;
  8935. +}
  8936. static const char py_crypto_arcfour_crypt_blob_doc[] = "arcfour_crypt_blob(data, key)\n"
  8937. "Encrypt the data with RC4 algorithm using the key";
  8938. static PyMethodDef py_crypto_methods[] = {
  8939. { "arcfour_crypt_blob", (PyCFunction)py_crypto_arcfour_crypt_blob, METH_VARARGS, py_crypto_arcfour_crypt_blob_doc },
  8940. + { "set_relax_mode", (PyCFunction)py_crypto_set_relax_mode, METH_NOARGS, "Set fips to relax mode" },
  8941. + { "set_strict_mode", (PyCFunction)py_crypto_set_strict_mode, METH_NOARGS, "Set fips to strict mode" },
  8942. {0},
  8943. };
  8944. --
  8945. 2.29.2
  8946. From e3059d24a83175efb4f9eb3844c2e02d2af7775a Mon Sep 17 00:00:00 2001
  8947. From: Andreas Schneider <asn@samba.org>
  8948. Date: Wed, 28 Oct 2020 17:05:36 +0100
  8949. Subject: [PATCH 083/104] s4:param: Add 'weak crypto' getter to pyparam
  8950. Signed-off-by: Andreas Schneider <asn@samba.org>
  8951. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  8952. (cherry picked from commit 7d54e4b49c235dc571f47d15e6b0a6fa63340773)
  8953. ---
  8954. source4/param/pyparam.c | 22 ++++++++++++++++++++++
  8955. 1 file changed, 22 insertions(+)
  8956. diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
  8957. index 4023fac4dd6..e15592b5743 100644
  8958. --- a/source4/param/pyparam.c
  8959. +++ b/source4/param/pyparam.c
  8960. @@ -463,6 +463,23 @@ static PyObject *py_lp_ctx_config_file(PyObject *self, void *closure)
  8961. return PyUnicode_FromString(configfile);
  8962. }
  8963. +static PyObject *py_lp_ctx_weak_crypto(PyObject *self, void *closure)
  8964. +{
  8965. + enum samba_weak_crypto weak_crypto =
  8966. + lpcfg_weak_crypto(PyLoadparmContext_AsLoadparmContext(self));
  8967. +
  8968. + switch(weak_crypto) {
  8969. + case SAMBA_WEAK_CRYPTO_UNKNOWN:
  8970. + Py_RETURN_NONE;
  8971. + case SAMBA_WEAK_CRYPTO_ALLOWED:
  8972. + return PyUnicode_FromString("allowed");
  8973. + case SAMBA_WEAK_CRYPTO_DISALLOWED:
  8974. + return PyUnicode_FromString("disallowed");
  8975. + }
  8976. +
  8977. + Py_RETURN_NONE;
  8978. +}
  8979. +
  8980. static PyGetSetDef py_lp_ctx_getset[] = {
  8981. {
  8982. .name = discard_const_p(char, "default_service"),
  8983. @@ -473,6 +490,11 @@ static PyGetSetDef py_lp_ctx_getset[] = {
  8984. .get = (getter)py_lp_ctx_config_file,
  8985. .doc = discard_const_p(char, "Name of last config file that was loaded.")
  8986. },
  8987. + {
  8988. + .name = discard_const_p(char, "weak_crypto"),
  8989. + .get = (getter)py_lp_ctx_weak_crypto,
  8990. + .doc = discard_const_p(char, "If weak crypto is allowed.")
  8991. + },
  8992. { .name = NULL }
  8993. };
  8994. --
  8995. 2.29.2
  8996. From 2c10e3c1bbd7527f8563dca42700310c86ec04d4 Mon Sep 17 00:00:00 2001
  8997. From: Andreas Schneider <asn@samba.org>
  8998. Date: Wed, 21 Oct 2020 10:09:22 +0200
  8999. Subject: [PATCH 084/104] python:tests: Add SAMR password change tests for fips
  9000. Signed-off-by: Andreas Schneider <asn@samba.org>
  9001. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  9002. (cherry picked from commit 9a3ba502d8193b25799ef92917efafd52de2e8c2)
  9003. ---
  9004. .../tests/dcerpc/samr_change_password.py | 188 ++++++++++++++++++
  9005. selftest/tests.py | 2 +
  9006. 2 files changed, 190 insertions(+)
  9007. create mode 100644 python/samba/tests/dcerpc/samr_change_password.py
  9008. diff --git a/python/samba/tests/dcerpc/samr_change_password.py b/python/samba/tests/dcerpc/samr_change_password.py
  9009. new file mode 100644
  9010. index 00000000000..109eeea98cc
  9011. --- /dev/null
  9012. +++ b/python/samba/tests/dcerpc/samr_change_password.py
  9013. @@ -0,0 +1,188 @@
  9014. +# Unix SMB/CIFS implementation.
  9015. +#
  9016. +# Copyright © 2020 Andreas Schneider <asn@samba.org>
  9017. +#
  9018. +# This program is free software; you can redistribute it and/or modify
  9019. +# it under the terms of the GNU General Public License as published by
  9020. +# the Free Software Foundation; either version 3 of the License, or
  9021. +# (at your option) any later version.
  9022. +#
  9023. +# This program is distributed in the hope that it will be useful,
  9024. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  9025. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9026. +# GNU General Public License for more details.
  9027. +#
  9028. +# You should have received a copy of the GNU General Public License
  9029. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  9030. +#
  9031. +
  9032. +"""Tests for samba.dcerpc.samr.password"""
  9033. +
  9034. +import os
  9035. +import ctypes
  9036. +import samba.tests
  9037. +
  9038. +from samba import crypto, generate_random_password, generate_random_bytes, ntstatus
  9039. +from samba.auth import system_session
  9040. +from samba.credentials import Credentials
  9041. +from samba.credentials import SMB_ENCRYPTION_REQUIRED
  9042. +from samba.dcerpc import samr, security, lsa
  9043. +from samba.samdb import SamDB
  9044. +from samba.tests import RpcInterfaceTestCase
  9045. +
  9046. +
  9047. +class SamrPasswordTests(RpcInterfaceTestCase):
  9048. + def setUp(self):
  9049. + super(SamrPasswordTests, self).setUp()
  9050. + self.open_samdb()
  9051. +
  9052. + self.create_user_account(10000)
  9053. +
  9054. + self.remote_server = samba.tests.env_get_var_value('SERVER')
  9055. + self.remote_domain = samba.tests.env_get_var_value('DOMAIN')
  9056. + self.remote_user = samba.tests.env_get_var_value('USERNAME')
  9057. + self.remote_password = samba.tests.env_get_var_value('PASSWORD')
  9058. + self.remote_binding_string = "ncacn_np:%s[krb5]" % (self.remote_server)
  9059. +
  9060. + self.remote_creds = Credentials()
  9061. + self.remote_creds.guess(self.lp)
  9062. + self.remote_creds.set_username(self.remote_user)
  9063. + self.remote_creds.set_password(self.remote_password)
  9064. +
  9065. + def tearDown(self):
  9066. + super(SamrPasswordTests, self).tearDown()
  9067. +
  9068. + samr.Close(self.user_handle)
  9069. + samr.Close(self.domain_handle)
  9070. + samr.Close(self.handle)
  9071. +
  9072. + samba.tests.delete_force(self.samdb, self.user_dn)
  9073. +
  9074. + #
  9075. + # Open the samba database
  9076. + #
  9077. + def open_samdb(self):
  9078. + self.lp = samba.tests.env_loadparm()
  9079. +
  9080. + self.local_creds = Credentials()
  9081. + self.local_creds.guess(self.lp)
  9082. + self.session = system_session()
  9083. + self.samdb = SamDB(session_info=self.session,
  9084. + credentials=self.local_creds,
  9085. + lp=self.lp)
  9086. +
  9087. + #
  9088. + # Open a SAMR Domain handle
  9089. + #
  9090. + def open_domain_handle(self):
  9091. + self.handle = self.conn.Connect2(None,
  9092. + security.SEC_FLAG_MAXIMUM_ALLOWED)
  9093. +
  9094. + self.domain_sid = self.conn.LookupDomain(self.handle,
  9095. + lsa.String(self.remote_domain))
  9096. +
  9097. + self.domain_handle = self.conn.OpenDomain(self.handle,
  9098. + security.SEC_FLAG_MAXIMUM_ALLOWED,
  9099. + self.domain_sid)
  9100. +
  9101. + def open_user_handle(self):
  9102. + name = lsa.String(self.user_name)
  9103. +
  9104. + rids = self.conn.LookupNames(self.domain_handle, [name])
  9105. +
  9106. + self.user_handle = self.conn.OpenUser(self.domain_handle,
  9107. + security.SEC_FLAG_MAXIMUM_ALLOWED,
  9108. + rids[0].ids[0])
  9109. + #
  9110. + # Create a test user account
  9111. + #
  9112. + def create_user_account(self, user_id):
  9113. + self.user_name = ("SAMR_USER_%d" % user_id)
  9114. + self.user_pass = generate_random_password(32, 32)
  9115. + self.user_dn = "cn=%s,cn=users,%s" % (self.user_name, self.samdb.domain_dn())
  9116. +
  9117. + samba.tests.delete_force(self.samdb, self.user_dn)
  9118. +
  9119. + self.samdb.newuser(self.user_name,
  9120. + self.user_pass,
  9121. + description="Password for " + self.user_name + " is " + self.user_pass,
  9122. + givenname=self.user_name,
  9123. + surname=self.user_name)
  9124. +
  9125. +
  9126. + def init_samr_CryptPassword(self, password, session_key):
  9127. +
  9128. + def encode_pw_buffer(password):
  9129. + data = bytearray([0] * 516)
  9130. +
  9131. + p = samba.string_to_byte_array(password.encode('utf-16-le'))
  9132. + plen = len(p)
  9133. +
  9134. + b = generate_random_bytes(512 - plen)
  9135. +
  9136. + i = 512 - plen
  9137. + data[0:i] = b
  9138. + data[i:i+plen] = p
  9139. + data[512:516] = plen.to_bytes(4, byteorder='little')
  9140. +
  9141. + return bytes(data)
  9142. +
  9143. + # This is a test, so always allow to encrypt using RC4
  9144. + try:
  9145. + crypto.set_relax_mode()
  9146. + encrypted_blob = samba.arcfour_encrypt(session_key, encode_pw_buffer(password))
  9147. + finally:
  9148. + crypto.set_strict_mode()
  9149. +
  9150. + out_blob = samr.CryptPassword()
  9151. + out_blob.data = list(encrypted_blob)
  9152. +
  9153. + return out_blob
  9154. +
  9155. +
  9156. + def test_setUserInfo2_Password(self, password='P@ssw0rd'):
  9157. + self.conn = samr.samr(self.remote_binding_string,
  9158. + self.get_loadparm(),
  9159. + self.remote_creds)
  9160. + self.open_domain_handle()
  9161. + self.open_user_handle()
  9162. +
  9163. + password='P@ssw0rd'
  9164. +
  9165. + level = 24
  9166. + info = samr.UserInfo24()
  9167. +
  9168. + info.password_expired = 0
  9169. + info.password = self.init_samr_CryptPassword(password, self.conn.session_key)
  9170. +
  9171. + # If the server is in FIPS mode, it should reject the password change!
  9172. + try:
  9173. + self.conn.SetUserInfo2(self.user_handle, level, info)
  9174. + except samba.NTSTATUSError as e:
  9175. + code = ctypes.c_uint32(e.args[0]).value
  9176. + print(code)
  9177. + if ((code == ntstatus.NT_STATUS_ACCESS_DENIED) and
  9178. + (self.lp.weak_crypto == 'disallowed')):
  9179. + pass
  9180. + else:
  9181. + raise
  9182. +
  9183. +
  9184. + def test_setUserInfo2_Password_Encrypted(self, password='P@ssw0rd'):
  9185. + self.remote_creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  9186. +
  9187. + self.conn = samr.samr(self.remote_binding_string,
  9188. + self.get_loadparm(),
  9189. + self.remote_creds)
  9190. + self.open_domain_handle()
  9191. + self.open_user_handle()
  9192. +
  9193. + password='P@ssw0rd'
  9194. +
  9195. + level = 24
  9196. + info = samr.UserInfo24()
  9197. +
  9198. + info.password_expired = 0
  9199. + info.password = self.init_samr_CryptPassword(password, self.conn.session_key)
  9200. +
  9201. + self.conn.SetUserInfo2(self.user_handle, level, info)
  9202. diff --git a/selftest/tests.py b/selftest/tests.py
  9203. index adcb5b53189..86cab3f8046 100644
  9204. --- a/selftest/tests.py
  9205. +++ b/selftest/tests.py
  9206. @@ -93,6 +93,8 @@ planpythontestsuite(
  9207. os.path.join(samba4srcdir, "..", "third_party", "waf")])
  9208. planpythontestsuite("fileserver", "samba.tests.smbd_fuzztest")
  9209. planpythontestsuite("nt4_dc_smb1", "samba.tests.dcerpc.binding")
  9210. +for env in [ 'ad_dc:local', 'ad_dc_fips:local' ]:
  9211. + planpythontestsuite(env, "samba.tests.dcerpc.samr_change_password")
  9212. def cmdline(script, *args):
  9213. --
  9214. 2.29.2
  9215. From 65f6aef76ebc4b432f2743fb36cec64d7e06e71d Mon Sep 17 00:00:00 2001
  9216. From: Andreas Schneider <asn@samba.org>
  9217. Date: Wed, 21 Oct 2020 10:09:22 +0200
  9218. Subject: [PATCH 085/104] python:tests: Add SAMR password change tests for fips
  9219. Signed-off-by: Andreas Schneider <asn@samba.org>
  9220. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  9221. Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
  9222. Autobuild-Date(master): Thu Oct 29 15:41:37 UTC 2020 on sn-devel-184
  9223. (cherry picked from commit ebd687335b9accfdbae7dbc65c9882ab4d5c0986)
  9224. ---
  9225. selftest/target/Samba4.pm | 2 +-
  9226. 1 file changed, 1 insertion(+), 1 deletion(-)
  9227. diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
  9228. index 649e923ff9a..1ebdf2a5484 100755
  9229. --- a/selftest/target/Samba4.pm
  9230. +++ b/selftest/target/Samba4.pm
  9231. @@ -1040,7 +1040,7 @@ servicePrincipalName: http/testupnspn.$ctx->{dnsname}
  9232. $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
  9233. $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
  9234. $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
  9235. - . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
  9236. + . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account' -d10";
  9237. unless (system($samba_tool_cmd) == 0) {
  9238. warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
  9239. return undef;
  9240. --
  9241. 2.29.2
  9242. From 114ce58de5ac14035c095e12aeb31931c7859d89 Mon Sep 17 00:00:00 2001
  9243. From: Andreas Schneider <asn@samba.org>
  9244. Date: Thu, 20 Aug 2020 09:40:41 +0200
  9245. Subject: [PATCH 086/104] auth:creds: Rename CRED_USE_KERBEROS values
  9246. Signed-off-by: Andreas Schneider <asn@samba.org>
  9247. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  9248. (cherry picked from commit 1298280a22ef7494fb85a6a5953bae15d22fa204)
  9249. ---
  9250. auth/credentials/credentials.c | 8 +++++---
  9251. auth/credentials/credentials.h | 9 ++++++---
  9252. auth/credentials/credentials_krb5.c | 4 ++--
  9253. auth/credentials/credentials_ntlm.c | 2 +-
  9254. auth/credentials/credentials_secrets.c | 5 +++--
  9255. auth/credentials/pycredentials.c | 6 +++---
  9256. auth/credentials/tests/simple.c | 2 +-
  9257. auth/credentials/wscript_build | 2 +-
  9258. auth/gensec/gensec_start.c | 8 ++++----
  9259. examples/winexe/winexe.c | 4 ++--
  9260. source3/auth/auth_generic.c | 4 ++--
  9261. source3/lib/util_cmdline.c | 18 +++++++++---------
  9262. source3/libads/sasl.c | 8 ++++----
  9263. source3/libnet/libnet_join.c | 2 +-
  9264. source3/libsmb/cliconnect.c | 16 ++++++++--------
  9265. source3/passdb/passdb.c | 6 +++---
  9266. source3/passdb/pdb_samba_dsdb.c | 4 ++--
  9267. source3/rpc_client/cli_pipe.c | 2 +-
  9268. source3/rpcclient/rpcclient.c | 8 ++++----
  9269. source3/utils/net_ads.c | 2 +-
  9270. source3/utils/net_util.c | 6 +++---
  9271. source3/utils/ntlm_auth.c | 4 ++--
  9272. source3/winbindd/winbindd_cm.c | 2 +-
  9273. source4/auth/gensec/gensec_gssapi.c | 2 +-
  9274. source4/auth/session.c | 2 +-
  9275. source4/lib/cmdline/popt_credentials.c | 4 ++--
  9276. source4/torture/ldap/session_expiry.c | 2 +-
  9277. source4/torture/raw/session.c | 4 ++--
  9278. source4/torture/rpc/schannel.c | 4 ++--
  9279. source4/torture/smb2/session.c | 12 ++++++------
  9280. 30 files changed, 84 insertions(+), 78 deletions(-)
  9281. diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
  9282. index 77c35dd104b..1bdd6f15a09 100644
  9283. --- a/auth/credentials/credentials.c
  9284. +++ b/auth/credentials/credentials.c
  9285. @@ -44,6 +44,8 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
  9286. cred->winbind_separator = '\\';
  9287. + cred->use_kerberos = CRED_USE_KERBEROS_DESIRED;
  9288. +
  9289. cred->signing_state = SMB_SIGNING_DEFAULT;
  9290. /*
  9291. @@ -360,7 +362,7 @@ _PUBLIC_ bool cli_credentials_authentication_requested(struct cli_credentials *c
  9292. return true;
  9293. }
  9294. - if (cli_credentials_get_kerberos_state(cred) == CRED_MUST_USE_KERBEROS) {
  9295. + if (cli_credentials_get_kerberos_state(cred) == CRED_USE_KERBEROS_REQUIRED) {
  9296. return true;
  9297. }
  9298. @@ -1018,7 +1020,7 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
  9299. }
  9300. if (lp_ctx != NULL &&
  9301. - cli_credentials_get_kerberos_state(cred) != CRED_DONT_USE_KERBEROS) {
  9302. + cli_credentials_get_kerberos_state(cred) != CRED_USE_KERBEROS_DISABLED) {
  9303. cli_credentials_set_ccache(cred, lp_ctx, NULL, CRED_GUESS_FILE,
  9304. &error_string);
  9305. }
  9306. @@ -1097,7 +1099,7 @@ _PUBLIC_ void cli_credentials_set_anonymous(struct cli_credentials *cred)
  9307. cli_credentials_set_principal(cred, NULL, CRED_SPECIFIED);
  9308. cli_credentials_set_realm(cred, NULL, CRED_SPECIFIED);
  9309. cli_credentials_set_workstation(cred, "", CRED_UNINITIALISED);
  9310. - cli_credentials_set_kerberos_state(cred, CRED_DONT_USE_KERBEROS);
  9311. + cli_credentials_set_kerberos_state(cred, CRED_USE_KERBEROS_DISABLED);
  9312. }
  9313. /**
  9314. diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
  9315. index 438bcdce232..f468b8558dd 100644
  9316. --- a/auth/credentials/credentials.h
  9317. +++ b/auth/credentials/credentials.h
  9318. @@ -53,9 +53,12 @@ enum credentials_obtained {
  9319. };
  9320. enum credentials_use_kerberos {
  9321. - CRED_AUTO_USE_KERBEROS = 0, /* Default, we try kerberos if available */
  9322. - CRED_DONT_USE_KERBEROS, /* Sometimes trying kerberos just does 'bad things', so don't */
  9323. - CRED_MUST_USE_KERBEROS /* Sometimes administrators are parinoid, so always do kerberos */
  9324. + /** Sometimes trying kerberos just does 'bad things', so don't */
  9325. + CRED_USE_KERBEROS_DISABLED = 0,
  9326. + /** Default, we try kerberos if available */
  9327. + CRED_USE_KERBEROS_DESIRED,
  9328. + /** Sometimes administrators are paranoid, so always do kerberos */
  9329. + CRED_USE_KERBEROS_REQUIRED,
  9330. };
  9331. enum credentials_krb_forwardable {
  9332. diff --git a/auth/credentials/credentials_krb5.c b/auth/credentials/credentials_krb5.c
  9333. index 259b35b73b0..36f6b59a72b 100644
  9334. --- a/auth/credentials/credentials_krb5.c
  9335. +++ b/auth/credentials/credentials_krb5.c
  9336. @@ -871,7 +871,7 @@ _PUBLIC_ int cli_credentials_get_client_gss_creds(struct cli_credentials *cred,
  9337. ret = cli_credentials_get_ccache(cred, event_ctx, lp_ctx,
  9338. &ccache, error_string);
  9339. if (ret) {
  9340. - if (cli_credentials_get_kerberos_state(cred) == CRED_MUST_USE_KERBEROS) {
  9341. + if (cli_credentials_get_kerberos_state(cred) == CRED_USE_KERBEROS_REQUIRED) {
  9342. DEBUG(1, ("Failed to get kerberos credentials (kerberos required): %s\n", *error_string));
  9343. } else {
  9344. DEBUG(4, ("Failed to get kerberos credentials: %s\n", *error_string));
  9345. @@ -1431,7 +1431,7 @@ _PUBLIC_ void cli_credentials_set_impersonate_principal(struct cli_credentials *
  9346. cred->impersonate_principal = talloc_strdup(cred, principal);
  9347. talloc_free(cred->self_service);
  9348. cred->self_service = talloc_strdup(cred, self_service);
  9349. - cli_credentials_set_kerberos_state(cred, CRED_MUST_USE_KERBEROS);
  9350. + cli_credentials_set_kerberos_state(cred, CRED_USE_KERBEROS_REQUIRED);
  9351. }
  9352. /*
  9353. diff --git a/auth/credentials/credentials_ntlm.c b/auth/credentials/credentials_ntlm.c
  9354. index f1b22a6c9e2..1bec60e5dce 100644
  9355. --- a/auth/credentials/credentials_ntlm.c
  9356. +++ b/auth/credentials/credentials_ntlm.c
  9357. @@ -53,7 +53,7 @@ _PUBLIC_ NTSTATUS cli_credentials_get_ntlm_response(struct cli_credentials *cred
  9358. const struct samr_Password *nt_hash = NULL;
  9359. int rc;
  9360. - if (cred->use_kerberos == CRED_MUST_USE_KERBEROS) {
  9361. + if (cred->use_kerberos == CRED_USE_KERBEROS_REQUIRED) {
  9362. TALLOC_FREE(frame);
  9363. return NT_STATUS_INVALID_PARAMETER_MIX;
  9364. }
  9365. diff --git a/auth/credentials/credentials_secrets.c b/auth/credentials/credentials_secrets.c
  9366. index 52a89d4d5b4..58067a5bece 100644
  9367. --- a/auth/credentials/credentials_secrets.c
  9368. +++ b/auth/credentials/credentials_secrets.c
  9369. @@ -370,7 +370,8 @@ _PUBLIC_ NTSTATUS cli_credentials_set_machine_account_db_ctx(struct cli_credenti
  9370. }
  9371. if (secrets_tdb_password_more_recent) {
  9372. - enum credentials_use_kerberos use_kerberos = CRED_DONT_USE_KERBEROS;
  9373. + enum credentials_use_kerberos use_kerberos =
  9374. + CRED_USE_KERBEROS_DISABLED;
  9375. char *machine_account = talloc_asprintf(tmp_ctx, "%s$", lpcfg_netbios_name(lp_ctx));
  9376. cli_credentials_set_password(cred, secrets_tdb_password, CRED_SPECIFIED);
  9377. cli_credentials_set_old_password(cred, secrets_tdb_old_password, CRED_SPECIFIED);
  9378. @@ -386,7 +387,7 @@ _PUBLIC_ NTSTATUS cli_credentials_set_machine_account_db_ctx(struct cli_credenti
  9379. FALL_THROUGH;
  9380. case ROLE_ACTIVE_DIRECTORY_DC:
  9381. - use_kerberos = CRED_AUTO_USE_KERBEROS;
  9382. + use_kerberos = CRED_USE_KERBEROS_DESIRED;
  9383. break;
  9384. }
  9385. }
  9386. diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
  9387. index 17c90573f09..95dde276ef7 100644
  9388. --- a/auth/credentials/pycredentials.c
  9389. +++ b/auth/credentials/pycredentials.c
  9390. @@ -1492,9 +1492,9 @@ MODULE_INIT_FUNC(credentials)
  9391. PyModule_AddObject(m, "CALLBACK_RESULT", PyLong_FromLong(CRED_CALLBACK_RESULT));
  9392. PyModule_AddObject(m, "SPECIFIED", PyLong_FromLong(CRED_SPECIFIED));
  9393. - PyModule_AddObject(m, "AUTO_USE_KERBEROS", PyLong_FromLong(CRED_AUTO_USE_KERBEROS));
  9394. - PyModule_AddObject(m, "DONT_USE_KERBEROS", PyLong_FromLong(CRED_DONT_USE_KERBEROS));
  9395. - PyModule_AddObject(m, "MUST_USE_KERBEROS", PyLong_FromLong(CRED_MUST_USE_KERBEROS));
  9396. + PyModule_AddObject(m, "AUTO_USE_KERBEROS", PyLong_FromLong(CRED_USE_KERBEROS_DESIRED));
  9397. + PyModule_AddObject(m, "DONT_USE_KERBEROS", PyLong_FromLong(CRED_USE_KERBEROS_DISABLED));
  9398. + PyModule_AddObject(m, "MUST_USE_KERBEROS", PyLong_FromLong(CRED_USE_KERBEROS_REQUIRED));
  9399. PyModule_AddObject(m, "AUTO_KRB_FORWARDABLE", PyLong_FromLong(CRED_AUTO_KRB_FORWARDABLE));
  9400. PyModule_AddObject(m, "NO_KRB_FORWARDABLE", PyLong_FromLong(CRED_NO_KRB_FORWARDABLE));
  9401. diff --git a/auth/credentials/tests/simple.c b/auth/credentials/tests/simple.c
  9402. index 7f122bed3bc..b39d7a2251b 100644
  9403. --- a/auth/credentials/tests/simple.c
  9404. +++ b/auth/credentials/tests/simple.c
  9405. @@ -73,7 +73,7 @@ static bool test_guess(struct torture_context *tctx)
  9406. const char *passwd_fd = getenv("PASSWD_FD");
  9407. const char *passwd_file = getenv("PASSWD_FILE");
  9408. - cli_credentials_set_kerberos_state(creds, CRED_MUST_USE_KERBEROS);
  9409. + cli_credentials_set_kerberos_state(creds, CRED_USE_KERBEROS_REQUIRED);
  9410. unsetenv("USER");
  9411. unsetenv("PASSWD_FD");
  9412. diff --git a/auth/credentials/wscript_build b/auth/credentials/wscript_build
  9413. index 1e3302e3e48..ad16b7d8008 100644
  9414. --- a/auth/credentials/wscript_build
  9415. +++ b/auth/credentials/wscript_build
  9416. @@ -5,7 +5,7 @@ bld.SAMBA_LIBRARY('samba-credentials',
  9417. public_headers='credentials.h',
  9418. pc_files='samba-credentials.pc',
  9419. deps='LIBCRYPTO samba-errors events LIBCLI_AUTH samba-security CREDENTIALS_SECRETS CREDENTIALS_KRB5',
  9420. - vnum='0.1.0'
  9421. + vnum='1.0.0'
  9422. )
  9423. bld.SAMBA_SUBSYSTEM('CREDENTIALS_KRB5',
  9424. diff --git a/auth/gensec/gensec_start.c b/auth/gensec/gensec_start.c
  9425. index 3f42d611140..56306efed13 100644
  9426. --- a/auth/gensec/gensec_start.c
  9427. +++ b/auth/gensec/gensec_start.c
  9428. @@ -117,18 +117,18 @@ static const struct gensec_security_ops **gensec_use_kerberos_mechs(
  9429. }
  9430. switch (use_kerberos) {
  9431. - case CRED_AUTO_USE_KERBEROS:
  9432. + case CRED_USE_KERBEROS_DESIRED:
  9433. keep = true;
  9434. break;
  9435. - case CRED_DONT_USE_KERBEROS:
  9436. + case CRED_USE_KERBEROS_DISABLED:
  9437. if (old_gensec_list[i]->kerberos == false) {
  9438. keep = true;
  9439. }
  9440. break;
  9441. - case CRED_MUST_USE_KERBEROS:
  9442. + case CRED_USE_KERBEROS_REQUIRED:
  9443. if (old_gensec_list[i]->kerberos == true) {
  9444. keep = true;
  9445. }
  9446. @@ -156,7 +156,7 @@ _PUBLIC_ const struct gensec_security_ops **gensec_security_mechs(
  9447. TALLOC_CTX *mem_ctx)
  9448. {
  9449. const struct gensec_security_ops * const *backends = gensec_security_all();
  9450. - enum credentials_use_kerberos use_kerberos = CRED_AUTO_USE_KERBEROS;
  9451. + enum credentials_use_kerberos use_kerberos = CRED_USE_KERBEROS_DESIRED;
  9452. bool keep_schannel = false;
  9453. if (gensec_security != NULL) {
  9454. diff --git a/examples/winexe/winexe.c b/examples/winexe/winexe.c
  9455. index 03e7ec85198..95386211c0a 100644
  9456. --- a/examples/winexe/winexe.c
  9457. +++ b/examples/winexe/winexe.c
  9458. @@ -283,8 +283,8 @@ static void parse_args(int argc, const char *argv[],
  9459. if (opt_kerberos) {
  9460. cli_credentials_set_kerberos_state(cred,
  9461. strcmp(opt_kerberos, "yes")
  9462. - ? CRED_MUST_USE_KERBEROS
  9463. - : CRED_DONT_USE_KERBEROS);
  9464. + ? CRED_USE_KERBEROS_REQUIRED
  9465. + : CRED_USE_KERBEROS_DISABLED);
  9466. }
  9467. if (options->runas == NULL && options->runas_file != NULL) {
  9468. diff --git a/source3/auth/auth_generic.c b/source3/auth/auth_generic.c
  9469. index 0e9500ac08d..f314acd9559 100644
  9470. --- a/source3/auth/auth_generic.c
  9471. +++ b/source3/auth/auth_generic.c
  9472. @@ -356,9 +356,9 @@ NTSTATUS auth_generic_prepare(TALLOC_CTX *mem_ctx,
  9473. cli_credentials_set_conf(server_credentials, lp_ctx);
  9474. if (lp_security() == SEC_ADS || USE_KERBEROS_KEYTAB) {
  9475. - cli_credentials_set_kerberos_state(server_credentials, CRED_AUTO_USE_KERBEROS);
  9476. + cli_credentials_set_kerberos_state(server_credentials, CRED_USE_KERBEROS_DESIRED);
  9477. } else {
  9478. - cli_credentials_set_kerberos_state(server_credentials, CRED_DONT_USE_KERBEROS);
  9479. + cli_credentials_set_kerberos_state(server_credentials, CRED_USE_KERBEROS_DISABLED);
  9480. }
  9481. nt_status = gensec_server_start(tmp_ctx, gensec_settings,
  9482. diff --git a/source3/lib/util_cmdline.c b/source3/lib/util_cmdline.c
  9483. index 9c9e2f0ac0f..d2af34ee19b 100644
  9484. --- a/source3/lib/util_cmdline.c
  9485. +++ b/source3/lib/util_cmdline.c
  9486. @@ -307,9 +307,9 @@ void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info,
  9487. enum credentials_use_kerberos krb5_state;
  9488. if (b) {
  9489. - krb5_state = CRED_MUST_USE_KERBEROS;
  9490. + krb5_state = CRED_USE_KERBEROS_REQUIRED;
  9491. } else {
  9492. - krb5_state = CRED_DONT_USE_KERBEROS;
  9493. + krb5_state = CRED_USE_KERBEROS_DISABLED;
  9494. }
  9495. cli_credentials_set_kerberos_state(auth_info->creds, krb5_state);
  9496. @@ -321,7 +321,7 @@ bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info)
  9497. krb5_state = cli_credentials_get_kerberos_state(auth_info->creds);
  9498. - if (krb5_state == CRED_MUST_USE_KERBEROS) {
  9499. + if (krb5_state == CRED_USE_KERBEROS_REQUIRED) {
  9500. return true;
  9501. }
  9502. @@ -336,17 +336,17 @@ void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_i
  9503. krb5_state = cli_credentials_get_kerberos_state(auth_info->creds);
  9504. switch (krb5_state) {
  9505. - case CRED_MUST_USE_KERBEROS:
  9506. + case CRED_USE_KERBEROS_REQUIRED:
  9507. if (b) {
  9508. - krb5_state = CRED_AUTO_USE_KERBEROS;
  9509. + krb5_state = CRED_USE_KERBEROS_DESIRED;
  9510. }
  9511. break;
  9512. - case CRED_AUTO_USE_KERBEROS:
  9513. + case CRED_USE_KERBEROS_DESIRED:
  9514. if (!b) {
  9515. - krb5_state = CRED_MUST_USE_KERBEROS;
  9516. + krb5_state = CRED_USE_KERBEROS_REQUIRED;
  9517. }
  9518. break;
  9519. - case CRED_DONT_USE_KERBEROS:
  9520. + case CRED_USE_KERBEROS_DISABLED:
  9521. /* nothing to do */
  9522. break;
  9523. }
  9524. @@ -360,7 +360,7 @@ bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *
  9525. krb5_state = cli_credentials_get_kerberos_state(auth_info->creds);
  9526. - if (krb5_state == CRED_AUTO_USE_KERBEROS) {
  9527. + if (krb5_state == CRED_USE_KERBEROS_DESIRED) {
  9528. return true;
  9529. }
  9530. diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c
  9531. index 87beeafe3ed..90ffa040ec0 100644
  9532. --- a/source3/libads/sasl.c
  9533. +++ b/source3/libads/sasl.c
  9534. @@ -158,7 +158,7 @@ static ADS_STATUS ads_sasl_spnego_gensec_bind(ADS_STRUCT *ads,
  9535. use_spnego_principal = false;
  9536. }
  9537. - if (krb5_state == CRED_DONT_USE_KERBEROS) {
  9538. + if (krb5_state == CRED_USE_KERBEROS_DISABLED) {
  9539. use_spnego_principal = false;
  9540. }
  9541. @@ -565,7 +565,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
  9542. {
  9543. status = ads_sasl_spnego_gensec_bind(ads, "GSS-SPNEGO",
  9544. - CRED_MUST_USE_KERBEROS,
  9545. + CRED_USE_KERBEROS_REQUIRED,
  9546. p.service, p.hostname,
  9547. blob);
  9548. if (ADS_ERR_OK(status)) {
  9549. @@ -581,7 +581,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
  9550. if (ADS_ERR_OK(status)) {
  9551. status = ads_sasl_spnego_gensec_bind(ads, "GSS-SPNEGO",
  9552. - CRED_MUST_USE_KERBEROS,
  9553. + CRED_USE_KERBEROS_REQUIRED,
  9554. p.service, p.hostname,
  9555. blob);
  9556. if (!ADS_ERR_OK(status)) {
  9557. @@ -616,7 +616,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
  9558. library for HMAC_MD4 encryption */
  9559. mech = "NTLMSSP";
  9560. status = ads_sasl_spnego_gensec_bind(ads, "GSS-SPNEGO",
  9561. - CRED_DONT_USE_KERBEROS,
  9562. + CRED_USE_KERBEROS_DISABLED,
  9563. p.service, p.hostname,
  9564. data_blob_null);
  9565. done:
  9566. diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
  9567. index f3bf27e6c00..bd3aeec9434 100644
  9568. --- a/source3/libnet/libnet_join.c
  9569. +++ b/source3/libnet/libnet_join.c
  9570. @@ -1707,7 +1707,7 @@ NTSTATUS libnet_join_ok(struct messaging_context *msg_ctx,
  9571. if (use_kerberos) {
  9572. cli_credentials_set_kerberos_state(cli_creds,
  9573. - CRED_MUST_USE_KERBEROS);
  9574. + CRED_USE_KERBEROS_REQUIRED);
  9575. }
  9576. status = cli_full_connection_creds(&cli, NULL,
  9577. diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
  9578. index abfd18bfaf1..f7b4741de89 100644
  9579. --- a/source3/libsmb/cliconnect.c
  9580. +++ b/source3/libsmb/cliconnect.c
  9581. @@ -124,13 +124,13 @@ struct cli_credentials *cli_session_creds_init(TALLOC_CTX *mem_ctx,
  9582. if (use_kerberos && fallback_after_kerberos) {
  9583. cli_credentials_set_kerberos_state(creds,
  9584. - CRED_AUTO_USE_KERBEROS);
  9585. + CRED_USE_KERBEROS_DESIRED);
  9586. } else if (use_kerberos) {
  9587. cli_credentials_set_kerberos_state(creds,
  9588. - CRED_MUST_USE_KERBEROS);
  9589. + CRED_USE_KERBEROS_REQUIRED);
  9590. } else {
  9591. cli_credentials_set_kerberos_state(creds,
  9592. - CRED_DONT_USE_KERBEROS);
  9593. + CRED_USE_KERBEROS_DISABLED);
  9594. }
  9595. if (use_ccache) {
  9596. @@ -255,7 +255,7 @@ NTSTATUS cli_session_creds_prepare_krb5(struct cli_state *cli,
  9597. krb5_state = cli_credentials_get_kerberos_state(creds);
  9598. - if (krb5_state != CRED_DONT_USE_KERBEROS) {
  9599. + if (krb5_state != CRED_USE_KERBEROS_DISABLED) {
  9600. try_kerberos = true;
  9601. }
  9602. @@ -275,7 +275,7 @@ NTSTATUS cli_session_creds_prepare_krb5(struct cli_state *cli,
  9603. try_kerberos = false;
  9604. }
  9605. - if (krb5_state == CRED_MUST_USE_KERBEROS && !try_kerberos) {
  9606. + if (krb5_state == CRED_USE_KERBEROS_REQUIRED && !try_kerberos) {
  9607. DEBUG(0, ("Kerberos auth with '%s' (%s\\%s) to access "
  9608. "'%s' not possible\n",
  9609. user_principal, user_domain, user_account,
  9610. @@ -286,7 +286,7 @@ NTSTATUS cli_session_creds_prepare_krb5(struct cli_state *cli,
  9611. if (pass == NULL || strlen(pass) == 0) {
  9612. need_kinit = false;
  9613. - } else if (krb5_state == CRED_MUST_USE_KERBEROS) {
  9614. + } else if (krb5_state == CRED_USE_KERBEROS_REQUIRED) {
  9615. need_kinit = try_kerberos;
  9616. } else {
  9617. need_kinit = try_kerberos;
  9618. @@ -321,14 +321,14 @@ NTSTATUS cli_session_creds_prepare_krb5(struct cli_state *cli,
  9619. if (ret != 0) {
  9620. int dbglvl = DBGLVL_NOTICE;
  9621. - if (krb5_state == CRED_MUST_USE_KERBEROS) {
  9622. + if (krb5_state == CRED_USE_KERBEROS_REQUIRED) {
  9623. dbglvl = DBGLVL_ERR;
  9624. }
  9625. DEBUG(dbglvl, ("Kinit for %s to access %s failed: %s\n",
  9626. user_principal, target_hostname,
  9627. error_message(ret)));
  9628. - if (krb5_state == CRED_MUST_USE_KERBEROS) {
  9629. + if (krb5_state == CRED_USE_KERBEROS_REQUIRED) {
  9630. TALLOC_FREE(frame);
  9631. return krb5_to_nt_status(ret);
  9632. }
  9633. diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c
  9634. index 8ed1bafcea3..b12c845d9d2 100644
  9635. --- a/source3/passdb/passdb.c
  9636. +++ b/source3/passdb/passdb.c
  9637. @@ -2630,7 +2630,7 @@ NTSTATUS pdb_get_trust_credentials(const char *netbios_domain,
  9638. /*
  9639. * It's not possible to use NTLMSSP with a domain trust account.
  9640. */
  9641. - cli_credentials_set_kerberos_state(creds, CRED_MUST_USE_KERBEROS);
  9642. + cli_credentials_set_kerberos_state(creds, CRED_USE_KERBEROS_REQUIRED);
  9643. } else {
  9644. /*
  9645. * We can't use kerberos against an NT4 domain.
  9646. @@ -2638,7 +2638,7 @@ NTSTATUS pdb_get_trust_credentials(const char *netbios_domain,
  9647. * We should have a mode that also disallows NTLMSSP here,
  9648. * as only NETLOGON SCHANNEL is possible.
  9649. */
  9650. - cli_credentials_set_kerberos_state(creds, CRED_DONT_USE_KERBEROS);
  9651. + cli_credentials_set_kerberos_state(creds, CRED_USE_KERBEROS_DISABLED);
  9652. }
  9653. ok = cli_credentials_set_username(creds, account_name, CRED_SPECIFIED);
  9654. @@ -2656,7 +2656,7 @@ NTSTATUS pdb_get_trust_credentials(const char *netbios_domain,
  9655. /*
  9656. * We currently can't do kerberos just with an NTHASH.
  9657. */
  9658. - cli_credentials_set_kerberos_state(creds, CRED_DONT_USE_KERBEROS);
  9659. + cli_credentials_set_kerberos_state(creds, CRED_USE_KERBEROS_DISABLED);
  9660. goto done;
  9661. }
  9662. diff --git a/source3/passdb/pdb_samba_dsdb.c b/source3/passdb/pdb_samba_dsdb.c
  9663. index 276bda88efc..93e8f5bebe6 100644
  9664. --- a/source3/passdb/pdb_samba_dsdb.c
  9665. +++ b/source3/passdb/pdb_samba_dsdb.c
  9666. @@ -2599,13 +2599,13 @@ static NTSTATUS pdb_samba_dsdb_get_trusteddom_creds(struct pdb_methods *m,
  9667. * Force kerberos if this is an active directory domain
  9668. */
  9669. cli_credentials_set_kerberos_state(creds,
  9670. - CRED_MUST_USE_KERBEROS);
  9671. + CRED_USE_KERBEROS_REQUIRED);
  9672. } else {
  9673. /*
  9674. * TODO: we should allow krb5 with the raw nt hash.
  9675. */
  9676. cli_credentials_set_kerberos_state(creds,
  9677. - CRED_DONT_USE_KERBEROS);
  9678. + CRED_USE_KERBEROS_DISABLED);
  9679. }
  9680. *_creds = talloc_move(mem_ctx, &creds);
  9681. diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
  9682. index 8227ef0b0bd..ba6c86cc227 100644
  9683. --- a/source3/rpc_client/cli_pipe.c
  9684. +++ b/source3/rpc_client/cli_pipe.c
  9685. @@ -2637,7 +2637,7 @@ NTSTATUS rpccli_ncalrpc_bind_data(TALLOC_CTX *mem_ctx,
  9686. NAME_NT_AUTHORITY, /* domain */
  9687. "SYSTEM",
  9688. NULL, /* password */
  9689. - CRED_DONT_USE_KERBEROS,
  9690. + CRED_USE_KERBEROS_DISABLED,
  9691. NULL, /* netlogon_creds_CredentialState */
  9692. presult);
  9693. }
  9694. diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
  9695. index 575a42ebf70..a38f69f5592 100644
  9696. --- a/source3/rpcclient/rpcclient.c
  9697. +++ b/source3/rpcclient/rpcclient.c
  9698. @@ -810,19 +810,19 @@ static NTSTATUS do_cmd(struct cli_state *cli,
  9699. case DCERPC_AUTH_TYPE_SPNEGO:
  9700. switch (pipe_default_auth_spnego_type) {
  9701. case PIPE_AUTH_TYPE_SPNEGO_NTLMSSP:
  9702. - krb5_state = CRED_DONT_USE_KERBEROS;
  9703. + krb5_state = CRED_USE_KERBEROS_DISABLED;
  9704. break;
  9705. case PIPE_AUTH_TYPE_SPNEGO_KRB5:
  9706. - krb5_state = CRED_MUST_USE_KERBEROS;
  9707. + krb5_state = CRED_USE_KERBEROS_REQUIRED;
  9708. break;
  9709. case PIPE_AUTH_TYPE_SPNEGO_NONE:
  9710. - krb5_state = CRED_AUTO_USE_KERBEROS;
  9711. + krb5_state = CRED_USE_KERBEROS_DESIRED;
  9712. break;
  9713. }
  9714. FALL_THROUGH;
  9715. case DCERPC_AUTH_TYPE_NTLMSSP:
  9716. case DCERPC_AUTH_TYPE_KRB5:
  9717. - if (krb5_state != CRED_AUTO_USE_KERBEROS) {
  9718. + if (krb5_state != CRED_USE_KERBEROS_DESIRED) {
  9719. cli_credentials_set_kerberos_state(creds,
  9720. krb5_state);
  9721. }
  9722. diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
  9723. index 7f5b9c3a440..1a0e8a5c9dd 100644
  9724. --- a/source3/utils/net_ads.c
  9725. +++ b/source3/utils/net_ads.c
  9726. @@ -2432,7 +2432,7 @@ static int net_ads_printer_publish(struct net_context *c, int argc, const char *
  9727. talloc_destroy(mem_ctx);
  9728. return -1;
  9729. }
  9730. - cli_credentials_set_kerberos_state(creds, CRED_MUST_USE_KERBEROS);
  9731. + cli_credentials_set_kerberos_state(creds, CRED_USE_KERBEROS_REQUIRED);
  9732. nt_status = cli_full_connection_creds(&cli, lp_netbios_name(), servername,
  9733. &server_ss, 0,
  9734. diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
  9735. index 5829d891075..6c5321db0fd 100644
  9736. --- a/source3/utils/net_util.c
  9737. +++ b/source3/utils/net_util.c
  9738. @@ -493,13 +493,13 @@ struct cli_credentials *net_context_creds(struct net_context *c,
  9739. if (c->opt_kerberos && c->opt_user_specified) {
  9740. cli_credentials_set_kerberos_state(creds,
  9741. - CRED_AUTO_USE_KERBEROS);
  9742. + CRED_USE_KERBEROS_DESIRED);
  9743. } else if (c->opt_kerberos) {
  9744. cli_credentials_set_kerberos_state(creds,
  9745. - CRED_MUST_USE_KERBEROS);
  9746. + CRED_USE_KERBEROS_REQUIRED);
  9747. } else {
  9748. cli_credentials_set_kerberos_state(creds,
  9749. - CRED_DONT_USE_KERBEROS);
  9750. + CRED_USE_KERBEROS_DISABLED);
  9751. }
  9752. if (c->opt_ccache) {
  9753. diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
  9754. index 7f8d2688978..bfaeff5188d 100644
  9755. --- a/source3/utils/ntlm_auth.c
  9756. +++ b/source3/utils/ntlm_auth.c
  9757. @@ -1364,9 +1364,9 @@ static NTSTATUS ntlm_auth_prepare_gensec_server(TALLOC_CTX *mem_ctx,
  9758. cli_credentials_set_conf(server_credentials, lp_ctx);
  9759. if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC || lp_security() == SEC_ADS || USE_KERBEROS_KEYTAB) {
  9760. - cli_credentials_set_kerberos_state(server_credentials, CRED_AUTO_USE_KERBEROS);
  9761. + cli_credentials_set_kerberos_state(server_credentials, CRED_USE_KERBEROS_DESIRED);
  9762. } else {
  9763. - cli_credentials_set_kerberos_state(server_credentials, CRED_DONT_USE_KERBEROS);
  9764. + cli_credentials_set_kerberos_state(server_credentials, CRED_USE_KERBEROS_DISABLED);
  9765. }
  9766. nt_status = gensec_server_start(tmp_ctx, gensec_settings,
  9767. diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
  9768. index 5fb22d7e9c8..466a0095ef2 100644
  9769. --- a/source3/winbindd/winbindd_cm.c
  9770. +++ b/source3/winbindd/winbindd_cm.c
  9771. @@ -706,7 +706,7 @@ static NTSTATUS cm_get_ipc_credentials(TALLOC_CTX *mem_ctx,
  9772. }
  9773. cli_credentials_set_conf(creds, lp_ctx);
  9774. - cli_credentials_set_kerberos_state(creds, CRED_DONT_USE_KERBEROS);
  9775. + cli_credentials_set_kerberos_state(creds, CRED_USE_KERBEROS_DISABLED);
  9776. ok = cli_credentials_set_domain(creds, netbios_domain, CRED_SPECIFIED);
  9777. if (!ok) {
  9778. diff --git a/source4/auth/gensec/gensec_gssapi.c b/source4/auth/gensec/gensec_gssapi.c
  9779. index d66abf32a7f..b668d4ed258 100644
  9780. --- a/source4/auth/gensec/gensec_gssapi.c
  9781. +++ b/source4/auth/gensec/gensec_gssapi.c
  9782. @@ -1556,7 +1556,7 @@ static NTSTATUS gensec_gssapi_session_info(struct gensec_security *gensec_securi
  9783. }
  9784. /* This credential handle isn't useful for password authentication, so ensure nobody tries to do that */
  9785. - cli_credentials_set_kerberos_state(session_info->credentials, CRED_MUST_USE_KERBEROS);
  9786. + cli_credentials_set_kerberos_state(session_info->credentials, CRED_USE_KERBEROS_REQUIRED);
  9787. /* It has been taken from this place... */
  9788. gensec_gssapi_state->delegated_cred_handle = GSS_C_NO_CREDENTIAL;
  9789. diff --git a/source4/auth/session.c b/source4/auth/session.c
  9790. index c5fc226a7d7..8e44dcd24f1 100644
  9791. --- a/source4/auth/session.c
  9792. +++ b/source4/auth/session.c
  9793. @@ -295,7 +295,7 @@ struct auth_session_info *auth_session_info_from_transport(TALLOC_CTX *mem_ctx,
  9794. /* This credential handle isn't useful for password
  9795. * authentication, so ensure nobody tries to do that */
  9796. cli_credentials_set_kerberos_state(creds,
  9797. - CRED_MUST_USE_KERBEROS);
  9798. + CRED_USE_KERBEROS_REQUIRED);
  9799. }
  9800. #endif
  9801. diff --git a/source4/lib/cmdline/popt_credentials.c b/source4/lib/cmdline/popt_credentials.c
  9802. index 5dd61f6339c..7d8963da99e 100644
  9803. --- a/source4/lib/cmdline/popt_credentials.c
  9804. +++ b/source4/lib/cmdline/popt_credentials.c
  9805. @@ -120,8 +120,8 @@ static void popt_common_credentials_callback(poptContext con,
  9806. cli_credentials_set_kerberos_state(
  9807. popt_get_cmdline_credentials(),
  9808. use_kerberos
  9809. - ? CRED_MUST_USE_KERBEROS
  9810. - : CRED_DONT_USE_KERBEROS);
  9811. + ? CRED_USE_KERBEROS_REQUIRED
  9812. + : CRED_USE_KERBEROS_DISABLED);
  9813. break;
  9814. }
  9815. diff --git a/source4/torture/ldap/session_expiry.c b/source4/torture/ldap/session_expiry.c
  9816. index 35dda439b17..e5e38450745 100644
  9817. --- a/source4/torture/ldap/session_expiry.c
  9818. +++ b/source4/torture/ldap/session_expiry.c
  9819. @@ -55,7 +55,7 @@ bool torture_ldap_session_expiry(struct torture_context *torture)
  9820. torture, url!=NULL, ret, fail, "talloc_asprintf failed");
  9821. cli_credentials_set_kerberos_state(
  9822. - credentials, CRED_MUST_USE_KERBEROS);
  9823. + credentials, CRED_USE_KERBEROS_REQUIRED);
  9824. ok = lpcfg_set_option(
  9825. torture->lp_ctx, "gensec_gssapi:requested_life_time=4");
  9826. diff --git a/source4/torture/raw/session.c b/source4/torture/raw/session.c
  9827. index 0c460ae3069..e246d25e9fb 100644
  9828. --- a/source4/torture/raw/session.c
  9829. +++ b/source4/torture/raw/session.c
  9830. @@ -245,12 +245,12 @@ static bool test_session_expire1(struct torture_context *tctx)
  9831. use_kerberos = cli_credentials_get_kerberos_state(
  9832. popt_get_cmdline_credentials());
  9833. - if (use_kerberos != CRED_MUST_USE_KERBEROS) {
  9834. + if (use_kerberos != CRED_USE_KERBEROS_REQUIRED) {
  9835. torture_warning(tctx, "smb2.session.expire1 requires -k yes!");
  9836. torture_skip(tctx, "smb2.session.expire1 requires -k yes!");
  9837. }
  9838. - torture_assert_int_equal(tctx, use_kerberos, CRED_MUST_USE_KERBEROS,
  9839. + torture_assert_int_equal(tctx, use_kerberos, CRED_USE_KERBEROS_REQUIRED,
  9840. "please use -k yes");
  9841. lpcfg_set_option(tctx->lp_ctx, "gensec_gssapi:requested_life_time=4");
  9842. diff --git a/source4/torture/rpc/schannel.c b/source4/torture/rpc/schannel.c
  9843. index fff0b1aacbd..a5755041040 100644
  9844. --- a/source4/torture/rpc/schannel.c
  9845. +++ b/source4/torture/rpc/schannel.c
  9846. @@ -965,8 +965,8 @@ bool torture_rpc_schannel_bench1(struct torture_context *torture)
  9847. torture_assert(torture, s->join_ctx2 != NULL,
  9848. "Failed to join domain with acct_flags=ACB_WSTRUST");
  9849. - cli_credentials_set_kerberos_state(s->wks_creds1, CRED_DONT_USE_KERBEROS);
  9850. - cli_credentials_set_kerberos_state(s->wks_creds2, CRED_DONT_USE_KERBEROS);
  9851. + cli_credentials_set_kerberos_state(s->wks_creds1, CRED_USE_KERBEROS_DISABLED);
  9852. + cli_credentials_set_kerberos_state(s->wks_creds2, CRED_USE_KERBEROS_DISABLED);
  9853. for (i=0; i < s->nprocs; i++) {
  9854. struct cli_credentials *wks = s->wks_creds1;
  9855. diff --git a/source4/torture/smb2/session.c b/source4/torture/smb2/session.c
  9856. index 07c6faebb15..701dfc10a07 100644
  9857. --- a/source4/torture/smb2/session.c
  9858. +++ b/source4/torture/smb2/session.c
  9859. @@ -956,7 +956,7 @@ bool test_session_reauth6(struct torture_context *tctx, struct smb2_tree *tree)
  9860. krb_state = cli_credentials_get_kerberos_state(
  9861. popt_get_cmdline_credentials());
  9862. - if (krb_state == CRED_MUST_USE_KERBEROS) {
  9863. + if (krb_state == CRED_USE_KERBEROS_REQUIRED) {
  9864. torture_skip(tctx,
  9865. "Can't test failing session setup with kerberos.");
  9866. }
  9867. @@ -1064,12 +1064,12 @@ static bool test_session_expire1i(struct torture_context *tctx,
  9868. size_t i;
  9869. use_kerberos = cli_credentials_get_kerberos_state(credentials);
  9870. - if (use_kerberos != CRED_MUST_USE_KERBEROS) {
  9871. + if (use_kerberos != CRED_USE_KERBEROS_REQUIRED) {
  9872. torture_warning(tctx, "smb2.session.expire1 requires -k yes!");
  9873. torture_skip(tctx, "smb2.session.expire1 requires -k yes!");
  9874. }
  9875. - torture_assert_int_equal(tctx, use_kerberos, CRED_MUST_USE_KERBEROS,
  9876. + torture_assert_int_equal(tctx, use_kerberos, CRED_USE_KERBEROS_REQUIRED,
  9877. "please use -k yes");
  9878. cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
  9879. @@ -1250,12 +1250,12 @@ static bool test_session_expire2i(struct torture_context *tctx,
  9880. struct smb2_notify ntf2;
  9881. use_kerberos = cli_credentials_get_kerberos_state(credentials);
  9882. - if (use_kerberos != CRED_MUST_USE_KERBEROS) {
  9883. + if (use_kerberos != CRED_USE_KERBEROS_REQUIRED) {
  9884. torture_warning(tctx, "smb2.session.expire2 requires -k yes!");
  9885. torture_skip(tctx, "smb2.session.expire2 requires -k yes!");
  9886. }
  9887. - torture_assert_int_equal(tctx, use_kerberos, CRED_MUST_USE_KERBEROS,
  9888. + torture_assert_int_equal(tctx, use_kerberos, CRED_USE_KERBEROS_REQUIRED,
  9889. "please use -k yes");
  9890. cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
  9891. @@ -1612,7 +1612,7 @@ static bool test_session_expire_disconnect(struct torture_context *tctx)
  9892. bool connected;
  9893. use_kerberos = cli_credentials_get_kerberos_state(credentials);
  9894. - if (use_kerberos != CRED_MUST_USE_KERBEROS) {
  9895. + if (use_kerberos != CRED_USE_KERBEROS_REQUIRED) {
  9896. torture_warning(tctx, "smb2.session.expire1 requires -k yes!");
  9897. torture_skip(tctx, "smb2.session.expire1 requires -k yes!");
  9898. }
  9899. --
  9900. 2.29.2
  9901. From dd116a6a1b334431981b786c103503d9e2998247 Mon Sep 17 00:00:00 2001
  9902. From: Andreas Schneider <asn@samba.org>
  9903. Date: Tue, 1 Sep 2020 12:32:28 +0200
  9904. Subject: [PATCH 087/104] auth:creds:tests: Migrate test to a cmocka unit test
  9905. Signed-off-by: Andreas Schneider <asn@samba.org>
  9906. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  9907. (cherry picked from commit 1a92994a9513f5e73d30604a1dc217ddeb1ac8d5)
  9908. ---
  9909. auth/credentials/tests/test_creds.c | 221 ++++++++++++++++++++++++++++
  9910. auth/credentials/wscript_build | 6 +
  9911. selftest/tests.py | 2 +
  9912. source4/torture/local/local.c | 1 -
  9913. source4/torture/local/wscript_build | 2 +-
  9914. 5 files changed, 230 insertions(+), 2 deletions(-)
  9915. create mode 100644 auth/credentials/tests/test_creds.c
  9916. diff --git a/auth/credentials/tests/test_creds.c b/auth/credentials/tests/test_creds.c
  9917. new file mode 100644
  9918. index 00000000000..d2d3d30d73d
  9919. --- /dev/null
  9920. +++ b/auth/credentials/tests/test_creds.c
  9921. @@ -0,0 +1,221 @@
  9922. +/*
  9923. + * Unix SMB/CIFS implementation.
  9924. + *
  9925. + * Copyright (C) 2018-2019 Andreas Schneider <asn@samba.org>
  9926. + *
  9927. + * This program is free software; you can redistribute it and/or modify
  9928. + * it under the terms of the GNU General Public License as published by
  9929. + * the Free Software Foundation; either version 3 of the License, or
  9930. + * (at your option) any later version.
  9931. + *
  9932. + * This program is distributed in the hope that it will be useful,
  9933. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9934. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9935. + * GNU General Public License for more details.
  9936. + *
  9937. + * You should have received a copy of the GNU General Public License
  9938. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9939. + */
  9940. +
  9941. +#include <stdarg.h>
  9942. +#include <stddef.h>
  9943. +#include <stdint.h>
  9944. +#include <setjmp.h>
  9945. +#include <cmocka.h>
  9946. +
  9947. +#include "lib/replace/replace.h"
  9948. +#include "auth/credentials/credentials.c"
  9949. +
  9950. +static int setup_talloc_context(void **state)
  9951. +{
  9952. + TALLOC_CTX *frame = talloc_stackframe();
  9953. +
  9954. + *state = frame;
  9955. + return 0;
  9956. +}
  9957. +
  9958. +static int teardown_talloc_context(void **state)
  9959. +{
  9960. + TALLOC_CTX *frame = *state;
  9961. + TALLOC_FREE(frame);
  9962. + return 0;
  9963. +}
  9964. +
  9965. +static void torture_creds_init(void **state)
  9966. +{
  9967. + TALLOC_CTX *mem_ctx = *state;
  9968. + struct cli_credentials *creds = NULL;
  9969. + const char *username = NULL;
  9970. + const char *domain = NULL;
  9971. + const char *password = NULL;
  9972. + bool ok;
  9973. +
  9974. + creds = cli_credentials_init(mem_ctx);
  9975. + assert_non_null(creds);
  9976. + assert_null(creds->username);
  9977. + assert_int_equal(creds->username_obtained, CRED_UNINITIALISED);
  9978. +
  9979. + domain = cli_credentials_get_domain(creds);
  9980. + assert_null(domain);
  9981. + ok = cli_credentials_set_domain(creds, "WURST", CRED_SPECIFIED);
  9982. + assert_true(ok);
  9983. + assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
  9984. + domain = cli_credentials_get_domain(creds);
  9985. + assert_string_equal(domain, "WURST");
  9986. +
  9987. + username = cli_credentials_get_username(creds);
  9988. + assert_null(username);
  9989. + ok = cli_credentials_set_username(creds, "brot", CRED_SPECIFIED);
  9990. + assert_true(ok);
  9991. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  9992. + username = cli_credentials_get_username(creds);
  9993. + assert_string_equal(username, "brot");
  9994. +
  9995. + password = cli_credentials_get_password(creds);
  9996. + assert_null(password);
  9997. + ok = cli_credentials_set_password(creds, "SECRET", CRED_SPECIFIED);
  9998. + assert_true(ok);
  9999. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10000. + password = cli_credentials_get_password(creds);
  10001. + assert_string_equal(password, "SECRET");
  10002. +}
  10003. +
  10004. +static void torture_creds_init_anonymous(void **state)
  10005. +{
  10006. + TALLOC_CTX *mem_ctx = *state;
  10007. + struct cli_credentials *creds = NULL;
  10008. +
  10009. + creds = cli_credentials_init_anon(mem_ctx);
  10010. + assert_non_null(creds);
  10011. +
  10012. + assert_string_equal(creds->domain, "");
  10013. + assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
  10014. +
  10015. + assert_string_equal(creds->username, "");
  10016. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  10017. +
  10018. + assert_null(creds->password);
  10019. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10020. +}
  10021. +
  10022. +static void torture_creds_guess(void **state)
  10023. +{
  10024. + TALLOC_CTX *mem_ctx = *state;
  10025. + struct cli_credentials *creds = NULL;
  10026. + const char *env_user = getenv("USER");
  10027. +
  10028. + creds = cli_credentials_init(mem_ctx);
  10029. + assert_non_null(creds);
  10030. +
  10031. + setenv("PASSWD", "SECRET", 1);
  10032. + cli_credentials_guess(creds, NULL);
  10033. +
  10034. + assert_string_equal(creds->username, env_user);
  10035. + assert_int_equal(creds->username_obtained, CRED_GUESS_ENV);
  10036. +
  10037. + assert_string_equal(creds->password, "SECRET");
  10038. + assert_int_equal(creds->password_obtained, CRED_GUESS_ENV);
  10039. + unsetenv("PASSWD");
  10040. +}
  10041. +
  10042. +static void torture_creds_anon_guess(void **state)
  10043. +{
  10044. + TALLOC_CTX *mem_ctx = *state;
  10045. + struct cli_credentials *creds = NULL;
  10046. +
  10047. + creds = cli_credentials_init_anon(mem_ctx);
  10048. + assert_non_null(creds);
  10049. +
  10050. + setenv("PASSWD", "SECRET", 1);
  10051. + cli_credentials_guess(creds, NULL);
  10052. +
  10053. + assert_string_equal(creds->username, "");
  10054. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  10055. +
  10056. + assert_null(creds->password);
  10057. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10058. + unsetenv("PASSWD");
  10059. +}
  10060. +
  10061. +static void torture_creds_parse_string(void **state)
  10062. +{
  10063. + TALLOC_CTX *mem_ctx = *state;
  10064. + struct cli_credentials *creds = NULL;
  10065. +
  10066. + creds = cli_credentials_init(mem_ctx);
  10067. + assert_non_null(creds);
  10068. +
  10069. + /* Anonymous */
  10070. + cli_credentials_parse_string(creds, "%", CRED_SPECIFIED);
  10071. +
  10072. + assert_string_equal(creds->domain, "");
  10073. + assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
  10074. +
  10075. + assert_string_equal(creds->username, "");
  10076. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  10077. +
  10078. + assert_null(creds->password);
  10079. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10080. +
  10081. + /* Username + password */
  10082. + cli_credentials_parse_string(creds, "wurst%BROT", CRED_SPECIFIED);
  10083. +
  10084. + assert_string_equal(creds->domain, "");
  10085. + assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
  10086. +
  10087. + assert_string_equal(creds->username, "wurst");
  10088. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  10089. +
  10090. + assert_string_equal(creds->password, "BROT");
  10091. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10092. +
  10093. + /* Domain + username + password */
  10094. + cli_credentials_parse_string(creds, "XXL\\wurst%BROT", CRED_SPECIFIED);
  10095. +
  10096. + assert_string_equal(creds->domain, "XXL");
  10097. + assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
  10098. +
  10099. + assert_string_equal(creds->username, "wurst");
  10100. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  10101. +
  10102. + assert_string_equal(creds->password, "BROT");
  10103. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10104. +
  10105. + /* Principal */
  10106. + cli_credentials_parse_string(creds, "wurst@brot.realm", CRED_SPECIFIED);
  10107. +
  10108. + assert_string_equal(creds->domain, "");
  10109. + assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
  10110. +
  10111. + assert_string_equal(creds->username, "wurst@brot.realm");
  10112. + assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
  10113. +
  10114. + assert_string_equal(creds->principal, "wurst@brot.realm");
  10115. + assert_int_equal(creds->principal_obtained, CRED_SPECIFIED);
  10116. +
  10117. + assert_string_equal(creds->password, "BROT");
  10118. + assert_int_equal(creds->password_obtained, CRED_SPECIFIED);
  10119. +}
  10120. +
  10121. +int main(int argc, char *argv[])
  10122. +{
  10123. + int rc;
  10124. + const struct CMUnitTest tests[] = {
  10125. + cmocka_unit_test(torture_creds_init),
  10126. + cmocka_unit_test(torture_creds_init_anonymous),
  10127. + cmocka_unit_test(torture_creds_guess),
  10128. + cmocka_unit_test(torture_creds_anon_guess),
  10129. + cmocka_unit_test(torture_creds_parse_string),
  10130. + };
  10131. +
  10132. + if (argc == 2) {
  10133. + cmocka_set_test_filter(argv[1]);
  10134. + }
  10135. + cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
  10136. +
  10137. + rc = cmocka_run_group_tests(tests,
  10138. + setup_talloc_context,
  10139. + teardown_talloc_context);
  10140. +
  10141. + return rc;
  10142. +}
  10143. diff --git a/auth/credentials/wscript_build b/auth/credentials/wscript_build
  10144. index ad16b7d8008..46111164b36 100644
  10145. --- a/auth/credentials/wscript_build
  10146. +++ b/auth/credentials/wscript_build
  10147. @@ -31,3 +31,9 @@ bld.SAMBA_PYTHON('pycredentials',
  10148. public_deps='samba-credentials cmdline-credentials %s %s CREDENTIALS_KRB5 CREDENTIALS_SECRETS' % (pytalloc_util, pyparam_util),
  10149. realname='samba/credentials.so'
  10150. )
  10151. +
  10152. +bld.SAMBA_BINARY('test_creds',
  10153. + source='tests/test_creds.c',
  10154. + deps='cmocka samba-credentials',
  10155. + local_include=False,
  10156. + for_selftest=True)
  10157. diff --git a/selftest/tests.py b/selftest/tests.py
  10158. index 86cab3f8046..4a968cdbe8a 100644
  10159. --- a/selftest/tests.py
  10160. +++ b/selftest/tests.py
  10161. @@ -418,3 +418,5 @@ plantestsuite("samba.unittests.test_oLschema2ldif", "none",
  10162. if with_elasticsearch_backend:
  10163. plantestsuite("samba.unittests.mdsparser_es", "none",
  10164. [os.path.join(bindir(), "default/source3/test_mdsparser_es")] + [configuration])
  10165. +plantestsuite("samba.unittests.credentials", "none",
  10166. + [os.path.join(bindir(), "default/auth/credentials/test_creds")])
  10167. diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
  10168. index a3186788524..d19b55e9502 100644
  10169. --- a/source4/torture/local/local.c
  10170. +++ b/source4/torture/local/local.c
  10171. @@ -70,7 +70,6 @@
  10172. torture_local_tevent_req,
  10173. torture_local_torture,
  10174. torture_local_dbspeed,
  10175. - torture_local_credentials,
  10176. torture_ldb,
  10177. torture_dsdb_dn,
  10178. torture_dsdb_syntax,
  10179. diff --git a/source4/torture/local/wscript_build b/source4/torture/local/wscript_build
  10180. index 38b6c8f4b6e..f0ab0357986 100644
  10181. --- a/source4/torture/local/wscript_build
  10182. +++ b/source4/torture/local/wscript_build
  10183. @@ -16,7 +16,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c
  10184. ../../libcli/security/tests/sddl.c ../../../lib/tdr/testsuite.c
  10185. ../../../lib/tevent/testsuite.c ../../param/tests/share.c
  10186. ../../../lib/tevent/test_req.c
  10187. - ../../param/tests/loadparm.c ../../../auth/credentials/tests/simple.c local.c
  10188. + ../../param/tests/loadparm.c local.c
  10189. dbspeed.c torture.c ../ldb/ldb.c ../../dsdb/common/tests/dsdb_dn.c
  10190. ../../dsdb/schema/tests/schema_syntax.c
  10191. ../../../lib/util/tests/anonymous_shared.c
  10192. --
  10193. 2.29.2
  10194. From 48c31546ad4c2a072497e3ce9eff37ef37bc81c8 Mon Sep 17 00:00:00 2001
  10195. From: Isaac Boukris <iboukris@gmail.com>
  10196. Date: Thu, 20 Aug 2020 12:09:05 +0200
  10197. Subject: [PATCH 088/104] Add smb2cli_session_get_encryption_cipher()
  10198. When 'session->smb2->should_encrypt' is true, the client MUST encrypt
  10199. all transport messages (see also MS-SMB2 3.2.4.1.8).
  10200. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10201. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10202. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10203. (cherry picked from commit f0f8de9d4a4e05445e427f00bb10eb34e1110a97)
  10204. ---
  10205. libcli/smb/smbXcli_base.c | 13 +++++++++++++
  10206. libcli/smb/smbXcli_base.h | 1 +
  10207. 2 files changed, 14 insertions(+)
  10208. diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c
  10209. index 7d2da4b9ebc..471319a32f1 100644
  10210. --- a/libcli/smb/smbXcli_base.c
  10211. +++ b/libcli/smb/smbXcli_base.c
  10212. @@ -6436,6 +6436,19 @@ NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
  10213. return NT_STATUS_OK;
  10214. }
  10215. +uint16_t smb2cli_session_get_encryption_cipher(struct smbXcli_session *session)
  10216. +{
  10217. + if (session->conn->protocol < PROTOCOL_SMB2_24) {
  10218. + return 0;
  10219. + }
  10220. +
  10221. + if (!session->smb2->should_encrypt) {
  10222. + return 0;
  10223. + }
  10224. +
  10225. + return session->conn->smb2.server.cipher;
  10226. +}
  10227. +
  10228. struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx)
  10229. {
  10230. struct smbXcli_tcon *tcon;
  10231. diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h
  10232. index 2afc7165cd9..db5f5d58799 100644
  10233. --- a/libcli/smb/smbXcli_base.h
  10234. +++ b/libcli/smb/smbXcli_base.h
  10235. @@ -518,6 +518,7 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
  10236. const DATA_BLOB channel_key,
  10237. const struct iovec *recv_iov);
  10238. NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session);
  10239. +uint16_t smb2cli_session_get_encryption_cipher(struct smbXcli_session *session);
  10240. struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx);
  10241. struct smbXcli_tcon *smbXcli_tcon_copy(TALLOC_CTX *mem_ctx,
  10242. --
  10243. 2.29.2
  10244. From 25a7d3534f7e3798cdf2432de62ed62f9e11547b Mon Sep 17 00:00:00 2001
  10245. From: Isaac Boukris <iboukris@gmail.com>
  10246. Date: Thu, 20 Aug 2020 12:18:21 +0200
  10247. Subject: [PATCH 089/104] Add dcerpc_transport_encrypted()
  10248. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10249. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10250. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10251. (cherry picked from commit 339bfcd67af2675d10287946d8f5dabba1022d57)
  10252. ---
  10253. source4/librpc/rpc/dcerpc.h | 2 ++
  10254. source4/librpc/rpc/dcerpc_smb.c | 11 +++++++++++
  10255. source4/librpc/rpc/dcerpc_util.c | 13 +++++++++++++
  10256. 3 files changed, 26 insertions(+)
  10257. diff --git a/source4/librpc/rpc/dcerpc.h b/source4/librpc/rpc/dcerpc.h
  10258. index 6b0b841d64d..57124f10778 100644
  10259. --- a/source4/librpc/rpc/dcerpc.h
  10260. +++ b/source4/librpc/rpc/dcerpc.h
  10261. @@ -87,6 +87,7 @@ struct dcecli_connection {
  10262. struct dcerpc_transport {
  10263. enum dcerpc_transport_t transport;
  10264. void *private_data;
  10265. + bool encrypted;
  10266. struct tstream_context *stream;
  10267. /** to serialize write events */
  10268. @@ -181,6 +182,7 @@ NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
  10269. const struct ndr_interface_table *table);
  10270. NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
  10271. DATA_BLOB *session_key);
  10272. +bool dcerpc_transport_encrypted(struct dcerpc_pipe *p);
  10273. struct composite_context;
  10274. NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c,
  10275. struct dcerpc_pipe **p2);
  10276. diff --git a/source4/librpc/rpc/dcerpc_smb.c b/source4/librpc/rpc/dcerpc_smb.c
  10277. index b20b154a1cb..101ed64f0cd 100644
  10278. --- a/source4/librpc/rpc/dcerpc_smb.c
  10279. +++ b/source4/librpc/rpc/dcerpc_smb.c
  10280. @@ -145,6 +145,7 @@ static void dcerpc_pipe_open_smb_done(struct tevent_req *subreq)
  10281. struct dcerpc_pipe_open_smb_state);
  10282. struct composite_context *ctx = state->ctx;
  10283. struct dcecli_connection *c = state->c;
  10284. + uint16_t enc_cipher;
  10285. ctx->status = tstream_smbXcli_np_open_recv(subreq,
  10286. state->smb,
  10287. @@ -173,6 +174,16 @@ static void dcerpc_pipe_open_smb_done(struct tevent_req *subreq)
  10288. /* Over-ride the default session key with the SMB session key */
  10289. c->security_state.session_key = smb_session_key;
  10290. + enc_cipher = smb2cli_session_get_encryption_cipher(state->smb->session);
  10291. + switch (enc_cipher) {
  10292. + case SMB2_ENCRYPTION_AES128_CCM:
  10293. + case SMB2_ENCRYPTION_AES128_GCM:
  10294. + c->transport.encrypted = true;
  10295. + break;
  10296. + default:
  10297. + c->transport.encrypted = false;
  10298. + }
  10299. +
  10300. c->transport.private_data = talloc_move(c, &state->smb);
  10301. composite_done(ctx);
  10302. diff --git a/source4/librpc/rpc/dcerpc_util.c b/source4/librpc/rpc/dcerpc_util.c
  10303. index bd79a072bc8..6ea27a8d9a3 100644
  10304. --- a/source4/librpc/rpc/dcerpc_util.c
  10305. +++ b/source4/librpc/rpc/dcerpc_util.c
  10306. @@ -743,6 +743,19 @@ _PUBLIC_ NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
  10307. return NT_STATUS_OK;
  10308. }
  10309. +_PUBLIC_ bool dcerpc_transport_encrypted(struct dcerpc_pipe *p)
  10310. +{
  10311. + if (p == NULL) {
  10312. + return false;
  10313. + }
  10314. +
  10315. + if (p->conn == NULL) {
  10316. + return false;
  10317. + }
  10318. +
  10319. + return p->conn->transport.encrypted;
  10320. +}
  10321. +
  10322. /*
  10323. create a secondary context from a primary connection
  10324. --
  10325. 2.29.2
  10326. From a0b8ea04d7030d2cb97d6ccea9d28072d6e3dbda Mon Sep 17 00:00:00 2001
  10327. From: Isaac Boukris <iboukris@gmail.com>
  10328. Date: Thu, 20 Aug 2020 12:35:01 +0200
  10329. Subject: [PATCH 090/104] Add py binding for dcerpc_transport_encrypted
  10330. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10331. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10332. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10333. (cherry picked from commit eba91f0dfa8e3267689b4076302e257f4cecd63b)
  10334. ---
  10335. source4/librpc/rpc/pyrpc.c | 14 ++++++++++++++
  10336. 1 file changed, 14 insertions(+)
  10337. diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c
  10338. index be914ed5f14..309a6d72e26 100644
  10339. --- a/source4/librpc/rpc/pyrpc.c
  10340. +++ b/source4/librpc/rpc/pyrpc.c
  10341. @@ -293,11 +293,25 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar
  10342. return ret;
  10343. }
  10344. +static PyObject *py_iface_transport_encrypted(PyObject *self)
  10345. +{
  10346. + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;
  10347. +
  10348. + if (dcerpc_transport_encrypted(iface->pipe)) {
  10349. + Py_RETURN_TRUE;
  10350. + }
  10351. +
  10352. + Py_RETURN_FALSE;
  10353. +}
  10354. +
  10355. static PyMethodDef dcerpc_interface_methods[] = {
  10356. { "request", PY_DISCARD_FUNC_SIG(PyCFunction, py_iface_request),
  10357. METH_VARARGS|METH_KEYWORDS,
  10358. "S.request(opnum, data, object=None) -> data\n"
  10359. "Make a raw request" },
  10360. + { "transport_encrypted", PY_DISCARD_FUNC_SIG(PyCFunction, py_iface_transport_encrypted),
  10361. + METH_NOARGS,
  10362. + "Check if the DCE transport is encrypted" },
  10363. { NULL, NULL, 0, NULL },
  10364. };
  10365. --
  10366. 2.29.2
  10367. From ff38da1d43f7ec3312a90fb8c53f977c9466e199 Mon Sep 17 00:00:00 2001
  10368. From: Isaac Boukris <iboukris@gmail.com>
  10369. Date: Thu, 20 Aug 2020 12:44:08 +0200
  10370. Subject: [PATCH 091/104] selftest: add a test for py dce transport_encrypted
  10371. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10372. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10373. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10374. (cherry picked from commit a77551bea969ce73a3dc27384d94b4126bef04f7)
  10375. ---
  10376. python/samba/tests/dcerpc/binding.py | 23 ++++++++++++++++++++++-
  10377. 1 file changed, 22 insertions(+), 1 deletion(-)
  10378. diff --git a/python/samba/tests/dcerpc/binding.py b/python/samba/tests/dcerpc/binding.py
  10379. index 8e0d6a5ef0a..24e4ac77d89 100644
  10380. --- a/python/samba/tests/dcerpc/binding.py
  10381. +++ b/python/samba/tests/dcerpc/binding.py
  10382. @@ -22,7 +22,7 @@ import samba.tests
  10383. from samba.tests import RpcInterfaceTestCase, TestCase
  10384. from samba.dcerpc import lsa
  10385. import samba.dcerpc.security as security
  10386. -from samba.credentials import Credentials, SMB_ENCRYPTION_REQUIRED
  10387. +from samba.credentials import Credentials, SMB_ENCRYPTION_REQUIRED, SMB_ENCRYPTION_OFF
  10388. from samba import NTSTATUSError
  10389. class RpcBindingTests(RpcInterfaceTestCase):
  10390. @@ -40,6 +40,26 @@ class RpcBindingTests(RpcInterfaceTestCase):
  10391. c.set_password(password)
  10392. return c
  10393. + def test_smb3_dcerpc_no_encryption(self):
  10394. + creds = self.get_user_creds()
  10395. + creds.set_smb_encryption(SMB_ENCRYPTION_OFF)
  10396. +
  10397. + lp = self.get_loadparm()
  10398. + lp.set('client ipc max protocol', 'SMB3')
  10399. + lp.set('client ipc min protocol', 'SMB3')
  10400. +
  10401. + binding_string = ("ncacn_np:%s" % (samba.tests.env_get_var_value('SERVER')))
  10402. + lsa_conn = lsa.lsarpc(binding_string, lp, creds)
  10403. + self.assertFalse(lsa_conn.transport_encrypted())
  10404. +
  10405. + objectAttr = lsa.ObjectAttribute()
  10406. + objectAttr.sec_qos = lsa.QosInfo()
  10407. +
  10408. + pol_handle = lsa_conn.OpenPolicy2('',
  10409. + objectAttr,
  10410. + security.SEC_FLAG_MAXIMUM_ALLOWED)
  10411. + self.assertIsNotNone(pol_handle)
  10412. +
  10413. def test_smb3_dcerpc_encryption(self):
  10414. creds = self.get_user_creds()
  10415. creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  10416. @@ -50,6 +70,7 @@ class RpcBindingTests(RpcInterfaceTestCase):
  10417. binding_string = ("ncacn_np:%s" % (samba.tests.env_get_var_value('SERVER')))
  10418. lsa_conn = lsa.lsarpc(binding_string, lp, creds)
  10419. + self.assertTrue(lsa_conn.transport_encrypted())
  10420. objectAttr = lsa.ObjectAttribute()
  10421. objectAttr.sec_qos = lsa.QosInfo()
  10422. --
  10423. 2.29.2
  10424. From 5ffb0a0d9093bba2c4630d89512f623a35122f8e Mon Sep 17 00:00:00 2001
  10425. From: Isaac Boukris <iboukris@gmail.com>
  10426. Date: Thu, 20 Aug 2020 12:47:12 +0200
  10427. Subject: [PATCH 092/104] Add CreateTrustedDomainRelax wrapper for fips mode
  10428. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10429. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10430. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10431. (cherry picked from commit c2644032b49b4160517a7c73634cebc54a76f827)
  10432. ---
  10433. python/samba/trust_utils.py | 62 +++++++++++++++++++++++++++++++++++++
  10434. 1 file changed, 62 insertions(+)
  10435. create mode 100644 python/samba/trust_utils.py
  10436. diff --git a/python/samba/trust_utils.py b/python/samba/trust_utils.py
  10437. new file mode 100644
  10438. index 00000000000..b4df0fa5bb8
  10439. --- /dev/null
  10440. +++ b/python/samba/trust_utils.py
  10441. @@ -0,0 +1,62 @@
  10442. +# trust utils
  10443. +#
  10444. +# Copyright Isaac Boukris 2020
  10445. +#
  10446. +# This program is free software; you can redistribute it and/or modify
  10447. +# it under the terms of the GNU General Public License as published by
  10448. +# the Free Software Foundation; either version 3 of the License, or
  10449. +# (at your option) any later version.
  10450. +#
  10451. +# This program is distributed in the hope that it will be useful,
  10452. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  10453. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10454. +# GNU General Public License for more details.
  10455. +#
  10456. +# You should have received a copy of the GNU General Public License
  10457. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  10458. +
  10459. +
  10460. +from samba.dcerpc import lsa, drsblobs
  10461. +from samba.ndr import ndr_pack
  10462. +from samba import arcfour_encrypt, string_to_byte_array
  10463. +import random
  10464. +from samba import crypto
  10465. +
  10466. +def CreateTrustedDomainRelax(lsaconn, policy, trust_info, mask, in_blob, out_blob):
  10467. +
  10468. + def generate_AuthInfoInternal(session_key, incoming=None, outgoing=None):
  10469. + confounder = [0] * 512
  10470. + for i in range(len(confounder)):
  10471. + confounder[i] = random.randint(0, 255)
  10472. +
  10473. + trustpass = drsblobs.trustDomainPasswords()
  10474. +
  10475. + trustpass.confounder = confounder
  10476. + trustpass.outgoing = outgoing
  10477. + trustpass.incoming = incoming
  10478. +
  10479. + trustpass_blob = ndr_pack(trustpass)
  10480. +
  10481. + encrypted_trustpass = arcfour_encrypt(session_key, trustpass_blob)
  10482. +
  10483. + auth_blob = lsa.DATA_BUF2()
  10484. + auth_blob.size = len(encrypted_trustpass)
  10485. + auth_blob.data = string_to_byte_array(encrypted_trustpass)
  10486. +
  10487. + auth_info = lsa.TrustDomainInfoAuthInfoInternal()
  10488. + auth_info.auth_blob = auth_blob
  10489. +
  10490. + return auth_info
  10491. +
  10492. + session_key = lsaconn.session_key
  10493. +
  10494. + try:
  10495. + if lsaconn.transport_encrypted():
  10496. + crypto.set_relax_mode()
  10497. + auth_info = generate_AuthInfoInternal(session_key,
  10498. + incoming=in_blob,
  10499. + outgoing=out_blob)
  10500. + finally:
  10501. + crypto.set_strict_mode()
  10502. +
  10503. + return lsaconn.CreateTrustedDomainEx2(policy, trust_info, auth_info, mask)
  10504. --
  10505. 2.29.2
  10506. From d980bb1444e318825457ead9bdbce1c9353ccc66 Mon Sep 17 00:00:00 2001
  10507. From: Isaac Boukris <iboukris@gmail.com>
  10508. Date: Thu, 20 Aug 2020 12:49:17 +0200
  10509. Subject: [PATCH 093/104] Use the new CreateTrustedDomainRelax()
  10510. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10511. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10512. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10513. (cherry picked from commit baf4e2930ee13b47c23c63c7e945fdc4444f0c69)
  10514. ---
  10515. python/samba/netcmd/domain.py | 57 ++++++++---------------------------
  10516. 1 file changed, 13 insertions(+), 44 deletions(-)
  10517. diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py
  10518. index 1d12c362911..93a3258d28d 100644
  10519. --- a/python/samba/netcmd/domain.py
  10520. +++ b/python/samba/netcmd/domain.py
  10521. @@ -102,6 +102,7 @@ from samba.netcmd.domain_backup import cmd_domain_backup
  10522. from samba.compat import binary_type
  10523. from samba.compat import get_string
  10524. +from samba.trust_utils import CreateTrustedDomainRelax
  10525. string_version_to_constant = {
  10526. "2008_R2": DS_DOMAIN_FUNCTION_2008_R2,
  10527. @@ -2528,54 +2529,20 @@ class cmd_domain_trust_create(DomainTrustCommand):
  10528. return blob
  10529. - def generate_AuthInfoInternal(session_key, incoming=None, outgoing=None):
  10530. - confounder = [0] * 512
  10531. - for i in range(len(confounder)):
  10532. - confounder[i] = random.randint(0, 255)
  10533. -
  10534. - trustpass = drsblobs.trustDomainPasswords()
  10535. -
  10536. - trustpass.confounder = confounder
  10537. - trustpass.outgoing = outgoing
  10538. - trustpass.incoming = incoming
  10539. -
  10540. - trustpass_blob = ndr_pack(trustpass)
  10541. -
  10542. - encrypted_trustpass = arcfour_encrypt(session_key, trustpass_blob)
  10543. -
  10544. - auth_blob = lsa.DATA_BUF2()
  10545. - auth_blob.size = len(encrypted_trustpass)
  10546. - auth_blob.data = string_to_byte_array(encrypted_trustpass)
  10547. -
  10548. - auth_info = lsa.TrustDomainInfoAuthInfoInternal()
  10549. - auth_info.auth_blob = auth_blob
  10550. -
  10551. - return auth_info
  10552. -
  10553. update_time = samba.current_unix_time()
  10554. incoming_blob = generate_AuthInOutBlob(incoming_secret, update_time)
  10555. outgoing_blob = generate_AuthInOutBlob(outgoing_secret, update_time)
  10556. - local_tdo_handle = None
  10557. - remote_tdo_handle = None
  10558. -
  10559. - local_auth_info = generate_AuthInfoInternal(local_lsa.session_key,
  10560. - incoming=incoming_blob,
  10561. - outgoing=outgoing_blob)
  10562. - if remote_trust_info:
  10563. - remote_auth_info = generate_AuthInfoInternal(remote_lsa.session_key,
  10564. - incoming=outgoing_blob,
  10565. - outgoing=incoming_blob)
  10566. -
  10567. try:
  10568. if remote_trust_info:
  10569. self.outf.write("Creating remote TDO.\n")
  10570. current_request = {"location": "remote", "name": "CreateTrustedDomainEx2"}
  10571. - remote_tdo_handle = \
  10572. - remote_lsa.CreateTrustedDomainEx2(remote_policy,
  10573. - remote_trust_info,
  10574. - remote_auth_info,
  10575. - lsa.LSA_TRUSTED_DOMAIN_ALL_ACCESS)
  10576. + remote_tdo_handle = CreateTrustedDomainRelax(remote_lsa,
  10577. + remote_policy,
  10578. + remote_trust_info,
  10579. + lsa.LSA_TRUSTED_DOMAIN_ALL_ACCESS,
  10580. + outgoing_blob,
  10581. + incoming_blob)
  10582. self.outf.write("Remote TDO created.\n")
  10583. if enc_types:
  10584. self.outf.write("Setting supported encryption types on remote TDO.\n")
  10585. @@ -2586,10 +2553,12 @@ class cmd_domain_trust_create(DomainTrustCommand):
  10586. self.outf.write("Creating local TDO.\n")
  10587. current_request = {"location": "local", "name": "CreateTrustedDomainEx2"}
  10588. - local_tdo_handle = local_lsa.CreateTrustedDomainEx2(local_policy,
  10589. - local_trust_info,
  10590. - local_auth_info,
  10591. - lsa.LSA_TRUSTED_DOMAIN_ALL_ACCESS)
  10592. + local_tdo_handle = CreateTrustedDomainRelax(local_lsa,
  10593. + local_policy,
  10594. + local_trust_info,
  10595. + lsa.LSA_TRUSTED_DOMAIN_ALL_ACCESS,
  10596. + incoming_blob,
  10597. + outgoing_blob)
  10598. self.outf.write("Local TDO created\n")
  10599. if enc_types:
  10600. self.outf.write("Setting supported encryption types on local TDO.\n")
  10601. --
  10602. 2.29.2
  10603. From e06d01fe3370501ab45d01c5511aa0b5de9d854e Mon Sep 17 00:00:00 2001
  10604. From: Isaac Boukris <iboukris@gmail.com>
  10605. Date: Tue, 1 Sep 2020 20:14:29 +0300
  10606. Subject: [PATCH 094/104] selftest: add a test for the CreateTrustedDomainRelax
  10607. wrapper
  10608. Originally copied from 'source4/scripting/devel/createtrust'
  10609. (had to drop the TRUST_AUTH_TYPE_VERSION part though, as it
  10610. fails against samba DC).
  10611. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10612. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10613. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10614. (cherry picked from commit cfaad16ff632df83a881fe5d8ec498bab102c9c9)
  10615. ---
  10616. python/samba/tests/dcerpc/createtrustrelax.py | 131 ++++++++++++++++++
  10617. selftest/knownfail.d/createtrustrelax_server | 1 +
  10618. source4/selftest/tests.py | 4 +
  10619. 3 files changed, 136 insertions(+)
  10620. create mode 100644 python/samba/tests/dcerpc/createtrustrelax.py
  10621. create mode 100644 selftest/knownfail.d/createtrustrelax_server
  10622. diff --git a/python/samba/tests/dcerpc/createtrustrelax.py b/python/samba/tests/dcerpc/createtrustrelax.py
  10623. new file mode 100644
  10624. index 00000000000..48beb0f9680
  10625. --- /dev/null
  10626. +++ b/python/samba/tests/dcerpc/createtrustrelax.py
  10627. @@ -0,0 +1,131 @@
  10628. +# Unix SMB/CIFS implementation.
  10629. +#
  10630. +# Copyright (C) Andrew Bartlett 2011
  10631. +# Copyright (C) Isaac Boukris 2020
  10632. +#
  10633. +# This program is free software; you can redistribute it and/or modify
  10634. +# it under the terms of the GNU General Public License as published by
  10635. +# the Free Software Foundation; either version 3 of the License, or
  10636. +# (at your option) any later version.
  10637. +#
  10638. +# This program is distributed in the hope that it will be useful,
  10639. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  10640. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10641. +# GNU General Public License for more details.
  10642. +#
  10643. +# You should have received a copy of the GNU General Public License
  10644. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  10645. +#
  10646. +
  10647. +"""Tests for the CreateTrustedDomainRelax wrapper"""
  10648. +
  10649. +import os
  10650. +import samba
  10651. +from samba.tests import TestCase
  10652. +from samba.dcerpc import lsa, security, drsblobs
  10653. +from samba.credentials import Credentials, SMB_ENCRYPTION_REQUIRED, SMB_ENCRYPTION_OFF
  10654. +from samba.trust_utils import CreateTrustedDomainRelax
  10655. +
  10656. +class CreateTrustedDomainRelaxTest(TestCase):
  10657. + def setUp(self):
  10658. + super(CreateTrustedDomainRelaxTest, self).setUp()
  10659. +
  10660. + def get_user_creds(self):
  10661. + c = Credentials()
  10662. + c.guess()
  10663. + domain = samba.tests.env_get_var_value('DOMAIN')
  10664. + username = samba.tests.env_get_var_value('USERNAME')
  10665. + password = samba.tests.env_get_var_value('PASSWORD')
  10666. + c.set_domain(domain)
  10667. + c.set_username(username)
  10668. + c.set_password(password)
  10669. + return c
  10670. +
  10671. + def _create_trust_relax(self, smbencrypt=True):
  10672. + creds = self.get_user_creds()
  10673. +
  10674. + if smbencrypt:
  10675. + creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
  10676. + else:
  10677. + creds.set_smb_encryption(SMB_ENCRYPTION_OFF)
  10678. +
  10679. + lp = self.get_loadparm()
  10680. +
  10681. + binding_string = ("ncacn_np:%s" % (samba.tests.env_get_var_value('SERVER')))
  10682. + lsa_conn = lsa.lsarpc(binding_string, lp, creds)
  10683. +
  10684. + if smbencrypt:
  10685. + self.assertTrue(lsa_conn.transport_encrypted())
  10686. + else:
  10687. + self.assertFalse(lsa_conn.transport_encrypted())
  10688. +
  10689. + objectAttr = lsa.ObjectAttribute()
  10690. + objectAttr.sec_qos = lsa.QosInfo()
  10691. +
  10692. + pol_handle = lsa_conn.OpenPolicy2('',
  10693. + objectAttr,
  10694. + security.SEC_FLAG_MAXIMUM_ALLOWED)
  10695. + self.assertIsNotNone(pol_handle)
  10696. +
  10697. + name = lsa.String()
  10698. + name.string = "tests.samba.example.com"
  10699. + try:
  10700. + info = lsa_conn.QueryTrustedDomainInfoByName(pol_handle, name,
  10701. + lsa.LSA_TRUSTED_DOMAIN_INFO_FULL_INFO)
  10702. +
  10703. + lsa_conn.DeleteTrustedDomain(pol_handle, info.info_ex.sid)
  10704. + except RuntimeError:
  10705. + pass
  10706. +
  10707. + info = lsa.TrustDomainInfoInfoEx()
  10708. + info.domain_name.string = name.string
  10709. + info.netbios_name.string = "createtrustrelax"
  10710. + info.sid = security.dom_sid("S-1-5-21-538490383-3740119673-95748416")
  10711. + info.trust_direction = lsa.LSA_TRUST_DIRECTION_INBOUND | lsa.LSA_TRUST_DIRECTION_OUTBOUND
  10712. + info.trust_type = lsa.LSA_TRUST_TYPE_UPLEVEL
  10713. + info.trust_attributes = lsa.LSA_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
  10714. +
  10715. + password_blob = samba.string_to_byte_array("password".encode('utf-16-le'))
  10716. +
  10717. + clear_value = drsblobs.AuthInfoClear()
  10718. + clear_value.size = len(password_blob)
  10719. + clear_value.password = password_blob
  10720. +
  10721. + clear_authentication_information = drsblobs.AuthenticationInformation()
  10722. + clear_authentication_information.LastUpdateTime = 0
  10723. + clear_authentication_information.AuthType = lsa.TRUST_AUTH_TYPE_CLEAR
  10724. + clear_authentication_information.AuthInfo = clear_value
  10725. +
  10726. + authentication_information_array = drsblobs.AuthenticationInformationArray()
  10727. + authentication_information_array.count = 1
  10728. + authentication_information_array.array = [clear_authentication_information]
  10729. +
  10730. + outgoing = drsblobs.trustAuthInOutBlob()
  10731. + outgoing.count = 1
  10732. + outgoing.current = authentication_information_array
  10733. +
  10734. + trustdom_handle = None
  10735. + try:
  10736. + trustdom_handle = CreateTrustedDomainRelax(lsa_conn,
  10737. + pol_handle,
  10738. + info,
  10739. + security.SEC_STD_DELETE,
  10740. + outgoing,
  10741. + outgoing)
  10742. + except samba.NTSTATUSError as nt:
  10743. + raise AssertionError(nt)
  10744. + except OSError as e:
  10745. + if smbencrypt:
  10746. + raise AssertionError(e)
  10747. +
  10748. + if smbencrypt:
  10749. + self.assertIsNotNone(trustdom_handle)
  10750. + lsa_conn.DeleteTrustedDomain(pol_handle, info.sid)
  10751. + else:
  10752. + self.assertIsNone(trustdom_handle)
  10753. +
  10754. + def test_create_trust_relax_encrypt(self):
  10755. + self._create_trust_relax(True)
  10756. +
  10757. + def test_create_trust_relax_no_enc(self):
  10758. + self._create_trust_relax(False)
  10759. diff --git a/selftest/knownfail.d/createtrustrelax_server b/selftest/knownfail.d/createtrustrelax_server
  10760. new file mode 100644
  10761. index 00000000000..80effda8343
  10762. --- /dev/null
  10763. +++ b/selftest/knownfail.d/createtrustrelax_server
  10764. @@ -0,0 +1 @@
  10765. +^samba.tests.dcerpc.createtrustrelax.samba.tests.dcerpc.createtrustrelax.CreateTrustedDomainRelaxTest.test_create_trust_relax_encrypt\(ad_dc_fips\)
  10766. diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
  10767. index 3a903a7eee0..96f51b68cfc 100755
  10768. --- a/source4/selftest/tests.py
  10769. +++ b/source4/selftest/tests.py
  10770. @@ -704,6 +704,10 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex
  10771. name = module
  10772. plantestsuite_loadlist(name, env, args)
  10773. +if have_gnutls_crypto_policies:
  10774. + planoldpythontestsuite("ad_dc", "samba.tests.dcerpc.createtrustrelax", environ={'GNUTLS_FORCE_FIPS_MODE':'1'})
  10775. + planoldpythontestsuite("ad_dc_fips", "samba.tests.dcerpc.createtrustrelax", environ={'GNUTLS_FORCE_FIPS_MODE':'1'})
  10776. +
  10777. # Run complex search expressions test once for each database backend.
  10778. # Right now ad_dc has mdb and ad_dc_ntvfs has tdb
  10779. mdb_testenv = "ad_dc"
  10780. --
  10781. 2.29.2
  10782. From 93b792d5d0dcf96833e32958aeb3877f74125f07 Mon Sep 17 00:00:00 2001
  10783. From: Isaac Boukris <iboukris@gmail.com>
  10784. Date: Thu, 5 Nov 2020 15:38:19 +0200
  10785. Subject: [PATCH 095/104] Remove source4/scripting/devel/createtrust script
  10786. We now have the 'samba-tool domain trust' command.
  10787. Signed-off-by: Isaac Boukris <iboukris@samba.org>
  10788. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10789. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10790. Autobuild-User(master): Isaac Boukris <iboukris@samba.org>
  10791. Autobuild-Date(master): Fri Nov 6 11:25:02 UTC 2020 on sn-devel-184
  10792. (cherry picked from commit 604153525afc892f57a1df710c41ffca275b0dd3)
  10793. ---
  10794. source4/scripting/devel/createtrust | 125 ----------------------------
  10795. 1 file changed, 125 deletions(-)
  10796. delete mode 100755 source4/scripting/devel/createtrust
  10797. diff --git a/source4/scripting/devel/createtrust b/source4/scripting/devel/createtrust
  10798. deleted file mode 100755
  10799. index 26b0d0dcb68..00000000000
  10800. --- a/source4/scripting/devel/createtrust
  10801. +++ /dev/null
  10802. @@ -1,125 +0,0 @@
  10803. -#!/usr/bin/env python3
  10804. -
  10805. -# create a domain trust
  10806. -
  10807. -import sys
  10808. -from optparse import OptionParser
  10809. -
  10810. -sys.path.insert(0, "bin/python")
  10811. -
  10812. -import samba
  10813. -import samba.getopt as options
  10814. -from samba.dcerpc import lsa, security, drsblobs
  10815. -from samba.ndr import ndr_pack
  10816. -from samba import arcfour_encrypt, string_to_byte_array
  10817. -import random
  10818. -
  10819. -########### main code ###########
  10820. -if __name__ == "__main__":
  10821. - parser = OptionParser("createtrust [options] server")
  10822. - sambaopts = options.SambaOptions(parser)
  10823. - credopts = options.CredentialsOptionsDouble(parser)
  10824. - parser.add_option_group(credopts)
  10825. -
  10826. - (opts, args) = parser.parse_args()
  10827. -
  10828. - lp = sambaopts.get_loadparm()
  10829. - creds = credopts.get_credentials(lp)
  10830. -
  10831. - if len(args) != 1:
  10832. - parser.error("You must supply a server")
  10833. -
  10834. - if not creds.authentication_requested():
  10835. - parser.error("You must supply credentials")
  10836. -
  10837. - server = args[0]
  10838. -
  10839. - binding_str = "ncacn_np:%s[print]" % server
  10840. -
  10841. - lsaconn = lsa.lsarpc(binding_str, lp, creds)
  10842. -
  10843. - objectAttr = lsa.ObjectAttribute()
  10844. - objectAttr.sec_qos = lsa.QosInfo()
  10845. -
  10846. - pol_handle = lsaconn.OpenPolicy2(''.decode('utf-8'),
  10847. - objectAttr, security.SEC_FLAG_MAXIMUM_ALLOWED)
  10848. -
  10849. - name = lsa.String()
  10850. - name.string = "sub2.win2k3.obed.home.abartlet.net"
  10851. - try:
  10852. - info = lsaconn.QueryTrustedDomainInfoByName(pol_handle, name, lsa.LSA_TRUSTED_DOMAIN_INFO_FULL_INFO)
  10853. -
  10854. - lsaconn.DeleteTrustedDomain(pol_handle, info.info_ex.sid)
  10855. - except RuntimeError:
  10856. - pass
  10857. -
  10858. - info = lsa.TrustDomainInfoInfoEx()
  10859. - info.domain_name.string = "sub2.win2k3.obed.home.abartlet.net"
  10860. - info.netbios_name.string = "sub2"
  10861. - info.sid = security.dom_sid("S-1-5-21-538090388-3760119675-95745416")
  10862. - info.trust_direction = lsa.LSA_TRUST_DIRECTION_INBOUND | lsa.LSA_TRUST_DIRECTION_OUTBOUND
  10863. - info.trust_type = lsa.LSA_TRUST_TYPE_UPLEVEL
  10864. - info.trust_attributes = lsa.LSA_TRUST_ATTRIBUTE_WITHIN_FOREST
  10865. -
  10866. - password_blob = string_to_byte_array("password".encode('utf-16-le'))
  10867. -
  10868. - clear_value = drsblobs.AuthInfoClear()
  10869. - clear_value.size = len(password_blob)
  10870. - clear_value.password = password_blob
  10871. -
  10872. - clear_authentication_information = drsblobs.AuthenticationInformation()
  10873. - clear_authentication_information.LastUpdateTime = 0
  10874. - clear_authentication_information.AuthType = lsa.TRUST_AUTH_TYPE_CLEAR
  10875. - clear_authentication_information.AuthInfo = clear_value
  10876. -
  10877. - version_value = drsblobs.AuthInfoVersion()
  10878. - version_value.version = 1
  10879. -
  10880. - version = drsblobs.AuthenticationInformation()
  10881. - version.LastUpdateTime = 0
  10882. - version.AuthType = lsa.TRUST_AUTH_TYPE_VERSION
  10883. - version.AuthInfo = version_value
  10884. -
  10885. - authentication_information_array = drsblobs.AuthenticationInformationArray()
  10886. - authentication_information_array.count = 2
  10887. - authentication_information_array.array = [clear_authentication_information, version]
  10888. -
  10889. - outgoing = drsblobs.trustAuthInOutBlob()
  10890. - outgoing.count = 1
  10891. - outgoing.current = authentication_information_array
  10892. -
  10893. - trustpass = drsblobs.trustDomainPasswords()
  10894. - confounder = [3] * 512
  10895. -
  10896. - for i in range(512):
  10897. - confounder[i] = random.randint(0, 255)
  10898. -
  10899. - trustpass.confounder = confounder
  10900. -
  10901. -# print "confounder: ", trustpass.confounder
  10902. -
  10903. - trustpass.outgoing = outgoing
  10904. - trustpass.incoming = outgoing
  10905. -
  10906. - trustpass_blob = ndr_pack(trustpass)
  10907. -
  10908. -# print "trustpass_blob: ", list(trustpass_blob)
  10909. -
  10910. - encrypted_trustpass = arcfour_encrypt(lsaconn.session_key, trustpass_blob)
  10911. -
  10912. -# print "encrypted_trustpass: ", list(encrypted_trustpass)
  10913. -
  10914. - auth_blob = lsa.DATA_BUF2()
  10915. - auth_blob.size = len(encrypted_trustpass)
  10916. - auth_blob.data = string_to_byte_array(encrypted_trustpass)
  10917. -
  10918. - auth_info = lsa.TrustDomainInfoAuthInfoInternal()
  10919. - auth_info.auth_blob = auth_blob
  10920. -
  10921. -
  10922. -# print "auth_info.auth_blob.data: ", auth_info.auth_blob.data
  10923. -
  10924. - trustdom_handle = lsaconn.CreateTrustedDomainEx2(pol_handle,
  10925. - info,
  10926. - auth_info,
  10927. - security.SEC_STD_DELETE)
  10928. --
  10929. 2.29.2
  10930. From 4577786be36993e958b745e4953f582e3de301a1 Mon Sep 17 00:00:00 2001
  10931. From: Andreas Schneider <asn@samba.org>
  10932. Date: Fri, 6 Nov 2020 14:30:26 +0100
  10933. Subject: [PATCH 096/104] s3:rpc_server: Use gnutls_cipher_decrypt() in
  10934. get_trustdom_auth_blob()
  10935. It doesn't matter for RC4, but just to be correct.
  10936. Signed-off-by: Andreas Schneider <asn@samba.org>
  10937. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10938. (cherry picked from commit 6c11e5f42ba3248c97d85c989d422b256d2465a9)
  10939. ---
  10940. source3/rpc_server/lsa/srv_lsa_nt.c | 2 +-
  10941. 1 file changed, 1 insertion(+), 1 deletion(-)
  10942. diff --git a/source3/rpc_server/lsa/srv_lsa_nt.c b/source3/rpc_server/lsa/srv_lsa_nt.c
  10943. index 198387424e6..e749caf2551 100644
  10944. --- a/source3/rpc_server/lsa/srv_lsa_nt.c
  10945. +++ b/source3/rpc_server/lsa/srv_lsa_nt.c
  10946. @@ -1726,7 +1726,7 @@ static NTSTATUS get_trustdom_auth_blob(struct pipes_struct *p,
  10947. goto out;
  10948. }
  10949. - rc = gnutls_cipher_encrypt(cipher_hnd,
  10950. + rc = gnutls_cipher_decrypt(cipher_hnd,
  10951. auth_blob->data,
  10952. auth_blob->length);
  10953. gnutls_cipher_deinit(cipher_hnd);
  10954. --
  10955. 2.29.2
  10956. From ad9c90d18c2efdee16535ade97d4b151e4a64c5e Mon Sep 17 00:00:00 2001
  10957. From: Andreas Schneider <asn@samba.org>
  10958. Date: Fri, 6 Nov 2020 14:33:38 +0100
  10959. Subject: [PATCH 097/104] s4:rpc_server: Use gnutls_cipher_decrypt() in
  10960. get_trustdom_auth_blob()
  10961. It doesn't matter for RC4, but just to be correct.
  10962. Signed-off-by: Andreas Schneider <asn@samba.org>
  10963. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10964. (cherry picked from commit c93ccebdfedd60c1d19f1b1436ac30062259952a)
  10965. ---
  10966. source4/rpc_server/lsa/dcesrv_lsa.c | 2 +-
  10967. 1 file changed, 1 insertion(+), 1 deletion(-)
  10968. diff --git a/source4/rpc_server/lsa/dcesrv_lsa.c b/source4/rpc_server/lsa/dcesrv_lsa.c
  10969. index 8333cb149b6..4bb8aaa9592 100644
  10970. --- a/source4/rpc_server/lsa/dcesrv_lsa.c
  10971. +++ b/source4/rpc_server/lsa/dcesrv_lsa.c
  10972. @@ -889,7 +889,7 @@ static NTSTATUS get_trustdom_auth_blob(struct dcesrv_call_state *dce_call,
  10973. goto out;
  10974. }
  10975. - rc = gnutls_cipher_encrypt(cipher_hnd,
  10976. + rc = gnutls_cipher_decrypt(cipher_hnd,
  10977. auth_blob->data,
  10978. auth_blob->length);
  10979. gnutls_cipher_deinit(cipher_hnd);
  10980. --
  10981. 2.29.2
  10982. From 6c73bf8553c48e28abd09ff225cbfb8278528d0d Mon Sep 17 00:00:00 2001
  10983. From: Andreas Schneider <asn@samba.org>
  10984. Date: Thu, 20 Aug 2020 13:40:21 +0200
  10985. Subject: [PATCH 098/104] s3:rpc_server: Allow to use RC4 for creating trusts
  10986. Signed-off-by: Andreas Schneider <asn@samba.org>
  10987. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  10988. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  10989. (cherry picked from commit 4425f2c113a4dc33a8dc609d84a92018d61b4d2e)
  10990. ---
  10991. source3/rpc_server/lsa/srv_lsa_nt.c | 13 +++++++++++++
  10992. 1 file changed, 13 insertions(+)
  10993. diff --git a/source3/rpc_server/lsa/srv_lsa_nt.c b/source3/rpc_server/lsa/srv_lsa_nt.c
  10994. index e749caf2551..d6d606ddeca 100644
  10995. --- a/source3/rpc_server/lsa/srv_lsa_nt.c
  10996. +++ b/source3/rpc_server/lsa/srv_lsa_nt.c
  10997. @@ -51,6 +51,8 @@
  10998. #include "../libcli/lsarpc/util_lsarpc.h"
  10999. #include "lsa.h"
  11000. #include "librpc/rpc/dcesrv_core.h"
  11001. +#include "librpc/rpc/dcerpc_helper.h"
  11002. +#include "lib/param/loadparm.h"
  11003. #include "lib/crypto/gnutls_helpers.h"
  11004. #include <gnutls/gnutls.h>
  11005. @@ -1706,6 +1708,14 @@ static NTSTATUS get_trustdom_auth_blob(struct pipes_struct *p,
  11006. gnutls_datum_t my_session_key;
  11007. NTSTATUS status;
  11008. int rc;
  11009. + bool encrypted;
  11010. +
  11011. + encrypted =
  11012. + dcerpc_is_transport_encrypted(p->session_info);
  11013. + if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  11014. + !encrypted) {
  11015. + return NT_STATUS_ACCESS_DENIED;
  11016. + }
  11017. status = session_extract_session_key(p->session_info, &lsession_key, KEY_USE_16BYTES);
  11018. if (!NT_STATUS_IS_OK(status)) {
  11019. @@ -1717,11 +1727,13 @@ static NTSTATUS get_trustdom_auth_blob(struct pipes_struct *p,
  11020. .size = lsession_key.length,
  11021. };
  11022. + GNUTLS_FIPS140_SET_LAX_MODE();
  11023. rc = gnutls_cipher_init(&cipher_hnd,
  11024. GNUTLS_CIPHER_ARCFOUR_128,
  11025. &my_session_key,
  11026. NULL);
  11027. if (rc < 0) {
  11028. + GNUTLS_FIPS140_SET_STRICT_MODE();
  11029. status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  11030. goto out;
  11031. }
  11032. @@ -1730,6 +1742,7 @@ static NTSTATUS get_trustdom_auth_blob(struct pipes_struct *p,
  11033. auth_blob->data,
  11034. auth_blob->length);
  11035. gnutls_cipher_deinit(cipher_hnd);
  11036. + GNUTLS_FIPS140_SET_STRICT_MODE();
  11037. if (rc < 0) {
  11038. status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  11039. goto out;
  11040. --
  11041. 2.29.2
  11042. From 20f0e078f2dd5681513253788216313851df428d Mon Sep 17 00:00:00 2001
  11043. From: Andreas Schneider <asn@samba.org>
  11044. Date: Thu, 20 Aug 2020 13:51:39 +0200
  11045. Subject: [PATCH 099/104] s4:rpc_server: Allow to use RC4 for creating trusts
  11046. Signed-off-by: Andreas Schneider <asn@samba.org>
  11047. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  11048. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  11049. (cherry picked from commit c75dd1ea178325b8f65343cb5c35bb93f43a49a3)
  11050. ---
  11051. source4/rpc_server/lsa/dcesrv_lsa.c | 18 ++++++++++++++++++
  11052. 1 file changed, 18 insertions(+)
  11053. diff --git a/source4/rpc_server/lsa/dcesrv_lsa.c b/source4/rpc_server/lsa/dcesrv_lsa.c
  11054. index 4bb8aaa9592..5b3ef71d458 100644
  11055. --- a/source4/rpc_server/lsa/dcesrv_lsa.c
  11056. +++ b/source4/rpc_server/lsa/dcesrv_lsa.c
  11057. @@ -33,6 +33,8 @@
  11058. #include "libcli/lsarpc/util_lsarpc.h"
  11059. #include "lib/messaging/irpc.h"
  11060. #include "libds/common/roles.h"
  11061. +#include "lib/param/loadparm.h"
  11062. +#include "librpc/rpc/dcerpc_helper.h"
  11063. #include "lib/crypto/gnutls_helpers.h"
  11064. #include <gnutls/gnutls.h>
  11065. @@ -869,6 +871,19 @@ static NTSTATUS get_trustdom_auth_blob(struct dcesrv_call_state *dce_call,
  11066. gnutls_cipher_hd_t cipher_hnd = NULL;
  11067. gnutls_datum_t _session_key;
  11068. int rc;
  11069. + struct auth_session_info *session_info =
  11070. + dcesrv_call_session_info(dce_call);
  11071. + struct loadparm_context *lp_ctx = dce_call->conn->dce_ctx->lp_ctx;
  11072. + bool encrypted;
  11073. +
  11074. + encrypted =
  11075. + dcerpc_is_transport_encrypted(session_info);
  11076. + if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED &&
  11077. + !encrypted) {
  11078. + DBG_ERR("Transport isn't encrypted and weak crypto disallowed!\n");
  11079. + return NT_STATUS_ACCESS_DENIED;
  11080. + }
  11081. +
  11082. nt_status = dcesrv_transport_session_key(dce_call, &session_key);
  11083. if (!NT_STATUS_IS_OK(nt_status)) {
  11084. @@ -880,11 +895,13 @@ static NTSTATUS get_trustdom_auth_blob(struct dcesrv_call_state *dce_call,
  11085. .size = session_key.length,
  11086. };
  11087. + GNUTLS_FIPS140_SET_LAX_MODE();
  11088. rc = gnutls_cipher_init(&cipher_hnd,
  11089. GNUTLS_CIPHER_ARCFOUR_128,
  11090. &_session_key,
  11091. NULL);
  11092. if (rc < 0) {
  11093. + GNUTLS_FIPS140_SET_STRICT_MODE();
  11094. nt_status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  11095. goto out;
  11096. }
  11097. @@ -893,6 +910,7 @@ static NTSTATUS get_trustdom_auth_blob(struct dcesrv_call_state *dce_call,
  11098. auth_blob->data,
  11099. auth_blob->length);
  11100. gnutls_cipher_deinit(cipher_hnd);
  11101. + GNUTLS_FIPS140_SET_STRICT_MODE();
  11102. if (rc < 0) {
  11103. nt_status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
  11104. goto out;
  11105. --
  11106. 2.29.2
  11107. From 8c7a60700f7c7925749ccfd0f3ccb17ca47df7da Mon Sep 17 00:00:00 2001
  11108. From: Andreas Schneider <asn@samba.org>
  11109. Date: Fri, 6 Nov 2020 10:13:48 +0100
  11110. Subject: [PATCH 100/104] sefltest: Enable the dcerpc.createtrustrelax test
  11111. against ad_dc_fips
  11112. Signed-off-by: Andreas Schneider <asn@samba.org>
  11113. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  11114. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  11115. Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
  11116. Autobuild-Date(master): Mon Nov 9 10:22:51 UTC 2020 on sn-devel-184
  11117. (cherry picked from commit b89134013041e772418c2c8bcfffe8a9ade6db91)
  11118. ---
  11119. selftest/knownfail.d/createtrustrelax_server | 1 -
  11120. 1 file changed, 1 deletion(-)
  11121. delete mode 100644 selftest/knownfail.d/createtrustrelax_server
  11122. diff --git a/selftest/knownfail.d/createtrustrelax_server b/selftest/knownfail.d/createtrustrelax_server
  11123. deleted file mode 100644
  11124. index 80effda8343..00000000000
  11125. --- a/selftest/knownfail.d/createtrustrelax_server
  11126. +++ /dev/null
  11127. @@ -1 +0,0 @@
  11128. -^samba.tests.dcerpc.createtrustrelax.samba.tests.dcerpc.createtrustrelax.CreateTrustedDomainRelaxTest.test_create_trust_relax_encrypt\(ad_dc_fips\)
  11129. --
  11130. 2.29.2
  11131. From 9db0e9602ea96849a6f854415f4cd988576cccf2 Mon Sep 17 00:00:00 2001
  11132. From: Andreas Schneider <asn@samba.org>
  11133. Date: Wed, 11 Nov 2020 13:42:06 +0100
  11134. Subject: [PATCH 101/104] s3:smbd: Fix possible null pointer dereference in
  11135. token_contains_name()
  11136. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14572
  11137. Signed-off-by: Andreas Schneider <asn@samba.org>
  11138. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  11139. Autobuild-User(master): Alexander Bokovoy <ab@samba.org>
  11140. Autobuild-Date(master): Thu Nov 12 15:13:47 UTC 2020 on sn-devel-184
  11141. (cherry picked from commit 8036bf9717f83e83c3e4a9cf00fded42e9a5de15)
  11142. ---
  11143. source3/smbd/share_access.c | 2 +-
  11144. 1 file changed, 1 insertion(+), 1 deletion(-)
  11145. diff --git a/source3/smbd/share_access.c b/source3/smbd/share_access.c
  11146. index 57754a0f766..694c0c290e8 100644
  11147. --- a/source3/smbd/share_access.c
  11148. +++ b/source3/smbd/share_access.c
  11149. @@ -79,7 +79,7 @@ static bool token_contains_name(TALLOC_CTX *mem_ctx,
  11150. enum lsa_SidType type;
  11151. if (username != NULL) {
  11152. - size_t domain_len = strlen(domain);
  11153. + size_t domain_len = domain != NULL ? strlen(domain) : 0;
  11154. /* Check if username starts with domain name */
  11155. if (domain_len > 0) {
  11156. --
  11157. 2.29.2
  11158. From b92cbd97865ea6ef49892df75c59f37e9917ddb3 Mon Sep 17 00:00:00 2001
  11159. From: Alexander Bokovoy <ab@samba.org>
  11160. Date: Tue, 10 Nov 2020 17:35:24 +0200
  11161. Subject: [PATCH 102/104] lookup_name: allow lookup names prefixed with DNS
  11162. forest root for FreeIPA DC
  11163. In FreeIPA deployment with active Global Catalog service, when a two-way
  11164. trust to Active Directory forest is established, Windows systems can
  11165. look up FreeIPA users and groups. When using a security tab in Windows
  11166. Explorer on AD side, a lookup over a trusted forest might come as
  11167. realm\name instead of NetBIOS domain name:
  11168. --------------------------------------------------------------------
  11169. [2020/01/13 11:12:39.859134, 1, pid=33253, effective(1732401004, 1732401004), real(1732401004, 0), class=rpc_parse] ../../librpc/ndr/ndr.c:471(ndr_print_function_debug)
  11170. lsa_LookupNames3: struct lsa_LookupNames3
  11171. in: struct lsa_LookupNames3
  11172. handle : *
  11173. handle: struct policy_handle
  11174. handle_type : 0x00000000 (0)
  11175. uuid : 0000000e-0000-0000-1c5e-a750e5810000
  11176. num_names : 0x00000001 (1)
  11177. names: ARRAY(1)
  11178. names: struct lsa_String
  11179. length : 0x001e (30)
  11180. size : 0x0020 (32)
  11181. string : *
  11182. string : 'ipa.test\admins'
  11183. sids : *
  11184. sids: struct lsa_TransSidArray3
  11185. count : 0x00000000 (0)
  11186. sids : NULL
  11187. level : LSA_LOOKUP_NAMES_UPLEVEL_TRUSTS_ONLY2 (6)
  11188. count : *
  11189. count : 0x00000000 (0)
  11190. lookup_options : LSA_LOOKUP_OPTION_SEARCH_ISOLATED_NAMES (0)
  11191. client_revision : LSA_CLIENT_REVISION_2 (2)
  11192. --------------------------------------------------------------------
  11193. If we are running as a DC and PASSDB supports returning domain info
  11194. (pdb_get_domain_info() returns a valid structure), check domain of the
  11195. name in lookup_name() against DNS forest name and allow the request to
  11196. be done against the primary domain. This corresponds to FreeIPA's use of
  11197. Samba as a DC. For normal domain members a realm-based lookup falls back
  11198. to a lookup over to its own domain controller with the help of winbindd.
  11199. Signed-off-by: Alexander Bokovoy <ab@samba.org>
  11200. Reviewed-by: Stefan Metzmacher <metze@samba.org>
  11201. Autobuild-User(master): Alexander Bokovoy <ab@samba.org>
  11202. Autobuild-Date(master): Wed Nov 11 10:59:01 UTC 2020 on sn-devel-184
  11203. (cherry picked from commit 31c703766fd2b89737826fb7e9a707f0622bb8cd)
  11204. ---
  11205. source3/passdb/lookup_sid.c | 37 ++++++++++++++++++++++++++++---------
  11206. 1 file changed, 28 insertions(+), 9 deletions(-)
  11207. diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
  11208. index 82c47b3145b..864246da56e 100644
  11209. --- a/source3/passdb/lookup_sid.c
  11210. +++ b/source3/passdb/lookup_sid.c
  11211. @@ -113,17 +113,36 @@ bool lookup_name(TALLOC_CTX *mem_ctx,
  11212. full_name, domain, name));
  11213. DEBUG(10, ("lookup_name: flags = 0x0%x\n", flags));
  11214. - if (((flags & LOOKUP_NAME_DOMAIN) || (flags == 0)) &&
  11215. - strequal(domain, get_global_sam_name()))
  11216. - {
  11217. + if ((flags & LOOKUP_NAME_DOMAIN) || (flags == 0)) {
  11218. + bool check_global_sam = false;
  11219. +
  11220. + check_global_sam = strequal(domain, get_global_sam_name());
  11221. +
  11222. + /* If we are running on a DC that has PASSDB module with domain
  11223. + * information, check if DNS forest name is matching the domain
  11224. + * name. This is the case of FreeIPA domain controller when
  11225. + * trusted AD DC looks up users found in a Global Catalog of
  11226. + * the forest root domain. */
  11227. + if (!check_global_sam && (IS_DC)) {
  11228. + struct pdb_domain_info *dom_info = NULL;
  11229. + dom_info = pdb_get_domain_info(tmp_ctx);
  11230. +
  11231. + if ((dom_info != NULL) && (dom_info->dns_forest != NULL)) {
  11232. + check_global_sam = strequal(domain, dom_info->dns_forest);
  11233. + }
  11234. - /* It's our own domain, lookup the name in passdb */
  11235. - if (lookup_global_sam_name(name, flags, &rid, &type)) {
  11236. - sid_compose(&sid, get_global_sam_sid(), rid);
  11237. - goto ok;
  11238. + TALLOC_FREE(dom_info);
  11239. + }
  11240. +
  11241. + if (check_global_sam) {
  11242. + /* It's our own domain, lookup the name in passdb */
  11243. + if (lookup_global_sam_name(name, flags, &rid, &type)) {
  11244. + sid_compose(&sid, get_global_sam_sid(), rid);
  11245. + goto ok;
  11246. + }
  11247. + TALLOC_FREE(tmp_ctx);
  11248. + return false;
  11249. }
  11250. - TALLOC_FREE(tmp_ctx);
  11251. - return false;
  11252. }
  11253. if ((flags & LOOKUP_NAME_BUILTIN) &&
  11254. --
  11255. 2.29.2
  11256. From 5bf01d45325bcc6819f807620267e35841f826a3 Mon Sep 17 00:00:00 2001
  11257. From: Alexander Bokovoy <ab@samba.org>
  11258. Date: Wed, 11 Nov 2020 14:42:55 +0200
  11259. Subject: [PATCH 103/104] auth_sam: use pdb_get_domain_info to look up DNS
  11260. forest information
  11261. When Samba is used as a part of FreeIPA domain controller, Windows
  11262. clients for a trusted AD forest may try to authenticate (perform logon
  11263. operation) as a REALM\name user account.
  11264. Fix auth_sam plugins to accept DNS forest name if we are running on a DC
  11265. with PASSDB module providing domain information (e.g. pdb_get_domain_info()
  11266. returning non-NULL structure). Right now, only FreeIPA or Samba AD DC
  11267. PASSDB backends return this information but Samba AD DC configuration is
  11268. explicitly ignored by the two auth_sam (strict and netlogon3) modules.
  11269. Detailed logs below:
  11270. [2020/11/11 09:23:53.281296, 1, pid=42677, effective(65534, 65534), real(65534, 0), class=rpc_parse] ../../librpc/ndr/ndr.c:482(ndr_print_function_debug)
  11271. netr_LogonSamLogonWithFlags: struct netr_LogonSamLogonWithFlags
  11272. in: struct netr_LogonSamLogonWithFlags
  11273. server_name : *
  11274. server_name : '\\master.ipa.test'
  11275. computer_name : *
  11276. computer_name : 'AD1'
  11277. credential : *
  11278. credential: struct netr_Authenticator
  11279. cred: struct netr_Credential
  11280. data : 529f4b087c5f6546
  11281. timestamp : Wed Nov 11 09:23:55 AM 2020 UTC
  11282. return_authenticator : *
  11283. return_authenticator: struct netr_Authenticator
  11284. cred: struct netr_Credential
  11285. data : 204f28f622010000
  11286. timestamp : Fri May 2 06:37:50 AM 1986 UTC
  11287. logon_level : NetlogonNetworkTransitiveInformation (6)
  11288. logon : *
  11289. logon : union netr_LogonLevel(case 6)
  11290. network : *
  11291. network: struct netr_NetworkInfo
  11292. identity_info: struct netr_IdentityInfo
  11293. domain_name: struct lsa_String
  11294. length : 0x0010 (16)
  11295. size : 0x01fe (510)
  11296. string : *
  11297. string : 'IPA.TEST'
  11298. parameter_control : 0x00002ae0 (10976)
  11299. 0: MSV1_0_CLEARTEXT_PASSWORD_ALLOWED
  11300. 0: MSV1_0_UPDATE_LOGON_STATISTICS
  11301. 0: MSV1_0_RETURN_USER_PARAMETERS
  11302. 0: MSV1_0_DONT_TRY_GUEST_ACCOUNT
  11303. 1: MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
  11304. 1: MSV1_0_RETURN_PASSWORD_EXPIRY
  11305. 1: MSV1_0_USE_CLIENT_CHALLENGE
  11306. 0: MSV1_0_TRY_GUEST_ACCOUNT_ONLY
  11307. 1: MSV1_0_RETURN_PROFILE_PATH
  11308. 0: MSV1_0_TRY_SPECIFIED_DOMAIN_ONLY
  11309. 1: MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
  11310. 0: MSV1_0_DISABLE_PERSONAL_FALLBACK
  11311. 1: MSV1_0_ALLOW_FORCE_GUEST
  11312. 0: MSV1_0_CLEARTEXT_PASSWORD_SUPPLIED
  11313. 0: MSV1_0_USE_DOMAIN_FOR_ROUTING_ONLY
  11314. 0: MSV1_0_ALLOW_MSVCHAPV2
  11315. 0: MSV1_0_S4U2SELF
  11316. 0: MSV1_0_CHECK_LOGONHOURS_FOR_S4U
  11317. 0: MSV1_0_SUBAUTHENTICATION_DLL_EX
  11318. logon_id : 0x0000000000884ef2 (8933106)
  11319. account_name: struct lsa_String
  11320. length : 0x000e (14)
  11321. size : 0x000e (14)
  11322. string : *
  11323. string : 'idmuser'
  11324. workstation: struct lsa_String
  11325. length : 0x0000 (0)
  11326. size : 0x0000 (0)
  11327. string : *
  11328. string : ''
  11329. challenge : 417207867bd33c74
  11330. nt: struct netr_ChallengeResponse
  11331. length : 0x00c0 (192)
  11332. size : 0x00c0 (192)
  11333. data : *
  11334. data: ARRAY(192)
  11335. [0000] A5 24 62 6E 31 DF 69 66 9E DC 54 D6 63 4C D6 2F .$bn1.if ..T.cL./
  11336. [0010] 01 01 00 00 00 00 00 00 50 37 D7 60 0C B8 D6 01 ........ P7.`....
  11337. [0020] 15 1B 38 4F 47 95 4D 62 00 00 00 00 02 00 0E 00 ..8OG.Mb ........
  11338. [0030] 57 00 49 00 4E 00 32 00 30 00 31 00 36 00 01 00 W.I.N.2. 0.1.6...
  11339. [0040] 06 00 41 00 44 00 31 00 04 00 18 00 77 00 69 00 ..A.D.1. ....w.i.
  11340. [0050] 6E 00 32 00 30 00 31 00 36 00 2E 00 74 00 65 00 n.2.0.1. 6...t.e.
  11341. [0060] 73 00 74 00 03 00 20 00 61 00 64 00 31 00 2E 00 s.t... . a.d.1...
  11342. [0070] 77 00 69 00 6E 00 32 00 30 00 31 00 36 00 2E 00 w.i.n.2. 0.1.6...
  11343. [0080] 74 00 65 00 73 00 74 00 05 00 18 00 77 00 69 00 t.e.s.t. ....w.i.
  11344. [0090] 6E 00 32 00 30 00 31 00 36 00 2E 00 74 00 65 00 n.2.0.1. 6...t.e.
  11345. [00A0] 73 00 74 00 07 00 08 00 50 37 D7 60 0C B8 D6 01 s.t..... P7.`....
  11346. [00B0] 06 00 04 00 02 00 00 00 00 00 00 00 00 00 00 00 ........ ........
  11347. lm: struct netr_ChallengeResponse
  11348. length : 0x0018 (24)
  11349. size : 0x0018 (24)
  11350. data : *
  11351. data : 000000000000000000000000000000000000000000000000
  11352. validation_level : 0x0006 (6)
  11353. flags : *
  11354. flags : 0x00000000 (0)
  11355. 0: NETLOGON_SAMLOGON_FLAG_PASS_TO_FOREST_ROOT
  11356. 0: NETLOGON_SAMLOGON_FLAG_PASS_CROSS_FOREST_HOP
  11357. 0: NETLOGON_SAMLOGON_FLAG_RODC_TO_OTHER_DOMAIN
  11358. 0: NETLOGON_SAMLOGON_FLAG_RODC_NTLM_REQUEST
  11359. In such case checks for a workgroup name will not match the DNS forest
  11360. name used in the username specification:
  11361. [2020/11/11 09:23:53.283055, 3, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth.c:200(auth_check_ntlm_password)
  11362. check_ntlm_password: Checking password for unmapped user [IPA.TEST]\[idmuser]@[] with the new password interface
  11363. [2020/11/11 09:23:53.283073, 3, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth.c:203(auth_check_ntlm_password)
  11364. check_ntlm_password: mapped user is: [IPA.TEST]\[idmuser]@[]
  11365. [2020/11/11 09:23:53.283082, 10, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth.c:213(auth_check_ntlm_password)
  11366. check_ntlm_password: auth_context challenge created by fixed
  11367. [2020/11/11 09:23:53.283091, 10, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth.c:216(auth_check_ntlm_password)
  11368. challenge is:
  11369. [2020/11/11 09:23:53.283099, 5, pid=42677, effective(65534, 65534), real(65534, 0)] ../../lib/util/util.c:678(dump_data)
  11370. [0000] 41 72 07 86 7B D3 3C 74 Ar..{.<t
  11371. [2020/11/11 09:23:53.283113, 10, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth_sam.c:209(auth_sam_netlogon3_auth)
  11372. auth_sam_netlogon3_auth: Check auth for: [IPA.TEST]\[idmuser]
  11373. [2020/11/11 09:23:53.283123, 5, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth_sam.c:234(auth_sam_netlogon3_auth)
  11374. auth_sam_netlogon3_auth: IPA.TEST is not our domain name (DC for IPA)
  11375. [2020/11/11 09:23:53.283131, 10, pid=42677, effective(65534, 65534), real(65534, 0), class=auth] ../../source3/auth/auth.c:249(auth_check_ntlm_password)
  11376. auth_check_ntlm_password: sam_netlogon3 had nothing to say
  11377. and overall authentication attempt will fail: auth_winbind will complain
  11378. that this domain is not a trusted one and refuse operating on it:
  11379. [2020/11/11 09:23:53.283784, 10, pid=42663, effective(0, 0), real(0, 0), class=winbind] ../../source3/winbindd/winbindd.c:742(process_request_send)
  11380. process_request_send: process_request: Handling async request smbd(42677):PAM_AUTH_CRAP
  11381. [2020/11/11 09:23:53.283796, 3, pid=42663, effective(0, 0), real(0, 0), class=winbind] ../../source3/winbindd/winbindd_pam_auth_crap.c:110(winbindd_pam_auth_crap_send)
  11382. [42677]: pam auth crap domain: [IPA.TEST] user: idmuser
  11383. [2020/11/11 09:23:53.283810, 3, pid=42663, effective(0, 0), real(0, 0), class=winbind] ../../source3/winbindd/winbindd_pam.c:409(find_auth_domain)
  11384. Authentication for domain [IPA.TEST] refused as it is not a trusted domain
  11385. [2020/11/11 09:23:53.283825, 10, pid=42663, effective(0, 0), real(0, 0), class=winbind] ../../source3/winbindd/winbindd.c:810(process_request_done)
  11386. process_request_done: [smbd(42677):PAM_AUTH_CRAP]: NT_STATUS_NO_SUCH_USER
  11387. [2020/11/11 09:23:53.283844, 10, pid=42663, effective(0, 0), real(0, 0), class=winbind] ../../source3/winbindd/winbindd.c:855(process_request_written)
  11388. process_request_written: [smbd(42677):PAM_AUTH_CRAP]: delivered response to client
  11389. Signed-off-by: Alexander Bokovoy <ab@samba.org>
  11390. Reviewed-by: Andreas Schneider <asn@samba.org>
  11391. (cherry picked from commit 2a8b672652dcbcf55ec59be537773d76f0f14d0a)
  11392. ---
  11393. source3/auth/auth_sam.c | 45 +++++++++++++++++++++++++++++++++++++----
  11394. 1 file changed, 41 insertions(+), 4 deletions(-)
  11395. diff --git a/source3/auth/auth_sam.c b/source3/auth/auth_sam.c
  11396. index 3c12f959faf..e8e0d543f8c 100644
  11397. --- a/source3/auth/auth_sam.c
  11398. +++ b/source3/auth/auth_sam.c
  11399. @@ -22,6 +22,7 @@
  11400. #include "includes.h"
  11401. #include "auth.h"
  11402. +#include "passdb.h"
  11403. #undef DBGC_CLASS
  11404. #define DBGC_CLASS DBGC_AUTH
  11405. @@ -142,10 +143,28 @@ static NTSTATUS auth_samstrict_auth(const struct auth_context *auth_context,
  11406. break;
  11407. case ROLE_DOMAIN_PDC:
  11408. case ROLE_DOMAIN_BDC:
  11409. - if ( !is_local_name && !is_my_domain ) {
  11410. - DEBUG(6,("check_samstrict_security: %s is not one of my local names or domain name (DC)\n",
  11411. - effective_domain));
  11412. - return NT_STATUS_NOT_IMPLEMENTED;
  11413. + if (!is_local_name && !is_my_domain) {
  11414. + /* If we are running on a DC that has PASSDB module with domain
  11415. + * information, check if DNS forest name is matching the domain
  11416. + * name. This is the case of FreeIPA domain controller when
  11417. + * trusted AD DCs attempt to authenticate FreeIPA users using
  11418. + * the forest root domain (which is the only domain in FreeIPA).
  11419. + */
  11420. + struct pdb_domain_info *dom_info = NULL;
  11421. +
  11422. + dom_info = pdb_get_domain_info(mem_ctx);
  11423. + if ((dom_info != NULL) && (dom_info->dns_forest != NULL)) {
  11424. + is_my_domain = strequal(user_info->mapped.domain_name,
  11425. + dom_info->dns_forest);
  11426. + }
  11427. +
  11428. + TALLOC_FREE(dom_info);
  11429. + if (!is_my_domain) {
  11430. + DEBUG(6,("check_samstrict_security: %s is not one "
  11431. + "of my local names or domain name (DC)\n",
  11432. + effective_domain));
  11433. + return NT_STATUS_NOT_IMPLEMENTED;
  11434. + }
  11435. }
  11436. break;
  11437. @@ -230,6 +249,24 @@ static NTSTATUS auth_sam_netlogon3_auth(const struct auth_context *auth_context,
  11438. }
  11439. is_my_domain = strequal(user_info->mapped.domain_name, lp_workgroup());
  11440. + if (!is_my_domain) {
  11441. + /* If we are running on a DC that has PASSDB module with domain
  11442. + * information, check if DNS forest name is matching the domain
  11443. + * name. This is the case of FreeIPA domain controller when
  11444. + * trusted AD DCs attempt to authenticate FreeIPA users using
  11445. + * the forest root domain (which is the only domain in FreeIPA).
  11446. + */
  11447. + struct pdb_domain_info *dom_info = NULL;
  11448. + dom_info = pdb_get_domain_info(mem_ctx);
  11449. +
  11450. + if ((dom_info != NULL) && (dom_info->dns_forest != NULL)) {
  11451. + is_my_domain = strequal(user_info->mapped.domain_name,
  11452. + dom_info->dns_forest);
  11453. + }
  11454. +
  11455. + TALLOC_FREE(dom_info);
  11456. + }
  11457. +
  11458. if (!is_my_domain) {
  11459. DBG_INFO("%s is not our domain name (DC for %s)\n",
  11460. effective_domain, lp_workgroup());
  11461. --
  11462. 2.29.2
  11463. From edd405a3918b5d52e7eeff2f8425478a0a1867ed Mon Sep 17 00:00:00 2001
  11464. From: Andreas Schneider <asn@samba.org>
  11465. Date: Fri, 27 Nov 2020 11:22:15 +0100
  11466. Subject: [PATCH 104/104] docs-xml: Add a section about weak crypto in testparm
  11467. manpage
  11468. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14583
  11469. Signed-off-by: Andreas Schneider <asn@samba.org>
  11470. Reviewed-by: Alexander Bokovoy <ab@samba.org>
  11471. Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
  11472. Autobuild-Date(master): Fri Nov 27 13:48:20 UTC 2020 on sn-devel-184
  11473. (cherry picked from commit 5c27740aeff273bcd5f027d36874e56170234146)
  11474. ---
  11475. docs-xml/manpages/testparm.1.xml | 9 +++++++++
  11476. 1 file changed, 9 insertions(+)
  11477. diff --git a/docs-xml/manpages/testparm.1.xml b/docs-xml/manpages/testparm.1.xml
  11478. index 9099cda010f..7c7abf50e8b 100644
  11479. --- a/docs-xml/manpages/testparm.1.xml
  11480. +++ b/docs-xml/manpages/testparm.1.xml
  11481. @@ -171,6 +171,15 @@
  11482. errors and warnings if the file did not load. If the file was
  11483. loaded OK, the program then dumps all known service details
  11484. to stdout. </para>
  11485. +
  11486. + <para>For certain use cases, SMB protocol requires use of
  11487. + cryptographic algorithms which are known to be weak and already
  11488. + broken. DES and ARCFOUR (RC4) ciphers and the SHA1 and MD5 hash
  11489. + algorithms are considered weak but they are required for backward
  11490. + compatibility. The testparm utility shows whether the Samba tools
  11491. + will fall back to these weak crypto algorithms if it is not possible
  11492. + to use strong cryptography by default.
  11493. + In FIPS mode weak crypto cannot be enabled.</para>
  11494. </refsect1>
  11495. --
  11496. 2.29.2