[pptp-server] diff - CAREFUL!

Peter Galbavy Peter.Galbavy at knowledge.com
Fri May 14 03:47:09 CDT 1999


attached are a set of diffs to make 0.8.4 run on OpenBSD. I *HAVE NOT*
included changes to the autogenerated files - so reconf is needed.

Note I *have* left the change from SYNC to ASYNC in there, but a
future version from me will make this command line selectable. I
suggest ignoring this particular part of the diffs...

-- 
Peter Galbavy
Knowledge Matters Ltd
http://www.knowledge.com/
-------------- next part --------------
Index: configure.in
===================================================================
RCS file: /cvs/software/pptpd/configure.in,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- configure.in	1999/05/13 06:44:09	1.1.1.2
+++ configure.in	1999/05/13 17:36:50	1.2
@@ -16,12 +16,16 @@
 AC_OBJEXT
 AC_SYS_INTERPRETER
 
+AC_CHECK_FUNCS(setsid daemon)
+
 AC_CHECK_HEADERS(stdio.h)
 AC_CHECK_HEADERS(getopt.h)
 AC_CHECK_HEADERS(stdlib.h)
 AC_CHECK_HEADERS(signal.h)
 AC_CHECK_HEADERS(string.h)
 AC_CHECK_HEADERS(unistd.h)
+AC_CHECK_HEADERS(termios.h)
+AC_CHECK_HEADERS(termio.h)
 AC_CHECK_HEADERS(arpa/inet.h)
 AC_CHECK_HEADERS(netdb.h)
 AC_CHECK_HEADERS(netinet/in.h)
Index: ctrlpacket.c
===================================================================
RCS file: /cvs/software/pptpd/ctrlpacket.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- ctrlpacket.c	1999/05/13 06:44:08	1.1.1.2
+++ ctrlpacket.c	1999/05/13 17:36:50	1.2
@@ -9,11 +9,11 @@
 #include "config.h"
 #endif
 
-#include <netinet/in.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <netinet/in.h>
 
 #include "pptpdebug.h"
 #include "pptpdefs.h"
@@ -265,7 +265,7 @@
 	start_ctrl_conn_rply.version = htons(PPTP_VERSION);
 	start_ctrl_conn_rply.result_code = 0x01;
 	start_ctrl_conn_rply.error_code = 0x00;
-	start_ctrl_conn_rply.framing_cap = htonl(SYNCHRONOUS_FRAMING);
+	start_ctrl_conn_rply.framing_cap = htonl(ASYNCHRONOUS_FRAMING);
 	start_ctrl_conn_rply.bearer_cap = htonl(DIGITAL_ACCESS);
 	start_ctrl_conn_rply.max_channels = htons(0x0001);
 	start_ctrl_conn_rply.firmware_rev = htons(PPTP_FIRMWARE_VERSION);
Index: pptpctrl.c
===================================================================
RCS file: /cvs/software/pptpd/pptpctrl.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- pptpctrl.c	1999/05/13 06:44:09	1.1.1.2
+++ pptpctrl.c	1999/05/13 17:36:50	1.2
@@ -14,14 +14,14 @@
 #endif
 
 
-#include <netinet/in.h>
-#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <netinet/in.h>
 
 #include "inststr.h"
 #include "pptpctrl.h"
Index: pptpd.c
===================================================================
RCS file: /cvs/software/pptpd/pptpd.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- pptpd.c	1999/05/12 20:06:11	1.1.1.1
+++ pptpd.c	1999/05/13 17:36:50	1.2
@@ -20,9 +20,17 @@
 
 #define CONSOLE "/dev/console"
 
+#if HAVE_TERMIO_H
 #include <termio.h>
 #define IOCTLPARM TCGETA
+#elif HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+#if HAVE_SETSID
+#define SETPGRP() (setsid())
+#else
 #define SETPGRP() (setpgrp())
+#endif
 
 
 
