#include <atalk/logger.h>
#include <atalk/unix.h>
#include <atalk/acl.h>
+#include <atalk/compat.h>
/* -----------------------------
a dropbox is a folder where w is set but not r eg:
{
int retval = 0;
-#ifdef DROPKLUDGE
- /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
- if ((dropbox & AFPVOL_DROPBOX)) {
- 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) & ~v_umask) )) < 0) {
- LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(errno) );
- } else {
- LOG(log_debug, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(retval) );
- }
- 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) & ~v_umask ) < 0) && errno != EPERM &&
+ if ( (chmod_acl( 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) );
mode |= st->st_mode & ~mask; /* keep other bits from previous mode */
- if ( chmod( name, mode & ~v_umask ) < 0 && errno != EPERM ) {
+ if ( chmod_acl( name, mode & ~v_umask ) < 0 && errno != EPERM ) {
return -1;
}
return 0;
/*
* @brief system rmdir with afp error code.
*
- * Supports *at semantics (cf openat) if HAVE_RENAMEAT. Pass dirfd=-1 to ignore this.
+ * Supports *at semantics (cf openat) if HAVE_ATFUNCS. Pass dirfd=-1 to ignore this.
*/
int netatalk_rmdir_all_errors(int dirfd, const char *name)
{
int err;
-#ifdef HAVE_RENAMEAT
+#ifdef HAVE_ATFUNCS
if (dirfd == -1)
- dirfd = ATFD_CWD;
+ dirfd = AT_FDCWD;
err = unlinkat(dirfd, name, AT_REMOVEDIR);
#else
err = rmdir(name);
/*
* @brief System rmdir with afp error code, but ENOENT is not an error.
*
- * Supports *at semantics (cf openat) if HAVE_RENAMEAT. Pass dirfd=-1 to ignore this.
+ * Supports *at semantics (cf openat) if HAVE_ATFUNCS. Pass dirfd=-1 to ignore this.
*/
int netatalk_rmdir(int dirfd, const char *name)
{
return AFP_OK;
}
-char *fullpathname(const char *name)
-{
- static char wd[ MAXPATHLEN + 1];
-
- if ( getcwd( wd , MAXPATHLEN) ) {
- strlcat(wd, "/", MAXPATHLEN);
- strlcat(wd, name, MAXPATHLEN);
- }
- else {
- strlcpy(wd, name, MAXPATHLEN);
- }
- return wd;
-}
-
-
/**************************************************************************
* *at semnatics support functions (like openat, renameat standard funcs)
**************************************************************************/
/*
- * Supports *at semantics if HAVE_RENAMEAT, pass dirfd=-1 to ignore this
+ * Supports *at semantics if HAVE_ATFUNCS, pass dirfd=-1 to ignore this
*/
int copy_file(int dirfd, const char *src, const char *dst, mode_t mode)
{
size_t buflen;
char filebuf[8192];
-#ifdef HAVE_RENAMEAT
+#ifdef HAVE_ATFUNCS
if (dirfd == -1)
- dirfd = ATFD_CWD;
+ dirfd = AT_FDCWD;
sfd = openat(dirfd, src, O_RDONLY);
#else
sfd = open(src, O_RDONLY);
#endif
if (sfd < 0) {
- LOG(log_error, logtype_afpd, "copy_file('%s'/'%s'): open '%s' error: %s",
+ LOG(log_info, logtype_afpd, "copy_file('%s'/'%s'): open '%s' error: %s",
src, dst, src, strerror(errno));
return -1;
}
if ((dfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) {
- LOG(log_error, logtype_afpd, "copy_file('%s'/'%s'): open '%s' error: %s",
+ LOG(log_info, logtype_afpd, "copy_file('%s'/'%s'): open '%s' error: %s",
src, dst, dst, strerror(errno));
ret = -1;
goto exit;
*/
int netatalk_unlinkat(int dirfd, const char *name)
{
-#ifdef HAVE_RENAMEAT
+#ifdef HAVE_ATFUNCS
if (dirfd == -1)
dirfd = AT_FDCWD;
/*
* @brief This is equivalent of unix rename()
*
- * unix_rename mulitplexes rename and renameat. If we dont HAVE_RENAMEAT, sfd and dfd
+ * unix_rename mulitplexes rename and renameat. If we dont HAVE_ATFUNCS, sfd and dfd
* are ignored.
*
- * @param sfd (r) if we HAVE_RENAMEAT, -1 gives AT_FDCWD
+ * @param sfd (r) if we HAVE_ATFUNCS, -1 gives AT_FDCWD
* @param oldpath (r) guess what
* @param dfd (r) same as sfd
* @param newpath (r) guess what
*/
int unix_rename(int sfd, const char *oldpath, int dfd, const char *newpath)
{
-#ifdef HAVE_RENAMEAT
+#ifdef HAVE_ATFUNCS
if (sfd == -1)
sfd = AT_FDCWD;
if (dfd == -1)
#else
if (rename(oldpath, newpath) < 0)
return -1;
-#endif /* HAVE_RENAMEAT */
+#endif /* HAVE_ATFUNCS */
return 0;
}
/*
* @brief stat/fsstatat multiplexer
*
- * statat mulitplexes stat and fstatat. If we dont HAVE_RENAMEAT, dirfd is ignored.
+ * statat mulitplexes stat and fstatat. If we dont HAVE_ATFUNCS, dirfd is ignored.
*
- * @param dirfd (r) Only used if HAVE_RENAMEAT, ignored else, -1 gives AT_FDCWD
+ * @param dirfd (r) Only used if HAVE_ATFUNCS, ignored else, -1 gives AT_FDCWD
* @param path (r) pathname
* @param st (rw) pointer to struct stat
*/
int statat(int dirfd, const char *path, struct stat *st)
{
-#ifdef HAVE_RENAMEAT
+#ifdef HAVE_ATFUNCS
if (dirfd == -1)
dirfd = AT_FDCWD;
return (fstatat(dirfd, path, st, 0));
/*
* @brief lstat/fsstatat multiplexer
*
- * lstatat mulitplexes lstat and fstatat. If we dont HAVE_RENAMEAT, dirfd is ignored.
+ * lstatat mulitplexes lstat and fstatat. If we dont HAVE_ATFUNCS, dirfd is ignored.
*
- * @param dirfd (r) Only used if HAVE_RENAMEAT, ignored else, -1 gives AT_FDCWD
+ * @param dirfd (r) Only used if HAVE_ATFUNCS, ignored else, -1 gives AT_FDCWD
* @param path (r) pathname
* @param st (rw) pointer to struct stat
*/
int lstatat(int dirfd, const char *path, struct stat *st)
{
-#ifdef HAVE_RENAMEAT
+#ifdef HAVE_ATFUNCS
if (dirfd == -1)
dirfd = AT_FDCWD;
return (fstatat(dirfd, path, st, AT_SYMLINK_NOFOLLOW));