Ticket #632: acl.patch

File acl.patch, 6.9 KB (added by egarette, 10 years ago)
  • xapian-applications/omega/Makefile.am

    diff --git a/xapian-applications/omega/Makefile.am b/xapian-applications/omega/Makefile.am
    index 50d172a..9b0c6ad 100644
    a b omindex_SOURCES = omindex.cc myhtmlparse.cc htmlparse.cc\  
    154154if NEED_MKDTEMP
    155155omindex_SOURCES += portability/mkdtemp.cc
    156156endif
    157 omindex_LDADD = $(MAGIC_LIBS) $(XAPIAN_LIBS)
     157omindex_LDADD = $(MAGIC_LIBS) $(XAPIAN_LIBS) $(ACL_LIBS)
    158158
    159159scriptindex_SOURCES = scriptindex.cc myhtmlparse.cc htmlparse.cc\
    160160 common/getopt.cc commonhelp.cc utils.cc hashterm.cc loadfile.cc\
  • xapian-applications/omega/configure.ac

    diff --git a/xapian-applications/omega/configure.ac b/xapian-applications/omega/configure.ac
    index 3f2c7a4..124f282 100644
    a b if test $ac_cv_func_getgrouplist = yes ; then  
    155155    AC_DEFINE([GETGROUPLIST_TAKES_INT_P], 1, [Define if getgrouplist takes int *]))
    156156fi
    157157
     158dnl ACL permission checks.
     159AC_CHECK_HEADERS([acl/libacl.h])
     160
     161dnl Check ACL library
     162AC_SUBST(ACL_LIBS, [])
     163AC_CHECK_LIB(acl, acl_get_perm,        [AC_DEFINE([HAVE_ACL_GET_PERM], [],
     164     [acl_get_perm is available]) AC_SUBST(ACL_LIBS, [-lacl])],)
     165
    158166dnl Check for lstat() (not available under mingw for example).
    159167AC_CHECK_FUNCS(lstat)
    160168
  • xapian-applications/omega/diritor.h

    diff --git a/xapian-applications/omega/diritor.h b/xapian-applications/omega/diritor.h
    index 59b3692..9358030 100644
    a b class CommitAndExit {  
    5656    const std::string & what() const { return msg; }
    5757};
    5858
     59#ifdef HAVE_ACL_LIBACL_H
     60#include <sys/acl.h>
     61#include <acl/libacl.h>
     62#include <map>
     63#include <string>
     64using std::string;
     65using std::map;
     66#endif
     67
    5968class DirectoryIterator {
    6069#if defined O_NOATIME && O_NOATIME != 0
    6170    static uid_t euid;
    class DirectoryIterator {  
    162171        return statbuf.st_size;
    163172    }
    164173
    165     off_t get_mtime() {
     174    off_t get_ctime() {
    166175        ensure_statbuf_valid();
    167         return statbuf.st_mtime;
     176        return statbuf.st_ctime;
     177    }
     178
     179#ifndef __WIN32__
     180    const char * get_user_name(uid_t uid) {
     181        struct passwd * pwentry = getpwuid(uid);
     182        return pwentry ? pwentry->pw_name : "";
     183    }
     184    const char * get_group_name(gid_t gid) {
     185        struct group * grentry = getgrgid(gid);
     186        return grentry ? grentry->gr_name : "";
    168187    }
     188#endif
    169189
    170190    const char * get_owner() {
    171191#ifndef __WIN32__
    172192        ensure_statbuf_valid();
    173         struct passwd * pwentry = getpwuid(statbuf.st_uid);
    174         return pwentry ? pwentry->pw_name : NULL;
     193        return get_user_name(statbuf.st_uid);
    175194#else
    176195        return NULL;
    177196#endif
    178197    }
    179198
     199#ifdef HAVE_ACL_LIBACL_H
     200    int is_acl_readable(acl_entry_t acl_entry)
     201    {
     202        acl_permset_t permset;
     203        acl_get_permset(acl_entry, &permset);
     204        if (acl_get_perm(permset, ACL_READ) != 0)
     205            return 1;
     206        return 0;
     207    }
     208    void get_acls(map<string, int> *acl_users, map<string, int> *acl_groups) {
     209        void* ptr_acl;
     210        uid_t *acl_uid;
     211        gid_t *acl_gid;
     212        acl_t acl;
     213        acl_entry_t acl_entry;
     214        int entry_id=ACL_FIRST_ENTRY;
     215        map<string, int>::const_iterator user;
     216
     217        acl = acl_get_file(path.c_str(), ACL_TYPE_ACCESS);
     218        while (acl_get_entry(acl, entry_id, &acl_entry) == 1) {
     219            acl_tag_t tag_type;
     220            if (acl_get_tag_type(acl_entry, &tag_type) < 0)
     221                break;
     222            ptr_acl = acl_get_qualifier(acl_entry);
     223            switch (tag_type) {
     224                case ACL_USER:
     225                    acl_uid = (uid_t*) ptr_acl;
     226                    if (!acl_uid)
     227                        break;
     228                    (*acl_users)[get_user_name(*acl_uid)] = is_acl_readable(acl_entry);
     229                case ACL_GROUP:
     230                    acl_gid = (uid_t*) ptr_acl;
     231                    if (!acl_gid)
     232                        break;
     233                    (*acl_groups)[get_group_name(*acl_gid)] = is_acl_readable(acl_entry);
     234            }
     235            entry_id = ACL_NEXT_ENTRY;
     236        }
     237        acl_free(ptr_acl);
     238        acl_free(acl);
     239    }
     240#endif
     241
    180242    const char * get_group() {
    181243#ifndef __WIN32__
    182         ensure_statbuf_valid();
    183         struct group * grentry = getgrgid(statbuf.st_gid);
    184         return grentry ? grentry->gr_name : NULL;
     244        ensure_statbuf_valid();
     245        return get_group_name(statbuf.st_gid);
    185246#else
    186         return NULL;
     247        return "";
    187248#endif
    188249    }
    189250
  • xapian-applications/omega/omindex.cc

    diff --git a/xapian-applications/omega/omindex.cc b/xapian-applications/omega/omindex.cc
    index 762808e..04d0c05 100644
    a b index_file(const string &file, const string &url, DirectoryIterator & d,  
    315315{
    316316    string ext;
    317317    const char * dot_ptr = strrchr(d.leafname(), '.');
     318#ifdef HAVE_ACL_LIBACL_H
     319    map<string, int> acl_users;
     320    map<string, int> acl_groups;
     321    map<string, int>::iterator acl;
     322#endif
     323
    318324    if (dot_ptr)
    319325        ext.assign(dot_ptr + 1);
    320326
    index_mimetype(const string & file, const string & url, const string & ext,  
    360366    if (urlterm.length() > MAX_SAFE_TERM_LENGTH)
    361367        urlterm = hash_long_term(urlterm, MAX_SAFE_TERM_LENGTH);
    362368
    363     time_t last_mod = d.get_mtime();
     369    time_t last_mod = d.get_ctime();
    364370    time_t created = time_t(-1);
    365371
    366372    Xapian::docid did = 0;
    index_mimetype(const string & file, const string & url, const string & ext,  
    934940        newdocument.add_value(VALUE_SIZE,
    935941                              Xapian::sortable_serialise(d.get_size()));
    936942
    937         bool inc_tag_added = false;
    938         if (d.is_other_readable()) {
    939             inc_tag_added = true;
     943        if (d.is_other_readable())
    940944            newdocument.add_boolean_term("I*");
    941         } else if (d.is_group_readable()) {
    942             const char * group = d.get_group();
    943             if (group) {
    944                 newdocument.add_boolean_term(string("I#") + group);
    945             }
     945
     946        const char * group = d.get_group();
     947        if (group) {
     948            newdocument.add_boolean_term(string("G") + group);
     949            if (d.is_group_readable())
     950                newdocument.add_boolean_term(string("I#") + group);
    946951        }
    947952        const char * owner = d.get_owner();
    948953        if (owner) {
    949954            newdocument.add_boolean_term(string("O") + owner);
    950             if (!inc_tag_added && d.is_owner_readable())
    951                 newdocument.add_boolean_term(string("I@") + owner);
     955            if (d.is_owner_readable())
     956                newdocument.add_boolean_term(string("I@") + owner);
    952957        }
    953958
     959#ifdef HAVE_ACL_LIBACL_H
     960        d.get_acls(&acl_users, &acl_groups);
     961        for (acl = acl_users.begin(); acl != acl_users.end(); ++acl) {
     962            newdocument.add_boolean_term(string("O") + acl->first);
     963            if (acl->second == 1)
     964                newdocument.add_boolean_term(string("I@") + acl->first);
     965        }
     966        for (acl = acl_groups.begin(); acl != acl_groups.end(); ++acl) {
     967            newdocument.add_boolean_term(string("G") + acl->first);
     968            if (acl->second == 1)
     969                newdocument.add_boolean_term(string("I#") + acl->first);
     970        }
     971#endif
    954972        string ext_term("E");
    955973        for (string::const_iterator i = ext.begin(); i != ext.end(); ++i) {
    956974            char ch = *i;