X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=etc%2Fafpd%2Fdesktop.c;h=258f3e5fc04735307a24dd30a33b40a08d1280fc;hp=9f105e13e13c612757386f70c342626e28fe5e77;hb=260c314546ffcfdbef47f2c7de82d5310b26df0a;hpb=bb18f4d45a9760f2daee860e71c80578bddf4712 diff --git a/etc/afpd/desktop.c b/etc/afpd/desktop.c index 9f105e13..258f3e5f 100644 --- a/etc/afpd/desktop.c +++ b/etc/afpd/desktop.c @@ -1,6 +1,4 @@ /* - * $Id: desktop.c,v 1.50.2.1 2010-02-01 10:56:08 franklahm Exp $ - * * See COPYRIGHT. * * bug: @@ -23,18 +21,16 @@ #include #include #include -#include -#include +#include + #include -#include -#include #include #include #include +#include #include "volume.h" #include "directory.h" #include "fork.h" -#include "globals.h" #include "desktop.h" #include "mangle.h" @@ -42,7 +38,7 @@ int afp_opendt(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { struct vol *vol; - u_int16_t vid; + uint16_t vid; ibuf += 2; @@ -118,14 +114,11 @@ static int iconopen(struct vol *vol, u_char creator[ 4 ], int flags, int mode) int afp_addicon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { struct vol *vol; -#ifndef NO_DDP - struct iovec iov[ 2 ]; -#endif u_char fcreator[ 4 ], imh[ 12 ], irh[ 12 ], *p; int itype, cc = AFP_OK, iovcnt = 0; size_t buflen; - u_int32_t ftype, itag; - u_int16_t bsize, rsize, vid; + uint32_t ftype, itag; + uint16_t bsize, rsize, vid; buflen = *rbuflen; *rbuflen = 0; @@ -211,80 +204,34 @@ int afp_addicon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t */ addicon_err: if ( cc < 0 ) { - if (obj->proto == AFPPROTO_DSI) { - dsi_writeinit(obj->handle, rbuf, buflen); - dsi_writeflush(obj->handle); - } + dsi_writeinit(obj->dsi, rbuf, buflen); + dsi_writeflush(obj->dsi); return cc; } - switch (obj->proto) { -#ifndef NO_DDP - case AFPPROTO_ASP: - buflen = bsize; - if ((asp_wrtcont(obj->handle, rbuf, &buflen) < 0) || buflen != bsize) - return( AFPERR_PARAM ); - -#ifdef DEBUG1 - if (obj->options.flags & OPTION_DEBUG) { - printf("(write) len: %d\n", buflen); - bprint(rbuf, buflen); - } -#endif + DSI *dsi = obj->dsi; - /* - * We're at the end of the file, add the headers, etc. */ - if ( cc == 0 ) { - iov[ 0 ].iov_base = (caddr_t)imh; - iov[ 0 ].iov_len = sizeof( imh ); - iov[ 1 ].iov_base = rbuf; - iov[ 1 ].iov_len = bsize; - iovcnt = 2; - } + iovcnt = dsi_writeinit(dsi, rbuf, buflen); - /* - * We found an icon to replace. - */ - if ( cc > 0 ) { - iov[ 0 ].iov_base = rbuf; - iov[ 0 ].iov_len = bsize; - iovcnt = 1; - } - - if ( writev( si.sdt_fd, iov, iovcnt ) < 0 ) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): writev: %s", icon_dtfile(vol, fcreator), strerror(errno) ); - return( AFPERR_PARAM ); - } - break; -#endif /* no afp/asp */ - case AFPPROTO_DSI: - { - DSI *dsi = obj->handle; - - iovcnt = dsi_writeinit(dsi, rbuf, buflen); - - /* add headers at end of file */ - if ((cc == 0) && (write(si.sdt_fd, imh, sizeof(imh)) < 0)) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } + /* add headers at end of file */ + if ((cc == 0) && (write(si.sdt_fd, imh, sizeof(imh)) < 0)) { + LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } - if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } + if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { + LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } - while ((iovcnt = dsi_write(dsi, rbuf, buflen))) { - if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } - } + while ((iovcnt = dsi_write(dsi, rbuf, buflen))) { + if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { + LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; } - break; } close( si.sdt_fd ); @@ -337,8 +284,8 @@ static const u_char uicon[] = { int afp_geticoninfo(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { struct vol *vol; - u_char fcreator[ 4 ], ih[ 12 ]; - u_int16_t vid, iindex, bsize; + unsigned char fcreator[ 4 ], ih[ 12 ]; + uint16_t vid, iindex, bsize; *rbuflen = 0; ibuf += 2; @@ -411,7 +358,7 @@ int afp_geticon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t off_t offset; ssize_t rc, buflen; u_char fcreator[ 4 ], ftype[ 4 ], itype, ih[ 12 ]; - u_int16_t vid, bsize, rsize; + uint16_t vid, bsize, rsize; buflen = *rbuflen; *rbuflen = 0; @@ -486,8 +433,8 @@ int afp_geticon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t #define min(a,b) ((a)<(b)?(a):(b)) rc = min( bsize, rsize ); - if ((obj->proto == AFPPROTO_DSI) && (buflen < rc)) { - DSI *dsi = obj->handle; + if (buflen < rc) { + DSI *dsi = obj->dsi; struct stat st; off_t size; @@ -597,7 +544,7 @@ char *mtoupath(const struct vol *vol, char *mpath, cnid_t did, int utf8) char *m, *u; size_t inplen; size_t outlen; - u_int16_t flags; + uint16_t flags; if ( *mpath == '\0' ) { strcpy(upath, "."); @@ -636,7 +583,7 @@ char *utompath(const struct vol *vol, char *upath, cnid_t id, int utf8) { static char mpath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */ char *m, *u; - u_int16_t flags; + uint16_t flags; size_t outlen; m = mpath; @@ -689,12 +636,14 @@ static int ad_addcomment(struct vol *vol, struct path *path, char *ibuf) isadir = path_isadir(path); if (isadir || !(of = of_findname(path))) { - ad_init(&ad, vol->v_adouble, vol->v_ad_options); + ad_init(&ad, vol); adp = &ad; } else adp = of->of_ad; - if (ad_open_metadata( upath , ( (isadir) ? ADFLAGS_DIR : 0), O_CREAT, adp) < 0 ) { + if (ad_open(adp, upath, + ADFLAGS_HF | ( (isadir) ? ADFLAGS_DIR : 0) | ADFLAGS_CREATE | ADFLAGS_RDWR, + 0666) < 0 ) { return( AFPERR_ACCESS ); } @@ -711,7 +660,7 @@ static int ad_addcomment(struct vol *vol, struct path *path, char *ibuf) memcpy( ad_entry( adp, ADEID_COMMENT ), ibuf, clen ); ad_flush( adp ); } - ad_close_metadata( adp); + ad_close(adp, ADFLAGS_HF); return( AFP_OK ); } @@ -721,8 +670,8 @@ int afp_addcomment(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _ struct vol *vol; struct dir *dir; struct path *path; - u_int32_t did; - u_int16_t vid; + uint32_t did; + uint16_t vid; *rbuflen = 0; ibuf += 2; @@ -762,7 +711,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t upath = path->u_name; isadir = path_isadir(path); if (isadir || !(of = of_findname(path))) { - ad_init(&ad, vol->v_adouble, vol->v_ad_options); + ad_init(&ad, vol); adp = &ad; } else adp = of->of_ad; @@ -772,7 +721,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t } if (!ad_getentryoff(adp, ADEID_COMMENT)) { - ad_close_metadata( adp ); + ad_close(adp, ADFLAGS_HF); return AFPERR_NOITEM; } /* @@ -780,7 +729,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t */ if ( ad_getentrylen( adp, ADEID_COMMENT ) <= 0 || ad_getentrylen( adp, ADEID_COMMENT ) > 199 ) { - ad_close_metadata( adp ); + ad_close(adp, ADFLAGS_HF); return( AFPERR_NOITEM ); } @@ -788,7 +737,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t *rbuf++ = clen; memcpy( rbuf, ad_entry( adp, ADEID_COMMENT ), clen); *rbuflen = clen + 1; - ad_close_metadata( adp); + ad_close(adp, ADFLAGS_HF); return( AFP_OK ); } @@ -799,8 +748,8 @@ int afp_getcomment(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, struct vol *vol; struct dir *dir; struct path *s_path; - u_int32_t did; - u_int16_t vid; + uint32_t did; + uint16_t vid; *rbuflen = 0; ibuf += 2; @@ -839,12 +788,12 @@ static int ad_rmvcomment(struct vol *vol, struct path *path) isadir = path_isadir(path); if (isadir || !(of = of_findname(path))) { - ad_init(&ad, vol->v_adouble, vol->v_ad_options); + ad_init(&ad, vol); adp = &ad; } else adp = of->of_ad; - if ( ad_open_metadata( upath, (isadir) ? ADFLAGS_DIR : 0, 0, adp) < 0 ) { + if ( ad_open(adp, upath, ADFLAGS_HF | ADFLAGS_RDWR | ((isadir) ? ADFLAGS_DIR : 0)) < 0 ) { switch ( errno ) { case ENOENT : return( AFPERR_NOITEM ); @@ -859,7 +808,7 @@ static int ad_rmvcomment(struct vol *vol, struct path *path) ad_setentrylen( adp, ADEID_COMMENT, 0 ); ad_flush( adp ); } - ad_close_metadata( adp); + ad_close(adp, ADFLAGS_HF); return( AFP_OK ); } @@ -869,8 +818,8 @@ int afp_rmvcomment(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _ struct vol *vol; struct dir *dir; struct path *s_path; - u_int32_t did; - u_int16_t vid; + uint32_t did; + uint16_t vid; *rbuflen = 0; ibuf += 2;