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\
|
| 154 | 154 | if NEED_MKDTEMP |
| 155 | 155 | omindex_SOURCES += portability/mkdtemp.cc |
| 156 | 156 | endif |
| 157 | | omindex_LDADD = $(MAGIC_LIBS) $(XAPIAN_LIBS) |
| | 157 | omindex_LDADD = $(MAGIC_LIBS) $(XAPIAN_LIBS) $(ACL_LIBS) |
| 158 | 158 | |
| 159 | 159 | scriptindex_SOURCES = scriptindex.cc myhtmlparse.cc htmlparse.cc\ |
| 160 | 160 | common/getopt.cc commonhelp.cc utils.cc hashterm.cc loadfile.cc\ |
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
|
| 155 | 155 | AC_DEFINE([GETGROUPLIST_TAKES_INT_P], 1, [Define if getgrouplist takes int *])) |
| 156 | 156 | fi |
| 157 | 157 | |
| | 158 | dnl ACL permission checks. |
| | 159 | AC_CHECK_HEADERS([acl/libacl.h]) |
| | 160 | |
| | 161 | dnl Check ACL library |
| | 162 | AC_SUBST(ACL_LIBS, []) |
| | 163 | AC_CHECK_LIB(acl, acl_get_perm, [AC_DEFINE([HAVE_ACL_GET_PERM], [], |
| | 164 | [acl_get_perm is available]) AC_SUBST(ACL_LIBS, [-lacl])],) |
| | 165 | |
| 158 | 166 | dnl Check for lstat() (not available under mingw for example). |
| 159 | 167 | AC_CHECK_FUNCS(lstat) |
| 160 | 168 | |
diff --git a/xapian-applications/omega/diritor.h b/xapian-applications/omega/diritor.h
index 59b3692..9358030 100644
|
a
|
b
|
class CommitAndExit {
|
| 56 | 56 | const std::string & what() const { return msg; } |
| 57 | 57 | }; |
| 58 | 58 | |
| | 59 | #ifdef HAVE_ACL_LIBACL_H |
| | 60 | #include <sys/acl.h> |
| | 61 | #include <acl/libacl.h> |
| | 62 | #include <map> |
| | 63 | #include <string> |
| | 64 | using std::string; |
| | 65 | using std::map; |
| | 66 | #endif |
| | 67 | |
| 59 | 68 | class DirectoryIterator { |
| 60 | 69 | #if defined O_NOATIME && O_NOATIME != 0 |
| 61 | 70 | static uid_t euid; |
| … |
… |
class DirectoryIterator {
|
| 162 | 171 | return statbuf.st_size; |
| 163 | 172 | } |
| 164 | 173 | |
| 165 | | off_t get_mtime() { |
| | 174 | off_t get_ctime() { |
| 166 | 175 | 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 : ""; |
| 168 | 187 | } |
| | 188 | #endif |
| 169 | 189 | |
| 170 | 190 | const char * get_owner() { |
| 171 | 191 | #ifndef __WIN32__ |
| 172 | 192 | 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); |
| 175 | 194 | #else |
| 176 | 195 | return NULL; |
| 177 | 196 | #endif |
| 178 | 197 | } |
| 179 | 198 | |
| | 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 | |
| 180 | 242 | const char * get_group() { |
| 181 | 243 | #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); |
| 185 | 246 | #else |
| 186 | | return NULL; |
| | 247 | return ""; |
| 187 | 248 | #endif |
| 188 | 249 | } |
| 189 | 250 | |
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,
|
| 315 | 315 | { |
| 316 | 316 | string ext; |
| 317 | 317 | 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 | |
| 318 | 324 | if (dot_ptr) |
| 319 | 325 | ext.assign(dot_ptr + 1); |
| 320 | 326 | |
| … |
… |
index_mimetype(const string & file, const string & url, const string & ext,
|
| 360 | 366 | if (urlterm.length() > MAX_SAFE_TERM_LENGTH) |
| 361 | 367 | urlterm = hash_long_term(urlterm, MAX_SAFE_TERM_LENGTH); |
| 362 | 368 | |
| 363 | | time_t last_mod = d.get_mtime(); |
| | 369 | time_t last_mod = d.get_ctime(); |
| 364 | 370 | time_t created = time_t(-1); |
| 365 | 371 | |
| 366 | 372 | Xapian::docid did = 0; |
| … |
… |
index_mimetype(const string & file, const string & url, const string & ext,
|
| 934 | 940 | newdocument.add_value(VALUE_SIZE, |
| 935 | 941 | Xapian::sortable_serialise(d.get_size())); |
| 936 | 942 | |
| 937 | | bool inc_tag_added = false; |
| 938 | | if (d.is_other_readable()) { |
| 939 | | inc_tag_added = true; |
| | 943 | if (d.is_other_readable()) |
| 940 | 944 | 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); |
| 946 | 951 | } |
| 947 | 952 | const char * owner = d.get_owner(); |
| 948 | 953 | if (owner) { |
| 949 | 954 | 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); |
| 952 | 957 | } |
| 953 | 958 | |
| | 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 |
| 954 | 972 | string ext_term("E"); |
| 955 | 973 | for (string::const_iterator i = ext.begin(); i != ext.end(); ++i) { |
| 956 | 974 | char ch = *i; |