-#ifdef DROPKLUDGE
-int matchfile2dirperms(
-/* Since it's kinda' big; I decided against an
- inline function */
- char *upath,
- struct vol *vol,
- int did)
-/* The below code changes the way file ownership is determined in the name of
- fixing dropboxes. It has known security problem. See the netatalk FAQ for
- more information */
-{
- struct stat st, sb;
- struct dir *dir;
- char *adpath;
- uid_t uid;
- int ret = AFP_OK;
-#ifdef DEBUG
- LOG(log_debug9, logtype_afpd, "begin matchfile2dirperms:");
-#endif
-
- if (stat(upath, &st ) < 0) {
- LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
- return AFPERR_NOOBJ ;
- }
-
- adpath = vol->vfs->ad_path( upath, ADFLAGS_HF );
- /* FIXME dirsearch doesn't move cwd to did ! */
- if (( dir = dirlookup( vol, did )) == NULL ) {
- LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
- ret = AFPERR_NOOBJ;
- }
- else if (stat(".", &sb) < 0) {
- LOG(log_error, logtype_afpd,
- "matchfile2dirperms: Error checking directory \"%s\": %s",
- dir->d_m_name, strerror(errno));
- ret = AFPERR_NOOBJ;
- }
- else {
- uid=geteuid();
- if ( uid != sb.st_uid )
- {
- seteuid(0);
- if (lchown(upath, sb.st_uid, sb.st_gid) < 0)
- {
- LOG(log_error, logtype_afpd,
- "matchfile2dirperms(%s): Error changing owner/gid: %s",
- upath, strerror(errno));
- ret = AFPERR_ACCESS;
- }
- else if ((!S_ISLNK(st->st_mode)) && (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0))
- {
- LOG(log_error, logtype_afpd,
- "matchfile2dirperms(%s): Error adding file read permissions: %s",
- upath, strerror(errno));
- ret = AFPERR_ACCESS;
- }
- else if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
- {
- LOG(log_error, logtype_afpd,
- "matchfile2dirperms(%s): Error changing AppleDouble owner/gid: %s",
- adpath, strerror(errno));
- ret = AFPERR_ACCESS;
- }
- else if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
- {
- LOG(log_error, logtype_afpd,
- "matchfile2dirperms(%s): Error adding AD file read permissions: %s",
- adpath, strerror(errno));
- ret = AFPERR_ACCESS;
- }
- seteuid(uid);
- }
- } /* end else if stat success */
-
-#ifdef DEBUG
- LOG(log_debug9, logtype_afpd, "end matchfile2dirperms:");
-#endif
- return ret;
-}
-#endif
-