/*
- * $Id: file.c,v 1.57 2002-09-06 04:23:45 didg Exp $
+ * $Id: file.c,v 1.58 2002-09-07 19:18:59 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
* and locks need to stay coherent. as a result,
* we just balk if the file is opened already. */
+ newname = obj->newtmp;
+ strcpy( newname, path );
+
upath = mtoupath(vol, newname );
if (of_findname(upath, NULL))
return AFPERR_DENYCONF;
- newname = obj->newtmp;
- strcpy( newname, path );
-
p = ctoupath( vol, curdir, newname );
#ifdef FORCE_UIDGID
/* FIXME svid != dvid && dvid's user can't read svid */
return( AFPERR_PARAM );
}
}
-
- if ( (err = copyfile(p, mtoupath(vol, newname),
- newname, vol_noadouble(vol))) < 0 ) {
+ upath = mtoupath(vol, newname);
+ if ( (err = copyfile(p, upath , newname, vol_noadouble(vol))) < 0 ) {
return err;
}
#ifdef DROPKLUDGE
if (vol->v_flags & AFPVOL_DROPBOX) {
- retvalue=matchfile2dirperms(newname, vol, sdid);
+ retvalue=matchfile2dirperms(upath, vol, ddid); /* FIXME sdir or ddid */
}
#endif /* DROPKLUDGE */
/*
- * $Id: filedir.c,v 1.30 2002-09-05 14:52:06 didg Exp $
+ * $Id: filedir.c,v 1.31 2002-09-07 19:18:59 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
{
struct stat st, sb;
struct dir *dir;
- char adpath[50];
+ char *adpath;
int uid;
-
+ int ret = AFP_OK;
#ifdef DEBUG
LOG(log_info, logtype_afpd, "begin matchfile2dirperms:");
#endif /* DEBUG */
- if (stat(upath, &st ) < 0)
+ if (stat(upath, &st ) < 0) {
LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
- strcpy (adpath, "./.AppleDouble/");
- strcat (adpath, upath);
+ return AFPERR_NOOBJ ;
+ }
+
+ adpath = ad_path( upath, ADFLAGS_HF );
+ /* FIXME dirsearch doesn't move cwd to did ! */
if (( dir = dirsearch( vol, did )) == NULL ) {
LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
- return( AFPERR_NOOBJ );
+ ret = AFPERR_NOOBJ;
}
else if (stat(".", &sb) < 0) {
LOG(log_error, logtype_afpd,
"matchfile2dirperms: Error checking directory \"%s\": %s",
dir->d_name, strerror(errno));
- return(AFPERR_NOOBJ );
+ ret AFPERR_NOOBJ;
}
else {
uid=geteuid();
LOG(log_error, logtype_afpd,
"matchfile2dirperms: Error changing owner/gid of %s: %s",
upath, strerror(errno));
- return (AFPERR_ACCESS);
+ ret = AFPERR_ACCESS;
}
- if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
+ else if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
{
LOG(log_error, logtype_afpd,
"matchfile2dirperms: Error adding file read permissions: %s",
strerror(errno));
- return (AFPERR_ACCESS);
+ ret = AFPERR_ACCESS;
}
-#ifdef DEBUG
- else
- LOG(log_info, logtype_afpd,
- "matchfile2dirperms: Added S_IRGRP and S_IROTH: %s",
- strerror(errno));
-#endif /* DEBUG */
- if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
+ else if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
{
LOG(log_error, logtype_afpd,
"matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s",
adpath, strerror(errno));
- return (AFPERR_ACCESS);
+ ret = AFPERR_ACCESS;
}
- if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
+ else if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
{
LOG(log_error, logtype_afpd,
"matchfile2dirperms: Error adding AD file read permissions: %s",
strerror(errno));
- return (AFPERR_ACCESS);
+ ret = AFPERR_ACCESS;
}
-#ifdef DEBUG
- else
- LOG(log_info, logtype_afpd,
- "matchfile2dirperms: Added S_IRGRP and S_IROTH to AD: %s",
- strerror(errno));
-#endif /* DEBUG */
+ seteuid(uid);
}
-#ifdef DEBUG
- else
- LOG(log_info, logtype_afpd,
- "matchfile2dirperms: No ownership change necessary.");
-#endif /* DEBUG */
} /* end else if stat success */
- seteuid(uid); /* Restore process ownership to normal */
+
#ifdef DEBUG
LOG(log_info, logtype_afpd, "end matchfile2dirperms:");
#endif /* DEBUG */
-
- return (AFP_OK);
-
+ return ret;
}
rc = moveandrename(vol, sdir, oldname, newname, isdir);
if ( rc == AFP_OK ) {
+ char *upath = mtoupath(vol, newname);
#ifdef DROPKLUDGE
if (vol->v_flags & AFPVOL_DROPBOX) {
- if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) {
+ if (retvalue=matchfile2dirperms (upath, vol, did) != AFP_OK) {
return retvalue;
}
}
else
#endif /* DROPKLUDGE */
if (!isdir) {
- char *upath = mtoupath(vol, newname);
int admode = ad_mode("", 0777);
setfilmode(upath, admode, NULL);
/*
- * $Id: unix.c,v 1.36 2002-08-29 18:57:26 didg Exp $
+ * $Id: unix.c,v 1.37 2002-09-07 19:18:59 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
return( mode );
}
-int stickydirmode(name, mode, dropbox)
+/*
+ a dropbox is a folder where w is set but not r eg:
+ rwx-wx-wx or rwx-wx--
+ rwx----wx (is not asked by a Mac with OS >= 8.0 ?)
+*/
+static int stickydirmode(name, mode, dropbox)
char * name;
const mode_t mode;
const int dropbox;
{
- int retval;
-#ifdef DROPKLUDGE
- int uid;
-#endif /* DROPKLUDGE */
+ int retval = 0;
- /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
- retval=0;
#ifdef DROPKLUDGE
+ /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
if (dropbox) {
- if (mode & S_IWOTH) {
- if (mode & S_IROTH);
- else { /* if S_IWOTH and not S_IROTH */
- uid=geteuid();
- if ( seteuid(0) < 0) {
- LOG(log_error, logtype_afpd, "stickydirmode: unable to seteuid root: %s", strerror(errno));
- }
- if ( retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & ~default_options.umask) ) < 0) {
- LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", name, strerror(errno) );
- return(AFPERR_ACCESS);
- } else {
+ int uid;
+
+ if ( ( (mode & S_IWOTH) && !(mode & S_IROTH)) ||
+ ( (mode & S_IWGRP) && !(mode & S_IRGRP)) )
+ {
+ uid=geteuid();
+ if ( seteuid(0) < 0) {
+ LOG(log_error, logtype_afpd, "stickydirmode: unable to seteuid root: %s", strerror(errno));
+ }
+ if ( retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & ~default_options.umask) ) < 0) {
+ LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", name, strerror(errno) );
+ } else {
#ifdef DEBUG
- LOG(log_info, logtype_afpd, "stickydirmode: (debug) chmod \"%s\": %s", name, strerror(retval) );
+ LOG(log_info, logtype_afpd, "stickydirmode: (debug) chmod \"%s\": %s", name, strerror(retval) );
#endif /* DEBUG */
- seteuid(uid);
- } /* end getting retval */
- } /* end if not & S_IROTH */
- } else { /* end if S_IWOTH and not S_IROTH */
-#endif /* DROPKLUDGE */
-
- /*
- * Ignore EPERM errors: We may be dealing with a directory that is
- * group writable, in which case chmod will fail.
- */
- if ( (chmod( name, (DIRBITS | mode) & ~default_options.umask ) < 0) && errno != EPERM) {
- LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s",
- name, strerror(errno) );
- retval = -1;
}
-#ifdef DROPKLUDGE
- } /* end if not mode */
- } /* end checking for "dropbox" */
+ seteuid(uid);
+ return retval;
+ }
+ }
#endif /* DROPKLUDGE */
+
+ /*
+ * Ignore EPERM errors: We may be dealing with a directory that is
+ * group writable, in which case chmod will fail.
+ */
+ if ( (chmod( name, (DIRBITS | mode) & ~default_options.umask ) < 0) && errno != EPERM) {
+ LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s",name, strerror(errno) );
+ retval = -1;
+ }
+
return retval;
}
continue;
}
if (S_ISREG(st.st_mode)) {
- if (setfilmode(dirp->d_name, ad_hf_mode(mode), &st) < 0) {
+ if (setfilmode(buf, ad_hf_mode(mode), &st) < 0) {
/* FIXME what do we do then? */
}
}
/*
- * $Id: adouble.h,v 1.9 2002-08-29 18:57:36 didg Exp $
+ * $Id: adouble.h,v 1.10 2002-09-07 19:19:00 didg Exp $
* Copyright (c) 1990,1991 Regents of The University of Michigan.
* All Rights Reserved.
*
extern int ad_open __P((char *, int, int, int, struct adouble *));
extern int ad_refresh __P((struct adouble *));
-/* extend to RW if R for locking */
+/* extend header to RW if R or W (W if R for locking),
+ */
static inline mode_t ad_hf_mode (mode_t mode)
{
#ifndef USE_FLOCK_LOCKS
if ((mode & S_IROTH))
mode |= S_IWOTH;
#endif
+ /* if write mode set add read mode */
+ if ((mode & S_IWUSR))
+ mode |= S_IRUSR;
+ if ((mode & S_IWGRP))
+ mode |= S_IRGRP;
+ if ((mode & S_IWOTH))
+ mode |= S_IROTH;
+
return mode;
}