@@ -88,7 +96,7 @@
 
 		if(execvp(PPTP_MANAGER_BIN, &argv[0]) == -1) {
 		
-			printf("Couldn't 'exec' PPTP_MANAGER_BINARY\n\n");
+			printf("Couldn't 'exec' PPTP_MANAGER_BIN\n\n");
 			
 		}
 		
@@ -130,37 +138,3 @@
 	return 0;
 		
 }
-
-
-
-/*
- * Determine whether this file is a tty
- *
- */
-isitatty(fp)
-FILE *fp;
-{
-   return (!((ioctl(fileno(fp), IOCTLPARM, NULL) == -1) &&
-             (errno == ENOTTY)));
-}
-
-
-#ifdef BSD
-/*
- * Disassociate the current process from it's control terminal.
- *
- */
-static disoctty()
-{
-   int fd;
-
-   if ((fd = open("/dev/tty", O_RDWR)) >= 0)
-   {
-      ioctl(fd, TIOCNOTTY, NULL);
-      close(fd);
-   }
-}
-#endif
-
-
-
Index: pptpdcmds.c
===================================================================
RCS file: /cvs/software/pptpd/pptpdcmds.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- pptpdcmds.c	1999/05/12 20:06:12	1.1.1.1
+++ pptpdcmds.c	1999/05/13 17:36:50	1.2
@@ -10,21 +10,23 @@
 #endif
 
 
-#include <errno.h>
-#include <arpa/inet.h>
-#include <getopt.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <setjmp.h>
-#include <signal.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <errno.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <setjmp.h>
 
 #include "configfile.h"
 #include "defaults.h"
@@ -36,9 +38,18 @@
 #include <sys/types.h>
 #endif
 
+#if HAVE_TERMIO_H
 #include <termio.h>
 #define IOCTLPARM TCGETA
+#elif HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+
+#if HAVE_SETSID
+#define SETPGRP() (setsid())
+#else
 #define SETPGRP() (setpgrp())
+#endif
 
 #ifndef FALSE
 #define FALSE 0
@@ -145,7 +156,7 @@
 		int this_option_optind  = optind ? optind : 1;
 		int option_index = 0;
 		
-#ifdef EMBED
+#if EMBED || BSD
 #define	getopt_long(a,b,c,d,e)	getopt(a,b,c)
 #else
 		static struct option long_options[] =
Index: pptpdefs.h
===================================================================
RCS file: /cvs/software/pptpd/pptpdefs.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- pptpdefs.h	1999/05/12 20:06:11	1.1.1.1
+++ pptpdefs.h	1999/05/13 17:36:50	1.2
@@ -305,6 +305,8 @@
 
 #if EMBED
 	#define PPPD_BINARY		"/bin/pppd"
+#elif __OpenBSD__
+	#define	PPPD_BINARY		"/usr/sbin/ppp"
 #else
 	#define PPPD_BINARY		"/usr/sbin/pppd"
 #endif
Index: pptpgre.c
===================================================================
RCS file: /cvs/software/pptpd/pptpgre.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- pptpgre.c	1999/05/12 20:06:11	1.1.1.1
+++ pptpgre.c	1999/05/13 17:36:50	1.2
@@ -9,23 +9,25 @@
  *                Handle the IP Protocol 47 portion of PPTP.
  *                C. Scott Ananian <cananian at alumni.princeton.edu>
  *
- * $Id: pptpgre.c,v 1.1.1.1 1999/05/12 20:06:11 peter Exp $
+ * $Id: pptpgre.c,v 1.2 1999/05/13 17:36:50 peter Exp $
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
 #include "ppphdlc.h"
 #include "pptpdefs.h"
 #include "pptpdebug.h"
