4 #include <OSD_WhoAmI.hxx>
5 #include <OSD_Protection.ixx>
9 // Ci-joint le tableau de gestion des protection (Ajout et Retrait). Les
10 // tableaux sont des tableaux a deux dimensions, indices par l'enumeration
11 // OSD_SingleProtection. Il y a en tout 16 possibilites dans l enumeration.
12 // Voir JPT pour tous renseignements....
14 static OSD_SingleProtection TabProtAdd [16][16] =
16 {OSD_None,OSD_R,OSD_W,OSD_RW,OSD_X,OSD_RX,OSD_WX,OSD_RWX,OSD_D,OSD_RD,OSD_WD,OSD_RWD,OSD_XD,OSD_RXD,OSD_WXD,OSD_RWXD},
18 {OSD_R,OSD_R,OSD_RW,OSD_RW,OSD_RX,OSD_RX,OSD_RWX,OSD_RWX,OSD_RD,OSD_RD,OSD_RWD,OSD_RWD,OSD_RXD,OSD_RXD,OSD_RWXD,OSD_RWXD},
20 {OSD_W,OSD_RW,OSD_W,OSD_RW,OSD_WX,OSD_RWX,OSD_WX,OSD_RWX,OSD_WD,OSD_RWD,OSD_WD,OSD_RWD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD},
22 {OSD_RW,OSD_RW,OSD_RW,OSD_RW,OSD_RWX,OSD_RWX,OSD_RWX,OSD_RWX,OSD_RWD,OSD_RWD,OSD_RWD,OSD_RWD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD},
24 {OSD_X,OSD_RX,OSD_WX,OSD_RWX,OSD_X,OSD_RX,OSD_WX,OSD_RWX,OSD_XD,OSD_RXD,OSD_WXD,OSD_RWXD,OSD_XD,OSD_RXD,OSD_WXD,OSD_RWXD},
26 {OSD_RX,OSD_RX,OSD_RWX,OSD_RWX,OSD_RX,OSD_RX,OSD_RWX,OSD_RWX,OSD_RXD,OSD_RXD,OSD_RWXD,OSD_RWXD,OSD_RXD,OSD_RXD,OSD_RWXD,OSD_RWXD},
28 {OSD_WX,OSD_RWX,OSD_RWX,OSD_RWX,OSD_WX,OSD_RWX,OSD_WX,OSD_RWX,OSD_WXD,OSD_RWXD,OS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D,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD},
46 {OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD,OSD_RWXD}
50 // -----------------------
52 static OSD_SingleProtection TabProtSub [16][16] =
54 {OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None},
56 {OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None},
58 {OSD_W,OSD_W,OSD_None,OSD_None,OSD_W,OSD_W,OSD_None,OSD_None,OSD_W,OSD_W,OSD_None,OSD_None,OSD_W,OSD_W,OSD_None,OSD_None},
60 {OSD_RW,OSD_W,OSD_R,OSD_None,OSD_RW,OSD_W,OSD_R,OSD_None,OSD_RW,OSD_W,OSD_R,OSD_None,OSD_RW,OSD_W,OSD_R,OSD_None},
62 {OSD_X,OSD_X,OSD_X,OSD_None,OSD_None,OSD_None,OSD_None,OSD_X,OSD_X,OSD_X,OSD_X,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None},
64 {OSD_RX,OSD_X,OSD_RX,OSD_X,OSD_R,OSD_None,OSD_R,OSD_None,OSD_RX,OSD_X,OSD_RX,OSD_X,OSD_R,OSD_None,OSD_R,OSD_None},
66 {OSD_WX,OSD_WX,OSD_X,OSD_X,OSD_W,OSD_W,OSD_None,OSD_None,OSD_WX,OSD_WX,OSD_X,OSD_X,OSD_W,OSD_W,OSD_None,OSD_None},
68 {OSD_RWX,OSD_WX,OSD_RX,OSD_X,OSD_RW,OSD_W,OSD_R,OSD_None,OSD_RWX,OSD_WX,OSD_RX,OSD_X,OSD_RW,OSD_W,OSD_R,OSD_None},
70 {OSD_D,OSD_D,OSD_D,OSD_D,OSD_D,OSD_D,OSD_D,OSD_D,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None,OSD_None},
72 {OSD_RD,OSD_D,OSD_RD,OSD_D,OSD_RD,OSD_D,OSD_RD,OSD_D,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None,OSD_R,OSD_None},
74 {OSD_WD,OSD_WD,OSD_D,OSD_D,OSD_WD,OSD_WD,OSD_D,OSD_D,OSD_W,OSD_W,OSD_None,OSD_None,OSD_W,OSD_W,OSD_None,OSD_None},
76 {OSD_RWD,OSD_WD,OSD_RD,OSD_D,OSD_RWD,OSD_WD,OSD_RD,OSD_D,OSD_RW,OSD_W,OSD_R,OSD_None,OSD_RW,OSD_W,OSD_R,OSD_None},
78 {OSD_XD,OSD_XD,OSD_XD,OSD_XD,OSD_D,OSD_D,OSD_D,OSD_D,OSD_X,OSD_X,OSD_X,OSD_X,OSD_None,OSD_None,OSD_None,OSD_None},
80 {OSD_RXD,OSD_XD,OSD_RXD,OSD_XD,OSD_RD,OSD_D,OSD_RD,OSD_D,OSD_RX,OSD_X,OSD_RX,OSD_X,OSD_R,OSD_None,OSD_R,OSD_None},
82 {OSD_WXD,OSD_WXD,OSD_XD,OSD_XD,OSD_WD,OSD_WD,OSD_D,OSD_D,OSD_WX,OSD_WX,OSD_X,OSD_X,OSD_W,OSD_W,OSD_None,OSD_None},
84 {OSD_RWXD,OSD_WXD,OSD_RXD,OSD_XD,OSD_RWD,OSD_WD,OSD_RD,OSD_D,OSD_RWX,OSD_WX,OSD_RX,OSD_X,OSD_RW,OSD_W,OSD_R,OSD_None}
87 //const OSD_WhoAmI Iam = OSD_WProtection;
90 // Initialize System, Group, World for read only and User for read & write
92 OSD_Protection::OSD_Protection(){
99 OSD_Protection::OSD_Protection(const OSD_SingleProtection System,
100 const OSD_SingleProtection User,
101 const OSD_SingleProtection Group,
102 const OSD_SingleProtection World){
110 void OSD_Protection::Values(OSD_SingleProtection& System,
111 OSD_SingleProtection& User,
112 OSD_SingleProtection& Group,
113 OSD_SingleProtection& World){
121 void OSD_Protection::SetValues(const OSD_SingleProtection System,
122 const OSD_SingleProtection User,
123 const OSD_SingleProtection Group,
124 const OSD_SingleProtection World){
133 void OSD_Protection::SetSystem (const OSD_SingleProtection priv){
137 void OSD_Protection::SetUser (const OSD_SingleProtection priv){
141 void OSD_Protection::SetGroup (const OSD_SingleProtection priv){
145 void OSD_Protection::SetWorld (const OSD_SingleProtection priv){
150 OSD_SingleProtection OSD_Protection::System()const{
154 OSD_SingleProtection OSD_Protection::User()const{
158 OSD_SingleProtection OSD_Protection::Group()const{
162 OSD_SingleProtection OSD_Protection::World()const{
167 void OSD_Protection::Add(OSD_SingleProtection& aProtection,
168 const OSD_SingleProtection aRight){
169 aProtection = TabProtAdd[aProtection][aRight];
173 void OSD_Protection::Sub(OSD_SingleProtection& aProtection,
174 const OSD_SingleProtection aRight){
175 aProtection = TabProtSub[aProtection][aRight];
179 /* Get internal UNIX's access rights for user, group and other */
181 Standard_Integer OSD_Protection::Internal()const{
183 Standard_Integer internal_prot = 0;
185 if (u & OSD_R) internal_prot |= S_IRUSR;
186 if (u & OSD_W) internal_prot |= S_IWUSR;
187 if (u & OSD_D) internal_prot |= S_IWUSR;
188 if (u & OSD_X) internal_prot |= S_IXUSR;
190 if (g & OSD_R) internal_prot |= S_IRGRP;
191 if (g & OSD_W) internal_prot |= S_IWGRP;
192 if (g & OSD_D) internal_prot |= S_IWGRP;
193 if (g & OSD_X) internal_prot |= S_IXGRP;
195 if (w & OSD_R) internal_prot |= S_IROTH;
196 if (w & OSD_W) internal_prot |= S_IWOTH;
197 if (w & OSD_D) internal_prot |= S_IWOTH;
198 if (w & OSD_X) internal_prot |= S_IXOTH;
200 if (s & OSD_R) internal_prot |= S_IROTH;
201 if (s & OSD_W) internal_prot |= S_IWOTH;
202 if (s & OSD_D) internal_prot |= S_IWOTH;
203 if (s & OSD_X) internal_prot |= S_IXOTH;
205 return ( internal_prot );
211 //------------------------------------------------------------------------
212 //------------------- WNT Sources of OSD_Protection ---------------------
213 //------------------------------------------------------------------------
215 #include <OSD_Protection.hxx>
217 #define FLAG_READ 0x00000001
218 #define FLAG_WRITE 0x00000002
219 #define FLAG_EXECUTE 0x00000004
220 #define FLAG_DELETE 0x00000008
222 static Standard_Integer __fastcall _get_mask ( OSD_SingleProtection );
223 static OSD_SingleProtection __fastcall _get_prot ( Standard_Integer );
225 OSD_Protection :: OSD_Protection () {
232 } // end constructor ( 1 )
234 OSD_Protection :: OSD_Protection (
235 const OSD_SingleProtection System,
236 const OSD_SingleProtection User,
237 const OSD_SingleProtection Group,
238 const OSD_SingleProtection World
241 SetValues ( System, User, Group, World );
243 } // end constructor ( 2 )
245 void OSD_Protection :: Values (
246 OSD_SingleProtection& System,
247 OSD_SingleProtection& User,
248 OSD_SingleProtection& Group,
249 OSD_SingleProtection& World
256 } // end OSD_Protection :: Values
258 void OSD_Protection :: SetValues (
259 const OSD_SingleProtection System,
260 const OSD_SingleProtection User,
261 const OSD_SingleProtection Group,
262 const OSD_SingleProtection World
270 } // end OSD_Protection :: SetValues
272 void OSD_Protection :: SetSystem ( const OSD_SingleProtection priv ) {
276 } // end OSD_Protection :: SetSystem
278 void OSD_Protection :: SetUser ( const OSD_SingleProtection priv ) {
282 } // end OSD_Protection :: SetUser
284 void OSD_Protection :: SetGroup ( const OSD_SingleProtection priv ) {
288 } // end OSD_Protection :: SetGroup
290 void OSD_Protection :: SetWorld ( const OSD_SingleProtection priv ) {
294 } // end OSD_Protection :: SetWorld
296 OSD_SingleProtection OSD_Protection :: System () const {
300 } // end OSD_Protection :: System
302 OSD_SingleProtection OSD_Protection :: User () const {
306 } // end OSD_Protection :: User
308 OSD_SingleProtection OSD_Protection :: Group () const {
312 } // end OSD_Protection :: Group
314 OSD_SingleProtection OSD_Protection :: World () const {
318 } // end OSD_Protection :: World
320 void OSD_Protection :: Add (
321 OSD_SingleProtection& aProt,
322 const OSD_SingleProtection aRight
325 Standard_Integer pMask = 0;
326 Standard_Integer rMask = 0;
327 Standard_Integer sMask = 0;
329 pMask = _get_mask ( aProt );
330 rMask = _get_mask ( aRight );
332 if ( ( rMask & FLAG_READ && !( pMask & FLAG_READ ) ) || pMask & FLAG_READ )
336 if ( ( rMask & FLAG_WRITE && !( pMask & FLAG_WRITE ) ) || pMask & FLAG_WRITE )
340 if ( ( rMask & FLAG_EXECUTE && !( pMask & FLAG_EXECUTE ) ) || pMask & FLAG_EXECUTE )
342 sMask |= FLAG_EXECUTE;
344 if ( ( rMask & FLAG_DELETE && !( pMask & FLAG_DELETE ) ) || pMask & FLAG_DELETE )
346 sMask |= FLAG_DELETE;
348 aProt = _get_prot ( sMask );
350 } // end OSD_Protection :: Add
352 void OSD_Protection :: Sub (
353 OSD_SingleProtection& aProt,
354 const OSD_SingleProtection aRight
357 Standard_Integer pMask = 0;
358 Standard_Integer rMask = 0;
360 pMask = _get_mask ( aProt );
361 rMask = _get_mask ( aRight );
363 if ( rMask & FLAG_READ )
367 if ( rMask & FLAG_WRITE )
369 pMask &= ~FLAG_WRITE;
371 if ( rMask & FLAG_EXECUTE )
373 pMask &= ~FLAG_EXECUTE;
375 if ( rMask & FLAG_DELETE )
377 pMask &= ~FLAG_DELETE;
379 aProt = _get_prot ( pMask );
381 } // end OSD_Protection :: Sub
383 Standard_Integer OSD_Protection :: Internal () const {
387 } // end OSD_Protection :: Internal
389 static Standard_Integer __fastcall _get_mask ( OSD_SingleProtection p ) {
391 Standard_Integer retVal = 0;
393 if ( p == OSD_R || p == OSD_RW || p == OSD_RX || p == OSD_RWX ||
394 p == OSD_RXD || p == OSD_RWXD || p == OSD_RD || p == OSD_RWD
395 ) retVal |= FLAG_READ;
397 if ( p == OSD_W || p == OSD_RW || p == OSD_WX || p == OSD_RWX ||
398 p == OSD_WXD || p == OSD_RWXD || p == OSD_WD || p == OSD_RWD
399 ) retVal |= FLAG_WRITE;
401 if ( p == OSD_X || p == OSD_RX || p == OSD_WX || p == OSD_RWX ||
402 p == OSD_XD || p == OSD_RXD || p == OSD_WXD || p == OSD_RWXD
403 ) retVal |= FLAG_EXECUTE;
405 if ( p == OSD_D || p == OSD_RD || p == OSD_WD || p == OSD_RWD ||
406 p == OSD_XD || p == OSD_RXD || p == OSD_WXD || p == OSD_RWXD
407 ) retVal |= FLAG_DELETE;
413 static OSD_SingleProtection __fastcall _get_prot ( Standard_Integer m ) {
415 OSD_SingleProtection retVal;
431 case FLAG_READ | FLAG_WRITE:
443 case FLAG_READ | FLAG_EXECUTE:
449 case FLAG_WRITE | FLAG_EXECUTE:
455 case FLAG_READ | FLAG_WRITE | FLAG_EXECUTE:
467 case FLAG_READ | FLAG_DELETE:
473 case FLAG_WRITE | FLAG_DELETE:
479 case FLAG_READ | FLAG_WRITE | FLAG_DELETE:
485 case FLAG_EXECUTE | FLAG_DELETE:
491 case FLAG_READ | FLAG_EXECUTE | FLAG_DELETE:
497 case FLAG_WRITE | FLAG_EXECUTE | FLAG_DELETE:
503 case FLAG_READ | FLAG_WRITE | FLAG_EXECUTE | FLAG_DELETE: