/* ----------------------------- */
int setfilowner(const struct vol *vol, const uid_t uid, const gid_t gid, struct path* path)
{
-
- if (!path->st_valid) {
- of_stat(path);
- }
-
- if (path->st_errno) {
- return -1;
- }
-
- if ( lchown( 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;
+ uid, gid, path->u_name, strerror(errno));
+ return -1;
}
- if (vol->vfs->vfs_chown(vol, path->u_name, uid, gid ) < 0 && errno != EPERM) {
+ if (vol->vfs->vfs_chown(vol, path->u_name, uid, gid) < 0 && errno != EPERM) {
LOG(log_debug, logtype_afpd, "setfilowner: rf_chown %d/%d %s: %s",
uid, gid, path->u_name, strerror(errno) );
return -1;
* co-opting some bits. */
int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const gid_t gid)
{
- struct stat st;
- struct dirent *dirp;
- DIR *dir;
-
- if (( dir = opendir( name )) == NULL ) {
- return( -1 );
- }
- for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) {
- if ( *dirp->d_name == '.') {
- continue;
- }
- 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 ( 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 */
- }
- }
+ if (lchown(name, uid, gid ) < 0 && errno != EPERM ) {
+ LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
+ uid, gid, fullpathname(name), strerror(errno) );
}
- closedir( dir );
- if (vol->vfs->vfs_setdirowner(vol, name, uid, gid) < 0) {
+ if (vol->vfs->vfs_setdirowner(vol, name, uid, gid) < 0)
return -1;
- }
-
- if ( lstat( ".", &st ) < 0 ) {
- return( -1 );
- }
- 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) );
- }
return( 0 );
}
-#if 0
-/* recursive chown()ing of a directory */
-static int recursive_chown(const char *path, uid_t uid, gid_t gid) {
- struct stat sbuf;
- DIR *odir = NULL;
- struct dirent *entry;
- char *name;
- int ret = 0;
- char newpath[PATH_MAX+1];
- newpath[PATH_MAX] = '\0';
-
- if (chown(path, uid, gid) < 0) {
- LOG(log_error, logtype_afpd, "cannot chown() file [%s] (uid = %d): %s", path, uid, strerror(errno));
- return -1;
- }
-
- if (lstat(path, &sbuf) < 0) {
- LOG(log_error, logtype_afpd, "cannot chown() file [%s] (uid = %d): %s", path, uid, strerror(errno));
- return -1;
- }
-
- if (S_ISDIR(sbuf.st_mode)) {
- odir = opendir(path);
- if (odir == NULL) {
- LOG(log_error, logtype_afpd, "cannot opendir() [%s] (uid = %d): %s", path, uid, strerror(errno));
- goto recursive_chown_end;
- }
- while (NULL != (entry=readdir(odir)) ) {
- name = entry->d_name;
- if (name[0] == '.' && name[1] == '\0')
- continue;
- if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
- continue;
- sprintf(newpath, "%s/%s", path, name);
- if (recursive_chown(newpath, uid, gid) < 0)
- ret = -1;
- } /* while */
- } /* if */
-
-recursive_chown_end:
- if (odir != NULL) {
- closedir(odir);
- }
- return ret;
-}
-#endif
-
return 0;
}
-/* ----------------- */
-static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
-{
- struct perm *owner = data;
-
- if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
- LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
- owner->uid, owner->gid, fullpathname(name), strerror(errno) );
- /* return ( -1 ); Sometimes this is okay */
- }
- return 0;
-}
-
static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
{
- char *adouble_p;
- struct stat st;
- struct perm owner;
-
- owner.uid = uid;
- owner.gid = gid;
-
- adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
-
- if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, 0, vol->v_umask))
- return -1;
-
- /*
- * We cheat: we know that chown doesn't do anything.
- */
- if ( stat( ".AppleDouble", &st ) < 0) {
- LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
- return -1;
- }
- if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
+ if (lchown(".AppleDouble", uid, gid) < 0 && errno != EPERM ) {
LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
- uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
- /* return ( -1 ); Sometimes this is okay */
+ uid, gid,fullpathname(".AppleDouble"), strerror(errno));
}
return 0;
}