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\
|
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..8af22ce 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 {
|
167 | 176 | return statbuf.st_mtime; |
168 | 177 | } |
169 | 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 : ""; |
| 187 | } |
| 188 | #endif |
| 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 | 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 | |
180 | 244 | const char * get_group() { |
181 | 245 | #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); |
185 | 248 | #else |
186 | | return NULL; |
| 249 | return ""; |
187 | 250 | #endif |
188 | 251 | } |
189 | 252 | |
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,
|
319 | 319 | { |
320 | 320 | string ext; |
321 | 321 | 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 | |
322 | 328 | if (dot_ptr) { |
323 | 329 | ext.assign(dot_ptr + 1); |
324 | 330 | if (ext.size() > max_ext_len) |
… |
… |
index_mimetype(const string & file, const string & url, const string & ext,
|
941 | 947 | newdocument.add_value(VALUE_SIZE, |
942 | 948 | Xapian::sortable_serialise(d.get_size())); |
943 | 949 | |
944 | | bool inc_tag_added = false; |
945 | | if (d.is_other_readable()) { |
946 | | inc_tag_added = true; |
| 950 | if (d.is_other_readable()) |
947 | 951 | 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); |
953 | 958 | } |
954 | 959 | const char * owner = d.get_owner(); |
955 | 960 | if (owner) { |
956 | 961 | 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); |
959 | 964 | } |
960 | 965 | |
| 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 |
961 | 979 | string ext_term("E"); |
962 | 980 | for (string::const_iterator i = ext.begin(); i != ext.end(); ++i) { |
963 | 981 | char ch = *i; |