Projet

Général

Profil

diritor.h.patch

Emmanuel GARETTE, 18/10/2013 21:40

Télécharger (2,85 ko)

Voir les différences:

diritor.h
43 43
#include "loadfile.h"
44 44
#include "runfilter.h" // For class ReadError.
45 45

  
46
#ifdef HAVE_LIBACL
47
#include <sys/acl.h>
48
#include <acl/libacl.h>
49
#include <map>
50
#include <string>
51
using std::string;
52
using std::map;
53
#endif
54

  
46 55
class DirectoryIterator {
47 56
#if defined O_NOATIME && O_NOATIME != 0
48 57
    static uid_t euid;
......
150 159
	return statbuf.st_mtime;
151 160
    }
152 161

  
153
    const char * get_owner() {
162
#ifndef __WIN32__
163
    char * get_user_name(uid_t uid) {
164
        struct passwd * pwentry = getpwuid(uid);
165
        return pwentry ? pwentry->pw_name : NULL;
166
    }
167
    char * get_group_name(gid_t gid) {
168
        struct group * grentry = getgrgid(gid);
169
        return grentry ? grentry->gr_name : NULL;
170
    }
171
#endif
172

  
173
    char * get_owner() {
154 174
#ifndef __WIN32__
155 175
	ensure_statbuf_valid();
156
	struct passwd * pwentry = getpwuid(statbuf.st_uid);
157
	return pwentry ? pwentry->pw_name : NULL;
176
	return get_user_name(statbuf.st_uid);
158 177
#else
159 178
	return NULL;
160 179
#endif
161 180
    }
162 181

  
182
#ifdef HAVE_LIBACL
183
    int is_acl_readable(acl_entry_t acl_entry)
184
    {
185
        acl_permset_t permset;
186
        acl_get_permset(acl_entry, &permset);
187
        if (acl_get_perm(permset, ACL_READ) != 0)
188
            return 1;
189
        return 0;
190
    }
191
    void get_acls(map<string, int> *acl_users, map<string, int> *acl_groups) {
192
        void* ptr_acl;
193
        uid_t *acl_uid;
194
        gid_t *acl_gid;
195
        acl_t acl;
196
        acl_entry_t acl_entry;
197
        int entry_id=ACL_FIRST_ENTRY;
198
        map<string, int>::const_iterator user;
199

  
200
        acl = acl_get_file(path.c_str(), ACL_TYPE_ACCESS);
201
        while (acl_get_entry(acl, entry_id, &acl_entry) == 1) {
202
            acl_tag_t tag_type;
203
            if (acl_get_tag_type(acl_entry, &tag_type) < 0)
204
                break;
205
            ptr_acl = acl_get_qualifier(acl_entry);
206
            switch (tag_type) {
207
                case ACL_USER:
208
                    acl_uid = (uid_t*) ptr_acl;
209
                    if (!acl_uid)
210
                        break;
211
                    (*acl_users)[get_user_name(*acl_uid)] = is_acl_readable(acl_entry);
212
                case ACL_GROUP:
213
                    acl_gid = (uid_t*) ptr_acl;
214
                    if (!acl_gid)
215
                        break;
216
                    (*acl_groups)[get_group_name(*acl_gid)] = is_acl_readable(acl_entry);
217
            }
218
            entry_id = ACL_NEXT_ENTRY;
219
        }
220
        acl_free(ptr_acl);
221
        acl_free(acl);
222
    }
223
#endif
224

  
163 225
    const char * get_group() {
164 226
#ifndef __WIN32__
165
	ensure_statbuf_valid();
166
	struct group * grentry = getgrgid(statbuf.st_gid);
167
	return grentry ? grentry->gr_name : NULL;
227
        ensure_statbuf_valid();
228
        return get_group_name(statbuf.st_gid);
168 229
#else
169
	return NULL;
230
        return NULL;
170 231
#endif
171 232
    }
172 233