/*
- * $Id: unix.c,v 1.56 2009-10-15 12:06:07 franklahm Exp $
+ * $Id: unix.c,v 1.57 2009-10-27 10:24:02 franklahm Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
}
#endif
-/* This is equivalent of unix rename(). */
-int unix_rename(const char *oldpath, const char *newpath)
-{
-#if 0
- char pd_name[PATH_MAX+1];
- int i;
- struct stat pd_stat;
- uid_t uid;
-#endif
-
- if (rename(oldpath, newpath) < 0)
- return -1;
-#if 0
- for (i = 0; i <= PATH_MAX && newpath[i] != '\0'; i++)
- pd_name[i] = newpath[i];
- pd_name[i] = '\0';
-
- while (i > 0 && pd_name[i] != '/') i--;
- if (pd_name[i] == '/') i++;
-
- pd_name[i++] = '.'; pd_name[i++] = '\0';
-
- if (stat(pd_name, &pd_stat) < 0) {
- LOG(log_error, logtype_afpd, "stat() of parent dir failed: pd_name = %s, uid = %d: %s",
- pd_name, geteuid(), strerror(errno));
- return 0;
- }
-
- /* So we have SGID bit set... */
- if ((S_ISGID & pd_stat.st_mode) != 0) {
- uid = geteuid();
- if (seteuid(0) < 0)
- LOG(log_error, logtype_afpd, "seteuid() failed: %s", strerror(errno));
- if (recursive_chown(newpath, uid, pd_stat.st_gid) < 0)
- LOG(log_error, logtype_afpd, "chown() of parent dir failed: newpath=%s, uid=%d: %s",
- pd_name, geteuid(), strerror(errno));
- seteuid(uid);
- }
-#endif
- return 0;
-}
-
/*
- * $Id: unix.c,v 1.5 2009-10-16 00:57:12 didg Exp $
+ * $Id: unix.c,v 1.6 2009-10-27 10:24:02 franklahm Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
/* -----------------------------
a dropbox is a folder where w is set but not r eg:
- rwx-wx-wx or rwx-wx--
+ rwx-wx-wx or rwx-wx--
rwx----wx (is not asked by a Mac with OS >= 8.0 ?)
*/
int stickydirmode(const char *name, const mode_t mode, const int dropbox, const mode_t v_umask)
* 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) & ~v_umask ) < 0) && errno != EPERM &&
- !(errno == ENOENT && (dropbox & AFPVOL_NOADOUBLE)) )
+ if ( (chmod( name, (DIRBITS | mode) & ~v_umask ) < 0) && errno != EPERM &&
+ !(errno == ENOENT && (dropbox & AFPVOL_NOADOUBLE)) )
{
LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(errno) );
retval = -1;
/* --------------------- */
int setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
{
-struct stat sb;
-mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO; /* rwx for owner group and other, by default */
+ struct stat sb;
+ mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO; /* rwx for owner group and other, by default */
if (!st) {
if (stat(name, &sb) != 0)
return -1;
st = &sb;
}
-
- mode |= st->st_mode & ~mask; /* keep other bits from previous mode */
- if ( chmod( name, mode & ~v_umask ) < 0 && errno != EPERM ) {
- return -1;
- }
- return 0;
+
+ mode |= st->st_mode & ~mask; /* keep other bits from previous mode */
+ if ( chmod( name, mode & ~v_umask ) < 0 && errno != EPERM ) {
+ return -1;
+ }
+ return 0;
}
/* -------------------
system rmdir with afp error code.
ENOENT is not an error.
- */
+*/
int netatalk_rmdir(const char *name)
{
if (rmdir(name) < 0) {
switch ( errno ) {
case ENOENT :
break;
- case ENOTEMPTY :
+ case ENOTEMPTY :
return AFPERR_DIRNEMPT;
case EPERM:
case EACCES :
/* -------------------
system unlink with afp error code.
ENOENT is not an error.
- */
+*/
int netatalk_unlink(const char *name)
{
if (unlink(name) < 0) {
if (!ret && err) {
/* don't bother to report an error if there's already one */
LOG(log_error, logtype_afpd, "copy_file('%s'/'%s'): close '%s' error: %s",
- src, dst, dst, strerror(errno));
+ src, dst, dst, strerror(errno));
ret = -1;
}
}
return ret;
}
+
+/* This is equivalent of unix rename(). */
+int unix_rename(const char *oldpath, const char *newpath)
+{
+#if 0
+ char pd_name[PATH_MAX+1];
+ int i;
+ struct stat pd_stat;
+ uid_t uid;
+#endif
+
+ if (rename(oldpath, newpath) < 0)
+ return -1;
+#if 0
+ for (i = 0; i <= PATH_MAX && newpath[i] != '\0'; i++)
+ pd_name[i] = newpath[i];
+ pd_name[i] = '\0';
+
+ while (i > 0 && pd_name[i] != '/') i--;
+ if (pd_name[i] == '/') i++;
+
+ pd_name[i++] = '.'; pd_name[i++] = '\0';
+
+ if (stat(pd_name, &pd_stat) < 0) {
+ LOG(log_error, logtype_afpd, "stat() of parent dir failed: pd_name = %s, uid = %d: %s",
+ pd_name, geteuid(), strerror(errno));
+ return 0;
+ }
+
+ /* So we have SGID bit set... */
+ if ((S_ISGID & pd_stat.st_mode) != 0) {
+ uid = geteuid();
+ if (seteuid(0) < 0)
+ LOG(log_error, logtype_afpd, "seteuid() failed: %s", strerror(errno));
+ if (recursive_chown(newpath, uid, pd_stat.st_gid) < 0)
+ LOG(log_error, logtype_afpd, "chown() of parent dir failed: newpath=%s, uid=%d: %s",
+ pd_name, geteuid(), strerror(errno));
+ seteuid(uid);
+ }
+#endif
+ return 0;
+}