net-mgmt/mac-telnet: Several fixes
* Fix building with OpenSSL 1.1 * Replace use of undirected broadcast with directed broadcast when sockets are bound to an interface IP * Do not override the mactelnetd.users file
This commit is contained in:
parent
c174cd15a9
commit
078b0010cf
@ -1,5 +1,6 @@
|
|||||||
PORTNAME= mac-telnet
|
PORTNAME= mac-telnet
|
||||||
PORTVERSION= 0.6.1
|
PORTVERSION= 0.6.1
|
||||||
|
PORTREVISION= 1
|
||||||
PORTEPOCH= 1
|
PORTEPOCH= 1
|
||||||
CATEGORIES= net-mgmt net
|
CATEGORIES= net-mgmt net
|
||||||
|
|
||||||
@ -20,10 +21,13 @@ GNU_CONFIGURE= yes
|
|||||||
GNU_CONFIGURE_MANPREFIX= ${PREFIX}/share
|
GNU_CONFIGURE_MANPREFIX= ${PREFIX}/share
|
||||||
LDFLAGS+= -L${LOCALBASE}/lib
|
LDFLAGS+= -L${LOCALBASE}/lib
|
||||||
CPPFLAGS+= -I${LOCALBASE}/include
|
CPPFLAGS+= -I${LOCALBASE}/include
|
||||||
|
CONFIGURE_ARGS+=--without-config
|
||||||
CONFIGURE_ENV+= CRYPTO_CFLAGS="-I${OPENSSLINC}" CRYPTO_LIBS="-L${OPENSSLLIB} -lssl -lcrypto"
|
CONFIGURE_ENV+= CRYPTO_CFLAGS="-I${OPENSSLINC}" CRYPTO_LIBS="-L${OPENSSLLIB} -lssl -lcrypto"
|
||||||
|
|
||||||
post-install:
|
post-install:
|
||||||
@${CHMOD} 0600 ${STAGEDIR}${PREFIX}/etc/mactelnetd.users
|
${INSTALL_DATA} ${BUILD_WRKSRC}/config/mactelnetd.users \
|
||||||
@-${CHOWN} root ${STAGEDIR}${PREFIX}/etc/mactelnetd.users
|
${STAGEDIR}${PREFIX}/etc/mactelnetd.users.sample
|
||||||
|
@${CHMOD} 0600 ${STAGEDIR}${PREFIX}/etc/mactelnetd.users.sample
|
||||||
|
@-${CHOWN} root ${STAGEDIR}${PREFIX}/etc/mactelnetd.users.sample
|
||||||
|
|
||||||
.include <bsd.port.mk>
|
.include <bsd.port.mk>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
--- configure.ac.orig 2024-06-19 14:50:22 UTC
|
--- configure.ac.orig 2024-08-12 21:08:19 UTC
|
||||||
+++ configure.ac
|
+++ configure.ac
|
||||||
@@ -79,6 +79,10 @@ case "$host_os" in
|
@@ -93,6 +93,10 @@ case "$host_os" in
|
||||||
AC_MSG_ERROR([pthreads library not found])
|
AC_MSG_ERROR([pthreads library not found])
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|||||||
40
net-mgmt/mac-telnet/files/patch-src_interfaces.c
Normal file
40
net-mgmt/mac-telnet/files/patch-src_interfaces.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
--- src/interfaces.c.orig 2024-08-15 15:58:48 UTC
|
||||||
|
+++ src/interfaces.c
|
||||||
|
@@ -150,6 +150,9 @@ int net_get_interfaces(struct net_interface **interfac
|
||||||
|
static const struct ifaddrs *ifaddrsp;
|
||||||
|
const struct sockaddr_in *dl_addr;
|
||||||
|
int found = 0;
|
||||||
|
+#if !defined(__FreeBSD__)
|
||||||
|
+ long allones_bcast = htonl(INADDR_BROADCAST);
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
if (getifaddrs(&int_addrs) < 0) {
|
||||||
|
perror("getifaddrs");
|
||||||
|
@@ -173,8 +176,14 @@ int net_get_interfaces(struct net_interface **interfac
|
||||||
|
|
||||||
|
if (ifaddrsp->ifa_addr->sa_family == AF_INET) {
|
||||||
|
memcpy(interface->ipv4_addr, &dl_addr->sin_addr, IPV4_ALEN);
|
||||||
|
+#if defined(__FreeBSD__)
|
||||||
|
+ memcpy(interface->bcast_addr, &((const struct sockaddr_in *)ifaddrsp->ifa_broadaddr)->sin_addr, IPV4_ALEN);
|
||||||
|
+#else
|
||||||
|
+ memcpy(interface->bcast_addr, &allones_bcast, IPV4_ALEN);
|
||||||
|
+#endif
|
||||||
|
} else {
|
||||||
|
memset(interface->ipv4_addr, 0, IPV4_ALEN);
|
||||||
|
+ memset(interface->bcast_addr, 0, IPV4_ALEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef __linux__
|
||||||
|
@@ -208,9 +217,12 @@ int net_get_interfaces(struct net_interface **interfac
|
||||||
|
DL_FOREACH(*interfaces, interface) {
|
||||||
|
struct in_addr *addr =
|
||||||
|
(struct in_addr *)interface->ipv4_addr;
|
||||||
|
+ struct in_addr *bcast =
|
||||||
|
+ (struct in_addr *)interface->bcast_addr;
|
||||||
|
|
||||||
|
printf("Interface %s:\n", interface->name);
|
||||||
|
printf("\tIP: %s\n", inet_ntoa(*addr));
|
||||||
|
+ printf("\tBCAST: %s\n", inet_ntoa(*bcast));
|
||||||
|
printf("\tMAC: %s\n",
|
||||||
|
ether_ntoa((struct ether_addr *)interface->mac_addr));
|
||||||
|
#ifdef __linux__
|
||||||
17
net-mgmt/mac-telnet/files/patch-src_interfaces.h
Normal file
17
net-mgmt/mac-telnet/files/patch-src_interfaces.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
--- src/interfaces.h.orig 2024-08-15 16:06:02 UTC
|
||||||
|
+++ src/interfaces.h
|
||||||
|
@@ -25,6 +25,7 @@ struct net_interface {
|
||||||
|
char name[256];
|
||||||
|
unsigned char ipv4_addr[IPV4_ALEN];
|
||||||
|
unsigned char mac_addr[ETH_ALEN];
|
||||||
|
+ unsigned char bcast_addr[IPV4_ALEN];
|
||||||
|
|
||||||
|
/* used by mactelnetd */
|
||||||
|
int socketfd;
|
||||||
|
@@ -57,4 +58,4 @@ extern int net_send_udp(const int socket, struct net_i
|
||||||
|
const unsigned char *destmac, const struct in_addr *sourceip, const int sourceport,
|
||||||
|
const struct in_addr *destip, const int destport, const unsigned char *data, const int datalen);
|
||||||
|
extern unsigned short in_cksum(unsigned short *addr, int len);
|
||||||
|
-#endif
|
||||||
|
\ No newline at end of file
|
||||||
|
+#endif
|
||||||
38
net-mgmt/mac-telnet/files/patch-src_mactelnet.c
Normal file
38
net-mgmt/mac-telnet/files/patch-src_mactelnet.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
--- src/mactelnet.c.orig 2024-08-15 16:46:24 UTC
|
||||||
|
+++ src/mactelnet.c
|
||||||
|
@@ -126,6 +126,8 @@ unsigned char mt_direction_fromserver = 0;
|
||||||
|
|
||||||
|
static unsigned int send_socket;
|
||||||
|
|
||||||
|
+static unsigned char *bcast_addr;
|
||||||
|
+
|
||||||
|
static int handle_packet(unsigned char *data, int data_len);
|
||||||
|
|
||||||
|
static void print_version() {
|
||||||
|
@@ -168,7 +170,7 @@ static int send_udp(struct mt_packet *packet, int retr
|
||||||
|
struct sockaddr_in socket_address;
|
||||||
|
socket_address.sin_family = AF_INET;
|
||||||
|
socket_address.sin_port = htons(MT_MACTELNET_PORT);
|
||||||
|
- socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||||
|
+ memcpy(&(socket_address.sin_addr), bcast_addr, IPV4_ALEN);
|
||||||
|
|
||||||
|
sent_bytes = sendto(send_socket, packet->data, packet->size, 0, (struct sockaddr *)&socket_address,
|
||||||
|
sizeof(socket_address));
|
||||||
|
@@ -470,6 +472,9 @@ static int find_interface() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
+#if defined(__FreeBSD__)
|
||||||
|
+ setsockopt(testsocket, IPPROTO_IP, IP_ONESBCAST, &optval, sizeof(optval));
|
||||||
|
+#endif
|
||||||
|
setsockopt(testsocket, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
|
||||||
|
setsockopt(testsocket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
||||||
|
|
||||||
|
@@ -488,6 +493,7 @@ static int find_interface() {
|
||||||
|
send_socket = testsocket;
|
||||||
|
memcpy(srcmac, interface->mac_addr, ETH_ALEN);
|
||||||
|
active_interface = interface;
|
||||||
|
+ bcast_addr = interface->bcast_addr;
|
||||||
|
|
||||||
|
/* Send a SESSIONSTART message with the current device */
|
||||||
|
init_packet(&data, MT_PTYPE_SESSIONSTART, srcmac, dstmac, sessionkey, 0);
|
||||||
33
net-mgmt/mac-telnet/files/patch-src_mactelnetd.c
Normal file
33
net-mgmt/mac-telnet/files/patch-src_mactelnetd.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
--- src/mactelnetd.c.orig 2024-08-15 17:08:22 UTC
|
||||||
|
+++ src/mactelnetd.c
|
||||||
|
@@ -254,6 +254,12 @@ static void setup_sockets() {
|
||||||
|
perror("SO_BROADCAST");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
+#if defined(__FreeBSD__)
|
||||||
|
+ if (setsockopt(interface->socketfd, IPPROTO_IP, IP_ONESBCAST, &optval, sizeof(optval)) == -1) {
|
||||||
|
+ perror("IP_ONESBCAST");
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
setsockopt(interface->socketfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
||||||
|
|
||||||
|
@@ -290,7 +296,7 @@ static int send_udp(const struct mt_connection *conn,
|
||||||
|
struct sockaddr_in socket_address;
|
||||||
|
socket_address.sin_family = AF_INET;
|
||||||
|
socket_address.sin_port = htons(conn->srcport);
|
||||||
|
- socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||||
|
+ memcpy(&(socket_address.sin_addr), &conn->interface->bcast_addr, IPV4_ALEN);
|
||||||
|
|
||||||
|
return sendto(conn->interface->socketfd, packet->data, packet->size, 0, (struct sockaddr *)&socket_address,
|
||||||
|
sizeof(socket_address));
|
||||||
|
@@ -315,7 +321,7 @@ static int send_special_udp(struct net_interface *inte
|
||||||
|
struct sockaddr_in socket_address;
|
||||||
|
socket_address.sin_family = AF_INET;
|
||||||
|
socket_address.sin_port = htons(port);
|
||||||
|
- socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||||
|
+ memcpy(&(socket_address.sin_addr), &interface->bcast_addr, IPV4_ALEN);
|
||||||
|
|
||||||
|
return sendto(interface->socketfd, packet->data, packet->size, 0, (struct sockaddr *)&socket_address,
|
||||||
|
sizeof(socket_address));
|
||||||
@ -1,6 +1,6 @@
|
|||||||
--- src/mndp.c.orig 2024-06-19 14:43:14 UTC
|
--- src/mndp.c.orig 2024-08-12 21:08:19 UTC
|
||||||
+++ src/mndp.c
|
+++ src/mndp.c
|
||||||
@@ -170,9 +170,12 @@ int mndp(int timeout, int batch_mode) {
|
@@ -177,9 +177,12 @@ int mndp(int timeout, int batch_mode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
90
net-mgmt/mac-telnet/files/patch-src_users.c
Normal file
90
net-mgmt/mac-telnet/files/patch-src_users.c
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
--- src/users.c.orig 2024-08-15 14:34:02 UTC
|
||||||
|
+++ src/users.c
|
||||||
|
@@ -211,6 +211,24 @@ struct mt_credentials *find_user(char *username) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+/*
|
||||||
|
+ * Filter out colons from the decoded string.
|
||||||
|
+ * By default, the OPENSSL_buf2hexstr function in OpenSSL 1.1
|
||||||
|
+ * uses colons as a byte separator, and this cannot be overridden.
|
||||||
|
+ */
|
||||||
|
+static void remove_colons(char *s) {
|
||||||
|
+ const char *p = s;
|
||||||
|
+ char *q = s;
|
||||||
|
+ while (*p != '\0') {
|
||||||
|
+ *q = *p++;
|
||||||
|
+ q += (*q != ':');
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ *q = '\0';
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
int add_user(const char *username, const char *password) {
|
||||||
|
FILE *rfile;
|
||||||
|
FILE *wfile;
|
||||||
|
@@ -289,12 +307,27 @@ int add_user(const char *username, const char *passwor
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fprintf(wfile, "%s:", username);
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+ char *output;
|
||||||
|
+ output = OPENSSL_buf2hexstr(newhash, MT_CRED_HASHLEN);
|
||||||
|
+ remove_colons(output);
|
||||||
|
+#else
|
||||||
|
char output[MT_CRED_HASHLEN * 2 + 1];
|
||||||
|
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newhash, MT_CRED_HASHLEN, '\0');
|
||||||
|
+#endif
|
||||||
|
fputs(output, wfile);
|
||||||
|
fputs(":", wfile);
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+ OPENSSL_free(output);
|
||||||
|
+ output = OPENSSL_buf2hexstr(newsalt, MT_CRED_SALTLEN);
|
||||||
|
+ remove_colons(output);
|
||||||
|
+#else
|
||||||
|
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newsalt, MT_CRED_SALTLEN, '\0');
|
||||||
|
+#endif
|
||||||
|
fputs(output, wfile);
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+ OPENSSL_free(output);
|
||||||
|
+#endif
|
||||||
|
fputs("\n", wfile);
|
||||||
|
found = 1;
|
||||||
|
} else {
|
||||||
|
@@ -306,12 +339,27 @@ int add_user(const char *username, const char *passwor
|
||||||
|
if (!found && password != NULL) {
|
||||||
|
// Write username, salt, and hashed password to the file
|
||||||
|
fprintf(wfile, "%s:", username);
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+ char *output;
|
||||||
|
+ output = OPENSSL_buf2hexstr(newhash, MT_CRED_HASHLEN);
|
||||||
|
+ remove_colons(output);
|
||||||
|
+#else
|
||||||
|
char output[MT_CRED_HASHLEN * 2 + 1];
|
||||||
|
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newhash, MT_CRED_HASHLEN, '\0');
|
||||||
|
+#endif
|
||||||
|
fputs(output, wfile);
|
||||||
|
fputs(":", wfile);
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+ OPENSSL_free(output);
|
||||||
|
+ output = OPENSSL_buf2hexstr(newsalt, MT_CRED_SALTLEN);
|
||||||
|
+ remove_colons(output);
|
||||||
|
+#else
|
||||||
|
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newsalt, MT_CRED_SALTLEN, '\0');
|
||||||
|
+#endif
|
||||||
|
fputs(output, wfile);
|
||||||
|
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
|
||||||
|
+ OPENSSL_free(output);
|
||||||
|
+#endif
|
||||||
|
fputs("\n", wfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -327,4 +375,4 @@ int add_user(const char *username, const char *passwor
|
||||||
|
}
|
||||||
|
|
||||||
|
return found ? 2 : 1;
|
||||||
|
-}
|
||||||
|
\ No newline at end of file
|
||||||
|
+}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
bin/macping
|
bin/macping
|
||||||
bin/mactelnet
|
bin/mactelnet
|
||||||
bin/mndp
|
bin/mndp
|
||||||
etc/mactelnetd.users
|
@sample etc/mactelnetd.users.sample
|
||||||
sbin/mactelnetd
|
sbin/mactelnetd
|
||||||
share/locale/bg/LC_MESSAGES/mactelnet.mo
|
share/locale/bg/LC_MESSAGES/mactelnet.mo
|
||||||
share/locale/nb/LC_MESSAGES/mactelnet.mo
|
share/locale/nb/LC_MESSAGES/mactelnet.mo
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user