X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Ffile.c;h=47555f3c241396d4ed55f39fb9122054cabaf954;hb=ea05e68c3aad7262dc00f85b1ce8769de409b6b1;hp=fac35b7fa71a1e282d92dcb28a30f1b2f75e3f5c;hpb=21b17908047ad4f3b00a9f6a4655494d874390b0;p=netatalk.git diff --git a/etc/afpd/file.c b/etc/afpd/file.c index fac35b7f..47555f3c 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -1,5 +1,5 @@ /* - * $Id: file.c,v 1.120 2009-11-02 14:35:27 didg Exp $ + * $Id: file.c,v 1.139 2010-02-18 08:08:01 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -89,7 +89,7 @@ static int default_type(void *finder) } /* FIXME path : unix or mac name ? (for now it's unix name ) */ -void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *adp, void *data) +void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *adp, void *data, int islink) { struct extmap *em; void *ad_finder = NULL; @@ -114,6 +114,17 @@ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *a memcpy((char *)data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort)); } } + + if (islink){ + u_int16_t linkflag; + memcpy(&linkflag, (char *)data + FINDERINFO_FRFLAGOFF, 2); + linkflag |= htons(FINDERINFO_ISALIAS); + memcpy((char *)data + FINDERINFO_FRFLAGOFF, &linkflag, 2); + memcpy((char *)data + FINDERINFO_FRTYPEOFF,"slnk",4); + memcpy((char *)data + FINDERINFO_FRCREATOFF,"rhap",4); + chk_ext = 0; + } + /** Only enter if no appledouble information and no finder information found. */ if (chk_ext && (em = getextmap( upath ))) { memcpy(data, em->em_type, sizeof( em->em_type )); @@ -158,7 +169,7 @@ char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t if (aint > 255) /* FIXME safeguard, anyway if no ascii char it's game over*/ aint = 255; - utf8 = vol->v_mac?htonl(vol->v_mac->kTextEncoding):0; /* htonl(utf8) */ + utf8 = vol->v_kTextEncoding; memcpy(data, &utf8, sizeof(utf8)); data += sizeof(utf8); @@ -187,25 +198,24 @@ char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t (1 << FILPBIT_RFLEN) |\ (1 << FILPBIT_EXTRFLEN) |\ (1 << FILPBIT_PDINFO) |\ + (1 << FILPBIT_FNUM) |\ (1 << FILPBIT_UNIXPR))) /* -------------------------- */ u_int32_t get_id(struct vol *vol, struct adouble *adp, const struct stat *st, - const cnid_t did, char *upath, const int len) + const cnid_t did, char *upath, const int len) { -u_int32_t aint = 0; - -#if AD_VERSION > AD_VERSION1 - - if ((aint = ad_getid(adp, st->st_dev, st->st_ino, did, vol->v_stamp))) { - return aint; - } -#endif + u_int32_t adcnid; + u_int32_t dbcnid = CNID_INVALID; if (vol->v_cdb != NULL) { - aint = cnid_add(vol->v_cdb, st, did, upath, len, aint); + /* prime aint with what we think is the cnid, set did to zero for + catching moved files */ + adcnid = ad_getid(adp, st->st_dev, st->st_ino, 0, vol->v_stamp); + + dbcnid = cnid_add(vol->v_cdb, st, did, upath, len, adcnid); /* Throw errors if cnid_add fails. */ - if (aint == CNID_INVALID) { + if (dbcnid == CNID_INVALID) { switch (errno) { case CNID_ERR_CLOSE: /* the db is closed */ break; @@ -221,18 +231,15 @@ u_int32_t aint = 0; return CNID_INVALID; } } -#if AD_VERSION > AD_VERSION1 - else if (adp ) { - /* update the ressource fork - * for a folder adp is always null - */ - if (ad_setid(adp, st->st_dev, st->st_ino, aint, did, vol->v_stamp)) { + else if (adp && (adcnid != dbcnid)) { + /* Update the ressource fork. For a folder adp is always null */ + LOG(log_debug, logtype_afpd, "get_id: calling ad_setid. adcnid: %u, dbcnid: %u", htonl(adcnid), htonl(dbcnid)); + if (ad_setid(adp, st->st_dev, st->st_ino, dbcnid, did, vol->v_stamp)) { ad_flush(adp); } } -#endif } - return aint; + return dbcnid; } /* -------------------------- */ @@ -268,7 +275,7 @@ int getmetadata(struct vol *vol, id = get_id(vol, adp, st, dir->d_did, upath, strlen(upath)); else id = path->id; - if (id == 0) + if (id == CNID_INVALID) return afp_errno; if (!path->m_name) { path->m_name = utompath(vol, upath, id, utf8_encoding()); @@ -336,7 +343,7 @@ int getmetadata(struct vol *vol, break; case FILPBIT_FINFO : - get_finderinfo(vol, upath, adp, (char *)data); + get_finderinfo(vol, upath, adp, (char *)data,S_ISLNK(st->st_mode)); data += ADEDLEN_FINDERI; break; @@ -531,7 +538,7 @@ int getfilparams(struct vol *vol, adp = of_ad(vol, path, &ad); upath = path->u_name; - if ( ad_metadata( upath, flags, adp) < 0 ) { + if ( ad_metadata( upath, flags|ADFLAGS_CREATE, adp) < 0 ) { switch (errno) { case EACCES: LOG(log_error, logtype_afpd, "getfilparams(%s): %s: check resource fork permission?", @@ -623,7 +630,7 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, openf = O_RDWR|O_CREAT|O_EXCL; } - if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF|ADFLAGS_CREATE, + if ( ad_open( upath, ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF|ADFLAGS_CREATE, openf, 0666, adp) < 0 ) { switch ( errno ) { case EROFS: @@ -741,7 +748,7 @@ int setfilparams(struct vol *vol, int bit, isad = 1, err = AFP_OK; char *upath; u_char achar, *fdType, xyy[4]; /* uninitialized, OK 310105 */ - u_int16_t ashort, bshort; + u_int16_t ashort, bshort, oshort; u_int32_t aint; u_int32_t upriv; u_int16_t upriv_bit = 0; @@ -799,6 +806,28 @@ int setfilparams(struct vol *vol, case FILPBIT_FINFO : change_mdate = 1; memcpy(finder_buf, buf, 32 ); + if (memcmp(buf,"slnkrhap",8)==0 && !S_ISLNK(path->st.st_mode)){ + // SLFINFO + int fp; + ssize_t len; + int erc=1; + char buf[PATH_MAX+1]; + if ((fp=open(path->u_name,O_RDONLY))>=0){ + if ((len=read(fp,buf,PATH_MAX+1))){ + if (unlink(path->u_name)==0){ + buf[len]=0; + erc = symlink(buf, path->u_name); + if (!erc) + of_stat(path); + } + } + close(fp); + } + if (erc!=0){ + err=AFPERR_BITMAP; + goto setfilparam_done; + } + } buf += 32; break; case FILPBIT_UNIXPR : @@ -861,16 +890,16 @@ int setfilparams(struct vol *vol, /* second try with adouble open */ - if ( ad_open_metadata( upath, vol_noadouble(vol), O_CREAT, adp) < 0) { + if ( ad_open_metadata( upath, 0, O_CREAT, adp) < 0) { LOG(log_debug, logtype_afpd, "setfilparams: ad_open_metadata error"); /* * For some things, we don't need an adouble header: * - change of modification date * - UNIX privs (Bug-ID #2863424) */ - if ( (f_bitmap & ~(1<newtmp; @@ -1188,42 +1218,54 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si p = ctoupath( s_vol, curdir, newname ); if (!p) { - return AFPERR_PARAM; - + retvalue = AFPERR_PARAM; + goto copy_exit; } + #ifdef FORCE_UIDGID /* FIXME svid != dvid && dvid's user can't read svid */ #endif if (NULL == ( d_vol = getvolbyvid( dvid )) ) { - return( AFPERR_PARAM ); + retvalue = AFPERR_PARAM; + goto copy_exit; } - if (d_vol->v_flags & AFPVOL_RO) - return AFPERR_VLOCK; + if (d_vol->v_flags & AFPVOL_RO) { + retvalue = AFPERR_VLOCK; + goto copy_exit; + } if (NULL == ( dir = dirlookup( d_vol, ddid )) ) { - return afp_errno; + retvalue = afp_errno; + goto copy_exit; } if (( s_path = cname( d_vol, dir, &ibuf )) == NULL ) { - return get_afp_errno(AFPERR_NOOBJ); + retvalue = get_afp_errno(AFPERR_NOOBJ); + goto copy_exit; } + if ( *s_path->m_name != '\0' ) { - path_error(s_path, AFPERR_PARAM); + retvalue =path_error(s_path, AFPERR_NOOBJ); + goto copy_exit; } /* one of the handful of places that knows about the path type */ if (copy_path_name(d_vol, newname, ibuf) < 0) { - return( AFPERR_PARAM ); + retvalue = AFPERR_PARAM; + goto copy_exit; } /* newname is always only a filename so curdir *is* its * parent folder */ if (NULL == (upath = mtoupath(d_vol, newname, curdir->d_did, utf8_encoding()))) { - return( AFPERR_PARAM ); + retvalue =AFPERR_PARAM; + goto copy_exit; } + if ( (err = copyfile(s_vol, d_vol, p, upath , newname, adp)) < 0 ) { - return err; + retvalue = err; + goto copy_exit; } curdir->offcnt++; @@ -1235,6 +1277,8 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si setvoltime(obj, d_vol ); +copy_exit: + ad_close( adp, ADFLAGS_DF |ADFLAGS_HF ); return( retvalue ); } @@ -1359,7 +1403,7 @@ int copyfile(const struct vol *s_vol, const struct vol*d_vol, ad_init(&ads, s_vol->v_adouble, s_vol->v_ad_options); adp = &ads; } - ad_init(&add, d_vol->v_adouble, d_vol->v_ad_options); + adflags = ADFLAGS_DF; if (newname) { adflags |= ADFLAGS_HF; @@ -1382,6 +1426,7 @@ int copyfile(const struct vol *s_vol, const struct vol*d_vol, st.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; } + ad_init(&add, d_vol->v_adouble, d_vol->v_ad_options); if (ad_open(dst , adflags, O_RDWR|O_CREAT|O_EXCL, st.st_mode, &add) < 0) { ret_err = errno; ad_close( adp, adflags ); @@ -1498,7 +1543,11 @@ int deletefile(const struct vol *vol, char *file, int checkAttrib) if (checkAttrib) { /* was EACCESS error try to get only metadata */ ad_init(&ad, vol->v_adouble, vol->v_ad_options); - if ( ad_metadata( file , ADFLAGS_OPENFORKS, &ad) == 0 ) { + /* we never want to create a resource fork here, we are going to delete it + * moreover sometimes deletefile is called with a no existent file and + * ad_open would create a 0 byte resource fork + */ + if ( ad_metadata( file, ADFLAGS_OPENFORKS, &ad) == 0 ) { ad_close( &ad, adflags ); if ((err = check_attrib(&ad))) { return err; @@ -1654,7 +1703,7 @@ static int reenumerate_loop(struct dirent *de, char *mname _U_, void *data) cnid_t did = param->did; cnid_t aint; - if ( stat(de->d_name, &path.st)<0 ) + if ( lstat(de->d_name, &path.st)<0 ) return 0; /* update or add to cnid */ @@ -1699,7 +1748,7 @@ reenumerate_id(struct vol *vol, char *name, struct dir *dir) } /* FIXME use of_statdir ? */ - if (stat(name, &st)) { + if (lstat(name, &st)) { return -1; } @@ -1869,7 +1918,7 @@ int afp_deleteid(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_ } err = AFP_OK; - if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) { + if ((movecwd(vol, dir) < 0) || (lstat(upath, &st) < 0)) { switch (errno) { case EACCES: case EPERM: @@ -2114,10 +2163,10 @@ int afp_exchangefiles(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U if (did) { cnid_delete(vol->v_cdb, did); } - if ((did && ( (crossdev && stat( upath, &srcst) < 0) || + if ((did && ( (crossdev && lstat( upath, &srcst) < 0) || cnid_update(vol->v_cdb, did, &srcst, curdir->d_did,upath, dlen) < 0)) || - (sid && ( (crossdev && stat(p, &destst) < 0) || + (sid && ( (crossdev && lstat(p, &destst) < 0) || cnid_update(vol->v_cdb, sid, &destst, sdir->d_did,supath, slen) < 0)) ) { switch (errno) {