Ticket #632: acl.2.patch

File acl.2.patch, 6.5 KB (added by egarette, 10 years ago)

New version of my patch

  • xapian-applications/omega/Makefile.am

    diff --git a/xapian-applications/omega/Makefile.am b/xapian-applications/omega/Makefile.am
    index 5c8dec8..7955750 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..8af22ce 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 {  
    167176        return statbuf.st_mtime;
    168177    }
    169178
     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 : "";
     187    }
     188#endif
     189
    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                    break;
     230                case ACL_GROUP:
     231                    acl_gid = (gid_t*) ptr_acl;
     232                    if (!acl_gid)
     233                        break;
     234                    (*acl_groups)[get_group_name(*acl_gid)] = is_acl_readable(acl_entry);
     235                    break;
     236            }
     237            entry_id = ACL_NEXT_ENTRY;
     238        }
     239        acl_free(ptr_acl);
     240        acl_free(acl);
     241    }
     242#endif
     243
    180244    const char * get_group() {
    181245#ifndef __WIN32__
    182         ensure_statbuf_valid();
    183         struct group * grentry = getgrgid(statbuf.st_gid);
    184         return grentry ? grentry->gr_name : NULL;
     246        ensure_statbuf_valid();
     247        return get_group_name(statbuf.st_gid);
    185248#else
    186         return NULL;
     249        return "";
    187250#endif
    188251    }
    189252
  • xapian-applications/omega/omindex.cc

    diff --git a/xapian-applications/omega/omindex.cc b/xapian-applications/omega/omindex.cc
    index 691b0e7..d634e80 100644
    a b index_file(const string &file, const string &url, DirectoryIterator & d,  
    319319{
    320320    string ext;
    321321    const char * dot_ptr = strrchr(d.leafname(), '.');
     322#ifdef HAVE_ACL_LIBACL_H
     323    map<string, int> acl_users;
     324    map<string, int> acl_groups;
     325    map<string, int>::iterator acl;
     326#endif
     327
    322328    if (dot_ptr) {
    323329        ext.assign(dot_ptr + 1);
    324330        if (ext.size() > max_ext_len)
    index_mimetype(const string & file, const string & url, const string & ext,  
    941947        newdocument.add_value(VALUE_SIZE,
    942948                              Xapian::sortable_serialise(d.get_size()));
    943949
    944         bool inc_tag_added = false;
    945         if (d.is_other_readable()) {
    946             inc_tag_added = true;
     950        if (d.is_other_readable())
    947951            newdocument.add_boolean_term("I*");
    948         } else if (d.is_group_readable()) {
    949             const char * group = d.get_group();
    950             if (group) {
    951                 newdocument.add_boolean_term(string("I#") + group);
    952             }
     952
     953        const char * group = d.get_group();
     954        if (group) {
     955            newdocument.add_boolean_term(string("G") + group);
     956            if (d.is_group_readable())
     957                newdocument.add_boolean_term(string("I#") + group);
    953958        }
    954959        const char * owner = d.get_owner();
    955960        if (owner) {
    956961            newdocument.add_boolean_term(string("O") + owner);
    957             if (!inc_tag_added && d.is_owner_readable())
    958                 newdocument.add_boolean_term(string("I@") + owner);
     962            if (d.is_owner_readable())
     963                newdocument.add_boolean_term(string("I@") + owner);
    959964        }
    960965
     966#ifdef HAVE_ACL_LIBACL_H
     967        d.get_acls(&acl_users, &acl_groups);
     968        for (acl = acl_users.begin(); acl != acl_users.end(); ++acl) {
     969            newdocument.add_boolean_term(string("O") + acl->first);
     970            if (acl->second == 1)
     971                newdocument.add_boolean_term(string("I@") + acl->first);
     972        }
     973        for (acl = acl_groups.begin(); acl != acl_groups.end(); ++acl) {
     974            newdocument.add_boolean_term(string("G") + acl->first);
     975            if (acl->second == 1)
     976                newdocument.add_boolean_term(string("I#") + acl->first);
     977        }
     978#endif
    961979        string ext_term("E");
    962980        for (string::const_iterator i = ext.begin(); i != ext.end(); ++i) {
    963981            char ch = *i;