/*
- * $Id: directory.c,v 1.38 2002-08-29 18:57:26 didg Exp $
+ * $Id: directory.c,v 1.41.2.2 2002-11-07 17:10:02 srittau Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include "globals.h"
#include "unix.h"
-#ifdef FORCE_UIDGID
-#include "uid.h"
-#endif /* FORCE_UIDGID */
-
struct dir *curdir;
#define SENTINEL (&sentinel)
char *ptr;
static char buffer[12 + MAXPATHLEN + 1];
int buflen = 12 + MAXPATHLEN + 1;
-
+ char *mpath;
+
ret = dirsearch(vol, did);
if (ret != NULL)
return ret;
return NULL;
}
ptr = path + MAXPATHLEN;
- len = strlen(upath);
+ mpath = utompath(vol, upath);
+ len = strlen(mpath);
pathlen = len; /* no 0 in the last part */
len++;
- strcpy(ptr - len, upath);
+ strcpy(ptr - len, mpath);
ptr -= len;
while (1) {
ret = dirsearch(vol,id);
}
if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL)
return NULL;
- len = strlen(upath) + 1;
+ mpath = utompath(vol, upath);
+ len = strlen(mpath) + 1;
pathlen += len;
if (pathlen > 255)
return NULL;
- strcpy(ptr - len, upath);
+ strcpy(ptr - len, mpath);
ptr -= len;
}
/* fill the cache */
if ( !extend ) {
cdir = dir->d_child;
while (cdir) {
- if ( strcasecmp( cdir->d_name, path ) == 0 ) {
+ if ( strcmp( cdir->d_name, path ) == 0 ) {
break;
}
cdir = (cdir == dir->d_child->d_prev) ? NULL :
/* dir is not valid anymore
we delete dir from the cache and abort.
*/
- dir_invalidate(vol, dir);
+ if ( dir->d_did != DIRDID_ROOT_PARENT)
+ dir_invalidate(vol, dir);
return( NULL );
}
cdir = extenddir( vol, dir, path );
int bit = 0, isad = 1;
u_int32_t aint;
u_int16_t ashort;
-#ifdef FORCE_UIDGID
- uidgidset *uidgid;
- memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
memset(&ad, 0, sizeof(ad));
-#ifdef FORCE_UIDGID
- save_uidgid ( &uidgid );
- set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
-
if ( ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
DIRBITS | 0777, &ad) < 0 ) {
isad = 0;
if ( isad ) {
ad_close( &ad, ADFLAGS_HF );
}
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_BITMAP );
}
bitmap = bitmap>>1;
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( int );
- if (( dir = dirsearch( vol, did )) == NULL ) {
+ if (( dir = dirlookup( vol, did )) == NULL ) {
return( AFPERR_NOOBJ );
}
int change_mdate = 0;
int change_parent_mdate = 0;
int newdate = 0;
-#ifdef FORCE_UIDGID
- uidgidset *uidgid;
-
- memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
upath = mtoupath(vol, path);
memset(&ad, 0, sizeof(ad));
-#ifdef FORCE_UIDGID
- save_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
O_RDWR|O_CREAT, 0666, &ad) < 0) {
if (!vol_noadouble(vol) && (bitmap &
~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
(1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_ACCESS;
}
ad_close( &ad, ADFLAGS_HF );
}
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
-
if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
&& gettimeofday(&tv, NULL) == 0) {
if (!movecwd(vol, curdir->d_parent)) {
char *path, *upath;
u_int32_t did;
u_int16_t vid;
-#ifdef FORCE_UIDGID
- uidgidset *uidgid;
-
- memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
*rbuflen = 0;
ibuf += 2;
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( did );
- if (( dir = dirsearch( vol, did )) == NULL ) {
+ if (( dir = dirlookup( vol, did )) == NULL ) {
return( AFPERR_NOOBJ );
}
}
}
-#ifdef FORCE_UIDGID
- save_uidgid ( &uidgid );
- set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
-
if ( ad_mkdir( upath, DIRBITS | 0777 ) < 0 ) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
switch ( errno ) {
case ENOENT :
return( AFPERR_NOOBJ );
}
if (stat(upath, &st) < 0) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_MISC;
}
if ((dir = adddir( vol, curdir, path, strlen( path ), upath,
strlen(upath), &st)) == NULL) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_MISC;
}
if ( movecwd( vol, dir ) < 0 ) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_PARAM );
}
O_RDWR|O_CREAT, 0666, &ad ) < 0) {
if (vol_noadouble(vol))
goto createdir_done;
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_ACCESS );
}
memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
*rbuflen = sizeof( u_int32_t );
setvoltime(obj, vol );
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFP_OK );
}
DIR *dp;
struct adouble ad;
u_int16_t ashort;
-#ifdef FORCE_UIDGID
- uidgidset *uidgid;
-
- memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
if ( curdir->d_parent == NULL ) {
return( AFPERR_ACCESS );
fdir = curdir;
-#ifdef FORCE_UIDGID
- save_uidgid ( &uidgid );
- set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
-
memset(&ad, 0, sizeof(ad));
if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
DIRBITS | 0777, &ad) == 0 ) {
ad_getattr(&ad, &ashort);
ad_close( &ad, ADFLAGS_HF );
if ((ashort & htons(ATTRBIT_NODELETE))) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_OLOCK;
}
}
* note: this will not fail with dangling symlinks */
if (stat(de->d_name, &st) == 0) {
closedir(dp);
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_DIRNEMPT;
}
switch (errno) {
case EPERM:
case EACCES :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_ACCESS );
case EROFS:
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_VLOCK;
case ENOENT :
continue;
default :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_PARAM );
}
}
case ENOENT :
break;
case ENOTEMPTY :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_DIRNEMPT );
case EROFS:
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_VLOCK;
case EPERM:
case EACCES :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_ACCESS );
default :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_PARAM );
}
}
/* bail if it's not a symlink */
if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_DIRNEMPT;
}
switch (errno) {
case EPERM:
case EACCES :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_ACCESS );
case EROFS:
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_VLOCK;
case ENOENT :
continue;
default :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_PARAM );
}
}
}
if ( movecwd( vol, curdir->d_parent ) < 0 ) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_NOOBJ );
}
if ( rmdir(mtoupath(vol, fdir->d_name)) < 0 ) {
switch ( errno ) {
case ENOENT :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_NOOBJ );
case ENOTEMPTY :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_DIRNEMPT );
case EPERM:
case EACCES :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_ACCESS );
case EROFS:
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_VLOCK;
default :
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFPERR_PARAM );
}
}
#endif /* CNID_DB */
dir_remove( vol, fdir );
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return( AFP_OK );
}
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( did );
- if (( dir = dirsearch( vol, did )) == NULL ) {
+ if (( dir = dirlookup( vol, did )) == NULL ) {
return( AFPERR_PARAM );
}
char *path, *upath;
u_int32_t did;
u_int16_t vid;
-#ifdef FORCE_UIDGID
- uidgidset *uidgid;
-
- memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
*rbuflen = 0;
ibuf += 2;
memcpy(&did, ibuf, sizeof(did));
ibuf += sizeof(did);
- if (( parentdir = dirsearch( vol, did )) == NULL ) {
+ if (( parentdir = dirlookup( vol, did )) == NULL ) {
return( AFPERR_NOOBJ );
}
dir = (dir == parentdir->d_child->d_prev) ? NULL : dir->d_next;
}
-#ifdef FORCE_UIDGID
- save_uidgid ( &uidgid );
- set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
-
/* we don't already have a did. add one in. */
if ((dir = adddir(vol, parentdir, path, strlen(path),
upath, strlen(upath), &st)) == NULL) {
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFPERR_MISC;
}
memcpy(rbuf, &dir->d_did, sizeof(dir->d_did));
*rbuflen = sizeof(dir->d_did);
-#ifdef FORCE_UIDGID
- restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
return AFP_OK;
}