From: Volker Kuhlmann <bugz57@top.geek.nz>
Date: 2025-09-25 08:02:32 +0200
References: https://bugzilla.suse.com/show_bug.cgi?id=1250493

cdda2wab fails CDDB lookups from gnudb.org.
Unfortunately gnudb.org is the only freedb style server still
available.
Within the last few months gnudb started to require registrations
(free, no personal details needed, only a receive-one email address)
to get a unique code.
This is sensible for dealing with DDoS attacks or other service
abuse.

Unfortunately cdda2wav can't deal with passing the user-token to the
server.
This problem affects all versions of cdda2wav.

This patch adds a command line option to set the unique code to use
with gnudb.

<https://gnudb.org/info.php>
---
 cdda2wav/cdda2wav.1 |    5 ++++-
 cdda2wav/cdda2wav.c |    3 +++
 cdda2wav/global.h   |    1 +
 cdda2wav/toc.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)

Index: cdrtools/cdda2wav/cdda2wav.1
===================================================================
--- cdrtools.orig/cdda2wav/cdda2wav.1
+++ cdrtools/cdda2wav/cdda2wav.1
@@ -14,7 +14,7 @@
 .if n .ds s sz
 .if t .ds m \\(*m
 .if n .ds m micro
-.TH CDDA2WAV 1 "2022/09/11" "J\*org Schilling" "Schily\'s USER COMMANDS"
+.TH CDDA2WAV 1 "2025/09/25" "J\*org Schilling" "Schily\'s USER COMMANDS"
 .SH NAME
 cdda2wav \- dumps CD audio data into sound files with extra data verification
 .SH SYNOPSIS
@@ -223,6 +223,9 @@ sets the server to be contacted for titl
 .BI cddbp\-port= portnumber
 sets the port number to be used for title lookups.
 .TP
+.BI cddbp\-user= username
+sets the username (gnudb.org uniqcode) for title lookups.
+.TP
 .BI \-d " duration"
 .TP
 .BI \-duration " duration"
Index: cdrtools/cdda2wav/cdda2wav.c
===================================================================
--- cdrtools.orig/cdda2wav/cdda2wav.c
+++ cdrtools/cdda2wav/cdda2wav.c
@@ -192,6 +192,7 @@ find-extremes,F,find-mono,G,no-infofile,
 no-textfile,cuefile,no-hidden-track,\
 deemphasize,T,info-only,J,silent-scsi,Q,\
 cddbp-server*,cddbp-port*,\
+cddbp-user*,\
 scanbus,device*,dev*,D*,scgopts*,debug#,debug-scsi#,kdebug#,kd#,kdebug-scsi#,ts&,\
 auxdevice*,A*,interface*,I*,output-format*,O*,\
 output-endianness*,E*,cdrom-endianness*,C*,speed#,S#,\
@@ -1194,6 +1195,7 @@ OPTIONS:\n\
        -paraopts=opts		set options for lib paranoia (see -paraopts=help).\n\
        -cddbp-server=servername	set the cddbp server to use for title lookups.\n\
        -cddbp-port=portnumber	set the cddbp port to use for title lookups.\n\
+       -cddbp-user=username     set the unique user name for title lookups (needed for gnudb).\n\
        -interactive		select interactive mode (used by gstreamer plugin).\n\
        -version			print version information.\n\
 \n\
@@ -4004,6 +4006,7 @@ gargs(argc, argv)
 			&global.scsi_silent, &global.scsi_silent,
 
 			&global.cddbp_server, &global.cddbp_port,
+			&global.cddbp_user,
 			&global.scanbus,
 			&global.dev_name, &global.dev_name, &global.dev_name,
 			&global.dev_opts,
Index: cdrtools/cdda2wav/global.h
===================================================================
--- cdrtools.orig/cdda2wav/global.h
+++ cdrtools/cdda2wav/global.h
@@ -114,6 +114,7 @@ typedef struct global {
 	int			cddbp;
 	char *			cddbp_server;
 	char *			cddbp_port;
+	char *			cddbp_user;
 	unsigned		cddb_revision;
 	int			cddb_year;
 	char			cddb_genre[60];
Index: cdrtools/cdda2wav/toc.c
===================================================================
--- cdrtools.orig/cdda2wav/toc.c
+++ cdrtools/cdda2wav/toc.c
@@ -9,6 +9,8 @@ static	UConst char sccsid[] =
  * Copyright (c) 2004-2020 J. Schilling, Heiko Eissfeldt
  *
  * The CDDB routines are compatible to cddbd (C) Ti Kan and Steve Scherf
+ *
+ * gnudb.org uniqcode usernames added by Volker Kuhlmann, 25 Sep 2025.
  */
 /*
  * The contents of this file are subject to the terms of the
@@ -1413,6 +1415,43 @@ request_titles()
 	/*
 	 * say hello
 	 */
+
+	/*
+	 * When a CDDBP user name was supplied.
+	 * By Sep 2025, gnudb.org requires a "unique code" (user identifier,
+	 * free with a random name and a receive-once email address).
+	 * Also now the "cddb" line must be sent in one packet, or the gnudb
+	 * server returns an error, so it must be assembled in memory first.
+	 *
+	 * There seems to be no other free freedb-style service left.
+	 *
+	 * Formats accepted by gnudb.org, Sep 2025:
+	 *   cddb hello= uniqcode schily.cdda2wav.net cdda2wav 3.02_linux_x86_64_x86_64
+	 *   cddb hello=uniqcode user host cdda2wav 3.02_linux_x86_64_x86_64
+	 *   cddb hello=uniqcode uniqcode host cdda2wav 3.02_linux_x86_64_x86_64
+	 */
+	if (global.cddbp_user != NULL) {
+		char *s = malloc(100+2*64+strlen(VERSION)+strlen(VERSION_OS));
+		if (s == NULL) {
+			retval = -1;
+			goto errout;
+		}
+		strcpy(s, "cddb hello=");
+		strncat(s, global.cddbp_user, 64);
+		strcat(s, " ");
+		strncat(s, global.cddbp_user, 64);
+		strcat(s, " schily.cdda2wav.net cdda2wav ");
+		strcat(s, VERSION);
+		strcat(s, VERSION_OS);
+		writen(sock_fd, s, strlen(s));
+		free(s);
+	} else {
+
+	/*
+	 * The original part not using a unique code.
+	 * Alternatively one could change this part to assemble the cddb line
+	 * in memory first, with alternatives for gnudb.
+	 */
 	hostname[0] = '\0';
 	if (0 > gethostname(hostname, sizeof (hostname)))
 		strcpy(hostname, "unknown_host");
@@ -1485,6 +1524,9 @@ request_titles()
 	writen(sock_fd, " cdda2wav ", 10);
 	writen(sock_fd, VERSION, strlen(VERSION));
 	writen(sock_fd, VERSION_OS, strlen(VERSION_OS));
+	/* End of original cddbp code. */
+
+    	}
 	writen(sock_fd, "\n", 1);
 
 	readbytes = readn(sock_fd, inbuff, sizeof (inbuff));
