X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Fvfs%2Funix.c;h=6679c296eac5d0fd22edb177e29e1145b73527e3;hb=refs%2Ftags%2Fbranch-symlink-commit;hp=3b71dec206a8a59c0c11603395f4a58b5575d5c7;hpb=877f52dd179a14258f10d0b55e361deb60cb2398;p=netatalk.git diff --git a/libatalk/vfs/unix.c b/libatalk/vfs/unix.c index 3b71dec2..6679c296 100644 --- a/libatalk/vfs/unix.c +++ b/libatalk/vfs/unix.c @@ -1,5 +1,5 @@ /* - * $Id: unix.c,v 1.5 2009-10-16 00:57:12 didg Exp $ + * $Id: unix.c,v 1.6.2.1 2010-01-02 10:22:33 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -26,7 +26,7 @@ /* ----------------------------- 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) @@ -60,8 +60,8 @@ int stickydirmode(const char *name, const mode_t mode, const int dropbox, const * 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; @@ -79,33 +79,35 @@ int dir_rx_set(mode_t mode) /* --------------------- */ 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) + if (lstat(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; + + if (S_ISLNK(st->st_mode)) return 0; /* we don't want to change link permissions */ + + 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 : @@ -122,7 +124,7 @@ int netatalk_rmdir(const char *name) /* ------------------- system unlink with afp error code. ENOENT is not an error. - */ +*/ int netatalk_unlink(const char *name) { if (unlink(name) < 0) { @@ -212,10 +214,52 @@ exit: 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; +}