From: Frank Lahm Date: Mon, 16 Apr 2012 10:04:25 +0000 (+0200) Subject: Move AppleDesktop to localstatedir X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=7392efc658e4fab6399f2a243e87c934a3042e68 Move AppleDesktop to localstatedir --- diff --git a/etc/afpd/desktop.c b/etc/afpd/desktop.c index 2a408467..5c45d312 100644 --- a/etc/afpd/desktop.c +++ b/etc/afpd/desktop.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "volume.h" #include "directory.h" @@ -37,109 +38,21 @@ #include "desktop.h" #include "mangle.h" -typedef struct _special_folder { - const char *name; - int precreate; - mode_t mode; - int hide; -} _special_folder; - -static const _special_folder special_folders[] = { - {".AppleDesktop", 1, 0777, 0}, - {NULL, 0, 0, 0}}; - -/* - * precreate a folder - * this is only intended for folders in the volume root - * It will *not* work if the folder name contains extended characters - */ -static int create_special_folder (const struct vol *vol, const struct _special_folder *folder) -{ - char *p,*q,*r; - struct adouble ad; - uint16_t attr; - struct stat st; - int ret; - - - p = (char *) malloc ( strlen(vol->v_path)+strlen(folder->name)+2); - if ( p == NULL) { - LOG(log_error, logtype_afpd,"malloc failed"); - exit (EXITERR_SYS); - } - - q=strdup(folder->name); - if ( q == NULL) { - LOG(log_error, logtype_afpd,"malloc failed"); - exit (EXITERR_SYS); - } - - strcpy(p, vol->v_path); - strcat(p, "/"); - - r=q; - while (*r) { - if ((vol->v_casefold & AFPVOL_MTOUUPPER)) - *r=toupper(*r); - else if ((vol->v_casefold & AFPVOL_MTOULOWER)) - *r=tolower(*r); - r++; - } - strcat(p, q); - - if ( (ret = stat( p, &st )) < 0 ) { - if (folder->precreate) { - if (ad_mkdir(p, folder->mode)) { - LOG(log_debug, logtype_afpd,"Creating '%s' failed in %s: %s", p, vol->v_path, strerror(errno)); - free(p); - free(q); - return -1; - } - ret = 0; - } - } - - if ( !ret && folder->hide) { - /* Hide it */ - ad_init(&ad, vol); - if (ad_open(&ad, p, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0) { - free(p); - free(q); - return (-1); - } - - ad_setname(&ad, folder->name); - - ad_getattr(&ad, &attr); - attr |= htons( ntohs( attr ) | ATTRBIT_INVISIBLE ); - ad_setattr(&ad, attr); - - /* do the same with the finder info */ - if (ad_entry(&ad, ADEID_FINDERI)) { - memcpy(&attr, ad_entry(&ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, sizeof(attr)); - attr |= htons(FINDERINFO_INVISIBLE); - memcpy(ad_entry(&ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF,&attr, sizeof(attr)); - } - - ad_flush(&ad); - ad_close(&ad, ADFLAGS_HF); - } - free(p); - free(q); - return 0; -} - static void create_appledesktop_folder(const struct vol * vol) { - const _special_folder *p = &special_folders[0]; + bstring dtpath; + struct stat st; - become_root(); + dtpath = bfromcstr(vol->v_dbpath); + bcatcstr(dtpath, "."); - for (; p->name != NULL; p++) { - create_special_folder (vol, p); + if (stat(bdata(dtpath), &st) != 0) { + become_root(); + mkdir(bdata(dtpath), 0777); + unbecome_root(); } - unbecome_root(); + bdestroy(dtpath); } int afp_opendt(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) @@ -612,8 +525,8 @@ char *dtfile(const struct vol *vol, u_char creator[], char *ext ) char *p; unsigned int i; - strcpy( path, vol->v_path ); - strcat( path, "/.AppleDesktop/" ); + strcpy( path, vol->v_dbpath ); + strcat( path, "/" APPLEDESKTOP "/" ); for ( p = path; *p != '\0'; p++ ) ; diff --git a/etc/afpd/desktop.h b/etc/afpd/desktop.h index ccaa1654..aa6a4b0f 100644 --- a/etc/afpd/desktop.h +++ b/etc/afpd/desktop.h @@ -1,6 +1,4 @@ /* - * $Id: desktop.h,v 1.6 2009-10-15 10:43:13 didg Exp $ - * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. * @@ -30,6 +28,8 @@ #include "volume.h" +#define APPLEDESKTOP ".AppleDesktop" + struct savedt { u_char sdt_creator[ 4 ]; int sdt_fd;