+
+server_signature_user:
+
+ /* Signature is defined in afp.conf */
+ memset(options->signature, 0, 16);
+ memcpy(options->signature, options->signatureopt, len);
+ goto server_signature_done;
+
+server_signature_auto:
+
+ /* Signature type is auto, using afp_signature.conf */
+ if (!stat(options->sigconffile, &tmpstat)) { /* conf file exists? */
+ if ((fp = fopen(options->sigconffile, "r")) != NULL) { /* read open? */
+ /* scan in the conf file */
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ p = buf;
+ while (p && isblank(*p))
+ p++;
+ if (!p || (*p == '#') || (*p == '\n'))
+ continue; /* invalid line */
+ if (*p == '"') {
+ p++;
+ if ((servername_conf = strtok( p, "\"" )) == NULL)
+ continue; /* syntax error: invalid quoted servername */
+ } else {
+ if ((servername_conf = strtok( p, " \t" )) == NULL)
+ continue; /* syntax error: invalid servername */
+ }
+ p = strchr(p, '\0');
+ p++;
+ if (*p == '\0')
+ continue; /* syntax error: missing signature */
+
+ if (strcmp(server_tmp, servername_conf))
+ continue; /* another servername */
+
+ while (p && isblank(*p))
+ p++;
+ if ( 16 == sscanf(p, "%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX%2hhX",
+ &options->signature[ 0], &options->signature[ 1],
+ &options->signature[ 2], &options->signature[ 3],
+ &options->signature[ 4], &options->signature[ 5],
+ &options->signature[ 6], &options->signature[ 7],
+ &options->signature[ 8], &options->signature[ 9],
+ &options->signature[10], &options->signature[11],
+ &options->signature[12], &options->signature[13],
+ &options->signature[14], &options->signature[15]
+ )) {
+ fclose(fp);
+ goto server_signature_done; /* found in conf file */
+ }
+ }
+ if ((fp = freopen(options->sigconffile, "a+", fp)) != NULL) { /* append because not found */
+ fseek(fp, 0L, SEEK_END);
+ if(ftell(fp) == 0) { /* size = 0 */
+ header = 1;
+ goto server_signature_random;
+ } else {
+ fseek(fp, -1L, SEEK_END);
+ if(fgetc(fp) != '\n') fputc('\n', fp); /* last char is \n? */
+ goto server_signature_random;
+ }
+ } else {
+ LOG(log_error, logtype_afpd, "ERROR: Cannot write in %s (%s). Using one-time signature.",
+ options->sigconffile, strerror(errno));
+ goto server_signature_random;
+ }
+ } else {
+ LOG(log_error, logtype_afpd, "ERROR: Cannot read %s (%s). Using one-time signature.",
+ options->sigconffile, strerror(errno));
+ goto server_signature_random;