1/* -*-C-*-
2
3 Header file for the GNU Emacs server and client C code.
4
5 This file is part of GNU Emacs.
6
7 Copying is permitted under those conditions described by the GNU
8 General Public License.
9
10 Copyright (C) 1989 Free Software Foundation, Inc.
11
12 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
13         'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
14         Emacs distribution.
15
16 Please mail bugs and suggestions to the author at the above address.
17*/
18
19/* HISTORY
20 * 11-Nov-1990		bristor@simba
21 *    Added EOT stuff.
22 */
23
24/*
25 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
26 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
27 * Please see the note at the end of the README file for details.
28 *
29 * (If gnuserv came bundled with your emacs, the README file is probably
30 * ../etc/gnuserv.README relative to the directory containing this file)
31 */
32
33#define GNUSERV_VERSION "3.12"
34
35#define USE_TMPDIR
36
37#define PATCHLEVEL 2
38
39#define NO_SHORTNAMES
40/* gnuserv should not be compiled using SOCKS */
41#define DO_NOT_SOCKSIFY
42#define DONT_ENCAPSULATE
43#include <config.h>
44#undef signal
45
46/* Define the communication method between server and clients:
47 *   You can have either or both kinds of sockets, but you can't mix
48 *   sockets with sysv ipc
49 */
50
51
52#if defined(HAVE_INTERNET_DOMAIN_SOCKETS) || defined(HAVE_UNIX_DOMAIN_SOCKETS)
53#if defined(HAVE_INTERNET_DOMAIN_SOCKETS)
54#define INTERNET_DOMAIN_SOCKETS
55#endif
56#if defined(HAVE_UNIX_DOMAIN_SOCKETS)
57#define UNIX_DOMAIN_SOCKETS
58#endif
59#else
60#if defined(HAVE_SYSVIPC)
61#define SYSV_IPC
62#endif
63#endif
64/*
65 * Define additional authentication protocols to be used. These methods will
66 * be tried before falling back to the default gnuserv protocol (based on
67 * the GNU_SECURE environment variable). Currently, only MIT-MAGIC-COOKIE-1
68 * is also supported.
69 *
70 * Comment out the next line(s) if you don't want to enable the
71 * appropriate authentication protocol.
72 */
73
74#if defined (HAVE_XAUTH)
75#define AUTH_MAGIC_COOKIE
76#endif /* HAVE_XAUTH */
77
78/*
79 * stuff related to supporting MIT-MAGIC-COOKIE-1
80 */
81
82#define MCOOKIE_SCREEN "999"     /* screen # to use as the gnuserv cookie */
83#define MCOOKIE_NAME   "MAGIC-1" /* authentication protocol name */
84#define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1"  /* as needed by X */
85
86
87#define DEFAUTH_NAME "GNU-SECURE"  /* name of default auth protocol */
88#define AUTH_TIMEOUT  15           /* # seconds to wait for auth data */
89#define AUTH_NAMESZ   15           /* max allows auth protocol name size */
90
91#include <sys/types.h>
92#include <sys/param.h>
93#include <sys/stat.h>
94#include <stdio.h>
95#include <stdlib.h>
96#include <string.h>
97#include <signal.h>
98#include <errno.h>
99
100#ifdef HAVE_UNISTD_H
101#include <unistd.h>
102#endif
103
104#ifdef HAVE_SYS_TIME_H
105#include <sys/time.h>
106#endif
107
108/*
109 * If you are using SYSV_IPC, you might want to make the buffer size bigger
110 * since it limits the size of requests and responses. Don't make it bigger
111 * than your system's max message size though (usually a couple of k) or else
112 * msgsend will start failing. For sockets, using the system BUFSIZ is usually
113 * what you want.
114 */
115
116# define GSERV_BUFSZ BUFSIZ
117
118
119#ifdef SYSV_IPC
120#include <sys/ipc.h>
121#include <sys/msg.h>
122
123#define send_string(s,str) \
124  if (strlen(msgp->mtext) + strlen(str) < GSERV_BUFSZ) \
125     strcat(msgp->mtext,str); \
126  else \
127  { \
128    fprintf(stderr,"%s: not enough message buffer space\n",progname); \
129     exit(1); \
130  } \
131
132#endif /* SYSV_IPC */
133
134#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
135#include <sys/socket.h>
136#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
137
138#ifdef INTERNET_DOMAIN_SOCKETS
139#include <netdb.h>
140#include <netinet/in.h>
141#include <arpa/inet.h>
142#define TABLE_SIZE 101		/* The number of entries in the hash table */
143#define HASH(host) host		/* Rather simplistic hash function */
144#define DEFAULT_PORT 21490	/* default port number to use is
145				 * DEFAULT_PORT + uid */
146#endif /* INTERNET_DOMAIN_SOCKETS */
147
148#ifdef UNIX_DOMAIN_SOCKETS
149#include <sys/un.h>
150#define HIDE_UNIX_SOCKET	/* put the unix socket in a protected dir */
151#endif /* UNIX_DOMAIN_SOCKETS */
152
153/* On some platforms, we need to do the equivalent of "stty litout" to get
154 * characters like ^D to pass through to emacs.  This problem has only
155 * been observed under emacs18; fsf19 and lemacs are probably okay without it.
156 */
157#ifndef DONT_USE_LITOUT
158#if !defined(HAVE_TERMIO) && !defined(HAVE_TERMIOS) && !defined(VMS)
159#if !defined(BSD4_1)
160#define USE_LITOUT
161#endif
162#endif
163#endif
164
165
166#define HOSTNAMSZ 255		/* max size of a hostname */
167#define REPLYSIZ 300		/* max size of reply from server to client */
168#undef FALSE
169#define FALSE 0
170#undef TRUE
171#define TRUE 1
172
173extern char *optarg;
174extern int optind;
175extern char *progname;
176extern char *tmpdir;
177
178/* The casts shut Sun's compiler up and are safe in the context these
179   are actually used. */
180#define max2(x,y) (((int) (x) > (int) (y)) ? (x) : (y))
181#define min2(x,y) (((int) (x) < (int) (y)) ? (x) : (y))
182
183#ifndef _NFILE            /* rough guess at maximum number of open files */
184#define _NFILE 20
185#endif
186
187#define EOT_STR "\004"
188#define EOT_CHR '\004'
189
190/* connection types */
191#define CONN_UNIX     0
192#define CONN_INTERNET 1
193#define CONN_IPC      2
194
195/* function declarations */
196int make_connection (char *hostarg, int portarg, int *s);
197#ifdef SYSV_IPC
198void disconnect_from_ipc_server();
199#endif
200#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
201void send_string (int s, const char *msg);
202void disconnect_from_server (int s, int echo);
203int read_line (int s, char *dest);
204#endif
205#ifdef INTERNET_DOMAIN_SOCKETS
206int internet_addr (char *host);
207#endif
208