/*
- * $Id: filedir.c,v 1.37 2003-01-08 15:01:34 didg Exp $
+ * $Id: filedir.c,v 1.45 2003-04-20 06:53:40 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
memcpy( &vid, ibuf, sizeof( vid ));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( did );
- if (( dir = dirlookup( vol, did )) == NULL ) {
+ if (NULL == ( dir = dirlookup( vol, did )) ) {
return afp_errno;
}
dbitmap = ntohs( dbitmap );
ibuf += sizeof( dbitmap );
- if (( s_path = cname( vol, dir, &ibuf )) == NULL) {
- return afp_errno;
+ if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
+ return get_afp_errno(AFPERR_NOOBJ);
}
st = &s_path->st;
buflen = 0;
if (S_ISDIR(st->st_mode)) {
if (dbitmap) {
- if (*s_path->m_name != '\0') {
- /* the dir wasn't in the cache and we weren't able to chdir in it.
- */
- return AFPERR_ACCESS;
- }
- ret = getdirparams(vol, dbitmap, s_path, curdir,
+ dir = s_path->dir;
+ if (!dir)
+ return AFPERR_NOOBJ;
+
+ ret = getdirparams(vol, dbitmap, s_path, dir,
rbuf + 3 * sizeof( u_int16_t ), &buflen );
if (ret != AFP_OK )
return( ret );
/* this is a directory */
*(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
} else {
- if (fbitmap && ( ret = getfilparams(vol, fbitmap, s_path, curdir,
- rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
+ if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir,
+ rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
return( ret );
}
/* this is a file */
memcpy( &vid, ibuf, sizeof(vid));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
memcpy( &did, ibuf, sizeof( did));
ibuf += sizeof( did);
- if (( dir = dirlookup( vol, did )) == NULL ) {
+ if (NULL == ( dir = dirlookup( vol, did )) ) {
return afp_errno;
}
bitmap = ntohs( bitmap );
ibuf += sizeof( bitmap );
- if (( path = cname( vol, dir, &ibuf )) == NULL ) {
- return afp_errno;
+ if (NULL == ( path = cname( vol, dir, &ibuf ))) {
+ return get_afp_errno(AFPERR_NOOBJ);
}
st = &path->st;
if (!isdir) {
#ifdef CNID_DB
- p = mtoupath(vol, oldname);
+ p = mtoupath(vol, oldname, utf8_encoding());
+ if (!p) {
+ return AFPERR_PARAM; /* can't convert */
+ }
id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p));
#endif /* CNID_DB */
p = ctoupath( vol, sdir, oldname );
+ if (!p) {
+ return AFPERR_PARAM; /* pathname too long */
+ }
path.st_valid = 0;
path.u_name = p;
if ((opened = of_findname(&path))) {
id = sdir->d_did; /* we already have the CNID */
#endif /* CNID_DB */
p = ctoupath( vol, sdir->d_parent, oldname );
+ if (!p) {
+ return AFPERR_PARAM;
+ }
adflags = ADFLAGS_DIR;
}
/*
return(AFPERR_OLOCK);
}
- upath = mtoupath(vol, newname);
+ if (NULL == (upath = mtoupath(vol, newname, utf8_encoding()))){
+ return AFPERR_PARAM;
+ }
path.u_name = upath;
st = &path.st;
if (0 != (rc = check_name(vol, upath))) {
memcpy( &vid, ibuf, sizeof( vid ));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( did );
- if (( sdir = dirlookup( vol, did )) == NULL ) {
+ if (NULL == ( sdir = dirlookup( vol, did )) ) {
return afp_errno;
}
/* source pathname */
- if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
- return afp_errno;
+ if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
+ return get_afp_errno(AFPERR_NOOBJ);
}
sdir = curdir;
newname = obj->newtmp;
oldname = obj->oldtmp;
+ isdir = path_isadir(path);
if ( *path->m_name != '\0' ) {
strcpy(oldname, path->m_name); /* an extra copy for of_rename */
+ if (isdir) {
+ /* curdir parent dir, need to move sdir back */
+ sdir = path->dir;
+ }
}
else {
if ( sdir->d_parent == NULL ) { /* root directory */
if ( movecwd( vol, sdir->d_parent ) < 0 ) {
return afp_errno;
}
- isdir = 1;
strcpy(oldname, sdir->d_m_name);
}
memcpy( &vid, ibuf, sizeof( vid ));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( int );
- if (( dir = dirlookup( vol, did )) == NULL ) {
+ if (NULL == ( dir = dirlookup( vol, did )) ) {
return afp_errno;
}
- if (( s_path = cname( vol, dir, &ibuf )) == NULL ) {
- return afp_errno;
+ if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
+ return get_afp_errno(AFPERR_NOOBJ);
}
upath = s_path->u_name;
- if ( *s_path->m_name == '\0' ) {
- rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
+ if ( path_isadir( s_path) ) {
+ if (*s_path->m_name != '\0') {
+ rc = AFPERR_ACCESS;
+ }
+ else {
+ rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
+ }
} else if (of_findname(s_path)) {
rc = AFPERR_BUSY;
- } else if ((rc = deletefile( upath, 1)) == AFP_OK) {
-#ifdef CNID_DB /* get rid of entry */
- cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
- cnid_delete(vol->v_db, id);
-#endif /* CNID_DB */
+ } else {
+ rc = deletefile(vol, upath, 1);
}
if ( rc == AFP_OK ) {
curdir->offcnt--;
char *p;
int len;
+ if (u == NULL)
+ return NULL;
+
p = path + sizeof( path ) - 1;
*p = '\0';
len = strlen( u );
p -= len;
strncpy( p, u, len );
- for ( d = dir; d->d_parent; d = d->d_parent ) {
- *--p = '/';
+ if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) {
u = d->d_u_name;
len = strlen( u );
+ if (p -len -1 < path) {
+ /* FIXME
+ rather rare so LOG error and/or client message ?
+ */
+ return NULL;
+ }
+ *--p = '/';
p -= len;
strncpy( p, u, len );
}
- *--p = '/';
len = strlen( vol->v_path );
+ if (p -len -1 < path) {
+ return NULL;
+ }
+ *--p = '/';
p -= len;
strncpy( p, vol->v_path, len );
struct dir *dir;
char *name;
{
- return absupath(vol, dir, mtoupath(vol, name));
+ return absupath(vol, dir, mtoupath(vol, name, utf8_encoding()));
}
/* ------------------------- */
{
struct vol *vol;
struct dir *sdir, *ddir;
- int isdir = 0;
+ int isdir;
char *oldname, *newname;
struct path *path;
int did;
memcpy( &vid, ibuf, sizeof( vid ));
ibuf += sizeof( vid );
- if (( vol = getvolbyvid( vid )) == NULL ) {
+ if (NULL == ( vol = getvolbyvid( vid )) ) {
return( AFPERR_PARAM );
}
/* source did followed by dest did */
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( int );
- if (( sdir = dirlookup( vol, did )) == NULL ) {
- return( AFPERR_PARAM );
+ if (NULL == ( sdir = dirlookup( vol, did )) ) {
+ return afp_errno; /* was AFPERR_PARAM */
}
memcpy( &did, ibuf, sizeof( did ));
ibuf += sizeof( int );
/* source pathname */
- if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
- return( AFPERR_NOOBJ );
+ if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
+ return get_afp_errno(AFPERR_NOOBJ);
}
sdir = curdir;
newname = obj->newtmp;
oldname = obj->oldtmp;
+
+ isdir = path_isadir(path);
if ( *path->m_name != '\0' ) {
- /* not a directory */
+ if (isdir) {
+ sdir = path->dir;
+ }
strcpy(oldname, path->m_name); /* an extra copy for of_rename */
} else {
- isdir = 1;
strcpy(oldname, sdir->d_m_name);
}
/* get the destination directory */
- if (( ddir = dirlookup( vol, did )) == NULL ) {
- return( AFPERR_PARAM );
+ if (NULL == ( ddir = dirlookup( vol, did )) ) {
+ return afp_errno; /* was AFPERR_PARAM */
}
if (( path = cname( vol, ddir, &ibuf )) == NULL ) {
return( AFPERR_NOOBJ );
}
if ( *path->m_name != '\0' ) {
- return( AFPERR_BADTYPE );
+ return path_error(path, AFPERR_NOOBJ);
}
/* one more place where we know about path type */
rc = moveandrename(vol, sdir, oldname, newname, isdir);
if ( rc == AFP_OK ) {
- char *upath = mtoupath(vol, newname);
-
+ char *upath = mtoupath(vol, newname, utf8_encoding());
+
+ if (NULL == upath) {
+ return AFPERR_PARAM;
+ }
curdir->offcnt++;
sdir->offcnt--;
#ifdef DROPKLUDGE