#endif /* BYTE_ORDER == BIG_ENDIAN */
#endif /* ! NO_LARGE_VOL_SUPPORT */
+#ifndef UUID_PRINTABLE_STRING_LENGTH
+#define UUID_PRINTABLE_STRING_LENGTH 37
+#endif
+
static struct vol *Volumes = NULL;
static u_int16_t lastvid = 0;
static char *Trash = "\02\024Network Trash Folder";
if (volume->v_flags & AFPVOL_TM) {
char *uuid = get_uuid(obj, volume->v_localname);
if (!uuid) {
- LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID, disabling TM support",
+ LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID",
volume->v_localname);
- volume->v_flags &= ~AFPVOL_TM;
} else {
volume->v_uuid = uuid;
LOG(log_debug, logtype_afpd, "Volume '%s': UUID '%s'",
*/
char *get_uuid(const AFPObj *obj, const char *volname)
{
- struct stat st;
-
- char *usersign;
- int fd, i;
- struct stat tmpstat;
char *volname_conf;
- int header = 0;
char buf[1024], uuid[UUID_PRINTABLE_STRING_LENGTH], *p;
- FILE *fp, *randomp;
- size_t len;
+ FILE *fp;
+ struct stat tmpstat;
+ int fd;
if ((fp = fopen(obj->options.uuidconf, "r")) != NULL) { /* read open? */
/* scan in the conf file */
p++;
if (sscanf(p, "%36s", uuid) == 1 ) {
+ for (int i=0; uuid[i]; i++)
+ uuid[i] = toupper(uuid[i]);
LOG(log_debug, logtype_afpd, "get_uuid('%s'): UUID: '%s'", volname, uuid);
fclose(fp);
return strdup(uuid);
fclose(fp);
/* not found or no file, reopen in append mode */
- if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) {
+
+ if (stat(obj->options.uuidconf, &tmpstat)) { /* no file */
+ if (( fd = creat(obj->options.uuidconf, 0644 )) < 0 ) {
+ LOG(log_error, logtype_atalkd, "ERROR: Cannot create %s (%s).",
+ obj->options.uuidconf, strerror(errno));
+ return NULL;
+ }
+ if (( fp = fdopen( fd, "w" )) == NULL ) {
+ LOG(log_error, logtype_atalkd, "ERROR: Cannot fdopen %s (%s).",
+ obj->options.uuidconf, strerror(errno));
+ close(fd);
+ return NULL;
+ }
+ } else if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) { /* not found */
LOG(log_error, logtype_afpd, "Cannot create or append to %s (%s).",
obj->options.uuidconf, strerror(errno));
return NULL;
fseek(fp, 0L, SEEK_END);
if(ftell(fp) == 0) { /* size = 0 */
fprintf(fp, "# DON'T TOUCH NOR COPY THOUGHTLESSLY!\n");
- fprintf(fp, "# This file is auto-generated by afpd.\n");
- fprintf(fp, "# \n");
- fprintf(fp, "# This file stores UUIDs for all volumes, either auto-generated ones\n");
- fprintf(fp, "# or the value from AppleVolumes.default:uuid\n");
- fprintf(fp, "# \n");
- fprintf(fp, "# If both values differ, the one from AppleVolumes.default is used.\n\n");
+ fprintf(fp, "# This file is auto-generated by afpd\n");
+ fprintf(fp, "# and stores UUIDs for TM volumes.\n\n");
} else {
fseek(fp, -1L, SEEK_END);
if(fgetc(fp) != '\n') fputc('\n', fp); /* last char is \n? */
uuid_t id;
uuid_generate(id);
uuid_unparse(id, uuid);
+ for (int i=0; uuid[i]; i++)
+ uuid[i] = toupper(uuid[i]);
LOG(log_debug, logtype_afpd, "get_uuid('%s'): generated UUID '%s'", volname, uuid);
fprintf(fp, "\"%s\"\t%36s\n", volname, uuid);