miniupnpd: dynamically retrieve `uname -r`

fixes #547
This commit is contained in:
Thomas Bernard 2021-05-22 00:16:40 +02:00
parent 479f6ed616
commit 08ae9e9e71
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
8 changed files with 105 additions and 22 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.477 2021/05/13 11:31:18 nanard Exp $ $Id: Changelog.txt,v 1.478 2021/05/21 22:03:13 nanard Exp $
2021/05/22:
dynamically retrieve `uname -r`
VERSION 2.2.2 : released on 2021/05/13 VERSION 2.2.2 : released on 2021/05/13

16
miniupnpd/configure vendored
View File

@ -1,10 +1,10 @@
#! /bin/sh #! /bin/sh
# $Id: configure,v 1.114 2020/10/30 22:10:26 nanard Exp $ # $Id: configure,v 1.116 2021/05/21 22:04:34 nanard Exp $
# vim: tabstop=4 shiftwidth=4 noexpandtab # vim: tabstop=4 shiftwidth=4 noexpandtab
# #
# miniupnp daemon # miniupnp daemon
# http://miniupnp.free.fr or https://miniupnp.tuxfamily.org/ # http://miniupnp.free.fr or https://miniupnp.tuxfamily.org/
# (c) 2006-2020 Thomas Bernard # (c) 2006-2021 Thomas Bernard
# This software is subject to the conditions detailed in the # This software is subject to the conditions detailed in the
# LICENCE file provided within the distribution # LICENCE file provided within the distribution
@ -16,7 +16,11 @@ UPNP_VERSION_MINOR=1
# input environment variables : # input environment variables :
# IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER, # IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER,
# PORTINUSE, DISABLEPPPCONN, FW, IPTABLESPATH, TARGET_OPENWRT, # PORTINUSE, DISABLEPPPCONN, FW, IPTABLESPATH, TARGET_OPENWRT,
# PKG_CONFIG, NO_BACKGROUND_NO_PIDFILE # PKG_CONFIG, NO_BACKGROUND_NO_PIDFILE, DYNAMIC_OS_VERSION
if [ -z "$DYNAMIC_OS_VERSION" ] ; then
DYNAMIC_OS_VERSION=1
fi
for argv; do for argv; do
case "$argv" in case "$argv" in
@ -131,7 +135,7 @@ ${RM} ${CONFIGFILE}
echo "/* MiniUPnP Project" >> ${CONFIGFILE} echo "/* MiniUPnP Project" >> ${CONFIGFILE}
echo " * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/" >> ${CONFIGFILE} echo " * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
echo " * (c) 2006-2020 Thomas Bernard" >> ${CONFIGFILE} echo " * (c) 2006-2021 Thomas Bernard" >> ${CONFIGFILE}
echo " * generated by $0 on `date`" >> ${CONFIGFILE} echo " * generated by $0 on `date`" >> ${CONFIGFILE}
echo " * `uname -a`" >> ${CONFIGFILE} echo " * `uname -a`" >> ${CONFIGFILE}
if [ -z "$*" ] ; then if [ -z "$*" ] ; then
@ -606,6 +610,10 @@ echo " * figure 2.2 in UPnP-gw-WANIPConnection-v2-Service.pdf */" >> ${CONFIGFIL
echo "#define ENABLE_PORT_TRIGGERING" >> ${CONFIGFILE} echo "#define ENABLE_PORT_TRIGGERING" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE} echo "" >> ${CONFIGFILE}
if [ $DYNAMIC_OS_VERSION -ne 0 ] ; then
OS_VERSION="%s"
echo "#define DYNAMIC_OS_VERSION 1" >> ${CONFIGFILE}
fi
echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE} echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE} echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE} echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}

View File

