/*
- * $Id: appl.c,v 1.17 2009-10-13 22:55:36 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include <atalk/adouble.h>
#include <atalk/afp.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+#include <atalk/globals.h>
+#include <atalk/netatalk_conf.h>
#include "volume.h"
-#include "globals.h"
#include "directory.h"
#include "file.h"
#include "desktop.h"
{
int cc;
char *p;
- u_int16_t len;
- u_char appltag[ 4 ];
+ uint16_t len;
+ unsigned char appltag[ 4 ];
char buf[ MAXPATHLEN ];
while (( cc = read( sfd, buf, sizeof(appltag) + sizeof( u_short ))) > 0 ) {
* See afp_getappl() for the backward compatiblity code.
*/
static char *
-makemacpath(char *mpath, int mpathlen, struct dir *dir, char *path)
+makemacpath(const struct vol *vol, char *mpath, int mpathlen, struct dir *dir, char *path)
{
char *p;
p -= strlen( path );
memcpy( p, path, strlen( path ));
- while ( dir->d_parent != NULL ) {
- p -= strlen( dir->d_m_name ) + 1;
+ while ( dir->d_did != DIRDID_ROOT ) {
+ p -= blength(dir->d_m_name) + 1;
if (p < mpath) {
/* FIXME: pathname too long */
return NULL;
}
- strcpy( p, dir->d_m_name );
- dir = dir->d_parent;
+ memcpy(p, cfrombstr(dir->d_m_name), blength(dir->d_m_name) + 1);
+ if ((dir = dirlookup(vol, dir->d_pdid)) == NULL)
+ return NULL;
}
return( p );
+
+
+#if 0
+ char buffer[12 + MAXPATHLEN + 1];
+ int buflen = 12 + MAXPATHLEN + 1;
+ char *ret = mpath;
+ char *path = name;
+ char *uname = NULL;
+ struct bstrList *pathlist = NULL;
+ cnid_t cnid = dir->d_pdid;
+
+ /* Create list for path elements, request 16 list elements for now*/
+ if ((pathlist = bstListCreateMin(16)) == NULL) {
+ LOG(log_error, logtype_afpd, "makemacpath: OOM: %s", strerror(errno));
+ return NULL;
+ }
+
+ while ( cnid != DIRDID_ROOT ) {
+
+ /* construct path, copy already found uname to path element list*/
+ if ((bstrListPush(pathlist, bfromcstr(path))) != BSTR_OK) {
+ afp_errno = AFPERR_MISC;
+ ret = NULL;
+ goto exit;
+ }
+
+ /* next part */
+ AFP_CNID_START("cnid_resolve");
+ uname = cnid_resolve(vol->v_cdb, &cnid, buffer, buflen);
+ AFP_CNID_DONE();
+
+ if (uname == NULL) {
+ afp_errno = AFPERR_NOOBJ;
+ ret = NULL;
+ goto exit;
+ }
+
+ if ((path = utompath(vol, uname, cnid, utf8_encoding())) == NULL) {
+ afp_errno = AFPERR_MISC;
+ ret = NULL;
+ goto exit;
+ }
+ }
+
+
+
+exit:
+ if (pathlist)
+ bstrListDestroy(pathlist);
+
+ return(ret);
+#endif
}
-int afp_addappl(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
+int afp_addappl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
{
struct vol *vol;
struct dir *dir;
int tfd, cc;
- u_int32_t did;
- u_int16_t vid, mplen;
+ uint32_t did;
+ uint16_t vid, mplen;
struct path *path;
char *dtf, *p, *mp;
- u_char creator[ 4 ];
- u_char appltag[ 4 ];
+ unsigned char creator[ 4 ];
+ unsigned char appltag[ 4 ];
char *mpath, *tempfile;
*rbuflen = 0;
return( AFPERR_PARAM );
}
mpath = obj->newtmp;
- mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path->m_name );
+ mp = makemacpath( vol, mpath, AFPOBJ_TMPSIZ, curdir, path->m_name );
if (!mp) {
+ close(tfd);
return AFPERR_PARAM;
}
mplen = mpath + AFPOBJ_TMPSIZ - mp;
memcpy(p, appltag, sizeof( appltag ));
cc = mpath + AFPOBJ_TMPSIZ - p;
if ( write( tfd, p, cc ) != cc ) {
+ close(tfd);
unlink( tempfile );
return( AFPERR_PARAM );
}
return( AFP_OK );
}
-int afp_rmvappl(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
+int afp_rmvappl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
{
struct vol *vol;
struct dir *dir;
int tfd, cc;
- u_int32_t did;
- u_int16_t vid, mplen;
+ uint32_t did;
+ uint16_t vid, mplen;
struct path *path;
char *dtf, *mp;
- u_char creator[ 4 ];
+ unsigned char creator[ 4 ];
char *tempfile, *mpath;
*rbuflen = 0;
return( AFPERR_PARAM );
}
mpath = obj->newtmp;
- mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path->m_name );
+ mp = makemacpath( vol, mpath, AFPOBJ_TMPSIZ, curdir, path->m_name );
if (!mp) {
+ close(tfd);
return AFPERR_PARAM ;
}
return( AFP_OK );
}
-int afp_getappl(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen)
+int afp_getappl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
{
struct vol *vol;
char *p, *q;
- int cc, buflen;
- u_int16_t vid, aindex, bitmap, len;
- u_char creator[ 4 ];
- u_char appltag[ 4 ];
+ int cc;
+ size_t buflen;
+ uint16_t vid, aindex, bitmap, len;
+ unsigned char creator[ 4 ];
+ unsigned char appltag[ 4 ];
char *buf, *cbuf;
struct path *path;
memcpy( q, p, len );
q = cbuf;
- if (( path = cname( vol, vol->v_dir, &q )) == NULL ) {
+ if (( path = cname( vol, vol->v_root, &q )) == NULL ) {
*rbuflen = 0;
return( AFPERR_NOITEM );
}
return( AFPERR_NOITEM );
}
buflen = *rbuflen - sizeof( bitmap ) - sizeof( appltag );
- if ( getfilparams(vol, bitmap, path, curdir, rbuf + sizeof( bitmap ) +
- sizeof( appltag ), &buflen ) != AFP_OK ) {
+ if ( getfilparams(obj, vol, bitmap, path, curdir, rbuf + sizeof( bitmap ) +
+ sizeof( appltag ), &buflen, 0) != AFP_OK ) {
*rbuflen = 0;
return( AFPERR_BITMAP );
}