#include <fcntl.h>
#include <dirent.h>
#include <string.h>
+#include <unistd.h>
#include "directory.h"
#include "desktop.h"
#include "globals.h"
#include "filedir.h"
+int matchfile2dirperms(upath, vol, did)
+ /* 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[50];
+ int uid;
+
+#ifdef DEBUG
+ syslog (LOG_INFO, "begin matchfile2dirperms:");
+#endif DEBUG
+
+ if (stat(upath, &st ) < 0)
+ syslog(LOG_ERR, "Could not stat %s: %m", upath);
+ strcpy (adpath, "./.AppleDouble/");
+ strcat (adpath, upath);
+ if (( dir = dirsearch( vol, did )) == NULL ) {
+ syslog (LOG_ERR, "matchfile2dirperms: Unable to get directory info.");
+ return( AFPERR_NOOBJ );
+ }
+ else if (stat(".", &sb) < 0) {
+ syslog (LOG_ERR,
+ "matchfile2dirperms: Error checking directory \"%s\": %m",
+ dir->d_name);
+ return(AFPERR_NOOBJ );
+ }
+ else {
+ uid=geteuid();
+ if ( uid != sb.st_uid )
+ {
+ seteuid(0);
+ if (lchown(upath, sb.st_uid, sb.st_gid) < 0)
+ {
+ syslog (LOG_ERR,
+ "matchfile2dirperms: Error changing owner/gid of %s: %m", upath);
+ return (AFPERR_ACCESS);
+ }
+ if (chmod(upath,(st.st_mode&0x0FFFF)| S_IRGRP| S_IROTH) < 0)
+ {
+ syslog (LOG_ERR,
+ "matchfile2dirperms: Error adding file read permissions: %m");
+ return (AFPERR_ACCESS);
+ }
+#ifdef DEBUG
+ else
+ syslog (LOG_INFO,
+ "matchfile2dirperms: Added S_IRGRP and S_IROTH: %m");
+#endif DEBUG
+ if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
+ {
+ syslog (LOG_ERR,
+ "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %m",
+ adpath);
+ return (AFPERR_ACCESS);
+ }
+ if (chmod(adpath, (st.st_mode&0x0FFFF)| S_IRGRP| S_IROTH) < 0)
+ {
+ syslog (LOG_ERR,
+ "matchfile2dirperms: Error adding AD file read permissions: %m");
+ return (AFPERR_ACCESS);
+ }
+#ifdef DEBUG
+ else
+ syslog (LOG_INFO,
+ "matchfile2dirperms: Added S_IRGRP and S_IROTH to AD: %m");
+#endif DEBUG
+ }
+#ifdef DEBUG
+ else
+ syslog (LOG_INFO,
+ "matchfile2dirperms: No ownership change necessary.");
+#endif DEBUG
+ } /* end else if stat success */
+ seteuid(uid); /* Restore process ownership to normal */
+#ifdef DEBUG
+ syslog (LOG_INFO, "end matchfile2dirperms:");
+#endif DEBUG
+
+ return (AFP_OK);
+
+}
+
+
int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
AFPObj *obj;
char *ibuf, *rbuf;
char *path;
u_int16_t fbitmap, dbitmap, vid;
+#ifdef DEBUG
+ syslog(LOG_INFO, "begin afp_getfildirparams:");
+#endif DEBUG
+
*rbuflen = 0;
ibuf += 2;
rbuf += sizeof( dbitmap ) + sizeof( u_char );
*rbuf = 0;
+#ifdef DEBUG
+ syslog(LOG_INFO, "end afp_getfildirparams:");
+#endif DEBUG
+
return( AFP_OK );
}
u_int16_t vid, bitmap;
int did, rc;
+#ifdef DEBUG
+ syslog(LOG_INFO, "begin afp_setfildirparams:");
+#endif DEBUG
+
*rbuflen = 0;
ibuf += 2;
memcpy( &vid, ibuf, sizeof(vid));
if ( rc == AFP_OK ) {
setvoltime(obj, vol );
}
+
+#ifdef DEBUG
+ syslog(LOG_INFO, "end afp_setfildirparams:");
+#endif DEBUG
+
return( rc );
}
cnid_t id;
#endif
+#ifdef DEBUG
+ syslog(LOG_INFO, "begin afp_rename:");
+#endif DEBUG
+
*rbuflen = 0;
ibuf += 2;
if (of_rename(vol, curdir, path, curdir, ibuf) < 0)
return AFPERR_MISC;
+#ifdef DEBUG
+ syslog(LOG_INFO, "end afp_rename:");
+#endif DEBUG
+
return( AFP_OK );
}
int did, rc;
u_int16_t vid;
+#ifdef DEBUG
+ syslog(LOG_INFO, "begin afp_delete:");
+#endif DEBUG
+
*rbuflen = 0;
ibuf += 2;
if ( rc == AFP_OK ) {
setvoltime(obj, vol );
}
+
+#ifdef DEBUG
+ syslog(LOG_INFO, "end afp_delete:");
+#endif DEBUG
+
return( rc );
}
cnid_t id;
#endif
+#ifdef DEBUG
+ syslog(LOG_INFO, "begin afp_moveandrename:");
+#endif DEBUG
+
*rbuflen = 0;
ibuf += 2;
rc = renamedir(p, upath, odir, curdir, newname, vol_noadouble(vol));
}
+#ifdef DROPKLUDGE
+ if (vol->v_flags & AFPVOL_DROPBOX) {
+ if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) {
+ return retvalue;
+ }
+ }
+#endif DROPKLUDGE
+
if ( rc == AFP_OK ) {
#if AD_VERSION > AD_VERSION1
/* renaming may have moved the file/dir across a filesystem */
#endif
setvoltime(obj, vol );
}
+
+#ifdef DEBUG
+ syslog(LOG_INFO, "end afp_moveandrename:");
+#endif DEBUG
+
return( rc );
}