File: pptp_compat.c

package info (click to toggle)
pptp-linux 1.10.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: ansic: 3,689; makefile: 142; perl: 117
file content (93 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* pptp_compat.c ... Compatibility functions
 *
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#if defined (__SVR4) && defined (__sun) /* Solaris */
#include <stropts.h>
#endif
#include <strings.h>
#include "pptp_compat.h"
#include <stdio.h>
#include "util.h"

#if defined (__SVR4) && defined (__sun) /* Solaris */
/*
 * daemon implementation from uClibc
 */
int daemon(int nochdir, int noclose)
{
	int fd;

	switch (fork()) {
	case -1:
		return (-1);
	case 0:
		break;
	default:
		_exit(0);
	}

	if (setsid() == -1)
		return (-1);

	if (!nochdir)
		chdir("/");

	if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
		dup2(fd, STDIN_FILENO);
		dup2(fd, STDOUT_FILENO);
		dup2(fd, STDERR_FILENO);
		if (fd > 2)
			close (fd);
	}
	return (0);
}

/*
 * openpty implementation based on pts(7D) example
 */ 
int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize * winp) {
	int fdm,fds;
	char * slavename;

	/* open master */
	if ( (fdm = open("/dev/ptmx", O_RDWR)) == -1 ) 
		return -1;

	/* grant access to the slave pseudo-terminal device */
	if ( grantpt(fdm) == -1 )
		return -1;

	/* unlock a pseudo-terminal master/slave pair */
	if ( unlockpt(fdm) == -1 )
		return -1;

	/* get name of the slave pseudo-terminal device */
	if ( (slavename = ptsname(fdm)) == NULL ) 
		return -1;

	if ( (fds = open(slavename, O_RDWR)) == -1 ) {
		free(slavename);
		return -1;
	}

	ioctl(fds, I_PUSH, "ptem");       /* push ptem */
	ioctl(fds, I_PUSH, "ldterm");     /* push ldterm*/
	
	if ( name != NULL )
		strcpy(name,slavename);

	*amaster = fdm;
	*aslave = fds;

	free(slavename);
	return 0;
	
}
#endif /* Solaris */