#include "config.h"
#endif /* HAVE_CONFIG_H */
-
+#include <unistd.h>
+#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#ifdef STDC_HEADERS
#include <string.h>
-#endif
#include <sys/param.h>
#include <atalk/adouble.h>
#include <atalk/logger.h>
#include <atalk/volinfo.h>
#include <atalk/volume.h>
+#include <atalk/compat.h>
#ifdef CNID_DB
#include <atalk/cnid.h>
#endif /* CNID_DB*/
static const vol_opt_name_t vol_opt_names[] = {
- {AFPVOL_A2VOL, "PRODOS"}, /* prodos volume */
- {AFPVOL_CRLF, "CRLF"}, /* cr/lf translation */
- {AFPVOL_NOADOUBLE, "NOADOUBLE"}, /* don't create .AppleDouble by default */
{AFPVOL_RO, "READONLY"}, /* read-only volume */
- {AFPVOL_MSWINDOWS, "MSWINDOWS"}, /* deal with ms-windows yuckiness. this is going away. */
{AFPVOL_NOHEX, "NOHEX"}, /* don't do :hex translation */
{AFPVOL_USEDOTS, "USEDOTS"}, /* use real dots */
- {AFPVOL_LIMITSIZE, "LIMITSIZE"}, /* limit size for older macs */
- {AFPVOL_MAPASCII, "MAPASCII"}, /* map the ascii range as well */
- {AFPVOL_DROPBOX, "DROPBOX"}, /* dropkludge dropbox support */
- {AFPVOL_NOFILEID, "NOFILEID"}, /* don't advertise createid resolveid and deleteid calls */
{AFPVOL_NOSTAT, "NOSTAT"}, /* advertise the volume even if we can't stat() it
* maybe because it will be mounted later in preexec */
{AFPVOL_UNIX_PRIV, "UNIXPRIV"}, /* support unix privileges */
{AFPVOL_NODEV, "NODEV"}, /* always use 0 for device number in cnid calls */
{AFPVOL_CASEINSEN, "CASEINSENSITIVE"}, /* volume is case insensitive */
{AFPVOL_EILSEQ, "ILLEGALSEQ"}, /* encode illegal sequence */
- {AFPVOL_CACHE, "CACHEID"}, /* Use adouble v2 CNID caching, default don't use it */
{AFPVOL_INV_DOTS, "INVISIBLEDOTS"},
{AFPVOL_ACLS, "ACLS"}, /* Vol supports ACLs */
{AFPVOL_TM, "TM"}, /* Set "kSupportsTMLockSteal" is volume attributes */
vol->v_ad_options = 0;
if ((vol->v_flags & AFPVOL_NODEV))
vol->v_ad_options |= ADVOL_NODEV;
- if ((vol->v_flags & AFPVOL_CACHE))
- vol->v_ad_options |= ADVOL_CACHE;
if ((vol->v_flags & AFPVOL_UNIX_PRIV))
vol->v_ad_options |= ADVOL_UNIXPRIV;
if ((vol->v_flags & AFPVOL_INV_DOTS))
*/
int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_port)
{
+ uid_t process_uid;
char buf[16348];
char item[MAXPATHLEN];
int fd;
strlcat (item, "/.AppleDesktop/", sizeof(item));
strlcat (item, VOLINFOFILE, sizeof(item));
- if ((fd = open( item, O_RDWR | O_CREAT , 0666)) <0 ) {
- LOG(log_debug, logtype_afpd,"Error opening %s: %s", item, strerror(errno));
+ process_uid = geteuid();
+ if (process_uid) {
+ if (seteuid(0) == -1) {
+ process_uid = 0;
+ }
+ }
+
+ if ((fd = open(item, O_RDWR | O_CREAT , 0666)) <0 ) {
+ LOG(log_debug, logtype_default,"Error opening %s: %s", item, strerror(errno));
+ if (process_uid) {
+ if (seteuid(process_uid) == -1) {
+ LOG(log_error, logtype_default, "can't seteuid back %s", strerror(errno));
+ exit(EXITERR_SYS);
+ }
+ }
return (-1);
}
+ if (process_uid) {
+ if (seteuid(process_uid) == -1) {
+ LOG(log_error, logtype_default, "can't seteuid back %s", strerror(errno));
+ exit(EXITERR_SYS);
+ }
+ }
+
/* try to get a lock */
lock.l_start = 0;
lock.l_whence = SEEK_SET;
/* ignore, other process already writing the file */
return 0;
} else {
- LOG(log_error, logtype_cnid, "savevoloptions: cannot get lock: %s", strerror(errno));
+ LOG(log_error, logtype_default, "savevoloptions: cannot get lock: %s", strerror(errno));
return (-1);
}
}
strlcat(buf, item, sizeof(buf));
if (strlen(buf) >= sizeof(buf)-1)
- LOG(log_debug, logtype_afpd,"Error writing .volinfo file: buffer too small, %s", buf);
+ LOG(log_debug, logtype_default, "Error writing .volinfo file: buffer too small, %s", buf);
if (write( fd, buf, strlen(buf)) < 0 || ftruncate(fd, strlen(buf)) < 0 ) {
- LOG(log_debug, logtype_afpd,"Error writing .volinfo file: %s", strerror(errno));
+ LOG(log_debug, logtype_default, "Error writing .volinfo file: %s", strerror(errno));
}
lock.l_type = F_UNLCK;