@ -1,4 +1,4 @@
/* $Id: minissdp.c,v 1.99 2020/05/10 17:55:32 nanard Exp $ */ /* $Id: minissdp.c,v 1.103 2021/05/21 22:05:17 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project * MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
@ -558,6 +558,9 @@ SendSSDPResponse(int s, const struct sockaddr * addr,
st_len, st, suffix, st_len, st, suffix,
uuidvalue, st_is_uuid ? "" : "::", uuidvalue, st_is_uuid ? "" : "::",
st_is_uuid ? 0 : st_len, st, suffix, st_is_uuid ? 0 : st_len, st, suffix,
#ifdef DYNAMIC_OS_VERSION
os_version,
#endif
host, (unsigned int)http_port, host, (unsigned int)http_port,
#ifdef RANDOMIZE_URLS #ifdef RANDOMIZE_URLS
random_url, random_url,
@ -687,6 +690,9 @@ SendSSDPNotify(int s, const struct sockaddr * dest, socklen_t dest_len,
random_url, random_url,
#endif /* RANDOMIZE_URLS */ #endif /* RANDOMIZE_URLS */
#endif /* ENABLE_HTTPS */ #endif /* ENABLE_HTTPS */
#ifdef DYNAMIC_OS_VERSION
os_version,
#endif
nt, suffix, /* NT: */ nt, suffix, /* NT: */
usn1, usn2, usn3, suffix, /* USN: */ usn1, usn2, usn3, suffix, /* USN: */
upnp_bootid, /* 01-NLS: */ upnp_bootid, /* 01-NLS: */
@ -1541,9 +1547,22 @@ SubmitServicesToMiniSSDPD(const char * host, unsigned short port) {
CODELENGTH(l, p); CODELENGTH(l, p);
memcpy(p, strbuf, l); memcpy(p, strbuf, l);
p += l; p += l;
#ifdef DYNAMIC_OS_VERSION
l = snprintf(strbuf, sizeof(strbuf), MINIUPNPD_SERVER_STRING,
os_version);
if(l<0) {
syslog(LOG_WARNING, "SubmitServicesToMiniSSDPD: snprintf %m");
continue;
} else if((unsigned)l>=sizeof(strbuf)) {
l = sizeof(strbuf) - 1;
}
CODELENGTH(l, p);
memcpy(p, strbuf, l);
#else
l = (int)strlen(MINIUPNPD_SERVER_STRING); l = (int)strlen(MINIUPNPD_SERVER_STRING);
CODELENGTH(l, p); CODELENGTH(l, p);
memcpy(p, MINIUPNPD_SERVER_STRING, l); memcpy(p, MINIUPNPD_SERVER_STRING, l);
#endif
p += l; p += l;
l = snprintf(strbuf, sizeof(strbuf), "http://%s:%u" ROOTDESC_PATH, l = snprintf(strbuf, sizeof(strbuf), "http://%s:%u" ROOTDESC_PATH,
host, (unsigned int)port); host, (unsigned int)port);

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpd.c,v 1.243 2020/04/12 17:43:13 nanard Exp $ */ /* $Id: miniupnpd.c,v 1.250 2021/05/21 22:04:34 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project * MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
@ -59,6 +59,10 @@
#include <openssl/crypto.h> #include <openssl/crypto.h>
#endif #endif
#ifdef DYNAMIC_OS_VERSION
#include <sys/utsname.h>
#endif
#ifdef TOMATO #ifdef TOMATO
#include <sys/stat.h> #include <sys/stat.h>
#endif /* TOMATO */ #endif /* TOMATO */
@ -2199,6 +2203,18 @@ main(int argc, char * * argv)
} }
} }
#ifdef DYNAMIC_OS_VERSION
{
struct utsname utsname;
if (uname(&utsname) < 0) {
syslog(LOG_ERR, "uname(): %m");
os_version = strdup("unknown");
} else {
os_version = strdup(utsname.release);
}
}
#endif /* DYNAMIC_OS_VERSION */
if(GETFLAG(ENABLEUPNPMASK)) if(GETFLAG(ENABLEUPNPMASK))
{ {
unsigned short listen_port; unsigned short listen_port;
@ -3109,6 +3125,9 @@ shutdown:
#ifndef DISABLE_CONFIG_FILE #ifndef DISABLE_CONFIG_FILE
/* in some case shutdown_redirect() may need the option values */ /* in some case shutdown_redirect() may need the option values */
freeoptions(); freeoptions();
#endif
#ifdef DYNAMIC_OS_VERSION
free(os_version);
#endif #endif
closelog(); closelog();
return 0; return 0;

View File

@ -1,18 +1,25 @@
/* $Id: $ */ /* $Id: testssdppktgen.c,v 1.2 2021/05/21 22:05:17 nanard Exp $ */
#include <stdio.h> #include <stdio.h>
#include <syslog.h> #include <syslog.h>
#include <time.h> #include <time.h>
#include "config.h" #include "config.h"
#ifdef DYNAMIC_OS_VERSION
#include <string.h>
#include <sys/utsname.h>
#endif
#include "miniupnpdpath.h" #include "miniupnpdpath.h"
#include "upnphttp.h" #include "upnphttp.h"
#include "macros.h" #include "macros.h"
#define SSDP_PORT 1900 #define SSDP_PORT 1900
char uuidvalue_igd[] = "uuid:12345678-0000-0000-0000-000000abcd01"; const char uuidvalue_igd[] = "uuid:12345678-0000-0000-0000-000000abcd01";
unsigned upnp_bootid; unsigned upnp_bootid;
unsigned upnp_configid; unsigned upnp_configid;
#ifdef DYNAMIC_OS_VERSION
char * os_version;
#endif
static int static int
MakeSSDPPacket(const char * dest_str, MakeSSDPPacket(const char * dest_str,
@ -49,6 +56,9 @@ MakeSSDPPacket(const char * dest_str,
host, (unsigned int)http_port, /* LOCATION: */ host, (unsigned int)http_port, /* LOCATION: */
#ifdef ENABLE_HTTPS #ifdef ENABLE_HTTPS
host, (unsigned int)https_port, /* SECURE-LOCATION: */ host, (unsigned int)https_port, /* SECURE-LOCATION: */
#endif
#ifdef DYNAMIC_OS_VERSION
os_version,
#endif #endif
nt, suffix, /* NT: */ nt, suffix, /* NT: */
usn1, usn2, usn3, suffix, /* USN: */ usn1, usn2, usn3, suffix, /* USN: */
@ -64,6 +74,7 @@ MakeSSDPPacket(const char * dest_str,
l = sizeof(bufr) - 1; l = sizeof(bufr) - 1;
return -1; return -1;
} }
syslog(LOG_DEBUG, "%s", bufr);
return 0; return 0;
} }
@ -71,9 +82,21 @@ MakeSSDPPacket(const char * dest_str,
int main(int argc, char * * argv) int main(int argc, char * * argv)
{ {
int r; int r;
#ifdef DYNAMIC_OS_VERSION
struct utsname utsname;
#endif
UNUSED(argc); UNUSED(argv); UNUSED(argc); UNUSED(argv);
openlog("testssdppktgen", LOG_CONS|LOG_PERROR, LOG_USER); openlog("testssdppktgen", LOG_CONS|LOG_PERROR, LOG_USER);
#ifdef DYNAMIC_OS_VERSION
if (uname(&utsname) < 0) {
syslog(LOG_ERR, "uname(): %m");
os_version = strdup("unknown");
} else {
os_version = strdup(utsname.release);
syslog(LOG_INFO, "OS_VERSION : %s", os_version);
}
#endif
upnp_bootid = (unsigned)time(NULL); upnp_bootid = (unsigned)time(NULL);
upnp_configid = 1234567890; upnp_configid = 1234567890;
r = MakeSSDPPacket("123.456.789.123", "222.222.222.222", 12345, r = MakeSSDPPacket("123.456.789.123", "222.222.222.222", 12345,

View File

@ -1,8 +1,8 @@
/* $Id: upnpglobalvars.c,v 1.45 2019/10/02 22:02:58 nanard Exp $ */ /* $Id: upnpglobalvars.c,v 1.47 2021/05/21 22:03:38 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project * MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard * (c) 2006-2021 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -157,3 +157,7 @@ unsigned int upnp_configid = 1337; /* CONFIGID.UPNP.ORG */
#ifdef RANDOMIZE_URLS #ifdef RANDOMIZE_URLS
char random_url[RANDOM_URL_MAX_LEN] = "random"; char random_url[RANDOM_URL_MAX_LEN] = "random";
#endif /* RANDOMIZE_URLS */ #endif /* RANDOMIZE_URLS */
#ifdef DYNAMIC_OS_VERSION
char * os_version = NULL;
#endif /* DYNAMIC_OS_VERSION */

View File

@ -1,8 +1,8 @@
/* $Id: upnpglobalvars.h,v 1.48 2019/05/21 08:39:45 nanard Exp $ */ /* $Id: upnpglobalvars.h,v 1.51 2021/05/21 22:03:38 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project * MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard * (c) 2006-2021 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -171,4 +171,8 @@ extern unsigned int upnp_configid;
extern char random_url[]; extern char random_url[];
#endif /* RANDOMIZE_URLS */ #endif /* RANDOMIZE_URLS */
#ifdef DYNAMIC_OS_VERSION
extern char * os_version;
#endif
#endif /* UPNPGLOBALVARS_H_INCLUDED */ #endif /* UPNPGLOBALVARS_H_INCLUDED */

View File

@ -1,9 +1,9 @@
/* $Id: upnphttp.c,v 1.108 2019/10/05 18:05:13 nanard Exp $ */ /* $Id: upnphttp.c,v 1.110 2021/05/21 22:03:14 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* Project : miniupnp * Project : miniupnp
* Website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Website : http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* Author : Thomas Bernard * Author : Thomas Bernard
* Copyright (c) 2005-2020 Thomas Bernard * Copyright (c) 2005-2021 Thomas Bernard
* This software is subject to the conditions detailed in the * This software is subject to the conditions detailed in the
* LICENCE file included in this distribution. * LICENCE file included in this distribution.
* */ * */
@ -29,7 +29,7 @@
#include "upnpsoap.h" #include "upnpsoap.h"
#include "upnpevents.h" #include "upnpevents.h"
#include "upnputils.h" #include "upnputils.h"
#ifdef RANDOMIZE_URLS #if defined(RANDOMIZE_URLS) || defined(DYNAMIC_OS_VERSION)
#include "upnpglobalvars.h" #include "upnpglobalvars.h"
#endif /* RANDOMIZE_URLS */ #endif /* RANDOMIZE_URLS */
@ -1103,12 +1103,11 @@ BuildHeader_upnphttp(struct upnphttp * h, int respcode,
const char * respmsg, const char * respmsg,
int bodylen) int bodylen)
{ {
int templen; int templen = sizeof(httpresphead) + 256 + bodylen;
if(!h->res_buf || if(!h->res_buf ||
h->res_buf_alloclen < ((int)sizeof(httpresphead) + 256 + bodylen)) { h->res_buf_alloclen < templen) {
if(h->res_buf) if(h->res_buf)
free(h->res_buf); free(h->res_buf);
templen = sizeof(httpresphead) + 256 + bodylen;
h->res_buf = (char *)malloc(templen); h->res_buf = (char *)malloc(templen);
if(!h->res_buf) { if(!h->res_buf) {
syslog(LOG_ERR, "malloc error in BuildHeader_upnphttp()"); syslog(LOG_ERR, "malloc error in BuildHeader_upnphttp()");
@ -1121,7 +1120,11 @@ BuildHeader_upnphttp(struct upnphttp * h, int respcode,
httpresphead, h->HttpVer, httpresphead, h->HttpVer,
respcode, respmsg, respcode, respmsg,
(h->respflags&FLAG_HTML)?"text/html":"text/xml; charset=\"utf-8\"", (h->respflags&FLAG_HTML)?"text/html":"text/xml; charset=\"utf-8\"",
bodylen); bodylen
#ifdef DYNAMIC_OS_VERSION
, os_version
#endif
);
/* Content-Type MUST be 'text/xml; charset="utf-8"' according to UDA v1.1 */ /* Content-Type MUST be 'text/xml; charset="utf-8"' according to UDA v1.1 */
/* Content-Type MUST be 'text/xml' according to UDA v1.0 */ /* Content-Type MUST be 'text/xml' according to UDA v1.0 */
/* Additional headers */ /* Additional headers */