#include <tcpd.h>
#endif
+#include <libcfs/portals_utils.h>
#include <portals/api-support.h>
-#include <portals/list.h>
#include <portals/lib-types.h>
#include <portals/socknal.h>
void
usage (char *myname)
{
- fprintf (stderr, "Usage: %s [-N nal_id] port\n", myname);
+ fprintf (stderr,
+ "Usage: %s [-N nal_id] [-p] [-l] port\n\n"
+ " -l\tKeep stdin/stdout open\n"
+ " -p\tAllow connections from non-privileged ports\n",
+ myname);
exit (1);
}
int c;
int noclose = 0;
int nal = SOCKNAL;
+ int rport;
+ int require_privports = 1;
- while ((c = getopt (argc, argv, "N:l")) != -1)
- switch (c)
- {
- case 'l':
- noclose = 1;
- break;
-
+ while ((c = getopt (argc, argv, "N:lp")) != -1) {
+ switch (c) {
case 'N':
if (sscanf(optarg, "%d", &nal) != 1 ||
nal < 0 || nal > NAL_MAX_NR)
usage(argv[0]);
break;
-
+ case 'l':
+ noclose = 1;
+ break;
+ case 'p':
+ require_privports = 0;
+ break;
default:
usage (argv[0]);
break;
}
+ }
if (optind >= argc)
usage (argv[0]);
exit(1);
}
- rc = daemon(1, noclose);
+ rc = daemon(0, noclose);
if (rc < 0) {
perror("daemon(): ");
exit(1);
struct portals_cfg pcfg;
#ifdef HAVE_LIBWRAP
struct request_info request;
- char addrstr[INET_ADDRSTRLEN];
#endif
+ char addrstr[INET_ADDRSTRLEN];
cfd = accept(fd, (struct sockaddr *)&clntaddr, &len);
if ( cfd < 0 ) {
continue;
}
#endif
+
+ if (require_privports && ntohs(clntaddr.sin_port) >= IPPORT_RESERVED) {
+ inet_ntop(AF_INET, &clntaddr.sin_addr,
+ addrstr, INET_ADDRSTRLEN);
+ syslog(LOG_ERR, "Closing non-privileged connection from %s:%d\n",
+ addrstr, ntohs(clntaddr.sin_port));
+ rc = close(cfd);
+ if (rc)
+ perror ("close un-privileged client failed");
+ continue;
+ }
+
show_connection (cfd, clntaddr.sin_addr.s_addr);
PCFG_INIT(pcfg, NAL_CMD_REGISTER_PEER_FD);