New upstream version 2.1.3
This commit is contained in:
29
nxredir/Makefile
Normal file
29
nxredir/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
PREFIX ?= /usr
|
||||
PATH_BIN ?= $(PREFIX)/bin
|
||||
PATH_LIB ?= $(PREFIX)/lib
|
||||
CUPS_BACKEND ?= $(PREFIX)/lib/cups/backend
|
||||
|
||||
all: libnxredir.so
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-g -O2 -Wall -fPIC
|
||||
LIBNAME=libnxredir.so
|
||||
VERSION=0
|
||||
|
||||
libnxredir.so: nxredir.o
|
||||
$(CC) -fPIC $(CFLAGS) -nostdlib -shared -Wl,-soname,$(LIBNAME).$(VERSION) -o $(LIBNAME).$(VERSION) nxredir.o -ldl -lc
|
||||
|
||||
clean:
|
||||
rm -f $(LIBNAME)
|
||||
rm -f $(LIBNAME).$(VERSION)
|
||||
rm -f *.o
|
||||
|
||||
install:
|
||||
install -m755 -s $(LIBNAME).$(VERSION) $(DESTDIR)/$(PATH_LIB)/freenx-server/
|
||||
install -m755 nxredir $(DESTDIR)/$(PATH_BIN)/
|
||||
install -m755 nxsmb $(DESTDIR)/$(CUPS_BACKEND)/
|
||||
sed -i -e 's|PATH_LIB=.*|PATH_LIB='$(PATH_LIB)'|' $(DESTDIR)/$(PATH_BIN)/nxredir
|
||||
sed -i -e 's|PATH_LIB=.*|PATH_LIB='$(PATH_LIB)'|' $(DESTDIR)/$(CUPS_BACKEND)/nxsmb
|
||||
sed -i -e 's|CUPS_BACKEND=.*|CUPS_BACKEND='$(CUPS_BACKEND)'|' $(DESTDIR)/$(CUPS_BACKEND)/nxsmb
|
||||
|
||||
.PHONY: clean install
|
||||
21
nxredir/nxredir
Executable file
21
nxredir/nxredir
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
PATH_LIB="/usr/lib"
|
||||
NXREDIR_LIBRARY="$PATH_LIB/freenx-server/libnxredir.so.0"
|
||||
|
||||
if [ -z "$NXCUPS_PORT" -a -z "$NXSAMBA_PORT" ]
|
||||
then
|
||||
echo "nxredir: Redirect standard ports to nxproxy"
|
||||
echo ""
|
||||
echo "Usage: export NXCUPS_PORT='where_cups_is_running'"
|
||||
echo " export NXSAMBA_PORT='where_samba_is_running'"
|
||||
|
||||
# invoke the program with the args given
|
||||
exec "$@"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
export LD_PRELOAD="$NXREDIR_LIBRARY${LD_PRELOAD:+:$LD_PRELOAD}"
|
||||
|
||||
# invoke the program with the args given
|
||||
exec "$@"
|
||||
116
nxredir/nxredir.c
Normal file
116
nxredir/nxredir.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* libnxredir - Redirect certain ports to other forwarded ports.
|
||||
*
|
||||
* Copyright (c) 2005-2008 by Fabian Franz <freenx@fabian-franz.de>.
|
||||
*
|
||||
* License: GPL, version 2
|
||||
*
|
||||
* Based on TSOCKS - Wrapper library for transparent SOCKS
|
||||
*
|
||||
* Copyright (C) 2000 Shaun Clowes
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
char *progname = "libnxredir"; /* Name used in err msgs */
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
/* Header Files */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/time.h>
|
||||
#include <pwd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sys/un.h>
|
||||
|
||||
#define CONNECT_SIGNATURE int __fd, const struct sockaddr * __addr, socklen_t __len
|
||||
|
||||
static int (*realconnect)(CONNECT_SIGNATURE);
|
||||
|
||||
/* Exported Function Prototypes */
|
||||
void _init(void);
|
||||
|
||||
int connect(CONNECT_SIGNATURE);
|
||||
|
||||
void _init(void)
|
||||
{
|
||||
realconnect = dlsym(RTLD_NEXT, "connect");
|
||||
}
|
||||
|
||||
int is_local(struct in_addr *testip) {
|
||||
|
||||
if (testip->s_addr == htonl(0x7f000001))
|
||||
return(1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int connect(CONNECT_SIGNATURE)
|
||||
{
|
||||
struct sockaddr_in *connaddr;
|
||||
struct sockaddr_in peer_address;
|
||||
int sock_type = -1;
|
||||
socklen_t sock_type_len = sizeof(sock_type);
|
||||
socklen_t namelen = sizeof(peer_address);
|
||||
|
||||
if (realconnect == NULL) {
|
||||
perror("Unresolved symbol: connect\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
connaddr = (struct sockaddr_in *) __addr;
|
||||
|
||||
/* Get the type of the socket */
|
||||
getsockopt(__fd, SOL_SOCKET, SO_TYPE,
|
||||
(void *) &sock_type, &sock_type_len);
|
||||
|
||||
/* If this isn't an INET socket for a TCP stream we can't */
|
||||
/* handle it, just call the real connect now */
|
||||
if ((connaddr->sin_family != AF_INET) || (sock_type != SOCK_STREAM))
|
||||
return(realconnect(__fd, __addr, __len));
|
||||
|
||||
/* If the socket is already connected, just call connect */
|
||||
/* and get its standard reply */
|
||||
if (!getpeername(__fd, (struct sockaddr *) &peer_address, &namelen))
|
||||
return(realconnect(__fd, __addr, __len));
|
||||
|
||||
/* If the address is not local call realconnect */
|
||||
if (!is_local(&(connaddr->sin_addr)))
|
||||
return(realconnect(__fd, __addr, __len));
|
||||
|
||||
/* CUPS */
|
||||
if ((getenv("NXCUPS_PORT") != NULL) && connaddr->sin_port==htons(631))
|
||||
connaddr->sin_port=htons(atoi(getenv("NXCUPS_PORT")));
|
||||
|
||||
/* SAMBA */
|
||||
if ((getenv("NXSAMBA_PORT") != NULL) && (connaddr->sin_port==htons(139) || connaddr->sin_port==htons(445)))
|
||||
connaddr->sin_port=htons(atoi(getenv("NXSAMBA_PORT")));
|
||||
|
||||
return realconnect(__fd, __addr, __len);
|
||||
}
|
||||
45
nxredir/nxsmb
Executable file
45
nxredir/nxsmb
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# nxsmb: Small wrapper for the SMB backend to be able to print to CIFS or SMB ports directly.
|
||||
#
|
||||
# Copyright (c) 2008 by Fabian Franz.
|
||||
#
|
||||
#
|
||||
|
||||
# turn on DEBUG?
|
||||
#set -x -v
|
||||
CUPS_BACKEND="/usr/lib/cups/backend"
|
||||
PATH_LIB="/usr/lib"
|
||||
|
||||
NXREDIR_LIBRARY="$PATH_LIB/freenx-server/libnxredir.so.0"
|
||||
COMMAND_SMB="$CUPS_BACKEND/smb"
|
||||
|
||||
PORT=$(echo $DEVICE_URI | cut -d/ -f3 | cut -d@ -f2 | cut -d: -f2)
|
||||
PROTOCOL=$(echo $DEVICE_URI | cut -d/ -f4)
|
||||
PRINTER=$(echo $DEVICE_URI | cut -d/ -f5)
|
||||
|
||||
if [ -z "$PRINTER" ]; then # old style setup
|
||||
echo "Warning: Not using nxredir library. The DEVICE_URI is not in the right format."
|
||||
exec "$COMMAND_SMB" "$@"
|
||||
fi
|
||||
|
||||
if [ ! -x "$NXREDIR_LIBRARY" ]; then
|
||||
# repair DEVICE_URI
|
||||
DEVICE_URI=$(echo $DEVICE_URI | sed "s|/$PROTOCOL||g")
|
||||
echo "Error: Not using nxredir library. $NXREDIR_LIBRARY could not be found or is not executable."
|
||||
exec "$COMMAND_SMB" "$@"
|
||||
fi
|
||||
|
||||
if [ "$PROTOCOL" = "cifs" -o "$PROTOCOL" = "CIFS" ]; then
|
||||
REAL_PORT="445"
|
||||
else
|
||||
REAL_PORT="139"
|
||||
fi
|
||||
|
||||
DEVICE_URI=$(echo $DEVICE_URI | sed "s|:$PORT/$PROTOCOL/|:$REAL_PORT/|g")
|
||||
export DEVICE_URI=$(echo $DEVICE_URI | sed "s|nxsmb://|smb://|g")
|
||||
|
||||
export NXSAMBA_PORT="$PORT"
|
||||
export LD_PRELOAD="$NXREDIR_LIBRARY${LD_PRELOAD:+:$LD_PRELOAD}"
|
||||
|
||||
exec "$COMMAND_SMB" "$@"
|
||||
Reference in New Issue
Block a user