#include "config.h"
#endif /* HAVE_CONFIG_H */
-
+#include <unistd.h>
+#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
*/
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;