dm.h revision b7d26471
1/*
2
3Copyright 1988, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included
12in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall
23not be used in advertising or otherwise to promote the sale, use or
24other dealings in this Software without prior written authorization
25from The Open Group.
26
27*/
28
29/*
30 * xdm - display manager daemon
31 * Author:  Keith Packard, MIT X Consortium
32 *
33 * dm.h
34 *
35 * public interfaces for greet/verify functionality
36 */
37
38#ifndef _DM_H_
39# define _DM_H_ 1
40
41# ifdef HAVE_CONFIG_H
42#  include "config.h"
43# endif
44
45# include <X11/Xos.h>
46# include <X11/Xfuncs.h>
47# include <X11/Xfuncproto.h>
48# include <X11/Xmd.h>
49# include <X11/Xauth.h>
50# include <X11/Intrinsic.h>
51
52# if defined(X_POSIX_C_SOURCE)
53#  define _POSIX_C_SOURCE X_POSIX_C_SOURCE
54#  include <setjmp.h>
55#  include <limits.h>
56#  undef _POSIX_C_SOURCE
57# else
58#  include <setjmp.h>
59#  include <limits.h>
60# endif
61# include <time.h>
62# define Time_t time_t
63
64/* If XDMCP symbol defined, compile to run XDMCP protocol */
65
66# define XDMCP
67
68# ifdef XDMCP
69#  include <X11/Xdmcp.h>
70# endif
71
72# ifdef pegasus
73#  undef dirty		/* Some bozo put a macro called dirty in sys/param.h */
74# endif /* pegasus */
75
76# ifndef X_NOT_POSIX
77#  ifdef _POSIX_SOURCE
78#   include <sys/wait.h>
79#  else
80#   define _POSIX_SOURCE
81#   include <sys/wait.h>
82#   undef _POSIX_SOURCE
83#  endif
84#  define waitCode(w)	(WIFEXITED(w) ? WEXITSTATUS(w) : 0)
85#  define waitSig(w)	(WIFSIGNALED(w) ? WTERMSIG(w) : 0)
86#  define waitCore(w)    0	/* not in POSIX.  so what? */
87typedef int		waitType;
88# else /* X_NOT_POSIX */
89#  ifdef SYSV
90#   define waitCode(w)	(((w) >> 8) & 0x7f)
91#   define waitSig(w)	((w) & 0xff)
92#   define waitCore(w)	(((w) >> 15) & 0x01)
93typedef int		waitType;
94#  else /* SYSV */
95#   include <sys/wait.h>
96#   define waitCode(w)	((w).w_T.w_Retcode)
97#   define waitSig(w)	((w).w_T.w_Termsig)
98#   define waitCore(w)	((w).w_T.w_Coredump)
99typedef union wait	waitType;
100#  endif
101# endif /* X_NOT_POSIX */
102
103# ifdef USE_PAM
104#  ifdef HAVE_SECURITY_PAM_APPL_H
105#   include <security/pam_appl.h>
106#  elif defined(HAVE_PAM_PAM_APPL_H)
107#   include <pam/pam_appl.h>
108#  else
109#   error "Unable to determine pam headers"
110#  endif
111# endif
112
113# ifdef CSRG_BASED
114#  include <sys/param.h>
115#  ifdef HAVE_SETUSERCONTEXT
116#   include <login_cap.h>
117#   include <pwd.h>
118#   ifdef USE_BSDAUTH
119#    include <bsd_auth.h>
120#   endif
121#  endif
122# endif
123
124# define waitCompose(sig,core,code) ((sig) * 256 + (core) * 128 + (code))
125# define waitVal(w)	waitCompose(waitSig(w), waitCore(w), waitCode(w))
126
127typedef enum displayStatus { running, notRunning, zombie, phoenix } DisplayStatus;
128
129# ifndef FD_ZERO
130typedef	struct	my_fd_set { int fds_bits[1]; } my_fd_set;
131#  define FD_ZERO(fdp)	bzero ((fdp), sizeof (*(fdp)))
132#  define FD_SET(f,fdp)	((fdp)->fds_bits[(f) / (sizeof (int) * 8)] |=  (1 << ((f) % (sizeof (int) * 8))))
133#  define FD_CLR(f,fdp)	((fdp)->fds_bits[(f) / (sizeof (int) * 8)] &= ~(1 << ((f) % (sizeof (int) * 8))))
134#  define FD_ISSET(f,fdp)	((fdp)->fds_bits[(f) / (sizeof (int) * 8)] & (1 << ((f) % (sizeof (int) * 8))))
135#  define FD_TYPE	my_fd_set
136# else
137#  define FD_TYPE	fd_set
138# endif
139
140/*
141 * local     - server runs on local host
142 * foreign   - server runs on remote host
143 * permanent - session restarted when it exits
144 * transient - session not restarted when it exits
145 * fromFile  - started via entry in servers file
146 * fromXDMCP - started with XDMCP
147 */
148
149typedef struct displayType {
150	unsigned int	location:1;
151	unsigned int	lifetime:1;
152	unsigned int	origin:1;
153} DisplayType;
154
155# define Local		1
156# define Foreign	0
157
158# define Permanent	1
159# define Transient	0
160
161# define FromFile	1
162# define FromXDMCP	0
163
164extern DisplayType parseDisplayType (char *string, int *usedDefault);
165
166typedef enum fileState { NewEntry, OldEntry, MissingEntry } FileState;
167
168struct display {
169	struct display	*next;
170	/* Xservers file / XDMCP information */
171	char		*name;		/* DISPLAY name */
172	char		*class;		/* display class (may be NULL) */
173	DisplayType	displayType;	/* method to handle with */
174	char		**argv;		/* program name and arguments */
175
176	/* display state */
177	DisplayStatus	status;		/* current status */
178	pid_t		pid;		/* process id of child */
179	pid_t		serverPid;	/* process id of server (-1 if none) */
180	FileState	state;		/* state during HUP processing */
181	int		startTries;	/* current start try */
182	Time_t		lastReserv;     /* time of last reserver crash */
183	int		reservTries;	/* current reserver try */
184# ifdef XDMCP
185	/* XDMCP state */
186	CARD32		sessionID;	/* ID of active session */
187	XdmcpNetaddr    peer;		/* display peer address */
188	int		peerlen;	/* length of peer address */
189	XdmcpNetaddr    from;		/* XDMCP port of display */
190	int		fromlen;
191	CARD16		displayNumber;
192	int		useChooser;	/* Run the chooser for this display */
193	ARRAY8		clientAddr;	/* for chooser picking */
194	CARD16		connectionType;	/* ... */
195	int		xdmcpFd;
196# endif
197	/* server management resources */
198	int		serverAttempts;	/* number of attempts at running X */
199	int		openDelay;	/* open delay time */
200	int		openRepeat;	/* open attempts to make */
201	int		openTimeout;	/* abort open attempt timeout */
202	int		startAttempts;	/* number of attempts at starting */
203	int		reservAttempts;	/* allowed start-IO error sequences */
204	int		pingInterval;	/* interval between XSync */
205	int		pingTimeout;	/* timeout for XSync */
206	int		terminateServer;/* restart for each session */
207	int		grabServer;	/* keep server grabbed for Login */
208	int		grabTimeout;	/* time to wait for grab */
209	int		resetSignal;	/* signal to reset server */
210	int		termSignal;	/* signal to terminate server */
211	int		resetForAuth;	/* server reads auth file at reset */
212	char            *keymaps;       /* binary compat with DEC */
213	char		*greeterLib;	/* greeter shared library name */
214
215	/* session resources */
216	char		*resources;	/* resource file */
217	char		*xrdb;		/* xrdb program */
218	char		*setup;		/* Xsetup program */
219	char		*startup;	/* Xstartup program */
220	char		*reset;		/* Xreset program */
221	char		*session;	/* Xsession program */
222	char		*userPath;	/* path set for session */
223	char		*systemPath;	/* path set for startup/reset */
224	char		*systemShell;	/* interpreter for startup/reset */
225	char		*failsafeClient;/* a client to start when the session fails */
226	char		*chooser;	/* chooser program */
227
228	/* authorization resources */
229	int		authorize;	/* enable authorization */
230	char		**authNames;	/* authorization protocol names */
231	unsigned short	*authNameLens;	/* authorization protocol name lens */
232	char		*clientAuthFile;/* client specified auth file */
233	char		*userAuthDir;	/* backup directory for tickets */
234	int		authComplain;	/* complain when no auth for XDMCP */
235
236	/* information potentially derived from resources */
237	int		authNameNum;	/* number of protocol names */
238	Xauth		**authorizations;/* authorization data */
239	int		authNum;	/* number of authorizations */
240	char		*authFile;	/* file to store authorization in */
241
242	int		version;	/* to keep dynamic greeter clued in */
243	/* add new fields only after here.  And preferably at the end. */
244
245	/* Hack for making "Willing to manage" configurable */
246	char		*willing;	/* "Willing to manage" program */
247	Display		*dpy;		/* Display */
248	char		*windowPath;	/* path to server "window" */
249};
250
251# ifdef XDMCP
252
253#  define PROTO_TIMEOUT	(30 * 60)   /* 30 minutes should be long enough */
254#  define XDM_BROKEN_INTERVAL (120)   /* server crashing more than once within */
255                                    /* two minutes is assumed to be broken!  */
256struct protoDisplay {
257	struct protoDisplay	*next;
258	XdmcpNetaddr		address;   /* UDP address */
259	int			addrlen;    /* UDP address length */
260	unsigned long		date;	    /* creation date */
261	CARD16			displayNumber;
262	CARD16			connectionType;
263	ARRAY8			connectionAddress;
264	CARD32			sessionID;
265	Xauth			*fileAuthorization;
266	Xauth			*xdmcpAuthorization;
267	ARRAY8			authenticationName;
268	ARRAY8			authenticationData;
269	XdmAuthKeyRec		key;
270};
271# endif /* XDMCP */
272
273struct greet_info {
274	char		*name;		/* user name */
275	char		*password;	/* user password */
276	char		*string;	/* random string */
277	char            *passwd;        /* binary compat with DEC */
278	int		version;	/* for dynamic greeter to see */
279	/* add new fields below this line, and preferably at the end */
280	Boolean		allow_null_passwd; /* allow null password on login */
281	Boolean		allow_root_login; /* allow direct root login */
282};
283
284typedef void (*ChooserFunc)(CARD16 connectionType, ARRAY8Ptr addr, char *closure);
285typedef void (*ListenFunc)(ARRAY8Ptr addr, void **closure);
286
287struct verify_info {
288	int		uid;		/* user id */
289	int		gid;		/* group id */
290	char		**argv;		/* arguments to session */
291	char		**userEnviron;	/* environment for session */
292	char		**systemEnviron;/* environment for startup/reset */
293	int		version;	/* for dynamic greeter to see */
294	/* add new fields below this line, and preferably at the end */
295};
296
297/* display manager exit status definitions */
298
299# define OBEYSESS_DISPLAY	0	/* obey multipleSessions resource */
300# define REMANAGE_DISPLAY	1	/* force remanage */
301# define UNMANAGE_DISPLAY	2	/* force deletion */
302# define RESERVER_DISPLAY	3	/* force server termination */
303# define OPENFAILED_DISPLAY	4	/* XOpenDisplay failed, retry */
304
305# ifndef TRUE
306#  define TRUE	1
307#  define FALSE	0
308# endif
309
310extern char	*config;
311
312extern char	*servers;
313extern int	request_port;
314extern int	debugLevel;
315extern char	*errorLogFile;
316extern int	daemonMode;
317extern char	*pidFile;
318extern int	lockPidFile;
319extern char	*authDir;
320extern int	autoRescan;
321extern int	removeDomainname;
322extern char	*keyFile;
323extern char	*accessFile;
324extern char	**exportList;
325# if !defined(HAVE_ARC4RANDOM)
326extern char	*randomFile;
327extern char	*prngdSocket;
328extern int	prngdPort;
329# endif
330
331extern char	*greeterLib;
332extern char	*willing;
333extern int	choiceTimeout;	/* chooser choice timeout */
334
335extern struct display	*FindDisplayByName (char *name),
336			*FindDisplayBySessionID (CARD32 sessionID),
337			*FindDisplayByAddress (XdmcpNetaddr addr, int addrlen, CARD16 displayNumber),
338			*FindDisplayByPid (pid_t pid),
339			*FindDisplayByServerPid (pid_t serverPid),
340			*NewDisplay (char *name, char *class);
341
342extern struct protoDisplay	*FindProtoDisplay (
343					XdmcpNetaddr address,
344					int          addrlen,
345					CARD16       displayNumber);
346extern struct protoDisplay	*NewProtoDisplay (
347					XdmcpNetaddr address,
348					int	     addrlen,
349					CARD16	     displayNumber,
350					CARD16	     connectionType,
351					ARRAY8Ptr    connectionAddress,
352					CARD32	     sessionID);
353
354/* in Login.c */
355extern void DrawFail (Widget ctx);
356
357/* in access.c */
358extern ARRAY8Ptr getLocalAddress (void);
359extern int AcceptableDisplayAddress (ARRAY8Ptr clientAddress, CARD16 connectionType, xdmOpCode type);
360extern int ForEachMatchingIndirectHost (ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure);
361extern int ScanAccessDatabase (void);
362extern int UseChooser (ARRAY8Ptr clientAddress, CARD16 connectionType);
363extern void ForEachChooserHost (ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure);
364extern void ForEachListenAddr(ListenFunc listenfunction,
365  ListenFunc mcastfcuntion, void **closure);
366
367/* in choose.c */
368extern ARRAY8Ptr IndirectChoice (ARRAY8Ptr clientAddress, CARD16 connectionType);
369extern int IsIndirectClient (ARRAY8Ptr clientAddress, CARD16 connectionType);
370extern int RememberIndirectClient (ARRAY8Ptr clientAddress, CARD16 connectionType);
371extern void ForgetIndirectClient ( ARRAY8Ptr clientAddress, CARD16 connectionType);
372extern void ProcessChooserSocket (int fd);
373
374/* in chooser.c */
375extern void RunChooser (struct display *d) _X_NORETURN;
376
377/* in daemon.c */
378extern void BecomeDaemon (void);
379extern void BecomeOrphan (void);
380
381/* in dm.c */
382extern void CloseOnFork (void);
383extern void RegisterCloseOnFork (int fd);
384extern void StartDisplay (struct display *d);
385# ifndef HAVE_SETPROCTITLE
386extern void SetTitle (char *name, ...);
387# endif
388
389/* in dpylist.c */
390extern int AnyDisplaysLeft (void);
391extern void ForEachDisplay (void (*f)(struct display *));
392extern void RemoveDisplay (struct display *old);
393
394/* in file.c */
395extern void ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable);
396
397/* in netaddr.c */
398extern char *NetaddrAddress(XdmcpNetaddr netaddrp, int *lenp);
399extern char *NetaddrPort(XdmcpNetaddr netaddrp, int *lenp);
400extern int ConvertAddr (XdmcpNetaddr saddr, int *len, char **addr);
401extern int NetaddrFamily (XdmcpNetaddr netaddrp);
402extern int addressEqual (XdmcpNetaddr a1, int len1, XdmcpNetaddr a2, int len2);
403
404/* in policy.c */
405extern ARRAY8Ptr ChooseAuthentication (ARRAYofARRAY8Ptr authenticationNames);
406extern int CheckAuthentication (struct protoDisplay *pdpy, ARRAY8Ptr displayID, ARRAY8Ptr name, ARRAY8Ptr data);
407extern int SelectAuthorizationTypeIndex (ARRAY8Ptr authenticationName, ARRAYofARRAY8Ptr authorizationNames);
408extern int SelectConnectionTypeIndex (ARRAY16Ptr connectionTypes, ARRAYofARRAY8Ptr connectionAddresses);
409extern int Willing (ARRAY8Ptr addr, CARD16 connectionType, ARRAY8Ptr authenticationName, ARRAY8Ptr status, xdmOpCode type);
410
411/* in protodpy.c */
412extern void DisposeProtoDisplay(struct protoDisplay *pdpy);
413
414/* in reset.c */
415extern void pseudoReset (Display *dpy);
416
417/* in resource.c */
418extern void InitResources (int argc, char **argv);
419extern void LoadDMResources (void);
420extern void LoadServerResources (struct display *d);
421extern void LoadSessionResources (struct display *d);
422extern void ReinitResources (void);
423
424/* in session.c */
425# ifdef USE_PAM
426extern pam_handle_t **thepamhp(void);
427extern pam_handle_t *thepamh(void);
428# endif
429extern char **defaultEnv (void);
430extern char **systemEnv (struct display *d, char *user, char *home);
431extern int PingServer(struct display *d, Display *alternateDpy);
432extern int source (char **environ, char *file);
433extern void ClearCloseOnFork (int fd);
434extern void DeleteXloginResources (struct display *d, Display *dpy);
435extern void LoadXloginResources (struct display *d);
436extern void ManageSession (struct display *d) _X_NORETURN;
437extern void SecureDisplay (struct display *d, Display *dpy);
438extern void SessionExit (struct display *d, int status, int removeAuth) _X_NORETURN;
439extern void SessionPingFailed (struct display *d) _X_NORETURN;
440extern void SetupDisplay (struct display *d);
441extern void UnsecureDisplay (struct display *d, Display *dpy);
442extern void execute(char **argv, char **environ);
443
444/* server.c */
445extern const char *_SysErrorMsg (int n);
446extern int StartServer (struct display *d);
447extern int WaitForServer (struct display *d);
448extern void ResetServer (struct display *d);
449
450/* socket.c */
451extern int GetChooserAddr (char *addr, int *lenp);
452extern void CreateWellKnownSockets (void);
453extern void UpdateListenSockets (void);
454extern void CloseListenSockets (void);
455extern void ProcessListenSockets (fd_set *readmask);
456
457/* in util.c */
458# ifndef HAVE_ASPRINTF
459#  define asprintf Asprintf
460extern int Asprintf(char ** ret, const char *restrict format, ...)
461    _X_ATTRIBUTE_PRINTF(2,3);
462# endif
463extern char *localHostname (void);
464extern char **parseArgs (char **argv, const char *string);
465extern char **setEnv (char **e, const char *name, const char *value);
466extern char **putEnv(const char *string, char **env);
467extern char *getEnv (char **e, const char *name);
468extern void CleanUpChild (void);
469extern void freeArgs (char **argv);
470extern void freeEnv (char **env);
471extern void printEnv (char **e);
472
473/* in verify.c */
474extern int Verify (struct display *d, struct greet_info *greet, struct verify_info *verify);
475
476/* in xdmcp.c */
477extern char *NetworkAddressToHostname (CARD16 connectionType, ARRAY8Ptr connectionAddress);
478extern int AnyWellKnownSockets (void);
479extern void DestroyWellKnownSockets (void);
480extern void SendFailed (struct display *d, const char *reason);
481extern void StopDisplay (struct display *d);
482extern void WaitForChild (void);
483extern void WaitForSomething (void);
484extern void init_session_id(void);
485extern void registerHostname(char *name, int namelen);
486extern void ProcessRequestSocket(int fd);
487
488/*
489 * CloseOnFork flags
490 */
491
492# define CLOSE_ALWAYS	    0
493# define LEAVE_FOR_DISPLAY  1
494
495# include <stdlib.h>
496
497# if defined(X_NOT_POSIX) || defined(__NetBSD__) && defined(__sparc__)
498#  if defined(SYSV)
499#   define SIGNALS_RESET_WHEN_CAUGHT
500#   define UNRELIABLE_SIGNALS
501#  endif
502#  define Setjmp(e)	setjmp(e)
503#  define Longjmp(e,v)	longjmp(e,v)
504#  define Jmp_buf		jmp_buf
505# else
506#  define Setjmp(e)   sigsetjmp(e,1)
507#  define Longjmp(e,v)	siglongjmp(e,v)
508#  define Jmp_buf		sigjmp_buf
509# endif
510
511typedef void (*SIGFUNC)(int);
512
513void (*Signal(int, SIGFUNC Handler))(int);
514
515#endif /* _DM_H_ */
516