X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Funix.c;h=01688c94e66c2fef5c94e6bd5dc6f6e3f14e1f3b;hb=056d3ef4c88ba09eabb1fcbf06bdd9fe6e7af4cf;hp=d5bde724b9190ccb062122299ee879b2491575ec;hpb=42c8cb19e0091eee8cc3cfa2c97205d7a412fb1b;p=netatalk.git diff --git a/etc/afpd/unix.c b/etc/afpd/unix.c index d5bde724..01688c94 100644 --- a/etc/afpd/unix.c +++ b/etc/afpd/unix.c @@ -1,6 +1,4 @@ /* - * $Id: unix.c,v 1.60 2010-01-20 13:22:13 franklahm Exp $ - * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. */ @@ -11,24 +9,8 @@ #include #include - -/* STDC check */ -#ifdef STDC_HEADERS +#include #include -#else /* STDC_HEADERS */ - -#ifndef HAVE_STRCHR -#define strchr index -#define strrchr index -#endif /* HAVE_STRCHR */ -char *strchr (), *strrchr (); - -#ifndef HAVE_MEMCPY -#define memcpy(d,s,n) bcopy ((s), (d), (n)) -#define memmove(d,s,n) bcopy ((s), (d), (n)) -#endif /* ! HAVE_MEMCPY */ -#endif /* STDC_HEADERS */ - #include #include #include @@ -38,24 +20,23 @@ char *strchr (), *strrchr (); #include #include #include +#include #include "auth.h" #include "directory.h" #include "volume.h" #include "unix.h" #include "fork.h" - -#ifdef HAVE_NFSv4_ACLS -extern void acltoownermode(char *path, struct stat *st,uid_t uid, struct maccess *ma); +#ifdef HAVE_ACLS +#include "acls.h" #endif - /* * Get the free space on a partition. */ -int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal, u_int32_t *bsize) +int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal, uint32_t *bsize) { - VolSpace maxVolSpace = (~(VolSpace)0); + VolSpace maxVolSpace = UINT64_MAX; #ifdef ultrix struct fs_data sfs; @@ -63,7 +44,6 @@ int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal struct statfs sfs; #endif /*ultrix*/ - if ( statfs( vol->v_path, &sfs ) < 0 ) { LOG(log_error, logtype_afpd, "ustatfs_getvolspace unable to stat %s", vol->v_path); return( AFPERR_PARAM ); @@ -160,6 +140,7 @@ mode_t mode; } #ifdef accessmode + #undef accessmode #endif /* @@ -171,21 +152,19 @@ mode_t mode; * * dir parameter is used by AFS */ -void accessmode(char *path, struct maccess *ma, struct dir *dir _U_, struct stat *st) - +void accessmode(const struct vol *vol, char *path, struct maccess *ma, struct dir *dir _U_, struct stat *st) { -struct stat sb; + struct stat sb; ma->ma_user = ma->ma_owner = ma->ma_world = ma->ma_group = 0; if (!st) { - if (stat(path, &sb) != 0) + if (lstat(path, &sb) != 0) return; st = &sb; } utommode( st, ma ); -#ifdef HAVE_NFSv4_ACLS - /* 10.5 Finder looks at OS 9 mode, so we must do some mapping */ - acltoownermode( path, st, uuid, ma); +#ifdef HAVE_ACLS + acltoownermode(vol, path, st, ma); #endif } @@ -281,23 +260,23 @@ int setdeskmode(const mode_t mode) *m = '\0'; strcat( modbuf, subp->d_name ); /* XXX: need to preserve special modes */ - if (stat(modbuf, &st) < 0) { + if (lstat(modbuf, &st) < 0) { LOG(log_error, logtype_afpd, "setdeskmode: stat %s: %s",fullpathname(modbuf), strerror(errno) ); continue; } if (S_ISDIR(st.st_mode)) { - if ( chmod( modbuf, (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { + if ( chmod_acl( modbuf, (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(modbuf), strerror(errno) ); } - } else if ( chmod( modbuf, mode & ~(default_options.umask | EXEC_MODE) ) < 0 && errno != EPERM ) { + } else if ( chmod_acl( modbuf, mode & ~(default_options.umask | EXEC_MODE) ) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(modbuf), strerror(errno) ); } } closedir( sub ); /* XXX: need to preserve special modes */ - if ( chmod( deskp->d_name, (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { + if ( chmod_acl( deskp->d_name, (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(deskp->d_name), strerror(errno) ); } } @@ -307,7 +286,7 @@ int setdeskmode(const mode_t mode) return -1; } /* XXX: need to preserve special modes */ - if ( chmod( ".AppleDesktop", (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { + if ( chmod_acl( ".AppleDesktop", (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s", fullpathname(".AppleDesktop"),strerror(errno) ); } return( 0 ); @@ -336,9 +315,6 @@ int setfilunixmode (const struct vol *vol, struct path* path, mode_t mode) /* --------------------- */ int setdirunixmode(const struct vol *vol, const char *name, mode_t mode) { - - int dropbox = (vol->v_flags & AFPVOL_DROPBOX); - LOG(log_debug, logtype_afpd, "setdirunixmode('%s', mode:%04o) {v_dperm:%04o}", fullpathname(name), mode, vol->v_dperm); @@ -346,14 +322,14 @@ int setdirunixmode(const struct vol *vol, const char *name, mode_t mode) if (dir_rx_set(mode)) { /* extending right? dir first then .AppleDouble in rf_setdirmode */ - if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 ) + if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 ) return -1; } if (vol->vfs->vfs_setdirunixmode(vol, name, mode, NULL) < 0 && !vol_noadouble(vol)) { return -1 ; } if (!dir_rx_set(mode)) { - if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 ) + if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 ) return -1; } return 0; @@ -366,15 +342,13 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode) struct dirent *dirp; DIR *dir; mode_t hf_mode; - int osx = vol->v_adouble == AD_VERSION2_OSX; - int dropbox = (vol->v_flags & AFPVOL_DROPBOX); mode |= vol->v_dperm; hf_mode = ad_hf_mode(mode); if (dir_rx_set(mode)) { /* extending right? dir first */ - if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 ) + if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 ) return -1; } @@ -385,10 +359,10 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode) for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) { /* FIXME */ - if ( *dirp->d_name == '.' && (!osx || dirp->d_name[1] != '_')) { + if (*dirp->d_name == '.') { continue; } - if ( stat( dirp->d_name, &st ) < 0 ) { + if ( lstat( dirp->d_name, &st ) < 0 ) { LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s",dirp->d_name, strerror(errno) ); continue; } @@ -397,6 +371,7 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode) int setmode = (osx && *dirp->d_name == '.')?hf_mode:mode; if (setfilmode(dirp->d_name, setmode, &st, vol->v_umask) < 0) { + closedir( dir ); LOG(log_error, logtype_afpd, "setdirmode: chmod %s: %s",dirp->d_name, strerror(errno) ); return -1; } @@ -409,7 +384,7 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode) } if (!dir_rx_set(mode)) { - if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 ) + if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 ) return -1; } return( 0 ); @@ -489,7 +464,7 @@ int setfilowner(const struct vol *vol, const uid_t uid, const gid_t gid, struct return -1; } - if ( chown( path->u_name, uid, gid ) < 0 && errno != EPERM ) { + if ( lchown( path->u_name, uid, gid ) < 0 && errno != EPERM ) { LOG(log_debug, logtype_afpd, "setfilowner: chown %d/%d %s: %s", uid, gid, path->u_name, strerror(errno) ); return -1; @@ -514,22 +489,21 @@ int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const struct stat st; struct dirent *dirp; DIR *dir; - int osx = vol->v_adouble == AD_VERSION2_OSX; if (( dir = opendir( name )) == NULL ) { return( -1 ); } for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) { - if ( *dirp->d_name == '.' && (!osx || dirp->d_name[1] != '_')) { + if ( *dirp->d_name == '.') { continue; } - if ( stat( dirp->d_name, &st ) < 0 ) { + if ( lstat( dirp->d_name, &st ) < 0 ) { LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(dirp->d_name), strerror(errno) ); continue; } if (( st.st_mode & S_IFMT ) == S_IFREG ) { - if ( chown( dirp->d_name, uid, gid ) < 0 && errno != EPERM ) { + if ( lchown( dirp->d_name, uid, gid ) < 0 && errno != EPERM ) { LOG(log_debug, logtype_afpd, "setdirowner: chown %s: %s", fullpathname(dirp->d_name), strerror(errno) ); /* return ( -1 ); Sometimes this is okay */ @@ -542,10 +516,10 @@ int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const return -1; } - if ( stat( ".", &st ) < 0 ) { + if ( lstat( ".", &st ) < 0 ) { return( -1 ); } - if ( gid && gid != st.st_gid && chown( ".", uid, gid ) < 0 && errno != EPERM ) { + if ( gid && gid != st.st_gid && lchown( ".", uid, gid ) < 0 && errno != EPERM ) { LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s", uid, gid, fullpathname("."), strerror(errno) ); } @@ -569,7 +543,7 @@ static int recursive_chown(const char *path, uid_t uid, gid_t gid) { return -1; } - if (stat(path, &sbuf) < 0) { + if (lstat(path, &sbuf) < 0) { LOG(log_error, logtype_afpd, "cannot chown() file [%s] (uid = %d): %s", path, uid, strerror(errno)); return -1; }