• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
posixacladdons.cpp
1 /***************************************************************************
2  * Copyright (C) 2005 by Markus Brueffer <markus@brueffer.de> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 
20 #include "posixacladdons.h"
21 
22 #if defined(USE_POSIX_ACL) && !defined(HAVE_NON_POSIX_ACL_EXTENSIONS)
23 
24 #include <errno.h>
25 #include <sys/stat.h>
26 
27 #include <tqptrlist.h>
28 
29 class SortedEntryList : public TQPtrList<acl_entry_t>
30 {
31 protected:
32  int compareItems( TQPtrCollection::Item i1,
33  TQPtrCollection::Item i2 )
34  {
35  acl_entry_t *e1 = static_cast<acl_entry_t*>( i1 );
36  acl_entry_t *e2 = static_cast<acl_entry_t*>( i2 );
37 
38  acl_tag_t tag1, tag2;
39  uid_t uid1 = 0, uid2 = 0;
40 
41  acl_get_tag_type( *e1, &tag1 );
42  acl_get_tag_type( *e2, &tag2 );
43 
44  if ( tag1 == ACL_USER || tag1 == ACL_GROUP )
45  uid1 = *( (uid_t*) acl_get_qualifier( *e1 ) );
46 
47  if ( tag2 == ACL_USER || tag2 == ACL_GROUP )
48  uid2 = *( (uid_t*) acl_get_qualifier( *e2 ) );
49 
50  if ( tag1 < tag2 )
51  return -1;
52  else if ( tag1 > tag2 )
53  return 1;
54 
55  if ( uid1 < uid2 )
56  return -1;
57  else if ( uid1 > uid2 )
58  return 1;
59 
60  return 0;
61  }
62 };
63 
64 int acl_cmp(acl_t acl1, acl_t acl2)
65 {
66  if ( !acl1 || !acl2 )
67  return -1;
68 
69  SortedEntryList entries1, entries2;
70  entries1.setAutoDelete( true );
71  entries2.setAutoDelete( true );
72 
73  /* Add ACL entries to vectors */
74  acl_entry_t *entry = new acl_entry_t;
75  int ret = acl_get_entry( acl1, ACL_FIRST_ENTRY, entry );
76  while( ret == 1 ) {
77  entries1.append( entry );
78  entry = new acl_entry_t;
79  ret = acl_get_entry( acl1, ACL_NEXT_ENTRY, entry );
80  }
81  delete entry;
82 
83  entry = new acl_entry_t;
84  ret = acl_get_entry( acl2, ACL_FIRST_ENTRY, entry );
85  while ( ret == 1 ) {
86  entries2.append( entry );
87  entry = new acl_entry_t;
88  ret = acl_get_entry( acl2, ACL_NEXT_ENTRY, entry );
89  }
90  delete entry;
91 
92  /* If the entry count differs, we are done */
93  if ( entries1.count() != entries2.count() )
94  return 1;
95 
96  /* Sort vectors */
97  entries1.sort();
98  entries2.sort();
99 
100  /* Compare all entries */
101  acl_permset_t permset1, permset2;
102  acl_tag_t tag1, tag2;
103  uid_t uid1, uid2;
104  acl_entry_t *e1, *e2;
105 
106  for ( e1 = entries1.first(), e2 = entries2.first(); e1; e1 = entries1.next(), e2 = entries2.next() ) {
107  /* Compare tag */
108  if ( acl_get_tag_type( *e1, &tag1 ) != 0 ) return 1;
109  if ( acl_get_tag_type( *e2, &tag2 ) != 0 ) return 1;
110  if ( tag1 != tag2 ) return 1;
111 
112  /* Compare permissions */
113  if ( acl_get_permset( *e1, &permset1 ) != 0 ) return 1;
114  if ( acl_get_permset( *e2, &permset2 ) != 0 ) return 1;
115  if ( *permset1 != *permset2) return 1;
116 
117  /* Compare uid */
118  switch( tag1 ) {
119  case ACL_USER:
120  case ACL_GROUP:
121  uid1 = *( (uid_t*) acl_get_qualifier( *e1 ) );
122  uid2 = *( (uid_t*) acl_get_qualifier( *e2 ) );
123  if ( uid1 != uid2 ) return 1;
124  }
125  }
126 
127  return 0;
128 }
129 
130 acl_t acl_from_mode(mode_t mode)
131 {
132  acl_t newACL = acl_init( 3 );
133  acl_entry_t entry;
134  acl_permset_t permset;
135  int error = 0;
136 
137  /* Add owner entry */
138  if ( ( error = acl_create_entry( &newACL, &entry ) ) == 0 ) {
139  /* Set owner permissions */
140  acl_set_tag_type( entry, ACL_USER_OBJ );
141  acl_get_permset( entry, &permset );
142  acl_clear_perms( permset );
143  if ( mode & S_IRUSR ) acl_add_perm( permset, ACL_READ );
144  if ( mode & S_IWUSR ) acl_add_perm( permset, ACL_WRITE );
145  if ( mode & S_IXUSR ) acl_add_perm( permset, ACL_EXECUTE );
146  acl_set_permset( entry, permset );
147 
148  /* Add group entry */
149  if ( ( error = acl_create_entry( &newACL, &entry ) ) == 0 ) {
150  /* Set group permissions */
151  acl_set_tag_type( entry, ACL_GROUP_OBJ );
152  acl_get_permset( entry, &permset );
153  acl_clear_perms( permset );
154  if ( mode & S_IRGRP ) acl_add_perm( permset, ACL_READ );
155  if ( mode & S_IWGRP ) acl_add_perm( permset, ACL_WRITE );
156  if ( mode & S_IXGRP ) acl_add_perm( permset, ACL_EXECUTE );
157  acl_set_permset( entry, permset );
158 
159  /* Add other entry */
160  if ( ( error = acl_create_entry( &newACL, &entry ) ) == 0) {
161  /* Set other permissions */
162  acl_set_tag_type( entry, ACL_OTHER );
163  acl_get_permset( entry, &permset );
164  acl_clear_perms( permset );
165  if ( mode & S_IROTH ) acl_add_perm( permset, ACL_READ );
166  if ( mode & S_IWOTH ) acl_add_perm( permset, ACL_WRITE );
167  if ( mode & S_IXOTH ) acl_add_perm( permset, ACL_EXECUTE );
168  acl_set_permset( entry, permset );
169  }
170  }
171  }
172 
173  if ( error ) {
174  acl_free ( &newACL );
175  return NULL;
176  }
177 
178  return newACL;
179 }
180 
181 int acl_equiv_mode(acl_t acl, mode_t *mode_p)
182 {
183  acl_entry_t entry;
184  acl_tag_t tag;
185  acl_permset_t permset;
186  mode_t mode = 0;
187  int notEquiv = 0;
188 
189  if ( !acl )
190  return -1;
191 
192  int ret = acl_get_entry( acl, ACL_FIRST_ENTRY, &entry );
193  while ( ret == 1 ) {
194  acl_get_tag_type( entry, &tag );
195  acl_get_permset( entry, &permset );
196 
197  switch( tag ) {
198  case ACL_USER_OBJ:
199  if ( acl_get_perm( permset, ACL_READ ) ) mode |= S_IRUSR;
200  if ( acl_get_perm( permset, ACL_WRITE ) ) mode |= S_IWUSR;
201  if ( acl_get_perm( permset, ACL_EXECUTE ) ) mode |= S_IXUSR;
202  break;
203 
204  case ACL_GROUP_OBJ:
205  if ( acl_get_perm( permset, ACL_READ ) ) mode |= S_IRGRP;
206  if ( acl_get_perm( permset, ACL_WRITE ) ) mode |= S_IWGRP;
207  if ( acl_get_perm( permset, ACL_EXECUTE ) ) mode |= S_IXGRP;
208  break;
209 
210  case ACL_OTHER:
211  if ( acl_get_perm( permset, ACL_READ ) ) mode |= S_IROTH;
212  if ( acl_get_perm( permset, ACL_WRITE ) ) mode |= S_IWOTH;
213  if ( acl_get_perm( permset, ACL_EXECUTE ) ) mode |= S_IXOTH;
214  break;
215 
216  case ACL_USER:
217  case ACL_GROUP:
218  case ACL_MASK:
219  notEquiv = 1;
220  break;
221 
222  default:
223  errno = EINVAL;
224  return -1;
225  }
226 
227  ret = acl_get_entry( acl, ACL_NEXT_ENTRY, &entry );
228  }
229 
230  if (mode_p)
231  *mode_p = mode;
232 
233  return notEquiv;
234 }
235 
236 #endif // USE_POSIX_ACL

kio/kio

Skip menu "kio/kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |