0022904: Clean up sccsid variables
[occt.git] / src / OSD / OSD_Protection.cxx
1
2 #ifndef WNT
3
4 #include <OSD_WhoAmI.hxx>
5 #include <OSD_Protection.ixx>
6
7 #include <sys/stat.h>
8 //
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....
13 //
14 static OSD_SingleProtection TabProtAdd [16][16] =
15 {
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},
17
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},
19
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},
21
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},
23
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},
25
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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_RWXD,OSD_RXD,OSD_RXD,OSD_RWXD,OSD_RWXD,OSD_RXD,OSD_RXD,OSD_RWXD,OSD_RWXD},
43
44 {OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD,OSD_WXD,OSD_RWXD},
45
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}
47
48 };
49
50 // ----------------------- 
51
52 static OSD_SingleProtection TabProtSub [16][16] =
53 {
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},
55
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},
57
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},
59
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},
61
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},
63
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},
65
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},
67
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},
69
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},
71
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},
73
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},
75
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},
77
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},
79
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},
81
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},
83
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}
85
86 };
87 //const OSD_WhoAmI Iam = OSD_WProtection;
88
89
90 // Initialize System, Group, World for read only and User for read & write
91
92 OSD_Protection::OSD_Protection(){
93  s = OSD_R;
94  u = OSD_RWD;
95  g = OSD_R;
96  w = OSD_R;
97 }
98
99 OSD_Protection::OSD_Protection(const OSD_SingleProtection System, 
100                                      const OSD_SingleProtection User,
101                                      const OSD_SingleProtection Group,
102                                      const OSD_SingleProtection World){
103
104  s = System;
105  u = User;
106  g = Group;
107  w = World;
108 }
109
110 void  OSD_Protection::Values(OSD_SingleProtection& System, 
111                              OSD_SingleProtection& User,
112                              OSD_SingleProtection& Group,
113                              OSD_SingleProtection& World){
114  System = s;
115  User = u;
116  Group = g;
117  World = w;
118 }
119
120
121 void  OSD_Protection::SetValues(const OSD_SingleProtection System, 
122                                 const OSD_SingleProtection User,
123                                 const OSD_SingleProtection Group,
124                                 const OSD_SingleProtection World){
125  
126  s = System;
127  u = User;
128  g = Group;
129  w = World;
130 }
131
132
133 void OSD_Protection::SetSystem (const OSD_SingleProtection priv){
134  s = priv;
135 }
136
137 void OSD_Protection::SetUser (const OSD_SingleProtection priv){
138  u = priv;
139 }
140
141 void OSD_Protection::SetGroup (const OSD_SingleProtection priv){
142  g = priv;
143 }
144
145 void OSD_Protection::SetWorld (const OSD_SingleProtection priv){
146  w = priv;
147 }
148
149
150 OSD_SingleProtection OSD_Protection::System()const{
151  return(s);
152 }
153
154 OSD_SingleProtection OSD_Protection::User()const{
155  return(u);
156 }
157
158 OSD_SingleProtection OSD_Protection::Group()const{
159  return(g);
160 }
161
162 OSD_SingleProtection OSD_Protection::World()const{
163  return(w);
164 }
165
166
167 void OSD_Protection::Add(OSD_SingleProtection& aProtection,
168                          const OSD_SingleProtection aRight){
169  aProtection = TabProtAdd[aProtection][aRight];
170 }
171
172
173 void OSD_Protection::Sub(OSD_SingleProtection& aProtection,
174                          const OSD_SingleProtection aRight){
175  aProtection = TabProtSub[aProtection][aRight];
176 }
177
178
179 /* Get internal UNIX's access rights for user, group and other */
180
181 Standard_Integer  OSD_Protection::Internal()const{
182
183 Standard_Integer internal_prot = 0;
184
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;
189
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;
194
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;
199
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;                          
204
205  return ( internal_prot );
206 }
207
208
209 #else
210
211 //------------------------------------------------------------------------
212 //-------------------  WNT Sources of OSD_Protection ---------------------
213 //------------------------------------------------------------------------
214
215 #include <OSD_Protection.hxx>
216
217 #define FLAG_READ    0x00000001
218 #define FLAG_WRITE   0x00000002
219 #define FLAG_EXECUTE 0x00000004
220 #define FLAG_DELETE  0x00000008
221
222 static Standard_Integer     __fastcall _get_mask ( OSD_SingleProtection );
223 static OSD_SingleProtection __fastcall _get_prot ( Standard_Integer     );
224
225 OSD_Protection :: OSD_Protection () {
226
227  s = OSD_RWXD;
228  u = OSD_RWXD;
229  g = OSD_RX;
230  w = OSD_RX;
231
232 }  // end constructor ( 1 )
233
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
239                   ) {
240
241  SetValues ( System, User, Group, World );
242
243 }  // end constructor ( 2 )
244
245 void OSD_Protection :: Values (
246                         OSD_SingleProtection& System,
247                         OSD_SingleProtection& User,
248                         OSD_SingleProtection& Group,
249                         OSD_SingleProtection& World
250                        ) {
251  System = s;
252  User   = u;
253  Group  = g;
254  World  = w;
255
256 }  // end OSD_Protection :: Values
257
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
263                        ) {
264
265  s = System;
266  u = User;
267  g = Group;
268  w = World;
269
270 }  // end OSD_Protection :: SetValues
271
272 void OSD_Protection :: SetSystem ( const OSD_SingleProtection priv ) {
273
274  s = priv;
275
276 }  // end OSD_Protection :: SetSystem
277
278 void OSD_Protection :: SetUser ( const OSD_SingleProtection priv ) {
279
280  u = priv;
281
282 }  // end OSD_Protection :: SetUser
283
284 void OSD_Protection :: SetGroup ( const OSD_SingleProtection priv ) {
285
286  g = priv;
287
288 }  // end OSD_Protection :: SetGroup
289
290 void OSD_Protection :: SetWorld ( const OSD_SingleProtection priv ) {
291
292  w = priv;
293
294 }  // end OSD_Protection :: SetWorld
295
296 OSD_SingleProtection OSD_Protection :: System () const {
297
298  return s;
299
300 }  // end OSD_Protection :: System
301
302 OSD_SingleProtection OSD_Protection :: User () const {
303
304  return u;
305
306 }  // end OSD_Protection :: User
307
308 OSD_SingleProtection OSD_Protection :: Group () const {
309
310  return g;
311
312 }  // end OSD_Protection :: Group
313
314 OSD_SingleProtection OSD_Protection :: World () const {
315
316  return w;
317
318 }  // end OSD_Protection :: World
319
320 void OSD_Protection :: Add (
321                         OSD_SingleProtection& aProt,
322                         const OSD_SingleProtection aRight
323                        ) {
324
325  Standard_Integer pMask = 0;
326  Standard_Integer rMask = 0;
327  Standard_Integer sMask = 0;
328
329  pMask = _get_mask ( aProt  );
330  rMask = _get_mask ( aRight );
331
332  if (   (  rMask & FLAG_READ && !( pMask & FLAG_READ )  ) || pMask & FLAG_READ   )
333
334   sMask |= FLAG_READ;
335
336  if (   (  rMask & FLAG_WRITE && !( pMask & FLAG_WRITE )  ) || pMask & FLAG_WRITE   )
337
338   sMask |= FLAG_WRITE;
339
340  if (   (  rMask & FLAG_EXECUTE && !( pMask & FLAG_EXECUTE )  ) || pMask & FLAG_EXECUTE   )
341
342   sMask |= FLAG_EXECUTE;
343
344  if (   (  rMask & FLAG_DELETE && !( pMask & FLAG_DELETE )  ) || pMask & FLAG_DELETE   )
345
346   sMask |= FLAG_DELETE;
347
348  aProt = _get_prot ( sMask );
349
350 }  // end OSD_Protection :: Add
351
352 void OSD_Protection :: Sub (
353                         OSD_SingleProtection& aProt,
354                         const OSD_SingleProtection aRight
355                        ) {
356
357  Standard_Integer pMask = 0;
358  Standard_Integer rMask = 0;
359
360  pMask = _get_mask ( aProt  );
361  rMask = _get_mask ( aRight );
362
363  if ( rMask & FLAG_READ )
364
365   pMask &= ~FLAG_READ;
366
367  if ( rMask & FLAG_WRITE )
368
369   pMask &= ~FLAG_WRITE;
370
371  if ( rMask & FLAG_EXECUTE )
372
373   pMask &= ~FLAG_EXECUTE;
374
375  if ( rMask & FLAG_DELETE )
376
377   pMask &= ~FLAG_DELETE;
378
379  aProt = _get_prot ( pMask );
380
381 }  // end OSD_Protection :: Sub
382
383 Standard_Integer OSD_Protection :: Internal () const {
384
385  return 0;
386
387 }  // end OSD_Protection :: Internal
388
389 static Standard_Integer __fastcall _get_mask ( OSD_SingleProtection p ) {
390
391  Standard_Integer retVal = 0;
392
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;
396
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;
400
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;
404
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;
408
409  return retVal;
410
411 }  // end _get_mask
412
413 static OSD_SingleProtection __fastcall _get_prot ( Standard_Integer m ) {
414
415  OSD_SingleProtection retVal;
416
417  switch ( m ) {
418  
419   case FLAG_READ:
420
421    retVal = OSD_R;
422
423   break;
424
425   case FLAG_WRITE:
426
427    retVal = OSD_W;
428
429   break;
430
431   case FLAG_READ | FLAG_WRITE:
432
433    retVal = OSD_RW;
434
435   break;
436
437   case FLAG_EXECUTE:
438
439    retVal = OSD_X;
440
441   break;
442
443   case FLAG_READ | FLAG_EXECUTE:
444
445    retVal = OSD_RX;
446
447   break;
448
449   case FLAG_WRITE | FLAG_EXECUTE:
450
451    retVal = OSD_WX;
452
453   break;
454
455   case FLAG_READ | FLAG_WRITE | FLAG_EXECUTE:
456
457    retVal = OSD_RWX;
458
459   break;
460
461   case FLAG_DELETE:
462
463    retVal = OSD_D;
464
465   break;
466
467   case FLAG_READ | FLAG_DELETE:
468
469    retVal = OSD_RD;
470
471   break;
472
473   case FLAG_WRITE | FLAG_DELETE:
474
475    retVal = OSD_WD;
476
477   break;
478
479   case FLAG_READ | FLAG_WRITE | FLAG_DELETE:
480
481    retVal = OSD_RWD;
482
483   break;
484
485   case FLAG_EXECUTE | FLAG_DELETE:
486
487    retVal = OSD_XD;
488
489   break;
490
491   case FLAG_READ | FLAG_EXECUTE | FLAG_DELETE:
492
493    retVal = OSD_RXD;
494
495   break;
496
497   case FLAG_WRITE | FLAG_EXECUTE | FLAG_DELETE:
498
499    retVal = OSD_WXD;
500
501   break;
502
503   case FLAG_READ | FLAG_WRITE | FLAG_EXECUTE | FLAG_DELETE:
504
505    retVal = OSD_RWXD;
506
507   break;
508
509   default:
510
511    retVal = OSD_None;
512  
513  }  // end switch
514
515  return retVal;
516
517 }  // end _get_prot
518
519 #endif