diff --git a/opendkim/opendkim.c b/opendkim/opendkim.c index fbfb8c0..b5ecd14 100644 --- a/opendkim/opendkim.c +++ b/opendkim/opendkim.c @@ -4710,17 +4710,27 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) if (status != 0) return -1; - if ((s.st_mode & S_IFMT) == S_IFREG) +syslog(LOG_DEBUG, "path %s, uid %u, gid %u, mode %08o, me %u", path, s.st_uid, + s.st_gid, s.st_mode, myuid); + + if (S_ISREG(s.st_mode)) { +syslog(LOG_DEBUG, "- regular file", path); + /* owned by root or by me */ if (s.st_uid != 0 && s.st_uid != myuid) +{ +syslog(LOG_DEBUG, "- foreign owner"); return 0; +} /* if group read/write, the group is only me and/or root */ if ((s.st_mode & (S_IRGRP|S_IWGRP)) != 0) { int c; +syslog(LOG_DEBUG, "- group read/write", path); + /* check if anyone else has this file's gid */ pthread_mutex_lock(&pwdb_lock); setpwent(); @@ -4730,6 +4740,7 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) pw->pw_uid != 0 && s.st_gid == pw->pw_gid) { +syslog(LOG_DEBUG, "- user %s has same gid", pw->pw_name); pthread_mutex_unlock(&pwdb_lock); return 0; } @@ -4749,6 +4760,7 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) if (strcmp(gr->gr_mem[c], myname) != 0 && strcmp(gr->gr_mem[c], SUPERUSER) != 0) { +syslog(LOG_DEBUG, "- user %s in same group %s", gr->gr_mem[c], gr->gr_name); pthread_mutex_unlock(&pwdb_lock); return 0; } @@ -4759,15 +4771,22 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) /* not read/write by others */ if ((s.st_mode & (S_IROTH|S_IWOTH)) != 0) +{ +syslog(LOG_DEBUG, "- read/write by others"); return 0; +} *ino = s.st_ino; } - else if ((s.st_mode & S_IFMT) == S_IFDIR) + else if (S_ISDIR(s.st_mode)) { +syslog(LOG_DEBUG, "- directory", path); /* other write needs to be off */ if ((s.st_mode & S_IWOTH) != 0) +{ +syslog(LOG_DEBUG, "- writable by others", path); return 0; +} /* group write needs to be super-user or me only */ if ((s.st_mode & S_IWGRP) != 0) @@ -4783,6 +4802,7 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) pw->pw_uid != 0 && s.st_gid == pw->pw_gid) { +syslog(LOG_DEBUG, "- user %s has same gid", pw->pw_name); pthread_mutex_unlock(&pwdb_lock); return 0; } @@ -4801,6 +4821,7 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) if (strcmp(gr->gr_mem[c], myname) != 0 && strcmp(gr->gr_mem[c], SUPERUSER) != 0) { +syslog(LOG_DEBUG, "- user %s in same group %s", gr->gr_mem[c], gr->gr_name); pthread_mutex_unlock(&pwdb_lock); return 0; } @@ -4812,7 +4833,10 @@ dkimf_checkfsnode(const char *path, uid_t myuid, char *myname, ino_t *ino) /* owner write needs to be super-user or me only */ if ((s.st_mode & S_IWUSR) != 0 && (s.st_uid != 0 && s.st_uid != myuid)) +{ +syslog(LOG_DEBUG, "- owner write for foreign uid"); return 0; +} /* if nobody else can execute below here, that's good enough */ if ((s.st_mode & (S_IXGRP|S_IXOTH)) == 0)