Index: pptpmanager.c
===================================================================
RCS file: /cvs/software/pptpd/pptpmanager.c,v
retrieving revision 1.1.1.2
retrieving revision 1.4
diff -u -r1.1.1.2 -r1.4
--- pptpmanager.c	1999/05/13 06:44:10	1.1.1.2
+++ pptpmanager.c	1999/05/13 17:44:33	1.4
@@ -27,13 +27,6 @@
 #endif
 
 
-#include <arpa/inet.h>
-#include <errno.h>
-#include <getopt.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <setjmp.h>
-#include <signal.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -42,6 +35,16 @@
 #include <sys/un.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#if HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <setjmp.h>
+#include <signal.h>
 
 #include "configfile.h"
 #include "defaults.h"
@@ -77,6 +80,7 @@
 //void childHandler();
 
 
+
 int pptp_manager(int argc, char **argv, char **envp) {
 		
         char *addrtest; // added for hostname/address lookup	-tmk
@@ -92,7 +96,7 @@
 	pid_t pppd_pid; // for forking PPPD
 	
 	char ptydev[PTYMAX], ttydev[TTYMAX];
-	int pty_fd;
+	int pty_fd, sockfd[2];
 	
 	struct in_addr inetaddr;
 	
@@ -327,8 +331,13 @@
 			pptpd_byte_debug("CALL_ID for this session", outcallid, 2);
 			///////////////////////////////////////////////////////////////////
 			
+#if __OpenBSD__
+			socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd);
+			pty_fd = sockfd[1];
+#else
 			// STOLEN - Finds an open pty/tty pair.. this is for PPP
 			pty_fd = getpseudotty(ttydev, ptydev);
+#endif
 	
 			// debugging //////////////////////////////////////////////////////	
 			sprintf(debug_msg, "ttydev = %s", ttydev);
@@ -354,6 +363,11 @@
 				// simply launches PPPD	
 				pptpd_debug("launching PPPD...", VERBOSE);
 		
+#if __OpenBSD__
+				dup2(sockfd[0], 0);
+				dup2(sockfd[0], 1);
+				close(sockfd[0]);
+#endif
 				if(launch_pppd(ttydev) == -1) {
 			
 					pptpd_debug("PPPD launch failed...", CRITICAL);
@@ -366,11 +380,14 @@
 			default: // parent
 
 				// do nothing		
+				close(sockfd[0]);
 	
+#ifndef __OpenBSD__
 				//#ifndef EMBED
 				pptpd_debug("Waiting for the child to terminate", VERBOSE);
-				wait(&status); // wait for the child to die
+				wait(&status); // wait for the child to die (actually daemonise)
 				//#endif
+#endif
 						
 				break;
 	
@@ -386,6 +403,9 @@
 	
 			pptpd_debug("Launching GRE connection server..", VERBOSE);
        		
+			sprintf(debug_msg, "pty_fd = %d", pty_fd);
+			pptpd_debug(debug_msg, VERBOSE);
+
 			// the GRE session will have to be handed the correct callid
 			// which should be located in outcallid
 		       	// Start the GRE encaps/decaps
@@ -450,6 +470,8 @@
 	char fileStr[5];
 	char optFile[256];
 	char localStr[6];
+	char directStr[16];
+	char pptpStr[16];   
 	
 	int result;
 	int an = 0;
@@ -461,6 +483,15 @@
 	pppd_argv[an] = PPPD_BINARY;
 	an++;
 	
+#if __OpenBSD__
+	strcpy(directStr, "-direct");
+	pppd_argv[an] = directStr;
+	an++;
+
+	strcpy(pptpStr, "pptp");
+	pppd_argv[an] = pptpStr;
+	an++;
+#else
 	pppd_argv[an] = ttydev;
 	an++;
 
@@ -555,6 +586,7 @@
 	strcpy(localStr, "local");
 	pppd_argv[an] = localStr; // don't use the modem control lines
 	an++;
+#endif
 	
 	// must end with NULL or the pppd daemon spits chips
 	pppd_argv[an] = NULL;


More information about the pptp-server mailing list