sysacls.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784
  1. /*
  2. * Unix SMB/CIFS implementation.
  3. * Based on the Samba ACL support code.
  4. * Copyright (C) Jeremy Allison 2000.
  5. * Copyright (C) 2007-2008 Wayne Davison
  6. *
  7. * The permission functions have been changed to get/set all bits via
  8. * one call. Some functions that rsync doesn't need were also removed.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * with this program; if not, visit the http://fsf.org website.
  22. */
  23. #include "rsync.h"
  24. #include "sysacls.h"
  25. #ifdef SUPPORT_ACLS
  26. #ifdef DEBUG
  27. #undef DEBUG
  28. #endif
  29. #define DEBUG(x,y)
  30. void SAFE_FREE(void *mem)
  31. {
  32. if (mem)
  33. free(mem);
  34. }
  35. /*
  36. This file wraps all differing system ACL interfaces into a consistent
  37. one based on the POSIX interface. It also returns the correct errors
  38. for older UNIX systems that don't support ACLs.
  39. The interfaces that each ACL implementation must support are as follows :
  40. int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  41. int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
  42. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  43. SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
  44. SMB_ACL_T sys_acl_get_fd(int fd)
  45. SMB_ACL_T sys_acl_init( int count)
  46. int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
  47. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  48. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits)
  49. int sys_acl_valid( SMB_ACL_T theacl )
  50. int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
  51. int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
  52. int sys_acl_delete_def_file(const char *path)
  53. int sys_acl_free_acl(SMB_ACL_T posix_acl)
  54. */
  55. #if defined(HAVE_POSIX_ACLS) /*--------------------------------------------*/
  56. /* Identity mapping - easy. */
  57. int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  58. {
  59. return acl_get_entry( the_acl, entry_id, entry_p);
  60. }
  61. int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
  62. {
  63. return acl_get_tag_type( entry_d, tag_type_p);
  64. }
  65. SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
  66. {
  67. return acl_get_file( path_p, type);
  68. }
  69. #if 0
  70. SMB_ACL_T sys_acl_get_fd(int fd)
  71. {
  72. return acl_get_fd(fd);
  73. }
  74. #endif
  75. #if defined(HAVE_ACL_GET_PERM_NP)
  76. #define acl_get_perm(p, b) acl_get_perm_np(p, b)
  77. #endif
  78. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  79. {
  80. acl_permset_t permset;
  81. if (acl_get_tag_type(entry, tag_type_p) != 0
  82. || acl_get_permset(entry, &permset) != 0)
  83. return -1;
  84. *bits_p = (acl_get_perm(permset, ACL_READ) ? 4 : 0)
  85. | (acl_get_perm(permset, ACL_WRITE) ? 2 : 0)
  86. | (acl_get_perm(permset, ACL_EXECUTE) ? 1 : 0);
  87. if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) {
  88. void *qual;
  89. if ((qual = acl_get_qualifier(entry)) == NULL)
  90. return -1;
  91. *u_g_id_p = *(id_t*)qual;
  92. acl_free(qual);
  93. }
  94. return 0;
  95. }
  96. SMB_ACL_T sys_acl_init( int count)
  97. {
  98. return acl_init(count);
  99. }
  100. int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
  101. {
  102. return acl_create_entry(pacl, pentry);
  103. }
  104. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  105. {
  106. if (acl_set_tag_type(entry, tag_type) != 0)
  107. return -1;
  108. if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) {
  109. if (acl_set_qualifier(entry, (void*)&u_g_id) != 0)
  110. return -1;
  111. }
  112. return sys_acl_set_access_bits(entry, bits);
  113. }
  114. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits)
  115. {
  116. acl_permset_t permset;
  117. int rc;
  118. if ((rc = acl_get_permset(entry, &permset)) != 0)
  119. return rc;
  120. acl_clear_perms(permset);
  121. if (bits & 4)
  122. acl_add_perm(permset, ACL_READ);
  123. if (bits & 2)
  124. acl_add_perm(permset, ACL_WRITE);
  125. if (bits & 1)
  126. acl_add_perm(permset, ACL_EXECUTE);
  127. return acl_set_permset(entry, permset);
  128. }
  129. int sys_acl_valid( SMB_ACL_T theacl )
  130. {
  131. return acl_valid(theacl);
  132. }
  133. int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
  134. {
  135. return acl_set_file(name, acltype, theacl);
  136. }
  137. #if 0
  138. int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
  139. {
  140. return acl_set_fd(fd, theacl);
  141. }
  142. #endif
  143. int sys_acl_delete_def_file(const char *name)
  144. {
  145. return acl_delete_def_file(name);
  146. }
  147. int sys_acl_free_acl(SMB_ACL_T the_acl)
  148. {
  149. return acl_free(the_acl);
  150. }
  151. #elif defined(HAVE_TRU64_ACLS) /*--------------------------------------------*/
  152. /*
  153. * The interface to DEC/Compaq Tru64 UNIX ACLs
  154. * is based on Draft 13 of the POSIX spec which is
  155. * slightly different from the Draft 16 interface.
  156. *
  157. * Also, some of the permset manipulation functions
  158. * such as acl_clear_perm() and acl_add_perm() appear
  159. * to be broken on Tru64 so we have to manipulate
  160. * the permission bits in the permset directly.
  161. */
  162. int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  163. {
  164. SMB_ACL_ENTRY_T entry;
  165. if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
  166. return -1;
  167. }
  168. errno = 0;
  169. if ((entry = acl_get_entry(the_acl)) != NULL) {
  170. *entry_p = entry;
  171. return 1;
  172. }
  173. return errno ? -1 : 0;
  174. }
  175. int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
  176. {
  177. return acl_get_tag_type( entry_d, tag_type_p);
  178. }
  179. SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
  180. {
  181. return acl_get_file((char *)path_p, type);
  182. }
  183. #if 0
  184. SMB_ACL_T sys_acl_get_fd(int fd)
  185. {
  186. return acl_get_fd(fd, ACL_TYPE_ACCESS);
  187. }
  188. #endif
  189. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  190. {
  191. acl_permset_t permset;
  192. if (acl_get_tag_type(entry, tag_type_p) != 0
  193. || acl_get_permset(entry, &permset) != 0)
  194. return -1;
  195. *bits_p = *permset & 7; /* Tru64 doesn't have acl_get_perm() */
  196. if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) {
  197. void *qual;
  198. if ((qual = acl_get_qualifier(entry)) == NULL)
  199. return -1;
  200. *u_g_id_p = *(id_t*)qual;
  201. acl_free_qualifier(qual, *tag_type_p);
  202. }
  203. return 0;
  204. }
  205. SMB_ACL_T sys_acl_init( int count)
  206. {
  207. return acl_init(count);
  208. }
  209. int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
  210. {
  211. SMB_ACL_ENTRY_T entry;
  212. if ((entry = acl_create_entry(pacl)) == NULL) {
  213. return -1;
  214. }
  215. *pentry = entry;
  216. return 0;
  217. }
  218. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  219. {
  220. if (acl_set_tag_type(entry, tag_type) != 0)
  221. return -1;
  222. if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) {
  223. if (acl_set_qualifier(entry, (void*)&u_g_id) != 0)
  224. return -1;
  225. }
  226. return sys_acl_set_access_bits(entry, bits);
  227. }
  228. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits)
  229. {
  230. acl_permset_t permset;
  231. int rc;
  232. if ((rc = acl_get_permset(entry, &permset)) != 0)
  233. return rc;
  234. *permset = bits & 7;
  235. return acl_set_permset(entry, permset);
  236. }
  237. int sys_acl_valid( SMB_ACL_T theacl )
  238. {
  239. acl_entry_t entry;
  240. return acl_valid(theacl, &entry);
  241. }
  242. int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
  243. {
  244. return acl_set_file((char *)name, acltype, theacl);
  245. }
  246. #if 0
  247. int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
  248. {
  249. return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
  250. }
  251. #endif
  252. int sys_acl_delete_def_file(const char *name)
  253. {
  254. return acl_delete_def_file((char *)name);
  255. }
  256. int sys_acl_free_acl(SMB_ACL_T the_acl)
  257. {
  258. return acl_free(the_acl);
  259. }
  260. #elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) /*-----------*/
  261. /*
  262. * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
  263. * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
  264. */
  265. /*
  266. * Note that while this code implements sufficient functionality
  267. * to support the sys_acl_* interfaces it does not provide all
  268. * of the semantics of the POSIX ACL interfaces.
  269. *
  270. * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
  271. * from a call to sys_acl_get_entry() should not be assumed to be
  272. * valid after calling any of the following functions, which may
  273. * reorder the entries in the ACL.
  274. *
  275. * sys_acl_valid()
  276. * sys_acl_set_file()
  277. * sys_acl_set_fd()
  278. */
  279. /*
  280. * The only difference between Solaris and UnixWare / OpenUNIX is
  281. * that the #defines for the ACL operations have different names
  282. */
  283. #if defined(HAVE_UNIXWARE_ACLS)
  284. #define SETACL ACL_SET
  285. #define GETACL ACL_GET
  286. #define GETACLCNT ACL_CNT
  287. #endif
  288. int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  289. {
  290. if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
  291. errno = EINVAL;
  292. return -1;
  293. }
  294. if (entry_p == NULL) {
  295. errno = EINVAL;
  296. return -1;
  297. }
  298. if (entry_id == SMB_ACL_FIRST_ENTRY) {
  299. acl_d->next = 0;
  300. }
  301. if (acl_d->next < 0) {
  302. errno = EINVAL;
  303. return -1;
  304. }
  305. if (acl_d->next >= acl_d->count) {
  306. return 0;
  307. }
  308. *entry_p = &acl_d->acl[acl_d->next++];
  309. return 1;
  310. }
  311. int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
  312. {
  313. *type_p = entry_d->a_type;
  314. return 0;
  315. }
  316. /*
  317. * There is no way of knowing what size the ACL returned by
  318. * GETACL will be unless you first call GETACLCNT which means
  319. * making an additional system call.
  320. *
  321. * In the hope of avoiding the cost of the additional system
  322. * call in most cases, we initially allocate enough space for
  323. * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
  324. * be too small then we use GETACLCNT to find out the actual
  325. * size, reallocate the ACL buffer, and then call GETACL again.
  326. */
  327. #define INITIAL_ACL_SIZE 16
  328. SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
  329. {
  330. SMB_ACL_T acl_d;
  331. int count; /* # of ACL entries allocated */
  332. int naccess; /* # of access ACL entries */
  333. int ndefault; /* # of default ACL entries */
  334. if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
  335. errno = EINVAL;
  336. return NULL;
  337. }
  338. count = INITIAL_ACL_SIZE;
  339. if ((acl_d = sys_acl_init(count)) == NULL) {
  340. return NULL;
  341. }
  342. /*
  343. * If there isn't enough space for the ACL entries we use
  344. * GETACLCNT to determine the actual number of ACL entries
  345. * reallocate and try again. This is in a loop because it
  346. * is possible that someone else could modify the ACL and
  347. * increase the number of entries between the call to
  348. * GETACLCNT and the call to GETACL.
  349. */
  350. while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
  351. && errno == ENOSPC) {
  352. sys_acl_free_acl(acl_d);
  353. if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
  354. return NULL;
  355. }
  356. if ((acl_d = sys_acl_init(count)) == NULL) {
  357. return NULL;
  358. }
  359. }
  360. if (count < 0) {
  361. sys_acl_free_acl(acl_d);
  362. return NULL;
  363. }
  364. /*
  365. * calculate the number of access and default ACL entries
  366. *
  367. * Note: we assume that the acl() system call returned a
  368. * well formed ACL which is sorted so that all of the
  369. * access ACL entries preceed any default ACL entries
  370. */
  371. for (naccess = 0; naccess < count; naccess++) {
  372. if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
  373. break;
  374. }
  375. ndefault = count - naccess;
  376. /*
  377. * if the caller wants the default ACL we have to copy
  378. * the entries down to the start of the acl[] buffer
  379. * and mask out the ACL_DEFAULT flag from the type field
  380. */
  381. if (type == SMB_ACL_TYPE_DEFAULT) {
  382. int i, j;
  383. for (i = 0, j = naccess; i < ndefault; i++, j++) {
  384. acl_d->acl[i] = acl_d->acl[j];
  385. acl_d->acl[i].a_type &= ~ACL_DEFAULT;
  386. }
  387. acl_d->count = ndefault;
  388. } else {
  389. acl_d->count = naccess;
  390. }
  391. return acl_d;
  392. }
  393. #if 0
  394. SMB_ACL_T sys_acl_get_fd(int fd)
  395. {
  396. SMB_ACL_T acl_d;
  397. int count; /* # of ACL entries allocated */
  398. int naccess; /* # of access ACL entries */
  399. count = INITIAL_ACL_SIZE;
  400. if ((acl_d = sys_acl_init(count)) == NULL) {
  401. return NULL;
  402. }
  403. while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
  404. && errno == ENOSPC) {
  405. sys_acl_free_acl(acl_d);
  406. if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
  407. return NULL;
  408. }
  409. if ((acl_d = sys_acl_init(count)) == NULL) {
  410. return NULL;
  411. }
  412. }
  413. if (count < 0) {
  414. sys_acl_free_acl(acl_d);
  415. return NULL;
  416. }
  417. /*
  418. * calculate the number of access ACL entries
  419. */
  420. for (naccess = 0; naccess < count; naccess++) {
  421. if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
  422. break;
  423. }
  424. acl_d->count = naccess;
  425. return acl_d;
  426. }
  427. #endif
  428. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  429. {
  430. *tag_type_p = entry->a_type;
  431. *bits_p = entry->a_perm;
  432. if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP)
  433. *u_g_id_p = entry->a_id;
  434. return 0;
  435. }
  436. SMB_ACL_T sys_acl_init(int count)
  437. {
  438. SMB_ACL_T a;
  439. if (count < 0) {
  440. errno = EINVAL;
  441. return NULL;
  442. }
  443. /*
  444. * note that since the definition of the structure pointed
  445. * to by the SMB_ACL_T includes the first element of the
  446. * acl[] array, this actually allocates an ACL with room
  447. * for (count+1) entries
  448. */
  449. if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof a[0] + count * sizeof (struct acl))) == NULL) {
  450. errno = ENOMEM;
  451. return NULL;
  452. }
  453. a->size = count + 1;
  454. a->count = 0;
  455. a->next = -1;
  456. return a;
  457. }
  458. int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
  459. {
  460. SMB_ACL_T acl_d;
  461. SMB_ACL_ENTRY_T entry_d;
  462. if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
  463. errno = EINVAL;
  464. return -1;
  465. }
  466. if (acl_d->count >= acl_d->size) {
  467. errno = ENOSPC;
  468. return -1;
  469. }
  470. entry_d = &acl_d->acl[acl_d->count++];
  471. entry_d->a_type = 0;
  472. entry_d->a_id = -1;
  473. entry_d->a_perm = 0;
  474. *entry_p = entry_d;
  475. return 0;
  476. }
  477. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  478. {
  479. entry->a_type = tag_type;
  480. if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP)
  481. entry->a_id = u_g_id;
  482. entry->a_perm = bits;
  483. return 0;
  484. }
  485. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 bits)
  486. {
  487. entry_d->a_perm = bits;
  488. return 0;
  489. }
  490. /*
  491. * sort the ACL and check it for validity
  492. *
  493. * if it's a minimal ACL with only 4 entries then we
  494. * need to recalculate the mask permissions to make
  495. * sure that they are the same as the GROUP_OBJ
  496. * permissions as required by the UnixWare acl() system call.
  497. *
  498. * (note: since POSIX allows minimal ACLs which only contain
  499. * 3 entries - ie there is no mask entry - we should, in theory,
  500. * check for this and add a mask entry if necessary - however
  501. * we "know" that the caller of this interface always specifies
  502. * a mask so, in practice "this never happens" (tm) - if it *does*
  503. * happen aclsort() will fail and return an error and someone will
  504. * have to fix it ...)
  505. */
  506. static int acl_sort(SMB_ACL_T acl_d)
  507. {
  508. int fixmask = (acl_d->count <= 4);
  509. if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
  510. errno = EINVAL;
  511. return -1;
  512. }
  513. return 0;
  514. }
  515. int sys_acl_valid(SMB_ACL_T acl_d)
  516. {
  517. return acl_sort(acl_d);
  518. }
  519. int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
  520. {
  521. struct stat s;
  522. struct acl *acl_p;
  523. int acl_count;
  524. struct acl *acl_buf = NULL;
  525. int ret;
  526. if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
  527. errno = EINVAL;
  528. return -1;
  529. }
  530. if (acl_sort(acl_d) != 0) {
  531. return -1;
  532. }
  533. acl_p = &acl_d->acl[0];
  534. acl_count = acl_d->count;
  535. /*
  536. * if it's a directory there is extra work to do
  537. * since the acl() system call will replace both
  538. * the access ACLs and the default ACLs (if any)
  539. */
  540. if (stat(name, &s) != 0) {
  541. return -1;
  542. }
  543. if (S_ISDIR(s.st_mode)) {
  544. SMB_ACL_T acc_acl;
  545. SMB_ACL_T def_acl;
  546. SMB_ACL_T tmp_acl;
  547. int i;
  548. if (type == SMB_ACL_TYPE_ACCESS) {
  549. acc_acl = acl_d;
  550. def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
  551. } else {
  552. def_acl = acl_d;
  553. acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
  554. }
  555. if (tmp_acl == NULL) {
  556. return -1;
  557. }
  558. /*
  559. * allocate a temporary buffer for the complete ACL
  560. */
  561. acl_count = acc_acl->count + def_acl->count;
  562. acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
  563. if (acl_buf == NULL) {
  564. sys_acl_free_acl(tmp_acl);
  565. errno = ENOMEM;
  566. return -1;
  567. }
  568. /*
  569. * copy the access control and default entries into the buffer
  570. */
  571. memcpy(&acl_buf[0], &acc_acl->acl[0],
  572. acc_acl->count * sizeof(acl_buf[0]));
  573. memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
  574. def_acl->count * sizeof(acl_buf[0]));
  575. /*
  576. * set the ACL_DEFAULT flag on the default entries
  577. */
  578. for (i = acc_acl->count; i < acl_count; i++) {
  579. acl_buf[i].a_type |= ACL_DEFAULT;
  580. }
  581. sys_acl_free_acl(tmp_acl);
  582. } else if (type != SMB_ACL_TYPE_ACCESS) {
  583. errno = EINVAL;
  584. return -1;
  585. }
  586. ret = acl(name, SETACL, acl_count, acl_p);
  587. SAFE_FREE(acl_buf);
  588. return ret;
  589. }
  590. #if 0
  591. int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
  592. {
  593. if (acl_sort(acl_d) != 0) {
  594. return -1;
  595. }
  596. return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
  597. }
  598. #endif
  599. int sys_acl_delete_def_file(const char *path)
  600. {
  601. SMB_ACL_T acl_d;
  602. int ret;
  603. /*
  604. * fetching the access ACL and rewriting it has
  605. * the effect of deleting the default ACL
  606. */
  607. if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
  608. return -1;
  609. }
  610. ret = acl(path, SETACL, acl_d->count, acl_d->acl);
  611. sys_acl_free_acl(acl_d);
  612. return ret;
  613. }
  614. int sys_acl_free_acl(SMB_ACL_T acl_d)
  615. {
  616. SAFE_FREE(acl_d);
  617. return 0;
  618. }
  619. #elif defined(HAVE_HPUX_ACLS) /*---------------------------------------------*/
  620. #include <dl.h>
  621. /*
  622. * Based on the Solaris/SCO code - with modifications.
  623. */
  624. /*
  625. * Note that while this code implements sufficient functionality
  626. * to support the sys_acl_* interfaces it does not provide all
  627. * of the semantics of the POSIX ACL interfaces.
  628. *
  629. * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
  630. * from a call to sys_acl_get_entry() should not be assumed to be
  631. * valid after calling any of the following functions, which may
  632. * reorder the entries in the ACL.
  633. *
  634. * sys_acl_valid()
  635. * sys_acl_set_file()
  636. * sys_acl_set_fd()
  637. */
  638. /* This checks if the POSIX ACL system call is defined */
  639. /* which basically corresponds to whether JFS 3.3 or */
  640. /* higher is installed. If acl() was called when it */
  641. /* isn't defined, it causes the process to core dump */
  642. /* so it is important to check this and avoid acl() */
  643. /* calls if it isn't there. */
  644. static BOOL hpux_acl_call_presence(void)
  645. {
  646. shl_t handle = NULL;
  647. void *value;
  648. int ret_val=0;
  649. static BOOL already_checked=0;
  650. if(already_checked)
  651. return True;
  652. ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
  653. if(ret_val != 0) {
  654. DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
  655. ret_val, errno, strerror(errno)));
  656. DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
  657. return False;
  658. }
  659. DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
  660. already_checked = True;
  661. return True;
  662. }
  663. int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  664. {
  665. if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
  666. errno = EINVAL;
  667. return -1;
  668. }
  669. if (entry_p == NULL) {
  670. errno = EINVAL;
  671. return -1;
  672. }
  673. if (entry_id == SMB_ACL_FIRST_ENTRY) {
  674. acl_d->next = 0;
  675. }
  676. if (acl_d->next < 0) {
  677. errno = EINVAL;
  678. return -1;
  679. }
  680. if (acl_d->next >= acl_d->count) {
  681. return 0;
  682. }
  683. *entry_p = &acl_d->acl[acl_d->next++];
  684. return 1;
  685. }
  686. int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
  687. {
  688. *type_p = entry_d->a_type;
  689. return 0;
  690. }
  691. /*
  692. * There is no way of knowing what size the ACL returned by
  693. * ACL_GET will be unless you first call ACL_CNT which means
  694. * making an additional system call.
  695. *
  696. * In the hope of avoiding the cost of the additional system
  697. * call in most cases, we initially allocate enough space for
  698. * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
  699. * be too small then we use ACL_CNT to find out the actual
  700. * size, reallocate the ACL buffer, and then call ACL_GET again.
  701. */
  702. #define INITIAL_ACL_SIZE 16
  703. SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
  704. {
  705. SMB_ACL_T acl_d;
  706. int count; /* # of ACL entries allocated */
  707. int naccess; /* # of access ACL entries */
  708. int ndefault; /* # of default ACL entries */
  709. if(hpux_acl_call_presence() == False) {
  710. /* Looks like we don't have the acl() system call on HPUX.
  711. * May be the system doesn't have the latest version of JFS.
  712. */
  713. return NULL;
  714. }
  715. if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
  716. errno = EINVAL;
  717. return NULL;
  718. }
  719. count = INITIAL_ACL_SIZE;
  720. if ((acl_d = sys_acl_init(count)) == NULL) {
  721. return NULL;
  722. }
  723. /*
  724. * If there isn't enough space for the ACL entries we use
  725. * ACL_CNT to determine the actual number of ACL entries
  726. * reallocate and try again. This is in a loop because it
  727. * is possible that someone else could modify the ACL and
  728. * increase the number of entries between the call to
  729. * ACL_CNT and the call to ACL_GET.
  730. */
  731. while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
  732. sys_acl_free_acl(acl_d);
  733. if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
  734. return NULL;
  735. }
  736. if ((acl_d = sys_acl_init(count)) == NULL) {
  737. return NULL;
  738. }
  739. }
  740. if (count < 0) {
  741. sys_acl_free_acl(acl_d);
  742. return NULL;
  743. }
  744. /*
  745. * calculate the number of access and default ACL entries
  746. *
  747. * Note: we assume that the acl() system call returned a
  748. * well formed ACL which is sorted so that all of the
  749. * access ACL entries preceed any default ACL entries
  750. */
  751. for (naccess = 0; naccess < count; naccess++) {
  752. if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
  753. break;
  754. }
  755. ndefault = count - naccess;
  756. /*
  757. * if the caller wants the default ACL we have to copy
  758. * the entries down to the start of the acl[] buffer
  759. * and mask out the ACL_DEFAULT flag from the type field
  760. */
  761. if (type == SMB_ACL_TYPE_DEFAULT) {
  762. int i, j;
  763. for (i = 0, j = naccess; i < ndefault; i++, j++) {
  764. acl_d->acl[i] = acl_d->acl[j];
  765. acl_d->acl[i].a_type &= ~ACL_DEFAULT;
  766. }
  767. acl_d->count = ndefault;
  768. } else {
  769. acl_d->count = naccess;
  770. }
  771. return acl_d;
  772. }
  773. #if 0
  774. SMB_ACL_T sys_acl_get_fd(int fd)
  775. {
  776. /*
  777. * HPUX doesn't have the facl call. Fake it using the path.... JRA.
  778. */
  779. files_struct *fsp = file_find_fd(fd);
  780. if (fsp == NULL) {
  781. errno = EBADF;
  782. return NULL;
  783. }
  784. /*
  785. * We know we're in the same conn context. So we
  786. * can use the relative path.
  787. */
  788. return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
  789. }
  790. #endif
  791. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  792. {
  793. *tag_type_p = entry->a_type;
  794. *bits_p = entry->a_perm;
  795. if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP)
  796. *u_g_id_p = entry->a_id;
  797. return 0;
  798. }
  799. SMB_ACL_T sys_acl_init(int count)
  800. {
  801. SMB_ACL_T a;
  802. if (count < 0) {
  803. errno = EINVAL;
  804. return NULL;
  805. }
  806. /*
  807. * note that since the definition of the structure pointed
  808. * to by the SMB_ACL_T includes the first element of the
  809. * acl[] array, this actually allocates an ACL with room
  810. * for (count+1) entries
  811. */
  812. if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof a[0] + count * sizeof(struct acl))) == NULL) {
  813. errno = ENOMEM;
  814. return NULL;
  815. }
  816. a->size = count + 1;
  817. a->count = 0;
  818. a->next = -1;
  819. return a;
  820. }
  821. int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
  822. {
  823. SMB_ACL_T acl_d;
  824. SMB_ACL_ENTRY_T entry_d;
  825. if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
  826. errno = EINVAL;
  827. return -1;
  828. }
  829. if (acl_d->count >= acl_d->size) {
  830. errno = ENOSPC;
  831. return -1;
  832. }
  833. entry_d = &acl_d->acl[acl_d->count++];
  834. entry_d->a_type = 0;
  835. entry_d->a_id = -1;
  836. entry_d->a_perm = 0;
  837. *entry_p = entry_d;
  838. return 0;
  839. }
  840. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  841. {
  842. entry->a_type = tag_type;
  843. if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP)
  844. entry->a_id = u_g_id;
  845. entry->a_perm = bits;
  846. return 0;
  847. }
  848. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 bits)
  849. {
  850. entry_d->a_perm = bits;
  851. return 0;
  852. }
  853. /* Structure to capture the count for each type of ACE. */
  854. struct hpux_acl_types {
  855. int n_user;
  856. int n_def_user;
  857. int n_user_obj;
  858. int n_def_user_obj;
  859. int n_group;
  860. int n_def_group;
  861. int n_group_obj;
  862. int n_def_group_obj;
  863. int n_other;
  864. int n_other_obj;
  865. int n_def_other_obj;
  866. int n_class_obj;
  867. int n_def_class_obj;
  868. int n_illegal_obj;
  869. };
  870. /* count_obj:
  871. * Counts the different number of objects in a given array of ACL
  872. * structures.
  873. * Inputs:
  874. *
  875. * acl_count - Count of ACLs in the array of ACL strucutres.
  876. * aclp - Array of ACL structures.
  877. * acl_type_count - Pointer to acl_types structure. Should already be
  878. * allocated.
  879. * Output:
  880. *
  881. * acl_type_count - This structure is filled up with counts of various
  882. * acl types.
  883. */
  884. static void hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
  885. {
  886. int i;
  887. memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
  888. for(i=0;i<acl_count;i++) {
  889. switch(aclp[i].a_type) {
  890. case USER:
  891. acl_type_count->n_user++;
  892. break;
  893. case USER_OBJ:
  894. acl_type_count->n_user_obj++;
  895. break;
  896. case DEF_USER_OBJ:
  897. acl_type_count->n_def_user_obj++;
  898. break;
  899. case GROUP:
  900. acl_type_count->n_group++;
  901. break;
  902. case GROUP_OBJ:
  903. acl_type_count->n_group_obj++;
  904. break;
  905. case DEF_GROUP_OBJ:
  906. acl_type_count->n_def_group_obj++;
  907. break;
  908. case OTHER_OBJ:
  909. acl_type_count->n_other_obj++;
  910. break;
  911. case DEF_OTHER_OBJ:
  912. acl_type_count->n_def_other_obj++;
  913. break;
  914. case CLASS_OBJ:
  915. acl_type_count->n_class_obj++;
  916. break;
  917. case DEF_CLASS_OBJ:
  918. acl_type_count->n_def_class_obj++;
  919. break;
  920. case DEF_USER:
  921. acl_type_count->n_def_user++;
  922. break;
  923. case DEF_GROUP:
  924. acl_type_count->n_def_group++;
  925. break;
  926. default:
  927. acl_type_count->n_illegal_obj++;
  928. break;
  929. }
  930. }
  931. }
  932. /* swap_acl_entries: Swaps two ACL entries.
  933. *
  934. * Inputs: aclp0, aclp1 - ACL entries to be swapped.
  935. */
  936. static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
  937. {
  938. struct acl temp_acl;
  939. temp_acl.a_type = aclp0->a_type;
  940. temp_acl.a_id = aclp0->a_id;
  941. temp_acl.a_perm = aclp0->a_perm;
  942. aclp0->a_type = aclp1->a_type;
  943. aclp0->a_id = aclp1->a_id;
  944. aclp0->a_perm = aclp1->a_perm;
  945. aclp1->a_type = temp_acl.a_type;
  946. aclp1->a_id = temp_acl.a_id;
  947. aclp1->a_perm = temp_acl.a_perm;
  948. }
  949. /* prohibited_duplicate_type
  950. * Identifies if given ACL type can have duplicate entries or
  951. * not.
  952. *
  953. * Inputs: acl_type - ACL Type.
  954. *
  955. * Outputs:
  956. *
  957. * Return..
  958. *
  959. * True - If the ACL type matches any of the prohibited types.
  960. * False - If the ACL type doesn't match any of the prohibited types.
  961. */
  962. static BOOL hpux_prohibited_duplicate_type(int acl_type)
  963. {
  964. switch(acl_type) {
  965. case USER:
  966. case GROUP:
  967. case DEF_USER:
  968. case DEF_GROUP:
  969. return True;
  970. default:
  971. return False;
  972. }
  973. }
  974. /* get_needed_class_perm
  975. * Returns the permissions of a ACL structure only if the ACL
  976. * type matches one of the pre-determined types for computing
  977. * CLASS_OBJ permissions.
  978. *
  979. * Inputs: aclp - Pointer to ACL structure.
  980. */
  981. static int hpux_get_needed_class_perm(struct acl *aclp)
  982. {
  983. switch(aclp->a_type) {
  984. case USER:
  985. case GROUP_OBJ:
  986. case GROUP:
  987. case DEF_USER_OBJ:
  988. case DEF_USER:
  989. case DEF_GROUP_OBJ:
  990. case DEF_GROUP:
  991. case DEF_CLASS_OBJ:
  992. case DEF_OTHER_OBJ:
  993. return aclp->a_perm;
  994. default:
  995. return 0;
  996. }
  997. }
  998. /* acl_sort for HPUX.
  999. * Sorts the array of ACL structures as per the description in
  1000. * aclsort man page. Refer to aclsort man page for more details
  1001. *
  1002. * Inputs:
  1003. *
  1004. * acl_count - Count of ACLs in the array of ACL structures.
  1005. * calclass - If this is not zero, then we compute the CLASS_OBJ
  1006. * permissions.
  1007. * aclp - Array of ACL structures.
  1008. *
  1009. * Outputs:
  1010. *
  1011. * aclp - Sorted array of ACL structures.
  1012. *
  1013. * Outputs:
  1014. *
  1015. * Returns 0 for success -1 for failure. Prints a message to the Samba
  1016. * debug log in case of failure.
  1017. */
  1018. static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
  1019. {
  1020. #if !defined(HAVE_HPUX_ACLSORT)
  1021. /*
  1022. * The aclsort() system call is availabe on the latest HPUX General
  1023. * Patch Bundles. So for HPUX, we developed our version of acl_sort
  1024. * function. Because, we don't want to update to a new
  1025. * HPUX GR bundle just for aclsort() call.
  1026. */
  1027. struct hpux_acl_types acl_obj_count;
  1028. int n_class_obj_perm = 0;
  1029. int i, j;
  1030. if(!acl_count) {
  1031. DEBUG(10,("Zero acl count passed. Returning Success\n"));
  1032. return 0;
  1033. }
  1034. if(aclp == NULL) {
  1035. DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
  1036. return -1;
  1037. }
  1038. /* Count different types of ACLs in the ACLs array */
  1039. hpux_count_obj(acl_count, aclp, &acl_obj_count);
  1040. /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
  1041. * CLASS_OBJ and OTHER_OBJ
  1042. */
  1043. if( (acl_obj_count.n_user_obj != 1) ||
  1044. (acl_obj_count.n_group_obj != 1) ||
  1045. (acl_obj_count.n_class_obj != 1) ||
  1046. (acl_obj_count.n_other_obj != 1)
  1047. ) {
  1048. DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
  1049. USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
  1050. return -1;
  1051. }
  1052. /* If any of the default objects are present, there should be only
  1053. * one of them each.
  1054. */
  1055. if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
  1056. (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
  1057. DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
  1058. or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
  1059. return -1;
  1060. }
  1061. /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
  1062. * structures.
  1063. *
  1064. * Sorting crieteria - First sort by ACL type. If there are multiple entries of
  1065. * same ACL type, sort by ACL id.
  1066. *
  1067. * I am using the trival kind of sorting method here because, performance isn't
  1068. * really effected by the ACLs feature. More over there aren't going to be more
  1069. * than 17 entries on HPUX.
  1070. */
  1071. for(i=0; i<acl_count;i++) {
  1072. for (j=i+1; j<acl_count; j++) {
  1073. if( aclp[i].a_type > aclp[j].a_type ) {
  1074. /* ACL entries out of order, swap them */
  1075. hpux_swap_acl_entries((aclp+i), (aclp+j));
  1076. } else if ( aclp[i].a_type == aclp[j].a_type ) {
  1077. /* ACL entries of same type, sort by id */
  1078. if(aclp[i].a_id > aclp[j].a_id) {
  1079. hpux_swap_acl_entries((aclp+i), (aclp+j));
  1080. } else if (aclp[i].a_id == aclp[j].a_id) {
  1081. /* We have a duplicate entry. */
  1082. if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
  1083. DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
  1084. aclp[i].a_type, aclp[i].a_id));
  1085. return -1;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. /* set the class obj permissions to the computed one. */
  1092. if(calclass) {
  1093. int n_class_obj_index = -1;
  1094. for(i=0;i<acl_count;i++) {
  1095. n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
  1096. if(aclp[i].a_type == CLASS_OBJ)
  1097. n_class_obj_index = i;
  1098. }
  1099. aclp[n_class_obj_index].a_perm = n_class_obj_perm;
  1100. }
  1101. return 0;
  1102. #else
  1103. return aclsort(acl_count, calclass, aclp);
  1104. #endif
  1105. }
  1106. /*
  1107. * sort the ACL and check it for validity
  1108. *
  1109. * if it's a minimal ACL with only 4 entries then we
  1110. * need to recalculate the mask permissions to make
  1111. * sure that they are the same as the GROUP_OBJ
  1112. * permissions as required by the UnixWare acl() system call.
  1113. *
  1114. * (note: since POSIX allows minimal ACLs which only contain
  1115. * 3 entries - ie there is no mask entry - we should, in theory,
  1116. * check for this and add a mask entry if necessary - however
  1117. * we "know" that the caller of this interface always specifies
  1118. * a mask so, in practice "this never happens" (tm) - if it *does*
  1119. * happen aclsort() will fail and return an error and someone will
  1120. * have to fix it ...)
  1121. */
  1122. static int acl_sort(SMB_ACL_T acl_d)
  1123. {
  1124. int fixmask = (acl_d->count <= 4);
  1125. if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
  1126. errno = EINVAL;
  1127. return -1;
  1128. }
  1129. return 0;
  1130. }
  1131. int sys_acl_valid(SMB_ACL_T acl_d)
  1132. {
  1133. return acl_sort(acl_d);
  1134. }
  1135. int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
  1136. {
  1137. struct stat s;
  1138. struct acl *acl_p;
  1139. int acl_count;
  1140. struct acl *acl_buf = NULL;
  1141. int ret;
  1142. if(hpux_acl_call_presence() == False) {
  1143. /* Looks like we don't have the acl() system call on HPUX.
  1144. * May be the system doesn't have the latest version of JFS.
  1145. */
  1146. errno=ENOSYS;
  1147. return -1;
  1148. }
  1149. if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
  1150. errno = EINVAL;
  1151. return -1;
  1152. }
  1153. if (acl_sort(acl_d) != 0) {
  1154. return -1;
  1155. }
  1156. acl_p = &acl_d->acl[0];
  1157. acl_count = acl_d->count;
  1158. /*
  1159. * if it's a directory there is extra work to do
  1160. * since the acl() system call will replace both
  1161. * the access ACLs and the default ACLs (if any)
  1162. */
  1163. if (stat(name, &s) != 0) {
  1164. return -1;
  1165. }
  1166. if (S_ISDIR(s.st_mode)) {
  1167. SMB_ACL_T acc_acl;
  1168. SMB_ACL_T def_acl;
  1169. SMB_ACL_T tmp_acl;
  1170. int i;
  1171. if (type == SMB_ACL_TYPE_ACCESS) {
  1172. acc_acl = acl_d;
  1173. def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
  1174. } else {
  1175. def_acl = acl_d;
  1176. acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
  1177. }
  1178. if (tmp_acl == NULL) {
  1179. return -1;
  1180. }
  1181. /*
  1182. * allocate a temporary buffer for the complete ACL
  1183. */
  1184. acl_count = acc_acl->count + def_acl->count;
  1185. acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
  1186. if (acl_buf == NULL) {
  1187. sys_acl_free_acl(tmp_acl);
  1188. errno = ENOMEM;
  1189. return -1;
  1190. }
  1191. /*
  1192. * copy the access control and default entries into the buffer
  1193. */
  1194. memcpy(&acl_buf[0], &acc_acl->acl[0],
  1195. acc_acl->count * sizeof(acl_buf[0]));
  1196. memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
  1197. def_acl->count * sizeof(acl_buf[0]));
  1198. /*
  1199. * set the ACL_DEFAULT flag on the default entries
  1200. */
  1201. for (i = acc_acl->count; i < acl_count; i++) {
  1202. acl_buf[i].a_type |= ACL_DEFAULT;
  1203. }
  1204. sys_acl_free_acl(tmp_acl);
  1205. } else if (type != SMB_ACL_TYPE_ACCESS) {
  1206. errno = EINVAL;
  1207. return -1;
  1208. }
  1209. ret = acl(name, ACL_SET, acl_count, acl_p);
  1210. if (acl_buf) {
  1211. free(acl_buf);
  1212. }
  1213. return ret;
  1214. }
  1215. #if 0
  1216. int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
  1217. {
  1218. /*
  1219. * HPUX doesn't have the facl call. Fake it using the path.... JRA.
  1220. */
  1221. files_struct *fsp = file_find_fd(fd);
  1222. if (fsp == NULL) {
  1223. errno = EBADF;
  1224. return NULL;
  1225. }
  1226. if (acl_sort(acl_d) != 0) {
  1227. return -1;
  1228. }
  1229. /*
  1230. * We know we're in the same conn context. So we
  1231. * can use the relative path.
  1232. */
  1233. return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
  1234. }
  1235. #endif
  1236. int sys_acl_delete_def_file(const char *path)
  1237. {
  1238. SMB_ACL_T acl_d;
  1239. int ret;
  1240. /*
  1241. * fetching the access ACL and rewriting it has
  1242. * the effect of deleting the default ACL
  1243. */
  1244. if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
  1245. return -1;
  1246. }
  1247. ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
  1248. sys_acl_free_acl(acl_d);
  1249. return ret;
  1250. }
  1251. int sys_acl_free_acl(SMB_ACL_T acl_d)
  1252. {
  1253. free(acl_d);
  1254. return 0;
  1255. }
  1256. #elif defined(HAVE_IRIX_ACLS) /*---------------------------------------------*/
  1257. int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  1258. {
  1259. if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
  1260. errno = EINVAL;
  1261. return -1;
  1262. }
  1263. if (entry_p == NULL) {
  1264. errno = EINVAL;
  1265. return -1;
  1266. }
  1267. if (entry_id == SMB_ACL_FIRST_ENTRY) {
  1268. acl_d->next = 0;
  1269. }
  1270. if (acl_d->next < 0) {
  1271. errno = EINVAL;
  1272. return -1;
  1273. }
  1274. if (acl_d->next >= acl_d->aclp->acl_cnt) {
  1275. return 0;
  1276. }
  1277. *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
  1278. return 1;
  1279. }
  1280. int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
  1281. {
  1282. *type_p = entry_d->ae_tag;
  1283. return 0;
  1284. }
  1285. SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
  1286. {
  1287. SMB_ACL_T a;
  1288. if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
  1289. errno = ENOMEM;
  1290. return NULL;
  1291. }
  1292. if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
  1293. SAFE_FREE(a);
  1294. return NULL;
  1295. }
  1296. a->next = -1;
  1297. a->freeaclp = True;
  1298. return a;
  1299. }
  1300. #if 0
  1301. SMB_ACL_T sys_acl_get_fd(int fd)
  1302. {
  1303. SMB_ACL_T a;
  1304. if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
  1305. errno = ENOMEM;
  1306. return NULL;
  1307. }
  1308. if ((a->aclp = acl_get_fd(fd)) == NULL) {
  1309. SAFE_FREE(a);
  1310. return NULL;
  1311. }
  1312. a->next = -1;
  1313. a->freeaclp = True;
  1314. return a;
  1315. }
  1316. #endif
  1317. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  1318. {
  1319. *tag_type_p = entry->ae_tag;
  1320. *bits_p = entry->ae_perm;
  1321. if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP)
  1322. *u_g_id_p = entry->ae_id;
  1323. return 0;
  1324. }
  1325. SMB_ACL_T sys_acl_init(int count)
  1326. {
  1327. SMB_ACL_T a;
  1328. if (count < 0) {
  1329. errno = EINVAL;
  1330. return NULL;
  1331. }
  1332. if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof a[0] + sizeof (struct acl))) == NULL) {
  1333. errno = ENOMEM;
  1334. return NULL;
  1335. }
  1336. a->next = -1;
  1337. a->freeaclp = False;
  1338. a->aclp = (struct acl *)((char *)a + sizeof a[0]);
  1339. a->aclp->acl_cnt = 0;
  1340. return a;
  1341. }
  1342. int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
  1343. {
  1344. SMB_ACL_T acl_d;
  1345. SMB_ACL_ENTRY_T entry_d;
  1346. if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
  1347. errno = EINVAL;
  1348. return -1;
  1349. }
  1350. if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
  1351. errno = ENOSPC;
  1352. return -1;
  1353. }
  1354. entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
  1355. entry_d->ae_tag = 0;
  1356. entry_d->ae_id = 0;
  1357. entry_d->ae_perm = 0;
  1358. *entry_p = entry_d;
  1359. return 0;
  1360. }
  1361. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  1362. {
  1363. entry->ae_tag = tag_type;
  1364. if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP)
  1365. entry->ae_id = u_g_id;
  1366. entry->ae_perm = bits;
  1367. return 0;
  1368. }
  1369. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 bits)
  1370. {
  1371. entry_d->ae_perm = bits;
  1372. return 0;
  1373. }
  1374. int sys_acl_valid(SMB_ACL_T acl_d)
  1375. {
  1376. return acl_valid(acl_d->aclp);
  1377. }
  1378. int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
  1379. {
  1380. return acl_set_file(name, type, acl_d->aclp);
  1381. }
  1382. #if 0
  1383. int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
  1384. {
  1385. return acl_set_fd(fd, acl_d->aclp);
  1386. }
  1387. #endif
  1388. int sys_acl_delete_def_file(const char *name)
  1389. {
  1390. return acl_delete_def_file(name);
  1391. }
  1392. int sys_acl_free_acl(SMB_ACL_T acl_d)
  1393. {
  1394. if (acl_d->freeaclp) {
  1395. acl_free(acl_d->aclp);
  1396. }
  1397. acl_free(acl_d);
  1398. return 0;
  1399. }
  1400. #elif defined(HAVE_AIX_ACLS) /*----------------------------------------------*/
  1401. /* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
  1402. int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  1403. {
  1404. struct acl_entry_link *link;
  1405. struct new_acl_entry *entry;
  1406. int keep_going;
  1407. if (entry_id == SMB_ACL_FIRST_ENTRY)
  1408. theacl->count = 0;
  1409. else if (entry_id != SMB_ACL_NEXT_ENTRY) {
  1410. errno = EINVAL;
  1411. return -1;
  1412. }
  1413. DEBUG(10,("This is the count: %d\n",theacl->count));
  1414. /* Check if count was previously set to -1. *
  1415. * If it was, that means we reached the end *
  1416. * of the acl last time. */
  1417. if(theacl->count == -1)
  1418. return(0);
  1419. link = theacl;
  1420. /* To get to the next acl, traverse linked list until index *
  1421. * of acl matches the count we are keeping. This count is *
  1422. * incremented each time we return an acl entry. */
  1423. for(keep_going = 0; keep_going < theacl->count; keep_going++)
  1424. link = link->nextp;
  1425. entry = *entry_p = link->entryp;
  1426. DEBUG(10,("*entry_p is %d\n",entry_p));
  1427. DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
  1428. /* Increment count */
  1429. theacl->count++;
  1430. if(link->nextp == NULL)
  1431. theacl->count = -1;
  1432. return(1);
  1433. }
  1434. int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
  1435. {
  1436. /* Initialize tag type */
  1437. *tag_type_p = -1;
  1438. DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
  1439. /* Depending on what type of entry we have, *
  1440. * return tag type. */
  1441. switch(entry_d->ace_id->id_type) {
  1442. case ACEID_USER:
  1443. *tag_type_p = SMB_ACL_USER;
  1444. break;
  1445. case ACEID_GROUP:
  1446. *tag_type_p = SMB_ACL_GROUP;
  1447. break;
  1448. case SMB_ACL_USER_OBJ:
  1449. case SMB_ACL_GROUP_OBJ:
  1450. case SMB_ACL_OTHER:
  1451. *tag_type_p = entry_d->ace_id->id_type;
  1452. break;
  1453. default:
  1454. return(-1);
  1455. }
  1456. return(0);
  1457. }
  1458. SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
  1459. {
  1460. struct acl *file_acl = (struct acl *)NULL;
  1461. struct acl_entry *acl_entry;
  1462. struct new_acl_entry *new_acl_entry;
  1463. struct ace_id *idp;
  1464. struct acl_entry_link *acl_entry_link;
  1465. struct acl_entry_link *acl_entry_link_head;
  1466. int i;
  1467. int rc = 0;
  1468. /* AIX has no DEFAULT */
  1469. if ( type == SMB_ACL_TYPE_DEFAULT ) {
  1470. errno = ENOTSUP;
  1471. return NULL;
  1472. }
  1473. /* Get the acl using statacl */
  1474. DEBUG(10,("Entering sys_acl_get_file\n"));
  1475. DEBUG(10,("path_p is %s\n",path_p));
  1476. file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  1477. if(file_acl == NULL) {
  1478. errno=ENOMEM;
  1479. DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
  1480. return(NULL);
  1481. }
  1482. memset(file_acl,0,BUFSIZ);
  1483. rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
  1484. if(rc == -1) {
  1485. DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
  1486. SAFE_FREE(file_acl);
  1487. return(NULL);
  1488. }
  1489. DEBUG(10,("Got facl and returned it\n"));
  1490. /* Point to the first acl entry in the acl */
  1491. acl_entry = file_acl->acl_ext;
  1492. /* Begin setting up the head of the linked list *
  1493. * that will be used for the storing the acl *
  1494. * in a way that is useful for the posix_acls.c *
  1495. * code. */
  1496. acl_entry_link_head = acl_entry_link = sys_acl_init(0);
  1497. if(acl_entry_link_head == NULL)
  1498. return(NULL);
  1499. acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1500. if(acl_entry_link->entryp == NULL) {
  1501. SAFE_FREE(file_acl);
  1502. errno = ENOMEM;
  1503. DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
  1504. return(NULL);
  1505. }
  1506. DEBUG(10,("acl_entry is %d\n",acl_entry));
  1507. DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
  1508. /* Check if the extended acl bit is on. *
  1509. * If it isn't, do not show the *
  1510. * contents of the acl since AIX intends *
  1511. * the extended info to remain unused */
  1512. if(file_acl->acl_mode & S_IXACL){
  1513. /* while we are not pointing to the very end */
  1514. while(acl_entry < acl_last(file_acl)) {
  1515. /* before we malloc anything, make sure this is */
  1516. /* a valid acl entry and one that we want to map */
  1517. idp = id_nxt(acl_entry->ace_id);
  1518. if((acl_entry->ace_type == ACC_SPECIFY ||
  1519. (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
  1520. acl_entry = acl_nxt(acl_entry);
  1521. continue;
  1522. }
  1523. idp = acl_entry->ace_id;
  1524. /* Check if this is the first entry in the linked list. *
  1525. * The first entry needs to keep prevp pointing to NULL *
  1526. * and already has entryp allocated. */
  1527. if(acl_entry_link_head->count != 0) {
  1528. acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
  1529. if(acl_entry_link->nextp == NULL) {
  1530. SAFE_FREE(file_acl);
  1531. errno = ENOMEM;
  1532. DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
  1533. return(NULL);
  1534. }
  1535. acl_entry_link->nextp->prevp = acl_entry_link;
  1536. acl_entry_link = acl_entry_link->nextp;
  1537. acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1538. if(acl_entry_link->entryp == NULL) {
  1539. SAFE_FREE(file_acl);
  1540. errno = ENOMEM;
  1541. DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
  1542. return(NULL);
  1543. }
  1544. acl_entry_link->nextp = NULL;
  1545. }
  1546. acl_entry_link->entryp->ace_len = acl_entry->ace_len;
  1547. /* Don't really need this since all types are going *
  1548. * to be specified but, it's better than leaving it 0 */
  1549. acl_entry_link->entryp->ace_type = acl_entry->ace_type;
  1550. acl_entry_link->entryp->ace_access = acl_entry->ace_access;
  1551. memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
  1552. /* The access in the acl entries must be left shifted by *
  1553. * three bites, because they will ultimately be compared *
  1554. * to S_IRUSR, S_IWUSR, and S_IXUSR. */
  1555. switch(acl_entry->ace_type){
  1556. case ACC_PERMIT:
  1557. case ACC_SPECIFY:
  1558. acl_entry_link->entryp->ace_access = acl_entry->ace_access;
  1559. acl_entry_link->entryp->ace_access <<= 6;
  1560. acl_entry_link_head->count++;
  1561. break;
  1562. case ACC_DENY:
  1563. /* Since there is no way to return a DENY acl entry *
  1564. * change to PERMIT and then shift. */
  1565. DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
  1566. acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
  1567. DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
  1568. acl_entry_link->entryp->ace_access <<= 6;
  1569. acl_entry_link_head->count++;
  1570. break;
  1571. default:
  1572. return(0);
  1573. }
  1574. DEBUG(10,("acl_entry = %d\n",acl_entry));
  1575. DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
  1576. acl_entry = acl_nxt(acl_entry);
  1577. }
  1578. } /* end of if enabled */
  1579. /* Since owner, group, other acl entries are not *
  1580. * part of the acl entries in an acl, they must *
  1581. * be dummied up to become part of the list. */
  1582. for( i = 1; i < 4; i++) {
  1583. DEBUG(10,("i is %d\n",i));
  1584. if(acl_entry_link_head->count != 0) {
  1585. acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
  1586. if(acl_entry_link->nextp == NULL) {
  1587. SAFE_FREE(file_acl);
  1588. errno = ENOMEM;
  1589. DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
  1590. return(NULL);
  1591. }
  1592. acl_entry_link->nextp->prevp = acl_entry_link;
  1593. acl_entry_link = acl_entry_link->nextp;
  1594. acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1595. if(acl_entry_link->entryp == NULL) {
  1596. SAFE_FREE(file_acl);
  1597. errno = ENOMEM;
  1598. DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
  1599. return(NULL);
  1600. }
  1601. }
  1602. acl_entry_link->nextp = NULL;
  1603. new_acl_entry = acl_entry_link->entryp;
  1604. idp = new_acl_entry->ace_id;
  1605. new_acl_entry->ace_len = sizeof(struct acl_entry);
  1606. new_acl_entry->ace_type = ACC_PERMIT;
  1607. idp->id_len = sizeof(struct ace_id);
  1608. DEBUG(10,("idp->id_len = %d\n",idp->id_len));
  1609. memset(idp->id_data,0,sizeof(uid_t));
  1610. switch(i) {
  1611. case 2:
  1612. new_acl_entry->ace_access = file_acl->g_access << 6;
  1613. idp->id_type = SMB_ACL_GROUP_OBJ;
  1614. break;
  1615. case 3:
  1616. new_acl_entry->ace_access = file_acl->o_access << 6;
  1617. idp->id_type = SMB_ACL_OTHER;
  1618. break;
  1619. case 1:
  1620. new_acl_entry->ace_access = file_acl->u_access << 6;
  1621. idp->id_type = SMB_ACL_USER_OBJ;
  1622. break;
  1623. default:
  1624. return(NULL);
  1625. }
  1626. acl_entry_link_head->count++;
  1627. DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
  1628. }
  1629. acl_entry_link_head->count = 0;
  1630. SAFE_FREE(file_acl);
  1631. return(acl_entry_link_head);
  1632. }
  1633. #if 0
  1634. SMB_ACL_T sys_acl_get_fd(int fd)
  1635. {
  1636. struct acl *file_acl = (struct acl *)NULL;
  1637. struct acl_entry *acl_entry;
  1638. struct new_acl_entry *new_acl_entry;
  1639. struct ace_id *idp;
  1640. struct acl_entry_link *acl_entry_link;
  1641. struct acl_entry_link *acl_entry_link_head;
  1642. int i;
  1643. int rc = 0;
  1644. /* Get the acl using fstatacl */
  1645. DEBUG(10,("Entering sys_acl_get_fd\n"));
  1646. DEBUG(10,("fd is %d\n",fd));
  1647. file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  1648. if(file_acl == NULL) {
  1649. errno=ENOMEM;
  1650. DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
  1651. return(NULL);
  1652. }
  1653. memset(file_acl,0,BUFSIZ);
  1654. rc = fstatacl(fd,0,file_acl,BUFSIZ);
  1655. if(rc == -1) {
  1656. DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
  1657. SAFE_FREE(file_acl);
  1658. return(NULL);
  1659. }
  1660. DEBUG(10,("Got facl and returned it\n"));
  1661. /* Point to the first acl entry in the acl */
  1662. acl_entry = file_acl->acl_ext;
  1663. /* Begin setting up the head of the linked list *
  1664. * that will be used for the storing the acl *
  1665. * in a way that is useful for the posix_acls.c *
  1666. * code. */
  1667. acl_entry_link_head = acl_entry_link = sys_acl_init(0);
  1668. if(acl_entry_link_head == NULL){
  1669. SAFE_FREE(file_acl);
  1670. return(NULL);
  1671. }
  1672. acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1673. if(acl_entry_link->entryp == NULL) {
  1674. errno = ENOMEM;
  1675. DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
  1676. SAFE_FREE(file_acl);
  1677. return(NULL);
  1678. }
  1679. DEBUG(10,("acl_entry is %d\n",acl_entry));
  1680. DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
  1681. /* Check if the extended acl bit is on. *
  1682. * If it isn't, do not show the *
  1683. * contents of the acl since AIX intends *
  1684. * the extended info to remain unused */
  1685. if(file_acl->acl_mode & S_IXACL){
  1686. /* while we are not pointing to the very end */
  1687. while(acl_entry < acl_last(file_acl)) {
  1688. /* before we malloc anything, make sure this is */
  1689. /* a valid acl entry and one that we want to map */
  1690. idp = id_nxt(acl_entry->ace_id);
  1691. if((acl_entry->ace_type == ACC_SPECIFY ||
  1692. (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
  1693. acl_entry = acl_nxt(acl_entry);
  1694. continue;
  1695. }
  1696. idp = acl_entry->ace_id;
  1697. /* Check if this is the first entry in the linked list. *
  1698. * The first entry needs to keep prevp pointing to NULL *
  1699. * and already has entryp allocated. */
  1700. if(acl_entry_link_head->count != 0) {
  1701. acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
  1702. if(acl_entry_link->nextp == NULL) {
  1703. errno = ENOMEM;
  1704. DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
  1705. SAFE_FREE(file_acl);
  1706. return(NULL);
  1707. }
  1708. acl_entry_link->nextp->prevp = acl_entry_link;
  1709. acl_entry_link = acl_entry_link->nextp;
  1710. acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1711. if(acl_entry_link->entryp == NULL) {
  1712. errno = ENOMEM;
  1713. DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
  1714. SAFE_FREE(file_acl);
  1715. return(NULL);
  1716. }
  1717. acl_entry_link->nextp = NULL;
  1718. }
  1719. acl_entry_link->entryp->ace_len = acl_entry->ace_len;
  1720. /* Don't really need this since all types are going *
  1721. * to be specified but, it's better than leaving it 0 */
  1722. acl_entry_link->entryp->ace_type = acl_entry->ace_type;
  1723. acl_entry_link->entryp->ace_access = acl_entry->ace_access;
  1724. memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
  1725. /* The access in the acl entries must be left shifted by *
  1726. * three bites, because they will ultimately be compared *
  1727. * to S_IRUSR, S_IWUSR, and S_IXUSR. */
  1728. switch(acl_entry->ace_type){
  1729. case ACC_PERMIT:
  1730. case ACC_SPECIFY:
  1731. acl_entry_link->entryp->ace_access = acl_entry->ace_access;
  1732. acl_entry_link->entryp->ace_access <<= 6;
  1733. acl_entry_link_head->count++;
  1734. break;
  1735. case ACC_DENY:
  1736. /* Since there is no way to return a DENY acl entry *
  1737. * change to PERMIT and then shift. */
  1738. DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
  1739. acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
  1740. DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
  1741. acl_entry_link->entryp->ace_access <<= 6;
  1742. acl_entry_link_head->count++;
  1743. break;
  1744. default:
  1745. return(0);
  1746. }
  1747. DEBUG(10,("acl_entry = %d\n",acl_entry));
  1748. DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
  1749. acl_entry = acl_nxt(acl_entry);
  1750. }
  1751. } /* end of if enabled */
  1752. /* Since owner, group, other acl entries are not *
  1753. * part of the acl entries in an acl, they must *
  1754. * be dummied up to become part of the list. */
  1755. for( i = 1; i < 4; i++) {
  1756. DEBUG(10,("i is %d\n",i));
  1757. if(acl_entry_link_head->count != 0){
  1758. acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
  1759. if(acl_entry_link->nextp == NULL) {
  1760. errno = ENOMEM;
  1761. DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
  1762. SAFE_FREE(file_acl);
  1763. return(NULL);
  1764. }
  1765. acl_entry_link->nextp->prevp = acl_entry_link;
  1766. acl_entry_link = acl_entry_link->nextp;
  1767. acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1768. if(acl_entry_link->entryp == NULL) {
  1769. SAFE_FREE(file_acl);
  1770. errno = ENOMEM;
  1771. DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
  1772. return(NULL);
  1773. }
  1774. }
  1775. acl_entry_link->nextp = NULL;
  1776. new_acl_entry = acl_entry_link->entryp;
  1777. idp = new_acl_entry->ace_id;
  1778. new_acl_entry->ace_len = sizeof(struct acl_entry);
  1779. new_acl_entry->ace_type = ACC_PERMIT;
  1780. idp->id_len = sizeof(struct ace_id);
  1781. DEBUG(10,("idp->id_len = %d\n",idp->id_len));
  1782. memset(idp->id_data,0,sizeof(uid_t));
  1783. switch(i) {
  1784. case 2:
  1785. new_acl_entry->ace_access = file_acl->g_access << 6;
  1786. idp->id_type = SMB_ACL_GROUP_OBJ;
  1787. break;
  1788. case 3:
  1789. new_acl_entry->ace_access = file_acl->o_access << 6;
  1790. idp->id_type = SMB_ACL_OTHER;
  1791. break;
  1792. case 1:
  1793. new_acl_entry->ace_access = file_acl->u_access << 6;
  1794. idp->id_type = SMB_ACL_USER_OBJ;
  1795. break;
  1796. default:
  1797. return(NULL);
  1798. }
  1799. acl_entry_link_head->count++;
  1800. DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
  1801. }
  1802. acl_entry_link_head->count = 0;
  1803. SAFE_FREE(file_acl);
  1804. return(acl_entry_link_head);
  1805. }
  1806. #endif
  1807. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  1808. {
  1809. uint *permset;
  1810. if (sys_acl_get_tag_type(entry, tag_type_p) != 0)
  1811. return -1;
  1812. if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP)
  1813. memcpy(u_g_id_p, entry->ace_id->id_data, sizeof (id_t));
  1814. permset = &entry->ace_access;
  1815. DEBUG(10,("*permset is %d\n",*permset));
  1816. *bits_p = (*permset & S_IRUSR ? 4 : 0)
  1817. | (*permset & S_IWUSR ? 2 : 0)
  1818. | (*permset & S_IXUSR ? 1 : 0);
  1819. return 0;
  1820. }
  1821. SMB_ACL_T sys_acl_init( int count)
  1822. {
  1823. struct acl_entry_link *theacl = NULL;
  1824. if (count < 0) {
  1825. errno = EINVAL;
  1826. return NULL;
  1827. }
  1828. DEBUG(10,("Entering sys_acl_init\n"));
  1829. theacl = SMB_MALLOC_P(struct acl_entry_link);
  1830. if(theacl == NULL) {
  1831. errno = ENOMEM;
  1832. DEBUG(0,("Error in sys_acl_init is %d\n",errno));
  1833. return(NULL);
  1834. }
  1835. theacl->count = 0;
  1836. theacl->nextp = NULL;
  1837. theacl->prevp = NULL;
  1838. theacl->entryp = NULL;
  1839. DEBUG(10,("Exiting sys_acl_init\n"));
  1840. return(theacl);
  1841. }
  1842. int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
  1843. {
  1844. struct acl_entry_link *theacl;
  1845. struct acl_entry_link *acl_entryp;
  1846. struct acl_entry_link *temp_entry;
  1847. int counting;
  1848. DEBUG(10,("Entering the sys_acl_create_entry\n"));
  1849. theacl = acl_entryp = *pacl;
  1850. /* Get to the end of the acl before adding entry */
  1851. for(counting=0; counting < theacl->count; counting++){
  1852. DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
  1853. temp_entry = acl_entryp;
  1854. acl_entryp = acl_entryp->nextp;
  1855. }
  1856. if(theacl->count != 0){
  1857. temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
  1858. if(acl_entryp == NULL) {
  1859. errno = ENOMEM;
  1860. DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
  1861. return(-1);
  1862. }
  1863. DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
  1864. acl_entryp->prevp = temp_entry;
  1865. DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
  1866. }
  1867. *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
  1868. if(*pentry == NULL) {
  1869. errno = ENOMEM;
  1870. DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
  1871. return(-1);
  1872. }
  1873. memset(*pentry,0,sizeof(struct new_acl_entry));
  1874. acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
  1875. acl_entryp->entryp->ace_type = ACC_PERMIT;
  1876. acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
  1877. acl_entryp->nextp = NULL;
  1878. theacl->count++;
  1879. DEBUG(10,("Exiting sys_acl_create_entry\n"));
  1880. return(0);
  1881. }
  1882. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  1883. {
  1884. entry->ace_id->id_type = tag_type;
  1885. DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
  1886. if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP)
  1887. memcpy(entry->ace_id->id_data, &u_g_id, sizeof (id_t));
  1888. entry->ace_access = bits;
  1889. DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
  1890. return 0;
  1891. }
  1892. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits)
  1893. {
  1894. DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
  1895. entry->ace_access = bits;
  1896. DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
  1897. DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
  1898. return(0);
  1899. }
  1900. int sys_acl_valid( SMB_ACL_T theacl )
  1901. {
  1902. int user_obj = 0;
  1903. int group_obj = 0;
  1904. int other_obj = 0;
  1905. struct acl_entry_link *acl_entry;
  1906. for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
  1907. user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
  1908. group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
  1909. other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
  1910. }
  1911. DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
  1912. if(user_obj != 1 || group_obj != 1 || other_obj != 1)
  1913. return(-1);
  1914. return(0);
  1915. }
  1916. int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
  1917. {
  1918. struct acl_entry_link *acl_entry_link = NULL;
  1919. struct acl *file_acl = NULL;
  1920. struct acl *file_acl_temp = NULL;
  1921. struct acl_entry *acl_entry = NULL;
  1922. struct ace_id *ace_id = NULL;
  1923. uint id_type;
  1924. uint user_id;
  1925. uint acl_length;
  1926. uint rc;
  1927. DEBUG(10,("Entering sys_acl_set_file\n"));
  1928. DEBUG(10,("File name is %s\n",name));
  1929. /* AIX has no default ACL */
  1930. if(acltype == SMB_ACL_TYPE_DEFAULT)
  1931. return(0);
  1932. acl_length = BUFSIZ;
  1933. file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  1934. if(file_acl == NULL) {
  1935. errno = ENOMEM;
  1936. DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
  1937. return(-1);
  1938. }
  1939. memset(file_acl,0,BUFSIZ);
  1940. file_acl->acl_len = ACL_SIZ;
  1941. file_acl->acl_mode = S_IXACL;
  1942. for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
  1943. acl_entry_link->entryp->ace_access >>= 6;
  1944. id_type = acl_entry_link->entryp->ace_id->id_type;
  1945. switch(id_type) {
  1946. case SMB_ACL_USER_OBJ:
  1947. file_acl->u_access = acl_entry_link->entryp->ace_access;
  1948. continue;
  1949. case SMB_ACL_GROUP_OBJ:
  1950. file_acl->g_access = acl_entry_link->entryp->ace_access;
  1951. continue;
  1952. case SMB_ACL_OTHER:
  1953. file_acl->o_access = acl_entry_link->entryp->ace_access;
  1954. continue;
  1955. case SMB_ACL_MASK:
  1956. continue;
  1957. }
  1958. if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
  1959. acl_length += sizeof(struct acl_entry);
  1960. file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
  1961. if(file_acl_temp == NULL) {
  1962. SAFE_FREE(file_acl);
  1963. errno = ENOMEM;
  1964. DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
  1965. return(-1);
  1966. }
  1967. memcpy(file_acl_temp,file_acl,file_acl->acl_len);
  1968. SAFE_FREE(file_acl);
  1969. file_acl = file_acl_temp;
  1970. }
  1971. acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
  1972. file_acl->acl_len += sizeof(struct acl_entry);
  1973. acl_entry->ace_len = acl_entry_link->entryp->ace_len;
  1974. acl_entry->ace_access = acl_entry_link->entryp->ace_access;
  1975. /* In order to use this, we'll need to wait until we can get denies */
  1976. /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
  1977. acl_entry->ace_type = ACC_SPECIFY; */
  1978. acl_entry->ace_type = ACC_SPECIFY;
  1979. ace_id = acl_entry->ace_id;
  1980. ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
  1981. DEBUG(10,("The id type is %d\n",ace_id->id_type));
  1982. ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
  1983. memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
  1984. memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
  1985. }
  1986. rc = chacl((char*)name,file_acl,file_acl->acl_len);
  1987. DEBUG(10,("errno is %d\n",errno));
  1988. DEBUG(10,("return code is %d\n",rc));
  1989. SAFE_FREE(file_acl);
  1990. DEBUG(10,("Exiting the sys_acl_set_file\n"));
  1991. return(rc);
  1992. }
  1993. #if 0
  1994. int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
  1995. {
  1996. struct acl_entry_link *acl_entry_link = NULL;
  1997. struct acl *file_acl = NULL;
  1998. struct acl *file_acl_temp = NULL;
  1999. struct acl_entry *acl_entry = NULL;
  2000. struct ace_id *ace_id = NULL;
  2001. uint id_type;
  2002. uint user_id;
  2003. uint acl_length;
  2004. uint rc;
  2005. DEBUG(10,("Entering sys_acl_set_fd\n"));
  2006. acl_length = BUFSIZ;
  2007. file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  2008. if(file_acl == NULL) {
  2009. errno = ENOMEM;
  2010. DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
  2011. return(-1);
  2012. }
  2013. memset(file_acl,0,BUFSIZ);
  2014. file_acl->acl_len = ACL_SIZ;
  2015. file_acl->acl_mode = S_IXACL;
  2016. for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
  2017. acl_entry_link->entryp->ace_access >>= 6;
  2018. id_type = acl_entry_link->entryp->ace_id->id_type;
  2019. DEBUG(10,("The id_type is %d\n",id_type));
  2020. switch(id_type) {
  2021. case SMB_ACL_USER_OBJ:
  2022. file_acl->u_access = acl_entry_link->entryp->ace_access;
  2023. continue;
  2024. case SMB_ACL_GROUP_OBJ:
  2025. file_acl->g_access = acl_entry_link->entryp->ace_access;
  2026. continue;
  2027. case SMB_ACL_OTHER:
  2028. file_acl->o_access = acl_entry_link->entryp->ace_access;
  2029. continue;
  2030. case SMB_ACL_MASK:
  2031. continue;
  2032. }
  2033. if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
  2034. acl_length += sizeof(struct acl_entry);
  2035. file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
  2036. if(file_acl_temp == NULL) {
  2037. SAFE_FREE(file_acl);
  2038. errno = ENOMEM;
  2039. DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
  2040. return(-1);
  2041. }
  2042. memcpy(file_acl_temp,file_acl,file_acl->acl_len);
  2043. SAFE_FREE(file_acl);
  2044. file_acl = file_acl_temp;
  2045. }
  2046. acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
  2047. file_acl->acl_len += sizeof(struct acl_entry);
  2048. acl_entry->ace_len = acl_entry_link->entryp->ace_len;
  2049. acl_entry->ace_access = acl_entry_link->entryp->ace_access;
  2050. /* In order to use this, we'll need to wait until we can get denies */
  2051. /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
  2052. acl_entry->ace_type = ACC_SPECIFY; */
  2053. acl_entry->ace_type = ACC_SPECIFY;
  2054. ace_id = acl_entry->ace_id;
  2055. ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
  2056. DEBUG(10,("The id type is %d\n",ace_id->id_type));
  2057. ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
  2058. memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
  2059. memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
  2060. }
  2061. rc = fchacl(fd,file_acl,file_acl->acl_len);
  2062. DEBUG(10,("errno is %d\n",errno));
  2063. DEBUG(10,("return code is %d\n",rc));
  2064. SAFE_FREE(file_acl);
  2065. DEBUG(10,("Exiting sys_acl_set_fd\n"));
  2066. return(rc);
  2067. }
  2068. #endif
  2069. int sys_acl_delete_def_file(UNUSED(const char *name))
  2070. {
  2071. /* AIX has no default ACL */
  2072. return 0;
  2073. }
  2074. int sys_acl_free_acl(SMB_ACL_T posix_acl)
  2075. {
  2076. struct acl_entry_link *acl_entry_link;
  2077. for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
  2078. SAFE_FREE(acl_entry_link->prevp->entryp);
  2079. SAFE_FREE(acl_entry_link->prevp);
  2080. }
  2081. SAFE_FREE(acl_entry_link->prevp->entryp);
  2082. SAFE_FREE(acl_entry_link->prevp);
  2083. SAFE_FREE(acl_entry_link->entryp);
  2084. SAFE_FREE(acl_entry_link);
  2085. return(0);
  2086. }
  2087. #elif defined(HAVE_OSX_ACLS) /*----------------------------------------------*/
  2088. #define OSX_BROKEN_GETENTRY /* returns 0 instead of 1 */
  2089. #include <membership.h>
  2090. int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
  2091. {
  2092. int ret = acl_get_entry(the_acl, entry_id, entry_p);
  2093. #ifdef OSX_BROKEN_GETENTRY
  2094. if (ret == 0)
  2095. ret = 1;
  2096. else if (ret == -1 && errno == 22)
  2097. ret = 0;
  2098. #endif
  2099. return ret;
  2100. }
  2101. SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
  2102. {
  2103. if (type == ACL_TYPE_DEFAULT) {
  2104. errno = ENOTSUP;
  2105. return NULL;
  2106. }
  2107. errno = 0;
  2108. return acl_get_file(path_p, type);
  2109. }
  2110. #if 0
  2111. SMB_ACL_T sys_acl_get_fd(int fd)
  2112. {
  2113. return acl_get_fd(fd);
  2114. }
  2115. #endif
  2116. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p)
  2117. {
  2118. uuid_t *uup;
  2119. acl_tag_t tag;
  2120. acl_flagset_t flagset;
  2121. acl_permset_t permset;
  2122. uint32 bits, fb, bb, pb;
  2123. int id_type = -1;
  2124. int rc;
  2125. if (acl_get_tag_type(entry, &tag) != 0
  2126. || acl_get_flagset_np(entry, &flagset) != 0
  2127. || acl_get_permset(entry, &permset) != 0
  2128. || (uup = acl_get_qualifier(entry)) == NULL)
  2129. return -1;
  2130. rc = mbr_uuid_to_id(*uup, u_g_id_p, &id_type);
  2131. acl_free(uup);
  2132. if (rc != 0)
  2133. return rc;
  2134. if (id_type == ID_TYPE_UID)
  2135. *tag_type_p = SMB_ACL_USER;
  2136. else
  2137. *tag_type_p = SMB_ACL_GROUP;
  2138. bits = tag == ACL_EXTENDED_ALLOW ? 1 : 0;
  2139. for (fb = (1u<<4), bb = (1u<<1); bb < (1u<<12); fb *= 2, bb *= 2) {
  2140. if (acl_get_flag_np(flagset, fb) == 1)
  2141. bits |= bb;
  2142. }
  2143. for (pb = (1u<<1), bb = (1u<<12); bb < (1u<<25); pb *= 2, bb *= 2) {
  2144. if (acl_get_perm_np(permset, pb) == 1)
  2145. bits |= bb;
  2146. }
  2147. *bits_p = bits;
  2148. return 0;
  2149. }
  2150. SMB_ACL_T sys_acl_init(int count)
  2151. {
  2152. return acl_init(count);
  2153. }
  2154. int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
  2155. {
  2156. return acl_create_entry(pacl, pentry);
  2157. }
  2158. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id)
  2159. {
  2160. acl_flagset_t flagset;
  2161. acl_permset_t permset;
  2162. uint32 fb, bb, pb;
  2163. int is_user = tag_type == SMB_ACL_USER;
  2164. uuid_t uu;
  2165. int rc;
  2166. tag_type = bits & 1 ? ACL_EXTENDED_ALLOW : ACL_EXTENDED_DENY;
  2167. if (acl_get_flagset_np(entry, &flagset) != 0
  2168. || acl_get_permset(entry, &permset) != 0)
  2169. return -1;
  2170. acl_clear_flags_np(flagset);
  2171. acl_clear_perms(permset);
  2172. for (fb = (1u<<4), bb = (1u<<1); bb < (1u<<12); fb *= 2, bb *= 2) {
  2173. if (bits & bb)
  2174. acl_add_flag_np(flagset, fb);
  2175. }
  2176. for (pb = (1u<<1), bb = (1u<<12); bb < (1u<<25); pb *= 2, bb *= 2) {
  2177. if (bits & bb)
  2178. acl_add_perm(permset, pb);
  2179. }
  2180. if (is_user)
  2181. rc = mbr_uid_to_uuid(u_g_id, uu);
  2182. else
  2183. rc = mbr_gid_to_uuid(u_g_id, uu);
  2184. if (rc != 0)
  2185. return rc;
  2186. if (acl_set_tag_type(entry, tag_type) != 0
  2187. || acl_set_qualifier(entry, &uu) != 0
  2188. || acl_set_permset(entry, permset) != 0
  2189. || acl_set_flagset_np(entry, flagset) != 0)
  2190. return -1;
  2191. return 0;
  2192. }
  2193. #if 0
  2194. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits)
  2195. {
  2196. return -1; /* Not needed for OS X. */
  2197. }
  2198. #endif
  2199. int sys_acl_valid(SMB_ACL_T theacl)
  2200. {
  2201. return acl_valid(theacl);
  2202. }
  2203. int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
  2204. {
  2205. return acl_set_file(name, acltype, theacl);
  2206. }
  2207. #if 0
  2208. int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
  2209. {
  2210. return acl_set_fd(fd, theacl);
  2211. }
  2212. #endif
  2213. int sys_acl_delete_def_file(const char *name)
  2214. {
  2215. return acl_delete_def_file(name);
  2216. }
  2217. int sys_acl_free_acl(SMB_ACL_T the_acl)
  2218. {
  2219. return acl_free(the_acl);
  2220. }
  2221. #else /* No ACLs. */
  2222. #error No ACL functions defined for this platform!
  2223. #endif
  2224. /************************************************************************
  2225. Deliberately outside the ACL defines. Return 1 if this is a "no acls"
  2226. errno, 0 if not.
  2227. ************************************************************************/
  2228. int no_acl_syscall_error(int err)
  2229. {
  2230. #ifdef HAVE_OSX_ACLS
  2231. if (err == ENOENT)
  2232. return 1; /* Weird problem with directory ACLs. */
  2233. #endif
  2234. #if defined(ENOSYS)
  2235. if (err == ENOSYS) {
  2236. return 1;
  2237. }
  2238. #endif
  2239. #if defined(ENOTSUP)
  2240. if (err == ENOTSUP) {
  2241. return 1;
  2242. }
  2243. #endif
  2244. return 0;
  2245. }
  2246. #endif /* SUPPORT_ACLS */